/*
 * Dark-mode overrides for hand-written CSS classes that Tailwind's `dark:`
 * modifier can't reach. Loaded last in base.html so these win the cascade.
 *
 * Scope: only declares colors/backgrounds/borders. Layout, spacing, and
 * animations stay in their original component files.
 *
 * Tailwind config has `darkMode: 'class'` — every selector here is gated
 * behind `.dark` on <html>, set by the boot-time inline script.
 *
 * On `!important`: this file loads before the per-page component CSS
 * (timetable/components.css, mobile.css) which `base.html` pulls in via the
 * `extra_css` block AFTER this one. The few `!important` rules below are NOT
 * redundant — they override later-loaded rules that win on load order or use
 * `!important` themselves (e.g. `.modern-search-input:focus` re-asserts a white
 * background; mobile.css forces `#schDays/#schTimes { background: white
 * !important }`). Removing them turns those surfaces white in dark mode. Each
 * cluster is annotated; don't strip without re-checking the overriding rule.
 */

/* ---------- Body / surface fallbacks ---------- */
.dark body {
    color: #e5e7eb;
}

/* ---------- Generic card patterns used across pages ---------- */
.dark .modern-card {
    background: rgba(31, 41, 55, 0.85);
    border: 1px solid rgba(75, 85, 99, 0.4);
    color: #e5e7eb;
}

.dark .modern-card .empty-state h3,
.dark .modern-card .empty-state h4 {
    color: #f3f4f6;
}

.dark .modern-card .empty-state p {
    color: #d1d5db;
}

.dark .glass-card {
    background: rgba(31, 41, 55, 0.7);
    border: 1px solid rgba(75, 85, 99, 0.3);
    color: #e5e7eb;
}

/* !important needed: components.css `.modern-search-input:focus` (loaded after
   this file) re-asserts a white background at equal specificity. */
.dark .modern-search-input,
.dark .modern-input,
.dark .modern-filter-select {
    background: rgba(17, 24, 39, 0.7) !important;
    color: #f3f4f6 !important;
    border-color: rgba(75, 85, 99, 0.6) !important;
}

.dark .modern-search-input::placeholder,
.dark .modern-input::placeholder {
    color: #9ca3af;
}

.dark .floating-label {
    color: #9ca3af;
}

/* ---------- Timetable grid ---------- */
.dark .day-header {
    background: rgba(31, 41, 55, 0.95);
    color: #e5e7eb;
    border-color: rgba(75, 85, 99, 0.4);
}

.dark .time-label {
    color: #9ca3af;
}

.dark .hour-line,
.dark .day-line {
    background: rgba(75, 85, 99, 0.5);
}

/* !important needed: mobile.css forces `#schTimes/#schDays { background: white
   !important }` inside its media queries, which would otherwise win. */
.dark #schTimes,
.dark #schDays {
    background: #1f2937 !important;
}

.dark #schDays {
    background: rgba(31, 41, 55, 0.95) !important;
}

/* The canvas's own border (UI-20). layout.css draws it #ddd and nothing
   answered it here, so on a dark page the grid's left and right edges were two
   near-white lines. The colour of the hour and day lines above. */
.dark #schTimes {
    border-color: rgba(75, 85, 99, 0.5);
}

/* ---------- Timetable action bar ---------- */
.dark .tb-action-btn {
    background: rgba(31, 41, 55, 0.7);
    color: #e5e7eb;
    border-color: rgba(75, 85, 99, 0.4);
}

.dark .tb-action-btn:hover {
    background: rgba(55, 65, 81, 0.9);
}

/* The Edit dialog's Delete, armed (UI-23). The colours Clear All's armed
   state has on a dark page (desktop.css). */
.dark #delete-timetable-btn.confirming,
.dark #delete-timetable-btn.confirming:hover {
    background: #450a0a;
    color: #f87171;
    box-shadow: inset 0 0 0 1px #991b1b;
}

/* ---------- Filter card / dropdown wrappers ---------- */
/* !important needed: the gradient `.modern-filter-card` background in
   components.css (loaded after this file) overrides a plain dark rule. */
.dark .modern-filter-card {
    background: rgba(31, 41, 55, 0.85) !important;
    border-color: rgba(75, 85, 99, 0.4) !important;
    color: #e5e7eb;
}

