/* hidden gilt immer, auch wenn eine Klasse display setzt (etwa .button) */
[hidden] {
  display: none !important;
}

/* ============= TOKENS ============= */
:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6f6d68;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #2a78d6;
  --accent-hover: #1c5cab;
  --accent-ink: #1c5cab;
  --accent-wash: #cde2fb;
  --on-accent: #ffffff;
  --good: #006300;
  --bad: #d03b3b;
  --warn-bg: #fdf1d6;
  --warn-ink: #6b4a00;
  --error-bg: #fbe4e4;
  --error-ink: #8f2020;

  /* Schatten nur für Schwebendes (Menüs, Dialoge, Meldungen). Karten liegen flach auf der Seite. */
  --shadow-pop: 0 2px 6px rgba(11, 11, 11, 0.06), 0 12px 32px rgba(11, 11, 11, 0.12);
  --shadow-raised: 0 1px 2px rgba(11, 11, 11, 0.14);

  /* Radien nach Rang: Fläche, Bedienelement, Pille */
  --radius: 14px;
  --radius-s: 9px;
  --radius-pill: 99px;

  /* Abstände: eine Skala für alles */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  /* Inter, falls auf dem Gerät vorhanden, sonst die Schrift des Systems */
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI Variable Text', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;

  --nav-h: 62px;
  --ease: 0.14s ease;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #a3a198;
    --line: #2c2c2a;
    --line-strong: #454541;
    --accent: #3987e5;
    --accent-hover: #1c5cab;
    --accent-ink: #86b6ef;
    --accent-wash: #184f95;
    --on-accent: #ffffff;
    --good: #2fc22f;
    --bad: #e66767;
    --warn-bg: #3a2e10;
    --warn-ink: #f4cf7a;
    --error-bg: #3f1d1d;
    --error-ink: #f3a9a9;
    --shadow-pop: 0 2px 6px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.5);
    --shadow-raised: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --ink-3: #a3a198;
  --line: #2c2c2a;
  --line-strong: #454541;
  --accent: #3987e5;
  --accent-hover: #1c5cab;
  --accent-ink: #86b6ef;
  --accent-wash: #184f95;
  --on-accent: #ffffff;
  --good: #2fc22f;
  --bad: #e66767;
  --warn-bg: #3a2e10;
  --warn-ink: #f4cf7a;
  --error-bg: #3f1d1d;
  --error-ink: #f3a9a9;
  --shadow-pop: 0 2px 6px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-raised: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ============= GRUNDLAGEN ============= */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}
h1 {
  font-size: 1.6rem;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -0.02em;
  outline: none;
}
h2 {
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.005em;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Die Überschrift bekommt beim Seitenwechsel den Fokus für Screenreader, ist aber nicht bedienbar: kein Rahmen */
#view-title:focus,
#view-title:focus-visible {
  outline: none;
}

.sr-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ============= LAYOUT ============= */
.shell {
  display: flex;
  min-height: 100dvh;
}

.main {
  flex: 1;
  min-width: 0;
  padding: var(--s-4) var(--s-4) calc(var(--nav-h) + 88px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
/* Auf schmalen Bildschirmen rutschen die Aktionen in eine eigene Zeile statt über den Rand */
.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  min-width: 0;
  max-width: 100%;
  margin-left: auto;
}
/* Nebensachen neben der Überschrift: ohne Rahmen, damit die Überschrift führt */
.topbar__actions .button {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}
.topbar__actions .button:hover {
  background: var(--surface-2);
  color: var(--ink);
}

#view {
  max-width: 1500px;
}

