/* Fuel Manager — app design system (dashboard redesign).
 * Ported from fuel-manager-compact-v4.html. Loaded AFTER Bootstrap; the tokens
 * + shell chrome + Overview components below take over, other screens keep the
 * Bootstrap look until reworked incrementally.
 *
 * Dark palette (Track E): system-preference by default
 * (`prefers-color-scheme`), with a `[data-theme]` attribute on `<html>` as a
 * manual override hook for a future toggle — same shape as any other
 * light/dark web app, no toggle UI exists yet. `index.html` mirrors the
 * resolved theme onto `data-bs-theme` so Bootstrap's own dark-mode CSS
 * (5.3+) covers the screens still wearing the plain Bootstrap look. First
 * pass — values aren't browser-verified for contrast, same caveat as every
 * other design pass in this repo ("Browser QA" in TODO.md). */

:root {
  color-scheme: light;
  --ink: #1a1d1f;
  --ink-soft: #6b7075;
  --line: #e4e6e8;
  --line-hover: #d7dade;
  --surface: #ffffff;
  --bg: #f6f7f8;
  --accent: #c4491d;
  --accent-hover: #a13a17;
  --accent-soft: #fdeee7;
  --good: #2f7a4f;
  --good-soft: #eaf5ee;
  --bad: #b3311c;
  --bad-soft: #fbeae7;
  --bad-border: #f3c9c0;
  --info: #3b6ea5;
  --info-soft: #e8f0f8;

  /* Bridge a few Bootstrap vars so shared components blend in */
  --bs-primary: var(--accent);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-hover);
  --bs-border-color: var(--line);
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #e9e9ea;
    --ink-soft: #9a9fa4;
    --line: #34383c;
    --line-hover: #40454a;
    --surface: #1c1e21;
    --bg: #131416;
    --accent: #e2703c;
    --accent-hover: #f08a5c;
    --accent-soft: #3a2415;
    --good: #4caf7d;
    --good-soft: #17301f;
    --bad: #e2604a;
    --bad-soft: #331915;
    --bad-border: #5c332b;
    --info: #6fa3d6;
    --info-soft: #16232f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e9e9ea;
  --ink-soft: #9a9fa4;
  --line: #34383c;
  --line-hover: #40454a;
  --surface: #1c1e21;
  --bg: #131416;
  --accent: #e2703c;
  --accent-hover: #f08a5c;
  --accent-soft: #3a2415;
  --good: #4caf7d;
  --good-soft: #17301f;
  --bad: #e2604a;
  --bad-soft: #331915;
  --bad-border: #5c332b;
  --info: #6fa3d6;
  --info-soft: #16232f;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

.btn-primary,
.btn-primary:hover,
.btn-primary:focus {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-hover);
  --bs-btn-hover-border-color: var(--accent-hover);
  --bs-btn-active-bg: var(--accent-hover);
}
a {
  color: var(--accent);
}

/* Content column for the reworked (mobile-first) screens (design system §3) */
.screen-narrow {
  max-width: 430px;
  margin: 0 auto;
}

/* Login screen (Track E) — a single .form-card, no bespoke component. */
.login-wrap {
  margin-top: 2rem;
}
.login-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 0.9rem;
}

/* --- Shell -------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
}
.btn-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  background: none;
  text-decoration: none;
  cursor: pointer;
}
.btn-logout svg {
  display: block;
}
#nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.veh-select {
  font-size: 0.8rem;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.25rem 1.5rem 0.25rem 0.6rem;
  border-radius: 6px;
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23888' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E")
    no-repeat right 0.55rem center;
  -webkit-appearance: none;
  appearance: none;
  max-width: 48vw;
  text-overflow: ellipsis;
}

.subhead {
  padding: 0.7rem 0 0.3rem;
}
.odo-readout {
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin-bottom: 0.3rem;
}
.odo-readout b {
  color: var(--ink);
  font-weight: 700;
}

.tabbar {
  display: flex;
  gap: 1.1rem;
  overflow-x: auto;
  padding: 0 0 0.55rem;
  border-bottom: 1px solid var(--line);
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar {
  display: none;
}
.tabbar .tab {
  font-size: 0.88rem;
  color: var(--ink-soft);
  white-space: nowrap;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid transparent;
  text-decoration: none;
}
.tabbar .tab.active {
  color: var(--ink);
  font-weight: 600;
  border-color: var(--accent);
}

/* --- Quick actions --------------------------------------------- */
.quick-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0.85rem 0 0;
}
.qa-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 0.5rem;
  border-radius: 9px;
  border: none;
  cursor: pointer;
}
.qa-btn.primary {
  background: var(--accent);
  color: #fff;
}
.qa-btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

