/* =========================================================
   Familjeplaneraren – UI
   ========================================================= */
:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e9ecf5;
  --border: #e4e7f0;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef2ff;
  --primary-text: #3730a3;
  --success: #10b981;
  --success-soft: #dcfce7;
  --success-text: #047857;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --warning-text: #b45309;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --danger-text: #b91c1c;
  --info-soft: #e0f2fe;
  --info-text: #0369a1;
  --grid: rgba(15, 23, 42, .07);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 24px -8px rgba(15, 23, 42, .12);
  --shadow-lg: 0 24px 60px -12px rgba(15, 23, 42, .35);
  --sidebar-w: 264px;
  --topbar-h: 64px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #121a2e;
    --surface-2: #19223a;
    --surface-3: #212b46;
    --border: #243052;
    --text: #e8ecf8;
    --text-2: #c3cbe0;
    --muted: #8b97b5;
    --primary: #818cf8;
    --primary-600: #6366f1;
    --primary-soft: rgba(129, 140, 248, .14);
    --primary-text: #c7d2fe;
    --success-soft: rgba(16, 185, 129, .16);
    --success-text: #6ee7b7;
    --warning-soft: rgba(245, 158, 11, .16);
    --warning-text: #fcd34d;
    --danger-soft: rgba(239, 68, 68, .16);
    --danger-text: #fca5a5;
    --info-soft: rgba(14, 165, 233, .16);
    --info-text: #7dd3fc;
    --grid: rgba(255, 255, 255, .06);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 30px -10px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}
body.modal-open { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.015em; }
h1 { font-size: 1.6rem; font-weight: 750; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 650; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.xs { font-size: .76rem; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: .6rem; }
.row-wrap { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1.25rem 1rem; z-index: 50;
  padding-top: max(1.25rem, env(safe-area-inset-top));
  transition: transform .28s var(--ease);
}
.brand { display: flex; align-items: center; gap: .75rem; padding: .25rem .5rem 1.25rem; }
.brand strong { display: block; font-size: 1rem; }
.brand small { display: block; color: var(--muted); font-size: .8rem; }
.nav { display: flex; flex-direction: column; gap: .2rem; }
.nav a {
  display: flex; align-items: center; gap: .8rem; padding: .7rem .85rem; border-radius: 12px;
  color: var(--text-2); font-weight: 550; text-decoration: none; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary-soft); color: var(--primary-text); }
