/* ---------------------------------------------------------------------------
   App shell styles.

   The design tokens live in css/system.css, which this file is loaded after.
   The names below are the ones the app's ~900 lines of rules already say; each
   is an alias onto a system token, so the app inherits ConnectAble's scale,
   radii, shadows and motion without a find-replace across every rule.
--------------------------------------------------------------------------- */
:root {
  /* MHI brand — official logo blues */
  --mhi-navy: var(--color-primary-hover);
  --mhi-blue: var(--color-primary);
  --mhi-blue-dark: var(--color-primary-hover);
  --mhi-mid: var(--color-primary-mid);
  --mhi-light: var(--color-primary-pale);
  --mhi-gold: #c9a227;
  --mhi-gold-light: #f5e6b8;
  --mhi-warm: var(--color-primary-light);

  --blue-900: var(--color-primary-deep);
  --blue-800: var(--color-primary-hover);
  --blue-700: var(--color-primary);
  --blue-600: #3d6fad;
  --blue-500: var(--color-primary-mid);
  --blue-100: var(--color-primary-pale);
  --blue-50: var(--color-primary-light);
  --chart-sys: var(--color-primary-hover);
  --chart-dia: var(--color-primary-mid);

  --slate-900: var(--color-text-primary);
  --slate-700: var(--color-text-secondary);
  --slate-500: var(--color-text-muted);
  --slate-200: #D7DFE9;
  --slate-100: #E9EFF5;
  --slate-50: var(--color-surface);
  --white: var(--color-surface-raised);
  --red-600: var(--color-error);
  --amber-500: #f59e0b;

  --radius: var(--radius-xl);
  --radius-sm: var(--radius-lg);
  --shadow: var(--shadow-sm);
  --nav-h: 72px;
  --header-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  /* rem, so the text-size setting reaches it. */
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text-primary);
  background:
    radial-gradient(ellipse at 30% 0%, rgba(4, 81, 132, 0.08) 0%, transparent 60%),
    var(--color-bg);
  min-height: 100dvh;
}

button, input, select, textarea {
  font: inherit;
}

button { cursor: pointer; border: none; background: none; }

a { color: var(--blue-700); }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--brand-navy);
  color: var(--color-on-brand);
  padding: 12px 16px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  /* It is a link home, but it is header chrome: it keeps the header's own
     color rather than the page link color. */
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
  background: #5F88C2;
  object-fit: cover;
}

.brand-org {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
  line-height: 1.2;
}

.brand-title {
  margin: 2px 0 0;
  font-size: 1.0625rem;
  font-weight: 700;
  text-wrap: balance;
  line-height: 1.2;
}

.brand-patient {
  margin: 2px 0 0;
  font-size: 1rem;
  opacity: 0.9;
  overflow-wrap: anywhere;
}

.app-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
}

/* The person and the date get a row of their own, full width, so the line
   wraps once at most instead of four times beside the buttons. */
.app-header-inner .brand-patient { flex-basis: 100%; margin: 0; min-height: 1.5em; }

/* On a phone the logo carries the organisation's name, as on the public
   pages; the three-line uppercase name doubled the header's height. */
@media (max-width: 480px) {
  .brand-org { display: none; }
}

.app-header h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  text-wrap: balance;
}

/* Charts */
.chart-wrap {
  margin: 8px 0 4px;
  overflow-x: auto;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  min-width: 280px;
}

.chart-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--slate-500);
  font-size: 1rem;
  background: var(--slate-50);
  border-radius: 12px;
  border: 1px dashed var(--slate-200);
}

.chart-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 10px;
  font-size: 1rem;
  color: var(--slate-500);
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  font-style: normal;
}

.chart-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.chart-tab {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--slate-200);
  background: var(--white);
  font-size: 1rem;
  font-weight: 600;
  color: var(--slate-500);
}

.chart-tab.active {
  background: var(--mhi-blue);
  border-color: var(--mhi-blue);
  color: var(--color-on-primary);
}

/* MHI footer strip */
.mhi-footer {
  text-align: center;
  padding: 16px;
  margin-top: 8px;
}

.mhi-footer img {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  margin-bottom: 8px;
}

.mhi-footer p {
  margin: 0;
  font-size: 1rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
  text-wrap: pretty;
}

.mhi-footer a {
  color: var(--mhi-blue);
  font-weight: 600;
  text-decoration: none;
}

.app-header .sub {
  margin: 2px 0 0;
  font-size: 1rem;
  opacity: 0.85;
}

.header-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgb(255 255 255 / 0.15);
  color: var(--color-on-brand);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.icon-btn:active { transform: scale(0.96); }

