:root {
  --bg: #f3f6f7; --surface: #ffffff; --panel: #f7fafb; --ink: #1c2526; --muted: #5f6f71; --line: #dde7e9;
  --brand: #2a9da4; --brand-ink: #fff; --brand-soft: #e2f5f6;
  --err: #d64545; --err-soft: #fde8e8; --warn: #d98a12; --warn-soft: #fdf1dc; --ok: #2f9e66; --ok-soft: #e1f4ea;
  --plan-bg: #fbfdfd; --street: #e3e9ea; --strand: #2a9da4; --duct: #8a63c9; --fiber: #e07b2a; --drop: #8fb82f; --text: #7c8a8c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1415; --surface: #142021; --panel: #111b1c; --ink: #e6eff0; --muted: #98abad; --line: #243335;
    --brand: #68ccd1; --brand-ink: #0d1415; --brand-soft: #173436;
    --err: #f07070; --err-soft: #3a1d1d; --warn: #f0b04a; --warn-soft: #3a2c14; --ok: #5cc98f; --ok-soft: #173326;
    --plan-bg: #0f1819; --street: #1f2c2e; --strand: #68ccd1; --duct: #b08ee8; --fiber: #f0974f; --drop: #b2d65a; --text: #7d9092;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1415; --surface: #142021; --panel: #111b1c; --ink: #e6eff0; --muted: #98abad; --line: #243335;
  --brand: #68ccd1; --brand-ink: #0d1415; --brand-soft: #173436;
  --err: #f07070; --err-soft: #3a1d1d; --warn: #f0b04a; --warn-soft: #3a2c14; --ok: #5cc98f; --ok-soft: #173326;
  --plan-bg: #0f1819; --street: #1f2c2e; --strand: #68ccd1; --duct: #b08ee8; --fiber: #f0974f; --drop: #b2d65a; --text: #7d9092;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 Lato, system-ui, sans-serif; display: flex; flex-direction: column; }
h1, h2, .brand, .btn { font-family: Alata, system-ui, sans-serif; font-weight: 400; }
h1 { font-size: 1.25rem; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: .84rem; }
button { font: inherit; color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-size: 1.2rem; }
.brand em { font-style: normal; font-size: .75rem; background: var(--brand-soft); color: var(--brand); padding: 2px 8px; border-radius: 99px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.select { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; }
.select select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; max-width: 240px; }
.btn { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 99px; padding: 8px 16px; cursor: pointer; font-size: .92rem; }
.btn:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; color: var(--brand); box-shadow: inset 0 0 0 1.5px var(--brand); }
.btn.pulse { animation: pop .5s; } @keyframes pop { 40% { transform: scale(1.08); } }
.notice { margin: 0; padding: 8px 16px; background: var(--brand-soft); color: var(--ink); font-size: .85rem; }

.layout { flex: 1; display: grid; grid-template-columns: 300px 1fr 340px; gap: 12px; padding: 12px; min-height: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow: auto; min-height: 0; }
.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; }
@media (max-width: 1100px) {
  html, body { height: auto; }
  .layout { grid-template-columns: 1fr; flex: none; }
  .stage { order: -1; }
  .canvas-wrap { height: 60vh; flex: none !important; }
  .panel { overflow: visible; }
}

/* Rules */
.rule { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: var(--panel); }
.rule.off { opacity: .55; }
.rule-head { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px; align-items: center; cursor: pointer; }
.rid { font-weight: 700; color: var(--brand); font-size: .85rem; }
.rname { font-size: .9rem; }
.rule details { margin-top: 6px; }
.rule summary, .layers summary { cursor: pointer; color: var(--muted); font-size: .82rem; }
.param { display: grid; gap: 2px; margin: 6px 0; font-size: .8rem; color: var(--muted); }
.param input { font: inherit; font-size: .85rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; width: 100%; }
.sev { font-size: .72rem; padding: 2px 8px; border-radius: 99px; white-space: nowrap; font-weight: 700; }
.sev-error { background: var(--err-soft); color: var(--err); }
.sev-warning { background: var(--warn-soft); color: var(--warn); }
.layers { margin-top: 14px; }
.layer { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; font-size: .82rem; padding: 3px 0; overflow-wrap: anywhere; }