/* ============= NAVIGATION ============= */
/* Unten auf dem Handy, links auf dem Desktop */
.nav {
  position: fixed;
  z-index: 20;
  inset: auto 0 0 0;
  display: grid;
  /* Höchstens fünf Einträge unten, sonst werden die Namen abgeschnitten. Tankstellen erreicht man über Einstellungen. */
  grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav__brand {
  display: none;
}

.nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  font-size: 0.68rem;
  font-weight: 550;
  color: var(--ink-3);
  text-decoration: none;
}
.nav__item > span:last-child {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Eine Strichstärke für alle Symbole. Die Pille dahinter zeigt am Handy den aktiven Reiter. */
.nav__icon {
  flex: none;
  box-sizing: content-box;
  width: 22px;
  height: 22px;
  padding: 3px 16px;
  border-radius: var(--radius-pill);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: background var(--ease);
}

.nav__item[aria-current='page'] {
  color: var(--accent-ink);
  font-weight: 650;
}
.nav__item[aria-current='page'] .nav__icon {
  background: var(--accent-wash);
}

@media (max-width: 899px) {
  /* Seltenes steht unter Einstellungen, unten bleiben fünf Einträge mit vollem Namen */
  .nav__item--secondary {
    display: none;
  }
}

@media (min-width: 900px) {
  .nav {
    position: sticky;
    top: 0;
    inset: 0 auto auto 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 0 0 220px;
    height: 100dvh;
    padding: var(--s-5) var(--s-3);
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .nav__brand {
    display: block;
    padding: 0 var(--s-3) var(--s-5);
    font-size: 1.15rem;
    font-weight: 750;
    letter-spacing: -0.02em;
  }
  .nav__item {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--s-3);
    min-height: 42px;
    padding: var(--s-2) var(--s-3);
    border-radius: var(--radius-s);
    font-size: 0.95rem;
    color: var(--ink-2);
    transition:
      background var(--ease),
      color var(--ease);
  }
  .nav__icon {
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 0;
  }
  .nav__item:hover {
    background: var(--surface-2);
    color: var(--ink);
  }
  /* Am Desktop trägt die Zeile den Zustand, das Symbol behält die Akzentfarbe */
  .nav__item[aria-current='page'] {
    background: var(--surface-2);
    color: var(--ink);
  }
  .nav__item[aria-current='page'] .nav__icon {
    background: transparent;
    color: var(--accent-ink);
  }
  .main {
    padding: var(--s-5) 28px 96px;
  }
}

/* ============= BEDIENELEMENTE ============= */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: var(--s-2) var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--ease),
    border-color var(--ease),
    color var(--ease);
}
a.button {
  text-decoration: none;
}
.button:hover {
  background: var(--surface-2);
}
.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
/* In beiden Modi die gleiche dunklere Stufe: Das Weiß der Schrift bleibt so auch im Dark Mode lesbar */
.button--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.button--danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}
.button--danger:hover {
  background: var(--bad);
  filter: brightness(0.92);
}
/* Löschen im Dialog: zurückhaltend und links, getrennt von „Speichern“ */
.button--danger-quiet {
  margin-right: auto;
  background: transparent;
  border-color: transparent;
  color: var(--bad);
}
.button--danger-quiet:hover {
  background: var(--error-bg);
}
.button--small {
  min-height: 36px;
  padding: var(--s-1) 11px;
  font-size: 0.86rem;
}
.button--block {
  width: 100%;
  justify-content: center;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition:
    background var(--ease),
    color var(--ease);
}
.icon-button:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  max-width: 100%;
  overflow-x: auto;
  background: var(--surface-2);
  border-radius: 10px;
  scrollbar-width: none;
}
.segmented button {
  flex: none;
  min-height: 36px;
  padding: var(--s-1) var(--s-3);
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--ease);
}
.segmented button:hover {
  color: var(--ink);
}
.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  box-shadow: var(--shadow-raised);
}
.tabs {
  margin-bottom: var(--s-4);
}
.theme-switch {
  margin-top: var(--s-3);
}

/* Mit dem Finger mindestens 44 px, wie es Apple und WCAG empfehlen */
@media (pointer: coarse) {
  .button--small,
  .segmented button,
  .icon-button {
    min-height: 44px;
  }
  .icon-button {
    min-width: 44px;
  }
}

/* ============= FELDER ============= */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--ink-2);
}

input[type='date'],
input[type='time'],
input[type='number'],
input[type='text'],
input[type='password'],
input[type='url'],
input[type='search'],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--s-2) 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px; /* verhindert das Einzoomen unter iOS */
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--ease);
}
input:hover,
select:hover,
textarea:hover {
  border-color: var(--ink-3);
}
::placeholder {
  color: var(--ink-3);
  opacity: 1;
}
textarea {
  min-height: 72px;
  resize: vertical;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 550;
  cursor: pointer;
}
.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.check--compact {
  min-height: 38px;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}

