/* App layout and screen-level styles. Components live in components.css. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--surface-base); color: var(--ink);
  font: 400 17px/22px var(--font-sans); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
a { color: var(--ember); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); }
.icon { flex: none; display: block; }

/* ---- navigation bar ---------------------------------------------------- */
.navbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  background: transparent; border-bottom: 1px solid transparent;
  transition: background-color 140ms ease, border-color 140ms ease;
}
.navbar.is-compact {
  background: color-mix(in srgb, var(--surface-overlay) 82%, transparent);
  -webkit-backdrop-filter: blur(var(--blur-regular)); backdrop-filter: blur(var(--blur-regular));
  border-bottom-color: var(--line);
}
.navbar__inner { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; max-width: 720px; height: var(--nav-bar-height); margin: 0 auto; padding: 0 var(--space-2); }
.navbar__title { font: 700 17px/22px var(--font-sans); opacity: 0; transform: translateY(4px); transition: opacity 140ms ease, transform 140ms ease; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navbar.is-compact .navbar__title { opacity: 1; transform: none; }
.navbar__lead { justify-self: start; }
.navbar__trail { justify-self: end; display: flex; gap: var(--space-1); }
.navbar__back { padding-left: var(--space-1); gap: 0; }
.icon-btn { display: inline-grid; place-items: center; width: var(--tap-min); height: var(--tap-min); padding: 0; border: 0; border-radius: var(--radius-pill); background: none; color: var(--ember); cursor: pointer; }
.icon-btn:active { opacity: var(--opacity-pressed); }
.icon-btn--filled { background: var(--ember-subtle); }

/* ---- page ------------------------------------------------------------------ */
.page {
  max-width: 720px; margin: 0 auto;
  padding: 0 var(--space-4) calc(var(--tab-bar-height) + env(safe-area-inset-bottom, 0px) + var(--space-10));
  outline: none;
}
.large-title { font: 800 34px/41px var(--font-display); letter-spacing: -.02em; margin: var(--space-1) 0 var(--space-4); }
.section { margin-top: var(--space-8); }
.section:first-of-type { margin-top: 0; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin: 0 0 var(--space-2); padding: 0 var(--space-1); }
.section__title { font: 700 22px/28px var(--font-display); letter-spacing: -.01em; }
.section__label { font: 700 12px/16px var(--font-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); }
.section__link { font: 600 15px/20px var(--font-sans); color: var(--ember); background: none; border: 0; padding: var(--space-2) 0; min-height: var(--tap-min); cursor: pointer; }
.section__foot { margin: var(--space-2) var(--space-4) 0; font: 400 13px/18px var(--font-sans); color: var(--ink-muted); }
.stack { display: flex; flex-direction: column; gap: var(--space-6); }

/* ---- cards and stats ------------------------------------------------------------ */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.stat-grid .ag-card { min-width: 0; }
.ag-stat__value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-stat__value--md { font-size: 26px; }
.ag-stat__value--accent { color: var(--ember); }
.card-button { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.card-button:active { transform: scale(.985); }
.hero-stat { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); }
.hero-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin-top: var(--space-4); }
.hero-actions .ag-btn { padding: 0 var(--space-3); white-space: nowrap; }

/* ---- lists ---------------------------------------------------------------------------- */
.ag-list > li { list-style: none; position: relative; }
.ag-list > li + li > .ag-row::before { content: ""; position: absolute; top: 0; right: 0; left: var(--space-4); border-top: 1px solid var(--line); }
.ag-list > li + li > .ag-row:has(.ag-row__icon)::before { left: calc(var(--space-4) + var(--space-8) + var(--space-3)); }
button.ag-row:disabled { cursor: default; opacity: 1; }
button.ag-row:disabled:active { background: none; }
a.ag-row, button.ag-row { width: 100%; border: 0; background: none; text-align: left; text-decoration: none; color: var(--ink); }
.ag-row__body { display: flex; flex-direction: column; }
.ag-row__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-row__sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-row__meta { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-1); min-width: 0; }
.ag-row__meta .ag-badge { flex: none; }
.ag-row__end { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex: none; }
.ag-row__icon--text { font: 700 15px/1 var(--font-mono); }
.ag-row__icon--muted { background: var(--surface-sunken); color: var(--ink-muted); }
.ag-row .ag-badge { flex: none; }
.ag-row:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: -3px; border-radius: var(--radius-lg); }
.list-group-label { margin: var(--space-6) var(--space-1) var(--space-2); font: 700 12px/16px var(--font-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); display: flex; justify-content: space-between; }
.list-group-label:first-child { margin-top: 0; }
.mpg-tag { font: 600 13px/18px var(--font-mono); color: var(--ember); font-variant-numeric: tabular-nums; }

