:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #efe9e1;
  --line: #e4ddd3;
  --text: #22201d;
  --muted: #7b746a;
  --accent: #c9573a;
  --accent-soft: #f6e1d9;
  --danger: #c43d3d;
  --ok: #3d8a5a;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #211f1c;
    --surface-2: #2b2825;
    --line: #36322e;
    --text: #f2ede6;
    --muted: #a39b90;
    --accent: #e0714f;
    --accent-soft: #3a2620;
    --danger: #e06363;
    --ok: #5fb37d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea { font-size: 16px; } /* verhindert Zoom auf dem iPhone */

.splash { display: grid; place-items: center; height: 100vh; font-size: 28px; font-weight: 700; color: var(--accent); }

/* ---------- Grundgerüst ---------- */

.app { min-height: 100vh; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: calc(env(safe-area-inset-top) + 12px) 20px 10px;
}
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; font-weight: 750; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.topbar-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }

.view { padding: 4px 16px 0; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.tab .badge { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--accent); color: #fff; font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }

.fab {
  position: fixed; right: 18px; z-index: 21;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(201, 87, 58, .4);
  display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.94); }

/* ---------- Bausteine ---------- */

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
.section-title.danger { color: var(--danger); }
.section-title .link { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--accent); font-size: 14px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card + .card { margin-top: 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }

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

/* ---------- Einträge ---------- */

.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 0; position: relative; min-height: 60px; }
.item + .item { border-top: 1px solid var(--line); }
.item .bar { align-self: stretch; width: 5px; border-radius: 0 4px 4px 0; flex: none; }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 2px; align-items: center; }
.item.done .title { text-decoration: line-through; color: var(--muted); }
.item.skipped .title { color: var(--muted); font-style: italic; }
.item .time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }

.who { display: inline-flex; align-items: center; gap: 4px; }
.avatar { width: 18px; height: 18px; border-radius: 50%; color: #fff; font-size: 10px; font-weight: 700; display: inline-grid; place-items: center; flex: none; }
.avatar.both { background: linear-gradient(135deg, var(--c1) 50%, var(--c2) 50%); }

.check {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); display: grid; place-items: center; color: transparent;
  transition: background .15s, border-color .15s;
}
.check svg { width: 18px; height: 18px; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.icon-repeat { width: 13px; height: 13px; vertical-align: -2px; }
.tag-appt { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }

/* ---------- Kalender ---------- */

.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.cal-head h2 { margin: 0; font-size: 20px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); }
.icon-btn svg { width: 20px; height: 20px; }
.today-btn { font-size: 14px; font-weight: 600; color: var(--accent); padding: 8px 10px; }

.cal { padding: 8px 6px 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-wd { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0 6px; }
.cal-day { aspect-ratio: 1 / 1.05; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; gap: 4px; border-radius: 12px; font-size: 15px; font-variant-numeric: tabular-nums; }
.cal-day.other { color: var(--muted); opacity: .45; }
.cal-day .n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; }
.cal-day.today .n { background: var(--accent); color: #fff; }
.cal-day.sel { background: var(--accent-soft); }
.dots { display: flex; gap: 3px; height: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }

/* ---------- Einkauf ---------- */

.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; }
.add-row button { flex: none; width: 50px; border-radius: 14px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.add-row button svg { width: 24px; height: 24px; }
.shop .item { padding-left: 14px; }
.shop .item .title { white-space: normal; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Formulare ---------- */

.input, select.input, textarea.input {
  width: 100%; padding: 13px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
  -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 80px; resize: vertical; }
input[type="date"].input, input[type="time"].input { min-height: 50px; }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 22px, calc(100% - 14px) 22px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }

.field { margin-bottom: 14px; }
.field > label, .label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 4px 6px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.inline { display: flex; align-items: center; gap: 10px; }
.inline .input { width: 80px; flex: none; text-align: center; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg button svg { width: 17px; height: 17px; flex: none; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.cat-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-pick .chip.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface)); }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 3px solid transparent; box-shadow: inset 0 0 0 2px var(--surface); }
.swatch.on { border-color: var(--text); }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px; border-radius: 14px; font-weight: 700; font-size: 16px; background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); background: transparent; }
.btn.ok { background: var(--ok); color: #fff; }
.btn + .btn { margin-top: 8px; }
.btn:disabled { opacity: .5; }
.btn svg { width: 20px; height: 20px; }

/* ---------- Liste in "Mehr" ---------- */

.list-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%; text-align: left; }
.list-row + .list-row { border-top: 1px solid var(--line); }
.list-row .grow { flex: 1; }
.list-row .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.list-row .chev { width: 18px; height: 18px; color: var(--muted); }
.list-row.danger { color: var(--danger); font-weight: 600; }
.hint { font-size: 14px; color: var(--muted); padding: 14px 16px; line-height: 1.5; }

/* ---------- Sheet (Overlay von unten) ---------- */

.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .35); opacity: 0; transition: opacity .2s; }
.backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 92vh; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-head .x { font-weight: 600; color: var(--accent); padding: 6px 2px; }

.detail-color { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.detail-title { font-size: 24px; font-weight: 750; margin: 8px 0 12px; letter-spacing: -.01em; }
.detail-list { margin-bottom: 18px; }
.detail-list .list-row { padding: 12px 16px; }
.detail-list svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.notes { white-space: pre-wrap; }

/* ---------- Anmelden ---------- */

.auth { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 48px) 20px 40px; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin-bottom: 18px; box-shadow: var(--shadow); }
.auth h1 { font-size: 32px; margin: 0 0 4px; letter-spacing: -.02em; }
.auth p { color: var(--muted); margin: 0 0 24px; }
.auth h3 { margin: 22px 0 10px; font-size: 16px; }
.err { color: var(--danger); font-size: 14px; margin: 0 4px 12px; min-height: 1em; }

#toast {
  position: fixed; left: 50%; z-index: 100; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
