:root {
  --bg: #ffffff;
  --card: #ffffff;
  --ink: #14181c;
  --muted: #5d676f;
  --line: #d5d8dc;
  --green: #1f8a5b;
  --green-dark: #146b46;
  --health: #e8f1fb;
  --meds: #fdecea;
  --insurance: #e8f6ee;
  --docs: #eee8fb;
  --appts: #fef6e0;
  --team: #e8f0fb;
  --shadow: 0 10px 30px rgba(20, 24, 28, 0.06);
  --radius: 22px;
}

* { box-sizing: border-box; }

html {
  /* Stop iOS/Android from inflating text in landscape. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  font-size: 18px;
  line-height: 1.5;
}

body {
  /* `clip` contains stray overflow without turning body into a scroll
     container, which would break position: sticky on the header. */
  overflow-x: clip;
  -webkit-tap-highlight-color: rgba(31, 138, 91, 0.12);
}

a { color: inherit; }

img { max-width: 100%; display: block; }

/* Long medication names, member IDs, emails, and model output should wrap
   rather than push the page sideways. */
h1, h2, h3, h4, h5, h6, p, li, dd, dt, td, th, figcaption, label, summary {
  overflow-wrap: break-word;
}

.page {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto 40px;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.topbar,
.bottombar {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar { padding: 28px 0 8px; }
.bottombar { padding: 8px 0 36px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-name {
  display: block;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.brand-name strong { color: var(--green); font-weight: 800; }
.brand-tag { display: block; color: var(--muted); font-size: 0.92rem; }

.top-actions,
.row-actions,
.view-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.text-link,
.icon-btn,
.pill-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
}

.avatar,
.help-dot {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f1;
  font-weight: 800;
}

.account-menu { position: relative; }
.account-menu summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 700;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  width: max-content;
  min-width: 220px;
  max-width: min(280px, calc(100vw - 32px));
  padding: 14px;
  box-shadow: var(--shadow);
  z-index: 5;
}
.account-panel p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.account-panel a,
.account-panel button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 8px 0;
  font: inherit;
  cursor: pointer;
}

.hero {
  position: relative;
  margin: 18px 0 28px;
  min-height: 260px;
  border-radius: 28px;
  overflow: hidden;
  background: #eaf6ea;
}

.hero-banner {
  display: block;
  width: 100%;
  height: 280px;
  object-fit: cover;
  object-position: right center;
}

.hero-copy {
  position: absolute;
  left: 36px;
  top: 50%;
  transform: translateY(-50%);
  max-width: 34ch;
  z-index: 1;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(2.4rem, 5vw, 4rem);
  letter-spacing: -0.04em;
}

.lede {
  margin: 0;
  font-size: 1.2rem;
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr) minmax(320px, 1.1fr);
  grid-template-rows: auto auto;
  gap: 18px;
}

.tile,
.ask-card,
.panel,
.auth-card,
.empty,
.flash {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.tile {
  min-height: 196px;
  padding: 24px 20px 20px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
}
.tile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 10px;
}
.tile-icon img {
  display: block;
  width: 64px;
  height: 64px;
  margin: 0 auto;
  object-fit: contain;
}
.tile strong { font-size: clamp(1.1rem, 3.6vw, 1.45rem); }
.tile-copy { color: var(--muted); display: block; }
.tile-copy i { font-style: normal; }
.tile-health { background: var(--health); }
.tile-meds { background: var(--meds); }
.tile-insurance { background: var(--insurance); }
.tile-docs { background: var(--docs); }
.tile-appts { background: var(--appts); }
.tile-team { background: var(--team); }

.ask-card {
  grid-column: 4;
  grid-row: 1 / span 2;
  padding: 24px;
  border: 2px solid #b4b8bd;
  box-shadow: none;
}
.ask-card header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.ask-card h2 {
  margin: 0;
  font-size: 1.45rem;
}
.ask-card h2 strong { color: var(--green); }
.ask-card header p,
.ask-card p { margin: 0 0 10px; color: var(--muted); }
.ask-card ul {
  margin: 0 0 18px;
  padding-left: 20px;
  color: var(--muted);
}

