/* ============================================================
   MSR Dashboard — Invenio Unified Design System
   Tokens mirror /Users/eemm/CoWork/Invenio/InvenioStyle.
   Single source of truth for color, type, spacing, radius,
   shadow, motion, focus, and dark-theme pairing.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes skeleton-pulse {
    0%   { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

.fade-up { animation: fadeUp 0.3s var(--ease-standard) both; }

/* ── Tokens — Light theme (default) ─────────────────────────── */
:root,
[data-theme="light"] {
    /* Surfaces */
    --canvas:         #f8fafc;
    --surface:        #ffffff;
    --raised:         #f1f5f9;

    /* Borders */
    --border:         #e2e8f0;
    --border-strong:  #cbd5e1;

    /* Text */
    --text:           #1e293b;
    --text-muted:     #64748b;
    --text-subtle:    #94a3b8;
    --text-inverse:   #ffffff;

    /* Brand */
    --primary:        #0369a1;   /* sky-700 */
    --primary-hover:  #075985;
    --primary-soft:   #e0f2fe;
    --primary-pressed:#cde9fb;
    --accent:         #0891b2;   /* cyan-600 */
    --accent-soft:    #cffafe;

    /* Status */
    --success:        #059669;
    --success-soft:   #d1fae5;
    --warn:           #d97706;
    --warn-soft:      #fef3c7;
    --danger:         #dc2626;
    --danger-hover:   #b91c1c;
    --danger-soft:    #fee2e2;
    --info:           #7c3aed;
    --info-soft:      #ede9fe;

    /* Overlay */
    --overlay:        rgba(15, 23, 42, 0.45);

    /* Nav backdrop */
    --nav-bg:         rgba(255, 255, 255, 0.92);

    /* Brand mark — swaps in dark theme */
    --mark:           url('brand/invenio-mark.svg');
    --lockup:         url('brand/invenio-lockup.svg');

    /* Hero gradient — Invenio brand pair */
    --hero-gradient:  linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);

    /* Shadows */
    --shadow-sm:      0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md:      0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg:      0 12px 32px rgba(15, 23, 42, 0.12);

    /* Typography */
    --font-base:      'Inter', system-ui, -apple-system, sans-serif;
    --font-mono:      'JetBrains Mono', ui-monospace, Menlo, monospace;

    /* Radius */
    --radius-sm:      6px;
    --radius-md:      8px;
    --radius-lg:      12px;
    --radius-xl:      16px;
    --radius-pill:    999px;

    /* Motion */
    --motion-fast:     120ms;
    --motion-standard: 180ms;
    --motion-slow:     260ms;
    --ease-standard:   cubic-bezier(0.2, 0, 0, 1);
    --ease-emphasized: cubic-bezier(0.3, 0, 0, 1.2);

    /* Focus ring (a11y) */
    --ring:           0 0 0 2px var(--canvas), 0 0 0 4px var(--primary);

    /* Layout */
    --sidebar-width:  260px;
    --header-height:  56px;

    /* Legacy aliases — keep older inline references working.
       Why: dashboard.js, constants.js, and a few inline styles still
       read these names. Removing them is a separate cleanup pass. */
    --bg:               var(--canvas);
    --border-light:     var(--raised);
    --text-primary:     var(--text);
    --text-light:       var(--text-subtle);
    --primary-light:    var(--primary-soft);
    --accent-light:     var(--accent-soft);
    --success-light:    var(--success-soft);
    --warning:          var(--warn);
    --warning-light:    var(--warn-soft);
    --danger-light:     var(--danger-soft);
    --purple:           var(--info);
    --purple-light:     var(--info-soft);
    --primary-blue:     var(--primary);
    --primary-charcoal: var(--text);
    --lime-green:       var(--primary);
    --navbar-bg:        var(--surface);
    --navbar-text:      var(--text-muted);
    --navbar-active:    var(--primary);
    --text-dark:        var(--text);
    --off-white:        var(--canvas);
    --light-gray:       var(--raised);
    --medium-gray:      var(--border-strong);
    --dark-gray:        var(--text-muted);
    --success-green:    var(--success);
    --warning-orange:   var(--warn);
    --danger-red:       var(--danger);
    --info-blue:        var(--accent);
}