/* --- Time filter --------------------------------------------- */
.filter-row {
  margin: 0.75rem 0 0;
}
.filter-label {
  font-size: 0.68rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}
.segmented {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 2px;
}
.segmented button {
  flex: 1;
  border: none;
  background: none;
  font-size: 0.76rem;
  color: var(--ink-soft);
  padding: 0.4rem 0.3rem;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 500;
}
.segmented button.active {
  background: var(--ink);
  color: #fff;
  font-weight: 600;
}

/* --- Stat grid --------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin: 0.75rem 0 0;
}
.stat {
  background: var(--surface);
  padding: 0.75rem 0.85rem;
}
.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.15rem;
}
.stat .label {
  font-size: 0.68rem;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}
.stat .value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
}
.stat .value .unit {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-left: 0.15rem;
}
.stat .sub {
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-top: 0.3rem;
  line-height: 1.35;
}
.stat .sub b {
  color: var(--ink);
  font-weight: 600;
}
.data-quality {
  margin: 0.5rem 0 0;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--bad);
  background: var(--bad-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
}
.data-quality a {
  color: var(--bad);
  font-weight: 600;
}
.delta-badge {
  font-size: 0.63rem;
  font-weight: 700;
  padding: 0.08rem 0.38rem;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  white-space: nowrap;
}
.delta-badge.good {
  color: var(--good);
  background: var(--good-soft);
}
.delta-badge.bad {
  color: var(--bad);
  background: var(--bad-soft);
}

/* --- Tank card + range estimate --------------------------- */
.tank-card {
  margin: 0.6rem 0 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}
.tank-top {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.tank-top .head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.tank-top .label {
  font-size: 0.68rem;
  color: var(--ink-soft);
}
.tank-top .value {
  font-size: 1.1rem;
  font-weight: 700;
}
.tank-top .value .u {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink-soft);
}
.tank-bar-wrap {
  position: relative;
  padding-bottom: 0.95rem;
}
.tank-bar-track {
  width: 100%;
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  position: relative;
}
.tank-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
}
.tank-tick {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 10px;
  background: var(--ink);
}
.tank-tick .tick-label {
  position: absolute;
  top: 13px;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}