.main { padding: 16px; }

.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--white);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 14px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
  text-wrap: balance;
}

.card-sub {
  margin: -8px 0 12px;
  font-size: 1rem;
  color: var(--slate-500);
  text-wrap: pretty;
}

/* Dashboard hero */
.hero-card {
  background: linear-gradient(145deg, var(--brand-navy), var(--brand-navy) 50%, var(--brand-blue));
  color: var(--color-on-brand);
  border: none;
  padding: 20px;
  position: relative;
  overflow: hidden;
}



.hero-card .greeting {
  font-size: 1rem;
  opacity: 0.9;
  margin: 0 0 4px;
}

.hero-card .name {
  font-size: 1.375rem;
  font-weight: 700;
  margin: 0 0 16px;
  text-wrap: balance;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-pill {
  background: rgb(255 255 255 / 0.14);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}

/* The Meds pill opens the dose schedule (A1-10). */
button.stat-pill { font: inherit; color: inherit; border: 0; width: 100%; cursor: pointer; }

.stat-pill .num {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-pill .lbl {
  font-size: 0.8125rem;
  opacity: 0.85;
  line-height: 1.2;
}

/* Quick actions */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--slate-200);
  background: var(--white);
  text-align: left;
  min-height: 88px;
  transition: transform 120ms ease-out, border-color 120ms ease-out;
}

.quick-btn:active { transform: scale(0.98); }
.quick-btn .emoji { font-size: 1.5rem; }
.quick-btn .label { font-size: 1rem; font-weight: 600; color: var(--slate-900); }
.quick-btn .hint { font-size: 1rem; color: var(--slate-500); }

/* Week strip */
.week-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.week-strip::-webkit-scrollbar { display: none; }

.day-chip {
  flex: 1 0 44px;
  min-width: 44px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid var(--color-text-muted);
  background: var(--white);
  text-align: center;
  font-size: 1rem;
  color: var(--slate-500);
}

.day-chip .dow { display: block; font-weight: 600; }
.day-chip .dom { display: block; font-size: 1rem; font-weight: 700; color: var(--slate-900); font-variant-numeric: tabular-nums; }

.day-chip.selected {
  background: var(--blue-700);
  border-color: var(--blue-700);
  color: var(--color-on-primary);
}

.day-chip.selected .dom { color: var(--color-on-primary); }

.day-chip.has-data::after {
  content: "";
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--blue-500);
  margin: 4px auto 0;
}

.day-chip.selected.has-data::after { background: var(--white); }

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

.mood-btn {
  padding: 10px 4px;
  border-radius: 12px;
  border: 2px solid var(--color-border-input);
  background: var(--white);
  color: var(--color-text-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.mood-btn .m-emoji { display: block; font-size: 1.25rem; margin-bottom: 4px; }
.mood-btn.selected { border-color: var(--blue-600); background: var(--blue-50); color: var(--blue-800); }

/* Tasks */
.task-list { display: flex; flex-direction: column; gap: 4px; }

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--color-border-input);
  background: var(--slate-50);
  min-height: 48px;
}

.task-item input { width: 20px; height: 20px; accent-color: var(--blue-600); flex-shrink: 0; }
.task-item.done span { text-decoration: line-through; color: var(--color-text-secondary); }

/* Water stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stepper button {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--color-surface);
  border: 1px solid var(--color-border-input);
  color: var(--color-text-primary);
}

.stepper button.plus { background: var(--blue-600); color: var(--color-on-brand); border-color: var(--blue-600); }
.stepper .value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 40px; text-align: center; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 1rem; font-weight: 600; color: var(--slate-700); margin-bottom: 6px; }
.field-hint { display: block; font-weight: 400; color: var(--color-text-muted); }
.form-date-line { margin: 0; font-size: 1rem; color: var(--color-text-secondary); }
.form-date #bpDateField { margin-top: 8px; }
.btn-text {
  min-height: 32px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--color-primary);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.btn-text:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: var(--focus-ring-offset); }
/* The message sits beside the field it is about, and the field says it is
   wrong to a screen reader through aria-invalid (F04). */
.field-error { margin: 6px 0 0; font-size: 1rem; font-weight: 600; color: var(--color-error); }
.input[aria-invalid="true"] { border-color: var(--color-error); }
.modal-notice { margin: 12px 0 0; font-size: 1rem; font-weight: 600; color: var(--color-error); }

.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--color-border-input);
  border-radius: 12px;
  background: var(--white);
  color: var(--slate-900);
}

.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--blue-500);
  outline-offset: 0;
  border-color: var(--blue-500);
}

