/* ---------------------------------------------------------------------------
   Calmon Family Hub — design system
   Warm, calm, book-like. Paper background, ink text, one terracotta accent,
   soft feature tints. Mobile-first; centered column on wide screens.
--------------------------------------------------------------------------- */

:root {
  --bg: #FAF7F1; --surface: #FFFFFF; --ink: #22303C; --muted: #6E7B87;
  --line: #E7E0D4; --accent: #C05A3C; --accent-soft: #F6E3DB;
  --tint-cal: #B98424; --tint-tasks: #4E8A5F; --tint-trips: #47749E; --tint-notes: #8A63A8;
  --radius: 14px; --pad: 16px; --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;

  --danger: #B23B2E;
  --danger-soft: #F7E1DD;
  --shadow: 0 1px 2px rgba(34, 48, 60, 0.05), 0 4px 16px rgba(34, 48, 60, 0.05);
  --tabbar-h: 62px;
}

/* ---- Base ---------------------------------------------------------------- */

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--accent-soft); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3, p { margin: 0; }

.icon { display: block; flex: none; }

/* ---- Header -------------------------------------------------------------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px var(--pad);
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.header-title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.header-title:hover { text-decoration: none; color: var(--accent); }

.header-actions { display: flex; align-items: center; gap: 2px; }

.lang-form, .logout-form { display: contents; }

.header-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 10px;
  border: 0;
  background: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.header-link:hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }

.lang-toggle { letter-spacing: 0.06em; }

/* ---- Page + tab bar ------------------------------------------------------ */

.page {
  padding: var(--pad);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: var(--pad);
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(34, 48, 60, 0.06);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 2px 6px;
  min-height: 44px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.tab:hover { text-decoration: none; }
.tab .icon { width: 24px; height: 24px; }

.tab-active { color: var(--accent); }
.tab-active span { position: relative; }
.tab-active span::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateX(-50%);
}

/* ---- Cards & lists ------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card > h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-tint-cal { border-left: 4px solid var(--tint-cal); }
.card-tint-tasks { border-left: 4px solid var(--tint-tasks); }
.card-tint-trips { border-left: 4px solid var(--tint-trips); }
.card-tint-notes { border-left: 4px solid var(--tint-notes); }

.card-tint-cal > h2 { color: var(--tint-cal); }
.card-tint-tasks > h2 { color: var(--tint-tasks); }
.card-tint-trips > h2 { color: var(--tint-trips); }
.card-tint-notes > h2 { color: var(--tint-notes); }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 0;
}
.list-item + .list-item { border-top: 1px solid var(--line); }

.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }

.meta {
  font-size: 13px;
  color: var(--muted);
}

/* ---- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn .icon { width: 18px; height: 18px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #A94C31; border-color: #A94C31; color: #fff; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }

.btn-danger {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

/* ---- Chips & badges ------------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-due {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.family-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.family-badge-everyone {
  border-style: dashed;
}

.family-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.scope-group {
  display: flex;
  flex-direction: column;
  gap: var(--pad);
}

.scope-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.filter-chips .chip {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  min-height: 32px;
  padding: 4px 14px;
}

.filter-chips .chip[aria-current="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Keep a family's dot visible when its chip is filled with the accent —
   without the ring, an accent-adjacent dot melts into the background. */
.filter-chips .chip[aria-current="true"] .family-dot {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

/* The Everyone chip mirrors the dashed .family-badge-everyone styling so the
   shared scope reads differently from the "no filter" All chip. */
.filter-chips .chip-everyone {
  border-style: dashed;
}

/* ---- Forms --------------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 480px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid > .field:has(textarea),
  .form-grid > .field:has(input[type="text"]),
  .form-grid > .field:has(input[type="email"]),
  .form-grid > .row,
  .form-grid > .btn,
  .form-grid > button {
    grid-column: 1 / -1;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field > span,
.field > label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field input:not([type="checkbox"]),
.field select,
.field textarea,
input.field-input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-family: inherit;
  font-size: 16px; /* 16px stops iOS zoom-on-focus */
  color: var(--ink);
}

.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input::placeholder,
.field textarea::placeholder { color: var(--muted); opacity: 0.7; }

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236E7B87' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ---- Custom checkbox ----------------------------------------------------- */

.checkbox {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.checkbox:checked {
  background-color: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12.5 4 4 8-9'/%3E%3C/svg%3E");
  background-size: 15px;
  background-position: center;
  background-repeat: no-repeat;
}
/* The checkbox lives inside its own toggle <form>, so also match the .grow
   label that follows that form. */
.checkbox:checked ~ .grow,
.checkbox:checked + .grow,
form:has(> .checkbox:checked) + .grow,
form:has(> .checkbox:checked) ~ .grow { color: var(--muted); text-decoration: line-through; }

/* ---- Inline add-forms (details > summary as buttons) --------------------- */

details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
details > summary::-webkit-details-marker { display: none; }

/* Only add-form summaries get the "+" glyph — Edit/Completed toggles and
   summaries that already carry a plus icon must not. */
details.add-form > summary::before {
  content: "+";
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}

details.add-form > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
}
details.add-form > summary:hover { background: var(--accent-soft); }
details[open].add-form > summary { color: var(--muted); }
details[open].add-form > summary::before { content: "–"; }
details[open] > .form-grid, details[open] > form { margin-top: 10px; }

