:root {
  --bg: #16130f;
  --surface: #211d17;
  --surface-2: #2b261e;
  --line: #3a3328;
  --text: #f3ece0;
  --muted: #a99d8a;
  --accent: #e8a628;
  --accent-ink: #1d1505;
  --danger: #e5534b;
  --ok: #4fb477;
  --info: #5aa7e0;
  --radius: 14px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f2ea; --surface: #fffdf8; --surface-2: #f0eadf; --line: #e2d9c8;
    --text: #241d12; --muted: #7a6e5c; --accent: #c98a0e; --accent-ink: #fff;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.splash { min-height: 100vh; display: grid; place-items: center; }
.splash img { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; transform: scale(.95); } }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar .brand img { width: 30px; height: 30px; border-radius: 8px; }
.topbar h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

main {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 24px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; position: relative;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }
.tabbar .badge { top: 6px; right: calc(50% - 22px); }

@media (min-width: 900px) {
  .tabbar { top: 0; bottom: 0; right: auto; width: 96px; height: auto; flex-direction: column; justify-content: flex-start; padding: calc(var(--safe-t) + 80px) 0 0; border-top: 0; border-right: 1px solid var(--line); }
  .tabbar a { flex: 0 0 76px; }
  .topbar, main { margin-left: 96px; }
  main { padding-bottom: 40px; }
}

/* ---------- Komponenten ---------- */
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 0 10px; }
.section-title:first-child { margin-top: 4px; }
.section-title h2 { font-size: 17px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.open { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }
.chip.offered { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.chip.mine { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); }
.chip.info { background: color-mix(in srgb, var(--info) 22%, transparent); color: var(--info); }

.segmented { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.segmented button { flex: 1; border: 0; background: none; padding: 7px 10px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface-2); color: var(--text); }

/* Formulare */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="color"] { padding: 4px; height: 44px; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; }

/* Dienst-Karten */
.shift {
  display: flex; gap: 12px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.shift .bar { width: 5px; border-radius: 3px; background: var(--muted); flex: none; }
.shift.is-open .bar { background: repeating-linear-gradient(45deg, var(--danger) 0 4px, transparent 4px 8px); }
.shift .body { flex: 1; min-width: 0; }
.shift .time { font-weight: 700; font-size: 17px; }
.shift .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.shift .who { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.shift .notes { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }
.shift .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.shift .date-col { text-align: center; min-width: 46px; flex: none; }
.shift .date-col .dow { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.shift .date-col .dom { font-size: 24px; font-weight: 800; line-height: 1.1; }
.shift .date-col .mon { font-size: 12px; color: var(--muted); }
.avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; flex: none; }

/* Kalender */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head h2 { flex: 1; font-size: 19px; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1 / 1.05; border-radius: 10px; border: 1px solid transparent; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; padding: 5px 2px; gap: 3px; cursor: pointer; min-width: 0;
}
.cal-day.other { opacity: .35; }
.cal-day.today .num { background: var(--accent); color: var(--accent-ink); }
.cal-day.selected { border-color: var(--accent); }
.cal-day .num { font-size: 14px; font-weight: 700; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; }
.cal-day .dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 100%; }
.cal-day .dot { width: 7px; height: 7px; border-radius: 50%; }
.cal-day .dot.open { background: transparent; box-shadow: inset 0 0 0 1.5px var(--danger); }
.cal-day.has-mine { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); }
.cal-day.has-open::after { content: ""; }

.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .big { font-size: 38px; margin-bottom: 6px; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 14px;
}
.notice .grow { flex: 1; }

.swap-card .arrow { font-size: 20px; color: var(--muted); text-align: center; }
.notif { padding: 12px 0; border-bottom: 1px solid var(--line); }
.notif.unread .title::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: middle; }

/* Sheet / Modal */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 18px calc(var(--safe-b) + 18px);
  animation: up .2s ease-out; -webkit-overflow-scrolling: touch;
}
.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h3 { font-size: 19px; margin-bottom: 14px; }
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; padding-bottom: 20px; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.pick-list { max-height: 50vh; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.pick { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--bg); margin-bottom: 6px; cursor: pointer; }
.pick.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }

/* Toast */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b) + 12px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3); animation: up .2s; max-width: 480px; }
.toast.error { background: var(--danger); color: #fff; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box .logo { display: block; margin: 0 auto 14px; width: 84px; height: 84px; border-radius: 20px; }
.auth-box h1 { text-align: center; font-size: 26px; margin-bottom: 4px; }
.auth-box p.sub { text-align: center; margin: 0 0 22px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.alert .n { color: var(--danger); }

/* Vorlagen-Editor: Felder dürfen im Grid schrumpfen */
[data-preset-row] input { min-width: 0; }

/* Neuer Dienst: Dienstart + Mehrfach-Tagesauswahl */
.label-sm { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.preset-row .btn.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--surface-2)); box-shadow: inset 0 0 0 1px var(--accent); }
.preset-row .btn .muted { font-weight: 500; }
.pick-cal .dow { border: 0; background: none; cursor: pointer; border-radius: 8px; }
.pick-cal .dow:hover { background: var(--surface-2); color: var(--text); }
.pick-day {
  aspect-ratio: 1 / 1; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  font-weight: 700; font-size: 15px; cursor: pointer; padding: 0; min-width: 0; line-height: 1.1;
}
.pick-day i { font-style: normal; font-size: 10px; letter-spacing: 1px; color: var(--muted); line-height: 1; }
.pick-day.today { border-color: var(--accent); }
.pick-day.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pick-day.on i { color: var(--accent-ink); }
.pick-day:disabled { opacity: .3; cursor: default; }
.pick-summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 14px; font-weight: 600; min-height: 34px; }
