/* ============================================================================
   Buddy — styles. Shell tokens come from /shared/porter-tokens.css; this file
   declares Buddy's signature hue and its components.

   Design intent (DESIGN.md): violet primary + blush support, soft parenting
   mood. But the EMERGENCY surface overrides that softness where it matters —
   the call bar and care alerts use the danger token (red) and oversized tap
   targets, because under stress the design job is "definitive answer, fast,"
   not "pretty." Colour-as-status wins over colour-as-identity in the red zones.
   ============================================================================ */

:root {
  /* Buddy signature hue — violet primary + blush support. */
  --accent:        #8a7ad8;   /* violet — primary */
  --accent-dim:    #54489a;
  --accent-bright: #a596ec;
  --accent-tint:   rgba(138, 122, 216, 0.15);
  --support:       #e0a8c8;   /* blush */
  --support-dim:   #a87694;
  --support-tint:  rgba(224, 168, 200, 0.15);
  /* Local override: cool --success slightly so it separates from the
     violet/blush support (documented divergence — DESIGN.md). */
  --success:       #4fb8a0;
  --hdr-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* The `hidden` attribute must win over the explicit display: on overlays
   (.care-sheet / .modal-scrim set display:flex, which would otherwise override
   hidden's default display:none and leak the overlays onto the page at load). */
[hidden] { display: none !important; }
html, body { overflow-x: hidden; }
html { scrollbar-gutter: stable; -webkit-font-smoothing: antialiased; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-weight: 300;
  min-height: 100dvh; display: flex; flex-direction: column;
  padding-top: calc(var(--hdr-h) + env(safe-area-inset-top));
  font-size: var(--fs-base); -webkit-tap-highlight-color: transparent;
}
body.sheet-open, body.modal-open { overflow: hidden; }

/* ── Header (shared standard, DESIGN.md) ─────────────────────────────────────
   Full-bleed bar; inner contents centre on the shared --app-width spine. */
.app-header {
  position: fixed; inset: 0 0 auto 0; background: var(--surface);
  border-bottom: 1px solid var(--border); z-index: var(--z-sticky);
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  max-width: var(--app-width); margin: 0 auto; height: var(--hdr-h);
  padding: 0 var(--app-pad); display: flex; align-items: center;
  justify-content: space-between; gap: var(--space-sm);
}
.app-title {
  display: flex; align-items: center; gap: var(--space-sm); min-width: 0;
  font-family: var(--font-display); font-weight: 500; font-size: var(--fs-lg);
  letter-spacing: var(--ls-title); text-transform: uppercase; color: var(--text);
}
.back-link {
  font-family: var(--font-mono); font-weight: 400; font-size: var(--fs-2xs);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--text-muted);
  text-decoration: none; transition: color var(--motion-base); flex-shrink: 0;
}
.back-link:hover { color: var(--steel); }
.header-divider { width: 1px; height: 1.2em; background: var(--border); flex-shrink: 0; align-self: center; }
.app-title-icon { display: block; width: 1.7em; height: 1.7em; flex-shrink: 0; }
.wordmark { display: inline-block; color: var(--text); }
.app-title .dot { color: var(--accent); margin-left: -1px; }

/* Header tabs (desktop). Active tab uses the app hue; inactive steel. */
.tabs { display: flex; gap: var(--space-2xs); }
.tab {
  font-family: var(--font-mono); font-size: var(--fs-2xs); letter-spacing: var(--ls-label);
  text-transform: uppercase; color: var(--text-muted);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-pill);
  padding: var(--space-2xs) var(--space-md); cursor: pointer;
  transition: color var(--motion-fast), border-color var(--motion-fast), background var(--motion-fast);
}
.tab:hover { color: var(--steel); }
.tab.is-active { color: var(--accent-bright); background: var(--surface-2); border-color: var(--accent-dim); }

/* Mobile sub-strip (hidden on desktop). Full-width segmented control. */
.tabs-strip { display: none; }

/* ── Main spine ────────────────────────────────────────────────────────────── */
.app-main {
  width: 100%; max-width: var(--app-width); margin: 0 auto;
  padding: var(--space-lg) var(--app-pad) var(--space-2xl);
  flex: 1;
}
.view { display: none; }
.view.is-active { display: block; }

