/* ==========================================================================
   BreatheOS — dark-only design system
   Mobile-first. Everything is driven by the tokens in :root.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg:            #0A0E13;
  --bg-soft:       #0E141C;
  --surface:       #121A24;
  --surface-2:     #18222E;
  --surface-3:     #1F2A38;
  --line:          rgba(255, 255, 255, .07);
  --line-strong:   rgba(255, 255, 255, .14);

  /* Text */
  --text:          #E8EDF4;
  --text-muted:    #96A3B6;
  --text-faint:    #7E8DA3;

  /* Brand + semantics */
  --mint:          #5CE1C4;
  --blue:          #5AA9FF;
  --violet:        #A78BFA;
  --amber:         #FFB454;
  --red:           #FF6B6B;
  --green:         #6EE7A0;

  --accent:        var(--mint);
  --on-accent:     #04231D;

  /* Accent washes used for chips, tags, icon tiles and callouts. Restated
     per theme, because a 14% tint of a neon on black is not the same idea
     as a 14% tint of a deep teal on white. */
  --tint-mint:   var(--tint-mint);
  --tint-blue:   var(--tint-blue);
  --tint-amber:  var(--tint-amber);
  --tint-red:    var(--tint-red);
  --tint-violet: var(--tint-violet);
  --ring-mint:   var(--ring-mint);
  --ring-red:    var(--ring-red);

  /* Severity ramp (1 → 5) */
  --sev-1: #5CE1C4;
  --sev-2: #8FDF8A;
  --sev-3: #FFD166;
  --sev-4: #FF9F5A;
  --sev-5: #FF6B6B;

  /* Type */
  --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Shape + depth */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 8px 24px -12px rgba(0, 0, 0, .8);
  --shadow-3: 0 24px 60px -20px rgba(0, 0, 0, .9);

  /* Metrics */
  --tabbar-h: 62px;
  --pad: 16px;
  --maxw: 1080px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

/* A component's own `display` beats the UA rule for [hidden] on specificity,
   so .tabbar / .topbar stayed visible when hidden was set. Settle it once. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  min-height: 100svh;
}

/* Ambient light behind everything — keeps the dark from going flat */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(90% 55% at 50% -12%, rgba(92, 225, 196, .10), transparent 62%),
    radial-gradient(70% 45% at 105% 8%, rgba(90, 169, 255, .07), transparent 60%);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.015em; line-height: 1.25; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
input, textarea, select { -webkit-appearance: none; appearance: none; }
a { color: var(--mint); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; border-radius: 6px; }
::selection { background: rgba(92, 225, 196, .28); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }

/* Inline icons carry no width/height of their own — without this they would
   stretch to fill whatever box they land in. */
svg { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.18em; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- boot ---- */
.boot {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-content: center; justify-items: center; gap: 20px;
  background: var(--bg);
  transition: opacity .3s ease;
}
.boot--out { opacity: 0; pointer-events: none; }
.boot-orb {
  width: 76px; height: 76px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--mint) 0 22%, transparent 24%),
              radial-gradient(circle at 50% 50%, transparent 0 44%, rgba(92,225,196,.85) 45% 52%, transparent 54%),
              radial-gradient(circle at 50% 50%, transparent 0 70%, rgba(90,169,255,.35) 71% 76%, transparent 78%);
  animation: breathe 5.2s ease-in-out infinite;
}
.boot-name { color: var(--text-faint); letter-spacing: .28em; text-transform: uppercase; font-size: 11px; font-weight: 500; }
@keyframes breathe {
  0%, 100% { transform: scale(.86); opacity: .75; }
  45%      { transform: scale(1.06); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .boot-orb, .onboard__orb { animation: none; }
}

/* ---------------------------------------------------------------- app ---- */
.app { position: relative; z-index: 1; min-height: 100svh; display: flex; flex-direction: column; }
.app[hidden] { display: none; }

.view {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(var(--safe-t) + 14px) var(--pad) calc(var(--tabbar-h) + var(--safe-b) + 28px);
  outline: none;
}

/* ------------------------------------------------------------- topbar ---- */
.topbar { display: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 50% 50%, var(--mint) 0 26%, transparent 28%),
              radial-gradient(circle at 50% 50%, transparent 0 52%, var(--mint) 53% 66%, transparent 68%),
              radial-gradient(circle at 50% 50%, transparent 0 84%, rgba(90,169,255,.55) 85% 100%);
}