.tank-tick.worst .tick-label {
  right: 4px;
  text-align: right;
  color: var(--bad);
}
.tank-tick.best .tick-label {
  left: 4px;
  text-align: left;
  color: var(--good);
}
.tank-top .pct {
  font-size: 0.7rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
/* Low-fuel warning (Track E polish item — no separate design, reuses §4.15's
 * bad/flag semantics, which the color-token comment already scopes to
 * "warnings" generically). Needs the extra specificity to beat .tank-top .pct
 * above. */
.tank-top .pct.flag {
  color: var(--bad);
}
.tank-split {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.tank-split .col {
  flex: 1;
  min-width: 0;
}
.tank-split .divider {
  width: 1px;
  align-self: stretch;
  background: var(--line);
}
.est-col .label {
  font-size: 0.68rem;
  color: var(--ink-soft);
  margin-bottom: 0.15rem;
}
.est-col .figures {
  font-size: 1.1rem;
  font-weight: 700;
}
.est-col .figures .sep {
  color: var(--ink-soft);
  font-weight: 500;
  margin: 0 0.25rem;
}
.est-col .note {
  font-size: 0.63rem;
  color: var(--ink-soft);
  margin-top: 0.15rem;
  line-height: 1.3;
}
.range-estimate {
  display: flex;
  justify-content: space-between;
  margin-top: 0.6rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}
.range-estimate .cell {
  text-align: center;
  flex: 1;
}
.range-estimate .cell .n {
  font-size: 0.9rem;
  font-weight: 700;
}
.range-estimate .cell .l {
  font-size: 0.63rem;
  color: var(--ink-soft);
  margin-top: 0.1rem;
}
.range-estimate .cell.mid .n {
  color: var(--accent);
}
.range-bar {
  height: 5px;
  border-radius: 99px;
  margin: 0.5rem 0 0.1rem;
  background: linear-gradient(
    to right,
    var(--bad) 0%,
    var(--accent) 50%,
    var(--good) 100%
  );
  position: relative;
}
.range-bar .marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 11px;
  background: var(--ink);
}
.tank-range-caption {
  font-size: 0.63rem;
  color: var(--ink-soft);
  margin-top: 0.25rem;
  line-height: 1.3;
}
.fill-range {
  font-size: 0.63rem;
  color: var(--ink-soft);
  margin-top: 0.3rem;
  line-height: 1.4;
}
.fill-range .w {
  color: var(--bad);
  font-weight: 600;
}
.fill-range .b {
  color: var(--good);
  font-weight: 600;
}

/* --- Recent refuels ------------------------------------- */
.refuel-card {
  margin: 0.6rem 0 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.refuel-card .heading {
  font-size: 0.68rem;
  color: var(--ink-soft);
  padding: 0.6rem 0.85rem 0.35rem;
}
.refuel-card .empty {
  font-size: 0.78rem;
  color: var(--ink-soft);
  padding: 0.4rem 0.85rem 0.8rem;
}
.refuel-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  border-top: 1px solid var(--line);
  cursor: pointer;
  width: 100%;
  background: none;
  border-left: none;
  border-right: none;
  border-bottom: none;
  text-align: left;
  font: inherit;
}
.refuel-item:active {
  background: var(--bg);
}
.refuel-item .left {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  overflow: hidden;
  font-size: 0.72rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.refuel-item .left .date {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink);
}
.refuel-item .right {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  white-space: nowrap;
}
.refuel-item .right .kml {
  font-size: 0.78rem;
  font-weight: 700;
}
.refuel-item .right .delta {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.03rem 0.35rem;
  border-radius: 99px;
}
.delta.up {
  color: var(--good);
  background: var(--good-soft);
}
.delta.down {
  color: var(--bad);
  background: var(--bad-soft);
}

.quicklinks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.9rem 0 0;
}
.quicklinks a {
  font-size: 0.78rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 0.32rem 0.75rem;
  text-decoration: none;
}

