/* =====================================================================
   DSTMS - assets/css/dark.css
   Dark theme. Load last (after app.css or auth.css).

   How the theme is chosen: a tiny inline script in the page <head> (layout
   files) sets <html data-theme="light|dark"> before first paint, from the
   saved choice in localStorage ("dstms-theme": light | dark | auto) and
   otherwise from prefers-color-scheme. The first block below is the
   no-JavaScript fallback for tokens only.
   ===================================================================== */

/* ---------- No-JS fallback: follow the system ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --primary: #60a5fa; --primary-d: #bfdbfe; --primary-l: rgba(96, 165, 250, .16);
    --ok: #4ade80; --ok-bg: rgba(34, 197, 94, .16);
    --warn: #fbbf24; --warn-bg: rgba(245, 158, 11, .16);
    --bad: #f87171; --bad-bg: rgba(239, 68, 68, .16);
    --info: #38bdf8; --info-bg: rgba(14, 165, 233, .16);
    --bg: #0b1220; --surface: #111a2e; --surface-2: #18233b;
    --text: #e5e7eb; --text-2: #cbd5e1; --muted: #94a3b8; --line: #26334d;
    --overlay: rgba(0, 0, 0, .65); --focus: rgba(96, 165, 250, .4);
    color-scheme: dark;
  }
}

/* ---------- Dark tokens ---------- */
:root[data-theme="dark"] {
  --primary: #60a5fa;                      /* links and active text */
  --primary-d: #bfdbfe;
  --primary-l: rgba(96, 165, 250, .16);
  --accent: #fbbf24;

  --ok: #4ade80;    --ok-bg: rgba(34, 197, 94, .16);
  --warn: #fbbf24;  --warn-bg: rgba(245, 158, 11, .16);
  --bad: #f87171;   --bad-bg: rgba(239, 68, 68, .16);
  --info: #38bdf8;  --info-bg: rgba(14, 165, 233, .16);

  --bg: #0b1220;
  --surface: #111a2e;
  --surface-2: #18233b;
  --text: #e5e7eb;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --line: #26334d;
  --overlay: rgba(0, 0, 0, .65);
  --focus: rgba(96, 165, 250, .4);

  --shadow: 0 4px 18px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);

  color-scheme: dark;
}

/* ---------- Surfaces with fixed (non-token) colours ---------- */
[data-theme="dark"] .topbar { background: rgba(17, 26, 46, .86); }
[data-theme="dark"] .bottomnav { background: rgba(17, 26, 46, .92); }
[data-theme="dark"] .bn-center .bn-circle { border-color: var(--bg); }
[data-theme="dark"] .icon-btn .dot-badge { border-color: var(--surface); }

/* ---------- Buttons: the light "primary" token is for text, so fix fills ---------- */
[data-theme="dark"] .btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
[data-theme="dark"] .btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
[data-theme="dark"] .btn-ok { background: #16a34a; border-color: #16a34a; }
[data-theme="dark"] .btn-danger { background: #dc2626; border-color: #dc2626; }
[data-theme="dark"] .btn-ok:hover, [data-theme="dark"] .btn-danger:hover { filter: brightness(1.1); }
[data-theme="dark"] .btn-soft { color: var(--primary); }
[data-theme="dark"] .chip.is-active,
[data-theme="dark"] .pg.is-active { background: #2563eb; border-color: #2563eb; color: #fff; }
[data-theme="dark"] .chip-high.is-active { background: #dc2626; }
[data-theme="dark"] .chip-medium.is-active { background: #d97706; }
[data-theme="dark"] .chip-low.is-active { background: #16a34a; }

/* ---------- Gradients keep the brand blues ---------- */
[data-theme="dark"] .hero,
[data-theme="dark"] .auth-brand {
  background:
    radial-gradient(circle at 90% 0%, rgba(245, 158, 11, .3), transparent 45%),
    linear-gradient(135deg, #1d4ed8, #172554);
}
[data-theme="dark"] .fab,
[data-theme="dark"] .bn-center .bn-circle,
[data-theme="dark"] .brand-mark { background: linear-gradient(135deg, #2563eb, #1e3a8a); }
[data-theme="dark"] .progress > span { background: linear-gradient(90deg, #2563eb, #38bdf8); }
[data-theme="dark"] .error-code { background: linear-gradient(135deg, #60a5fa, #fbbf24); -webkit-background-clip: text; background-clip: text; }

/* ---------- Forms ---------- */
[data-theme="dark"] .input:hover,
[data-theme="dark"] .select:hover,
[data-theme="dark"] .textarea:hover { border-color: #3b4a68; }
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
[data-theme="dark"] .select option { background: var(--surface); color: var(--text); }
[data-theme="dark"] .check input[type="checkbox"],
[data-theme="dark"] .check input[type="radio"] { border-color: #475569; background: var(--surface-2); }
[data-theme="dark"] .check input:checked { background: #2563eb; border-color: #2563eb; }
[data-theme="dark"] .switch input { background: #475569; }
[data-theme="dark"] .switch input:checked { background: #16a34a; }
[data-theme="dark"] input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
}

/* ---------- Alerts, badges, toasts ---------- */
[data-theme="dark"] .alert-ok   { color: #bbf7d0; border-color: rgba(74, 222, 128, .3); }
[data-theme="dark"] .alert-warn { color: #fde68a; border-color: rgba(251, 191, 36, .3); }
[data-theme="dark"] .alert-bad  { color: #fecaca; border-color: rgba(248, 113, 113, .3); }
[data-theme="dark"] .alert-info { color: #bae6fd; border-color: rgba(56, 189, 248, .3); }
[data-theme="dark"] .badge-ok   { color: var(--ok); }
[data-theme="dark"] .badge-warn { color: var(--warn); }
[data-theme="dark"] .badge-bad  { color: var(--bad); }
[data-theme="dark"] .badge-info { color: var(--info); }
[data-theme="dark"] .a2hs { color: #bae6fd; border-color: rgba(56, 189, 248, .3); }
[data-theme="dark"] .toast { background: #263349; }
[data-theme="dark"] .toast.ok { background: #16a34a; }
[data-theme="dark"] .toast.bad { background: #dc2626; }
[data-theme="dark"] .toast.warn { background: #d97706; }
[data-theme="dark"] .toast.info { background: #0284c7; }

/* ---------- Auth screens ---------- */
[data-theme="dark"] .auth-card { background: var(--surface); }
@media (min-width: 1024px) {
  [data-theme="dark"] .auth-lang .btn { color: var(--text); background: var(--surface); border-color: var(--line); }
}

/* ---------- Theme toggle icons: show the one for the next theme ---------- */
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* Keep QR codes and ticket paper white and high contrast */
[data-theme="dark"] .qr-box,
[data-theme="dark"] canvas.qr { background: #fff; padding: 10px; border-radius: var(--radius-sm); }