/* ── Tokens — Dark theme ────────────────────────────────────── */
[data-theme="dark"] {
    --canvas:         #0b1220;
    --surface:        #111a2e;
    --raised:         #1a2744;

    --border:         #334155;
    --border-strong:  #475569;

    --text:           #f1f5f9;
    --text-muted:     #94a3b8;
    --text-subtle:    #64748b;
    --text-inverse:   #0b1220;

    --primary:        #22d3ee;   /* cyan-400 — brighter for dark contrast */
    --primary-hover:  #67e8f9;
    --primary-soft:   rgba(34, 211, 238, 0.14);
    --primary-pressed:rgba(34, 211, 238, 0.28);
    --accent:         #0891b2;
    --accent-soft:    rgba(8, 145, 178, 0.18);

    --success:        #10b981;
    --success-soft:   rgba(16, 185, 129, 0.15);
    --warn:           #f59e0b;
    --warn-soft:      rgba(245, 158, 11, 0.15);
    --danger:         #ef4444;
    --danger-hover:   #dc2626;
    --danger-soft:    rgba(239, 68, 68, 0.15);
    --info:           #8b5cf6;
    --info-soft:      rgba(139, 92, 246, 0.15);

    --overlay:        rgba(0, 0, 0, 0.6);

    --nav-bg:         rgba(11, 18, 32, 0.88);
    --mark:           url('brand/invenio-mark-dark.svg');
    --lockup:         url('brand/invenio-lockup-dark.svg');

    --hero-gradient:  linear-gradient(135deg, #0c4a6e 0%, #0e7490 100%);

    --shadow-sm:      0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md:      0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg:      0 12px 32px rgba(0, 0, 0, 0.6);
}

/* ── Auto theme — honor OS preference until user picks ──────── */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        color-scheme: dark;
        --canvas:         #0b1220;
        --surface:        #111a2e;
        --raised:         #1a2744;
        --border:         #334155;
        --border-strong:  #475569;
        --text:           #f1f5f9;
        --text-muted:     #94a3b8;
        --text-subtle:    #64748b;
        --text-inverse:   #0b1220;
        --primary:        #22d3ee;
        --primary-hover:  #67e8f9;
        --primary-soft:   rgba(34, 211, 238, 0.14);
        --primary-pressed:rgba(34, 211, 238, 0.28);
        --accent-soft:    rgba(8, 145, 178, 0.18);
        --success:        #10b981;
        --success-soft:   rgba(16, 185, 129, 0.15);
        --warn:           #f59e0b;
        --warn-soft:      rgba(245, 158, 11, 0.15);
        --danger:         #ef4444;
        --danger-soft:    rgba(239, 68, 68, 0.15);
        --info:           #8b5cf6;
        --info-soft:      rgba(139, 92, 246, 0.15);
        --overlay:        rgba(0, 0, 0, 0.6);
        --nav-bg:         rgba(11, 18, 32, 0.88);
        --mark:           url('brand/invenio-mark-dark.svg');
        --lockup:         url('brand/invenio-lockup-dark.svg');
        --hero-gradient:  linear-gradient(135deg, #0c4a6e 0%, #0e7490 100%);
        --shadow-sm:      0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md:      0 4px 12px rgba(0, 0, 0, 0.5);
        --shadow-lg:      0 12px 32px rgba(0, 0, 0, 0.6);
    }
}

/* ── Base Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
    margin: 0;
    font-family: var(--font-base);
    font-size: 14px;
    color: var(--text);
    background: var(--canvas);
    line-height: 1.5;
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    transition:
        background-color var(--motion-standard) var(--ease-standard),
        color var(--motion-standard) var(--ease-standard);
}

/* Hide until auth ready */
html:not(.auth-ready) body { visibility: hidden; }

button, select, input, textarea { font-family: inherit; }