/* Charts tab */
.charts-panel {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
  max-width: 900px;
}
@media (min-width: 720px) {
  .charts-panel {
    grid-template-columns: 1fr 1fr;
  }
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem 0.85rem;
}
.chart-card .t {
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}
.chart-box {
  width: 100%;
  height: 260px;
}
.chart-card.wide {
  grid-column: 1 / -1;
}
.chart-card .hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.chart-card .hd .t {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-card .hd select {
  font-size: 0.72rem;
  padding: 0.28rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
}
.chart-btn {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
}
.chart-btn:hover {
  color: var(--ink);
  border-color: var(--ink-soft);
}

/* Maximized chart modal */
.chart-modal {
  position: fixed;
  inset: 4vh 4vw;
  z-index: 1091;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}
.chart-modal .hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.chart-modal .t {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}
.chart-modal-box {
  flex: 1;
  min-height: 0;
}
@media (min-width: 720px) {
  .chart-modal {
    inset: 6vh 8vw;
  }
}

/* --- Bottom sheet -------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1090;
}
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  z-index: 1091;
  padding: 0.9rem 1rem 1.2rem;
  max-height: 88vh;
  overflow-y: auto;
}
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 99px;
  margin: 0 auto 0.8rem;
}
.sheet h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 0.8rem;
}
.sheet .field,
.form-card .field {
  margin-bottom: 0.7rem;
}
.sheet label,
.form-card label {
  font-size: 0.78rem;
  color: var(--ink-soft);
  display: block;
  margin-bottom: 0.3rem;
}
.sheet input,
.sheet select,
.form-card input,
.form-card select,
.form-card textarea {
  width: 100%;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
}
.form-card textarea {
  resize: vertical;
}
.sheet input.locked,
.form-card input.locked {
  background: var(--line);
  color: var(--ink-soft);
}
.sheet .hint,
.form-card .hint {
  font-size: 0.68rem;
  color: var(--ink-soft);
  margin-top: 0.3rem;
}
/* Non-modal counterpart to the sheet — a permanent-on-page form surface
 * (Maintenance's inline "Log a service" + the standalone component form).
 * Shares field/label/input/hint styling with .sheet via the selectors above. */
.form-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  margin: 0.6rem 0;
}
.form-card h2,
.form-card h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 0 0 0.6rem;
}
.form-card + .form-card {
  margin-top: 0.6rem;
}

/* Restyle Bootstrap nav-pills as a form's section switcher (Vehicle form) —
 * same restyle-in-place approach as bootstrap-table on Records desktop. */
.veh-tabs .nav-link {
  color: var(--ink-soft);
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
}
.veh-tabs .nav-link.active {
  background: var(--accent);
  color: #fff;
}
.sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.7rem;
}
.sheet-grid > * {
  min-width: 0; /* let the columns shrink instead of overflowing */
}
/* Track E polish item: below 360px the two-column grid leaves each field too
 * narrow to type into comfortably (e.g. a 320px iPhone SE) — collapse to one
 * column. Shared by the record sheet + both maintenance forms. */
@media (max-width: 359px) {
  .sheet-grid {
    grid-template-columns: 1fr;
  }
}
/* Refuel sheet: fields are in focus order in the source (Odometer → Total
 * cost → Volume → Fuel type → Price), placed back into the visual columns
 * Date/Odometer/Fuel type | Price/Total/Volume. One column: source order. */
.refuel-grid .f-date   { grid-column: 1; grid-row: 1; }
.refuel-grid .f-odo    { grid-column: 1; grid-row: 2; }
.refuel-grid .f-fuel   { grid-column: 1; grid-row: 3; }
.refuel-grid .f-price  { grid-column: 2; grid-row: 1; }
.refuel-grid .f-total  { grid-column: 2; grid-row: 2; }
.refuel-grid .f-volume { grid-column: 2; grid-row: 3; }
@media (max-width: 359px) {
  .refuel-grid > .field {
    grid-column: auto;
    grid-row: auto;
  }
}
.sheet input,
.sheet select {
  box-sizing: border-box;
  max-width: 100%;
}
/* iOS Safari sizes date inputs by their intrinsic content and overflows the
   grid track otherwise. */
