/* V2X Sim web UI: brand-blue top bar, grey secondary, orange accent. */
@import url(fonts.css);

:root {
  --brand: #0393ca;         /* top bar */
  --primary: #0277a5;       /* buttons: brand blue one step darker for 4.5:1 with white text */
  --primary-hover: #02658d;
  --primary-soft: #e1f3fa;
  --on-primary: #ffffff;
  --orange: #f08a24;        /* accent: active nav, highlights */
  --orange-soft: #fff1e2;
  --grey: #5f6b76;          /* secondary buttons */
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #dde3e8;
  --border-strong: #c3ccd4;
  --text: #17212b;
  --muted: #5d6b78;
  --faint: #8794a0;
  --good: #0ca30c; --warn: #c98200; --bad: #d03b3b;
  --good-soft: #e3f5e3; --warn-soft: #fff3d6; --bad-soft: #fde8e8;
  /* series: validated categorical slots 1 and 2 (colour follows the backend) */
  --s-veins: #2a78d6; --s-ns3: #eb6834;
  --grid: #e7eaed; --axis: #b9c1c8;
  --road: #e4e8ec; --lane: #c4ccd3;
  --vehicle: #33414e;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 16px rgba(16, 24, 32, .06);
  --radius: 10px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --primary: #4cb6e3; --primary-hover: #74c6ea; --primary-soft: #0f2f3c; --on-primary: #0b1218;
  --orange: #f29a45; --orange-soft: #3a2a17;
  --grey: #8e9ca8;
  --bg: #0f151b; --surface: #161e26; --surface-2: #1b252e;
  --border: #2a3641; --border-strong: #3a4855;
  --text: #e3e9ee; --muted: #9aa7b2; --faint: #74828e;
  --good-soft: #0f3326; --warn-soft: #3a2c10; --bad-soft: #3a1717;
  --s-veins: #3987e5; --s-ns3: #d95926;
  --grid: #26313b; --axis: #45535f;
  --road: #222c35; --lane: #3a4753;
  --vehicle: #c9d3db;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: .92em; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 4px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 6px; font-weight: 600; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }

/* ---- top bar */
.top { background: var(--brand); color: #fff; height: 52px; display: flex; align-items: center; gap: 18px; padding: 0 20px;
  position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: baseline; gap: 8px; color: #fff; text-decoration: none; white-space: nowrap; }
.brand b { font-size: 18px; font-weight: 600; letter-spacing: .2px; }
.brand span { font-size: 12px; opacity: .85; }
.nav { display: flex; gap: 2px; height: 100%; }
.nav a { color: #fff; text-decoration: none; display: flex; align-items: center; padding: 0 12px; height: 100%;
  border-bottom: 3px solid transparent; border-top: 3px solid transparent; opacity: .92; }
.nav a:hover { opacity: 1; background: rgba(255, 255, 255, .08); }
.nav a.active { border-bottom-color: var(--orange); opacity: 1; font-weight: 500; }
.top .tools { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.top .tools button { background: transparent; border: 1px solid rgba(255, 255, 255, .45); color: #fff; border-radius: 6px;
  padding: 3px 9px; cursor: pointer; font-size: 12px; }
.top .tools button:hover { background: rgba(255, 255, 255, .12); }
.who { font-size: 12px; opacity: .92; }

main { max-width: 1320px; margin: 0 auto; padding: 22px 20px 60px; }
main.wide { max-width: none; }

/* ---- cards, buttons, forms */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); }
.card > h2 + .lead, .lead { color: var(--muted); margin: 0 0 12px; }
.btn { border: 1px solid transparent; border-radius: 7px; padding: 6px 14px; cursor: pointer; background: var(--primary);
  color: var(--on-primary); font-weight: 500; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; }
.btn:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; padding: 6px 9px; min-width: 0; }
input.full, select.full { width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 4px 11px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 500; }

/* ---- tables */
table.t { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.t th, .t td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: middle; }
.t th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
.t td.num, .t th.num { text-align: right; }
.t tr.sel td { background: var(--primary-soft); }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover td { background: var(--surface-2); }
.tablewrap { overflow: auto; }
.t.sticky thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }

/* ---- chips */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.chip.queued { color: var(--muted); }
.chip.running, .chip.analysing { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.chip.done, .chip.succeeded { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.failed { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.cancelled { color: var(--muted); text-decoration: line-through; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.key { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); margin-right: 14px; font-size: 13px; }

/* ---- page layout helpers */
.pagehead { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.pagehead .sub { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 960px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 6px 0 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent;
  white-space: nowrap; font-weight: 500; }
.tabs a.active { color: var(--text); border-bottom-color: var(--orange); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 860px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .l { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; display: flex; gap: 8px; align-items: center; }
.tile .v + .v { font-size: 16px; }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.notice { border-left: 3px solid var(--orange); background: var(--orange-soft); padding: 8px 12px; border-radius: 6px; }
.err { border-left: 3px solid var(--bad); background: var(--bad-soft); padding: 8px 12px; border-radius: 6px;
  white-space: pre-wrap; font-family: var(--mono); font-size: 12px; }

/* ---- auth */
.auth { max-width: 400px; margin: 60px auto; }
.auth .card { padding: 24px; }

/* ---- charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; z-index: 5; display: none; }
details.tv { margin-top: 8px; } details.tv summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.tv table { margin-top: 6px; font-size: 12px; }

/* ---- map replay */
.mapgrid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
@media (max-width: 1100px) { .mapgrid { grid-template-columns: 1fr; } }
.lanehead { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin: 6px 0 4px; }
.mapcanvas { width: 100%; display: block; border-radius: 8px; background: var(--surface-2); cursor: grab; touch-action: none; }
.mapcanvas.drag { cursor: grabbing; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.clock { font-variant-numeric: tabular-nums; min-width: 70px; font-family: var(--mono); }
.timeline { width: 100%; height: 64px; display: block; cursor: pointer; }
.side h3 { margin-top: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ---- inspector */
.inspect { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; align-items: start; }
.inspect > .card:last-child { position: sticky; top: 68px; max-height: calc(100vh - 84px); overflow: auto; }
@media (max-width: 1100px) { .inspect { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.layers { font-size: 13px; }
.layers details { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--surface); }
.layers summary { padding: 6px 10px; cursor: pointer; font-weight: 500; }
.layers table { width: 100%; border-collapse: collapse; }
.layers td { padding: 3px 10px; border-top: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.layers td:first-child { color: var(--muted); width: 45%; }
.layers tr.hl td { background: var(--orange-soft); }
.hex { font-family: var(--mono); font-size: 12px; line-height: 1.6; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; overflow-x: auto; white-space: nowrap; }
.hex .off { color: var(--faint); margin-right: 10px; }
.hex .b { padding: 0 2px; border-radius: 3px; cursor: default; }
.hex .b.l0 { color: #0b7aa6; } .hex .b.l1 { color: #7a5ac8; } .hex .b.l2 { color: #1f8a5b; }
.hex .b.l3 { color: #b8620f; } .hex .b.l4 { color: var(--text); } .hex .b.pad { color: var(--faint); }
.hex .b.hl { background: var(--orange); color: #fff; }
:root[data-theme='dark'] .hex .b.l0 { color: #5fc5ee; } :root[data-theme='dark'] .hex .b.l1 { color: #b4a0f0; }
:root[data-theme='dark'] .hex .b.l2 { color: #5fd09a; } :root[data-theme='dark'] .hex .b.l3 { color: #f0a35a; }

/* ---- editor */
.editor { display: grid; grid-template-columns: 260px minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1200px) { .editor { grid-template-columns: 1fr; } }
.slist a { display: block; padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
.slist a:hover { background: var(--surface-2); } .slist a.active { background: var(--primary-soft); color: var(--primary); }
.slist .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin: 12px 10px 4px; }
.code { display: grid; grid-template-columns: auto 1fr; border: 1px solid var(--border-strong); border-radius: 8px;
  overflow: hidden; background: var(--surface); }
.code .gutter { background: var(--surface-2); color: var(--faint); font: 12.5px/1.55 var(--mono); padding: 8px 8px 8px 10px;
  text-align: right; user-select: none; border-right: 1px solid var(--border); overflow: hidden; }
.code .gutter div.bad { color: #fff; background: var(--bad); border-radius: 3px; }
.code textarea { border: 0; border-radius: 0; resize: vertical; min-height: 520px; font: 12.5px/1.55 var(--mono);
  padding: 8px 10px; white-space: pre; overflow: auto; tab-size: 2; outline: none; width: 100%; }
.errlist li { margin-bottom: 6px; } .errlist a { cursor: pointer; }

/* ---- toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 8px 16px; border-radius: 8px; z-index: 50; box-shadow: var(--shadow); max-width: 80vw; }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .top { gap: 8px; padding: 0 10px; } .brand span { display: none; } .nav a { padding: 0 8px; }
  .who { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
