/* ==========================================================================
   Noori Madrasa — Design System
   --------------------------------------------------------------------------
   A single, dependency-free stylesheet layered over Bootstrap 5.3. It defines
   the design tokens first, then restyles Bootstrap's primitives so that every
   existing screen inherits the system, then adds the components Bootstrap has
   no equivalent for (app shell, command palette, stat tiles, skeletons).

   Structure:
     1.  Tokens
     2.  Base & typography
     3.  Accessibility primitives (focus, skip link, reduced motion)
     4.  App shell (sidebar, topbar, breadcrumbs, content)
     5.  Command palette & global search
     6.  Buttons
     7.  Forms & inputs
     8.  Cards & surfaces
     9.  Stat tiles & data visualisation
     10. Tables
     11. Badges & status
     12. Dialogs, dropdowns, toasts
     13. Empty & loading states
     14. Utilities
     15. Print
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
    /* Brand — a deep academic emerald. Chosen to read as institutional rather
       than consumer-blue, and to sit comfortably beside the madrasa's identity. */
    --brand-50:  #eef7f4;
    --brand-100: #d6ece5;
    --brand-200: #aed9cd;
    --brand-300: #7cbfae;
    --brand-400: #4a9f8b;
    --brand-500: #2b806d;
    --brand-600: #1c6656;
    --brand-700: #175346;
    --brand-800: #134238;
    --brand-900: #0f342d;

    /* Accent — warm gold, used sparingly for favourites and highlights. */
    --gold-100: #f7edd8;
    --gold-500: #b1863b;
    --gold-600: #946d2c;

    /* Neutrals — very slightly warm so large white areas feel like paper. */
    --ink-950: #10161c;
    --ink-900: #18212b;
    --ink-800: #26313d;
    --ink-700: #3a4756;
    --ink-600: #566374;
    --ink-500: #737f8f;
    --ink-400: #97a1ae;
    --ink-300: #c2c9d2;
    --ink-200: #dde2e8;
    --ink-100: #edf0f3;
    --ink-50:  #f6f8fa;

    /* Semantic status. All text-on-surface pairings below meet WCAG AA. */
    --success-50:  #e9f6ed;  --success-600: #1a7f3c;  --success-700: #14632f;
    --warning-50:  #fdf3e3;  --warning-600: #9a6413;  --warning-700: #7c500f;
    --danger-50:   #fdecec;  --danger-600:  #b3261e;  --danger-700:  #8f1e18;
    --info-50:     #eaf1fd;  --info-600:    #1f4fb6;  --info-700:    #1a3f92;

    /* Surfaces */
    --bg:            #f4f6f8;
    --surface:       #ffffff;
    --surface-sunk:  #fafbfc;
    --surface-raised:#ffffff;
    --border:        var(--ink-200);
    --border-strong: var(--ink-300);

    /* Text roles */
    --text:          var(--ink-900);
    --text-secondary:var(--ink-600);
    --text-muted:    var(--ink-500);
    --text-inverse:  #ffffff;

    /* Typography — system stack, so there is no webfont round-trip and the UI
       matches the host OS. Data is rendered with tabular figures. */
    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text",
                 "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono", Consolas, monospace;

    --text-xs:   0.75rem;    /* 12 */
    --text-sm:   0.8125rem;  /* 13 */
    --text-base: 0.9375rem;  /* 15 — comfortable default for dense admin UI */
    --text-md:   1rem;       /* 16 */
    --text-lg:   1.125rem;   /* 18 */
    --text-xl:   1.375rem;   /* 22 */
    --text-2xl:  1.75rem;    /* 28 */
    --text-3xl:  2.25rem;    /* 36 */

    --leading-tight: 1.25;
    --leading-normal: 1.55;

    /* Spacing — 4px base grid. */
    --space-1: 0.25rem;  --space-2: 0.5rem;   --space-3: 0.75rem;
    --space-4: 1rem;     --space-5: 1.5rem;   --space-6: 2rem;
    --space-7: 2.5rem;   --space-8: 3rem;     --space-9: 4rem;

    /* Radii */
    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-pill: 999px;

    /* Depth — layered, low-opacity shadows rather than one heavy blur. */
    --shadow-xs: 0 1px 2px rgba(16, 22, 28, 0.05);
    --shadow-sm: 0 1px 2px rgba(16, 22, 28, 0.06), 0 1px 3px rgba(16, 22, 28, 0.04);
    --shadow-md: 0 2px 4px rgba(16, 22, 28, 0.05), 0 4px 12px rgba(16, 22, 28, 0.06);
    --shadow-lg: 0 8px 20px rgba(16, 22, 28, 0.09), 0 2px 6px rgba(16, 22, 28, 0.05);
    --shadow-xl: 0 24px 48px rgba(16, 22, 28, 0.16), 0 8px 16px rgba(16, 22, 28, 0.08);

    /* Motion — a single easing curve used everywhere for coherence. */
    --ease: cubic-bezier(0.32, 0.72, 0, 1);
    --duration-fast: 120ms;
    --duration: 200ms;
    --duration-slow: 320ms;

    /* Layout */
    --sidebar-w: 264px;
    --topbar-h: 60px;
    --content-max: 1400px;

    --focus-ring: 0 0 0 3px rgba(28, 102, 86, 0.28);
    --z-sticky: 20;
    --z-topbar: 40;
    --z-sidebar: 50;
    --z-overlay: 90;
    --z-toast: 100;
}