/* ---- Empty states -------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 36px 20px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}
.empty .icon { width: 32px; height: 32px; opacity: 0.5; }

.error-empty { border: 0; padding-top: 64px; gap: 12px; }
.error-empty .page-title { color: var(--ink); }

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

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
}

.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 4px 0 6px;
}

.cal-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 46px;
  padding: 5px 2px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--ink);
  text-decoration: none;
}
a.cal-day:hover { background: var(--accent-soft); text-decoration: none; }

.cal-day-out { color: var(--muted); opacity: 0.45; }

.cal-day-today {
  background: var(--accent-soft);
  font-weight: 700;
  color: var(--accent);
}

.cal-dots { display: flex; gap: 3px; justify-content: center; min-height: 6px; }
.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--tint-cal);
}
/* Everyone-scoped events: neutral, never the accent (which today's cell and
   selected chips use as a background). */
.cal-dot-shared { background: var(--muted); }

/* ---- Public (login) pages ------------------------------------------------ */

.public-body {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.public-page {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.public-page .page-title { font-size: 28px; }
.public-page .btn { width: 100%; }

/* ---- Wide screens: centered column, tab bar becomes a top nav row -------- */

@media (min-width: 720px) {
  .header {
    padding-left: max(var(--pad), calc((100vw - 640px) / 2));
    padding-right: max(var(--pad), calc((100vw - 640px) / 2));
  }

  .tabbar {
    position: static;
    grid-template-columns: none;
    display: flex;
    justify-content: center;
    gap: 4px;
    min-height: 0;
    padding: 6px 0;
    background: var(--bg);
    border-top: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: none;
  }

  .tab {
    flex-direction: row;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 14px;
  }
  .tab .icon { width: 19px; height: 19px; }
  .tab:hover { background: var(--accent-soft); }
  .tab-active { background: var(--accent-soft); }
  .tab-active span::after { display: none; }

  .page {
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
    padding-top: 28px;
    padding-bottom: 64px;
  }

  .page-title { font-size: 28px; }
}

/* ---- Login (consolidated from T2) ---------------------------------------- */

.login-error { color: var(--accent); font-weight: 600; }

/* ---- Calendar (consolidated from T3) ------------------------------------- */

.cal-toolbar { display: flex; align-items: center; gap: 6px; }
.cal-nav-btn { min-width: 44px; padding: 8px 10px; border-color: transparent; }
.cal-nav-prev .icon { transform: rotate(180deg); }
.cal-month { text-align: center; font-size: 20px; }
.cal-month::first-letter { text-transform: uppercase; }
.cal-day-num { line-height: 1.15; }
.cal-actions { display: flex; gap: 8px; }
.cal-actions .btn { flex: 1 1 auto; }
.cal-agenda { display: flex; flex-direction: column; gap: 4px; scroll-margin-top: 12px; }
.cal-agenda-date {
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted); padding-top: 6px;
}
.cal-agenda-date-today { color: var(--accent); }
.cal-item-title { font-weight: 600; }
.cal-when { min-width: 74px; font-variant-numeric: tabular-nums; }
/* .cal-check-label instead of .grow: the `.checkbox:checked + .grow`
   strikethrough rule must not hit the all-day checkbox label. */
.cal-check-label { font-weight: 600; }
.cal-delete { justify-content: center; }
@media (min-width: 720px) { .cal-day { min-height: 58px; font-size: 15px; } }

/* ---- Trips (consolidated from T5) ---------------------------------------- */

.section-title { font-size: 1.05rem; font-weight: 650; margin: 18px 0 8px; }
.trip-day { margin-bottom: 14px; }
.day-header { text-transform: capitalize; margin: 10px 0 4px; letter-spacing: .02em; }
.trip-notes { white-space: pre-wrap; margin: 8px 0 4px; }
.past-trips { margin-top: 18px; }

/* ---- Notes (consolidated from T6) ---------------------------------------- */

.note-body { line-height: 1.65; }
.note-body h1 { font-size: 1.3rem; margin: 1.1em 0 .4em; }
.note-body h2 { font-size: 1.15rem; margin: 1em 0 .35em; }
.note-body h3 { font-size: 1rem; margin: .9em 0 .3em; }
.note-body p { margin: .6em 0; }
.note-body ul { margin: .6em 0; padding-left: 1.2em; }
.note-body li { margin: .25em 0; }
.note-body a { color: var(--accent); }
.note-body :first-child { margin-top: 0; }
.note-title-row { align-items: flex-start; }
.note-pin { color: var(--tint-notes); }
.note-actions { flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ---- Admin rows (phase 2) ------------------------------------------------- */

/* The families and members rows carry inline edit forms; on narrow screens
   they must wrap instead of pushing the page sideways. The edit form takes a
   full line of its own, its fields sharing it at a readable minimum width. */
.admin-row { flex-wrap: wrap; }
.admin-row > .row.grow { flex: 1 1 100%; flex-wrap: wrap; }
.admin-row .field { flex: 1 1 140px; }
