/* Family Planner — mobile-first, almanac-inspired. */
:root {
  --bg: #f6f4ee;
  --paper: #fffdf8;
  --ink: #1d1c1a;
  --ink-2: #57534e;
  --ink-3: #8a857d;
  --line: #e6e1d6;
  --line-2: #d8d2c4;
  --weekend: #efebe1;
  --accent: #1f5c4a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe4;
  --red: #c0352b;
  --danger: #b42318;
  --warn-bg: #fff4d6;
  --shadow: 0 1px 2px rgba(29, 28, 26, .06), 0 8px 24px rgba(29, 28, 26, .08);
  --radius: 14px;
  --top-h: 56px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --paper: #1e1d1b;
    --ink: #f1eee8;
    --ink-2: #c3beb4;
    --ink-3: #8c877e;
    --line: #2d2b28;
    --line-2: #3a3834;
    --weekend: #1b1a18;
    --accent: #6fbf9f;
    --accent-ink: #0f1f19;
    --accent-soft: #1f3a30;
    --red: #f07167;
    --danger: #f97066;
    --warn-bg: #3a3016;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top-h);
  padding: 0 12px;
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title small { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.topbar .title strong { font: 600 22px/1.1 var(--serif); }
.year-nav { display: flex; align-items: center; gap: 2px; }
.year-nav strong { font: 600 22px/1 var(--serif); min-width: 58px; text-align: center; font-variant-numeric: tabular-nums; }

main { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 24px); }
.page { padding: 16px; max-width: 640px; margin: 0 auto; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 500;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.active { color: var(--accent); }

.fab {
  position: fixed; z-index: 35;
  right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.96); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--paper); color: var(--ink);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--line); }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--paper); font-size: 16px; /* 16px avoids iOS zoom */
  outline: none; appearance: none; -webkit-appearance: none;
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 10px; }
.grid-2 > *, .input { min-width: 0; }
input[type=date].input, input[type=time].input { display: block; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line-2); position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

.seg { display: flex; padding: 3px; gap: 3px; border-radius: 12px; background: var(--line); }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- Cards & lists ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.card h3 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 12px; }
.list { margin: 0 -16px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); min-height: 56px; }
.list-item:first-child { border-top: 0; }
.list-item.tap { cursor: pointer; }
.list-item.tap:active { background: var(--weekend); }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 13px; color: var(--ink-3); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c, var(--ink-3)); flex: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--c, var(--accent)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--line); color: var(--ink-2); white-space: nowrap; }
.badge.premium { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-bg); color: #8a5a00; }
.badge.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); font-size: 14px; }
.copybox { display: flex; gap: 8px; }
.copybox input { flex: 1; min-width: 0; font-size: 14px; }

