/* ── HomePlan — native-feel PWA styling ─────────────────────────────────── */
:root {
  --bg: #0b1020;
  --bg-elev: #141b32;
  --bg-elev2: #1c2542;
  --text: #eef1f8;
  --muted: #9aa3bd;
  --primary: #6366f1;
  --primary-2: #0ea5e9;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #eab308;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb; --bg-elev: #ffffff; --bg-elev2: #eef1f8;
    --text: #121826; --muted: #5b647d;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Native feel: no bounce, no pull-to-refresh, no text selection, no zoom */
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  overscroll-behavior-y: none;   /* no rubber-band, but NORMAL document scroll */
}
/* Normal document scroll (NOT a fixed overflow:hidden app-shell). The fixed
   shell was what made iOS report env(safe-area-inset-*) as 0 in portrait —
   this matches the known-good approach: body scrolls, safe-area works. */
body { min-height: 100vh; }
input, textarea { -webkit-user-select: text; user-select: text; }
a { color: var(--primary-2); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 18px; }

/* ── Auth ─────────────────────────────────────────────────────────────── */
.auth { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--bg-elev);
  border-radius: 20px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.brand { font-size: 28px; font-weight: 800; }
.auth-card input {
  width: 100%; margin-top: 12px; padding: 14px; border-radius: 12px;
  border: 1px solid var(--bg-elev2); background: var(--bg-elev2); color: var(--text);
  font-size: 16px;
}
/* Breathing room between the last field and the submit button. */
.auth-card .btn.primary { margin-top: 22px; }
.auth-toggle { text-align: center; margin-top: 14px; }

/* ── App shell (normal document scroll) ───────────────────────────────── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid rgba(255,255,255,.06);
}
.topbar-title { flex: 1; text-align: center; font-weight: 700; font-size: 17px; }
.hh-pill {
  background: var(--bg-elev2); color: var(--text); border: none;
  padding: 8px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn {
  position: relative; background: none; border: none; color: var(--text);
  font-size: 20px; padding: 6px;
}
.badge {
  position: absolute; top: -2px; right: -2px; background: var(--danger);
  color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px;
  display: grid; place-items: center; padding: 0 4px;
}

.view {
  flex: 1; padding: 16px;
  /* clear the fixed tab bar (~64px) + home-indicator inset */
  padding-bottom: calc(84px + var(--safe-bottom));
}

/* ── Bottom tab bar ───────────────────────────────────────────────────── */
/* Pinned to the PHYSICAL bottom edge. Fixed + bottom:0 + safe-area padding is
   the reliable way to keep it on the iPhone's bottom in a standalone PWA
   (dvh/flex alone leaves a gap because iOS reserves the home-indicator inset). */
.tabbar {
  /* Fixed to the cover-viewport's physical bottom. With no position:fixed on
     body and no transform/filter ancestor, the containing block is the ICB =
     the full (edge-to-edge) screen, so bottom:0 is the true bottom even when
     100dvh comes up short. Safe-area padding fills the home-indicator strip. */
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  /* With normal document scroll, iOS reports env(safe-area-inset-bottom)
     correctly, so this padding fills the home-indicator strip in the bar's own
     colour and the bar sits flush on the physical bottom. */
  background: var(--bg-elev);
  border-top: 1px solid rgba(128,140,170,.18);
  padding-bottom: max(var(--safe-bottom), 8px);
}
@media (prefers-color-scheme: light) { .tabbar { background: #ffffff; } }
.tab {
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 48px; padding: 10px 0 8px; font-size: 11px;
}
.tab span { font-size: 22px; }
.tab.active { color: var(--primary-2); }

/* ── Cards / lists ────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elev); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin: 18px 4px 8px; font-weight: 700; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { color: var(--muted); font-size: 13px; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--bg-elev2); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  border: none; border-radius: 12px; padding: 12px 16px; font-size: 15px;
  font-weight: 600; background: var(--bg-elev2); color: var(--text);
  transition: transform .06s ease; cursor: pointer;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; width: 100%; }
.btn.ok { background: var(--ok); color: #04210f; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 12px; }
.checkbtn {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--muted);
  background: none; flex: none; font-size: 15px; color: transparent;
}
.checkbtn.done { background: var(--ok); border-color: var(--ok); color: #04210f; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--bg-elev); border-radius: var(--radius); padding: 14px; }
.stat .num { font-size: 26px; font-weight: 800; }
.stat .lbl { color: var(--muted); font-size: 12px; }

/* ── Bottom sheet / modal ─────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; z-index: 50;
}
.sheet {
  width: 100%; background: var(--bg-elev); border-radius: 22px 22px 0 0;
  padding: 20px; padding-bottom: calc(20px + var(--safe-bottom));
  max-height: 88vh; overflow-y: auto; animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h3 { margin: 0 0 14px; }
/* Form controls in sheets AND cards. Exclude checkbox/radio/color from
   full-width. box-sizing + min-width:0 stop native date/time/select pickers
   from overflowing to the right on iOS Safari. */
.sheet input:not([type=checkbox]):not([type=radio]):not([type=color]),
.sheet select, .sheet textarea,
.card input:not([type=checkbox]):not([type=radio]):not([type=color]),
.card select, .card textarea {
  width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box;
  margin-bottom: 12px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--bg-elev2); background: var(--bg-elev2);
  color: var(--text); font-size: 16px; font-family: inherit;
}
/* Custom dropdown arrow (native one removed for consistent width). */
.sheet select, .card select {
  -webkit-appearance: none; appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%239aa3bd' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
/* Normalize native date/time so they size like text inputs. */
.sheet input[type=date], .sheet input[type=time], .sheet input[type=datetime-local],
.card input[type=date], .card input[type=time], .card input[type=datetime-local] {
  -webkit-appearance: none; appearance: none; min-height: 46px;
}
.sheet input[type=color], .card input[type=color] {
  width: 100%; height: 46px; padding: 4px; box-sizing: border-box;
  border-radius: 10px; border: 1px solid var(--bg-elev2);
  background: var(--bg-elev2); margin-bottom: 12px;
}
.field-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.weekday-row { display: flex; gap: 6px; margin-bottom: 12px; }
.weekday { flex: 1; text-align: center; padding: 8px 0; border-radius: 8px;
  background: var(--bg-elev2); font-size: 13px; }
.weekday.on { background: var(--primary); color: #fff; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(84px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%); background: var(--bg-elev2); color: var(--text);
  padding: 12px 18px; border-radius: 999px; font-size: 14px; z-index: 60;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 8px); } }

