/*
 * ICT Ticketing System — design tokens and project components.
 * Bootstrap 5 handles layout and base components; this file only overrides
 * variables and adds project-specific pieces (CLAUDE.md §11.2).
 */

/* Poppins (SIL Open Font License, public/assets/fonts/poppins/OFL.txt), self-hosted for the strict CSP.
   Latin only, weights 400/500/700 (CLAUDE.md §11.3); swap shows the system font until it loads. */
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/poppins/poppins-latin-400-normal.woff2") format("woff2");
}

@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/poppins/poppins-latin-500-normal.woff2") format("woff2");
}

@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/poppins/poppins-latin-700-normal.woff2") format("woff2");
}

:root {
    /* Poppins first, then the device's own font (San Francisco, Segoe UI, Roboto, Helvetica Neue / Arial)
       while it loads or for characters outside the Latin set. */
    --font-family: "Poppins", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --app-primary: #0b3d91;
    --app-primary-rgb: 11, 61, 145;
    --app-secondary: #5c6b7a;
    --app-success: #1e7b34;
    --app-warning: #b25e00;
    --app-danger: #b3261e;
    --app-info: #0b6e8a;
    --app-bg: #f4f6f9;
    --app-surface: #ffffff;
    --app-text: #1c2430;
    --app-muted: #5c6b7a;
    --app-border: #dde2e8;
    --app-focus: #f2b705;
    /* Fills (navbar, primary buttons) vs. text/links/icons (--app-primary): they
       differ in dark mode so both keep enough contrast. */
    --app-brand: #0b3d91;
    --app-brand-hover: #082f70;
    --app-brand-active: #072861;
    --app-on-brand: #ffffff;
    --app-note-bg: #fff8e1;
    --app-note-border: #f2c94c;
    --app-radius: 0.5rem;
    --app-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);

    /* Bootstrap variable overrides */
    --bs-font-sans-serif: var(--font-family);
    --bs-body-font-family: var(--bs-font-sans-serif);
    --bs-body-color: var(--app-text);
    --bs-body-bg: var(--app-bg);
    --bs-primary: var(--app-primary);
    --bs-primary-rgb: var(--app-primary-rgb);
    --bs-border-color: var(--app-border);
    --bs-border-radius: var(--app-radius);
    --bs-link-color: var(--app-primary);
    --bs-link-color-rgb: var(--app-primary-rgb);
    --bs-secondary-color: var(--app-muted);
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.55;
}

main {
    flex: 1 0 auto;
}

.btn-primary {
    --bs-btn-bg: var(--app-brand);
    --bs-btn-border-color: var(--app-brand);
    --bs-btn-hover-bg: var(--app-brand-hover);
    --bs-btn-hover-border-color: var(--app-brand-hover);
    --bs-btn-active-bg: var(--app-brand-active);
    --bs-btn-active-border-color: var(--app-brand-active);
    --bs-btn-disabled-bg: var(--app-brand);
    --bs-btn-disabled-border-color: var(--app-brand);
}

/* Highly visible focus ring for keyboard users (CLAUDE.md §11.7). */
:focus-visible {
    outline: 3px solid var(--app-focus);
    outline-offset: 2px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(242, 183, 5, 0.5);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 1080;
    padding: 0.5rem 1rem;
    background: var(--app-surface);
}

.skip-link:focus {
    left: 1rem;
    top: 1rem;
}

.app-navbar {
    background-color: var(--app-brand);
}

.app-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
}

.app-footer {
    color: var(--app-muted);
    font-size: 0.875rem;
}

/* Preserve line breaks in user-entered plain text (rendered escaped). */
.text-preline {
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* Internal notes: tinted and labelled "Internal note" in text (CLAUDE.md §11.7). */
.comment-internal {
    background-color: var(--app-note-bg);
    border-color: var(--app-note-border) !important;
}

/* ---- Charts (CLAUDE.md §11; dataviz: one series, one hue, thin marks) ----
 * Horizontal bars inside a real table: label | bar | value. The bar is
 * decorative (aria-hidden); the number is always shown as text.
 * Widths use .bar-w-N classes because the CSP forbids inline styles.
 */
.bar-chart {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0 6px;
}

.bar-chart th {
    width: 38%;
    padding-right: 0.75rem;
    font-weight: 400;
    font-size: 0.875rem;
    vertical-align: middle;
    overflow-wrap: anywhere;
}

.bar-chart td.bar-cell {
    vertical-align: middle;
    background-image: linear-gradient(to right, var(--app-border) 1px, transparent 1px);
}

.bar-chart td.bar-value {
    width: 4.5rem;
    padding-left: 0.5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 0.875rem;
    color: var(--app-text);
    vertical-align: middle;
}

.bar {
    display: block;
    height: 12px;
    min-width: 0;
    background: var(--app-primary);
    border-radius: 0 4px 4px 0;
}

.bar-chart tr:hover .bar {
    background: var(--app-brand-hover);
}

.bar-chart tr:hover th,
.bar-chart tr:hover td.bar-value {
    font-weight: 500;
}

/* Stat tiles (views/components/stat-tile.php): icon chip + number + label. */
.stat-tile {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    height: 100%;
    padding: 1rem 1.125rem;
    color: inherit;
    text-decoration: none;
}

a.stat-tile:hover {
    color: inherit;
    border-color: rgba(var(--app-primary-rgb), 0.45);
    box-shadow: var(--app-shadow-hover);
    transform: translateY(-1px);
}

.stat-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-name {
    font-weight: 500;
}

.stat-label {
    color: var(--app-muted);
    font-size: 0.8125rem;
}

/* Tinted icon chip. Tone only decorates; the text label carries the meaning (§11.7). */
.stat-icon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.75rem;
    font-size: 1.25rem;
}

.stat-icon-primary { color: var(--app-primary); background: rgba(var(--app-primary-rgb), 0.1); }
.stat-icon-info { color: var(--app-info); background: rgba(11, 110, 138, 0.1); }
.stat-icon-success { color: var(--app-success); background: rgba(30, 123, 52, 0.1); }
.stat-icon-warning { color: var(--app-warning); background: rgba(178, 94, 0, 0.12); }
.stat-icon-danger { color: var(--app-danger); background: rgba(179, 38, 30, 0.1); }
.stat-icon-secondary { color: var(--app-secondary); background: rgba(92, 107, 122, 0.12); }

