/* styles.css — Recallection: warm editorial / paper-and-ink */
:root {
  --paper: #f4efe6;        /* warm cream */
  --paper-soft: #ede6d8;
  --paper-deep: #e2d9c5;
  --ink: #1a1815;          /* near-black with warm undertone */
  --ink-soft: #4a4541;
  --ink-faint: #8a847b;
  --rule: #c9bfa9;
  --accent: #b54a2b;       /* deep terracotta */
  --accent-soft: #d96e4f;
  --ok: #4a7a3e;
  --ok-deep: #356a2c;
  --warn: #b8860b;
  --danger: #a83232;
  --danger-deep: #8a2828;

  --serif: 'Fraunces', 'Georgia', serif;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;
  --radius: 6px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Subtle paper grain */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(181, 74, 43, 0.025) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(26, 24, 21, 0.02) 0%, transparent 40%);
  z-index: 1;
}

#app {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Safe-area padding for notched iPhones — keeps the home indicator and notch from clipping content */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ============ Auth views ============ */
.view-auth {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  animation: fade-up 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.brand {
  text-align: center;
  margin-bottom: 2rem;
}

.logo {
  font-family: var(--serif);
  font-weight: 500;
  font-style: italic;
  font-size: 2.6rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
  color: var(--ink);
  font-variation-settings: "opsz" 144;
}

.tagline {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-faint);
  margin: 0;
  letter-spacing: 0.005em;
}

.auth-card {
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 2rem 1.75rem 1.75rem;
  width: 100%;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 8px 24px -12px rgba(26, 24, 21, 0.15);
}

.auth-card h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.5rem;
  letter-spacing: -0.015em;
  margin: 0 0 1.2rem;
  color: var(--ink);
}

.auth-card label {
  display: block;
  margin-bottom: 1rem;
}

.auth-card label > span {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}

.auth-card label em {
  font-style: italic;
  font-weight: 400;
  text-transform: none;
  color: var(--ink-faint);
  letter-spacing: 0;
}

input, textarea, select {
  width: 100%;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  font-family: var(--sans);
  font-size: 1rem; /* 16px — anything smaller triggers iOS auto-zoom on focus */
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(181, 74, 43, 0.12);
}

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

.code-input {
  font-family: var(--serif);
  font-size: 1.6rem !important;
  letter-spacing: 0.45em;
  text-align: center;
  padding-left: 0.5em !important;
  font-variation-settings: "opsz" 144;
}

.hint {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-style: italic;
}

.muted { color: var(--ink-soft); }
.muted.small { font-size: 0.88rem; }

/* Status banners — used at the top of forms to confirm an action succeeded
   (e.g., "✓ Reset code sent") or warn about a state. Visible by default; hide
   by adding the [hidden] attribute when no message is needed. */
