/* components.css — Unit 17: upgrade icon cards, segmented controls. Base layout classes are
   Tailwind utilities in index.html; this file adds the checked-state fallback (:has), the
   lucide icon sizing inside chips, and the segmented control. Keep under 300 lines. */

/* --- Upgrade cards (label wraps a visually-hidden checkbox) --- */

/* Unit 73 (owner, desktop feedback #2): the icon chip + label pair is centered inside the card at
   ALL widths (justify-content:center). The checkbox is .visually-hidden (position:absolute, style.css:20-23)
   so it never participates in the flex line — only the pair.
   Unit 79 (owner, desktop feedback #1) put the chip INLINE with the first label line so the ink centred
   in the card — but that is not what the owner wants to see: the text then shares a line with the icon,
   so its later lines run back UNDER the chip (measured at 1024: "Home battery" line 2 starts 18.5px,
   "Heat-pump hot water" 50.1px and "EV charger" 32.0px LEFT of the chip's right edge — text under the icon).
   Unit 82 (owner feedback, SUPERSEDES the Unit 79 layout): the TEXT is one item and the ICON is another.
   .upgrade-pair is a flex ROW again, but this time the label is a shrink-to-content block, not a
   stretched column: flex:0 1 auto + width:auto makes its base size its max-content width, and the flex
   shrink plus min-width:0 clamp it to the space left after the chip (the owner's width:min(max-content,
   available)) — Unit 79 measured that a raw max-content label overflows the 3-column cards, so the clamp
   is load-bearing. text-align:center then centres EVERY LINE inside that label box, and the flex card
   centres the whole chip+label box in the bubble. align-items:center seats the chip at the label box's
   vertical middle (measured: the 40px circle's centre sits EXACTLY on the label box centre, Δ0.0px for
   all seven cards at 390/768/1024/1280, and it overlaps no text line). Card box, min-height, equal-row
   stretch (Unit 71) and the (i) sibling in .upgrade-wrap are untouched.
   Below 420px the chip is dropped (Unit 71) and the label stays centred. */
.upgrade-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  padding: 0.75rem;
  border: 1px solid var(--ec-slate-200);
  border-radius: 0.75rem;
  background: var(--ec-card);
  cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out,
    box-shadow 150ms ease-out;
}

.upgrade-card:hover { border-color: rgb(var(--ec-t-emerald-300)); }

/* CSS fallback + JS class toggle (app.js adds ring-2 ring-emerald-500 bg-emerald-50). */
.upgrade-card:has(input:checked) {
  border-color: var(--ec-emerald-500);
  background: var(--ec-emerald-50);
  box-shadow: 0 0 0 2px var(--ec-emerald-500);
}

.upgrade-card:has(input:focus-visible) { outline: 2px solid var(--ec-emerald-600); outline-offset: 2px; }

/* Icon chip: 40px emerald-tinted circle; lucide replaces <i data-lucide> with an svg.
   Unit 82: the chip is the FIRST ITEM of the .upgrade-pair flex row — flex:none keeps the circle at
   exactly 40px (never squeezed by a long label) and it no longer needs vertical-align or a negative
   margin: align-items on the pair places it, and the pair's column-gap is the design gap (0.75rem)
   between the chip's right edge and the label box's left edge. */
.icon-chip {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgb(var(--ec-t-emerald-100));
  color: var(--ec-emerald-700);
}

/* Unit 82: the owner's two items — chip THEN text, one row, the exact 12px gap between them.
   justify-content:center + max-width:100% keep this box shrink-to-content (chip 40 + 12 + the label's
   max-content) and never wider than the card's content box, so the flex card's justify-content:center
   centres the PAIR in the bubble. Column-gap (not margin) is the only thing between the two items, so
   no text line can ever start left of the chip's right edge. Whitespace between the two spans is not
   a flex item, so no font-size:0 trick is needed for the gap. align-items:center seats the chip on the
   label box's vertical middle — the owner's alternative (hugging the FIRST line) was measured too: the
   40px circle's centre then lands 9.5px BELOW line 1's centre (1280: "Solar PV"), i.e. it does not read
   centred on the text at all, and on wrapped labels it drifts 2.5–13.7px above the block's middle.
   Centred is symmetric: Δ0.0px circle centre vs label-box centre, all seven cards, 390/768/1024/1280. */
