/* Family Dashboard styles. Phone first, works on tablets and computers too. */

:root {
  --bg: #f6f5fb;
  --card: #ffffff;
  --text: #1f2333;
  --muted: #6b7083;
  --line: #e6e4f0;
  --primary: #4f46e5;
  --primary-soft: #eceafe;
  --good: #15803d;
  --good-soft: #e6f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(20, 20, 50, 0.06), 0 4px 16px rgba(20, 20, 50, 0.05);
  --radius: 16px;
  --nav-h: 64px;
  --top-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131a;
    --card: #1c1e28;
    --text: #eceef6;
    --muted: #9da2b5;
    --line: #2c2f3d;
    --primary: #8b85ff;
    --primary-soft: #2a2850;
    --good: #4ade80;
    --good-soft: #15301f;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --bad: #f87171;
    --bad-soft: #3a1b1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0.4em 0; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.loading { text-align: center; color: var(--muted); padding: 3rem 1rem; }

.icon { display: inline-flex; width: 1.25em; height: 1.25em; flex: none; }
.icon svg { width: 100%; height: 100%; }

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

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.signed-in .top { display: flex; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; min-width: 0; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.me-btn { background: none; border: 0; padding: 4px; border-radius: 50%; }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom));
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: none;
  justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.signed-in .nav { display: flex; }

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}
.tab .icon { width: 24px; height: 24px; }
.tab.active { color: var(--primary); }

@media (min-width: 900px) {
  .nav { top: calc(var(--top-h) + 16px); bottom: auto; left: 16px; right: auto; width: 96px; height: auto; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 0; gap: 4px; }
  .tab { padding: 10px 0; }
  main { padding-bottom: 96px; }
}