.ask-card-open {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 14px;
  margin: -6px -6px 6px;
  padding: 6px;
}
.ask-card-open:hover { background: #f4f6f4; }
.ask-card-open header { margin-bottom: 0; }
.ask-card-open p i { color: var(--green); font-style: normal; font-weight: 800; }

.ask-examples li { margin-bottom: 4px; }
.ask-examples a {
  color: var(--muted);
  text-decoration: none;
}
.ask-examples a:hover { color: var(--green-dark); text-decoration: underline; }

.ask-card-link {
  display: block;
  margin-top: 12px;
  text-align: center;
  font-weight: 700;
  color: var(--green-dark);
  text-decoration: none;
}
.ask-card-link:hover { text-decoration: underline; }

.ask-inline {
  display: flex;
  gap: 10px;
  background: #f4f6f4;
  border-radius: 999px;
  padding: 8px 8px 8px 18px;
}
.ask-inline input,
.stack-form input,
.stack-form textarea,
.stack-form select {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
}
.ask-inline input { outline: none; }
.ask-inline button,
.primary-btn {
  border: 0;
  background: var(--green);
  color: white;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.ask-inline button {
  width: 46px;
  height: 46px;
}
.primary-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  text-decoration: none;
}
.ghost-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
}

.pill-link {
  background: white;
  border-radius: 999px;
  padding: 8px 16px 8px 8px;
  box-shadow: var(--shadow);
}
.pill-link small { display: block; color: var(--muted); font-size: 0.85rem; }

.icon-btn {
  background: white;
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
}

.page-head { padding: 18px 0 8px; }
.eyebrow {
  margin: 0;
  color: var(--green-dark);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.82rem;
}
.page-head h1 { margin: 6px 0; font-size: clamp(1.75rem, 6vw, 2.3rem); letter-spacing: -0.02em; }
.page-head p { color: var(--muted); max-width: 60ch; }

.two-col {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 20px;
  align-items: start;
}

.panel,
.empty,
.auth-card { padding: 22px; }
.stack { display: grid; gap: 16px; }
.stack-form { display: grid; gap: 12px; }
.stack-form label,
.days-field { display: grid; gap: 6px; font-weight: 700; }
.stack-form input,
.stack-form textarea {
  background: #f5f7f5;
  border-radius: 14px;
  padding: 12px 14px;
}
.days-field {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: #f5f7f5;
  border-radius: 14px;
  padding: 10px;
}
.days-field legend { padding: 0 4px; }
.check {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.85rem;
}

.view-toggle a {
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--line);
}
.view-toggle a.active {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.card-grid,
.week-grid {
  display: grid;
  gap: 14px;
}
.card-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.week-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.med-line { margin-bottom: 10px; }
.med-line span,
.muted { color: var(--muted); }
.emphasis { font-weight: 800; font-size: 1.1rem; }

.add-person {
  margin: 8px 0 22px;
  background: var(--card);
  border: 2px dashed #b6c9bd;
  border-radius: var(--radius);
}
.add-person > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 22px;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  color: var(--green-dark);
}
.add-person > summary::-webkit-details-marker { display: none; }
.add-person > summary:focus-visible,
.person-drawer > summary:focus-visible,
.contact-btn:focus-visible {
  outline: 3px solid var(--green-dark);
  outline-offset: 3px;
}
.add-person-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 1.7rem;
  line-height: 1;
}
.add-person[open] {
  border-style: solid;
  border-color: var(--green);
}
.add-person-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 0 22px 22px;
}
.add-person-form .wide { grid-column: 1 / -1; }

.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  gap: 18px;
  align-items: start;
}

.person-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 14px;
}
.person-head {
  display: flex;
  align-items: center;
  gap: 14px;
}
.person-avatar {
  flex: 0 0 auto;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 800;
}
.person-id h2 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}
.person-role { margin: 2px 0 0; color: var(--muted); }
.person-chip {
  justify-self: start;
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: #f1f4f2;
  font-weight: 700;
  font-size: 0.92rem;
}

.person-actions { display: grid; gap: 10px; }
.contact-btn {
  display: grid;
  gap: 2px;
  padding: 14px 20px;
  border-radius: 18px;
  background: var(--green);
  color: white;
  text-decoration: none;
}
.contact-btn strong { font-size: 1.2rem; }
.contact-btn small { font-size: 0.95rem; opacity: 0.9; word-break: break-all; }
.contact-btn-quiet {
  background: white;
  color: var(--ink);
  border: 2px solid var(--line);
}
.contact-btn-quiet small { color: var(--muted); opacity: 1; }
.person-empty { margin: 0; }

