:root {
  --bg: #f6f8f6;
  --surface: #ffffff;
  --ink: #1d2823;
  --muted: #66766e;
  --line: #e1e8e3;
  --basil: #2f6b4f;
  --basil-soft: #e2eee6;
  --on-basil: #ffffff;
  --tomato: #c4462e;
  --tomato-soft: #fbe7e2;
  --done: #9aa8a1;
  --radius-row: 14px;
  --radius-pill: 999px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151b18;
    --surface: #1d2521;
    --ink: #e7eee9;
    --muted: #9aaba2;
    --line: #2c3631;
    --basil: #73c39a;
    --basil-soft: #24362c;
    --on-basil: #102018;
    --tomato: #f08a72;
    --tomato-soft: #3a231d;
    --done: #64736b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--basil); outline-offset: 2px; }

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

#view {
  flex: 1;
  padding: max(12px, env(safe-area-inset-top)) 16px 96px;
}

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0 12px;
}

.top h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }

.icon-btn {
  min-width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 22px;
  color: var(--muted);
}

/* ---------- Chips (Geschäfte, Filter) ---------- */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -16px 12px;
  padding: 2px 16px 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}
.chip[aria-pressed="true"] {
  background: var(--basil);
  border-color: var(--basil);
  color: var(--on-basil);
  font-weight: 700;
}
.chip .count { font-size: 14px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.chip.add { color: var(--muted); border-style: dashed; }

/* ---------- Eingabe ---------- */

.add-form { display: flex; gap: 8px; }

.add-form input,
.field input,
.field select {
  min-width: 0;
  height: 52px;
  padding: 0 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--surface);
  font-size: 18px;
}
.add-form input { flex: 1; }
.add-form input:focus,.field input:focus, .field select:focus {
  border-color: var(--basil);
  outline: none;
}

.add-btn {
  width: 52px;
  height: 52px;
  flex: none;
  border: 0;
  border-radius: var(--radius-row);
  background: var(--basil);
  color: var(--on-basil);
  font-size: 28px;
  line-height: 1;
}

.mic-btn {
  width: 52px;
  height: 52px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-row);
  background: var(--surface);
  color: var(--basil);
}
.mic-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; }
.mic-btn.recording {
  border-color: var(--tomato);
  background: var(--tomato);
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
.mic-btn.busy { color: var(--muted); }
.mic-btn.busy svg { animation: mic-wait 1s ease-in-out infinite alternate; }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--tomato-soft); }
  50% { box-shadow: 0 0 0 8px var(--tomato-soft); }
}
@keyframes mic-wait { to { opacity: 0.3; } }

.target {
  margin: 8px 0 0;
  border: 0;
  background: none;
  padding: 6px 0;
  color: var(--muted);
  font-size: 15px;
}
.target b { color: var(--basil); }

/* ---------- Listen ---------- */

.list { list-style: none; margin: 16px 0 0; padding: 0; }

.group-title {
  margin: 22px 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
}

.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  padding: 8px 4px;
  border: 0;
  background: none;
  text-align: left;
}

.check {
  flex: none;
  width: 28px;
  height: 28px;
  border: 2px solid var(--muted);
  border-radius: 9px;
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.check svg { width: 18px; height: 18px; stroke: var(--on-basil); stroke-width: 3.2; fill: none; stroke-dasharray: 24; stroke-dashoffset: 24; }

.row.done .check { background: var(--basil); border-color: var(--basil); }
.row.done .check svg { stroke-dashoffset: 0; transition: stroke-dashoffset 0.22s ease-out; }
.row.done .text { color: var(--done); text-decoration: line-through; text-decoration-thickness: 2px; }

.text { overflow-wrap: anywhere; }

.meta { display: block; font-size: 14px; color: var(--muted); }
.meta.overdue { color: var(--tomato); font-weight: 700; }

.tag {
  margin-left: auto;
  flex: none;
  font-size: 13px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--basil-soft);
  color: var(--ink);
}

.more {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
}

.empty { color: var(--muted); text-align: center; margin: 40px 0; }

.clear-done {
  display: block;
  margin: 18px auto 0;
  padding: 10px 18px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
}

/* ---------- Reiter unten ---------- */

#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs[hidden] { display: none; }
#tabs button {
  flex: 1;
  max-width: 300px;
  height: 64px;
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 14px;
  color: var(--muted);
}
#tabs button span { font-size: 22px; filter: grayscale(1); opacity: 0.7; }
#tabs button[aria-current="page"] { color: var(--basil); font-weight: 700; }
#tabs button[aria-current="page"] span { filter: none; opacity: 1; }

/* ---------- Login ---------- */

.login {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
}
.login h1 { font-size: 30px; margin: 0; }
.login p { margin: 0; color: var(--muted); }
.login input { text-align: center; letter-spacing: 0.2em; }
.primary {
  height: 52px;
  border: 0;
  border-radius: var(--radius-row);
  background: var(--basil);
  color: var(--on-basil);
  font-weight: 700;
  font-size: 18px;
}
.primary:disabled { opacity: 0.6; }
.error { color: var(--tomato); font-weight: 700; min-height: 1.4em; }

/* ---------- Sheets ---------- */

dialog.sheet {
  width: 100%;
  max-width: 600px;
  margin: auto auto 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--ink);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.35); }
dialog.sheet h2 { font-size: 19px; margin: 0 0 14px; overflow-wrap: anywhere; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }
.sheet-actions button {
  min-height: 50px;
  border: 0;
  border-radius: var(--radius-row);
  background: var(--bg);
  text-align: left;
  padding: 0 16px;
}
.sheet-actions button.danger { color: var(--tomato); }
.sheet-actions button.primary { background: var(--basil); color: var(--on-basil); text-align: center; }
.sheet-actions button.selected { font-weight: 700; color: var(--basil); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 15px; color: var(--muted); }
.field-row { display: flex; gap: 8px; }
.check-field { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 12px; }
.check-field input { width: 22px; height: 22px; accent-color: var(--basil); }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(480px, calc(100% - 32px));
  padding: 12px 18px;
  border-radius: var(--radius-row);
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
}
#toast[hidden] { display: none; }
#toast button {
  flex: none;
  min-height: 36px;
  border: 0;
  background: none;
  color: var(--basil-soft);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
}

/* ---------- Verwaltung ---------- */

.person-row { display: flex; align-items: center; min-height: 56px; border-bottom: 1px solid var(--line); gap: 8px; }
.person-row .name { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
.field-row input { flex: 1; }