/* --------------------------------------------------------------------------
   2. Base & typography
   -------------------------------------------------------------------------- */

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

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv05" 1;
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
    color: var(--ink-950);
    font-weight: 640;
    letter-spacing: -0.015em;
    line-height: var(--leading-tight);
}

h1, .h1 { font-size: var(--text-2xl); letter-spacing: -0.022em; }
h2, .h2 { font-size: var(--text-xl); }
h3, .h3 { font-size: var(--text-lg); }
h4, .h4 { font-size: var(--text-md); }

a { color: var(--brand-600); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-700); }

hr { border-color: var(--border); opacity: 1; }

.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }

/* Numerals in data contexts must align vertically across rows. */
.tabular, td, th, .stat-value, .metric { font-variant-numeric: tabular-nums; }

/* Section eyebrow used above grouped content. */
.eyebrow {
    font-size: var(--text-xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   3. Accessibility primitives
   -------------------------------------------------------------------------- */

/* One visible focus treatment for every interactive element. :focus-visible so
   pointer users are not shown rings, keyboard users always are. */
*:focus { outline: none; }
*:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.skip-link {
    position: absolute;
    left: var(--space-4);
    top: -100px;
    z-index: 200;
    padding: var(--space-3) var(--space-4);
    background: var(--brand-700);
    color: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-weight: 600;
    transition: top var(--duration) var(--ease);
}
.skip-link:focus { top: var(--space-4); color: #fff; }

.visually-hidden-focusable:not(:focus):not(:focus-within) {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}

/* Every interactive target is at least 44×44 on touch pointers. */
@media (pointer: coarse) {
    .btn, .nav-link, .table-action, .sidebar-link, select, input, textarea {
        min-height: 44px;
    }
}

@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;
    }
}

@media (prefers-contrast: more) {
    :root {
        --border: var(--ink-400);
        --border-strong: var(--ink-600);
        --text-secondary: var(--ink-800);
        --text-muted: var(--ink-700);
    }
}

/* --------------------------------------------------------------------------
   4. App shell
   -------------------------------------------------------------------------- */

.app { min-height: 100vh; }

.app-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-w);
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    background: var(--brand-900);
    color: rgba(255, 255, 255, 0.75);
    border-inline-end: 1px solid rgba(255, 255, 255, 0.06);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    min-height: var(--topbar-h);
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.app-brand:hover { color: #fff; }
.app-brand-mark {
    width: 34px; height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: linear-gradient(145deg, var(--brand-400), var(--brand-600));
    color: #fff;
    font-weight: 700;
    font-size: var(--text-sm);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.app-brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.app-brand-name { font-weight: 640; font-size: var(--text-md); letter-spacing: -0.01em; }
.app-brand-sub { font-size: var(--text-xs); color: rgba(255, 255, 255, 0.55); }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: var(--space-4) var(--space-3); }

.sidebar-section + .sidebar-section { margin-top: var(--space-5); }
.sidebar-heading {
    padding: 0 var(--space-3) var(--space-2);
    font-size: var(--text-xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.42);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    margin-bottom: 2px;
    border-radius: var(--radius);
    color: rgba(255, 255, 255, 0.78);
    text-decoration: none;
    font-size: var(--text-base);
    font-weight: 500;
    transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.sidebar-link i { font-size: 1.05rem; width: 1.25rem; text-align: center; flex: none; opacity: 0.85; }
.sidebar-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sidebar-link:focus-visible { outline-color: #fff; }
.sidebar-link.is-active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 2px 0 0 var(--brand-300);
}
.sidebar-link .badge { margin-inline-start: auto; }

.sidebar-footer {
    padding: var(--space-3);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
}
.avatar {
    width: 34px; height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--radius-pill);
    background: var(--brand-500);
    color: #fff;
    font-weight: 640;
    font-size: var(--text-sm);
    text-transform: uppercase;
}
/* --------------------------------------------------------------------------
   Mobile step navigation (see partials/mobile-step-filter.blade.php)

   Everything here is inert above the lg breakpoint: the wizard never shows on
   desktop, and the .stepnav-hidden class it puts on the list only takes effect
   inside the media query, so a phone-to-desktop resize cannot strand the page
   with its table hidden.
   -------------------------------------------------------------------------- */

.stepnav { display: none; }
.stepnav-crumbs { display: none; }

@media (max-width: 991.98px) {
    .stepnav.is-active {
        display: block;
        padding: var(--space-5) var(--space-4) var(--space-6);
    }
    .stepnav-hidden { display: none !important; }

    .stepnav-eyebrow {
        font-size: var(--text-xs);
        font-weight: 650;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--text-muted);
        margin: 0 0 var(--space-1);
    }

    .stepnav-title {
        font-size: var(--text-xl);
        margin: 0 0 var(--space-4);
    }

    .stepnav-back {
        display: inline-flex;
        align-items: center;
        gap: var(--space-1);
        margin-bottom: var(--space-3);
        padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2);
        border: 0;
        border-radius: var(--radius);
        background: transparent;
        color: var(--brand-600);
        font-size: var(--text-sm);
        font-weight: 600;
    }
    .stepnav-back:active { background: var(--ink-100); }

    .stepnav-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
    }

    /* Deliberately tall: these are the primary targets on the screen, and one
       mis-tap costs the user the whole step. */
    .stepnav-option {
        width: 100%;
        min-height: 64px;
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-4);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-xs);
        text-align: left;
    }
    .stepnav-option:active { background: var(--brand-50); border-color: var(--brand-300); }

    .stepnav-option-label {
        flex: 1;
        min-width: 0;
        font-size: var(--text-md);
        font-weight: 600;
        color: var(--text);
    }

    .stepnav-option-meta {
        flex: none;
        font-size: var(--text-sm);
        color: var(--text-muted);
        font-variant-numeric: tabular-nums;
    }

    .stepnav-option-arrow { flex: none; color: var(--ink-400); }

    .stepnav-crumbs {
        display: flex;
        align-items: center;
        gap: var(--space-1);
        flex-wrap: wrap;
        padding: var(--space-3) var(--space-4);
        border-bottom: 1px solid var(--border);
        background: var(--surface-sunk);
    }
    .stepnav-crumbs[hidden] { display: none; }

    .stepnav-crumb {
        padding: var(--space-1) var(--space-3);
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        background: var(--surface);
        color: var(--brand-700);
        font-size: var(--text-sm);
        font-weight: 600;
    }
    .stepnav-crumb:active { background: var(--brand-50); }
    .stepnav-crumb-sep { color: var(--text-muted); }
}

