/*
 * Circuitcheck — site.css (§10). One file, no framework, CSS variables.
 * Character: an engineering drawing sheet, not a dashboard. Reference: offgrid-design.html.
 * Forbidden (§10.7): shadows, radii > --r (except header pill chips), decorative gradients
 * (the 24px paper grid is the only one), all-caps labels, arrows at the end of links/buttons,
 * monospace numbers, icon fonts.
 */

/* ------------------------------------------------------------------ tokens */
:root {
  --paper:  #F1F3EE;   /* page background */
  --grid:   #DCE1D8;   /* graph-paper lines, hairline borders */
  --white:  #FFFFFF;   /* cards and tables on top of paper */
  --ink:    #1E2933;   /* text, schematic strokes, outline buttons */
  --ink-2:  #55606B;   /* secondary text (5.7:1 on paper) */
  --ink-3:  #8C959E;   /* tertiary — non-text marks only (2.7:1) */
  --wire:   #2B2F33;   /* healthy schematic wire */
  --fault:   #D23F2C; --fault-bg:   #FBE9E5;   /* error: broken wire */
  --caution: #B8800F; --caution-bg: #FBF1D9;   /* warning */
  --ok:      #2F8F5B; --ok-bg:      #E2F1E7;   /* all good */
  --action: #1F57C3;   /* the only accent: links and the primary button */
  --sun:    #F0B32D;   /* logo and decoration only, never UI state */
  --sans: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --r: 4px;

  /* Text-on-tint variants. The status colours above fail 4.5:1 as text on their own
     backgrounds (§10.8: caution 3.05, fault 3.99, ok 3.46, ink-3 2.72), so text uses these. */
  --fault-ink:   #B02F1F;  /* 5.47:1 on --fault-bg */
  --caution-ink: #8A5F06;  /* 5.02:1 on --caution-bg */
  --ok-ink:      #237047;  /* 5.16:1 on --ok-bg */
  --ink-3-text:  #646D76;  /* 4.71:1 on --paper — source lines */

  --frame: 1120px;
  --text-frame: 720px;
  --gap: 32px;
  --tap: 44px;
}