/* Fehler direkt am Feld */
.field__error {
  display: block;
  margin-top: 2px;
  color: var(--bad);
  font-size: 0.82rem;
  font-weight: 600;
}
[aria-invalid='true'] {
  border-color: var(--bad) !important;
  box-shadow: 0 0 0 1px var(--bad);
}

.chooser {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-4);
  margin-bottom: var(--s-3);
}
.chooser--inline {
  margin-bottom: 0;
  gap: 0 var(--s-3);
}
.chooser--inline .check {
  min-height: 38px;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}

/* Auswahl mehrerer Tags als Schaltflächen */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  min-height: 32px;
  padding: 3px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.82rem;
  cursor: pointer;
}
.chip[aria-pressed='true'] {
  background: var(--accent-wash);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.chips__filter {
  width: 100%;
  margin-bottom: var(--s-1);
}
.chips__box {
  max-height: 180px;
  overflow: auto;
  padding: 2px;
}
.field-map {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  align-items: center;
}

/* Kennzeichen: Teile in der Breite ihrer Zeichenzahl, damit es nach einem Nummernschild aussieht */
.plate {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.plate input {
  min-width: 0;
  padding: var(--s-2) 6px;
  text-align: center;
  font-weight: 650;
  letter-spacing: 0.04em;
}
.plate__ort {
  flex: 3 1 0;
}
.plate__buchstaben {
  flex: 2.4 1 0;
}
.plate__zahl {
  flex: 4 1 0;
}
.plate select.plate__suffix {
  flex: 0 0 62px;
  width: 62px;
  padding: var(--s-2) var(--s-1);
}
.plate__dash {
  flex: none;
  font-weight: 700;
  color: var(--ink-2);
}

/* ============= FILTERLEISTE ============= */
.filter {
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--s-2) var(--s-3);
  margin: 0 calc(-1 * var(--s-4)) var(--s-4);
  padding: var(--s-2) var(--s-4);
  background: var(--page);
  border-bottom: 1px solid var(--line);
}
.filter .field {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}
/* Lange Fahrzeugnamen dürfen die Auswahl nicht über den Rand schieben */
.filter select,
.filter input {
  min-height: 38px;
  padding: var(--s-1) var(--s-2);
  width: auto;
  min-width: 0;
  max-width: 100%;
  flex: 0 1 auto;
}
.filter__range {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
/* Eine Zeile je Frage: Zeitraum, Vergleich. Die Beschriftung steht davor wie bei „Fahrzeug“ */
.filter__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px var(--s-2);
  max-width: 100%;
}
.filter__label {
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--ink-2);
}
.filter__choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}
/* Alle Zeiträume sichtbar, auch am Handy: lieber zwei Zeilen als Knöpfe außerhalb des Bildes */
.filter .segmented {
  flex-wrap: wrap;
}
/* Ein älteres Jahr aus der Auswahl ist so gewählt wie ein Knopf */
.filter select.is-chosen {
  border-color: var(--ink-2);
  color: var(--ink);
  font-weight: 550;
}
.filter__info {
  flex-basis: 100%;
  font-size: 0.8rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.filter__body {
  display: contents;
}
.filter__toggle {
  display: none;
}
/* Am Handy: eine Zeile mit dem aktuellen Filter, ein Tipp klappt die Auswahl auf */
@media (max-width: 899px) {
  .filter__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    width: 100%;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
  }
  .filter__summary {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .filter__change {
    flex: none;
    color: var(--accent-ink);
    font-size: 0.9rem;
  }
  .filter__change::after {
    content: ' ▾';
  }
  .filter--open .filter__change::after {
    content: ' ▴';
  }
  .filter__body {
    display: none;
  }
  .filter--open .filter__body {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--s-2) var(--s-3);
    width: 100%;
    padding-bottom: var(--s-1);
  }
}

@media (min-width: 900px) {
  .filter {
    position: sticky;
    top: 0;
    margin: 0 -28px var(--s-5);
    padding: 10px 28px;
  }
}