.section-label {
  font-family: var(--font-display); font-weight: 500; font-size: var(--fs-md);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--accent-bright);
  margin-bottom: var(--space-sm);
}
.section-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-sm); margin-bottom: var(--space-sm);
}
.section-row .section-label { margin-bottom: 0; }
.age-chip {
  font-family: var(--font-mono); font-size: var(--fs-2xs); letter-spacing: var(--ls-label);
  text-transform: uppercase; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: var(--space-3xs) var(--space-sm); white-space: nowrap;
}

/* ════════════════════════════════════════════════════════════════════════════
   EMERGENCY VIEW
   ════════════════════════════════════════════════════════════════════════════ */

/* Call bar — three oversized one-tap targets, always visible without scrolling.
   911 leads, in danger red, biggest. */
.call-bar {
  display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.call {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-2xs); min-height: 84px; padding: var(--space-sm);
  border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-family: var(--font-body); text-decoration: none; cursor: pointer;
  text-align: center; transition: transform var(--motion-fast), background var(--motion-fast), border-color var(--motion-fast);
}
.call:active { transform: scale(0.97); }
.call-glyph { font-size: 1.6rem; line-height: 1; }
.call-label { font-size: var(--fs-sm); line-height: 1.2; color: var(--text-muted); }
.call-label strong { font-size: var(--fs-lg); color: var(--text); display: inline-block; }

.call--911 {
  background: var(--danger-tint); border-color: var(--danger);
}
.call--911 .call-glyph, .call--911 .call-label strong { color: var(--danger); }
.call--911 .call-label { color: var(--danger); }
.call--911:hover { background: rgba(224, 122, 106, 0.22); }

.call--poison .call-glyph { color: var(--warn); }
.call--er .call-glyph { color: var(--accent-bright); }
.call--poison:hover, .call--er:hover { border-color: var(--steel-dim); background: var(--surface-2); }

.reference-note {
  font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.6;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--warn);
  border-radius: var(--radius); padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-lg);
}
.reference-note strong { color: var(--text); font-weight: 500; }

/* Situation grid — big tiles, generous tap targets. */
.situation-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-sm);
}
.situation {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xs);
  min-height: 108px; padding: var(--space-md);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  cursor: pointer; text-align: left;
  transition: transform var(--motion-fast), border-color var(--motion-fast), background var(--motion-fast);
}
.situation:hover { border-color: var(--accent-dim); background: var(--surface-2); }
.situation:active { transform: scale(0.98); }
.situation-glyph { font-size: 1.9rem; line-height: 1; }
.situation-name {
  font-family: var(--font-display); font-weight: 500; font-size: var(--fs-base);
  color: var(--text); line-height: 1.25; margin-top: auto;
}

/* ── Full-screen care card ───────────────────────────────────────────────────
   When you've opened a situation you want ONE thing in front of you — the steps.
   Full viewport, no chrome distractions, steps pre-expanded. */
.care-sheet {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: var(--bg); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.care-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-sm) var(--app-pad);
  border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
}
.care-back {
  font-family: var(--font-mono); font-size: var(--fs-xs); letter-spacing: var(--ls-label);
  text-transform: uppercase; color: var(--text-muted);
  background: transparent; border: none; cursor: pointer; padding: var(--space-xs) 0;
}
.care-back:hover { color: var(--steel); }
.care-911 {
  font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: 500;
  letter-spacing: var(--ls-tight); color: var(--danger); text-decoration: none;
  background: var(--danger-tint); border: 1px solid var(--danger); border-radius: var(--radius-pill);
  padding: var(--space-2xs) var(--space-md);
}
.care-sheet-body {
  flex: 1; overflow-y: auto;
  padding: var(--space-lg) var(--app-pad) calc(var(--space-2xl) + env(safe-area-inset-bottom));
  max-width: 680px; margin: 0 auto; width: 100%;
}
.care-title {
  font-family: var(--font-display); font-weight: 600; font-size: var(--fs-xl);
  color: var(--text); margin-bottom: var(--space-md); line-height: 1.15;
}
.care-alert {
  background: var(--danger-tint); border: 1px solid var(--danger); border-radius: var(--radius-lg);
  padding: var(--space-md); margin-bottom: var(--space-lg);
}
.care-alert-tag {
  display: inline-block; font-family: var(--font-mono); font-size: var(--fs-2xs);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--danger);
  font-weight: 500; margin-bottom: var(--space-2xs);
}
.care-alert p { font-size: var(--fs-base); color: var(--text); line-height: 1.55; }

/* Age-band note on age-divergent care cards (choking, CPR) — makes it explicit
   the technique shown is tuned to Oliver's current age. */
