/* Savory Tools — shared styles. SavoryUI v1.1 tokens (grayscale + green #16A34A). */
:root {
  color-scheme: light;
  --bg: #FAFAFA; --surface: #FFFFFF; --surface2: #F4F4F5; --border: #E4E4E7;
  --divider: #D4D4D8; --text: #18181B; --text2: #52525B; --muted: #71717A; --disabled: #A1A1AA;
  --green: #16A34A; --green-hover: #15803D; --green-light: #DCFCE7; --green-dark: #166534;
  /* Brand green is 3.3:1 on white — fine for fills and icons, fails WCAG AA for text.
     --green-text is the same hue darkened to 5.02:1 for links and other small green text. */
  --green-text: #15803D;
  --warn: #EAB308; --error: #DC2626;
  --r-sm: 8px; --r: 12px; --r-lg: 16px; --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --sans: 'Plus Jakarta Sans', system-ui, sans-serif; --mono: 'JetBrains Mono', monospace;
  --display: 'Michroma', sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09090B; --surface: #18181B; --surface2: #27272A; --border: #3F3F46;
  /* --muted was #71717A in both themes: 4.83:1 on light, but only 3.67:1 here. Lightened to 5.26:1. */
  --divider: #52525B; --text: #FAFAFA; --text2: #A1A1AA; --muted: #8B8B96; --disabled: #52525B;
  --green: #22C55E; --green-hover: #16A34A; --green-light: rgba(34,197,94,.15);
  --green-text: #22C55E;   /* 7.78:1 on the dark surface — already passes */
  --warn: #FACC15; --error: #F87171;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans);
  font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
.display, .brand { font-family: var(--display); letter-spacing: .04em; }
code, .mono, td.num { font-family: var(--mono); }
a { color: var(--green-text); text-decoration: none; }
a:hover { color: var(--green-hover); }

/* Top bar — brand centered, theme toggle right, (mobile) menu toggle left */
header.top {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 30;
}
header.top .brand { grid-column: 2; justify-self: center; font-family: var(--display); letter-spacing: .06em; font-size: 18px; color: var(--text); }
header.top .top-actions { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 2px; }
header.top .dash-toggle { grid-column: 1; justify-self: start; }
header.top .iconbtn {
  padding: 7px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text2); background: transparent; border: none; border-radius: var(--r-sm); cursor: pointer;
}
header.top .iconbtn:hover { color: var(--text); background: var(--surface2); }
header.top .unitbtn { font-family: var(--mono); font-size: 12px; font-weight: 600; min-width: 34px; }
header.top .dash-toggle { display: none; }

/* Left dashboard */
:root { --dash-w: 236px; --header-h: 57px; }
.dashboard {
  position: fixed; top: var(--header-h); left: 0; width: var(--dash-w);
  height: calc(100vh - var(--header-h)); z-index: 20;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.dash-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 12px 12px 8px; }
.dash-tabs button {
  padding: 8px 6px; font-size: 12px; font-weight: 600; border: 1px solid var(--border);
  background: var(--surface); color: var(--text2); border-radius: var(--r-sm);
}
.dash-tabs button:hover { border-color: var(--green); color: var(--text); }
.dash-tabs button.active { background: var(--green); color: #fff; border-color: var(--green); }
.dash-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }

/* Collapsible category groups */
.dash-cat {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 7px 8px; margin: 2px 0; border: none; background: transparent; cursor: pointer;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  border-radius: var(--r-sm);
}
.dash-cat:hover { background: var(--surface2); color: var(--text2); }
.dash-cat .icon { width: 14px; height: 14px; flex: none; transition: transform .15s ease-out; }
.dash-group.open .dash-cat .icon { transform: rotate(90deg); }
.dash-cat-name { flex: 1; text-align: left; }
.dash-cat-n { font-family: var(--mono); font-size: 10px; color: var(--muted); background: var(--surface2); padding: 1px 6px; border-radius: 999px; }
.dash-cat-items { display: none; padding-left: 6px; margin-bottom: 4px; }
.dash-group.open .dash-cat-items { display: block; }

.dash-item {
  display: block; padding: 6px 10px; border-radius: var(--r-sm); font-size: 13px;
  color: var(--text2); text-decoration: none; line-height: 1.35;
}
.dash-item:hover { background: var(--surface2); color: var(--text); }
.dash-item.active { background: var(--green-light); color: var(--green-dark); font-weight: 600; }
:root[data-theme="dark"] .dash-item.active { color: var(--green); }

.dash-controls { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.dash-ctl {
  flex: 1; padding: 7px 4px; font-size: 11px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text2); border-radius: var(--r-sm);
}
.dash-ctl:hover { border-color: var(--green); color: var(--text); }
.dash-backdrop { display: none; }

