:root {
  /* color roles — this app's violet identity (ADR 0001: theme is NOT shared
     with kids-bank; the design system is) */
  --bg: #f6f4f8;
  --card: #ffffff;
  --text: #221a30;
  --muted: #746b86;
  --line: #e9e5ef;
  --violet: #8b5cf6;
  --violet-dark: #6d3ee3;
  --green: #10b981;
  --green-dark: #0b9268;
  --amber: #d97706;
  --warn: #d97706;
  --red: #ef4444;
  /* type ramp — 9 steps; everything readable sits on one of these.
     (exceptions kept on purpose: 0.72rem tab micro-labels, 3.2rem logo) */
  --fs-micro: 0.72rem;
  --fs-xs: 0.8rem;
  --fs-sm: 0.88rem;
  --fs-base: 0.95rem;
  --fs-md: 1.05rem;
  --fs-lg: 1.2rem;
  --fs-xl: 1.35rem;
  --fs-2xl: 1.6rem;
  --fs-hero: 3rem;
  /* spacing scale */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  /* elevation — cards sit, sheets/FAB raise, overlays float */
  --elev-1: 0 1px 3px rgba(24, 16, 40, 0.08), 0 4px 14px rgba(24, 16, 40, 0.06);
  --elev-2: 0 8px 30px rgba(24, 16, 40, 0.18);
  --elev-3: 0 12px 48px rgba(24, 16, 40, 0.3);
  --radius: 18px;
  --shadow: var(--elev-1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131019;
    --card: #1d1926;
    --text: #f2eef7;
    --muted: #a294b8;
    --line: #322a44;
    --elev-1: 0 1px 3px rgba(0, 0, 0, 0.4);
    --elev-2: 0 8px 30px rgba(0, 0, 0, 0.5);
    --elev-3: 0 12px 48px rgba(0, 0, 0, 0.6);
  }
}

/* inline SVG icons (vendored Phosphor — see icons.js) */
.icon { width: 1.15em; height: 1.15em; vertical-align: -0.22em; flex: none; }
.tab .icon { width: 23px; height: 23px; }
.fab .icon { width: 26px; height: 26px; }

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen { max-width: 560px; margin: 0 auto; padding: 20px 16px 96px; min-height: 100dvh; }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }

.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--violet);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
.sub { color: var(--muted); font-size: var(--fs-base); }
.small { font-size: var(--fs-sm); }

/* Arnica montana brand mark (public/icons/mark.svg), not an interface icon. */
.logo { display: block; width: 56px; height: 56px; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 24px 0 28px; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.wrap { flex-wrap: wrap; }

/* Buttons are actions, cards are containers (audit A2/A15): a plain button
   carries a border, never the card shadow. Fills and chrome bring their own
   shape; navigation cards opt back into elevation below. */
button {
  font: inherit; cursor: pointer; border-radius: 14px;
  padding: 14px 18px; font-weight: 600; font-size: var(--fs-md);
  background: var(--card); color: var(--text);
  border: 1.5px solid var(--line); box-shadow: none;
  touch-action: manipulation;
}
.primary, .danger, .warn, .ghost, .tab, .fab, .set-card { border: 0; }
.person-card, button.card { border: 0; box-shadow: var(--shadow); }
button:active { transform: scale(0.98); }
button.primary { background: var(--violet); color: #fff; }
button.danger { background: var(--red); color: #fff; }
button.warn { background: var(--amber); color: #fff; } /* armed non-destructive (D7) */
button.ghost { background: transparent; box-shadow: none; color: var(--muted); font-weight: 500; }
button.small { padding: 8px 12px; font-size: var(--fs-sm); border-radius: 10px; }
button:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  font: inherit; width: 100%; padding: 13px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font-size: var(--fs-md);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--violet); border-color: transparent; }
label { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); display: block; margin-bottom: 6px; }

.err { color: var(--red); font-size: var(--fs-sm); min-height: 1.2em; }

.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: var(--fs-lg);
}