/* ============= KARTEN UND RASTER ============= */
.grid {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
}
/* Mehrere Karten in einer Zelle, jede nur so hoch wie ihr Inhalt */
.grid__stack {
  display: grid;
  gap: var(--s-4);
  align-content: start;
  min-width: 0;
}
.grid + .grid,
.grid + .card,
.card + .grid,
.kpis + .grid,
.stack > * + * {
  margin-top: var(--s-4);
}

.card {
  container-type: inline-size;
  min-width: 0;
  padding: var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
@media (min-width: 900px) {
  .card {
    padding: 20px;
  }
}
.card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-2) var(--s-3);
  margin-bottom: var(--s-3);
}
/* Sonst schieben breite Umschalter die ganze Seite auf */
.card__head > * {
  min-width: 0;
  max-width: 100%;
}
/* Der Titel nimmt den freien Platz. Knöpfe bleiben rechts daneben und rutschen erst darunter, wenn es wirklich eng wird. */
.card__head > :first-child {
  flex: 1 1 9rem;
}
/* Umschalter des Diagramms und der Knopf „Tabelle“ nebeneinander */
.card__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.chart-table-toggle[aria-pressed='true'] {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--ink-3);
}
.card__sub {
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--ink-3);
  max-width: 75ch;
}
.card__sub--spaced {
  margin-top: 10px;
}
/* Breite Tabellen belegen die ganze Reihe des Rasters */
.card--wide {
  grid-column: 1 / -1;
}
.scroll-x {
  overflow-x: auto;
}

.empty {
  padding: 28px var(--s-3);
  text-align: center;
  color: var(--ink-3);
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge--good {
  color: var(--good);
}
.badge--pending {
  background: var(--warn-bg);
  color: var(--warn-ink);
}
.badge--error {
  background: var(--error-bg);
  color: var(--error-ink);
  white-space: normal;
}

.alert {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-s);
  font-size: 0.88rem;
}
.alert--warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
}
.alert--error {
  background: var(--error-bg);
  color: var(--error-ink);
}
.alerts {
  display: grid;
  gap: 6px;
}
.alerts:empty {
  display: none;
}

