/* ------------------------------------------------------------ Tokens
   Calm, warm neutrals with one teal accent. All text colours meet WCAG AA on their
   backgrounds; the "contrast" setting raises them further. */

:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #fffefb;
  --surface-2: #efece5;
  --ink: #1d2427;
  --ink-2: #444c50;
  --muted: #5d6569;
  --line: #d9d4ca;
  --grid: #e7e3db;
  --axis: #b9b3a7;
  --brand: #2f6f68;
  --brand-hover: #255a54;
  --brand-ink: #1f5650;
  --on-brand: #ffffff;
  --brand-soft: #e1eeeb;
  --good: #2c7a4b;
  --good-soft: #e3f1e7;
  --warn: #85560a;
  --warn-soft: #fbefd6;
  --danger: #ad2a22;
  --danger-soft: #fae4e1;
  --focus: #1b5fc1;
  --shadow: 0 1px 2px rgb(40 30 10 / 0.05), 0 4px 14px rgb(40 30 10 / 0.05);
  --backdrop: rgb(20 20 15 / 0.45);
  --accent: var(--brand);
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 3rem;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 112.5%; /* 18px */
}

:root[data-text='large'] { font-size: 125%; }
:root[data-text='xlarge'] { font-size: 143.75%; }

:root.contrast {
  --ink: #000;
  --ink-2: #1b1b1b;
  --muted: #333a3d;
  --line: #6b6b6b;
  --brand: #1d524c;
  --brand-hover: #123a35;
  --brand-ink: #123a35;
  --surface-2: #e6e2d9;
}

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

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, dl, dd { margin: 0; }
h1 { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 650; }
h4 { font-size: 1rem; font-weight: 650; }
a { color: var(--brand-ink); }
ul, ol { list-style: none; margin: 0; padding: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
h1:focus { outline: none; }

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

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -100px;
  z-index: 50;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--surface);
  border-radius: 10px;
}
.skip-link:focus { top: 8px; }

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.center { text-align: center; }
.block { display: block; }
.error-text { color: var(--danger); }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.5rem; }

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

.view { max-width: 720px; margin: 0 auto; min-height: 100dvh; }
.view.wide { max-width: 1000px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: env(safe-area-inset-top) 16px 0;
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid color-mix(in oklab, var(--line) 60%, transparent);
}

.topbar h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; }
.brand { font-weight: 700; color: var(--brand-ink); font-size: 0.85rem; letter-spacing: 0.02em; }
.topbar:has(.back-btn) { grid-template-columns: auto 1fr auto; }

.page { padding: 16px 16px calc(110px + env(safe-area-inset-bottom)); }

.section-title {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 0 4px;
}

.sub-title { font-size: 0.95rem; color: var(--ink-2); padding: 0 4px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 16px;
}

.contrast .card { border-width: 2px; }
.card.flush { padding: 0; overflow: hidden; }
.card-heading { font-size: 1rem; }
.card-question { font-size: 1.1rem; font-weight: 650; }
.error-card { text-align: center; align-items: center; }
.error-card > .icon { width: 2.5rem; height: 2.5rem; color: var(--danger); }

.empty { padding: 24px 16px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  color: var(--ink);
}
.notice > .icon { color: var(--brand-ink); margin-top: 2px; }

/* Bottom navigation on phones, left rail on wide screens */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgb(0 0 0 / 0.04);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink-2);
  font-size: clamp(13px, 0.74rem, 15px);
  font-weight: 600;
  min-width: 0;
}
.tab span { max-width: 100%; text-align: center; line-height: 1.15; hyphens: manual; }
@media (max-width: 380px) { .tabbar { padding-inline: 2px; } .tab { font-size: 13px; } }
.tab .icon { width: 1.6rem; height: 1.6rem; }
.tab[aria-current='page'] { color: var(--brand-ink); background: var(--brand-soft); }
.tab:hover { color: var(--ink); }

