/*
 * Token names match bridge getTheme / window.__theme (Task 8 themeTokensFor).
 * :root + prefers-color-scheme hexes are the GistedColors light/dark values —
 * the same pins as apps/receiver theme_tokens_test. Update those first if the
 * shell palette changes; do not invent a second Contacts palette.
 */
:root {
  --surface: #FFFBF8;
  --surface-low: #FFF3EC;
  --ink: #2A1710;
  --muted: #8A5A1E;
  --primary: #A8412A;
  --outline: #8C756B;
  --line: #E0CFC6;
  --danger: #8C3A26;
  --danger-container: #FBE0DA;
  --on-primary: #FFFBF8;
  /* Message-delivery semantics (matches the finance-app sweep): reached =
     green, partial = amber, needs-attention = --danger. The shared
     GistedColors palette carries no success/warning hue, so both light and
     dark values live here, same as apps/finance. */
  --good: #2E8B63;
  --warn: #B4740E;
  /* Fixed "urgent" red for life-safety SOS surfaces — not the theme-varying
     --danger (whose dark value is a pale pink meant for on-dark text, not a
     button fill). Promoted from .sos-block below so #sos-send (outside the
     strip) can use the same strong red as the Home SOS block. */
  --sos-strip: #8c3a26;
  --sos-strip-ink: #fffbf8;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --control-font: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --tabbar-h: calc(3.75rem + var(--safe-bottom));
}

/* Author .btn { display: inline-flex } would otherwise override the UA
   [hidden] rule and leave Discard (etc.) visible when skipped. */
[hidden] {
  display: none !important;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #17110F;
    --surface-low: #241B18;
    --ink: #F7EDE8;
    --muted: #F0C08A;
    --primary: #E8845F;
    --outline: #8E7F79;
    --line: #3A2E2A;
    --danger: #F3B5A2;
    --danger-container: #3A211C;
    --on-primary: #17110F;
    --good: #4FB286;
    --warn: #E0A63A;
    --sos-strip: #6e2e1f;
    --sos-strip-ink: #fff3ec;
  }
}

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

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

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* Native feel: no visible scrollbars; content still scrolls. */
* {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-touch-callout: none;
}

button {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
}

input,
textarea,
select {
  font-size: var(--control-font);
  line-height: 1.35;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 10px;
}

textarea {
  resize: none;
}

.app {
  height: 100%;
  max-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  /* Keep height stable when #nav-back is [hidden] on Home (display:none
     would otherwise collapse the bar below the 44px back control). */
  min-height: calc(var(--safe-top) + 44px + 1.1rem);
  padding: calc(0.55rem + var(--safe-top)) 1rem 0.55rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(12px);
  -webkit-backdrop-filter: saturate(1.2) blur(12px);
  z-index: 3;
  box-sizing: border-box;
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--primary);
  margin: 0 0 0 -0.35rem;
  padding: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  -webkit-tap-highlight-color: transparent;
}

.back-chevron {
  display: block;
  width: 0.78rem;
  height: 1.25rem;
}

.back[hidden] {
  display: none;
}

.main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 0.9rem 1rem calc(1.5rem + var(--tabbar-h));
}

.view[hidden] {
  display: none;
}

/* Hash-route page enters — leave is instant; enter fades or slides lightly. */
.view.pt-enter-fade {
  animation: pt-enter-fade 200ms ease-out both;
}

.view.pt-enter-forward {
  animation: pt-enter-forward 240ms ease-out both;
}

.view.pt-enter-back {
  animation: pt-enter-back 240ms ease-out both;
}