/* --------------------------------------------------------------------------
   Marks selection action bar

   Desktop keeps the labelled buttons. On a phone the same four buttons become
   one row of icons pinned to the bottom -- four stacked full-width buttons
   were taking half the screen. The markup is shared, so the two cannot drift
   apart; only what is shown differs.
   -------------------------------------------------------------------------- */

.marks-action-icon { display: none; }

@media (max-width: 575.98px) {
    .marks-actions { padding-bottom: env(safe-area-inset-bottom, 0); }

    /* !important because Bootstrap's .d-grid on this row is itself !important;
       without it the buttons stay stacked and the bar keeps its full height. */
    .marks-actions .marks-actions-row {
        display: flex !important;
        gap: var(--space-2);
    }

    .marks-actions-row .btn {
        flex: 1 1 0;
        min-width: 0;
        padding: var(--space-3) var(--space-2);
        font-size: var(--text-lg);
        line-height: 1;
    }

    .marks-action-icon { display: inline-block; }
    .marks-action-label { display: none; }

    /* The count and the hint both stay: the count is what the two marks
       buttons act on, and the hint is the only thing explaining why they are
       disabled. Only the footnote goes -- it describes one button that now
       says what it does through its icon and label. */
    .marks-actions-status { margin-bottom: var(--space-2) !important; font-size: var(--text-sm); }
    .marks-actions-note { display: none; }
}

.avatar-lg { width: 56px; height: 56px; font-size: var(--text-lg); }
.avatar-xl { width: 84px; height: 84px; font-size: var(--text-2xl); }
.sidebar-username { color: #fff; font-weight: 560; font-size: var(--text-sm); }
.sidebar-role { font-size: var(--text-xs); color: rgba(255, 255, 255, 0.55); }

/* Mobile: sidebar becomes an overlay drawer. */
.sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(16, 22, 28, 0.45);
    backdrop-filter: blur(2px);
    z-index: var(--z-overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration) var(--ease);
}
body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform var(--duration-slow) var(--ease);
        box-shadow: var(--shadow-xl);
        z-index: calc(var(--z-overlay) + 1);
    }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
}

.app-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-inline-start: var(--sidebar-w);
}
@media (max-width: 991.98px) { .app-main { margin-inline-start: 0; } }

.app-topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--topbar-h);
    padding: var(--space-2) var(--space-5);
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border);
}
@media (max-width: 575.98px) { .app-topbar { padding-inline: var(--space-3); } }

.topbar-toggle {
    display: none;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    width: 38px; height: 38px;
    color: var(--ink-700);
}
@media (max-width: 991.98px) { .topbar-toggle { display: grid; place-items: center; } }

.app-content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin-inline: auto;
    padding: var(--space-6) var(--space-5) var(--space-9);
}
@media (max-width: 575.98px) { .app-content { padding: var(--space-4) var(--space-3) var(--space-8); } }

/* Page header — the consistent top of every screen. */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}
.page-title { margin: 0; font-size: var(--text-2xl); }
.page-subtitle { margin: var(--space-1) 0 0; color: var(--text-secondary); font-size: var(--text-base); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* Breadcrumbs */
.breadcrumb-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    min-width: 0;
}
.breadcrumb-bar a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb-bar a:hover { color: var(--brand-600); text-decoration: underline; }
.breadcrumb-bar .sep { color: var(--ink-300); }
.breadcrumb-bar .current { color: var(--text); font-weight: 550; }

/* --------------------------------------------------------------------------
   5. Command palette & global search
   -------------------------------------------------------------------------- */

