/* ==================================================================
   Design system — Professional / Minimal / Futuristic
   A cool, precise instrument-panel language: a single electric-teal
   accent, cold neutrals (never warm cream/gray), thin hairline borders
   over heavy shadows, geometric type, and deliberate motion on every
   interactive element. Semantic status colors (risk red/amber/green,
   workflow badges) are left alone by design — those are load-bearing
   meaning, not brand decoration, and read correctly in any aesthetic.
   ================================================================== */

:root, [data-bs-theme="light"] {
    /* Brand / interactive accent */
    --accent: #0a7ea3;
    --accent-dim: #086282;
    --accent-bright: #12aed6;
    --accent-tint: #e5f3f7;
    --accent-glow: rgba(10, 126, 163, .22);

    /* Neutrals — cool, not warm */
    --ink: #0d1418;
    --ink-soft: #55636c;
    --ink-faint: #8b979e;
    --paper: #f3f6f7;
    --paper-raised: #ffffff;
    --paper-sunken: #eaeff1;
    --line: #dbe3e6;
    --line-soft: #e9eef0;

    --sidebar-rail-w: 68px;
    --sidebar-panel-w: 188px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(13, 20, 24, .05), 0 1px 1px rgba(13, 20, 24, .04);
    --shadow-md: 0 4px 16px rgba(13, 20, 24, .07), 0 1px 3px rgba(13, 20, 24, .05);
    --shadow-glow: 0 0 0 1px rgba(10, 126, 163, .18), 0 4px 20px rgba(10, 126, 163, .12);
    --ease: cubic-bezier(.22, .61, .36, 1);

    /* Reskin Bootstrap's own primary + links to the new accent, so
       .btn-primary, .text-primary, form focus rings etc. follow automatically. */
    --bs-primary: #0a7ea3;
    --bs-primary-rgb: 10, 126, 163;
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--paper);
    --bs-border-color: var(--line);
    --bs-link-color: #0a7ea3;
    --bs-link-color-rgb: 10, 126, 163;
    --bs-link-hover-color: #086282;
    --bs-link-hover-color-rgb: 8, 98, 130;
    --bs-focus-ring-color: rgba(10, 126, 163, .25);
}
[data-bs-theme="dark"] {
    --accent: #2dd4e0;
    --accent-dim: #67e2ea;
    --accent-bright: #7fecf2;
    --accent-tint: rgba(45, 212, 224, .12);
    --accent-glow: rgba(45, 212, 224, .28);

    --ink: #e7f1f3;
    --ink-soft: #93a5ab;
    --ink-faint: #5c6a70;
    --paper: #060a0d;
    --paper-raised: #0d1417;
    --paper-sunken: #10181b;
    --line: #1b2529;
    --line-soft: #161f23;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-glow: 0 0 0 1px rgba(45, 212, 224, .22), 0 0 24px rgba(45, 212, 224, .16);

    --bs-primary: #2dd4e0;
    --bs-primary-rgb: 45, 212, 224;
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--paper);
    --bs-border-color: var(--line);
    --bs-link-color: #4fe0ea;
    --bs-link-color-rgb: 79, 224, 234;
    --bs-link-hover-color: #8ff0f7;
    --bs-link-hover-color-rgb: 143, 240, 247;
    --bs-focus-ring-color: rgba(45, 212, 224, .3);
}

/* ==================================================================
   Type system — Manrope for display/labels, Inter for body copy,
   IBM Plex Mono for anything numeric/tabular (KPIs, codes, timestamps).
   Fonts loaded via <link> in each page's own <head>.
   ================================================================== */