/* ============= AUSWERTUNG ============= */
/* Kennzahlen als eine Tafel: Zellen mit feinen Trennlinien statt sechs einzelner Karten */
.kpis {
  container-type: inline-size;
  margin-bottom: var(--s-4);
}
.kpis__grid {
  display: grid;
  gap: 1px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
/* Kennzahlen passen sich ihrem eigenen Container an, nicht dem Fenster */
@container (min-width: 620px) {
  .kpis__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@container (min-width: 1100px) {
  .kpis__grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.kpi {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px var(--s-4);
  background: var(--surface);
}
.kpi__label {
  font-size: 0.82rem;
  font-weight: 550;
  line-height: 1.3;
  color: var(--ink-2);
}
/* Der Wert sitzt unten: Bricht eine Beschriftung um, stehen die Zahlen einer Reihe trotzdem auf einer Linie */
.kpi__value {
  margin-top: auto;
  padding-top: 6px;
  font-size: clamp(1.4rem, 5.4cqi, 1.85rem);
  font-weight: 720;
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kpi__unit {
  font-size: 0.5em;
  font-weight: 550;
  color: var(--ink-2);
  letter-spacing: 0;
}
.kpi__delta {
  margin-top: var(--s-1);
  font-size: 0.78rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.delta--good {
  color: var(--good);
  font-weight: 600;
}
.delta--bad {
  color: var(--bad);
  font-weight: 600;
}

/* Wertepaare: Beschriftung oben, Zahl darunter */
.facts {
  display: grid;
  gap: 14px var(--s-4);
  margin: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
/* Drei kurze Werte nebeneinander: Jede Spalte so breit wie ihr Inhalt, damit „6,40 L/100km“ nicht umbricht */
.facts--compact {
  grid-template-columns: repeat(3, minmax(0, auto));
  justify-content: space-between;
}
@container (min-width: 520px) {
  .facts:not(.facts--compact, .facts--list) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.fact {
  min-width: 0;
}
.fact dt {
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--ink-2);
}
.fact dd {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.fact .fact__note {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-3);
  letter-spacing: 0;
}
.facts--compact .fact dd {
  font-size: 0.98rem;
}
/* Schlichte Liste „Begriff: Wert“ in den Einstellungen */
.facts--list {
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--s-1) 14px;
  margin: var(--s-2) 0;
  font-size: 0.9rem;
}
.facts--list dt {
  color: var(--ink-3);
}
.facts--list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.forecast {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: 1fr;
}
@container (min-width: 420px) {
  .forecast {
    grid-template-columns: 1fr 1fr;
  }
}
.forecast__label {
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--ink-2);
}
.forecast__value {
  font-size: 1.5rem;
  font-weight: 720;
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.forecast__note {
  font-size: 0.82rem;
  color: var(--ink-3);
}

/* Sprungmarken zu den Abschnitten der Auswertung */
.dash-nav {
  display: flex;
  gap: 6px;
  margin: var(--s-4) 0 var(--s-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.dash-nav__item {
  flex: none;
  min-height: 36px;
  padding: var(--s-1) 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.88rem;
  font-weight: 550;
  cursor: pointer;
  transition:
    border-color var(--ease),
    color var(--ease);
}
.dash-nav__item:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}
@media (pointer: coarse) {
  .dash-nav__item {
    min-height: 44px;
  }
}

.dash-section {
  margin-top: var(--s-6);
  scroll-margin-top: 80px;
}
.dash-section__title {
  margin-bottom: var(--s-3);
  font-size: 1.2rem;
  font-weight: 720;
  letter-spacing: -0.015em;
}
.dash-section__title:focus {
  outline: none;
}

/* ============= DIAGRAMME ============= */
.chart {
  width: 100%;
  height: 320px;
}
@container (max-width: 480px) {
  .chart {
    height: 270px;
  }
}

.chart-table {
  max-height: 260px;
  overflow: auto;
  margin-top: 10px;
  font-size: 0.85rem;
}
.effects-table {
  margin-top: var(--s-4);
}

/* ============= TABELLEN ============= */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}
th,
td {
  padding: var(--s-2) 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
th.text,
td.text {
  text-align: left;
}
td.wrap {
  white-space: normal;
  min-width: 160px;
}
/* Der Kopf tritt zurück: kleiner und grau, die Zahlen darunter führen */
thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
  border-bottom-color: var(--line-strong);
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 600;
}
thead th button {
  all: unset;
  cursor: pointer;
}
thead th button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
tbody th,
tbody td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
}
thead th:first-child {
  left: 0;
  z-index: 4;
}
tbody tr:hover td {
  background: var(--surface-2);
}
tbody tr:last-child td {
  border-bottom: 0;
}

/* ============= VERLAUF: TABELLE UND KARTENLISTE ============= */
.history {
  container-type: inline-size;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: var(--s-3);
}
.toolbar__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}

/* Suche und Sammelzuordnung im Verlauf */
.search {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.search select,
.search input {
  width: auto;
  min-height: 38px;
  padding: var(--s-1) var(--s-2);
  max-width: 100%;
  flex: 0 1 auto;
}
.search .search__text {
  flex: 1 1 240px;
}
.search__count {
  margin-bottom: var(--s-2);
}

/* Aufklappmenüs: Spaltenwahl und Export */
.columns {
  position: relative;
}
.columns > summary {
  list-style: none;
}
.columns > summary::-webkit-details-marker {
  display: none;
}
.columns__menu {
  position: absolute;
  z-index: 6;
  right: 0;
  margin-top: var(--s-1);
  min-width: 190px;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow-pop);
}
/* Am Handy stehen die Knöpfe links, das Menü öffnet dann nach rechts statt aus dem Bild */
@media (max-width: 899px) {
  .columns__menu {
    right: auto;
    left: 0;
  }
}
.columns__menu .check {
  min-height: 34px;
  font-weight: 450;
  font-size: 0.9rem;
}
/* Einträge im Export-Menü: ganze Zeile anklickbar */
.columns__item {
  display: block;
  width: 100%;
  min-height: 38px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}
.columns__item:hover {
  color: var(--accent-ink);
}

.table-wrap {
  display: none;
  max-height: calc(100dvh - 300px);
  min-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.entry-cards {
  display: grid;
  gap: var(--s-2);
}
/* Listen, die unabhängig von der Breite Karten bleiben */
.entry-cards--always {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
}
/* Spalten gibt es nur in der Tabelle, die Karten zeigen immer dieselben Werte */
.columns--table {
  display: none;
}
@container (min-width: 760px) {
  .table-wrap {
    display: block;
  }
  .entry-cards:not(.entry-cards--always) {
    display: none;
  }
  .columns--table {
    display: inline-block;
  }
}

/* Bearbeiten und Löschen bleiben sichtbar, auch wenn die Tabelle seitlich scrollt */
.table-wrap td.actions {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--surface);
}
.table-wrap th.actions {
  position: sticky;
  right: 0;
  z-index: 4;
}
.table-wrap tbody tr:hover td.actions {
  background: var(--surface-2);
}

.entry-card {
  padding: var(--s-3) 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
/* Karten im Verlauf und bei den Kosten: ein Tipp öffnet den Eintrag */
.entry-card--button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition:
    border-color var(--ease),
    background var(--ease);
}
.entry-card--button:hover {
  border-color: var(--line-strong);
}
.entry-card--button:active {
  background: var(--surface-2);
}
.entry-card__top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.entry-card__date {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.entry-card__main {
  font-size: 1.2rem;
  font-weight: 720;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
}
.entry-card__facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px 10px;
  margin: var(--s-2) 0 0;
}
.entry-card__facts div {
  min-width: 0;
}
.entry-card__facts dt {
  font-size: 0.74rem;
  color: var(--ink-3);
}
.entry-card__facts dd {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}
.entry-card__line {
  margin-top: var(--s-1);
  font-size: 0.9rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.entry-card__meta {
  margin-top: var(--s-2);
  font-size: 0.85rem;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.entry-card__receipt {
  margin-top: var(--s-2);
}
/* Links ausgerichtet, damit der "+"-Button die Aktionen nicht verdeckt */
.entry-card__actions {
  display: flex;
  gap: 6px;
  margin-top: var(--s-2);
}
.vehicle-card .entry-card__actions {
  flex-wrap: wrap;
  margin-top: var(--s-4);
}

/* Fälligkeiten: Status steht immer auch als Text und Symbol da */
.due__state {
  flex: none;
  font-size: 0.82rem;
  font-weight: 650;
}
.due--overdue {
  border-color: var(--bad);
}
.due--overdue .due__state,
.due-banner__row.due--overdue b {
  color: var(--bad);
}
.due--soon .due__state,
.due-banner__row.due--soon b {
  color: var(--warn-ink);
}
.due-banner {
  display: grid;
  gap: 6px;
  justify-items: start;
  margin-bottom: var(--s-4);
  padding: var(--s-3) 14px;
  background: var(--warn-bg);
  border-radius: var(--radius);
}
.due-banner__row {
  font-size: 0.92rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* ============= FORMULAR ============= */
.form-layout {
  container-type: inline-size;
}
.entry-form {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.entry-form .span-full {
  grid-column: 1 / -1;
}
.entry-form .span-2 {
  grid-column: span 2;
}
.entry-form .span-ort {
  grid-column: span 1;
}
@container (min-width: 680px) {
  .entry-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .entry-form .span-ort {
    grid-column: span 3;
  }
}

/* „Mehr Angaben“: eingeklappte seltene Felder, aufgeklappt im selben Raster wie das Formular */
.more > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 550;
  cursor: pointer;
}
.more > summary:hover {
  color: var(--ink);
}
.more > summary::-webkit-details-marker {
  display: none;
}
.more > summary::before {
  content: '▸';
  width: 1.1em;
}
.more[open] > summary::before {
  content: '▾';
}
.more[open] > summary {
  margin-bottom: var(--s-2);
}
.more__body {
  padding-left: 2px;
}

/* Vorschau der errechneten Werte unter dem Formular */
.preview {
  padding: var(--s-3) 14px;
  background: var(--surface-2);
  border-radius: var(--radius-s);
}
.preview dl {
  margin: 0;
}
.preview__facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-2);
}
.preview__facts dt {
  font-size: 0.74rem;
  color: var(--ink-2);
}
.preview__facts dd {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.preview__note {
  margin-top: var(--s-2);
  font-size: 0.84rem;
  color: var(--ink-2);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.form-actions .button--primary {
  flex: 1 1 200px;
}

/* Belege aus Paperless */
.receipt {
  gap: 6px;
}
.receipt__current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  min-height: 36px;
  font-weight: 400;
}
.receipt__inputs {
  display: flex;
  gap: var(--s-2);
}
.receipt__inputs .receipt__search {
  flex: 1 1 auto;
  min-width: 0;
}
.receipt__inputs .receipt__number {
  flex: 0 0 96px;
  width: 96px;
}
.receipt__results {
  display: grid;
  gap: var(--s-1);
  max-height: 220px;
  overflow: auto;
}
.receipt__results:empty {
  display: none;
}
.receipt__result {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 10px;
  width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  cursor: pointer;
}
.receipt__result:hover {
  background: var(--surface-2);
}
.receipt__title {
  font-weight: 550;
  overflow-wrap: anywhere;
}
.receipt__upload {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-s);
}
.receipt-link {
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 0.9rem;
  align-self: center;
}
.entry-card__actions .receipt-link {
  margin-right: auto;
}

/* ============= EINSTELLUNGEN ============= */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin: var(--s-2) 0;
}
.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: 10px var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
}
.settings-row__main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.settings-row__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Verweise auf weitere Bereiche unter Einstellungen */
.settings-links {
  display: flex;
  flex-direction: column;
  margin-top: var(--s-1);
}
.settings-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 44px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.settings-link:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.settings-link:hover b {
  color: var(--accent-ink);
}
.settings-link b::after {
  content: ' ›';
  color: var(--ink-3);
}

/* ============= SCHWEBENDES: KNOPF, DIALOGE, MELDUNGEN ============= */
.fab {
  position: fixed;
  z-index: 15;
  right: var(--s-4);
  bottom: calc(var(--nav-h) + var(--s-4) + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.5rem;
  box-shadow: var(--shadow-pop);
  cursor: pointer;
  transition: background var(--ease);
}
.fab:hover {
  background: var(--accent-hover);
}
@media (min-width: 900px) {
  .fab {
    bottom: var(--s-5);
    right: 28px;
  }
}
/* Am Handy ist der Reiter „Erfassen“ schon in Daumennähe. Ein schwebender Knopf würde nur Inhalte verdecken. */
@media (max-width: 899px) {
  .fab {
    display: none;
  }
}

dialog {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-pop);
}
dialog::backdrop {
  background: rgba(11, 11, 11, 0.5);
}

.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0;
  padding: var(--s-4) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  overflow: auto;
}
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sheet__head h2 {
  font-size: 1.2rem;
  font-weight: 720;
  letter-spacing: -0.015em;
}
@media (min-width: 720px) {
  .sheet {
    width: 680px;
    max-width: calc(100vw - 48px);
    margin: auto;
    border-radius: 18px;
    padding: var(--s-5);
  }
}

.confirm {
  max-width: min(420px, calc(100vw - 32px));
  padding: var(--s-5);
  border-radius: var(--radius);
}
.confirm__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: var(--s-4);
}

/* Meldung unten, auf Wunsch mit Knopf, etwa „Rückgängig“ */
.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--s-4) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 10px var(--s-4);
  background: var(--ink);
  color: var(--surface);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow-pop);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast--show {
  opacity: 1;
  pointer-events: auto;
}
.toast__action {
  min-height: 36px;
  padding: var(--s-1) var(--s-2);
  border: 0;
  background: transparent;
  color: var(--accent-wash);
  font-weight: 700;
  cursor: pointer;
}
@media (min-width: 900px) {
  .toast {
    bottom: var(--s-5);
  }
}

/* Hinweis bei fehlendem Netz und wartenden Einträgen */
.offline-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  margin: 0 0 var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-s);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.85rem;
}
.offline-bar .button {
  margin-left: auto;
}

/* ============= ANMELDUNG ============= */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s-4);
}
.login__card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: var(--s-5);
}
.login__card h1 {
  margin: 0;
}
.login__card form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.login__card input:not([type='checkbox']) {
  width: 100%;
}
.login__divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-3);
  font-size: 0.82rem;
}
.login__divider::before,
.login__divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--line);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