.status-banner {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  text-align: center;
  font-weight: 500;
  font-size: 0.92rem;
  margin: 0 0 1.25rem;
}
.status-banner.ok { background: rgba(74,122,62,0.12); color: var(--ok-deep, #356a2c); border: 1px solid rgba(74,122,62,0.3); }
.status-banner.warn { background: rgba(184,134,11,0.12); color: #7a5a07; border: 1px solid rgba(184,134,11,0.3); }
.status-banner.danger { background: rgba(168,50,50,0.12); color: var(--danger-deep, #8a2828); border: 1px solid rgba(168,50,50,0.3); }
.status-banner strong { font-weight: 600; }

.fineprint {
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin: 1rem 0 0;
  text-align: center;
  line-height: 1.5;
}

.fineprint a { color: var(--accent); }

/* ============ Buttons ============ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.06s, box-shadow 0.15s;
  margin-top: 0.4rem;
  letter-spacing: 0.005em;
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 4px 12px -4px rgba(181, 74, 43, 0.3);
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary.btn-sm {
  width: auto;
  padding: 0.5rem 0.95rem;
  font-size: 0.85rem;
  margin: 0;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.55rem 0.95rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-ghost:hover {
  color: var(--ink);
  border-color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.5);
}

.link-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.link-btn:hover { color: var(--accent); background: rgba(255,255,255,0.4); }

.auth-links {
  margin-top: 1.2rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--ink-faint);
}
.auth-links a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.auth-links a:hover { border-bottom-color: var(--accent); }
.auth-links span { margin: 0 0.5rem; color: var(--rule); }

.error {
  margin-top: 1rem;
  padding: 0.65rem 0.85rem;
  background: rgba(168, 50, 50, 0.08);
  border-left: 3px solid var(--danger);
  color: var(--danger);
  font-size: 0.88rem;
  border-radius: 3px;
}

/* ============ App view ============ */
.view-app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  animation: fade-up 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0 1.25rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.5rem;
}
/* On mobile: header allows wrap so .app-tabs (with flex-basis: 100%, order: 3) drops to row 2 */

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0; /* don't get squeezed by .app-tabs's flex:1 — keep avatar + name + sign-out at natural width */
}
.header-right .link-btn { white-space: nowrap; }

.avatar-btn {
  width: 36px; height: 36px;
  padding: 0; border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper-deep);
  cursor: pointer;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, transform 0.06s;
}
.avatar-btn:hover { border-color: var(--accent); }
.avatar-btn:active { transform: scale(0.96); }
.avatar-btn img,
.avatar-btn span { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.avatar-btn img { object-fit: cover; }
.avatar-initial {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink-soft);
  background: var(--paper-deep);
}

/* Caregiver name shown next to the avatar — clickable, opens the profile modal */
.user-name-btn {
  background: none;
  border: none;
  padding: 0.3rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  border-radius: 4px;
  max-width: 14ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s, background 0.15s;
}
.user-name-btn:hover { color: var(--accent); background: rgba(255,255,255,0.4); }
@media (max-width: 540px) {
  .user-name-btn { display: none; } /* avatar alone on small screens; name takes too much room */
}

.logo-sm {
  font-size: 1.4rem;
  margin: 0;
}

.app-tabs {
  display: flex;
  gap: 0.4rem;
  flex: 1;
  justify-content: center;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-faint);
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap; /* prevent "Check-ins" from breaking to two lines on narrow viewports */
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  color: var(--ink);
  background: var(--paper-deep);
  border-color: var(--paper-deep);
}

.panel {
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap; /* long calendar titles ("September 2026") sit alongside ‹ Today › nav without overflowing */
  margin-bottom: 1.25rem;
  gap: 0.6rem 1rem;
}
.panel-head h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  margin: 0;
}

