:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel2: #172030;
  --line: #223047;
  --fg: #dbe4f0;
  --muted: #7d8da3;
  --accent: #4ade80;
  --accent2: #38bdf8;
  --warn: #fb923c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

body { display: flex; flex-direction: column; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #131b26, #0e141c);
  flex: 0 0 auto;
}
header h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.2px; white-space: nowrap; }
header h1 .sub { font-weight: 400; color: var(--muted); font-size: 14px; }
.sat { filter: grayscale(.2); }
.headline { font-size: 12.5px; color: #a9b6c8; max-width: 620px; }
.headline a { color: var(--accent2); text-decoration: none; }
.headline a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.counter { text-align: right; min-width: 120px; }
.c-val { font: 600 18px/1.1 var(--mono); color: var(--accent); }
.c-lab { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ---------- main ---------- */
main { flex: 1; display: flex; min-height: 0; }
#mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

.mapctl {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap;
  background: rgba(11,15,20,.86); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
}
.mapctl label { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.maphint {
  position: absolute; bottom: 10px; left: 12px; z-index: 5;
  font-size: 11.5px; color: #93a2b8; background: rgba(11,15,20,.8);
  padding: 5px 9px; border-radius: 6px; border: 1px solid var(--line);
}

select, button, input[type=range] { font-family: inherit; }
select {
  background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 7px; font-size: 12.5px; min-width: 130px;
}
button {
  background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 11px; font-size: 12.5px; cursor: pointer;
}
button:hover { border-color: #35507a; }
button.primary { background: #1d4ed8; border-color: #2563eb; color: #fff; font-weight: 600; width: 100%; padding: 9px; }
button.primary:disabled { background: #1b2534; border-color: var(--line); color: #55637a; cursor: not-allowed; }
button.ghost { background: transparent; }

/* ---------- panel ---------- */
#panel {
  width: 400px; flex: 0 0 400px; border-left: 1px solid var(--line);
  background: var(--panel); display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.tabs button {
  flex: 1; border: 0; border-radius: 0; background: transparent; color: var(--muted);
  padding: 10px 0; font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 2px solid transparent;
}
.tabs button.on { color: var(--fg); border-bottom-color: var(--accent); }
.tab { padding: 14px; overflow-y: auto; flex: 1; min-height: 0; }
.hidden { display: none; }
.empty { color: var(--muted); font-size: 12.5px; font-style: italic; }

.sellist { margin-bottom: 12px; }
.selrow {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px; margin-bottom: 5px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; font-size: 12px;
}
.selrow .sw { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.selrow .nm { flex: 1; font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selrow .x { cursor: pointer; color: var(--muted); padding: 0 3px; }
.selrow .x:hover { color: var(--warn); }
.note { margin-top: 9px; font-size: 11.5px; color: var(--muted); }
button.primary.alt { background: #15803d; border-color: #16a34a; margin-bottom: 2px; }
.fbrow { display: flex; gap: 7px; margin-bottom: 14px; }
.fbrow select { flex: 1; min-width: 0; }
#fallback { border-top: 1px solid var(--line); margin-top: 14px; }
.mapfail {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 6; max-width: 430px; text-align: center; line-height: 1.55;
  background: rgba(17,23,32,.96); border: 1px solid #3b4c66; border-radius: 10px;
  padding: 16px 20px; font-size: 12.5px; color: #c6d2e2;
}
.mapfail b { color: var(--warn); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 16px; }
.kpi { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.kpi .v { font: 600 16px/1.2 var(--mono); color: var(--accent2); }
.kpi .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-top: 2px; }

h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 16px 0 7px; font-weight: 600; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 11px; font-family: var(--mono); }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid #1a2536; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--panel2); position: sticky; top: 0; }
td.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }

.metasel { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; margin-bottom: 12px; }
.metasel select { width: 100%; }
details { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel2); }
details > summary { cursor: pointer; padding: 8px 11px; font-size: 12px; font-weight: 600; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--muted); }
details[open] > summary::before { content: "▾ "; }
details .body { padding: 0 11px 11px; }
pre { margin: 0; font-family: var(--mono); font-size: 10.5px; color: #b9c8dc; white-space: pre-wrap; word-break: break-word; }
.kv { display: grid; grid-template-columns: minmax(90px, 38%) 1fr; gap: 3px 10px; font-size: 11.5px; }
.kv dt { color: var(--muted); font-family: var(--mono); font-size: 10.5px; }
.kv dd { margin: 0; font-family: var(--mono); font-size: 11px; word-break: break-word; }
.chip { display: inline-block; background: #16233a; border: 1px solid #24406b; color: #9ec5ff; border-radius: 5px; padding: 0 6px; font-size: 10.5px; font-family: var(--mono); }

/* ---------- footer ---------- */
footer { flex: 0 0 auto; border-top: 1px solid var(--line); background: var(--panel); padding: 8px 16px 10px; }

/* One template for the master row, the axis and every lane, so the playhead
   lines up with the ticks below it to the pixel. */
.tlrow, .lane {
  display: grid;
  grid-template-columns: var(--lane-left) 1fr var(--lane-right);
  align-items: center;
  gap: 0 12px;
}
:root { --lane-left: 232px; --lane-right: 104px; }

.ctrls { display: flex; align-items: center; gap: 4px; }
.ctrls .ic {
  padding: 4px 7px; font-size: 11px; line-height: 1.1; background: var(--panel2);
  min-width: 30px; color: #b9c8dc;
}
.ctrls .ic.play { min-width: 40px; font-size: 13px; background: #14532d; border-color: #197544; color: #d7ffe6; }
.ctrls .ic.play.on { background: #7c2d12; border-color: #b4501f; color: #ffe2cf; }
.ctrls select { min-width: 56px; padding: 4px 5px; font-size: 11.5px; }

/* master scrubber — a plain div, not <input type=range>: a range thumb is
   inset by half its width at each end, so its position never matches a tick
   drawn at left:pct%. */
.master {
  position: relative; height: 22px; border-radius: 5px; cursor: pointer;
  background: #0e1620; border: 1px solid #22314a; outline: none;
}
.master:focus-visible { border-color: var(--accent2); }
.mfill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: linear-gradient(90deg, rgba(74,222,128,.14), rgba(74,222,128,.30));
  border-radius: 4px 0 0 4px; pointer-events: none;
}
.mhead {
  position: absolute; top: -3px; width: 3px; height: 28px; margin-left: -1.5px;
  background: #f78166; border-radius: 2px; pointer-events: none;
  box-shadow: 0 0 6px rgba(247,129,102,.85);
}
.tlmeta { text-align: right; }
#tl-date { font: 600 14px/1 var(--mono); color: var(--accent); }

.axis-row { margin-top: 2px; }
.tl-axis { position: relative; height: 14px; }
.tl-axis span {
  position: absolute; transform: translateX(-50%); font-size: 9.5px;
  color: var(--muted); font-family: var(--mono); white-space: nowrap;
}
.tl-axis span.edge-l { transform: none; }
.tl-axis span.edge-r { transform: translateX(-100%); }

.tlfoot { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.tlfoot label { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; }
.tlfoot input[type=range] { width: 90px; accent-color: #58a6ff; }

/* ---------- per-tile timeline lanes ---------- */
.lanes { max-height: 168px; overflow-y: auto; overflow-x: hidden; margin-top: 4px; }
.lanes .empty { padding: 8px 0; grid-column: 1 / -1; }
.lane { height: 24px; }
.lane .lhs { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lane .sw { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.lane .lbl {
  font-family: var(--mono); font-size: 10.5px; color: #aab8cc;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lane .track {
  position: relative; height: 15px; border-radius: 4px;
  background: #0e1620; border: 1px solid #1b2637; cursor: pointer;
}
.lane .tick { position: absolute; top: 2px; width: 2px; height: 11px; border-radius: 1px; margin-left: -1px; }
.lane .now {
  position: absolute; top: -2px; width: 2px; height: 19px; margin-left: -1px;
  background: #f78166; border-radius: 1px; pointer-events: none; opacity: .9;
}
.lane .cnt { text-align: right; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.lane:hover .track { border-color: #2c405c; }

/* ---------- logs ---------- */
.badge {
  display: inline-block; margin-left: 5px; background: var(--warn); color: #1a1005;
  border-radius: 8px; padding: 0 5px; font-size: 9.5px; font-weight: 700; vertical-align: middle;
}
.logbar { display: flex; gap: 7px; margin-bottom: 10px; }
.logbar button { flex: 0 0 auto; }
.logbar .primary { flex: 1; padding: 7px; }
.logfilter { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin: 10px 0 8px; }
.logbody {
  border: 1px solid var(--line); border-radius: 8px; background: #0c121a;
  font-family: var(--mono); font-size: 10.5px; max-height: 46vh; overflow: auto;
}
.logline { display: flex; gap: 8px; padding: 3px 8px; border-bottom: 1px solid #131c28; }
.logline:last-child { border-bottom: 0; }
.logline .lt { color: #56637a; flex: 0 0 46px; text-align: right; }
.logline .lg { flex: 0 0 62px; color: #7aa2d0; }
.logline .lm { flex: 1; color: #b8c6d9; word-break: break-word; }
.logline.error { background: rgba(248,81,73,.09); }
.logline.error .lm { color: #ff9d94; }
.logline.warn { background: rgba(251,146,60,.07); }
.logline.warn .lm { color: #ffc48a; }


.maplibregl-popup-content {
  background: #101722; color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; font-size: 11.5px; font-family: var(--mono); padding: 8px 10px;
}
.maplibregl-popup-tip { border-top-color: #101722 !important; border-bottom-color: #101722 !important; }
.maplibregl-ctrl-attrib { font-size: 10px; }

@media (max-width: 1100px) {
  #panel { width: 330px; flex-basis: 330px; }
  .headline { display: none; }
}

/* ---------- loading spinner ---------- */
.busy {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 7;
  display: flex; align-items: center; gap: 9px;
  background: rgba(11,15,20,.9); border: 1px solid var(--line); border-radius: 20px;
  padding: 7px 15px 7px 12px; font-size: 12px; color: #cfdaea;
  backdrop-filter: blur(6px); box-shadow: 0 3px 14px rgba(0,0,0,.45);
}
.busy .spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(88,166,255,.28); border-top-color: var(--accent2);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .busy .spin { animation-duration: 2.4s; } }