/* person cards */
.person-card { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 16px; }
.person-card .meta { color: var(--muted); font-size: var(--fs-sm); }

/* list rows */
.item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .what { font-weight: 600; }
.item .when { color: var(--muted); font-size: var(--fs-xs); }

/* status + stock pills */
.pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 10px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
}
.pill.active { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.pill.paused { background: rgba(217, 119, 6, 0.15); color: var(--amber); }
.pill.resolved { background: rgba(139, 92, 246, 0.15); color: var(--violet); }
.pill.have { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.pill.low { background: rgba(217, 119, 6, 0.15); color: var(--amber); }
.pill.missing { background: rgba(239, 68, 68, 0.13); color: var(--red); }
/* near-miss: owns the remedy, wrong potency — caution, not "don't have it" (D1) */
.pill.warn { background: rgba(217, 119, 6, 0.15); color: var(--amber); }
.pill.neutral { background: var(--line); color: var(--muted); }

/* remedy line display */
.rline { padding: 10px 0; border-bottom: 1px solid var(--line); }
.rline:last-child { border-bottom: 0; }
.rline .name { font-weight: 700; }
.rline .freq { color: var(--muted); font-size: var(--fs-sm); }
.rline .instr { color: var(--muted); font-size: var(--fs-sm); font-style: italic; margin-top: 2px; }
.rline.stopped .name, .rline.stopped .freq { text-decoration: line-through; opacity: 0.55; }
/* mixed group — remedies taken together (D3): a violet bracket + label so the
   grouping reads as one clinical instruction, not adjacent separate lines. */
.rline.mix { border-left: 3px solid var(--violet); padding-left: 12px; }
.together {
  font-size: var(--fs-micro); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--violet); margin-bottom: 3px;
}

/* inline informational hint (e.g. protocol→plan provenance, D4) */
.hint {
  display: flex; gap: 8px; align-items: flex-start;
  background: color-mix(in srgb, var(--violet) 8%, var(--card));
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px;
  font-size: var(--fs-sm); color: var(--muted);
}
.hint .icon { color: var(--violet); flex: none; margin-top: 1px; }

/* small tag chip (e.g. a journal note's plan, D5) */
.tag {
  display: inline-block; font-size: var(--fs-micro); font-weight: 700;
  padding: 1px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--violet) 12%, transparent); color: var(--violet);
}

/* shopping list rows — tappable, jump to the remedy (D2) */
.shop-row {
  width: 100%; text-align: left; background: none; box-shadow: none;
  border-radius: 0; padding: 12px 0;
}

/* the one inline "add" pattern (Phase 3 add-grammar): dashed, quiet, full
   width. The FAB adds a page's primary object; every other add uses this. */
.add-btn {
  width: 100%; background: transparent; box-shadow: none;
  border: 1.5px dashed var(--muted); color: var(--muted); font-weight: 600;
}

/* settings hub cards (Phase 2) */
.set-card { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 16px; }
.set-card .set-ic { color: var(--violet); display: flex; }
.set-card .set-ic .icon { width: 1.4em; height: 1.4em; }
.set-card > .icon { color: var(--muted); flex: none; }
.person-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.person-row:last-child { border-bottom: 0; }

/* person switcher (Phase 3) — narrow screens only; the wide split's list pane
   is the switcher ≥900px */
.pswitch { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; margin-bottom: 4px; }
.pchip {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 5px 14px 5px 6px; border-radius: 999px;
  background: var(--card); border: 1.5px solid var(--line); box-shadow: none;
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
}
.pchip.on { border-color: var(--violet); color: var(--violet); }
@media (min-width: 900px) { .pswitch { display: none; } }

