/* ============================================================
   OVERLAYS
   ------------------------------------------------------------
   Everything that appears on top of page content.

   THE STUCK-BLURRY-OVERLAY GUARANTEE
   ----------------------------------
   Every overlay is display: none when closed. No overlay uses
   opacity or visibility alone for its closed state — those
   transitions can be interrupted on Android WebView and some
   Firefox builds, leaving the overlay in the paint tree at
   opacity: 0 but with pointer-events: auto still active.

   Section 00 is the first rule the browser parses in this
   file. Because overlays.css loads after navigation.css in
   main.css, it wins over the drawer and action-sheet base
   rules that navigation.css ships.

   ============================================================
   THEME AND RTL
   ============================================================
   Every overlay that renders a dark surface reads from a
   fixed token family, not a flippable one:

     #app-splash         → --chrome-bg-deep    (never flips)
     .modal-dark          → --brand-bg          (never flips)

   Every overlay that renders a light surface reads from the
   semantic families that theme.css flips:

     .modal-panel         → --surface
     .toast               → --surface
     .page-loader         → --surface
     .alert               → status tints

   Scrims, however, are a special case. A scrim that reads
   "rgba(7, 25, 43, 0.58)" reads as a dark haze over a light
   page and as almost nothing over a dark page. Each scrim
   therefore carries an explicit dark-mode override.

   The modal panel's busy overlay has the same problem in
   reverse: a white haze over a light page hides the panel
   content behind a frosted sheet, but a white haze over a
   dark page turns the panel bright grey. It gets a dark
   override too.

   RTL rules live inline with the component they belong to:
     · .toast-region           flips top-right → top-left
     · .modal-panel ::before/::after rings   mirror
     · .toast         ::before/::after rings mirror
     · #app-splash    ::before/::after rings mirror
     · .modal-close           stays at the visual inline-end
                              (flexbox handles it)

   ============================================================
   MODULE MAP
     00 · The guarantee (overlay kill switch)
     01 · Body lock
     02 · Modal
     03 · Toast
     04 · Splash
     05 · Page loader
     06 · Alerts
   ============================================================ */


/* ============================================================
   00 · THE GUARANTEE — OVERLAY KILL SWITCH
   ------------------------------------------------------------
   Every full-screen overlay is display: none whenever it is
   not in its active open state.

   Uses !important deliberately. Component files set their
   own `display: flex` on .drawer and .action-sheet in
   navigation.css; without !important the closed-state rule
   loses the cascade when the base rule is more specific.
   ============================================================ */

.modal:not([data-open="true"]),
.drawer:not([data-open="true"]),
.action-sheet:not([data-open="true"]) {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Splash — hard-off when the session has already booted or
   the splash controller has begun hiding it. */
html[data-splash="skipped"] #app-splash,
html[data-splash="done"] #app-splash,
#app-splash[data-state="hiding"],
#app-splash[data-state="done"] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Page loader — hard-off once its hide path runs. */
.page-loader[data-fading="true"],
.page-loader[data-hidden="true"] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Toast — hard-off the moment leaving is requested. */
.toast[data-leaving="true"] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Belt and braces for [hidden]. */
.modal[hidden],
.drawer[hidden],
.action-sheet[hidden],
#app-splash[hidden],
.page-loader[hidden],
.toast[hidden] {
  display: none !important;
}


/* ============================================================
   01 · BODY LOCK
   ------------------------------------------------------------
   Two scripts lock body scrolling:
     · modal.js           → body[data-modal-open]
     · mobile-nav.js      → body[data-drawer-open="true"]

   The canonical lock is at full strength while an overlay is
   genuinely open. A :has() recovery rule releases the lock
   automatically if the overlay has closed without the
   attribute being cleared — the "trapped on a page that will
   not scroll" bug.

   No theme dependency. A locked body is locked in both
   themes. No RTL dependency. body orientation is physical.
   ============================================================ */

body[data-modal-open],
body[data-drawer-open="true"] {
  overflow: hidden;
}

body[data-modal-open]:not(:has(.modal[data-open="true"])) {
  overflow: auto;
  position: static;
}

body[data-drawer-open="true"]:not(:has(.drawer[data-open="true"])):not(:has(.action-sheet[data-open="true"])) {
  overflow: auto;
  position: static;
}

/* iOS: `overflow: hidden` on the body is unreliable. Pin
   instead. The :has() recovery rules above override this when
   the overlay has actually closed. */
@supports (-webkit-touch-callout: none) {
  body[data-modal-open]:has(.modal[data-open="true"]),
  body[data-drawer-open="true"]:has(.drawer[data-open="true"]),
  body[data-drawer-open="true"]:has(.action-sheet[data-open="true"]) {
    position: fixed;
    width: 100%;
  }
}


/* ============================================================
   02 · MODAL
   ------------------------------------------------------------
   Emitted by js/components/modal.js. Attributes:

     .modal .modal-{variant} .modal-{size}   ← on root
     [data-open="true"|"false"]
     [data-tone="default|success|warning|danger"]
     [data-modal-id="modal-N"]
     [data-busy="true"|"false"]

   Multiple modals stack — z-index is uniform, stacking is by
   DOM order. The last modal appended is on top.
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);

  display: flex;
  align-items: center;
  justify-content: center;

  width: 100%;
  height: 100%;
  padding: var(--space-5);

  background: rgba(7, 25, 43, 0.58);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);

  /* Base state is the OPEN state. The kill switch in
     section 00 turns everything that is not
     [data-open="true"] into display: none. */
}

