/* Dark-first UI. Chart tokens follow the dataviz reference palette (dark steps). */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --series-1: #3987e5; /* blue */
  --series-2: #d95926; /* orange */
  --series-3: #199e70; /* aqua */
  --accent: #eda100;
  --gain: #3987e5;
  --loss: #e66767;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--text-primary); }
body {
  display: grid;
  grid-template-columns: 360px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "top top" "side main";
  overflow: hidden;
}
button, .button, input, select { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 9px;
  padding: 6px 12px; cursor: pointer; transition: background .15s, border-color .15s;
}
button:hover, .button:hover { background: var(--surface-3); }
button.primary { background: linear-gradient(135deg, #eda100, #d95926); border: none; color: #0b0b0b; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost, .button.ghost { background: transparent; }
button.icon { width: 34px; height: 34px; padding: 0; border-radius: 50%; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }

/* top bar */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  border-bottom: 1px solid var(--border); background: rgba(26, 26, 25, 0.85); backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand strong { font-size: 17px; letter-spacing: .2px; }
.sun-dot { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffd36b, #eda100 55%, #d95926); box-shadow: 0 0 14px #eda10088; }
.project-name { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; min-width: 200px; }
.project-name:hover, .project-name:focus { border-color: var(--border); }
.status { flex: 1; color: var(--text-secondary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status .bar { display: inline-block; width: 80px; height: 4px; border-radius: 2px; background: var(--surface-3); vertical-align: middle; margin-left: 8px; overflow: hidden; }
.status .bar i { display: block; height: 100%; background: var(--accent); }
.actions { display: flex; gap: 6px; }

/* sidebar */
.sidebar { grid-area: side; overflow-y: auto; border-right: 1px solid var(--border); background: var(--surface-1); padding: 8px 0 40px; }
.section { border-bottom: 1px solid var(--border); }
.section > summary {
  list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: "›"; color: var(--text-muted); transition: transform .2s; }
.section[open] > summary::after { transform: rotate(90deg); }
.section .body { padding: 0 16px 14px; display: grid; gap: 10px; }
.field { display: grid; gap: 4px; }
.field > span { color: var(--text-secondary); font-size: 12px; display: flex; justify-content: space-between; }
.field > span output { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.field input[type="number"], .field input[type="text"], .field select, .search input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { flex: 1; border: none; background: transparent; border-radius: 7px; padding: 5px 6px; font-size: 13px; color: var(--text-secondary); }
.seg button.on { background: var(--surface-3); color: var(--text-primary); box-shadow: 0 1px 0 rgba(255,255,255,.06) inset; }
.osm-dark { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6); }
.map { height: 180px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.search { position: relative; }
.search ul { position: absolute; z-index: 1000; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px; list-style: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.search li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search li:hover { background: var(--surface-3); }
.checks { display: grid; gap: 6px; }
.check { display: grid; grid-template-columns: 18px 1fr; gap: 6px; font-size: 12.5px; color: var(--text-secondary); align-items: start; }
.check b { color: var(--text-primary); font-weight: 600; }
.check .ic { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; color: #0b0b0b; font-weight: 700; margin-top: 1px; }
.check.good .ic { background: var(--good); }
.check.warning .ic { background: var(--warning); }
.check.critical .ic { background: var(--critical); color: #fff; }
.obst { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 8px; }
.obst .row3 input { padding: 4px 6px; }
.obst header { font-size: 12px; color: var(--text-secondary); grid-column: 1 / -1; display: flex; justify-content: space-between; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }

/* main */
.main { grid-area: main; overflow-y: auto; padding: 16px; display: grid; gap: 16px; align-content: start; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card > header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card > header .sub { margin: 4px 0 12px; color: var(--text-muted); font-size: 12.5px; }
.viewport { padding: 0; position: relative; overflow: hidden; height: 46vh; min-height: 340px; }
.scene { position: absolute; inset: 0; }
.scene canvas { display: block; }
.scene-hud { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; justify-content: space-between; align-items: end; gap: 12px; pointer-events: none; }
.scene-hud > * { pointer-events: auto; }
.hud-now { background: rgba(13,13,13,.72); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; display: grid; gap: 2px; min-width: 210px; }
.hud-now .big { font-size: 26px; font-weight: 600; }
.hud-now .l { color: var(--text-secondary); font-size: 12px; }
.hud-controls { background: rgba(13,13,13,.72); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: end; }
.hud-controls label { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 12px; }
.hud-controls input[type="range"] { width: 140px; }
.hud-controls .mono { min-width: 52px; font-size: 12px; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; }
.tile .label { color: var(--text-secondary); font-size: 12.5px; }
.tile .value { font-size: 24px; font-weight: 600; }
.tile .value small { font-size: 13px; color: var(--text-secondary); font-weight: 400; margin-left: 3px; }
.tile .note { color: var(--text-muted); font-size: 12px; }
.tile.hero { background: linear-gradient(160deg, #2a2110, var(--surface-1) 60%); border-color: #eda10044; }
.tile.hero .value { font-size: 30px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span2 { grid-column: span 2; }
svg { display: block; overflow: visible; }
svg text { fill: var(--text-secondary); font-size: 11.5px; font-family: inherit; }
svg .muted-t { fill: var(--text-muted); }
svg .prim { fill: var(--text-primary); }
svg .num { font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; vertical-align: 3px; width: 14px; }
.tooltip { position: fixed; z-index: 2000; pointer-events: none; background: #0d0d0d; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--text-primary); box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 280px; }
.tooltip .t { color: var(--text-secondary); margin-bottom: 2px; }
.fin { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fin .tile { padding: 10px 12px; }
.fin .tile .value { font-size: 19px; }
.assumptions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 24px; font-size: 12.5px; color: var(--text-secondary); }
.assumptions dt { color: var(--text-muted); font-size: 11.5px; margin-top: 6px; }
.assumptions dd { margin: 0; color: var(--text-primary); }
.banner { background: #3a2a06; border: 1px solid #fab21955; color: var(--text-primary); border-radius: 10px; padding: 8px 12px; font-size: 12.5px; }
table.data { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--grid); }
table.data th:first-child, table.data td:first-child { text-align: left; }
details.table-view summary { cursor: pointer; color: var(--text-muted); font-size: 12px; margin-top: 8px; }

@media (max-width: 1300px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1000px) {
  body { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .sidebar { display: none; }
  .grid { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
}

@media print {
  body { display: block; overflow: visible; background: #fff; }
  .sidebar, .actions, .hud-controls, #btnExplore { display: none !important; }
  .main { overflow: visible; }
  .card, .tile { break-inside: avoid; }
}
