:root {
    /* Brand palette — matches the public landing page (4-color brand system) */
    --navy-950: #251d3a;
    --navy-900: #251d3a;
    --navy-800: #2a2550;
    --navy-700: #2a2550;
    --gold-500: #ffcc00;
    --gold-400: #ffcc00;
    --gold-300: #ffcc00;

    --primary: var(--navy-900);
    --primary-hover: var(--navy-700);
    --accent: var(--gold-500);
    --accent-hover: var(--gold-400);
    --accent-text: var(--navy-900); /* dark text reads best on both the bright-yellow accent and its orange hover state */
    --sidebar-bg: linear-gradient(160deg, var(--navy-900), var(--navy-700));
    --sidebar-text: rgba(255, 255, 255, 0.75);
    --bg-light: #f3f4f6;
    --sidebar-width: 260px;
    --card-trend-up: #10b981; /* Emeral Green for increases */

    /* --- Theme tokens (light) --- */
    --bg-main: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --navbar-bg: #ffffff;

    /* ==================== TYPOGRAPHY ====================
       Two families, one job each, and nothing else anywhere in the app:

         --font-display  Playfair Display. Institutional headings ONLY — the
                         landing page's section titles, the auth pages' CQA
                         headline, the survey hero. It is what makes a page
                         read as belonging to a college office rather than to
                         a generic admin template, and it is deliberately not
                         used for anything a user operates: a serif at 13px in
                         a form label is harder to read, not more official.

         --font-ui       Plus Jakarta Sans. Every other piece of text — body
                         copy, labels, buttons, tables, the sidebar. Inter is
                         the second name on purpose: it is metrically close
                         enough that a swap between the two does not reflow
                         the page, so it is a genuine fallback rather than a
                         different design.

       Both are requested in ONE <link> in views/layout/header.ejs, italics
       included (see the comment there for why that matters). Use the tokens,
       not the literal family names — a page that hardcodes 'Inter' or
       'Plus Jakarta Sans' is a page that will drift the next time this
       changes, which is exactly how the login page ended up not matching the
       landing page it links to.

       The print/report templates (report.ejs, dashboard-report.ejs,
       offices.ejs, survey-records.ejs, cluster-detail.ejs's print block) stay
       on Arial ON PURPOSE — those reproduce an official CQA form and have to
       match the paper original, so they are not part of this system. */
    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-ui: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html[data-bs-theme="dark"] {
    --bg-main: #0b1526;
    --bg-card: #141d30;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #263045;
    --navbar-bg: #101a2c;
    --bg-light: #0b1526;

    /* The admin pages each declare their own local token set (--card-bg,
       --surface-subtle, --text-heading, --border-subtle, ...) in their inline
       <style>. Those names are repeated here so a page that only defines the
       LIGHT values still lands on the shared dark palette instead of keeping
       its white surfaces — one palette, defined once, for every admin screen.
       A page is free to override any of them in its own dark block; this is
       the floor, not a ceiling. */
    --bg-body: #0b1526;
    --card-bg: #141d30;
    --surface-subtle: #1a2438;
    --text-heading: #f1f5f9;
    --text-dark: #f1f5f9;
    --text-faint: #64748b;
    --border-subtle: #263045;
    --border-strong: #2c3a54;
    --border-soft: rgba(148, 163, 184, 0.16);
    --border-soft-strong: rgba(148, 163, 184, 0.26);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.35);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 16px -10px rgba(0, 0, 0, 0.5);
    --shadow-card-hover: 0 2px 6px rgba(0, 0, 0, 0.4), 0 16px 32px -14px rgba(0, 0, 0, 0.55);
    --shadow-hero: 0 24px 48px -16px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);

    /* Bootstrap 5.3 ships its own dark theme under this same attribute, but on
       ITS palette (#212529 greys), which read as a different product sitting
       next to our navy surfaces. Re-pointing Bootstrap's variables at our
       tokens is what makes .card, .modal, .dropdown-menu, .table, .list-group
       and the form controls come out the right color without restyling each
       one by hand. */
    --bs-body-bg: #0b1526;
    --bs-body-color: #e2e8f0;
    --bs-emphasis-color: #f8fafc;
    --bs-secondary-color: rgba(226, 232, 240, 0.72);
    --bs-secondary-bg: #1a2438;
    --bs-tertiary-bg: #141d30;
    --bs-tertiary-color: rgba(226, 232, 240, 0.5);
    --bs-border-color: #263045;
    --bs-border-color-translucent: rgba(255, 255, 255, 0.12);
    --bs-heading-color: #f1f5f9;
    --bs-link-color: #93c5fd;
    --bs-link-hover-color: #bfdbfe;
    --bs-link-color-rgb: 147, 197, 253;
    --bs-code-color: #f0abfc;
}

