/* =========================================================================
   Haushalt – Styles
   Mobile-first. Light/Dark über [data-theme] am <html> (von app.js gesetzt).
   ========================================================================= */

:root {
  --bg:        #f4f5f8;
  --bg-elev:   #ffffff;
  --bg-sunk:   #eceef3;
  --line:      #e2e5ec;
  --line-soft: #eef0f5;
  --text:      #171a21;
  --text-dim:  #6b7280;
  --text-mute: #9aa1ad;

  --accent:      #5b6cff;
  --accent-soft: #eaecff;
  --accent-text: #ffffff;
  --ok:          #16a34a;
  --ok-soft:     #e4f7ea;
  --warn:        #d97706;
  --warn-soft:   #fdf0dc;
  --danger:      #dc2626;
  --danger-soft: #fdeaea;
  --gold:        #eab308;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --shadow-sm: 0 1px 2px rgba(16, 20, 35, .06), 0 1px 3px rgba(16, 20, 35, .04);
  --shadow-md: 0 4px 16px rgba(16, 20, 35, .08);
  --shadow-lg: 0 12px 40px rgba(16, 20, 35, .16);

  --topbar-h: 56px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

[data-theme="dark"] {
  --bg:        #0f1117;
  --bg-elev:   #181b24;
  --bg-sunk:   #14171f;
  --line:      #272b37;
  --line-soft: #21242e;
  --text:      #e9ecf3;
  --text-dim:  #9aa3b2;
  --text-mute: #6d7686;

  --accent:      #7d8bff;
  --accent-soft: #232842;
  --accent-text: #0f1117;
  --ok:          #34d17d;
  --ok-soft:     #16281f;
  --warn:        #f0a83c;
  --warn-soft:   #2b2114;
  --danger:      #f4736f;
  --danger-soft: #2c1719;
  --gold:        #facc15;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
h1, h2, h3, h4, p, ul, ol { margin: 0; }
ul, ol { list-style: none; padding: 0; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------ Onboarding */

.onboarding {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b));
  background: radial-gradient(120% 80% at 50% 0%, var(--accent-soft) 0%, var(--bg) 62%);
}
.onboarding-inner { width: 100%; max-width: 420px; }
.brand { text-align: center; margin-bottom: 24px; }
.brand-icon { border-radius: 18px; box-shadow: var(--shadow-md); }
.brand h1 { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin-top: 12px; }
.brand-sub { color: var(--text-dim); font-size: 15px; margin-top: 4px; }
.onboarding-card { display: grid; gap: 18px; }
.onboarding-actions { display: grid; gap: 8px; margin-top: 2px; }
.ob-step { display: grid; gap: 18px; }
#obStepWho { gap: 8px; }

.who-list { display: grid; gap: 8px; margin-top: 4px; }
.who-btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; text-align: left;
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: transform .1s, border-color .15s;
}
.who-btn:active { transform: scale(.98); border-color: var(--accent); }
.who-emoji {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  display: grid; place-items: center; font-size: 21px;
}
.who-name { flex: 1; font-size: 16px; font-weight: 680; letter-spacing: -.01em; }
.who-go { color: var(--text-mute); font-size: 20px; flex: none; }
.onboarding-hint {
  color: var(--text-mute); font-size: 13px; text-align: center;
  margin-top: 18px; line-height: 1.5;
}

/* ---------------------------------------------------------------- Layout */

.app { min-height: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) 14px 0 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-title {
  font-size: 18px; font-weight: 750; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-right { display: flex; gap: 2px; flex: none; }
.sync-state { font-size: 10px; color: var(--text-mute); flex: none; transition: color .2s; }
.sync-state.is-busy { color: var(--accent); }
.sync-state.is-off { color: var(--warn); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 19px;
  transition: background .15s;
}
.icon-btn:active { background: var(--bg-sunk); }

.view {
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 88px);
  max-width: 720px; margin: 0 auto;
  outline: none;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--text-mute);
  transition: color .15s;
}
.tab-ico { font-size: 20px; line-height: 1; filter: grayscale(1) opacity(.55); transition: filter .15s, transform .15s; }
.tab.is-active { color: var(--accent); }
.tab.is-active .tab-ico { filter: none; transform: translateY(-1px) scale(1.06); }