/* ------------------------------------------------------------- tabbar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-top: 1px solid var(--line);
}
.tabbar__item {
  background: none; border: 0; cursor: pointer;
  display: grid; justify-items: center; gap: 3px;
  padding: 6px 2px; color: var(--text-faint);
  font-size: 10px; font-weight: 500; letter-spacing: .01em;
  transition: color .18s ease;
}
.tabbar__item svg { width: 22px; height: 22px; }
.tabbar__item[aria-current='page'] { color: var(--mint); }
.tabbar__fab {
  justify-self: center;
  width: 52px; height: 52px; border-radius: 50%;
  border: 0; cursor: pointer;
  display: grid; place-items: center;
  color: var(--on-accent);
  background: linear-gradient(150deg, #7BF0D6, var(--mint) 55%, #43C7AC);
  box-shadow: 0 6px 20px -6px rgba(92, 225, 196, .6), inset 0 1px 0 rgba(255,255,255,.4);
  transform: translateY(-10px);
  transition: transform .18s ease;
}
.tabbar__fab svg { width: 26px; height: 26px; }
.tabbar__fab:active { transform: translateY(-10px) scale(.93); }

/* ------------------------------------------------------- page headings --- */
.page-head { margin-bottom: 18px; }
.page-head__eyebrow {
  color: var(--text-faint); font-size: 12px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase;
}
.page-head h1 { font-size: 26px; margin-top: 2px; }
.page-head p { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }

.section { margin-top: 26px; }
.section__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 10px;
}
.section__head h2 { font-size: 15px; }

.link-btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: 0; padding: 4px 2px; cursor: pointer;
  color: var(--mint); font-size: 12.5px; font-weight: 500; flex: none;
}
/* Expand the tap area to ~44px without changing how the link looks or sits.
   Vertical only: widening it would push past right-aligned containers and
   create horizontal overflow. */
.link-btn::after { content: ''; position: absolute; inset: -9px 0; }
.link-btn svg { width: 14px; height: 14px; }
.link-btn--muted { color: var(--text-muted); }

/* --------------------------------------------------------------- card ---- */
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-1);
}
.card--flush { padding: 0; overflow: hidden; }
.card__title { font-size: 14px; font-weight: 600; }
.card__sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