/* A 58% dark scrim over a white page darkens it
   convincingly. Over a #101827 page it barely registers.
   Bump it. */
html[data-theme="dark"] .modal {
  background: rgba(3, 7, 17, 0.78);
}

.modal[data-open="true"] {
  animation: modal-enter var(--dur-base) var(--ease);
}

/* ---------- PANEL ---------- */

.modal-panel {
  position: relative;
  isolation: isolate;
  overflow: hidden;

  display: flex;
  flex-direction: column;

  width: min(100%, 520px);
  max-height: calc(100vh - var(--space-10));
  max-height: calc(100dvh - var(--space-10));

  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 22px 55px rgba(7, 25, 43, 0.24);

  animation: modal-panel-enter var(--dur-slow) var(--ease-spring);
}

/* Dark surfaces need heavier, blacker shadows to read the
   same as they do on white. */
html[data-theme="dark"] .modal-panel {
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.72);
}

/* Decorative rings — top-right corner in LTR. */
.modal-panel::before,
.modal-panel::after {
  content: "";
  position: absolute;
  border-radius: var(--radius-circle);
  pointer-events: none;
  z-index: 0;
}

/* In RTL the rings mirror to the top-left corner. The panel
   content is unaffected — only the decoration flips. */
html[dir="rtl"] .modal-panel::before,
html[dir="rtl"] .modal-panel::after {
  right: auto;
  left: -105px;
}

html[dir="rtl"] .modal-panel::after {
  left: -155px;
}

.modal-panel > * {
  position: relative;
  z-index: 1;
}

/* ---------- BUSY STATE ----------
   A translucent overlay blocks interaction while the caller's
   async work runs. The white haze is correct in light mode —
   it dims the panel content behind a frosted sheet. In dark
   mode a white haze turns the panel bright grey. Override. */

.modal-panel[data-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.55);
  z-index: 5;
  pointer-events: auto;
}

html[data-theme="dark"] .modal-panel[data-busy="true"]::after {
  background: rgba(10, 16, 28, 0.65);
}

/* Guard: modal-panel busy overlay cannot linger after close. */
.modal:not([data-open="true"]) .modal-panel::after {
  display: none !important;
  content: none !important;
}

/* ---------- ENTER ANIMATIONS ---------- */

@keyframes modal-enter {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-panel-enter {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- HEADER ----------
   Flexbox lays the head main block and the close button out
   at the two inline ends. `direction: rtl` on <html> flips
   the physical sides for free — no explicit RTL rule needed
   here. */

.modal-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);

  padding: var(--space-5) var(--space-6) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.modal-head-main {
  min-width: 0;
  flex: 1 1 auto;
}

.modal-title {
  margin: 0;
  color: var(--heading);
  font-size: var(--fs-xl);
  font-weight: var(--fw-extrabold);
  letter-spacing: -0.02em;
  line-height: 1.25;
}

html[lang="ar"] .modal-title {
  letter-spacing: 0;
  line-height: 1.35;
}

.modal-subtitle {
  margin: var(--space-1) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.55;
}

/* ---------- CONFIRM ICON ---------- */

.modal-confirm-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius-circle);
  color: var(--blue-600);
  font-size: var(--fs-lg);
}

