/* SHARED·MODALSHELL (1152) — THE BOTTOM-SHEET DIALOG CHROME: overlay, sheet, top, title, close
 * (×), body, foot. The shared scaffold consumed by chat + profile + disclaimer_modal +
 * week-read — 26 modal-* call sites across nine view files (chat.js, profile.js,
 * disclaimer_modal.js, report.js, mfa.render.js, prof-language.render.js, textinput.render.js,
 * and the related gallery files).
 *
 * RE-SOURCED 2026-09-25 from web/css/app.css lines 1855–1999, brief 558
 * (REPORT-558-redo-move-modal). Consumers keep working because the class NAMES did not
 * change — every renderer still emits `class="modal-overlay"`, `class="modal-sheet"`,
 * `class="modal-top"`, etc. Values VERBATIM — the brief is explicit on no design changes.
 *
 * RE-DO of brief 536 (REPORT-536, 9a07cbd7, never landed) and brief 482 (REPORT-482,
 * d30b8a74, never landed) — REPORT-543 §1 LOST. The line numbers in the RE-SOURCED comment
 * above updated 1845–1990 → 1855–1999 to reflect today's app.css; the rule bodies are
 * byte-equivalent to the prior blob.
 *
 * The token linter (forward-only, scans ADDED lines in the staged diff) would otherwise
 * refuse the raw 14px / 6px / 10px spacing values and the var(--size-N) font-size roles that
 * ship in app.css today. Each affected line carries a `/* token-exception *\/` marker (the
 * linter's bypass hatch) so the moved CSS stays byte-identical in source and render, and no
 * rule value is changed by this extraction. The markers are comments — stripped before the
 * cascade parses — so the rendered modal is identical to the prior app.css.
 *
 * Card CSS is self-contained: every element a modal renders gets its style explicitly
 * under its own root class (overlay, sheet, top, title, close, body, foot) with zero
 * reliance on page or user-agent defaults. The body's NESTED classes (.modal-body .label,
 * .modal-body .input, .modal-body .radio-grid, .modal-foot .btn) compose the app's
 * shared pre-card types — those stay owned by other rows (label/input/radio/button
 * families) and remain declared in app.css.
 *
 * ⚠️ THE OVERLAY USES --kb-h — Capacitor Keyboard willShow / willHide keeps the var in
 * sync with the iOS keyboard height; the sheet uses dvh as a belt-and-braces. Both
 * fall back to 0 so the overlay reaches the screen edge when no keyboard is shown.
 *
 * Local aliases mirror app.css's own :root block for the four colours the modal
 * references but that live as aliases in app.css, not in web/styles/tokens.css. Without
 * these the static contrast audit cannot resolve --paper / --paper-card / --ink / --rule
 * and reports false-positive failures against the OVERLAY (--overlay-scrim) it cannot see
 * past — the modal renders on --paper, not on the overlay. Renders identically.
 */
:root {
  --paper:        var(--surface-ground);
  --paper-card:   var(--surface-card);
  --ink:          var(--text-primary);
  --rule:         var(--border-hairline);
}

/* ============================================================================
 * Modal — used for "Edit baby" and similar full-sheet forms.
 * Slides up from the bottom on mobile, centred on desktop. Cream paper inside,
 * dimmed ink overlay outside. Shares input/label/btn styles with the rest.
 * ========================================================================== */
/* The overlay uses a CSS variable --kb-h that the modal JS keeps in sync with the
 * iOS keyboard height (Capacitor Keyboard willShow / willHide). When the keyboard
 * is up, we lift the bottom of the overlay so the modal sheet sits above it.
 * Default is 0 so the overlay reaches the screen edge when no keyboard is shown. */
.modal-overlay {
  position: fixed;
  inset: 0;
  bottom: var(--kb-h, 0px);
  z-index: 1000;
  background: var(--overlay-scrim);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  transition: bottom 0.18s ease;
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 24px;
  }
}

/* Sheet uses dvh so keyboard correctly shrinks viewport on platforms that report it.
 * On iOS Capacitor the dvh trick doesn't always fire — that's why we also use --kb-h
 * on the overlay above as a belt-and-braces. */
.modal-sheet {
  background: var(--paper);
  width: 100%;
  max-width: var(--col-max);
  height: auto;
  max-height: calc(100dvh - var(--kb-h, 0px) - 24px);
  display: flex;
  flex-direction: column;
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
}

@media (min-width: 600px) {
  .modal-sheet {
    border-radius: var(--r-lg);
    max-height: 88dvh;
  }
}

.modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--size-17); /* token-exception */
  font-weight: 500;
  color: var(--ink);
}

.modal-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--size-22); /* token-exception */
  line-height: var(--leading-100);
  color: var(--ink-600);
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.modal-close:hover {
  background: var(--paper-card);
  color: var(--ink);
}

.modal-body {
  padding: 14px 20px 16px; /* token-exception */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

/* Tighter spacing inside modals than full-page forms */
.modal-body .label {
  margin-top: 14px; /* token-exception */
  margin-bottom: 6px; /* token-exception */
  display: block;
  font-family: var(--font-label);
  font-size: var(--size-11); /* token-exception */
  letter-spacing: var(--tracking-12);
  text-transform: uppercase;
  color: var(--ink-600);
}

.modal-body .label:first-child {
  margin-top: 0;
}

.modal-body .input {
  width: 100%;
  padding: 12px 14px; /* token-exception */
  font-size: var(--size-16); /* token-exception */
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  color: var(--ink);
  outline: none;
}

.modal-body .input:focus {
  border-color: var(--accent);
}

.modal-body .radio-grid {
  margin-bottom: 4px;
}

.modal-foot {
  display: flex;
  flex-direction: row-reverse;
  gap: 10px; /* token-exception */
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); /* token-exception */
  border-top: 1px solid var(--rule);
  background: var(--paper);
  flex-shrink: 0;
}

.modal-foot .btn {
  flex: 1;
  padding: 14px 20px; /* token-exception */
}

@media (min-width: 600px) {
  .modal-foot .btn {
    flex: 0 0 auto;
    min-width: 120px;
  }
}
