/* Brand bridge for the standalone free-tools apps (ph-lens, crop-suitability,
   soil-tax-calculator, crop-mix-planner — separate repos, same domain).
   Maps their legacy utility tokens onto the v3 brand system from
   /assets/css/site.css and enforces brand geometry inside <main>:
   square keylines, no shadows, Archivo/Space Mono, one hover rule
   (lime fill, navy text, inset keyline). Load AFTER site.css.
   `html:root` outranks each tool's own `:root` block regardless of order. */

html:root {
  /* ---- legacy utility tokens → brand ---- */
  --color-surface:          var(--ivory);
  --color-surface-elevated: #FFFFFF;
  --color-border:           rgba(34,59,195,.30);
  --color-ink:              var(--blue);
  --color-ink-muted:        rgba(34,59,195,.86);   /* .72 measured 4.3:1 on white — below AA */
  --color-muted:            rgba(34,59,195,.86);
  --color-primary:          var(--blue);
  --color-primary-hover:    var(--navy);
  --color-accent:           var(--lime);
  --color-info-surface:     rgba(34,59,195,.06);
  --color-error:            #FE3D33;
  --red:                    #FE3D33;   /* crop-mix-planner redefines --red at :root */
  --color-problem:          #EC8D34;
  --color-success:          var(--blue);
  --gradient-hero:          var(--blue);

  /* ---- type ---- */
  --font-body:    var(--f-sans);
  --font-heading: var(--f-sans);
  --font-display: var(--f-sans);
  --font-ui-label: var(--f-mono);
  --font:         var(--f-sans);
  --font-mono:    var(--f-mono);

  /* ---- brand quarter status ramp (brand book dataviz) ---- */
  --q1:  #EB4E3E;   /* failed · low · toxic */
  --q1t: #F06050;
  --q2:  #EC8D34;   /* warning */
  --q3:  #F9D64A;   /* pending · watch */
  --q4:  #C7FB50;   /* passed · optimal */
  /* tints for status surfaces */
  --tq1: rgba(235,78,62,.12);
  --tq2: rgba(236,141,52,.16);
  --tq3: rgba(249,214,74,.30);
  --tq4: rgba(199,251,80,.30);

  /* ---- tool palettes → brand ---- */
  /* ph-lens */
  --green:  var(--q4);
  --gold:   var(--q3);
  --sky:    var(--b4);
  --brown:  var(--blue);
  --status-toxic: #FE3D33;
  /* crop-suitability */
  --accent:      var(--blue);
  --accent-dark: var(--navy);
  --accent-dim:  var(--navy);
  --accent-pale: rgba(34,59,195,.08);
  --highlight:      var(--blue);
  --highlight-soft: var(--b4);
  --green-400: var(--q4);
  --green-500: var(--q4);
  --green-600: var(--blue);
  --green-700: var(--navy);
  --terra-300: var(--q3);
  --terra-400: var(--q2);
  --terra-500: var(--q2);
  --terra-600: #C96A02;
  --terra-700: var(--navy);
  --ink-900: var(--blue);
  --ink-700: var(--b2);
  --ink-500: var(--b2);   /* text tint: b3 is 3.4:1 on ivory */
  --ink-300: var(--b4);
  --ink-100: var(--b5);
  --cream-50:  #FFFFFF;
  --cream-100: var(--ivory);
  --cream-200: var(--ivory);
  --cream-300: rgba(34,59,195,.30);
  /* soil-tax */
  --cream: var(--blue);
  --surface-alt: var(--ivory);
  /* crop-mix-planner */
  --green-dark:  var(--navy);
  --green-light: rgba(34,59,195,.08);
  --green-pale:  var(--ivory);
  --amber:       var(--q2);
  --amber-pale:  var(--tq2);
  --line:        rgba(34,59,195,.30);
  --background:  var(--ivory);
  --muted:       rgba(34,59,195,.86);
  --text:        var(--blue);
  --text-primary:   var(--blue);
  --text-secondary: var(--b2);
  --text-muted:     var(--b2);
  --text-body:   rgba(34,59,195,.86);
  --text-dark:   var(--blue);
  --border:      rgba(34,59,195,.30);
  --surface:     #FFFFFF;

  /* ---- geometry ---- */
  --radius:    0;
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
  --radius-xl: 0;
  --radius-pill: 0;
  --shadow:    none;
  --shadow-sm: none;
  --shadow-lg: none;
}

/* ================= geometry: everything square, no shadows ============= */
main * { border-radius: 0 !important; }
main :is(div,section,article,aside,form,fieldset) { box-shadow: none; }
main ::-webkit-slider-thumb          { border-radius: 0 !important; }
main ::-moz-range-thumb              { border-radius: 0 !important; }
main ::-webkit-slider-runnable-track { border-radius: 0 !important; }
main ::-moz-range-track              { border-radius: 0 !important; }