/* lines editor */
.line-edit { border: 1.5px solid var(--line); border-radius: 14px; padding: 12px; }
.line-edit .grid { display: grid; grid-template-columns: 1fr 90px; gap: 8px; }
.mixtag { font-size: var(--fs-xs); color: var(--violet); font-weight: 700; }
.line-tools { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.line-tools button { flex: none; }
.quick-scroll {
  display: flex; gap: 6px; overflow-x: auto; padding: 1px 1px 3px;
  scrollbar-width: none; overscroll-behavior-x: contain;
}
.quick-scroll::-webkit-scrollbar { display: none; }
button.quick-chip {
  flex: none; padding: 5px 10px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; color: var(--muted);
  background: color-mix(in srgb, var(--line) 62%, transparent);
}
button.quick-chip.on {
  color: var(--violet); border-color: var(--violet);
  background: color-mix(in srgb, var(--violet) 10%, var(--card));
}
.mixed-frequency {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: var(--fs-sm); padding: 4px 2px;
}
.instruction-add { padding-left: 0; align-self: flex-start; }
.check-row {
  display: flex; align-items: center; gap: var(--s2); margin: 0;
  color: var(--text); font-size: var(--fs-sm); font-weight: 600;
}
.check-row input { width: 20px; height: 20px; flex: none; accent-color: var(--violet); }

/* Reusable bottom-sheet pattern. On larger screens the same markup becomes a
   centered dialog, matching the app's established responsive convention. */
dialog.sheet {
  width: min(100%, 560px); max-width: none; max-height: min(88dvh, 760px);
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 24px 24px 0 0; color: var(--text); background: var(--card);
  box-shadow: var(--elev-3); overflow: hidden;
}
dialog.sheet::backdrop { background: rgba(17, 12, 26, 0.58); backdrop-filter: blur(2px); }
.sheet-inner { padding: var(--s5); max-height: min(88dvh, 760px); overflow-y: auto; }
.sheet-footer {
  position: sticky; bottom: calc(0px - var(--s5)); z-index: 2;
  margin: 0 calc(0px - var(--s5)) calc(0px - var(--s5));
  padding: var(--s3) var(--s5) var(--s5);
  background: linear-gradient(to bottom, transparent, var(--card) 12px);
}
.icon-btn { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; flex: none; }
.paste-box { min-height: 210px; line-height: 1.5; }

/* Protocol-first new-plan flow. */
.protocol-start { border: 1.5px solid color-mix(in srgb, var(--violet) 30%, var(--line)); }
.or-label {
  display: flex; align-items: center; gap: var(--s2);
  color: var(--muted); font-size: var(--fs-xs); text-align: center;
}
.or-label::before, .or-label::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.or-label span { white-space: nowrap; }
.selected-protocol {
  border: 1.5px solid color-mix(in srgb, var(--violet) 38%, var(--line));
  border-radius: 14px; padding: var(--s3);
  background: color-mix(in srgb, var(--violet) 5%, var(--card));
}
.protocol-line-summary { display: block; margin-top: var(--s2); }
.protocol-line-summary .rline { text-align: left; padding: 6px 0; }
.protocol-line-summary .rline .pill { display: none; }
.protocol-options { display: flex; flex-direction: column; gap: var(--s2); }
button.protocol-option {
  display: block; width: 100%; text-align: left; padding: var(--s3);
  border-radius: 14px; background: var(--card);
}
button.protocol-option.on { border-color: var(--violet); }
.protocol-variant { display: block; margin-top: 2px; }
.empty-picker { padding: var(--s5) 0; text-align: center; }

/* Reuse actions and multi-person plan copying. */
.plan-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-top: var(--s3); }
.plan-actions button { min-width: 0; padding: 12px; font-size: var(--fs-sm); }
.plan-actions button:last-child:nth-child(3) { grid-column: 1 / -1; }
.reuse-note { margin-top: var(--s2); }
.copy-summary {
  border-radius: 14px; padding: var(--s3);
  background: color-mix(in srgb, var(--violet) 8%, var(--card));
}
.person-choices { border: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.person-choices legend { font-size: var(--fs-sm); font-weight: 700; color: var(--muted); margin-bottom: var(--s2); }
.person-choice {
  display: flex; align-items: center; gap: var(--s3); margin: 0; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 14px;
  color: var(--text); background: var(--card); cursor: pointer;
}
.person-choice:has(input:checked) {
  border-color: var(--violet);
  background: color-mix(in srgb, var(--violet) 8%, var(--card));
}
.person-choice:focus-within { outline: 2.5px solid var(--violet); outline-offset: 2px; }
.person-choice input { width: 20px; height: 20px; flex: none; accent-color: var(--violet); }
.person-choice .avatar { width: 38px; height: 38px; font-size: var(--fs-base); }

/* potency chips on remedy rows */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600;
  background: var(--line); color: var(--text);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.full { background: var(--green); }
.dot.low { background: var(--amber); }
.dot.out { background: var(--red); }

/* Bulk kit stocker. Presets are quiet reference cards; the review sheet is
   where selection and changes happen. */
.kit-card { display: flex; flex-direction: column; gap: var(--s2); }
.kit-brand {
  color: var(--violet); font-size: var(--fs-micro); font-weight: 800;
  letter-spacing: 0.055em; text-transform: uppercase;
}
.kit-title { align-items: flex-start; gap: var(--s2); }
.kit-title h2 { line-height: 1.25; }
.kit-dialog-head { align-items: flex-start; }
.kit-dialog-head > div { min-width: 0; }
.kit-dialog-head h2 { line-height: 1.22; overflow-wrap: anywhere; }
.kit-meta { margin-top: var(--s1); }
.kit-actions { margin-top: var(--s2); }
.kit-actions a, .kit-source {
  color: var(--violet); font-size: var(--fs-sm); font-weight: 600;
  text-underline-offset: 3px;
}
.kit-notice {
  border: 1.5px dashed var(--line); box-shadow: none;
  background: color-mix(in srgb, var(--line) 34%, var(--card));
}
.kit-source { display: inline-block; margin-top: var(--s3); }
.kit-contents {
  border: 1.5px solid var(--line); border-radius: 14px;
  max-height: min(46dvh, 430px); overflow-y: auto;
}
.kit-line {
  display: flex; align-items: center; gap: var(--s2); margin: 0; padding: 10px 12px;
  border-bottom: 1px solid var(--line); color: var(--text); cursor: pointer;
}
.kit-line:last-child { border-bottom: 0; }
.kit-line:has(input:checked) {
  background: color-mix(in srgb, var(--violet) 6%, var(--card));
}
.kit-line.stocked { color: var(--muted); cursor: default; }
.kit-line input { width: 20px; height: 20px; flex: none; accent-color: var(--violet); }
.kit-line .pill { font-size: var(--fs-micro); padding: 2px 7px; }
.kit-label { display: block; color: var(--muted); font-size: var(--fs-xs); font-weight: 500; }
.kit-potency { color: var(--muted); font-size: var(--fs-sm); font-weight: 700; }

/* notes journal */
.note { padding: 12px 0; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note .body { white-space: pre-wrap; margin-top: 3px; }
.note .when { color: var(--muted); font-size: var(--fs-xs); font-weight: 600; }

/* search */
.search { position: sticky; top: 8px; z-index: 5; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: var(--fs-base);
  box-shadow: var(--shadow); z-index: 60; animation: pop 0.18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; box-shadow: none; border-radius: 12px;
  padding: 6px 14px; font-size: var(--fs-lg); color: var(--muted);
}
.tab span { font-size: var(--fs-micro); font-weight: 600; }
.tab.on { color: var(--violet); }

/* floating action button — bottom clears the tab bar AND the home-indicator
   safe area, so it never tucks behind the bar on iPhone. */
.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--violet); color: #fff; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(109, 62, 227, 0.4);
}

