:root {
  --bg: #f4f4f1; --panel: #ffffff; --ink: #1d1d1b; --muted: #6b6b66; --line: #c9c9c2; --accent: #b8860b;
  --comp-bg: #ffffff; --grid: #e7e7e1; --hl: #e11d48;
  --live: #8a4b1f; --sl: #c2410c; --neutral: #1d4ed8; --earth: #15803d; --strap: #6b7280;
  --err: #b91c1c; --warn: #a16207; --info: #1d4ed8; --ok: #15803d;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141614; --panel: #1d201d; --ink: #e9e9e4; --muted: #a3a39c; --line: #4a4d48; --accent: #e0a526;
    --comp-bg: #232723; --grid: #222522; --hl: #fb7185;
    --live: #d08a55; --sl: #fb923c; --neutral: #60a5fa; --earth: #4ade80; --strap: #9ca3af;
    --err: #f87171; --warn: #facc15; --info: #93c5fd; --ok: #4ade80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141614; --panel: #1d201d; --ink: #e9e9e4; --muted: #a3a39c; --line: #4a4d48; --accent: #e0a526;
  --comp-bg: #232723; --grid: #222522; --hl: #fb7185;
  --live: #d08a55; --sl: #fb923c; --neutral: #60a5fa; --earth: #4ade80; --strap: #9ca3af;
  --err: #f87171; --warn: #facc15; --info: #93c5fd; --ok: #4ade80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; min-height: 36px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, var(--line)); }
button.small { padding: 4px 8px; min-height: 30px; font-size: 13px; }
button.icon { padding: 4px 8px; min-width: 34px; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; }
input, select, textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font-size: 16px; min-height: 36px; }
textarea { resize: vertical; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--err); font-size: 14px; min-height: 1em; margin: 6px 0; }

/* Sign-in */
#login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); border-radius: 10px; padding: 28px; width: min(360px, 100%); box-shadow: 0 6px 24px rgba(0,0,0,.15); }
.login-card h1 { font-size: 20px; margin: 0 0 16px; }
.login-card button { width: 100%; margin-top: 6px; }

/* App shell */
/* Rows are pinned so the hidden banner (display:none drops it from the grid) can't shift the others. */
#app { height: 100%; height: 100dvh; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
#app > .bar { grid-row: 1; } #app > .banner { grid-row: 2; } #app > .main { grid-row: 3; } #app > .disclaimer { grid-row: 4; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
#picker { width: auto; max-width: 280px; font-weight: 600; }
.status { color: var(--muted); font-size: 13px; }
.status.dirty { color: var(--warn); }
.tools { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.banner { padding: 8px 12px; background: color-mix(in srgb, var(--accent) 18%, var(--panel)); border-bottom: 1px solid var(--line); font-size: 14px; }
.main { display: grid; grid-template-columns: 1fr 360px; min-height: 0; }
.stage { position: relative; min-height: 0; overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none;
  background-color: var(--bg); background-image: radial-gradient(var(--grid) 1px, transparent 1px); background-size: 20px 20px; }
.empty-stage { position: absolute; inset: 40% 16px auto; text-align: center; color: var(--muted); }
.panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: none; border-bottom: 2px solid transparent; padding: 10px 4px; }
.tabs button.active { border-bottom-color: var(--accent); font-weight: 600; }
.count:not(:empty) { background: var(--warn); color: #000; border-radius: 9px; padding: 0 6px; font-size: 12px; margin-left: 2px; }
.panel-body { overflow-y: auto; padding: 12px 14px 24px; }
.disclaimer { padding: 6px 12px; font-size: 13px; text-align: center; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); }
.disclaimer-inline { font-size: 12px; color: var(--muted); margin-top: 16px; }
.only-narrow { display: none; }