.grid { display: grid; gap: 12px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ---------------------------------------------------------- stat tile ---- */
.stat {
  background: linear-gradient(180deg, var(--surface), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px 14px;
  min-width: 0;
}
.stat__label {
  color: var(--text-muted); font-size: 11.5px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.stat__value {
  font-size: 25px; font-weight: 600; letter-spacing: -.03em; margin-top: 4px;
  display: flex; align-items: baseline; gap: 5px;
}
.stat__unit { font-size: 12px; font-weight: 500; color: var(--text-faint); letter-spacing: 0; }
.stat__foot { color: var(--text-faint); font-size: 11.5px; margin-top: 2px; }
.stat--accent .stat__value { color: var(--mint); }
.stat--warn .stat__value { color: var(--amber); }
.stat--danger .stat__value { color: var(--red); }

/* ------------------------------------------------------------ buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 999px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: transform .12s ease, background .18s ease, opacity .18s ease;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }
.btn--primary {
  background: linear-gradient(150deg, #7BF0D6, var(--mint) 60%, #43C7AC);
  color: var(--on-accent); font-weight: 600;
  box-shadow: 0 8px 22px -12px rgba(92, 225, 196, .9);
}
.btn--ghost { background: transparent; border-color: var(--line-strong); }
.btn--danger { background: var(--tint-red); color: var(--red); border-color: var(--ring-red); }
.btn--danger-solid { background: var(--red); color: #2A0808; font-weight: 600; }
.btn--sm { padding: 8px 14px; font-size: 13px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-muted); cursor: pointer;
  transition: color .18s ease, background .18s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text); }
.icon-btn--sm { width: 30px; height: 30px; font-size: 18px; line-height: 1; }

/* --------------------------------------------------- big action buttons -- */
.actions-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.action-card {
  position: relative; overflow: hidden;
  display: grid; gap: 8px; align-content: start;
  padding: 16px 14px; text-align: left; cursor: pointer;
  border-radius: var(--r-lg); border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  color: var(--text); transition: transform .12s ease, border-color .18s ease;
}
.action-card:active { transform: scale(.98); }
.action-card__icon { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; }
.action-card__icon svg { width: 20px; height: 20px; }
.action-card__title { font-size: 14px; font-weight: 600; }
.action-card__sub { font-size: 11.5px; color: var(--text-muted); line-height: 1.35; }
.action-card--inhaler .action-card__icon { background: var(--tint-blue); color: var(--blue); }
.action-card--inhaler:hover { border-color: rgba(90, 169, 255, .4); }
.action-card--episode .action-card__icon { background: var(--tint-violet); color: var(--violet); }
.action-card--episode:hover { border-color: rgba(167, 139, 250, .4); }

/* --------------------------------------------------------------- rows ---- */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 13px 15px; background: none; border: 0; cursor: pointer;
  border-bottom: 1px solid var(--line);
  color: var(--text); transition: background .16s ease;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: rgba(255, 255, 255, .025); }
.row--static { cursor: default; }
.row--static:hover { background: none; }
.row__icon {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: var(--surface-2); color: var(--text-muted);
}
.row__icon svg { width: 18px; height: 18px; }
.row__body { flex: 1; min-width: 0; }
.row__title { font-size: 13.5px; font-weight: 500; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.row__sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; overflow-wrap: anywhere; }
.row__meta { flex: none; text-align: right; color: var(--text-faint); font-size: 11.5px; }
.row__chev { flex: none; color: var(--text-faint); display: grid; }
.row__chev svg { width: 16px; height: 16px; }

/* -------------------------------------------------------------- chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 13px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-muted); font-size: 12.5px; font-weight: 500;
  transition: all .16s ease; white-space: nowrap;
}
.chip:active { transform: scale(.96); }
.chip svg { width: 15px; height: 15px; vertical-align: -2.5px; }
.chip--icon { display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed='true'] {
  background: var(--tint-mint); border-color: var(--ring-mint); color: var(--mint);
}
.chip--sm { padding: 6px 11px; font-size: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-muted);
  font-size: 10.5px; font-weight: 500; white-space: nowrap;
}
.tag svg { width: 12px; height: 12px; }
.tag--cardio { background: var(--tint-amber); color: var(--amber); }
.tag--inhaler { background: var(--tint-blue); color: var(--blue); }
.tag--mint { background: var(--tint-mint); color: var(--mint); }
.tag--danger { background: var(--tint-red); color: var(--red); }

/* -------------------------------------------------- segmented control ---- */
.segmented {
  display: flex; gap: 3px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented__item {
  flex: 1 0 auto; padding: 7px 14px; border: 0; border-radius: 999px; cursor: pointer;
  background: none; color: var(--text-muted); font-size: 12.5px; font-weight: 500;
  white-space: nowrap; transition: all .16s ease;
}
.segmented__item[aria-selected='true'] { background: var(--surface-3); color: var(--text); }
/* Five range tabs have to fit a narrow phone without clipping. */
@media (max-width: 430px) {
  .segmented__item { padding-left: 11px; padding-right: 11px; }
}

/* -------------------------------------------------------------- forms ---- */
.field { display: block; margin-bottom: 16px; }
.field__label {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 2px 10px;
  font-size: 12.5px; font-weight: 500; color: var(--text-muted); margin-bottom: 7px;
}
.field__hint { margin-left: auto; }
.field__hint { font-size: 11.5px; color: var(--text-faint); font-weight: 400; }
.input, .select, .textarea {
  width: 100%; padding: 13px 14px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  color: var(--text); font-size: 15px;
  transition: border-color .16s ease, background .16s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: rgba(92, 225, 196, .6); background: var(--surface-2);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.select {
  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='%2396A3B6' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; padding-right: 40px;
}

.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  margin-bottom: 12px;
}
.toggle-row__text { min-width: 0; }
.toggle-row__title { font-size: 13.5px; font-weight: 500; }
.toggle-row__sub { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }

.switch { position: relative; flex: none; width: 48px; height: 28px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  transition: background .2s ease, border-color .2s ease;
}
.switch__thumb {
  position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-faint); transition: transform .2s cubic-bezier(.3,1.4,.6,1), background .2s ease;
  pointer-events: none;
}
.switch input:checked ~ .switch__track { background: var(--ring-mint); border-color: var(--ring-mint); }
.switch input:checked ~ .switch__thumb { transform: translateX(20px); background: var(--mint); }
.switch input:focus-visible ~ .switch__track { outline: 2px solid var(--mint); outline-offset: 2px; }

/* Severity picker */
.sev-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.sev-btn {
  padding: 11px 4px 9px; border-radius: var(--r-md); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; gap: 4px; justify-items: center;
  transition: all .16s ease;
}
.sev-btn__num { font-size: 17px; font-weight: 600; color: var(--text-muted); }
.sev-btn__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .45; }
.sev-btn[aria-pressed='true'] { border-color: currentColor; background: color-mix(in srgb, currentColor 14%, transparent); }
.sev-btn[aria-pressed='true'] .sev-btn__num { color: currentColor; }
.sev-btn[aria-pressed='true'] .sev-btn__dot { opacity: 1; }
.sev-1 { color: var(--sev-1); } .sev-2 { color: var(--sev-2); } .sev-3 { color: var(--sev-3); }
.sev-4 { color: var(--sev-4); } .sev-5 { color: var(--sev-5); }
.sev-caption { margin-top: 8px; font-size: 12px; color: var(--text-muted); min-height: 18px; }

/* Stepper */
.stepper {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px; padding: 3px;
}
.stepper__btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-size: 19px; line-height: 1;
  display: grid; place-items: center;
}
.stepper__btn:active { transform: scale(.92); }
.stepper__value { min-width: 46px; text-align: center; font-size: 16px; font-weight: 600; }

