/* ════════════════════════════════════════════════════════════════════
   App modal — shared liquid-glass dialog shell
   ────────────────────────────────────────────────────────────────────
   Reusable dialog primitives. Two consumers:

     1. Static markup (e.g. the CEX add-credential form in index.html)
        uses these classes directly. The form-specific bits
        (.cex-modal-form, .cex-modal-field, .is-secret) live in
        pages/funds.css — those are field styles, not shell styles.

     2. The programmatic confirm/alert API in js/components/modal.js
        builds the same DOM at runtime: backdrop > .app-modal >
        head/body/actions. Replaces native confirm()/alert() with
        styled, themed dialogs that match the rest of the app.

   The "liquid glass" treatment:
     • Backdrop has only the page-blur — no scrim color. The dim is
       painted from the modal card outward via a 100vmax box-shadow,
       so the card itself never sees the tint and the glass fill
       reads cleanly. Without this, the card's translucent fill
       would be muddied by the dim layer underneath.
     • Card alpha is held at ~.55 in BOTH themes so dark and light
       read as the same material. The default --surface-card token
       is .30 dark / 1.0 light — too far apart to align visually.
   ════════════════════════════════════════════════════════════════════ */

.app-modal-backdrop {
  position: fixed; inset: 0;
  /* Transparent — the dim is painted by the card's box-shadow below.
     Putting a scrim color here would bleed through the card's
     translucency and muddy the glass surface. */
  background: transparent;
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 200;
}
/* `[hidden]` is the open/close source of truth (set by the JS lifecycle).
   Pairs with `.is-open` so removing hidden + adding is-open renders
   the flex backdrop. The :not([hidden]) selector wins over [hidden]'s
   default display:none in source-order specificity. */
.app-modal-backdrop.is-open:not([hidden]) { display: flex; }

.app-modal {
  background: rgba(20,20,20,.55);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  width: min(480px, 92vw);
  max-height: 90vh; overflow-y: auto;
  -webkit-backdrop-filter: blur(10px) saturate(120%);
          backdrop-filter: blur(10px) saturate(120%);
  /* First shadow = the scrim (100vmax dim ring around the card,
     painted ONLY outside the card's rounded rect — see file header).
     Second/third = inner highlight + drop shadow for elevation. */
  box-shadow:
    0 0 0 100vmax rgba(0,0,0,.38),
    0 1px 0 rgba(255,255,255,.03) inset,
    0 18px 60px rgba(0,0,0,.45);
}
:root[data-theme="light"] .app-modal {
  background: rgba(255,255,255,.55);
  box-shadow:
    0 0 0 100vmax rgba(0,0,0,.32),
    0 1px 0 rgba(255,255,255,.6) inset,
    0 18px 60px rgba(17,17,17,.16);
}

.app-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 4px;
}
.app-modal-title {
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
}
/* When a CEX badge glyph is rendered into the title (cexBadge nameOnly),
   bump it slightly larger than the inline-list size and tint the
   wrapper with the venue's brand color via a --venue-color custom
   property the caller sets on the title element. The 3px outer halo
   uses color-mix to derive a soft 18% alpha ring without the caller
   needing to compute it — works for any color the venue meta exposes
   (hex literals or var(--foreground) for theme-flipping marks). */
.app-modal-title .tdd-cex-logo-wrap {
  width: 28px; height: 28px;
  border-radius: 7px;
  border-color: color-mix(in srgb, var(--venue-color, var(--border)) 55%, var(--border));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--venue-color, transparent) 18%, transparent),
    0 1px 4px rgba(0,0,0,.18);
}
.app-modal-sub {
  font-size: 12px; color: var(--muted-foreground);
  margin-bottom: 14px;
}
/* Body slot for confirm/alert message text. Form-driven modals (the
   CEX add-credential dialog) skip this and lay out their own fields. */
.app-modal-body {
  font-size: 13px; color: var(--foreground); line-height: 1.5;
  white-space: pre-wrap;          /* preserve \n in confirm messages */
  margin-bottom: 16px;
}
.app-modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 6px;
}
.app-modal-status {
  font-size: 12px; color: var(--muted-foreground); margin-right: auto;
}
.app-modal-status.is-error { color: var(--neg, var(--loss)); }
.app-modal-status.is-ok    { color: var(--pos, var(--profit)); }

/* Mobile sheet — same treatment the cex-modal had: nearly full-screen
   on phones so action targets stay easy to hit. */
@media (max-width: 720px) {
  .app-modal {
    width: calc(100vw - 24px);
    padding: 16px;
    max-height: calc(100vh - 24px);
  }
  .app-modal-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }
  .app-modal-actions .app-modal-status {
    flex: 1 1 100%; margin-right: 0; order: -1;
  }
  .app-modal-actions button {
    flex: 1 1 auto;
  }
}

/* ── Destructive primary button ──────────────────────────────────────
   Used for confirm-delete actions. Layered as `.primary.is-destructive`
   so the base .primary geometry (padding/font) is preserved and only
   the color scheme flips to a red affirmative. */
button.primary.is-destructive {
  background: var(--loss);
  color: #ffffff;
}
button.primary.is-destructive:hover { opacity: .9; }