/* Phase 0 — a FAB floats above the tab bar; its screens reserve room (safe
   area included) so the last row of content can always scroll clear of it. */
.screen.has-fab { padding-bottom: calc(160px + env(safe-area-inset-bottom)); }

/* Phase 0 — keyboard focus: a visible ring on anything focusable, without
   affecting mouse/touch taps. */
button:focus-visible, a:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2.5px solid var(--violet);
  outline-offset: 2px;
}

/* Phase 0 — hover feedback only on pointer devices (no sticky states on touch). */
@media (hover: hover) {
  button:not(:disabled):hover { filter: brightness(0.97); }
  .tab:hover, button.ghost:hover { filter: none; color: var(--text); }
  .fab:hover { transform: scale(1.05); }
  @media (prefers-color-scheme: dark) {
    button:not(:disabled):hover { filter: brightness(1.15); }
    .tab:hover, button.ghost:hover { filter: none; }
  }
}

/* Phase 1 — small utility set. New UI composes these instead of inline
   styles; the older screens migrate onto them as they're touched. */
.w-full { width: 100%; }
.ta-left { text-align: left; }
.prewrap { white-space: pre-wrap; }
.fw7 { font-weight: 700; }
.mt2 { margin-top: var(--s2); }
.mt3 { margin-top: var(--s3); }
.mt4 { margin-top: var(--s4); }
.mt5 { margin-top: var(--s5); }
.avatar.lg { width: 56px; height: 56px; font-size: var(--fs-xl); }
.form-title { margin: var(--s3) 0 var(--s4); }
.w-date { max-width: 170px; }