/* Dark theme is OPTIONAL (§10.1) and deliberately not shipped in the first release. */

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--paper); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}
img, svg { max-width: 100%; }
a { color: var(--action); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h2 { font-size: 22px; letter-spacing: -.01em; margin-bottom: 14px; }
h3 { font-size: 18px; }
p { margin: 0; }
p + p { margin-top: 10px; }
small { font-size: 13px; }

.frame { max-width: var(--frame); margin: 0 auto; padding: 0 24px; }
.frame-text { max-width: var(--text-frame); margin: 0 auto; padding: 0 24px; }
.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip { position: absolute; left: 8px; top: -60px; background: var(--white); border: 1.5px solid var(--ink); padding: 10px 14px; z-index: 10; }
.skip:focus { top: 8px; }

/* ------------------------------------------------------------------ header: drawing title block */
.site-header { padding: 22px 0 0; }
.site { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-bottom: 14px; color: var(--ink); text-decoration: none; width: max-content; }
.site svg { width: 26px; height: 26px; flex: none; }
.titleblock {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 24px; flex-wrap: wrap;
  border-bottom: 2px solid var(--ink); padding-bottom: 14px;
}
.titleblock h1 { font-size: 40px; line-height: 1.05; letter-spacing: -.02em; }
.titleblock h1 small { display: block; font-size: 16px; font-weight: 400; letter-spacing: 0; color: var(--ink-2); margin-top: 8px; }

.ctx { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 15px; line-height: 1.2;
  background: var(--white); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 999px; /* the one allowed pill (§10.7) */
  padding: 8px 14px; min-height: 38px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.chip:hover { border-width: 2px; padding: 7.5px 13.5px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  font: inherit; font-size: 15px; font-weight: 600; text-align: left;
  padding: 12px 16px; min-height: var(--tap);
  border: 1.5px solid var(--ink); border-radius: var(--r);
  background: var(--white); color: var(--ink); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { background: var(--paper); }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--white); }
.btn.primary:hover { background: #17469F; border-color: #17469F; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

/* ------------------------------------------------------------------ hero: verdict + schematic */
.hero { display: grid; grid-template-columns: 260px 1fr; gap: var(--gap); padding: 32px 0 8px; align-items: start; }

.verdict { border-left: 6px solid var(--fault); padding-left: 16px; }
.verdict[data-state="warning"] { border-left-color: var(--caution); }
.verdict[data-state="ok"] { border-left-color: var(--ok); }
.verdict .n { font-size: 64px; line-height: 1; font-weight: 600; letter-spacing: -.03em; }
.verdict .label { display: inline-block; font-size: 13px; font-weight: 600; margin-bottom: 6px; padding: 2px 8px; border-radius: var(--r); }
.verdict[data-state="error"] .label { background: var(--fault-bg); color: var(--fault-ink); }
.verdict[data-state="warning"] .label { background: var(--caution-bg); color: var(--caution-ink); }
.verdict[data-state="ok"] .label { background: var(--ok-bg); color: var(--ok-ink); }
.verdict p { margin: 8px 0 0; font-size: 18px; }
.verdict .sub { color: var(--ink-2); font-size: 15px; }
.verdict .actions { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }

.schematic { margin: 0; background: var(--white); border: 1.5px solid var(--ink); padding: 18px 18px 10px; position: relative; }
.schematic svg { display: block; width: 100%; height: auto; }
.schematic svg text { font-family: var(--sans); }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.legend i { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 6px; background: var(--wire); }
.legend i.f { background: var(--fault); }
.legend i.c { background: var(--caution); }

/* SVG schematic classes (shared with the print single-line diagram, §5.13) */
.sch-wire { stroke: var(--wire); stroke-width: 2.5; fill: none; }
.sch-wire.fault { stroke: var(--fault); }
.sch-wire.caution { stroke: var(--caution); }
.sch-body { stroke: var(--wire); stroke-width: 2; fill: var(--white); }
.sch-hair { stroke: var(--grid); stroke-width: 1; fill: none; }
.sch-lead { stroke-width: 1.5; stroke-dasharray: 3 3; fill: none; }
.sch-lead.fault { stroke: var(--fault); }
.sch-lead.caution { stroke: var(--caution); }
.sch-note.fault { fill: var(--fault-bg); stroke: var(--fault); stroke-width: 1.5; }
.sch-note.caution { fill: var(--caution-bg); stroke: var(--caution); stroke-width: 1.5; }
.sch-t { font-size: 13px; fill: var(--ink); }
.sch-t2 { font-size: 13px; fill: var(--ink-2); }
.sch-tb { font-size: 13px; font-weight: 600; fill: var(--ink); }
.sch-t-fault { font-size: 14px; font-weight: 600; fill: var(--fault-ink); }
.sch-t-caution { font-size: 14px; font-weight: 600; fill: var(--caution-ink); }
.sch-t-ok { font-size: 12px; fill: var(--ok-ink); }

/* ------------------------------------------------------------------ problems (§10.4) */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); padding: 32px 0; }
.problems { margin: 0; padding: 0; list-style: none; }
.problem { display: grid; grid-template-columns: 28px 1fr; gap: 12px; padding: 16px 0; border-top: 1px solid var(--grid); }
.problem:last-child { border-bottom: 1px solid var(--grid); }
.dot { width: 16px; height: 16px; border-radius: 50%; margin-top: 4px; background: var(--ink-3); }
.dot.f { background: var(--fault); }
.dot.c { background: var(--caution); }
.dot.i { background: var(--ink-2); }
.dot.ok { background: var(--ok); }
.problem h3 { font-size: 18px; }
.problem .sev { font-size: 13px; font-weight: 600; color: var(--ink-2); display: block; margin-bottom: 2px; }
.problem .sev.f { color: var(--fault-ink); }
.problem .sev.c { color: var(--caution-ink); }
.problem .sev.ok { color: var(--ok-ink); }
.problem p { margin-top: 6px; color: var(--ink-2); }
.problem details { margin-top: 8px; }
.problem summary { cursor: pointer; color: var(--action); font-size: 15px; min-height: 28px; }
.problem .tech { background: var(--paper); border-left: 3px solid var(--ink); padding: 10px 12px; margin-top: 8px; font-size: 15px; }
.problem .tech b { font-weight: 600; }
.src { font-size: 13px; color: var(--ink-3-text); margin-top: 6px; }
.src a { color: inherit; }
.fix { margin-top: 10px; font-size: 15px; }
.more { margin-top: 12px; }