@keyframes pt-enter-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pt-enter-forward {
  from {
    opacity: 0;
    transform: translateX(14%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pt-enter-back {
  from {
    opacity: 0;
    transform: translateX(-10%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.lede {
  margin: 0 0 1rem;
  color: var(--outline);
  font-size: 0.95rem;
}

.setup-card {
  margin: 0 0 1.1rem;
  padding: 1.1rem 1rem 1.15rem;
  border: 1px solid var(--outline-variant, rgba(0, 0, 0, 0.12));
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface, #fff) 92%, var(--outline, #888) 8%);
}

.setup-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.setup-card p {
  margin: 0 0 0.9rem;
  font-size: 0.92rem;
  color: var(--outline);
}

.setup-card .btn {
  text-decoration: none;
}

.setup-banner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.95rem;
  padding: 0.7rem 0.15rem;
  border-bottom: 1px solid color-mix(in srgb, var(--outline, #888) 28%, transparent);
}

.setup-banner p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--outline);
  line-height: 1.35;
}

.setup-banner a {
  flex-shrink: 0;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--primary, #1a5cff);
  text-decoration: none;
}

.sos-ready-line {
  margin: 0 0 0.75rem !important;
  font-size: 0.82rem !important;
  letter-spacing: 0.02em;
  color: var(--sos-strip-muted) !important;
}

/* Full-width urgency strip — calm high-contrast terracotta, not a tinted card.
   --sos-strip/--sos-strip-ink now live at :root (see top of file) so the
   standalone Confirm SOS button (#sos-send, not inside this strip) can share
   the same strong red; only the muted on-strip text stays local here. */
.sos-block {
  --sos-strip-muted: rgba(255, 251, 248, 0.86);
  margin: 0 -1rem 1.1rem;
  padding: 1.15rem 1rem 1.2rem;
  border-radius: 0;
  border: none;
  background: var(--sos-strip);
  color: var(--sos-strip-ink);
}

@media (prefers-color-scheme: dark) {
  .sos-block {
    --sos-strip-muted: rgba(255, 243, 236, 0.86);
  }
}

.sos-block h2 {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--sos-strip-ink);
}

.sos-block p {
  margin: 0 0 0.85rem;
  font-size: 0.92rem;
  color: var(--sos-strip-muted);
  opacity: 1;
}

.sos-block .hint {
  margin: 0.65rem 0 0;
  color: var(--sos-strip-muted);
  font-size: 0.82rem;
}

.sos-block .btn-sos {
  background: var(--sos-strip-ink);
  color: var(--sos-strip);
  border-color: var(--sos-strip-ink);
}

.sos-block .btn-sos.is-disabled,
.sos-block .btn-sos:disabled {
  opacity: 0.55;
  filter: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  transition: opacity 0.15s ease, transform 0.08s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
  opacity: 0.92;
}

/* A life-safety confirm action must read as unmistakably strong in both
   themes — --danger's dark value is a pale pink (meant for on-dark text, not
   a button fill), so this uses the fixed "urgent" red instead. Falls back to
   --danger/--on-primary if the sos-strip tokens are ever unset. */
.btn-sos {
  background: var(--sos-strip, var(--danger));
  color: var(--sos-strip-ink, var(--on-primary));
  border-color: var(--sos-strip, var(--danger));
}

.btn-sos.is-disabled,
.btn-sos:disabled {
  opacity: 0.42;
  filter: grayscale(0.35);
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn + .btn {
  margin-top: 0.5rem;
}

.home-live {
  margin: 0 0 1rem;
}

.home-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 0.85rem;
}

.home-status a {
  display: inline-flex;
  align-items: center;
  min-height: 1.85rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-low);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 650;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.home-recent-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.4rem;
}

.home-recent-heading h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.home-recent-heading a {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--primary, #1a5cff);
  text-decoration: none;
}

.home-recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-low);
}

.home-recent-list li + li {
  border-top: 1px solid var(--line);
}

.home-recent-list a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  color: var(--ink);
  text-decoration: none;
}

.home-recent-list .home-recent-label {
  font-size: 0.92rem;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-recent-list .home-recent-when {
  flex: none;
  font-size: 0.78rem;
  color: var(--outline);
}

/* Coloured status on a Recent row — only shown when a send is not fully
   delivered yet, so a healthy inbox stays quiet. */
.home-recent-list .home-recent-when.is-warn {
  color: var(--warn);
  font-weight: 650;
}

.home-recent-list .home-recent-when.is-danger {
  color: var(--danger);
  font-weight: 650;
}

/* Home fills the scroll area so the empty state can sit in the space a set-up
   book with no recent activity would otherwise leave blank. Scoped :not([hidden])
   so it never beats .view[hidden] { display: none } when another tab is active. */
#view-home:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.home-empty {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  padding: 1.5rem 0;
}

.home-empty-icon {
  width: 2.4rem;
  height: 2.4rem;
  color: var(--outline);
  opacity: 0.75;
}

.home-empty-title {
  margin: 0.35rem 0 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
}