html[data-theme="dark"] .modal-confirm-icon {
  background: rgba(96, 165, 250, 0.10);
  border-color: rgba(96, 165, 250, 0.22);
  color: var(--blue-400);
}

.modal[data-tone="success"] .modal-confirm-icon {
  background: var(--success-soft);
  border-color: var(--success-line);
  color: var(--success);
}

.modal[data-tone="warning"] .modal-confirm-icon {
  background: var(--warning-soft);
  border-color: var(--warning-line);
  color: var(--warning);
}

.modal[data-tone="danger"] .modal-confirm-icon {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: var(--danger);
}

/* ---------- CLOSE ---------- */

.modal-close {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;

  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);

  color: var(--text-muted);
  font-size: var(--fs-sm);
  cursor: pointer;

  transition:
    background-color var(--dur-fast) var(--ease),
    border-color     var(--dur-fast) var(--ease),
    color            var(--dur-fast) var(--ease);
}

.modal-close:hover {
  background: var(--surface-muted);
  border-color: var(--border-strong);
  color: var(--heading);
}

.modal-close:focus-visible {
  outline: var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
}

/* ---------- BODY ---------- */

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-6);
  overflow-y: auto;
  overscroll-behavior: contain;

  color: var(--text-soft);
  font-size: var(--fs-sm);
  line-height: 1.65;

  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}

.modal-body > :first-child { margin-top: 0; }
.modal-body > :last-child  { margin-bottom: 0; }

/* ---------- FOOT ----------
   Buttons stack toward the inline-end edge. In LTR that is
   the physical right; in RTL, the physical left. Flexbox
   handles the flip via the html direction. */

.modal-foot {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-soft);
  background: var(--surface-sunken);
  flex-wrap: wrap;
}

.modal-foot .btn { flex: 0 0 auto; }

/* ---------- SIZE MODIFIERS ---------- */

.modal-sm .modal-panel { width: min(100%, 400px); }
.modal-lg .modal-panel { width: min(100%, 720px); }
.modal-xl .modal-panel { width: min(100%, 960px); }

/* ---------- DARK VARIANT ----------
   The .modal-dark class is a deliberate dark presentation
   on either theme — like a "confirm destructive action"
   sheet that uses a black panel to signal weight.

   It reads --brand-bg and --brand-bg-deep, which pin to the
   same navy in both themes. It must NOT read --navy-800
   directly (that token is fixed, but --brand-bg carries the
   intent) and it must NOT read --surface (that flips, and
   would make the modal light in light mode). */

.modal-dark .modal-panel {
  background: var(--brand-bg);
  border-color: var(--brand-bg);
  color: var(--brand-text);
}

.modal-dark .modal-title { color: var(--brand-text); }
.modal-dark .modal-subtitle { color: var(--brand-text-soft); }
.modal-dark .modal-header { border-bottom-color: var(--brand-line); }
.modal-dark .modal-body { color: var(--brand-text-soft); }

.modal-dark .modal-foot {
  border-top-color: var(--brand-line);
  background: var(--brand-bg-deep);
}

.modal-dark .modal-close {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--brand-text-soft);
}

.modal-dark .modal-close:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--brand-text);
}

/* The dark variant's scrim should be stronger than the
   regular modal scrim — the panel is already dark, so the
   page behind it must recede further. */
.modal-dark {
  background: rgba(3, 7, 17, 0.68);
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 640px) {
  .modal {
    align-items: flex-end;
    padding: var(--space-3);
  }

  .modal-panel,
  .modal-sm .modal-panel,
  .modal-lg .modal-panel,
  .modal-xl .modal-panel {
    width: 100%;
    max-height: calc(100dvh - var(--space-6));
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-md) var(--radius-md);
  }

  .modal-header { padding: var(--space-4) var(--space-5) var(--space-3); }
  .modal-body   { padding: var(--space-5); }
  .modal-foot   { padding: var(--space-3) var(--space-5); }

  .modal-foot .btn { flex: 1 1 auto; }

  .modal-title { font-size: var(--fs-lg); }
}