.textarea { resize: vertical; min-height: 80px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  min-height: 48px;
  letter-spacing: -0.01em;
  transition: background var(--duration-hover) var(--ease-standard),
              box-shadow var(--duration-hover) var(--ease-standard),
              border-color var(--duration-hover) var(--ease-standard),
              color var(--duration-hover) var(--ease-standard),
              transform var(--duration-hover) var(--ease-standard);
}

.btn:active { transform: scale(0.98); }
/* Colour and hover live in system.css; a gradient copy here overrode them. */
.btn-primary { width: 100%; }
/* .btn-secondary lives in system.css only. A copy here loaded later and
   overrode its dark-mode rule, leaving white glass under light text (1.49:1). */
/* #DC2626 on #fef2f2 measured 4.41:1, just under AA. */
.btn-danger { background: #fef2f2; color: #a81c1c; }
.btn-sm { padding: 8px 14px; min-height: 44px; font-size: 1rem; }
/* A label wraps rather than running off a small phone: Spanish ones are a
   quarter longer ("Semana siguiente", "Agregar el resurtido a mi calendario"). */
.btn { white-space: normal; text-align: center; }
.btn-sm { line-height: 1.2; }

/* BP badge */
.bp-badge {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.bp-normal { background: var(--color-ok-light); color: var(--color-ok); }
.bp-elevated { background: #fef9c3; color: #854d0e; }
.bp-stage1 { background: #ffedd5; color: #9a3412; }
.bp-high { background: #fee2e2; color: #991b1b; }
.bp-crisis { background: #fecaca; color: #7f1d1d; font-weight: 700; }

/* Vitals log */
.log-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--slate-100);
  font-size: 1rem;
}

.log-row:last-child { border-bottom: none; }
/* A reading is tapped to change or delete it (F05): a real button, styled
   as the row it always was. */
button.log-row {
  width: 100%;
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
button.log-row:last-child { border-bottom: none; }
button.log-row:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: var(--focus-ring-offset); }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-delete { margin-top: 16px; }
.log-date { color: var(--slate-500); font-variant-numeric: tabular-nums; }
.log-value { font-weight: 600; font-variant-numeric: tabular-nums; }
/* The category in words beside the tint: Stage 2 and Crisis were
   near-identical pinks, and a tint says nothing to a colour-blind reader (F40). */
.log-reading { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }
.avg-crisis { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; background: var(--color-error-light); color: var(--color-text-primary); font-weight: 600; }
.log-category { font-size: 0.875rem; font-weight: 600; color: var(--color-text-secondary); }

/* Med cards */
.med-card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
}

.med-card h3 { margin: 0 0 4px; font-size: 1rem; }
.med-card .meta { font-size: 1rem; color: var(--slate-500); margin-bottom: 10px; }

.slot-grid { display: flex; flex-direction: column; gap: 8px; }

.slot-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  background: var(--white);
  min-height: 48px;
}

.slot-item.taken { background: var(--blue-50); border-color: var(--blue-100); }
.slot-item input { width: 22px; height: 22px; accent-color: var(--blue-600); }

/* "When is it taken?" in the medicine form: the same rows as the daily schedule. */
.med-times { display: grid; gap: 8px; border: 0; padding: 0; min-width: 0; }
.med-times legend { padding: 0; margin-bottom: 6px; font-size: 1rem; font-weight: 600; color: var(--slate-700); }

/* Visit card */
.visit-card {
  border-left: 4px solid var(--blue-600);
  padding-left: 14px;
  margin-bottom: 14px;
}

.visit-card h3 { margin: 0 0 4px; font-size: 1rem; }
.visit-card p { margin: 0; font-size: 1rem; color: var(--slate-700); }

/* Contact card */
.contact-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  margin-bottom: 8px;
}

.contact-card a { font-size: 1rem; font-weight: 600; text-decoration: none; }

/* Resources */
.resource-item {
  display: block;
  padding: 14px;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  margin-bottom: 8px;
  text-decoration: none;
  color: inherit;
}

.resource-item strong { display: block; color: var(--blue-800); margin-bottom: 8px; }
.resource-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.resource-actions .btn { width: auto; }
.resource-note { margin: 8px 0 0; color: var(--color-text-secondary); }

/* PHQ */
.phq-q { margin-bottom: 16px; }
.phq-q p { margin: 0 0 8px; font-size: 1rem; font-weight: 500; }
.phq-scale { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.phq-opt { line-height: 1.25; padding: 8px 6px; }
.phq-score { font-weight: 400; color: var(--color-text-secondary); }
.phq-opt.selected .phq-score { color: inherit; }
.phq-opt {
  padding: 10px 4px;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--white);
  color: var(--color-text-primary);
}
.phq-opt.selected { background: var(--blue-600); color: var(--color-on-brand); border-color: var(--blue-600); }

.score-banner {
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 12px;
}
.score-ok { background: var(--color-ok-light); color: var(--color-ok); }
.score-warn { background: #fef3c7; color: #92400e; }
.score-alert { background: #fee2e2; color: #991b1b; }

/* BP reference table */
.ref-table { width: 100%; font-size: 1rem; border-collapse: collapse; }
.ref-table th, .ref-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--slate-100); }
.ref-table th { font-weight: 600; color: var(--slate-500); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--white);
  border-top: 1px solid var(--slate-200);
  padding-bottom: var(--safe-bottom);
}

