/* DataMap — tokens from the data-viz reference palette. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #2a78d6;
  --nodata: #ebeae5;
  --ocean: #f3f2ee;
  --critical: #d03b3b;
  --warning: #fab219;
  --good: #0ca30c;
  --shadow: 0 1px 2px rgba(11, 11, 11, .05), 0 8px 24px rgba(11, 11, 11, .06);
  --r: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.20);
    --accent: #3987e5;
    --nodata: #262624;
    --ocean: #232322;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);
  --accent: #3987e5;
  --nodata: #262624;
  --ocean: #232322;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 320px 1fr; min-height: 100vh; }
.panel {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 18px 16px 40px;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
}
.stage { padding: 18px 22px 48px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
/* Flex items default to min-width:auto and would grow to fit a wide table. */
.stage > * { min-width: 0; max-width: 100%; }

/* ---------- panel bits ---------- */
.brand { display: flex; align-items: baseline; gap: 8px; margin-bottom: 16px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }

.group { border-top: 1px solid var(--grid); padding-top: 14px; margin-top: 14px; }
.group:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.group > h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 10px; font-weight: 600;
}
.field { margin-bottom: 10px; }
.field > label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }

select, input[type="text"], input[type="number"], textarea {
  width: 100%; padding: 7px 9px;
  background: var(--plane);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
}
select:focus-visible, input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; resize: vertical; min-height: 130px; line-height: 1.45; }

.btn {
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
  background: var(--plane); border: 1px solid var(--border-strong);
}
.btn:hover { background: var(--grid); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--grid); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

.seg { display: flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; padding: 6px 4px; background: var(--plane); border: 0; cursor: pointer;
  border-right: 1px solid var(--border-strong); font-size: 12px; color: var(--text-secondary);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 22px; border-radius: 6px; cursor: pointer; padding: 0;
  border: 1px solid var(--border); position: relative; overflow: hidden;
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }
.swatch i { display: block; height: 100%; float: left; }

.check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-secondary); margin: 7px 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.hint { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; }
.status { font-size: 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.status b { font-weight: 600; }
.status .ok { color: var(--good); }
.status .warn { color: var(--critical); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }

/* ---------- stage ---------- */
.stage-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.titles { flex: 1; min-width: 240px; }
.titles input {
  border: 1px solid transparent; background: transparent; padding: 2px 6px; margin-left: -6px;
  border-radius: 6px; width: 100%;
}
.titles input:hover { border-color: var(--border); }
#chartTitle { font-size: 22px; font-weight: 650; letter-spacing: -0.015em; }
#chartSub { font-size: 13px; color: var(--text-secondary); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 6px 10px 12px;
  position: relative;
}
#mapWrap { min-height: 260px; }
svg#map { display: block; width: 100%; height: auto; }
svg#map .region { stroke: var(--surface-1); stroke-width: 0.6px; stroke-linejoin: round; cursor: default; transition: fill 140ms ease; }
svg#map .region.hit:hover { stroke: var(--text-primary); stroke-width: 1.4px; }
svg#map .region.sel { stroke: var(--text-primary); stroke-width: 1.6px; }
svg#map .outline { fill: none; stroke: var(--axis); stroke-width: 0.7px; pointer-events: none; }
svg#map .graticule { fill: none; stroke: var(--grid); stroke-width: 0.5px; pointer-events: none; }
svg#map .sphere { fill: var(--ocean); stroke: var(--axis); stroke-width: 0.7px; }
svg#map text.lbl {
  font-family: var(--font); font-size: 9px; font-weight: 600;
  fill: var(--text-primary); paint-order: stroke; stroke: var(--surface-1); stroke-width: 2.4px;
  pointer-events: none; text-anchor: middle;
}

