/* ===================================================================
 * dark.css — الوضع الداكن (Research HR System)
 * ===================================================================
 * Loaded LAST on admin.html, employee.html, index.html and profile.html, after every other
 * stylesheet, so its overrides win without touching the module files that other
 * people own. js/theme.js (+ the inline <head> snippet) sets <html data-theme>.
 *
 * Rules of this file
 * - Every dark rule is scoped to html[data-theme="dark"] and wrapped in
 *   @media screen: paper is always white, so printing (payslip, reports, the
 *   employee file) never inherits a dark ground. The @media print block at the
 *   end also puts the shared tokens back to their light values for print.
 * - Grounds: page #0A1330 → surface #0D1940 (navy) → #12204F → #1A2B63.
 *   Text #EAF0FA (15.6:1 on the surface), muted #A9B6D3 (8.6:1).
 * - Blue as TEXT uses --accent-text #8DB9EA (8.0:1); --accent #2F6FBF stays the
 *   fill for buttons (white on it 5.1:1) and is fine for icons (3.4:1 ≥ 3:1).
 * - Orange: the brand orange #F58220 is readable as text on navy (6.6:1).
 * - Status text on dark: good #4ADE80, bad #FCA5A5, warn #FBBF24/#F58220, info #93C5FD.
 * - Inline styles written by JS templates can only be reached with attribute
 *   selectors + !important; those blocks are marked «inline».
 * =================================================================== */

/* ─────────────────────────────────────────────────────────────────
   1. Tokens
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] {
  color-scheme: dark;
  --accent-text: #8DB9EA;
  --text: #EAF0FA;              /* used with light fallbacks by dialogs/task modules */
  --text-primary: #EAF0FA;
  --surface-1: #0D1940;
  --bg-card: #12204F;
  --bg-body: #0A1330;
  --white: #FFFFFF;
  --glass-border: rgba(234, 240, 250, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --dk-good: #4ADE80;           /* 9.6:1 on the surface */
  --dk-bad: #FCA5A5;            /* 8.6:1 */
  --dk-warn: #FBBF24;           /* 10.1:1 */
  --dk-info: #93C5FD;           /* 8.9:1 */
  --dk-good-bg: rgba(74, 222, 128, 0.14);
  --dk-bad-bg: rgba(248, 113, 113, 0.15);
  --dk-warn-bg: rgba(251, 191, 36, 0.14);
  --dk-info-bg: rgba(147, 197, 253, 0.14);
}

/* ─────────────────────────────────────────────────────────────────
   2. Theme switch (both themes — the control itself)
   ───────────────────────────────────────────────────────────────── */
.theme-switch {
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 0.55rem 0.5rem 0.6rem;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  margin: 0.25rem 0;
}
.theme-switch__label {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: max(12px, 0.8rem); font-weight: 700; color: var(--text-muted);
  padding-inline: 0.5rem;
}
.theme-switch__options {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px;
  background: var(--surface-3); border-radius: 10px; padding: 3px;
}
.theme-switch [data-theme-value] {
  min-height: 44px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  color: var(--text-muted); font: inherit; font-size: 12px; font-weight: 700; line-height: 1.2;
  padding: 0.3rem 0.2rem; text-align: center;
  transition: background-color .15s ease, color .15s ease;
}
.theme-switch [data-theme-value] i { font-size: 0.95rem; width: auto; }
.theme-switch [data-theme-value]:hover { color: var(--text-main); }
.theme-switch [data-theme-value][aria-checked="true"] {
  background: var(--surface); color: var(--text-main);
  box-shadow: 0 1px 3px rgba(13, 25, 64, 0.18);
}
.theme-switch [data-theme-value][aria-checked="true"] i { color: var(--accent); }
.theme-switch [data-theme-value]:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
/* the employee «حسابي» card: wider buttons, no menu dividers */
.theme-switch--wide { border: 0; padding: 0; margin: 0; }
.theme-switch--wide [data-theme-value] { flex-direction: row; gap: 0.4rem; font-size: 0.85rem; }
.theme-card__hint { font-size: max(12px, 0.8rem); color: var(--text-muted); margin: 0 0 0.75rem; }
/* the admin dropdown is 200px wide — give the three options room */
.topbar .header-dropdown:has(.theme-switch) { width: 240px; }
@media (prefers-reduced-motion: reduce) {
  .theme-switch [data-theme-value] { transition: none; }
}