.bottom-nav-inner {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  height: var(--nav-h);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--slate-500);
  padding: 8px 4px;
}

.nav-btn .nav-icon { font-size: 1.25rem; line-height: 1; }
.nav-btn.active { color: var(--blue-700); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgb(15 23 42 / 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal-sheet {
  width: 100%;
  max-width: 480px;
  overscroll-behavior: contain;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--white);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  animation: slideUp 200ms ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--slate-200);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h2 { margin: 0; font-size: 1.125rem; }

/* Toast */
.toast-wrap {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100% - 32px));
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--color-ink);
  border: 1px solid rgb(255 255 255 / 0.16);
  color: var(--color-on-brand);
  font-size: 1rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: fadeIn 200ms ease-out;
}

.toast.success { background: var(--brand-blue); }
.toast.error {
  background: var(--color-error-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: auto;
}
.toast.has-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: auto;
}
.toast-action {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.toast-action:focus-visible { outline: var(--focus-ring-width) solid currentColor; outline-offset: var(--focus-ring-offset); }
.toast-close {
  flex: none;
  min-width: 36px;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.toast-close:focus-visible { outline: var(--focus-ring-width) solid currentColor; outline-offset: var(--focus-ring-offset); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Empty state */
.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--slate-500);
}

.empty .empty-icon { font-size: 2rem; margin-bottom: 8px; }
.empty p { margin: 0 0 14px; font-size: 1rem; text-wrap: pretty; }

/* Onboarding */
.onboard {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--white);
  display: flex;
  flex-direction: column;
  padding: 24px 20px calc(24px + var(--safe-bottom));
}

.onboard.hidden { display: none; }
/* MHI's name on the first screen, and the step in words: three bars alone
   said nothing to a screen reader and looked like any template (A4-11). */
.onboard { overflow-y: auto; }
.onboard-brand { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; font-weight: 600; color: var(--color-text-secondary); }
.onboard-brand img { border-radius: 50%; flex-shrink: 0; }
.onboard-step { margin: 8px 0 4px; font-size: 1rem; font-weight: 600; color: var(--color-text-secondary); }
#obEasier { margin: 4px 0 16px; }

/* The language menu sits with the text size controls: its own row, the
   label beside it. */
.lang-pick { display: flex; align-items: center; gap: var(--space-2); flex-basis: 100%; font-weight: 600; }
.lang-pick .select { width: auto; min-width: 12rem; min-height: 44px; }
/* Until the chosen language's words arrive (js/i18n.js, at most 3 s), so
   English does not flash past someone who reads another language. */
html[data-i18n='loading'] body { visibility: hidden; }
/* Right to left (Arabic), overflow to the left scrolls: the skip link parked
   at left -9999px made the page 10,000px wide. It waits off the right edge. */
html[dir='rtl'] .skip-link { left: auto; right: -9999px; }
html[dir='rtl'] .skip-link:focus { right: 0; }
/* MHI's name, address and phone are English and must read exactly as
   everywhere else: in Arabic, "1781" and "(941)" moved to the line's end. */
html[dir='rtl'] .app-footer p:first-child { direction: ltr; text-align: right; }
/* Longer words than English ("Показания", "Сохранить копию", "Ужасно")
   wrap inside their buttons rather than widen a 320px screen. English fits
   as before, so nothing wraps there. */
.app-header .header-actions { flex-wrap: wrap; }
.nav-btn, .mood-btn { min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.mood-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.onboard-progress {
  display: flex;
  gap: 6px;
  margin-bottom: 32px;
}

.onboard-dot {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--slate-200);
}

.onboard-dot.done { background: var(--blue-600); }

.onboard h2 { font-size: 1.5rem; margin: 0 0 8px; text-wrap: balance; }
.onboard p { color: var(--slate-500); margin: 0 0 24px; text-wrap: pretty; }

.onboard-actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