body {
    font-family: var(--font-ui);
    font-size: 0.95rem;
    line-height: 1.6;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow-x: hidden;
    transition: background-color 0.25s ease, color 0.25s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
    font-family: inherit;
    font-weight: 700;
    /* Headings are set tighter than body text because they are read as a
       shape, not word by word; body copy keeps its default tracking so it
       stays comfortable at 15px. */
    letter-spacing: -0.01em;
    line-height: 1.25;
}

/* Numbers that sit in a column — dashboard KPI figures, table cells, the
   notification count — need to line up digit under digit. Proportional
   figures make "1" narrower than "8", so a column of scores visibly wobbles.
   Plus Jakarta Sans ships tabular figures; this is what turns them on. */
.table-custom td,
.table-custom th,
.stat-card-number,
.notif-badge,
time,
.tabular-nums {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
}

/* --- Dark mode overrides for shared components --- */
html[data-bs-theme="dark"] #content { background-color: var(--bg-main); }

html[data-bs-theme="dark"] .top-navbar {
    background: var(--navbar-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
html[data-bs-theme="dark"] .top-navbar #pageTitle,
html[data-bs-theme="dark"] .top-navbar .text-dark { color: var(--text-main) !important; }

html[data-bs-theme="dark"] .card-custom,
html[data-bs-theme="dark"] .stat-card {
    background: var(--bg-card);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.35);
}
html[data-bs-theme="dark"] .stat-card-number { color: var(--text-main); }
html[data-bs-theme="dark"] .stat-card-title,
html[data-bs-theme="dark"] .stat-card-smalltext { color: var(--text-muted); }

html[data-bs-theme="dark"] .table-custom th {
    background: var(--bg-card);
    color: var(--text-muted);
    border-bottom-color: var(--border-color);
}
html[data-bs-theme="dark"] .table-custom td { color: var(--text-main); }

html[data-bs-theme="dark"] .modal-content,
html[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--bg-card);
    color: var(--text-main);
}
html[data-bs-theme="dark"] .text-dark { color: var(--text-main) !important; }
html[data-bs-theme="dark"] .form-select,
html[data-bs-theme="dark"] .form-control {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-color: var(--border-color);
}

/* --- App shell ---
   #wrapper owns one fixed viewport-height box; #sidebar and #content are its
   two panes and #content is the ONLY one that scrolls. This replaces the
   previous position:sticky sidebar, which was silently unreliable: body's
   `overflow-x: hidden` computes (per spec) to `overflow: hidden auto`,
   making body itself a scroll-container-establishing ancestor even though
   it never visibly scrolled — which is enough to make it (rather than the
   real viewport) the sticky sidebar's containing block, so "stuck"
   positioning could disagree with what was actually being scrolled. Giving
   #wrapper an explicit height + overflow:hidden and letting #content scroll
   internally sidesteps that whole class of bug and guarantees exactly one
   scrollbar, ever.

   Sidebar link colors/hover/active/collapse states live entirely in
   layout/sidebar.ejs's own <style> block now — this file only owns the
   shell's structural geometry (width, height, background, stacking), so
   there is a single place that decides what a nav link looks like. */
#wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
#sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
}
#sidebar.active { margin-left: calc(var(--sidebar-width) * -1); }

/* --- Content & Navbar --- */
#content {
    width: 100%;
    height: 100%;
    min-width: 0;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    transition: margin 0.3s ease, opacity 0.18s ease-out, transform 0.18s ease-out;
    animation: pageFadeIn 0.3s ease-out;
}
/* Matches the 180ms setTimeout in main.js exactly, so the outgoing page never
   gets cut off mid-transition (a shorter JS delay than this duration is what
   produced the visible "jump" when navigating between pages).
   will-change lives ONLY on this transient class, not on #content itself:
   `will-change: transform` makes an element behave as if it had a transform,
   which creates a new containing block for any position:fixed descendant —
   and Bootstrap modals (like #adminLogsModal, rendered inside #content via
   the navbar partial) use position:fixed. A permanent will-change on #content
   was hijacking that, so modals opened clipped/mispositioned inside the
   scrolling #content box instead of the viewport, while the backdrop (which
   Bootstrap appends straight to <body>) still covered the full screen —
   looking like a stuck dark screen the modal couldn't be clicked through. */
#content.page-fade-out { opacity: 0; transform: translateY(8px); will-change: opacity, transform; }

