/* ICT Design Tools stylesheet. See docs/ui-guidelines.md and, in development, /styleguide/.
   Order: design tokens, base, components, then tool-specific rules. Use the tokens; avoid
   one-off colours and sizes. */

/* --- design tokens ---------------------------------------------------------------------- */
/* Theme: follows the system unless the header toggle has set data-theme on <html>. */
:root {
  color-scheme: light;
  --fg: #1b1f24; --bg: #ffffff; --muted: #5b6470; --accent: #0b5cad; --on-accent: #ffffff;
  --pass: #1a7f37; --warn: #b26b00; --fail: #b42318; --error: var(--fail);
  --line: color-mix(in srgb, var(--fg) 15%, transparent);
  --line-strong: color-mix(in srgb, var(--fg) 25%, transparent);
  --track: color-mix(in srgb, var(--fg) 12%, transparent);
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem; --space-5: 1.5rem; --space-6: 2rem;
  --radius: 6px; --radius-pill: 999px;
  --text-xs: .8rem; --text-sm: .9rem; --text-base: 1rem; --text-lg: 1.25rem;
  --font-sans: system-ui, sans-serif; --font-mono: ui-monospace, monospace;
  --control-h: 2.4rem; --page-w: 960px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark; --fg: #e6e8eb; --bg: #121417; --muted: #9aa3ad; --accent: #5aa2ff;
    --on-accent: #0b1220; --pass: #56d364; --warn: #f0b429; --fail: #ff8a80;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark; --fg: #e6e8eb; --bg: #121417; --muted: #9aa3ad; --accent: #5aa2ff;
  --on-accent: #0b1220; --pass: #56d364; --warn: #f0b429; --fail: #ff8a80;
}

/* --- base ---------------------------------------------------------------------------------- */
* { box-sizing: border-box; }
body { margin: 0; font: var(--text-base)/1.5 var(--font-sans); color: var(--fg); background: var(--bg); }
a { color: var(--accent); }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4); border-bottom: 1px solid var(--line); }
.brand { color: var(--fg); font-weight: 700; text-decoration: none; }
main { max-width: var(--page-w); margin: 0 auto; padding: var(--space-5) var(--space-4); }
.site-footer { max-width: var(--page-w); margin: var(--space-6) auto 0; padding: var(--space-4); display: flex;
  flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); color: var(--muted);
  font-size: var(--text-sm); border-top: 1px solid var(--line); }
.site-footer .version { font-family: var(--font-mono); }

/* --- buttons ------------------------------------------------------------------------------- */
/* One primary action per form (Calculate); secondary for adding things and downloads; danger
   for removing a whole group; icon for removing a single row; quiet for site chrome. */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1);
  min-height: var(--control-h); padding: 0 var(--space-4); font: inherit; font-size: var(--text-sm);
  font-weight: 600; line-height: 1; white-space: nowrap; text-decoration: none; cursor: pointer;
  color: var(--fg); background: transparent; border: 1px solid transparent; border-radius: var(--radius); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { color: var(--on-accent); background: var(--accent); font-size: var(--text-base); padding: 0 var(--space-5); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, var(--fg)); }
.btn-secondary { color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn-danger { color: var(--fail); border-color: var(--fail); background: color-mix(in srgb, var(--fail) 10%, transparent); }
.btn-danger:hover, .btn-danger:focus-visible { color: var(--bg); background: var(--fail); }
.btn-quiet { font-weight: 500; border-color: var(--line-strong); }
.btn-quiet:hover { border-color: var(--accent); }
.btn-icon { width: var(--control-h); padding: 0; font-size: 1.2rem; font-weight: 400; color: var(--muted);
  border-color: var(--line); }
.btn-icon:hover, .btn-icon:focus-visible { color: var(--fail); border-color: var(--fail); }
.btn-sm { min-height: 2rem; padding: 0 var(--space-3); font-size: var(--text-sm); }

/* --- form controls ------------------------------------------------------------------------- */
.tool-form select, .tool-form input:not([type="checkbox"]) { min-height: var(--control-h); min-width: 0;
  padding: 0 .7rem; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); }