.nav a.active svg.i { color: var(--primary); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; padding-bottom: env(safe-area-inset-bottom); }
.me { display: flex; align-items: center; gap: .7rem; padding: .6rem; border-radius: 14px; background: var(--surface-2); }
.me strong { display: block; font-size: .92rem; }
.me small { color: var(--muted); font-size: .78rem; }
.scrim { display: none; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; min-width: 0; overflow-x: clip; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: .75rem; padding: 0 1.5rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar-title { font-size: 1.05rem; font-weight: 650; }
.topbar-actions { margin-left: auto; display: flex; gap: .4rem; }
.menu-btn { display: none !important; }
.view { padding: 1.25rem 1.5rem 3rem; width: 100%; max-width: 1240px; margin: 0 auto; outline: none; animation: fadeIn .25s var(--ease); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (max-width: 960px) {
  .sidebar { transform: translateX(-102%); box-shadow: var(--shadow-lg); width: min(84vw, 300px); }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 45; }
  .scrim.open { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex !important; }
  .topbar { padding: 0 .75rem; padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .view { padding: 1rem 1rem calc(2.5rem + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.35rem; }
}

/* ---------- Page heads ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin-top: .25rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (max-width: 960px) { .page-head h1 { display: none; } .page-head { margin-bottom: 1rem; } }

/* ---------- Cards / grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1.15rem 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1.25rem .5rem; }
.card-head h3 { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.card-body { padding: .5rem 1.25rem 1.15rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 1rem; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

.hero { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.hero .eyebrow { color: var(--muted); font-size: .85rem; text-transform: capitalize; }
.hero h1 { font-size: 1.8rem; }
@media (max-width: 960px) { .hero h1 { font-size: 1.45rem; display: block; } }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
@media (max-width: 760px) { .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat {
  display: flex; flex-direction: column; gap: .35rem; padding: 1rem 1.1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  text-decoration: none !important; color: inherit; transition: transform .15s var(--ease), box-shadow .15s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat .stat-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 1.15rem; }
.stat strong { font-size: 1.6rem; line-height: 1; font-weight: 750; }
.stat span { color: var(--muted); font-size: .85rem; }
.tone-danger .stat-icon { background: var(--danger-soft); color: var(--danger-text); }
.tone-warning .stat-icon { background: var(--warning-soft); color: var(--warning-text); }
.tone-info .stat-icon { background: var(--info-soft); color: var(--info-text); }
.tone-success .stat-icon { background: var(--success-soft); color: var(--success-text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 42px; padding: .55rem 1rem; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; font-size: .92rem; cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s, opacity .15s;
  background: var(--surface-2); color: var(--text);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg.i { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--primary) 70%, transparent); }
.btn-primary:hover { background: var(--primary-600); }
.btn-soft { background: var(--primary-soft); color: var(--primary-text); }
.btn-soft:hover { background: color-mix(in srgb, var(--primary-soft) 70%, var(--primary) 12%); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-outline { background: var(--surface); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger-text); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ai { background: linear-gradient(135deg, #8b5cf6, #6366f1 55%, #06b6d4); color: #fff; }
.btn-ai:hover { filter: brightness(1.07); }
.btn-sm { min-height: 34px; padding: .35rem .7rem; font-size: .84rem; border-radius: 10px; }
.btn-lg { min-height: 50px; font-size: 1rem; padding: .7rem 1.3rem; }
.btn-block { width: 100%; }
@media (max-width: 760px) { .btn { white-space: normal; text-align: center; max-width: 100%; } }
.btn-google { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-google:hover { background: var(--surface-2); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer; position: relative; flex: none;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.sm { width: 34px; height: 34px; border-radius: 10px; }
.icon-btn.sm svg.i { width: 18px; height: 18px; }
.check-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--muted); flex: none; transition: all .15s;
}
.check-btn:hover { border-color: var(--success); color: var(--success); background: var(--success-soft); }
.check-btn.done { background: var(--success); border-color: var(--success); color: #fff; }
.badge-dot {
  position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--bg);
}

/* ---------- Chips / pills ---------- */
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; margin-bottom: 1rem; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .85rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font-size: .86rem; font-weight: 550; cursor: pointer; white-space: nowrap; transition: all .15s;
}
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .count { font-size: .75rem; opacity: .7; }
.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 650; white-space: nowrap; }
.pill-danger { background: var(--danger-soft); color: var(--danger-text); }
.pill-warning { background: var(--warning-soft); color: var(--warning-text); }
.pill-success { background: var(--success-soft); color: var(--success-text); }
.pill-info { background: var(--info-soft); color: var(--info-text); }
.pill-muted { background: var(--surface-2); color: var(--muted); }
.pill-primary { background: var(--primary-soft); color: var(--primary-text); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: .9rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field > span { font-size: .84rem; font-weight: 600; color: var(--text-2); }
.field small { font-weight: 400; color: var(--muted); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .75rem; }
.field-row.icon-row { grid-template-columns: 76px minmax(0, 1fr); }
.field, .field-row > * { min-width: 0; }
@media (max-width: 480px) { .field-row.stack-sm { grid-template-columns: minmax(0, 1fr); } }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: .6rem .85rem; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; transition: border-color .15s, box-shadow .15s;
  appearance: none; -webkit-appearance: none; min-width: 0; max-width: 100%; display: block;
}
/* iOS Safari gives date/time inputs a wide intrinsic size */
input[type=date], input[type=time], input[type=datetime-local] { line-height: 1.4; }
input::-webkit-date-and-time-value { text-align: left; min-width: 0; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; padding-right: 2.2rem; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
input[type=color] { width: 46px; height: 46px; border: 1px solid var(--border); border-radius: 12px; padding: 4px; background: var(--surface); }
.check { display: flex; align-items: center; gap: .6rem; cursor: pointer; font-size: .92rem; user-select: none; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.inline-add { display: flex; gap: .5rem; }
.inline-add input { flex: 1; min-width: 0; }

.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg button, .seg label {
  padding: .5rem .8rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: .86rem; font-weight: 550; display: inline-flex; align-items: center; gap: .35rem;
}
.seg input { display: none; }
.seg button.active, .seg label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-text); }

.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
.type-grid label {
  display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: .7rem .4rem; border-radius: 14px;
  border: 1.5px solid var(--border); cursor: pointer; font-size: .8rem; font-weight: 600; text-align: center; background: var(--surface);
  transition: all .15s;
}
.type-grid label .emoji { font-size: 1.5rem; }
.type-grid input { display: none; }
.type-grid label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-text); }