h1, h2 {
    color: var(--text);
    font-weight: 800;
    margin: 0 0 0.5rem;
}
h3, h4, h5, h6 {
    color: var(--text);
    font-weight: 700;
    margin: 0 0 0.5rem;
}

/* Numeric / code */
.mono, code, kbd, samp, pre {
    font-family: var(--font-mono);
}

/* Custom scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--raised); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ── Focus ring (a11y) ──────────────────────────────────────── */
:focus { outline: none; }
:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: var(--radius-sm);
    transition: box-shadow var(--motion-fast) var(--ease-standard);
}

/* ── App Shell (sidebar + main) ─────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition:
        width var(--motion-slow) var(--ease-standard),
        min-width var(--motion-slow) var(--ease-standard),
        background-color var(--motion-standard) var(--ease-standard),
        border-color var(--motion-standard) var(--ease-standard);
    overflow: hidden;
    z-index: 100;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
}

.sidebar-logo {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    min-height: 72px;
}
.sidebar-logo .lockup {
    height: 32px;
    width: auto;
    display: block;
}
.sidebar-logo img {
    height: 32px;
    width: auto;
}
.sidebar-logo .logo-text {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-subtle);
    padding: 16px 12px 6px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition:
        background var(--motion-fast) var(--ease-standard),
        color var(--motion-fast) var(--ease-standard);
    white-space: nowrap;
}
.sidebar-nav a:hover {
    background: var(--raised);
    color: var(--text);
}
.sidebar-nav a.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}
.sidebar-nav a i {
    width: 20px;
    text-align: center;
    font-size: 15px;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-lg);
    background: var(--raised);
}
.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-inverse);
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}
.sidebar-user-info { overflow: hidden; }
.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-email {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-signout {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    transition:
        background var(--motion-fast) var(--ease-standard),
        color var(--motion-fast) var(--ease-standard);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.sidebar-signout:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

/* ── Top Header Bar ─────────────────────────────────────────── */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-header {
    height: var(--header-height);
    min-height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    transition:
        background-color var(--motion-standard) var(--ease-standard),
        border-color var(--motion-standard) var(--ease-standard);
}
.top-header .toggle-btn,
.top-header .header-icon-btn {
    background: none;
    border: none;
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 17px;
    transition:
        background var(--motion-fast) var(--ease-standard),
        color var(--motion-fast) var(--ease-standard);
}
.top-header .toggle-btn { font-size: 18px; }
.top-header .toggle-btn:hover,
.top-header .header-icon-btn:hover {
    background: var(--raised);
    color: var(--text);
}
.top-header .page-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}
.top-header .header-search-wrap { position: relative; }
.top-header .header-search {
    width: 220px;
    padding: 8px 12px 8px 34px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--raised);
    font-size: 13px;
    color: var(--text);
    outline: none;
    transition:
        border-color var(--motion-fast) var(--ease-standard),
        background var(--motion-fast) var(--ease-standard),
        box-shadow var(--motion-fast) var(--ease-standard);
}
.top-header .header-search::placeholder { color: var(--text-subtle); }
.top-header .header-search:focus-visible {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.top-header .header-search-wrap i {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-subtle);
    font-size: 13px;
}
.top-header .notif-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
}

/* Theme toggle in header */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition:
        color var(--motion-fast) var(--ease-standard),
        border-color var(--motion-fast) var(--ease-standard),
        background var(--motion-fast) var(--ease-standard);
}
.theme-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}
.theme-toggle i { font-size: 14px; }
[data-theme="light"] .theme-toggle .icon-sun,
:root:not([data-theme]) .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .theme-toggle .icon-sun { display: inline; }
    :root:not([data-theme]) .theme-toggle .icon-moon { display: none; }
}

