:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --text: #1b1b1f;
  --muted: #6d6b73;
  --border: #e4e1da;
  --accent: #b8862b;
  --accent-text: #ffffff;
  --accent-soft: #f3e7cf;
  --danger: #c0392b;
  --ok: #2e7d4f;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111114;
    --surface: #1c1c21;
    --text: #f2f1ee;
    --muted: #9d9ba4;
    --border: #2c2c33;
    --accent: #d6a548;
    --accent-text: #16161a;
    --accent-soft: #3a3020;
    --danger: #ef6f61;
    --ok: #5cc28a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111114;
  --surface: #1c1c21;
  --text: #f2f1ee;
  --muted: #9d9ba4;
  --border: #2c2c33;
  --accent: #d6a548;
  --accent-text: #16161a;
  --accent-soft: #3a3020;
  --danger: #ef6f61;
  --ok: #5cc28a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

[hidden] { display: none !important; }

h1 { font-size: 1.75rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 28px 4px 8px; font-weight: 600; }

.muted { color: var(--muted); margin: 4px 0 0; }
.small { font-size: 0.85rem; margin-top: 20px; }
.error { color: var(--danger); margin: 0; font-weight: 500; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.page-head { margin: 8px 4px 20px; }

.stack { display: flex; flex-direction: column; gap: 14px; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.95rem; }

input {
  font: inherit;
  font-size: 17px; /* verhindert Auto-Zoom auf iOS */
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  font-weight: 600;
  touch-action: manipulation;
}
button:disabled { opacity: 0.6; }
.primary { background: var(--accent); color: var(--accent-text); }
.primary.big { font-size: 1.15rem; padding: 18px; }
.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); width: 100%; margin-top: 12px; }
.link-btn { background: none; color: var(--accent); padding: 0 0 8px; font-weight: 500; }
.danger-btn { background: none; color: var(--danger); padding: 8px 10px; font-weight: 500; font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Login */
.login-box { max-width: 360px; margin: 12vh auto 0; }
.login-box h1 { text-align: center; margin-bottom: 28px; }
.logo {
  width: 64px; height: 64px; margin: 0 auto 14px;
  border-radius: 18px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-size: 32px;
}

/* Name wählen */
.pick-grid { display: grid; gap: 12px; }
.pick-btn {
  display: flex; align-items: center; gap: 16px;
  width: 100%; text-align: left;
  padding: 20px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  min-height: 92px;
}
.pick-btn:active { transform: scale(0.985); background: var(--accent-soft); }
.avatar {
  flex: none; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 1.4rem; font-weight: 700;
}
.pick-text { display: flex; flex-direction: column; }
.pick-name { font-size: 1.35rem; font-weight: 700; }
.pick-sub { color: var(--muted); font-weight: 500; font-size: 0.95rem; }

/* Betrag */
.amount-field {
  flex-direction: row; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 20px;
}
.amount-field:focus-within { outline: 2px solid var(--accent); }
.amount-field input {
  border: 0; outline: 0; background: transparent;
  font-size: 2.6rem; font-weight: 700; text-align: right; padding: 8px 8px 8px 0;
  font-variant-numeric: tabular-nums;
}
.amount-field input:focus { outline: 0; }
.currency { font-size: 2rem; font-weight: 600; color: var(--muted); }

/* Statistik */
.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 4px; gap: 4px;
}
.segmented button { background: transparent; color: var(--muted); padding: 10px 4px; border-radius: 9px; }
.segmented button.active { background: var(--accent); color: var(--accent-text); }

.total-card { margin-top: 14px; padding: 20px; display: flex; flex-direction: column; gap: 2px; }
.total-card strong { font-size: 2.3rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.list > .row { padding: 14px 16px; border-top: 1px solid var(--border); }
.list > .row:first-child { border-top: 0; }
.list > .empty { padding: 16px; color: var(--muted); }

.row-main { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row-main strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }
.bar { height: 6px; border-radius: 3px; background: var(--accent-soft); margin-top: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.entry-row { display: flex; align-items: center; gap: 8px; }
.entry-row .grow { flex: 1; min-width: 0; }

/* Team */
.team-row { display: flex; align-items: center; justify-content: space-between; }
.row-form { display: flex; gap: 8px; margin-top: 12px; }
.row-form input { flex: 1; min-width: 0; }

/* Tabbar */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
}
#tabbar button {
  background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.75rem; padding: 6px;
}
#tabbar button span { font-size: 1.3rem; line-height: 1; }
#tabbar button.active { color: var(--accent); }

