/* SPDX-License-Identifier: GPL-3.0-or-later */
:root {
  --bg: #0b131e; --panel: rgba(17, 24, 34, 0.92); --panel-solid: #111822; --raise: #1a2432; --line: #263243;
  --text: #e6ebf1; --muted: #93a1b3; --faint: #5d6b7d; --accent: #4fa3ff; --accent-ink: #06121f;
  --green: #3fbf7f; --yellow: #f2c14e; --red: #ef5a5a; --focus: #8cc4ff;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45); --radius: 12px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans", sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "DejaVu Sans Mono", monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #e9eef3; --panel: rgba(255, 255, 255, 0.94); --panel-solid: #ffffff; --raise: #f1f4f8; --line: #d6dde6;
  --text: #172231; --muted: #566577; --faint: #8c99a8; --accent: #1468d0; --accent-ink: #ffffff;
  --green: #1f9a5a; --yellow: #b8860b; --red: #c93636; --focus: #1468d0;
  --shadow: 0 8px 24px rgba(20, 35, 60, 0.18);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 14px/1.4 var(--font); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- the map */
#map { position: fixed; inset: 0; }
#map canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#map canvas.flow { pointer-events: none; }
#map canvas.ovl { cursor: crosshair; }
#map canvas.ovl.dragging { cursor: grabbing; }

/* ---- floating panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--raise); }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; }
.icon-btn:hover, .icon-btn[aria-pressed="true"] { background: var(--raise); }

header#top { position: fixed; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; pointer-events: none; z-index: 5; }
header#top > * { pointer-events: auto; }
#brand { display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 6px; }
#brand h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
#brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #2a7de1, #3fbfb0); display: grid; place-items: center; color: #fff; }
#sys { padding: 8px 12px; font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
#sys .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
#sys.on .dot { background: var(--green); }
#sys.busy .dot { background: var(--yellow); }
#search { flex: 0 1 260px; padding: 0 10px; display: flex; align-items: center; gap: 6px; position: relative; }
#search input { border: 0; background: transparent; padding: 8px 0; width: 100%; outline: none; }
#search ul { position: absolute; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 4px; list-style: none; }
#search li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
#search li[aria-selected="true"], #search li:hover { background: var(--raise); }
#tools { margin-left: auto; display: flex; gap: 2px; padding: 3px; }

/* ---- left drawer */
#drawer { position: fixed; top: 64px; left: 12px; bottom: 96px; width: 372px; display: flex; flex-direction: column; z-index: 4; overflow: hidden; }
#drawer.closed { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 11px 6px; border: 0; background: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs button[aria-selected="true"] { color: var(--text); border-color: var(--accent); }
.tabpane { flex: 1; overflow: auto; padding: 12px 14px 16px; }
.tabpane h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); margin: 18px 0 8px; }
.tabpane h3:first-child { margin-top: 2px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.fld { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); position: relative; }
.fld input, .fld select { padding: 6px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--raise); color: var(--text); min-width: 0; }
.fld.bad input, .fld.bad select { border-color: var(--red); }
.fld .err { color: var(--red); font-size: 12px; }
.fld .sub { color: var(--faint); font-size: 11.5px; }
.fld[data-tip] > span::after { content: " ⓘ"; color: var(--faint); }
.row { display: flex; gap: 8px; align-items: center; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--raise); font-size: 12.5px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
details.adv { margin-top: 10px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; }
details.adv > summary { padding: 9px 0; cursor: pointer; font-weight: 600; }
details.adv .grp { font-size: 12px; color: var(--accent); margin: 10px 0 4px; font-weight: 600; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mode { text-align: left; padding: 8px; border-radius: 9px; border: 1px solid var(--line); background: var(--raise); }
.mode b { display: block; font-size: 12.5px; }
.mode small { color: var(--muted); font-size: 11.5px; }
.mode .t { font-family: var(--mono); font-size: 12px; margin-top: 4px; display: block; }
.mode[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mode:disabled { opacity: 0.45; }

/* the estimate */
#est { margin-top: 12px; border-radius: 10px; border: 1px solid var(--line); overflow: hidden; }
#est .head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; font-weight: 700; }
#est .head .lvl { width: 10px; height: 10px; border-radius: 50%; }
#est.green .head { background: color-mix(in srgb, var(--green) 16%, transparent); } #est.green .lvl { background: var(--green); }
#est.yellow .head { background: color-mix(in srgb, var(--yellow) 18%, transparent); } #est.yellow .lvl { background: var(--yellow); }
#est.red .head { background: color-mix(in srgb, var(--red) 18%, transparent); } #est.red .lvl { background: var(--red); }
#est .head .tot { margin-left: auto; font-family: var(--mono); }
#est .body { padding: 8px 12px 10px; font-size: 12.5px; }
#est .bars { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin: 6px 0 8px; background: var(--raise); }
#est .bars span { height: 100%; }
#est table { width: 100%; border-collapse: collapse; }
#est td { padding: 2px 0; }
#est td:last-child { text-align: right; font-family: var(--mono); }
#est .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
#est .msg { margin: 6px 0 0; padding: 0; list-style: none; }
#est .msg li { margin: 3px 0; }
#est .msg li.e { color: var(--red); }
#est .msg li.w { color: var(--yellow); }
#est .fix { margin-top: 6px; }
#est .src { color: var(--faint); font-size: 11.5px; margin-top: 6px; }
.meter { height: 6px; border-radius: 3px; background: var(--raise); overflow: hidden; margin-top: 2px; }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter.hot i { background: var(--yellow); }
.meter.over i { background: var(--red); }
.go { position: sticky; bottom: -16px; background: var(--panel-solid); padding: 10px 0 2px; margin-top: 10px; display: flex; gap: 8px; }
.go .btn.primary { flex: 1; justify-content: center; padding: 10px; }

/* the offline notice */
.notice { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; }
.notice code, pre.code { font-family: var(--mono); font-size: 12px; background: var(--raise); border-radius: 6px; padding: 8px; display: block; white-space: pre-wrap; margin: 8px 0; }

/* ---- progress */
#progress { position: fixed; top: 64px; right: 76px; width: 340px; z-index: 6; padding: 12px 14px; }
#progress h4 { margin: 0 0 6px; display: flex; gap: 8px; align-items: center; font-size: 14px; }
#progress .stages { display: flex; gap: 3px; margin: 8px 0; }
#progress .stages span { flex: 1; text-align: center; font-size: 10.5px; padding: 3px 0; border-radius: 4px; background: var(--raise); color: var(--muted); }
#progress .stages span.done { background: color-mix(in srgb, var(--green) 30%, transparent); color: var(--text); }
#progress .stages span.now { background: var(--accent); color: var(--accent-ink); }
#progress .bar { height: 6px; border-radius: 3px; background: var(--raise); overflow: hidden; }
#progress .bar i { display: block; height: 100%; background: var(--accent); transition: width 0.4s; }
#progress dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12.5px; margin: 8px 0; }
#progress dt { color: var(--muted); }
#progress dd { margin: 0; text-align: right; font-family: var(--mono); }
#progress pre { max-height: 140px; overflow: auto; font: 11px/1.35 var(--mono); background: var(--raise); padding: 6px 8px; border-radius: 6px; margin: 6px 0 0; white-space: pre-wrap; }
#progress .msg { color: var(--red); font-size: 13px; }
#progress .acts { display: flex; gap: 6px; margin-top: 8px; }

/* ---- library and points */
.run { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-bottom: 8px; }
.run.cur { border-color: var(--accent); }
.run .t { display: flex; gap: 6px; align-items: center; font-weight: 600; }
.run .t .st { margin-left: auto; font-size: 11.5px; font-weight: 500; padding: 1px 7px; border-radius: 999px; background: var(--raise); }
.run .st.done { color: var(--green); } .run .st.failed { color: var(--red); } .run .st.running { color: var(--accent); }
.run .m { color: var(--muted); font-size: 12px; margin: 3px 0; }
.run .acts { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.run .acts .btn { padding: 4px 8px; font-size: 12px; }
.star { border: 0; background: none; color: var(--faint); font-size: 16px; padding: 0 2px; }
.star[aria-pressed="true"] { color: var(--yellow); }
.pt { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 6px; }
.pt span { flex: 1; cursor: pointer; }

/* ---- right rail: layers */
#rail { position: fixed; top: 64px; right: 12px; width: 52px; padding: 4px; display: flex; flex-direction: column; gap: 2px; z-index: 4; max-height: calc(100% - 170px); overflow: auto; scrollbar-width: none; }
#rail button { position: relative; width: 44px; height: 40px; border: 0; border-radius: 8px; background: none; display: grid; place-items: center; color: var(--muted); }
#rail button:hover { background: var(--raise); color: var(--text); }
#rail button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
#rail button .k { position: absolute; right: 3px; bottom: 1px; font-size: 9px; opacity: 0.7; }
#rail button.na { opacity: 0.35; }
#layerbox { position: fixed; right: 76px; top: 64px; z-index: 4; padding: 10px 12px; min-width: 210px; max-width: 280px; }
#layerbox h4 { margin: 0 0 8px; font-size: 14px; }
#layerbox .chips { margin-bottom: 8px; }
#layerbox .opts { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }

/* ---- bottom: time bar and legend */
#timebar { position: fixed; left: 396px; right: 12px; bottom: 34px; height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 10px; z-index: 4; }
body.drawer-closed #timebar { left: 12px; }
#timebar .now { min-width: 130px; font-weight: 700; font-size: 13.5px; }
#timebar .now small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
#ticks { position: relative; flex: 1; height: 36px; cursor: pointer; touch-action: none; }
#ticks .track { position: absolute; left: 0; right: 0; top: 17px; height: 3px; border-radius: 2px; background: var(--line); }
#ticks .ready { position: absolute; left: 0; top: 17px; height: 3px; background: var(--faint); border-radius: 2px; }
#ticks .tick { position: absolute; top: 12px; width: 1px; height: 13px; background: var(--faint); }
#ticks .day { position: absolute; top: 0; font-size: 10.5px; color: var(--muted); transform: translateX(2px); white-space: nowrap; }
#ticks .day::before { content: ""; position: absolute; left: -2px; top: 2px; height: 30px; border-left: 1px solid var(--line); }
#ticks .knob { position: absolute; top: 9px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel-solid); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
#legend { position: fixed; right: 12px; bottom: 94px; width: 300px; padding: 7px 10px 6px; z-index: 4; font-size: 11.5px; }
#legend .ttl { display: flex; justify-content: space-between; margin-bottom: 4px; }
#legend .ttl b { font-size: 12px; }
#legend .grad { height: 10px; border-radius: 3px; }
#legend .tk { position: relative; height: 14px; color: var(--muted); }
#legend .tk span { position: absolute; transform: translateX(-50%); }
footer#foot { position: fixed; left: 0; right: 0; bottom: 0; height: 26px; display: flex; align-items: center; gap: 12px; padding: 0 14px; font-size: 11.5px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); z-index: 5; }
footer#foot .sp { flex: 1; }
footer#foot a { color: inherit; }

/* ---- hover probe and point card */
#probe { position: fixed; pointer-events: none; z-index: 7; padding: 5px 8px; font-size: 12.5px; border-radius: 7px; white-space: nowrap; transform: translate(14px, 14px); }
#probe b { font-family: var(--mono); }
#probe small { color: var(--muted); display: block; }
#card { position: fixed; right: 76px; bottom: 150px; width: min(560px, calc(100% - 100px)); max-height: calc(100% - 230px); overflow: auto; z-index: 6; padding: 10px 12px; }
#card header { display: flex; align-items: center; gap: 8px; }
#card header h4 { margin: 0; font-size: 14px; flex: 1; }
#card .now { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; margin: 6px 0; }
#card .now b { font-family: var(--mono); }
#card canvas { width: 100%; display: block; }
#card .tabs button { padding: 7px; }
#card .note { color: var(--muted); font-size: 12px; margin: 4px 0; }

#toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); padding: 9px 14px; z-index: 20; }
#cmpbar { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 5; padding: 6px 8px; display: flex; gap: 6px; align-items: center; font-size: 12.5px; }
#splitline { position: fixed; top: 0; bottom: 0; width: 3px; margin-left: -1px; background: var(--accent); z-index: 3; cursor: ew-resize; }
#splitline span { position: absolute; top: 120px; padding: 2px 6px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); font-size: 11px; white-space: nowrap; }
#splitline .a { right: 6px; } #splitline .b { left: 6px; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-solid); color: var(--text); box-shadow: var(--shadow); padding: 16px; max-width: 420px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }

/* ---- phones */
@media (max-width: 760px) {
  header#top { top: 8px; left: 8px; right: 8px; gap: 6px; }
  #brand h1, #sys span.txt { display: none; }
  #search { flex: 1; }
  #drawer { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 62%; border-radius: 14px 14px 0 0; z-index: 8; }
  #rail { top: 58px; right: 8px; width: 46px; max-height: calc(100% - 200px); }
  #rail button { width: 38px; height: 36px; }
  #layerbox, #progress { right: 60px; top: 58px; left: 8px; width: auto; }
  #timebar { left: 8px; right: 8px; bottom: 30px; }
  #timebar .now { min-width: 92px; font-size: 12px; }
  #legend { left: 8px; right: 60px; width: auto; bottom: 88px; }
  #card { left: 8px; right: 8px; width: auto; bottom: 30px; max-height: 70%; z-index: 9; }
  footer#foot .lic, footer#foot #runTag { display: none; }
  footer#foot { white-space: nowrap; }
  footer#foot .disc { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  #tools .icon-btn { width: 30px; height: 30px; }
  #tools { gap: 0; padding: 2px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