.sheet input[type="date"],
.form-card input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.2rem;
}
.chip {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  user-select: none;
}
.chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.sheet-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}
.sheet-actions button,
.sheet-actions a {
  flex: 1;
  padding: 0.65rem;
  border-radius: 9px;
  border: none;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sheet-actions .cancel {
  background: var(--bg);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.sheet-actions .save {
  background: var(--accent);
  color: #fff;
}
.sheet-actions .save:disabled {
  opacity: 0.6;
}
/* Edit-mode only: text-only destructive action below the footer (§4.10) */
.sheet .delete-link {
  display: block;
  width: 100%;
  margin-top: 0.65rem;
  padding: 0.4rem;
  background: none;
  border: none;
  color: var(--bad);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

/* ============================================================
   Wide-screen Overview — two-column dashboard (min-width: 861px)

   Same markup as mobile. The .ov-toolbar / .ov-main / .ov-side
   wrappers (overview.js) are `display: contents` below the
   breakpoint, so they add nothing to the mobile layout — it stays
   the flat single column it has always been. Everything that turns
   them into real boxes lives inside the media query only.
   ============================================================ */
.ov-toolbar,
.ov-main,
.ov-side {
  display: contents;
}

/* Vehicle-name heading: switcher-only on mobile, heading at the wide
   breakpoint (design system §2 / §7). */
.vehicle-name {
  display: none;
}

@media (min-width: 861px) {
  .vehicle-name {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0.5rem 0 0.35rem;
  }

  /* Bootstrap caps #view (.container) at 720/960px in this range —
     widen it, but only when it's holding the Overview dashboard. */
  #view:has(> .ov-dash) {
    max-width: 1180px;
  }

  .ov-dash {
    max-width: 1120px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    column-gap: 1.5rem;
    row-gap: 1rem;
    align-items: start;
  }

  /* Name heading + tabs + odometer readout (above) and the "more stats"
     strip (below) span the full width across both columns */
  .ov-dash > .vehicle-name,
  .ov-dash > .subhead,
  .ov-dash > .tabbar,
  .ov-dash > .ov-detail {
    grid-column: 1 / -1;
  }

  /* Toolbar: quick actions on the left, time filter pushed right */
  .ov-toolbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 1rem;
  }
  .ov-toolbar .quick-actions {
    margin: 0;
    flex: 0 0 auto;
  }
  .ov-toolbar .qa-btn {
    flex: 0 0 auto;
    font-size: 0.9rem;
    padding: 0.6rem 1.15rem;
  }
  .ov-toolbar .filter-row {
    margin: 0 0 0 auto;
  }
  .ov-toolbar .filter-label {
    display: none;
  }
  .ov-toolbar .segmented button {
    font-size: 0.8rem;
    padding: 0.45rem 0.85rem;
  }

  /* The two columns */
  .ov-main {
    grid-column: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  .ov-side {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  /* mobile stacking margins → 0; flex `gap` now does the spacing */
  .ov-main > *,
  .ov-side > * {
    margin: 0;
  }

  /* Stat + tank cards: larger type / padding for mouse-at-a-distance */
  .ov-main .stat {
    padding: 1.15rem 1.35rem;
  }
  .ov-main .stat .label,
  .ov-main .tank-top .label,
  .ov-main .est-col .label {
    font-size: 0.74rem;
  }
  .ov-main .stat .value {
    font-size: 1.95rem;
  }
  .ov-main .stat .value .unit {
    font-size: 0.9rem;
  }
  .ov-main .stat .sub {
    font-size: 0.8rem;
    margin-top: 0.5rem;
  }
  .ov-main .tank-card {
    padding: 1.15rem 1.35rem;
  }
  .ov-main .tank-top .value,
  .ov-main .est-col .figures {
    font-size: 1.55rem;
  }
  .ov-main .range-estimate .cell .n {
    font-size: 1.15rem;
  }
  .ov-main .est-col .note,
  .ov-main .tank-range-caption {
    font-size: 0.7rem;
  }

  /* Sidebar: quick links stack full-width */
  .ov-side .quicklinks {
    flex-direction: column;
  }
  .ov-side .quicklinks a {
    text-align: center;
  }

  /* Mouse hover on the refuel rows (still click-to-edit) */
  .refuel-item {
    transition: background 0.12s ease;
  }
  .refuel-item:hover {
    background: var(--bg);
  }
}

/* ============================================================
   Records screen (design system §4.8 / §4.9)
   Mobile: filter toolbar + card list + "Load more".
   Desktop (>=861px): bootstrap-table, token-restyled.
   ============================================================ */
/* Mobile-first (< 861px, the card view): the toolbar stacks into three rows —
   [From | To] · [Fuel type | Clear] · [Export CSV | Add record]. Explicit px
   min-widths on the fields keep flexbox from collapsing them to near-zero at
   narrow widths (tested at 375px). Desktop overrides below. */
.rec-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0.8rem 0 0.9rem;
}
.rec-filters {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.rec-actions {
  display: flex;
  gap: 0.5rem;
}
.rec-dates,
.rec-ft-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.rec-dates label {
  flex: 1;
  min-width: 110px;
}
.rec-ft-row label {
  flex: 1;
}
.rec-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.66rem;
  color: var(--ink-soft);
}
.rec-filters input,
.rec-filters select {
  width: 100%;
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
.rec-filters input[type='date'] {
  min-width: 110px;
}
.rec-actions .rec-btn {
  flex: 1;
  text-align: center;
}
.rec-btn {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.rec-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.rec-btn.ghost {
  color: var(--ink-soft);
}
.rec-btn.wide {
  display: block;
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.55rem;
}

.rec-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.rec-empty {
  font-size: 0.82rem;
  color: var(--ink-soft);
  padding: 1.2rem 0;
  text-align: center;
}
.rec-card {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
}
.rec-card:hover {
  border-color: var(--line-hover);
}
.rec-card.flagged {
  border-color: var(--bad-border);
  background: var(--bad-soft);
}
.rec-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
}
.rec-date {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
}
.rec-kml {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}
.rec-meta {
  font-size: 0.74rem;
  color: var(--ink-soft);
  margin-top: 0.2rem;
}
.rec-figures {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.45rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--ink);
}
.rec-card.flagged .rec-figures {
  border-top-color: var(--bad-border);
}

/* §4.9 generic small pill — namespaced so it can't collide with Bootstrap */
.rec-badge {
  font-size: 0.64rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 0.08rem 0.42rem;
  white-space: nowrap;
}
.rec-badge.neutral {
  background: var(--bg);
  color: var(--ink-soft);
}
.rec-badge.good {
  background: var(--good-soft);
  color: var(--good);
}
.rec-badge.warn {
  background: var(--bad-soft);
  color: var(--bad);
}

/* Maintenance due-status callout (component detail). */
.due-note {
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font-size: 0.78rem;
  line-height: 1.4;
  margin: 0.6rem 0;
}
.due-note .headline {
  font-weight: 700;
  margin-bottom: 0.1rem;
}
.due-note.ok {
  background: var(--good-soft);
  color: var(--good);
}
.due-note.bad {
  background: var(--bad-soft);
  color: var(--bad);
}
.due-note.neutral {
  background: var(--bg);
  color: var(--ink-soft);
}

@media (min-width: 861px) {
  /* Desktop (table view): fold the toolbar back into one wrapping row. */
  .rec-toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: flex-end;
    justify-content: space-between;
  }
  .rec-filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
  }
  .rec-dates label,
  .rec-ft-row label,
  .rec-ft-row {
    flex: 0 0 auto;
  }
  .rec-actions .rec-btn {
    flex: 0 0 auto;
  }

  /* bootstrap-table restyle — token overrides (its CSS loads before app.css) */
  #rec-table.table {
    --bs-table-bg: var(--surface);
    --bs-table-color: var(--ink);
    --bs-table-hover-bg: var(--bg);
    --bs-table-hover-color: var(--ink);
    --bs-table-border-color: var(--line);
    font-family: inherit;
  }
  #rec-table > thead th {
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: none;
  }
  #rec-table > tbody td {
    font-size: 0.85rem;
  }
  .bootstrap-table .pagination .active .page-link {
    background: var(--accent);
    border-color: var(--accent);
  }
  .bootstrap-table .page-link {
    color: var(--accent);
  }
  .fixed-table-toolbar .btn {
    color: var(--accent);
  }
}