/* Terms with explanations (§10.4): dotted underline, opens on tap/click/focus, never hover-only */
.term {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: help;
  text-decoration: underline dotted; text-decoration-thickness: 1.5px; text-underline-offset: 3px;
  position: relative;
}
.term-tip {
  position: absolute; z-index: 5; left: 0; top: calc(100% + 6px);
  width: max-content; max-width: min(300px, 80vw);
  background: var(--white); color: var(--ink); border: 1.5px solid var(--ink); border-radius: var(--r);
  padding: 8px 10px; font-size: 14px; font-weight: 400; line-height: 1.4; text-align: left;
}
.term-tip[hidden] { display: none; }

/* ------------------------------------------------------------------ year ribbon (§10.5) */
.ribbon-wrap { background: var(--white); border: 1.5px solid var(--ink); padding: 16px; }
.ribbon { display: grid; grid-template-columns: repeat(365, 1fr); height: 110px; align-items: end; }
.ribbon span { display: block; background: var(--ok); min-height: 3px; }
.ribbon span.lo { background: var(--caution); }
.ribbon span.out { background: var(--fault); }
.months { display: grid; grid-template-columns: repeat(12, 1fr); font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 24px; margin-top: 16px; }
.stats div { font-size: 14px; color: var(--ink-2); }
.stats b { display: block; font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; color: var(--ink); }
.stats b.f { color: var(--fault-ink); }
.pending { font-size: 14px; color: var(--ink-2); }
.note { margin-top: 12px; font-size: 14px; color: var(--ink-2); }

/* ------------------------------------------------------------------ slots (configurator, §8.1, §10.6) */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.slot { background: var(--white); border: 1.5px solid var(--ink); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 4px; }
.slot .k { font-size: 13px; color: var(--ink-2); }
.slot .v { font-weight: 600; }
.slot .spec { font-size: 14px; color: var(--ink-2); }
.slot.empty { border-style: dashed; color: var(--ink-2); }
.slot button { justify-self: start; }
.field { display: grid; gap: 4px; font-size: 14px; }
.field input, .field select {
  width: 100%; min-width: 0; max-width: 100%;
  font: inherit; font-size: 16px; min-height: var(--tap); padding: 8px 10px;
  border: 1.5px solid var(--ink); border-radius: var(--r); background: var(--white); color: var(--ink);
}