/* ------------------------------------------------------------- sheets ---- */
.sheet-host {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-host[hidden] { display: none; }
.sheet-backdrop {
  position: absolute; inset: 0; background: rgba(3, 6, 10, .68);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade-in .22s ease;
}
.sheet {
  position: relative; z-index: 1;
  width: 100%; max-width: 560px;
  max-height: min(92svh, 900px);
  display: flex; flex-direction: column;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  animation: sheet-up .3s cubic-bezier(.22, 1, .36, 1);
}
.sheet--closing { animation: sheet-down .2s ease forwards; }
.sheet-host--closing .sheet-backdrop { animation: fade-out .2s ease forwards; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheet-down { to { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop, .sheet--closing { animation: none !important; }
}
.sheet__grab { width: 38px; height: 4px; border-radius: 999px; background: var(--line-strong); margin: 9px auto 0; flex: none; }
.sheet__head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; flex: none;
  border-bottom: 1px solid var(--line);
}
.sheet__head h2 { font-size: 16px; flex: 1; }
.sheet__body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet__foot {
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); flex: none;
  display: flex; gap: 10px; background: var(--bg-soft);
}
.sheet__foot .btn { flex: 1; }

@media (min-width: 640px) {
  .sheet-host { align-items: center; padding: 20px; }
  .sheet { border-radius: var(--r-xl); border-bottom: 1px solid var(--line-strong); animation: pop-in .24s cubic-bezier(.22,1,.36,1); }
  .sheet__grab { display: none; }
  .sheet__foot { padding-bottom: 12px; }
  @keyframes pop-in { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
}

/* -------------------------------------------------------------- toast ---- */
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: calc(100vw - 32px); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2); font-size: 13px; font-weight: 500;
  animation: toast-in .26s cubic-bezier(.22,1,.36,1);
  pointer-events: auto;
}
.toast--out { animation: toast-out .22s ease forwards; }
.toast--ok { border-color: var(--ring-mint); }
.toast--err { border-color: var(--ring-red); color: #FFD3D3; }
.toast__undo { background: none; border: 0; color: var(--mint); font-weight: 600; font-size: 13px; cursor: pointer; padding: 0 2px; }
@keyframes toast-in { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateY(10px); opacity: 0; } }