/* ============================================================
   Shared stat primitives: full-width stat, collapsible "more"
   (design system §4.4 / §4.14 / §4.15). Used by the "more stats"
   strip at the foot of Overview.
   ============================================================ */
.stat.full {
  grid-column: 1 / -1;
}
.ov-detail {
  margin-top: 0.9rem;
}
.ov-detail .more-section .stat-grid + .stat-grid {
  margin-top: 0.55rem;
}

/* §4.15 — inline anomaly flag + standalone note card */
.flag {
  color: var(--bad);
  font-weight: 700;
}
.data-note {
  margin: 0.55rem 0 0;
  font-size: 0.7rem;
  line-height: 1.45;
  color: var(--bad);
  background: var(--bad-soft);
  border: 1px solid var(--bad-border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}

/* §4.14 — collapsible "more" section */
.more-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  margin: 0.8rem 0 0;
  padding: 0.55rem;
  background: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.more-toggle .chev {
  transition: transform 0.15s ease;
}
.more-toggle[aria-expanded="true"] .chev {
  transform: rotate(180deg);
}
.more-section {
  display: none;
}
.more-section.open {
  display: block;
}
.more-section .stat-grid {
  margin-top: 0.6rem;
}

/* --- Trip detail (trip-detail enhancements) --------------------- */
.trip-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.trip-name-input {
  flex: 1 1 12rem;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
}
.trip-name-input:focus {
  outline: none;
  border-color: var(--accent);
}
.trip-source {
  margin-left: auto;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  background: var(--info-soft);
  color: var(--info);
  white-space: nowrap;
}
/* The two analysis stats added to the trip grid read as accented (mockup). */
#trip-stats .stat.new {
  background: var(--accent-soft);
}
/* Weak-GPS note — the Records anomaly strip, dashed. */
.trip-quality {
  margin: 0 0 0.6rem;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--bad);
  background: var(--bad-soft);
  border: 1px dashed var(--bad);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}
