/* =========================================================
   STANDOUT — Cluster D calculators (additive widget layer)
   --------------------------------------------------------
   Loaded AFTER tokens.css + tools.css on the client-side
   calculator pages (final-grade, weighted-grade, tip,
   percentage-increase, percentage-difference, days-between,
   invoice) and on the /resources hub.

   Why this file exists: the shared tools.css carries the
   editorial shell, hero, sections, tables and FAQ we reuse
   as-is. The interactive *result widget* primitives we need
   here (a result-as-hero block, label/value breakdown rows,
   segmented toggles, quick-tap chips, dynamic rows, a stepper
   and the invoice document) are calculator-specific, so they
   live here in their own `.calc-*` namespace — never touching
   tools.css. Everything is built from the canonical Standout
   semantic tokens, so light/dark (OS-driven) just work and
   nothing is hardcoded.
   ========================================================= */

/* Status tokens (--tool-pass / --tool-warn / --tool-fail, plus their
   dark-mode variants) are defined in tools.css, which loads before this
   file — reuse them for the "what do I need" verdicts and weight-sum
   warnings. We only add the soft pass-tint the calculators use. */
:root {
  --calc-pass-soft: var(--color-primary-soft);
}

/* Keep "hidden means hidden". The shared .tool-field rule sets display:flex
   (and .calc-note sets display:grid below), which both outrank the UA
   [hidden]{display:none}; this reset keeps the fields, notes, verdicts,
   errors and flashes that the engines toggle via the `hidden` attribute
   actually hidden. Scoped to pages that load calculators.css. */
[hidden] { display: none !important; }

/* Hero: a tall live tool beside shorter marketing copy. Top-align the columns
   (so the headline never floats to centre leaving a big gap above it), tighten
   the column gap, and bring the oversized display headline to a balanced size. */
.hero.hero--calc { align-items: start; gap: var(--s-8); }
.hero.hero--calc h1 { font-size: clamp(34px, 4.4vw, 56px); line-height: 1.05; margin: var(--s-4) 0 var(--s-5); }
.hero.hero--calc .lede { margin-bottom: var(--s-6); }

/* On mobile, lead with the live tool so the answer is above the fold
   (the hero is a 1-col stack < 960px; pull the tool panel up first). */
@media (max-width: 960px) {
  .hero--calc { gap: var(--s-6); }
  .hero--calc > aside.tool-shell { order: -1; margin-bottom: var(--s-5); }
}
/* On a phone, tighten the in-tool form's vertical rhythm so the live result
   (the big number) stays within the first viewport rather than getting pushed
   below the fold by stacked fields + hints. */
@media (max-width: 560px) {
  .hero--calc .tool-form { gap: var(--s-3); }
  .hero--calc .tool-field .calc-hint { line-height: 1.35; }
}
@media (max-width: 560px) {
  .hero--calc .hero-ctas { width: 100%; }
  .hero--calc .hero-ctas .btn { width: 100%; justify-content: center; }
}

/* ---------- Form helpers layered on the alive .tool-form/.tool-field ---------- */
.calc-hint { font-size: var(--text-xs); color: var(--text-faint); line-height: 1.45; }
.calc-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
/* Keep the two-up field row side-by-side down to the narrowest phones (360px);
   stacking it vertically here is what pushed the result below the fold. */
@media (max-width: 359px) { .calc-field-row { grid-template-columns: 1fr; } }
/* Let grid-track inputs shrink below their intrinsic width (no overflow). */
.calc-field-row > *, .calc-item > *, .calc-item .tool-field { min-width: 0; }
.calc-item input, .calc-field-row input, .calc-item select { width: 100%; min-width: 0; }
.tool-field input,
.tool-field select { min-height: 44px; } /* thumb-reachable tap targets */