/* Push page content clear of the fixed sidebar */
body.has-dash main { margin-left: var(--dash-w); }

@media (max-width: 900px) {
  header.top .dash-toggle { display: inline-flex; }
  body.has-dash main { margin-left: 0; }
  .dashboard { transform: translateX(-100%); transition: transform .18s ease-out; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
  body.dash-open .dashboard { transform: translateX(0); }
  body.dash-open .dash-backdrop { display: block; position: fixed; inset: var(--header-h) 0 0 0; background: rgba(0,0,0,.35); z-index: 15; }
}

/* Layout */
main { max-width: 1040px; margin: 0 auto; padding: 32px 24px 64px; overflow-x: clip; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 24px; margin-bottom: 24px;
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }

/* Buttons */
button, .btn {
  font-family: var(--sans); font-size: 14px; font-weight: 600; padding: 8px 16px;
  border-radius: var(--r); border: 1px solid transparent; cursor: pointer; transition: all .15s ease-out;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--green); color: var(--green-text); }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--surface2); }

/* Forms */
label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; color: var(--text2); }
input, select {
  width: 100%; padding: 8px 12px; font-family: var(--sans); font-size: 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-sm);
}
input:focus, select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-light); }
.field { margin-bottom: 16px; }
.helper { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
/* Wide tables scroll inside their own box on narrow screens rather than the whole page. */
@media (max-width: 720px) { main table { display: block; overflow-x: auto; white-space: nowrap; } }
th { text-align: left; font-weight: 600; color: var(--text2); padding: 8px 12px; border-bottom: 1px solid var(--divider); position: sticky; top: 0; background: var(--surface); }
td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
td.num, th.num { text-align: right; font-family: var(--mono); }
tr:hover td { background: var(--surface2); }

/* Result readouts */
.readout { font-family: var(--mono); font-size: 32px; color: var(--green-text); font-weight: 500; }
.readout small { font-size: 14px; color: var(--muted); }
.stat { padding: 16px; background: var(--surface2); border-radius: var(--r); }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-family: var(--mono); font-size: 24px; color: var(--text); }

/* Landing tiles */
main.landing { max-width: 900px; }
.home-tile { color: inherit; margin-bottom: 0; transition: border-color .15s, transform .15s; }
.home-tile:hover { border-color: var(--green); transform: translateY(-2px); color: inherit; }
.home-tile h2 { margin-bottom: 6px; }
.home-tile p { color: var(--text2); margin: 0; }
.tile-h { font-size: 22px; display: flex; align-items: center; gap: 10px; }
.tile-i { width: 24px; height: 24px; flex: none; color: var(--green); }

/* Lucide icons inherit text color and size */
svg.icon { width: 20px; height: 20px; display: block; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--green-dark); background: var(--green-light); padding: 2px 8px; border-radius: var(--r-sm); }
:root[data-theme="dark"] .badge { color: var(--green); }

/* Tool intro + diagram */
.tool-intro h2 { font-size: 16px; font-weight: 700; }
.tool-intro p { color: var(--text2); margin: 0 0 8px; }
.dgm-wrap { margin: 16px 0 0; }
svg.dgm { width: 100%; max-height: 260px; display: block; }
svg.dgm text { font-family: var(--mono); font-size: 11px; fill: var(--text2); }
.dgm-line { stroke: var(--text2); fill: none; stroke-width: 1.5; stroke-linecap: round; }
.dgm-part { fill: var(--surface2); stroke: var(--text2); stroke-width: 1.5; }
.dgm-force { stroke: var(--green); stroke-width: 2; fill: none; }
.dgm-dim { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 2; fill: none; }

/* Standards list */
.standards h2 { font-size: 16px; font-weight: 700; }
.standards ul { margin: 0 0 12px; padding-left: 20px; color: var(--text2); font-size: 14px; }
.standards li { margin-bottom: 6px; }

/* Acronym hover cards */
.gloss {
  border-bottom: 1px dotted var(--green); cursor: help; position: relative; outline: none;
}
.gloss::after {
  content: attr(data-def);
  position: absolute; left: 0; top: calc(100% + 8px); z-index: 30;
  width: max-content; max-width: min(320px, 80vw);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: 0 4px 16px rgba(0,0,0,.12);
  padding: 12px; font-size: 13px; font-weight: 400; line-height: 1.45; text-align: left;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s ease-out, transform .15s ease-out, visibility .15s;
  pointer-events: none;
}
/* .is-open is set by tap/click so this works on touch, where :hover never fires. */
.gloss:hover::after, .gloss:focus::after, .gloss:focus-visible::after, .gloss.is-open::after {
  opacity: 1; visibility: visible; transform: translateY(0);
}
.gloss:focus-visible { box-shadow: 0 0 0 3px var(--green-light); border-radius: 2px; }

