/* VIDA web app. Mobile first; wider screens get a top nav and two-pane views. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16191d;
  --muted: #5d6673;
  --border: #d9dde3;
  --accent: #1d5fa8;
  --accent-soft: #e3edf8;
  --on-accent: #ffffff;
  --bar: #14233a;
  --on-bar: #f2f5f9;
  --warn-bg: #fff4e0;
  --warn: #8a5300;
  --danger-bg: #fde8e8;
  --danger: #a32121;
  --ok: #1d7a3e;
  --mark: #ffe58a;
  --hot: rgba(29, 95, 168, 0.18);
  --hot-line: rgba(29, 95, 168, 0.75);
  --hot-on: rgba(230, 120, 0, 0.35);
  --hot-on-line: #e67800;
  --radius: 10px;
  --nav-h: 60px;
  --top-h: 52px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #20262e; --text: #e6e9ed; --muted: #9aa4b1;
    --border: #2c333d; --accent: #6aa8ec; --accent-soft: #1b2a3c; --on-accent: #0b1320; --bar: #0b1320;
    --warn-bg: #3a2a10; --warn: #f2b45a; --danger-bg: #3d1717; --danger: #f08a8a; --ok: #6fd08f; --mark: #6b5a12;
    --hot: rgba(106, 168, 236, 0.16); --hot-line: rgba(106, 168, 236, 0.8);
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) .zoom-stage img, :root:not([data-theme="light"]) .md figure img { filter: invert(0.88) hue-rotate(180deg); }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #20262e; --text: #e6e9ed; --muted: #9aa4b1;
  --border: #2c333d; --accent: #6aa8ec; --accent-soft: #1b2a3c; --on-accent: #0b1320; --bar: #0b1320;
  --warn-bg: #3a2a10; --warn: #f2b45a; --danger-bg: #3d1717; --danger: #f08a8a; --ok: #6fd08f; --mark: #6b5a12;
  --hot: rgba(106, 168, 236, 0.16); --hot-line: rgba(106, 168, 236, 0.8);
  color-scheme: dark;
}
:root[data-theme="dark"] .zoom-stage img, :root[data-theme="dark"] .md figure img { filter: invert(0.88) hue-rotate(180deg); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font);
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 1.35rem; line-height: 1.3; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1.1rem 0 .4rem; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* ---------- shell ---------- */
.top {
  position: sticky; top: 0; z-index: 20; height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0; background: var(--bar); color: var(--on-bar);
  display: flex; align-items: center; gap: 10px;
}
.top .brand { font-weight: 700; letter-spacing: .08em; color: var(--on-bar); font-size: 1.05rem; }
.top .back { background: none; border: 0; color: var(--on-bar); padding: 6px; margin-left: -6px; display: flex; cursor: pointer; }
.top .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.vpill {
  display: inline-flex; align-items: center; gap: 6px; max-width: 52vw; padding: 5px 10px; border-radius: 999px;
  background: rgba(255,255,255,.12); color: var(--on-bar); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vpill:hover { text-decoration: none; background: rgba(255,255,255,.2); }
.topnav { display: none; }

main { max-width: 1180px; margin: 0 auto; padding: 14px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; text-decoration: none;
}
.bottomnav a.on { color: var(--accent); font-weight: 600; }
.bottomnav svg, .topnav svg { width: 22px; height: 22px; }

@media (min-width: 900px) {
  .bottomnav { display: none; }
  .topnav { display: flex; gap: 2px; margin-left: 18px; }
  .topnav a { color: var(--on-bar); opacity: .78; padding: 7px 12px; border-radius: 8px; display: flex; gap: 6px; align-items: center; font-size: .92rem; }
  .topnav a.on, .topnav a:hover { opacity: 1; background: rgba(255,255,255,.12); text-decoration: none; }
  .topnav svg { width: 18px; height: 18px; }
  .top .spacer { flex: 1; }
  main { padding-bottom: 40px; }
}

/* ---------- building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.err { background: var(--danger-bg); color: var(--danger); border-radius: var(--radius); padding: 10px 12px; }
.note { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 10px 12px; }
.spin { color: var(--muted); padding: 24px 0; text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { background: none; border: 0; padding: 6px; cursor: pointer; color: inherit; display: inline-flex; }

input[type=search], input[type=text], select {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px;
  font-size: .85rem; cursor: pointer; white-space: nowrap; color: var(--text);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip:hover { text-decoration: none; }
.tag { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: 1px; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

/* lists */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list > a, .list > .li {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; color: var(--text); border-top: 1px solid var(--border);
  text-decoration: none; min-height: 48px;
}
.list > :first-child { border-top: 0; }
.list > a:hover { background: var(--surface-2); text-decoration: none; }
.list .sub { color: var(--muted); font-size: .85rem; }
.list .count { color: var(--muted); font-size: .85rem; margin-left: auto; padding-left: 8px; }
.list .chev { color: var(--muted); flex: 0 0 auto; }
.list .ttl { min-width: 0; }
.list .snip { color: var(--muted); font-size: .85rem; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.snip mark, .md mark { background: var(--mark); color: inherit; border-radius: 2px; }
.sechead { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 2px 8px; }
.sechead h2 { margin: 0; font-size: 1rem; }

.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs a { color: var(--muted); }
.crumbs span.sep { opacity: .6; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; color: var(--text); display: block; }
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile b { display: block; }
.tile .muted { font-size: .85rem; }

.searchbar { position: relative; }
.searchbar input { padding-left: 40px; font-size: 1.05rem; min-height: 48px; }
.searchbar svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); }