/* ---------- loading ---------- */
.loading {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  border-radius: var(--r); backdrop-filter: blur(1px);
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--grid); border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; color: var(--text-secondary); }
.loading-bar { width: 210px; height: 4px; border-radius: 2px; background: var(--grid); overflow: hidden; }
.loading-bar i { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--accent); transition: width 140ms linear; }
.loading-bar i.indeterminate { animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.loading-pct { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .loading-bar i.indeterminate { animation: none; }
}

.tooltip {
  position: fixed; z-index: 40; pointer-events: none; opacity: 0;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 7px 10px; box-shadow: var(--shadow);
  font-size: 12.5px; max-width: 260px; transition: opacity 90ms ease;
}
.tooltip .t-name { font-weight: 650; margin-bottom: 1px; }
.tooltip .t-val { font-size: 16px; font-weight: 600; }
.tooltip .t-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.tooltip .t-chip { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: baseline; border: 1px solid var(--border); }

/* ---------- legend ---------- */
.legend { display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap; padding: 0 4px 0 0; max-width: 100%; }
.legend > div { min-width: 0; max-width: 100%; }
.legend-title { font-size: 11.5px; color: var(--text-secondary); margin-bottom: 5px; }
.lg-bins { display: flex; max-width: 100%; padding-right: 26px; }
.lg-bin { display: flex; flex-direction: column; align-items: stretch; flex: 1 1 auto; min-width: 0; }
.lg-bin i { display: block; height: 12px; width: 46px; max-width: 100%; border-radius: 2px; }
.lg-bin.start { flex: 0 0 0; }
.lg-bin.first i { border-radius: 3px 2px 2px 3px; }
.lg-bin.last i { border-radius: 2px 3px 3px 2px; }
.lg-bin span { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 4px; text-align: right; transform: translateX(50%); white-space: nowrap; }
.lg-cont { width: 220px; height: 12px; border-radius: 3px; }
.lg-cont-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 4px; }
.lg-na { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.lg-na i { width: 14px; height: 12px; border-radius: 3px; background: var(--nodata); border: 1px solid var(--border); display: inline-block; }

/* ---------- stats + table ---------- */
.tiles { display: flex; gap: 10px; flex-wrap: wrap; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); padding: 9px 14px; min-width: 108px; }
.tile dt { font-size: 11px; color: var(--muted); margin: 0 0 2px; }
.tile dd { margin: 0; font-size: 19px; font-weight: 620; letter-spacing: -0.01em; }
.tile dd small { font-size: 11px; font-weight: 400; color: var(--muted); display: block; letter-spacing: 0; }

details.tableview { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); min-width: 0; overflow: hidden; }
details.tableview > summary { cursor: pointer; padding: 10px 14px; font-size: 13px; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.tableview > summary::-webkit-details-marker { display: none; }
details.tableview > summary::before { content: "▸"; color: var(--muted); font-size: 11px; }
details.tableview[open] > summary::before { content: "▾"; }
details.tableview > summary em { font-style: normal; color: var(--muted); font-weight: 400; font-size: 12px; }
.tw { max-height: 420px; max-width: 100%; overflow: auto; border-top: 1px solid var(--grid); }
table.data { width: 100%; min-width: 320px; border-collapse: collapse; font-size: 12.5px; }
table.data th, table.data td { padding: 5px 14px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface-1); font-weight: 600; color: var(--text-secondary); cursor: pointer; user-select: none; z-index: 1; }
table.data th::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--grid); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--plane); }
table.data i.chip { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 7px; border: 1px solid var(--border); }
table.data td.rank { color: var(--muted); font-variant-numeric: tabular-nums; }

.unmatched { padding: 10px 14px; font-size: 12.5px; color: var(--text-secondary); border-top: 1px solid var(--grid); }
.unmatched code { background: var(--plane); padding: 1px 5px; border-radius: 4px; margin: 0 3px 3px 0; display: inline-block; border: 1px solid var(--border); font-size: 11.5px; }

.foot { color: var(--muted); font-size: 11.5px; padding: 0 4px; }
.foot input { border: 1px solid transparent; background: transparent; padding: 2px 5px; margin-left: -5px; border-radius: 5px; width: 100%; color: var(--muted); font-size: 11.5px; }
.foot input:hover { border-color: var(--border); }

.toolbar { display: flex; gap: 6px; align-items: center; }

/* forced-colors / print fallbacks keep the map readable without color */
@media print {
  .panel, .toolbar { display: none; }
  .app { grid-template-columns: 1fr; }
  .card { box-shadow: none; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--border); }
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