/* Toast */
#toast {
  position: fixed; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 12px);
  max-width: 488px; margin: 0 auto;
  background: var(--ok); color: #fff;
  padding: 14px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 10;
}
#toast.error { background: var(--danger); }
.edit-btn { background: none; color: var(--accent); padding: 8px 10px; font-weight: 500; font-size: 0.9rem; }

/* Statistik-Tabellen */
.small-hint { font-size: 0.9rem; }
.table-card { padding: 4px 4px 0; overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats-table th {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); text-align: right; padding: 10px 10px 6px;
}
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table td { padding: 10px; border-top: 1px solid var(--border); white-space: nowrap; }
.stats-table td.num { text-align: right; }
.stats-table td.muted-cell { color: var(--muted); }
.stats-table tfoot td { font-weight: 700; border-top: 2px solid var(--text); }
.list .stats-table th, .list .stats-table td { padding-left: 4px; padding-right: 4px; }
.day-title { font-weight: 700; margin-bottom: 4px; }
.table-card { padding: 4px 12px 0; overflow-x: visible; }
.stats-table { font-size: 0.95rem; }
.stats-table th, .stats-table td { padding-left: 4px; padding-right: 4px; }
.stats-table th:first-child, .stats-table td:first-child { padding-left: 0; }
.stats-table th:last-child, .stats-table td:last-child { padding-right: 0; }

/* ---------- Rollen, PIN, Offline, Diagramm, Protokoll ---------- */
.center { text-align: center; align-self: center; }

.banner {
  position: sticky; top: 0; z-index: 5;
  background: #b7791f; color: #fff;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  font-size: 0.9rem; font-weight: 600; text-align: center;
}

.pin-dots { display: flex; justify-content: center; gap: 14px; min-height: 18px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.filled { background: var(--accent); border-color: var(--accent); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font-size: 1.5rem; font-weight: 600; padding: 16px 0; border-radius: 14px;
}
.pin-key:active { background: var(--accent-soft); }
.pin-del { font-size: 1.2rem; color: var(--muted); }

.admin-link { display: block; margin: 32px auto 0; color: var(--muted); }

.day-nav { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; margin-top: 12px; align-items: stretch; }
.day-nav > button {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font-size: 1.5rem; padding: 0; line-height: 1;
}
.day-picker {
  position: relative; flex-direction: row; justify-content: center; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  font-weight: 600; padding: 12px; min-height: 48px;
}
/* Unsichtbares Datumsfeld über der Beschriftung öffnet den nativen Kalender */
.day-picker input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; padding: 0; border: 0; }

.compare { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-top: 6px; }
.compare.up { color: var(--ok); }
.compare.down { color: var(--danger); }

.chart-card { padding: 12px 12px 8px; position: relative; }
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; }
.chart .bar { fill: var(--accent); }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: var(--muted); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--accent-soft); fill-opacity: 0.35; }
.chart-tip {
  position: absolute; top: 8px; right: 12px;
  background: var(--text); color: var(--bg);
  font-size: 0.85rem; font-weight: 600; padding: 6px 10px; border-radius: 8px; pointer-events: none;
}
.tiny { font-size: 0.8rem; margin: 6px 0 0; }

.day-row .day-title {
  background: none; color: var(--accent); padding: 0 0 4px; font-weight: 700; font-size: 1rem; text-align: left;
}

.badge {
  display: inline-block; margin-left: 8px; padding: 1px 6px; border-radius: 6px;
  background: var(--accent-soft); color: var(--text); font-size: 0.75rem; font-weight: 600;
}

.export-row { display: grid; gap: 8px; }
.export-row .secondary { margin-top: 0; }

.log-row { display: flex; gap: 12px; align-items: flex-start; }
.log-icon {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--bg); color: var(--muted); font-weight: 700;
}
.log-row.warn .log-icon { background: var(--accent-soft); color: var(--accent); }

#pw-form { margin-top: 0; }
#toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#toast-action {
  background: rgba(255, 255, 255, 0.2); color: #fff; padding: 8px 12px; border-radius: 8px; flex: none;
}
#tabbar { grid-template-columns: repeat(4, 1fr); }