/* ---------- Calendar ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; scrollbar-width: none; border-bottom: 1px solid var(--line); background: var(--bg); }
.filters::-webkit-scrollbar { display: none; }
.pill { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--paper); font-size: 14px; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.pill.on { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 14%, var(--paper)); color: var(--ink); }

.month {
  position: sticky; top: var(--top-h); z-index: 20;
  padding: 18px 16px 8px;
  font: 600 26px/1.1 var(--serif);
  background: var(--bg);
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 1px solid var(--line-2);
}
.month small { font: 500 13px var(--sans); color: var(--ink-3); }
.wk { display: flex; align-items: center; gap: 8px; padding: 6px 16px 2px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.wk::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.day {
  position: relative;
  display: grid; grid-template-columns: 66px 1fr; gap: 8px;
  min-height: 48px; padding: 6px 12px 6px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  cursor: pointer;
}
.day:active { filter: brightness(.97); }
.day.we { background: var(--weekend); }
.day.tint { background: color-mix(in srgb, var(--tint) 11%, var(--paper)); }
.day.we.tint { background: color-mix(in srgb, var(--tint) 14%, var(--weekend)); }
.day.past { opacity: .62; }
.day.today { box-shadow: inset 4px 0 0 var(--accent); }
.day.today .n { background: var(--accent); color: var(--accent-ink); border-radius: 10px; }
.bars { position: absolute; left: 0; top: 0; bottom: 0; display: flex; gap: 2px; }
.bars i { width: 4px; height: 100%; background: var(--c); opacity: .9; }
.d-num { display: flex; align-items: center; gap: 6px; align-self: start; padding-top: 4px; }
.d-num .wd { width: 30px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.d-num .n { min-width: 30px; justify-content: end; height: 28px; padding: 0 4px; display: grid; place-items: center; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.day.red .n, .day.sun .n { color: var(--red); }
.day.red .wd, .day.sun .wd { color: var(--red); }
.day.today.red .n, .day.today.sun .n { color: var(--accent-ink); }
.d-body { min-width: 0; display: flex; flex-wrap: wrap; align-content: center; gap: 4px 6px; padding: 3px 0; }
.hol { width: 100%; font-size: 12px; font-weight: 600; color: var(--red); }
.hol.eve { color: var(--ink-3); }
.info-label { width: 100%; font-size: 12.5px; font-style: italic; color: color-mix(in srgb, var(--c) 70%, var(--ink)); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  padding: 3px 8px 3px 6px; border-radius: 8px;
  border-left: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 13%, var(--paper));
  font-size: 13.5px; line-height: 1.25;
}
.chip .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.chip .ti { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.cont { opacity: .7; }
.chip .who { display: inline-flex; gap: 2px; margin-left: 2px; }
.chip .who i { width: 7px; height: 7px; border-radius: 50%; background: var(--c2); }

.year-end { padding: 28px 16px 40px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ---------- Sheets ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; background: rgba(15, 14, 12, .38); opacity: 0; transition: opacity .18s; }
.scrim.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  padding: 8px 16px calc(20px + var(--safe-b));
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: translateY(0); }
@media (min-width: 680px) {
  .sheet { left: 50%; right: auto; width: 620px; margin-left: -310px; }
}
.sheet .grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line-2); margin: 2px auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { flex: 1; font: 600 22px/1.2 var(--serif); }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }

.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tpl {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 78px; padding: 8px 6px; border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--c) 30%, var(--line));
  background: color-mix(in srgb, var(--c) 9%, var(--paper));
  cursor: pointer; text-align: center; font-size: 13px; font-weight: 600; line-height: 1.15;
}
.tpl .ic { font-size: 26px; line-height: 1; }
.tpl .k { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.tpl:active { transform: scale(.97); }

.entry { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--c) 10%, var(--paper)); border-left: 4px solid var(--c); cursor: pointer; }
.entry + .entry { margin-top: 8px; }
.entry .ic { font-size: 22px; }
.entry .title { font-weight: 650; }
.entry .sub { font-size: 13px; color: var(--ink-2); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; }
.swatches button.on { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--paper); }
.who-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-input { width: 58px; text-align: center; font-size: 24px; padding: 6px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px calc(24px + var(--safe-b)); max-width: 440px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand img { width: 48px; height: 48px; }
.brand h1 { font: 600 30px/1.1 var(--serif); }
.brand p { margin: 2px 0 0; color: var(--ink-3); font-size: 14px; }
.auth .switch-mode { margin-top: 18px; text-align: center; font-size: 15px; }
.auth .switch-mode button { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px; }

/* ---------- Plan ---------- */
.plan-hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.plan-hero .name { font: 600 24px/1.1 var(--serif); }
.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.price-opt { padding: 14px; border-radius: 14px; border: 1.5px solid var(--line-2); background: var(--paper); text-align: left; cursor: pointer; }
.price-opt.best { border-color: var(--accent); }
.price-opt .amt { font: 600 22px/1.1 var(--serif); }
.price-opt .per { font-size: 13px; color: var(--ink-3); }
.price-opt .save { display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--accent); }
.feat { margin: 12px 0 0; padding: 0; list-style: none; font-size: 14px; }
.feat li { display: flex; gap: 8px; padding: 4px 0; }
.feat li::before { content: "✓"; color: var(--accent); font-weight: 800; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 14px; border-radius: 14px; background: var(--paper); border: 1px solid var(--line); }
.stat b { display: block; font: 600 28px/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--ink-3); }
.log { font-size: 13px; }
.log .list-item { min-height: 0; padding: 8px 16px; display: block; }
.log code { font-size: 12px; color: var(--ink-2); word-break: break-all; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 90; bottom: calc(var(--nav-h) + var(--safe-b) + 90px);
  transform: translate(-50%, 20px); opacity: 0;
  max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); transition: all .2s; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.err { background: var(--danger); color: #fff; }

.spinner { width: 28px; height: 28px; margin: 40px auto; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