.bar-w-0 { width: 0%; }
.bar-w-1 { width: 1%; }
.bar-w-2 { width: 2%; }
.bar-w-3 { width: 3%; }
.bar-w-4 { width: 4%; }
.bar-w-5 { width: 5%; }
.bar-w-6 { width: 6%; }
.bar-w-7 { width: 7%; }
.bar-w-8 { width: 8%; }
.bar-w-9 { width: 9%; }
.bar-w-10 { width: 10%; }
.bar-w-11 { width: 11%; }
.bar-w-12 { width: 12%; }
.bar-w-13 { width: 13%; }
.bar-w-14 { width: 14%; }
.bar-w-15 { width: 15%; }
.bar-w-16 { width: 16%; }
.bar-w-17 { width: 17%; }
.bar-w-18 { width: 18%; }
.bar-w-19 { width: 19%; }
.bar-w-20 { width: 20%; }
.bar-w-21 { width: 21%; }
.bar-w-22 { width: 22%; }
.bar-w-23 { width: 23%; }
.bar-w-24 { width: 24%; }
.bar-w-25 { width: 25%; }
.bar-w-26 { width: 26%; }
.bar-w-27 { width: 27%; }
.bar-w-28 { width: 28%; }
.bar-w-29 { width: 29%; }
.bar-w-30 { width: 30%; }
.bar-w-31 { width: 31%; }
.bar-w-32 { width: 32%; }
.bar-w-33 { width: 33%; }
.bar-w-34 { width: 34%; }
.bar-w-35 { width: 35%; }
.bar-w-36 { width: 36%; }
.bar-w-37 { width: 37%; }
.bar-w-38 { width: 38%; }
.bar-w-39 { width: 39%; }
.bar-w-40 { width: 40%; }
.bar-w-41 { width: 41%; }
.bar-w-42 { width: 42%; }
.bar-w-43 { width: 43%; }
.bar-w-44 { width: 44%; }
.bar-w-45 { width: 45%; }
.bar-w-46 { width: 46%; }
.bar-w-47 { width: 47%; }
.bar-w-48 { width: 48%; }
.bar-w-49 { width: 49%; }
.bar-w-50 { width: 50%; }
.bar-w-51 { width: 51%; }
.bar-w-52 { width: 52%; }
.bar-w-53 { width: 53%; }
.bar-w-54 { width: 54%; }
.bar-w-55 { width: 55%; }
.bar-w-56 { width: 56%; }
.bar-w-57 { width: 57%; }
.bar-w-58 { width: 58%; }
.bar-w-59 { width: 59%; }
.bar-w-60 { width: 60%; }
.bar-w-61 { width: 61%; }
.bar-w-62 { width: 62%; }
.bar-w-63 { width: 63%; }
.bar-w-64 { width: 64%; }
.bar-w-65 { width: 65%; }
.bar-w-66 { width: 66%; }
.bar-w-67 { width: 67%; }
.bar-w-68 { width: 68%; }
.bar-w-69 { width: 69%; }
.bar-w-70 { width: 70%; }
.bar-w-71 { width: 71%; }
.bar-w-72 { width: 72%; }
.bar-w-73 { width: 73%; }
.bar-w-74 { width: 74%; }
.bar-w-75 { width: 75%; }
.bar-w-76 { width: 76%; }
.bar-w-77 { width: 77%; }
.bar-w-78 { width: 78%; }
.bar-w-79 { width: 79%; }
.bar-w-80 { width: 80%; }
.bar-w-81 { width: 81%; }
.bar-w-82 { width: 82%; }
.bar-w-83 { width: 83%; }
.bar-w-84 { width: 84%; }
.bar-w-85 { width: 85%; }
.bar-w-86 { width: 86%; }
.bar-w-87 { width: 87%; }
.bar-w-88 { width: 88%; }
.bar-w-89 { width: 89%; }
.bar-w-90 { width: 90%; }
.bar-w-91 { width: 91%; }
.bar-w-92 { width: 92%; }
.bar-w-93 { width: 93%; }
.bar-w-94 { width: 94%; }
.bar-w-95 { width: 95%; }
.bar-w-96 { width: 96%; }
.bar-w-97 { width: 97%; }
.bar-w-98 { width: 98%; }
.bar-w-99 { width: 99%; }
.bar-w-100 { width: 100%; }

/* Admin → Settings: a short numeric field with its unit. */
.settings-days {
    max-width: 12rem;
}

/* Admin → Audit log */
.audit-entry + .audit-entry {
    border-top: 1px solid var(--bs-border-color);
}

.audit-changes th[scope="col"] {
    font-weight: 500;
    color: var(--bs-secondary-color);
}

.audit-changes th[scope="row"] {
    width: 25%;
}

.audit-changes td {
    width: 37.5%;
    overflow-wrap: anywhere;
}

/* Login details for the requester: easy to read aloud and select. */
.credential-secret {
    font-size: 1rem;
    letter-spacing: 0.05em;
    user-select: all;
    word-break: break-all;
}

/* ---- Modern UI building blocks (CLAUDE.md §11.8) ---- */

/* Bootstrap Icons from the self-hosted sprite: icon('name'). Sized with the text. */
.bi {
    display: inline-block;
    flex-shrink: 0;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    fill: currentColor;
}

.brand-icon {
    font-size: 1.25rem;
}

.alert-icon {
    margin-top: 0.2em;
    font-size: 1.1em;
}

/* Page title row: title + supporting text on the left, primary action on the right. */
.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

/* Navigation: clear active state, not color alone (also aria-current). */
.app-navbar .nav-link.active,
.app-navbar .nav-link[aria-current="page"] {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
    border-radius: var(--app-radius);
}

.app-navbar .nav-link {
    padding-inline: 0.75rem;
}

/* Cards: a slightly larger radius and a hover lift for clickable ones. */
:root {
    --app-shadow-hover: 0 4px 12px rgba(16, 24, 40, 0.1), 0 2px 4px rgba(16, 24, 40, 0.06);
}

.app-card {
    border-radius: calc(var(--app-radius) * 1.5);
}

/* Empty states (views/components/empty-state.php). */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2.5rem 1rem;
    text-align: center;
}

.empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: 0.75rem;
    border-radius: 50%;
    color: var(--app-primary);
    background: rgba(var(--app-primary-rgb), 0.08);
    font-size: 1.5rem;
}