.dark .filter-label {
    color: #d1d5db;
}

/* ---------- Generic Tailwind class overrides for custom modal markup ---------- */
.dark .bg-white {
    background-color: #1f2937;
    color: #e5e7eb;
}

.dark .bg-gray-50 {
    background-color: #111827;
}

.dark .bg-gray-100 {
    background-color: #1f2937;
}

.dark .text-gray-700 { color: #d1d5db; }
.dark .text-gray-800 { color: #e5e7eb; }
.dark .text-gray-900 { color: #f3f4f6; }
.dark .text-gray-600 { color: #9ca3af; }
.dark .text-gray-500 { color: #9ca3af; }

.dark .border-gray-100,
.dark .border-gray-200,
.dark .border-gray-300 {
    border-color: rgba(75, 85, 99, 0.5);
}

/* Inputs inside modals */
.dark input[type="text"]:not(.modern-search-input):not(.modern-input),
.dark input[type="email"],
.dark input[type="search"],
.dark input[type="password"],
.dark input[type="number"],
.dark input[type="time"],
.dark textarea,
.dark select:not(.modern-filter-select) {
    background-color: rgba(17, 24, 39, 0.85);
    color: #f3f4f6;
    border-color: rgba(75, 85, 99, 0.6);
}

.dark input::placeholder,
.dark textarea::placeholder {
    color: #9ca3af;
}

/* Course-info / favorites empty states */
.dark .empty-state .text-gray-500,
.dark .empty-state .text-gray-400 {
    color: #9ca3af;
}

/* ---------- Timetable tabs strip ---------- */
.dark #draft-tabs-strip {
    border-color: rgba(75, 85, 99, 0.4);
}

/* ---------- Notification / toast container leaves itself; uses inline colors ---------- */

/* =========================================================================
   Light-only Tailwind utilities the blanket rules above don't reach.
   Templates deliberately carry almost no `dark:` variants (the navbar and
   help page are the exceptions) — THIS file is the site's dark theme, so
   every light-surface utility used in templates/JS needs a row here.
   `bg-white/5..20` are intentionally untouched: they're translucent white
   glints on colored gradients and must stay white in both themes.
   ========================================================================= */

/* ---------- White/gray surface opacity variants ---------- */
.dark .bg-white\/60 { background-color: rgba(31, 41, 55, 0.6); }
.dark .bg-white\/80 { background-color: rgba(31, 41, 55, 0.8); }
.dark .bg-white\/90 { background-color: rgba(31, 41, 55, 0.9); }
.dark .bg-gray-50\/80 { background-color: rgba(17, 24, 39, 0.8); }
.dark .bg-gray-200 { background-color: #374151; }
.dark .bg-gray-300 { background-color: #4b5563; }

/* ---------- Gradient stops (from/via/to) on light tints ----------
   Card/hero gradients built from white and *-50/-100 tints collapse to a
   subtle dark slope (#1f2937 → #111827). Saturated 400+ stops (buttons,
   colored headers) are left alone. Format mirrors the built Tailwind 4
   output: each variable holds the colour alone, and Tailwind composes the
   stop list (direction, colours, positions) from them. Tailwind 3's format,
   colour + position var and a hand-built stop list for `via`, dropped the
   direction under Tailwind 4. */
.dark .from-white,
.dark .from-white\/60,
.dark .from-gray-50,
.dark .from-primary-50,
.dark .from-secondary-50,
.dark .from-accent-50,
.dark .from-accent-100,
.dark .from-amber-50,
.dark .from-blue-50,
.dark .from-emerald-50,
.dark .from-green-50,
.dark .from-orange-50,
.dark .from-red-50 {
    --tw-gradient-from: #1f2937;
    --tw-gradient-to: rgba(31, 41, 55, 0);
}

.dark .via-white,
.dark .via-primary-50,
.dark .via-primary-50\/20,
.dark .via-primary-50\/30,
.dark .via-secondary-50,
.dark .via-accent-50\/30 {
    --tw-gradient-via: #1f2937;
}

.dark .to-white,
.dark .to-primary-50,
.dark .to-primary-50\/30,
.dark .to-primary-100\/50,
.dark .to-secondary-50,
.dark .to-secondary-50\/20,
.dark .to-secondary-50\/30,
.dark .to-secondary-100\/50,
.dark .to-accent-50,
.dark .to-accent-50\/30,
.dark .to-accent-100\/50,
.dark .to-amber-50\/30,
.dark .to-emerald-50,
.dark .to-emerald-50\/30,
.dark .to-accent-200 {
    --tw-gradient-to: #111827;
}

/* ---------- Colored tint backgrounds (pills, chips, alerts) ----------
   Light *-50/-100/-200 tints become their color's -900 shade at low alpha,
   the standard Tailwind dark-mode idiom, so the hue survives. */
.dark .bg-primary-50 { background-color: rgba(26, 76, 104, 0.3); }
.dark .bg-primary-100 { background-color: rgba(26, 76, 104, 0.4); }
.dark .bg-primary-200 { background-color: rgba(26, 76, 104, 0.5); }
.dark .bg-primary-200\/50 { background-color: rgba(26, 76, 104, 0.35); }
.dark .bg-secondary-100 { background-color: rgba(17, 65, 90, 0.4); }
.dark .bg-secondary-200 { background-color: rgba(17, 65, 90, 0.5); }
.dark .bg-secondary-200\/50 { background-color: rgba(17, 65, 90, 0.35); }
.dark .bg-accent-100 { background-color: rgba(0, 78, 92, 0.4); }
.dark .bg-accent-200 { background-color: rgba(0, 78, 92, 0.5); }
.dark .bg-accent-200\/50 { background-color: rgba(0, 78, 92, 0.35); }
.dark .bg-red-50 { background-color: rgba(127, 29, 29, 0.3); }
.dark .bg-red-100 { background-color: rgba(127, 29, 29, 0.4); }
.dark .bg-green-50 { background-color: rgba(20, 83, 45, 0.3); }
.dark .bg-green-100 { background-color: rgba(20, 83, 45, 0.4); }
.dark .bg-blue-50 { background-color: rgba(30, 58, 138, 0.3); }
.dark .bg-blue-100 { background-color: rgba(30, 58, 138, 0.4); }
.dark .bg-amber-50 { background-color: rgba(120, 53, 15, 0.3); }
.dark .bg-yellow-50 { background-color: rgba(113, 63, 18, 0.3); }
.dark .bg-yellow-100 { background-color: rgba(113, 63, 18, 0.4); }
.dark .bg-orange-50 { background-color: rgba(124, 45, 18, 0.3); }

/* ---------- Dark-on-tint text lightened for dark surfaces ---------- */
.dark .text-primary-600 { color: #5ecaff; }
.dark .text-primary-700, .dark .text-primary-800 { color: #9edcff; }
.dark .text-secondary-600 { color: #52a8d9; }
.dark .text-secondary-700 { color: #90caef; }
.dark .text-accent-600 { color: #00bddd; }
.dark .text-accent-700 { color: #43dafb; }
.dark .text-red-600 { color: #f87171; }
.dark .text-red-700, .dark .text-red-800 { color: #fca5a5; }
.dark .text-green-600 { color: #4ade80; }
.dark .text-green-700, .dark .text-green-800 { color: #86efac; }
.dark .text-blue-600 { color: #60a5fa; }
.dark .text-blue-700, .dark .text-blue-800 { color: #93c5fd; }
.dark .text-amber-800, .dark .text-amber-900 { color: #fcd34d; }
.dark .text-yellow-700 { color: #fde047; }
.dark .text-emerald-600 { color: #34d399; }

/* ---------- Light hover surfaces ---------- */
.dark .hover\:bg-gray-50:hover { background-color: rgba(55, 65, 81, 0.6); }
.dark .hover\:bg-gray-100:hover { background-color: rgba(55, 65, 81, 0.7); }
.dark .hover\:bg-gray-200:hover { background-color: rgba(75, 85, 99, 0.7); }
.dark .hover\:bg-gray-300:hover { background-color: rgba(75, 85, 99, 0.8); }
.dark .hover\:bg-primary-50:hover { background-color: rgba(26, 76, 104, 0.35); }
.dark .hover\:bg-red-50:hover { background-color: rgba(127, 29, 29, 0.35); }
.dark .hover\:bg-red-100:hover { background-color: rgba(127, 29, 29, 0.45); }

/* ---------- Colored tint borders ----------
   `border-white(/xx)` overlays are left alone — they sit on colored or
   glass surfaces where a white edge is correct in both themes. */
.dark .border-primary-50,
.dark .border-primary-100,
.dark .border-primary-100\/50,
.dark .border-primary-200,
.dark .border-primary-200\/30,
.dark .border-primary-300 { border-color: rgba(29, 93, 127, 0.6); }
.dark .border-secondary-100\/50,
.dark .border-secondary-200,
.dark .border-secondary-300 { border-color: rgba(20, 80, 112, 0.6); }
.dark .border-accent-100\/50,
.dark .border-accent-200,
.dark .border-accent-300 { border-color: rgba(0, 95, 113, 0.6); }
.dark .border-red-200 { border-color: rgba(153, 27, 27, 0.6); }
.dark .border-green-100\/50,
.dark .border-green-200 { border-color: rgba(22, 101, 52, 0.6); }
.dark .border-emerald-100\/50,
.dark .border-emerald-200,
.dark .border-emerald-300 { border-color: rgba(6, 95, 70, 0.6); }
.dark .border-blue-200 { border-color: rgba(30, 64, 175, 0.6); }
.dark .border-amber-100\/50,
.dark .border-amber-200,
.dark .border-amber-300 { border-color: rgba(146, 64, 14, 0.6); }
.dark .border-yellow-200 { border-color: rgba(133, 77, 14, 0.6); }

/* ---------- Ink and highlight (UI-02) ----------
   Only the LIGHT-surface classes of the two families get a row: a tint, its
   border, and the dark text that sits on it. Everything else is the same in
   both themes and has no row, on purpose:
     - an ink band (bg-ink-900, bg-ink-950) and the text on it
       (text-ink-100/200/300, text-white) are dark already. On a dark page a
       band is told apart by a hairline, set in the markup
       (`dark:bg-ink-950 border border-ink-900 dark:border-ink-700`): no row
       here competes with those classes, so the `dark:` variants hold;
     - a highlight fill (bg-highlight-300/400) keeps its text-ink-950.
   Tints follow the file's idiom: the family at low alpha, so the hue stays. */
.dark .bg-ink-50 { background-color: rgba(95, 141, 179, 0.18); }
.dark .bg-ink-100 { background-color: rgba(95, 141, 179, 0.26); }
.dark .border-ink-100,
.dark .border-ink-200 { border-color: rgba(143, 177, 205, 0.28); }
.dark .text-ink-600,
.dark .text-ink-700,
.dark .text-ink-800 { color: #bdd2e3; }
.dark .bg-highlight-50,
.dark .bg-highlight-100 { background-color: rgba(245, 164, 0, 0.18); }
.dark .border-highlight-100,
.dark .border-highlight-200 { border-color: rgba(255, 190, 46, 0.4); }
.dark .text-highlight-600,
.dark .text-highlight-700,
.dark .text-highlight-800 { color: #ffcf52; }

/* ---------- Timetable page components not covered above ---------- */
/* Panel and empty-state titles (components.css): plain text since UI-13, so
   they need a light colour here; as gradient text they needed none. */
.dark .gradient-text,
.dark .course-info-header {
    color: #f3f4f6;
}

.dark #timetable-bar {
    background: #1f2937;
}

.dark .search-result-item,
.dark .favorite-item {
    background: rgba(31, 41, 55, 0.9);
    border-color: rgba(75, 85, 99, 0.4);
}

.dark .search-result-item:hover,
.dark .favorite-item:hover {
    background: rgba(55, 65, 81, 0.95);
}

.dark .version-tab {
    background: #1f2937;
    color: #e5e7eb;
    border-color: rgba(75, 85, 99, 0.5);
}

.dark .version-tab .tab-context {
    background: #374151;
    color: #d1d5db;
}

/* The start card over the empty grid (Round B, components.css). */
.dark #draft-start {
    background: #1f2937;
    border-color: #374151;
}
.dark .draft-start-title {
    color: #f3f4f6;
}
.dark .draft-start-note {
    color: #9ca3af;
}
.dark .draft-start-field {
    color: #d1d5db;
}
.dark .draft-start-select {
    background: #111827;
    border-color: #374151;
    color: #e5e7eb;
}

/* !important needed: mobile.css `.timetable-section { background: white !important }`. */
.dark .timetable-section {
    background: #111827 !important;
}

.dark .overflow-y-auto::-webkit-scrollbar-track { background: #1f2937; }
.dark .overflow-y-auto::-webkit-scrollbar-thumb { background: #4b5563; }

/* ---------- Auth pages (auth-base.css components) ----------
   auth-base.css loads AFTER this file (extra_head), so ties on specificity
   lose — the :hover/:focus rows below out-specify its white re-asserts. */
.dark .auth-card {
    background: #1f2937;
    box-shadow: 0 0 0 1px rgba(75, 85, 99, 0.5), 0 20px 25px -5px rgb(0 0 0 / 0.3);
}

/* The way back (UI-10): the bar's links and the in-card Home link. */
.dark .auth-nav__brand { color: #f3f4f6; }
.dark .auth-nav__links a { color: #d1d5db; }
.dark .auth-nav__links a:hover,
.dark .auth-home:hover { color: #9edcff; }
.dark .auth-home { color: #9ca3af; }

.dark .auth-title { color: #f3f4f6; }
.dark .auth-subtitle { color: #9ca3af; }

.dark .auth-footer {
    background: rgba(17, 24, 39, 0.6);
    color: #9ca3af;
}

.dark .form-label,
.dark .checkbox-label { color: #d1d5db; }

/* Links on the dark auth card: the brand's deep blue is too dark there
   (BRAND-01), so they take the theme's primary-400, about 8:1, on every
   auth page (forgot-password lost its amber in UI-10). */
.dark .auth-footer a,
.dark .checkbox-label a,
.dark .forgot-link { color: #5ecaff; }
.dark .auth-footer a:hover,
.dark .forgot-link:hover { color: #9edcff; }

.dark .form-input {
    background: rgba(17, 24, 39, 0.85);
    color: #f3f4f6;
    border-color: rgba(75, 85, 99, 0.6);
}

.dark .form-input:hover,
.dark .form-input:focus {
    background: rgba(17, 24, 39, 0.95);
}

.dark .alert-success {
    background: rgba(6, 95, 70, 0.3);
    color: #6ee7b7;
    border-color: rgba(6, 95, 70, 0.6);
}

.dark .alert-danger {
    background: rgba(127, 29, 29, 0.3);
    color: #fca5a5;
    border-color: rgba(153, 27, 27, 0.6);
}

.dark .alert-warning {
    background: rgba(120, 53, 15, 0.3);
    color: #fcd34d;
    border-color: rgba(146, 64, 14, 0.6);
}

/* signup.css "Check your inbox" (UI-22). signup.css loads after this file,
   so each row out-specifies the rule it answers. */
.dark .signup-sent .signup-sent__title { color: #f3f4f6; }
.dark .signup-sent p { color: #9ca3af; }
.dark .signup-sent strong { color: #f3f4f6; }
.dark .signup-sent .signup-sent__resend {
    background: rgba(17, 24, 39, 0.85);
    color: #f3f4f6;
    border-color: rgba(75, 85, 99, 0.6);
}
.dark .signup-sent .signup-sent__link { color: #5ecaff; }
.dark .signup-sent .signup-sent__link:hover { color: #9edcff; }
.dark .signup-sent .signup-sent__status[data-status='success'] { color: #4ade80; }
.dark .signup-sent .signup-sent__status[data-status='danger'] { color: #fca5a5; }

/* forgot-password.css tab strip */
.dark .tab-btn.active {
    background: #1f2937;
    color: #e5e7eb;
}

/* ---------- Legal pages (legal.css) ----------
   Prose on the page itself since UI-09: no card behind it. */
.dark .legal-body {
    color: #d1d5db;
}

.dark .legal-section {
    border-top-color: rgba(75, 85, 99, 0.5);
}

.dark .legal-section h2,
.dark .legal-section h3,
.dark .legal-section li strong { color: #f3f4f6; }

.dark .legal-section p,
.dark .legal-section li,
.dark .contact-info p { color: #b8c0cc; }

.dark .contact-info {
    background: #1f2937;
    border-color: rgba(75, 85, 99, 0.5);
}

/* ---------- Error pages (404.css / 500.css) ---------- */
.dark .message-box,
.dark .card-container {
    background-color: #1f2937;
    color: #e5e7eb;
}

.dark .schedule-grid,
.dark .magnifying-glass {
    background-color: #1f2937;
}

/* ---------- Profile page (profile.css, UI-14) ---------- */
.dark .profile-section {
    border-bottom-color: rgba(75, 85, 99, 0.5);
}

.dark #danger-zone.profile-section {
    border-color: rgba(153, 27, 27, 0.6);
}

.dark .profile-menu__link {
    color: #9ca3af;
}

.dark .profile-menu__link:hover {
    color: #f3f4f6;
    background: rgba(55, 65, 81, 0.6);
}

.dark .profile-menu__link[aria-current="true"] {
    color: #f3f4f6;
    background: #1f2937;
    border-left-color: #8fb1cd;
}

/* A slot the script has not painted yet. Painted slots carry inline colours. */
.dark .palette-slot {
    background: #1f2937;
    color: #e5e7eb;
}

/* ---------- Timetable: the search filter chips (UI-18) ---------- */
/* The strip's own surface and the Filters button exist in the narrow desktop
   band only; their dark rows are beside their rules in timetable/desktop.css. */
.dark .search-filters .sf-label {
    color: #9ca3af;
}

.dark .sf-chip {
    background: rgba(31, 41, 55, 0.7);
    border-color: rgba(75, 85, 99, 0.6);
    color: #e5e7eb;
}

.dark .sf-chip:hover {
    border-color: #9ca3af;
}

.dark .sf-chip[aria-pressed="true"],
.dark .sf-select.is-set {
    background: #27577f;
    border-color: #27577f;
    color: #fff;
}

.dark .sf-select option {
    background: #1f2937;
    color: #e5e7eb;
}

.dark .sf-clear {
    color: #9edcff;
}

/* ---------- The finals calendar (finals.css, UI-42) ----------
   The exam blocks keep the student's course colours, as on the planner. */
.dark .finals-drop {
    border-color: rgba(107, 114, 128, 0.8);
}

.dark .finals-drop:hover,
.dark .finals-drop:focus-visible,
.dark .finals-drop.is-dragging {
    border-color: #9edcff;
    background: rgba(32, 113, 156, 0.15);
}

.dark .finals-status { color: #9ca3af; }
.dark .finals-status[data-status='error'] { color: #fca5a5; }

.dark .finals-button {
    border-color: rgba(75, 85, 99, 0.8);
    background: #1f2937;
    color: #9edcff;
}

.dark .finals-button:hover:not(:disabled) {
    border-color: #9ca3af;
    background: #374151;
}

.dark .finals-button.is-armed {
    border-color: #f87171;
    color: #fca5a5;
}

.dark .finals-results {
    border-color: rgba(75, 85, 99, 0.5);
    background: #1f2937;
}

.dark .fr-row { border-top-color: rgba(75, 85, 99, 0.4); }
.dark .fr-code { color: #f3f4f6; }
.dark .fr-name { color: #d1d5db; }
.dark .fr-meta { color: #9ca3af; }

.dark .fr-add {
    border-color: #9edcff;
    background: transparent;
    color: #9edcff;
}

.dark .fr-add:hover { background: rgba(32, 113, 156, 0.2); }

.dark .fr-add.is-added {
    border-color: #20719c;
    background: #20719c;
    color: #ffffff;
}

.dark .fc-weekday { color: #9ca3af; }

.dark .fc-day {
    border-color: rgba(75, 85, 99, 0.5);
    background: #1f2937;
}

.dark .fc-day.is-quiet { background: #111827; }
.dark .fc-day.is-exam-day { box-shadow: inset 0 3px 0 #2387ba; }
.dark .fc-date { color: #d1d5db; }
.dark .fc-day.is-quiet .fc-date { color: #6b7280; }
.dark .fc-block.is-clash { outline-color: #f87171; }

/* A phone lists the days (finals.css): no exam-period bar there either. */
@media (max-width: 639px) {
    .dark .fc-day.is-exam-day { box-shadow: none; }
}
