:root {
  --bg: #f2f3f7;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --text: #10131a;
  --muted: #6b7280;
  --line: #e6e8ee;
  --accent: #0b5cff;
  --accent-ink: #ffffff;
  --ok: #128a4b;
  --warn: #b45309;
  --danger: #d33a2c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16,19,26,.06), 0 8px 24px rgba(16,19,26,.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0f;
    --surface: #16171d;
    --surface-2: #1e2029;
    --text: #f3f4f8;
    --muted: #9aa1ad;
    --line: #2a2c36;
    --accent: #3d7bff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  height: calc(var(--bar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar__title { text-align: center; font-weight: 650; font-size: 17px; letter-spacing: -.2px; }
.appbar__back {
  border: 0; background: none; color: var(--accent);
  font-size: 30px; line-height: 1; padding: 0 4px; font-weight: 400;
}
.appbar__badge {
  justify-self: end; margin-right: 12px;
  font-size: 10px; font-weight: 800; letter-spacing: .5px;
  color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent);
  padding: 3px 7px; border-radius: 999px;
}

/* ---------- Layout ---------- */
main { padding: 16px 16px calc(120px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- Upload / Empty ---------- */
.hero { text-align: center; padding: 22px 8px 6px; }
.hero h1 { font-size: 26px; margin: 6px 0 6px; letter-spacing: -.5px; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 34ch; line-height: 1.45; }

.dropzone {
  margin-top: 20px; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 34px 18px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.dropzone .big { font-size: 40px; }
.dropzone label { display: contents; }

.btn {
  appearance: none; border: 0; border-radius: 999px; font-size: 16px; font-weight: 650;
  padding: 14px 22px; background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; transition: transform .06s ease, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn--ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn--ok { background: var(--ok); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Case cards ---------- */
.listhead { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 2px 2px; }
.listhead h2 { font-size: 20px; margin: 0; letter-spacing: -.3px; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; border: 1px solid var(--line);
}
.case { display: grid; grid-template-columns: 92px 1fr auto; gap: 12px; align-items: center; padding: 12px; cursor: pointer; }
.case__thumb { width: 92px; height: 92px; border-radius: var(--radius-sm); object-fit: cover; background: var(--surface-2); }
.case__thumb-wrap { position: relative; }
.case__count { position: absolute; right: 5px; bottom: 5px; font-size: 11px; font-weight: 700; color: #fff; background: rgba(0,0,0,.6); padding: 2px 6px; border-radius: 999px; }
.plate {
  display: inline-flex; align-items: stretch; border: 2px solid #111; border-radius: 6px; overflow: hidden;
  font-weight: 800; font-family: "SF Mono", ui-monospace, monospace; background: #fff; color: #111;
  font-size: 15px; letter-spacing: .5px;
}
.plate .eu { background: #0b3fb0; color: #fff; display: flex; align-items: center; padding: 0 4px; font-size: 9px; }
.plate .num { padding: 3px 8px; }
.case__meta { min-width: 0; }
.case__line { font-size: 14px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); font-size: 22px; }

.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.pill--review { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.pill--sent { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }

/* ---------- Detail ---------- */
.photostrip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; scroll-snap-type: x mandatory; }
.photostrip img { height: 210px; border-radius: var(--radius-sm); scroll-snap-align: start; object-fit: cover; }

.field { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
.field input, .field select, .field textarea {
  width: 100%; border: 0; background: none; color: var(--text);
  font-size: 16px; font-family: inherit; padding: 2px 0;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; }
.field textarea { resize: vertical; min-height: 46px; line-height: 1.4; }
.field--ai::after { content: "KI"; float: right; font-size: 10px; font-weight: 800; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 2px 6px; border-radius: 999px; margin-top: -2px; }
.field--warn { background: color-mix(in srgb, var(--warn) 7%, transparent); }
.field--warn input { color: var(--warn); font-weight: 700; }
.fieldhint { font-size: 12px; color: var(--warn); margin-top: 6px; font-weight: 600; }

.linkbtn { display: inline-block; margin: 2px 2px 0; padding: 6px 2px; background: none; border: 0; color: var(--accent); font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer; }
.pm-row { display: flex; gap: 12px; align-items: center; }
.pm-thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; }
.pm-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 999px; font-family: inherit; cursor: pointer; }
.chip:active { transform: scale(.97); }

.field-inline { display: flex; gap: 8px; align-items: center; }
.field-inline input { flex: 1; }
.field-inline .chip { flex: none; }

/* Karten-Overlay */
.mapov { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column; padding-top: var(--safe-top); }
.map-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.map-head span { font-weight: 650; }
.map-head .btn { padding: 9px 16px; font-size: 15px; }
.map-canvas { flex: 1; min-height: 0; }
.map-hint { text-align: center; padding: 10px calc(14px + var(--safe-bottom)); padding-bottom: calc(12px + var(--safe-bottom)); font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }
.leaflet-container { background: var(--surface-2); }

/* Archiv */
.searchbar { margin: 4px 0 12px; }
.searchbar input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 16px; font-family: inherit; padding: 12px 14px; border-radius: 12px;
}
.searchbar input:focus { outline: none; border-color: var(--accent); }
.arch-summary { font-size: 13px; color: var(--muted); font-weight: 600; margin: 2px 2px 10px; }
.arch-when { font-size: 13px; margin: 10px 2px 0; }
.arch-del { flex: none; border: 0; background: none; font-size: 20px; padding: 8px; cursor: pointer; opacity: .7; }
.arch-del:active { opacity: 1; }
.field-val { font-size: 16px; color: var(--text); padding: 2px 0; }

.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 20px 4px 8px; text-transform: uppercase; letter-spacing: .5px; }
.sign { display: flex; align-items: center; gap: 12px; padding: 14px; }
.sign img { height: 42px; }

/* ---------- Action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  display: flex; gap: 10px; max-width: 640px; margin: 0 auto;
}

/* ---------- Toast / overlay ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%);
  background: #111; color: #fff; padding: 12px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 24px; }
.sheet { background: var(--surface); border-radius: 20px; padding: 24px; max-width: 340px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.sheet .big { font-size: 44px; }
.sheet h3 { margin: 8px 0 4px; }
.sheet p { color: var(--muted); margin: 0 0 18px; line-height: 1.45; }

.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; color: var(--muted); font-size: 14px; }
.progress-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

/* Foto gedrückt-halten-Zoom */
.photostrip img { cursor: zoom-in; }
.zoomov {
  position: fixed; inset: 0; z-index: 100; background: #000;
  overflow: hidden; touch-action: none; overscroll-behavior: none;
}
.zoomimg { position: absolute; top: 0; left: 0; max-width: none; will-change: transform; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.zoomhint {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  color: #fff; background: rgba(0,0,0,.6); padding: 8px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; pointer-events: none;
}