.empty-state-title {
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.empty-state-text {
    max-width: 32rem;
    margin-bottom: 1rem;
    color: var(--app-muted);
    font-size: 0.9375rem;
}

.empty-state-compact {
    padding: 1.25rem 0.5rem;
}

.empty-state-compact .empty-state-icon {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.25rem;
}

.empty-state-compact .empty-state-title {
    color: var(--app-muted);
    font-size: 0.875rem;
    font-weight: 400;
}

/* Dashboard mini lists: whole row is the link target. */
.mini-list li + li {
    border-top: 1px solid var(--app-border);
}

.mini-list-item {
    display: block;
    margin: 0 -0.5rem;
    padding: 0.625rem 0.5rem;
    border-radius: var(--app-radius);
    color: inherit;
    text-decoration: none;
}

.mini-list-item:hover {
    color: inherit;
    background: rgba(var(--app-primary-rgb), 0.05);
}

/* Tables that become stacked cards on phones: each cell shows its data-label. */
.table-stack thead th {
    color: var(--app-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

@media (max-width: 767.98px) {
    .table-stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .table-stack,
    .table-stack tbody,
    .table-stack tr,
    .table-stack td {
        display: block;
        width: 100%;
    }

    .table-stack tr {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--app-border);
    }

    .table-stack tr:last-child {
        border-bottom: 0;
    }

    .table-stack td {
        display: flex;
        gap: 0.75rem;
        padding: 0.2rem 0;
        border: 0;
        white-space: normal !important;
    }

    .table-stack td::before {
        content: attr(data-label);
        flex: 0 0 7.5rem;
        color: var(--app-muted);
        font-size: 0.8125rem;
    }
}

/* Subtle motion only (≤200 ms), and none for people who ask for less. */
.btn,
.app-card,
.stat-tile,
.mini-list-item,
.nav-link,
.dropdown-item {
    transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

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

    a.stat-tile:hover {
        transform: none;
    }
}

/* Tables inside cards sit on the card surface, not the page background. */
.app-card .table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: rgba(var(--app-primary-rgb), 0.04);
}

/* Navbar links: readable contrast on the blue bar (WCAG AA). */
.app-navbar {
    --bs-navbar-color: rgba(255, 255, 255, 0.88);
    --bs-navbar-hover-color: #fff;
    --bs-navbar-active-color: #fff;
}

.btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-brand);
    --bs-btn-hover-border-color: var(--app-brand);
    --bs-btn-active-bg: var(--app-brand-hover);
    --bs-btn-active-border-color: var(--app-brand-hover);
    --bs-btn-disabled-color: var(--app-primary);
    --bs-btn-disabled-border-color: var(--app-primary);
}

/* Section headings with a leading icon. */
.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title > .bi {
    color: var(--app-primary);
}

/* Choice tiles: large, tappable checkboxes/radios (input.btn-check + label.choice-tile).
   Selection is shown by the check icon and weight, not only color (§11.7). */
.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr));
    gap: 0.5rem;
}

.choice-tile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    margin: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-surface);
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.choice-tile:hover {
    border-color: rgba(var(--app-primary-rgb), 0.5);
}

.choice-tile .choice-on {
    display: none;
}

.choice-tile .choice-off {
    color: var(--app-muted);
}

.btn-check:checked + .choice-tile {
    border-color: var(--app-primary);
    background: rgba(var(--app-primary-rgb), 0.07);
    color: var(--app-primary);
    font-weight: 500;
}

.btn-check:checked + .choice-tile .choice-on {
    display: inline-block;
}

.btn-check:checked + .choice-tile .choice-off {
    display: none;
}

.btn-check:focus-visible + .choice-tile {
    outline: 3px solid var(--app-focus);
    outline-offset: 2px;
}

.is-invalid-group .choice-tile {
    border-color: var(--app-danger);
}

.choice-group-title {
    margin-bottom: 0.5rem;
    color: var(--app-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Long forms: keep the submit buttons in reach on phones. */
.form-actions {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (max-width: 767.98px) {
    .form-actions-sticky {
        position: sticky;
        bottom: 0;
        z-index: 1020;
        margin-inline: calc(var(--bs-gutter-x, 1.5rem) * -0.5);
        padding: 0.75rem calc(var(--bs-gutter-x, 1.5rem) * 0.5);
        background: var(--app-surface);
        border-top: 1px solid var(--app-border);
        box-shadow: 0 -4px 12px rgba(16, 24, 40, 0.06);
    }
}

@media (min-width: 576px) {
    .form-actions {
        flex-direction: row;
        justify-content: flex-end;
    }
}

/* Timeline (JO history). */
.timeline {
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
}

.timeline li {
    position: relative;
    padding: 0 0 0.875rem 1.5rem;
}

.timeline li::before {
    content: "";
    position: absolute;
    top: 0.35rem;
    left: 0.3rem;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--app-primary);
}

.timeline li:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 1rem;
    bottom: 0;
    left: calc(0.3rem + 0.24rem);
    width: 1px;
    background: var(--app-border);
}

/* Comments: avatar initial + bubble. */
.comment-avatar {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: rgba(var(--app-primary-rgb), 0.1);
    color: var(--app-primary);
    font-size: 1.1rem;
}

.comment.is-internal .comment-avatar {
    background: rgba(178, 94, 0, 0.14);
    color: var(--app-warning);
}

/* Disclosure summaries (<details>) with an icon and a pointer cursor. */
details > summary {
    cursor: pointer;
}

.summary-action {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.min-w-0 {
    min-width: 0;
}

/* ---- Dark theme (CLAUDE.md §11.8): same components, redefined tokens. ----
 * Applied by public/assets/js/theme.js as <html data-bs-theme="dark">.
 * Text/icon colors are lightened for contrast on dark surfaces; fills that
 * carry white text (--app-brand) stay dark enough for AA contrast. */
[data-bs-theme="dark"] {
    color-scheme: dark;
    --app-primary: #8ab4f8;
    --app-primary-rgb: 138, 180, 248;
    --app-brand: #2453a6;
    --app-brand-hover: #1d4588;
    --app-brand-active: #183a73;
    --app-secondary: #9aa7b6;
    --app-success: #5fc77b;
    --app-warning: #f0a44b;
    --app-danger: #ff8a80;
    --app-info: #5cc4e0;
    --app-bg: #0f141b;
    --app-surface: #171d26;
    --app-text: #e3e8ef;
    --app-muted: #9aa7b6;
    --app-border: #2b3442;
    --app-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
    --app-shadow-hover: 0 4px 14px rgba(0, 0, 0, 0.55);
    --app-note-bg: #2a2416;
    --app-note-border: #8a6d1f;

    --bs-body-color: var(--app-text);
    --bs-body-bg: var(--app-bg);
    --bs-secondary-color: var(--app-muted);
    --bs-border-color: var(--app-border);
    --bs-link-color: var(--app-primary);
    --bs-link-color-rgb: var(--app-primary-rgb);
    --bs-link-hover-color: #b3cdfb;
    --bs-primary: var(--app-primary);
    --bs-primary-rgb: var(--app-primary-rgb);
    --bs-tertiary-bg: #1d2430;
}

[data-bs-theme="dark"] .app-navbar {
    background-color: #111a2b;
    border-bottom: 1px solid var(--app-border);
}

[data-bs-theme="dark"] .btn-primary,
[data-bs-theme="dark"] .btn-outline-primary {
    --bs-btn-color: var(--app-on-brand);
}

[data-bs-theme="dark"] .btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-hover-color: #fff;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .input-group-text {
    background-color: #111720;
}

[data-bs-theme="dark"] .text-bg-light {
    color: var(--app-text) !important;
    background-color: #232b37 !important;
}

[data-bs-theme="dark"] .bg-body {
    background-color: var(--app-surface) !important;
}

/* Theme switcher (Light / Dark / Auto). */
.theme-switch .dropdown-item.active,
.theme-switch .btn.active {
    font-weight: 500;
}

/* Login and password pages. */
.auth-brand {
    margin-bottom: 1.5rem;
    text-align: center;
}

.auth-logo {
    display: block;
    width: 72px;
    height: 72px;
    margin: 0 auto 0.75rem;
}

.auth-logo-fallback {
    margin-bottom: 0.75rem;
}

.auth-card {
    padding: 1.5rem;
}

@media (min-width: 576px) {
    .auth-card {
        padding: 2rem;
    }
}

/* Request links: QR code always dark-on-white (scanners need contrast, also in dark mode). */
.qr-box {
    width: 11rem;
    max-width: 100%;
    aspect-ratio: 1;
    padding: 0.25rem;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    background: #ffffff;
}

.qr-box svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Public request-link pages: brand bar without navigation. */
.public-header {
    color: #fff;
}

.public-logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
}