/* ---------- markdown docs ---------- */
.doc-head .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.md { overflow-wrap: anywhere; }
.md h3, .md h4 { margin: 1.3rem 0 .4rem; font-size: 1.02rem; }
.md p { margin: .55rem 0; }
.md ul, .md ol { padding-left: 1.3rem; }
.md li { margin: .2rem 0; }
.md blockquote { margin: .8rem 0; padding: 8px 12px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; }
.md blockquote.warning { border-color: var(--danger); background: var(--danger-bg); }
.md blockquote.caution { border-color: var(--warn); background: var(--warn-bg); }
.md blockquote p { margin: .2rem 0; }
.md figure { margin: .8rem 0; display: inline-block; max-width: 100%; vertical-align: top; }
.md figure img { max-width: 100%; height: auto; background: #fff; border: 1px solid var(--border); border-radius: 6px; cursor: zoom-in; display: block; }
.md figcaption { font-size: .75rem; color: var(--muted); }
.md .tablewrap { overflow-x: auto; margin: .8rem 0; }
.md table { border-collapse: collapse; font-size: .9rem; min-width: 50%; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md thead:has(th:empty) { display: none; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }
.md a.vcc, .md a.tool { white-space: nowrap; }

/* ---------- zoomable viewer (diagrams, lightbox) ---------- */
.zoom { position: relative; overflow: hidden; touch-action: none; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); user-select: none; -webkit-user-select: none; }
.zoom-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.zoom-stage img { display: block; pointer-events: none; -webkit-user-drag: none; }
.zoom-tools { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; z-index: 2; }
.zoom-tools button { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 1.1rem; display: grid; place-items: center; }
.hot { position: absolute; border: 2px solid var(--hot-line); background: var(--hot); border-radius: 4px; cursor: pointer; }
.hot.on { border-color: var(--hot-on-line); background: var(--hot-on); border-width: 3px; }
.hot.dim { opacity: .35; }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.85); display: flex; flex-direction: column; }
.lightbox .zoom { flex: 1; border: 0; border-radius: 0; background: #fff; }
.lightbox .lb-bar { display: flex; align-items: center; justify-content: space-between; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; color: #fff; }
.lightbox .lb-bar button { color: #fff; }

/* diagram page */
.dia { display: grid; gap: 12px; }
.dia .zoom { height: 58vh; min-height: 300px; }
.dia-parts { max-height: none; }
.callout-row { display: flex; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.callout-row:first-child { border-top: 0; }
.callout-row.on { background: var(--accent-soft); }
.callout-row .num { flex: 0 0 auto; min-width: 30px; height: 26px; border-radius: 7px; background: var(--surface-2); display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.callout-row.on .num { background: var(--hot-on-line); color: #fff; }
.callout-row .pn { font-family: var(--mono); font-size: .9rem; }
@media (min-width: 900px) {
  .dia { grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); align-items: start; }
  .dia .zoom { height: calc(100vh - var(--top-h) - 120px); position: sticky; top: calc(var(--top-h) + 14px); }
  .dia-parts { max-height: calc(100vh - var(--top-h) - 120px); overflow: auto; }
}

/* fault tracing */
.steps { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; }
.steps .chip { font-variant-numeric: tabular-nums; }
.stepnav { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); display: flex; gap: 8px; justify-content: space-between; margin-top: 16px; }
@media (min-width: 900px) { .stepnav { bottom: 12px; } }
.stepnav .btn { box-shadow: 0 2px 10px rgba(0,0,0,.12); }

table.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.grid th, table.grid td { padding: 7px 8px; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
table.grid th { color: var(--muted); font-weight: 600; font-size: .8rem; border-top: 0; }

.signin { max-width: 420px; margin: 12vh auto 0; text-align: center; }
.signin .logo { width: 72px; height: 72px; margin: 0 auto 12px; }
.vpill svg { width: 16px; height: 16px; flex: 0 0 auto; }
.tile b { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.tile b svg { width: 20px; height: 20px; color: var(--accent); }
.btn svg { width: 16px; height: 16px; }
.iconbtn svg { width: 20px; height: 20px; }
.top .back svg { width: 24px; height: 24px; }
.chev svg { width: 18px; height: 18px; display: block; }
.searchbar svg { pointer-events: none; }
.cap::first-letter { text-transform: uppercase; }
.cap { display: inline-block; }
.sheet-back { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 30px rgba(0,0,0,.25); }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 16px; } }
.warn-text { color: var(--warn); }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--border); display: inline-block; flex: 0 0 auto; }
.dot.green { background: #2e9d52; } .dot.red { background: #d23b3b; } .dot.yellow { background: #e0b21b; }
.outcome { border-radius: var(--radius); padding: 14px; font-weight: 600; }
.outcome.found { background: var(--danger-bg); color: var(--danger); }
.outcome.notfound { background: var(--accent-soft); color: var(--accent); }
.toolchip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-size: .85em; font-family: var(--mono); }
/* assistant */
.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 76px; }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; max-width: 92%; align-self: flex-start; }
.bubble.me { background: var(--accent-soft); border-color: transparent; align-self: flex-end; white-space: pre-wrap; }
.bubble.md > :first-child { margin-top: 0; } .bubble.md > :last-child { margin-bottom: 0; }
.toolrow { padding: 0 4px; }
.chatbar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 15; display: flex; gap: 8px; align-items: flex-end;
  padding: 8px max(14px, calc((100vw - 1180px) / 2 + 14px)); background: var(--bg); border-top: 1px solid var(--border); }
.chatbar textarea { flex: 1; min-width: 0; resize: none; font: inherit; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); max-height: 30vh; }

.logstatus { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.logstatus .dot { width: 10px; height: 10px; }
.logstatus.ok .dot { background: #2e9d52; }
.logstatus.wait .dot { background: #e0b21b; }
.logstatus.bad .dot { background: #d23b3b; }
.logstatus.off { color: var(--muted); }
.top .iconbtn svg { width: 22px; height: 22px; }