.person-drawer > summary {
  list-style: none;
  cursor: pointer;
  color: var(--green-dark);
  font-weight: 700;
  padding: 6px 0;
}
.person-drawer > summary::-webkit-details-marker { display: none; }
.person-drawer > summary::before {
  content: "▸ ";
  font-size: 0.8em;
}
.person-drawer[open] > summary::before { content: "▾ "; }
.person-drawer > p { margin: 4px 0 0; }
.person-drawer .stack-form { padding-top: 10px; }

.person-card.tone-0 .person-avatar { background: var(--team); color: #2b6cb0; }
.person-card.tone-1 .person-avatar { background: var(--insurance); color: var(--green-dark); }
.person-card.tone-2 .person-avatar { background: var(--appts); color: #96650a; }
.person-card.tone-3 .person-avatar { background: var(--docs); color: #5a3fc0; }
.person-card.tone-4 .person-avatar { background: var(--meds); color: #b8433a; }

.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 18px;
  align-items: start;
}

.slot-card {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 14px;
  border-top: 6px solid transparent;
}
.slot-morning { background: #fff8e8; border-top-color: #e6b23c; }
.slot-midday { background: #fdeeea; border-top-color: #d4574a; }
.slot-evening { background: #f3ecfb; border-top-color: #8a5cc4; }
.slot-bedtime { background: #eaf1fb; border-top-color: #3b6cb5; }
.slot-anytime { background: #eef1ef; border-top-color: #7c8a82; }

.slot-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.slot-icon {
  flex: 0 0 auto;
  display: inline-flex;
  width: 46px;
  height: 46px;
}
.slot-icon svg { width: 46px; height: 46px; }
.slot-head h2 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}
.slot-hint { margin: 0; color: var(--muted); font-size: 0.95rem; }
.slot-count {
  margin-left: auto;
  align-self: flex-start;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}
.slot-none { margin: 0; }

.dose-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.dose-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: white;
  border-radius: 16px;
  padding: 12px 14px;
}
.dose-mark {
  flex: 0 0 auto;
  width: 14px;
  height: 24px;
  margin-top: 3px;
  border-radius: 999px;
  background: linear-gradient(to bottom, #1f8a5b 0 50%, #cfe8dc 50% 100%);
}
.dose-text { display: grid; gap: 2px; }
.dose-text strong { font-size: 1.2rem; }
.dose-text small { color: var(--muted); font-size: 0.95rem; }

.slot-footnote { margin: 20px 0 0; }

.slot-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr));
  gap: 10px;
  border: 0;
  padding: 0;
  margin: 0;
}
.slot-picker legend {
  padding: 0 0 8px;
  font-weight: 700;
}
.slot-choice {
  display: grid;
  justify-items: center;
  gap: 2px;
  text-align: center;
  padding: 12px 8px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: white;
  cursor: pointer;
  font-weight: 700;
}
.slot-choice small { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.slot-choice-icon svg { width: 34px; height: 34px; }
.slot-choice input { width: 22px; height: 22px; margin: 0 0 4px; }
.slot-choice:has(input:checked) {
  border-color: var(--green);
  background: #eef8f2;
}
.slot-choice:focus-within {
  outline: 3px solid var(--green-dark);
  outline-offset: 2px;
}

.med-avatar svg { width: 34px; height: 34px; }
.med-when {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.big-btn {
  padding: 16px 28px;
  font-size: 1.15rem;
  font-weight: 800;
}

.uploader {
  display: grid;
  gap: 16px;
  margin: 8px 0 28px;
  justify-items: start;
}

.dropzone {
  position: relative;
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 44px 24px;
  border: 3px dashed #b6c9bd;
  border-radius: var(--radius);
  background: #f7fbf8;
  cursor: pointer;
}
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.dropzone-icon svg { width: 56px; height: 56px; }
.dropzone-title { font-size: 1.5rem; }
.dropzone-hint { color: var(--muted); }
.dropzone.is-dragging,
.dropzone:focus-within {
  border-color: var(--green);
  background: #eef8f2;
}
.dropzone.has-file {
  border-style: solid;
  border-color: var(--green);
  background: #eef8f2;
}
.dropzone.has-file .dropzone-hint { color: var(--green-dark); font-weight: 700; }

.uploader-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.camera-btn { display: none; }
.uploader-ready .camera-btn { display: inline-flex; }

.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 18px;
  align-items: start;
}

.doc-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.doc-thumb {
  display: grid;
  place-items: center;
  height: 180px;
  background: #eef1ef;
  overflow: hidden;
}
.doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.doc-thumb-pdf { background: var(--meds); }
.doc-thumb-file { background: var(--docs); }
.doc-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.85);
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: 0.04em;
}
.doc-body { padding: 16px 18px 4px; }
.doc-body h2 {
  margin: 0;
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}
.doc-body p { margin: 4px 0 0; font-size: 0.95rem; }
.doc-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 18px 18px;
}

.back-link { text-decoration: none; }

.viewer {
  background: #eef1ef;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 300px;
}
.viewer-image {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
}
.viewer-frame {
  width: 100%;
  height: 72vh;
  border: 0;
  background: white;
}
.viewer-fallback {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
}
.viewer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 20px 0 0;
}

.section-heading {
  margin: 30px 0 14px;
  font-size: 1.4rem;
}

.date-badge {
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  align-content: center;
  width: 68px;
  padding: 8px 0;
  border-radius: 16px;
  background: white;
  box-shadow: var(--shadow);
  line-height: 1.1;
}
.date-badge small {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}
.date-badge strong { font-size: 1.8rem; letter-spacing: -0.03em; }
.date-badge-lg { width: 92px; padding: 12px 0; }
.date-badge-lg strong { font-size: 2.6rem; }

.next-up {
  margin: 8px 0 10px;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--appts);
  border: 2px solid #e6c874;
  display: grid;
  gap: 18px;
}
.next-up-label {
  margin: 0;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.82rem;
  color: #8a6410;
}
.next-up-body {
  display: flex;
  align-items: flex-start;
  gap: 18px;
}
.next-up-detail h2 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.03em;
}
.next-up-when {
  margin: 4px 0 8px;
  font-size: 1.35rem;
  font-weight: 800;
}
.next-up-line { margin: 0 0 4px; font-size: 1.1rem; }
.next-up-actions { align-items: center; }