.global-search {
    position: relative;
    flex: 1;
    max-width: 460px;
}
.global-search-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--ink-50);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: var(--text-sm);
    text-align: start;
    transition: border-color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.global-search-btn:hover { background: var(--surface); border-color: var(--border-strong); }
.global-search-btn .label { flex: 1; }

.kbd {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    line-height: 1.4;
}

.palette-backdrop {
    position: fixed; inset: 0;
    z-index: var(--z-toast);
    display: none;
    padding: 10vh var(--space-4) var(--space-4);
    background: rgba(16, 22, 28, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.palette-backdrop.is-open { display: block; }

.palette {
    max-width: 620px;
    margin-inline: auto;
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: palette-in var(--duration) var(--ease);
}
@keyframes palette-in {
    from { opacity: 0; transform: translateY(-8px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}

.palette-input-wrap {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}
.palette-input {
    flex: 1;
    border: 0;
    background: transparent;
    font-size: var(--text-lg);
    color: var(--text);
}
.palette-input::placeholder { color: var(--text-muted); }
.palette-input:focus { outline: none; }

.palette-results { max-height: 46vh; overflow-y: auto; padding: var(--space-2); }
.palette-group-label {
    padding: var(--space-3) var(--space-3) var(--space-1);
    font-size: var(--text-xs);
    font-weight: 650;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.palette-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3);
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    text-align: start;
    text-decoration: none;
    font-size: var(--text-base);
}
.palette-item i { color: var(--text-muted); width: 1.25rem; text-align: center; }
.palette-item .meta { margin-inline-start: auto; font-size: var(--text-xs); color: var(--text-muted); }
.palette-item.is-active,
.palette-item:hover { background: var(--brand-50); color: var(--brand-800); }
.palette-item.is-active i, .palette-item:hover i { color: var(--brand-600); }

.palette-footer {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
    background: var(--surface-sunk);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   6. Buttons
   -------------------------------------------------------------------------- */

.btn {
    --btn-bg: var(--surface);
    --btn-fg: var(--ink-800);
    --btn-border: var(--border-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0.5rem 0.9rem;
    min-height: 38px;
    font-size: var(--text-base);
    font-weight: 550;
    line-height: 1.2;
    color: var(--btn-fg);
    background-color: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    transition: transform var(--duration-fast) var(--ease),
                box-shadow var(--duration-fast) var(--ease),
                background-color var(--duration-fast) var(--ease),
                border-color var(--duration-fast) var(--ease);
}
.btn:hover { box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0.5px) scale(0.995); box-shadow: var(--shadow-xs); }
.btn:disabled, .btn.disabled { opacity: 0.5; box-shadow: none; transform: none; }

.btn-lg { min-height: 46px; padding: 0.65rem 1.25rem; font-size: var(--text-md); border-radius: var(--radius-lg); }
.btn-sm { min-height: 32px; padding: 0.3rem 0.65rem; font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn-icon { padding: 0; width: 38px; }
.btn-icon.btn-sm { width: 32px; }

.btn-primary {
    --btn-bg: var(--brand-600);
    --btn-fg: #fff;
    --btn-border: var(--brand-700);
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.btn-primary:hover { --btn-bg: var(--brand-700); --btn-fg: #fff; }
.btn-primary:active { --btn-bg: var(--brand-800); }

.btn-secondary, .btn-outline-secondary {
    --btn-bg: var(--surface);
    --btn-fg: var(--ink-800);
    --btn-border: var(--border-strong);
}
.btn-secondary:hover, .btn-outline-secondary:hover {
    --btn-bg: var(--ink-50);
    --btn-fg: var(--ink-900);
    --btn-border: var(--ink-400);
}

.btn-outline-primary { --btn-bg: var(--surface); --btn-fg: var(--brand-700); --btn-border: var(--brand-200); }
.btn-outline-primary:hover { --btn-bg: var(--brand-50); --btn-fg: var(--brand-800); --btn-border: var(--brand-300); }

.btn-success, .btn-outline-success { --btn-bg: var(--surface); --btn-fg: var(--success-700); --btn-border: #b7dcc3; }
.btn-success:hover, .btn-outline-success:hover { --btn-bg: var(--success-50); --btn-fg: var(--success-700); }

.btn-danger { --btn-bg: var(--danger-600); --btn-fg: #fff; --btn-border: var(--danger-700); }
.btn-danger:hover { --btn-bg: var(--danger-700); --btn-fg: #fff; }
.btn-outline-danger { --btn-bg: var(--surface); --btn-fg: var(--danger-600); --btn-border: #f0c4c1; }
.btn-outline-danger:hover { --btn-bg: var(--danger-50); --btn-fg: var(--danger-700); --btn-border: #e2a7a3; }

.btn-ghost {
    --btn-bg: transparent;
    --btn-fg: var(--ink-700);
    --btn-border: transparent;
    box-shadow: none;
}
.btn-ghost:hover { --btn-bg: var(--ink-100); --btn-fg: var(--ink-900); box-shadow: none; }

.btn-link { --btn-bg: transparent; --btn-border: transparent; --btn-fg: var(--brand-600); box-shadow: none; }

/* Loading state: the label stays for width stability, a spinner replaces it. */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
    content: "";
    position: absolute;
    width: 15px; height: 15px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    color: var(--btn-fg);
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-group > .btn { box-shadow: none; }

/* --------------------------------------------------------------------------
   7. Forms & inputs
   -------------------------------------------------------------------------- */

.form-label {
    font-size: var(--text-sm);
    font-weight: 580;
    color: var(--ink-800);
    margin-bottom: var(--space-2);
}
.form-label .req { color: var(--danger-600); margin-inline-start: 2px; }

.form-control, .form-select {
    padding: 0.5rem 0.75rem;
    min-height: 40px;
    font-size: var(--text-base);
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--duration-fast) var(--ease),
                box-shadow var(--duration-fast) var(--ease);
}
.form-control::placeholder { color: var(--ink-400); }
.form-control:hover:not(:disabled), .form-select:hover:not(:disabled) { border-color: var(--ink-400); }
.form-control:focus, .form-select:focus {
    border-color: var(--brand-500);
    box-shadow: var(--focus-ring);
    outline: none;
}
.form-control:disabled, .form-select:disabled,
.form-control[readonly] {
    background-color: var(--ink-50);
    color: var(--text-muted);
    box-shadow: none;
}
textarea.form-control { min-height: 96px; line-height: var(--leading-normal); }

.form-text { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); }

/* Validation — colour is never the only signal; an icon and message accompany it. */
.form-control.is-invalid, .form-select.is-invalid,
.was-validated .form-control:invalid {
    border-color: var(--danger-600);
    box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.12);
    background-image: none;
    padding-right: 0.75rem;
}
.invalid-feedback {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--danger-700);
    margin-top: var(--space-2);
}
.invalid-feedback::before {
    content: "\F33A"; /* bi-exclamation-circle-fill */
    font-family: "bootstrap-icons";
    font-size: 0.9em;
    line-height: 1.5;
    flex: none;
}
.form-control.is-valid, .form-select.is-valid { border-color: var(--success-600); background-image: none; }

.form-check-input {
    width: 1.05em; height: 1.05em;
    margin-top: 0.22em;
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-xs);
    transition: background-color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.form-check-input:checked { background-color: var(--brand-600); border-color: var(--brand-700); }
.form-check-input:focus { border-color: var(--brand-500); box-shadow: var(--focus-ring); }
.form-check-label { font-size: var(--text-base); }

.input-group-text {
    background: var(--ink-50);
    border-color: var(--border-strong);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/* Form sections — the organising unit of every form screen. */
.form-section { display: grid; grid-template-columns: 260px 1fr; gap: var(--space-6); padding: var(--space-6) 0; }
.form-section + .form-section { border-top: 1px solid var(--border); }
.form-section:first-child { padding-top: var(--space-2); }
.form-section-title { margin: 0 0 var(--space-1); font-size: var(--text-md); font-weight: 620; }
.form-section-help { margin: 0; font-size: var(--text-sm); color: var(--text-secondary); }
.form-section-body { min-width: 0; }
@media (max-width: 991.98px) {
    .form-section { grid-template-columns: 1fr; gap: var(--space-4); }
}

/* Sticky action bar for long forms. */
.form-actions {
    position: sticky;
    bottom: 0;
    z-index: var(--z-sticky);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    margin: var(--space-6) calc(var(--space-5) * -1) calc(var(--space-5) * -1);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.form-actions .spacer { margin-inline-end: auto; font-size: var(--text-sm); color: var(--text-muted); }

/* Tom Select — align the third-party control with the system. */
.ts-wrapper .ts-control {
    min-height: 40px;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    font-size: var(--text-base);
}
.ts-wrapper.focus .ts-control { border-color: var(--brand-500); box-shadow: var(--focus-ring); }
.ts-wrapper .ts-control > .item {
    background: var(--brand-50);
    color: var(--brand-800);
    border: 1px solid var(--brand-200);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 550;
}
.ts-dropdown {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-base);
}
.ts-dropdown .active { background: var(--brand-50); color: var(--brand-800); }

/* --------------------------------------------------------------------------
   8. Cards & surfaces
   -------------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: var(--space-5); }
@media (max-width: 575.98px) { .card-body { padding: var(--space-4); } }

.card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: transparent;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.card-header h2, .card-header h3, .card-title { margin: 0; font-size: var(--text-md); font-weight: 620; }
.card-header .subtitle { margin: 2px 0 0; font-size: var(--text-sm); color: var(--text-secondary); font-weight: 400; }
.card-footer {
    padding: var(--space-3) var(--space-5);
    background: var(--surface-sunk);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.card-interactive { transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease); }
.card-interactive:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }

/* Definition list used on detail screens. */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-5) var(--space-6); }
.detail-item { min-width: 0; }
.detail-label { font-size: var(--text-xs); font-weight: 620; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--space-1); }
.detail-value { font-size: var(--text-base); color: var(--text); overflow-wrap: anywhere; }
.detail-value.is-empty { color: var(--ink-400); font-style: italic; }

/* --------------------------------------------------------------------------
   9. Stat tiles & data visualisation
   -------------------------------------------------------------------------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--space-4); }

.stat-tile {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
a.stat-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: var(--brand-200); color: inherit; }

.stat-head { display: flex; align-items: center; gap: var(--space-3); }
.stat-icon {
    width: 34px; height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: var(--brand-50);
    color: var(--brand-600);
    font-size: 1rem;
}
.stat-icon.is-success { background: var(--success-50); color: var(--success-600); }
.stat-icon.is-warning { background: var(--warning-50); color: var(--warning-600); }
.stat-icon.is-danger  { background: var(--danger-50);  color: var(--danger-600); }
.stat-icon.is-info    { background: var(--info-50);    color: var(--info-600); }

.stat-label { font-size: var(--text-sm); font-weight: 560; color: var(--text-secondary); }
.stat-value { font-size: var(--text-3xl); font-weight: 660; letter-spacing: -0.03em; line-height: 1.1; color: var(--ink-950); }
.stat-meta { font-size: var(--text-sm); color: var(--text-muted); }

.trend { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-sm); font-weight: 580; }
.trend.is-up { color: var(--success-600); }
.trend.is-down { color: var(--danger-600); }
.trend.is-flat { color: var(--text-muted); }

/* Meter — a labelled proportional bar, used for distributions and averages. */
.meter { display: block; }
.meter-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.meter-label { font-size: var(--text-sm); color: var(--text); font-weight: 520; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter-value { font-size: var(--text-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; flex: none; }
.meter-track { height: 8px; background: var(--ink-100); border-radius: var(--radius-pill); overflow: hidden; }
.meter-fill {
    display: block;
    height: 100%;
    border-radius: var(--radius-pill);
    background: var(--brand-500);
    transition: width var(--duration-slow) var(--ease);
}
.meter-fill.is-success { background: var(--success-600); }
.meter-fill.is-warning { background: var(--warning-600); }
.meter-fill.is-danger  { background: var(--danger-600); }
.meter + .meter { margin-top: var(--space-4); }

/* Bar chart — CSS only, no charting dependency. */
.chart-bars { display: flex; align-items: flex-end; gap: var(--space-2); height: 168px; padding-top: var(--space-4); }
.chart-bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: var(--space-2); min-width: 0; height: 100%; }
.chart-bar-fill {
    width: 100%;
    max-width: 46px;
    background: linear-gradient(180deg, var(--brand-400), var(--brand-600));
    border-radius: var(--radius-sm) var(--radius-sm) 2px 2px;
    min-height: 3px;
    transition: filter var(--duration) var(--ease);
}
.chart-bar:hover .chart-bar-fill { filter: brightness(1.08); }
.chart-bar-label { font-size: var(--text-xs); color: var(--text-muted); text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-bar-value { font-size: var(--text-xs); font-weight: 620; color: var(--ink-800); font-variant-numeric: tabular-nums; }

.legend { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-5); font-size: var(--text-sm); color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: var(--space-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* --------------------------------------------------------------------------
   10. Tables
   -------------------------------------------------------------------------- */

.table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table-scroll { overflow-x: auto; overflow-y: visible; max-height: 68vh; }

.table {
    --bs-table-bg: transparent;
    margin: 0;
    font-size: var(--text-base);
    color: var(--text);
    border-color: var(--border);
}

.table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    padding: var(--space-3) var(--space-4);
    background: var(--surface-sunk);
    border-bottom: 1px solid var(--border);
    font-size: var(--text-xs);
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    white-space: nowrap;
    vertical-align: middle;
}
/* A shadow under the sticky header makes the layer relationship legible. */
.table > thead > tr > th::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    bottom: -1px;
    height: 1px;
    background: var(--border);
}

.table > tbody > tr > td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--ink-100);
    vertical-align: middle;
}
.table > tbody > tr:last-child > td { border-bottom: 0; }
.table > tbody > tr { transition: background-color var(--duration-fast) var(--ease); }
.table-hover > tbody > tr:hover > * { background-color: var(--brand-50); }
.table > tbody > tr.is-selected > td { background-color: var(--brand-50); box-shadow: inset 2px 0 0 var(--brand-500); }

/* Sortable column headers. */
.th-sort { cursor: pointer; user-select: none; }
.th-sort .sort-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
}
.th-sort .sort-ind { opacity: 0.35; font-size: 0.85em; transition: opacity var(--duration-fast) var(--ease); }
.th-sort:hover .sort-ind { opacity: 0.7; }
.th-sort[aria-sort="ascending"] .sort-ind,
.th-sort[aria-sort="descending"] .sort-ind { opacity: 1; color: var(--brand-600); }

.cell-primary { font-weight: 560; color: var(--ink-900); }
.cell-secondary { font-size: var(--text-sm); color: var(--text-muted); }
.cell-id { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }

/* Row actions reveal on hover but remain permanently visible on touch and to
   keyboard users, so they are never unreachable. */
.row-actions { display: flex; gap: var(--space-1); justify-content: flex-end; }
.row-actions .btn { opacity: 0; transition: opacity var(--duration-fast) var(--ease); }
tr:hover .row-actions .btn,
tr:focus-within .row-actions .btn { opacity: 1; }
@media (hover: none) { .row-actions .btn { opacity: 1; } }

/* Bulk selection bar. */
.bulk-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--brand-800);
    color: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.bulk-bar .count { font-weight: 600; }
.bulk-bar .btn { --btn-bg: rgba(255,255,255,0.12); --btn-fg: #fff; --btn-border: rgba(255,255,255,0.24); }
.bulk-bar .btn:hover { --btn-bg: rgba(255,255,255,0.2); }

/* Toolbar above tables. */
.table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}
.table-toolbar .search { flex: 1; min-width: 220px; max-width: 380px; position: relative; }
.table-toolbar .search i {
    position: absolute;
    inset-inline-start: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.table-toolbar .search .form-control { padding-inline-start: 2.25rem; }

.table-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    background: var(--surface-sunk);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.pagination-controls { display: flex; align-items: center; gap: var(--space-1); }
.page-btn {
    min-width: 34px; height: 34px;
    display: inline-grid;
    place-items: center;
    padding: 0 var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-700);
    font-size: var(--text-sm);
    font-weight: 550;
    font-variant-numeric: tabular-nums;
    transition: background var(--duration-fast) var(--ease);
}
.page-btn:hover:not(:disabled) { background: var(--ink-100); }
.page-btn[aria-current="page"] { background: var(--brand-600); color: #fff; border-color: var(--brand-700); }
.page-btn:disabled { opacity: 0.4; }

/* Expandable rows. */
.row-expand { background: var(--surface-sunk); }
.row-expand > td { padding: var(--space-5) var(--space-4) !important; border-bottom: 1px solid var(--border) !important; }
.expand-toggle { transition: transform var(--duration) var(--ease); }
.expand-toggle[aria-expanded="true"] { transform: rotate(90deg); }

/* On narrow screens the table becomes a stack of labelled cards. */
@media (max-width: 767.98px) {
    .table-cards > thead { display: none; }
    .table-cards, .table-cards > tbody, .table-cards > tbody > tr, .table-cards > tbody > tr > td { display: block; width: 100%; }
    .table-cards > tbody > tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: var(--space-3);
        padding: var(--space-2);
        background: var(--surface);
        box-shadow: var(--shadow-xs);
    }
    .table-cards > tbody > tr > td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-4);
        padding: var(--space-2) var(--space-3);
        border-bottom: 0;
        text-align: end;
    }
    .table-cards > tbody > tr > td::before {
        content: attr(data-label);
        font-size: var(--text-xs);
        font-weight: 620;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--text-muted);
        text-align: start;
        flex: none;
    }
    .table-cards > tbody > tr > td:not([data-label]) { justify-content: flex-end; }
    .row-actions { justify-content: flex-end; flex-wrap: wrap; }
    .table-scroll { max-height: none; }
}