:root {
    --font-display: 'Manrope', 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

html {
    scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
    font-family: var(--font-body);
    background-color: var(--paper);
    color: var(--ink);
    letter-spacing: -0.001em;
}

h1, h2, h3, h4, h5, h6,
.navbar-brand, .card-title, .modal-title {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
}

.tabular-nums, .fw-bold, code, .badge, th {
    font-variant-numeric: tabular-nums;
}

[x-cloak] {
    display: none !important;
}

/* ==================================================================
   Global smoothness — every interactive surface eases, nothing snaps.
   ================================================================== */
a, .btn, .nav-link, .dropdown-item, .form-control, .form-select,
.card, .badge, .accordion-button, input, select, textarea {
    transition: background-color .16s var(--ease), border-color .16s var(--ease),
                color .16s var(--ease), box-shadow .16s var(--ease),
                transform .16s var(--ease), opacity .16s var(--ease);
}
.btn:active {
    transform: translateY(1px) scale(.98);
}
.dropdown-menu {
    animation: al-dropdown-in .14s var(--ease);
    transform-origin: top center;
    border-color: var(--line);
    box-shadow: var(--shadow-md);
}
@keyframes al-dropdown-in {
    from { opacity: 0; transform: translateY(-4px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.tab-pane.fade {
    transition: opacity .18s var(--ease);
}

.form-control, .form-select {
    background-color: var(--paper-raised);
    border-color: var(--line);
    color: var(--ink);
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
}
.form-label {
    font-weight: 600;
    font-size: .84rem;
    color: var(--ink-soft);
    letter-spacing: .01em;
}
.form-text {
    color: var(--ink-faint);
}

.card {
    background-color: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: .88rem;
}
.btn-primary {
    border-color: transparent;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover, .btn-primary:focus {
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}
.btn-outline-primary {
    color: var(--accent);
    border-color: var(--accent);
}
.btn-outline-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}
.btn-outline-secondary {
    border-color: var(--line);
    color: var(--ink-soft);
}
.btn-outline-secondary:hover {
    border-color: var(--ink-faint);
    color: var(--ink);
}

.nav-tabs {
    border-bottom: 1px solid var(--line);
    gap: .15rem;
}
.nav-tabs .nav-link {
    border: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: var(--ink-soft);
    font-weight: 600;
    font-size: .86rem;
    padding: .55rem 1rem;
    position: relative;
}
.nav-tabs .nav-link:hover {
    color: var(--accent);
    background: var(--accent-tint);
    border-color: transparent;
}
.nav-tabs .nav-link.active {
    color: var(--accent);
    background: transparent;
    border-color: transparent;
}
.nav-tabs .nav-link.active::after {
    content: "";
    position: absolute;
    left: .4rem; right: .4rem; bottom: -1px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
    box-shadow: 0 0 8px var(--accent-glow);
}

table {
    color: var(--ink);
}
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--ink);
    --bs-table-striped-bg: var(--paper-sunken);
    --bs-table-hover-bg: var(--accent-tint);
    --bs-table-border-color: var(--line-soft);
}
.table thead th {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-faint);
    border-bottom-width: 1px;
    background: transparent;
}

/* ==================================================================
   Wide-form layout utilities — used across every create/edit form so
   fields read in organized, labeled groups and the page uses the full
   available width instead of one narrow floating card.
   ================================================================== */
.form-shell {
    max-width: 980px;
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.1rem 1.5rem;
    align-items: start;
}
.form-grid .field-full {
    grid-column: 1 / -1;
}
@media (max-width: 720px) {
    .form-grid { grid-template-columns: 1fr; }
}
.form-section {
    padding: 1.4rem 1.6rem;
    margin-bottom: 1.25rem;
}
.form-section-title {
    font-family: var(--font-display);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--accent);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.form-section-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}
.form-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding-top: .25rem;
}

/* ==================================================================
   Two-panel sidebar — Panel 1: icon rail (always visible, 68 px).
   Panel 2: section sub-panel (slides in when a section is selected).
   .sidebar-outer: the fixed clipping wrapper that controls visible width.
   .sidebar: absolute inside the wrapper, always full width; flex children
             are flex-shrink:0 so the flex container cannot collapse — the
             wrapper clips instead.
   ================================================================== */
.sidebar-outer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-rail-w);
    overflow: hidden;
    z-index: 1040;
    transition: width .22s var(--ease);
}
.nav-panel-open .sidebar-outer {
    width: calc(var(--sidebar-rail-w) + var(--sidebar-panel-w));
}
.sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: calc(var(--sidebar-rail-w) + var(--sidebar-panel-w));
    display: flex;
    flex-direction: row;
    background: linear-gradient(180deg, #060a0c 0%, #04070a 100%);
}