.appt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  gap: 18px;
  align-items: start;
}

.appt-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 12px;
}
.appt-card.is-cancelled { background: #f4f5f4; }
.appt-card.is-cancelled .appt-id h3 { text-decoration: line-through; }

.appt-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.appt-id h3 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.appt-when { margin: 4px 0 0; font-weight: 700; }

.appt-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.appt-chip {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--appts);
  font-weight: 700;
  font-size: 0.92rem;
}
.appt-chip-quiet { background: #f1f4f2; }
.appt-chip-off { background: var(--meds); }
.appt-line { margin: 0; color: var(--muted); }

.appt-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.note-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.note-card time { color: var(--muted); font-size: 0.92rem; }

/* ============================ Ask SusanCare chat ========================== */

body.chat-page .page {
  width: min(1320px, calc(100% - 32px));
  margin-bottom: 16px;
}
body.no-scroll { overflow: hidden; }

/* Scoped to the chat so it does not clobber the pill-shaped .icon-btn used by
   the footer, which was being squeezed into a 40px box. */
.chat-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.chat-icon-btn:hover { background: #eceff1; color: var(--ink); }
.chat-icon-btn-danger:hover { background: #fdecea; color: #b3352a; }

.chat {
  position: relative;
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 16px;
  height: calc(100dvh - 210px);
  min-height: 460px;
  transition: grid-template-columns 0.22s ease, gap 0.22s ease;
}
.chat.side-hidden { grid-template-columns: 0 minmax(0, 1fr); gap: 0; }
.chat.side-hidden .chat-side {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-16px);
}

/* --- conversation list --- */

.chat-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 14px 12px;
  background: #f7f8f9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.chat-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 8px;
}
.chat-side-title { font-weight: 800; font-size: 1.05rem; }
.chat-side-close { display: none; }
.chat-side-new { margin: 0; }

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.new-chat:hover { border-color: var(--green); color: var(--green-dark); }

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  padding: 2px;
  margin: 0 -2px;
}
.thread {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  text-decoration: none;
  color: inherit;
}
.thread:hover { background: #eceff1; }
.thread.is-active {
  background: #fff;
  border-color: var(--line);
  box-shadow: var(--shadow);
}
.thread-title {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-summary {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.thread-empty,
.thread-setup { color: var(--muted); font-size: 0.9rem; padding: 0 10px; }
.thread-setup code { font-size: 0.82rem; word-break: break-all; }

/* --- chat column --- */

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.chat-top-new { display: none; }
.chat-top form { margin: 0; }
.chat-top-text { min-width: 0; flex: 1; }
.chat-top-text strong {
  display: block;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-top-text span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: 16px;
  padding: 24px clamp(14px, 4vw, 40px) 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* --- avatars --- */

.chat-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: none;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.chat-avatar-bot { background: var(--insurance); color: var(--green-dark); }
.chat-avatar-user { background: var(--health); color: #2b5f9e; }
.chat-avatar-lg { width: 56px; height: 56px; }

/* --- messages --- */

.msg {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.msg-body { min-width: 0; }
/* Model output can contain long URLs, IDs, and code. Break them instead of
   letting them widen the whole chat column. */
.msg-text {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.msg-text pre {
  margin: 0 0 10px;
  padding: 12px 14px;
  background: #f1f3f4;
  border-radius: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.msg-text pre code {
  background: none;
  padding: 0;
  white-space: pre;
  overflow-wrap: normal;
}
.msg-text table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}
.msg-text img { border-radius: 12px; }
.msg-who {
  margin: 0 0 4px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.msg-text > *:first-child { margin-top: 0; }
.msg-text > *:last-child { margin-bottom: 0; }
.msg-text p { margin: 0 0 10px; }
.msg-text ul,
.msg-text ol { margin: 0 0 10px; padding-left: 22px; }
.msg-text li { margin: 3px 0; }
.msg-text li > ul,
.msg-text li > ol { margin: 4px 0 2px; }
.msg-text h2,
.msg-text h3,
.msg-text h4,
.msg-text h5,
.msg-text h6 {
  margin: 18px 0 8px;
  line-height: 1.3;
  font-weight: 800;
}
.msg-text h2 { font-size: 1.25rem; }
.msg-text h3 { font-size: 1.12rem; }
.msg-text h4 { font-size: 1.02rem; }
.msg-text h5,
.msg-text h6 { font-size: 0.95rem; color: var(--muted); }
.msg-text a { color: var(--green-dark); text-decoration: underline; }
.msg-text a:hover { color: var(--green); }
.msg-text em { font-style: italic; }
.msg-text hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}
.msg-text strong { font-weight: 800; }
.msg-text code {
  background: #f1f3f4;
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.9em;
}
.msg-user .msg-text {
  background: var(--health);
  border-radius: 4px 16px 16px 16px;
  padding: 12px 16px;
}

.dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.tool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 6px 0 0;
  margin: 0;
}
.tool-chips li {
  background: var(--insurance);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--green-dark);
}

/* --- welcome state --- */

.chat-welcome {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 10px;
  margin: auto 0;
  padding: 20px 0 30px;
}
.chat-welcome h2 { margin: 4px 0 0; font-size: 1.7rem; }
.chat-welcome p { margin: 0; color: var(--muted); max-width: 46ch; }
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}
.suggestion {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  cursor: pointer;
}
.suggestion:hover { border-color: var(--green); color: var(--green-dark); }

/* --- streaming --- */

.msg-status { margin: 0; color: var(--muted); font-size: 0.92rem; }
.msg-stream { white-space: pre-wrap; }
/* A soft caret while text is still arriving. */
.msg.is-streaming .msg-stream::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  background: var(--green);
  vertical-align: -0.18em;
  animation: caret 1s steps(2, start) infinite;
}
@keyframes caret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.msg-error .msg-text { color: #b3352a; }

.chat-jump {
  position: absolute;
  top: -46px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  z-index: 2;
}
.chat-jump:hover { border-color: var(--green); color: var(--green-dark); }
.chat-jump[hidden] { display: none; }

/* --- composer --- */

.chat-composer {
  flex: none;
  position: relative;
  padding: 10px clamp(14px, 4vw, 40px) 14px;
  background: #fff;
  border-top: 1px solid transparent;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #fff;
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--green); }
.composer textarea {
  flex: 1;
  min-height: 26px;
  max-height: 200px;
  padding: 6px 0;
  border: 0;
  outline: none;
  resize: none;
  font: inherit;
  line-height: 1.45;
  background: transparent;
  color: inherit;
}
.composer button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  flex: none;
}
.composer button:hover { background: var(--green-dark); }
.composer.is-busy button { opacity: 0.5; pointer-events: none; }
.composer-hint {
  margin: 8px 4px 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.chat-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 28, 0.4);
  z-index: 20;
}

.memory-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.memory-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.auth-body .page { display: grid; place-items: center; min-height: 70vh; }
.auth-card { width: min(460px, 100%); }
.auth-card h1 { margin-top: 0; }

.flash { padding: 12px 16px; margin: 12px 0 18px; }
.flash-success { background: #e8f6ee; }
.flash-error { background: #fdecea; }

/* ============================== Responsive =============================== */

/* --- tablets and small laptops --- */

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }
  .ask-card {
    grid-column: 1 / -1;
    grid-row: auto;
  }
  .hero-banner { height: 240px; }
}

@media (max-width: 900px) {
  .two-col { grid-template-columns: minmax(0, 1fr); }

  /* The assistant is the thing people reach for first on a phone. */
  .ask-card { order: -1; }
  .dashboard-grid { display: flex; flex-wrap: wrap; gap: 14px; }
  .dashboard-grid .tile { flex: 1 1 calc(50% - 7px); min-height: 150px; }
  .dashboard-grid .ask-card { flex: 1 1 100%; }
}

/* --- phones --- */

@media (max-width: 760px) {
  /* Stack the hero instead of absolutely positioning copy over the photo,
     which overflowed and became unreadable at narrow widths. */
  .hero {
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 12px 0 20px;
    border-radius: 22px;
  }
  .hero-banner {
    height: clamp(130px, 32vw, 190px);
    object-position: center 30%;
  }
  .hero-copy {
    position: static;
    transform: none;
    max-width: none;
    padding: 16px 20px 20px;
  }
  .hero h1 { font-size: clamp(1.9rem, 8vw, 2.6rem); }
  .lede { font-size: 1.05rem; }
}

@media (max-width: 640px) {
  html, body { font-size: 16px; }

  .topbar, .bottombar, .page { width: min(100% - 24px, 1180px); }

  /* Keep the brand and account menu reachable while scrolling long lists. */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--bg);
    padding: calc(12px + env(safe-area-inset-top)) 0 10px;
    gap: 10px;
  }
  .brand-tag { display: none; }
  .brand-name { font-size: 1.35rem; }
  .brand-mark svg { width: 24px; height: 24px; }
  .top-actions { gap: 8px; }
  .top-actions .text-link { font-size: 0.95rem; }
  .account-greeting { display: none; }
  .avatar, .help-dot { width: 38px; height: 38px; }

  .bottombar {
    padding: 8px 0 max(24px, env(safe-area-inset-bottom));
    gap: 10px;
  }
  .pill-link { padding: 8px 14px 8px 8px; font-size: 0.95rem; }
  .pill-link small { font-size: 0.78rem; }

  .page-head { padding: 12px 0 6px; }
  .panel, .empty, .auth-card, .person-card, .ask-card { padding: 18px; }
  .slot-card { padding: 16px; }

  /* Comfortable thumb targets everywhere. */
  .primary-btn,
  .ghost-btn,
  .new-chat,
  .suggestion,
  .view-toggle a,
  .contact-btn { min-height: 44px; }
  .primary-btn, .ghost-btn { padding: 11px 18px; }

  .days-field { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .note-card header { flex-direction: column; }
  .add-person-form { grid-template-columns: 1fr; }
  .add-person > summary { padding: 14px 16px; font-size: 1.1rem; }
  .add-person-form { padding: 0 16px 18px; }
  .add-person-plus { width: 36px; height: 36px; font-size: 1.5rem; }

  .memory-list li { flex-direction: column; align-items: stretch; }

  /* Action rows read better as full-width stacked buttons. */
  .row-actions > * { flex: 1 1 auto; }
  .doc-foot > *,
  .viewer-actions > * { flex: 1 1 auto; }
  .doc-foot .primary-btn,
  .doc-foot button,
  .viewer-actions .primary-btn,
  .viewer-actions .ghost-btn,
  .viewer-actions button { width: 100%; }
  .next-up-body { gap: 14px; }
  .next-up-detail h2 { font-size: 1.6rem; }
  .next-up-when { font-size: 1.15rem; }
  .date-badge-lg { width: 72px; }
  .date-badge-lg strong { font-size: 2rem; }
  .next-up-actions > *,
  .appt-foot > * { flex: 1 1 auto; }
  .dropzone { padding: 32px 18px; }
  .dropzone-title { font-size: 1.25rem; }
  .uploader-actions > * { flex: 1 1 auto; }
  /* Direct children only: a nested form inside a collapsible drawer must keep
     its own grid layout instead of being flattened into a row. */
  .row-actions > form { display: flex; }
  .row-actions > button,
  .row-actions > .primary-btn,
  .row-actions > .ghost-btn,
  .row-actions > form > button { width: 100%; }
}