/* Filter pills use the brand color (Bootstrap's default blue otherwise). */
.nav-pills {
    --bs-nav-pills-link-active-bg: var(--app-brand);
    --bs-nav-link-color: var(--app-primary);
    --bs-nav-link-hover-color: var(--app-primary);
}

/* ---- Consistent type scale (UI audit) ----
 * Page title: h1.h3. Card titles: one style everywhere (small, semibold,
 * uppercase). Sub-titles (chart captions, "Add a finding"): small semibold.
 * Body text 1rem; secondary text .875rem; labels medium weight. */
.app-card h2.h6,
.app-card h2.h5,
.app-card .section-title:not(h1) {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    font-style: normal;
    line-height: 1.35;
}

.app-card h3.h6,
.app-card .subsection-title,
.bar-chart caption,
figure > figcaption.h6 {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
}

.form-label {
    font-weight: 500;
}

.form-label.small {
    font-weight: 500;
    color: var(--app-muted);
}

/* Label/value lists in cards: muted labels; stacked on phones (dt col-sm-*). */
.app-card dl.row dt {
    font-weight: 500;
    color: var(--app-muted);
}

.app-card dl.row dd {
    color: var(--app-text);
}

@media (max-width: 575.98px) {
    .app-card dl.row dt {
        margin-bottom: 0;
    }

    .app-card dl.row dd {
        margin-bottom: 0.5rem;
    }
}

/* Tables in cards: the same quiet header everywhere. */
.app-card .table thead th {
    color: var(--app-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* Badges next to a page title stay badge-sized. */
.page-header h1 .badge {
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.4em 0.7em;
}

/* Checked/unchecked lists (JO page): wrapped text stays indented under its label. */
.check-item {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
}

.check-item > .bi {
    flex-shrink: 0;
    transform: translateY(0.1em);
}

.list-inline .check-item {
    display: inline-flex;
}

/* The JO form description fills its card (no empty block under a short textarea). */
.description-fill {
    flex: 1 1 auto;
    min-height: 12rem;
    resize: vertical;
}

/* Helper text inside a card title, e.g. "(select at least one)", stays in normal case. */
.app-card .section-title .fw-normal {
    text-transform: none;
    letter-spacing: 0;
}

/* ❔ field help buttons (help_tip()) and their popovers. */
.help-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    margin: -0.375rem 0 -0.375rem 0.125rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--app-muted);
    font-size: 0.95rem;
    vertical-align: middle;
    cursor: help;
}

.help-tip:hover,
.help-tip[aria-describedby] {
    color: var(--app-primary);
    background: rgba(var(--app-primary-rgb), 0.08);
}

.help-popover {
    --bs-popover-max-width: 18rem;
    --bs-popover-font-size: 0.875rem;
    --bs-popover-body-padding-x: 0.875rem;
    --bs-popover-body-padding-y: 0.625rem;
}

/* Section titles keep the helper button aligned with the text. */
.section-title .help-tip {
    text-transform: none;
}

/* ---- User guide (/help) ---- */
.help-toc {
    position: sticky;
    top: 1rem;
}

.help-toc-link {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    margin: 0 -0.5rem;
    border-radius: var(--app-radius);
    color: var(--app-text);
    font-size: 0.9375rem;
    text-decoration: none;
}

.help-toc-link .bi {
    margin-top: 0.2em;
    color: var(--app-primary);
}

.help-toc-link:hover {
    color: var(--app-primary);
    background: rgba(var(--app-primary-rgb), 0.06);
}

.help-section {
    scroll-margin-top: 1rem;
}

.help-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: var(--app-brand);
    color: var(--app-on-brand);
    font-size: 0.75rem;
}

.help-section p,
.help-section li {
    line-height: 1.6;
}

/* Numbered steps with circles. */
.help-steps {
    counter-reset: step;
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
}

.help-steps > li {
    position: relative;
    counter-increment: step;
    padding: 0 0 0.75rem 2.25rem;
}

.help-steps > li::before {
    content: counter(step);
    position: absolute;
    top: 0.05rem;
    left: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid rgba(var(--app-primary-rgb), 0.4);
    border-radius: 50%;
    color: var(--app-primary);
    font-size: 0.75rem;
    font-weight: 600;
}

/* A button or menu name as it appears in the app. */
.ui-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.05rem 0.45rem;
    border: 1px solid var(--app-border);
    border-radius: 0.375rem;
    background: var(--app-bg);
    font-size: 0.875em;
    font-weight: 500;
    white-space: nowrap;
}

.help-callout {
    display: flex;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--app-primary);
    border-radius: var(--app-radius);
    background: rgba(var(--app-primary-rgb), 0.06);
    font-size: 0.9375rem;
}

.help-callout > .bi {
    flex-shrink: 0;
    margin-top: 0.25rem;
    color: var(--app-primary);
}

.help-callout-warning {
    border-left-color: var(--app-warning);
    background: rgba(178, 94, 0, 0.08);
}

.help-callout-warning > .bi {
    color: var(--app-warning);
}

@media (max-width: 991.98px) {
    .help-toc {
        position: static;
    }
}

.help-popover {
    --bs-popover-bg: var(--app-surface);
    --bs-popover-border-color: var(--app-border);
    --bs-popover-box-shadow: var(--app-shadow-hover);
    box-shadow: var(--app-shadow-hover);
}

/* ---- Process flow chart in the user guide (views/pages/help/partials/flow.php) ----
 * A numbered rail on the left with arrows down; side paths beside each step on
 * wide screens and under it on phones. Actors and statuses always have text. */
.flow {
    margin: 0;
    padding: 0;
    list-style: none;
}

.flow-row {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
    padding: 0 0 1.75rem 3rem;
}

