/* Shared dark-mode surfaces, form controls and chrome.
   Brand palettes live in theme-lokeai.css / theme-afixcal.css. */

html {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --card: #121a2b;
  --input-bg: #0e1626;
  --header-bg: rgba(8, 13, 24, 0.86);
  --overlay: rgba(2, 6, 14, 0.72);
  --mix-base: #121a2b;
  --muted: var(--text-muted);
  scrollbar-color: #3d4d68 transparent;
}

html[data-theme="dark"] body {
  background: var(--bg-subtle);
  color: var(--text);
}

html.theme-ready,
html.theme-ready body {
  transition: background-color 0.22s ease, color 0.22s ease;
}

@media (prefers-reduced-motion: reduce) {
  html.theme-ready,
  html.theme-ready body {
    transition: none;
  }
}

/* Toggle */
.theme-toggle {
  position: relative;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--bg-subtle, #f8fafc);
  color: var(--text, #1e293b);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.theme-toggle:hover {
  background: var(--card, #fff);
  transform: translateY(-1px);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #2563eb) 28%, transparent);
}

.theme-toggle .theme-icon {
  position: absolute;
  width: 1.15rem;
  height: 1.15rem;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

html[data-theme="dark"] .theme-icon-sun,
html:not([data-theme="dark"]) .theme-icon-moon {
  opacity: 0;
  transform: rotate(80deg) scale(0.4);
  pointer-events: none;
}

html[data-theme="dark"] .theme-icon-moon,
html:not([data-theme="dark"]) .theme-icon-sun {
  opacity: 1;
  transform: none;
}

.theme-toggle-float {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 80;
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(15, 39, 68, 0.16));
}

.app-header .theme-toggle,
header .theme-toggle {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.app-header .theme-toggle:hover,
header .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

.login-form-panel {
  position: relative;
}

.login-theme-slot {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 2;
}

html[data-theme="dark"] .login-form-panel {
  background: var(--bg-subtle);
}

html[data-theme="dark"] .login-card {
  background: var(--card);
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}

html[data-theme="dark"] .login-card-header h2 {
  color: var(--primary);
}

/* Surfaces that were hardcoded white */
html[data-theme="dark"] .card,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .ticket-item,
html[data-theme="dark"] .ticket-msg,
html[data-theme="dark"] .month-card,
html[data-theme="dark"] .cat-col,
html[data-theme="dark"] .upload-card,
html[data-theme="dark"] .chat-card,
html[data-theme="dark"] .chat-bubble,
html[data-theme="dark"] .modal-dialog,
html[data-theme="dark"] .req-suggest,
html[data-theme="dark"] .ocr-pill,
html[data-theme="dark"] .fx-card,
html[data-theme="dark"] .fx-modal-card,
html[data-theme="dark"] .fx-portal,
html[data-theme="dark"] .al-dialog,
html[data-theme="dark"] .incident-msg,
html[data-theme="dark"] .icon-btn,
html[data-theme="dark"] .btn-mark-undo,
html[data-theme="dark"] .companies button {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}

html[data-theme="dark"] .btn-secondary {
  background: var(--bg-subtle);
  color: var(--text);
  border-color: var(--border);
}

html[data-theme="dark"] button.stat-card.is-active {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
}

html[data-theme="dark"] .ticket-msg.owner,
html[data-theme="dark"] .incident-msg.owner,
html[data-theme="dark"] .req-head,
html[data-theme="dark"] .req-suggest-foot,
html[data-theme="dark"] .activity-progress,
html[data-theme="dark"] .check-row,
html[data-theme="dark"] .portal-box,
html[data-theme="dark"] .sig-preview {
  background: var(--bg-subtle);
}

html[data-theme="dark"] .chat-row.mine .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

html[data-theme="dark"] .req-search input:focus,
html[data-theme="dark"] kbd {
  background: var(--card);
}

html[data-theme="dark"] .req-suggest-item:hover,
html[data-theme="dark"] .req-suggest-item.is-active,
html[data-theme="dark"] .req-suggest-all:hover,
html[data-theme="dark"] .req-suggest-all.is-active,
html[data-theme="dark"] .req-row:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
}

html[data-theme="dark"] .req-row.is-flash {
  animation: none;
  background: color-mix(in srgb, var(--accent) 18%, var(--card));
}

html[data-theme="dark"] .dropzone.dragover,
html[data-theme="dark"] .dropzone:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
}

html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]):not([type="color"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .req-advisor select,
html[data-theme="dark"] td select,
html[data-theme="dark"] .req-cegid-filter,
html[data-theme="dark"] .fx-btn,
html[data-theme="dark"] .al-btn,
html[data-theme="dark"] .doc-actions a,
html[data-theme="dark"] .doc-actions button,
html[data-theme="dark"] .toolbar select,
html[data-theme="dark"] .toolbar input {
  background-color: var(--input-bg);
  color: var(--text);
  border-color: var(--border);
}

html[data-theme="dark"] .fx-btn.primary,
html[data-theme="dark"] .al-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

html[data-theme="dark"] .al-btn.success {
  background: #15803d;
  color: #fff;
}

html[data-theme="dark"] .fx-address code,
html[data-theme="dark"] .fx-code {
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .fx-rules th,
html[data-theme="dark"] .fx-rules td,
html[data-theme="dark"] .fx-runs th,
html[data-theme="dark"] .fx-runs td {
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .fx-modal {
  background: var(--overlay);
}

html[data-theme="dark"] .modal-backdrop,
html[data-theme="dark"] .al-backdrop {
  background: var(--overlay);
}

html[data-theme="dark"] .profile-dropdown {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}

html[data-theme="dark"] .profile-dropdown-header strong,
html[data-theme="dark"] .profile-dropdown a,
html[data-theme="dark"] .profile-dropdown button {
  color: var(--text);
}

html[data-theme="dark"] .profile-dropdown a:hover,
html[data-theme="dark"] .profile-dropdown button:hover {
  background: var(--bg-subtle);
}

html[data-theme="dark"] .profile-dropdown a.active {
  background: color-mix(in srgb, var(--accent) 16%, var(--card));
  color: var(--accent);
}

html[data-theme="dark"] .profile-dropdown .logout-item {
  color: #fca5a5;
}

html[data-theme="dark"] .profile-dropdown .logout-item:hover {
  background: var(--danger-soft);
}

html[data-theme="dark"] .month-card.locked,
html[data-theme="dark"] .lock-banner {
  background: #2a1c10;
  border-color: #92400e;
  color: #fdba74;
}

html[data-theme="dark"] .notice {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  color: var(--text);
}

html[data-theme="dark"] .error,
html[data-theme="dark"] .error-banner,
html[data-theme="dark"] .banner.err {
  background: var(--danger-soft);
  color: #fca5a5;
}

html[data-theme="dark"] .ok,
html[data-theme="dark"] .banner.ok {
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
}

html[data-theme="dark"] .status-pending,
html[data-theme="dark"] .status-open,
html[data-theme="dark"] .badge-open,
html[data-theme="dark"] .chip-pending,
html[data-theme="dark"] .chip-review,
html[data-theme="dark"] .ocr-pill.pending,
html[data-theme="dark"] .ocr-pill.review {
  background: rgba(217, 119, 6, 0.18);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.28);
}

html[data-theme="dark"] .status-received,
html[data-theme="dark"] .status-approved,
html[data-theme="dark"] .status-resolved,
html[data-theme="dark"] .badge-on,
html[data-theme="dark"] .badge-resolved,
html[data-theme="dark"] .chip-connected,
html[data-theme="dark"] .ocr-pill.ok,
html[data-theme="dark"] .tag-mine {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.28);
}

html[data-theme="dark"] .status-reminded,
html[data-theme="dark"] .status-overdue,
html[data-theme="dark"] .ocr-pill.warn,
html[data-theme="dark"] .badge-off,
html[data-theme="dark"] .chip-disconnected,
html[data-theme="dark"] .chip-cegid-off {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border-color: rgba(252, 165, 165, 0.28);
}

html[data-theme="dark"] .status-review,
html[data-theme="dark"] .status-waiting,
html[data-theme="dark"] .badge-waiting,
html[data-theme="dark"] .tag-shared {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
}

html[data-theme="dark"] .status-sent,
html[data-theme="dark"] .status-in_progress,
html[data-theme="dark"] .badge-in_progress {
  background: rgba(168, 85, 247, 0.16);
  color: #d8b4fe;
}

html[data-theme="dark"] .status-closed,
html[data-theme="dark"] .status-draft,
html[data-theme="dark"] .badge-closed,
html[data-theme="dark"] .chip-cegid-unknown,
html[data-theme="dark"] .fx-badge.disabled {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

html[data-theme="dark"] .chip,
html[data-theme="dark"] .cat-col .file-actions .btn-danger,
html[data-theme="dark"] .doc-actions .doc-delete,
html[data-theme="dark"] .file-list button {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(252, 165, 165, 0.28);
  color: #fca5a5;
}

html[data-theme="dark"] .doc.is-review .chip {
  background: rgba(217, 119, 6, 0.16);
  border-color: rgba(251, 191, 36, 0.28);
  color: #fbbf24;
}

html[data-theme="dark"] .chip-cegid-on {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
}

html[data-theme="dark"] .fx-badge.ok { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }
html[data-theme="dark"] .fx-badge.degraded { background: rgba(217, 119, 6, 0.18); color: #fbbf24; }
html[data-theme="dark"] .fx-badge.down { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
html[data-theme="dark"] .fx-badge.needs_login { background: rgba(99, 102, 241, 0.18); color: #c7d2fe; }
html[data-theme="dark"] .fx-badge.running { background: rgba(6, 182, 212, 0.16); color: #67e8f9; }

html[data-theme="dark"] .doc.is-valid .doc-status,
html[data-theme="dark"] .doc.is-valid .dot { color: #34d399; background-color: transparent; }
html[data-theme="dark"] .doc.is-valid .dot { background: #34d399; }
html[data-theme="dark"] .doc.is-invalid .doc-status,
html[data-theme="dark"] .doc.is-invalid .doc-details { color: #fca5a5; }
html[data-theme="dark"] .doc.is-review .doc-status,
html[data-theme="dark"] .doc.is-review .doc-details,
html[data-theme="dark"] .doc.is-pending .doc-status { color: #fbbf24; }

html[data-theme="dark"] ::selection {
  background: color-mix(in srgb, var(--accent) 40%, transparent);
  color: #fff;
}

html[data-theme="dark"] .card > p:not(.error):not(.ok),
html[data-theme="dark"] .hint,
html[data-theme="dark"] .sub {
  color: var(--text-muted);
}

html[data-theme="dark"] .card h1,
html[data-theme="dark"] .card h2,
html[data-theme="dark"] .card h3 {
  color: var(--primary);
}

html[data-theme="dark"] option {
  background: var(--card);
  color: var(--text);
}

html[data-theme="dark"] .fx-lead,
html[data-theme="dark"] .fx-note,
html[data-theme="dark"] .fx-meta,
html[data-theme="dark"] .fx-empty,
html[data-theme="dark"] .fx-steps,
html[data-theme="dark"] .al-url,
html[data-theme="dark"] .al-hint,
html[data-theme="dark"] .al-status {
  color: var(--text-muted);
}

html[data-theme="dark"] .fx-card h3,
html[data-theme="dark"] .al-head h3 {
  color: var(--primary);
}