/* Section divider */
.section-label {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  margin: 20px 0 10px;
}

/* Progress ring */
.progress-ring {
  width: 56px;
  height: 56px;
  position: relative;
}

.progress-ring svg { transform: rotate(-90deg); }
.progress-ring .pct {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Landing */
.landing { min-height: 100dvh; }
.landing-hero {
  background: linear-gradient(160deg, var(--brand-navy) 0%, var(--brand-navy) 45%, var(--brand-blue) 100%);
  color: var(--color-on-brand);
  padding: 48px 24px 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.landing-hero::before {
  content: "";
  position: absolute;
  bottom: -60px;
  left: -60px;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: var(--mhi-gold);
  opacity: 0.1;
}

.landing-badge {
  display: inline-block;
  background: rgb(255 255 255 / 0.15);
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.landing-hero img { border-radius: 20px; margin-bottom: 20px; }
.landing-hero h1 { font-size: 1.75rem; margin: 0 0 8px; text-wrap: balance; }
.landing-hero p { opacity: 0.9; margin: 0; text-wrap: pretty; }

.landing-body { max-width: 480px; margin: 0 auto; padding: 24px 20px; }

.feature-list { list-style: none; padding: 0; margin: 0 0 24px; }
.feature-list li {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--slate-100);
  font-size: 1rem;
  text-wrap: pretty;
}

.feature-list .fi { font-size: 1.25rem; flex-shrink: 0; }

.landing-cta {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--mhi-blue);
  color: var(--color-on-primary);
  text-align: center;
  text-decoration: none;
  border-radius: 14px;
  font-weight: 700;
  font-size: 1.0625rem;
  margin-bottom: 12px;
  box-shadow: 0 4px 14px rgb(4 81 132 / 0.35);
}

.landing-cta:active { opacity: 0.9; }

/* Scene banner + help */
.scene-banner {
  width: 100%;
  height: 88px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius) var(--radius) 0 0;
  margin: -16px -16px 14px;
  width: calc(100% + 32px);
}

.card.has-scene {
  padding-top: 0;
  overflow: hidden;
}

/* Tips on a plain surface with a blue edge, not cream and gold (A4-08); the
   988 card is set apart from them without borrowing the crisis red. */
.edu-card {
  border-left: 4px solid var(--color-primary);
  background: var(--color-surface-raised);
}
.edu-card.support-card {
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary-border);
  border-left: 4px solid var(--color-primary);
}

.edu-card.crisis {
  border-left-color: var(--red-600);
  background: #fef2f2;
}

.edu-card h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  color: var(--mhi-navy);
}

.edu-card p {
  margin: 0;
  font-size: 1rem;
  color: var(--slate-700);
  text-wrap: pretty;
}

.help-step {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--slate-100);
}

.help-step:last-child { border-bottom: none; }

.help-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--mhi-blue);
  color: white;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 700;
}

.help-step .help-num { color: var(--color-on-primary); }
.help-step strong { display: block; margin-bottom: 2px; font-size: 1rem; }
.help-step span { font-size: 1rem; color: var(--slate-500); text-wrap: pretty; }

.bp-table-aha {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  border-radius: 12px;
  overflow: hidden;
}