.tool-form select:focus-visible, .tool-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.tool-form input[readonly] { opacity: .5; cursor: not-allowed; }
.form-actions { margin-top: var(--space-4); }
.lead { color: var(--muted); }
.tool-list { list-style: none; padding: 0; }
.tool-list li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.tool-list span { display: block; color: var(--muted); font-size: .9rem; }
.tool-form label { display: block; font-weight: 600; margin-bottom: .35rem; }
.input-row { display: flex; gap: .5rem; }
.input-row input { flex: 1; font-family: var(--font-mono); }
#result { margin-top: 1.5rem; }
#result.htmx-request { opacity: .5; }
.results { width: 100%; border-collapse: collapse; }
.results caption { text-align: left; font-weight: 700; font-size: 1.15rem; padding-bottom: .5rem; }
.results th, .results td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.results th { width: 12rem; color: var(--muted); font-weight: 500; }
.results td { font-family: ui-monospace, monospace; overflow-wrap: anywhere; }
.tag { font-size: .8rem; font-weight: 500; color: var(--muted); margin-left: .5rem; }
.error { color: var(--error); }
.note { color: var(--muted); font-size: .9rem; }
@media (max-width: 560px) {
  .results th { width: auto; }
  .results tr { display: block; border-bottom: 1px solid var(--line); }
  .results th, .results td { display: block; border: 0; padding: .2rem 0; }
  .results tr { padding: .4rem 0; }
}

/* --- fill calculators (conduit, tray) ------------------------------------------------------ */
.field-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.field-row > div { flex: 1 1 14rem; }
.field-row select { width: 100%; }
.cables { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3); margin: 0 0 var(--space-4); }
.cables legend { font-weight: 600; padding: 0 .35rem; }
.cable-head, .cable-row { display: grid; grid-template-columns: 1fr 8rem 6rem 2.4rem; gap: .5rem; margin-bottom: .5rem; }
.cable-head.weighted, .cable-row.weighted { grid-template-columns: 1fr 8rem 6rem 8rem 2.4rem; }
.cable-head.weighted.tensioned, .cable-row.weighted.tensioned { grid-template-columns: 1fr 7rem 5rem 7rem 7rem 2.4rem; }
.cable-head { color: var(--muted); font-size: .85rem; }
.result-title { margin: 0 0 .75rem; font-size: 1.25rem; }
.status { font-size: .8rem; font-weight: 700; margin-left: .6rem; padding: .15rem .5rem; border-radius: var(--radius-pill);
  border: 1px solid currentColor; vertical-align: middle; }
.status.pass { color: var(--pass); }
.status.fail { color: var(--fail); }
.fill-bar { position: relative; height: 1.1rem; background: var(--track); border-radius: 4px; overflow: hidden; }
.fill-bar .fill { height: 100%; }
.fill-bar .fill.pass { background: var(--pass); }
.fill-bar .fill.fail { background: var(--fail); }
.fill-bar .fill.warn { background: var(--warn); }
.fill-bar .limit { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--fg); }
.bar-caption { margin: .35rem 0 1rem; color: var(--muted); font-size: .9rem; }
.breakdown { margin-top: 1.5rem; }
.breakdown th { width: auto; }
.breakdown td { font-family: inherit; }
@media (max-width: 560px) {
  .cable-head { display: none; }
  .cable-row { grid-template-columns: 1fr 1fr 2.4rem; }
  .cable-row.weighted { grid-template-columns: 1fr 1fr 1fr 2.4rem; }
  .cable-row.weighted.tensioned { grid-template-columns: repeat(4, 1fr) 2.4rem; }
  .cable-row select { grid-column: 1 / -1; }
}