/* Rail between the step numbers, ending in an arrowhead. */
.flow-row:not(:last-child)::before {
    content: "";
    position: absolute;
    top: 2.25rem;
    bottom: 0.5rem;
    left: 1.0625rem;
    width: 2px;
    background: rgba(var(--app-primary-rgb), 0.35);
}

.flow-row:not(:last-child)::after {
    content: "";
    position: absolute;
    bottom: 0.25rem;
    left: 0.75rem;
    border-top: 0.45rem solid rgba(var(--app-primary-rgb), 0.55);
    border-right: 0.35rem solid transparent;
    border-left: 0.35rem solid transparent;
}

.flow-node {
    position: absolute;
    top: 0;
    left: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--app-brand);
    color: var(--app-on-brand);
    font-weight: 700;
}

/* Decision: a diamond, like a flowchart decision box (the number stays upright). */
.flow-node-decision {
    top: -0.25rem;
    left: -0.25rem;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0;
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.flow-node-end {
    background: var(--app-success);
}

.flow-card {
    padding: 0.875rem 1rem;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-surface);
}

.flow-card-you {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 1px var(--app-primary);
}

.flow-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
}

.flow-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.flow-text {
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
}

.flow-list {
    margin-bottom: 0.5rem;
    padding-left: 1.25rem;
    font-size: 0.9375rem;
}

.flow-result {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin: 0.5rem 0 0;
    color: var(--app-muted);
    font-size: 0.875rem;
}

.flow-actor,
.flow-you {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.flow-actor { color: var(--app-text); background: rgba(92, 107, 122, 0.14); }
.flow-actor-school { color: var(--app-info); background: rgba(11, 110, 138, 0.12); }
.flow-actor-ict { color: var(--app-primary); background: rgba(var(--app-primary-rgb), 0.1); }
.flow-actor-admin { color: var(--app-warning); background: rgba(178, 94, 0, 0.12); }

.flow-you {
    color: var(--app-on-brand);
    background: var(--app-brand);
}

.flow-side {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0.875rem;
    border: 1px dashed var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-bg);
    color: var(--app-text);
    font-size: 0.875rem;
}

.flow-side > .bi {
    flex-shrink: 0;
    margin-top: 0.2rem;
    color: var(--app-muted);
}

.flow-outcomes {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.flow-outcome {
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--app-border);
    border-top-width: 3px;
    border-radius: var(--app-radius);
}

.flow-outcome-yes { border-top-color: var(--app-success); }
.flow-outcome-no { border-top-color: var(--app-warning); }
.flow-outcome-wait { border-top-color: var(--app-secondary); }

.flow-outcome-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

/* Wide screens: side paths sit beside their step, joined by a dashed connector. */
@media (min-width: 768px) {
    .flow-row {
        grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
        align-items: start;
    }

    .flow-side {
        position: relative;
        margin-top: 1.25rem;
    }

    .flow-side::before {
        content: "";
        position: absolute;
        top: 1.1rem;
        left: -0.75rem;
        width: 0.75rem;
        border-top: 1px dashed var(--app-muted);
    }

    .flow-outcomes {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .flow-decision {
        grid-column: 1 / -1;
    }
}

/* Guide sections receive focus when jumped to from the contents: a subtle ring. */
.help-section:focus-visible {
    outline: 2px solid rgba(var(--app-primary-rgb), 0.35);
    outline-offset: 2px;
}

/* ---- Welcome page (views/pages/welcome/index.php) ---- */
.welcome {
    max-width: 68rem;
    margin: 0 auto;
}

.welcome-hero {
    padding: 2rem 1.25rem;
    text-align: center;
}

.welcome-hero-icon {
    margin-bottom: 1rem;
}

.welcome-eyebrow {
    margin-bottom: 0.5rem;
    color: var(--app-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

.welcome-title {
    max-width: 40rem;
    margin: 0 auto 0.75rem;
    font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2.25rem);
    font-weight: 700;
    line-height: 1.2;
}

.welcome-lead {
    max-width: 42rem;
    margin: 0 auto 1.5rem;
    color: var(--app-muted);
    font-size: 1.0625rem;
}

.welcome-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.welcome-note {
    display: inline-flex;
    align-items: flex-start;
    gap: 0.5rem;
    max-width: 40rem;
    margin: 0;
    color: var(--app-muted);
    font-size: 0.875rem;
    text-align: left;
}

.welcome-note > .bi {
    flex-shrink: 0;
    margin-top: 0.2em;
}

.welcome-section {
    margin-top: 2.5rem;
    scroll-margin-top: 1rem;
}

.welcome-heading {
    margin-bottom: 1rem;
    font-size: 1.25rem;
    font-weight: 700;
}

.welcome-feature,
.welcome-card {
    padding: 1.25rem;
}

.welcome-feature .stat-icon {
    margin-bottom: 0.75rem;
}

.welcome-feature-title {
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-weight: 700;
}

.welcome-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.welcome-chips .ui-chip {
    white-space: normal;
}

.welcome-group {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.375rem;
    color: var(--app-primary);
    font-weight: 500;
}

.welcome-list {
    margin: 0;
    padding-left: 1.25rem;
}

.welcome-cta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2.5rem;
    padding: 1.25rem;
}

@media (min-width: 768px) {
    .welcome-hero {
        padding: 3rem 2rem;
    }
}

/* ---- Notification bell (bell.js, NotificationController) ---- */
.bell-count {
    position: absolute;
    top: -0.35rem;
    right: -0.55rem;
    min-width: 1.15rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: var(--app-danger);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1.15rem;
    text-align: center;
}

.bell-menu {
    width: min(24rem, calc(100vw - 2rem));
    overflow: hidden;
}

/* The bell sits outside the collapsible menu, so it shows on every screen size. Its menu is
   anchored to the top bar (not the small bell), right-aligned with a 1rem gutter, so it never runs
   off a phone screen; below lg Bootstrap would otherwise make navbar dropdowns static (in-flow). */
.app-navbar > .container-fluid { position: relative; }
.bell-wrap { flex-direction: row; }
.bell-wrap .dropdown { position: static; }
.bell-toggle { min-width: 2.75rem; min-height: 2.75rem; justify-content: center; } /* comfortable tap target */
.bell-wrap .dropdown-menu,
.bell-wrap .dropdown-menu[data-bs-popper] {
    position: absolute;
    top: 100%;
    right: 1rem;
    left: auto;
    margin-top: 0.25rem;
}

.bell-body {
    max-height: min(26rem, 70vh);
    overflow-y: auto;
}

.bell-section-title {
    margin: 0;
    padding: 0.625rem 1rem 0.375rem;
    color: var(--app-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* "Needs attention" rows: icon + text, so the tone is never the only signal. */
.attention-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--app-border);
    border-left-width: 4px;
    border-radius: 0.5rem;
    color: var(--app-text);
    font-size: 0.875rem;
    text-decoration: none;
    transition: background-color 0.15s ease;
}
.attention-item:hover,
.attention-item:focus-visible { background: rgba(var(--app-primary-rgb), 0.06); color: var(--app-text); }
.attention-warning { border-left-color: var(--app-warning); }
.attention-warning > .bi:first-child { color: var(--app-warning); }
.attention-danger { border-left-color: var(--app-danger); }
.attention-danger > .bi:first-child { color: var(--app-danger); }

.notification-list > li + li { border-top: 1px solid var(--app-border); }

.notification-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.625rem 1rem;
    border: 0;
    background: transparent;
    color: var(--app-text);
    font-size: 0.875rem;
    text-align: left;
    transition: background-color 0.15s ease;
}
.notification-item:hover,
.notification-item:focus-visible { background: rgba(var(--app-primary-rgb), 0.06); }
.notification-item.is-unread { font-weight: 500; }