@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Breaks out of #content's own 20px padding (negative margin on three sides)
   so the sticky bar sits flush against the real top/left/right edges of the
   content pane instead of floating as a rounded, shadowed card 20px down —
   that gap was what let scrolled-past content (e.g. the dashboard's hero
   card) visually poke out above/behind it mid-scroll. */
.top-navbar {
    background: #fff;
    border-radius: 0;
    margin: -20px -20px 20px -20px;
    padding: 14px 24px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 900;
}

/* --- UI Elements & Animations --- */
.card-custom { border: none; border-radius: 0.75rem; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
.btn-primary { background-color: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background-color: var(--primary-hover); border-color: var(--primary-hover); }
.table-custom th { background: #f9fafb; font-weight: 600; color: #374151; border-bottom: 2px solid #e5e7eb; }
.table-custom td { vertical-align: middle; }

/* Dashboard-Specific Stats Cards */
.stat-card {
    background: #fff;
    border-radius: 0.75rem;
    padding: 24px;
    display: flex;
    align-items: center;
    position: relative;
    overflow: hidden;
    cursor: default;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    transition: all 0.2s ease-in-out;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.5s ease forwards;
}

.stat-card.animate-delayed-1 { animation-delay: 0.1s; }
.stat-card.animate-delayed-2 { animation-delay: 0.2s; }
.stat-card.animate-delayed-3 { animation-delay: 0.3s; }

.stat-card:hover {
    transform: translateY(-3px) scale(1.01);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

.stat-card-accent {
    position: absolute;
    top: 0;
    left: 0;
    height: 4px;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--primary-hover));
    border-radius: 0.75rem 0.75rem 0 0;
    transition: width 0.4s ease-out;
}
.stat-card:hover .stat-card-accent { width: 100%; }

.stat-card-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--navy-900);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 1.5rem;
    margin-right: 20px;
}

.stat-card-info { flex-grow: 1; }
.stat-card-title { font-size: 0.85rem; color: #6b7280; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px; }
.stat-card-number { font-size: 2rem; font-weight: 700; color: #111827; margin: 0; }
.stat-card-smalltext { font-size: 0.8rem; color: #9ca3af; margin: 0; }

.stat-card-trend {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    color: var(--card-trend-up);
    font-size: 0.85rem;
    font-weight: 600;
}
.trend-arrow { font-size: 0.9rem; margin-bottom: 2px; }

/* Subtle Animated Background Line Graph */
.stat-card-bg-graph {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 60%;
    height: 40%;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg width='241' height='100' viewBox='0 0 241 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 90C40 90 80 10 120 10C160 10 200 90 241 90V100H0V90Z' fill='%23251D3A'/%3E%3C/svg%3E");
    background-size: cover;
    background-position: bottom right;
    pointer-events: none;
    filter: blur(1px);
}

/* Specific Recent Logs Styling */
.recent-log-list {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.5s ease 0.4s forwards;
}
.list-group-item.log-item { display: flex; align-items: center; }
.log-item-icon { width: 40px; height: 40px; }

@keyframes fadeInUp {
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile */
@media (max-width: 768px) {
    /* Off-canvas drawer: fixed escapes #wrapper's overflow:hidden (no
       transform/filter on any ancestor, so fixed positioning isn't
       reclipped), and top/height are set explicitly since a fixed element
       no longer participates in #wrapper's flex sizing. */
    /* transition lives in layout/sidebar.ejs (one authoritative declaration
       covering min-width/max-width for desktop collapse AND margin-left for
       this drawer) so there's no cross-file cascade tie to resolve. */
    #sidebar {
        margin-left: calc(var(--sidebar-width) * -1);
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
    }
    #sidebar.active { margin-left: 0; box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25); }

    /* Dim/overlay behind the drawer, click to close (wired in main.js) */
    #sidebar-overlay {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 999;
    }
    #sidebar-overlay.active { display: block; animation: overlayIn 0.2s ease-out; }
    @keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

    body.sidebar-open { overflow: hidden; }
}
/* --- Cluster Report Accordion Styles --- */
.report-section {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s ease 0.3s forwards;
}

.accordion-custom .accordion-item {
    border: none;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    overflow: hidden;
}

.accordion-custom .accordion-button {
    background-color: #fff;
    color: #111827;
    font-weight: 600;
    padding: 1.25rem 1.5rem;
    box-shadow: none !important;
    border-bottom: 1px solid #f3f4f6;
}

.accordion-custom .accordion-button:not(.collapsed) {
    background-color: #f8fafc;
    color: var(--primary);
}

.accordion-custom .accordion-button::after {
    filter: invert(30%) sepia(85%) saturate(1805%) hue-rotate(228deg) brightness(96%) contrast(94%); /* Colors the icon to primary */
}

.accordion-custom .accordion-button.collapsed::after {
    filter: none;
}

.table-report th {
    background-color: #f8fafc;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: #6b7280;
    padding: 1rem 1.5rem;
    border-bottom: 2px solid #e5e7eb;
}

.table-report td {
    padding: 1rem 1.5rem;
    vertical-align: middle;
    color: #374151;
    font-size: 0.9rem;
    border-bottom: 1px solid #f3f4f6;
}

.table-report tbody tr:hover {
    background-color: #f8fafc;
}

.badge-outstanding {
    background-color: #d1fae5;
    color: #065f46;
    padding: 0.4em 0.8em;
    font-weight: 600;
    border-radius: 0.5rem;
}

.overall-rating-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(37, 29, 58, 0.35);
}

/* --- Global UI/UX Consistency (placeholders, spacing) --- */
::placeholder {
    color: #94a3b8;
    opacity: 1;
    font-weight: 400;
    font-style: normal;
}

.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: #374151;
    margin-bottom: 0.35rem;
}