.home-empty-sub {
  margin: 0;
  max-width: 17rem;
  color: var(--outline);
  font-size: 0.88rem;
  line-height: 1.4;
}

.home-empty-cta {
  width: auto;
  min-height: 40px;
  margin-top: 0.7rem;
  padding: 0.5rem 1.15rem;
  text-decoration: none;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-low);
  padding: 1rem;
  overflow: hidden;
}

.panel h2 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
}

.people-view[hidden] {
  display: none;
}

/* Flatten "everything in one card": each section's heading sits on the view
   ground, not nested in a redundant outer .panel — the inner rows already
   carry their own border-top treatment (.item-list > li). Mirrors the
   apps/finance group-overview pattern (#view-setup > .view-section). A
   second-and-later .view-section gets a divider; the first sits flush under
   the lede. */
#view-people > .view-section + .view-section,
#view-compose > .view-section + .view-section,
#view-scheduled > .view-section + .view-section,
#view-sos > .view-section + .view-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.view-section > h2 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.section-heading h2 {
  margin: 0;
}

.section-action {
  flex: none;
  min-height: 36px;
  border: 1px solid var(--primary);
  border-radius: 9px;
  padding: 0.4rem 0.65rem;
  background: transparent;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 650;
}

.section-action-icon {
  width: 2.25rem;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.section-action-icon .icon-plus {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

/* Templates sits on the view ground as a flat tappable row (title + subtitle
   left, chevron right) — matching the flattened Address book / Groups sections
   rather than reading as an inset card. */
.people-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
}

.people-link-main {
  min-width: 0;
}

.people-link-title {
  display: block;
  font-size: 1rem;
  font-weight: 700;
}

.people-link small {
  display: block;
  margin-top: 0.15rem;
  color: var(--outline);
  font-size: 0.82rem;
  font-weight: 400;
}

.people-link-chevron {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  color: var(--outline);
}

.panel p,
.empty {
  margin: 0;
  color: var(--outline);
  font-size: 0.9rem;
}

.sos-confirm-lede {
  margin: 0 0 0.25rem;
}

.sos-loc-chip {
  margin: 0.75rem 0 1rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-low);
  color: var(--muted);
  font-size: 0.9rem;
}

.sos-loc-chip.is-ok {
  color: var(--ink);
  border-color: var(--outline);
}

.sos-loc-chip.is-bad {
  color: var(--danger);
}

.sos-audio-block {
  margin: 0 0 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-low);
}

.sos-audio-label {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--ink);
}

/* The parenthetical qualifier — "(optional, ≤15s)" — is a faint suffix, not
   competing with the label. .hint's default --muted reads too vivid/warm
   here (the same "clay" look as the old template-body preview), so this
   scopes it back to the app's genuinely calm secondary tone. */
.sos-audio-label .hint {
  color: var(--outline);
}

.sos-audio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.sos-audio-status {
  font-size: 0.85rem;
  color: var(--muted);
}

.member-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
}

.member-list li {
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.member-list li:first-child {
  border-top: none;
}

.sos-ledger-block {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.sos-ledger-block .btn {
  margin-top: 0.65rem;
}

.sent-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0;
  margin: 0;
}

/* Standalone inbox-style cards on the page (not nested in a panel). */
.item-list.sent-list > li,
.sent-list .sent-row {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--outline, var(--line));
  border-radius: 12px;
  border-top: 1px solid var(--outline, var(--line));
  background: var(--surface-low, var(--surface));
  overflow: hidden;
}

.sent-view .view-header {
  margin: 0 0 0.85rem;
}

.sent-view .view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.sent-view .view-header .lede-inline {
  margin: 0;
}

.sent-view .view-header .status {
  margin-top: 0.55rem;
}

.sent-view .empty-cta {
  margin-top: 0.5rem;
}

/* Templates — same inbox card language as Sent, split by ownership. */
.templates-view {
  display: grid;
  gap: 1.15rem;
  padding-bottom: 4.5rem;
}

.templates-view .view-header {
  margin: 0;
}

.templates-view .view-header .lede-inline {
  margin: 0;
}

.templates-view .view-header .status {
  margin-top: 0.55rem;
}

.template-section {
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

.template-section .section-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: normal;
  text-transform: none;
  color: var(--outline);
}

.template-section .section-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted, var(--outline));
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0;
  margin: 0.15rem 0 0;
}

