/* ==========================================================================
   Fuel & Stint Calculator — endurance strategy tool.

   Scoped under .fuel (inside .racedata, so it inherits the race-data colour
   variables and type). It lives in the iracing/ folder because it belongs with
   the endurance content, but unlike its neighbours it reads NO data at all —
   there is no JSON, no refresh step and nothing is sent anywhere. It's pure
   arithmetic in the browser.

   Colour use
   ----------
   Three states carry meaning and each is ALWAYS spelled out in words as well:
   good (comfortable margin), warn (close to the edge) and bad (over the line).
   These are the race-data status colours, never the categorical ones, so they
   can't be confused with a series or a class.
   ========================================================================== */

/* ---- inputs -------------------------------------------------------------- */
.fuel .inputs {
  margin: 18px 0 0; padding: 15px 16px;
  background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 14px;
}
.fuel .seg-row {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
  /* align-items defaults to STRETCH: without this the toggle pills grow to match the
     height of the mid-race box beside them and render as giant ovals, then snap back
     the moment that box wraps to its own line. */
  align-items: flex-start;
}
.fuel .seg {
  display: inline-flex; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.fuel .seg-btn {
  font: inherit; font-size: 12.5px; cursor: pointer; color: var(--muted);
  background: none; border: 0; border-radius: 999px; padding: 6px 15px;
  transition: background .12s, color .12s;
}
.fuel .seg-btn:hover { color: var(--ink); }
.fuel .seg-btn.active { background: var(--blue-br); color: #06182b; font-weight: 700; }
.fuel .seg-btn:focus-visible { outline: 2px solid var(--blue-br); outline-offset: 2px; }

/* ---- mid-race "what's left" box ----------------------------------------- */
.fuel .livebox {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 9px;
  margin-left: auto; padding: 7px 11px;
  background: rgba(56,169,232,.06); border: 1px solid rgba(56,169,232,.30);
  border-radius: 12px;
  /* Pinned width. The result message is a full-width flex line, and without a cap its
     text widens the whole box (461px -> 896px), which re-wraps the row under the user
     the instant they press the button. */
  width: 470px; max-width: 100%;
}
@media (max-width: 1100px) { .fuel .livebox { margin-left: 0; width: 100%; } }
.fuel .mini { display: flex; flex-direction: column; gap: 3px; }
.fuel .mini-l { font-size: 9.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.fuel .mini input, .fuel .mini-pair {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px; font-variant-numeric: tabular-nums;
}
.fuel .mini-pair { display: flex; align-items: center; gap: 4px; padding: 2px 8px; }
.fuel .mini-pair input {
  font: inherit; font-size: 13px; color: var(--ink); background: none; border: 0;
  width: 2.6em; padding: 5px 2px; font-variant-numeric: tabular-nums;
}
.fuel .mini input:focus, .fuel .mini-pair:focus-within { outline: none; border-color: var(--blue-br); }
.fuel .mini-pair input:focus { outline: none; }
.fuel .calc-btn {
  font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  color: #06182b; background: var(--blue-br); border: 1px solid var(--blue-br);
  border-radius: 999px; padding: 8px 15px; white-space: nowrap;
  min-width: 152px; text-align: center;   /* label swaps to "Live - stop"; keep one width */
}
.fuel .calc-btn:hover { filter: brightness(1.08); }
.fuel .calc-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.fuel .calc-btn.live { background: var(--good); border-color: var(--good); }
.fuel .livebox .src { flex-basis: 100%; margin-top: 1px; min-height: 1.35em; line-height: 1.35; }

.fuel .grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.fuel .fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
/* `display:flex` above out-specifies the browser's own [hidden] rule, so the hidden
   race-length field would otherwise stay on screen next to the visible one. */
.fuel .fld[hidden] { display: none; }
.fuel .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted); }
.fuel .lbl .hint { text-transform: none; letter-spacing: 0; color: #64789a; font-size: 10.5px; }
.fuel .fld.opt .lbl { color: #7d90ad; }
.fuel .fld.wide2 { grid-column: span 2; }
@media (max-width: 640px) { .fuel .fld.wide2 { grid-column: auto; } }

/* Where a number came from. An estimate must never look like a measured fact, so the
   source is spelled out under the field and colour only reinforces the words. */
.fuel .src { font-size: 10.5px; line-height: 1.35; color: var(--muted); min-height: 1em; }
.fuel .src.verified { color: var(--good); }
.fuel .src.estimate { color: var(--amber); }
.fuel .src.spec { color: var(--blue-br); }
.fuel .src.mine { color: var(--ink-2); }
.fuel .pair {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px 11px 3px 3px;
}
.fuel .pair:focus-within { border-color: var(--blue-br); }
.fuel .pair input {
  font: inherit; font-size: 16px; color: var(--ink); background: none; border: 0;
  padding: 9px 10px; width: 100%; min-width: 0; font-variant-numeric: tabular-nums;
}
.fuel .pair input:focus { outline: none; }
.fuel .pair input::placeholder { color: #55688a; }
.fuel .pair .suf { color: var(--muted); font-size: 12px; white-space: nowrap; }
/* two numbers in one field (hours + minutes) */
.fuel #wrap-time .pair input { width: 4.5em; }

.fuel .err {
  margin: 14px 0 0; padding: 11px 14px; border-radius: 10px;
  background: rgba(242,102,111,.10); border: 1px solid rgba(242,102,111,.45);
  color: var(--bad); font-size: 13.5px;
}

/* ---- results ------------------------------------------------------------- */
.fuel .tiles { grid-template-columns: repeat(4, 1fr); margin-top: 20px; }
@media (max-width: 820px) { .fuel .tiles { grid-template-columns: repeat(2, 1fr); } }

.fuel .sec-h {
  font-family: "Racing Sans One", sans-serif; font-size: 17px; color: var(--ink);
  margin: 26px 0 11px; letter-spacing: .3px;
}

/* the three gauges: save a stop / where you are / lose a stop */
.fuel .gauges { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 820px) { .fuel .gauges { grid-template-columns: 1fr; } }
.fuel .gauge {
  background: linear-gradient(150deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 13px; padding: 14px 16px;
  position: relative; overflow: hidden;
}
.fuel .gauge::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--line); }
.fuel #g-save::before { background: var(--good); }
.fuel #g-cost::before { background: var(--bad); }
.fuel #g-now::before { background: var(--blue); }
.fuel #g-now.warn::before { background: var(--amber); }
.fuel #g-now.tight::before { background: var(--bad); }
.fuel .g-k { font-size: 11px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted); }
.fuel .g-v { font-size: 25px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.fuel #g-save .g-v { color: var(--good); }
.fuel #g-cost .g-v { color: var(--bad); }
.fuel .g-t { font-size: 12px; color: var(--ink-2); margin-top: 5px; line-height: 1.45; }

.fuel .band-note {
  margin: 12px 0 0; font-size: 13px; color: var(--ink-2);
  border-left: 3px solid var(--blue); background: rgba(0,122,194,.08);
  padding: 10px 13px; border-radius: 0 9px 9px 0;
}
.fuel .band-note strong { color: var(--ink); }

/* the row for the plan you're actually on */
.fuel tr.is-now td { background: rgba(56,169,232,.10); }
.fuel tr.is-now td:first-child { box-shadow: inset 3px 0 0 var(--blue-br); }
.fuel td .tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .9px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; margin-left: 7px;
  color: #06182b; background: var(--blue-br);
}
.fuel td .good { color: var(--good); }
.fuel td .bad { color: var(--bad); }
.fuel td .muted { color: var(--muted); }

/* ---- the detail list ----------------------------------------------------- */
.fuel .facts { display: grid; gap: 9px; grid-template-columns: repeat(2, 1fr); }
@media (max-width: 820px) { .fuel .facts { grid-template-columns: 1fr; } }
/* `min-width: 0` matters: grid and flex children default to min-width:auto, so a long
   value (a 24-stop fuel list) refuses to shrink, blows the row past the page edge and
   shoves the OTHER rows' values off-screen with it. */
.fuel .fact {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 14px; flex-wrap: wrap; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 14px;
}
.fuel .fact .fk { color: var(--ink-2); font-size: 13px; min-width: 0; }
.fuel .fact .fv {
  font-family: "Racing Sans One", sans-serif; font-size: 15px; color: var(--ink);
  font-variant-numeric: tabular-nums; text-align: right;
  min-width: 0; overflow-wrap: anywhere;    /* wrap rather than overflow */
}
.fuel .fact.wide { grid-column: 1 / -1; }
.fuel .fact .fv.good { color: var(--good); }
.fuel .fact .fv.bad { color: var(--bad); }
.fuel .fact .fv.amber { color: var(--amber); }

/* The actual clock time to be in the pits, shown once "Calculate time left" has
   anchored the plan to now. Mid-race, "be in the pits at 21:47" is actionable in a
   way that "3:08:36 into the race" is not. */
.fuel .clock {
  display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--blue-br); background: rgba(56,169,232,.12);
  border: 1px solid rgba(56,169,232,.35);
}

/* The mid-race box reports what it just did — that message has to be readable, not
   the 10px grey used for field footnotes, or a failure looks like nothing happening. */
.fuel .livebox .src { font-size: 12px; font-weight: 600; }

/* ---- scenario picking ---------------------------------------------------- */
/* Rows in "what each stop count needs" are clickable: pick one and the stint plan
   below shows THAT scenario, worked at the burn it requires. */
.fuel tr.pickable { cursor: pointer; }
.fuel tr.pickable:hover td { background: rgba(56,169,232,.08); }
.fuel tr.pickable:focus-visible { outline: 2px solid var(--blue-br); outline-offset: -2px; }
.fuel tr.is-preview td { background: rgba(245,181,61,.10); }
.fuel tr.is-preview td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.fuel td .tag.pv { background: var(--amber); }

.fuel .plan-note {
  margin: 0 0 11px; font-size: 13px; color: var(--ink-2);
  border-left: 3px solid var(--amber); background: rgba(245,181,61,.08);
  padding: 9px 13px; border-radius: 0 9px 9px 0;
}
.fuel .plan-note strong { color: var(--ink); }
.fuel .linkish {
  font: inherit; font-size: 13px; color: var(--blue-br); background: none;
  border: 0; padding: 0; cursor: pointer; text-decoration: underline;
}

/* "Starts at" only appears once a race start time (or Start stint) gives the plan a
   wall-clock anchor — an all-dashes column is just noise. */
.fuel #tbl-stints .col-start { display: none; }
.fuel #tbl-stints.has-clock .col-start { display: table-cell; }