@media (min-width: 1000px) {
  .view { padding-left: 230px; max-width: 960px; }
  .view.wide { max-width: none; margin-left: max(0px, calc(50vw - 480px)); margin-right: 16px; }
  .tabbar {
    inset: 0 auto 0 max(0px, calc(50vw - 480px));
    width: 220px;
    grid-template-columns: 1fr;
    align-content: start;
    gap: 4px;
    padding: 84px 12px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
    box-shadow: none;
    background: transparent;
  }
  .tab { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; font-size: 1rem; }
  .tab span { white-space: normal; overflow: visible; }
  .page { padding-bottom: 48px; }
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  text-align: center;
  line-height: 1.2;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn[aria-busy='true'] { cursor: progress; }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 2.5rem; padding: 0 12px; font-size: 0.9rem; }
.btn.large { min-height: 3.6rem; font-size: 1.1rem; border-radius: 14px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.ghost { background: transparent; border-style: dashed; color: var(--ink-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.contrast .btn { border-width: 2px; border-color: var(--ink-2); }
.contrast .btn.primary { border-color: var(--brand); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: var(--tap);
  height: var(--tap);
  padding: 0 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }
.icon-btn-text { font-weight: 600; font-size: 0.9rem; }

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  min-height: 2.5rem;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--brand-ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn.small { font-size: 0.88rem; min-height: 2rem; }
.center > .link-btn, .auth .link-btn { align-self: center; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row.center { justify-content: center; }
.button-row.two > .btn { flex: 1 1 0; }

/* ------------------------------------------------------------ Profile bar, date nav */

.person-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 0;
}
.person-bar-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.person-bar-name { font-weight: 700; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  display: inline-grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  flex: none;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 700;
}
.avatar.large { width: 3rem; height: 3rem; font-size: 1.2rem; }
.avatar.small { width: 2rem; height: 2rem; font-size: 0.85rem; }
.avatar .icon { width: 1.1rem; height: 1.1rem; }

.date-nav {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
}
.date-nav-label { display: flex; flex-direction: column; align-items: center; text-align: center; }
.date-nav-label strong { font-size: 1.1rem; }
.date-nav-spacer { width: var(--tap); }
.today-btn { grid-column: 1 / -1; justify-self: center; }

@media (max-width: 420px) {
  .hide-narrow { display: none; }
}

/* ------------------------------------------------------------ Mood */

.mood-buttons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }

.mood-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 5rem;
  padding: 8px 4px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 650;
  font-size: 0.85rem;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}
.mood-btn:hover { background: var(--surface-2); border-color: var(--brand); }
.mood-dot { width: 1.3rem; height: 1.3rem; border-radius: 50%; border: 2px solid var(--ink-2); }
.m1 .mood-dot { background: #c9cdd0; }
.m2 .mood-dot { background: #dfe3d8; }
.m3 .mood-dot { background: #eef0e4; }
.m4 .mood-dot { background: #cfe5dc; }
.m5 .mood-dot { background: #9fcdbd; }

@media (max-width: 480px) {
  .mood-buttons { grid-template-columns: 1fr; }
  .mood-btn { flex-direction: row; justify-content: flex-start; gap: 14px; min-height: var(--tap); padding: 0 16px; font-size: 1rem; }
}

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

.pick-list, .link-list { display: flex; flex-direction: column; }
.link-list li + li, .entry-list li + li, .dose-list > li + li, .manage-list li + li { border-top: 1px solid var(--line); }

.pick-row, .link-list a, .link-list .pick-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 3.5rem;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.pick-list .pick-row { border-radius: 12px; padding: 10px 8px; }
.pick-row:hover, .link-list a:hover { background: var(--surface-2); }
.pick-row[aria-current='true'] { font-weight: 700; }
.pick-label { flex: 1; min-width: 0; }
.pick-row > .icon:last-child, .link-list a > .icon:last-child { color: var(--muted); }

.cat-icon {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  flex: none;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand-ink);
}
.cat-icon.muted { background: var(--surface-2); color: var(--muted); }

.entry-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  min-height: 3.5rem;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.card:not(.flush) .entry-row { padding-inline: 0; }
.entry-row:hover { background: var(--surface-2); }
.entry-row > .icon { color: var(--muted); margin-left: auto; align-self: center; }
.entry-when { min-width: 3.2rem; font-variant-numeric: tabular-nums; font-weight: 650; color: var(--ink-2); }
.entry-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.entry-cat { font-weight: 650; }
.entry-values { overflow-wrap: anywhere; }
.entry-note { color: var(--ink-2); overflow-wrap: anywhere; white-space: pre-line; }
.entry-by { color: var(--muted); font-size: 0.85rem; }

.meta { color: var(--muted); }

.value-list { display: grid; grid-template-columns: minmax(8rem, auto) 1fr; gap: 6px 16px; }
.value-list dt { color: var(--ink-2); font-weight: 600; }
.value-list dd { overflow-wrap: anywhere; }
.value-list.compact { font-size: 0.95rem; }
@media (max-width: 480px) {
  .value-list { grid-template-columns: 1fr; gap: 0; }
  .value-list dd { margin-bottom: 8px; }
}

.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-list li { padding-left: 14px; border-left: 3px solid var(--line); }

.activity-list { display: flex; flex-direction: column; gap: 14px; }
.activity-list li { display: flex; gap: 12px; align-items: flex-start; }

.member-list { display: flex; flex-direction: column; gap: 16px; }
.member { display: flex; gap: 12px; align-items: flex-start; }
.member-main { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.member-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.member-actions select { width: auto; min-width: 12rem; }

.manage-list li { display: flex; gap: 14px; align-items: flex-start; padding: 12px 16px; }
.manage-main { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.row-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.bullet-list { list-style: disc; padding-left: 1.4em; }

.account-row { display: flex; align-items: center; gap: 14px; }

/* ------------------------------------------------------------ Medications */

.dose {
  display: grid;
  grid-template-columns: 4rem 1fr;
  gap: 4px 12px;
  padding: 14px 16px;
}
.dose-time { font-weight: 750; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.dose-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.dose-name { font-weight: 700; }
.dose-dosage { color: var(--ink-2); }
.dose-actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.dose-actions .btn:not(.small) { flex: 1 1 9rem; }
.dose-taken { background: color-mix(in oklab, var(--good-soft) 55%, var(--surface)); }
.dose-skipped { background: color-mix(in oklab, var(--warn-soft) 55%, var(--surface)); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 3px 10px 3px 6px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 650;
  border: 1.5px solid transparent;
}
.status .icon { width: 1.1rem; height: 1.1rem; }
.status.open { border-style: dashed; border-color: var(--axis); color: var(--ink-2); background: var(--surface); }
.status.taken { background: var(--good-soft); color: var(--good); border-color: color-mix(in oklab, var(--good) 35%, transparent); }
.status.skipped { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in oklab, var(--warn) 35%, transparent); }

.med-card { display: flex; flex-direction: column; gap: 10px; }
.med-card.ended { opacity: 0.8; }
.med-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.med-head h4 { flex: 1; min-width: 8rem; font-size: 1.05rem; }

.time-list { display: flex; flex-direction: column; gap: 8px; }
.time-list li { display: flex; gap: 8px; align-items: center; }
.time-list input { max-width: 10rem; }

/* ------------------------------------------------------------ Agenda */

.agenda-list { display: flex; flex-direction: column; gap: 4px; }
.card.agenda-list { padding: 8px 16px; }
.agenda-item { display: flex; align-items: flex-start; gap: 14px; padding: 10px 0; }
.agenda-list > li + li { border-top: 1px solid var(--line); }
.agenda-icon { color: var(--brand-ink); padding-top: 2px; }
.agenda-icon .icon { width: 1.6rem; height: 1.6rem; }
.agenda-main { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; cursor: default; }
.task .agenda-main { cursor: pointer; }
.agenda-title { font-weight: 650; }
.agenda-sub { color: var(--ink-2); font-size: 0.92rem; }
.agenda-note { color: var(--ink-2); font-size: 0.92rem; white-space: pre-line; }
.task.done .agenda-title { text-decoration: line-through; text-decoration-thickness: 1.5px; color: var(--ink-2); }
.task.overdue .agenda-sub { color: var(--danger); font-weight: 600; }
.done-note { display: inline-flex; align-items: center; gap: 4px; color: var(--good); font-weight: 600; }

.task-check {
  appearance: none;
  flex: none;
  width: max(2.6rem, 44px);
  height: max(2.6rem, 44px);
  margin: 0;
  border: 2px solid var(--ink-2);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.task-check:checked { background: var(--good); border-color: var(--good); }
.task-check:checked::after { content: ''; width: 0.75rem; height: 1.3rem; border: solid #fff; border-width: 0 3px 3px 0; transform: translateY(-2px) rotate(45deg); }
.task-check:disabled { opacity: 0.5; cursor: default; }

.range-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

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

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field-label {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: baseline;
  font-weight: 650;
  color: var(--ink);
  padding: 0;
}
.hint { font-weight: 400; color: var(--muted); font-size: 0.86rem; }

input[type='text'], input[type='password'], input[type='email'], input[type='search'], input[type='date'], input[type='time'], input[type='number'], input:not([type]), select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1rem;
}
.contrast input, .contrast select, .contrast textarea { border: 2px solid var(--ink-2); }
textarea { resize: vertical; min-height: 4.5rem; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); outline-offset: -1px; border-color: transparent; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 380px) { .row-2 { grid-template-columns: 1fr; } }

.input-unit { display: flex; align-items: center; gap: 10px; }
.input-unit input { max-width: 12rem; }
.input-unit .unit { color: var(--ink-2); font-weight: 650; }

.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.form-actions .btn.primary, .form-actions .btn.danger { min-width: 10rem; }
.form-actions .danger-ghost { margin-right: auto; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-toggle { position: relative; }
.chip-input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }

.chip-toggle span {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-weight: 600;
}
.contrast .chip-toggle span { border: 2px solid var(--ink-2); }
.chip-input:checked + span { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); }
.chip-input:checked + span::before { content: '✓'; margin-right: 6px; font-weight: 800; }
.chip-input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.scale { display: flex; flex-direction: column; gap: 6px; }
.scale-steps { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.scale-steps.many { gap: 4px; }
.scale-step { position: relative; }
.scale-input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.scale-step span {
  display: grid;
  place-items: center;
  min-height: var(--tap);
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.scale-input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.scale-input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.scale-ends { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 0.86rem; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--tap);
  cursor: pointer;
  font-weight: 600;
}

.switch {
  appearance: none;
  flex: none;
  position: relative;
  width: 3.4rem;
  height: 2rem;
  margin: 0;
  border-radius: 999px;
  background: var(--axis);
  cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 0.15s;
}
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(1.4rem); }

.check-list { display: flex; flex-direction: column; gap: 4px; }
.check-row { display: flex; gap: 12px; align-items: flex-start; min-height: 2.75rem; padding: 6px 0; cursor: pointer; }
.check-row input { width: 1.4rem; height: 1.4rem; margin: 0.1rem 0 0; flex: none; accent-color: var(--brand); }

.kind-options { display: flex; flex-direction: column; gap: 8px; }
.kind-option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.kind-option input { width: 1.3rem; height: 1.3rem; margin: 0.15rem 0 0; flex: none; accent-color: var(--brand); }
.kind-option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }

.option-list { display: flex; flex-direction: column; gap: 6px; }
.option-list li, .option-add { display: flex; gap: 6px; align-items: center; }
.field-card { background: var(--surface-2); box-shadow: none; }
.field-card-actions { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }

.icon-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-choice { position: relative; }
.icon-choice input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.icon-choice > span { display: grid; place-items: center; width: var(--tap); height: var(--tap); border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); }
.icon-choice input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); }
.icon-choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
  overflow-x: auto;
}
.segmented button {
  flex: 1 1 0;
  min-height: 2.6rem;
  padding: 4px 6px;
  line-height: 1.15;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 650;
  cursor: pointer;
}
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.invite-url { font-family: ui-monospace, monospace; font-size: 0.85rem !important; }

/* ------------------------------------------------------------ Sheets, toasts, banners */

.sheet {
  width: min(640px, 100%);
  max-height: min(92dvh, 900px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -8px 40px rgb(0 0 0 / 0.2);
}
.sheet::backdrop { background: var(--backdrop); }
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 20px; }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 1.15rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sheet-head .icon-btn { flex: none; }
@media (max-width: 400px) { .sheet-head .icon-btn-text { display: none; } }
.sheet-body { padding: 16px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.confirm-text { font-size: 1.05rem; }

#toasts, .sheet-toasts {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 100;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, calc(100% - 24px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 10px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--surface);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  pointer-events: auto;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(8px); }
.toast-text { flex: 1; }
.toast-action { min-height: 2.5rem; padding: 0 12px; border: 1.5px solid currentColor; border-radius: 10px; background: transparent; font-weight: 700; cursor: pointer; }
.toast-close { display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border: 0; border-radius: 10px; background: transparent; cursor: pointer; }

.connection {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 16px;
  background: var(--warn-soft);
  color: var(--ink);
  border-bottom: 2px solid var(--warn);
}
.connection .icon { color: var(--warn); margin-top: 2px; }

/* ------------------------------------------------------------ Auth & welcome */

.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 520px;
  margin: 0 auto;
  padding-top: 8vh;
  padding-bottom: 48px;
}
.auth-card { width: 100%; }
.auth > p { max-width: 32em; }
.welcome { align-items: center; text-align: center; padding: 32px 20px; }
.welcome-mark {
  display: grid;
  place-items: center;
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 22px;
  background: var(--brand-soft);
  color: var(--brand-ink);
}
.welcome-mark .icon { width: 2.4rem; height: 2.4rem; }
.disclaimer { max-width: 30em; }

/* ------------------------------------------------------------ Charts (from Pawlio) */

.chart-card { gap: 10px; }
.chart { position: relative; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--accent); }
.chart .quiet-mark { fill: var(--good); }
.chart .hit { fill: transparent; }
.chart .hover-band { fill: var(--ink); opacity: 0.06; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .end-label { fill: var(--ink); font-size: 13px; font-weight: 650; }
.chart-tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.85rem;
  line-height: 1.35;
  white-space: nowrap;
}