/* ── Main Content Scroll Area ───────────────────────────────── */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ── Hero / Dashboard Banner ────────────────────────────────── */
.hero-banner {
    background: var(--hero-gradient);
    border-radius: var(--radius-xl);
    padding: 36px 40px;
    color: #fff;
    position: relative;
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
}
.hero-banner h1 {
    color: #fff;                 /* Always white — hero is a saturated gradient in both themes */
    font-size: 32px;
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.hero-banner h1 i {
    font-size: 30px;             /* Icon scales with the headline */
    line-height: 1;
    color: #fff;
}
.hero-banner p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 15px;
    margin: 0;
}
.hero-banner::before,
.hero-banner::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
}
.hero-banner::before {
    width: 200px; height: 200px;
    top: -60px; right: -40px;
}
.hero-banner::after {
    width: 140px; height: 140px;
    bottom: -40px; right: 60px;
    background: rgba(255, 255, 255, 0.05);
}

.hero-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
    align-items: center;
}

/* ── Buttons (canonical InvenioStyle) ───────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    transition:
        background var(--motion-fast) var(--ease-standard),
        color var(--motion-fast) var(--ease-standard),
        border-color var(--motion-fast) var(--ease-standard),
        box-shadow var(--motion-fast) var(--ease-standard);
    text-decoration: none;
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
}
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 48px; padding: 0 20px; font-size: 15px; }

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
}
.btn-primary:hover {
    background: var(--primary-hover);
    color: var(--text-inverse);
}

.btn-secondary {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: var(--primary);
}
.btn-secondary:hover {
    background: var(--primary-pressed);
    color: var(--primary-hover);
}

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--raised); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); color: #fff; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline:hover {
    background: var(--primary-soft);
    color: var(--primary-hover);
}

/* On-hero variants — invert against the gradient */
.hero-actions .btn-primary {
    background: var(--surface);
    color: var(--primary);
}
.hero-actions .btn-primary:hover { background: var(--raised); color: var(--primary-hover); }
.hero-actions .btn-secondary,
.hero-actions .btn-ghost {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.32);
    backdrop-filter: blur(4px);
}
.hero-actions .btn-secondary:hover,
.hero-actions .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.24);
    color: #fff;
}

/* Bootstrap-class compatibility */
.btn-primary, .btn-outline-primary, .btn-secondary {
    font-family: inherit;
}
.btn-outline-primary {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}
.btn-outline-primary:hover {
    background: var(--primary-soft);
    color: var(--primary-hover);
    border-color: var(--primary);
}

/* ── Cards ──────────────────────────────────────────────────── */
.card, .msr-card, .surface {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition:
        background-color var(--motion-standard) var(--ease-standard),
        border-color var(--motion-standard) var(--ease-standard),
        box-shadow var(--motion-standard) var(--ease-standard);
}
.card:hover, .msr-card:hover {
    box-shadow: var(--shadow-md);
}

.card-header, .msr-card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body, .msr-card-body {
    padding: 20px 24px;
}

/* ── KPI / Metric Cards ─────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--motion-fast) var(--ease-standard),
        box-shadow var(--motion-standard) var(--ease-standard),
        background-color var(--motion-standard) var(--ease-standard),
        border-color var(--motion-standard) var(--ease-standard);
}
.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
.kpi-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
    font-family: var(--font-mono);
    font-feature-settings: "tnum" 1;
}
.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}
.kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.kpi-icon.blue   { background: var(--primary-soft); color: var(--primary); }
.kpi-icon.teal   { background: var(--accent-soft);  color: var(--accent);  }
.kpi-icon.green  { background: var(--success-soft); color: var(--success); }
.kpi-icon.amber  { background: var(--warn-soft);    color: var(--warn);    }
.kpi-icon.red    { background: var(--danger-soft);  color: var(--danger);  }
.kpi-icon.purple { background: var(--info-soft);    color: var(--info);    }

/* ── Tables ─────────────────────────────────────────────────── */
.table-container {
    max-height: 500px;
    overflow-y: auto;
}

table.table {
    font-size: 13px;
    margin-bottom: 0;
    width: 100%;
    border-collapse: collapse;
}
table.table thead {
    background: var(--raised);
}
table.table thead th {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    text-align: left;
    white-space: nowrap;
    background: var(--raised);
}
table.table tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
    font-size: 14px;
}
table.table tbody tr {
    transition: background var(--motion-fast) var(--ease-standard);
}
table.table tbody tr:hover {
    background: var(--raised);
}
table.table tbody tr:last-child td { border-bottom: 0; }

