/* Fluiten Home — mobile-first styles; sidebar dashboard layout from 900px. */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f1eee7;
  --border: #e4dfd4;
  --text: #1f2a26;
  --muted: #6b746f;
  --primary: #2f6f5e;
  --primary-ink: #ffffff;
  --primary-soft: #e3efe9;
  --accent: #f4a261;
  --danger: #c2413b;
  --danger-soft: #fbe9e7;
  --warn: #a8650b;
  --warn-soft: #fdf1dc;
  --ok: #2d7a4c;
  --ok-soft: #e2f3e8;
  --shadow: 0 1px 2px rgba(31, 42, 38, .05), 0 4px 16px rgba(31, 42, 38, .05);
  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --surface: #1b221e;
    --surface-2: #232b27;
    --border: #2e3833;
    --text: #e8ece9;
    --muted: #9aa59f;
    --primary: #5fb39a;
    --primary-ink: #0d1411;
    --primary-soft: #1f3a31;
    --danger: #ef7d74;
    --danger-soft: #3a2220;
    --warn: #f0b457;
    --warn-soft: #3a2f1c;
    --ok: #6fcf97;
    --ok-soft: #1c3326;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .5rem; }
a { color: var(--primary); }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strike { text-decoration: line-through; color: var(--muted); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.right { margin-left: auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Boot / spinner ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.sidebar { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; }
.main { padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); max-width: 1180px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600;
}
.tabbar a.active { color: var(--primary); }
.tabbar .icon { width: 22px; height: 22px; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 248px 1fr; }
  .topbar, .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 4px 8px 18px; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: var(--text); text-decoration: none; font-weight: 500;
  }
  .sidebar nav a:hover { background: var(--surface-2); }
  .sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
  .sidebar .foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
  .main { padding: 28px 32px 48px; }
}

/* ---------- Page ---------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; }
.section-title h2 { font-size: 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head .icon { color: var(--primary); }
.card-head a { margin-left: auto; font-size: .85rem; font-weight: 600; text-decoration: none; }
.card.flush { padding: 0; overflow: hidden; }

.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) {
  .grid.dash { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.dash .span-2 { grid-column: span 2; }
  .grid.dash .row-2 { grid-row: span 2; }
}
@media (min-width: 640px) and (max-width: 1099px) {
  .grid.dash { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.dash .span-2 { grid-column: span 2; }
}

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); min-width: 0; }
.item:last-child { border-bottom: 0; }
.card:not(.flush) .item { padding-left: 0; padding-right: 0; }
.item .title { font-weight: 600; }
.item .meta { color: var(--muted); font-size: .82rem; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { background: var(--surface-2); }
.group-label { padding: 14px 16px 6px; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty .icon { width: 34px; height: 34px; margin-bottom: 6px; opacity: .6; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.bordered { border-color: var(--border); background: var(--surface); }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--primary); color: var(--primary-ink); display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(47, 111, 94, .35); cursor: pointer;
}
.fab .icon { width: 26px; height: 26px; }
@media (min-width: 900px) { .fab { display: none; } }
.desktop-only { display: none !important; }
@media (min-width: 900px) { .desktop-only { display: inline-flex !important; } }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: .82rem; font-weight: 650; color: var(--muted); }
.field .hint { font-size: .78rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
  font-size: 16px; /* prevents iOS zoom */
}
textarea.input { min-height: 110px; resize: vertical; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 1px; border-color: var(--primary); }
.input.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .12em; text-transform: uppercase; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.inline-add { display: flex; gap: 8px; }
.inline-add .input { flex: 1; }
.inline-add .qty { flex: 0 0 90px; }