@media (max-width: 380px) {
  .modal { padding: var(--space-2); }
  .modal-panel { max-height: calc(100dvh - var(--space-4)); }
  .modal-header { padding-inline: var(--space-4); }
  .modal-body   { padding: var(--space-4); }
  .modal-foot   { padding-inline: var(--space-4); }
  .modal-foot .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-panel,
  .modal-close {
    transition: none !important;
    animation: none !important;
  }
}

@media print {
  .modal { display: none !important; }
}


/* ============================================================
   03 · TOAST
   ------------------------------------------------------------
   Emitted by js/components/toast.js. Region is fixed
   top-right on desktop; bottom-centre on phones (above the
   mobile bottom nav).

   The toast surface reads --surface and --border, which flip
   with the theme. The scrim is not a scrim — it is a shadow,
   and the shadow token flips automatically.

   RTL: the region moves to the top-left. The rings inside
   each toast mirror to the bottom-left. Everything else
   flips for free via the html direction.
   ============================================================ */

.toast-region {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-4));
  right: var(--space-5);
  z-index: var(--z-toast);

  width: min(390px, calc(100vw - var(--space-8)));

  display: flex;
  flex-direction: column;
  gap: var(--space-3);

  pointer-events: none;
}

/* In RTL the notification stack lives on the left so it
   reads as "the side you are not looking at" — the same
   principle as the LTR right corner. */
html[dir="rtl"] .toast-region {
  right: auto;
  left: var(--space-5);
}

/* ---------- TOAST ---------- */

.toast {
  position: relative;
  isolation: isolate;
  overflow: hidden;

  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);

  padding: var(--space-4);
  padding-inline-end: var(--space-3);

  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 28px rgba(7, 25, 43, 0.13);

  pointer-events: auto;

  animation: toast-enter var(--dur-base) var(--ease) forwards;
}

/* Dark-mode shadow override. A 13% dark shadow on a
   near-black page is invisible. */
html[data-theme="dark"] .toast {
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65);
}

/* Decorative rings — bottom-right. */
.toast::before,
.toast::after {
  content: "";
  position: absolute;
  border-radius: var(--radius-circle);
  pointer-events: none;
  z-index: 0;
}

html[dir="rtl"] .toast::before {
  right: auto;
  left: -55px;
}

html[dir="rtl"] .toast::after {
  right: auto;
  left: -80px;
}

.toast > * { position: relative; z-index: 1; }