.item-list.template-list > li,
.template-list .template-row {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--outline, var(--line));
  border-radius: 12px;
  background: var(--surface-low, var(--surface));
  overflow: hidden;
}

/* Inbox card + swipe: override People-list padding bleed so the face
   fills the rounded card without looking like a panel row. */
.template-list > li.swipe-row.template-row {
  padding: 0;
}

.template-list .template-row .swipe-front {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  margin: 0;
  padding: 0.85rem 0.9rem;
  background: var(--surface-low, var(--surface));
  border-radius: 12px;
}

.template-row-title {
  font-weight: 650;
  font-size: 0.98rem;
}

.template-row-sub {
  font-size: 0.82rem;
  color: var(--outline);
}

.template-row-body {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin-top: 0.15rem;
  font-size: 0.88rem;
  line-height: 1.4;
  /* Calm, not clay: --muted computes to a vivid saturated peach in dark mode
     (the same tone --danger's dark value avoids using as a button fill) — too
     loud for a two-line body preview. --outline is the app's genuinely quiet
     secondary tone in both themes, matching .template-row-sub above it. */
  color: var(--outline);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.templates-view .empty {
  margin: 0.25rem 0 0;
}

.sent-row-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  width: 100%;
  padding: 0.85rem 0.9rem;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sent-row-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.sent-row-btn strong {
  font-weight: 650;
}

.sent-row-sub {
  font-size: 0.85rem;
  color: var(--outline);
}

.sent-row-detail {
  padding: 0 0.9rem 0.85rem;
}

.sent-row-body {
  margin: 0 0 0.65rem;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.sent-row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  width: 100%;
}

/* The delivery-status pill sits as its own flex child — the row gap already
   spaces it from the text before it, so drop .badge's own left margin. */
.sent-row-meta .badge {
  margin-left: 0;
}

.sent-row-cues {
  display: inline-flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.sent-cue {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--outline, var(--line));
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--outline);
  background: color-mix(in srgb, var(--surface-low, var(--surface)) 88%, var(--primary) 12%);
}

.sent-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 0.75rem;
}

.sent-action-chip {
  appearance: none;
  border: 1px solid var(--outline, var(--line));
  background: color-mix(in srgb, var(--primary) 14%, var(--surface-low, var(--surface)));
  color: inherit;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}

.sent-action-chip:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.sent-action-chip:active {
  transform: translateY(1px);
}


.sent-row-detail .sos-ledger-block {
  margin-top: 0;
  padding-top: 0.5rem;
}

.sent-row-detail .status {
  margin-top: 0.55rem;
}

.sos-ledger-title {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 650;
  letter-spacing: normal;
  color: var(--outline);
  text-transform: none;
}

.sos-ledger {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sos-ledger li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
}

.sos-ledger li:first-child {
  border-top: none;
}

.sos-ledger-name {
  font-weight: 600;
  color: var(--ink);
  min-width: 0;
}

.sos-ledger-status {
  flex: 0 0 auto;
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--outline);
}

.sos-ledger-status.is-reached {
  color: var(--primary);
}

.sos-ledger-status.is-failed,
.sos-ledger-status.is-unreachable {
  color: var(--danger);
}

.sos-ledger-status.is-muted {
  color: var(--muted);
}

.sos-ledger-status.is-pending {
  color: var(--outline);
}

.actions {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
}

.compose-actions {
  display: grid;
  gap: 0.5rem;
}

.compose-actions .btn + .btn {
  margin-top: 0;
}

.compose-attach {
  display: grid;
  gap: 0.35rem;
}

.compose-attach-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.compose-attach-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.9rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compose-attach-clear {
  min-width: 2.25rem;
  padding-inline: 0.5rem;
  font-size: 1.25rem;
  line-height: 1;
}

.compose-attach.is-disabled .compose-attach-row {
  opacity: 0.45;
  pointer-events: none;
}

.hint {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.stack-form {
  display: grid;
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
  min-width: 0;
}

#schedule-edit-fields,
#schedule-repeat-fields {
  display: grid;
  gap: 0.75rem;
}

#schedule-edit-fields[hidden],
#schedule-repeat-fields[hidden] {
  display: none;
}

.stack-form label {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--outline);
  letter-spacing: 0.01em;
}

