:root {
  color-scheme: light;
  --ink: #1f2527;
  --muted: #647174;
  --paper: #f7f4ed;
  --panel: #ffffff;
  --panel-strong: #ece6d9;
  --line: #d8d0c1;
  --teal: #147c72;
  --coral: #df6b54;
  --gold: #c2912b;
  --green: #3c8a4a;
  --shadow: 0 22px 70px rgba(46, 39, 28, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(20, 124, 114, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(194, 145, 43, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 44px 44px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: #fff;
  background: var(--teal);
  cursor: pointer;
  font-weight: 750;
}

button:hover {
  filter: brightness(0.96);
}

button:active {
  transform: translateY(1px);
}

.secondary {
  color: var(--ink);
  background: var(--panel-strong);
}

.ghost {
  width: 100%;
  color: var(--teal);
  background: transparent;
  border: 1px solid rgba(20, 124, 114, 0.35);
}

.full-button {
  width: 100%;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.workspace {
  min-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
}

.topbar,
.data-band,
.control-rail,
.metric-rail,
.map-stage {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-radius: 8px;
  padding: 18px 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3.5vw, 3.7rem);
  line-height: 0.96;
}

h2 {
  font-size: 1rem;
}

.status-cluster {
  min-width: 116px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid rgba(60, 138, 74, 0.28);
  border-radius: 999px;
  background: rgba(60, 138, 74, 0.1);
  color: #235c2f;
  font-weight: 750;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(60, 138, 74, 0.16);
}

.stage-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(218px, 260px) minmax(0, 1fr) minmax(210px, 250px);
  gap: 16px;
}

.control-rail,
.metric-rail,
.map-stage,
.data-band {
  border-radius: 8px;
}

.control-rail,
.metric-rail {
  align-content: start;
  display: grid;
  gap: 16px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.api-panel {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid rgba(20, 124, 114, 0.22);
  border-radius: 8px;
  background: rgba(20, 124, 114, 0.08);
}

.api-panel span {
  color: var(--teal);
  font-size: 0.86rem;
  font-weight: 850;
}

.api-panel small {
  color: var(--muted);
  line-height: 1.35;
}

.label-row,
.band-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

label,
.metric span,
.band-header span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

output {
  color: var(--teal);
  font-weight: 800;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.map-stage {
  position: relative;
  min-height: 540px;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 18%, rgba(223, 107, 84, 0.12), transparent 30%),
    radial-gradient(circle at 88% 78%, rgba(20, 124, 114, 0.14), transparent 34%),
    #fbfaf6;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-width: calc(100% - 28px);
  padding: 9px 10px;
  border: 1px solid rgba(31, 37, 39, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  font-size: 0.82rem;
  font-weight: 750;
}

.ai-render {
  position: absolute;
  top: 14px;
  right: 14px;
  width: min(360px, 38%);
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(31, 37, 39, 0.12);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(31, 37, 39, 0.18);
}

.ai-render img {
  width: 100%;
  display: block;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend i {
  width: 24px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.legend .raw {
  background: var(--coral);
}

.legend .fixed {
  background: var(--teal);
}

.legend .field {
  background: var(--gold);
}

.metric {
  min-height: 82px;
  display: grid;
  gap: 6px;
  align-content: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.metric strong {
  font-size: clamp(1.3rem, 2vw, 1.85rem);
  line-height: 1;
}

.trace-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

ol {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
}

.ai-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

li {
  color: var(--muted);
  font-weight: 700;
}

li.done {
  color: var(--teal);
}

.data-band {
  min-height: 210px;
  padding: 16px;
}

.table-wrap {
  width: 100%;
  margin-top: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: #fffdfa;
}

th,
td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid rgba(216, 208, 193, 0.76);
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 1120px) {
  .stage-grid {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  }

  .metric-rail {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .trace-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 20px, 1480px);
    padding: 10px 0;
  }

  .workspace {
    min-height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-grid,
  .metric-rail {
    grid-template-columns: 1fr;
  }

  .map-stage {
    min-height: 420px;
  }

  .ai-render {
    position: relative;
    top: auto;
    right: auto;
    width: calc(100% - 28px);
    margin: 14px auto 0;
  }

  .button-row {
    grid-template-columns: 1fr;
  }
}