/* Range slider */
.range {
  --val: 50%; -webkit-appearance: none; appearance: none; width: 100%; height: 10px; border-radius: 999px; outline: none;
  background: linear-gradient(90deg, var(--range-color, var(--primary)) 0 var(--val), var(--surface-3) var(--val) 100%);
  cursor: pointer; margin: 0;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff;
  border: 3px solid var(--range-color, var(--primary)); box-shadow: 0 2px 8px rgba(15, 23, 42, .25); cursor: grab;
}
.range::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--range-color, var(--primary)); box-shadow: 0 2px 8px rgba(15, 23, 42, .25); }
.level-row { display: flex; align-items: center; gap: .85rem; }
.level-row output { min-width: 3.2rem; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.lvl-low { --range-color: var(--danger); }
.lvl-mid { --range-color: var(--warning); }
.lvl-high { --range-color: var(--success); }
.lvl-full { --range-color: var(--danger); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--success); transition: width .4s var(--ease); }
.progress.warn > span { background: var(--warning); }
.progress.bad > span { background: var(--danger); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: .85rem; padding: .75rem 0; border-top: 1px solid var(--border); }
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item strong { display: block; font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: .82rem; }
.emoji-tile { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 1.3rem; background: var(--surface-2); flex: none; }
.clickable { cursor: pointer; }
.clickable:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

.group-title { display: flex; align-items: center; gap: .5rem; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.25rem 0 .5rem; }
.group-title:first-child { margin-top: 0; }

.empty { text-align: center; padding: 2.5rem 1.25rem; color: var(--muted); }
.empty .emoji { font-size: 2.6rem; display: block; margin-bottom: .5rem; }
.empty h3 { color: var(--text); margin-bottom: .35rem; }
.empty .btn { margin-top: 1rem; }