.stack-form input,
.stack-form textarea,
.stack-form select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.75rem 0.85rem;
}

.stack-form textarea {
  min-height: 5.5rem;
}

/* iOS-style confirm toggle — stays inside the panel */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  width: 100%;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.toggle-copy {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.3;
}

.toggle {
  position: relative;
  flex: none;
  display: inline-flex;
  width: 51px;
  height: 31px;
  margin: 0;
}

.toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.toggle-ui {
  display: block;
  width: 51px;
  height: 31px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.18s ease;
  pointer-events: none;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s ease;
}

.toggle input:checked + .toggle-ui {
  background: var(--primary);
}

.toggle input:checked + .toggle-ui::after {
  transform: translateX(20px);
}

.toggle input:focus-visible + .toggle-ui {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.item-list > li {
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
  min-width: 0;
}

.item-list .row-title {
  margin: 0;
  font-weight: 650;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.item-list .row-meta {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--outline);
  overflow-wrap: anywhere;
}

.item-list .row-last {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted, var(--outline));
}

.item-list .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.item-list .row-actions button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  min-height: 36px;
  font-size: 0.8rem;
  font-weight: 600;
}

.item-list .row-actions button.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.member-picker {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.55rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 0;
}

.member-picker label {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 0;
}

.member-picker label span,
.check-list label span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.status {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.status.is-error {
  color: var(--danger);
}

/* The retry a failed list read offers, inline after its error (list_load.js). */
.status-retry {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.status-retry:disabled {
  opacity: 0.5;
  cursor: default;
}

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--outline);
  vertical-align: middle;
}

/* Semantic delivery-status badges (mirrors the apps/finance sweep): reached
   = green, partial = amber, needs-attention = red. Clay (--primary) stays
   reserved for actions, never for status. */
.badge-ok {
  border-color: color-mix(in srgb, var(--good) 35%, var(--line));
  color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, transparent);
}

.badge-warn {
  border-color: color-mix(in srgb, var(--warn) 50%, var(--line));
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
}

.badge-danger {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
  color: var(--danger);
  background: var(--danger-container);
}

.schedule-status-paused {
  color: var(--muted);
}

.schedule-error {
  color: var(--danger) !important;
}

.schedule-time {
  text-transform: capitalize;
}

.empty-cta {
  display: grid;
  gap: 0.8rem;
  padding-top: 0.5rem;
}

.empty-cta[hidden] {
  display: none;
}

.empty-cta .btn {
  color: var(--on-primary);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.lede-inline {
  margin: 0 0 0.85rem;
  color: var(--outline);
  font-size: 0.9rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.85rem;
}

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  min-height: 36px;
  font-size: 0.85rem;
  font-weight: 650;
}

.chip.is-active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface);
}

.chip:disabled {
  opacity: 0.45;
}

.compose-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.compose-fieldset legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--outline);
  margin-bottom: 0.4rem;
}

.check-list {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
}

.check-list label {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  min-width: 0;
}

.check-list input,
.member-picker input {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.1rem;
  flex: none;
  accent-color: var(--primary);
}

a.btn {
  text-align: center;
}

.app.tabbar-hidden .main {
  padding-bottom: calc(1rem + var(--safe-bottom));
}

.app.tabbar-hidden .tabbar {
  display: none;
}

/* Bottom tab bar — floating pill, native mobile pattern.
   A capsule inset from all three edges, blurred over the content, with the
   active tab filled in the accent. */
.tabbar {
  flex: none;
  position: fixed;
  left: 0.8rem;
  right: 0.8rem;
  bottom: calc(var(--safe-bottom) + 0.7rem);
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.25rem;
  padding: 0.4rem;
  border-radius: 1.65rem;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: color-mix(in srgb, var(--surface) 52%, transparent);
  backdrop-filter: saturate(1.7) blur(26px);
  -webkit-backdrop-filter: saturate(1.7) blur(26px);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--surface) 70%, transparent),
    0 14px 32px -14px color-mix(in srgb, var(--ink) 55%, transparent),
    0 3px 10px -6px color-mix(in srgb, var(--ink) 40%, transparent);
  transition: transform 0.24s ease, opacity 0.24s ease;
  will-change: transform;
}