.filter-row {
  display: flex;
  flex-wrap: wrap; /* wrap to a second row on narrow viewports rather than overflowing */
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.filter {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.82rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* Reminder list items */
.reminders-list, .contacts-list, .recipients-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.reminder, .contact, .recipient {
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.reminder:last-child, .contact:last-child, .recipient:last-child { border-bottom: none; }

.reminder-main {
  flex: 1;
  min-width: 0;
}

.reminder-label {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--ink);
  margin: 0 0 0.2rem;
}

.reminder-message {
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0 0 0.45rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.reminder-meta {
  font-size: 0.8rem;
  color: var(--ink-faint);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  row-gap: 0.35rem;
}

.reminder-time {
  font-weight: 500;
  color: var(--ink-soft);
}

.status-pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.status-pill.scheduled { background: rgba(74, 122, 62, 0.15); color: var(--ok); }
.status-pill.sent { background: var(--paper-deep); color: var(--ink-soft); }
.status-pill.failed { background: rgba(168, 50, 50, 0.15); color: var(--danger); }
.status-pill.canceled { background: var(--paper-deep); color: var(--ink-faint); }

.reminder-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.6);
  border-color: var(--danger);
  color: var(--danger);
}

/* Contact / recipient rows */
.contact-name, .recipient-name {
  font-weight: 500;
  font-size: 0.98rem;
  margin: 0 0 0.2rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.contact-phone, .recipient-phone {
  font-size: 0.85rem;
  color: var(--ink-faint);
  font-feature-settings: 'tnum';
  margin: 0;
}

/* Consent + response pills */
.consent-pill, .response-pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.consent-pill.pending, .response-pill.pending { background: rgba(184,134,11,0.15); color: #7a5a07; }
.consent-pill.confirmed, .response-pill.acknowledged { background: rgba(74,122,62,0.15); color: var(--ok); }
.consent-pill.declined, .consent-pill.stopped,
.response-pill.help_requested, .response-pill.no_response,
.response-pill.caregiver_alerted { background: rgba(168,50,50,0.15); color: var(--danger); }
.response-pill.escalated_voice { background: rgba(181, 74, 43, 0.15); color: var(--accent); }

/* Profile gate panel inside main app */
.panel-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.6rem;
}

/* Profile modal — avatar editor */
.avatar-edit {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 1rem 0;
  margin-bottom: 0.5rem;
}
.avatar-preview {
  width: 80px; height: 80px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--paper-deep);
  overflow: hidden;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-preview .avatar-initial {
  font-size: 2rem;
  width: 100%; height: 100%;
}
.file-label {
  display: inline-block;
  cursor: pointer;
  margin: 0;
}
.file-label input[type="file"] {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.file-label > span {
  display: inline-block;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.5rem 0.95rem;
  font-size: 0.88rem;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.file-label:hover > span {
  color: var(--ink);
  border-color: var(--ink-soft);
  background: rgba(255,255,255,0.5);
}

.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { color: var(--danger); background: rgba(168, 50, 50, 0.06); }

.btn-row {
  display: flex;
  gap: 0.6rem;
}
.btn-row .btn-primary {
  width: auto;
  flex: 1;
  margin: 0;
}

/* Checkbox + label combos used in signup, add-recipient, and similar consent forms */
.checkbox-label {
  display: flex !important;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 1rem 0 1.1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.5;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: auto;
  flex-shrink: 0;
  margin: 0.2rem 0 0 0;
  cursor: pointer;
}
.checkbox-label > span { display: block; text-transform: none !important; letter-spacing: 0 !important; font-size: 0.85rem !important; color: var(--ink-soft) !important; margin-bottom: 0 !important; }
.checkbox-label a { color: var(--accent); }

/* Date + time block in the new-check-in modal */
.datetime-block {
  margin-bottom: 1rem;
}
.datetime-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.datetime-half {
  flex: 1;
  margin-bottom: 0 !important;
}
.btn-confirm-datetime {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  background: var(--paper-deep);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 0.5rem;
}
.btn-confirm-datetime:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn-confirm-datetime.confirmed {
  background: var(--ok);
  color: white;
  border-color: var(--ok);
  cursor: default;
}
.btn-confirm-datetime.confirmed:hover {
  background: var(--ok);
}

/* Preview text — confirms what's been picked (and locked in) */
.datetime-preview {
  margin: 0.5rem 0 0;
  padding: 0.6rem 0.85rem;
  background: rgba(255,255,255,0.5);
  border: 1px dashed var(--rule);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-family: var(--sans);
}
.datetime-preview.ok {
  color: var(--ok-deep);
  border-color: rgba(74,122,62,0.4);
  border-style: solid;
  background: rgba(74,122,62,0.1);
  font-weight: 500;
}

/* Channel pill on reminder rows / detail */
.channel-pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--paper-deep);
  color: var(--ink-soft);
}
.channel-pill.email { background: rgba(74,122,62,0.12); color: var(--ok); }
.channel-pill.voice { background: rgba(181,74,43,0.12); color: var(--accent); }

/* Voice options panel inside the new-check-in modal */
.voice-options {
  background: rgba(255,255,255,0.4);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.voice-options label { margin-bottom: 0; }

/* Recordings list rows */
.recordings-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.recording-row {
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.recording-row:last-child { border-bottom: none; }
.recording-name { font-weight: 500; font-size: 0.98rem; margin: 0 0 0.2rem; }
.recording-meta { margin: 0 0 0.5rem; }
.recording-row audio { width: 100%; max-width: 360px; }
.recording-usage {
  color: var(--accent);
  font-weight: 500;
}

/* Voice preview audio inside the new-check-in modal */
.voice-preview-audio {
  width: 100%;
  margin-top: 0.5rem;
  display: block;
}

/* Recording modal — record/stop button + timer */
.recording-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--rule);
  border-radius: 8px;
  margin-bottom: 1rem;
}
.btn-record {
  flex: 1;
  padding: 0.85rem 1.1rem;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-record:hover { background: var(--accent); border-color: var(--accent); }
.btn-record.recording {
  background: var(--danger);
  border-color: var(--danger);
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168,50,50,0.6); }
  50% { box-shadow: 0 0 0 6px rgba(168,50,50,0); }
}
/* Microphone picker shown above the Record button when ≥2 input devices are detected.
   Only revealed after permission is granted (browsers don't expose device labels otherwise). */
.rec-device-row { margin-bottom: 0.85rem; }
.rec-device-row > span {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}
.rec-device-row select { width: 100%; }

/* Live VU meter — tells the user instantly whether the mic is picking up sound.
   Visible only while recording; bar width reflects RMS level (0..100%).
   .rec-meter is a wrapper so the label can sit OUTSIDE the clipped track. */
.rec-meter { margin-bottom: 1rem; }
.rec-meter-track {
  position: relative;
  height: 10px;
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid var(--rule);
  border-radius: 5px;
  overflow: hidden; /* clips the bar; label is a sibling so it isn't clipped */
}
.rec-meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(
    to right,
    #4a7a3e 0%,
    #4a7a3e 55%,
    #b8860b 80%,
    #a83232 100%
  );
  background-size: 100vw 100%; /* gradient stays anchored to container, so the visible color reflects level */
  background-position: left;
  transition: width 0.06s linear;
}
.rec-meter-label {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-faint);
  text-align: center;
  margin-top: 0.4rem;
  font-style: italic;
}
.rec-meter.silent .rec-meter-label { color: var(--danger); font-style: normal; font-weight: 500; }