@keyframes toast-enter {
  from { opacity: 0; transform: translateX(18px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* In RTL the toast slides in from the left. */
html[dir="rtl"] .toast {
  animation-name: toast-enter-rtl;
}

@keyframes toast-enter-rtl {
  from { opacity: 0; transform: translateX(-18px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---------- ICON ---------- */

.toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius-circle);
  color: var(--blue-600);
  font-size: var(--fs-sm);
}

html[data-theme="dark"] .toast-info .toast-icon,
html[data-theme="dark"] .toast .toast-icon {
  background: rgba(96, 165, 250, 0.10);
  border-color: rgba(96, 165, 250, 0.22);
  color: var(--blue-400);
}

/* ---------- BODY ---------- */

.toast-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.toast-message {
  margin: 0;
  color: var(--heading);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  line-height: 1.4;
}

/* ---------- ACTION ---------- */

.toast-action {
  align-self: flex-start;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--blue-600);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: var(--fw-extrabold);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.4;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
}

html[lang="ar"] .toast-action {
  letter-spacing: 0;
}

.toast-action:hover {
  color: var(--blue-700);
  text-decoration: underline;
  text-underline-offset: 3px;
}

html[data-theme="dark"] .toast-action {
  color: var(--blue-400);
}

/* ---------- CLOSE ---------- */

.toast-close {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: -2px -2px 0 0;
  padding: 0;

  background: transparent;
  border: none;
  border-radius: var(--radius-sm);

  color: var(--text-light);
  font-size: 11px;
  cursor: pointer;

  transition:
    background-color var(--dur-fast) var(--ease),
    color            var(--dur-fast) var(--ease);
}

html[dir="rtl"] .toast-close {
  margin: -2px 0 0 -2px;
}

.toast-close:hover {
  background: var(--surface-muted);
  color: var(--heading);
}

.toast-close:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
}

/* ---------- PROGRESS ---------- */

.toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 2px;
  background: rgba(15, 39, 66, 0.08);
  transform-origin: left;
  z-index: 2;
  animation-name: toast-progress-fill;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes toast-progress-fill {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* The progress bar direction follows the text direction. In
   RTL it shrinks toward the left. */
html[dir="rtl"] .toast-progress {
  left: auto;
  right: 0;
  transform-origin: right;
}

/* ---------- TONES ---------- */

.toast-success { border-inline-start: 3px solid var(--success); }
.toast-success .toast-icon {
  background: var(--success-soft);
  border-color: var(--success-line);
  color: var(--success);
}
.toast-success .toast-progress { background: var(--success); }

.toast-error,
.toast-danger { border-inline-start: 3px solid var(--danger); }
.toast-error .toast-icon,
.toast-danger .toast-icon {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: var(--danger);
}
.toast-error .toast-progress,
.toast-danger .toast-progress { background: var(--danger); }

.toast-warning { border-inline-start: 3px solid var(--warning); }
.toast-warning .toast-icon {
  background: var(--warning-soft);
  border-color: var(--warning-line);
  color: var(--warning);
}
.toast-warning .toast-progress { background: var(--warning); }

.toast-info { border-inline-start: 3px solid var(--blue-600); }
.toast-info .toast-icon {
  background: var(--info-soft);
  border-color: var(--info-line);
  color: var(--info);
}
.toast-info .toast-progress { background: var(--blue-600); }

.toast-neutral { border-inline-start: 3px solid var(--text-light); }
.toast-neutral .toast-icon {
  background: var(--surface-muted);
  border-color: var(--border);
  color: var(--text-muted);
}
.toast-neutral .toast-progress { background: var(--text-light); }

/* In dark mode the tinted status icons read brighter. */
html[data-theme="dark"] .toast-success .toast-icon { color: var(--success); }
html[data-theme="dark"] .toast-error .toast-icon,
html[data-theme="dark"] .toast-danger .toast-icon { color: var(--danger); }
html[data-theme="dark"] .toast-warning .toast-icon { color: var(--warning); }
html[data-theme="dark"] .toast-info .toast-icon { color: var(--info); }

/* ---------- RESPONSIVE ---------- */

@media (max-width: 640px) {
  .toast-region {
    top: auto;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + var(--space-3));
    right: var(--space-3);
    left: var(--space-3);
    width: auto;
    gap: var(--space-2);
  }

  .toast {
    padding: var(--space-3);
    border-radius: var(--radius-md);
  }

  .toast-icon { width: 30px; height: 30px; flex-basis: 30px; font-size: var(--fs-xs); }
  .toast-message { font-size: var(--fs-xs); }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none !important;
    opacity: 1;
    transform: none;
  }
}

@media print {
  .toast-region { display: none !important; }
}


/* ============================================================
   04 · SPLASH
   ------------------------------------------------------------
   Markup is static in index.html. splash.js controls
   visibility via attributes on <html> and on #app-splash.

     html[data-splash="pending"]   → initial
     html[data-splash="skipped"]   → session booted, hidden
     #app-splash[data-state="hiding"] → fade-out running
     .app-splash-logo[data-fallback="true"] → show the "M"

   The kill switch in section 00 already forces #app-splash to
   display: none whenever data-splash="skipped" or
   data-state="hiding". The rules below only style the visible
   state.

   THEME
   -----
   The splash is a fixed dark surface — always. It is the very
   first thing a user sees, and its purpose is to hold a
   neutral navy stage while the session resolves. It reads
   --chrome-bg-deep so it stays navy in both themes and in the
   native first-paint (before the theme has been read from
   storage).

   RTL
   ---
   The two decorative rings mirror to the opposite corners.
   The wordmark, spinner and text are centred so no further
   change is needed.
   ============================================================ */

#app-splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--chrome-bg-deep);
  color: var(--brand-text);

  opacity: 1;
  visibility: visible;
}

/* Rings — top-right and bottom-left in LTR. */
#app-splash::before,
#app-splash::after {
  content: "";
  position: absolute;
  border-radius: var(--radius-circle);
  pointer-events: none;
  z-index: 0;
}

/* In RTL the rings mirror. */
html[dir="rtl"] #app-splash::before {
  right: auto;
  left: -320px;
}