.alert { padding: .8rem 1rem; border-radius: 12px; font-size: .9rem; margin-bottom: .75rem; }
.alert-error { background: var(--danger-soft); color: var(--danger-text); }
.alert-success { background: var(--success-soft); color: var(--success-text); }
.alert-info { background: var(--info-soft); color: var(--info-text); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: .85rem; color: #fff; background: var(--c, var(--primary)); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 24px; height: 24px; font-size: .68rem; }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1.5rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .5); opacity: 0; transition: opacity .22s; backdrop-filter: blur(2px); }
.modal {
  position: relative; width: 100%; max-width: 560px; max-height: calc(100dvh - 3rem); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(.98); opacity: 0; transition: transform .26s var(--ease), opacity .2s;
}
.modal.modal-wide { max-width: 820px; }
.modal-wrap.open .modal-backdrop { opacity: 1; }
.modal-wrap.open .modal { transform: none; opacity: 1; }
.modal-head { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.25rem .6rem; }
.modal-head h2 { flex: 1; font-size: 1.15rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: .5rem 1.25rem 1.25rem; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; flex: 1 1 auto; min-height: 0; min-width: 0; }
.modal-head, .modal-foot { flex: none; }
.modal-foot { display: flex; gap: .5rem; justify-content: flex-end; padding: .85rem 1.25rem 1.1rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
@media (max-width: 760px) {
  /* Flex instead of grid: an auto-sized grid row grows with content and prevents scrolling */
  .modal-wrap { padding: 0; display: flex; align-items: stretch; justify-content: stretch; height: 100%; height: 100dvh; }
  .modal, .modal.modal-wide {
    max-width: none; width: 100%; height: 100%; max-height: 100%; border-radius: 0; transform: translateY(24px);
  }
  .modal-head { padding-top: calc(.9rem + env(safe-area-inset-top)); border-bottom: 1px solid var(--border); padding-bottom: .8rem; }
  .modal-body { padding-top: 1rem; }
  .modal-foot { padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  .modal-foot .left { flex: 0 0 auto; }
}

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; width: min(92vw, 440px); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-radius: 14px;
  background: #0f172a; color: #fff; box-shadow: var(--shadow-lg); font-size: .9rem; width: 100%;
  animation: toastIn .25s var(--ease);
}
.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }
.toast button { margin-left: auto; background: rgba(255, 255, 255, .15); border: 0; color: #fff; border-radius: 8px; padding: .35rem .7rem; font-weight: 600; cursor: pointer; }
.toast.hide { opacity: 0; transform: translateY(8px); transition: all .2s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Loading ---------- */
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--primary); animation: spin .8s linear infinite; display: inline-block; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 3rem; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.ai-loading { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 2.5rem 1rem; text-align: center; }
.ai-orb { width: 64px; height: 64px; border-radius: 50%; background: conic-gradient(from 0deg, #8b5cf6, #6366f1, #06b6d4, #8b5cf6); animation: spin 1.6s linear infinite; position: relative; }
.ai-orb::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--surface); }

/* ---------- Floor plan ---------- */
.floor-tabs { display: flex; gap: .4rem; align-items: center; overflow-x: auto; margin-bottom: .75rem; scrollbar-width: none; }
.floor-tabs::-webkit-scrollbar { display: none; }
.plan-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .65rem .8rem; margin-bottom: .75rem;
  border-radius: 14px; background: var(--primary-soft); color: var(--primary-text); font-size: .88rem;
}
.plan-toolbar .hint { display: flex; align-items: center; gap: .45rem; flex: 1; min-width: 200px; }
.plan-card { padding: .75rem; overflow: hidden; }
.plan-scroll { overflow: auto; border-radius: 12px; -webkit-overflow-scrolling: touch; }
.plan-svg { display: block; width: 100%; height: auto; min-width: 560px; user-select: none; -webkit-user-select: none; background: var(--surface-2); border-radius: 12px; }
@media (min-width: 761px) { .plan-svg { min-width: 0; } }
.plan-svg.editing { touch-action: none; cursor: crosshair; min-width: 0; }
.plan-svg .room { cursor: pointer; }
.plan-svg.editing .room { cursor: move; }
.room-rect { stroke: rgba(15, 23, 42, .35); stroke-width: .12; transition: filter .15s; }
.plan-svg .room:hover .room-rect { filter: brightness(.97) saturate(1.15); }
.room.selected .room-rect { stroke: var(--primary); stroke-width: .22; }
.room-name { font-weight: 700; fill: #1e293b; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.room-sub { fill: #475569; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.room-icon { text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.handle { fill: #fff; stroke: var(--primary); stroke-width: .16; cursor: nwse-resize; }
.handle[data-handle=ne], .handle[data-handle=sw] { cursor: nesw-resize; }
.draft { fill: color-mix(in srgb, var(--primary) 18%, transparent); stroke: var(--primary); stroke-width: .12; stroke-dasharray: .4 .25; }
.draft-label { fill: var(--primary); font-weight: 700; text-anchor: middle; dominant-baseline: middle; }
.marker circle { fill: #fff; stroke: rgba(15, 23, 42, .25); stroke-width: .06; }
.marker.attention circle { fill: #fee2e2; stroke: var(--danger); stroke-width: .12; animation: pulse 1.6s ease-in-out infinite; }
.marker text { text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.plan-badge circle { fill: var(--danger); }
.plan-badge text { fill: #fff; font-weight: 800; text-anchor: middle; dominant-baseline: central; }
@keyframes pulse { 50% { stroke-width: .28; } }

.room-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: .75rem; margin-top: 1rem; }
.room-card { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; transition: transform .15s var(--ease), box-shadow .15s; text-align: left; width: 100%; }
.room-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.room-card .swatch { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; flex: none; border: 1px solid rgba(15, 23, 42, .1); }

.onboard { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); margin-top: 1rem; }
.onboard-card { padding: 1.25rem; border-radius: 18px; border: 1.5px dashed var(--border); background: var(--surface); cursor: pointer; text-align: left; transition: all .15s; }
.onboard-card:hover { border-color: var(--primary); background: var(--primary-soft); }
.onboard-card .emoji { font-size: 2rem; }
.onboard-card h3 { margin: .5rem 0 .25rem; }

/* Room modal */
.room-mini { border-radius: 16px; overflow: hidden; background: var(--surface-2); margin-bottom: 1rem; position: relative; }
.room-mini svg { display: block; width: 100%; max-height: 240px; }
.room-mini.placing { outline: 3px solid var(--primary); outline-offset: -3px; }
.room-mini.placing svg { cursor: crosshair; }
.room-mini .place-hint { position: absolute; left: .6rem; right: .6rem; bottom: .6rem; background: var(--primary); color: #fff; font-size: .82rem; font-weight: 600; padding: .45rem .7rem; border-radius: 10px; display: flex; align-items: center; gap: .5rem; }
.room-mini .place-hint button { margin-left: auto; background: rgba(255, 255, 255, .2); border: 0; color: #fff; border-radius: 8px; padding: .2rem .6rem; cursor: pointer; }
.section { margin-top: 1.25rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; flex-wrap: wrap; }
.item-cards { display: grid; gap: .65rem; }
.item-card { padding: .9rem 1rem; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); }
.item-card.attention { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: color-mix(in srgb, var(--danger-soft) 45%, var(--surface)); }
.item-head { display: flex; align-items: center; gap: .7rem; }
.item-head .grow { flex: 1; min-width: 0; }
.item-head strong { display: block; }
.item-body { margin-top: .75rem; display: flex; flex-direction: column; gap: .6rem; }
.instructions { font-size: .88rem; padding: .6rem .75rem; border-radius: 10px; background: var(--warning-soft); color: var(--warning-text); white-space: pre-wrap; }
.kv { font-size: .88rem; color: var(--text-2); }
.kv b { font-weight: 600; }

/* Chores */
.chore-row { display: flex; align-items: center; gap: .85rem; padding: .8rem .9rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.chore-row + .chore-row { margin-top: .5rem; }
.chore-row .grow { flex: 1; min-width: 0; cursor: pointer; }
.chore-row strong { display: block; font-weight: 600; }
.chore-row .meta { color: var(--muted); font-size: .8rem; display: flex; flex-wrap: wrap; gap: .25rem .6rem; margin: .1rem 0 .4rem; }
.chore-row.overdue { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.chore-row.compact { padding: .6rem .7rem; }

/* Calendar */
.cal-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1000px) { .cal-layout { grid-template-columns: minmax(0, 1fr); } }
.cal-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.cal-head h2 { flex: 1; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { font-size: .72rem; font-weight: 700; text-transform: uppercase; color: var(--muted); text-align: center; padding: .25rem 0; }
.cal-day {
  min-height: 96px; border-radius: 12px; background: var(--surface-2); padding: .35rem; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
  border: 1.5px solid transparent; transition: border-color .15s; overflow: hidden; text-align: left;
}
.cal-day:hover { border-color: var(--border); }
.cal-day.other { opacity: .45; }
.cal-day.today .num { background: var(--primary); color: #fff; }
.cal-day.selected { border-color: var(--primary); }
.cal-day .num { font-size: .8rem; font-weight: 700; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; }
.cal-ev { font-size: .72rem; padding: 1px 6px; border-radius: 6px; color: #fff; background: var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; padding: 0 2px; }
.cal-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
@media (max-width: 760px) {
  .cal-day { min-height: 54px; align-items: center; padding: .25rem .1rem; }
  .cal-ev { display: none; }
  .cal-dots { display: flex; justify-content: center; }
}
.event-row { display: flex; gap: .85rem; align-items: flex-start; padding: .8rem 0; border-top: 1px solid var(--border); cursor: pointer; }
.event-row:first-child { border-top: 0; }
.event-date { width: 52px; flex: none; text-align: center; border-radius: 12px; padding: .35rem 0; background: var(--surface-2); }
.event-date b { display: block; font-size: 1.2rem; line-height: 1.1; }
.event-date small { font-size: .7rem; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.event-bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--c); flex: none; }
.ai-input { display: flex; gap: .5rem; padding: .5rem; border-radius: 16px; background: linear-gradient(135deg, rgba(139, 92, 246, .12), rgba(6, 182, 212, .1)); border: 1px solid color-mix(in srgb, #8b5cf6 25%, var(--border)); margin-bottom: 1rem; }
.ai-input input { border: 0; background: transparent; box-shadow: none !important; }

/* Food */
.tabs { display: flex; gap: .25rem; padding: .3rem; border-radius: 14px; background: var(--surface-2); margin-bottom: 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1; border: 0; background: transparent; padding: .6rem .9rem; border-radius: 11px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.food-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: .65rem; }
.food-item { padding: .85rem 1rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.food-item.low { border-color: color-mix(in srgb, var(--warning) 50%, var(--border)); }
.food-item.empty-item { opacity: .6; }
.food-top { display: flex; align-items: flex-start; gap: .6rem; margin-bottom: .6rem; }
.food-top .grow { flex: 1; min-width: 0; }
.food-top strong { display: block; }
.food-est { font-size: .78rem; color: var(--muted); margin-top: .45rem; display: flex; flex-wrap: wrap; gap: .3rem .75rem; }
.scan-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; }
@media (max-width: 760px) { .scan-cards { grid-template-columns: minmax(0, 1fr); } }
.scan-card { position: relative; padding: 1.4rem 1.2rem; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; overflow: hidden; transition: transform .15s var(--ease), box-shadow .15s; display: block; }
.scan-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.scan-card .emoji { font-size: 2.3rem; }
.scan-card h3 { margin: .6rem 0 .3rem; }
.scan-card input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.scan-card::after { content: ""; position: absolute; right: -40px; top: -40px; width: 120px; height: 120px; border-radius: 50%; background: var(--primary-soft); z-index: 0; }
.scan-card > * { position: relative; z-index: 1; }
.nutri { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.nutri div { padding: .7rem .5rem; border-radius: 12px; background: var(--surface-2); text-align: center; }
.nutri b { display: block; font-size: 1.1rem; }
.nutri small { color: var(--muted); font-size: .75rem; }
.review-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .6rem; align-items: start; padding: .7rem 0; border-top: 1px solid var(--border); }
.review-item:first-child { border-top: 0; }
.review-item .fields { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr); gap: .4rem; }
.review-item .fields.two { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.review-item .fields input, .review-item .fields select { min-height: 40px; padding: .4rem .6rem; font-size: 15px; }
@media (max-width: 560px) { .review-item .fields, .review-item .fields.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .review-item .fields > :first-child { grid-column: 1 / -1; } }
.shop-item { display: flex; align-items: center; gap: .75rem; padding: .7rem .2rem; border-top: 1px solid var(--border); }
.shop-item:first-child { border-top: 0; }
.shop-item .grow { flex: 1; min-width: 0; }
.shop-item.checked strong { text-decoration: line-through; color: var(--muted); }
.shop-check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--border); display: grid; place-items: center; cursor: pointer; background: var(--surface); flex: none; color: transparent; }
.shop-item.checked .shop-check { background: var(--success); border-color: var(--success); color: #fff; }
.trip { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: .9rem; padding: .9rem; }
.trip img { width: 88px; height: 88px; object-fit: cover; border-radius: 12px; background: var(--surface-2); }
.meal { padding: .9rem 1rem; border-radius: 14px; background: var(--surface-2); }
.meal + .meal { margin-top: .6rem; }

/* Household */
.member-row { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-top: 1px solid var(--border); }
.member-row:first-child { border-top: 0; }
.member-row .grow { flex: 1; min-width: 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.reset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: .5rem; }

/* Notifications panel */
.notif { display: flex; gap: .75rem; padding: .75rem 0; border-top: 1px solid var(--border); cursor: pointer; }
.notif:first-child { border-top: 0; }
.notif.unread strong::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-left: .4rem; vertical-align: middle; }

/* ---------- Auth pages ---------- */
.auth-body {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem 1rem;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, .22), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(16, 185, 129, .18), transparent 60%),
    var(--bg);
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; margin-bottom: 1.25rem; }
.auth-brand img { border-radius: 16px; box-shadow: var(--shadow); }
.auth-brand h1 { margin-top: .75rem; font-size: 1.6rem; }
.auth-brand p { color: var(--muted); margin-top: .25rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 1.75rem; box-shadow: var(--shadow); }
.auth-card h2 { margin-bottom: .35rem; }
.auth-card > .muted { margin-bottom: 1rem; font-size: .92rem; }
.auth-card .form { margin-top: .5rem; }
.auth-card .btn-google { margin-top: 1rem; }
.auth-foot { text-align: center; margin-top: 1.25rem; font-size: .92rem; color: var(--muted); }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; margin: 1.1rem 0 .4rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