/* Panel 1 — icon rail */
.sidebar-rail {
    width: var(--sidebar-rail-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-right: 1px solid rgba(255, 255, 255, .06);
}
.sidebar-rail-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 64px;
    flex-shrink: 0;
    color: var(--accent-bright);
    font-size: 1.35rem;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    transition: background .16s var(--ease);
    filter: drop-shadow(0 0 6px var(--accent-glow));
}
.sidebar-rail-brand:hover {
    color: var(--accent-bright);
    background: rgba(255, 255, 255, .05);
}
.sidebar-rail-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .4rem 0;
}
.sidebar-rail-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .18rem;
    width: 100%;
    padding: .6rem .25rem;
    background: transparent;
    border: none;
    border-left: 2px solid transparent;
    color: rgba(255, 255, 255, .48);
    font-size: .58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    cursor: pointer;
    transition: color .16s var(--ease), background .16s var(--ease), border-color .16s var(--ease);
    font-family: var(--font-display);
    text-align: center;
    line-height: 1.2;
}
.sidebar-rail-btn i {
    font-size: 1.05rem;
    line-height: 1;
}
.sidebar-rail-btn:hover {
    color: rgba(255, 255, 255, .88);
    background: rgba(255, 255, 255, .06);
}
.sidebar-rail-btn.active {
    color: var(--accent-bright);
    background: rgba(45, 212, 224, .1);
    border-left-color: var(--accent-bright);
}
.sidebar-rail-footer {
    flex-shrink: 0;
    padding: .25rem 0;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

/* Panel 2 — section sub-panel */
.sidebar-sub-panel {
    width: 0;
    flex-shrink: 0;
    height: 100%;
    overflow: hidden;
    transition: width .22s var(--ease);
    background: rgba(0, 0, 0, .2);
    border-right: 1px solid rgba(45, 212, 224, .06);
}
.nav-panel-open .sidebar-sub-panel {
    width: var(--sidebar-panel-w);
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar-sub-header {
    font-family: var(--font-display);
    font-size: .59rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255, 255, 255, .28);
    padding: .9rem .85rem .35rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-bottom: 1px solid rgba(255, 255, 255, .05);
    margin-bottom: .3rem;
}
.sidebar .nav-link {
    display: flex;
    align-items: flex-start;
    color: rgba(255, 255, 255, 0.65);
    border-radius: var(--radius-sm);
    padding: 0.42rem 0.85rem;
    margin: 0 .35rem .08rem;
    font-size: 0.83rem;
    font-weight: 500;
    line-height: 1.35;
    border: 1px solid transparent;
}
.sidebar .nav-link i {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
    margin-top: 0.1rem;
}
.nav-label {
    flex: 1;
    min-width: 0;
}
.sidebar .nav-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.06);
}
.sidebar .nav-link.active {
    color: var(--accent-bright);
    background: rgba(45, 212, 224, .1);
    border-color: rgba(45, 212, 224, .25);
    box-shadow: inset 2px 0 0 var(--accent-bright), 0 0 16px rgba(45, 212, 224, .12);
}
.sidebar .nav-link.active i {
    filter: drop-shadow(0 0 4px var(--accent-glow));
}

.main-content {
    margin-left: var(--sidebar-rail-w);
    transition: margin-left .22s var(--ease);
}
.nav-panel-open .main-content {
    margin-left: calc(var(--sidebar-rail-w) + var(--sidebar-panel-w));
}

/* Collapsed sidebar state is driven by Alpine :style on .sidebar-outer and
   .main-content directly (inline styles always beat external-CSS rules and
   bypass any browser caching of this file).  The .al-sc FOUC guard lives in
   an inline <style> block in main.php <head> so it takes effect immediately. */

.topbar {
    z-index: 1030;
    background-color: var(--paper-raised) !important;
    border-bottom: 1px solid var(--line) !important;
}

.permission-group-row td {
    background: var(--paper-sunken);
    border-top: 1px dashed var(--line);
}

.demo-mode-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.55rem 1rem;
    background: repeating-linear-gradient(135deg, #fbbf24, #fbbf24 10px, #f59e0b 10px, #f59e0b 20px);
    color: #451a03;
    font-size: 0.82rem;
    position: sticky;
    top: 0;
    z-index: 1031;
}
.demo-mode-banner-text {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}
.demo-mode-banner-note {
    opacity: 0.75;
    font-size: 0.76rem;
}
[data-bs-theme="dark"] .demo-mode-banner {
    color: #1c0a00;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 1035;
}

@media (max-width: 991.98px) {
    .sidebar-outer {
        transform: translateX(-100%);
        width: calc(var(--sidebar-rail-w) + var(--sidebar-panel-w)) !important;
        transition: transform .22s var(--ease);
    }
    .sidebar-outer.sidebar-open {
        transform: translateX(0);
    }
    /* Sub-panel always at full width on mobile when sidebar is open */
    .sidebar-sub-panel,
    .nav-panel-open .sidebar-sub-panel {
        width: var(--sidebar-panel-w) !important;
        overflow-y: auto;
        overflow-x: hidden;
    }
    .main-content,
    .nav-panel-open .main-content {
        margin-left: 0;
    }
    /* Don't collapse on mobile — user controls it with the hamburger */
    .sidebar-collapsed .sidebar-outer {
        width: calc(var(--sidebar-rail-w) + var(--sidebar-panel-w)) !important;
        transform: translateX(-100%);
    }
}