.notification-dot {
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: transparent;
}
.notification-item.is-unread .notification-dot { background: var(--app-primary); }

@media (prefers-reduced-motion: reduce) {
    .attention-item,
    .notification-item { transition: none; }
}

/* ---- Insights charts (views/components/line-chart.php, insights.js) ----
   Series colors: dataviz reference slots 1–2 (blue, orange), validated against this
   app's surfaces (#ffffff light, #171d26 dark): CVD and normal-vision separation, contrast. */
:root {
    --viz-1: #2a78d6;
    --viz-2: #eb6834;
    --viz-grid: #e6e9ee;
    --viz-axis: #c3c9d2;
}
[data-bs-theme="dark"] {
    --viz-1: #3987e5;
    --viz-2: #d95926;
    --viz-grid: #262e3a;
    --viz-axis: #3a4454;
}

.viz-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { stroke: var(--viz-axis); stroke-width: 1; }
.viz-tick { fill: var(--app-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-end { fill: var(--app-text); font-size: 11px; font-weight: 600; }
/* The SVG scales down on phones; enlarge its text (in viewBox units) so it stays ~10px on screen. */
@media (max-width: 575.98px) {
    .viz-tick, .viz-end { font-size: 19px; }
}
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-stroke-1 { stroke: var(--viz-1); }
.viz-stroke-2 { stroke: var(--viz-2); }
.viz-fill-1 { fill: var(--viz-1); }
.viz-fill-2 { fill: var(--viz-2); }
.viz-dot { stroke: var(--app-surface); stroke-width: 2; }   /* 2px surface ring */
.viz-hit rect { fill: transparent; }
.viz-hit:focus { outline: none; }
.viz-crosshair { stroke: var(--app-muted); stroke-width: 1; opacity: 0; }
.viz-hit:hover .viz-crosshair,
.viz-hit:focus .viz-crosshair { opacity: 1; }
.viz-hit:focus-visible rect { fill: rgba(var(--app-primary-rgb), 0.06); }

.viz-key {
    display: inline-block;
    width: 1rem;
    height: 0;
    border-top: 2px solid;
    border-radius: 2px;
}
.viz-key.viz-stroke-1 { border-color: var(--viz-1); }
.viz-key.viz-stroke-2 { border-color: var(--viz-2); }

.viz-tooltip {
    position: absolute;
    z-index: 1080;
    max-width: 16rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--app-border);
    border-radius: 0.5rem;
    background: var(--app-surface);
    color: var(--app-text);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    font-size: 0.8125rem;
    pointer-events: none;
}
.viz-tooltip-title { color: var(--app-muted); font-size: 0.75rem; margin-bottom: 0.25rem; }

.tabular-nums { font-variant-numeric: tabular-nums; }

/* KPI tiles with a change vs the previous period (direction in words + arrow, never color alone). */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
    gap: 0.75rem;
}
.kpi-tile {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.875rem 1rem;
}
.kpi-label { color: var(--app-muted); font-size: 0.8125rem; }
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.kpi-delta { font-size: 0.8125rem; }
.kpi-good { color: var(--app-success); }
.kpi-bad { color: var(--app-danger); }

/* "View as school" banner (layouts/app.php): unmistakable, read-only, with the way out. */
.view-as-banner {
    position: sticky;
    top: 0;
    z-index: 1020;
    background: var(--app-warning);
    color: #fff;
    font-size: 0.875rem;
}
.view-as-banner .bi { flex: none; }
[data-bs-theme="dark"] .view-as-banner { color: #1a1206; }

/* School dashboard: quick actions and the open-JO lists. */
.quick-action {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--app-border);
    border-radius: 0.5rem;
    color: var(--app-text);
    text-decoration: none;
    transition: background-color 0.15s ease;
}
.quick-action > .bi { flex: none; margin-top: 0.2rem; color: var(--app-primary); }
.quick-action:hover,
.quick-action:focus-visible { background: rgba(var(--app-primary-rgb), 0.06); color: var(--app-text); }
.open-jo { padding: 0.375rem 0.5rem; border-radius: 0.375rem; color: var(--app-text); text-decoration: none; }
.open-jo:hover,
.open-jo:focus-visible { background: rgba(var(--app-primary-rgb), 0.06); color: var(--app-text); }
@media (prefers-reduced-motion: reduce) { .quick-action { transition: none; } }

/* ---- Mobile-first spacing and readability (CLAUDE.md §11.4, §11.8) ----
 * Phones get a 16px page gutter, compact two-up stat tiles, full-width header
 * actions with the primary one first, and tighter stacked-table cards. */
.app-main {
    padding-inline: 1rem;
}

@media (min-width: 768px) {
    .app-main {
        padding-inline: 1.5rem;
    }
}

body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

h1, .h1 {
    line-height: 1.25;
    text-wrap: balance;
}

p, li, dd {
    text-wrap: pretty;
}