.upgrade-pair {
  display: flex;
  align-items: center;
  justify-content: center;
  column-gap: 0.75rem;
  max-width: 100%;
  min-width: 0;
}

.icon-chip svg { width: 20px; height: 20px; }

/* Unit 71 C (owner report: seven labels, several 3-line wraps at 390px): below 420px the 2x2
   text column is ~77px and 0.9375rem pushed "Heat-pump hot water" / "Reverse-cycle air con" to
   3 lines (cards 72 vs 94 tall). 0.8125rem lands every label on <=2 lines at 390px (measured
   in tests/layout_phone.mjs) and keeps the 2x2 rhythm; from 420px the established 0.9375rem
   returns. Colour is untouched, so AA (slate-900 on the card) is unchanged (sampled in-suite). */
.upgrade-name {
  /* Unit 73: centred label text at ALL widths. Unit 82: the label is the SECOND ITEM of the pair, a
     shrink-to-content block — flex-basis auto makes its base size its max-content width, the flex
     shrink and min-width:0 clamp that to the room left after the chip (width:min(max-content,
     available)), and text-align:center centres EVERY LINE inside that box (the owner's "text centred
     within itself"). The <=2-line wrapping measured in Unit 71 is unchanged at 390px (no chip there);
     text-align:center also stays as the computed-style contract. Colour pair untouched (AA). */
  display: block;
  flex: 0 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ec-slate-900);
  overflow-wrap: break-word;
}

@media (min-width: 420px) { .upgrade-name { font-size: 0.9375rem; } }

/* Unit 71 C (measurement, this file): 0.8125rem alone still left "Reverse-cycle air con" on 3
   lines at 390px — with the 40px chip + gap the text column is only ~74px (measured: lines=3,
   card 85 vs 72). Below 420px the card therefore drops the chip: it is purely decorative (aria-hidden
   svg, never a control), the row keeps the 2x2 grid rhythm, the 72px+ full-width tap target and the
   text contrast pair, and every one of the seven labels then lands <=2 lines at 390px (colW ~129
   measured in tests/layout_phone.mjs). From 420px the chip returns.
   Unit 85 (sweep tmp/u85_sweep*.log): 420px was NOT quite wide enough — at 420-423 the 2-col card
   leaves too little room beside the chip and "Reverse-cycle air con" still wraps to 3 lines
   (3 lines at 420/422/423, 2 lines from 424). The hide therefore extends to 423px: the 0.9375rem
   label + 2 full-width lines fit from 420 up. From 424px the chip returns (measured). */
@media (max-width: 423px) {
  .upgrade-card .icon-chip { display: none; }
}

/* Unit 85 (owner report, measurement sweep tmp/u85_sweep_coarse/_high/_edge.log): with the sticky
   results sidebar the 1fr main column squeezes the 3-col cards so the label beside the chip drops
   to ~72px — "Heat-pump hot water" AND "Reverse-cycle air con" wrap to 3 short word-intact lines
   (row 93.5px). The band starts EXACTLY at 1024 (where lg: shows the sidebar; 1022 is fine) and
   ends at 1080 (1081 measured back to <=2 lines; 1120/1280 all fit). In this band the card drops
   the chip — the same treatment as below 423px: purely decorative aria-hidden svg, the pair stays
   a flex row so the text-only label centres byte-identically to the phone, rows stay equal height,
   tap targets and the (i) button untouched. From 1081px the chip returns. */
@media (min-width: 1024px) and (max-width: 1080px) {
  .upgrade-card .icon-chip { display: none; }
}

/* --- Segmented controls (existing solar, timing) --- */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  max-width: 26rem;
  padding: 4px;
  background: var(--ec-slate-100);
  border-radius: 999px;
}