/* ------------------------------------------------------------- charts ---- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart__readout {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  min-height: 20px; margin-bottom: 8px;
  font-size: 12px; color: var(--text-muted);
}
.chart__readout strong { color: var(--text); font-weight: 600; font-size: 13px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 11.5px; color: var(--text-muted); }
.chart-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend__swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.bar { cursor: pointer; transition: opacity .15s ease; }
.bar:hover { opacity: .78; }
.chart-empty {
  display: grid; place-items: center; min-height: 110px;
  color: var(--text-faint); font-size: 12.5px; text-align: center; padding: 16px;
}

/* ---------------------------------------------------------- misc bits ---- */
.empty {
  display: grid; justify-items: center; gap: 10px; text-align: center;
  padding: 34px 20px; border-radius: var(--r-lg);
  border: 1px dashed var(--line-strong); background: rgba(255, 255, 255, .015);
}
.empty__icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-faint); }
.empty__icon svg { width: 22px; height: 22px; }
.empty__title { font-size: 14px; font-weight: 600; }
.empty__text { font-size: 12.5px; color: var(--text-muted); max-width: 34ch; }

.day-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 18px 2px 8px; position: sticky; top: 0; z-index: 2;
  background: linear-gradient(180deg, var(--bg) 62%, transparent);
}
.day-head__label { font-size: 12.5px; font-weight: 600; }
.day-head__meta { font-size: 11.5px; color: var(--text-faint); }

.meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter__fill { height: 100%; border-radius: 999px; background: var(--mint); transition: width .4s ease; }
.meter__fill--warn { background: var(--amber); }
.meter__fill--danger { background: var(--red); }

.callout {
  display: flex; gap: 11px; padding: 13px 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); font-size: 12.5px; color: var(--text-muted);
  line-height: 1.5;
}
.callout svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.callout--warn { background: var(--tint-amber); border-color: var(--ring-amber); color: var(--ink-warn); }
.callout--danger { background: var(--tint-red); border-color: var(--ring-red); color: var(--ink-danger); }
.callout--mint { background: var(--tint-mint); border-color: var(--ring-mint); color: var(--ink-mint); }
.callout strong { color: var(--text); font-weight: 600; }

.insight-list { display: grid; gap: 10px; }
.insight {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
}
.insight__dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--mint); }
.insight__text { font-size: 12.5px; line-height: 1.5; color: var(--text-muted); }
.insight__text strong { color: var(--text); font-weight: 600; }

.danger-zone { border-color: var(--ring-red); background: var(--tint-red); }

/* Active-episode live card */
.live-card {
  position: relative; overflow: hidden;
  border: 1px solid rgba(167, 139, 250, .4);
  background: linear-gradient(150deg, var(--tint-violet), var(--surface) 60%);
}
.live-card::after {
  content: ''; position: absolute; inset: -40% -10% auto auto; width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(167, 139, 250, .22), transparent 68%);
  pointer-events: none;
}
.live-card > * { position: relative; z-index: 1; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--violet); flex: none;
  box-shadow: 0 0 0 0 rgba(167, 139, 250, .6); animation: pulse 2s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 9px rgba(167, 139, 250, 0); }
  100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0); }
}
.live-timer { font-size: 34px; font-weight: 600; letter-spacing: -.03em; }

/* Onboarding */
/* Onboarding owns the whole screen: .view's tabbar padding does not apply,
   because there is no tabbar yet. `safe center` matters — plain `center` clips
   the top of the content on short phones instead of letting it scroll. */
.view--onboarding { padding: 0; max-width: none; }

.onboard {
  min-height: 100svh; display: grid; align-content: safe center; gap: 22px;
  padding: calc(var(--safe-t) + 28px) 22px calc(var(--safe-b) + 28px);
  max-width: 460px; margin: 0 auto;
}

/* Short screens: tighten up so the whole thing still fits on one screen.
   A 360x780 phone is the common case this is tuned against. */
