/* SLE-T7-modal — canonical modal primitive per campscout v2.
 *
 * Two overlay variants:
 *   .overlay       — display:none by default; toggle .open to show
 *   .modal-overlay — display:flex by default; toggle .u-hidden to hide
 *
 * Both render the same centered-flex modal surface. Pair with a `.modal`
 * child. Use the .modal-w-{sm,md,lg,xl} size scale; legacy numeric aliases
 * (.modal-w-360..-680) map to the nearest canonical size.
 *
 * On mobile (≤639px) the modal becomes a bottom sheet with a grab handle.
 *
 * Depends on tokens.css. Optionally pair with @suite/lib/components/modal.
 */

/* Backdrops */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay, rgba(0, 0, 0, 0.45));
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: var(--z-modal, 1000);
  align-items: center;
  justify-content: center;
  contain: layout style;
}
.overlay.open { display: flex; }

/* .modal-backdrop is a legacy alias used by secretariat templates. */
.modal-overlay,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay, rgba(0, 0, 0, 0.45));
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: var(--z-modal, 1000);
  display: flex;
  align-items: center;
  justify-content: center;
  contain: layout style;
}

/* Modal surface */
.modal {
  background: var(--wh);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  max-width: 420px;
  width: 92%;
  animation: modal-slide-up 0.15s cubic-bezier(0.2, 0.7, 0.3, 1);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-overlay, 0 16px 50px rgba(0, 0, 0, 0.18));
}
@keyframes modal-slide-up {
  from { transform: translateY(12px) scale(0.985); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .modal { animation: none; }
}

/* Header / close button / footer actions */
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--g2);
}
.modal-hd h3,
.modal-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: var(--fs-xl);
}
.modal-x {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--fs-lg);
  color: var(--g4);
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-xs);
  transition: background var(--dur-fast);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  outline: none;
}
.modal-x:hover { background: var(--g2); }
.modal-acts,
.modal-actions {
  display: flex;
  gap: var(--sp-2h);
  justify-content: flex-end;
  margin-top: 1.1rem;
  padding: 0.9rem 0 0;
  border-top: 1px solid var(--g2);
  position: sticky;
  bottom: -1.5rem;
  background: var(--wh);
  margin-bottom: -1.5rem;
  padding-bottom: 1.5rem;
  z-index: 1;
}

/* Center-actions utility (used by Aperçu/widget settings). */
.u-modal-center-acts { justify-content: center; margin-top: 1rem; }

/* Canonical size scale. */
.modal-w-sm { max-width: 380px; }
.modal-w-md { max-width: 480px; }
.modal-w-lg { max-width: 600px; }
.modal-w-xl { max-width: 680px; }

/* Legacy numeric aliases — map to nearest canonical size. */
:is(.modal-w-360, .modal-w-380) { max-width: 380px; }
.modal-w-420 { max-width: 420px; }
.modal-w-480 { max-width: 480px; }
:is(.modal-w-520, .modal-w-540, .modal-w-560, .modal-w-580) { max-width: 600px; }
:is(.modal-w-600, .modal-w-640, .modal-w-680) { max-width: 680px; }
.modal-w-95,
.modal-w-96 { width: 95%; }
.modal-w-95vw { width: 95vw; }
.modal-scroll-y { overflow-y: auto; }
.modal-maxh-90 { max-height: 90vh; max-height: 90dvh; }

/* Mobile bottom-sheet (≤639px) — replaces centered card.
 * Aligned to Camp v2 Style Guide §19 phone breakpoint by the 2026-06-02 sweep. */
@media (max-width: 639px) {
  .modal {
    width: 98%;
    padding: 1rem;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    max-width: 100%;
    max-height: calc(100vh - 8px);
    max-height: calc(100dvh - 8px);
  }
  .overlay { align-items: flex-end; }
  .modal::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--g3);
    border-radius: var(--radius-pill);
    margin: var(--sp-2) auto var(--sp-1);
  }
  .modal-acts,
  .modal-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }
  .modal-acts .btn,
  .modal-actions .btn {
    flex: 1 1 140px;
    justify-content: center;
  }
}
@media (pointer: coarse) {
  .modal-x {
    width: 36px;
    height: 36px;
    font-size: var(--fs-lg);
  }
}

/* ── Paired with @suite/lib/components/modal ──────────────────── */

/* Danger accent — openModalDialog({ danger: true }) adds .modal-danger. */
.modal-danger .modal-title {
  color: var(--red, #dc2626);
}

/* Body text — emitted as .modal-message by openModalDialog(). */
.modal-message {
  font-size: var(--fs-md, 12.8px);
  color: var(--g4, #6E6B62);
  margin: 0 0 var(--sp-3, 12px);
}

/* Prompt input — emitted as .modal-input by openModalDialog({ type: 'prompt' }). */
.modal-input {
  width: 100%;
  margin-bottom: var(--sp-3, 12px);
}

/* Generic card surface — emitted as .card by openPanel(). */
.card {
  background: var(--wh);
  border: 1px solid var(--g2);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4);
}

/* ── Full-screen modal variant ──────────────────────────────────────────
 *
 * Promoted from matos's local `.matos-modal-fullscreen` by the 2026-06-01
 * audit (§3.4). Used by mobile flows that need to take over the whole
 * viewport (scanner + scan-resolve workflows). Matos's row variants
 * (`.matos-modal-row`, `.matos-modal-return-row`, `.matos-modal-flag-*`)
 * remain matos-local — they're tightly coupled to the sortir/rentrer
 * parts-review flow and don't generalize cleanly.
 */
.modal-fullscreen-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
}
.modal-fullscreen {
  position: fixed;
  inset: 0;
  background: var(--wh);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}
.modal-fullscreen-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--g2);
  flex-shrink: 0;
}
.modal-fullscreen-header h2 {
  flex: 1;
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
}
.modal-fullscreen-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--g4);
  flex-shrink: 0;
}
.modal-fullscreen-close:hover {
  background: var(--g1);
}
.modal-fullscreen-close:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}
.modal-fullscreen-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3);
  -webkit-overflow-scrolling: touch;
}