.care-band {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--space-2xs);
  background: var(--accent-tint); border: 1px solid var(--accent-dim);
  border-radius: var(--radius); padding: var(--space-xs) var(--space-md);
  margin-bottom: var(--space-md); font-size: var(--fs-sm); color: var(--text);
}
.care-band-tag {
  font-family: var(--font-mono); font-size: var(--fs-2xs); letter-spacing: var(--ls-label);
  text-transform: uppercase; color: var(--accent-bright);
}
.care-band-meta { color: var(--text-muted); font-size: var(--fs-xs); }

/* Procedure image (choking, CPR). Most first-aid diagrams are dark-on-light, so
   the figure sits on a light panel with a contained max height — it reads as a
   deliberate reference plate, not a UI surface, and never dominates the steps. */
.care-figure {
  margin: 0 0 var(--space-md); background: #f4f5f7;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-sm); text-align: center;
}
.care-figure img {
  display: block; max-width: 100%; max-height: 320px; margin: 0 auto;
  object-fit: contain;
}
.care-figure figcaption {
  margin-top: var(--space-xs); font-family: var(--font-mono);
  font-size: var(--fs-2xs); letter-spacing: var(--ls-label);
  color: #6b7280;
}

.care-steps { list-style: none; counter-reset: step; }
.care-steps li {
  counter-increment: step; position: relative;
  padding: var(--space-md) 0 var(--space-md) calc(var(--space-xl) + var(--space-xs));
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-base); line-height: 1.6; color: var(--text);
}
.care-steps li:last-child { border-bottom: none; }
.care-steps li::before {
  content: counter(step); position: absolute; left: 0; top: var(--space-md);
  width: var(--space-xl); height: var(--space-xl);
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-tint); color: var(--accent-bright);
  border: 1px solid var(--accent-dim); border-radius: 50%;
  font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: 500;
}

.care-after {
  margin-top: var(--space-lg); background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius); padding: var(--space-md);
}
.care-after-tag {
  display: inline-block; font-family: var(--font-mono); font-size: var(--fs-2xs);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--accent-bright);
  margin-bottom: var(--space-2xs);
}
.care-after p { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.6; }

.care-disclaimer {
  margin-top: var(--space-lg); font-size: var(--fs-xs); color: var(--text-dim);
  text-align: center; line-height: 1.5;
}

/* ════════════════════════════════════════════════════════════════════════════
   FAVORITES VIEW
   ════════════════════════════════════════════════════════════════════════════ */
.fav-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-2xs);
}
.fav-head .section-label { margin-bottom: 0; }
.fav-intro { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--space-md); }

.fav-filters { display: flex; flex-wrap: wrap; gap: var(--space-2xs); margin-bottom: var(--space-md); }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-3xs);
  font-family: var(--font-mono); font-size: var(--fs-xs); letter-spacing: var(--ls-tight);
  text-transform: uppercase; color: var(--text-muted);
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: var(--space-2xs) var(--space-sm); cursor: pointer;
  transition: color var(--motion-fast), border-color var(--motion-fast), background var(--motion-fast);
}
.chip:hover { color: var(--steel); }
.chip.is-active { color: var(--accent-bright); background: var(--surface-2); border-color: var(--accent-dim); }

.fav-list { display: flex; flex-direction: column; gap: var(--space-xs); }
.fav-item {
  display: flex; align-items: center; gap: var(--space-sm); width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; text-align: left;
  transition: border-color var(--motion-fast), background var(--motion-fast);
}
.fav-item:hover { border-color: var(--accent-dim); background: var(--surface-2); }
.fav-glyph { font-size: 1.4rem; line-height: 1; flex-shrink: 0; }
.fav-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.fav-name { font-family: var(--font-display); font-weight: 500; font-size: var(--fs-base); color: var(--text); }
.fav-note { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.4; }
.fav-cat {
  flex-shrink: 0; font-family: var(--font-mono); font-size: var(--fs-2xs);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--text-dim);
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px var(--space-xs);
}
.fav-empty {
  padding: var(--space-2xl) var(--space-md); text-align: center;
  font-size: var(--fs-sm); color: var(--text-dim); line-height: 1.6;
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
}

