:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #18202f;
  --muted: #5d6779;
  --line: #dde1e8;
  --brand: #1d2a44;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --warn: #b86e00;
  --ok: #1f8a4c;
  --prio-high: #d64545;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  --tabbar: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141d;
    --surface: #182030;
    --surface-2: #212b3d;
    --text: #e7ebf2;
    --muted: #97a1b3;
    --line: #2b3548;
    --brand: #0f141d;
    --accent: #6b9cff;
    --accent-text: #0b1220;
    --danger: #ff7a6b;
    --warn: #f0a640;
    --ok: #4cc584;
    --prio-high: #ff7070;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f141d;
  --surface: #182030;
  --surface-2: #212b3d;
  --text: #e7ebf2;
  --muted: #97a1b3;
  --line: #2b3548;
  --brand: #0f141d;
  --accent: #6b9cff;
  --accent-text: #0b1220;
  --danger: #ff7a6b;
  --warn: #f0a640;
  --ok: #4cc584;
  --prio-high: #ff7070;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "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; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px;
  padding: 28px 22px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { font-size: 1.3rem; margin: 12px 0 20px; }
.login-card .field { text-align: left; }
.login-logo { border-radius: 14px; }

/* ---------------------------------------------------------------- Layout */
.app { min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view-sub { color: var(--muted); font-size: .9rem; margin-right: auto; padding-left: 4px; white-space: nowrap; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); flex: none;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--surface-2); color: var(--text); }
#btn-back { margin-left: -8px; color: var(--accent); }

.search-bar { display: flex; gap: 10px; align-items: center; padding: 0 16px 10px; }
.search-bar input[type="search"] {
  flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}

.content {
  max-width: 720px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar) + var(--safe-bottom) + 88px);
}

/* ---------------------------------------------------------------- Abschnitte & Karten */
.section { margin: 14px 0 22px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: .8rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 0 4px 8px;
}
.section-head .count { font-weight: 500; }
.section.overdue .section-head { color: var(--danger); }
.section.done .card { opacity: .62; }
.section.done .card .title { text-decoration: line-through; }
.empty-day { color: var(--muted); font-size: .9rem; padding: 2px 4px 0; }

.list { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; align-items: stretch; gap: 12px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line); min-height: 58px; overflow: hidden;
}
.card .check {
  flex: none; width: 50px; display: grid; place-items: center; border: 0; background: transparent; padding: 0;
}
.card .check span {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center;
  transition: background .15s, border-color .15s;
}
.card .check:hover span { border-color: var(--accent); }
.card.prio-1 .check span { border-color: var(--prio-high); }
.card.is-done .check span { background: var(--ok); border-color: var(--ok); }
.card.is-done .check span::after { content: ""; width: 10px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.card .time {
  flex: none; width: 62px; padding: 10px 0 10px 12px; display: flex; flex-direction: column; justify-content: center;
  font-variant-numeric: tabular-nums; font-weight: 650; font-size: .95rem; color: var(--accent);
  border-right: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.card .time small { color: var(--muted); font-weight: 500; font-size: .78rem; }
.card .body {
  flex: 1; min-width: 0; padding: 10px 14px 10px 0; border: 0; background: transparent; text-align: left;
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.card .time + .body { padding-left: 2px; }
.card .title { font-weight: 550; overflow-wrap: anywhere; }
.card .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .82rem; color: var(--muted); }
.card .meta .overdue { color: var(--danger); font-weight: 600; }
.card .meta .prio { color: var(--prio-high); font-weight: 600; }
.card .meta .badge { background: var(--surface-2); border-radius: 6px; padding: 0 6px; }
.card .note-flag { color: var(--muted); }

.empty {
  text-align: center; color: var(--muted); padding: 56px 16px;
}
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

/* Bereiche */
.area-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.area-tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 96px;
}
.area-tile .name { font-weight: 650; }
.area-tile .num { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.area-tile .breakdown { color: var(--muted); font-size: .78rem; }

/* ---------------------------------------------------------------- Tabbar & FAB */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: .7rem; font-weight: 550; min-width: 0;
}
.tab span { white-space: nowrap; }
.tab[aria-current="page"] { color: var(--accent); }
.fab {
  position: fixed; z-index: 21; right: max(16px, calc(50vw - 344px)); bottom: calc(var(--tabbar) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(30, 60, 140, .3);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* ---------------------------------------------------------------- Formulare */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; flex: 1; }
.field > span { font-size: .8rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  min-height: 44px;
}
.field textarea { resize: vertical; min-height: 72px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.row { display: flex; gap: 10px; }
.check-inline { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); margin-bottom: 10px; white-space: nowrap; }
.check-inline input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: .78rem; color: var(--muted); margin: 0 0 12px; }
.error { color: var(--danger); font-size: .9rem; margin: 0 0 12px; }

.btn {
  border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 600; min-height: 44px; background: var(--surface-2);
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; color: var(--accent); padding-inline: 10px; }
.btn-ghost.danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; }

.segmented {
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); border-radius: 12px; padding: 3px;
  margin-bottom: 14px;
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block; text-align: center; padding: 8px 2px; border-radius: 9px; font-size: .85rem; font-weight: 600; color: var(--muted);
  white-space: nowrap;
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.move-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 14px; font-size: .85rem; color: var(--muted); }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: .85rem; font-weight: 550; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- Dialog */
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--text);
}
.sheet::backdrop { background: rgba(8, 12, 20, .45); }
.sheet form { padding: 14px 16px calc(16px + var(--safe-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 1.15rem; margin: 0; }
.sheet-foot { display: flex; align-items: center; gap: 4px; position: sticky; bottom: 0; background: var(--bg); padding-top: 6px; }
.spacer { flex: 1; }
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 20px; }
}

/* ---------------------------------------------------------------- Toast */
.toast {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + var(--safe-bottom) + 84px);
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  background: #1d2433; color: #fff; padding: 10px 14px 10px 16px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  font-size: .9rem;
}
.toast button { border: 0; background: transparent; color: #8fb4ff; font-weight: 650; padding: 4px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