.fab {
  position: fixed; right: 18px; z-index: 46;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border-radius: 20px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 42%, transparent);
  transition: transform .12s;
}
.fab:active { transform: scale(.93); }

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

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.section { margin-bottom: 22px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin: 0 4px 9px;
}
.section-title {
  font-size: 13px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim);
}
.section-title.is-overdue { color: var(--danger); }
.section-count { font-size: 12px; font-weight: 650; color: var(--text-mute); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 18px; border-radius: var(--r-md);
  font-size: 15px; font-weight: 650; letter-spacing: -.01em;
  background: var(--bg-sunk); color: var(--text);
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 13px; font-size: 13.5px; border-radius: 11px; }

.field { display: grid; gap: 7px; }
.field-label {
  font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
  color: var(--text-dim); text-transform: uppercase;
}
.field-hint { font-size: 12.5px; color: var(--text-mute); line-height: 1.4; }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 12px 14px;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 16px; /* verhindert iOS-Zoom beim Fokus */
  appearance: none; -webkit-appearance: none;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}
.form-error {
  background: var(--danger-soft); color: var(--danger);
  padding: 10px 13px; border-radius: var(--r-md); font-size: 14px; font-weight: 600;
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-btn {
  padding: 8px 13px; border-radius: 999px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  font-size: 13.5px; font-weight: 600; color: var(--text-dim);
  transition: background .12s, color .12s, border-color .12s;
}
.chip-btn.is-on {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-text);
}
.emoji-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-opt {
  width: 42px; height: 42px; border-radius: 12px; font-size: 21px;
  display: grid; place-items: center;
  background: var(--bg-sunk); border: 2px solid transparent;
}
.emoji-opt.is-on { border-color: var(--accent); background: var(--accent-soft); }

/* ------------------------------------------------------------- Aufgaben */

.task-list { display: grid; gap: 8px; }

.task {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px 12px 12px;
  box-shadow: var(--shadow-sm);
  transition: opacity .25s, transform .25s, background .15s;
}
.task.is-overdue { border-color: color-mix(in srgb, var(--danger) 34%, var(--line)); }
.task.is-done { opacity: 0; transform: translateX(38px) scale(.96); }
.task.is-archived { opacity: .55; }

.check {
  position: relative;
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 2.2px solid var(--line);
  background: transparent;
  display: grid; place-items: center;
  transition: background .15s, border-color .15s, transform .12s;
}
/* Tippfläche auf 46px vergrößern, ohne den Kreis größer zu machen. */
.check::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.check::after {
  content: ""; width: 11px; height: 6px;
  border-left: 2.4px solid var(--accent-text);
  border-bottom: 2.4px solid var(--accent-text);
  transform: rotate(-45deg) scale(.3); opacity: 0;
  transition: transform .15s, opacity .15s;
  margin-top: -2px;
}
.check:active { transform: scale(.86); }
.check.is-on { background: var(--ok); border-color: var(--ok); }
.check.is-on::after { transform: rotate(-45deg) scale(1); opacity: 1; }
.task.is-overdue .check { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }

.task-main { flex: 1; min-width: 0; text-align: left; }
.task-title {
  font-size: 15.5px; font-weight: 620; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px 8px;
  margin-top: 3px; font-size: 12.5px; color: var(--text-mute);
}
.meta-room { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: var(--room-c, var(--text-dim)); }
.meta-due { font-weight: 650; }
.meta-due.is-overdue { color: var(--danger); }
.meta-due.is-today { color: var(--ok); }
.meta-sep { color: var(--line); }

.task-points {
  flex: none; font-size: 13px; font-weight: 750;
  color: var(--accent); background: var(--accent-soft);
  padding: 4px 9px; border-radius: 9px;
}