/* ════════════════════════════════════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════════════════════════════════════ */
.btn {
  font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 400;
  border-radius: var(--radius); padding: var(--space-xs) var(--space-md);
  cursor: pointer; border: 1px solid transparent; transition: all var(--motion-fast);
}
.btn--primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-bright); border-color: var(--accent-bright); }
.btn--secondary { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn--secondary:hover { color: var(--steel); border-color: var(--steel-dim); }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-tint); }

/* ════════════════════════════════════════════════════════════════════════════
   MODALS (shared shapes, DESIGN.md)
   ════════════════════════════════════════════════════════════════════════════ */
.modal-scrim {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: rgba(0, 0, 0, 0.75); display: flex; align-items: center; justify-content: center;
  padding: var(--space-md); animation: scrim-in var(--motion-base);
}
@keyframes scrim-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-modal);
  animation: modal-in var(--motion-base);
}
.modal--confirm { max-width: 400px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-md); border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  font-family: var(--font-display); font-weight: 500; font-size: var(--fs-lg);
  color: var(--text); letter-spacing: var(--ls-title);
}
.modal-close {
  font-size: 1.5rem; line-height: 1; color: var(--text-muted);
  background: transparent; border: none; cursor: pointer; padding: 0 var(--space-2xs);
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: var(--space-md); display: flex; flex-direction: column; gap: var(--space-md); }
.modal-body p { font-size: var(--fs-base); color: var(--text); line-height: 1.55; }
.modal-foot {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: var(--space-md); border-top: 1px solid var(--border); justify-content: flex-end;
}
.modal-foot .btn--danger { margin-right: auto; } /* destructive sits left, separated */

.field { display: flex; flex-direction: column; gap: var(--space-2xs); }
.field-label {
  font-family: var(--font-mono); font-size: var(--fs-2xs); letter-spacing: var(--ls-label);
  text-transform: uppercase; color: var(--text-muted);
}
.field-opt { color: var(--text-dim); text-transform: none; }
.field input, .field select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--space-sm) var(--space-md);
  font-family: var(--font-body); font-size: var(--fs-base); color: var(--text);
  color-scheme: dark; transition: border-color var(--motion-fast);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }

/* ════════════════════════════════════════════════════════════════════════════
   TOASTS (top-center, DESIGN.md)
   ════════════════════════════════════════════════════════════════════════════ */
.toast-wrap {
  position: fixed; top: calc(var(--hdr-h) + env(safe-area-inset-top) + var(--space-sm));
  left: 0; right: 0; z-index: var(--z-toast);
  display: flex; justify-content: center; pointer-events: none;
}
.toast {
  background: var(--surface-3); border: 1px solid var(--accent-dim); border-radius: var(--radius-pill);
  padding: var(--space-xs) var(--space-md); font-size: var(--fs-sm); color: var(--text);
  box-shadow: var(--shadow-pop); animation: toast-in var(--motion-base);
}
.toast--warn { border-color: var(--warn); }
.toast--success { border-color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Footer (shared standard, DESIGN.md) ─────────────────────────────────────── */
.app-footer {
  margin-top: auto; text-align: center; font-family: var(--font-mono);
  font-size: var(--fs-2xs); letter-spacing: 0.4px; color: var(--text-dim); opacity: 0.7;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border);
}
.app-footer .sep { opacity: 0.5; margin: 0 7px; }

/* ════════════════════════════════════════════════════════════════════════════
   MOBILE (≤768px) — the primary target. Out-in-the-world use is on a phone.
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  html { font-size: 15px; }

  /* Header tabs move to a full-width sub-strip below the header. */
  .header-inner .tabs { display: none; }
  .tabs-strip {
    display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2xs);
    position: fixed; top: calc(var(--hdr-h) + env(safe-area-inset-top)); left: 0; right: 0;
    z-index: var(--z-sticky); background: var(--surface); border-bottom: 1px solid var(--border);
    padding: var(--space-2xs) var(--app-pad);
  }
  .tabs-strip .tab {
    padding: var(--space-xs); border-radius: var(--radius); text-align: center;
    font-size: var(--fs-xs);
  }
  /* Body reserves header + sub-strip height. */
  body { padding-top: calc(var(--hdr-h) + env(safe-area-inset-top) + 44px); }
  .toast-wrap { top: calc(var(--hdr-h) + env(safe-area-inset-top) + 44px + var(--space-sm)); }

  .call-bar { grid-template-columns: 1.4fr 1fr 1fr; }
  .situation-grid { grid-template-columns: 1fr 1fr; }

  .modal { align-self: flex-end; max-width: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-scrim { align-items: flex-end; padding: 0; }
}