/* ---- empty state ------------------------------------------------------------------------ */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); padding: var(--space-10) var(--space-4); background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.empty__title { font: 700 20px/25px var(--font-display); }
.empty__sub { font: 400 15px/20px var(--font-sans); color: var(--ink-muted); max-width: 32ch; margin-bottom: var(--space-3); }

/* ---- tab bar ------------------------------------------------------------------------------- */
.ag-tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; }
.ag-tab { text-decoration: none; justify-content: center; }
.ag-tab:active { opacity: var(--opacity-pressed); }
.tabbar-inner { display: flex; width: 100%; max-width: 720px; margin: 0 auto; }

/* ---- garage hero --------------------------------------------------------------------------- */
.ag-hero__head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }
.ag-hero__odo { text-align: right; }
.ag-hero__odo .ag-stat__value { font-size: 28px; line-height: 32px; }
.vehicle-switch { display: inline-flex; align-items: center; gap: var(--space-1); background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-align: left; }
.vehicle-switch .icon { color: var(--ink-faint); transform: rotate(90deg); }
.car-placeholder { display: grid; place-items: center; aspect-ratio: 1200 / 586; color: var(--steel); }

/* ---- bottom sheet ------------------------------------------------------------------------------ */
dialog.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; padding: 0; border: 0;
  width: 100%; max-width: 640px; max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 24px);
  background: var(--surface-overlay); color: var(--ink);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0; box-shadow: var(--shadow-sheet);
  animation: sheet-in 300ms cubic-bezier(.2, .8, .2, 1);
}
dialog.sheet.is-closing { animation: sheet-out 220ms ease-in forwards; }
dialog.sheet::backdrop { background: var(--scrim); animation: fade-in 300ms ease; }
dialog.sheet.is-closing::backdrop { animation: fade-out 220ms ease forwards; }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.sheet__form { display: flex; flex-direction: column; max-height: inherit; }
.sheet__head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: var(--space-2) var(--space-2) 0; }
.sheet__head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: var(--radius-pill); background: var(--line-strong); opacity: .6; }
.sheet__head .ag-btn--plain { justify-self: start; font-weight: 400; }
.sheet__title { font: 700 17px/22px var(--font-sans); text-align: center; }
.sheet__body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); overscroll-behavior: contain; }
.sheet__foot { padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface-overlay); }
.sheet__destroy { margin-top: var(--space-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.form-grid > *, .ag-field, .ag-field__control { min-width: 0; }
.ag-field__input { width: 100%; min-width: 0; }
.ag-field__input:focus-visible { outline: none; }
.sheet__body { overflow-x: hidden; }
.form-grid > .span-2 { grid-column: 1 / -1; }
.form-note { font: 400 13px/18px var(--font-sans); color: var(--ink-muted); }
.form-error { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-3); border-radius: var(--radius-md); background: var(--danger-subtle); color: var(--danger); font: 600 15px/20px var(--font-sans); }
.form-error[hidden] { display: none; }
.calc-line { display: flex; justify-content: space-between; align-items: baseline; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--surface-sunken); }
.calc-line__label { font: 700 12px/16px var(--font-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); }
.calc-line__value { font: 700 22px/28px var(--font-mono); font-variant-numeric: tabular-nums; }

/* fields: text inputs use the sans face; numbers stay mono */
.ag-field__input--text { font: 400 17px/22px var(--font-sans); }
.ag-field__input[type="date"], .ag-field__input[type="datetime-local"] { font: 600 17px/22px var(--font-mono); min-height: 42px; -webkit-appearance: none; appearance: none; }
.ag-field__input::-webkit-date-and-time-value { text-align: left; }
.ag-field__control { position: relative; }
.ag-field__control--area { padding: var(--space-3) var(--space-4); align-items: stretch; }
.ag-field__control--area textarea { resize: vertical; min-height: 66px; }
select.ag-field__input { -webkit-appearance: none; appearance: none; padding-right: var(--space-6); cursor: pointer; }
.select-chev { position: absolute; right: var(--space-3); transform: rotate(90deg); color: var(--ink-faint); pointer-events: none; }
.ag-field__error { margin: 0; }