/* --------------------------------------------------------------------------
   11. Badges & status
   -------------------------------------------------------------------------- */

.badge, .status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-pill);
    font-size: var(--text-xs);
    font-weight: 620;
    letter-spacing: 0.01em;
    line-height: 1.5;
    border: 1px solid transparent;
}
/* A dot carries the status in addition to hue, for colour-blind users. */
.status::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}
.status-neutral { background: var(--ink-100); color: var(--ink-700); border-color: var(--ink-200); }
.status-success { background: var(--success-50); color: var(--success-700); border-color: #bfe0ca; }
.status-warning { background: var(--warning-50); color: var(--warning-700); border-color: #ecd5ac; }
.status-danger  { background: var(--danger-50);  color: var(--danger-700);  border-color: #efc3c0; }
.status-info    { background: var(--info-50);    color: var(--info-700);    border-color: #c3d3f5; }
.status-brand   { background: var(--brand-50);   color: var(--brand-700);   border-color: var(--brand-200); }

.text-bg-light { background: var(--ink-100) !important; color: var(--ink-700) !important; }

/* --------------------------------------------------------------------------
   12. Dialogs, dropdowns, toasts
   -------------------------------------------------------------------------- */

.modal-content {
    border: 0;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}
.modal-header { padding: var(--space-5) var(--space-5) var(--space-3); border-bottom: 0; }
.modal-title { font-size: var(--text-lg); font-weight: 620; }
.modal-body { padding: 0 var(--space-5) var(--space-4); color: var(--text-secondary); }
.modal-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); gap: var(--space-2); }
.modal-backdrop.show { opacity: 0.45; backdrop-filter: blur(3px); }

.dropdown-menu {
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-base);
    min-width: 200px;
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--ink-800);
}
.dropdown-item i { color: var(--text-muted); width: 1.1rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--brand-50); color: var(--brand-800); }
.dropdown-item.is-danger { color: var(--danger-600); }
.dropdown-item.is-danger:hover { background: var(--danger-50); color: var(--danger-700); }
.dropdown-item.is-danger i { color: inherit; }
.dropdown-divider { margin: var(--space-2) 0; border-color: var(--border); }
.dropdown-header { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); }

