/**
 * Dark mode — token overrides only. Activated by data-bs-theme="dark" on <html>
 * (set before first paint in base.html, toggled by [data-theme-toggle]).
 *
 * Loaded after brand-tokens.css and bootstrap-bridge.css. Components already read
 * these tokens, so flipping the neutral ramp and the brand family re-skins the app
 * without touching component CSS. Hardcoded hex in page CSS is fixed per page.
 *
 * Dark brand = champagne gold (#F0C482). Emerald stays as the SUCCESS colour only,
 * so "green = ok" keeps its meaning. Filled controls use --neutral-0 as label
 * colour, which is dark here, so gold buttons get dark ink automatically.
 *
 * White-label: override --dark-accent (and optionally --dark-bg) in a
 * [data-theme="…"] block; the whole gold family derives from it.
 */
:root {
  --dark-accent: #f0c482;
  --dark-bg: #0f1115;
  --dark-card: #171a21;
}

html[data-bs-theme="dark"] {
  color-scheme: dark;

  /* ── Brand family (gold) ───────────────────────────────────────────────── */
  --brand-green: var(--dark-accent);
  --brand-green-hover: color-mix(in srgb, var(--dark-accent) 82%, #fff);
  --brand-green-strong: var(--dark-accent);
  --brand-green-ink: color-mix(in srgb, var(--dark-accent) 70%, #fff);
  --brand-green-ink-deep: color-mix(in srgb, var(--dark-accent) 88%, #000);
  --brand-green-50: color-mix(in srgb, var(--dark-accent) 6%, var(--dark-card));
  --brand-green-100: color-mix(in srgb, var(--dark-accent) 12%, var(--dark-card));
  --brand-green-200: color-mix(in srgb, var(--dark-accent) 30%, var(--dark-card));
  --brand-green-300: color-mix(in srgb, var(--dark-accent) 55%, var(--dark-card));
  --brand-green-400: color-mix(in srgb, var(--dark-accent) 85%, var(--dark-card));
  --brand-green-rgb: 240, 196, 130;
  --brand-green-surface: color-mix(in srgb, var(--dark-accent) 4%, var(--dark-card));
  --brand-green-surface-2: color-mix(in srgb, var(--dark-accent) 8%, var(--dark-card));
  --brand-green-btn: var(--dark-accent);
  --brand-green-btn-hover: var(--brand-green-hover);
  --brand-green-btn-strong: var(--brand-green-hover);
  --brand-green-pill-bg: var(--brand-green-100);
  --brand-green-pill-text: var(--brand-green-ink);
  --brand-green-pill-border: var(--brand-green-200);
  --brand-green-toggle-on-start: var(--brand-green-hover);
  --brand-green-toggle-on-end: var(--dark-accent);
  --brand-action: var(--dark-accent);
  --brand-action-hover: var(--brand-green-hover);
  --brand-action-active: var(--brand-green-ink-deep);
  --brand-link: var(--dark-accent);
  --focus-ring-color: var(--dark-accent);
  --focus-ring: 0 0 0 3px rgba(var(--brand-green-rgb), 0.4);

  /* ── Success stays green ───────────────────────────────────────────────── */
  --color-success: #34d399;
  --color-success-tint: color-mix(in srgb, #34d399 16%, var(--dark-card));
  --color-success-ink: #6ee7b7;
  --color-success-deep: #6ee7b7;
  --color-success-bright: #34d399;
  --color-success-ink-deep: #6ee7b7;
  --color-success-surface: color-mix(in srgb, #34d399 12%, var(--dark-card));
  --color-success-border: color-mix(in srgb, #34d399 35%, var(--dark-card));

  /* ── Neutral ramp (inverted) ───────────────────────────────────────────── */
  --neutral-0: var(--dark-card);
  --neutral-50: #1c2028;
  --neutral-100: #222731;
  --neutral-200: #2d333f;
  --neutral-300: #3c4452;
  --neutral-400: #7d8798;
  --neutral-500: #98a1b0;
  --neutral-600: #b3bac6;
  --neutral-700: #cbd1da;
  --neutral-800: #e4e8ee;
  --neutral-900: #f3f5f8;
  --color-pearl: var(--dark-bg);
  --color-pearl-deep: #0b0d10;
  --color-bg-app: var(--dark-bg);

  /* ── Surfaces / borders / text ─────────────────────────────────────────── */
  --color-surface: var(--dark-card);
  --color-surface-2: #1c2028;
  --color-surface-3: #222731;
  --color-surface-muted: #14171d;
  --color-surface-frost: #1c2028;
  --color-surface-cool: #1c2028;
  --color-surface-subtle: #1c2028;
  --color-surface-form: #1c2028;
  --color-surface-empty: #14171d;
  --color-surface-ios: #14171d;
  --color-gray-100: #222731;
  --color-border: #2d333f;
  --color-border-subtle: #222731;
  --color-border-alt: #2d333f;
  --color-border-muted: #3c4452;
  --color-border-panel: #2d333f;
  --color-border-cool: #2d333f;
  --color-border-google: #2d333f;
  --color-border-form: #3c4452;
  --color-border-dim: #3c4452;
  --color-border-faint: #222731;
  --color-border-divider: #222731;
  --color-border-hover: #2d333f;
  --color-border-dashed: #3c4452;
  --color-gray-300: #3c4452;
  --control-border: #3c4452;
  --color-text: #e4e8ee;
  --color-text-secondary: #b3bac6;
  --color-text-muted: #98a1b0;
  --color-text-faint: #6f7888;
  --color-text-subtle: #98a1b0;
  --color-text-emphasis: #cbd1da;
  --color-text-mid: #b3bac6;
  --color-text-dark: #e4e8ee;
  --color-text-bootstrap: #98a1b0;
  --color-text-form-muted: #6f7888;
  --color-ink-bootstrap: #e4e8ee;
  --color-gray-400: #6f7888;
  --color-gray-700: #cbd1da;
  --color-heading: #f3f5f8;
  --color-ink: #f3f5f8;
  --color-ink-slate: #f3f5f8;

  /* ── Status tints ──────────────────────────────────────────────────────── */
  --color-danger: #f87171;
  --color-danger-bright: #f87171;
  --color-danger-strong: #fca5a5;
  --color-danger-ink: #fca5a5;
  --color-danger-ink-deep: #fca5a5;
  --color-danger-ink-bright: #fca5a5;
  --color-danger-tint: color-mix(in srgb, #ef4444 18%, var(--dark-card));
  --color-danger-surface: color-mix(in srgb, #ef4444 10%, var(--dark-card));
  --color-danger-border: color-mix(in srgb, #ef4444 35%, var(--dark-card));
  --color-danger-soft: color-mix(in srgb, #ef4444 40%, var(--dark-card));

  /* Warning leans orange so it stays apart from the gold brand */
  --color-warning: #fb923c;
  --color-warning-bright: #fb923c;
  --color-warning-ink: #fdba74;
  --color-warning-ink-mid: #fdba74;
  --color-warning-ink-strong: #fdba74;
  --color-warning-ink-deep: #fed7aa;
  --color-warning-deep: #fdba74;
  --color-warning-tint: color-mix(in srgb, #fb923c 16%, var(--dark-card));
  --color-warning-surface: color-mix(in srgb, #fb923c 10%, var(--dark-card));
  --color-warning-surface-alt: color-mix(in srgb, #fb923c 10%, var(--dark-card));
  --color-warning-pending-surface: color-mix(in srgb, #fb923c 14%, var(--dark-card));
  --color-warning-soft: color-mix(in srgb, #fb923c 40%, var(--dark-card));
  --color-warning-soft-alt: color-mix(in srgb, #fb923c 30%, var(--dark-card));

  --color-info: #60a5fa;
  --color-info-ink: #93c5fd;
  --color-info-tint: color-mix(in srgb, #60a5fa 16%, var(--dark-card));
  --color-info-surface: color-mix(in srgb, #60a5fa 10%, var(--dark-card));
  --color-info-border-light: color-mix(in srgb, #60a5fa 40%, var(--dark-card));
  --color-info-sky-surface: color-mix(in srgb, #38bdf8 10%, var(--dark-card));
  --color-info-sky-surface-2: color-mix(in srgb, #38bdf8 16%, var(--dark-card));
  --color-info-sky-border: color-mix(in srgb, #38bdf8 30%, var(--dark-card));
  --color-info-sky-border-mid: color-mix(in srgb, #38bdf8 50%, var(--dark-card));
  --color-info-sky-accent: #38bdf8;
  --color-info-sky-ink: #7dd3fc;
  --color-info-sky-ink-deep: #bae6fd;

  --color-ai: #a78bfa;
  --color-ai-ink: #c4b5fd;
  --color-ai-ink-deep: #c4b5fd;
  --color-ai-tint: color-mix(in srgb, #a78bfa 16%, var(--dark-card));
  --color-ai-surface: color-mix(in srgb, #a78bfa 10%, var(--dark-card));
  --color-ai-border: color-mix(in srgb, #a78bfa 30%, var(--dark-card));

  --color-pink-surface: color-mix(in srgb, #ec4899 14%, var(--dark-card));
  --color-pink-ink: #f9a8d4;
  --color-lime-surface: color-mix(in srgb, #a3e635 12%, var(--dark-card));
  --color-lime-surface-2: color-mix(in srgb, #a3e635 8%, var(--dark-card));
  --color-lime-border: color-mix(in srgb, #a3e635 35%, var(--dark-card));
  --color-lime-accent: #bef264;
  --color-lime-ink: #d9f99d;

  /* ── Leftover light tokens (found by auditing brand-tokens.css) ────────── */
  --media-step-violet-soft: color-mix(in srgb, var(--dark-accent) 6%, var(--dark-card));
  --media-step-violet-border: color-mix(in srgb, var(--dark-accent) 35%, var(--dark-card));
  --mobile-bubble-incoming: #222731;
  --color-whatsapp-bubble-out: #1d3b2c;
  --color-gray-50: #1c2028;
  --color-ink-deep: #f3f5f8;
  --sp-surface: var(--dark-card);
  --sp-gray-light: #222731;
  --sp-border-light: #222731;
  --sp-post-bozza-bg: color-mix(in srgb, #fb923c 16%, var(--dark-card));
  --sp-post-bozza-ink: #fdba74;
  --sp-post-da-approvare-bg: color-mix(in srgb, #a78bfa 16%, var(--dark-card));
  --sp-post-da-approvare-ink: #c4b5fd;
  --sp-post-pubblicato-ink: #93c5fd;
  --sp-ai-purple-hover: #c4b5fd;

  /* ── Sidebar / chrome ──────────────────────────────────────────────────── */
  --sidebar-text-light: #98a1b0;
  --sidebar-hover-bg: #222731;
  --sidebar-section-header-color: #f3f5f8;

  /* rgba(var(--rgb-white), .x) is the frosted "card on card" overlay: in dark it
     must be the card colour, not white. */
  --rgb-white: 23, 26, 33;

  /* ── Elevation ─────────────────────────────────────────────────────────── */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-popover: 0 10px 24px -6px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-modal: 0 24px 48px -12px rgba(0, 0, 0, 0.7);

  /* ── Bootstrap variables that the bridge pins to light values ──────────── */
  --bs-body-color-rgb: 228, 232, 238;
  --bs-link-color-rgb: 240, 196, 130;
  --bs-link-hover-color-rgb: 246, 211, 160;
  --bs-border-color-translucent: rgba(255, 255, 255, 0.08);
  --bs-success: #34d399;
  --bs-success-rgb: 52, 211, 153;
  --bs-success-text-emphasis: #6ee7b7;
  --bs-success-bg-subtle: color-mix(in srgb, #34d399 12%, var(--dark-card));
  --bs-success-border-subtle: color-mix(in srgb, #34d399 30%, var(--dark-card));
  --bs-danger-rgb: 248, 113, 113;
  --bs-warning-rgb: 251, 146, 60;
  --bs-info-rgb: 96, 165, 250;
  --bs-secondary-rgb: 152, 161, 176;
  --bs-danger-text-emphasis: #fca5a5;
  --bs-danger-bg-subtle: var(--color-danger-surface);
  --bs-danger-border-subtle: var(--color-danger-border);
  --bs-warning-text-emphasis: #fdba74;
  --bs-warning-bg-subtle: var(--color-warning-surface);
  --bs-warning-border-subtle: var(--color-warning-soft);
  --bs-info-text-emphasis: #93c5fd;
  --bs-info-bg-subtle: var(--color-info-surface);
  --bs-info-border-subtle: var(--color-info-border-light);
}

/* Light-on-colour labels that are not routed through --neutral-0 */
html[data-bs-theme="dark"] .badge.bg-success,
html[data-bs-theme="dark"] .badge.bg-primary,
html[data-bs-theme="dark"] .badge.bg-info,
html[data-bs-theme="dark"] .badge.bg-warning,
html[data-bs-theme="dark"] .badge.bg-danger {
  color: var(--dark-bg) !important;
}

html[data-bs-theme="dark"] .modal-backdrop {
  --bs-backdrop-bg: #000;
  --bs-backdrop-opacity: 0.6;
}

/* Brand mark: the accent half of the logo follows the dark brand colour */
html[data-bs-theme="dark"] .logo-accent,
html[data-bs-theme="dark"] .brand-accent {
  color: var(--dark-accent);
}

/* Theme toggle (topbar + mobile menu): show the icon for the mode you'd switch to */
.theme-toggle-btn .bi-sun-fill { display: none; }
html[data-bs-theme="dark"] .theme-toggle-btn .bi-sun-fill { display: inline-block; }
html[data-bs-theme="dark"] .theme-toggle-btn .bi-moon-stars-fill { display: none; }

/* Mobile PWA paints chat text with --color-ink-ios (dark on light bubbles). The
   same token is the phone-mockup bezel on desktop, so only flip it on phones. */
@media (max-width: 768px) {
  html[data-bs-theme="dark"] { --color-ink-ios: #e4e8ee; }
}

/* Bootstrap utilities that hardcode light/dark values */
html[data-bs-theme="dark"] {
  --bs-light-rgb: 34, 39, 49;
}
html[data-bs-theme="dark"] .bg-white { background-color: var(--neutral-0) !important; }
html[data-bs-theme="dark"] .bg-light,
html[data-bs-theme="dark"] .text-bg-light { background-color: var(--neutral-100) !important; color: var(--color-text) !important; }
html[data-bs-theme="dark"] .text-dark { color: var(--color-text) !important; }
html[data-bs-theme="dark"] .border-white { border-color: var(--neutral-200) !important; }