/* ================= fields: .inp spec ================= */
main :is(select,
         input:not([type=range]):not([type=radio]):not([type=checkbox])
              :not([type=file]):not([type=hidden]):not([type=submit])
              :not([type=button]),
         textarea,
         .num-input, .coord-text-input, .fert-rate-input, .liming-rate-input,
         .fert-select, .liming-select, .years-select, .select-input) {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(34,59,195,.7);
  background: #FFFFFF;
  color: var(--blue);
  padding: 11px 12px;
  font: 400 14px var(--f-mono);
  border-radius: 0;
  width: 100%;
  min-height: 44px;
  outline: none;
  box-shadow: none;
}
main :is(select,input,textarea):focus,
main :is(select,input,textarea):focus-visible {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

/* select: brand chevron, no native arrow */
main select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--blue) 50%),
    linear-gradient(135deg, var(--blue) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}
main .select-arrow { display: none; }   /* tools draw their own arrows */

/* labels: .flab spec */
main label { font-weight: 500; font-size: 13px; color: var(--blue); }

/* ================= buttons: .btn / .chip spec ================= */
main :is(button, .btn-cta, .btn-analyse, .btn-calculate, .btn-fetch,
         .btn-reset, [type=submit]) {
  font-family: var(--f-sans);
  font-weight: 500;
  font-size: 14.5px;
  line-height: 1.1;
  letter-spacing: -.01em;
  color: var(--blue);
  border-radius: 0;
  cursor: pointer;
  transition: background .25s, color .25s, font-weight .3s var(--ease-o);
}
/* primary CTAs read as brand .btn */
main :is(.btn-cta, .btn-analyse, .btn-calculate, .btn-fetch,
         [type=submit], .submit-section button, .button-row button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  background: var(--blue);
  color: var(--ivory);
}
/* secondary / reset = .btn ghost */
main :is(.btn-reset, .sheet-close, .modal-close) {
  background: var(--ivory);
  border: 1px solid rgba(34,59,195,.55);
}
/* one hover for everything you can touch */
main :is(button, .btn-cta, .btn-analyse, .btn-calculate, .btn-fetch,
         .btn-reset, [type=submit], .month-btn, .season-preset,
         .toggle-btn, .fert-slot, .crop-card, a.chief-link)
     :is(:hover, :focus-visible) {
  background: var(--lime) !important;
  color: var(--navy) !important;
  border-color: var(--navy);
  box-shadow: inset 0 0 0 1px var(--navy);
  font-weight: 700;
}
/* pressed/selected = brand chip-on */
main :is([aria-pressed="true"], .month-btn.on, .season-preset.on,
         .toggle-btn.on, .fert-slot.on, .crop-card.on) {
  background: var(--blue);
  color: var(--ivory);
  border-color: var(--blue);
}

/* ================= panels: keyline cells ================= */
/* field wrappers (.field, .num-field, .coord-field …) stay unboxed — the input
   carries the keyline; boxing both drew nested frames with labels on the line */
main :is(.panel, .side-card,
         .result-block, .metric, .recommendation-card, .fert-slot,
         .crop-card, .form-section, .tool-section, .fi-summary,
         .diag-pill, .modal-box, .sheet-inner, .context-badge, .notice,
         .warnings, .cautions, .assumptions, .breakdown, .evidence,
         .results-panel, .total-block,
         .result-header, .recommendation-topline, .rank, .score-box) {
  border: 1px solid rgba(34,59,195,.55);
  border-radius: 0;
  box-shadow: none;
}

/* progress / track bars: blue fill, square */
main :is(.progress-bar, .opt-bar-track i, .diagnosis-bar i) {
  border-radius: 0;
  background: var(--blue);
}
main .progress-wrap { border-radius: 0; background: rgba(34,59,195,.12); }

/* scrims stay neutral-navy */
main :is(.modal-overlay, .sheet-backdrop) { background: rgba(11,26,110,.45); }

/* footnote/meta text = brand mono-dim */
main :is(.tool-note, .section-hint, .select-meta, .hint, .panel-hint,
         .methodology-note__label, .submit-hint, .fetch-badge,
         .diag-counts, .years-labels, .fi-label, .slider-row-val) {
  font-family: var(--f-mono);
  color: rgba(34,59,195,.86);
}

/* tool content sits inside .sw/.wrap; neutralise legacy wrappers */
.page-wrap, .page { max-width: none; padding: 0; margin: 0; }
.cta-section, .cta-block { display: none; }   /* v3 prefooter carries the CTA */

/* ================= icons: inline Lucide (tools render them via ico()) ===== */
svg.li { width: 1.1em; height: 1.1em; vertical-align: -.18em; flex: none;
         fill: none; stroke: currentColor; stroke-width: 2;
         stroke-linecap: round; stroke-linejoin: round; }
main .crop-icon svg.li { width: 28px; height: 28px; }
main .nut-info-icon { color: var(--blue); display: inline-flex; }

/* ================= contrast: text never sits on a status colour as white === */
/* status surfaces (q1–q4, lime) carry navy text — white measured 1.2–2.3:1 */
main :is(.ph-zone-badge, .nut-status, .crop-status-pill, .fix-action-badge,
         .diag-pill, .zone-badge, .badge, .pill) { color: var(--navy) !important; }