/* Toasts — announced via aria-live in the markup. */
.toast-stack {
    position: fixed;
    inset-block-start: calc(var(--topbar-h) + var(--space-3));
    inset-inline-end: var(--space-5);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: min(400px, calc(100vw - var(--space-6)));
    pointer-events: none;
}
@media (max-width: 575.98px) {
    .toast-stack { inset-inline: var(--space-3); width: auto; }
}

.toast-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 3px solid var(--ink-400);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toast-in var(--duration-slow) var(--ease);
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}
.toast-item.is-leaving { opacity: 0; transform: translateX(12px); transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease); }
.toast-item .icon { font-size: 1.1rem; line-height: 1.35; flex: none; }
.toast-item .body { flex: 1; min-width: 0; }
.toast-item .title { font-weight: 600; font-size: var(--text-base); color: var(--ink-900); }
.toast-item .message { font-size: var(--text-sm); color: var(--text-secondary); margin-top: 2px; }
.toast-item .close { background: none; border: 0; color: var(--text-muted); padding: 2px; border-radius: var(--radius-sm); flex: none; }
.toast-item .close:hover { color: var(--ink-800); background: var(--ink-100); }
.toast-success { border-inline-start-color: var(--success-600); }
.toast-success .icon { color: var(--success-600); }
.toast-danger { border-inline-start-color: var(--danger-600); }
.toast-danger .icon { color: var(--danger-600); }
.toast-warning { border-inline-start-color: var(--warning-600); }
.toast-warning .icon { color: var(--warning-600); }
.toast-info { border-inline-start-color: var(--info-600); }
.toast-info .icon { color: var(--info-600); }