@media (max-height: 820px) {
  .onboard {
    gap: 12px;
    padding-top: calc(var(--safe-t) + 12px);
    padding-bottom: calc(var(--safe-b) + 12px);
  }
  .onboard__orb { width: 54px; height: 54px; }
  .onboard h1 { font-size: 23px; }
  .onboard > p { font-size: 12.5px; line-height: 1.45; }
  .onboard__points { gap: 8px; margin: 0; }
  .onboard__point { font-size: 12px; }
  .onboard__point strong { font-size: 13px; }
  .onboard .btn { padding-top: 11px; padding-bottom: 11px; }
}
@media (max-height: 680px) {
  .onboard__orb { display: none; }
  .onboard__points { gap: 7px; }
  .onboard__point { font-size: 12px; }
}
.onboard__orb {
  width: 84px; height: 84px; justify-self: center; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--mint) 0 22%, transparent 24%),
              radial-gradient(circle at 50% 50%, transparent 0 44%, rgba(92,225,196,.85) 45% 52%, transparent 54%),
              radial-gradient(circle at 50% 50%, transparent 0 70%, rgba(90,169,255,.4) 71% 76%, transparent 78%);
  animation: breathe 5.2s ease-in-out infinite;
}
.onboard h1 { font-size: 30px; text-align: center; }
.onboard > p { color: var(--text-muted); text-align: center; font-size: 14px; }
.onboard__points { display: grid; gap: 12px; margin: 4px 0; }
.onboard__point { display: flex; gap: 12px; align-items: flex-start; font-size: 12.5px; color: var(--text-muted); }
.onboard__point svg { width: 18px; height: 18px; color: var(--mint); flex: none; margin-top: 1px; }
.onboard__point strong { color: var(--text); font-weight: 600; display: block; font-size: 13.5px; }

.fine-print { font-size: 11.5px; color: var(--text-faint); line-height: 1.55; }

/* The printable report is built into the DOM only while printing.
   css/print.css reveals it; on screen it never shows. */
.report { display: none; }
.fine-print svg { width: 13px; height: 13px; vertical-align: -2px; }

/* A labelled control with its value on the right — used for preferences. */
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.setting-row:first-child { padding-top: 0; }
.setting-row:last-child { padding-bottom: 0; border-bottom: 0; }
.setting-row__text { min-width: 0; flex: 1; }
.setting-row__title { display: block; font-size: 13.5px; font-weight: 500; }
.setting-row__sub { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 2px; line-height: 1.45; }
.setting-row .input { width: 84px; flex: none; text-align: center; padding: 10px 8px; }