@media (max-width: 575.98px) {
    .page-header {
        margin-bottom: 1rem;
    }

    /* Header actions: a full-width row; the primary action first and widest. */
    .page-header > div + div {
        width: 100%;
    }

    .page-header > div + div > .btn {
        flex: 1 1 auto;
        justify-content: center;
    }

    .page-header > div + div > .btn-primary {
        order: -1;
        flex-basis: 100%;
    }

    /* Two tiles per row: icon above the number, short hint underneath. */
    .stat-tile {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.875rem;
    }

    .stat-tile .stat-icon {
        width: 2.25rem;
        height: 2.25rem;
        border-radius: 0.625rem;
        font-size: 1.05rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-name {
        font-size: 0.9375rem;
        line-height: 1.3;
    }

    .stat-label {
        font-size: 0.75rem;
        line-height: 1.35;
        margin-top: 0.125rem;
    }

    /* Label/value rows on the JO page sit side by side with even spacing. */
    .app-card dl.row dt,
    .app-card dl.row dd {
        margin-bottom: 0.375rem;
    }
}

@media (max-width: 767.98px) {
    /* Stacked-table cards: a narrower label column and a bold first line. */
    .table-stack tr {
        padding: 0.875rem 1rem;
    }

    .table-stack td {
        align-items: baseline;
        padding: 0.15rem 0;
        min-width: 0;
        font-size: 0.9375rem;
        overflow-wrap: break-word;
    }

    .table-stack td::before {
        flex: 0 0 5.5rem;
        font-size: 0.75rem;
        line-height: 1.5;
    }

    .table-stack td:first-child {
        padding-bottom: 0.35rem;
        font-weight: 500;
    }

    /* Bigger tap targets for row links and actions. */
    .table-stack td a {
        padding-block: 0.125rem;
    }

    /* Comfortable tap targets for the form buttons. */
    .form-actions .btn {
        min-height: 2.75rem;
    }
}

/* Inputs: 16px text on phones so iOS does not zoom in when a field gets focus. */
@media (max-width: 575.98px) {
    .form-control,
    .form-select,
    .input-group-text {
        font-size: 1rem;
    }
}

/* The sticky form bar still reaches both screen edges with the wider page gutter. */
@media (max-width: 767.98px) {
    .app-main .form-actions-sticky {
        margin-inline: -1rem;
        padding-inline: 1rem;
    }
}

/* ---- Modern refresh (CLAUDE.md §11.8) ----
 * Softer surfaces, a sticky top bar, pill badges, sentence-case card titles.
 * Everything comes from the tokens above, so light and dark themes both follow. */
:root {
    --app-radius: 0.625rem;
    --app-radius-lg: 0.875rem;
    --app-bg: #f3f5f9;
    --app-border: #e1e6ee;
    --app-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --app-shadow-hover: 0 6px 16px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.05);
    --app-brand-2: #1552b5;
    /* Field outlines need 3:1 against the surface (WCAG 1.4.11). */
    --app-input-border: #8a96a5;
}

[data-bs-theme="dark"] {
    --app-bg: #0d1218;
    --app-border: #263040;
    --app-brand-2: #1d4588;
    --app-input-border: #5d6a7d;
}