.fab {
  position: fixed; right: 18px; bottom: calc(80px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none; font-size: 26px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  box-shadow: 0 10px 30px rgba(99,102,241,.5); z-index: 40;
}
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.progress { height: 8px; background: var(--bg-elev2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg,var(--primary),var(--primary-2)); }

/* ── Desktop / Laptop ─────────────────────────────────────────────────── */
@keyframes popIn { from { transform: scale(.96); opacity: .5; } to { transform: scale(1); opacity: 1; } }
@media (min-width: 900px) {
  /* Fixed left sidebar with brand + styled nav */
  .tabbar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 256px; z-index: 40;
    grid-template-columns: none; grid-auto-rows: min-content;
    background: var(--bg-elev); border-top: none;
    border-right: 1px solid rgba(128,140,170,.15);
    padding: 14px 12px; gap: 4px;
  }
  .tabbar::before {
    content: "🏠 HomePlan"; display: block;
    font-weight: 800; font-size: 20px; letter-spacing: -.3px;
    padding: 12px 14px 22px;
  }
  .tab {
    flex-direction: row; justify-content: flex-start; gap: 14px;
    min-height: 0; padding: 12px 14px; font-size: 15px; font-weight: 600;
    border-radius: 12px; transition: background .15s, color .15s;
  }
  .tab span { font-size: 20px; }
  .tab:hover { background: var(--bg-elev2); color: var(--text); }
  .tab.active {
    background: linear-gradient(135deg, rgba(99,102,241,.20), rgba(14,165,233,.14));
    color: var(--primary-2);
  }

  /* Content column clears the sidebar; topbar stays (household switch + bell) */
  .app { padding-left: 256px; }
  .topbar {
    position: sticky; top: 0; padding: 16px 40px;
    background: var(--bg-elev); border-bottom: 1px solid rgba(128,140,170,.12);
  }
  .topbar-title { text-align: left; font-size: 20px; }
  .hh-pill { max-width: none; }
  .view { padding: 28px 40px 48px; max-width: 1120px; margin: 0 auto; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .card { box-shadow: 0 2px 10px rgba(0,0,0,.16); }
  .fab { right: 44px; bottom: 34px; }
  .toast { bottom: 28px; }

  /* Modals become centered dialogs instead of bottom sheets */
  .sheet-backdrop { align-items: center; justify-content: center; }
  .sheet {
    width: min(560px, 92vw); max-height: 86vh; border-radius: 20px;
    padding-bottom: 20px; animation: popIn .18s ease;
    box-shadow: 0 30px 90px rgba(0,0,0,.5);
  }
}

/* ── Print (Einkaufsliste / Tablettenplan / Verleih-Statement) ──────────── */
@media print {
  .topbar, .tabbar, .fab, .icon-btn { display: none !important; }
  body, html { position: static; overflow: visible; background: #fff; color: #000; }
  .view { padding: 0; overflow: visible; }
  .card { border: 1px solid #ccc; box-shadow: none; }
}