.rec-timer {
  font-family: var(--sans);
  font-feature-settings: 'tnum';
  font-size: 1rem;
  color: var(--ink-soft);
  min-width: 3.5rem;
  text-align: right;
}
.rec-preview {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  background: rgba(74,122,62,0.07);
  border: 1px solid rgba(74,122,62,0.3);
  border-radius: 8px;
}
.rec-preview audio { width: 100%; margin-bottom: 0.4rem; }

/* Inline failure reason on a reminder row */
.reminder-error {
  margin: 0.4rem 0 0.6rem;
  padding: 0.45rem 0.65rem;
  background: rgba(168,50,50,0.08);
  border-left: 3px solid var(--danger);
  border-radius: 3px;
  font-size: 0.82rem;
  color: var(--danger);
}

/* Reminder detail modal */
.detail-h3 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink-soft);
  margin: 1.5rem 0 0.6rem;
}
.detail-summary {
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem 1rem;
}
.detail-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.event-row {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--rule);
  font-size: 0.88rem;
}
@media (max-width: 540px) {
  .event-row { grid-template-columns: 1fr; gap: 0.15rem; } /* timestamp stacks above the event description */
}
.event-row:last-child { border-bottom: none; }
.event-when { color: var(--ink-faint); font-feature-settings: 'tnum'; font-size: 0.78rem; }
.event-what { color: var(--ink-soft); }

/* "Roll up series" toggle in the Check-ins filter row */
.rollup-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0 auto !important;
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.rollup-toggle input { width: auto; margin: 0; cursor: pointer; }
.rollup-toggle > span { font-size: 0.78rem !important; text-transform: none !important; letter-spacing: 0 !important; color: var(--ink-soft) !important; margin: 0 !important; }

.rollup-tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-weight: 500;
}

/* Series pill on reminder rows */
.series-pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: rgba(184,134,11,0.12);
  color: #7a5a07;
  border: 1px solid rgba(184,134,11,0.25);
}