.slot .k small { color: var(--ink-2); font-weight: 400; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.inline .field { flex: 1 1 110px; }
.field small { color: var(--ink-2); font-size: 13px; }
.config { padding: 24px 0 0; }
.mode { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }

/* start screen: five buttons (§8.1) */
.start { padding: 32px 0; }
.start-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.start-btn { width: 100%; min-height: 88px; align-items: flex-start; }
.start-btn span { display: grid; gap: 4px; }
.start-btn small { font-weight: 400; color: var(--ink-2); font-size: 14px; }
.start-kit { align-content: center; }

/* loads */
.loads { list-style: none; margin: 0 0 12px; padding: 0; }
.loads li { display: grid; grid-template-columns: 1fr 120px auto; gap: 10px; align-items: end; padding: 10px 0; border-top: 1px solid var(--grid); }
.loads li:last-child { border-bottom: 1px solid var(--grid); }
.loads small { display: block; color: var(--ink-2); font-size: 13px; }

.week { border: 0; padding: 0; margin: 8px 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; grid-column: 1 / -1; }
.week legend { font-size: 13px; color: var(--ink-2); margin-bottom: 4px; padding: 0; }
.week .field input { padding: 8px 4px; text-align: center; }
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; min-height: var(--tap); justify-content: center; }
.day input { width: 22px; height: 22px; margin: 0; }
.loads li.charger { grid-template-columns: 1fr auto; }
.actions-row { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.fixnotes { margin-top: 14px; font-size: 14px; background: var(--ok-bg); border-left: 3px solid var(--ok); padding: 8px 12px; }
.fixnotes ul { margin: 6px 0 0; padding-left: 18px; }

/* picker: full-screen list with search (§10.6) */
.picker { border: 1.5px solid var(--ink); border-radius: var(--r); padding: 0; width: min(640px, 100vw); max-height: min(80vh, 720px); background: var(--white); color: var(--ink); }
.picker::backdrop { background: rgba(30, 41, 51, .35); }
.picker-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1.5px solid var(--ink); position: sticky; top: 0; background: var(--white); }
.picker-head h2 { margin: 0; font-size: 18px; }
.picker-search { font: inherit; font-size: 16px; width: calc(100% - 32px); margin: 12px 16px; min-height: var(--tap); padding: 8px 10px; border: 1.5px solid var(--ink); border-radius: var(--r); }
.picker-list { list-style: none; margin: 0; padding: 0 16px 16px; }
.picker-item { font: inherit; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--grid); padding: 12px 4px; min-height: var(--tap); cursor: pointer; color: var(--ink); display: grid; gap: 2px; }
.picker-item:hover { background: var(--paper); }
.picker-item small { color: var(--ink-2); font-size: 14px; }

/* ------------------------------------------------------------------ tables / BOM */
.bom { padding: 8px 0 48px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--white); border: 1.5px solid var(--ink); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--grid); font-size: 15px; vertical-align: top; }
th { font-weight: 600; border-bottom: 1.5px solid var(--ink); }
td.n, th.n { text-align: right; white-space: nowrap; }
td small, th small { display: block; color: var(--ink-2); font-size: 13px; }
tr.new td { background: var(--ok-bg); } /* rows added by auto-fix — the only row fill allowed (§10.5) */
caption { text-align: left; font-size: 14px; color: var(--ink-2); padding: 0 0 8px; }

/* ------------------------------------------------------------------ live calculators (guide-calc, econ-calc) —
   label + input pairs had no rules at all before this, so the label text and the input box ran
   together edge-to-edge on narrow screens ("Panel Voc at 25°C (V)48.2", no visible gap). */
.guide-calc, .econ-calc { margin: 16px 0; }
.econ-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 10px; }
.econ-row label { flex: 1 1 220px; }
.econ-row input[type="number"] { flex: 0 1 120px; min-height: var(--tap); padding: 6px 10px; border: 1.5px solid var(--ink); border-radius: var(--r); font: inherit; }
.econ-row input[type="range"] { flex: 1 1 140px; min-height: var(--tap); }
.econ-row select { min-height: var(--tap); padding: 6px 10px; border: 1.5px solid var(--ink); border-radius: var(--r); font: inherit; }
.econ-row output { min-width: 64px; text-align: right; font-weight: 600; }
.econ-result { font-size: 16px; }

/* ------------------------------------------------------------------ text pages (720px) */
.prose { font-size: 17px; line-height: 1.6; }
.prose h2 { margin-top: 32px; }
.prose p, .prose ul, .prose ol, .prose table { margin: 0 0 16px; }
.prose code { font-family: inherit; background: var(--white); border: 1px solid var(--grid); padding: 0 4px; border-radius: var(--r); }

/* ------------------------------------------------------------------ footer + disclaimer (§1.5) */
.disclaimer { border: 1.5px solid var(--ink); background: var(--white); padding: 10px 14px; font-size: 14px; margin: 24px 0 0; }
.site-footer {
  border-top: 2px solid var(--ink); padding: 16px 0 40px; margin-top: 16px;
  font-size: 14px; color: var(--ink-2);
  display: flex; gap: 24px; flex-wrap: wrap; justify-content: space-between;
}
.footer-nav { flex-basis: 100%; padding-top: 8px; border-top: 1px solid var(--grid); }
.footer-nav a { color: var(--ink-2); }