/* Conduit cross-section diagram. Categorical hues are fixed-order slots from the reference palette. */
.viz-root, .diagram {
  color-scheme: light;
  --surface-1: #fcfcfb; --wall: #c3c2b7; --ink: #0b0b0b; --ink-muted: #52514e;
  --series-0: #2a78d6; --series-1: #eb6834; --series-2: #1baf7a; --series-3: #eda100;
  --series-4: #e87ba4; --series-5: #008300; --series-6: #6250d6; --series-7: #e34948;
  --series-x: #898781; --on-series: #ffffff; --on-series-3: #0b0b0b;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .diagram {
    color-scheme: dark;
    --surface-1: #1a1a19; --wall: #383835; --ink: #f0efec; --ink-muted: #c3c2b7;
    --series-0: #3987e5; --series-1: #d95926; --series-2: #199e70; --series-3: #c98500;
    --series-4: #d55181; --series-5: #0ca30c; --series-6: #9085e9; --series-7: #e66767;
    --on-series-3: #ffffff;
  }
}
:root[data-theme="dark"] .diagram {
  color-scheme: dark;
  --surface-1: #1a1a19; --wall: #383835; --ink: #f0efec; --ink-muted: #c3c2b7;
  --series-0: #3987e5; --series-1: #d95926; --series-2: #199e70; --series-3: #c98500;
  --series-4: #d55181; --series-5: #0ca30c; --series-6: #9085e9; --series-7: #e66767;
  --on-series-3: #ffffff;
}
.diagram { margin: 0 0 1.25rem; display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: center; }
.conduit-svg { width: min(100%, 300px); height: auto; flex: none; }
.conduit-svg .bore { fill: var(--surface-1); }
.conduit-svg .fill-band { fill: var(--ink-muted); opacity: 0.35; }
.conduit-svg .wall { fill: none; stroke: var(--wall); }
.conduit-svg .cable circle { stroke: var(--surface-1); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.conduit-svg .cable text { fill: var(--on-series); text-anchor: middle; dominant-baseline: central;
  font-family: system-ui, sans-serif; font-weight: 700; pointer-events: none; }
.conduit-svg .c3 text { fill: var(--on-series-3); }
.c0 circle { fill: var(--series-0); } .c1 circle { fill: var(--series-1); } .c2 circle { fill: var(--series-2); }
.c3 circle { fill: var(--series-3); } .c4 circle { fill: var(--series-4); } .c5 circle { fill: var(--series-5); }
.c6 circle { fill: var(--series-6); } .c7 circle { fill: var(--series-7); } .cx circle { fill: var(--series-x); }
.diagram figcaption { flex: 1 1 14rem; min-width: 0; }
.diagram-note { margin: 0 0 .5rem; color: var(--muted); font-size: .9rem; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; font-size: .9rem; }
.legend .muted { color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.legend .letter { width: 1.1rem; font-weight: 700; text-align: center; }
.swatch { width: 2.4rem; height: 2.4rem; flex: none; }
.swatch circle { stroke: none; }
.conduit-svg .scale line { stroke: var(--ink-muted); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.conduit-svg .scale text { fill: var(--ink-muted); text-anchor: middle; font-family: system-ui, sans-serif; }

/* Cable tray diagram */
.tray-svg { width: min(100%, 560px); height: auto; flex: none; }
.tray-svg .usable { fill: var(--surface-1); }
.tray-svg .fill-band { fill: var(--ink-muted); opacity: 0.35; }
.tray-svg .rail { stroke: var(--wall); fill: none; }
.tray-svg .floor { stroke: var(--wall); fill: none; }
.tray-svg .calc-depth { stroke: var(--ink-muted); stroke-width: 1.5px; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.tray-svg .calc-note { fill: var(--ink-muted); font-family: system-ui, sans-serif; }
.tray-svg .cable circle { stroke: var(--surface-1); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.tray-svg .cable text { fill: var(--on-series); text-anchor: middle; dominant-baseline: central;
  font-family: system-ui, sans-serif; font-weight: 700; pointer-events: none; }
.tray-svg .c3 text { fill: var(--on-series-3); }
.tray-svg .scale line { stroke: var(--ink-muted); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.tray-svg .scale text { fill: var(--ink-muted); text-anchor: middle; font-family: system-ui, sans-serif; }
.fill-bar .target { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dashed var(--fg); }

.exports { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: 1.2rem 0 .6rem; }
.exports-label { color: var(--muted); font-size: .9rem; }

/* Lanes and subducts */
.tool-form { counter-reset: lane subduct; }
.group { margin-bottom: .75rem; }
.lane .group-title::before { counter-increment: lane; content: "Lane " counter(lane); }
.subduct .group-title::before { counter-increment: subduct; content: "Subduct " counter(subduct); }
.group-title { font-weight: 600; padding: 0 .35rem; }
.group-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem; margin-bottom: .75rem; }
.group-head .field { display: flex; flex-direction: column; gap: .2rem; flex: 1 1 8rem; font-size: .85rem; color: var(--muted); }
.group-head .field input, .group-head .field select { font-size: 1rem; width: 100%; }
.group-head .field:first-child { flex: 2 1 12rem; }
/* A group's actions: add on the left, remove the whole group on the right. */
.group-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-2); }
#lanes .group:only-child .remove-group { display: none; }
.add-group { margin-bottom: var(--space-2); }
.bar-label { margin: .9rem 0 .3rem; font-size: .9rem; font-weight: 600; }
.table-scroll { overflow-x: auto; }
.compartments td, .compartments th { font-size: .85rem; }
.conduit-svg .sub-bore { fill: var(--surface-1); }
.conduit-svg .sub-wall { fill: none; stroke: var(--ink-muted); opacity: .6; }
.conduit-svg .subduct.mesh .sub-wall { stroke-dasharray: 3 2; }
.conduit-svg .fill-band { fill: var(--ink-muted); opacity: 0.35; }
.tray-svg .divider { stroke: var(--ink-muted); opacity: .6; }
.tray-svg .lane-label { fill: var(--ink-muted); text-anchor: middle; font-family: system-ui, sans-serif; }
.tray-svg .unused { fill: var(--wall); opacity: .45; }

.check { display: flex; align-items: center; gap: .5rem; margin: 1rem 0; font-weight: 600; }
.tool-form:has(#use-subducts:checked) .loose { display: none; }
.tool-form:not(:has(#use-subducts:checked)) #subduct-section { display: none; }
.tool-form:not(:has(#use-run:checked)) #run-section { display: none; }
.run-head, .run-row { display: grid; grid-template-columns: 1fr 12rem 2.4rem; gap: .5rem; margin-bottom: .5rem; }
.run .field-row > div { flex: 0 1 16rem; }
@media (max-width: 560px) { .run-head, .run-row { grid-template-columns: 1fr 1fr 2.4rem; } .run-head { display: grid; } }


.lane-status { list-style: none; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; padding: 0; margin: -.25rem 0 1rem; }
.lane-status .status { margin-left: .3rem; }

.tray-svg .dim line { stroke: var(--ink-muted); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.tray-svg .dim text { fill: var(--ink-muted); font-family: system-ui, sans-serif; }

/* Optical budget calculators */
.field-row input { width: 100%; }
.field-row > .wide { flex-basis: 100%; }
.formula { font-family: ui-monospace, monospace; overflow-wrap: anywhere; }
.diagram.optical { display: block; }
.diagram.optical figcaption { margin-top: .75rem; }
.optical-svg { width: 100%; max-width: 620px; height: auto; display: block; font-family: system-ui, sans-serif; }
.optical-svg .track { fill: var(--surface-1); }
.optical-svg .seg { stroke: var(--surface-1); stroke-width: 2px; }
.optical-svg .seg-fibre, .chip.seg-fibre { fill: var(--series-0); background: var(--series-0); }
.optical-svg .seg-connectors, .chip.seg-connectors { fill: var(--series-1); background: var(--series-1); }
.optical-svg .seg-splices, .chip.seg-splices { fill: var(--series-2); background: var(--series-2); }
.optical-svg .seg-splitter, .chip.seg-splitter { fill: var(--series-3); background: var(--series-3); }
.optical-svg .seg-other, .chip.seg-other { fill: var(--series-4); background: var(--series-4); }
.optical-svg .seg-margin, .chip.seg-margin { fill: var(--series-x); background: var(--series-x); opacity: .55; }
.optical-svg .seg-text { fill: var(--on-series); text-anchor: middle; font-size: 13px; font-weight: 700; }
.optical-svg .seg-text-splitter { fill: var(--on-series-3); }
.optical-svg .axis, .optical-svg .grid { stroke: var(--ink-muted); stroke-width: 1px; }
.optical-svg .grid { opacity: .2; }
.optical-svg .tick, .optical-svg .axis-title, .optical-svg .mark-text, .optical-svg .atten-text { fill: var(--ink-muted); font-size: 12px; }
.optical-svg .tick { text-anchor: middle; }
.optical-svg .axis-title { font-weight: 600; }
.optical-svg .total-line { stroke: var(--ink); stroke-width: 2px; }
.optical-svg .total-text, .optical-svg .node-title { fill: var(--ink); font-size: 13px; font-weight: 700; }
.optical-svg .node-title { text-anchor: middle; }
.optical-svg .budget-line { stroke-width: 2px; stroke-dasharray: 5 3; }
.optical-svg .budget-line.pass { stroke: var(--pass); } .optical-svg .budget-line.fail { stroke: var(--fail); }
.optical-svg .budget-text { fill: var(--ink); font-size: 12px; font-weight: 600; }
.optical-svg .zone-window { fill: var(--series-2); opacity: .22; }
.optical-svg .zone-weak, .optical-svg .zone-overload { fill: var(--fail); opacity: .12; }
.optical-svg .zone-text { fill: var(--ink-muted); font-size: 11px; }
.optical-svg .level-text { fill: var(--ink); font-size: 12px; font-weight: 600; }
.optical-svg .tx-bar { fill: var(--series-0); }
.optical-svg .rx-bar.pass { fill: var(--pass); } .optical-svg .rx-bar.fail { fill: var(--fail); }
.optical-svg .link { stroke: var(--ink-muted); stroke-width: 1px; stroke-dasharray: 4 3; }
.optical-svg .atten-text { font-weight: 700; fill: var(--ink); }
.optical-svg .mark { stroke-width: 1.5px; }
.optical-svg .mark-tx { stroke: var(--ink); }
.optical-svg .mark-sens, .optical-svg .mark-ovl { stroke: var(--fail); stroke-dasharray: 6 3; }
.optical-svg .mark-floor { stroke: var(--series-3); stroke-dasharray: 2 3; }
.optical-svg .mark-target { stroke: var(--series-3); stroke-dasharray: 2 3; }
.chip { display: inline-block; width: 1.1rem; height: .8rem; border-radius: 2px; }
.chip.tx { background: var(--series-0); } .chip.window { background: var(--series-2); opacity: .35; }
.chip.rx.pass { background: var(--pass); } .chip.rx.fail { background: var(--fail); }
.chip.budget { background: transparent; border-top: 2px dashed var(--ink); height: 0; }

/* Styleguide page (development only) */
.sg-swatches { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-5); }
.sg-swatches li { display: flex; align-items: center; gap: var(--space-2); font-family: var(--font-mono); font-size: var(--text-sm); }
.sg-swatch { width: 1.5rem; height: 1.5rem; border-radius: var(--radius); border: 1px solid var(--line-strong); }
.sg-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

/* Duct bank designer */
.ductbank-form fieldset { min-width: 0; }
.diagram.section { display: block; }
.section-svg { width: 100%; max-width: 680px; max-height: 75vh; height: auto; display: block; background: #fcfcfb; border-radius: var(--radius, 6px); }
.section .diagram-note { margin-top: .75rem; }
.cable-head.positioned, .cable-row.positioned { grid-template-columns: 5rem 1fr 8rem 6rem 2.4rem; }
.duct-fills h3 { margin-top: 1.5rem; }
@media (max-width: 560px) { .cable-row.positioned { grid-template-columns: 1fr 1fr 2.4rem; } }
.duct-grid { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(4.25rem, 7rem)); gap: .5rem; margin-bottom: .5rem; overflow-x: auto; }

/* Microtrench designer */
.product-head, .product-row { display: grid; grid-template-columns: 1fr 6rem 8.5rem 7.5rem 4.5rem 2.4rem; gap: .5rem; margin-bottom: .5rem; }
.product-head { color: var(--muted); font-size: .85rem; }
.product-row [hidden] { display: block; visibility: hidden; }
@media (max-width: 560px) {
  .product-head { display: none; }
  .product-row { grid-template-columns: repeat(3, minmax(0, 1fr)) 3.25rem 2.4rem; }
  .product-row [name=kind] { grid-column: 1 / -1; }
  .product-row [hidden] { display: none; }
}
.issues { color: var(--fail); margin: 0 0 1rem; padding-left: 1.2rem; }