.segmented-3 { grid-template-columns: repeat(3, 1fr); max-width: 22rem; }

/* Unit 39.4: four-pill group — clean 2×2 on narrow widths, one row of 4 from 768px,
   equal widths/heights, never an orphan row of one beside a row of three. */
.segmented-4 { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 1fr; max-width: 26rem; }
@media (min-width: 768px) {
  .segmented-4 { grid-template-columns: repeat(4, 1fr); max-width: 36rem; }
}

/* Unit 60a: five-option group (reverse-cycle heating answer) — 3 over 2 narrow, one row of 5
   wide, never an orphan row of one beside a row of three (Unit 39.4 rule). */
.segmented-5 { grid-template-columns: repeat(3, 1fr); max-width: 26rem; }
@media (min-width: 768px) {
  .segmented-5 { grid-template-columns: repeat(5, 1fr); max-width: 40rem; }
}

.seg { position: relative; display: block; min-width: 0; }

.seg-input {
  position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.seg-face {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 0.5rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  color: var(--ec-slate-600);
  cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

.seg-input:not(:checked) + .seg-face:hover { color: var(--ec-slate-900); }

/* Unit 32: selected face bg 059669 -> 047857 (white-on-green 5.4:1 AA for the white label). */
.seg-input:checked + .seg-face { background: rgb(var(--ec-t-emerald-700)); color: #ffffff; }

.seg-input:focus-visible + .seg-face { outline: 2px solid var(--ec-emerald-600); outline-offset: 2px; }

/* --- Editable value pills (number input + unit suffix, synced with range sliders) --- */

.num-wrap { display: inline-flex; align-items: center; gap: 0.375rem; }

.num-pill {
  width: 5.5rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--ec-slate-300);
  border-radius: 999px;
  background: var(--ec-card);
  color: var(--ec-slate-900);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}

.num-pill::-webkit-outer-spin-button,
.num-pill::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.num-pill:focus { border-color: var(--ec-emerald-500); box-shadow: 0 0 0 2px rgb(var(--ec-t-emerald-500) / 0.3); }

.num-suffix { font-size: 12px; color: var(--ec-slate-500); white-space: nowrap; }

/* --- Unit 50: unanswered required question (both estimate buttons) ---
   Red pill at the question + red ring around it. Danger token only: light rgb(185,28,28) on card
   6.5:1, dark rgb(248,113,113) on card 6.1:1 (both >=4.5 AA); the "!" badge keeps the signal
   readable without relying on colour. Outline, not border, so nothing reflows. */

.req-missing {
  display: none;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.25rem 0.6rem;
  border: 2px solid var(--ec-danger);
  border-radius: 999px;
  background: var(--ec-card);
  color: var(--ec-danger);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.25;
}

.req-missing.req-on { display: inline-flex; }

.req-missing::before {
  content: "!";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  flex: none;
  border-radius: 999px;
  background: var(--ec-danger);
  color: var(--ec-card);
  font-size: 0.8125rem;
  font-weight: 800;
}

.req-mark { outline: 2px solid var(--ec-danger); outline-offset: 4px; border-radius: 12px; }

/* --- Unit 52: "Reset to suggestion" — a peer of "Calculate my rebates" (same size/padding/
    44px tap target, set in index.html) but a ghost/outline fill so it is not clicked by accident.
    Accent inset ring + accent text on the transparent card fill (the ring is an inset box-shadow
    so it adds no height — the button stays pixel-identical in size to Calculate); AA in both
    themes (accent 4 120 87 on white card, 52 211 153 on dark card). Hover tints emerald-50; focus
    keeps a visible ring. */

.ec-reset-btn {
  background: transparent;
  color: var(--ec-accent);
  box-shadow: inset 0 0 0 2px var(--ec-accent);
}

.ec-reset-btn:hover { background: var(--ec-emerald-50); }

.ec-reset-btn:focus-visible { outline: 2px solid var(--ec-emerald-600); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .upgrade-card, .seg-face, .ec-reset-btn { transition: none; }
}
