/*
 * Dark mode (client task 15). The vendored Bootstrap predates data-bs-theme,
 * so this is a hand-written override sheet scoped under html.theme-dark — the
 * class an inline <head> script sets from localStorage BEFORE first paint, so
 * a dark-mode visitor never sees a white flash. Loaded unconditionally; every
 * rule is inert without the class.
 *
 * The banner stays #201e1d in both modes (it is already dark by design), and
 * the brand red (#ec3013) is shared. Charts and the world map keep their own
 * colors — recoloring canvas/SVG output is not worth the drift.
 */

html.theme-dark body,
html.theme-dark .main-content-wrapper {
  background-color: #141312;
  color: #d9d6d4;
}
html.theme-dark .main-container {
  background-color: #1c1a19;
}

/* Cards and their headers */
html.theme-dark .card {
  background-color: #242220;
  color: #d9d6d4;
  border-color: #38352f;
}
html.theme-dark .card-header {
  background-color: #242220;
  border-color: #38352f;
  color: #e6e3e0;
}
html.theme-dark .card-title,
html.theme-dark h1, html.theme-dark h2, html.theme-dark h3,
html.theme-dark h4, html.theme-dark h5, html.theme-dark h6 {
  color: #e6e3e0;
}

/* The second (menu) row of the header */
html.theme-dark .topnav {
  background-color: #201e1d;
  border-color: #38352f;
}
html.theme-dark .topnav .nav-link,
html.theme-dark .topnav .nav-link i {
  color: #d9d6d4;
}
/* Hover red like light mode, in the brightened dark-readable red (see the
   link-hover note at the end of this sheet). */