.badge-risk-high { background-color: #dc3545; }
.badge-risk-medium { background-color: #fd7e14; }
.badge-risk-low { background-color: #6c757d; }

/* ==================================================================
   Dashboard component classes
   ================================================================== */
.dash-header h1 { font-family: var(--font-display); font-size: 1.5rem; font-weight: 800; color: var(--ink); margin: 0; letter-spacing: -0.015em; }
.dash-header p { color: var(--ink-soft); font-size: .82rem; margin: .15rem 0 0; }

/* Section dividers grouping the dashboard into readable zones */
.dash-section-label {
    display: flex; align-items: center; gap: .75rem;
    margin: 1.75rem 0 .85rem;
    font-family: var(--font-display);
    font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
    color: var(--accent);
}
.dash-section-label:first-of-type { margin-top: 0; }
.dash-section-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.dash-date-chip {
    display: inline-flex; align-items: center; gap: .3rem;
    background: var(--paper-raised); border: 1px solid var(--line); border-radius: 20px;
    padding: .25rem .8rem; font-size: .75rem; color: var(--ink-soft); font-weight: 500;
    font-family: var(--font-mono);
}

.dash-filter-bar { background: var(--paper-raised); border: 1px solid var(--line); }

.dash-kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: .85rem; margin-bottom: 1.1rem; }
@media (max-width: 1200px) { .dash-kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .dash-kpi-grid { grid-template-columns: repeat(2, 1fr); } }

/* Accent rail: a thin top-edge glowing stripe reading as an
   instrument-panel cue. Color comes from --kpi-rail (set per-tile,
   inline, to match that tile's own semantic value color). */
.dash-kpi, .dash-card {
    position: relative;
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.dash-kpi::before, .dash-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--kpi-rail, var(--accent));
    box-shadow: 0 0 10px var(--kpi-rail, var(--accent-glow));
}

.dash-kpi {
    padding: 1rem 1.15rem;
    display: flex; flex-direction: column; gap: .3rem;
    text-decoration: none; color: inherit;
}
.dash-kpi:hover { box-shadow: var(--shadow-glow); transform: translateY(-2px); color: inherit; border-color: var(--accent); }

.dash-kpi-top { display: flex; align-items: center; gap: .6rem; }
.dash-kpi-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.dash-kpi-label { font-size: .67rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); line-height: 1.3; }
.dash-kpi-value { font-family: var(--font-mono); font-size: 1.85rem; font-weight: 600; line-height: 1.05; color: var(--ink); font-variant-numeric: tabular-nums; }
.dash-kpi-sub { font-size: .71rem; color: var(--ink-faint); display: flex; align-items: center; gap: .25rem; min-height: 1.1rem; }