/* Inline alerts (non-transient messages). */
.alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    font-size: var(--text-base);
}
.alert-success { background: var(--success-50); border-color: #bfe0ca; color: var(--success-700); }
.alert-danger  { background: var(--danger-50);  border-color: #efc3c0; color: var(--danger-700); }
.alert-warning { background: var(--warning-50); border-color: #ecd5ac; color: var(--warning-700); }
.alert-info    { background: var(--info-50);    border-color: #c3d3f5; color: var(--info-700); }

/* --------------------------------------------------------------------------
   13. Empty & loading states
   -------------------------------------------------------------------------- */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--space-9) var(--space-5);
    max-width: 460px;
    margin-inline: auto;
}
.empty-icon {
    width: 56px; height: 56px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-lg);
    background: var(--ink-50);
    border: 1px solid var(--border);
    color: var(--ink-400);
    font-size: 1.5rem;
    margin-bottom: var(--space-4);
}
.empty-title { font-size: var(--text-md); font-weight: 620; color: var(--ink-900); margin: 0 0 var(--space-2); }
.empty-text { font-size: var(--text-base); color: var(--text-secondary); margin: 0 0 var(--space-5); }

/* Skeletons — sized to the content they stand in for, so nothing shifts. */
.skeleton {
    background: linear-gradient(90deg, var(--ink-100) 25%, var(--ink-50) 37%, var(--ink-100) 63%);
    background-size: 400% 100%;
    border-radius: var(--radius-sm);
    animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
.skeleton-text { height: 0.85em; margin: 0.3em 0; }
.skeleton-title { height: 1.4em; width: 40%; }
.skeleton-line-sm { width: 60%; }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; background: var(--ink-100); } }