html.theme-dark .topnav .nav-link:hover,
html.theme-dark .topnav .nav-link:focus { color: #ff7a5c; }

/* Text utilities that hardcode light-mode grays */
html.theme-dark .text-muted { color: #98928d !important; }
html.theme-dark .text-dark { color: #d9d6d4 !important; }
/* ...but a .badge that opts into .text-dark — the bg-warning "as user …" badge
   in the audit log, the amber coverage badge on /admin/scanmaterials — sits on a
   LIGHT badge fill that STAYS light in dark mode, so its text must stay dark or
   it reads near-white on yellow (client, 2026-08-01). More specific than the
   blanket rule above, so it wins the !important tie. */
html.theme-dark .badge.text-dark { color: #201e1d !important; }
html.theme-dark .bg-light { background-color: #2c2a27 !important; }
html.theme-dark .border,
html.theme-dark .border-top,
html.theme-dark .border-bottom { border-color: #38352f !important; }

/* Tables (incl. DataTables) */
html.theme-dark .table {
  color: #d9d6d4;
  border-color: #38352f;
  --bs-table-bg: transparent;
  --bs-table-color: #d9d6d4;
  --bs-table-border-color: #38352f;
  --bs-table-striped-bg: #262421;
  --bs-table-striped-color: #d9d6d4;
}
html.theme-dark .table > :not(caption) > * > * {
  background-color: transparent;
  color: inherit;
  border-color: #38352f;
}
html.theme-dark .table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: #262421;
  color: #d9d6d4;
}
html.theme-dark .dataTables_wrapper,
html.theme-dark .dataTables_info,
html.theme-dark .dataTables_length,
html.theme-dark .dataTables_filter { color: #d9d6d4; }

/* Highlighted info rows (.table-info — e.g. the search report's "Found by AI"
   row): the light-blue variant paints its tint via an inset box-shadow on the
   cells, which survives the transparent cell backgrounds above and left
   near-white text sitting on a light-blue band (client catch). Repaint as a
   dark blue tint; !important because the variant writes per-cell channels. */
html.theme-dark .table-info,
html.theme-dark .table-info > * {
  background-color: #1d3440 !important;
  box-shadow: none !important;
  color: #cfe4f0 !important;
}

/* List groups (the folder detail page's contents list): the 5.3 list-group
   resolves its own bg/color variables from the light :root, which showed a
   white list with black text inside dark cards (client catch). Transparent
   lets the card color through. */
html.theme-dark .list-group-item {
  background-color: transparent;
  color: #d9d6d4;
  border-color: #38352f;
}

/* Forms */
html.theme-dark .form-control,
html.theme-dark .form-select,
html.theme-dark textarea,
html.theme-dark input[type="search"] {
  background-color: #2c2a27;
  border-color: #45413b;
  color: #e6e3e0;
}
html.theme-dark .form-control::placeholder { color: #8a847e; }
html.theme-dark .form-control:focus,
html.theme-dark .form-select:focus {
  background-color: #2c2a27;
  color: #e6e3e0;
  border-color: #ec3013;
  box-shadow: 0 0 0 0.25rem rgba(236, 48, 19, 0.2);
}
html.theme-dark .input-group-text {
  background-color: #2c2a27;
  border-color: #45413b;
  color: #d9d6d4;
}

/* Native <select> keeps the caret added in style.css unless recoloured: that
   arrow is dark-stroked and invisible on the dark field, so paint a light one.
   Same :not([multiple]) as style.css so multi-selects still get none. */
html.theme-dark select.form-control:not([multiple]) {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23d9d6d4' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

/* Dropdowns, modals, alerts */
html.theme-dark .dropdown-menu {
  background-color: #242220;
  border-color: #45413b;
  color: #d9d6d4;
}
html.theme-dark .dropdown-item { color: #d9d6d4; }
html.theme-dark .dropdown-item:hover {
  background-color: #2c2a27;
  color: #ffffff;
}
html.theme-dark .modal-content {
  background-color: #242220;
  color: #d9d6d4;
}

/* Contextual alerts. The template paints alert TEXT and BORDER directly
   (app.min.css) but leaves the BACKGROUND to Bootstrap's --bs-*-bg-subtle
   variables, which resolve from the light :root — so in dark mode every alert
   kept a pale box, and any link inside it (near-white from the dark link
   palette below) vanished: white-on-pale. That was the dev-login box the
   client hit, and the same latent bug sat in every delete-confirm page, draft
   warning and the impersonation banner. Repaint each variant as a dark tint of
   its own hue with light text; the near-white links then read fine on top.
   Selector (0,2,0) outranks the template's (0,1,0) alert rules — no !important
   needed. Only the variants the app actually uses are listed. */
html.theme-dark .alert-warning   { background-color: #332701; border-color: #5c4a12; color: #ffda6a; }
html.theme-dark .alert-danger    { background-color: #2c1012; border-color: #7c2b30; color: #f0a7ab; }
html.theme-dark .alert-success   { background-color: #0e2419; border-color: #26603e; color: #88d0a6; }
html.theme-dark .alert-info      { background-color: #0a2a33; border-color: #1d5866; color: #79d6ed; }
html.theme-dark .alert-secondary { background-color: #2a2825; border-color: #4a453f; color: #bdb8b2; }

/* Buttons that are light-gray by design */
html.theme-dark .btn-outline-secondary {
  color: #b5b0ab;
  border-color: #5a554e;
}
html.theme-dark .btn-outline-secondary:hover {
  background-color: #38352f;
  color: #ffffff;
}
html.theme-dark .btn-light {
  background-color: #2c2a27;
  border-color: #45413b;
  color: #d9d6d4;
}

/* Badges on light backgrounds (project tags) */
html.theme-dark .badge.bg-light {
  background-color: #2c2a27 !important;
  color: #d9d6d4 !important;
}

/* Bootstrap tabs (the share box's badge-snippet tabs). The vendored template
   colours inactive .nav-tabs links dark for a light surface, leaving them
   near black-on-dark here, and the active tab defaulted to the light body-bg.
   Repaint: inactive links light, active tab on the card's own dark surface so
   it reads as the selected pane (client, 2026-08-01). */
html.theme-dark .nav-tabs { border-color: #38352f; }
html.theme-dark .nav-tabs .nav-link { color: #d9d6d4; }
html.theme-dark .nav-tabs .nav-link:hover,
html.theme-dark .nav-tabs .nav-link:focus {
  color: #ff7a5c;
  border-color: #38352f #38352f transparent;
}
html.theme-dark .nav-tabs .nav-link.active {
  color: #e6e3e0;
  background-color: #242220;
  border-color: #45413b #45413b #242220;
}

/* The download-counter badge preview: its dark left segment (#201e1d) merges
   into the dark page, so the badge looked like floating text with a stray red
   number. Put it on the same light plate the logo tiles get above, so the whole
   badge reads as one object (client, 2026-08-01). Light mode needs none — the
   segment is dark-on-white there. */
html.theme-dark img.esl-badge-preview {
  background-color: #f4f2f0;
  padding: 3px 5px;
  border-radius: 4px;
  /* content-box so the plate's padding FRAMES the 20px badge instead of eating
     into it — Bootstrap's global border-box shrank the badge to ~14px in dark
     mode, which is why it looked too small there (client, 2026-08-01). Margin
     would also keep 20px but drop the light frame that makes the badge stand out
     against the dark page — the frame is the point. */
  box-sizing: content-box;
}

/* Footer + flag borders + logo tiles: logos are mostly dark-on-transparent,
   give them a light backing plate so they stay readable. */
html.theme-dark footer { border-color: #38352f !important; color: #98928d; }
html.theme-dark .card-img-top,
html.theme-dark .org-carousel-item img,
html.theme-dark .org-directory-logo {
  background-color: #f4f2f0;
  border-radius: 4px;
}

/* Breadcrumbs / pagination */
html.theme-dark .breadcrumb-item.active { color: #98928d; }
html.theme-dark .page-link {
  background-color: #242220;
  border-color: #45413b;
  color: #d9d6d4;
}

/* Link palette, dark variant (html.theme-dark outranks the :root block in
   style.css): rest color follows the dark body color — link TEXT is never
   red (client, twice) — and hover uses the brightened red, since #ec3013
   sits under 4.5:1 on dark surfaces. */
html.theme-dark {
  --bs-link-color: #d9d6d4;
  --bs-link-color-rgb: 217, 214, 212;
  --bs-link-hover-color: #ff7a5c;
  --bs-link-hover-color-rgb: 255, 122, 92;
}

/* Content links: "slightly darker than body text" inverts to slightly
   BRIGHTER on dark surfaces (the underline follows via currentColor); the
   explicit hover red brightens like everywhere else in this sheet. */
html.theme-dark .page-content a:not(.btn):not(.badge):not(.nav-link):not(.dropdown-item):not(.page-link):not(.text-reset):not(.text-decoration-none):not(.stretched-link) {
  color: #f2f0ef;
}
html.theme-dark .page-content a:not(.btn):not(.badge):not(.nav-link):not(.dropdown-item):not(.page-link):not(.text-reset):not(.text-decoration-none):not(.stretched-link):hover {
  color: #ff7a5c;
}
html.theme-dark footer a:hover { color: #ff7a5c; }

/* Link-styled submit button (the admin tables' "Login as user") — follows the
   dark content-link colours above so it matches the plain "Edit" link beside it. */
html.theme-dark .page-content button.link-action { color: #f2f0ef; }
html.theme-dark .page-content button.link-action:hover { color: #ff7a5c; }

/* Pagination: the dark .page-link recolor above wins the cascade tie against
   Bootstrap's hover/active rules, so both states need explicit dark values. */
html.theme-dark .page-link:hover,
html.theme-dark .page-link:focus { color: #ff9b85; }
html.theme-dark .page-item.active .page-link {
  background-color: #ec3013;
  border-color: #ec3013;
  color: #ffffff;
}

/* Outline buttons at rest, brightened like the links — #ec3013 text sits
   under 4.5:1 on dark cards (review catch). Hover fills solid and keeps the
   light-mode colors. */
html.theme-dark .btn-outline-primary,
html.theme-dark .btn-outline-info {
  --bs-btn-color: #ff7a5c;
  --bs-btn-border-color: #ff7a5c;
}

/* Inline PDF viewer (pdf-viewer.css): dark chrome, but the rendered pages
   themselves stay paper-white — they are documents, not UI. The active
   thumbnail accent brightens like every red on dark surfaces. */
html.theme-dark .pdfviewer-toolbar { border-color: #38352f; }
html.theme-dark .pdfviewer-pages { background-color: #141312; }
html.theme-dark .pdfviewer-thumbs {
  background-color: #1c1a19;
  border-color: #38352f;
}
html.theme-dark .pdfviewer-thumbnum { color: #98928d; }
html.theme-dark .pdfviewer-thumb.is-current .pdfviewer-thumbframe { outline-color: #ff7a5c; }
html.theme-dark .pdfviewer-thumb.is-current .pdfviewer-thumbnum { color: #ff7a5c; }
html.theme-dark .pdfviewer:fullscreen { background: #242220; }
