:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #ece7df;
  --border: #ddd5c9;
  --text: #22303a;
  --muted: #6c7d8b;
  --accent: #c4562a;
  --accent-soft: #f0dcd0;
  --sea: #1d7d8c;
  --sea-soft: #d7ebee;
  --ok: #2f7d55;
  --warn: #9a6b12;
  --bad: #b23b38;
  --shadow: 0 1px 2px rgba(30,40,50,.06), 0 8px 24px rgba(30,40,50,.07);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10171e;
    --surface: #18222c;
    --surface-2: #1f2b36;
    --border: #2b3945;
    --text: #e7eef4;
    --muted: #93a6b6;
    --accent: #e2814f;
    --accent-soft: #33241c;
    --sea: #45b3bf;
    --sea-soft: #16323a;
    --ok: #4cb884;
    --warn: #ddab4a;
    --bad: #e07370;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--sea); }

/* ------------------------------------------------------------- Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 0 0;
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 550; padding: 9px 14px;
  border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }
.view[hidden] { display: none; }

/* ------------------------------------------------------------- Bausteine */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.section-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 0 0 16px;
}
.section-head h2 { margin: 0; font-size: 20px; letter-spacing: -.015em; }
.section-head .spacer { flex: 1; }
.lead {
  margin: -8px 0 18px; max-width: 62ch;
  color: var(--muted); font-size: 14.5px; line-height: 1.55;
}

.btn {
  appearance: none; font: inherit; font-size: 14px; font-weight: 550;
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-danger { color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 650; padding: 2px 8px;
  border-radius: 999px; letter-spacing: .02em; white-space: nowrap;
}
.badge-hotel   { background: var(--sea-soft); color: var(--sea); }
.badge-faehre  { background: var(--accent-soft); color: var(--accent); }
.badge-fahrzeug{ background: var(--surface-2); color: var(--muted); }
.badge-parken  { background: var(--surface-2); color: var(--muted); }
.badge-offen   { background: var(--surface-2); color: var(--warn); border: 1px dashed var(--warn); }
.badge-ok      { background: var(--surface-2); color: var(--ok); }

/* ------------------------------------------------------------- Zeitstrahl */
.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}
.tl-item { position: relative; margin-bottom: 14px; }
.tl-item::before {
  content: ""; position: absolute; left: -23px; top: 20px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}
.tl-item.is-offen::before { background: var(--surface); border: 2px dashed var(--warn); }
.tl-date {
  font-size: 12.5px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px;
}
.tl-card { padding: 14px 16px; }
.tl-card h3 { margin: 0 0 2px; font-size: 16.5px; letter-spacing: -.01em; }
.tl-loc { color: var(--muted); font-size: 13.5px; }
.tl-row { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.tl-amount { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 6px 18px; margin-top: 10px; font-size: 13.5px;
}
.tl-meta div { display: flex; gap: 6px; }
.tl-meta dt { color: var(--muted); }
.tl-meta dd { margin: 0; font-weight: 550; }
.tl-notes {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 13.5px; color: var(--muted);
}
.tl-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ------------------------------------------------------------- Tabellen */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

/* ------------------------------------------------------------- Formulare */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sea); outline-offset: -1px; border-color: var(--sea); }
/* Kaestchen und Radiobuttons duerfen nicht die volle Breite belegen - sonst rutscht
   in Leaflets Ebenen-Auswahl jede Beschriftung in die naechste Zeile. */
input[type="checkbox"], input[type="radio"] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; padding-top: 4px; }
.checks label { display: flex; align-items: center; gap: 6px; font-size: 14.5px; color: var(--text); font-weight: 500; }
.checks input { width: auto; }

/* ------------------------------------------------------------- Salden */
.balances { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.balance { padding: 16px; }
.balance h4 { margin: 0 0 8px; font-size: 15px; }
.balance .big { font-size: 26px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.balance .big.pos { color: var(--ok); }
.balance .big.neg { color: var(--bad); }
.balance .rows { margin-top: 10px; font-size: 13px; color: var(--muted); }
.balance .rows div { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.transfers { list-style: none; margin: 0; padding: 0; }
.transfers li {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 15px;
}
.transfers li:last-child { border-bottom: 0; }
.transfers .amt { font-weight: 680; font-variant-numeric: tabular-nums; margin-left: auto; font-size: 17px; }
.arrow { color: var(--accent); font-weight: 700; }

/* ------------------------------------------------------------- Tadel */
.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
}
.ranking li:last-child { border-bottom: 0; }
.ranking .rank { width: 22px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.ranking .who { width: 92px; font-weight: 600; font-size: 15px; }
.ranking .who.leader { color: var(--accent); }
.ranking .bar-wrap { flex: 1; height: 9px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.ranking .bar { display: block; height: 100%; background: var(--sea); border-radius: 999px; }
.ranking .bar.leader { background: var(--accent); }
.ranking .cnt { width: 26px; text-align: right; font-weight: 680; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- Bilder */
.daygroup { margin-bottom: 28px; }
.daygroup h3 {
  margin: 0 0 10px; font-size: 16px; display: flex; align-items: baseline; gap: 10px;
  position: sticky; top: 58px; background: var(--bg); padding: 6px 0; z-index: 10;
}
.daygroup h3 .count { font-size: 13px; color: var(--muted); font-weight: 500; }
.grid-photos {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px;
}
.grid-photos figure { margin: 0; position: relative; aspect-ratio: 1; }
.grid-photos img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 10px;
  background: var(--surface-2); cursor: zoom-in; display: block;
}
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 28px 20px; text-align: center; color: var(--muted); margin-bottom: 20px;
  background: var(--surface);
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(8,12,16,.94);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
}
.lightbox img { max-width: 96vw; max-height: 82vh; object-fit: contain; border-radius: 6px; }
.lightbox .lb-bar { color: #dfe7ee; padding: 12px 16px; display: flex; gap: 14px; align-items: center; font-size: 14px; }
.lightbox button { background: rgba(255,255,255,.12); border: 0; color: #fff; font: inherit; padding: 8px 14px; border-radius: 9px; cursor: pointer; }

/* ------------------------------------------------------------- Karte */
#map { height: min(65vh, 620px); border-radius: var(--radius); border: 1px solid var(--border); z-index: 1; }
.route-list { display: grid; gap: 8px; margin-top: 16px; }
.route-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; flex-wrap: wrap; }
.route-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.route-item .name { font-weight: 600; font-size: 14.5px; }
.route-item .meta { color: var(--muted); font-size: 13px; }
.route-item .spacer { flex: 1; }
.route-item input[type=checkbox] { width: auto; }

/* ------------------------------------------------------------- Login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(400px, 100%); padding: 28px; text-align: center; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card form { display: grid; gap: 12px; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 550; z-index: 200; box-shadow: var(--shadow);
}
.hidden { display: none !important; }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .brand h1 { font-size: 16px; }
  .brand .sub { display: none; }
  /* Abmelden bleibt in der Kopfzeile, die Reiter bekommen die zweite Zeile ganz */
  .topbar-inner > #logout { order: 2; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; padding: 8px 6px; font-size: 13px; }
  main { padding: 16px 12px 60px; }
  /* Betrag und Zahlungsstand linksbuendig wie der Rest der Karte */
  .tl-row > div:last-child { text-align: left !important; }
  .daygroup h3 { top: 92px; }
}