.disclaimer { font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 16px; margin-top: 32px; }
.chart-bar { height: 20px; background: var(--green); border-radius: 4px; }
svg .zone { fill: var(--green-light); stroke: var(--green); }
svg text { font-family: var(--mono); font-size: 11px; fill: var(--text2); }
/* Labels sit over beams, circles, hatching and dimension lines, and a stroke crossing a glyph makes
   it unreadable. paint-order:stroke paints a surface-coloured halo UNDER the fill, masking whatever
   passes behind the label instead of letting it cut through. Theme-aware, and it fixes every figure
   at once — tool diagrams, guide figures and chart axis labels — rather than nudging labels one by
   one. Gated on @supports: without paint-order the stroke would paint OVER the glyphs and wreck
   them, so unsupported browsers keep plain text. */
@supports (paint-order: stroke) {
  svg text { paint-order: stroke; stroke: var(--surface); stroke-width: 2.5px; stroke-linejoin: round; }
}

/* Export / print toolbar (injected on every tool page by site.js) */
.tool-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 0; }
.tool-actions .btn { display: inline-flex; align-items: center; gap: 7px; }
.tool-actions .btn .icon { width: 16px; height: 16px; }

/* A value we couldn't interpret — flashes, then the last good value is restored */
input.input-rejected { border-color: var(--error); box-shadow: 0 0 0 3px rgba(239,68,68,.15); }

/* Recently-used tools, pinned above the dashboard categories */
.dash-recent { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.dash-recent-h { display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dash-recent-h .icon { width: 13px; height: 13px; }

/* Calculation-sheet link + count badge in the header */
.sheet-link { position: relative; }
.sheet-badge { position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: 999px; background: var(--green); color: #fff; font-family: var(--mono);
  font-size: 9px; line-height: 15px; text-align: center; }

/* Calculation sheet page */
.sheet-step-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sheet-step-h h2 { margin: 0; font-size: 17px; }
.sheet-when { margin: 2px 0 10px; }
.sheet-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 8px 0 4px; }
.sheet-cols h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.sheet-cols td { padding: 4px 8px; font-size: 13px; }
.sheet-src { margin: 10px 0 0; word-break: break-all; }
.sheet-src a { color: var(--text2); }
.sheet-empty { text-align: center; padding: 40px 20px; }
.sheet-empty .btn { display: inline-block; margin-top: 12px; text-decoration: none; }
@media (max-width: 640px) { .sheet-cols { grid-template-columns: 1fr; gap: 10px; } }
@media print { .sheet-del, .sheet-intro, #meta .field label { break-inside: avoid; } .sheet-del { display: none !important; } }

/* ---- Accessibility ---- */

/* Text for screen readers only — used for the skip target, figure descriptions and live regions. */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* Skip link: off-screen until focused, then a normal button at the top-left. */
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 60;
  background: var(--surface); color: var(--text); border: 1px solid var(--green);
  border-radius: var(--r-sm); padding: 10px 16px; font-weight: 600; font-size: 14px;
  transition: top .15s ease-out;
}
.skip-link:focus { top: 8px; }

/* A visible focus ring everywhere, not just on inputs — keyboard users need to see where they are. */
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 3px; }

/* Touch targets: dashboard rows were 30px. 44px is the usual minimum for a finger. */
@media (pointer: coarse) {
  .dash-item, .dash-cat, .dash-tabs button, .dash-ctl { min-height: 44px; display: flex; align-items: center; }
  .cmdk-item { min-height: 44px; }
  .iconbtn { min-width: 44px; min-height: 44px; }
}

/* Respect a reduced-motion preference: keep state changes, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  .home-tile:hover { transform: none; }
}

/* Breadcrumbs */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; margin: 0 0 10px; color: var(--muted); }
.crumbs a { color: var(--text2); text-decoration: none; }
.crumbs a:hover { color: var(--green-text); }
.crumbs span[aria-current] { color: var(--muted); }
.crumb-sep { color: var(--border); }

/* Worked example card */
.example .ex-task { margin-top: 0; color: var(--text2); }
.example .ex-grid { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 24px; margin: 16px 0; }
.example h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.example .ex-given { margin: 0; font-size: 14px; }
.example .ex-given dt { color: var(--text2); }
.example .ex-given dd { margin: 0 0 8px; font-family: var(--mono); font-size: 13px; color: var(--text); }
.example .ex-steps { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.7; color: var(--text2); }
.example .ex-steps strong { font-family: var(--mono); color: var(--text); }
.example .ex-answer { background: var(--green-light); color: var(--green-dark); border-radius: var(--r);
  padding: 12px 14px; font-size: 14px; line-height: 1.6; margin: 0; }
