/* ──────────────────────────────────────────────────────────────────────────
 * /css/_lib/dialog.css
 *
 * MANIFEST
 * Purpose: TrustGuard Glass Tier-3 confirmation dialog — the shared
 *          replacement for native confirm()/alert() popups. Pairs with
 *          /js/_lib/dialog.js (window.TG.dialog). A backdrop scrim + a glass
 *          surface that slides up as a BOTTOM SHEET below the 640px content-
 *          column breakpoint and presents as a CENTERED glass CARD at/above it
 *          (matches the dropdown component's 640px breakpoint, NOT 480px).
 *
 * Glass:   The Tier-3 recipe (LOCKED C97-A) is built ENTIRELY from the 3G.1
 *          Glass tokens in /css/tokens.css (--tier3-tint / --glass-blur /
 *          --glass-saturate / --glass-edge / --glass-shadow / --edge-highlight
 *          / --tier3-tint-opaque). NO hardcoded glass values. The destructive
 *          confirm button consumes the --btn-destructive-* tokens (canonical
 *          .btn-destructive treatment); the neutral confirm + cancel consume
 *          --btn-primary-* / --btn-secondary-*. @supports not(backdrop-filter)
 *          → solid opaque-tint fallback.
 *
 * Cascade: A /css/_lib/ shared module (LOCKED C82-A). Loaded AFTER the shared
 *          base layer (tokens → … → shared-themes) and BEFORE the page CSS,
 *          right after /css/_lib/dropdown.css. Single-class `.tg-dlg-*` rules —
 *          no page CSS competes with them, so no specificity scoping needed.
 *
 * Dark-only: DARK is the authoritative, shippable value set (launch is
 *          dark-only per LOCKED C99-A). LIGHT values resolve from the
 *          provisional light token set — finalized at the Phase 4 light sprint.
 *
 * Precache: Added to sw.js PRECACHE_URLS (loaded by 2+ portal pages once
 *          Sprint 2 sweeps the remaining surfaces; same rationale as
 *          dropdown.css + the /js/_lib/ shared modules).
 *
 * Consumed by: contracts.html (Void / Delete contract + Delete saved template
 *          content) this sprint (C106 Sprint 1); the remaining 8 page-JS
 *          confirm/alert surfaces sweep in C106 Sprint 2.
 *
 * Shipped: C106 (Tier-3 pop-up conversion Sprint 1).
 * ────────────────────────────────────────────────────────────────────────── */

/* ── Backdrop scrim ──────────────────────────────────────────────────────── *
 * Bottom-anchored (sheet) by default; re-centered at >=640px below. */
.tg-dlg-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);                /* above sticky tabs (10) + nav (100) */
  display: flex;
  align-items: flex-end;                  /* sheet pinned to the bottom < 640px */
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);        /* same scrim as the dropdown sheet */
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.tg-dlg-overlay.tg-dlg-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Glass dialog surface — BOTTOM SHEET (< 640px) ───────────────────────── *
 * Models the proven .quote-sheet / .tg-dd-sheet recipe (safe-area inset +
 * bottom-pinned slide) rendered in the TrustGuard Glass dark tokens. */
.tg-dlg {
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: var(--space-5) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom));
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;

  /* Glass recipe — Tier 3 (LOCKED C97-A), tokens only */
  background: var(--tier3-tint);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border: 1px solid var(--glass-edge);
  border-bottom: none;
  box-shadow: var(--glass-shadow), inset 0 1px 0 var(--edge-highlight);

  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.tg-dlg-overlay.tg-dlg-open .tg-dlg {
  transform: translateY(0);
}

/* Opaque-tint fallback where backdrop-filter is unsupported — AA legibility. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tg-dlg {
    background: var(--tier3-tint-opaque);
  }
}

/* ── Centered glass CARD (>= 640px) ──────────────────────────────────────── *
 * A dialog has no trigger anchor, so at/above the breakpoint it centers as a
 * card with a fade + subtle scale-in (not a bottom slide). */
@media (min-width: 640px) {
  .tg-dlg-overlay {
    align-items: center;
  }
  .tg-dlg {
    width: auto;
    min-width: 320px;
    max-width: 420px;
    padding-bottom: var(--space-5);
    border-radius: var(--radius-xl);
    border-bottom: 1px solid var(--glass-edge);
    transform: scale(0.96);
    transition: transform 0.2s ease;
  }
  .tg-dlg-overlay.tg-dlg-open .tg-dlg {
    transform: scale(1);
  }
}

/* ── Title + message ─────────────────────────────────────────────────────── */
.tg-dlg-title {
  margin: 0 0 var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--text);
}

.tg-dlg-message {
  margin: 0 0 var(--space-5);
  font-family: var(--font-sans);
  font-size: var(--text-input);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

/* ── Action buttons ──────────────────────────────────────────────────────── *
 * Two equal-width buttons (Cancel left / Confirm right). Mirrors the Glass
 * button system in /css/components.css — treatment from tokens, sizing local
 * (>=44px touch target per LOCKED C97-B). */
.tg-dlg-actions {
  display: flex;
  gap: var(--space-2-5);
  margin-top: auto;
}

.tg-dlg-btn {
  flex: 1 1 0;
  min-height: 44px;
  padding: var(--space-2-5) var(--space-4);
  border-radius: var(--btn-radius);
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: transform 0.18s var(--ease-spring), filter 0.15s ease;
}

.tg-dlg-btn:hover {
  filter: brightness(1.1);
}

.tg-dlg-btn:active {
  transform: scale(var(--press-scale));
}

.tg-dlg-btn:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* Neutral confirm (default) — primary accent button. */
.tg-dlg-confirm {
  background: var(--btn-primary-bg);
  border: var(--btn-primary-border);
  box-shadow: var(--btn-primary-shadow);
  color: var(--btn-primary-text);
}

/* Destructive confirm — contained tinted-red (canonical .btn-destructive). */
.tg-dlg-confirm.tg-dlg-danger {
  background: var(--btn-destructive-bg);
  border: var(--btn-destructive-border);
  box-shadow: none;
  color: var(--btn-destructive-text);
}

/* Cancel — neutral secondary. */
.tg-dlg-cancel {
  background: var(--btn-secondary-bg);
  border: var(--btn-secondary-border);
  box-shadow: var(--btn-secondary-shadow);
  color: var(--btn-secondary-text);
}

/* ── prefers-reduced-motion — no slide/scale, opacity cut-in only ────────── */
@media (prefers-reduced-motion: reduce) {
  .tg-dlg-overlay {
    transition: opacity 0.001s linear;
  }
  .tg-dlg,
  .tg-dlg-overlay.tg-dlg-open .tg-dlg {
    transition: none;
    transform: none;
  }
  .tg-dlg-btn {
    transition: filter 0.15s ease;
  }
}