/* --------------------------------------------------------- responsive ---- */
@media (min-width: 860px) {
  :root { --pad: 24px; }
  .topbar {
    display: block; position: sticky; top: 0; z-index: 40;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid var(--line);
  }
  .topbar__inner {
    max-width: var(--maxw); margin: 0 auto; padding: 12px var(--pad);
    display: flex; align-items: center; gap: 20px;
  }
  .topbar__brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
  .topbar__nav { display: flex; gap: 3px; flex: 1; }
  .topbar__nav .tabbar__item {
    display: flex; flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 14px; border-radius: 999px; font-size: 13px;
  }
  .topbar__nav .tabbar__item svg { width: 17px; height: 17px; }
  .topbar__nav .tabbar__item[aria-current='page'] { background: var(--surface-2); color: var(--text); }
  .tabbar { display: none; }
  .view { padding-top: 22px; padding-bottom: 60px; }
  .toast-host { bottom: 24px; }
  .grid--auto { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .actions-2 { max-width: 560px; }
  .page-head h1 { font-size: 30px; }
  .day-head { top: 58px; }
}

@media (min-width: 1000px) {
  .cols-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
  .cols-2 > .section:first-child { margin-top: 26px; }
}

/* Stacked sheet layers (a confirm can open on top of a form) */
.sheet-layer { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .sheet-layer { align-items: center; padding: 20px; } }
body.is-locked { overflow: hidden; }

/* Inhaler kind → themed colour. The hex stored on an inhaler belongs to the
   dark palette; using it directly left tags at 2.3:1 in light mode. */
.kind-reliever    { --kind: var(--blue);       --kind-tint: var(--tint-blue); }
.kind-preventer   { --kind: var(--amber);      --kind-tint: var(--tint-amber); }
.kind-combination { --kind: var(--violet);     --kind-tint: var(--tint-violet); }
.kind-other       { --kind: var(--text-muted); --kind-tint: var(--surface-2); }
.row__icon.kind-reliever, .row__icon.kind-preventer,
.row__icon.kind-combination, .row__icon.kind-other,
.tag.kind-reliever, .tag.kind-preventer,
.tag.kind-combination, .tag.kind-other {
  background: var(--kind-tint); color: var(--kind);
}

/* Custom date range (Insights → Custom tab) */
.range-custom {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  margin-top: 10px; padding: 12px 13px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.range-custom__field { flex: 1 1 130px; min-width: 0; }
.range-custom__field span {
  display: block; font-size: 11.5px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px;
}
.range-custom__field .input { padding: 9px 11px; font-size: 14px; }
.range-custom__span {
  flex: none; padding-bottom: 10px; font-size: 12px; font-weight: 500; color: var(--mint);
  font-variant-numeric: tabular-nums;
}

/* Export-report card */
.export-card__row { display: flex; align-items: center; gap: 12px; }
.export-card__text { flex: 1; min-width: 0; }
.export-card__row .btn { flex: none; }
.export-card__hint { margin-top: 11px; }
.export-card--locked { border-style: dashed; }

.export-gate {
  margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line);
  display: grid; gap: 7px;
}
.export-gate__title { font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.export-gate__check {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12px; color: var(--text-faint); line-height: 1.45;
}
.export-gate__check svg { width: 15px; height: 15px; margin-top: 1px; color: var(--text-faint); }
.export-gate__check strong { color: var(--text-muted); font-weight: 500; }
.export-gate__check.is-ok { color: var(--mint); }
.export-gate__check.is-ok svg { color: var(--mint); }
.export-gate__check.is-ok strong { color: var(--mint); }

@media (max-width: 420px) {
  .export-card__row { flex-wrap: wrap; }
  .export-card__row .btn { width: 100%; }
}

/* ==========================================================================
   Light mode
   Dark is the default and lives in :root. This restates only what changes,
   so every component keeps one definition and both themes stay in step.
   ========================================================================== */
:root { color-scheme: dark; }

:root[data-theme='light'] {
  --bg:            #F4F7FA;
  --bg-soft:       #FFFFFF;
  --surface:       #FFFFFF;
  --surface-2:     #EEF2F7;
  --surface-3:     #E1E8F1;
  --line:          rgba(16, 26, 40, .10);
  --line-strong:   rgba(16, 26, 40, .18);

  --text:          #101A24;
  --text-muted:    #4B5C73;
  --text-faint:    #5C6B80;

  --mint:          #0A7A63;
  --blue:          #1C63B4;
  --violet:        #5A3FC0;
  --amber:         #855600;
  --red:           #A82525;
  --green:         #227A44;
  --on-accent:     #FFFFFF;

  --sev-1: #0B8F76;
  --sev-2: #4C8C28;
  --sev-3: #A67C00;
  --sev-4: #C25E17;
  --sev-5: #CE3B3B;

  --tint-mint:   rgba(10, 122, 99, .10);
  --tint-blue:   rgba(28, 99, 180, .10);
  --tint-amber:  rgba(133, 86, 0, .11);
  --tint-red:    rgba(168, 37, 37, .09);
  --tint-violet: rgba(90, 63, 192, .10);
  --ring-mint:   rgba(10, 122, 99, .38);
  --ring-red:    rgba(168, 37, 37, .32);
  --ring-amber:  rgba(133, 86, 0, .3);

  --ink-mint:    #0A5B4A;
  --ink-warn:    #6F4700;
  --ink-danger:  #962626;

  --shadow-1: 0 1px 2px rgba(16, 26, 40, .05);
  --shadow-2: 0 8px 24px -14px rgba(16, 26, 40, .26);
  --shadow-3: 0 24px 60px -22px rgba(16, 26, 40, .3);

  color-scheme: light;
}

:root[data-theme='light'] body::before {
  background:
    radial-gradient(90% 55% at 50% -12%, rgba(11, 143, 118, .07), transparent 62%),
    radial-gradient(70% 45% at 105% 8%, rgba(35, 116, 206, .05), transparent 60%);
}
:root[data-theme='light'] ::selection { background: rgba(11, 143, 118, .18); }

:root[data-theme='light'] .btn--primary,
:root[data-theme='light'] .tabbar__fab {
  background: linear-gradient(150deg, #0C8569, #0A7A63 55%, #086A57);
  color: #fff;
}
:root[data-theme='light'] .btn--primary { box-shadow: 0 8px 20px -12px rgba(11, 143, 118, .8); }
:root[data-theme='light'] .tabbar__fab {
  box-shadow: 0 6px 18px -6px rgba(11, 143, 118, .5), inset 0 1px 0 rgba(255, 255, 255, .25);
}
:root[data-theme='light'] .input:focus,
:root[data-theme='light'] .select:focus,
:root[data-theme='light'] .textarea:focus { border-color: var(--ring-mint); }

:root[data-theme='light'] .boot { background: var(--bg); }
:root[data-theme='light'] .action-card--inhaler:hover { border-color: rgba(35, 116, 206, .4); }
:root[data-theme='light'] .action-card--episode:hover { border-color: rgba(107, 79, 216, .4); }
:root[data-theme='light'] .live-card { border-color: rgba(107, 79, 216, .3); }
:root[data-theme='light'] .empty { background: rgba(16, 26, 40, .015); }
:root[data-theme='light'] .row:hover { background: rgba(16, 26, 40, .025); }
:root[data-theme='light'] .toast { background: #1B2430; border-color: rgba(255, 255, 255, .16); color: #F2F6FA; }
:root[data-theme='light'] .toast__undo { color: #5CE1C4; }

/* ==========================================================================
   Date & time picker
   ========================================================================== */
.input--picker {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  text-align: left; cursor: pointer;
}
.input--picker svg { width: 17px; height: 17px; color: var(--text-faint); }
.input--picker:hover { border-color: var(--line-strong); background: var(--surface-2); }

.dp { display: grid; gap: 18px; }
.dp-quick { margin-bottom: -4px; }

.dp-cal__head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 10px;
}
.dp-cal__title { font-size: 14px; font-weight: 600; }

.dp-dow, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dp-dow {
  margin-bottom: 6px; text-align: center;
  font-size: 11px; font-weight: 500; color: var(--text-faint);
}

.dp-day {
  aspect-ratio: 1 / 1; min-height: 36px; min-width: 0;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 11px;
  background: none; color: var(--text);
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background .14s ease, color .14s ease;
}
.dp-day:hover:not(:disabled) { background: var(--surface-2); }
.dp-day.is-outside { color: var(--text-faint); opacity: .55; }
.dp-day.is-today { border-color: var(--line-strong); }
.dp-day[aria-selected='true'] {
  background: var(--mint); color: var(--on-accent); border-color: transparent; font-weight: 600; opacity: 1;
}
.dp-day:disabled { opacity: .22; cursor: not-allowed; }

.tp__readout {
  text-align: center; font-size: 26px; font-weight: 600; letter-spacing: -.02em;
  margin-bottom: 10px; font-variant-numeric: tabular-nums;
}
.tp__cols {
  display: flex; align-items: stretch; justify-content: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 6px; position: relative;
}
/* Centre band, so the column reads as a wheel rather than a list. */
.tp__cols::before {
  content: ''; position: absolute; left: 6px; right: 6px; top: 50%;
  height: 36px; transform: translateY(-50%);
  background: var(--surface-2); border-radius: 9px; pointer-events: none;
}
.tp-col {
  height: 148px; overflow-y: auto; scrollbar-width: none;
  scroll-snap-type: y mandatory; padding: 56px 0;
  position: relative; z-index: 1;
}
.tp-col::-webkit-scrollbar { display: none; }
.tp__sep { align-self: center; font-size: 18px; font-weight: 600; color: var(--text-faint); z-index: 1; }

.tp-item {
  display: block; width: 100%; scroll-snap-align: center;
  padding: 8px 16px; border: 0; border-radius: 8px; cursor: pointer;
  background: none; color: var(--text-muted);
  font-size: 16px; font-weight: 500; font-variant-numeric: tabular-nums;
  transition: color .14s ease;
}
.tp-item[aria-selected='true'] { color: var(--mint); font-weight: 600; }
.tp-item:hover { color: var(--text); }

.tp-ampm {
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  margin-left: 4px; z-index: 1;
}
.tp-ampm .tp-item { font-size: 13px; padding: 7px 12px; border: 1px solid var(--line); }
.tp-ampm .tp-item[aria-selected='true'] {
  background: var(--tint-mint); border-color: var(--ring-mint); color: var(--mint);
}