/* Scroll-away: slide the bar out while scrolling down, back on scroll up.
   Content padding is unchanged (it tracks --tabbar-h), so nothing reflows —
   only the floating bar moves. Distinct from tabbar-hidden, which removes it
   entirely for full-screen flows. */
.app.tabbar-collapsed .tabbar {
  transform: translateY(calc(100% + var(--safe-bottom) + 1.2rem));
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .tabbar {
    transition: none;
  }
}

/* Without backdrop-filter the glass can't frost the content behind it, so
   fall back to a near-opaque bar to keep the labels legible. */
@supports not (
  (-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))
) {
  .tabbar {
    background: color-mix(in srgb, var(--surface) 93%, transparent);
  }
}

.tabbar a {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.16rem;
  min-height: 44px;
  padding: 0.35rem 0.2rem 0.3rem;
  border-radius: 1.3rem;
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--outline);
  text-align: center;
  transition: color 0.24s ease;
}

@media (prefers-reduced-motion: reduce) {
  .tabbar a {
    transition: none;
  }
}

.tabbar .tab-icon {
  width: 1.35rem;
  height: 1.35rem;
  flex: none;
  display: block;
}

.tabbar a[aria-current="page"] {
  color: var(--on-primary);
}

/* The moving highlight: one pill that glides to the active tab. JS sizes it
   to the active tab (offset box) and translates it; CSS animates the move. */
.tabbar-thumb {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-radius: 1.3rem;
  background: var(--primary);
  transform: translate(0, 0);
  pointer-events: none;
  z-index: 0;
  transition:
    transform 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    width 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  .tabbar-thumb {
    transition: none;
  }
}

.tabbar a[aria-current="page"] .tab-icon {
  transform: translateY(-0.5px);
}

/* List views leave room for the FAB above the tab bar */
.panel-list {
  padding-bottom: 4.5rem;
}

.view {
  position: relative;
}

.fab {
  position: fixed;
  right: 1.1rem;
  bottom: calc(var(--tabbar-h) + 0.85rem);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--ink) 22%, transparent);
}

.fab .icon-plus {
  width: 1.35rem;
  height: 1.35rem;
  display: block;
  flex: none;
}

.fab:active {
  transform: scale(0.96);
}

.app.tabbar-hidden .fab {
  bottom: calc(1rem + var(--safe-bottom));
}

.field-block {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--outline);
  letter-spacing: 0.01em;
}

/* Searchable multi-select */
.ms {
  position: relative;
  min-width: 0;
}

.ms-trigger {
  width: 100%;
  min-height: 48px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.75rem 0.85rem;
  font-size: var(--control-font);
  font-weight: 500;
}

.ms-trigger[aria-expanded="true"] {
  border-color: var(--primary);
}

.ms-panel {
  margin-top: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.ms-search {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  padding: 0.75rem 0.85rem;
}

.ms-options {
  max-height: 12rem;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.ms-option {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 0.75rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 500;
  min-height: 44px;
}

.ms-option:last-child {
  border-bottom: 0;
}

.ms-option.is-selected {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
}

.ms-option .ms-check {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.1rem;
  border: 1.5px solid var(--outline);
  border-radius: 4px;
  background: var(--surface);
}

.ms-option.is-selected .ms-check {
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: inset 0 0 0 2px var(--surface);
}

.ms-option-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.ms-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
  min-height: 0;
}

.ms-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
  padding: 0.3rem 0.35rem 0.3rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 650;
}

