/* ═══════════════════════════════════════════════════════════════
   DARK MODE — pure black, OLED-friendly
   Applied when <html data-theme="dark"> is set.
   Auto mode resolves to dark when prefers-color-scheme: dark.
   ═══════════════════════════════════════════════════════════════ */

html[data-theme="dark"] {
    /* Surfaces */
    --bg-primary:       #000000;
    --bg-card:          #0a0a0a;
    --bg-card-hover:    #111111;
    --border-color:     #1f1f1f;
    --border-light:     #171717;

    /* Text */
    --text-primary:     #f4f4f5;
    --text-secondary:   #a1a1aa;
    --text-muted:       #6b7280;
    --text-inverse:     #000000;

    /* Sidebar (kept dark-blue but adjusted so it reads as "dark card" next to pure black) */
    --sidebar-bg:       #0f1117;
    --sidebar-text:     rgba(255,255,255,0.70);
    --sidebar-text-active: #ffffff;
    --sidebar-hover:    rgba(255,255,255,0.08);

    /* Status color backgrounds — denser for dark bg */
    --green-bg:         rgba(34, 197, 94, 0.16);
    --red-bg:           rgba(239, 68, 68, 0.16);
    --orange-bg:        rgba(245, 158, 11, 0.16);
    --blue-bg:          rgba(59, 130, 246, 0.16);
    --gray-bg:          rgba(148, 163, 184, 0.14);

    /* Accent on a pure-black page.
       The light-mode blue (#1554C0) is only 2.6:1 against black, so it is
       unreadable as text here. The fill is lifted just enough to separate
       from the page while still carrying white text (5.06:1), and the text
       variant goes much lighter (8.41:1). */
    --accent-orange:       #2A6BD4;
    --accent-orange-hover: #3C7DE6;
    --accent-ink:          #6AA6F7;
    --accent-orange-glow:  rgba(106, 166, 247, 0.22);

    /* Shadows — remove light shadows, use subtle elevation */
    --shadow-sm:        0 1px 2px rgba(0,0,0,0.4);
    --shadow-md:        0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg:        0 12px 32px rgba(0,0,0,0.6);
    --shadow-card:      0 0 0 1px rgba(255,255,255,0.02);
}

/* Status text colors — brightened for dark bg readability */
html[data-theme="dark"] {
    --green:  #4ade80;
    --red:    #f87171;
    --orange: #fbbf24;
    --blue:   #60a5fa;
    --gray:   #d4d4d8;
}

/* ── Component touch-ups ── */

/* Inputs, selects, textareas in dark mode */
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background: #0a0a0a !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
/* Was #52525b, which measures 2.6:1 on these near-black input backgrounds —
   below the 4.5:1 a placeholder needs to be read, so hints like
   "Reason (optional)" were all but invisible. #82828c gives 5.5:1 on #000 and
   5.2:1 on #0a0a0a while still reading as a hint rather than typed text. */
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: #82828c !important;
}

/* Modals */
html[data-theme="dark"] .modal {
    background: var(--bg-card) !important;
    color: var(--text-primary);
}
html[data-theme="dark"] .modal-overlay {
    background: rgba(0,0,0,0.8) !important;
}

/* Notification panel */
html[data-theme="dark"] .notification-panel,
html[data-theme="dark"] .notif-item {
    background: var(--bg-card) !important;
    color: var(--text-primary);
    border-color: var(--border-color) !important;
}

/* Tables */
html[data-theme="dark"] table thead th {
    background: #0a0a0a !important;
    color: var(--text-secondary) !important;
    border-color: var(--border-color) !important;
}
html[data-theme="dark"] table tbody td {
    color: var(--text-primary) !important;
    border-color: var(--border-light) !important;
}
html[data-theme="dark"] table tbody tr:hover td {
    background: #0a0a0a !important;
}

/* Button hover on dark */
html[data-theme="dark"] .btn-outline,
html[data-theme="dark"] .btn-ghost {
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* Cards and panels (common class names used across the app) */
html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .kpi-card,
html[data-theme="dark"] .stat-card {
    background: var(--bg-card) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary);
}

/* Chart.js — set grid lines to be visible on black */
html[data-theme="dark"] canvas {
    /* actual axis/grid colors need to be set in JS via Chart.defaults,
       but this keeps canvas bg transparent */
    background: transparent !important;
}

/* Anti-flash: smooth transitions on common properties */
html, body, .card, .panel, .top-bar, .sidebar,
.modal, input, select, textarea {
    transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

/* ── Theme toggle control itself ── */
.theme-toggle {
    display: inline-flex;
    align-items: stretch;
    background: rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
    border-radius: 99px;
    padding: 2px;
    gap: 1px;
    margin-right: 0.5rem;
}
html[data-theme="dark"] .theme-toggle {
    background: rgba(255,255,255,0.05);
    border-color: var(--border-color);
}
.theme-toggle-seg {
    width: 28px;
    height: 28px;
    border-radius: 99px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all .15s;
}
.theme-toggle-seg svg { width: 13px; height: 13px; }
.theme-toggle-seg:hover { color: var(--text-primary); }
.theme-toggle-seg.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
html[data-theme="dark"] .theme-toggle-seg.active {
    background: #1f1f1f;
    color: #fbbf24; /* warm highlight for active state in dark */
}