/* Indeterminate top progress bar for navigations. */
.route-progress {
    position: fixed;
    inset-block-start: 0;
    inset-inline: 0;
    height: 2px;
    z-index: calc(var(--z-toast) + 1);
    background: transparent;
    overflow: hidden;
    display: none;
}
.route-progress.is-active { display: block; }
.route-progress::after {
    content: "";
    display: block;
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--brand-500), transparent);
    animation: route-slide 1s var(--ease) infinite;
}
@keyframes route-slide { from { transform: translateX(-100%); } to { transform: translateX(350%); } }

/* --------------------------------------------------------------------------
   14. Utilities
   -------------------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; }
.stack-2 { gap: var(--space-2); } .stack-3 { gap: var(--space-3); }
.stack-4 { gap: var(--space-4); } .stack-5 { gap: var(--space-5); } .stack-6 { gap: var(--space-6); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--space-5) 0; }
.surface-sunk { background: var(--surface-sunk); }
.rounded-lg { border-radius: var(--radius-lg) !important; }
.shadow-soft { box-shadow: var(--shadow-md) !important; }
.fs-data { font-size: var(--text-base); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   15. Print
   -------------------------------------------------------------------------- */

@media print {
    .app-sidebar, .app-topbar, .toast-stack, .palette-backdrop,
    .sidebar-backdrop, .page-actions, .table-toolbar, .table-footer,
    .row-actions, .form-actions, .breadcrumb-bar, .skip-link, .route-progress,
    .no-print {
        display: none !important;
    }
    .app-main { margin: 0 !important; }
    .app-content { padding: 0 !important; max-width: none !important; }
    .card, .table-wrap, .panel { border: 0 !important; box-shadow: none !important; }
    .table-scroll { max-height: none !important; overflow: visible !important; }
    body { background: #fff !important; }

    /* Identity cards carry meaning in their colour, so stop the browser
       dropping backgrounds the way it does for ordinary page chrome. The
       .id-card rules themselves live in partials/idcard-styles.blade.php and
       are loaded after this file, so they keep precedence. */
    .id-card, .id-card * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