/* ---------- Chips, badges, avatars ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .74rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.avatar {
  display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: .8rem; background: var(--muted);
}
.avatar.sm { width: 24px; height: 24px; font-size: .68rem; }
.avatar.lg { width: 44px; height: 44px; font-size: 1rem; }
.avatars { display: flex; }
.avatars .avatar { border: 2px solid var(--surface); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }

.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 9px 10px; border-radius: 9px; font-weight: 650; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Stats & bars ---------- */
.stat .value { font-size: 1.7rem; font-weight: 750; letter-spacing: -.02em; }
.stat .label { color: var(--muted); font-size: .82rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav strong { min-width: 130px; text-align: center; }

/* ---------- Shopping checkbox ---------- */
.check {
  width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; padding: 0; color: transparent;
}
.check .icon { width: 16px; height: 16px; stroke-width: 3; }
.check.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* ---------- Chores ---------- */
.chore { display: flex; gap: 12px; align-items: center; }
.chore.done .title { text-decoration: line-through; color: var(--muted); }
.rotation-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.rotation-table th, .rotation-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rotation-table th { color: var(--muted); font-weight: 650; font-size: .78rem; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.picker { display: flex; flex-direction: column; gap: 6px; }
.picker .item { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }

/* ---------- Meals ---------- */
.days { display: grid; gap: 10px; }
@media (min-width: 1100px) { .days { grid-template-columns: repeat(7, minmax(0, 1fr)); } .day { min-height: 220px; } }
.day { display: flex; flex-direction: column; gap: 8px; }
.day.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.day .date { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.day.today .date { color: var(--primary); }
.day .dish { font-weight: 650; font-size: 1rem; }
.day .actions { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- House info ---------- */
.wifi { display: grid; gap: 10px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.05rem; letter-spacing: .03em; }
.code-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.5rem; font-weight: 700; letter-spacing: .08em;
  text-align: center; padding: 16px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); user-select: all; overflow-wrap: anywhere;
}

/* ---------- Calendar embed ---------- */
.calendar-frame { width: 100%; height: 440px; border: 0; border-radius: 12px; background: #fff; }
@media (min-width: 900px) { .calendar-frame { height: 560px; } }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 420px; padding: 24px; }
.auth .brand { justify-content: center; margin-bottom: 18px; font-size: 1.25rem; }
.auth .brand img { width: 44px; height: 44px; border-radius: 12px; }

/* ---------- Modal (bottom sheet on phones) ---------- */
dialog.modal {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: 100%; max-width: 100%; max-height: 92vh; margin: auto 0 0; border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .2);
}
dialog.modal::backdrop { background: rgba(10, 15, 12, .45); }
dialog.modal .modal-head { display: flex; align-items: center; gap: 8px; padding: 16px 16px 8px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
dialog.modal .modal-body { padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); }
dialog.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
dialog.modal .modal-actions .left { margin-right: auto; }
@media (min-width: 640px) {
  dialog.modal { max-width: 520px; margin: auto; border-radius: 20px; }
}

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (min-width: 900px) { #toasts { bottom: 24px; } }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .9rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); animation: pop .18s ease-out; max-width: 90vw; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- More menu (mobile) ---------- */
.more-list .item { text-decoration: none; color: var(--text); }
.more-list .item .icon { color: var(--primary); }

/* On phones, the calendar goes below the daily-use cards. */
@media (max-width: 639px) { .grid.dash > .cal { order: 1; } }

/* ---------- Weekly routine (week grid) ---------- */
.week { --hh: 48px; }
.wk-head { display: grid; border-bottom: 1px solid var(--border); background: var(--surface); }
.wk-day { padding: 10px 4px; text-align: center; font-weight: 700; font-size: .85rem; color: var(--muted); border-left: 1px solid var(--border); }
.wk-day.today { color: var(--primary); }
.wk-body { display: grid; position: relative; }
.wk-times { position: relative; }
.wk-times span { position: absolute; right: 8px; transform: translateY(-50%); font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.wk-times span:first-child { transform: none; }
.wk-col {
  position: relative; border-left: 1px solid var(--border); cursor: copy;
  background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 100% var(--hh);
}
.wk-col:hover { background-color: color-mix(in srgb, var(--primary) 3%, transparent); }
.wk-ev {
  position: absolute; overflow: hidden; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 1px; padding: 4px 6px; border: 0; border-radius: 8px;
  border-left: 3px solid var(--ev);
  background: color-mix(in srgb, var(--ev) 20%, var(--surface));
  color: var(--text); font-size: .78rem; line-height: 1.25; z-index: 1;
}
.wk-ev:hover { background: color-mix(in srgb, var(--ev) 30%, var(--surface)); z-index: 2; }
.wk-ev strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wk-ev span { color: var(--muted); font-size: .72rem; }
.wk-ev.short { flex-direction: row; align-items: center; gap: 6px; padding-top: 1px; padding-bottom: 1px; }
.wk-ev .avatars { margin-top: auto; }
.wk-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.wk-now::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }

.day-tabs { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.day-tabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 0; font-weight: 650; font-size: .82rem; color: var(--muted); cursor: pointer; }
.day-tabs button.is-today { color: var(--primary); }
.day-tabs button.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* Checkbox chips & color swatches (routine editor) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: .85rem; cursor: pointer; user-select: none; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { cursor: pointer; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch span { display: block; width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.swatch:has(input:checked) span { box-shadow: 0 0 0 2px var(--text); }
.swatch-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.item.muted .title { color: var(--muted); }