/* ------------------------------------------------------------------ motion (§10.8) */
@media (prefers-reduced-motion: no-preference) {
  .pulse { animation: pulse 1.6s ease-in-out 2; } /* two cycles, no more */
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
}

/* ------------------------------------------------------------------ mobile: one breakpoint (§10.6) */
@media (max-width: 767.98px) {
  .frame, .frame-text { padding: 0 16px; }
  .titleblock h1 { font-size: 30px; }
  .ctx { width: 100%; }
  .chip { min-height: var(--tap); }
  .hero, .two { grid-template-columns: 1fr; gap: 24px; }
  .verdict .n { font-size: 52px; }
  .verdict .actions .btn { width: 100%; justify-content: flex-start; }
  /* schematic moves below the verdict, view-only and scaled down */
  .schematic { padding: 10px; }
  .schematic .legend { font-size: 12px; gap: 10px; }
  .ribbon { height: 70px; }
  .slots, .start-grid { grid-template-columns: minmax(0, 1fr); }
  .picker { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .loads li { grid-template-columns: 1fr 96px; }
  .loads li .btn { grid-column: 1 / -1; justify-self: start; }
  .print-only-wide { display: none; } /* the printed single-line diagram is not drawn on phones */
  th, td { padding: 8px; font-size: 14px; }
  .term-tip { position: fixed; left: 16px; right: 16px; top: auto; bottom: 16px; max-width: none; width: auto; }
  .econ-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .econ-row label { flex: none; }
  .econ-row input[type="number"], .econ-row select { flex: none; max-width: none; }
  .econ-row output { text-align: left; }
}

/* ------------------------------------------------------------------ print: A4, black and white (§16 item 19) */
@media print {
  @page { size: A4; margin: 12mm; }
  :root {
    --paper: #fff; --grid: #bbb; --ink: #000; --ink-2: #000; --ink-3: #444; --ink-3-text: #000;
    --wire: #000; --fault: #000; --caution: #000; --ok: #000;
    --fault-ink: #000; --caution-ink: #000; --ok-ink: #000;
    --fault-bg: #fff; --caution-bg: #fff; --ok-bg: #fff;
  }
  body { background: #fff; font-size: 11pt; }
  .frame, .frame-text { max-width: none; padding: 0; }
  /* one A4 sheet: title block, verdict, schematic, parts list (§5.13, §16 item 19) */
  .ctx, .actions, .skip, .no-print, .print-hide, .config, .start, .fixnotes, details summary, .fix .btn, .site-footer a, .picker { display: none !important; }
  .hero { padding-top: 4px; }
  .schematic { padding: 6px; }
  .bom { padding: 6px 0 0; }
  th, td { padding: 4px 6px; font-size: 9pt; }
  .disclaimer { margin-top: 6px; padding: 4px 8px; font-size: 9pt; }
  details > .tech { display: block; }
  .hero, .two { grid-template-columns: 1fr; gap: 12px; padding: 8px 0; }
  .verdict { border-left-width: 3px; }
  .verdict .n { font-size: 36pt; }
  .schematic, .ribbon-wrap, table { border-width: 1px; break-inside: avoid; }
  /* faults stay distinguishable without colour: dashed broken wire, bold labels */
  .sch-wire.fault { stroke-dasharray: 6 3; stroke-width: 3; }
  .sch-wire.caution { stroke-dasharray: 2 3; stroke-width: 3; }
  .legend i.f { background: repeating-linear-gradient(90deg, #000 0 6px, transparent 6px 9px); }
  .legend i.c { background: repeating-linear-gradient(90deg, #000 0 2px, transparent 2px 5px); }
  .ribbon span, .ribbon span.lo, .ribbon span.out { background: #000; }
  tr.new td { background: #fff; font-weight: 600; }
  a { color: #000; text-decoration: none; }
  .print-break { break-before: page; }
  .dot { border: 1.5px solid #000; }
}
