/* Family calendar. System fonts only: no request ever leaves for a font CDN. */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1c1e22;
  --muted: #676b73;
  --line: #e3e1db;
  --accent: #4f6ef7;
  --accent-ink: #ffffff;
  --accent-soft: #e9edff;
  --ok: #23875a;
  --ok-soft: #e3f4ea;
  --warn: #a8650a;
  --warn-soft: #fbf0dc;
  --danger: #c93b3b;
  --danger-soft: #fbe6e6;
  --radius: 14px;
  --radius-s: 9px;
  --shadow: 0 1px 2px rgb(20 20 30 / 5%), 0 6px 18px rgb(20 20 30 / 5%);
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131519;
    --surface: #1b1e23;
    --surface-2: #20242a;
    --ink: #ecebe7;
    --muted: #9ba0a9;
    --line: #2c3037;
    --accent: #7b92ff;
    --accent-ink: #0f1220;
    --accent-soft: #232a45;
    --ok: #5cc592;
    --ok-soft: #173326;
    --warn: #e2a64b;
    --warn-soft: #36291a;
    --danger: #ef7474;
    --danger-soft: #3a1d1f;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    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.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: .05em .35em; }
.icon { width: 1.2em; height: 1.2em; flex: none; vertical-align: -0.22em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.hint { color: var(--muted); font-size: .9rem; }
.lead { color: var(--muted); margin: 0 0 1rem; max-width: 60ch; }

/* ---------------------------------------------------------------- frame */
.top { display: none; }
.page { max-width: 760px; margin: 0 auto; padding: 16px 16px 24px; }
.page.wide { max-width: 1120px; }
.page.narrow { max-width: 420px; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .72rem; padding: 6px 0; }
.tabbar a:hover { text-decoration: none; }
.tabbar a.on { color: var(--accent); }
.tabbar a .icon { width: 1.45em; height: 1.45em; }
.tabbar a.cam {
  justify-self: center; width: 56px; height: 56px; margin-top: -22px;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 6px 18px rgb(79 110 247 / 35%);
}
.tabbar a.cam .icon { width: 28px; height: 28px; }

@media (min-width: 820px) {
  body { padding-bottom: 32px; }
  .tabbar { display: none; }
  .top {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    max-width: 1120px; margin: 0 auto; padding: 14px 16px;
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); }
  .brand:hover { text-decoration: none; }
  .top-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .top-nav > a:not(.btn) { color: var(--muted); padding: 8px 10px; border-radius: var(--radius-s); }
  .top-nav > a:not(.btn):hover { background: var(--surface); text-decoration: none; }
  .top-nav > a.on { color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
}

/* -------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.subtle { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .9rem; }
.btn.wide { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--ink); background: var(--surface); border: 1px solid var(--line); }
.icon-btn:hover { text-decoration: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.actions.split { justify-content: space-between; }
.actions form { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.empty { text-align: center; color: var(--muted); padding: 28px 18px; }
.empty .actions { justify-content: center; }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 550; font-size: .95rem; }
.form label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.event-form:has(#all_day:checked) .time-only { display: none; }
.event-form:has(#all_day:checked) .row.two { grid-template-columns: 1fr; }
.form-error { margin: 0; padding: 10px 12px; border-radius: var(--radius-s); background: var(--danger-soft); color: var(--danger); font-weight: 550; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input { flex: 1 1 180px; width: auto; }

.flash { margin: 0 0 14px; padding: 10px 14px; border-radius: var(--radius-s); background: var(--accent-soft); }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

.tag { display: inline-block; font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; }
.tag.muted { background: var(--surface-2); color: var(--muted); }

/* ------------------------------------------------------------ overview */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.pager-nav { display: flex; align-items: center; gap: 6px; }
.today-tag { display: inline-block; margin-right: 8px; padding: 1px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .75em; font-weight: 650; vertical-align: .1em; }

.switches { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px 6px; scrollbar-width: none; }
.switches::-webkit-scrollbar { display: none; }
.switch-form { margin: 0; flex: none; }
.switch {
  display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-size: .9rem; cursor: pointer;
}
.switch .dot, .cal-tag .dot, .cal-list .dot, .matrix .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }
.switch.off { color: var(--muted); background: transparent; }
.switch.off .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

.notice { display: flex; align-items: center; gap: 10px; padding: 12px 14px; margin-bottom: 14px; border-radius: var(--radius-s); background: var(--warn-soft); color: var(--warn); }
.notice:hover { text-decoration: none; filter: brightness(.98); }