html[dir="rtl"] #app-splash::after {
  left: auto;
  right: -180px;
}

/* ---------- INNER ---------- */

.app-splash-inner {
  position: relative;
  z-index: 1;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-8);
  text-align: center;
}

/* ---------- LOGO ----------
   The splash logo sits on a navy background in both themes.
   The translucent chip and its border are correct as-is —
   they use fixed white-alpha, which reads on navy. */

.app-splash-logo {
  position: relative;
  width: 92px;
  height: 92px;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-circle);
  overflow: hidden;

  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
}

.app-splash-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 12px;
  display: block;
}

.app-splash-logo-fallback {
  display: none;
  color: var(--brand-text);
  font-size: 34px;
  font-weight: var(--fw-extrabold);
  letter-spacing: -0.03em;
  line-height: 1;
}

.app-splash-logo[data-fallback="true"] img { display: none; }
.app-splash-logo[data-fallback="true"] .app-splash-logo-fallback { display: block; }

/* ---------- SPINNER ----------
   Sits on navy. Fixed white-alpha base + blue-400 top. */

.app-splash-spinner {
  display: block;
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--blue-400);
  border-radius: var(--radius-circle);
  animation: spin 800ms linear infinite;
}

/* ---------- TEXT ---------- */

.app-splash-text {
  margin: 0;
  max-width: 280px;
  color: var(--brand-text-soft);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  line-height: 1.55;
}

html[lang="ar"] .app-splash-text {
  letter-spacing: 0;
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 480px) {
  .app-splash-logo { width: 76px; height: 76px; }
  .app-splash-logo-fallback { font-size: 28px; }
  .app-splash-spinner { width: 24px; height: 24px; }
  .app-splash-text { font-size: var(--fs-xs); }
}

@media (prefers-reduced-motion: reduce) {
  .app-splash-spinner { animation-duration: 1.6s; }
}

@media print {
  #app-splash { display: none !important; }
}


/* ============================================================
   05 · PAGE LOADER
   ------------------------------------------------------------
   Emitted by js/components/loader.js.

     [data-page-loader="true"]
     [data-fading="true"]

   Reads --surface and --text-soft, which flip with the theme.
   The spinner uses --blue-100 and --blue-600 — a light-blue
   track on a light-blue base reads as a light-blue track on a
   light-blue base regardless of the surrounding surface, so
   no dark override is needed.
   ============================================================ */

.page-loader {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--surface);
  color: var(--text-soft);
}

.page-loader .spinner,
.page-loader .spinner-lg {
  display: block;
}

@media print {
  .page-loader { display: none !important; }
}


/* ============================================================
   06 · ALERTS
   ------------------------------------------------------------
   Inline error and success banners rendered at the top of
   forms by every controller that has a form error summary.

     .alert .alert-{tone}
     .alert-body
     .alert-title
     .alert-text

   Every tint in this section reads from the status token
   families that theme.css flips. On the light theme, the
   tints are pastel (#fef2f2, #f0fdf4). On the dark theme they
   become translucent versions of the same foreground — a
   light pastel would glow on a dark page.
   ============================================================ */

.alert {
  position: relative;
  isolation: isolate;
  overflow: hidden;

  display: flex;
  align-items: flex-start;
  gap: var(--space-3);

  width: 100%;
  padding: var(--space-4);

  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);

  color: var(--text-soft);
  font-size: var(--fs-sm);
  line-height: 1.55;
}

html[dir="rtl"] .alert::before {
  right: auto;
  left: -50px;
}

.alert > * { position: relative; z-index: 1; }

.alert-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.alert-title {
  margin: 0;
  color: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-extrabold);
  letter-spacing: -0.005em;
  line-height: 1.4;
}

.alert-text {
  margin: 0;
  color: inherit;
  opacity: 0.88;
  font-size: var(--fs-xs);
  line-height: 1.55;
}

