/* ==========================================================================
   JuiceMyEV — Charging calculator
   ========================================================================== */

.calc {
  display: grid;
  gap: var(--sp-6);
  align-items: start;
}

@media (min-width: 980px) {
  .calc { grid-template-columns: 360px 1fr; gap: var(--sp-7); }
  .calc__controls { position: sticky; top: calc(var(--header-h) + var(--sp-5)); }
}

/* ---- Controls ------------------------------------------------------- */

/* Flex + gap rather than adjacent-sibling margins: #custom-fields sits between
   two .field elements and is usually hidden, which silently broke
   `.field + .field` and collapsed the spacing. A display:none child
   contributes no gap, so this stays correct whether it's shown or not. */
.calc__controls {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

#custom-fields {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

#custom-fields[hidden] { display: none; }

.field__label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  margin-bottom: var(--sp-2);
}

.field__hint {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: var(--sp-2);
  line-height: var(--lh-snug);
}

.select,
.input {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.select:hover, .input:hover { border-color: var(--text-muted); }

.select:focus, .input:focus {
  outline: none;
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 22%, transparent);
}

/* Segmented control — supply choice */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}

.segmented__opt { position: relative; }

.segmented__opt input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.segmented__opt span {
  display: block;
  padding: var(--sp-3);
  text-align: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}

.segmented__opt input:hover + span { border-color: var(--text-muted); }

.segmented__opt input:focus-visible + span {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

.segmented__opt input:checked + span {
  border-color: var(--brand-ink);
  background: var(--brand-ink);
  color: var(--text-on-dark);
}

/* Range slider */
.range-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}

.range-val {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  color: var(--series-1);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--brand-ink);
  cursor: pointer;
}

/* ---- Results -------------------------------------------------------- */

.calc__results { min-width: 0; }

/* Headline answer */
.answer {
  background: var(--brand-ink);
  color: var(--text-on-dark);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  position: relative;
  overflow: hidden;
  margin-bottom: var(--sp-5);
}

.answer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(30rem 16rem at 88% 0%, rgba(200, 240, 45, 0.16), transparent 65%);
  pointer-events: none;
}

.answer > * { position: relative; }

.answer__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: var(--sp-3);
}

.answer__hero {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.answer__kw {
  font-size: clamp(3rem, 9vw, 4.5rem);
  font-weight: var(--fw-bold);
  letter-spacing: -0.045em;
  line-height: 0.9;
  color: var(--brand-lime);
  font-variant-numeric: tabular-nums;
}

.answer__unit {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semi);
  color: rgba(255, 255, 255, 0.7);
}

.answer__verdict {
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
  color: var(--text-on-dark-2);
  max-width: 52ch;
}

.answer__verdict strong { color: #fff; font-weight: var(--fw-semi); }

/* Result stat row */
.result-row {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  margin-bottom: var(--sp-5);
}

.result-tile {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.result-tile__label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
  line-height: var(--lh-snug);
}

.result-tile__value {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* Tiles sit on a light surface — they need their own unit style.
   Reusing .answer__unit here rendered white-on-white and the unit vanished. */
.result-tile__unit {
  font-size: var(--fs-base);
  font-weight: var(--fw-semi);
  letter-spacing: 0;
  margin-left: 2px;
  color: var(--text-secondary);
}

.result-tile__sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: var(--sp-2);
}

/* ---- Comparison chart ----------------------------------------------- */

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
}

.chart-card__head { margin-bottom: var(--sp-5); }

.chart-card__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
  letter-spacing: -0.01em;
  margin-bottom: var(--sp-1);
}

.chart-card__sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* Bar rows */
.bar-row { position: relative; }
.bar-row + .bar-row { margin-top: var(--sp-5); }

.bar-row__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}

.bar-row__name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

/* Carries series identity beside the label, so the text itself can stay in
   ink tokens rather than a sub-3:1 series colour. */
.bar-row__swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.bar-row__value {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--text-primary);
}