/* Scope Checklist: per-heading coverage bar (engagement show page) */
.al-coverage-bar { width: 56px; height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; flex-shrink: 0; }
.al-coverage-bar > span { display: block; height: 100%; background: var(--bs-success, #198754); border-radius: 4px; }

/* Engagement page (Option A): read-only stage stepper above the tab bar —
   Planning / Fieldwork / Reporting / Closed, reflecting $engagement['status'].
   The status dropdown above it is still the only thing that changes it. */
.al-stepper-seg { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--ink-faint); }
.al-stepper-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.al-stepper-seg.done .al-stepper-dot { background: var(--bs-success, #198754); }
.al-stepper-seg.current .al-stepper-dot { background: var(--bs-primary, #0a7ea3); box-shadow: 0 0 0 4px rgba(10, 126, 163, .15); }
.al-stepper-seg.current .al-stepper-lbl { color: var(--ink); font-weight: 600; }
.al-stepper-seg.done .al-stepper-lbl { color: var(--ink-soft); }
.al-stepper-bar { width: 32px; height: 1.5px; background: var(--line); margin: 0 8px; }
.al-stepper-bar.done { background: var(--bs-success, #198754); }

/* Workpaper Step page: the Gated Pipeline — a slim single-row cousin of
   .al-stepper above, sized for a step page rather than a hero banner.
   Read-only visualization of $step['status'], four gates fixed at
   not_started/in_progress/ready_for_review/reviewed. The dropdown at the
   top of the step page is still the only *manual* way to change status;
   AuditProgram::autoAdvanceStatus() is the automatic path (see its
   docblock), and reaching gate 4 always stays manual/deliberate. Each
   gate's own trigger text lives in its `title` tooltip rather than
   permanent on-page copy; only the CURRENT gate's trigger is spelled out,
   in the one small line under the row. */
.al-gate-card {
    background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: .6rem .9rem; margin-bottom: .75rem;
}
.al-gate-row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.al-gate-title { font-size: .76rem; font-weight: 800; color: var(--ink-soft); display: flex; align-items: center; gap: .35rem; flex-shrink: 0; }
.al-gate-auto-badge {
    display: inline-flex; align-items: center; gap: .3rem; font-size: .62rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: .03em; background: var(--accent-tint); color: var(--accent-dim);
    padding: .15rem .55rem; border-radius: 100px; flex-shrink: 0; margin-left: auto;
}
[data-bs-theme="dark"] .al-gate-auto-badge { color: var(--accent-bright); }

.al-gate-track { display: flex; align-items: center; flex: 1 1 260px; min-width: 200px; }
.al-gate { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; cursor: default; }
.al-gate-dot {
    width: 21px; height: 21px; border-radius: 50%; background: var(--paper-sunken); border: 2px solid var(--line);
    display: flex; align-items: center; justify-content: center; font-size: .66rem; font-weight: 800;
    color: var(--ink-faint); flex-shrink: 0; line-height: 1;
}
.al-gate.done .al-gate-dot { background: #16a34a; border-color: #16a34a; color: #fff; }
.al-gate.current .al-gate-dot { background: var(--paper-raised); border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.al-gate-label { font-size: .76rem; font-weight: 600; color: var(--ink-faint); white-space: nowrap; }
.al-gate.current .al-gate-label { color: var(--accent-dim); font-weight: 800; }
[data-bs-theme="dark"] .al-gate.current .al-gate-label { color: var(--accent-bright); }
.al-gate.done .al-gate-label { color: var(--ink-soft); }
.al-gate-line { flex: 1 1 auto; height: 2px; background: var(--line); margin: 0 .5rem; min-width: 12px; }
.al-gate-line.done { background: #16a34a; }
.al-gate-current-trigger { font-size: .72rem; color: var(--ink-faint); margin-top: .3rem; padding-left: .05rem; }
@media (max-width: 720px) { .al-gate-label { display: none; } }

/* A Quill (AL.richEditor) editor whose container carries this class can be
   grown/shrunk via a dedicated .al-resize-handle bar placed right after it
   (see AL_makeResizable() in fieldwork/step.php) — opt-in per editor rather
   than applied to every .ql-editor in the app, so existing fixed-height
   editors elsewhere are unaffected. Native CSS `resize` was tried first but
   dragging it felt uncontrolled: a contenteditable element (Quill's own
   .ql-editor, not a plain textarea) reflows its own content on every
   keystroke and Quill mutates its DOM on 'text-change', both of which can
   fight the browser's native resize gesture mid-drag. A small custom drag
   handle with its own mousemove math sidesteps that entirely. */
.al-resizable-editor .ql-editor { overflow-y: auto; }
.al-resize-handle {
    height: 14px; margin-top: -1px; border: 1px solid var(--bs-border-color, #ced4da); border-top: none;
    border-radius: 0 0 .375rem .375rem; background: var(--paper-sunken, #eaeff1);
    display: flex; align-items: center; justify-content: center; cursor: ns-resize;
    color: var(--ink-faint, #8b979e); font-size: .7rem; line-height: 1; user-select: none; touch-action: none;
}
.al-resize-handle:hover, .al-resize-handle.al-resizing { background: var(--accent-tint, #e5f3f7); color: var(--accent, #0a7ea3); }

/* Workpaper Step page: the KPI strip — a slim row of stat chips, sized for
   a sub-header under the Gated Pipeline rather than reusing .dash-kpi-grid
   (that one's built for a full dashboard tile — big padding, a 1.85rem
   value — and felt oversized/heavy stacked this close under the pipeline
   strip). Horizontal icon+text layout instead of .dash-kpi's stacked one
   keeps each chip to a single compact row. */
.al-step-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: .55rem; margin-top: .7rem; }
@media (max-width: 900px) { .al-step-kpis { grid-template-columns: repeat(2, 1fr); } }
.al-step-kpi {
    position: relative; overflow: hidden;
    background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm); padding: .5rem .65rem; display: flex; align-items: center; gap: .55rem;
}
.al-step-kpi::before {
    content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: var(--kpi-rail, var(--accent));
}
.al-step-kpi-icon { width: 26px; height: 26px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: .78rem; flex-shrink: 0; }
.al-step-kpi-body { min-width: 0; }
.al-step-kpi-label { font-size: .6rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.al-step-kpi-value-row { display: flex; align-items: baseline; gap: .3rem; white-space: nowrap; }
.al-step-kpi-value { font-family: var(--font-mono); font-size: 1.02rem; font-weight: 700; color: var(--ink); line-height: 1.3; }
.al-step-kpi-sub { font-size: .66rem; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; }

/* Workpaper Step page: day-grouped Activity Log timeline (merged into the
   Overview tab alongside Scope Checklist — see fieldwork/step.php). */
.al-activity-day { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); margin: 0 0 .5rem; padding-left: .1rem; }
.al-activity-day:not(:first-child) { margin-top: 1rem; }
.al-activity-item { display: flex; gap: .7rem; position: relative; padding-bottom: .8rem; }
.al-activity-item:last-child { padding-bottom: 0; }
.al-activity-item:not(:last-child)::before { content: ""; position: absolute; left: 14px; top: 30px; bottom: -2px; width: 2px; background: var(--line-soft); }
.al-activity-icon { width: 29px; height: 29px; border-radius: .55rem; display: flex; align-items: center; justify-content: center; font-size: .82rem; flex-shrink: 0; z-index: 1; }
.al-activity-body { flex: 1; font-size: .83rem; padding-top: .1rem; }
.al-activity-time { font-size: .71rem; color: var(--ink-faint); margin-top: .1rem; }

/* Workpaper Step page: Overview tab layout — the "working" cards (Sample
   Selection, Scope Checklist) in a wider left column, the read-only
   Activity Log feed in a narrower right column, so a passive history feed
   doesn't push actionable content further down the page. */
.al-overview-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .al-overview-grid { grid-template-columns: 1fr; } }

/*
 * Off-canvas filter drawer — shared by every engagement-page tab whose
 * filter fields live in a slide-in panel instead of an always-visible row
 * (Fieldwork, Data Requests, Observations, Scope Checklist). Each tab wires
 * its own `filterDrawerOpen` boolean and its own filter fields inside the
 * drawer body; this only supplies the shared shell (backdrop + panel +
 * transition) so all four look and behave identically.
 */
.al-filter-backdrop {
    position: fixed; inset: 0; background: rgba(10, 14, 20, .35); z-index: 1040;
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.al-filter-backdrop.show { opacity: 1; pointer-events: auto; }
.al-filter-drawer {
    position: fixed; top: 0; right: 0; height: 100%; width: 340px; max-width: 88vw;
    background: var(--bs-body-bg); border-left: 1px solid var(--bs-border-color);
    box-shadow: -10px 0 28px -12px rgba(0, 0, 0, .3); z-index: 1045;
    transform: translateX(100%); transition: transform .22s ease;
    padding: 18px 18px 24px; overflow-y: auto; display: flex; flex-direction: column;
}
.al-filter-drawer.show { transform: translateX(0); }
.al-filter-drawer .al-filter-drawer-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.al-filter-drawer .al-filter-drawer-header h2 { font-size: 1rem; margin: 0; }
.al-filter-drawer .al-filter-field { margin-bottom: 14px; }
.al-filter-drawer .al-filter-field:last-of-type { margin-bottom: 0; }
.al-filter-launcher-badge {
    font-family: var(--font-mono, monospace); font-size: .68rem; background: var(--bs-primary, #0a7ea3);
    color: #fff; border-radius: 100px; padding: 0 6px; margin-left: 4px;
}

.dash-charts-grid { display: grid; grid-template-columns: 1.1fr 2fr 1.1fr; gap: .85rem; margin-bottom: 1.1rem; }
.dash-tables-grid { display: grid; grid-template-columns: 1.5fr 1.3fr 1.3fr; gap: .85rem; margin-bottom: 1.1rem; }
@media (max-width: 1100px) { .dash-charts-grid, .dash-tables-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .dash-charts-grid, .dash-tables-grid { grid-template-columns: 1fr; } }

.dash-card {
    padding: 1.1rem 1.2rem;
    display: flex; flex-direction: column;
}
.dash-card-title {
    font-family: var(--font-display);
    font-size: .68rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .08em; color: var(--ink-soft); margin-bottom: .75rem;
}

.dash-view-link {
    margin-top: .65rem; border-top: 1px solid var(--line-soft); padding-top: .55rem;
    font-size: .75rem; color: var(--accent); text-decoration: none; font-weight: 600;
    display: inline-flex; align-items: center; gap: .3rem;
}
.dash-view-link:hover { color: var(--accent-dim); gap: .45rem; }

.dash-donut-wrap { display: flex; justify-content: center; align-items: center; padding: .25rem 0; }

.dash-bar-list { display: flex; flex-direction: column; gap: .5rem; }
.dash-bar-row { display: flex; align-items: center; gap: .5rem; }
.dash-bar-label { width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); font-size: .75rem; }
.dash-bar-track { flex: 1; height: 6px; background: var(--paper-sunken); border-radius: 6px; overflow: hidden; }
.dash-bar-fill { height: 100%; border-radius: 6px; background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); transition: width .4s var(--ease); }
.dash-bar-val { width: 26px; text-align: right; font-weight: 600; color: var(--ink); font-size: .75rem; font-family: var(--font-mono); }

.dash-legend { list-style: none; padding: 0; margin: .35rem 0 0; display: flex; flex-direction: column; gap: .3rem; }
.dash-legend li { display: flex; align-items: center; font-size: .77rem; color: var(--ink-soft); }
.dash-legend-dot { width: 8px; height: 8px; border-radius: 2px; margin-right: .4rem; flex-shrink: 0; }
.dash-legend-count { margin-left: auto; color: var(--ink-faint); font-size: .72rem; font-weight: 600; font-family: var(--font-mono); }

.dash-table { width: 100%; border-collapse: collapse; font-size: .8rem; font-variant-numeric: tabular-nums; }
.dash-table th { color: var(--ink-faint); font-weight: 700; padding: .4rem .6rem; border-bottom: 1px solid var(--line-soft); text-align: left; font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; }
.dash-table td { padding: .5rem .6rem; border-bottom: 1px solid var(--line-soft); color: var(--ink-soft); vertical-align: middle; }
.dash-table tr:last-child td { border-bottom: none; }
.dash-table tr:hover td { background: var(--accent-tint); }

/* Severity stripe: colored left edge on the first cell of a table row,
   so risk reads at a glance during a fast scan — not just from the badge text.
   Standalone utility so it applies to any table, not just .dash-table. */
td.severity-high { box-shadow: inset 3px 0 0 #dc2626; }
td.severity-medium { box-shadow: inset 3px 0 0 #d97706; }
td.severity-low { box-shadow: inset 3px 0 0 #16a34a; }

.dash-chip-red { color: #dc2626; background: #fee2e2; border-radius: var(--radius-sm); padding: .1rem .45rem; font-weight: 700; display: inline-block; font-size: .74rem; font-family: var(--font-mono); }
.dash-chip-amber { color: #d97706; background: #fef3c7; border-radius: var(--radius-sm); padding: .1rem .45rem; font-weight: 700; display: inline-block; font-size: .74rem; font-family: var(--font-mono); }
.dash-chip-green { color: #16a34a; background: #dcfce7; border-radius: var(--radius-sm); padding: .1rem .45rem; font-weight: 700; display: inline-block; font-size: .74rem; font-family: var(--font-mono); }
.dash-chip-gray { color: var(--ink-soft); background: var(--paper-sunken); border-radius: var(--radius-sm); padding: .1rem .45rem; font-weight: 700; display: inline-block; font-size: .74rem; }

.dash-risk-high { color: #dc2626; background: #fee2e2; border-radius: 4px; padding: .08rem .4rem; font-size: .7rem; font-weight: 700; }
.dash-risk-medium { color: #d97706; background: #fef3c7; border-radius: 4px; padding: .08rem .4rem; font-size: .7rem; font-weight: 700; }
.dash-risk-low { color: #16a34a; background: #dcfce7; border-radius: 4px; padding: .08rem .4rem; font-size: .7rem; font-weight: 700; }

.dash-avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .62rem; color: #fff; flex-shrink: 0; }

/* Risk Heatmap — Impact x Issue Persistence matrix */
.risk-matrix-icon {
    width: 34px; height: 34px; border-radius: var(--radius-sm); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-tint); color: var(--accent); font-size: 1.05rem;
}
.risk-matrix-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 800; color: var(--ink); }
.risk-matrix-subtitle { font-size: .82rem; font-weight: 500; color: var(--ink-faint); margin-left: .5rem; }
.risk-matrix-hr { border-color: var(--line); margin: .85rem 0; }

.risk-matrix-legend-note { font-size: .78rem; color: var(--ink-soft); margin-bottom: 1.1rem; }

.risk-matrix-grid {
    display: grid;
    grid-template-columns: 9rem repeat(3, 1fr);
    gap: .6rem;
    align-items: stretch;
}
.risk-matrix-col-label {
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-faint); text-align: center; align-self: end; padding-bottom: .5rem;
}
.risk-matrix-row-pill {
    align-self: center;
    text-align: center;
    border-radius: 20px;
    padding: .4rem .5rem;
    font-size: .78rem;
    font-weight: 700;
}
.risk-matrix-cell {
    border-radius: var(--radius-sm);
    min-height: 5.5rem;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: transform .16s var(--ease);
}
.risk-matrix-cell:hover { transform: scale(1.03); }
.risk-matrix-cell-value { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.risk-matrix-cell-unit { font-size: .68rem; color: var(--ink-faint); margin-top: .1rem; }
.risk-matrix-cell-empty { font-size: 1.1rem; color: var(--ink-faint); }

.risk-matrix-legend { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.1rem; }
.risk-matrix-legend-pill { font-size: .74rem; font-weight: 700; padding: .3rem .75rem; border-radius: 20px; }

@media (max-width: 700px) {
    .risk-matrix-grid { grid-template-columns: 6rem repeat(3, 1fr); }
}

/* Audit Universe risk-ranked coverage list */
.au-process-label { font-size: .8rem; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.au-entity-label { font-size: .68rem; color: var(--ink-faint); flex-shrink: 0; white-space: nowrap; }
.au-coverage-line { font-size: .68rem; color: var(--ink-faint); margin-top: .25rem; }

/* ==================================================================
   Audit Universe page
   ================================================================== */
.au-kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .85rem; }
@media (max-width: 1100px) { .au-kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .au-kpi-grid { grid-template-columns: 1fr; } }

.au-count-badge {
    background: var(--accent-tint); color: var(--accent); font-size: .74rem; font-weight: 600;
    padding: .2rem .6rem; border-radius: 20px;
}

.au-row-icon {
    width: 34px; height: 34px; border-radius: var(--radius-sm); flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center; font-size: .95rem;
}

.au-risk-pill {
    display: inline-block; font-weight: 700; font-size: .8rem;
    padding: .15rem .55rem; border-radius: var(--radius-sm); font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
}

.au-freq-pill {
    display: inline-block; background: var(--accent-tint); color: var(--accent); font-size: .72rem; font-weight: 600;
    padding: .15rem .55rem; border-radius: 20px;
}

.au-status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .4rem; }

.au-table th, .au-table td { vertical-align: middle; }

.au-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; }
.au-item-card {
    border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
    background: var(--paper-raised);
    transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.au-item-card:hover { border-color: var(--accent); box-shadow: var(--shadow-glow); }

/* ── Dark mode: sidebar depth & separation ────────────────────────────────
   In light mode the sidebar's permanent near-black background already
   reads clearly against a light .main-content, so the hairline barely
   matters. In dark mode .main-content's own background (--paper) is a
   near-identical near-black, so that natural contrast disappears — a
   ~5%-opacity white hairline against near-black is effectively invisible
   (confirmed: computed border was rgba(255,255,255,.05), imperceptible in
   practice). --line is the same token every other dark-mode divider in
   this app uses (e.g. .topbar's border-bottom) for a visible-but-quiet
   hairline, so the sidebar edge now reads the same way. The gradient bleed
   stays as an added soft depth cue on top of that hairline, not instead of it. */
[data-bs-theme="dark"] .sidebar {
    background: linear-gradient(160deg, #030608 0%, #010203 100%);
}
[data-bs-theme="dark"] .sidebar-rail-brand {
    background: linear-gradient(180deg, rgba(45, 212, 224, .07) 0%, transparent 100%);
    border-bottom-color: rgba(45, 212, 224, .06);
}
[data-bs-theme="dark"] .sidebar-outer {
    box-shadow: none;
}
[data-bs-theme="dark"] .sidebar-sub-panel {
    background: #06111a;
    border-right-color: var(--line);
}
[data-bs-theme="dark"] .sidebar-rail {
    border-right-color: var(--line);
}
[data-bs-theme="dark"] .main-content {
    position: relative;
}
[data-bs-theme="dark"] .main-content::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    background: linear-gradient(to right, rgba(1, 2, 3, .58), transparent);
    pointer-events: none;
    z-index: 1;
}
[data-bs-theme="dark"] .topbar {
    background-color: var(--paper-raised) !important;
    border-bottom-color: var(--line) !important;
    box-shadow: 0 1px 0 var(--line), 0 2px 16px rgba(0, 0, 0, .35);
}

/* Print: circulate a plan/report as a clean PDF-via-browser-print copy —
   chrome (nav, topbar) and every interactive control disappear, only the
   informational content remains. */
@media print {
    .sidebar, .topbar, .sidebar-backdrop, .no-print,
    form, button, .btn, .dropdown-toggle, .collapse:not(.show) {
        display: none !important;
    }
    .content-area { margin: 0 !important; padding: 0 !important; width: 100% !important; }
    .card { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
}

/* Voice assistant: a mic button (command bar or a dictation icon next to
   a field) pulses red while actively listening — the only state cue
   needed, since recognition auto-stops on silence. */
.voice-listening {
    color: #fff !important;
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    animation: voice-pulse 1.4s ease-in-out infinite;
}
@keyframes voice-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(220, 53, 69, .55); }
    70%  { box-shadow: 0 0 0 8px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* Tables authored via the Quill editor (quill-table-better) — read-only
   display pages (Observation, Kickoff Notes, etc.) just echo the stored,
   sanitized HTML with no editor instance, so they need their own table
   styling; the editor's own snow theme only styles tables while live. */
.rich-note-content table {
    width: 100%;
    border-collapse: collapse;
    margin: .5rem 0;
}
.rich-note-content td,
.rich-note-content th {
    border: 1px solid var(--line);
    padding: .4rem .6rem;
    vertical-align: top;
}
.rich-note-content tr:first-child td,
.rich-note-content tr:first-child th {
    background: var(--paper-sunken);
    font-weight: 600;
}
.rich-note-content table p {
    margin: 0;
}