/* Stage */
.file-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.file-head p { margin: 2px 0 0; }
.verdict { font-family: Alata, sans-serif; padding: 6px 14px; border-radius: 99px; white-space: nowrap; }
.verdict.bad { background: var(--err-soft); color: var(--err); }
.verdict.warn { background: var(--warn-soft); color: var(--warn); }
.verdict.good { background: var(--ok-soft); color: var(--ok); }
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
@media (max-width: 640px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: grid; }
.kpi span { color: var(--muted); font-size: .78rem; }
.kpi strong { font-family: Alata, sans-serif; font-weight: 400; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.kpi.bad strong { color: var(--err); } .kpi.warn strong { color: var(--warn); } .kpi.good strong { color: var(--ok); }

.canvas-wrap { position: relative; flex: 1; min-height: 320px; background: var(--plan-bg); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
#plan { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#plan.grabbing { cursor: grabbing; }
#plan polyline, #plan polygon { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.l-street polyline { stroke: var(--street); stroke-width: 1.5; }
.l-strand polyline { stroke: var(--strand); stroke-width: 1.8; }
.l-duct polyline, .l-duct polygon { stroke: var(--duct); stroke-width: 1.8; stroke-dasharray: 5 3; }
.l-fiber polyline { stroke: var(--fiber); stroke-width: 2.6; }
.l-drop polyline { stroke: var(--drop); stroke-width: 1.4; stroke-dasharray: 2 2; }
.l-other polyline, .l-other polygon, .l-other circle { stroke: var(--muted); stroke-width: 1; }
.l-text text { fill: var(--text); font-family: Lato, sans-serif; }
#plan.far .l-text { display: none; }
.blocks * { stroke: var(--ink); stroke-width: 1; }
.b-pole, .b-anchor { fill: var(--surface); }
.b-anchor { fill: var(--strand); }
.b-mh { fill: var(--duct); }
.b-jb { fill: var(--fiber); }
.b-nap { fill: var(--drop); }
.b-eq { fill: var(--brand); }
#plan .hl { stroke: var(--err) !important; stroke-width: 4 !important; }
.mk { cursor: pointer; stroke-width: 2.5; fill-opacity: .18; }
.mk-error { stroke: var(--err); fill: var(--err); }
.mk-warning { stroke: var(--warn); fill: var(--warn); }
.mk.sel { stroke-width: 3.5; fill-opacity: .1; }
.zoom { position: absolute; right: 10px; top: 10px; display: grid; gap: 4px; }
.zoom button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 1.1rem; }
.legend { position: absolute; left: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 4px 12px; background: color-mix(in srgb, var(--surface) 90%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .75rem; color: var(--muted); max-width: calc(100% - 20px); }
.legend span { display: flex; align-items: center; gap: 5px; }
.lg { width: 16px; height: 0; border-top: 3px solid; display: inline-block; }
.lg.l-strand { border-color: var(--strand); } .lg.l-duct { border-color: var(--duct); border-top-style: dashed; }
.lg.l-fiber { border-color: var(--fiber); } .lg.l-drop { border-color: var(--drop); border-top-style: dotted; }
.lg.mk-error, .lg.mk-warning { width: 11px; height: 11px; border: 2px solid; border-radius: 50%; }
.lg.mk-error { border-color: var(--err); } .lg.mk-warning { border-color: var(--warn); }
.dropzone { position: absolute; inset: 0; display: none; place-items: center; background: color-mix(in srgb, var(--brand) 18%, transparent); border: 3px dashed var(--brand); border-radius: 12px; font-family: Alata, sans-serif; font-size: 1.3rem; }
.canvas-wrap.dragging .dropzone { display: grid; }

/* Results */
.results-head { display: flex; justify-content: space-between; align-items: center; }
.exports { display: flex; gap: 10px; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; text-decoration: underline; font-size: .88rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 10px; font-size: .8rem; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip.zero b { color: var(--ok); } .chip.on b { color: inherit; }
.findings, .history { list-style: none; padding: 0; margin: 0; }
.finding { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 9px 8px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--line); }
.finding:hover { background: var(--panel); }
.finding.sel { background: var(--brand-soft); }
.finding p { margin: 0; font-size: .86rem; }
.finding .sev { align-self: start; margin-top: 2px; }
.empty { padding: 14px; background: var(--ok-soft); color: var(--ok); border-radius: 8px; font-size: .88rem; }
.hist-title { margin-top: 20px; }
.history li { display: grid; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .85rem; overflow-wrap: anywhere; }
.tbad { color: var(--err); } .tgood { color: var(--ok); }