.ms-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-chip button {
  flex: none;
  border: 0;
  background: transparent;
  color: inherit;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.ms-empty {
  padding: 0.85rem;
  color: var(--outline);
  font-size: 0.9rem;
}

.ms.ms-open .ms-panel {
  display: block;
}

.ms.ms-open .ms-trigger {
  display: none;
}

/* Modal sheets */
.sheet {
  width: min(100% - 1.5rem, 26rem);
  max-height: min(90dvh, 40rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 16px 40px color-mix(in srgb, var(--ink) 28%, transparent);
}

/* A dark scrim in both themes — must NOT key off --ink, which is the light
   text colour in dark mode and would wash the backdrop lighter instead of
   dimming it. Same value and reasoning as apps/finance/styles.css, which
   already carried this fix. */
.sheet::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.sheet-form {
  padding: 1.1rem 1rem 1rem;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: min(90dvh, 40rem);
}

.sheet-form h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.sheet-actions {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.sheet-actions .btn + .btn {
  margin-top: 0;
}


/* P2 — People row polish + light motion */
.row-main {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  min-width: 0;
}

.row-monogram {
  flex: none;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: color-mix(in srgb, var(--primary, #1a5cff) 16%, var(--surface, #fff));
  border: 1px solid color-mix(in srgb, var(--primary, #1a5cff) 28%, var(--line, #ddd));
}

.row-copy {
  min-width: 0;
  flex: 1;
}

.row-title-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  min-width: 0;
}

.row-title-line .row-title {
  margin: 0;
  min-width: 0;
  flex: 1 1 auto;
}

.row-emergency-mark {
  flex: none;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sos-strip, #8c3a26);
  border: 1px solid color-mix(in srgb, var(--sos-strip, #8c3a26) 45%, transparent);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
  line-height: 1.2;
}

.item-list > li.row-enter {
  animation: row-enter 320ms ease-out;
}

.sos-block.is-sent-pulse,
#view-sos.is-sent-pulse .sos-block,
#sos-send.is-sent-pulse {
  animation: sos-sent-pulse 700ms ease-out;
}

@keyframes row-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes sos-sent-pulse {
  0% { filter: brightness(1); }
  35% { filter: brightness(1.12); }
  100% { filter: brightness(1); }
}

@media (prefers-reduced-motion: reduce) {
  .item-list > li.row-enter,
  .sos-block.is-sent-pulse,
  #view-sos.is-sent-pulse .sos-block,
  #sos-send.is-sent-pulse,
  .view.pt-enter-fade,
  .view.pt-enter-forward,
  .view.pt-enter-back {
    animation: none;
  }

  .swipe-front {
    transition: none !important;
  }
}

/* People book — swipe to reveal Rename / Remove */
.item-list > li.swipe-row {
  position: relative;
  /* Keep the same vertical padding as every other .item-list > li */
  padding: 0.85rem 0;
  overflow: hidden;
  touch-action: pan-y;
}

.swipe-actions {
  position: absolute;
  /* Cover the full row, including the li's vertical padding */
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  z-index: 0;
}

.swipe-action {
  border: 0;
  margin: 0;
  min-width: 4.75rem;
  padding: 0 0.85rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--on-primary, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.swipe-action-neutral {
  background: color-mix(in srgb, var(--primary, #a8412a) 82%, #1a1a1a);
}

.swipe-action-rename {
  background: var(--outline, #8c756b);
}

.swipe-action-remove {
  background: var(--danger, #8c3a26);
}

.swipe-front {
  position: relative;
  z-index: 1;
  /* Bleed into li padding so the opaque face covers the full row height.
     +1px kills compositor hairlines that flash action colors at the edges. */
  margin: calc(-0.85rem - 1px) 0;
  padding: calc(0.85rem + 1px) 0;
  /* Match .panel — not --surface — so rows don't read as inset cards */
  background: var(--surface-low, var(--surface, #fffbf8));
  touch-action: pan-y;
  will-change: transform;
}

.swipe-row.is-dragging .swipe-front {
  transition: none !important;
}

.swipe-row.is-open .swipe-front,
.swipe-row.is-dragging .swipe-front {
  box-shadow: -4px 0 12px color-mix(in srgb, var(--ink, #2a1710) 8%, transparent);
}

/* Address book, Groups and Scheduled rows are rounded swipe cards — matching
   Templates and the Sent inbox — instead of the square surface-low blocks the
   generic .swipe-front leaves. Mirrors the .template-list treatment. */
#book-list > li,
#groups-list > li,
.item-list.schedule-list > li {
  border: 1px solid var(--outline, var(--line));
  border-radius: 12px;
  background: var(--surface-low, var(--surface));
  overflow: hidden;
  /* Content inset for a non-swipe (plain-li) schedule row; swipe rows below
     reset this to 0 and let the sliding front carry the padding. */
  padding: 0.85rem 0.9rem;
}

#book-list > li + li,
#groups-list > li + li,
.item-list.schedule-list > li + li {
  margin-top: 0.55rem;
}

#book-list > li.swipe-row,
#groups-list > li.swipe-row,
.schedule-list > li.swipe-row {
  padding: 0;
}

#book-list .swipe-front,
#groups-list .swipe-front,
.schedule-list .swipe-front {
  margin: 0;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
}