.day-group { margin-bottom: 18px; }
.day-group h2 { font-size: .95rem; font-weight: 650; color: var(--muted); margin: 0 0 8px; text-transform: none; }
.day-group h2 a { color: inherit; }
.day-group.is-today h2 { color: var(--ink); }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ev {
  display: grid; grid-template-columns: 92px 1fr; gap: 12px; align-items: start;
  padding: 12px 14px; border-radius: var(--radius-s); background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--c); color: var(--ink);
}
.ev:hover { text-decoration: none; border-color: color-mix(in srgb, var(--c) 45%, var(--line)); border-left-color: var(--c); }
.ev-time { font-variant-numeric: tabular-nums; font-size: .9rem; color: var(--muted); padding-top: 1px; }
.ev-body { display: grid; gap: 2px; min-width: 0; }
.ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev-meta { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.ev.unconfirmed { border-style: dashed; border-left-style: solid; background: var(--surface-2); }
.waiting-mark { color: var(--warn); margin-right: 5px; }
.inline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -2px 0 6px 4px; }
.inline-actions form { margin: 0; }
.range-note { color: var(--muted); font-size: .88rem; text-align: center; }

/* month */
.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.wk-head, .week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.wk-head span { padding: 8px 6px; font-size: .78rem; font-weight: 650; color: var(--muted); text-align: center; border-bottom: 1px solid var(--line); }
.cell { position: relative; min-height: 64px; padding: 4px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.week .cell:nth-child(7) { border-right: 0; }
.week:last-child .cell { border-bottom: 0; }
.cell.out { background: var(--surface-2); }
.cell.out .num { color: var(--muted); opacity: .7; }
.cell-link { position: absolute; inset: 0; z-index: 1; }
.cell-link:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.num { display: inline-grid; place-items: center; width: 26px; height: 26px; margin: 2px; border-radius: 50%; font-size: .85rem; font-weight: 600; color: var(--ink); }
.cell.today .num { background: var(--accent); color: var(--accent-ink); }
.chips { display: none; list-style: none; margin: 2px 0 0; padding: 0; }
.dots { display: flex; gap: 3px; justify-content: center; margin-top: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
@media (min-width: 700px) {
  .cell { min-height: 108px; }
  .dots { display: none; }
  .chips { display: grid; gap: 2px; position: relative; z-index: 2; }
  .chip {
    display: block; font-size: .78rem; line-height: 1.3; padding: 2px 6px; border-radius: 5px;
    background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: var(--ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-left: 3px solid var(--c);
  }
  .chip:hover { text-decoration: none; background: color-mix(in srgb, var(--c) 26%, var(--surface)); }
  .chip.unconfirmed { background: var(--surface); outline: 1px dashed var(--c); outline-offset: -1px; }
  .chip b { font-weight: 650; font-variant-numeric: tabular-nums; }
  .more { font-size: .75rem; color: var(--muted); padding-left: 6px; }
}

/* ---------------------------------------------------------------- event */
.event-card { border-top: 5px solid var(--c); }
.cal-tag { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; color: var(--muted); font-size: .9rem; }
.event-card h1 { margin-bottom: 14px; overflow-wrap: anywhere; }
.facts { margin: 0; display: grid; gap: 10px; }
.facts > div { display: flex; gap: 10px; align-items: flex-start; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.notes { white-space: pre-wrap; background: var(--surface-2); border-radius: var(--radius-s); padding: 12px 14px; margin: 16px 0 0; overflow-wrap: anywhere; }
.check-box { background: var(--warn-soft); border-radius: var(--radius-s); padding: 14px; margin-bottom: 16px; }
.check-title { margin: 0 0 8px; color: var(--warn); font-weight: 650; display: flex; gap: 8px; align-items: center; }
.evidence { margin: 8px 0; }
.evidence q { font-style: italic; }
.check-photo img, .photo-link img { display: block; max-width: 100%; max-height: 260px; border-radius: var(--radius-s); border: 1px solid var(--line); }
.photo-link { display: inline-grid; gap: 6px; margin-top: 16px; color: var(--muted); font-size: .88rem; }
.danger-zone { position: relative; }
.danger-zone summary { list-style: none; }
.danger-zone summary::-webkit-details-marker { display: none; }
.danger-zone[open] form { margin-top: 10px; padding: 12px; border-radius: var(--radius-s); background: var(--danger-soft); }
.danger-zone p { margin: 0 0 10px; }
.back { margin-top: 4px; }
.back a { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }

/* --------------------------------------------------------------- photos */
.upload .pick { position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 58px; border-radius: var(--radius); border: 1.5px dashed var(--line); background: var(--surface-2); cursor: pointer; font-weight: 600; }
.upload .pick.primary { min-height: 96px; font-size: 1.1rem; border: 0; background: var(--accent); color: var(--accent-ink); }
.upload .pick.primary .icon { width: 30px; height: 30px; }
.upload .pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.upload .pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
/* paste and drag-and-drop: the hint shows only where there is a mouse */
.drop-hint { display: none; margin: 0; text-align: center; color: var(--muted); font-size: .92rem; }
@media (hover: hover) and (pointer: fine) { .drop-hint { display: block; } }
.drop-error { margin: 0; text-align: center; color: var(--danger); font-weight: 550; }
.upload.dragging { outline: 2px dashed var(--accent); outline-offset: 6px; background: var(--accent-soft); }
.upload.dragging .drop-hint { display: block; color: var(--accent); font-weight: 600; }
.recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recent-list a { display: flex; gap: 12px; align-items: center; color: var(--ink); padding: 8px; border-radius: var(--radius-s); background: var(--surface); border: 1px solid var(--line); }
.recent-list a:hover { text-decoration: none; }
.recent-list img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }
.recent-list span { display: grid; }
.status { font-size: .82rem; color: var(--muted); display: inline-flex; gap: 4px; align-items: center; }
.status.created { color: var(--ok); }
.status.failed { color: var(--danger); }
.status.needs_review, .status.empty { color: var(--warn); }

.photo-result { display: grid; gap: 16px; }
.photo-result .photo img { display: block; width: 100%; max-height: 420px; object-fit: contain; background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--line); }
@media (min-width: 820px) {
  .photo-result { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
  .photo-result .photo { position: sticky; top: 16px; }
  .photo-result .photo img { max-height: 80vh; }
}
.reading.waiting { border-style: dashed; }
.reading-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
.reading-facts dt { color: var(--muted); }
.reading-facts dd { margin: 0; }
.unsure { color: var(--warn); font-weight: 600; }
.unsure::after { content: " ?"; }
.unsure-note { color: var(--warn); font-size: .9rem; margin: 8px 0 0; }

/* whose event: which person's calendar it sits on */
.whose { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 12px 0 0; }
.whose label { color: var(--muted); font-size: .95rem; }
.whose select { width: auto; min-width: 9rem; max-width: 100%; min-height: 40px; padding: 6px 10px; }
.inline-actions .whose { margin: 0; }
.js .whose button { display: none; }

/* ------------------------------------------------------------- account */
.phones { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.phones li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-s); }
.phones li.revoked { opacity: .55; }
.phones form { margin: 0 0 0 auto; }
.phone-name { display: grid; }
.phone-name small { color: var(--muted); }
.secret { text-align: center; margin: 8px 0 14px; }
.secret code { font-size: 1.35rem; padding: 10px 16px; letter-spacing: .04em; user-select: all; }
.setup-os { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 14px; margin-bottom: 8px; background: var(--surface-2); }
.setup-os summary { font-weight: 650; cursor: pointer; }
.setup-os ol { padding-left: 1.2rem; margin: 10px 0 4px; display: grid; gap: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.logout { text-align: center; }

/* --------------------------------------------------------------- admin */
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table thead th { font-size: .8rem; color: var(--muted); font-weight: 650; }
.table tr.inactive { opacity: .55; }
.table-scroll { overflow-x: auto; }
.matrix select { min-width: 150px; min-height: 38px; padding: 6px 8px; }
.matrix th .dot { margin-right: 6px; }
.add-box { margin-top: 14px; }
.add-box summary { list-style: none; }
.add-box summary::-webkit-details-marker { display: none; }
.add-box[open] summary { margin-bottom: 14px; }
.cal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.cal-list li { display: grid; gap: 6px; }
/* Fixed columns, so a longer owner name cannot push the colour and the
   button out of line: dot | name | colour | owner | save. */
.cal-list .inline-form {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) 48px 7rem auto;
  align-items: center;
  gap: 8px 12px;
}
.cal-list .inline-form input[name="display_name"] { width: 100%; }
.cal-list .inline-form .colour-pick { width: 48px; padding: 4px; cursor: pointer; }
.cal-list .cal-owner { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-list .danger-zone { margin-left: 24px; }
@media (max-width: 600px) {
  /* two rows on a phone: dot | name | colour, then owner | save */
  .cal-list .inline-form { grid-template-columns: 12px minmax(0, 1fr) auto; }
  .cal-list .cal-owner { grid-column: 2; }
}
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--c); cursor: pointer; }
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ----------------------------------------------------------------- login */
.login-page { padding-top: 12vh; }
.login-card { text-align: center; display: grid; gap: 12px; justify-items: center; }
.login-card .form { width: 100%; text-align: left; }

/* ------------------------------------------------------------------ busy */
.busy { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgb(10 12 20 / 45%); }
.busy[hidden] { display: none; }
.busy-card { background: var(--surface); border-radius: var(--radius); padding: 22px 26px; max-width: 300px; text-align: center; box-shadow: var(--shadow); }
.busy-text { margin: 12px 0 0; }
.spinner { display: inline-block; width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