/* categorical tints are for swatches and tracks, not for words */
main :is(.slider-row__label, .liming-label, .num-field__unit, .num-field__label,
         .section-number, .texture-total__label, .texture-total__unit, .unit) { color: var(--blue) !important; }
main a.chief-link { color: var(--blue); text-decoration-color: currentColor; }
main .btn-fetch { color: var(--ivory); }

/* crop-suitability results sheet lives outside <main> */
.bottom-sheet { border-radius: 0 !important; border-top: 3px solid var(--blue) !important; box-shadow: none !important; }
.bottom-sheet .sheet-handle { border-radius: 0; background: rgba(34,59,195,.3); }

/* ================= status = swatch, words = navy ==========================
   Quarter-ramp colours measure 1.1–2.5:1 as text on white/ivory, so results
   carry status as a swatch (--st) or tint and keep every word navy. */
[data-st] { color: var(--navy) !important; }
.result-rating[data-st] { padding-left: 14px; box-shadow: inset 6px 0 0 var(--st); }
.suggestion-item__rating[data-st]::before,
:is(.param--ok, .param--low, .param--high, .param--warn)::before {
  content: ""; display: inline-block; width: .7em; height: .7em; margin-right: .45em;
  vertical-align: -.05em; background: var(--st); border: 1px solid rgba(11,26,110,.35);
}
.param--ok   { --st: var(--q4); }
.param--low, .param--high { --st: var(--q1); }
.param--warn { --st: var(--q2); }
:is(.param--ok, .param--low, .param--high, .param--warn) { color: var(--navy) !important; }

/* crop-mix-planner: ranks, eyebrows, evidence tags, warnings */
main :is(.rank, .eyebrow.dark, .warnings h3, .evidence.model_suggested) { color: var(--navy) !important; }
main .rank { display: inline-block; background: var(--lime); padding: 3px 8px; }

/* ph-lens: projections + modal score read navy; bars/badges keep the status colour */
main :is(.proj-badge, .proj-badge strong, .fi-acid, .fi-acid strong) { color: var(--navy) !important; }
.modal-score-val { color: var(--navy) !important; }

/* site.css .metric (marketing stat cell, min-height 300px) collides with the
   crop-mix-planner metric tiles */
main .metric-grid .metric { min-height: 0; }

/* ph-lens nutrient symbol tiles: brand tint, not peach */
main :is(.nut-symbol, .modal-symbol-big) { background: var(--b5); color: var(--blue); }

/* keyline panels need inner padding (crop-suitability sections had 0 inline) */
main .form-section { padding-inline: clamp(14px, 3vw, 24px); }

/* ph-lens diagnosis bar: let the count pills wrap under the sentence on phones */
@media (max-width: 620px) {
  main .diagnosis-bar { flex-wrap: wrap; }
  main .diagnosis-bar .diag-text { flex: 1 1 calc(100% - 40px); }
  main .diagnosis-bar .diag-counts { flex: 1 1 100%; justify-content: flex-start; }
}

/* ================= sliders: thumb centred on the track =====================
   The offset is only exact when both sizes are explicit: track height H,
   border-box thumb T, margin-top (H - T) / 2. ph-lens drew a 28px thumb with a
   3px content-box border (34px) on a -11px offset; .slider-input (crop-
   suitability, soil-tax) had no styled track, so Chromium placed its thumb
   against the 5px input box and it rode ~4px high. */
main input[type=range]::-webkit-slider-thumb { box-sizing: border-box; }
main input[type=range]::-moz-range-thumb     { box-sizing: border-box; }

main .slider-input { height: 6px; }
main .slider-input::-webkit-slider-runnable-track { height: 6px; background: transparent; }
main .slider-input::-moz-range-track             { height: 6px; background: transparent; }
main .slider-input::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -7px; box-shadow: none; }   /* (6 - 20) / 2 */
main .slider-input::-moz-range-thumb     { width: 20px; height: 20px; box-shadow: none; }

main .ph-slider::-webkit-slider-thumb { width: 28px; height: 28px; margin-top: -11px; }   /* (6 - 28) / 2 */
main .ph-slider::-moz-range-thumb     { width: 28px; height: 28px; }

/* ================= selects: Lucide chevron-down, vertically centred =========
   site.css forces `select { background: #FFFFFF !important }` through an :is()
   list whose specificity is its strongest member (.nl-row .dr-in = 0,2,0); the
   shorthand also forces background-image:none, which erased every tool chevron.
   Two :not() lift this rule to (0,2,2). */
main select:not(.x-):not(.y-) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23223BC3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  background-size: 16px 16px !important;
  padding-right: 38px !important;
}

/* ph-lens: the visible gradient bar is a sibling (.ph-track-bg) drawn at
   top:15px, but the input's own track centre sits at 2px margin + 18px = 20px —
   so the bar (and the projection marker riding on it) move down 2px to meet
   the thumb in every engine. */
main .ph-track-bg { top: 17px; }
main .proj-marker { top: 9px; }     /* centre 9 + 11 = 20px, on the bar */