.form-control, .form-select {
    border-radius: 0.5rem;
}

.container-fluid.px-4 {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.card-custom, .content-card, .records-card {
    margin-bottom: 1.5rem;
}

/* Archived record styling shared across management pages */
.archived-row { opacity: 0.55; background-color: #f8fafc; }
.badge-archived { background-color: #fee2e2; color: #b91c1c; font-weight: 600; font-size: 0.7rem; letter-spacing: 0.5px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}


/* ==================================================================
   Password field helpers — the show/hide toggle and the strength meter
   that public/js/alerts.js injects. Styled here (not inline in the JS)
   so every page that loads the shared stylesheet gets the same field,
   and so a page can override one rule without touching the script.
   ================================================================== */

/* The toggle renders as a plain icon sitting inside the field. It used to
   get Bootstrap's .btn-outline-secondary, whose own left/right borders drew
   a vertical rule through the input and made it look like the field had been
   split into two boxes. */
.password-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.9rem;
    min-height: 2.6rem;
    flex-shrink: 0;
    border: none;
    background: none;
    padding: 0;
    color: #94a3b8;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 0.75rem;
    transition: color 0.2s ease, background-color 0.2s ease;
}
.password-toggle:hover { color: #251d3a; background: rgba(37, 29, 58, 0.06); }
.password-toggle:focus-visible { outline: 2px solid #251d3a; outline-offset: -2px; }

/* Inside a Bootstrap .input-group the button is a grid/flex child sitting
   next to a bordered .form-control, so it has to carry the field's own
   border on the three outer edges (never on the side facing the input,
   which is what would redraw that split line) and round off the right end
   to match the group. */
.input-group > .password-toggle-grouped {
    border: 1px solid #dee2e6;
    border-left: 0;
    background-color: var(--bs-secondary-bg, #f8f9fa);
    border-top-right-radius: var(--bs-border-radius, 0.375rem);
    border-bottom-right-radius: var(--bs-border-radius, 0.375rem);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
.input-group > .password-toggle-grouped:hover { background-color: #eef0f2; }

/* Fallback placement when the input has no field wrapper to sit in — the
   script wraps the input alone and this floats over its right edge. 44px
   square is the comfortable-tap-target guideline. */
.password-toggle-floating {
    position: absolute;
    right: 0.2rem;
    top: 50%;
    transform: translateY(-50%);
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
}

/* Strength meter — a 4-segment bar plus a short label. Collapsed to zero
   height while the field is empty so it costs no vertical space on first
   paint; only the typing user pays for it, which matters on the auth pages
   that have to fit the fold without scrolling. */
.pw-strength {
    margin-top: 0.4rem;
    overflow: hidden;
    /* Only a collapse mechanism, never a real size limit — set well above the
       ~24px the meter needs so a hint that wraps on a narrow phone can't get
       clipped. */
    max-height: 5rem;
    opacity: 1;
    transition: max-height 0.25s ease, opacity 0.25s ease, margin-top 0.25s ease;
}
.pw-strength.is-empty {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}
/* A single rounded track with an animated gradient fill reads as a proper
   meter (think password managers), rather than four static blocks that just
   flip color — the smooth width/gradient transition is what sells "polished". */
.pw-strength-track {
    height: 6px;
    border-radius: 50px;
    background: #eef1f6;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
    overflow: hidden;
}
.pw-strength-fill {
    height: 100%;
    width: 0%;
    border-radius: 50px;
    background: #e2e8f0;
    transition: width 0.3s ease, background 0.3s ease;
}
.pw-strength-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0.45rem 0 0;
    line-height: 1.3;
}
/* The level word lives in a small pill (icon + text) instead of bare colored
   text, so it reads as a status chip rather than an afterthought caption. */
.pw-strength-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    flex: 0 0 auto;
    padding: 0.16rem 0.55rem;
    border-radius: 50px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: #f1f5f9;
    color: #94a3b8;
    transition: background-color 0.25s ease, color 0.25s ease;
}
.pw-strength-badge .pw-strength-icon { font-size: 0.6rem; }
.pw-strength-label .pw-strength-hint {
    flex: 1 1 auto;
    text-align: right;
    font-size: 0.7rem;
    font-weight: 500;
    color: #94a3b8;
    min-width: 0;
    overflow-wrap: anywhere;
}
/* Each level drives the fill's width/gradient and the badge's color via the
   [data-level] the script sets. */
.pw-strength[data-level="1"] .pw-strength-fill { width: 25%; background: linear-gradient(90deg, #ef4444, #f87171); }
.pw-strength[data-level="2"] .pw-strength-fill { width: 50%; background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.pw-strength[data-level="3"] .pw-strength-fill { width: 75%; background: linear-gradient(90deg, #eab308, #facc15); }
.pw-strength[data-level="4"] .pw-strength-fill { width: 100%; background: linear-gradient(90deg, #16a34a, #22c55e); }
.pw-strength[data-level="1"] .pw-strength-badge { background: #fee2e2; color: #dc2626; }
.pw-strength[data-level="2"] .pw-strength-badge { background: #fef3c7; color: #b45309; }
.pw-strength[data-level="3"] .pw-strength-badge { background: #fef9c3; color: #a16207; }
.pw-strength[data-level="4"] .pw-strength-badge { background: #dcfce7; color: #15803d; }

@media (max-width: 480px) {
    /* Match the ~41px input height these auth pages use on phones, so the
       whole right edge of the field is tappable. */
    .password-toggle { width: 2.9rem; min-height: 41px; font-size: 1.05rem; }
    .pw-strength-label { font-size: 0.74rem; }
}


/* ==================================================================
   DARK MODE — shared admin components
   ------------------------------------------------------------------
   Everything above this line was written light-first, and the pieces
   that hardcode a light value (rather than reading a token) are
   re-stated here for dark. Grouped by component so a change to, say,
   the report accordion is made in one place.

   Deliberately NOT darkened anywhere in the app:

     .report-container / .csm-export-container — the on-screen preview
     of an official CSPC form. html2pdf captures those elements exactly
     as they render, so darkening them would darken the exported PDF
     and the printed page. They stay white paper on a dark desk, which
     is also how every PDF viewer shows a document in dark mode.

   Contrast: every text color below was picked to clear WCAG AA (4.5:1)
   against the surface it sits on — #e2e8f0/#f1f5f9 on #141d30, with
   #94a3b8 for muted text, the lightest grey that still passes on the
   card background.
   ================================================================== */

/* --- App shell --- */
/* The sidebar is navy in BOTH themes (it is the brand rail, not a
   surface), but it is deepened in dark so it does not glow brighter
   than the content beside it — a light-navy sidebar next to a near
   black page reads as the page being unfinished. */
html[data-bs-theme="dark"] {
    --sidebar-bg: linear-gradient(160deg, #141131, #171340);
}
html[data-bs-theme="dark"] .top-navbar {
    border-bottom: 1px solid var(--border-color);
}

/* --- Cards & tables --- */
html[data-bs-theme="dark"] .card-custom {
    border: 1px solid var(--border-color);
}
html[data-bs-theme="dark"] .table-custom tbody tr:hover > * {
    background-color: rgba(255, 255, 255, 0.04);
}

/* The cluster/report accordion and its tables are light-first
   throughout, so all four surfaces (button, open button, header row,
   body row) are restated. */
html[data-bs-theme="dark"] .accordion-custom .accordion-item {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
}
html[data-bs-theme="dark"] .accordion-custom .accordion-button {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-bottom-color: var(--border-color);
}
html[data-bs-theme="dark"] .accordion-custom .accordion-button:not(.collapsed) {
    background-color: #1a2438;
    color: #93c5fd;
}
/* Bootstrap's chevron is a black SVG, and invert() is the only way to
   recolor a background-image icon. The first filter lightens it for the
   collapsed state, the second keeps the open state on the accent. */
html[data-bs-theme="dark"] .accordion-custom .accordion-button.collapsed::after {
    filter: invert(1) brightness(1.6);
}
html[data-bs-theme="dark"] .accordion-custom .accordion-button::after {
    filter: invert(74%) sepia(24%) saturate(1200%) hue-rotate(185deg) brightness(102%);
}

html[data-bs-theme="dark"] .table-report th {
    background-color: #1a2438;
    color: var(--text-muted);
    border-bottom-color: var(--border-color);
}
html[data-bs-theme="dark"] .table-report td {
    color: var(--text-main);
    border-bottom-color: var(--border-color);
}
html[data-bs-theme="dark"] .table-report tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

/* --- Status pills ---
   The light pills are a pale tint plus dark ink, which inverts badly:
   the tint turns into a bright block on a dark page. Dark mode uses the
   opposite construction — a translucent wash of the same hue plus light
   ink — so the color still MEANS the same thing at a glance. */
html[data-bs-theme="dark"] .badge-outstanding {
    background-color: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
}
html[data-bs-theme="dark"] .badge-archived {
    background-color: rgba(239, 68, 68, 0.18);
    color: #fca5a5;
}
html[data-bs-theme="dark"] .archived-row {
    opacity: 0.6;
    background-color: rgba(255, 255, 255, 0.03);
}

/* --- Forms --- */
html[data-bs-theme="dark"] #content .form-label { color: var(--text-main); }
html[data-bs-theme="dark"] #content ::placeholder { color: #64748b; }
html[data-bs-theme="dark"] #content .form-control:focus,
html[data-bs-theme="dark"] #content .form-select:focus {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-color: #6d96ff;
    box-shadow: 0 0 0 3px rgba(109, 150, 255, 0.25);
}
/* Bootstrap paints the select chevron as a dark SVG data-URI; without
   this it disappears against the dark field. */
html[data-bs-theme="dark"] #content .form-select {
    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='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
/* Left global on purpose (no #content scope): a select's dropdown list
   is drawn by the OS, not by CSS — the options
   only inherit a color if they are styled directly, which is why
   light-on-light unreadable option lists are the classic dark-mode bug
   on Windows. */
html[data-bs-theme="dark"] select.form-select option,
html[data-bs-theme="dark"] select.form-control option {
    background-color: #141d30;
    color: #e2e8f0;
}
/* .bg-light is a Bootstrap utility whose value does NOT follow the dark
   theme (it is a fixed near-white), so every field carrying it stays
   white unless it is re-pointed here. */
html[data-bs-theme="dark"] #content .bg-light {
    background-color: #1a2438 !important;
    color: var(--text-main);
}
html[data-bs-theme="dark"] #content .text-muted { color: var(--text-muted) !important; }
html[data-bs-theme="dark"] #content .border { border-color: var(--border-color) !important; }
html[data-bs-theme="dark"] #content .modal-header,
html[data-bs-theme="dark"] #content .modal-footer { border-color: var(--border-color); }
html[data-bs-theme="dark"] #content .list-group-item {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-color: var(--border-color);
}

/* --- Password field helpers (injected by /js/alerts.js) ---
   Also left global. The same script injects these controls on the client
   survey's change-password panel, which is a dark-capable page with no
   dark rules of its own for them — the toggle's hover state there is
   navy ink on a navy wash, i.e. invisible. Scoping these to #content
   would leave that broken for no gain. */
html[data-bs-theme="dark"] .password-toggle { color: #94a3b8; }
html[data-bs-theme="dark"] .password-toggle:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.08);
}
html[data-bs-theme="dark"] .password-toggle:focus-visible { outline-color: #6d96ff; }
html[data-bs-theme="dark"] .input-group > .password-toggle-grouped {
    border-color: var(--border-color);
    background-color: #1a2438;
}
html[data-bs-theme="dark"] .input-group > .password-toggle-grouped:hover { background-color: #22304a; }
html[data-bs-theme="dark"] .pw-strength-track {
    background: #1a2438;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}
html[data-bs-theme="dark"] .pw-strength-fill { background: #2c3a54; }
html[data-bs-theme="dark"] .pw-strength-badge { background: #1a2438; color: #94a3b8; }
html[data-bs-theme="dark"] .pw-strength-label .pw-strength-hint { color: #94a3b8; }
html[data-bs-theme="dark"] .pw-strength[data-level="1"] .pw-strength-badge { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
html[data-bs-theme="dark"] .pw-strength[data-level="2"] .pw-strength-badge { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
html[data-bs-theme="dark"] .pw-strength[data-level="3"] .pw-strength-badge { background: rgba(234, 179, 8, 0.18); color: #fde047; }
html[data-bs-theme="dark"] .pw-strength[data-level="4"] .pw-strength-badge { background: rgba(34, 197, 94, 0.18); color: #86efac; }

/* --- Scrollbars ---
   #content is the app's only scroller; a default light scrollbar down
   the right edge of a dark page is the last thing that gives away an
   unfinished dark mode. */
html[data-bs-theme="dark"] #content { scrollbar-color: #2c3a54 transparent; }
html[data-bs-theme="dark"] #content::-webkit-scrollbar { width: 10px; height: 10px; }
html[data-bs-theme="dark"] #content::-webkit-scrollbar-track { background: transparent; }
html[data-bs-theme="dark"] #content::-webkit-scrollbar-thumb {
    background: #2c3a54;
    border-radius: 10px;
    border: 2px solid var(--bg-main);
}
html[data-bs-theme="dark"] #content::-webkit-scrollbar-thumb:hover { background: #3b4c6b; }

/* --- Print ---
   Printing happens from whatever theme the admin is sitting in, so the
   dark surfaces are forced back to paper here. Without this, printing
   the Offices or Survey Records page from dark mode produces grey
   blocks and pale text. The .report-container pages are unaffected
   (they were never darkened) — this covers the ordinary screens. */
@media print {
    html[data-bs-theme="dark"] body,
    html[data-bs-theme="dark"] #content,
    html[data-bs-theme="dark"] .card,
    html[data-bs-theme="dark"] .card-custom,
    html[data-bs-theme="dark"] .stat-card {
        background: #fff !important;
        color: #000 !important;
    }
}

/* --- Bootstrap utilities that do not follow the theme ---
   .bg-white and .text-primary resolve to fixed values, not to theme
   variables, so a card header carrying .bg-white stays a white strip
   across the top of a dark card and the navy .text-primary link on it
   effectively disappears.

   Everything in this group is scoped to #content — the admin shell's
   scrolling pane, which only the sidebar-layout pages have. The client
   and office pages load this same stylesheet but style their own
   buttons and surfaces from their own token sets (see the
   .btn-outline-primary block in client-survey.ejs), and a bare
   html[dark] .btn-outline-primary here would outrank those and quietly
   restyle the survey. Admin modals are rendered inside #content too, so
   nothing on these pages is missed by the narrower scope.

   The :not() guards matter: .report-container and .csm-export-container
   are the on-screen previews of official CSPC forms, captured as-is by
   html2pdf. Anything inside them has to stay exactly as it prints, so
   they are carved out of every dark rule rather than darkened and then
   undone at print time. */
html[data-bs-theme="dark"] #content .bg-white:not(.report-container *):not(.csm-export-container *) {
    background-color: var(--bg-card) !important;
    color: var(--text-main);
}
html[data-bs-theme="dark"] #content .text-primary:not(.report-container *):not(.csm-export-container *) {
    color: #93c5fd !important;
}
html[data-bs-theme="dark"] #content .card-header,
html[data-bs-theme="dark"] #content .card-footer {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-color: var(--border-color);
}

/* Outline buttons are drawn in the brand navy, which on a navy-black
   page is a button-shaped hole. They keep their meaning (primary /
   neutral / danger) but are lifted to the light end of each hue. */
html[data-bs-theme="dark"] #content .btn-outline-primary {
    --bs-btn-color: #93c5fd;
    --bs-btn-border-color: #3f5a8a;
    --bs-btn-hover-bg: #3452a5;
    --bs-btn-hover-border-color: #3452a5;
    --bs-btn-hover-color: #ffffff;
}
html[data-bs-theme="dark"] #content .btn-outline-secondary {
    --bs-btn-color: #cbd5e1;
    --bs-btn-border-color: #3b4c6b;
    --bs-btn-hover-bg: #2c3a54;
    --bs-btn-hover-border-color: #2c3a54;
    --bs-btn-hover-color: #f1f5f9;
}
html[data-bs-theme="dark"] #content .btn-outline-danger {
    --bs-btn-color: #fca5a5;
    --bs-btn-border-color: #7f3a3a;
    --bs-btn-hover-bg: #b91c1c;
    --bs-btn-hover-border-color: #b91c1c;
    --bs-btn-hover-color: #ffffff;
}
/* .btn-primary is the navy brand button. It stays navy — it is the one
   element that should look identical in both themes — but gains a rim
   so it does not merge into the dark card behind it. */
html[data-bs-theme="dark"] #content .btn-primary {
    border-color: rgba(255, 255, 255, 0.18);
}

/* The paper previews: explicitly pinned back to black-on-white so no
   inherited dark color can leak into a page that will be exported as a
   PDF or printed. */
html[data-bs-theme="dark"] .report-container,
html[data-bs-theme="dark"] .csm-export-container {
    background: #fff;
    color: #000;
}
html[data-bs-theme="dark"] .report-container .text-muted {
    color: #6b7280 !important;
}
/* The white page is a bright rectangle on a dark desk; a soft rim keeps
   it reading as a sheet of paper rather than as a blown-out panel. */
html[data-bs-theme="dark"] .report-container {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}
@media print {
    html[data-bs-theme="dark"] .report-container { box-shadow: none; }
}

/* ==================================================================
   DARK MODE — status pills (sentiment, SQD score, AI topic)
   ------------------------------------------------------------------
   /dashboard and /survey-records render the SAME pill classes, so the
   dark values live here rather than in either page — otherwise the two
   screens drift apart the first time one of them is touched.

   Every light pill is built as "pale tint + dark ink". Inverted
   naively that becomes a bright block on a dark page, which is both
   loud and, for the pale ones, lower contrast than it looks. Each pill
   is therefore rebuilt the other way round — a translucent wash of the
   SAME hue plus light ink of that hue — so the color still carries the
   same meaning (green = positive, red = negative, amber = facility)
   while the surface stays quiet.

   This replaces an earlier `filter: brightness(0.92) saturate(0.9)` on
   the whole badge, which could only darken the existing pale tint: a
   near-white pill stayed near-white, so the badges were the brightest
   thing on a dark records table.
   ================================================================== */

/* --- Sentiment --- */
html[data-bs-theme="dark"] .bg-sentiment-positive { background-color: rgba(34, 197, 94, 0.18); color: #86efac; }
html[data-bs-theme="dark"] .bg-sentiment-negative { background-color: rgba(239, 68, 68, 0.18); color: #fca5a5; }
html[data-bs-theme="dark"] .bg-sentiment-neutral  { background-color: rgba(148, 163, 184, 0.20); color: #cbd5e1; }
html[data-bs-theme="dark"] .bg-sentiment-none {
    background-color: rgba(148, 163, 184, 0.10);
    color: #94a3b8;
    border-color: #3b4c6b;
}

/* --- SQD score badges (1-5 plus N/A) --- */
html[data-bs-theme="dark"] .sqd-badge-5,
html[data-bs-theme="dark"] .sqd-badge-4 { background: rgba(34, 197, 94, 0.18); color: #86efac; }
html[data-bs-theme="dark"] .sqd-badge-3 { background: rgba(148, 163, 184, 0.20); color: #cbd5e1; }
html[data-bs-theme="dark"] .sqd-badge-2,
html[data-bs-theme="dark"] .sqd-badge-1 { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
html[data-bs-theme="dark"] .sqd-badge-na,
html[data-bs-theme="dark"] .sqd-badge-unanswered { background: rgba(148, 163, 184, 0.10); color: #94a3b8; }

/* --- AI topic badges ---
   Scoped to .topic-badge because these hue names (.bg-online, .bg-docs,
   .bg-general) are generic enough to collide with something else later. */
html[data-bs-theme="dark"] .topic-badge.bg-cr          { background-color: rgba(239, 68, 68, 0.18);  color: #fca5a5; }
html[data-bs-theme="dark"] .topic-badge.bg-aircon      { background-color: rgba(14, 165, 233, 0.20); color: #7dd3fc; }
html[data-bs-theme="dark"] .topic-badge.bg-general     { background-color: rgba(148, 163, 184, 0.18); color: #cbd5e1; }
html[data-bs-theme="dark"] .topic-badge.bg-facility    { background-color: rgba(217, 119, 6, 0.22);  color: #fcd34d; }
html[data-bs-theme="dark"] .topic-badge.bg-staff       { background-color: rgba(124, 58, 237, 0.26); color: #c4b5fd; }
html[data-bs-theme="dark"] .topic-badge.bg-payment     { background-color: rgba(22, 163, 74, 0.20);  color: #86efac; }
html[data-bs-theme="dark"] .topic-badge.bg-docs        { background-color: rgba(37, 99, 235, 0.24);  color: #93c5fd; }
html[data-bs-theme="dark"] .topic-badge.bg-online      { background-color: rgba(8, 145, 178, 0.24);  color: #67e8f9; }
html[data-bs-theme="dark"] .topic-badge.bg-health      { background-color: rgba(219, 39, 119, 0.22); color: #f9a8d4; }
html[data-bs-theme="dark"] .topic-badge.bg-transaction { background-color: rgba(194, 65, 12, 0.24);  color: #fdba74; }
/* The two "nothing to classify" states keep their dashed outline — that
   is what marks them as not-a-real-topic rather than one more color. */
html[data-bs-theme="dark"] .topic-badge.bg-unclassified {
    background-color: rgba(148, 163, 184, 0.10);
    color: #94a3b8;
    border-color: #3b4c6b;
}
html[data-bs-theme="dark"] .topic-badge.bg-no-feedback {
    background-color: rgba(148, 163, 184, 0.10);
    color: #94a3b8;
    border-color: #3b4c6b;
}