/* toggles */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--tap-min); padding: var(--space-3) var(--space-4); background: var(--surface-sunken); border-radius: var(--radius-md); cursor: pointer; }
.toggle-row__text { display: flex; flex-direction: column; }
.toggle-row__label { font: 600 15px/20px var(--font-sans); }
.toggle-row__sub { font: 400 13px/18px var(--font-sans); color: var(--ink-muted); }
.switch { -webkit-appearance: none; appearance: none; flex: none; position: relative; width: 51px; height: 31px; margin: 0; border-radius: var(--radius-pill); background: var(--line-strong); cursor: pointer; transition: background-color 140ms ease; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px #0000004d; transition: transform 200ms cubic-bezier(.2, .8, .2, 1); }
.switch:checked { background: var(--ember); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

/* chips (multi-select of schedule items) */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip { display: inline-flex; align-items: center; gap: var(--space-1); min-height: 36px; padding: 0 var(--space-3); border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: none; font: 600 15px/20px var(--font-sans); color: var(--ink); cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip .icon { display: none; }
.chip:has(input:checked) { background: var(--ember-subtle); border-color: var(--ember); color: var(--ember); }
.chip:has(input:checked) .icon { display: block; }
.chip:has(input:focus-visible) { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.chips-label { font: 600 15px/20px var(--font-sans); margin-bottom: var(--space-2); }

/* alert */
dialog.alert { border: 0; padding: var(--space-6) var(--space-4) var(--space-4); width: min(320px, calc(100% - 32px)); border-radius: var(--radius-xl); background: var(--surface-overlay); color: var(--ink); box-shadow: var(--shadow-sheet); }
dialog.alert::backdrop { background: var(--scrim); }
.alert__msg { font: 600 17px/22px var(--font-sans); text-align: center; margin-bottom: var(--space-6); }
.alert__actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom, 0px) + var(--space-4)); z-index: 50; display: flex; align-items: center; gap: var(--space-2); max-width: calc(100% - 32px); padding: var(--space-3) var(--space-4); border-radius: var(--radius-pill); background: var(--ink); color: var(--surface-base); font: 600 15px/20px var(--font-sans); box-shadow: var(--shadow-sheet); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: transform 250ms cubic-bezier(.2, .8, .2, 1), opacity 200ms ease; }
.toast.is-in { transform: translate(-50%, 0); opacity: 1; }

/* ---- charts ------------------------------------------------------------------------------------ */
.chart-card { padding: var(--space-4) var(--space-4) var(--space-3); }
.chart-card__head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-3); margin-bottom: var(--space-3); }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font: 500 11px var(--font-sans); fill: var(--ink-muted); }
.chart .grid { stroke: var(--steel); stroke-width: 1; opacity: .5; }
.chart .series-1 { stroke: var(--ember); }
.chart .series-2 { stroke: var(--ink); }
.chart .fill-1 { fill: var(--ember); }
.chart .fill-2 { fill: var(--ink-muted); }
.chart .fill-3 { fill: var(--info); }
.chart .fill-4 { fill: var(--steel); }
.chart .fill-5 { fill: var(--warning); }
.chart .dot { fill: var(--surface-raised); stroke: var(--ember); stroke-width: 2; }
.chart-empty { padding: var(--space-8) 0; text-align: center; font: 400 15px/20px var(--font-sans); color: var(--ink-muted); }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-3); font: 500 12px/16px var(--font-sans); color: var(--ink-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.breakdown { display: flex; flex-direction: column; gap: var(--space-3); }
.breakdown__row { display: grid; grid-template-columns: 1fr auto; gap: var(--space-1) var(--space-3); align-items: baseline; }
.breakdown__name { font: 600 15px/20px var(--font-sans); }
.breakdown__val { font: 600 15px/20px var(--font-mono); font-variant-numeric: tabular-nums; }
.breakdown__bar { grid-column: 1 / -1; height: 8px; border-radius: var(--radius-xs); background: var(--surface-sunken); overflow: hidden; }
.breakdown__bar > i { display: block; height: 100%; border-radius: var(--radius-xs); }
.range-bar { display: flex; justify-content: flex-start; margin-bottom: var(--space-4); }
.range-bar .ag-seg { width: 100%; }
.range-bar .ag-seg__item { flex: 1; }

/* ---- import --------------------------------------------------------------------------------------- */
.map-table { width: 100%; border-collapse: collapse; font: 400 13px/18px var(--font-mono); }
.map-table th, .map-table td { text-align: left; padding: var(--space-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.map-table th { font: 700 12px/16px var(--font-sans); letter-spacing: .04em; color: var(--ink-muted); }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-sunken); }
.file-drop { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-8) var(--space-4); border: 2px dashed var(--line-strong); border-radius: var(--radius-lg); text-align: center; color: var(--ink-muted); cursor: pointer; }
.file-drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-drop:focus-within { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.callout { display: flex; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--info-subtle); color: var(--ink); font: 400 15px/20px var(--font-sans); }
.callout .icon { color: var(--info); margin-top: 1px; }
.callout--warning { background: var(--warning-subtle); }
.callout--warning .icon { color: var(--warning); }

/* ---- motion ---------------------------------------------------------------------------------------- */
.view-enter { animation: view-in 250ms cubic-bezier(.2, .8, .2, 1); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media (min-width: 720px) {
  .page { padding-left: var(--space-6); padding-right: var(--space-6); }
}