.empty {
  text-align: center; padding: 34px 20px;
  color: var(--text-mute);
}
.empty-emoji { font-size: 40px; display: block; margin-bottom: 10px; }
.empty-title { font-weight: 700; color: var(--text-dim); font-size: 15px; }
.empty-sub { font-size: 13.5px; margin-top: 4px; line-height: 1.5; }

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

.hero { margin-bottom: 20px; }
.hero-date { font-size: 13px; font-weight: 650; color: var(--text-mute); text-transform: capitalize; }
.hero-greet { font-size: 25px; font-weight: 800; letter-spacing: -.025em; margin-top: 1px; }

.hero-stats { display: flex; gap: 8px; margin-top: 14px; }
.stat {
  flex: 1; background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 11px 12px; box-shadow: var(--shadow-sm);
}
.stat-val { font-size: 20px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.stat-lbl { font-size: 11.5px; font-weight: 600; color: var(--text-mute); margin-top: 1px; }

.race { margin-top: 12px; }
.race-bar {
  height: 10px; border-radius: 99px; overflow: hidden;
  display: flex; background: var(--bg-sunk); border: 1px solid var(--line);
}
.race-seg { transition: width .5s cubic-bezier(.4,0,.2,1); }
.race-legend {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 7px; font-size: 12.5px; font-weight: 620; color: var(--text-dim);
}
.race-legend span { display: inline-flex; align-items: center; gap: 5px; }
.race-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ----------------------------------------------------------------- Räume */

.room-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .room-grid { grid-template-columns: repeat(3, 1fr); } }

.room-card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px; text-align: left;
  box-shadow: var(--shadow-sm);
  display: grid; gap: 3px;
  border-top: 3px solid var(--room-c, var(--accent));
  transition: transform .12s;
}
.room-card:active { transform: scale(.975); }
.room-emoji { font-size: 26px; line-height: 1.1; }
.room-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.room-sub { font-size: 12.5px; color: var(--text-mute); }
.room-sub .is-overdue { color: var(--danger); font-weight: 650; }
.room-card.is-add {
  border: 1.5px dashed var(--line); border-top: 1.5px dashed var(--line);
  background: transparent; box-shadow: none; place-content: center; text-align: center;
  color: var(--text-mute); font-weight: 650; min-height: 96px;
}

/* --------------------------------------------------------------- Punkte */