/* Recurrence form section in the new-check-in modal */
.recurrence-detail {
  background: rgba(255,255,255,0.4);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.recurrence-row {
  margin-bottom: 0.85rem;
}
.recurrence-row:last-child { margin-bottom: 0; }
.recurrence-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}
.dow-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.dow-picker label {
  margin: 0 !important;
  cursor: pointer;
}
.dow-picker label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
}
.dow-picker label > span {
  display: inline-block;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: transparent;
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-weight: 500 !important;
  margin: 0 !important;
}
.dow-picker label input[type="checkbox"]:checked + span {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.radio-row {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.5rem !important;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
}
.radio-row input[type="radio"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}
.radio-row input[type="number"], .radio-row input[type="date"] {
  width: auto;
  display: inline-block;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
}
.radio-row > span { font-size: 0.88rem !important; color: var(--ink-soft) !important; text-transform: none !important; letter-spacing: 0 !important; margin-bottom: 0 !important; }
[data-recurrence-row="monthly_weekday"] {
  display: flex;
  gap: 0.6rem;
}
[data-recurrence-row="monthly_weekday"] label {
  flex: 1;
  margin: 0 !important;
}

/* ============ Calendar tab ============ */
.cal-nav {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem 1rem;
  font-size: 0.75rem;
  color: var(--ink-faint);
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--rule);
}
.cal-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  font-style: normal;
}
.dot-scheduled { background: #4a7a8a; }
.dot-acknowledged { background: var(--ok); }
.dot-pending { background: #b8860b; }
.dot-help { background: var(--danger); }
.dot-canceled { background: var(--ink-faint); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.cal-head {
  background: var(--paper-deep);
  color: var(--ink-soft);
  text-align: center;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.45rem 0;
  font-weight: 500;
}
.cal-cell {
  background: rgba(255,255,255,0.6);
  border: none;
  cursor: pointer;
  text-align: left;
  padding: 0.4rem 0.5rem;
  min-height: 78px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: background 0.1s;
  font-family: var(--sans);
}
.cal-cell:hover { background: rgba(255,255,255,0.85); }
.cal-cell.out-of-month { opacity: 0.42; }
.cal-cell.today { background: rgba(181, 74, 43, 0.08); }
.cal-cell.today .cal-day { color: var(--accent); font-weight: 700; }
.cal-cell.selected { background: rgba(26, 24, 21, 0.05); border: 2px solid var(--ink); padding: calc(0.4rem - 1px) calc(0.5rem - 1px); }
.cal-day {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
}
.cal-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
}
.cal-more {
  font-size: 0.7rem;
  color: var(--ink-faint);
  margin-left: 0.2rem;
}

.cal-day-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cal-day-row {
  padding: 0.85rem 0;
  border-bottom: 1px dashed var(--rule);
  cursor: pointer;
  transition: background 0.1s;
}
.cal-day-row:last-child { border-bottom: none; }
.cal-day-row:hover { background: rgba(255,255,255,0.5); }
.cal-day-row-main p { margin: 0; }
.cal-day-row-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--ink);
  margin-bottom: 0.2rem !important;
}
.cal-day-row-meta {
  font-size: 0.85rem;
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.4rem !important;
}
.cal-day-row-pills {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.cal-day-time { color: var(--ink-faint); font-feature-settings: 'tnum'; font-size: 0.82rem; }

/* Backup caregivers list inside the edit-recipient modal */
.caregivers-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
}
.caregiver-row {
  padding: 0.7rem 0;
  border-bottom: 1px dashed var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
}
.caregiver-row:last-child { border-bottom: none; }

/* Modal X close button */
.modal-close {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 44px; /* Apple HIG min tap target */
  height: 44px;
  background: transparent;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--paper-deep); color: var(--ink); }
.modal-cal-day { position: relative; padding-top: 2.5rem; }
.modal-cal-day h2 { padding-right: 2rem; margin-bottom: 1rem; }

@media (max-width: 540px) {
  .cal-cell { min-height: 56px; padding: 0.3rem 0.35rem; }
  .cal-day { font-size: 0.78rem; }
  .cal-day-row { grid-template-columns: 4rem 1fr; }
  .cal-day-pills { grid-column: 1 / -1; justify-content: flex-start; padding-left: 4.6rem; }
}

/* Profile modal — danger zone (data export + account deletion) */
.profile-danger-zone {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}
.profile-danger-zone h3 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink-soft);
  margin: 0 0 0.4rem;
}
.btn-ghost.danger {
  color: var(--danger);
  border-color: rgba(168,50,50,0.3);
}
.btn-ghost.danger:hover {
  color: white;
  background: var(--danger);
  border-color: var(--danger);
}
.btn-primary.danger {
  background: var(--danger);
  border-color: var(--danger);
}
.btn-primary.danger:hover {
  background: var(--danger-deep);
  border-color: var(--danger-deep);
}