.trip-quality:empty {
  display: none;
}
/* Raw / processed data toggle (map + speed chart) */
#trip-data-mode:empty {
  display: none;
}
.trip-data-mode {
  max-width: 240px;
  margin: 0.5rem 0 0.2rem;
}
/* Simplify-tolerance debug slider (processed mode only) */
.simplify-tune {
  margin: 0.3rem 0 0.4rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.simplify-tune label {
  display: block;
  margin: 0.4rem 0 0.2rem;
}
.simplify-tune label:first-child {
  margin-top: 0;
}
.simplify-tune b {
  color: var(--ink);
}
.simplify-tune input[type='range'] {
  width: 100%;
  max-width: 260px;
}
/* Stop marker (manual + auto) */
.stop-pin {
  width: 20px;
  height: 20px;
  border-radius: 99px;
  background: var(--surface);
  border: 2px solid var(--ink-soft);
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}
/* Replay scrubber */
.trip-replay:empty {
  display: none;
}
.trip-replay {
  margin: 0.7rem 0 0.2rem;
}
.replay-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.replay-btn {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.7rem;
  cursor: pointer;
}
#replay-slider {
  flex: 1;
  accent-color: var(--accent);
}
.replay-speeds {
  display: flex;
  gap: 0.25rem;
}
.replay-speeds button {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
}
.replay-speeds button.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.replay-readout {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* --- Monthly report (views/monthly.js) ----------------------- */
/* Reuses .stat-grid / .refuel-card / .refuel-item; only the month stepper
 * and a few row states are new. */
.month-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
}
.month-step {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.month-step:disabled {
  opacity: 0.35;
  cursor: default;
}
.month-title {
  flex: 1;
  text-align: center;
}
.month-title .name {
  font-size: 1rem;
  font-weight: 700;
}
.month-title .hint {
  font-size: 0.68rem;
  color: var(--ink-soft);
}
.delta-badge.neutral {
  color: var(--ink-soft);
  background: var(--bg);
}
.refuel-item.static {
  cursor: default;
}
a.refuel-item {
  color: inherit;
  text-decoration: none;
}
.monthly .refuel-item .right {
  font-size: 0.72rem;
}
.monthly .stat .projection {
  margin-top: 0.15rem;
}
.month-list .refuel-item.current {
  background: var(--bg);
  box-shadow: inset 3px 0 0 var(--ink);
}
