:root {
  --ink: #172523;
  --ink-soft: #53605d;
  --paper: #f5f2eb;
  --surface: #fffdfa;
  --surface-2: #eeebe3;
  --line: #d9d5cb;
  --line-strong: #bdb8ab;
  --green: #146b55;
  --green-dark: #0d4e3f;
  --green-soft: #dcece6;
  --orange: #e9683a;
  --orange-soft: #fbe6dd;
  --yellow: #d79a22;
  --yellow-soft: #faedcc;
  --red: #bf3e45;
  --red-soft: #f7dfe0;
  --blue: #3a6f9d;
  --blue-soft: #e0eaf4;
  --shadow: 0 14px 38px rgba(34, 45, 42, .10);
  --shadow-small: 0 5px 18px rgba(34, 45, 42, .09);
  --radius: 12px;
  --topbar: 68px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(20, 107, 85, .25);
  outline-offset: 2px;
}

svg { display: block; }

.app-shell { min-height: 100vh; }

.topbar {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto 0;
  height: var(--topbar);
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(330px, 1fr);
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: rgba(255, 253, 250, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; width: max-content; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: #fff; background: var(--green); transform: rotate(-2deg); }
.brand-mark svg { width: 21px; fill: currentColor; }
.brand-copy { display: grid; line-height: 1; gap: 4px; }
.brand-copy strong { font-size: 16px; letter-spacing: -.02em; }
.brand-copy small { color: var(--ink-soft); font-size: 10px; letter-spacing: .075em; text-transform: uppercase; font-weight: 700; }

.main-nav { display: flex; align-items: center; align-self: stretch; gap: 3px; }
.nav-button { position: relative; height: 100%; padding: 0 14px; border: 0; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 13px; font-weight: 650; white-space: nowrap; }
.nav-button::after { content: ""; position: absolute; height: 3px; inset: auto 12px 0; background: var(--green); transform: scaleX(0); transition: transform .18s ease; }
.nav-button:hover { color: var(--ink); }
.nav-button.is-active { color: var(--green-dark); }
.nav-button.is-active::after { transform: scaleX(1); }
.nav-badge { display: inline-grid; place-items: center; margin-left: 3px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 20px; background: var(--orange-soft); color: #934121; font-size: 10px; }

.top-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.history-actions { display: flex; padding-right: 8px; margin-right: 2px; border-right: 1px solid var(--line); }
.icon-button { width: 38px; height: 38px; padding: 0; border: 0; border-radius: 9px; display: grid; place-items: center; background: transparent; cursor: pointer; }
.icon-button:hover:not(:disabled) { background: var(--surface-2); }
.icon-button:disabled { opacity: .32; cursor: default; }
.icon-button svg, .button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.more-button svg { fill: currentColor; stroke: none; }

.save-state { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-soft); white-space: nowrap; }
.save-state > span { width: 7px; height: 7px; border-radius: 50%; background: #69a890; }
.save-state.is-dirty > span { background: var(--yellow); }
.save-state.is-saving > span { background: var(--blue); animation: pulse 1s infinite; }
.save-state.is-error > span { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }

.button { min-height: 38px; padding: 0 15px; border-radius: 9px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-weight: 700; font-size: 12px; line-height: 1; white-space: nowrap; }
.button-primary { color: #fff; background: var(--green); border-color: var(--green); box-shadow: 0 4px 10px rgba(20, 107, 85, .18); }
.button-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.button-secondary { background: var(--surface); border-color: var(--line-strong); }
.button-secondary:hover { border-color: var(--green); color: var(--green-dark); }
.button-danger { color: #fff; background: var(--red); }
.button-small { min-height: 32px; padding: 0 11px; }

.action-menu { position: fixed; z-index: 80; top: 58px; right: 16px; min-width: 210px; padding: 7px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); }
.action-menu button { width: 100%; padding: 10px 11px; text-align: left; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 12px; }
.action-menu button:hover { background: var(--surface-2); }
.danger-text { color: var(--red) !important; }

.content { padding-top: var(--topbar); min-height: 100vh; }
.view { display: none; }
.view.is-active { display: grid; }

.view-plan { grid-template-columns: 88px minmax(0, 1fr) 310px; height: calc(100vh - var(--topbar)); overflow: hidden; }

.tool-rail { position: relative; z-index: 5; overflow-y: auto; padding: 15px 9px 20px; border-right: 1px solid var(--line); background: var(--surface); scrollbar-width: thin; }
.tool-group { display: grid; gap: 4px; margin-bottom: 16px; }
.tool-group + .tool-group { padding-top: 14px; border-top: 1px solid var(--line); }
.tool-group-label { padding: 0 5px 4px; color: #7b837f; font-size: 9px; letter-spacing: .095em; text-transform: uppercase; font-weight: 800; text-align: center; }
.tool-button { min-height: 52px; padding: 6px 4px; display: grid; place-items: center; gap: 4px; border: 1px solid transparent; border-radius: 9px; color: var(--ink-soft); background: transparent; cursor: pointer; }
.tool-button:hover { color: var(--green-dark); background: var(--green-soft); }
.tool-button.is-active { color: var(--green-dark); border-color: #a7c9bc; background: var(--green-soft); }
.tool-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.tool-button > span:last-child { font-size: 9px; line-height: 1.1; font-weight: 700; }
.mini-symbol { width: 22px; height: 22px; display: grid; place-items: center; border: 1.6px solid currentColor; border-radius: 50%; font-size: 10px; font-weight: 800; }
.socket-symbol::after { content: ""; width: 9px; border-top: 1.4px solid currentColor; transform: translateY(-3px); position: absolute; }
.light-symbol { font-size: 18px; font-weight: 400; }
.fixed-symbol { border-radius: 4px; }
.junction-symbol { border-radius: 3px; }
.data-symbol { border-radius: 4px; }
.symbols-group { padding-bottom: 6px; }
.tool-utility { margin-top: auto; }

.editor-stage { min-width: 0; display: grid; grid-template-rows: 45px minmax(0, 1fr); background: #e9e6de; }
.plan-tabs-bar { min-width: 0; display: flex; align-items: stretch; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.plan-tabs { min-width: 0; display: flex; overflow-x: auto; scrollbar-width: none; }
.plan-tab { position: relative; min-width: 95px; padding: 0 18px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 11px; font-weight: 700; white-space: nowrap; }
.plan-tab:first-child { border-left: 1px solid var(--line); }
.plan-tab.is-active { color: var(--green-dark); background: #f3f7f4; }
.plan-tab.is-active::after { content: ""; position: absolute; inset: auto 0 0; height: 2px; background: var(--green); }
.add-plan-button { width: 38px; border: 0; border-right: 1px solid var(--line); color: var(--green); background: transparent; cursor: pointer; font-size: 20px; }
.add-plan-button:hover { background: var(--green-soft); }
.stage-meta { margin-left: auto; display: flex; align-items: center; gap: 14px; padding-left: 14px; color: var(--ink-soft); font-size: 10px; white-space: nowrap; }
.snap-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.snap-toggle input { accent-color: var(--green); }

.canvas-viewport { position: relative; min-width: 0; min-height: 0; overflow: hidden; cursor: crosshair; touch-action: none; background-color: #dedbd3; background-image: radial-gradient(rgba(75, 86, 82, .15) .7px, transparent .7px); background-size: 8px 8px; }
.canvas-viewport[data-tool="select"] { cursor: default; }
.canvas-viewport[data-tool="pan"] { cursor: grab; }
.canvas-viewport.is-panning { cursor: grabbing; }
.plan-canvas { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; }
.canvas-empty-hint { position: absolute; z-index: 2; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(380px, calc(100% - 40px)); display: grid; justify-items: center; gap: 8px; text-align: center; color: var(--ink-soft); pointer-events: none; }
.canvas-empty-hint[hidden] { display: none; }
.canvas-empty-hint strong { color: var(--ink); font-family: ui-serif, Georgia, serif; font-size: 21px; }
.canvas-empty-hint > span { max-width: 330px; font-size: 12px; line-height: 1.5; }
.canvas-empty-hint .button { margin-top: 8px; pointer-events: auto; }
.hint-icon { width: 46px; height: 46px; display: grid; place-items: center; margin-bottom: 2px; color: var(--green); border-radius: 50%; background: var(--green-soft); }
.hint-icon svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.zoom-controls { position: absolute; z-index: 8; right: 15px; bottom: 15px; display: flex; height: 36px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 9px; background: rgba(255, 253, 250, .94); box-shadow: var(--shadow-small); }
.zoom-controls button { min-width: 36px; padding: 0 9px; border: 0; border-right: 1px solid var(--line); background: transparent; cursor: pointer; }
.zoom-controls button:last-child { border-right: 0; }
.zoom-controls button:hover { background: var(--surface-2); }
.zoom-controls .zoom-value { min-width: 53px; font-size: 10px; font-weight: 750; }
.zoom-controls svg { width: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.canvas-status { position: absolute; z-index: 5; left: 15px; bottom: 15px; padding: 7px 10px; border: 1px solid rgba(189,184,171,.75); border-radius: 7px; background: rgba(255,253,250,.85); color: var(--ink-soft); font-size: 10px; pointer-events: none; backdrop-filter: blur(8px); }

.inspector { min-width: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); border-left: 1px solid var(--line); background: var(--surface); overflow: hidden; }
.inspector-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 18px 13px; }
.inspector-head h2 { margin: 3px 0 0; font-family: ui-serif, Georgia, serif; font-size: 20px; font-weight: 650; letter-spacing: -.02em; }
.eyebrow { display: block; color: var(--green); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; font-weight: 850; }
.inspector-close { display: none; }
.inspector-tabs { display: grid; grid-template-columns: repeat(3, 1fr); padding: 0 12px; border-bottom: 1px solid var(--line); }
.inspector-tabs button { position: relative; height: 38px; padding: 0 3px; border: 0; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 10px; font-weight: 750; }
.inspector-tabs button.is-active { color: var(--green-dark); }
.inspector-tabs button.is-active::after { content: ""; position: absolute; inset: auto 4px -1px; height: 2px; background: var(--green); }
.inspector-body { min-height: 0; overflow-y: auto; padding: 17px 17px 30px; scrollbar-width: thin; }
.inspector-section { margin-bottom: 20px; }
.inspector-section + .inspector-section { padding-top: 17px; border-top: 1px solid var(--line); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 0 0 11px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.field-grid .field-full { grid-column: 1 / -1; }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span, .field-label { color: var(--ink-soft); font-size: 9px; letter-spacing: .04em; font-weight: 700; }
.field input, .field select, .field textarea, .filter-bar select, .search-field { width: 100%; min-height: 36px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); font-size: 11px; }
.field input, .field select { padding: 0 9px; }
.field textarea { min-height: 72px; resize: vertical; padding: 8px 9px; line-height: 1.45; }
.field input[type="range"] { padding: 0; accent-color: var(--green); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); }
.field-hint { color: #7d8582; font-size: 9px; line-height: 1.4; }
.inline-fields { display: flex; align-items: center; gap: 7px; }
.inline-fields > * { min-width: 0; }
.check-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; font-size: 11px; }
.check-field input { accent-color: var(--green); }
.inspector-actions { display: flex; gap: 7px; }
.inspector-actions .button { flex: 1; }
.delete-link { width: 100%; padding: 7px; border: 0; background: transparent; color: var(--red); cursor: pointer; font-size: 10px; font-weight: 700; }
.delete-link:hover { text-decoration: underline; }
.project-snapshot { padding: 12px; border-radius: 9px; background: var(--surface-2); }
.project-snapshot strong { display: block; margin-bottom: 4px; font-family: ui-serif, Georgia, serif; }
.project-snapshot span { font-size: 10px; color: var(--ink-soft); }
.quick-stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.quick-stat { padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.quick-stat strong { display: block; font-family: ui-serif, Georgia, serif; font-size: 20px; }
.quick-stat span { color: var(--ink-soft); font-size: 9px; }
.circuit-list { display: grid; gap: 7px; }
.circuit-item { display: grid; grid-template-columns: 8px minmax(0,1fr) auto; gap: 9px; align-items: center; padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.circuit-item:hover, .circuit-item.is-highlighted { border-color: var(--green); }
.circuit-dot { width: 8px; height: 100%; min-height: 29px; border-radius: 4px; }
.circuit-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.circuit-item small { color: var(--ink-soft); font-size: 9px; }
.count-pill { min-width: 23px; padding: 3px 6px; border-radius: 10px; background: var(--surface-2); font-size: 9px; text-align: center; }
.layer-row { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 9px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 11px; }
.layer-row input { accent-color: var(--green); }
.layer-icon { width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-soft); }
.layer-icon svg { width: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.mobile-inspector-button { display: none; }

/* SVG plan */
.plan-paper { fill: #fffefa; stroke: #c9c5bb; stroke-width: 1; filter: drop-shadow(0 6px 20px rgba(39,48,45,.14)); }
.grid-layer { fill: url(#grid); opacity: .55; pointer-events: none; }
.background-layer image { pointer-events: none; }
.wall-line { stroke: #39433f; stroke-width: 10; stroke-linecap: square; }
.cable-line { fill: none; stroke-width: 3; stroke-dasharray: 10 7; stroke-linecap: round; }
.line-hit { stroke: transparent; stroke-width: 18; cursor: pointer; }
.entity-line.is-selected .line-outline { stroke: var(--orange); stroke-width: 16; opacity: .35; }
.element { cursor: grab; }
.element:active { cursor: grabbing; }
.element .symbol-halo { fill: #fffdfa; stroke: #fffdfa; stroke-width: 8; filter: url(#symbolShadow); }
.element .symbol-body { fill: #fffdfa; stroke: var(--ink); stroke-width: 2.5; }
.element .symbol-detail { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.element .circuit-ring { fill: none; stroke-width: 4; opacity: .95; }
.element.is-selected .selection-ring { fill: none; stroke: var(--orange); stroke-width: 2; stroke-dasharray: 5 3; }
.element-label { fill: var(--ink); font-size: 13px; font-weight: 750; paint-order: stroke; stroke: #fffdfa; stroke-width: 4; stroke-linejoin: round; }
.element-meta { fill: #5f6966; font-size: 10px; font-weight: 600; paint-order: stroke; stroke: #fffdfa; stroke-width: 3; }
.status-badge-circle { stroke: #fff; stroke-width: 2; }
.room-marker .room-box { fill: rgba(255,253,250,.83); stroke: #73817c; stroke-width: 1.5; stroke-dasharray: 4 3; }
.room-marker text { text-anchor: middle; fill: #36413e; font-family: ui-serif, Georgia, serif; font-size: 20px; font-weight: 650; }
.note-marker .note-box { fill: #fff3bd; stroke: #d0a83d; stroke-width: 1.5; }
.note-marker text { fill: #57471c; font-size: 12px; }
.preview-line { stroke: var(--orange); stroke-width: 4; stroke-dasharray: 8 5; pointer-events: none; }

/* Page views */
.page-view.is-active { display: block; }
.page-view { min-height: calc(100vh - var(--topbar)); padding: 38px clamp(22px, 4vw, 62px) 60px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 28px; max-width: 1320px; margin: 0 auto 28px; }
.page-header h1 { margin: 4px 0 4px; font-family: ui-serif, Georgia, serif; font-size: clamp(30px, 4vw, 46px); line-height: 1; letter-spacing: -.035em; font-weight: 600; }
.page-header p { margin: 0; color: var(--ink-soft); font-size: 12px; }
.page-actions { display: flex; gap: 8px; }
.filter-bar { max-width: 1320px; margin: 0 auto 12px; display: grid; grid-template-columns: minmax(240px, 1fr) repeat(3, minmax(130px, 180px)) auto; align-items: center; gap: 8px; }
.search-field { display: grid; grid-template-columns: 34px minmax(0,1fr); align-items: center; overflow: hidden; background: #fff; }
.search-field svg { width: 15px; justify-self: center; fill: none; stroke: var(--ink-soft); stroke-width: 1.7; }
.search-field input { height: 34px; min-width: 0; padding: 0 8px 0 0; border: 0; outline: 0; font-size: 11px; }
.filter-bar select { padding: 0 28px 0 9px; }
.filter-result { padding-left: 8px; color: var(--ink-soft); font-size: 10px; white-space: nowrap; }
.table-card { position: relative; max-width: 1320px; margin: auto; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-small); }
.check-table { width: 100%; border-collapse: collapse; min-width: 960px; font-size: 11px; }
.check-table th { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line-strong); color: var(--ink-soft); background: var(--surface-2); font-size: 9px; letter-spacing: .065em; text-transform: uppercase; }
.check-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.check-table tbody tr { cursor: pointer; }
.check-table tbody tr:hover { background: #f2f7f4; }
.check-table tbody tr:last-child td { border-bottom: 0; }
.table-type { display: flex; gap: 9px; align-items: center; }
.type-icon { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; color: var(--green-dark); background: var(--green-soft); font-size: 10px; font-weight: 800; }
.table-type strong { display: block; font-size: 11px; }
.table-type small, .muted { color: var(--ink-soft); font-size: 9px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 16px; font-size: 9px; font-weight: 750; white-space: nowrap; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-unverified { color: #766018; background: var(--yellow-soft); }
.status-confirmed { color: var(--green-dark); background: var(--green-soft); }
.status-deviating { color: #9d302e; background: var(--red-soft); }
.status-additional { color: #245e8b; background: var(--blue-soft); }
.status-missing { color: #8b3f25; background: var(--orange-soft); }
.status-unclear { color: #655d75; background: #e9e4f0; }
.table-empty { padding: 60px 20px; text-align: center; color: var(--ink-soft); }

.safety-note { max-width: 1320px; margin: 0 auto 18px; display: flex; align-items: center; gap: 13px; padding: 13px 16px; border: 1px solid #e0c77b; border-radius: 10px; background: #fbf1d4; color: #66531e; }
.safety-note svg { flex: 0 0 auto; width: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.safety-note strong, .safety-note span { display: block; }
.safety-note strong { font-size: 11px; }
.safety-note span { margin-top: 2px; font-size: 9px; }
.distribution-summary { max-width: 1320px; margin: 0 auto 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.summary-tile { padding: 15px 17px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.summary-tile strong { display: block; font-family: ui-serif, Georgia, serif; font-size: 24px; }
.summary-tile span { color: var(--ink-soft); font-size: 9px; }
.distribution-grid { max-width: 1320px; margin: auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; align-items: start; }
.distribution-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-small); }
.distribution-card-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 17px 18px; border-bottom: 1px solid var(--line); background: #f0f5f2; }
.distribution-card-head h2 { margin: 2px 0; font-family: ui-serif, Georgia, serif; font-size: 20px; }
.distribution-card-head p { margin: 0; color: var(--ink-soft); font-size: 9px; }
.card-menu-button { border: 0; background: transparent; cursor: pointer; font-size: 18px; }
.circuit-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.circuit-table th { padding: 9px 12px; text-align: left; color: var(--ink-soft); background: var(--surface-2); font-size: 8px; text-transform: uppercase; letter-spacing: .06em; }
.circuit-table td { padding: 11px 12px; border-top: 1px solid var(--line); }
.circuit-table tbody tr { cursor: pointer; }
.circuit-table tbody tr:hover { background: #f4f8f6; }
.circuit-name-cell { display: flex; gap: 8px; align-items: center; }
.circuit-color { width: 6px; height: 26px; border-radius: 4px; }
.empty-card { grid-column: 1 / -1; padding: 70px 20px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--ink-soft); }

.stat-cards { max-width: 1320px; margin: 0 auto 16px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat-card { position: relative; overflow: hidden; min-height: 118px; padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-small); }
.stat-card::after { content: ""; position: absolute; right: -18px; bottom: -25px; width: 80px; height: 80px; border-radius: 50%; background: var(--card-color, var(--green-soft)); opacity: .7; }
.stat-card > span { color: var(--ink-soft); font-size: 9px; letter-spacing: .05em; text-transform: uppercase; font-weight: 750; }
.stat-card strong { display: block; margin: 9px 0 2px; font-family: ui-serif, Georgia, serif; font-size: 32px; line-height: 1; }
.stat-card small { color: var(--ink-soft); font-size: 9px; }
.stat-layout { max-width: 1320px; margin: auto; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.chart-card { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-small); }
.wide-card { grid-column: 1 / -1; }
.card-heading { display: flex; justify-content: space-between; margin-bottom: 18px; }
.card-heading h2 { margin: 3px 0 0; font-family: ui-serif, Georgia, serif; font-size: 20px; }
.bar-chart { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 105px minmax(0,1fr) 28px; align-items: center; gap: 9px; font-size: 10px; }
.bar-track { height: 8px; overflow: hidden; border-radius: 8px; background: var(--surface-2); }
.bar-fill { height: 100%; border-radius: inherit; background: var(--green); transition: width .35s ease; }
.bar-value { text-align: right; font-weight: 800; }
.donut-layout { min-height: 210px; display: flex; align-items: center; justify-content: center; gap: clamp(20px,5vw,60px); }
.donut { flex: 0 0 auto; width: 156px; height: 156px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--green) 0 0, var(--surface-2) 0 100%); position: relative; }
.donut::after { content: ""; position: absolute; inset: 21px; border-radius: 50%; background: var(--surface); }
.donut span { z-index: 1; display: grid; text-align: center; color: var(--ink-soft); font-size: 9px; }
.donut strong { color: var(--ink); font-family: ui-serif, Georgia, serif; font-size: 26px; }
.legend { display: grid; gap: 9px; min-width: 145px; }
.legend-row { display: grid; grid-template-columns: 8px minmax(0,1fr) auto; align-items: center; gap: 7px; font-size: 10px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.legend-row strong { font-size: 10px; }
.circuit-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px,1fr)); gap: 8px; }
.circuit-stat { padding: 11px; border: 1px solid var(--line); border-radius: 8px; }
.circuit-stat-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 10px; }
.circuit-stat-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.circuit-stat-track { height: 5px; overflow: hidden; border-radius: 5px; background: var(--surface-2); }
.circuit-stat-fill { height: 100%; }
.simple-list, .issue-list { display: grid; gap: 1px; }
.simple-list-row, .issue-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 10px; }
.simple-list-row:last-child, .issue-row:last-child { border: 0; }
.simple-list-row strong { font-family: ui-serif, Georgia, serif; font-size: 16px; }
.issue-row > span:first-child { display: flex; align-items: center; gap: 8px; }
.issue-icon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; background: var(--orange-soft); color: #99441f; font-size: 10px; font-weight: 800; }

/* Dialog and messages */
.app-dialog { width: min(500px, calc(100vw - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 80px rgba(23,37,35,.24); }
.app-dialog::backdrop { background: rgba(23,37,35,.42); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 19px 20px 14px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 3px 0 0; font-family: ui-serif, Georgia, serif; font-size: 23px; }
.dialog-body { max-height: calc(100vh - 190px); overflow-y: auto; padding: 19px 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 20px 18px; border-top: 1px solid var(--line); }
.dialog-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.dialog-grid .field-full { grid-column: 1 / -1; }
.color-input { height: 38px; padding: 3px !important; }
.toast-region { position: fixed; z-index: 120; right: 18px; bottom: 18px; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 240px; max-width: 360px; padding: 12px 14px; border-radius: 9px; color: #fff; background: var(--ink); box-shadow: var(--shadow); font-size: 11px; animation: toast-in .2s ease; }
.toast.is-error { background: var(--red); }
.toast.is-success { background: var(--green-dark); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 10px; }
  .brand-copy small, .save-state { display: none; }
  .main-nav { justify-self: center; }
  .view-plan { grid-template-columns: 76px minmax(0,1fr) 285px; }
  .tool-rail { padding-inline: 6px; }
  .tool-button { min-height: 49px; }
  .scale-label { display: none; }
}

@media (max-width: 900px) {
  :root { --topbar: 60px; }
  .topbar { padding: 0 12px; grid-template-columns: auto 1fr auto; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-copy { display: none; }
  .main-nav { overflow-x: auto; justify-self: stretch; scrollbar-width: none; }
  .nav-button { padding: 0 10px; font-size: 11px; }
  .history-actions, .top-actions .button-secondary, .more-button { display: none; }
  .top-actions .button-primary { width: 38px; padding: 0; }
  .top-actions .button-primary span { display: none; }
  .view-plan { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr) 69px; }
  .tool-rail { grid-row: 2; display: flex; align-items: stretch; gap: 3px; padding: 5px 7px calc(5px + env(safe-area-inset-bottom)); overflow-x: auto; overflow-y: hidden; border: 0; border-top: 1px solid var(--line); }
  .tool-group { display: flex; gap: 3px; margin: 0; }
  .tool-group + .tool-group { padding: 0 0 0 5px; border: 0; border-left: 1px solid var(--line); }
  .tool-group-label { display: none; }
  .tool-button { flex: 0 0 58px; min-height: 54px; }
  .tool-utility { margin: 0; }
  .editor-stage { grid-row: 1; }
  .inspector { position: fixed; z-index: 60; inset: auto 0 0; height: min(72vh, 650px); border: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -16px 45px rgba(23,37,35,.2); transform: translateY(105%); transition: transform .25s ease; }
  .inspector.is-open { transform: translateY(0); }
  .inspector-close { display: grid; }
  .mobile-inspector-button { display: block; position: fixed; z-index: 12; right: 14px; bottom: calc(78px + env(safe-area-inset-bottom)); min-height: 38px; padding: 0 14px; border: 0; border-radius: 20px; color: #fff; background: var(--green); box-shadow: var(--shadow); font-size: 11px; font-weight: 750; }
  .zoom-controls { bottom: 14px; }
  .canvas-status { bottom: 14px; max-width: calc(100% - 190px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page-view { padding: 28px 16px 45px; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .filter-result { grid-column: 1 / -1; }
  .distribution-summary, .stat-cards { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 640px) {
  .nav-button { padding: 0 7px; }
  .nav-button[data-view="distribution"] { display: none; }
  .top-actions { gap: 3px; }
  .plan-tabs-bar { padding: 0 6px; }
  .stage-meta { padding-left: 8px; }
  .snap-toggle span { display: none; }
  .page-header { display: block; }
  .page-header .button, .page-actions { margin-top: 16px; }
  .page-actions { display: flex; }
  .page-actions .button { flex: 1; margin-top: 0; }
  .filter-bar { grid-template-columns: 1fr; }
  .search-field, .filter-result { grid-column: auto; }
  .distribution-grid { grid-template-columns: 1fr; }
  .distribution-summary, .stat-cards { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .stat-layout { grid-template-columns: 1fr; }
  .wide-card { grid-column: auto; }
  .donut-layout { gap: 22px; }
  .donut { width: 130px; height: 130px; }
  .donut::after { inset: 18px; }
  .dialog-grid { grid-template-columns: 1fr; }
  .dialog-grid .field-full { grid-column: auto; }
  .toast-region { inset: auto 12px calc(82px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; width: calc(100vw - 24px); }
}

@media print {
  :root { --paper: #fff; }
  .topbar, .tool-rail, .inspector, .mobile-inspector-button, .page-header .button { display: none !important; }
  .content { padding: 0; }
  .view { display: none !important; }
  #statisticsView.is-active { display: block !important; padding: 15mm; }
  .stat-card, .chart-card { box-shadow: none; break-inside: avoid; }
}