/* Forms */
.form h3 { margin: 6px 0 10px; font-size: 16px; }
.form h3 small { color: var(--muted); font-weight: normal; font-size: 12px; }
.form h4 { margin: 14px 0 6px; font-size: 14px; }
.field { display: block; margin-bottom: 10px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.field-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.row { display: flex; gap: 8px; } .row > * { flex: 1; min-width: 0; }
.term-head, .term-row { display: grid; grid-template-columns: 1fr 1.6fr 64px 40px; gap: 6px; align-items: center; }
.term-head { font-size: 12px; color: var(--muted); }
.term-row { margin-bottom: 6px; }
.term-row input, .term-row select { padding: 5px 6px; font-size: 14px; }
.actions { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.ends { font-size: 14px; }
.empty p { color: var(--muted); }
.note-meta { font-size: 12px; color: var(--muted); }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }

/* Issues */
.issue { display: block; width: 100%; text-align: left; border-left: 4px solid var(--line); margin-bottom: 8px; padding: 8px 10px; background: var(--panel); }
.issue.sev-error { border-left-color: var(--err); }
.issue.sev-warning { border-left-color: var(--warn); }
.issue.sev-info { border-left-color: var(--info); }
.issue-head { display: block; font-weight: 600; font-size: 13px; }
.issue-msg, .issue-sug { display: block; overflow-wrap: anywhere; }
.issue-sug { color: var(--muted); font-size: 13px; margin-top: 3px; }
.issue ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.badge { text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
.sev-error .badge { color: var(--err); } .sev-warning .badge { color: var(--warn); } .sev-info .badge { color: var(--info); }

/* Dialog + toasts */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); padding: 0; width: min(520px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal { padding: 18px; }
.modal h2 { margin: 0 0 10px; font-size: 18px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.palette-btn { flex: 1 1 140px; }
.cond-btn { flex: 1 1 140px; border-width: 2px; }
.cond-btn.c-permanent_live { border-color: var(--live); } .cond-btn.c-switched_live { border-color: var(--sl); }
.cond-btn.c-neutral { border-color: var(--neutral); } .cond-btn.c-earth { border-color: var(--earth); } .cond-btn.c-switch_strap { border-color: var(--strap); }
.cond-btn.primary { color: #fff; }
.toasts { position: fixed; bottom: 48px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 10; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 6px; padding: 8px 12px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.error { border-left-color: var(--err); } .toast.ok { border-left-color: var(--ok); }

/* Legend */
.legend { position: absolute; left: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; max-width: calc(100% - 16px);
  background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12px; pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 3px; }
.legend .lg-status { color: var(--muted); }
.lg { fill: none; stroke-width: 2.5; }

/* ── SVG schematic ───────────────────────────────────────────────────────── */
.comp { cursor: grab; }
.comp-box { fill: var(--comp-bg); stroke: var(--line); stroke-width: 1.5; }
.comp.st-new .comp-box { stroke: var(--ink); stroke-width: 3; }
.comp.st-unknown .comp-box { stroke-dasharray: 6 4; }
.comp.selected .comp-box { stroke: var(--accent); stroke-width: 3.5; }
.comp.hl .comp-box { stroke: var(--hl); stroke-width: 4; }
.comp-label { fill: var(--ink); font-size: 14px; font-weight: 600; }
.comp-sub { fill: var(--muted); font-size: 11px; }
.comp-q { fill: var(--warn); font-size: 16px; font-weight: 700; }
.term-label { fill: var(--muted); font-size: 11px; pointer-events: none; }
.term-dot { stroke: var(--panel); stroke-width: 2; fill: var(--strap); pointer-events: none; }
.term.r-permanent_live .term-dot { fill: var(--live); } .term.r-switched_live .term-dot { fill: var(--sl); }
.term.r-neutral .term-dot { fill: var(--neutral); } .term.r-earth .term-dot { fill: var(--earth); }
.term.over .term-dot, .term.hl .term-dot { stroke: var(--hl); stroke-width: 3; }
.term-hit { fill: transparent; cursor: crosshair; }

.wire-line, .lg { fill: none; stroke-width: 2.5; stroke-linecap: butt; }
.c-permanent_live > .wire-line, .lg.c-permanent_live { stroke: var(--live); }
.c-switched_live > .wire-line, .lg.c-switched_live { stroke: var(--sl); stroke-dasharray: 10 5; }
.c-neutral > .wire-line, .lg.c-neutral { stroke: var(--neutral); stroke-dasharray: 14 4 3 4; }
.c-earth > .wire-line, .lg.c-earth { stroke: var(--earth); stroke-dasharray: 14 3 3 3 3 3; }
.c-switch_strap > .wire-line, .lg.c-switch_strap { stroke: var(--strap); stroke-dasharray: 5 3; }
.wire.st-new > .wire-line { stroke-width: 4.5; }
.wire.st-unknown > .wire-line { stroke-dasharray: 1 6; stroke-linecap: round; stroke-width: 3; }
.wire.selected > .wire-line { filter: drop-shadow(0 0 3px var(--accent)); stroke-width: 5; }
.wire.hl > .wire-line { filter: drop-shadow(0 0 3px var(--hl)); stroke-width: 5; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
.wire-tag rect { fill: var(--panel); stroke-width: 1.5; }
.wire-tag text { font-size: 11px; font-weight: 700; pointer-events: none; }
.wire-tag { pointer-events: none; }
.c-permanent_live .wire-tag rect { stroke: var(--live); } .c-permanent_live .wire-tag text { fill: var(--live); }
.c-switched_live .wire-tag rect { stroke: var(--sl); } .c-switched_live .wire-tag text { fill: var(--sl); }
.c-neutral .wire-tag rect { stroke: var(--neutral); } .c-neutral .wire-tag text { fill: var(--neutral); }
.c-earth .wire-tag rect { stroke: var(--earth); } .c-earth .wire-tag text { fill: var(--earth); }
.c-switch_strap .wire-tag rect { stroke: var(--strap); } .c-switch_strap .wire-tag text { fill: var(--strap); }
.wire-dangle { fill: var(--panel); stroke: var(--hl); stroke-width: 2; }
.wire-draft { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 4; }
.layer-draft { pointer-events: none; }

/* Banner variants */
.banner { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.banner > span { flex: 1 1 220px; }
.banner.preview { background: color-mix(in srgb, var(--info) 16%, var(--panel)); }
.banner.editing { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }
.banner.stale { background: color-mix(in srgb, var(--err) 14%, var(--panel)); }
.banner.plan { background: color-mix(in srgb, var(--ok) 14%, var(--panel)); }
.conflicts { max-height: 50vh; overflow-y: auto; }
.conflict code { font-size: 12px; }
.conflict .pick { display: flex; gap: 6px; align-items: baseline; margin-top: 6px; overflow-wrap: anywhere; }
.conflict .pick input { width: auto; min-height: 0; }
.plan-card { border-color: var(--ok); }
.key-add { color: var(--ok); font-weight: 700; } .key-chg { color: var(--warn); font-weight: 700; }
.is-hidden { visibility: hidden; }
.view-toggle { position: absolute; top: 8px; right: 8px; z-index: 2; font-size: 13px; min-height: 32px; padding: 4px 10px;
  background: color-mix(in srgb, var(--panel) 92%, transparent); }
.count.pending:not(:empty) { background: var(--accent); color: #fff; }
.tabs button { font-size: 14px; }

/* Changes panel */
.row-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.change-note { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.proposal { border-color: var(--accent); }
.warn-box { border-left: 4px solid var(--warn); padding: 6px 8px; background: color-mix(in srgb, var(--warn) 10%, var(--panel)); font-size: 14px; }
ul.diff { list-style: none; padding: 0; margin: 6px 0; font-size: 13px; max-height: 260px; overflow-y: auto; }
ul.diff li { padding: 2px 0 2px 8px; border-left: 3px solid var(--line); margin-bottom: 2px; overflow-wrap: anywhere; }
ul.diff li.d-add { border-left-color: var(--ok); } ul.diff li.d-del { border-left-color: var(--err); } ul.diff li.d-chg { border-left-color: var(--warn); }
.diff-detail { color: var(--muted); }
.version { border-bottom: 1px solid var(--line); padding: 8px 0; }
.version.current { border-left: 3px solid var(--accent); padding-left: 8px; }
.version.st-rejected, .version.st-stale { opacity: .7; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 9px; border: 1px solid var(--line); vertical-align: 1px; }
.chip-pending { border-color: var(--accent); } .chip-rejected { border-color: var(--err); color: var(--err); }
.chip-stale { border-color: var(--warn); color: var(--warn); }
.who-claude { background: color-mix(in srgb, var(--info) 15%, transparent); }
.review { margin: 6px 0; padding: 6px 8px; background: color-mix(in srgb, var(--info) 8%, var(--panel)); border-radius: 6px; }
.review-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.compare { margin-top: 6px; }
.err-list { font-size: 13px; padding-left: 18px; max-height: 50vh; overflow-y: auto; }

/* Proposal preview marks */
.comp.mk-add .comp-box { stroke: var(--ok); stroke-width: 4; }
.comp.mk-chg .comp-box { stroke: var(--warn); stroke-width: 4; }
.wire.mk-add > .wire-line, .cable.mk-add > .cable-line { filter: drop-shadow(0 0 3px var(--ok)); }
.wire.mk-chg > .wire-line, .cable.mk-chg > .cable-line { filter: drop-shadow(0 0 3px var(--warn)); }

/* Cable view */
.cable-line { fill: none; stroke: var(--ink); stroke-width: 7; stroke-linecap: round; opacity: .55; }
.cable.st-existing > .cable-line { stroke-width: 5; }
.cable.st-unknown > .cable-line { stroke-dasharray: 2 9; }
.cable.selected > .cable-line { stroke: var(--accent); opacity: 1; }
.cable.hl > .cable-line { stroke: var(--hl); opacity: 1; }
.cable-tag rect { fill: var(--panel); stroke: var(--ink); }
.cable-tag text { fill: var(--ink); font-size: 11px; font-weight: 700; }

/* Phones: panel becomes a bottom sheet */
@media (max-width: 820px) {
  .main { grid-template-columns: 1fr; position: relative; }
  .panel { position: absolute; left: 0; right: 0; bottom: 0; height: 52%; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 12px 12px 0 0; box-shadow: 0 -6px 20px rgba(0,0,0,.2); transform: translateY(calc(100% - 44px)); transition: transform .2s; }
  .panel.open { transform: none; }
  .only-narrow { display: inline-block; }
  .tools { margin-left: 0; width: 100%; }
  .tools { gap: 4px; }
  .tools button { flex: 1 1 0; padding: 6px 2px; min-height: 38px; font-size: 14px; white-space: nowrap; min-width: 0; }
  #picker { max-width: 60vw; }
  .legend { bottom: 52px; }
  .legend .lg-status { display: none; }
  .tabs button { font-size: 13px; padding: 10px 2px; }
  .bar { padding: 6px 8px; }
  .toasts { top: 100px; bottom: auto; }
}