.view { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Cards ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.card.accent { border: 2px solid var(--primary); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h3 { font-size: 1.02rem; }
.card h3 + .hint { margin-top: 0; }

.hello h1 { font-size: 1.5rem; }
.empty { color: var(--muted); margin: 6px 0; }
.day-group + .day-group { margin-top: 10px; }
.day-group h4 { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 2px; }

.list-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.list-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  text-align: left;
}
.list-tile .big { font-size: 1.6rem; font-weight: 700; color: var(--primary); }

/* ---------- Buttons and inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--bad); border-color: var(--line); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn.wide { width: 100%; }
.btn:active { transform: translateY(1px); }

.link { background: none; border: 0; color: var(--primary); font-weight: 600; font-size: 0.9rem; padding: 4px 0; }

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}
.icon-btn:hover { background: var(--primary-soft); }
.icon-btn.small { width: 32px; height: 32px; color: var(--muted); }
.icon-btn.small .icon { width: 1em; height: 1em; }

.badge {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e11d48;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.fab {
  position: fixed;
  right: max(16px, calc((100vw - 760px) / 2 + 16px));
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  z-index: 9;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 54px;
  padding: 0 20px;
  border: 0;
  border-radius: 27px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
}
@media (min-width: 900px) { .fab { bottom: 24px; } }

.field { display: flex; flex-direction: column; gap: 4px; }
.field .label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.hint { font-size: 0.82rem; color: var(--muted); margin: 2px 0; }

input[type=text], input[type=password], input[type=date], input[type=time], select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 16px; /* 16px stops iPhone from zooming in */
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

.form { display: flex; flex-direction: column; gap: 14px; }
.form h3 { margin-top: 6px; }
.form .inline { display: flex; align-items: flex-end; gap: 8px; }
.form .inline .field { flex: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- Chips and avatars ---------- */

.chips { display: flex; gap: 8px; }
.chips.wrap { flex-wrap: wrap; }
.chips.scroll { overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.soft { color: var(--muted); }
.chip.toggle { min-height: 36px; padding: 0 14px; background: var(--card); }
.chip.toggle.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  flex: none;
  user-select: none;
}
.avatar.sm { width: 26px; height: 26px; font-size: 0.68rem; border: 2px solid var(--card); }
.avatar.lg { width: 72px; height: 72px; font-size: 1.5rem; }

/* ---------- Sign in ---------- */

.auth { max-width: 460px; margin: 6vh auto 0; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.auth.setup { text-align: left; gap: 14px; }
.auth.setup h1, .auth.setup .auth-logo { align-self: center; }
.auth-logo { width: 76px; height: 76px; margin: 0 auto; border-radius: 20px; }
.auth h1 { font-size: 1.7rem; }

.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; margin-top: 12px; }
.member-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}
.member-tile.no-pin { opacity: 0.55; }
.tile-name { font-weight: 700; overflow-wrap: anywhere; }
.tile-note { font-size: 0.75rem; color: var(--muted); }

.pin-pad { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pin-dots { display: flex; gap: 14px; min-height: 18px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--primary); }
.pin-dot.on { background: var(--primary); }
.pin-msg { color: var(--bad); min-height: 1.4em; margin: 0; text-align: center; font-weight: 600; }
.keys { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.key {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 1.6rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.key .icon { width: 28px; height: 28px; }
.key.ok { background: var(--primary); color: #fff; border-color: var(--primary); }
.key:active { background: var(--primary-soft); }

/* ---------- Sheets ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 10, 30, 0);
  transition: background 0.2s;
}
.overlay.show { background: rgba(10, 10, 30, 0.45); }
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  transform: translateY(100%);
  transition: transform 0.22s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}
.overlay.show .sheet { transform: translateY(0); }
@media (min-width: 640px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 22px; max-height: 86vh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 6px 20px; }
.sheet-head h2 { font-size: 1.15rem; overflow-wrap: anywhere; }
.sheet-body { overflow-y: auto; padding: 6px 20px 22px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(92vw, 480px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #1f2333;
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow);
  transform: translate(-50%, 20px);
  opacity: 0;
  transition: all 0.25s;
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.bad { background: var(--bad); }

/* ---------- Calendar ---------- */

.cal-head { display: flex; align-items: center; gap: 4px; }
.cal-head h2 { flex: 1; text-align: center; font-size: 1.2rem; }

.month {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 8px;
}
.dow { text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; padding-bottom: 4px; }
.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 50px;
  padding: 6px 0 4px;
  border: 0;
  border-radius: 10px;
  background: none;
}
.day .num { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 600; font-size: 0.92rem; }
.day.other { opacity: 0.4; }
.day.today .num { background: var(--primary-soft); color: var(--primary); }
.day.selected .num { background: var(--primary); color: #fff; }
.dots { display: flex; gap: 2px; min-height: 6px; }
.mini-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.mini-dot.sports { outline: 1.5px solid #16a34a; outline-offset: 1px; }

.event {
  width: 100%;
  display: grid;
  grid-template-columns: 76px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0 10px 10px;
  border: 0;
  border-left: 4px solid var(--muted);
  background: none;
  text-align: left;
  border-radius: 4px;
}
.event + .event { margin-top: 6px; }
.event-time { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.event-main { display: flex; flex-direction: column; min-width: 0; }
.event-title { font-weight: 650; overflow-wrap: anywhere; }
.event-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--muted); }
.meta-loc, .meta-icon { display: inline-flex; align-items: center; gap: 3px; }
.meta-loc .icon, .meta-icon .icon { width: 14px; height: 14px; }
.event-people { display: flex; }
.event-people .avatar + .avatar { margin-left: -8px; }
.event-date { grid-column: 2 / 4; font-size: 0.8rem; color: var(--muted); }

.cat-general { border-left-color: #64748b; }
.cat-sports { border-left-color: #16a34a; }
.cat-school { border-left-color: #2563eb; }
.cat-appointment { border-left-color: #db2777; }
.cat-birthday { border-left-color: #ea580c; }
.cat-work { border-left-color: #7c3aed; }
.cat-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; border-left: 4px solid; background: var(--bg); }
.details { display: flex; flex-direction: column; gap: 10px; }
.details .icon { width: 16px; height: 16px; vertical-align: -2px; }

/* ---------- Chores ---------- */

.segmented { display: flex; background: var(--card); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.segmented button { flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: none; font-weight: 650; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.segmented button.on { background: var(--primary); color: #fff; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); font-size: 0.75rem; line-height: 20px; }
.segmented button.on .count { background: rgba(255, 255, 255, 0.25); color: #fff; }

.chore { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; flex-wrap: wrap; }
.chore + .chore { border-top: 1px solid var(--line); }
.chore-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.chore-main.tappable { cursor: pointer; }
.chore-title { font-weight: 650; font-size: 1.02rem; overflow-wrap: anywhere; }
.chore-notes { color: var(--muted); font-size: 0.9rem; }
.chore-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); }
.chore-actions { display: flex; gap: 8px; width: 100%; padding-left: 52px; }
.status-line { font-size: 0.85rem; color: var(--warn); }
.status-line.ok { color: var(--good); }
.sent-back { font-size: 0.88rem; padding: 6px 10px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.due { font-weight: 600; }
.due.soon { color: var(--warn); }
.due.late { color: var(--bad); }

.tick {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card);
  color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.tick:not(:disabled):hover { border-color: var(--good); color: var(--good); }
button.tick:disabled { opacity: 0.4; }
.tick.waiting { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.tick.signed { border-color: var(--good); background: var(--good); color: #fff; }
.tick .icon { width: 22px; height: 22px; }

/* ---------- Lists ---------- */

.add-item { display: flex; gap: 8px; }
.add-item input:first-child { flex: 1; }
.add-item .qty { width: 110px; flex: none; }
.add-item .btn { width: 50px; padding: 0; flex: none; min-height: 46px; }
.list-foot { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }

.items { padding: 4px 12px; }
.item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.item + .item { border-top: 1px solid var(--line); }
.item-check { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 44px; min-width: 0; cursor: pointer; }
.item-check input { width: 24px; height: 24px; flex: none; accent-color: var(--good); }
.item-name { font-weight: 600; overflow-wrap: anywhere; }
.item-qty { color: var(--muted); font-size: 0.88rem; white-space: nowrap; }
.item-by { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.item.got .item-name { text-decoration: line-through; color: var(--muted); }

/* ---------- Board ---------- */

.composer { display: flex; flex-direction: column; gap: 8px; }
.post { display: flex; gap: 12px; padding: 10px 0; }
.post + .post { border-top: 1px solid var(--line); }
.post-main { flex: 1; min-width: 0; }
.post-head { display: flex; align-items: center; gap: 8px; }
.post-head .icon-btn { margin-left: auto; }
.post p { margin: 2px 0 0; }

/* ---------- Notifications and menu ---------- */

.notes { display: flex; flex-direction: column; }
.note { display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; border-radius: 8px; }
.note.unread { background: var(--primary-soft); }
.note-title { font-weight: 700; }
.note-body { color: var(--text); font-size: 0.92rem; overflow-wrap: anywhere; }

.menu { display: flex; flex-direction: column; gap: 6px; }
.menu-item { min-height: 50px; text-align: left; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.menu-item.danger { color: var(--bad); }

.member-list { display: flex; flex-direction: column; gap: 6px; }
.member-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); text-align: left; }
.member-row-main { flex: 1; display: flex; flex-direction: column; }
.member-row .icon { color: var(--muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--card); }

.prompt p { margin: 0 0 6px; }

@media (max-width: 380px) {
  .keys { grid-template-columns: repeat(3, 66px); }
  .key { width: 66px; height: 66px; }
  .event { grid-template-columns: 64px 1fr auto; }
  .add-item .qty { width: 84px; }
}

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