/* ---- large screens (Phase 4) ----
   <700px: phone layout, untouched. ≥700px: wider column + card grids.
   ≥900px: bottom tabs become a left rail; split routes go two-pane.

   The split scaffold is inert on phones: .split and its panes are
   display:contents, so their children flow exactly as before. */
.split, .list-pane, .detail-pane { display: contents; }
.sel-card { outline: 2.5px solid var(--violet); outline-offset: -1px; }
.placeholder {
  display: none; color: var(--muted); text-align: center;
  padding: 48px 24px; font-size: var(--fs-base);
}

@media (min-width: 700px) {
  .screen { max-width: 720px; }
  .grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; align-items: start; }
  .grid-cards > p, .grid-cards > h3 { grid-column: 1 / -1; }
  .kit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
  .kit-grid > .kit-card { height: 100%; }
  .kit-grid > .kit-notice { grid-column: 1 / -1; }
  dialog.sheet {
    width: min(calc(100% - 48px), 620px); margin: auto;
    border-radius: 24px;
  }
}

@media (min-width: 900px) {
  body { padding-left: 216px; }
  .tabs {
    left: 0; right: auto; top: 0; bottom: 0; width: 216px;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line);
    padding: 24px 12px;
  }
  .tab {
    flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 12px 14px; width: 100%; font-size: var(--fs-md);
  }
  .tab span { font-size: var(--fs-md); }
  .tab .icon { width: 22px; height: 22px; }
  .screen.wide { max-width: 1120px; }
  .screen.has-fab { padding-bottom: 40px; }
  .split {
    display: grid; grid-template-columns: minmax(300px, 380px) 1fr;
    gap: 24px; align-items: start;
  }
  .list-pane, .detail-pane { display: block; min-width: 0; }
  .list-pane .grid-cards { grid-template-columns: 1fr; } /* narrow pane = one column */
  .placeholder { display: flex; align-items: center; justify-content: center; }
  .fab { right: 32px; bottom: 32px; }
}

/* instant-shell skeletons while a route's data loads (Phase 5) */
.skeleton { background: var(--line); box-shadow: none; border: 0; animation: skeleton-pulse 1.2s ease-in-out infinite; }
@keyframes skeleton-pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 0.85; } }

/* respect reduced-motion everywhere (View Transitions are also gated in JS) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