.bar-row__track {
  position: relative;
  height: 26px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.bar-row__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: var(--r-sm);
  transition: width 380ms var(--ease), background 200ms var(--ease);
}

/* The capacity the car can't use — hatched, not solid, so it reads as
   "absent" rather than as a second real series. */
.bar-row__wasted {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background-image: repeating-linear-gradient(
    135deg,
    var(--c-wasted) 0 3px,
    transparent 3px 7px
  );
  border: 1px dashed var(--c-wasted);
  border-left: 0;
  transition: left 380ms var(--ease), width 380ms var(--ease);
}

.bar-row__note {
  margin-top: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.bar-row--current .bar-row__name { font-weight: var(--fw-bold); }

.bar-row--current .bar-row__track {
  box-shadow: 0 0 0 2px var(--brand-ink);
}

/* Chart legend */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line-hairline);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.chart-legend__key {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}

.chart-legend__swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-legend__swatch--hatch {
  background-image: repeating-linear-gradient(
    135deg,
    var(--c-wasted) 0 2px,
    transparent 2px 5px
  );
  border: 1px dashed var(--c-wasted);
}

/* ---- Verdict callouts ------------------------------------------------ */

.verdict {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  border-left: 3px solid;
}

.verdict + .verdict { margin-top: var(--sp-3); }
.verdict__icon { flex-shrink: 0; margin-top: 2px; }
.verdict__title { font-weight: var(--fw-semi); margin-bottom: 2px; }
.verdict__body { color: var(--text-secondary); }

.verdict--good {
  border-left-color: var(--status-good);
  background: color-mix(in srgb, var(--status-good) 8%, var(--surface-1));
}
.verdict--good .verdict__icon { color: var(--status-good-text); }

.verdict--warning {
  border-left-color: var(--status-warning);
  background: color-mix(in srgb, var(--status-warning) 12%, var(--surface-1));
}
.verdict--warning .verdict__icon { color: #8a5d00; }
:root[data-theme="dark"] .verdict--warning .verdict__icon { color: var(--status-warning); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .verdict--warning .verdict__icon { color: var(--status-warning); }
}

.verdict--critical {
  border-left-color: var(--status-critical);
  background: color-mix(in srgb, var(--status-critical) 8%, var(--surface-1));
}
.verdict--critical .verdict__icon { color: var(--status-critical); }

/* ---- Working / maths panel ------------------------------------------ */

.working {
  border: 1px solid var(--line-hairline);
  border-radius: var(--r-md);
  background: var(--surface-2);
  overflow: hidden;
}

.working > summary {
  padding: var(--sp-4);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.working > summary::-webkit-details-marker { display: none; }

.working > summary::before {
  content: "";
  width: 7px; height: 7px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform var(--dur) var(--ease);
  flex-shrink: 0;
  margin-right: 2px;
}

.working[open] > summary::before { transform: rotate(45deg); }
.working > summary:hover { background: var(--surface-1); }

.working__body {
  padding: 0 var(--sp-4) var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.working__body > * + * { margin-top: var(--sp-3); }

.working__calc {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  background: var(--surface-1);
  border: 1px solid var(--line-hairline);
  border-radius: var(--r-sm);
  padding: var(--sp-3);
  overflow-x: auto;
  white-space: pre;
  color: var(--text-primary);
}

/* ---- Solar minimum-start figure -------------------------------------- */

.solar-figure {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-block: var(--sp-6);
}

.solar-figure__cap {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-5);
}

.sfig__row + .sfig__row { margin-top: var(--sp-5); }

.sfig__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}

.sfig__name {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.sfig__swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.sfig__kw {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.sfig__track {
  position: relative;
  height: 24px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.sfig__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: var(--r-sm);
}

.sfig__note {
  margin-top: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.sfig__footnote {
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line-hairline);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  line-height: var(--lh-snug);
}

/* ---- Table view toggle ---------------------------------------------- */

.table-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  background: none;
  border: 0;
  padding: 0;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--series-1);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.calc-table-wrap { margin-top: var(--sp-4); }
.calc-table-wrap[hidden] { display: none; }