/* Segmented control (mode switchers — % phrasings, etc.) */
.calc-seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 4px;
}
.calc-seg button {
  appearance: none;
  padding: 11px 15px;
  min-height: 44px;
  border-radius: var(--r-pill);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  transition: background var(--d-1) var(--ease), color var(--d-1) var(--ease);
}
.calc-seg button:hover { color: var(--ink); }
.calc-seg button[aria-pressed="true"] {
  background: var(--green);
  color: var(--text-on-dark);
}

/* Inline checkbox (round-up, business-days) */
.calc-check { display: inline-flex; align-items: center; gap: 9px; font-size: var(--text-sm); color: var(--text); cursor: pointer; min-height: 44px; }
.calc-check input { width: 18px; height: 18px; accent-color: var(--green); flex: none; }

/* Quick-tap chips (tip %, date presets) */
.calc-chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.calc-chip {
  appearance: none;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: border-color var(--d-1) var(--ease), background var(--d-1) var(--ease), color var(--d-1) var(--ease);
}
.calc-chip:hover { border-color: var(--green-soft); }
.calc-chip[aria-pressed="true"] {
  background: var(--green-soft);
  border-color: var(--green);
  color: var(--green);
}

/* Weighted-grade category rows: name | grade | weight | remove */
.wg-item { grid-template-columns: 1fr 78px 78px 44px; }
@media (max-width: 480px) {
  .wg-item { grid-template-columns: 1fr 1fr 44px; gap: var(--s-2); }
  .wg-item .wg-name { grid-column: 1 / -1; }
}
/* Phone: compress the dynamic category list so three default rows + the
   add button don't push the live result below the first viewport. */
@media (max-width: 560px) {
  .hero--calc .calc-list { gap: var(--s-2); }
  .hero--calc .calc-item { gap: 4px; }
}

/* +/- stepper (party size, quantities) */
.calc-stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: var(--surface-2);
}
.calc-stepper button {
  width: 44px;
  min-height: 44px;
  font-size: var(--text-lg);
  color: var(--ink);
  background: var(--surface-2);
  transition: background var(--d-1) var(--ease);
}
.calc-stepper button:hover { background: var(--bg-soft); }
.calc-stepper input {
  width: 56px;
  text-align: center;
  border: none;
  border-left: 1px solid var(--hairline);
  border-right: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 600;
}
.calc-stepper input:focus { outline: none; }

/* Dynamic rows (weighted-grade categories, invoice line items) */
.calc-list { display: flex; flex-direction: column; gap: var(--s-3); }
.calc-item {
  display: grid;
  gap: var(--s-2);
  align-items: end;
}
.calc-item .tool-field { gap: 4px; }
.calc-item .tool-field label { font-size: 10px; }
.calc-remove {
  appearance: none;
  width: 44px;
  height: 44px;
  align-self: end;
  margin-bottom: 2px;
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  background: var(--surface-2);
  font-size: var(--text-md);
  line-height: 1;
  transition: color var(--d-1) var(--ease), border-color var(--d-1) var(--ease);
}
.calc-remove:hover { color: var(--text-warn); border-color: var(--text-warn); }
.calc-add {
  appearance: none;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px dashed var(--hairline-2);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--green);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: border-color var(--d-1) var(--ease), background var(--d-1) var(--ease);
}
.calc-add:hover { border-color: var(--green); background: var(--green-soft); }

/* =========================================================
   The result — the hero. Lives inside the alive .tool-output
   (which gives the top divider + spacing). aria-live region.
   ========================================================= */
.calc-result { display: flex; flex-direction: column; gap: var(--s-5); }

.calc-hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.calc-hero-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.calc-hero-num {
  font-family: var(--font-body); letter-spacing: -0.02em;
  font-weight: 700;
  font-size: clamp(40px, 9vw, 60px);
  line-height: 1.0;
  letter-spacing: -0.02em;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}
.calc-hero-sub { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.5; }
.calc-hero-sub strong { color: var(--ink); font-weight: 600; }
/* The letter grade that sits beside the big % — give it room so it doesn't
   crowd the number. */