/* Top bar: brand gradient, stays in view while scrolling. Jump links land below it. */
html {
    scroll-padding-top: 4.5rem;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-navbar {
    background: linear-gradient(120deg, var(--app-brand) 0%, var(--app-brand-2) 100%);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 2px 10px rgba(11, 61, 145, 0.18);
}

[data-bs-theme="dark"] .app-navbar {
    background: linear-gradient(120deg, #101a2c 0%, #14233d 100%);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.app-navbar .navbar-brand {
    font-weight: 700;
    letter-spacing: -0.01em;
}

.app-navbar .navbar-brand .brand-icon {
    padding: 0.3rem;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.16);
}

.app-navbar .nav-link {
    border-radius: var(--app-radius);
    transition: background-color 0.15s ease;
}

.app-navbar .nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* The menu expands at xl (1200px): below that it is the menu button, so labels never wrap. */
.app-navbar .nav-link {
    white-space: nowrap;
}

@media (min-width: 1200px) and (max-width: 1399.98px) {
    .app-navbar .nav-link {
        padding-inline: 0.55rem;
    }

    .app-navbar .nav-user-role {
        display: none !important;
    }
}

/* An open phone/tablet menu scrolls inside the sticky bar instead of off-screen. */
@media (max-width: 1199.98px) {
    .app-navbar .navbar-collapse {
        max-height: calc(100vh - 3.5rem);
        max-height: calc(100dvh - 3.5rem);
        overflow-y: auto;
        padding-bottom: 0.5rem;
    }
}

/* Cards: rounder, lighter edge, soft shadow. */
.app-card {
    border-radius: var(--app-radius-lg);
}

/* Page titles: tighter tracking reads as a heading, not body text. */
.page-header h1 {
    font-weight: 700;
    letter-spacing: -0.015em;
}

/* Card titles: sentence case, readable size (the markup's text-uppercase is overridden). */
.app-card h2.h6,
.app-card h2.h5,
.app-card .section-title:not(h1),
h2.section-title.text-uppercase {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.005em;
    text-transform: none !important;
}

/* Buttons: medium weight, rounder, a hint of depth on the primary action. */
.btn {
    --bs-btn-font-weight: 500;
    --bs-btn-border-radius: var(--app-radius);
    --bs-btn-padding-x: 1rem;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.btn-sm {
    --bs-btn-border-radius: 0.5rem;
    --bs-btn-padding-x: 0.75rem;
}

.btn-primary {
    box-shadow: 0 1px 2px rgba(11, 61, 145, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 4px 10px rgba(11, 61, 145, 0.25);
}

/* Inputs: white fields on cards, a brand-tinted ring on click (keyboard focus keeps the yellow ring). */
.form-control,
.form-select,
.input-group-text {
    border-color: var(--app-input-border);
    background-color: var(--app-surface);
}

.input-group-text {
    color: var(--app-muted);
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(var(--app-primary-rgb), 0.55);
    box-shadow: 0 0 0 0.2rem rgba(var(--app-primary-rgb), 0.15);
}

.form-control::placeholder {
    color: var(--app-muted);
    opacity: 0.75;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .input-group-text {
    background-color: #111720;
}

/* Badges: pills everywhere. */
.badge {
    border-radius: 999px;
    font-weight: 600;
    padding: 0.35em 0.7em;
}

/* Status pills (TicketStatus::badgeClass): tinted fill, strong text, and a dot.
   The dot is decoration; the status word is always shown (§11.7). */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    color: var(--pill-fg);
    background-color: var(--pill-bg);
    border: 1px solid var(--pill-border);
}

.status-pill::before {
    content: "";
    width: 0.45em;
    height: 0.45em;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.status-pill-primary { --pill-fg: #0b3d91; --pill-bg: #e8effb; --pill-border: #c9d8f3; }
.status-pill-info { --pill-fg: #075468; --pill-bg: #e3f4f8; --pill-border: #bfe3ec; }
.status-pill-warning { --pill-fg: #8a4a00; --pill-bg: #fff3e0; --pill-border: #f8d9ad; }
.status-pill-success { --pill-fg: #1b6a2f; --pill-bg: #e7f5eb; --pill-border: #c3e5cc; }
.status-pill-secondary { --pill-fg: #46525f; --pill-bg: #eef1f4; --pill-border: #d9dfe6; }
.status-pill-danger { --pill-fg: #9b231c; --pill-bg: #fdecea; --pill-border: #f5c9c5; }

[data-bs-theme="dark"] .status-pill-primary { --pill-fg: #a9c7fa; --pill-bg: rgba(138, 180, 248, 0.14); --pill-border: rgba(138, 180, 248, 0.3); }
[data-bs-theme="dark"] .status-pill-info { --pill-fg: #8fd8ec; --pill-bg: rgba(92, 196, 224, 0.13); --pill-border: rgba(92, 196, 224, 0.3); }
[data-bs-theme="dark"] .status-pill-warning { --pill-fg: #f6c07f; --pill-bg: rgba(240, 164, 75, 0.14); --pill-border: rgba(240, 164, 75, 0.32); }
[data-bs-theme="dark"] .status-pill-success { --pill-fg: #8edba2; --pill-bg: rgba(95, 199, 123, 0.13); --pill-border: rgba(95, 199, 123, 0.3); }
[data-bs-theme="dark"] .status-pill-secondary { --pill-fg: #c3ccd6; --pill-bg: rgba(154, 167, 182, 0.14); --pill-border: rgba(154, 167, 182, 0.3); }
[data-bs-theme="dark"] .status-pill-danger { --pill-fg: #ffaba3; --pill-bg: rgba(255, 138, 128, 0.13); --pill-border: rgba(255, 138, 128, 0.3); }

/* Tables: roomier rows and a soft hover. */
.app-card .table > :not(caption) > * > * {
    padding-block: 0.7rem;
}

.app-card .table thead th {
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    border-bottom-color: var(--app-border);
}

/* Dropdown menus: rounded, floating. */
.dropdown-menu {
    --bs-dropdown-border-radius: var(--app-radius-lg);
    --bs-dropdown-border-color: var(--app-border);
    --bs-dropdown-box-shadow: 0 10px 30px rgba(16, 24, 40, 0.12);
    --bs-dropdown-link-active-bg: var(--app-brand);
    box-shadow: var(--bs-dropdown-box-shadow);
    padding: 0.375rem;
}

.dropdown-item {
    border-radius: 0.5rem;
}

/* Alerts and modals follow the rounder shape. */
.alert {
    --bs-alert-border-radius: var(--app-radius-lg);
}

.modal {
    --bs-modal-border-radius: 1rem;
}

@media (prefers-reduced-motion: reduce) {
    .btn,
    .app-navbar .nav-link {
        transition: none;
    }
}

/* Fields keep their surface colour while focused (Bootstrap would switch to the page colour). */
.form-control:focus,
.form-select:focus {
    background-color: var(--app-surface);
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: #111720;
}

/* Password field + show/hide button read as one control. */
.input-group > .form-control:has(+ [data-password-toggle]:not([hidden])) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group > [data-password-toggle] {
    --bs-btn-border-color: var(--app-input-border);
    --bs-btn-color: var(--app-muted);
}

/* Login and password pages: a soft brand wash behind the card. */
.auth-page {
    background:
        radial-gradient(60rem 30rem at 50% -10rem, rgba(var(--app-primary-rgb), 0.12), transparent 70%),
        var(--app-bg);
}

.auth-card {
    border-radius: 1rem;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.04);
}

/* Poppins is wider than the system font: on phones keep the brand, bell, and menu button on one line. */
@media (max-width: 575.98px) {
    .app-navbar .navbar-brand {
        margin-right: 0.5rem;
        font-size: 1.05rem;
    }

    .app-navbar .navbar-brand .brand-icon {
        width: 1.7rem;
        height: 1.7rem;
    }
}

.app-navbar .brand-short {
    display: none;
}

/* The smallest phones show the short name; the full name stays for screen readers. */
@media (max-width: 359.98px) {
    .app-navbar .brand-full {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .app-navbar .brand-short {
        display: inline;
    }
}

/* ---- Bottom tab bar on phones (views/components/bottom-nav.php) ----
 * Below 768px the main places are one thumb-tap away; "More" opens the full top menu,
 * which replaces the top menu button there. Labels are always shown (never icon-only). */
:root {
    --bottom-nav-h: 3.75rem;
}

.bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    .bottom-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1030;
        display: flex;
        align-items: stretch;
        padding: 0 0.25rem env(safe-area-inset-bottom);
        background: rgba(255, 255, 255, 0.92);
        border-top: 1px solid var(--app-border);
        box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.06);
        -webkit-backdrop-filter: saturate(180%) blur(12px);
        backdrop-filter: saturate(180%) blur(12px);
    }

    [data-bs-theme="dark"] .bottom-nav {
        background: rgba(23, 29, 38, 0.92);
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35);
    }

    .has-bottom-nav {
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    }

    /* "More" in the bottom bar opens the menu, so the top bar keeps just the brand and the bell. */
    .has-bottom-nav .app-navbar .navbar-toggler {
        display: none;
    }

    .has-bottom-nav .app-navbar .navbar-collapse {
        max-height: calc(100dvh - 3.5rem - var(--bottom-nav-h) - env(safe-area-inset-bottom));
    }

    /* Long forms: the sticky Submit bar sits above the tab bar (older browsers), and where :has()
       works the tab bar steps aside so the form gets the whole screen. */
    .has-bottom-nav .form-actions-sticky {
        bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    }

    .has-bottom-nav:has(.form-actions-sticky) {
        padding-bottom: 0;
    }

    .has-bottom-nav:has(.form-actions-sticky) .bottom-nav {
        display: none;
    }

    .has-bottom-nav:has(.form-actions-sticky) .form-actions-sticky {
        bottom: 0;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
}

.bottom-nav-item {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    min-width: 0;
    min-height: var(--bottom-nav-h);
    padding: 0.375rem 0.125rem;
    color: var(--app-muted);
    font: inherit;
    font-size: 0.6875rem;
    line-height: 1.2;
    text-decoration: none;
    background: none;
    border: 0;
}

.bottom-nav-item:hover {
    color: var(--app-primary);
}

.bottom-nav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The icon sits in a pill that fills in for the current page (with aria-current, not colour alone). */
.bottom-nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.25rem;
    height: 1.75rem;
    border-radius: 999px;
    font-size: 1.2rem;
    transition: background-color 0.15s ease;
}

.bottom-nav-item.active,
.bottom-nav-item[aria-expanded="true"] {
    color: var(--app-primary);
    font-weight: 500;
}

.bottom-nav-item.active .bottom-nav-icon,
.bottom-nav-item[aria-expanded="true"] .bottom-nav-icon {
    background: rgba(var(--app-primary-rgb), 0.14);
}

/* "New JO": the main action, a raised brand circle. */
.bottom-nav-primary .bottom-nav-icon {
    width: 2.75rem;
    height: 2.75rem;
    margin-top: -1.1rem;
    color: var(--app-on-brand);
    background: linear-gradient(135deg, var(--app-brand), var(--app-brand-2));
    box-shadow: 0 4px 12px rgba(11, 61, 145, 0.35);
    font-size: 1.3rem;
}

.bottom-nav-primary.active .bottom-nav-icon {
    background: linear-gradient(135deg, var(--app-brand-active), var(--app-brand));
}

.bottom-nav-item:focus-visible {
    outline-offset: -3px;
    border-radius: 0.75rem;
}

@media (prefers-reduced-motion: reduce) {
    .bottom-nav-icon {
        transition: none;
    }
}
