:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2563eb; --accent-text: #fff; --open: #c2410c; --paid: #15803d; --err-bg: #fde8e8; --ok-bg: #e5f6ea;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b1f27; --text: #e6e8ec; --muted: #9aa1ad; --line: #2b313c;
    --accent: #3b82f6; --open: #fb923c; --paid: #4ade80; --err-bg: #3b1d1d; --ok-bg: #173023;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); overflow-x: hidden; }
a { color: var(--accent); }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right)); }
main.wrap { padding-bottom: max(24px, env(safe-area-inset-bottom)); }

/* Kopfzeile */
.top { background: var(--card); border-bottom: 1px solid var(--line); margin-bottom: 16px; position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; justify-content: space-between; align-items: center; min-height: 52px; gap: 12px; }
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; white-space: nowrap; }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav form { margin: 0; }
.topnav a, .topnav .link { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: 14px; }
.topnav a.active { color: var(--text); background: var(--bg); font-weight: 600; }

.muted { color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
h1, h2 { margin: 0 0 14px; font-size: 18px; }
h3 { margin: 20px 0 10px; font-size: 15px; }

/* Formulare – 16px verhindert Auto-Zoom auf iOS */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
label.full { margin-bottom: 12px; }
textarea { resize: vertical; line-height: 1.4; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; width: 100%; min-width: 0; min-height: 44px; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--accent); flex: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid .span2 { grid-column: span 2; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 12px; }
label.check, label.switch { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 15px; min-height: 36px; cursor: pointer; }
label.switch { margin-bottom: 12px; }
#route-name-wrap { margin-top: 10px; }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 10px 18px; min-height: 44px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: 0; background: none; min-height: 0; }
button:disabled { opacity: .6; }
.top-gap { margin-top: 14px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quick button { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }

.preview { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--bg); overflow-wrap: anywhere; }
.preview small { display: block; color: var(--muted); margin-top: 6px; }
.preview .total { font-size: 17px; margin-top: 4px; }
.preview.error { background: var(--err-bg); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-bg); overflow-wrap: anywhere; }
.flash.error { background: var(--err-bg); }
.login { max-width: 380px; margin: 32px auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }

/* Kennzahlen */
.stats { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; min-width: 0; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat strong { font-size: 22px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat small { color: var(--muted); }
.stat.open strong { color: var(--open); }
.stat.paid strong { color: var(--paid); }

/* Listen */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.list-head h2 { margin: 0; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 7px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-size: 14px; }
.tabs a.active { background: var(--bg); color: var(--text); font-weight: 600; }
.trips { list-style: none; margin: 0; padding: 0; }
.trip { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.trip form { margin: 0; }
.trip-main { flex: 1; min-width: 0; }
.trip-side { display: flex; align-items: center; gap: 2px; }
.route { font-weight: 600; overflow-wrap: anywhere; }
.meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.meta span:not(:last-child)::after { content: " · "; }
.tag { font-size: 11px; font-weight: 500; background: var(--bg); border-radius: 4px; padding: 1px 6px; color: var(--muted); white-space: nowrap; }
.cost { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--open); }
.trip.is-paid .cost { color: var(--paid); }
.trip.is-paid .route { text-decoration: line-through; text-decoration-color: var(--muted); }
.paidbox { padding: 2px; cursor: pointer; }
.paidbox input { width: 24px; height: 24px; accent-color: var(--paid); cursor: pointer; }
.del { border: 0; background: none; color: var(--muted); padding: 0 8px; min-height: 36px; min-width: 36px; }
.del:hover { color: var(--open); }

/* Tablet / Handy */
@media (max-width: 640px) {
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stats .price { grid-column: 1 / -1; }
  .stat strong { font-size: 20px; }
  .card { padding: 14px; border-radius: 10px; }
  .actions button { flex: 1; }
  .trip { flex-wrap: wrap; }
  .trip-side { margin-left: auto; }
}
@media (max-width: 560px) {
  .top-inner { flex-wrap: wrap; gap: 0; padding-top: 6px; }
  .brand { width: 100%; }
  .topnav { width: 100%; justify-content: space-between; margin: 0 -6px; }
}
@media (max-width: 400px) {
  .brand { font-size: 15px; }
  .topnav a, .topnav .link { padding: 8px 6px; font-size: 13px; }
  .wrap { padding-left: 12px; padding-right: 12px; }
  .tabs a { padding: 6px 10px; }
}
