:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17202a;
  --muted: #5b6673;
  --border: #d8dde3;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --in: #15803d;
  --pause: #b45309;
  --out: #b91c1c;
  --warn-bg: #fff4e5;
  --warn-ink: #8a4b00;
  --note-bg: #eaf2ff;
  --note-ink: #1d4ed8;
  --ok-bg: #e7f6ec;
  --ok-ink: #166534;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #182028;
    --surface-2: #212b35;
    --text: #e6eaee;
    --muted: #9aa5b1;
    --border: #2e3a46;
    --brand: #14b8a6;
    --brand-ink: #062b28;
    --in: #22c55e;
    --pause: #f59e0b;
    --out: #f87171;
    --warn-bg: #3a2a10;
    --warn-ink: #fcd38d;
    --note-bg: #172a4a;
    --note-ink: #a8c7ff;
    --ok-bg: #12301f;
    --ok-ink: #86efac;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0.2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 0 0 0.4rem; }
p { margin: 0.4rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
[hidden] { display: none !important; }

.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 420px; margin: 0 auto; }

/* ---- Kopfzeile & Navigation ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand img { border-radius: 6px; }
#nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
#nav a {
  padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500;
}
#nav a.active { background: var(--surface-2); color: var(--text); }

@media (max-width: 699px) {
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  #nav a { flex: 1; text-align: center; padding: 8px 4px; font-size: 0.85rem; }
  body.has-nav main { padding-bottom: 90px; }
}

.subnav { display: flex; gap: 6px; overflow-x: auto; margin: -4px 0 16px; padding-bottom: 4px; }
.subnav a {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); text-decoration: none;
  color: var(--muted); white-space: nowrap; font-size: 0.9rem;
}
.subnav a.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---- Karten, Listen ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--brand); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row > input { width: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.in { background: var(--ok-bg); color: var(--ok-ink); }
.badge.pause { background: var(--warn-bg); color: var(--warn-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.danger { background: #fde8e8; color: #9b1c1c; }
@media (prefers-color-scheme: dark) { .badge.danger { background: #3b1717; color: #fca5a5; } }

.hint { padding: 8px 12px; border-radius: 8px; font-size: 0.9rem; margin: 6px 0; }
.hint.warn { background: var(--warn-bg); color: var(--warn-ink); }
.hint.note { background: var(--note-bg); color: var(--note-ink); }
.hint.ok { background: var(--ok-bg); color: var(--ok-ink); }

/* ---- Stempeln ---- */
.status { text-align: center; padding: 24px 16px; }
.status .state { font-size: 1.05rem; color: var(--muted); }
.status .clock { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin: 4px 0; }
.status .sub { color: var(--muted); font-size: 0.95rem; }
.stamp-buttons { display: grid; gap: 12px; margin: 16px 0; }
@media (min-width: 560px) { .stamp-buttons { grid-template-columns: repeat(3, 1fr); } }
.stamp {
  appearance: none; border: 0; border-radius: 16px; padding: 22px 12px; font-size: 1.25rem; font-weight: 700;
  color: #fff; cursor: pointer; min-height: 72px; transition: transform 0.05s, opacity 0.15s;
}
.stamp:active:not(:disabled) { transform: scale(0.98); }
.stamp.in { background: var(--in); }
.stamp.pause { background: var(--pause); }
.stamp.out { background: var(--out); }
.stamp:disabled { opacity: 0.28; cursor: not-allowed; }
@media (prefers-color-scheme: dark) { .stamp { color: #0b0f13; } }

/* ---- Formulare ---- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input.code { font-size: 1.6rem; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }

button, .btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 14px; min-height: 40px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
}
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--out); border-color: var(--out); background: transparent; }
button.link { border: 0; background: none; color: var(--brand); padding: 4px; min-height: 0; font-weight: 500; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.block { width: 100%; }
.error { color: var(--out); font-size: 0.92rem; min-height: 1.2em; }

/* ---- Tabellen ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.weekend td { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.ev { font-size: 0.85rem; color: var(--muted); }
.ev.voided { text-decoration: line-through; opacity: 0.7; }
.ev .tag { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; margin-left: 4px; }

.monthnav { display: flex; align-items: center; gap: 8px; }
.monthnav strong { min-width: 9.5em; text-align: center; }
.totals { display: flex; gap: 24px; flex-wrap: wrap; }
.totals div strong { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }

.qr { display: block; margin: 12px auto; background: #fff; padding: 8px; border-radius: 8px; width: 240px; height: 240px; }

/* ---- Dialog & Toast ---- */
dialog {
  border: 0; border-radius: 16px; padding: 20px; width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgb(0 0 0 / 30%);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h2 { margin-top: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.secret-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.3rem; padding: 12px; background: var(--surface-2); border-radius: 8px; text-align: center; user-select: all; word-break: break-all; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }
#toast.error { background: var(--out); color: #fff; }

.footer-links { text-align: center; margin-top: 24px; font-size: 0.9rem; }
.print-only { display: none; }

@media print {
  .topbar, #nav, .subnav, .no-print, button, .btn, #toast { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; padding: 0; }
  tr.weekend td { background: #f2f2f2; }
  .container { max-width: none; padding: 0; }
}
