:root {
  --bg: #f3faef;
  --surface: #ffffff;
  --surface-2: #e7f0dc;
  --ink: #24372f;
  --muted: #627869;
  --primary: #1f8a70;
  --primary-dark: #126454;
  --primary-soft: #d8f1e7;
  --accent: #e17a56;
  --accent-soft: #ffe4d4;
  --gold: #e2b84d;
  --gold-soft: #fff0bf;
  --berry: #d85d75;
  --berry-soft: #f9dce4;
  --blue: #4c8fc7;
  --blue-soft: #dceefa;
  --danger: #c84d5d;
  --danger-soft: #f9d9dd;
  --success: #76a957;
  --border: #cfe1ca;
  --shadow-sm: 0 1px 3px rgba(36, 55, 47, 0.08);
  --shadow-md: 0 4px 16px rgba(36, 55, 47, 0.12);
  --shadow-lg: 0 8px 32px rgba(36, 55, 47, 0.18);
  --shadow: var(--shadow-md);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-pill: 9999px;
  --radius: var(--radius-md);
  --space-1: 4px;  --space-2: 8px;   --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px;  --space-7: 48px; --space-8: 64px;
  --transition-fast: 150ms ease;
  --transition-normal: 260ms ease;
  --sidebar: 236px;
  --bottom: 76px;
  --font: 'Atkinson Hyperlegible', 'Segoe UI', Arial, sans-serif;
  --display: 'Lora', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 17px; }
body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(216,241,231,0.72), rgba(255,240,191,0.38) 42%, rgba(255,228,212,0.42)),
    var(--bg);
  line-height: 1.55;
  padding-bottom: var(--bottom);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
svg, img { max-width: 100%; display: block; }

@media (min-width: 820px) {
  body { padding-left: var(--sidebar); padding-bottom: 0; }
  html { font-size: 16px; }
}

h1, h2, h3 { font-family: var(--display); line-height: 1.18; }
h1 { font-size: clamp(1.75rem, 3vw, 2.45rem); color: var(--primary-dark); }
h2 { font-size: 1.42rem; }
h3 { font-size: 1.3rem; }
p, label, input, textarea, select, button { font-size: 1rem; }
small { color: var(--muted); font-size: 0.92rem; }

/* ---- Page sections & transitions ---- */
.page-section { display: none; }
.page-section.active {
  display: block;
  animation: fadeSlideIn var(--transition-normal) forwards;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* a11y-reviewer: respect reduced-motion. Older users may have
   vestibular sensitivity; the slide-in feels sluggish to them. */
@media (prefers-reduced-motion: reduce) {
  .page-section.active { animation: none; }
}

.main { min-height: 100vh; padding: 24px 18px 100px; }
@media (min-width: 820px) { .main { padding: 26px 34px; } }
.page-header { display: flex; gap: 18px; justify-content: space-between; align-items: flex-start; margin-bottom: 26px; }
.page-header p { color: var(--muted); margin-top: 6px; max-width: 760px; }

/* ---- Sidebar ---- */
.sidebar {
  display: none;
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  background: linear-gradient(180deg, #f8fff9, #eef8e9);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  z-index: 20;
  flex-direction: column;
}
@media (min-width: 820px) { .sidebar { display: flex; } }

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand strong { display: block; color: var(--primary-dark); font-family: var(--display); font-size: 1.45rem; }
.brand span { display: block; color: var(--muted); font-size: 0.9rem; }
.brand-mark {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), #2fb693);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.55rem;
}
.brand-mark.large {
  width: 72px; height: 72px;
  margin: 0 auto 16px;
  font-size: 2.4rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.nav-list { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-item, .bottom-nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
}
.nav-item {
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  border-radius: var(--radius);
  font-weight: 700;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-item span:first-child {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--primary-dark);
  display: grid;
  place-items: center;
  flex: none;
  font-size: 0.85rem;
  transition: background var(--transition-fast);
}
.nav-item.active, .nav-item:hover {
  background: linear-gradient(135deg, var(--primary-soft), #fff6d8);
  color: var(--primary-dark);
}
.nav-item.active span:first-child, .nav-item:hover span:first-child {
  background: var(--primary-soft);
}
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; display: grid; gap: 8px; }
.logout-btn { color: var(--danger); }

/* ---- Bottom nav ---- */
.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  min-height: var(--bottom);
  background: #fbfff8;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 20;
  box-shadow: 0 -4px 20px rgba(36, 53, 47, 0.12);
}
@media (min-width: 820px) { .bottom-nav { display: none; } }
.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 700;
  color: var(--muted);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}
.bottom-nav button.active { color: var(--primary); background: var(--primary-soft); }
.bottom-nav span { font-size: 0.7rem; }

/* ---- Cards & layout ---- */
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card { padding: 22px; }
.stack { display: grid; gap: 18px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }

/* ---- Buttons ---- */
.btn {
  border: 0;
  border-radius: var(--radius-pill);
  padding: 11px 20px;
  min-height: 48px;
  font-weight: 700;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
  line-height: 1;
}
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn.primary:active { transform: translateY(0); box-shadow: none; }
.btn.secondary { background: #fff7df; color: var(--ink); border: 1px solid #f1d58a; }
.btn.secondary:hover { background: #fef0c3; border-color: var(--gold); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: white; }
.btn.ghost { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.full { width: 100%; }
.btn.small { min-height: 38px; padding: 7px 14px; font-size: 0.9rem; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ---- Forms ----
   min-height 50px matches a 48px touch target after border. Explicit
   select min-height ensures mobile renderings don't shrink to default
   browser size (a11y-reviewer flagged this). */
.field, textarea, select {
  width: 100%;
  border: 1.5px solid var(--border);
  background: #fffef9;
  color: var(--ink);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 50px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
select { min-height: 50px; padding: 12px 14px; }
textarea { min-height: 110px; resize: vertical; }
.field:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 138, 112, 0.15);
}
label {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form-block { display: grid; gap: 6px; }
.error { color: var(--danger); min-height: 28px; }
.hidden { display: none !important; }

/* ---- Tabs & language toggle ---- */
.tabs, .lang-toggle {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-pill);
}
.tab-btn, .lang-btn {
  border: 0;
  background: transparent;
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font-weight: 700;
  color: var(--muted);
  transition: all var(--transition-fast);
}
.tab-btn.active, .lang-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.tab-btn:hover:not(.active), .lang-btn:hover:not(.active) { color: var(--primary-dark); }

/* ---- Auth page ---- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background: linear-gradient(140deg, var(--primary-soft), #fffef5 52%, var(--accent-soft));
}
.auth-card {
  position: relative;
  width: min(100%, 480px);
  padding: 40px 36px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin: 18px 0 26px; }
.auth-brand h1 { color: var(--primary-dark); }
.auth-tagline { color: var(--muted); font-size: 0.9rem; letter-spacing: 0.01em; margin-top: 4px; }
.auth-form { display: grid; gap: 14px; }
.auth-lang { position: absolute; top: 16px; right: 16px; }

/* ---- Dashboard ----
   Hero band simplified per design-reviewer 2026-05-04: the previous
   teal→coral gradient created an uneven contrast zone in the middle
   that hurt readability for older eyes. Solid primary + subtle text
   shadow for depth. */
.hero-band {
  background: var(--primary);
  color: white;
  border-radius: var(--radius-lg);
  padding: 26px;
  margin-bottom: 18px;
}
.hero-band h1 { color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.10); }
.hero-band p { color: #f4fff9; font-size: 1.1rem; text-shadow: 0 1px 2px rgba(0,0,0,0.10); }
.today-list { display: grid; gap: 12px; }
.medicine-dose {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.medicine-dose:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.time-badge, .status-badge {
  background: var(--accent-soft);
  color: #704717;
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
}
.status-badge { background: var(--gold-soft); color: #6b4c00; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--blue-soft);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 0.88rem;
}
.list-item {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1.5px solid var(--border);
  background: #ffffff;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.list-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.list-title { font-size: 1.2rem; font-weight: 700; color: var(--primary-dark); }
.muted { color: var(--muted); }
.text-muted { color: var(--muted); }
.divider { border: none; border-top: 1px solid var(--border); margin: var(--space-5) 0; }
.empty {
  text-align: center;
  padding: 36px 18px;
  color: var(--muted);
  background: linear-gradient(135deg, #ffffff, #f5fbf0);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
}
.stat-value {
  font-size: 2.4rem;
  font-family: var(--display);
  color: var(--primary);
  font-weight: 700;
  line-height: 1;
  margin-bottom: var(--space-2);
}
.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(300px, 420px);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1180px) { .dashboard-layout { grid-template-columns: 1fr; } }

/* ---- Calendar ---- */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.calendar-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  text-align: center;
}
.calendar-head span {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 0;
  display: block;
}
.cal-day {
  /* Per design-reviewer: bumped min-height 58→66 + larger day number
     so a 75yo can confidently tap a specific day on touch devices. */
  min-height: 66px;
  border: 1.5px solid var(--border);
  background: #ffffff;
  border-radius: var(--radius);
  padding: 6px;
  display: grid;
  align-content: space-between;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.cal-day:hover { background: var(--primary-soft); border-color: var(--primary); }
.cal-day.other { opacity: 0.45; }
.cal-day.today { border-color: var(--primary) !important; outline: 2px solid var(--primary-soft); outline-offset: 1px; }
.cal-day.has-appointment { background: #fff3e9; border-color: var(--accent); }
.cal-day.has-log { box-shadow: inset 0 -4px 0 var(--success); }
.cal-num { font-weight: 900; font-size: 1.1rem; margin-bottom: 6px; }
.cal-icons { display: flex; gap: 4px; flex-wrap: wrap; min-height: 18px; }
.cal-icon {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
}
.cal-icon.appt { background: var(--accent); color: white; }
.cal-icon.log { background: var(--success); color: white; }

/* ---- Doctor notes ---- */
.doctor-note {
  border-left: 5px solid var(--berry);
  background: linear-gradient(135deg, var(--berry-soft), #f4fbef);
  padding: 12px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
  line-height: 1.6;
}

/* ---- Chart ---- */
.chart-wrap { min-height: 280px; position: relative; }
.chart-wrap canvas { border-radius: var(--radius-sm); }

/* ---- Toast ---- */
#toast-container {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 100;
  display: grid;
  gap: 10px;
  max-width: 320px;
  pointer-events: none;
}
.toast {
  background: var(--primary);
  color: white;
  padding: 14px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  font-size: 0.9rem;
  animation: toastIn 0.28s ease forwards;
  pointer-events: auto;
}
.toast.error { background: var(--danger); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---- TTS toggle (sidebar) & floating button (mobile) ---- */
.tts-toggle {
  display: flex;
  width: 100%;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.tts-toggle:hover, .tts-toggle.active {
  background: linear-gradient(135deg, var(--primary-soft), #fff6d8);
  color: var(--primary-dark);
}
.tts-toggle span:first-child {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--primary-dark);
  display: grid;
  place-items: center;
  flex: none;
  font-size: 1rem;
  line-height: 1;
}
.tts-fab {
  /* a11y-reviewer: bumped 50→56px so older users with arthritis can
     reliably tap. */
  position: fixed;
  bottom: calc(var(--bottom) + 16px);
  right: 16px;
  z-index: 30;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.tts-fab:hover { box-shadow: var(--shadow-lg); }
.tts-fab.active { background: var(--primary); color: white; border-color: var(--primary); }
@media (min-width: 820px) { .tts-fab { display: none; } }

/* ---- Responsive ---- */
@media (max-width: 560px) {
  html { font-size: 17px; }
  .main { padding: 20px 14px 96px; }
  .page-header { display: grid; }
  .auth-card { padding: 28px 18px; }
  .medicine-dose { grid-template-columns: 1fr; }
  .grid.three { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.8rem; }
}

@media print {
  .sidebar, .bottom-nav, .btn, .lang-toggle, .tts-toggle, .tts-fab, #toast-container { display: none !important; }
  body { padding: 0; background: white; }
  .main { padding: 0; }
  .card, .panel, .list-item { box-shadow: none; }
}

/* ============================================================
   Interactions card (Workstream I) — dashboard "Possible considerations"
   ============================================================ */
#interactions-card { gap: 12px; }
.interaction-item {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1.5px solid var(--border);
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.interaction-item--alert {
  border-left: 5px solid var(--danger);
  background: linear-gradient(135deg, #fff5f5, #fff);
}
.interaction-item--warn {
  border-left: 5px solid var(--accent-dark, #d97a4d);
  background: linear-gradient(135deg, #fff7ee, #fff);
}
.interaction-item--info {
  border-left: 5px solid var(--primary);
  background: linear-gradient(135deg, var(--primary-soft), #fff);
}
.interaction-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.interaction-sev {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}
.sev-alert { background: var(--danger); color: white; }
.sev-warn  { background: var(--accent, #f08b62); color: white; }
.sev-info  { background: var(--primary); color: white; }

/* ============================================================
   Daily log — conditional sections (Workstream H)
   ============================================================ */
.log-fieldset {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--surface);
  display: grid;
  gap: 12px;
}
.log-fieldset legend {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  padding: 0 8px;
}

/* ============================================================
   Onboarding questionnaire (Workstream G)
   Senior-friendly: large type, generous spacing, big buttons,
   clear progress dots.
   ============================================================ */
.q-card {
  max-width: 640px;
  margin: 32px auto;
  padding: 32px 28px;
  display: grid;
  gap: 18px;
}
.q-card h1 { font-size: 1.6rem; line-height: 1.25; }
.q-card p  { font-size: 1.05rem; line-height: 1.55; }

.q-progress {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 4px;
}
.q-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--border);
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.q-dot.active { background: var(--primary); transform: scale(1.15); }
.q-dot.done   { background: var(--primary-soft); border: 2px solid var(--primary); }
.q-progress-label { text-align: center; font-size: 0.85rem; margin: 0 0 10px; }

.q-checklist {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) {
  .q-checklist { grid-template-columns: 1fr 1fr; }
}
.q-check {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
  font-size: 1rem;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  min-height: 56px;
}
.q-check:hover { border-color: var(--primary); background: var(--primary-soft); }
.q-check input[type="checkbox"] {
  width: 22px; height: 22px;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.q-check input[type="checkbox"]:checked + span { font-weight: 700; color: var(--primary-dark); }
.q-suggested {
  color: var(--accent);
  font-weight: 700;
  margin-left: 4px;
}

.q-med-list {
  display: grid;
  gap: 18px;
}
.q-med-row {
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  gap: 12px;
}

.q-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 8px;
}
.q-actions .btn { min-width: 120px; }
.q-actions .btn.full { min-width: 0; flex: 1; }

@media (max-width: 560px) {
  .q-card { margin: 16px 8px; padding: 22px 16px; }
  .q-actions { flex-direction: column-reverse; }
  .q-actions .btn { width: 100%; }
}