/* ------------------------------------------------------------ Report & print */

.report { background: #fff; color: #000; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; gap: 20px; }
.report-head { display: flex; flex-direction: column; gap: 4px; border-bottom: 2px solid #000; padding-bottom: 12px; }
.report-head h2 { font-size: 1.4rem; }
.report-notice { margin-top: 8px; padding: 8px 12px; border: 1px solid #555; border-radius: 6px; font-size: 0.9rem; }
.report-part { display: flex; flex-direction: column; gap: 12px; }
.report-part > h2 { font-size: 1.2rem; border-bottom: 1px solid #999; padding-bottom: 4px; }
.report-section { display: flex; flex-direction: column; gap: 6px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.report-table th, .report-table td { border: 1px solid #bbb; padding: 5px 8px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.report-table th { background: #f0f0f0; font-weight: 700; }
.report-table.numbers td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.report-foot { color: #444; border-top: 1px solid #999; padding-top: 8px; }
@media (max-width: 640px) {
  .report { padding: 12px; overflow-x: auto; }
  .report-table { font-size: 0.8rem; }
}

@media print {
  :root { font-size: 11pt; }
  body { background: #fff; }
  .topbar, .tabbar, .no-print, #toasts, .connection, .skip-link { display: none !important; }
  .view { padding: 0 !important; max-width: none !important; }
  .page { padding: 0 !important; }
  .report { border: 0; padding: 0; }
  .report-table { font-size: 9.5pt; }
  .report-table tr, .report-section { break-inside: avoid; }
  .report-part > h2 { break-after: avoid; }
  thead { display: table-header-group; }
}

/* ------------------------------------------------------------ Simplified view */

.simple .person-bar .btn { display: none; }
.simple .date-nav .btn:not(.today-btn) { display: none; }
.simple .date-nav { grid-template-columns: 1fr; }
.simple .date-nav-spacer { display: none; }
.simple .card { padding: 20px; }
.simple .section-title { font-size: 0.95rem; }
.simple .dose-actions .btn { min-height: 3.6rem; font-size: 1.05rem; }
.simple .mood-btn { min-height: 5.5rem; font-size: 1rem; }
@media (max-width: 480px) { .simple .mood-btn { min-height: 3.6rem; } }

/* Phones held sideways: little height, so header scrolls away and navigation gets compact */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 999px) {
  .topbar { position: static; min-height: 52px; }
  .tabbar { grid-template-columns: repeat(5, auto); justify-content: space-evenly; padding: 2px max(8px, env(safe-area-inset-left)) calc(2px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right)); }
  .tab { flex-direction: row; gap: 5px; min-height: 44px; padding: 0 10px; font-size: clamp(12px, 0.78rem, 14px); }
  .tab .icon { width: 1.15rem; height: 1.15rem; }
  #toasts { bottom: calc(60px + env(safe-area-inset-bottom)); }
  .page { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* Notch / rounded corners in landscape */
.page { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

/* ------------------------------------------------------------ Account, legal, admin */

.notice.warn { background: var(--warn-soft); }
.notice.warn > .icon { color: var(--warn); }
.link-btn.inline { display: inline; min-height: 0; padding: 0; font: inherit; font-weight: 600; vertical-align: baseline; }
.consent-box { border-top: 1px solid var(--line); padding-top: 12px; }
.legal-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; padding: 8px 0; }
.legal-links a { color: var(--ink-2); min-height: 2.75rem; min-width: 2.75rem; padding: 0 4px; display: inline-flex; align-items: center; justify-content: center; }
.legal-page { max-width: 760px; }
.prose h2 { font-size: 1.25rem; margin-top: 8px; }
.prose h3 { font-size: 1.05rem; margin-top: 12px; }
.prose p { max-width: 70ch; }
.qr { display: block; width: min(260px, 100%); height: auto; margin: 0 auto; background: #fff; padding: 8px; border-radius: 12px; border: 1px solid var(--line); }
.secret { font-family: ui-monospace, monospace; font-size: 1rem; letter-spacing: 0.05em; overflow-wrap: anywhere; }
.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 8px; padding-left: 1.4em; }
.codes code { font-family: ui-monospace, monospace; font-size: 1.05rem; }
.steps { padding-left: 1.4em; display: flex; flex-direction: column; gap: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.tile-label { font-size: 0.85rem; color: var(--ink-2); }
.tile-value { font-size: 1.5rem; font-weight: 700; }
.row-search { display: flex; gap: 8px; }
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
.admin-table { font-size: 0.92rem; }
.admin-table td { vertical-align: middle; }
.file-row { cursor: pointer; }
.check-row.basis { padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); }

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

/* ------------------------------------------------------------ Legal functions */

/* Withdrawal function (§ 13a FAGG): highlighted, easy to find on every page. */
.legal-links a.withdraw-link { color: var(--danger); font-weight: 600; border: 1px solid currentColor; border-radius: 999px; padding: 0 14px; }
.notice.ok { background: var(--brand-soft, #e7f3ee); }
.consent-withdraw { border-top: 1px solid var(--line, #ddd); padding-top: 12px; }
.price-facts { margin: 0; }
.price-facts dt { font-weight: 600; }
.price-facts dd { margin: 0 0 8px; }
@media print {
  .legal-links, .no-print { display: none !important; }
  .print-sheet { border: 0; box-shadow: none; padding: 0; }
}

.auth .slogan { font-family: var(--font-display, inherit); font-size: 1.15em; font-style: italic; color: var(--brand, #2f6f68); margin: -4px 0 4px; }
