:root {
  color-scheme: light dark;
  --bg: #f3f4f1;
  --surface: #ffffff;
  --text: #1b1f1d;
  --muted: #5c6661;
  --line: #d4d8d3;
  --primary: #0b5d4e;
  --primary-text: #ffffff;
  --ok-bg: #dff3e7;
  --ok-text: #0f5132;
  --warn-bg: #fdf0cf;
  --warn-text: #6b4e00;
  --error-bg: #fbdfdc;
  --error-text: #8a1c12;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --surface: #1d211f;
    --text: #edf0ee;
    --muted: #a3aca7;
    --line: #363c39;
    --primary: #3cc4a6;
    --primary-text: #06231c;
    --ok-bg: #12362a;
    --ok-text: #a4e8c6;
    --warn-bg: #3b2f0b;
    --warn-text: #f4d98a;
    --error-bg: #431a15;
    --error-text: #f8b9b1;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); }

h1 { font-size: 1.6rem; line-height: 1.2; margin: .5rem 0 .75rem; }
h2 { font-size: 1.15rem; margin: 0 0 .25rem; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .25rem 1rem;
  padding: .65rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.brand-line { display: flex; align-items: baseline; gap: .75rem; }
.home { color: var(--muted); text-decoration: none; font-size: .95rem; }
.home:hover { color: var(--primary); }

.topbar nav { display: flex; align-items: center; gap: 1rem; font-size: .95rem; }

main { max-width: 34rem; margin: 0 auto; padding: 1rem 1rem 3rem; }
main.wide { max-width: 90rem; }

.back { display: inline-block; padding: .25rem 0; text-decoration: none; font-size: .95rem; }
.vehicle-line { margin: 0 0 1rem; color: var(--muted); }
.hint { margin: 0 0 .5rem; color: var(--muted); font-size: .9rem; }
.empty { color: var(--muted); }
small { font-weight: 400; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.inline { display: inline; margin: 0; }

.card, .capture {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
}

.capture { display: flex; flex-direction: column; gap: .6rem; }

.capture-stage canvas {
  display: block;
  max-width: 100%;
  max-height: 55vh;
  margin: 0 auto .5rem;
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.ocr-status { margin: 0; padding: .5rem .7rem; border-radius: 8px; font-size: .95rem; background: var(--bg); }
.ocr-status[data-kind="ok"] { background: var(--ok-bg); color: var(--ok-text); }
.ocr-status[data-kind="warn"] { background: var(--warn-bg); color: var(--warn-text); }

.field { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; }

input[type="text"], input[type="password"], input[type="date"], input[type="datetime-local"],
input[type="number"], textarea, select {
  width: 100%;
  min-height: 48px;
  padding: .6rem .7rem;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--muted);
  border-radius: 8px;
}

.km-input { font-size: 1.6rem; font-weight: 700; letter-spacing: .06em; font-variant-numeric: tabular-nums; }

.check {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding: .85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.check input { width: 1.5rem; height: 1.5rem; flex: none; margin: 0; accent-color: var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: .6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-secondary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
.capture-button:focus-within { outline: 3px solid var(--primary); outline-offset: 2px; }

.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }

.notice { margin: 0 0 1rem; padding: .7rem .9rem; border-radius: 8px; }
.stack > .notice { margin: 0; }
.notice-ok { background: var(--ok-bg); color: var(--ok-text); }
.notice-error { background: var(--error-bg); color: var(--error-text); }

.notice-warn { background: var(--warn-bg); color: var(--warn-text); }
.notice-warn small { color: inherit; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .75rem; }
.photo-slot { display: flex; flex-direction: column; gap: .5rem; }
.photo-slot .btn { min-height: 5rem; text-align: center; }
.photo-preview canvas { display: block; width: 100%; height: auto; border-radius: 8px; }

.check-warn { border-color: var(--warn-text); }

.vehicle-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .75rem; }

.vehicle-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .2rem;
  padding: .9rem 1rem;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.vehicle-card:hover { border-color: var(--primary); }
.vehicle-name { font-size: 1.15rem; font-weight: 700; }
.vehicle-meta { color: var(--muted); font-size: .95rem; }

.badge { display: inline-block; margin-top: .25rem; padding: .1rem .55rem; border-radius: 99px; font-size: .85rem; font-weight: 600; }
.badge-free { background: var(--ok-bg); color: var(--ok-text); }
.badge-busy { background: var(--warn-bg); color: var(--warn-text); }
.badge-down { background: var(--error-bg); color: var(--error-text); border-radius: 8px; }
.vehicle-reason { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.big-number { margin: 0 0 .75rem; font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.distance { margin: 0; padding: .7rem 1rem; border-radius: 8px; background: var(--ok-bg); color: var(--ok-text); font-weight: 700; }
.distance[data-invalid="1"] { background: var(--error-bg); color: var(--error-text); }

/* Verwaltung */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { flex: 1 1 10rem; font-size: .9rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .55rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td.purpose { min-width: 14rem; overflow-wrap: anywhere; }
td.vehicle { min-width: 11rem; }
.vehicle-sub { display: block; color: var(--muted); font-size: .85rem; }
.section-title { margin: 1.5rem 0 .5rem; }
.flag { display: block; font-size: .8rem; color: var(--warn-text); }
.photo-link { display: block; }
.status-form { flex-basis: 100%; }
.status-form summary { list-style: none; display: inline-flex; }
.status-form summary::-webkit-details-marker { display: none; }
.status-form[open] form { margin-top: .5rem; min-width: 16rem; }
.status-form input[type="file"] { font: inherit; font-size: .9rem; font-weight: 400; }
.summary { margin: 0 0 .75rem; color: var(--muted); }
.pager { display: flex; justify-content: space-between; margin-top: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.btn-small { min-height: 36px; padding: .25rem .7rem; font-size: .9rem; }