/* App footer */
.app-footer {
  margin-top: auto;
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-faint);
  padding-top: 2rem;
}
.app-footer a {
  color: var(--ink-faint);
  text-decoration: none;
  border-bottom: 1px dotted var(--rule);
}
.app-footer a:hover { color: var(--accent); border-color: var(--accent); }
.copyright-inline { display: block; margin-top: 0.5rem; color: var(--ink-faint); font-size: 0.74rem; }

/* ============ Modals ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 24, 21, 0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fade-in 0.15s ease-out;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 2rem 1.75rem 1.75rem;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 50px -10px rgba(26, 24, 21, 0.3);
  animation: scale-in 0.2s cubic-bezier(0.2, 0.7, 0.2, 1);
  max-height: 90vh;
  max-height: 90dvh; /* dvh accounts for the iOS Safari URL bar shrinking the viewport */
  overflow-y: auto;
}

.modal h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.5rem;
  margin: 0 0 1.25rem;
  letter-spacing: -0.01em;
}

.modal label {
  display: block;
  margin-bottom: 1rem;
}
.modal label > span {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}
.modal-actions .btn-primary {
  width: auto;
  padding: 0.7rem 1.1rem;
  margin: 0;
}

/* ============ Animations ============ */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ============ Mobile (≤540px — covers all iPhones in portrait) ============ */
@media (max-width: 540px) {
  .auth-card { padding: 1.5rem 1.25rem; }
  .panel { padding: 1.25rem 1rem; }
  .view-app { padding: 0.5rem 0.85rem 2rem; }

  /* Header reflow: logo + right cluster on row 1, tabs on a horizontally-scrollable row 2 */
  .app-header { flex-wrap: wrap; }
  .app-tabs {
    flex-basis: 100%;
    order: 3;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    gap: 0.3rem;
    padding-bottom: 0.25rem;
    scrollbar-width: none; /* Firefox; webkit covered by ::-webkit-scrollbar below */
  }
  .app-tabs::-webkit-scrollbar { display: none; } /* Chromium/Safari */
  .tab { font-size: 0.85rem; padding: 0.55rem 0.85rem; min-height: 40px; }
  .avatar-btn { width: 44px; height: 44px; } /* HIG tap target */

  /* Filter row: rollup toggle naturally drops to a 2nd row instead of being right-pinned */
  .rollup-toggle { margin: 0 !important; padding: 0.5rem 0.6rem; }
  .rollup-toggle input { width: 18px; height: 18px; }
  .filter { padding: 0.5rem 0.95rem; }

  /* Row content: let actions wrap onto their own full-width row beneath the message */
  .reminder, .contact, .recipient, .recording-row { flex-wrap: wrap; }
  .reminder-actions {
    flex-basis: 100%;
    flex-direction: row; /* horizontal on the new row, not stacked vertically */
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .recording-row audio { max-width: 100%; }
  .icon-btn { padding: 0.5rem 0.75rem; min-height: 36px; } /* keeps row compact while staying tappable */

  /* Modals: less backdrop padding (more usable width), stacked actions w/ primary on top */
  .modal-backdrop { padding: 0.6rem; }
  .modal { padding: 1.75rem 1.25rem 1.25rem; }
  .modal-actions {
    flex-direction: column-reverse; /* DOM is [Cancel, Primary]; reverse puts Primary on top */
    align-items: stretch;
    gap: 0.5rem;
  }
  .modal-actions .btn-primary,
  .modal-actions .btn-ghost { width: 100%; padding: 0.85rem 1rem; }
}

/* ============ iPhone SE / very narrow (≤380px) ============ */
@media (max-width: 380px) {
  .panel { padding: 1rem 0.75rem; }
  .modal { padding: 1.5rem 1rem 1rem; }
  .modal h2 { font-size: 1.3rem; }
  .panel-head h2 { font-size: 1.2rem; }
  .dow-picker label > span { padding: 0.4rem 0.55rem; font-size: 0.8rem; }
}

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