@media screen {
html[data-theme="dark"] .theme-switch [data-theme-value][aria-checked="true"] {
  background: var(--surface-2); box-shadow: 0 0 0 1px rgba(141, 185, 234, 0.35);
}
html[data-theme="dark"] .theme-switch [data-theme-value][aria-checked="true"] i { color: var(--accent-text); }

/* ─────────────────────────────────────────────────────────────────
   3. Page grounds & app chrome
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"],
html[data-theme="dark"] body { background-color: var(--bg-color); color: var(--text-main); }
html[data-theme="dark"] ::selection { background: rgba(91, 155, 224, 0.45); color: #FFFFFF; }

/* scrollbars */
html[data-theme="dark"] { scrollbar-color: #2A3B74 transparent; }   /* inherited by every scroller */
html[data-theme="dark"] ::-webkit-scrollbar-track { background: transparent; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background-color: #2A3B74; border-radius: 8px; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background-color: #3A4E8C; }

/* the navy sidebar sits on a navy ground: a hairline keeps the edge visible */
html[data-theme="dark"] .sidebar { border-inline-start: 1px solid var(--border); }
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .emp-header { background-color: var(--surface); border-bottom-color: var(--border); box-shadow: none; }
/* the "|" between date and time is drawn in --border (a 14% white hairline) */
html[data-theme="dark"] .topbar-center span[style*="var(--border)"],
html[data-theme="dark"] .emp-header span[style*="var(--border)"] { color: var(--text-muted) !important; opacity: .6; }
html[data-theme="dark"] .header-action-btn { color: var(--text-muted); }
html[data-theme="dark"] .header-action-btn:hover { color: var(--text-main); background: var(--surface-2); }
html[data-theme="dark"] .header-profile-btn { border-color: var(--border); background: var(--surface-2); }
html[data-theme="dark"] .sidebar-overlay { background: rgba(0, 0, 0, 0.6); }

/* focus rings: many components draw them in --accent (3.4:1 on navy); the lighter blue is 5.9:1.
   The hero keeps its own white ring. */
html[data-theme="dark"] :focus-visible:not(.home-hero *) { outline-color: #5B9BE0 !important; }

/* white logo on dark grounds (the navy one disappears on navy) */
html[data-theme="dark"] img[src*="research-logo-navy"] { content: url("../brand/research-logo-white.svg"); }
html[data-theme="dark"] img[src*="research-symbol.svg"] { content: url("../brand/research-symbol-white.svg"); }

/* ─────────────────────────────────────────────────────────────────
   4. Text colours that assumed a white ground
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .text-accent { color: var(--accent-text); }
html[data-theme="dark"] .page-title { color: var(--text-main); }
html[data-theme="dark"] a:not([class]) { color: var(--accent-text); }
html[data-theme="dark"] .dash-kpi-go,
html[data-theme="dark"] .re-subtab.active,
html[data-theme="dark"] .req-switch-btn.active,
html[data-theme="dark"] .re-emp-name-link:hover,
html[data-theme="dark"] .oaf-forcepw-logout,
html[data-theme="dark"] .ts-filter-chip:hover,
html[data-theme="dark"] .modal-close:hover,
html[data-theme="dark"] .bottom-nav-simple .nav-item.active,
html[data-theme="dark"] .bottom-nav-simple .nav-item.active i,
html[data-theme="dark"] .bottom-nav-simple .nav-item:hover,
html[data-theme="dark"] .bottom-nav .nav-item.active { color: var(--accent-text); }
html[data-theme="dark"] .re-subtab.active { border-bottom-color: var(--accent-text); }
html[data-theme="dark"] .ts-subtab-pill { color: var(--text-muted); }
html[data-theme="dark"] .ts-subtab-pill.active { color: #FFFFFF; }

/* ─────────────────────────────────────────────────────────────────
   5. Cards, panels, empty states, skeletons
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .card { background-color: var(--surface); border-color: var(--border); }
html[data-theme="dark"] .card:hover { box-shadow: var(--shadow-md); }
html[data-theme="dark"] .shadow-hover:hover { box-shadow: 0 10px 20px rgba(0, 0, 0, 0.45); }
html[data-theme="dark"] .re-empty, html[data-theme="dark"] .dash-empty { color: var(--text-muted); }

/* ─────────────────────────────────────────────────────────────────
   6. Forms
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not(.lp-input),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background-color: var(--surface-2);
  color: var(--text-main);
  border-color: rgba(234, 240, 250, 0.22);   /* 3.1:1 against the surface — visible field edge */
}
html[data-theme="dark"] select option, html[data-theme="dark"] select optgroup { background-color: #12204F; color: var(--text-main); }
html[data-theme="dark"] ::placeholder { color: #8A97B5; opacity: 1; }   /* 5.0:1 on the field */
html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] input:focus, html[data-theme="dark"] select:focus, html[data-theme="dark"] textarea:focus {
  border-color: #5B9BE0; box-shadow: 0 0 0 3px rgba(91, 155, 224, 0.28);
}
html[data-theme="dark"] .form-control:disabled, html[data-theme="dark"] input:disabled,
html[data-theme="dark"] select:disabled, html[data-theme="dark"] textarea:disabled,
html[data-theme="dark"] .form-control[readonly] {
  background-color: #0B1536; color: #A9B6D3; border-style: dashed; opacity: 1;
}
/* Chrome autofill paints a pale yellow box with dark text */
html[data-theme="dark"] input:-webkit-autofill,
html[data-theme="dark"] input:-webkit-autofill:hover,
html[data-theme="dark"] input:-webkit-autofill:focus,
html[data-theme="dark"] textarea:-webkit-autofill,
html[data-theme="dark"] select:-webkit-autofill {
  -webkit-text-fill-color: var(--text-main);
  -webkit-box-shadow: 0 0 0 1000px #12204F inset;
  caret-color: var(--text-main);
}
html[data-theme="dark"] .custom-select-arrow,
html[data-theme="dark"] select.form-control {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A9B6D3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  /* سهم واحد لكل select (من غير الخصائص دي كان بيتكرر شريط أسهم فوق السهم الأصلي) */
  -webkit-appearance: none;
  appearance: none;
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  background-size: 16px;
  padding-inline-end: 2.25rem;
}
html[data-theme="dark"] input[type="checkbox"], html[data-theme="dark"] input[type="radio"] { accent-color: #5B9BE0; }
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator { filter: invert(0.8); }
html[data-theme="dark"] label, html[data-theme="dark"] .form-label { color: inherit; }

/* ─────────────────────────────────────────────────────────────────
   7. Tables (zebra, hover, sticky headers, totals)
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .table th,
html[data-theme="dark"] .table thead th { background-color: var(--surface-2); color: var(--text-muted); border-bottom-color: var(--border); }
html[data-theme="dark"] .table td { border-bottom-color: var(--border); }
html[data-theme="dark"] .table tbody tr:hover { background-color: var(--ui-row-hover); }
html[data-theme="dark"] .table tr.re-total-row td,
html[data-theme="dark"] .table tr.re-total-row:hover td { background: #1A2B63; color: #FFFFFF; }

/* ─────────────────────────────────────────────────────────────────
   8. Menus: profile dropdown, notifications, command palette, toasts
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .header-dropdown,
html[data-theme="dark"] .notif-dropdown {
  background: var(--surface-2); border-color: rgba(234, 240, 250, 0.16);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}
html[data-theme="dark"] .header-dropdown .border-bottom { border-bottom-color: var(--border) !important; }
html[data-theme="dark"] .dropdown-item { color: var(--text-main); }
html[data-theme="dark"] .dropdown-item:hover { background: var(--surface-3); color: var(--text-main); }
/* logout items carry an inline #B91C1C (2.4:1 on navy) */
html[data-theme="dark"] .dropdown-item.text-error,
html[data-theme="dark"] .header-dropdown .dropdown-item--logout { color: var(--dk-bad) !important; }
html[data-theme="dark"] .dropdown-item.text-error:hover { background: var(--dk-bad-bg); }
html[data-theme="dark"] .theme-switch__options { background: rgba(0, 0, 0, 0.25); }
html[data-theme="dark"] .notif-header { color: var(--text-main); border-bottom-color: var(--border); }
html[data-theme="dark"] .notif-item { border-bottom-color: var(--border); color: var(--text-main); }
html[data-theme="dark"] .notif-item:hover { background: var(--surface-3); }
html[data-theme="dark"] .notif-item.unread { background: rgba(91, 155, 224, 0.10); }
html[data-theme="dark"] .notif-mark-all { color: var(--accent-text); }
html[data-theme="dark"] .notif-badge:not(:empty) { border-color: var(--surface); }

/* toasts (style.css .toast*) */
html[data-theme="dark"] .toast { box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5); }

/* ─────────────────────────────────────────────────────────────────
   9. Alerts, badges, status chips
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .alert-error { background-color: var(--dk-bad-bg); color: var(--dk-bad); border-color: rgba(252, 165, 165, 0.35); }
html[data-theme="dark"] .alert-success { background-color: var(--dk-good-bg); color: var(--dk-good); border-color: rgba(74, 222, 128, 0.35); }
html[data-theme="dark"] .alert-warning { background-color: var(--dk-warn-bg); color: var(--dk-warn); border-color: rgba(251, 191, 36, 0.35); }
html[data-theme="dark"] .alert-info { background-color: var(--dk-info-bg); color: var(--dk-info); border-color: rgba(147, 197, 253, 0.35); }
html[data-theme="dark"] .badge-active { background-color: var(--dk-good-bg); color: var(--dk-good); border-color: rgba(74, 222, 128, 0.35); }
html[data-theme="dark"] .badge-expired { background-color: var(--surface-3); color: var(--text-muted); border-color: var(--border); }
html[data-theme="dark"] .badge.re-status.att-badge-info { background: var(--dk-info-bg); color: var(--dk-info); }
/* avatar initials circle: white on the light-blue --primary was 2.0:1 */
html[data-theme="dark"] .avatar,
html[data-theme="dark"] .avatar[style*="var(--primary)"] { background: var(--accent) !important; color: #FFFFFF; }
/* nav badge (corrections etc.) used --ui-bad as a fill — keep a dark red fill behind white */
html[data-theme="dark"] .nav-item .badge,
html[data-theme="dark"] .corr-nav-badge { background: #B91C1C !important; color: #FFFFFF !important; }

/* Approve buttons: white on the bright dark-theme green was 1.7:1 */
html[data-theme="dark"] .re-btn-approve { background: #15803D !important; border-color: #15803D !important; color: #FFFFFF !important; }   /* 5.0:1 */
html[data-theme="dark"] .re-btn-approve:hover { background: #166534 !important; }
html[data-theme="dark"] .btn.re-btn-danger-solid { background: #B91C1C; border-color: #B91C1C; color: #FFFFFF; }
html[data-theme="dark"] .btn-danger-soft { background: var(--dk-bad-bg) !important; color: var(--dk-bad) !important; border-color: rgba(252, 165, 165, 0.35) !important; }
html[data-theme="dark"] .btn-danger-soft:hover { background: rgba(248, 113, 113, 0.25) !important; }
html[data-theme="dark"] .btn-outline { color: var(--text-main); border-color: rgba(234, 240, 250, 0.28); }
html[data-theme="dark"] .btn-outline:hover { background: var(--surface-3); color: var(--text-main); }

/* ─────────────────────────────────────────────────────────────────
   10. Modals & dialogs (style.css .modal, css/dialogs.css .oaf-dlg-*)
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .modal-overlay { background-color: rgba(0, 0, 0, 0.65); }
html[data-theme="dark"] .modal { background-color: var(--surface); color: var(--text-main); border: 1px solid rgba(234, 240, 250, 0.12); }
html[data-theme="dark"] .modal-header, html[data-theme="dark"] .modal-footer { border-color: var(--border); }
/* admin.html: the reject-request footer carries an inline #fafafa */
html[data-theme="dark"] .modal-footer[style*="background" i] { background: var(--surface-2) !important; }
html[data-theme="dark"] .modal-close { color: var(--text-muted); }
html[data-theme="dark"] .oaf-dlg-ok { background: var(--accent); color: #FFFFFF; }
html[data-theme="dark"] .oaf-dlg-ok.oaf-dlg-danger { background: #B91C1C; }
html[data-theme="dark"] .oaf-dlg-cancel { color: var(--text-main); }
html[data-theme="dark"] .oaf-dlg-cancel:hover { background: var(--surface-3); }

/* ─────────────────────────────────────────────────────────────────
   11. Inline colours written by HTML / JS templates (attribute selectors)
   Dark text colours become their light counterparts; pale tints become dark tints.
   :not([style*="background-color"]) leaves text that sits on its own solid fill alone.
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] :is([style*="color:#b91c1c" i], [style*="color: #b91c1c" i], [style*="color:#991b1b" i], [style*="color:#7f1d1d" i], [style*="color:#dc2626" i]):not([style*="background-color" i]) { color: var(--dk-bad) !important; }
html[data-theme="dark"] :is([style*="color:#047857" i], [style*="color: #047857" i], [style*="color:#15803d" i], [style*="color: #15803d" i], [style*="color:#166534" i], [style*="color:#065f46" i]):not([style*="background-color" i]) { color: var(--dk-good) !important; }
html[data-theme="dark"] :is([style*="color:#b45309" i], [style*="color: #b45309" i], [style*="color:#92400e" i], [style*="color:#78350f" i], [style*="color:#9a3412" i], [style*="color:#7c2d12" i], [style*="color:#c2410c" i], [style*="color: var(--orange-text" i], [style*="color:var(--orange-text" i]):not([style*="background-color" i]) { color: var(--dk-warn) !important; }
html[data-theme="dark"] :is([style*="color:#1d4ed8" i], [style*="color:#0369a1" i], [style*="color:#1e40af" i], [style*="color:#084887" i], [style*="color: #084887" i]):not([style*="background-color" i]) { color: var(--dk-info) !important; }
html[data-theme="dark"] :is([style*="color:#0d1940" i], [style*="color: #0d1940" i], [style*="color:#1f2937" i], [style*="color:#111827" i], [style*="color:#1e293b" i], [style*="color:var(--brand)" i], [style*="color: var(--brand)" i], [style*="color:var(--brand," i], [style*="color: var(--brand," i], [style*="color:var(--primary, #0d1940" i]):not([style*="background-color" i]) { color: var(--text-main) !important; }
html[data-theme="dark"] :is([style*="color:#475569" i], [style*="color:#64748b" i], [style*="color: #64748b" i], [style*="color:#6b7280" i], [style*="color: #6b7280" i], [style*="color:#4b5563" i]):not([style*="background-color" i]) { color: var(--text-muted) !important; }
html[data-theme="dark"] :is([style*="color: var(--accent)" i], [style*="color:var(--accent)" i], [style*="color:var(--accent," i], [style*="color: var(--accent," i]):not([style*="background-color" i]) { color: var(--accent-text) !important; }
html[data-theme="dark"] [style*="color: var(--border)" i]:not([style*="background-color" i]) { color: var(--text-muted) !important; }
/* white / near-white grounds first, so the tint rules below win for #fff7ed, #fffbeb … */
html[data-theme="dark"] :is([style*="background: var(--white)" i], [style*="background:var(--white)" i], [style*="background:#fff" i], [style*="background: #fff" i], [style*="background: white" i], [style*="background:white" i], [style*="background:#f8fafc" i], [style*="background: #f8fafc" i], [style*="background-color:#fff" i], [style*="background-color: #fff" i]) { background: var(--surface-2) !important; }
html[data-theme="dark"] :is([style*="background:#fef2f2" i], [style*="background: #fef2f2" i], [style*="background:#fee2e2" i]) { background: var(--dk-bad-bg) !important; color: var(--dk-bad) !important; }
html[data-theme="dark"] :is([style*="background:#fffbeb" i], [style*="background:#fff7ed" i], [style*="background:#fef3c7" i], [style*="background:#fed7aa" i], [style*="background:#fde68a" i]) { background: var(--dk-warn-bg) !important; color: var(--dk-warn) !important; }
html[data-theme="dark"] :is([style*="background:#ecfdf5" i], [style*="background:#f0fdf4" i], [style*="background:#dcfce7" i], [style*="background:#d1fae5" i]) { background: var(--dk-good-bg) !important; color: var(--dk-good) !important; }
html[data-theme="dark"] :is([style*="background:#eff6ff" i], [style*="background:#dbeafe" i], [style*="background:#f5f9ff" i]) { background: var(--dk-info-bg) !important; color: var(--dk-info) !important; }
html[data-theme="dark"] :is([style*="background: rgba(8, 72, 135, 0.05)" i], [style*="background: rgba(8, 72, 135,0.1)" i], [style*="background: rgba(13, 25, 64,0.1)" i]) { background: rgba(91, 155, 224, 0.10) !important; }

/* ─────────────────────────────────────────────────────────────────
   12. Employee portal
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .emp-layout { background-color: var(--bg-color); }
html[data-theme="dark"] .bottom-nav-simple,
html[data-theme="dark"] .bottom-nav { background: var(--surface); border-top-color: var(--border); box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45); }
/* home hero: navy → blue on a navy ground needs a hairline to keep its shape */
html[data-theme="dark"] .home-hero { background: linear-gradient(135deg, #12204F 0%, #084887 100%); box-shadow: inset 0 0 0 1px rgba(234, 240, 250, 0.08); }
html[data-theme="dark"] .home-stat-card { background: var(--surface); border-color: var(--border); }
html[data-theme="dark"] .home-grid-item { background: var(--surface); border-color: var(--border); color: var(--text-main); }
html[data-theme="dark"] .home-grid-item:hover { background: var(--surface-2); }
html[data-theme="dark"] .info-list, html[data-theme="dark"] .info-item { background-color: var(--surface); border-color: var(--border); }
html[data-theme="dark"] .profile-avatar { border-color: var(--surface-3); }
html[data-theme="dark"] .rule-penalty-table td.rule-penalty-severe { color: var(--dk-bad); }
html[data-theme="dark"] .req-switch-btn.active { background: var(--surface-3); }
html[data-theme="dark"] .leave-emp-link { color: var(--accent-text); }
/* «شغل النهاردة» card (inline <style> at the end of employee.html: var(--white) ground, --primary text) */
html[data-theme="dark"] .today-work-card { background: var(--surface); border-color: var(--border); box-shadow: none; }
html[data-theme="dark"] :is(.today-work-head, .today-work-item .tw-task) { color: var(--text-main); }
html[data-theme="dark"] .today-work-head .tw-count { background: rgba(91, 155, 224, 0.16); color: var(--accent-text); }
html[data-theme="dark"] .today-work-item .tw-dir { background: rgba(234, 240, 250, 0.08); color: var(--text-main); }
html[data-theme="dark"] .today-work-item .tw-due { color: var(--dk-warn); }
html[data-theme="dark"] .tw-open-btn { background: var(--accent); color: #FFFFFF; }   /* 5.1:1 */
html[data-theme="dark"] .ts-emp-group-title { color: var(--text-main); }
/* TMC series colour (#8b5cf6, 3.7:1 on navy) written inline by js/task-stats.js */
html[data-theme="dark"] [style*="color:#8b5cf6" i]:not([style*="background-color" i]) { color: #C4B5FD !important; }
html[data-theme="dark"] .tab-back-btn { color: var(--accent-text); }

/* ─────────────────────────────────────────────────────────────────
   13. Task distribution / task summary (css/task-summary.css, polish.css)
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] :is(.ts-idle-panel, .ts-dist-card, .ts-overlay-box, .ts-upload-card, .ts-section, .ts-pill,
  .ts-chart-wrap, .ts-history-card, .ts-project-card, .ts-perm-user, .ts-workspace-header, .ts-grid-wrap,
  .ts-row-menu, .oaf-redist-chart-card, .oaf-redist-popup-panel, .ts-parse-result .chip, .ts-sheet-card-icon,
  tr.ts-row-insert-bar .ts-row-insert-btn, th.ts-col-insert-th .ts-col-insert-btn) {
  background: var(--surface); border-color: var(--border); color: var(--text-main);
}
html[data-theme="dark"] .ts-grid td:last-child { background: var(--surface); }
html[data-theme="dark"] .ts-stat-box { background: var(--surface-2); border-color: var(--border); }
html[data-theme="dark"] .ts-history-card:hover, html[data-theme="dark"] .ts-row-menu-item:hover,
html[data-theme="dark"] .row-menu-btn:hover, html[data-theme="dark"] .ts-perm-user-head .reset-perms:hover { background: var(--surface-3); color: var(--text-main); }
html[data-theme="dark"] .ts-project-card.active { background: linear-gradient(135deg, #12204F, #1E2A4F); border-color: var(--brand-orange); }
html[data-theme="dark"] :is(.ts-idle-head h4, .ts-section-title, .ts-card-title, .ts-files-msg, .ts-card-hist-title, .ts-hist-file,
  .ts-spinner-logo, .ts-overlay-title, .ts-review-task-name, .ts-legend-note strong, .ts-due-badge, .ts-upload-title,
  .ts-parse-result, .ts-section-header h3, .ts-meta-badge, .ts-pill, .ts-history-name, .ts-emp-row .nm,
  .ts-projects-header h4, .ts-project-card .pname, .ts-project-card .pmeta span, .ts-perm-user-head .nm,
  .ts-perm-user-head .role-badge.employee, .ts-row-menu-item, .mv-wholetask-txt strong, .oaf-redist-chart-head h4,
  .oaf-redist-center-num, .oaf-redist-legend-item .lbl, .ts-assign-badge, .ts-emp-proj-row .name, .ts-dist-tag,
  #adminDistAddRowBtn, #adminDistAddColBtn, .subm-badge--atc, .ts-grid td .now-btn) { color: var(--text-main) !important; }
html[data-theme="dark"] :is(.ts-files-path, .ts-hist-item, .row-menu-btn, .pl-icon-btn, .ts-emp-row .v, .ts-perm-user-head .email) { color: var(--text-muted); }
html[data-theme="dark"] :is(.ts-card-status-pill--working, .ts-card-due--overdue, .ts-due-badge.overdue, .ts-project-card .pmeta .unassigned,
  .tc-error) { color: var(--dk-bad) !important; }
html[data-theme="dark"] :is(.ts-parse-result.is-error, .tc-task-note) { color: var(--dk-bad); }
html[data-theme="dark"] :is(.oaf-assign--has, .oaf-assign-extra, .ts-review-warn-list) { color: var(--dk-warn); }
html[data-theme="dark"] .ts-dist-tag, html[data-theme="dark"] .ts-files-location, html[data-theme="dark"] .ts-card-hist { background: rgba(0, 0, 0, 0.22); }
html[data-theme="dark"] .ts-dist-card--working { background: linear-gradient(145deg, #2A1A2E 0%, #1F1630 100%); }
html[data-theme="dark"] .ts-dist-card--paused  { background: linear-gradient(145deg, #12264F 0%, #10224A 100%); }
html[data-theme="dark"] .ts-dist-card--pending { background: linear-gradient(145deg, #2A2532 0%, #22203A 100%); }
html[data-theme="dark"] .ts-dist-card--done    { background: linear-gradient(145deg, #0F2E3A 0%, #0E2A3A 100%); }
html[data-theme="dark"] .ts-sheet-card { background: linear-gradient(135deg, #0F2E3A 0%, #0E2A3A 100%); border-color: rgba(74, 222, 128, 0.25); }
html[data-theme="dark"] .ts-sheet-card-title, html[data-theme="dark"] .ts-idle-name { color: var(--dk-good); }
html[data-theme="dark"] .ts-idle-item { background: var(--dk-good-bg); }
html[data-theme="dark"] .ts-locked-banner { background: var(--dk-warn-bg); color: var(--dk-warn); border-color: rgba(251, 191, 36, 0.35); }
html[data-theme="dark"] #tsBulkBar { background: linear-gradient(90deg, #2A2236, var(--surface)); }
html[data-theme="dark"] .oaf-redist-tab.active { background: var(--surface); color: var(--text-main); border-bottom-color: var(--surface); }
html[data-theme="dark"] .ts-perm-chk { background: var(--surface-2); color: var(--text-main); border-color: var(--border); }
html[data-theme="dark"] .ts-perm-chk:hover { background: var(--surface-3); }
html[data-theme="dark"] .ts-perm-chk small, html[data-theme="dark"] .ts-perm-note { color: var(--text-muted); }
html[data-theme="dark"] .ts-perm-user-head .role-badge.hr { background: var(--dk-warn-bg); color: var(--dk-warn); }
html[data-theme="dark"] .ts-grid tbody tr { border-bottom-color: var(--border); }
html[data-theme="dark"] .ts-grid td { border-left-color: var(--border); }
html[data-theme="dark"] .ts-grid td .cell-input:focus, html[data-theme="dark"] .ts-grid td .cell-select:focus { background: var(--surface-3); }
html[data-theme="dark"] .ts-grid td .now-btn { background: var(--surface-3); }
html[data-theme="dark"] .ts-grid .row-action-btn:hover { background: var(--dk-bad-bg); }
html[data-theme="dark"] .ts-grid thead th { background: #12204F !important; color: #FFFFFF !important; }
/* status selects inside the grid (polish.css / task-summary.css use !important) */
html[data-theme="dark"] .ts-grid td .cell-select.status-working,
html[data-theme="dark"] .ts-grid tbody tr.row-working td .cell-select.status-working { background: var(--dk-bad-bg) !important; color: var(--dk-bad) !important; border-color: rgba(252, 165, 165, 0.4) !important; }
html[data-theme="dark"] .ts-grid td .cell-select.status-pending,
html[data-theme="dark"] .ts-grid tbody tr.row-pending td .cell-select.status-pending,
html[data-theme="dark"] .ts-grid td .cell-select.status-active { background: var(--dk-warn-bg) !important; color: var(--dk-warn) !important; border-color: rgba(251, 191, 36, 0.4) !important; }
html[data-theme="dark"] .ts-grid td .cell-select.status-done,
html[data-theme="dark"] .ts-grid tbody tr.row-done td .cell-select.status-done { background: var(--dk-good-bg) !important; color: var(--dk-good) !important; border-color: rgba(74, 222, 128, 0.4) !important; }
html[data-theme="dark"] .ts-grid tbody tr.row-paused td .cell-select.status-paused { background: var(--dk-info-bg) !important; color: var(--dk-info) !important; border-color: rgba(147, 197, 253, 0.4) !important; }
html[data-theme="dark"] .submit-flag { color: var(--dk-info); background: var(--dk-info-bg); }
/* task-completion.css declares its tokens as var(--x, fallback) of themselves (a cycle the browser
   resolves to the light fallbacks), so it gets concrete dark values here */
html[data-theme="dark"] .tc-root {
  --brand: #0D1940; --accent: #2F6FBF; --surface: #0D1940; --surface-2: #12204F;
  --text: #EAF0FA; --text-muted: #A9B6D3; --border: rgba(234, 240, 250, 0.14);
}

/* ─────────────────────────────────────────────────────────────────
   14. Modules styled through their own classes
   ───────────────────────────────────────────────────────────────── */
/* competitions */
html[data-theme="dark"] .comp-title { color: var(--text-main); }
html[data-theme="dark"] .comp-btn--warning { background: var(--dk-warn-bg); color: var(--dk-warn); border-color: rgba(251, 191, 36, 0.4); }
html[data-theme="dark"] .comp-btn--warning:hover:not(:disabled) { background: rgba(251, 191, 36, 0.24); }
html[data-theme="dark"] .comp-btn--danger { background: var(--dk-bad-bg); color: var(--dk-bad); border-color: rgba(252, 165, 165, 0.4); }
html[data-theme="dark"] .comp-btn--danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.25); }

/* awards */
html[data-theme="dark"] .awards-rank-badge.rank-2 { color: #0D1940; }
html[data-theme="dark"] .podium-slot:nth-child(1) .podium-platform { background: linear-gradient(180deg, #5E6E8C 0%, #3E4C6C 100%); }

/* mood pulse (moodpulse.css uses var(--text, #1a202c) in places) */
html[data-theme="dark"] :is(.mp-chart-title, .mp-comment-text, .mp-title, .mp-question) { color: var(--text-main); }
html[data-theme="dark"] .mp-icon i { color: var(--dk-bad); }

/* payslip — screen only (print keeps payslip.css' own light layout) */
html[data-theme="dark"] .ps-group-earn, html[data-theme="dark"] .ps-item-earn, html[data-theme="dark"] .ps-subtotal-earn { color: #6EE7B7; }
html[data-theme="dark"] .ps-group-deduct, html[data-theme="dark"] .ps-item-deduct, html[data-theme="dark"] .ps-subtotal-deduct,
html[data-theme="dark"] .ps-legend-note { color: var(--dk-bad); }

/* leave / calendar / advances / corrections: their own [data-theme] rules exist; gaps only */
html[data-theme="dark"] .leave-card__over, html[data-theme="dark"] .la-remaining.la-over { color: var(--dk-bad); }
html[data-theme="dark"] .cal-state--error { color: var(--dk-bad); }
html[data-theme="dark"] .adv-btn-outline { color: var(--accent-text); border-color: rgba(141, 185, 234, 0.5); }
/* the count inside the selected chip: white at .8 opacity on #2F6FBF was 3.9:1 */
html[data-theme="dark"] .adv-chip.is-on .adv-chip-n { opacity: 1; }

/* login (already a navy page): the footer line was 3.2:1 */
html[data-theme="dark"] .lp-card-footer { color: #A9B6D3; }

/* employee file (profile.html / css/profile.css): links and the selected tab used --accent as text */
html[data-theme="dark"] :is(.prof-skip, .prof-hero-facts a, .prof-tab[aria-selected="true"], .prof-link, .prof-person-link,
  .prof-ltr, details.prof-details > summary, .prof-slip > summary) { color: var(--accent-text); }

/* ─────────────────────────────────────────────────────────────────
   15. Third-party widgets: Leaflet map, SheetJS preview tables, Chart.js boxes
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .leaflet-container { background: #12204F; }
html[data-theme="dark"] .leaflet-bar a,
html[data-theme="dark"] .leaflet-control-layers,
html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip { background: var(--surface-2); color: var(--text-main); border-color: var(--border); }
html[data-theme="dark"] .leaflet-bar a:hover { background: var(--surface-3); }
html[data-theme="dark"] .leaflet-control-attribution { background: rgba(13, 25, 64, 0.85) !important; color: var(--text-muted); }
html[data-theme="dark"] .leaflet-control-attribution a { color: var(--accent-text); }
/* Excel (SheetJS) import previews render into .ts-import-report / payroll result modals, which use
   the shared tokens; nothing extra needed. */

/* KMZ project map (js/kmz-map.js injects its own light <style id="kmzMapStyles">) */
html[data-theme="dark"] .kmz-modal { background: var(--surface); color: var(--text-main); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6); }
html[data-theme="dark"] .kmz-head { background: linear-gradient(135deg, #12204F, #084887); }
html[data-theme="dark"] :is(.kmz-toolbar, .kmz-rangegen, .kmz-list, .kmz-item) { border-color: var(--border); }
html[data-theme="dark"] .kmz-map { background: #12204F; }
html[data-theme="dark"] .kmz-list { background: var(--bg-color); }
html[data-theme="dark"] .kmz-item { background: var(--surface-2); }
html[data-theme="dark"] .kmz-item:hover { border-color: #5B9BE0; }
html[data-theme="dark"] :is(.kmz-item-head, .kmz-rangegen > summary, .kmz-range-lbl) { color: var(--text-main); }
html[data-theme="dark"] :is(.kmz-item-coords, .kmz-range-body, .kmz-range-status, .kmz-empty) { color: var(--text-muted); }
html[data-theme="dark"] .kmz-badge { background: var(--surface-3); color: var(--text-muted); }
html[data-theme="dark"] .kmz-badge.kmz-atc { background: var(--dk-good-bg); color: var(--dk-good); }
html[data-theme="dark"] .kmz-badge.kmz-tmc { background: rgba(167, 139, 250, 0.16); color: #C4B5FD; }   /* 9.3:1 */
html[data-theme="dark"] .kmz-badge.kmz-total { background: var(--dk-warn-bg); color: var(--dk-warn); }
html[data-theme="dark"] :is(.kmz-nature, .kmz-range-inp) { background: var(--surface-2); color: var(--text-main); border-color: rgba(234, 240, 250, 0.22); }
html[data-theme="dark"] :is(.kmz-title i, .kmz-rangegen > summary i) { color: var(--brand-orange); }
/* purple text written inline by task templates */
html[data-theme="dark"] :is([style*="color:#6d28d9" i], [style*="color:#7c3aed" i], [style*="color:#5b21b6" i]):not([style*="background-color" i]) { color: #C4B5FD !important; }

} /* end @media screen */

@media screen {
/* ─────────────────────────────────────────────────────────────────
   13b. Task modules: text colours hard-coded for a white ground (generated from
   css/task-summary.css, css/submissions.css, css/task-completion.css). The original
   grey/green/amber/blue/red text becomes the matching dark-theme tone.
   ───────────────────────────────────────────────────────────────── */
html[data-theme="dark"] :is(
  .btn-icon-soft,
  .btn-icon-soft:hover,
  .ts-idle-hint,
  .ts-idle-empty,
  .ts-grid tbody tr.row-done td .cell-input,
  .ts-section-title .ts-section-title-badge,
  .ts-card-project,
  .oaf-assign--full,
  .ts-card-due,
  .ts-files-path,
  .ts-hist-item,
  .ts-hist-ts,
  .ts-review-project,
  .ts-review-total-unit,
  .ts-review-meta,
  .ts-status-legend,
  .ts-legend-note,
  .ts-upload-hint,
  .ts-stat-box .lab,
  .ts-history-meta,
  .ts-history-total small,
  .ts-emp-row.head,
  .ts-emp-row.head .v,
  .ts-emp-row.head .nm,
  .ts-perm-user-head .reset-perms,
  .row-menu-btn,
  .mv-wholetask-txt small,
  .pl-icon-btn,
  .oaf-redist-chart-hint,
  .oaf-redist-center-lbl,
  .oaf-redist-tab
) { color: var(--text-muted) !important; }
html[data-theme="dark"] :is(
  .ts-sheet-card-title,
  .ts-sheet-card-meta,
  .ts-idle-name,
  .ts-idle-meta,
  .ts-grid tbody tr.row-done td .cell-select.status-done,
  .ts-card-status-pill--done,
  .ts-card-state-icon--done,
  .ts-card-timing.received,
  .ts-card-done-note,
  .ts-btn-receive,
  .ts-btn-resume,
  .ts-review-ok,
  .ts-project-card .pmeta .done,
  .ts-perm-chk.on,
  .ts-grid td .cell-select.status-done,
  .subm-wfh--office,
  .tc-task-complete
) { color: var(--dk-good) !important; }
html[data-theme="dark"] :is(
  .ts-locked-banner,
  .ts-grid tbody tr.row-pending td .cell-select.status-pending,
  .ts-card-status-pill--pending,
  .ts-card-state-icon--pending,
  .oaf-assign--has,
  .oaf-assign-label,
  .oaf-assign-extra,
  .ts-card-timing.submitted,
  .ts-card-pending-note,
  .ts-review-warn-title,
  .ts-review-warn-list,
  .ts-due-badge.soon,
  .ts-project-card .pmeta .pending,
  .ts-perm-user-head .role-badge.hr,
  .ts-grid td .cell-select.status-active,
  .ts-bulk-label,
  .ts-filter-chip.is-warn:not(.active),
  .ts-unlinked-chip,
  .ts-row-menu-item.is-accent,
  .ts-row-menu-item.is-warn,
  .ts-card-reopen-note,
  .pl-merge-warn,
  .oafpt-tmcday-legacy,
  .subm-wfh--pending
) { color: var(--dk-warn) !important; }
html[data-theme="dark"] :is(
  .ts-grid tbody tr.row-paused td .cell-select.status-paused,
  .ts-card-status-pill--paused,
  .ts-card-timing.paused,
  .ts-btn-pause,
  .subm-wfh--ok
) { color: var(--dk-info) !important; }
html[data-theme="dark"] :is(
  .ts-grid tbody tr.row-working td .cell-select.status-working,
  .ts-card-status-pill--working,
  .ts-card-due--overdue,
  .ts-due-badge.overdue,
  .ts-parse-result.is-error,
  .ts-project-card .pmeta .unassigned,
  .btn-danger-soft,
  .ts-overdue-chip,
  .ts-row-menu-item.is-danger,
  .ts-import-fail,
  .pl-merge-blocked,
  .pl-merge-err,
  .pl-merge-conf,
  .subm-wfh--rejected
) { color: var(--dk-bad) !important; }
} /* end @media screen */

/* ─────────────────────────────────────────────────────────────────
   16. Print: paper is white whatever the screen theme is.
   js/theme.js switches <html> to the light theme on beforeprint (and back on
   afterprint), so normally none of this applies. This block is the fallback for a
   print that starts without those events: the shared tokens and the module tokens that
   modules redefine for dark without print scoping (payslip --ps-*, employee file
   --prof-*, reports --rep-*) go back to their light values.
   ───────────────────────────────────────────────────────────────── */
@media print {
  html[data-theme="dark"] *, html[data-theme="dark"] *::before, html[data-theme="dark"] *::after { transition: none !important; }
  html[data-theme="dark"] {
    color-scheme: light;
    /* css/profile.css :root light values (attendance calendar is printed with exact colours) */
    --prof-cell: #FFFFFF; --prof-k-present: #E9F6EE; --prof-k-late: #FEF3E7; --prof-k-absent: #FDEDED;
    --prof-k-excused: #E8EEF7; --prof-k-off: #F3F5F9; --prof-k-holiday: #EEE8F7; --prof-k-holiday-fg: #5B3A8C;
    /* css/reports.css :root light values */
    --rep-series-1: #1F66AE; --rep-series-2: #D96A0B; --rep-bad: #B91C1C; --rep-bad-bg: #FEF2F2;
    --primary: #0D1940; --primary-light: #084887; --brand: #0D1940; --brand-strong: #084887;
    --accent: #084887; --accent-hover: #063A70; --accent-blue-light: #1F66AE; --accent-2: #F58220;
    --orange-text: #B45309; --orange-text-lg: #D96A0B; --on-accent: #FFFFFF; --accent-text: #084887;
    --bg-color: #FFFFFF; --surface: #FFFFFF; --surface-2: #F7F9FC; --surface-3: #EEF2F8;
    --text-main: #0D1940; --text-muted: #4A5578; --border: #DCE2EE; --focus-ring: #084887;
    --text: #1F2937; --glass-bg: rgba(255, 255, 255, 0.88);
    --shadow-sm: none; --shadow-md: none; --shadow-lg: none;
    --ui-chip-bg: #E8EEF7; --ui-chip-fg: #084887; --ui-zebra: #FAFBFD; --ui-row-hover: #F0F4FA;
    --ui-good: #15803D; --ui-good-bg: #E9F6EE; --ui-bad: #B91C1C; --ui-bad-bg: #FDEDED;
    --ui-warn: #B45309; --ui-warn-bg: #FEF3E7;
    --ui-chart-1: #0D1940; --ui-chart-2: #084887; --ui-chart-3: #5B9BE0; --ui-chart-4: #F58220;
    --ui-chart-5: #8C9AB8; --ui-chart-6: #A3B0CC; --ui-chart-good: #16A34A; --ui-chart-bad: #DC2626;
    --ui-chart-fill: rgba(8, 72, 135, 0.10);
  }
  html[data-theme="dark"], html[data-theme="dark"] body { background: #FFFFFF !important; color: #0D1940 !important; }
  /* payslip.css' own dark rules are not print-scoped: undo them on paper */
  html[data-theme="dark"] .ps-root {
    background: #FFFFFF !important; color: #0D1940 !important;
    /* css/payslip.css redefines these for [data-theme="dark"]; muted #4B5563 = 7.6:1 on white */
    --ps-surface: #FFFFFF; --ps-surface2: #F9FAFB; --ps-border: #E5E7EB; --ps-text: #1F2937; --ps-muted: #4B5563;
  }
  html[data-theme="dark"] .ps-payslip-card { background: #FFFFFF !important; color: #0D1940 !important; }
  html[data-theme="dark"] :is(.ps-legend-val, .ps-card-title, .ps-trend-latest, .ps-item-label) { color: #0D1940 !important; }
  html[data-theme="dark"] :is(.ps-group-earn, .ps-item-earn, .ps-subtotal-earn) { color: #065F46 !important; }
  html[data-theme="dark"] :is(.ps-group-deduct, .ps-item-deduct, .ps-subtotal-deduct) { color: #991B1B !important; }
}
