:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --line: #e6e1d6;
  --text: #1f1e1b;
  --muted: #6d685e;
  --accent: #2b4a3f;
  --accent-ink: #ffffff;
  --gold: #e9b949;
  --danger: #b4372f;
  --danger-bg: #fbe4e1;
  --warn: #8a5a00;
  --warn-bg: #fff2cc;
  --ok: #2e6b3a;
  --ok-bg: #e2f0d9;
  --prov: #5c5c5c;
  --prov-bg: #ededed;
  --weekend: #f1ede4;
  --shadow: 0 1px 2px rgba(31, 30, 27, .06), 0 4px 16px rgba(31, 30, 27, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1b19; --surface: #262522; --surface-2: #2d2b28; --line: #3b3935;
    --text: #efece6; --muted: #a8a397; --accent: #8cc2a8; --accent-ink: #13231c;
    --danger: #f08a80; --danger-bg: #43231f; --warn: #f0c46a; --warn-bg: #3d3220;
    --ok: #9ad1a5; --ok-bg: #22362a; --prov: #c4c4c4; --prov-bg: #34332f; --weekend: #23221f;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px;
  padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 12px;
}
.login-card.wide { max-width: 520px; }
.login-card h1 { margin: 4px 0 0; font-size: 24px; }
.login-card p { margin: 0; }
.login-card fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.login-card legend { padding: 0 6px; font-weight: 600; }
.alert { background: var(--danger-bg); color: var(--danger); padding: 8px 12px; border-radius: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 16px; color: var(--text); }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 10px;
  cursor: pointer; min-height: 44px; font-weight: 500;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar-inner { max-width: 960px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-right: auto; }
.brand img { width: 30px; height: 30px; }
.iconbtn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center; color: var(--muted);
}
.iconbtn:hover { background: var(--surface); }
.iconbtn svg { width: 20px; height: 20px; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 4px; }
.tabs a {
  text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 10px; font-weight: 500;
  display: flex; align-items: center; gap: 6px; position: relative;
}
.tabs a svg { width: 20px; height: 20px; }
.tabs a.active { color: var(--accent); background: var(--surface); box-shadow: var(--shadow); }
.tabs .badge {
  background: var(--danger); color: #fff; font-size: 11px; border-radius: 99px; padding: 0 6px; line-height: 17px; min-width: 17px; text-align: center;
}

main.view { max-width: 960px; margin: 0 auto; padding: 16px 16px 120px; }
h2 { font-size: 22px; margin: 8px 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
h3 .count { font-weight: 500; }

@media (max-width: 760px) {
  .topbar .tabs { display: none; }
  .bottomnav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface);
    border-top: 1px solid var(--line); padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
  }
  .bottomnav .tabs { justify-content: space-around; }
  .bottomnav .tabs a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; align-items: center; }
  .bottomnav .tabs a.active { box-shadow: none; background: transparent; }
  .bottomnav .tabs .badge { position: absolute; top: 2px; left: 50%; margin-left: 6px; }
}
@media (min-width: 761px) { .bottomnav { display: none; } }

/* ---------- Filter-Chips ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px;
  white-space: nowrap; cursor: pointer; font-size: 14px; min-height: 34px; display: inline-flex; align-items: center; gap: 6px;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--muted)); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Karten & Listen ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list > .row + .row { border-top: 1px solid var(--line); }
.row {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; position: relative;
  border-left: 4px solid var(--c, transparent); cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row.weekend { background: var(--weekend); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow-wrap: anywhere; }
.row .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.row .date { width: 92px; flex: none; font-variant-numeric: tabular-nums; }
.row .date b { display: block; font-weight: 600; }
.row .date span { font-size: 13px; color: var(--muted); }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.row.tentative .title { font-style: italic; color: var(--muted); }
.row.info .title { color: var(--muted); }
.row.google { cursor: default; }
.row.google:hover { background: inherit; }
.row.google.weekend:hover { background: var(--weekend); }

.check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); flex: none; margin-top: 1px;
  display: grid; place-items: center; background: var(--surface); cursor: pointer; padding: 0;
}
.check svg { width: 16px; height: 16px; opacity: 0; color: #fff; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on svg { opacity: 1; color: var(--accent-ink); }

.tag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--c);
  white-space: nowrap;
}
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill.offen { background: var(--danger-bg); color: var(--danger); }
.pill.provisorisch { background: var(--prov-bg); color: var(--prov); }
.pill.teilweise { background: var(--warn-bg); color: var(--warn); }
.pill.geloest { background: var(--ok-bg); color: var(--ok); }
.pill.g { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
.warn { color: var(--danger); font-weight: 600; }
.overdue { color: var(--danger); font-weight: 600; }
.due-soon { color: var(--warn); font-weight: 600; }
.ctx { margin-top: 6px; font-size: 13px; color: var(--muted); display: grid; gap: 2px; }
.ctx .tag { font-weight: 500; }

.month { position: sticky; top: 0; }
.empty { padding: 18px; text-align: center; color: var(--muted); }

/* Übersicht */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 4px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; text-decoration: none; color: inherit; }
.kpi b { font-size: 26px; display: block; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi.alert-kpi b { color: var(--danger); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 760px) { .cols { grid-template-columns: 1fr; } .kpi b { font-size: 22px; } }
.dayhead { padding: 8px 14px; font-size: 13px; font-weight: 600; background: var(--surface-2); border-left: 4px solid transparent; }
.dayhead.today { color: var(--accent); }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 15;
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 20px rgba(0,0,0,.2); cursor: pointer; display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }
@media (min-width: 761px) { .fab { bottom: 28px; right: max(28px, calc(50vw - 480px + 28px)); } }

/* Dialog */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(20, 18, 15, .45); }
dialog form { display: grid; gap: 12px; padding: 20px; }
dialog h2 { margin: 0 0 4px; font-size: 19px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
dialog .actions .left { margin-right: auto; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { display: inline-flex; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { border: 1px solid var(--line); padding: 7px 12px; border-radius: 99px; cursor: pointer; color: var(--text); font-size: 14px; }
.seg input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.checkline { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); }
.stamp { font-size: 12px; color: var(--muted); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 90px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 100;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow); font-size: 14px;
}
.toast.err { background: var(--danger); color: #fff; }

/* Einstellungen */
.settings section { margin-bottom: 8px; }
.settings .card { padding: 16px; display: grid; gap: 12px; }
.cal-item { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.cal-item .main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.steps li { margin: 2px 0; }
code { background: var(--surface-2); border: 1px solid var(--line); padding: 0 4px; border-radius: 5px; font-size: 13px; }
a.btn { color: inherit; text-decoration: none; display: inline-flex; align-items: center; }
.settings .card > div:has(> .btn) { display: flex; flex-wrap: wrap; gap: 8px; }