/* Keep two tiles per row on ordinary phones (375-430px) — one per row turns
   the dashboard into a long scroll. Just shrink the tiles instead. */
@media (max-width: 430px) {
  .dashboard-grid { gap: 10px; }
  .dashboard-grid .tile {
    flex: 1 1 calc(50% - 5px);
    min-height: 140px;
    padding: 16px 10px 14px;
    gap: 2px;
  }
  .tile-icon { width: 54px; height: 54px; margin-bottom: 4px; }
  .tile-icon img { width: 50px; height: 50px; }
  .tile-copy { font-size: 0.8rem; line-height: 1.35; }
}

@media (max-width: 340px) {
  .dashboard-grid .tile { flex: 1 1 100%; min-height: 0; padding: 18px 16px; }
  .days-field { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* --- chat: full-height app shell on small screens --- */

@media (max-width: 900px) {
  /* Instead of guessing the chrome height with calc(), let the body own the
     viewport and give the leftover space to the chat. --app-height is kept in
     sync with visualViewport by chat.js so the composer survives the on-screen
     keyboard. */
  body.chat-page {
    display: flex;
    flex-direction: column;
    height: var(--app-height, 100dvh);
    overflow: hidden;
  }
  /* The chat page never scrolls the document, so a sticky header only gets in
     the drawer's way. */
  body.chat-page .topbar { flex: none; position: static; z-index: auto; }
  body.chat-page .bottombar { display: none; }
  body.chat-page .page {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: min(100% - 20px, 1320px);
    margin-bottom: 0;
    padding-bottom: 0;
  }
  body.chat-page .flash { flex: none; margin: 8px 0 10px; }

  .chat {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
  }
  .chat.side-hidden { grid-template-columns: minmax(0, 1fr); }

  .chat-side {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    /* Above the app header so the drawer's own title and close button are not
       covered by it. */
    z-index: 61;
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: max(14px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
    transform: translateX(-102%);
    opacity: 1;
    visibility: visible;
    transition: transform 0.24s ease;
  }
  .chat.side-hidden .chat-side { opacity: 1; visibility: visible; transform: translateX(-102%); }
  .chat.side-open .chat-side,
  .chat.side-open.side-hidden .chat-side { transform: translateX(0); }

  .chat-scrim { display: block; z-index: 60; }
  .chat-scrim[hidden] { display: none; }
  .chat-side-close { display: inline-grid; }
  .chat-top-new { display: block; }
  .chat-top-new form { margin: 0; }

  .chat-welcome h2 { font-size: 1.4rem; }
  .chat-composer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
  /* Let the conversation use the full width of the screen. */
  body.chat-page .page {
    width: 100%;
    padding-left: 0;
    padding-right: 0;
  }
  body.chat-page .flash { margin: 8px 12px 10px; }
  .chat-main {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
  .chat-top { padding: 8px 10px; }
  .chat-top-text strong { font-size: 1rem; }
  .chat-top-text span { font-size: 0.8rem; }
  .chat-scroll {
    padding: 16px 14px 4px;
    gap: 18px;
  }
  .chat-composer { padding-left: 12px; padding-right: 12px; }
  .composer { padding: 6px 6px 6px 14px; border-radius: 22px; }
  .composer textarea { max-height: 140px; }
  .composer button { width: 40px; height: 40px; }
  .composer-hint { font-size: 0.72rem; margin-top: 6px; }

  /* Tighter message rows, and user turns as right-aligned bubbles. */
  .msg {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
  }
  .chat-avatar { width: 28px; height: 28px; font-size: 0.7rem; }
  .chat-avatar svg { width: 17px; height: 17px; }
  .chat-avatar-lg { width: 48px; height: 48px; }
  .msg-user {
    grid-template-columns: minmax(0, 1fr);
    justify-items: end;
  }
  .msg-user .chat-avatar,
  .msg-user .msg-who { display: none; }
  .msg-user .msg-body { max-width: 88%; }
  .msg-user .msg-text { border-radius: 16px 16px 4px 16px; }
  .suggestion { font-size: 0.88rem; padding: 9px 14px; }
}

@media (max-width: 420px) {
  .composer-hint { display: none; }
  .chat-composer { padding-top: 8px; }
}

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