.bp-table-aha th {
  background: #334155;
  color: white;
  padding: 10px 6px;
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
/* In capitals "DIASTÓLICA" pushed the last column off a phone screen. */
html[lang='es'] .bp-table-aha th { text-transform: none; letter-spacing: 0; }

.bp-table-aha td {
  padding: 10px 6px;
  text-align: center;
  font-weight: 600;
  border-bottom: 1px solid rgb(0 0 0 / 0.06);
}

/* The rows keep their fills in both themes, so their text is fixed too:
   ink on the light rows, white on the dark ones. Stage 2 was white on
   #f97316, 2.8:1; the deeper orange is 5.2:1 and still reads as orange. */
.bp-table-aha tr.row-normal td { background: #B5C6E0; color: var(--color-ink); }
.bp-table-aha tr.row-elevated td { background: #fef08a; color: var(--color-ink); }
.bp-table-aha tr.row-stage1 td { background: #fdba74; color: var(--color-ink); }
.bp-table-aha tr.row-stage2 td { background: #c2410c; color: var(--color-on-brand); }
.bp-table-aha tr.row-crisis td { background: #b91c1c; color: var(--color-on-brand); }

.bp-running-list .log-row {
  padding: 12px 0;
}

.bp-running-list .log-meta {
  font-size: 1rem;
  color: var(--slate-500);
}

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

/* Save-failure banner. Deliberately loud and not dismissible: the person is
   entering readings that are not being kept. */
.storage-warning {
  margin: 12px 16px 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--color-error-light);
  border: 1px solid var(--color-error);
  color: #7f1d1d;
}
.storage-warning p { margin: 0 0 6px; font-size: 1rem; }
.storage-warning .btn { margin-top: 6px; }

/* A new release waits for the person to choose when to refresh. Tokens only,
   so it follows the dark palette. */
.update-ready {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 16px 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary-border);
  color: var(--color-text-primary);
}
.update-ready p { margin: 0; font-size: 1rem; }

/* Seven-day average block. The average is the headline number because that is
   what a clinician reads; the single latest reading sits under it. */
.avg-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.avg-value { margin: 0; font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; color: var(--color-primary); font-family: var(--font-sans); font-variant-numeric: tabular-nums; }
.avg-caption { margin: 2px 0 0; font-size: 1rem; color: var(--slate-500); }
.avg-splits { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.avg-split { background: var(--color-surface); border-radius: 12px; padding: 10px 12px; }
.avg-split-label { display: block; font-size: 0.8125rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--slate-500); }
.avg-split-value { display: block; font-size: 1.125rem; font-weight: 700; color: var(--color-text-primary); }
.avg-split-count { display: block; font-size: 0.8125rem; color: var(--slate-500); }
.pattern-note { margin-top: 14px; padding: 12px 14px; border-radius: 12px; border-left: 4px solid var(--color-warning); background: var(--color-warning-light); }
.pattern-note p { margin: 0; font-size: 1rem; color: #7c3a06; }
.pattern-note.pattern-crisis { border-left-color: var(--color-error); background: var(--color-error-light); }
.pattern-note.pattern-crisis p { color: #7f1d1d; font-weight: 600; }

/* Install prompt. Shown once there are records worth protecting, never on a
   first visit. */
/* It appears after the page has drawn, so it floats above the tab bar rather
   than pushing everything down under a finger (F51). */
.install-card {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  z-index: 45;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--white);
  border: 1px solid var(--color-primary-border);
  box-shadow: var(--shadow-lg, 0 8px 24px rgb(0 0 0 / 0.18));
}
.install-card p { margin: 0 0 6px; font-size: 1rem; color: var(--color-text-secondary); }
.install-card p strong { color: var(--color-text-primary); }
.install-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.device-facts { margin: 0 0 12px; padding-left: 20px; }
.device-facts li { margin-bottom: 4px; }

/* The month picker and filters above the reading log (A6-01). */
.log-month { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; }
.log-month .btn { width: auto; }
.log-month-label { margin: 0; font-weight: 700; text-align: center; }
.log-filters { display: grid; gap: 8px; margin-bottom: 8px; }

/* One icon set, drawn in the text colour: blue on the page, white on the
   navy header (A4-07). */
/* 1em: the same box the emoji filled, so no bar or button grows. */
.icon { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.quick-btn .emoji, .empty-icon { color: var(--color-primary); }

/* Shown for the moment the backup on this device is read, while the screen
   behind takes no input. */
.records-loading {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  z-index: 46;
  margin: 0;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--white);
  border: 1px solid var(--color-primary-border);
  box-shadow: var(--shadow-lg, 0 8px 24px rgb(0 0 0 / 0.18));
  font-size: 1rem;
  color: var(--color-text-primary);
  text-align: center;
}
.install-actions .btn { width: auto; flex: 1; }

/* Technique coaching, at the point of entry rather than buried in help. */
.howto-details {
  margin: -4px 0 14px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
}
.howto-details summary {
  padding: 10px 14px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
}
.howto-list { margin: 0; padding: 0 16px 14px 32px; font-size: 1rem; line-height: 1.7; color: var(--color-text-secondary); }

.print-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.print-options { display: grid; gap: 8px; margin-top: 12px; }

/* App footer. The app screen carried no visible contact details, which broke
   the rule that the address a person can see matches the one in the markup. */
.app-footer {
  margin: 24px 16px 0;
  padding: 16px;
  border-top: 1px solid var(--color-border);
  font-size: 1rem;
  line-height: 1.7;
  /* It sits on the page background, which is darker than a card: the
     secondary grey measured 4.28:1 there. */
  color: var(--color-text-primary);
}
.app-footer p { margin: 0 0 8px; }
.app-footer a { color: var(--color-primary); }


/* Refill countdown and medication notes. */
.refill { margin: 6px 0 0; font-size: 1rem; font-weight: 600; color: var(--color-primary); }
.refill-soon { color: #92400e; }
.refill-late { color: var(--color-error); }
.med-notes { margin-top: 6px; font-size: 1rem; }

/* Backup nudge. Records live on one device; a copy elsewhere is the backup. */
.backup-card { border-color: var(--color-primary-border); background: var(--color-primary-light); }


/* Voice entry. Two numbers into two small boxes is the hardest part of this
   app for a person with a tremor or low vision. */
.voice-btn { width: 100%; margin: 0 0 12px; }
.voice-status { margin: -6px 0 12px; font-size: 1rem; color: var(--color-text-secondary); }
.voice-status:empty { display: none; }

/* Dark mode for the two banners that carry their own fills.
   Measured before this block: the save-failure banner at 1.34:1 and the pattern
   note at 1.41:1 — dark red text on a fill that had inverted underneath it. The
   banner that says records are not being saved is the worst element on the site
   to lose, so it gets the same treatment system.css already gives .btn-secondary. */
@media (prefers-color-scheme: dark) {
  .storage-warning {
    background: rgba(248, 113, 113, 0.14);
    border-color: rgba(248, 113, 113, 0.45);
    color: #FECACA;
  }
  .pattern-note { background: rgba(251, 191, 36, 0.14); }
  .pattern-note p { color: #FDE68A; }
  .pattern-note.pattern-crisis { background: rgba(248, 113, 113, 0.14); }
  .pattern-note.pattern-crisis p { color: #FECACA; }
  /* The remaining status chips are light fills with dark text for the same
     reason; the normal/ok pair reads --color-ok and needs nothing here. */
  .bp-elevated { background: rgba(251, 191, 36, 0.18); color: #FDE68A; }
  .bp-stage1 { background: rgba(251, 146, 60, 0.20); color: #FED7AA; }
  .bp-high { background: rgba(248, 113, 113, 0.18); color: #FECACA; }
  .bp-crisis { background: rgba(248, 113, 113, 0.28); color: #FEE2E2; }
  /* The two chart lines were one colour in dark mode (F39). */
  :root { --chart-dia: var(--color-primary-deep); }
  /* The education cards and the "When to seek help" card had light fills
     under text that turned light: 1.88:1 and 1.75:1, the 911 guidance
     among them (F12). */
  .edu-card { background: var(--color-surface-raised); }
  .edu-card h2 { color: var(--color-primary-deep); }
  .edu-card p { color: var(--color-text-secondary); }
  .edu-card.crisis { background: var(--color-error-light); }
  .edu-card.crisis h2, .edu-card.crisis p { color: #FECACA; }
}

/* Tablet, and a phone held sideways. Still the phone layout with its bottom
   tabs, which is right for a touch screen, but 480px of content inside a 768px
   screen reads as a mistake rather than a choice. */
@media (min-width: 600px) and (max-width: 859px) {
  .app-shell { max-width: 680px; }
  .bottom-nav-inner { max-width: 680px; }
  .quick-grid, .print-grid { grid-template-columns: repeat(4, 1fr); }
  .field-row { max-width: 560px; }
}

/* ---------------------------------------------------------------------------
   Laptop and tablet layout.

   The app was built phone-first and stayed 480px wide at every size, so on a
   laptop it was a narrow strip down the middle with a full-width tab bar
   stranded at the bottom of the screen. Below 860px that phone layout is still
   exactly right and nothing here applies.

   From 860px the same markup becomes a desktop app: the tab bar turns into a
   left sidebar, the content column widens, and the real estate goes to the
   cards rather than to empty margins. --header-h is measured from the header
   itself in js/app.js, so the sidebar sits under it at any text size.
--------------------------------------------------------------------------- */
@media (min-width: 860px) {
  .app-shell {
    max-width: none;
    padding-bottom: 0;
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    grid-template-areas:
      "header header"
      "nav    banners"
      "nav    main"
      "nav    footer";
    grid-template-rows: auto auto 1fr auto;
  }
  .app-banners { grid-area: banners; }
  .app-footer { grid-area: footer; }

  .app-header { grid-area: header; }
  .app-header-inner { max-width: 1240px; margin: 0 auto; }

  /* Same buttons, same order, read as a sidebar. */
  .bottom-nav {
    grid-area: nav;
    position: sticky;
    top: var(--header-h);
    bottom: auto;
    left: auto;
    right: auto;
    align-self: start;
    height: calc(100dvh - var(--header-h));
    background: var(--white);
    border-top: none;
    border-right: 1px solid var(--color-border);
    padding-bottom: 0;
  }
  .bottom-nav-inner {
    max-width: none;
    height: 100%;
    flex-direction: column;
    gap: 4px;
    padding: 20px 12px;
    overflow-y: auto;
  }
  .nav-btn {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 1rem;
    text-align: left;
    transition: background var(--duration-hover) var(--ease-standard),
                color var(--duration-hover) var(--ease-standard);
  }
  .nav-btn:hover { background: var(--color-surface); }
  .nav-btn .nav-icon { font-size: 1.25rem; }
  .nav-btn.active { background: var(--color-primary-light); }

  .main {
    grid-area: main;
    width: 100%;
    max-width: 1060px;
    padding: 28px 32px 72px;
  }

  .storage-warning,
  .update-ready,
  .app-footer { max-width: 1060px; margin-left: 32px; margin-right: 32px; }
  .install-card { left: auto; right: 32px; bottom: 32px; max-width: 420px; }

  /* A form that stretches to the full width of a laptop is harder to use, not
     easier: the label and its box end up a screen apart. */
  .field-row { max-width: 640px; }
  .input, .select, .textarea { max-width: 100%; }
  /* A full-width button on a laptop was 470px of blue (F77). */
  .btn-primary { width: auto; min-width: 220px; }
  .main .btn:not(.btn-sm) { max-width: 360px; }
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .print-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Two columns of cards once there is room for two readable columns. The
   full-width items stay full width: the dashboard banner, the section labels
   and the shortcut rows read as headers, not as cards. */
@media (min-width: 1200px) {
  .panel.active {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
  }
  .panel.active > * { margin-bottom: 0; }
  .panel.active > .card.has-scene,
  .panel.active > .section-label,
  .panel.active > .quick-grid,
  .panel.active > .mhi-footer,
  .panel.active > .backup-card { grid-column: 1 / -1; }
}

/* ---------------------------------------------------------------------------
   Touch, zoom and small phones (plan step 19, F37, F59, F65, F94).
--------------------------------------------------------------------------- */

/* 44px targets for every control a finger has to hit. */
.icon-btn, .chart-tab, .phq-opt, .btn-text, .day-chip, .mood-btn, .toast-close,
.toast-action, .stepper button, .nav-btn, .quick-btn { min-height: 44px; }
.icon-btn, .toast-close { min-width: 44px; }
/* The header buttons say what they do: two near-identical tray emoji with
   tooltip-only names were the way to save or lose the only copy (F57). */
.icon-btn.labelled { width: auto; height: auto; flex-direction: column; gap: 0; padding: 4px 8px; line-height: 1.1; }
.icon-label { display: block; font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }
/* Under 375px there is no room for the title beside three labelled buttons:
   the buttons take their own row instead of running into the title. */
@media (max-width: 374px) {
  .app-header .header-actions { flex-basis: 100%; justify-content: flex-end; }
}
/* Larger text makes the same squeeze on any phone: at Largest the title ran
   37px under Print. There the buttons take their own row, and the header
   scrolls away rather than covering up to 41% of the screen (A3-02). */
@media (max-width: 599px) {
  /* "Guardar una copia" is twice "Save": in Spanish the title had 3 lines and ran under Print. */
  html[lang='es'] .app-header .header-actions,
  html[data-text-size='larger'] .app-header .header-actions,
  html[data-text-size='largest'] .app-header .header-actions { flex-basis: 100%; justify-content: flex-end; }
  html[data-text-size='largest'] .app-header,
  html[data-reading-comfort='on'] .app-header { position: static; }
}
.contact-card a[href^="tel:"] { display: inline-flex; align-items: center; min-height: 44px; }

/* A focused field is never hidden under the header or the tab bar. */
html { scroll-padding-top: calc(var(--header-h) + 12px); scroll-padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); }

/* The category table scrolls inside its own box on a narrow phone; positioned
   so its screen-reader-only header stays inside that box too (it widened the
   Russian page to 371px). */
#bpReference { overflow-x: auto; position: relative; }

/* Seven 44px days do not fit across 320px; there the strip scrolls and fades
   at its edge, so the last day is seen to continue (F97). */
@media (max-width: 374px) {
  .week-strip { -webkit-mask-image: linear-gradient(90deg, #000 82%, transparent); mask-image: linear-gradient(90deg, #000 82%, transparent); }
}

/* At 400% zoom (a 320 x 256 window) a sticky header and the tab bar left 48px
   for the content; on a short window the header scrolls away. */
@media (max-height: 500px) {
  .app-header { position: static; }
}

/* On a narrow phone a form sheet stacks its pairs of fields, and Save stays
   in view at the bottom of the sheet. */
@media (max-width: 420px) {
  .modal-sheet .field-row { grid-template-columns: 1fr; }
}
#modalConfirm {
  position: sticky;
  bottom: 0;
  box-shadow: 0 -8px 16px var(--white);
}