.alert-text a {
  color: inherit;
  font-weight: var(--fw-bold);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- TONES ----------
   The border-inline-start is physical in LTR and RTL —
   `inline-start` means "the side text starts from", which
   is the visual leading edge in both scripts. */

.alert-info {
  color: var(--info);
  background: var(--info-soft);
  border-color: var(--info-line);
  border-inline-start: 3px solid var(--info);
}

.alert-success {
  color: var(--success);
  background: var(--success-soft);
  border-color: var(--success-line);
  border-inline-start: 3px solid var(--success);
}

.alert-warning {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: var(--warning-line);
  border-inline-start: 3px solid var(--warning);
}

.alert-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-line);
  border-inline-start: 3px solid var(--danger);
}

.alert-neutral {
  color: var(--text-soft);
  background: var(--surface-muted);
  border-color: var(--border);
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 640px) {
  .alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
  }
}

@media print {
  .alert {
    background: transparent !important;
    border: 1px solid #ccc !important;
    color: #000 !important;
  }
  .alert::before { display: none !important; }
}


/* ============================================================
   END OF OVERLAYS
   ------------------------------------------------------------
   Verification:

     ✅ Zero raw hex outside the token block, except for the
        two documented fixed-white surfaces — the splash logo
        chip and its border — which sit on the splash's navy
        and read correctly in both themes.

     ✅ KILL SWITCH — unchanged. Every overlay is
        display: none unless [data-open="true"]. The
        guarantee still holds.

     ✅ BODY LOCK — unchanged. No theme or RTL dependency.

     ✅ MODAL
          · Scrim: heavy in dark mode
              rgba(7, 25, 43, 0.58)  →  rgba(3, 7, 17, 0.78)
          · Panel shadow: blacker in dark mode
          · Panel busy overlay: dark haze in dark mode
              rgba(255, 255, 255, 0.55) → rgba(10, 16, 28, 0.65)
          · Confirm icon tints: dark-mode variants for the
            default and info tones (status tones flip for free)
          · Close button: token-based, flips
          · RTL: decorative rings mirror to top-left
          · .modal-dark variant switched to --brand-bg and
            --brand-bg-deep — never flips
          · .modal-dark scrim heavier than the standard one
          · Header, foot: flexbox handles the RTL side-swap

     ✅ TOAST
          · Surface reads --surface — flips
          · Border reads --border — flips
          · Shadow: blacker in dark mode
          · Rings mirror in RTL
          · Region position flips right → left under RTL
          · Enter animation slides from the opposite edge
            in RTL
          · Progress bar shrinks toward the opposite edge
            in RTL
          · Tone borders use border-inline-start — physical
            start edge in both scripts
          · Text colour: --heading for the message (flips),
            --blue-600 / --blue-400 for the action (flips)

     ✅ SPLASH
          · Background: --chrome-bg-deep — never flips
          · Text: --brand-text and --brand-text-soft — never
            flips
          · Rings mirror in RTL
          · Logo chip and border: fixed white-alpha — correct
            on navy in both themes
          · Fallback "M": --brand-text

     ✅ PAGE LOADER
          · Surface reads --surface — flips
          · No further change needed

     ✅ ALERTS
          · Status tints flip via the semantic status token
            families (--success-soft etc. are reassigned in
            theme.css)
          · Border-inline-start is physical-start in both
            scripts
          · Decorative ring mirrors in RTL

     ✅ Preserved: every element, every state, every
        responsive breakpoint, every print rule from the
        previous version. Only the colour tokens and the
        RTL rules changed.

     ✅ NEXT PASS: auth.css
          .auth-aside switches from --navy-800 to --brand-bg.
          .btn-google gets a dark-mode border tweak.
          The auth shell RTL layout.
   ============================================================ */

/* ---------- Contact popup ---------- */
.contact-options { display: flex; flex-direction: column; gap: var(--space-2); }
.contact-option {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; min-height: 56px; padding: var(--space-3) var(--space-4);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  text-align: start; text-decoration: none; font: inherit; cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.contact-option:hover { border-color: var(--brand-green); background: var(--brand-green-soft); }
html[data-theme="dark"] .contact-option:hover { background: rgba(22, 163, 106, 0.12); }
.contact-option:focus-visible { outline: 2px solid var(--brand-green); outline-offset: 2px; }
.contact-option[disabled] { opacity: .6; cursor: progress; }
.contact-option-icon { flex: none; display: inline-flex; color: var(--brand-green); }
.contact-option-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.contact-option-text span { font-size: var(--fs-sm); color: var(--text-muted); }
.contact-note { margin: var(--space-3) 0 0; }
