:root {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #34332f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --route: #ffffff;
  --teleport: #7fd0ff;
  --critical: #d03b3b;
  --seg-1: #3987e5;   /* mining   */
  --seg-2: #d95926;   /* overhead */
  --seg-3: #199e70;   /* travel   */
  --seg-4: #c98500;   /* idle     */
  --scene-bg: #0f0f0e;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --surface-0: #f3f2ef;
    --surface-1: #fcfcfb;
    --surface-2: #f0efec;
    --border: #dddcd6;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #77766f;
    --accent: #2a78d6;
    --route: #111111;
    --teleport: #1c5cab;
    --seg-1: #2a78d6;
    --seg-2: #eb6834;
    --seg-3: #1baf7a;
    --seg-4: #eda100;
    --scene-bg: #e9e8e4;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--surface-0); color: var(--text-primary); }
.app { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }
.sidebar { background: var(--surface-1); border-right: 1px solid var(--border); overflow-y: auto; padding: 16px; }
.brand h1 { font-size: 17px; margin: 0 0 4px; }
.muted { color: var(--text-muted); }
.hint { color: var(--text-muted); font-size: 12px; margin: 6px 0 0; line-height: 1.4; }
.group { border-top: 1px solid var(--border); padding: 12px 0; }
.group h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); margin: 0 0 8px; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 6px 0; color: var(--text-secondary); }
.field input[type=number], .field select { width: 120px; }
.field input[type=range] { width: 130px; }
input[type=number], select { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 7px; font: inherit; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); margin: 4px 0; cursor: pointer; }
.check select { padding: 3px 5px; }
.tp { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.tp .field { margin: 4px 0; }
.tp .field input { width: 90px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); border-radius: 999px; padding: 4px 10px 4px 8px; cursor: pointer; user-select: none; font-size: 13px; }
.chip .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chip.on { color: var(--text-primary); border-color: var(--text-muted); }
.chip:not(.on) .sw { opacity: .3; }
.chip .n { color: var(--text-muted); font-size: 11px; }
.chips.small .chip { padding: 2px 8px 2px 6px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
button, .button { font: inherit; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-primary); padding: 7px 12px; cursor: pointer; text-decoration: none; display: inline-block; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; flex: 1 0 100%; padding: 9px; }
button.primary:disabled { opacity: .6; cursor: progress; }
button.ghost { background: transparent; padding: 4px 9px; }
.zones-head { font-size: 12px; margin: 10px 0 4px; }
.zone { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); margin: 3px 0; }
.zone .coords { color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.zone .rm { margin-left: auto; padding: 0 6px; }
.zone-add { display: flex; gap: 6px; margin-top: 6px; }
.zone-add input { flex: 1; min-width: 0; background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 7px; font: inherit; font-size: 12px; }
.blocked { margin-top: 6px; font-size: 13px; }
.blocked .tag { display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; margin: 2px; color: var(--text-secondary); cursor: pointer; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.kpis { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 12px; padding: 14px 16px 8px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-label { color: var(--text-secondary); font-size: 12px; }
.kpi-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi.hero .kpi-value { font-size: 30px; }
.kpi-value.small { font-size: 16px; }
.kpi-sub { color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breakdown { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; }
.bar { flex: 1; display: flex; gap: 2px; height: 12px; }
.bar .seg { height: 100%; border-radius: 3px; min-width: 2px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.loading .kpis, .loading .panel { opacity: .55; transition: opacity .2s; }

.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--border); align-items: end; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--text-secondary); padding: 8px 12px; }
.tabs button.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab-note { margin-left: auto; color: var(--text-muted); font-size: 12px; padding-bottom: 8px; max-width: 55%; text-align: right; }
.panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.panel.active { display: flex; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface-1); }
.toolbar .sep { width: 1px; height: 18px; background: var(--border); }
.toolbar .slider input { width: 110px; }
.viewport { position: relative; flex: 1; min-height: 0; background: var(--scene-bg); }
.viewport canvas { display: block; width: 100%; height: 100%; outline: none; }
.overlay-help { position: absolute; left: 12px; bottom: 10px; font-size: 12px; color: var(--text-muted); pointer-events: none; }
.count { position: absolute; right: 12px; bottom: 10px; font-size: 12px; color: var(--text-muted); pointer-events: none; }
button.accent { border-color: var(--accent); color: var(--text-primary); }
button.accent.on { background: var(--accent); color: var(--accent-ink); }
.walk { position: absolute; left: 50%; bottom: 34px; transform: translateX(-50%); width: min(720px, calc(100% - 32px));
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; z-index: 6; }
.walk-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.walk-bar .walk-count { font-weight: 650; font-variant-numeric: tabular-nums; margin: 0 6px; }
.walk-bar #w-close { margin-left: auto; }
.walk-info { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin-top: 8px; font-size: 13px; }
.walk-info dt { color: var(--text-muted); }
.walk-info dd { margin: 0; font-variant-numeric: tabular-nums; }
.walk-info .place { color: var(--text-primary); font-weight: 600; }
.walk-keys { font-size: 11px; margin-top: 6px; }
.details { position: absolute; top: 12px; right: 12px; width: 290px; max-height: calc(100% - 24px); overflow: auto;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; font-size: 13px; }
.details h3 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.details .close { margin-left: auto; padding: 0 7px; }
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; }
.details dt { color: var(--text-muted); }
.details dd { margin: 0; font-variant-numeric: tabular-nums; }
.details .row { margin-top: 10px; display: flex; gap: 6px; }

.graph-head { display: flex; gap: 16px; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-1); flex-wrap: wrap; }
.readout { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.readout b { color: var(--text-primary); }
.graph-wrap, .heat-wrap { position: relative; flex: 1; min-height: 0; background: var(--surface-1); }
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
#graph.dragging { cursor: grabbing; }
.heat-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 9px; font-size: 12px; color: var(--text-secondary); max-width: 260px; z-index: 5; }
.tooltip b { color: var(--text-primary); font-size: 13px; }
.graph-legend { position: absolute; left: 12px; bottom: 12px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 12px; color: var(--text-secondary); }
.graph-legend.static { position: static; margin: 8px 16px; display: inline-block; }
.ramp { display: flex; gap: 2px; margin-top: 4px; }
.ramp span { width: 26px; height: 10px; border-radius: 2px; }
.ramp-ticks { display: flex; justify-content: space-between; color: var(--text-muted); margin-top: 2px; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }

.table-wrap { flex: 1; overflow: auto; padding: 0 16px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { position: sticky; top: 0; background: var(--surface-0); text-align: right; color: var(--text-secondary); font-weight: 600; padding: 8px 8px; border-bottom: 1px solid var(--border); }
table.data td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.data th:nth-child(-n+2), table.data td:nth-child(-n+2) { text-align: left; }
table.data tr:hover td { background: var(--surface-2); }
.notes { padding: 10px 16px 16px; color: var(--text-secondary); font-size: 13px; border-top: 1px solid var(--border); }
.notes ul { margin: 4px 0 8px; padding-left: 18px; }
.flag { display: inline-flex; align-items: center; gap: 4px; }
.flag.spof::before { content: "⚠"; color: var(--critical); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi.hero { grid-column: 1 / -1; }
  .viewport, .graph-wrap, .heat-wrap { min-height: 70vh; }
  .breakdown { flex-direction: column; align-items: stretch; }
}