.period-switch {
  display: grid; grid-auto-flow: column; gap: 3px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: 13px; padding: 3px; margin-bottom: 16px;
}
.period-switch button {
  padding: 8px; border-radius: 10px; font-size: 13.5px; font-weight: 650;
  color: var(--text-dim); transition: background .15s, color .15s;
}
.period-switch button.is-on { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

.score-list { display: grid; gap: 10px; }
.score-row {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.score-row.is-leader { border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }
.score-top { display: flex; align-items: center; gap: 10px; }
.score-avatar {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  font-size: 21px; background: var(--bg-sunk); flex: none;
}
.score-name { font-weight: 720; font-size: 16px; flex: 1; letter-spacing: -.01em; }
.score-pts { font-size: 21px; font-weight: 820; letter-spacing: -.03em; }
.score-pts small { font-size: 12px; font-weight: 650; color: var(--text-mute); margin-left: 3px; }
.score-meter { height: 8px; border-radius: 99px; background: var(--bg-sunk); margin-top: 11px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 99px; transition: width .5s cubic-bezier(.4,0,.2,1); }
.score-sub { font-size: 12.5px; color: var(--text-mute); margin-top: 7px; }

.history { display: grid; gap: 2px; }
.hist-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--line-soft);
}
.hist-row:last-child { border-bottom: none; }
.hist-emoji { font-size: 17px; flex: none; }
.hist-main { flex: 1; min-width: 0; }
.hist-title { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-sub { font-size: 12px; color: var(--text-mute); }
.hist-pts { font-size: 13px; font-weight: 700; color: var(--ok); flex: none; }
.hist-undo { font-size: 12.5px; font-weight: 650; color: var(--text-mute); padding: 11px 10px; border-radius: 9px; flex: none; }
.hist-undo:active { background: var(--bg-sunk); }

.bar-list { display: grid; gap: 9px; }
.bar-item { display: grid; gap: 5px; }
.bar-head { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 620; }
.bar-head span:last-child { color: var(--text-mute); font-weight: 650; }
.bar-track { height: 7px; border-radius: 99px; background: var(--bg-sunk); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }

/* ---------------------------------------------------------------- Sheet */

.sheet { position: fixed; inset: 0; z-index: 90; display: flex; align-items: flex-end; }
.sheet-backdrop {
  position: absolute; inset: 0; background: rgba(10, 12, 20, .48);
  animation: fade .2s ease;
}
.sheet-panel {
  position: relative; width: 100%; max-width: 560px; margin: 0 auto;
  max-height: 92vh; max-height: 92dvh;
  background: var(--bg-elev);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: slideUp .26s cubic-bezier(.22, 1, .36, 1);
}
.sheet-grip { padding: 11px 0 5px; display: grid; place-items: center; flex: none; }
.sheet-grip::before { content: ""; width: 38px; height: 4px; border-radius: 99px; background: var(--line); }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 6px 20px calc(24px + var(--safe-b));
}
.sheet-title { font-size: 20px; font-weight: 780; letter-spacing: -.02em; margin-bottom: 16px; }
.sheet-form { display: grid; gap: 17px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }
.sheet-list { display: grid; gap: 2px; margin: 0 -6px; }
.sheet-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 6px; text-align: left;
  border-bottom: 1px solid var(--line-soft);
  font-size: 15px; font-weight: 600;
}
.sheet-item:last-child { border-bottom: none; }
.sheet-item .sheet-item-sub { font-size: 12.5px; font-weight: 500; color: var(--text-mute); }
.sheet-item-ico { font-size: 19px; width: 26px; text-align: center; flex: none; }
.sheet-item-main { flex: 1; min-width: 0; }
.sheet-item-val { color: var(--text-mute); font-size: 13.5px; font-weight: 600; flex: none; }

.code-box {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 22px; font-weight: 700; letter-spacing: .12em;
  background: var(--bg-sunk); border: 1px dashed var(--line);
  border-radius: var(--r-md); padding: 16px 10px; text-align: center;
  user-select: all;
}

.seg { display: grid; grid-auto-flow: column; gap: 3px; background: var(--bg-sunk); border-radius: 12px; padding: 3px; }
.seg button { padding: 9px 6px; border-radius: 9px; font-size: 13.5px; font-weight: 640; color: var(--text-dim); }
.seg button.is-on { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

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

.toast {
  position: fixed; z-index: 100;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  width: calc(100% - 32px); max-width: 440px;
  display: flex; align-items: center; gap: 12px;
  background: #1c2029; color: #f4f6fa;
  border-radius: var(--r-md); padding: 13px 15px;
  font-size: 14.5px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toastIn .24s cubic-bezier(.22, 1, .36, 1);
}
[data-theme="dark"] .toast { background: #2a2f3d; }
.toast span { flex: 1; }
.toast-action {
  font-size: 14px; font-weight: 750; color: #8f9dff;
  padding: 5px 8px; margin: -5px -6px -5px 0; border-radius: 8px; flex: none;
}

/* --------------------------------------------------------------- Konfetti */

.burst { position: fixed; inset: 0; pointer-events: none; z-index: 95; overflow: hidden; }
.burst i {
  position: absolute; width: 8px; height: 8px; border-radius: 2px;
  animation: confetti .9s cubic-bezier(.2, .7, .4, 1) forwards;
}

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px) } to { opacity: 1; transform: translate(-50%, 0) } }
@keyframes confetti {
  from { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
  to   { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(.4); }
}