.calc-hero-tag {
  font-family: var(--font-body); font-weight: 600;
  font-size: 0.5em;
  color: var(--text-muted);
  margin-left: 0.4em;
  letter-spacing: 0;
}

/* Breakdown — label left, value right ("how we got this") */
.calc-rows { display: flex; flex-direction: column; }
.calc-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
  padding: 10px 0;
  border-top: 1px solid var(--hairline);
}
.calc-row:first-child { border-top: 0; }
.calc-row .k {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.calc-row .v {
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.calc-row.is-primary { align-items: center; }
.calc-row.is-primary .v { font-size: var(--text-xl); color: var(--color-primary); }
.calc-row .v small { font-weight: 500; color: var(--text-muted); font-size: var(--text-xs); }

/* Two-up mini stat cards (e.g. tip + total, increase + decrease) */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}
.calc-stat {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.calc-stat .k {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.calc-stat .v {
  font-family: var(--font-body); font-weight: 700;
  font-size: var(--text-2xl);
  color: var(--ink);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.calc-stat.is-primary .v { color: var(--color-primary); }

/* Inline verdict / info notes */
.calc-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: var(--text-sm);
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  color: var(--text-muted);
}
.calc-note .ico { flex: none; margin-top: 1px; font-weight: 700; }
.calc-note strong { color: var(--ink); font-weight: 600; }
.calc-note.is-good {
  background: color-mix(in oklab, var(--tool-pass) 12%, transparent);
  color: var(--ink);
}
.calc-note.is-good .ico { color: var(--tool-pass); }
.calc-note.is-warn {
  background: color-mix(in oklab, var(--tool-warn) 12%, transparent);
  color: var(--ink);
}
.calc-note.is-warn .ico { color: var(--tool-warn); }
.calc-note.is-bad {
  background: color-mix(in oklab, var(--tool-fail) 12%, transparent);
  color: var(--ink);
}
.calc-note.is-bad .ico { color: var(--tool-fail); }

/* Actions row (copy + share permalink, or print/save on the invoice).
   Size every control here to a thumb-reachable 44px — the shared .btn-sm
   padding (≈33px tall) is too short for the primary tool actions. */
.calc-actions { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.calc-actions .btn,
.calc-actions .btn-sm,
.calc-actions .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; min-height: 44px;
  border-radius: var(--r-pill);
  font-size: var(--text-xs); font-weight: 600;
}
.calc-flash { font-size: var(--text-xs); color: var(--tool-pass); font-weight: 600; }

/* Privacy reassurance line under every tool */
.calc-privacy {
  display: flex; align-items: center; gap: 8px;
  margin-top: var(--s-3);
  font-size: var(--text-xs);
  color: var(--text-faint);
  line-height: 1.45;
}
.calc-privacy svg { flex: none; color: var(--text-faint); }

/* =========================================================
   Invoice generator — live document preview + print stylesheet
   ========================================================= */
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: var(--s-7); align-items: start; }
@media (max-width: 900px) { .invoice-layout { grid-template-columns: 1fr; } }
.invoice-layout .tool-shell { margin: 0; }
.invoice-upload { display: inline-flex; align-items: center; gap: 8px; }
.invoice-upload .btn-ghost { cursor: pointer; }

/* Editor breathing room */
form[data-calc="invoice"] { gap: var(--s-5); }
form[data-calc="invoice"] .calc-list { gap: var(--s-3); }

/* One column-header for the line items (desktop) so each row stays a single
   compact line instead of repeating Description / Qty / Unit-price labels. */
.invoice-items-head { display: none; }
@media (min-width: 521px) {
  .invoice-items-head {
    display: grid;
    grid-template-columns: 1fr 64px 88px 44px;
    gap: var(--s-2);
    margin: 2px 0 6px;
  }
  .invoice-items-head span {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-faint);
  }
  .invoice-item { align-items: center; }
  .invoice-item > .tool-field > label {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0; border: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}

.invoice-doc {
  /* A printable document: forced to white "paper" with dark ink in BOTH
     themes (mirrors .resume-paper and the print output). We remap the
     semantic tokens its children use to the light palette locally, so the
     on-screen preview always matches the PDF you'll save. */
  --ink: #14201a;
  --text: #14201a;
  --text-muted: #5a6660;
  --text-faint: #8a8f86;
  --hairline: #e7e0d0;
  --hairline-2: #d9d2c2;
  --surface-2: #ffffff;
  --color-primary: #0b3d2e;
  background: #ffffff;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--s-7);
  color: #14201a;
  box-shadow: var(--shadow-2);
}
.invoice-doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s-5);
  flex-wrap: wrap;
}
.invoice-logo {
  max-height: 64px;
  max-width: 200px;
  object-fit: contain;
  border-radius: var(--r-sm);
}
.invoice-logo-ph {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-2xl);
  color: var(--ink);
}
.invoice-title {
  text-align: right;
}
.invoice-title h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-3xl);
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.invoice-title .meta { font-size: var(--text-sm); color: var(--text-muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-5);
  margin: var(--s-6) 0;
}
.invoice-parties .lab {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.invoice-parties .who { white-space: pre-wrap; font-size: var(--text-sm); line-height: 1.5; color: var(--ink); }

.invoice-table { width: 100%; border-collapse: collapse; margin-top: var(--s-4); font-size: var(--text-sm); }
.invoice-table thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--hairline-2);
  padding: 8px 10px;
}
.invoice-table tbody td { padding: 9px 10px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
.invoice-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.invoice-totals {
  margin-top: var(--s-4);
  margin-left: auto;
  width: min(280px, 100%);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.invoice-totals .row { display: flex; justify-content: space-between; gap: var(--s-4); padding: 6px 0; font-size: var(--text-sm); }
.invoice-totals .row .k { color: var(--text-muted); }
.invoice-totals .row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.invoice-totals .row.grand {
  border-top: 2px solid var(--ink);
  margin-top: 4px;
  padding-top: 10px;
}
.invoice-totals .row.grand .k { color: var(--ink); font-weight: 700; }
.invoice-totals .row.grand .v { font-size: var(--text-xl); color: var(--color-primary); }
.invoice-notes { margin-top: var(--s-6); font-size: var(--text-sm); color: var(--text-muted); white-space: pre-wrap; }
.invoice-notes .lab {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
}

/* Line-item editor grid */
.invoice-item {
  grid-template-columns: 1fr 64px 88px 44px;
}
@media (max-width: 520px) {
  .invoice-item { grid-template-columns: 1fr 1fr 44px; }
  .invoice-item .tool-field:first-child { grid-column: 1 / -1; }
}

/* Mobile: tighten the invoice document so the page never scrolls sideways. */
@media (max-width: 520px) {
  .invoice-doc { padding: var(--s-5); }
  .invoice-parties { grid-template-columns: 1fr; gap: var(--s-4); }
  .invoice-table { font-size: var(--text-xs); }
  .invoice-table thead th, .invoice-table tbody td { padding: 7px 6px; }
}

/* Print: show only the invoice document, full-bleed. The .invoice-doc rule
   above already remaps its palette to forced-light "paper" (white ground,
   forest ink) in both themes, so print inherits the same look — we only
   reset the screen chrome (position, borders, shadow) here. */
@media print {
  body * { visibility: hidden; }
  .invoice-doc, .invoice-doc * { visibility: visible; }
  .invoice-doc {
    position: absolute;
    inset: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 32px;
  }
  @page { margin: 14mm; }
}

/* Hub / related-tools cards (.tools-grid / .tool-card) come from the
   repaired tools.css — no copies needed here. */