/* Numeric / monospaced cells */
table.table td.po,
table.table td.mono,
table.table td.num {
    font-family: var(--font-mono);
    font-feature-settings: "tnum" 1;
}

/* Density variants */
table.table.density-compact thead th { padding: 8px 12px; font-size: 11px; }
table.table.density-compact tbody td { padding: 6px 12px; font-size: 13px; line-height: 1.35; }
table.table.density-spacious thead th { padding: 16px 20px; }
table.table.density-spacious tbody td { padding: 18px 20px; font-size: 15px; }

/* ── Chips / Badges ─────────────────────────────────────────── */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}
.chip-primary { background: var(--primary-soft); color: var(--primary); }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-warn    { background: var(--warn-soft);    color: var(--warn);    }
.chip-danger  { background: var(--danger-soft);  color: var(--danger);  }
.chip-info    { background: var(--info-soft);    color: var(--info);    }

.badge {
    font-weight: 600;
    font-size: 10px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
}
.bg-success { background-color: var(--success) !important; color: #fff !important; }
.bg-warning { background-color: var(--warn) !important;    color: #fff !important; }
.bg-danger  { background-color: var(--danger) !important;  color: #fff !important; }
.bg-info    { background-color: var(--accent) !important;  color: #fff !important; }

/* ── Tab pills (Bootstrap override) ─────────────────────────── */
.nav-pills .nav-link {
    color: var(--text-muted);
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 13px;
    padding: 8px 16px;
    transition:
        background var(--motion-fast) var(--ease-standard),
        color var(--motion-fast) var(--ease-standard);
    border: 1px solid transparent;
}
.nav-pills .nav-link:hover {
    background: var(--raised);
    color: var(--text);
}
.nav-pills .nav-link.active {
    background: var(--primary);
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}

/* ── Forms ──────────────────────────────────────────────────── */
.form-control, .form-select, .form-input, .form-textarea {
    font-family: inherit;
    font-size: 14px;
    min-height: 40px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    transition:
        border-color var(--motion-fast) var(--ease-standard),
        background var(--motion-fast) var(--ease-standard),
        box-shadow var(--motion-fast) var(--ease-standard);
}
.form-control::placeholder, .form-input::placeholder, .form-textarea::placeholder {
    color: var(--text-subtle);
}
.form-control:hover, .form-select:hover, .form-input:hover, .form-textarea:hover {
    border-color: var(--border-strong);
}
.form-control:focus, .form-select:focus,
.form-control:focus-visible, .form-select:focus-visible,
.form-input:focus-visible, .form-textarea:focus-visible {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-textarea { min-height: 88px; resize: vertical; }

.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-helper { font-size: 13px; color: var(--text-muted); }
.form-error { font-size: 13px; color: var(--danger); }

/* ── Chart container ────────────────────────────────────────── */
.chart-container {
    position: relative;
    height: 300px;
}

/* ── Loading spinner ────────────────────────────────────────── */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ── Status indicator ───────────────────────────────────────── */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.live    { background: var(--success); animation: pulse 2s infinite; }
.status-dot.warning { background: var(--warn); }
.status-dot.danger  { background: var(--danger); }

/* ── Phase / Discipline Cards ───────────────────────────────── */
.phase-card {
    transition:
        transform var(--motion-fast) var(--ease-standard),
        box-shadow var(--motion-standard) var(--ease-standard);
    cursor: pointer;
}
.phase-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.disc-chip {
    transition: transform var(--motion-fast) var(--ease-standard);
    cursor: pointer;
}
.disc-chip:hover {
    transform: scale(1.03);
}

/* ── Progress bars ──────────────────────────────────────────── */
.progress {
    height: 6px;
    border-radius: 3px;
    background: var(--raised);
}
.progress-bar {
    border-radius: 3px;
    background: var(--primary);
}

/* ── Toast / banner ─────────────────────────────────────────── */
.toast {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: 14px;
    line-height: 1.45;
}
.toast-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.toast-warn    { background: var(--warn-soft);    border-color: var(--warn);    color: var(--warn); }
.toast-danger  { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.toast-info    { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* ── Bootstrap utility overrides ────────────────────────────── */
.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.text-primary { color: var(--primary) !important; }
.text-dark    { color: var(--text) !important; }
.text-muted   { color: var(--text-muted) !important; }
.bg-primary   { background-color: var(--primary) !important; }

/* Token-aware overrides for Bootstrap's bg utilities — these otherwise
   render as hard-coded #fff / #f8f9fa and break dark mode by bleeding
   white through cards, sub-panels, and chart wrappers. */
.bg-white { background-color: var(--surface) !important; }
.bg-light { background-color: var(--raised) !important; }
.bg-body  { background-color: var(--canvas) !important; }

/* Bootstrap card defaults inherit a white background — token-ize them. */
.card {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
.card-header { background-color: var(--surface); border-color: var(--border); }
.card-footer { background-color: var(--raised); border-color: var(--border); }

/* Bootstrap modal */
.modal-content { background-color: var(--surface); color: var(--text); border-color: var(--border); }
.modal-header, .modal-footer { border-color: var(--border); }

/* Bootstrap dropdown */
.dropdown-menu { background-color: var(--surface); border-color: var(--border); }
.dropdown-item { color: var(--text); }
.dropdown-item:hover, .dropdown-item:focus { background-color: var(--raised); color: var(--text); }
.dropdown-divider { border-color: var(--border); }

/* Bootstrap list-group */
.list-group-item { background-color: var(--surface); border-color: var(--border); color: var(--text); }
.list-group-item-action:hover { background-color: var(--raised); }

/* Bootstrap form-check (checkboxes/radios) */
.form-check-input {
    background-color: var(--surface);
    border-color: var(--border-strong);
}
.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* Chart canvas — inherit card background, no forced white */
canvas { background: transparent !important; }

/* Bootstrap .table — override the CSS variables that force every cell
   to var(--bs-body-bg) (white) via an inset box-shadow. Without this,
   .table rows stay white in dark mode regardless of the card surface
   underneath. Tables NOT using our `.table.table` rules (i.e. plain
   Bootstrap tables) also get themed automatically. */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: var(--raised);
    --bs-table-striped-color: var(--text);
    --bs-table-hover-bg: var(--raised);
    --bs-table-hover-color: var(--text);
    --bs-table-active-bg: var(--primary-soft);
    --bs-table-active-color: var(--primary);
    color: var(--text);
    border-color: var(--border);
}

/* Bootstrap's <thead class="table-light"> bakes in #f8f9fa + black text;
   point it at our raised + muted-text tokens instead. */
.table-light,
.table > thead.table-light,
.table > thead > tr.table-light {
    --bs-table-bg: var(--raised);
    --bs-table-color: var(--text-muted);
    --bs-table-border-color: var(--border);
    background-color: var(--raised) !important;
    color: var(--text-muted) !important;
}
.table-light th,
.table > thead.table-light th {
    background-color: var(--raised) !important;
    color: var(--text-muted) !important;
    border-color: var(--border) !important;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.collapsed {
        width: 0;
        min-width: 0;
        box-shadow: none;
    }
    .kpi-grid { grid-template-columns: 1fr; }
    .hero-banner { padding: 24px; }
    .top-header .header-search { width: 140px; }
}

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

/* ── Print stylesheet ───────────────────────────────────────── */
@media print {
    body { background: #fff; color: #000; font-size: 11pt; overflow: visible; }
    .sidebar, .top-header, .theme-toggle, .hero-actions { display: none !important; }
    .app-shell, .main-area, .main-content { display: block; height: auto; overflow: visible; }
    .card, .msr-card, .kpi-card, .surface, .hero-banner {
        background: #fff !important;
        box-shadow: none !important;
        border: 1px solid #000 !important;
        break-inside: avoid;
    }
    .hero-banner { background: #fff !important; color: #000 !important; }
    .hero-banner h1, .hero-banner p { color: #000 !important; }
    thead { display: table-header-group; }
    tbody tr { break-inside: avoid; }
    thead th {
        background: #eee !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