@media (max-width: 640px) { .example .ex-grid { grid-template-columns: 1fr; gap: 14px; } }

/* FAQ card */
.faq details { border-top: 1px solid var(--border); padding: 12px 0; }
.faq details:first-of-type { border-top: none; }
.faq summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; color: var(--text); }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::before { content: "+"; font-family: var(--mono); color: var(--green-text); font-weight: 700; width: 14px; }
.faq details[open] summary::before { content: "\2212"; }
.faq .faq-a { margin: 8px 0 0 22px; color: var(--text2); font-size: 14px; line-height: 1.6; }
.faq .faq-a a { color: var(--green-text); }

/* Inline SVG line charts (SavoryChart) */
svg.cht { width: 100%; max-width: 520px; height: auto; display: block; margin: 4px auto 0; }
.cht-axis { stroke: var(--text2); stroke-width: 1; }
.cht-grid { stroke: var(--border); stroke-width: 1; }
.cht-marker { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.cht-tick { font-size: 10px; fill: var(--muted); }
.cht-lab { font-size: 11px; fill: var(--text2); }

/* ---- Print: cheat sheets and reference tables are meant to go on paper ---- */
@media print {
  header.top, .dashboard, .dash-backdrop, .cmdk-backdrop, .top-actions,
  button, .btn, .tool-actions, .tool-intro figure, .gloss::after { display: none !important; }
  :root { color-scheme: light; }
  html, body { background: #fff !important; color: #000 !important; }
  body.has-dash main { margin-left: 0; }
  main { max-width: none; margin: 0; padding: 0; overflow: visible; font-size: 10.5pt; }
  h1 { font-size: 18pt; margin: 0 0 8pt; }
  h2 { font-size: 12pt; margin: 10pt 0 4pt; break-after: avoid; page-break-after: avoid; }
  h3 { font-size: 11pt; break-after: avoid; page-break-after: avoid; }
  .card {
    background: #fff !important; box-shadow: none !important; border: 1px solid #bbb;
    border-radius: 4px; padding: 8pt 10pt; margin: 0 0 8pt;
    break-inside: avoid; page-break-inside: avoid;
  }
  table { font-size: 9pt; width: 100%; }
  thead { display: table-header-group; }          /* repeat headers across pages */
  tr { break-inside: avoid; page-break-inside: avoid; }
  th, td { padding: 2pt 5pt; border-bottom: 1px solid #ddd; color: #000 !important; }
  th { background: #f1f1f1 !important; }
  tr:hover td { background: transparent !important; }
  a { color: #000 !important; text-decoration: none; }
  .gloss { border-bottom: none; }
  .helper, .disclaimer { font-size: 8pt; color: #444 !important; }
  .stat { background: #f7f7f7 !important; padding: 6pt; }
  .readout { font-size: 16pt; color: #000 !important; }
  svg.dgm { max-height: 180pt; }
  @page { margin: 12mm; }
}

/* Command palette / search (Ctrl-K or the header search button) */
.cmdk-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.cmdk { width: min(560px, 100%); max-height: 70vh; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: 0 20px 60px rgba(0,0,0,.35); display: flex; flex-direction: column; overflow: hidden; }
.cmdk-input { width: 100%; border: none; border-bottom: 1px solid var(--border); border-radius: 0; padding: 15px 18px; font-size: 16px; background: transparent; color: var(--text); }
.cmdk-input:focus { outline: none; box-shadow: none; }
.cmdk-list { overflow-y: auto; padding: 6px; }
.cmdk-item { display: block; padding: 9px 12px; border-radius: var(--r-sm); cursor: pointer; text-decoration: none; }
.cmdk-item.sel, .cmdk-item:hover { background: var(--surface2); }
.cmdk-item .row1 { display: flex; align-items: center; gap: 8px; }
.cmdk-item .lbl { color: var(--text); font-weight: 600; font-size: 14px; }
.cmdk-item .type { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.cmdk-item .blurb { color: var(--text2); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-empty { padding: 28px; text-align: center; color: var(--muted); font-size: 14px; }
.cmdk-hint { padding: 8px 14px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); display: flex; gap: 16px; }
.cmdk-hint kbd { font-family: var(--mono); background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }


/* Shown only when JavaScript is disabled (injected by build.js) */
.noscript-note { background: var(--surface2); border: 1px solid var(--border); border-left: 3px solid var(--warn);
  border-radius: var(--r-sm); padding: 12px 16px; font-size: 14px; color: var(--text2); margin: 0 0 20px; }
