/* ============================================================
   OIL AI DDR — DESIGN SYSTEM
   Drilling operations console.

   Design principles, translated from the OIL AI brand voice:
     - Data leads, chrome recedes. Navigation is dark and quiet so the
       report surface is the brightest thing on screen.
     - Colour carries meaning, never decoration. Warm hues (amber/red)
       are reserved for operational state; the cool accent marks only
       what is active or selected.
     - Instrument, not landing page. Hairline borders and tight radii
       instead of gradients, soft shadows and pastel washes.
     - Numbers align. Tabular figures on every data surface so columns
       of depth, ROP and mud weight scan vertically.
   ============================================================ */

/* --- Design Tokens (CSS Custom Properties) --- */
:root {
    /* Chrome — control-room graphite. Used for nav surfaces only. */
    --ro-chrome:         #151C24;
    --ro-chrome-dark:    #0D1218;
    --ro-chrome-hover:   #1F2A35;
    --ro-chrome-line:    #2A3642;

    /* Brand Palette — steel blue for actions, copper for active state.
       The copper accent marks interaction only (active nav, focus, selected
       row, section rules). It is never used to report operational state. */
    --ro-primary:        #1B5E8C;
    --ro-primary-dark:   #12405F;
    --ro-primary-light:  #E7EFF5;
    --ro-accent:         #B85C24;
    --ro-accent-dark:    #94491B;
    --ro-accent-light:   #FAEEE6;

    /* Neutrals */
    --ro-bg:             #F4F6F8;
    --ro-surface:        #FFFFFF;
    --ro-border:         #CFD8E0;
    --ro-border-light:   #E5EAEF;
    --ro-text:           #131A21;
    --ro-text-secondary: #4A5763;
    --ro-text-muted:     #6E7C89;

    /* Status / Operational — desaturated so they read as instrumentation.
       Warning sits in the gold band, clear of the copper accent, so a
       caution state is never mistaken for an active-selection cue. */
    --ro-success:        #157F3D;
    --ro-success-bg:     #EDF7F0;
    --ro-warning:        #8C6908;
    --ro-warning-bg:     #FBF6E3;
    --ro-warning-text:   #5E4605;
    --ro-danger:         #B3261E;
    --ro-danger-bg:      #FBEDEC;
    --ro-info:           #1B6E8C;
    --ro-info-bg:        #EAF2F6;
    --ro-offline:        #6E7C89;

    /* Typography */
    --ro-font:           'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --ro-font-mono:      'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    --ro-text-xs:        0.8125rem; /* 13px */
    --ro-text-sm:        0.875rem;  /* 14px */
    --ro-text-base:      1rem;      /* 16px */
    --ro-text-md:        1.125rem;  /* 18px */
    --ro-text-lg:        1.25rem;   /* 20px */
    --ro-text-xl:        1.5rem;    /* 24px */
    --ro-text-2xl:       1.875rem;  /* 30px */
    --ro-text-3xl:       2.25rem;   /* 36px */

    /* Spacing (8px rhythm) */
    --ro-space-1:  0.25rem;  /* 4px */
    --ro-space-2:  0.5rem;   /* 8px */
    --ro-space-3:  0.75rem;  /* 12px */
    --ro-space-4:  1rem;     /* 16px */
    --ro-space-5:  1.25rem;  /* 20px */
    --ro-space-6:  1.5rem;   /* 24px */
    --ro-space-8:  2rem;     /* 32px */
    --ro-space-10: 2.5rem;   /* 40px */
    --ro-space-12: 3rem;     /* 48px */

    /* Component Tokens — tight radii and hairlines instead of soft shadows */
    --ro-radius-sm:  2px;
    --ro-radius:     3px;
    --ro-radius-lg:  4px;
    --ro-radius-xl:  5px;
    --ro-shadow-sm:  none;
    --ro-shadow:     none;
    --ro-shadow-md:  0 2px 4px rgba(19,26,33,0.07);
    --ro-shadow-lg:  0 8px 24px rgba(13,18,24,0.18);
    --ro-focus-ring: 0 0 0 2px var(--ro-surface), 0 0 0 4px var(--ro-accent);

    /* Sidebar — dark chrome */
    --ro-sidebar-w:              256px;
    --ro-sidebar-bg:             var(--ro-chrome);
    --ro-sidebar-border:         1px solid var(--ro-chrome-line);
    --ro-sidebar-text:           #C9D4DF;
    --ro-sidebar-text-muted:     #7D8C9B;
    --ro-sidebar-hover-bg:       var(--ro-chrome-hover);
    --ro-sidebar-active-bg:      rgba(184,92,36,0.20);
    --ro-sidebar-active-text:    #FFFFFF;
    --ro-sidebar-active-indicator: 2px solid var(--ro-accent);
    --ro-sidebar-section-text:   #AEBDCA;
    --ro-sidebar-focus-ring:     2px solid rgba(184,92,36,0.70);
    --ro-topbar-h:               3.25rem;

    /* Top Bar */
    --ro-topbar-bg:              var(--ro-chrome-dark);
    --ro-topbar-text:            #E8EEF4;
    --ro-topbar-border:          var(--ro-chrome-line);

    /* Table / Panel — header recedes, data leads.
       The column header and the row-label gutter are deliberately different
       weights so a grid never reads as one flat block of tint. */
    --ro-table-header-bg:        #DFE6ED;
    --ro-table-header-text:      #1F2A35;
    --ro-table-header-rule:      #94A3B1;
    --ro-table-row-label-bg:     #F5F7F9;
    --ro-table-hover-bg:         #FBF4EE;
    --ro-panel-header-bg:        #EEF2F6;
    --ro-form-panel-bg:          #FAFBFC;
}

/* --- Base / Reset --- */
html, body {
    font-family: var(--ro-font);
    font-size: var(--ro-text-base);
    color: var(--ro-text);
    background-color: var(--ro-bg);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Figures line up in columns wherever numbers are read side by side. */
.table, .kpi-value, .form-control, .form-select, .badge, .ctx-badge {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--ro-text);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.005em;
}
h1 { font-size: var(--ro-text-2xl); }
h2 { font-size: var(--ro-text-xl); }
h3 { font-size: var(--ro-text-lg); }
h4, h5 { font-size: var(--ro-text-md); }
h6 { font-size: var(--ro-text-base); }

h1:focus { outline: none; }

a, .btn-link {
    color: var(--ro-primary);
    text-decoration: none;
}
a:hover { color: var(--ro-primary-dark); }

/* --- Focus States (Accessibility) --- */
.btn:focus-visible,
.btn:active:focus-visible,
.btn-link.nav-link:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible {
    box-shadow: var(--ro-focus-ring);
    outline: none;
}
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--ro-accent);
    box-shadow: 0 0 0 3px rgba(184,92,36,0.20);
}

/* --- Validation --- */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--ro-success);
}
.invalid {
    outline: 1px solid var(--ro-danger);
}
.validation-message {
    color: var(--ro-danger);
    font-size: var(--ro-text-sm);
    margin-top: var(--ro-space-1);
}

/* --- Blazor Error UI --- */
#blazor-error-ui {
    background: var(--ro-warning-bg);
    border-top: 2px solid var(--ro-warning);
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    display: none;
    left: 0;
    padding: var(--ro-space-3) var(--ro-space-5);
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-size: var(--ro-text-sm);
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: var(--ro-space-3);
    top: var(--ro-space-2);
}

/* ============================================================
   LAYOUT: Page Shell, Sidebar, Top Bar
   ============================================================ */

.page {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    align-items: stretch;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--ro-bg);
    min-height: 100vh;
}

/* --- Sidebar (Light) --- */
.sidebar {
    background-color: var(--ro-sidebar-bg);
    border-right: var(--ro-sidebar-border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar .top-row {
    background-color: var(--ro-chrome-dark);
    border-bottom: 1px solid var(--ro-chrome-line);
    border-right: none;
    height: var(--ro-topbar-h);
    display: flex;
    align-items: center;
    padding: 0 var(--ro-space-4);
    overflow: hidden;
}

/* The brand sits on dark chrome, so it must win over Bootstrap's
   --bs-navbar-brand-color regardless of navbar theme classes. */
.sidebar .top-row .navbar-brand,
.sidebar .top-row .navbar-brand:hover,
.sidebar .top-row .navbar-brand:focus {
    color: #FFFFFF;
    font-weight: 600;
    font-size: var(--ro-text-md);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: var(--ro-space-2);
    padding: 0;
    margin: 0;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
}
.sidebar .top-row .navbar-brand i {
    color: var(--ro-accent);
    flex-shrink: 0;
}
.sidebar .top-row .navbar-brand .navbar-brand-logo,
img.navbar-brand-logo {
    height: 2.5rem;
    width: auto;
    max-height: 2.5rem;
    max-width: 8.75rem;
    object-fit: contain;
    object-position: left center;
    flex-shrink: 0;
    display: block;
}
/* Bootstrap's .navbar adds vertical padding and .container-fluid adds
   gutters; neither is wanted in a fixed-height chrome bar. */
.sidebar .top-row.navbar {
    padding: 0 var(--ro-space-4);
}
.sidebar .top-row > .container-fluid {
    padding: 0;
    margin: 0;
}

/* --- Top Bar --- */
.top-row {
    background-color: var(--ro-topbar-bg);
    border-bottom: 1px solid var(--ro-topbar-border);
    height: var(--ro-topbar-h);
    display: flex;
    align-items: center;
    z-index: 10;
    color: var(--ro-topbar-text);
}

.top-row a, .top-row .btn-link {
    white-space: nowrap;
    margin-left: var(--ro-space-4);
    color: var(--ro-topbar-text);
}
.top-row a:hover, .top-row .btn-link:hover {
    color: rgba(255,255,255,0.85);
}

.top-row a:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-row .app-title {
    font-weight: 600;
    color: var(--ro-topbar-text);
    margin-right: auto;
    font-size: var(--ro-text-sm);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* --- Sidebar Toggle --- */
.sidebar-toggle {
    border: none;
    background: transparent;
    font-size: 1.25rem;
    color: var(--ro-topbar-text);
    width: var(--ro-topbar-h);
    height: var(--ro-topbar-h);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 0;
    transition: color 0.15s, background-color 0.15s;
}
.sidebar-toggle:hover {
    color: #FFFFFF;
    background-color: rgba(255,255,255,0.15);
}
.sidebar-toggle:focus-visible {
    box-shadow: 0 0 0 2px rgba(255,255,255,0.5), 0 0 0 4px var(--ro-accent);
    outline: none;
}

/* --- Responsive Layout --- */
@media (max-width: 640.98px) {
    .top-row:not(.auth):not(.main-top-row) {
        display: none;
    }
    .main-top-row {
        display: flex !important;
    }
    .sidebar {
        width: var(--ro-sidebar-w);
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(0);
        transition: transform 0.25s ease;
    }
    .page.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }
    .nav-scrollable {
        overflow-y: auto;
    }
    .nav-scrollable.collapse { display: none; }
    .nav-scrollable:not(.collapse) { display: block; }
}

@media (min-width: 641px) {
    .page {
        flex-direction: row;
    }
    .sidebar {
        width: var(--ro-sidebar-w);
        min-height: 100%;
        align-self: stretch;
        overflow-x: hidden;
        overflow-y: visible;
        margin-left: 0;
        transition: margin-left 0.25s ease, width 0.25s ease;
    }
    .page.sidebar-collapsed .sidebar {
        width: 0 !important;
        min-width: 0 !important;
        flex: 0 0 0 !important;
        margin-left: calc(var(--ro-sidebar-w) * -1) !important;
        overflow: hidden !important;
        visibility: hidden !important;
    }
    main {
        min-width: 0;
        flex: 1;
    }
    .top-row {
        position: sticky;
        top: 0;
    }
    .top-row, article {
        padding-left: var(--ro-space-6) !important;
        padding-right: var(--ro-space-6) !important;
    }
    .top-row.main-top-row {
        padding-left: 0 !important;
        padding-right: var(--ro-space-4) !important;
    }
    .nav-scrollable,
    .nav-scrollable.collapse {
        display: block !important;
        overflow: visible;
        flex: 1 1 auto;
    }
}

/* ============================================================
   NAVIGATION MENU
   ============================================================ */

.nav-scrollable {
    overflow-x: hidden;
    overflow-y: visible;
    flex: 1;
    padding: var(--ro-space-2) 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.20) transparent;
}
.nav-scrollable::-webkit-scrollbar { width: 4px; }
.nav-scrollable::-webkit-scrollbar-track { background: transparent; }
.nav-scrollable::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.20);
    border-radius: 2px;
}

.navbar-toggler {
    background-color: var(--ro-sidebar-hover-bg);
    border: 1px solid var(--ro-chrome-line);
    color: var(--ro-sidebar-text);
}

.nav-item {
    padding: 1px var(--ro-space-3);
}
.nav-item:first-child { padding-top: var(--ro-space-2); }
.nav-item:last-child  { padding-bottom: var(--ro-space-2); }

/* NOTE: ::deep only works in scoped Component.razor.css files. This is a
   global stylesheet, so ::deep makes the whole rule invalid and the browser
   drops it. Plain descendant selectors are required here. */
.nav-item a {
    color: var(--ro-sidebar-text);
    border-radius: var(--ro-radius);
    height: 2.25rem;
    display: flex;
    align-items: center;
    line-height: 2.25rem;
    padding: 0 var(--ro-space-3);
    font-size: var(--ro-text-sm);
    font-weight: 400;
    transition: background-color 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}
.nav-item a .bi,
.nav-item a .oi {
    color: var(--ro-sidebar-text-muted);
}
.nav-item a.active {
    background-color: var(--ro-sidebar-active-bg);
    color: var(--ro-sidebar-active-text);
    font-weight: 500;
    border-left: var(--ro-sidebar-active-indicator);
}
.nav-item a.active .bi,
.nav-item a.active .oi {
    color: var(--ro-sidebar-active-text);
}
.nav-item a:hover {
    background-color: var(--ro-sidebar-hover-bg);
    color: #FFFFFF;
}
.nav-item a:hover .bi,
.nav-item a:hover .oi {
    color: #FFFFFF;
}
.nav-item a:focus-visible {
    outline: var(--ro-sidebar-focus-ring);
    outline-offset: 2px;
}

/* Nav Section Headers */
.nav-header {
    padding-top: var(--ro-space-3);
    padding-bottom: var(--ro-space-1);
}
.nav-header small {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ro-sidebar-section-text) !important;
    font-weight: 700;
}

/* Nav Icons */
.nav-link .bi {
    font-size: 1rem;
    margin-right: var(--ro-space-2);
    width: 1.25rem;
    text-align: center;
    vertical-align: middle;
    color: var(--ro-sidebar-text-muted);
}
.nav-item a.active .bi {
    color: var(--ro-sidebar-active-text);
}

.nav-link .oi {
    font-size: 0.875rem;
    margin-right: var(--ro-space-2);
    width: 1.25rem;
    text-align: center;
    color: var(--ro-sidebar-text-muted);
}

/* Collapsible Sections */
.nav-section {
    margin-bottom: 2px;
}
.nav-section-header {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s;
    border-radius: var(--ro-radius);
    margin: 0 var(--ro-space-2);
    padding: var(--ro-space-2) var(--ro-space-2);
}
.nav-section-header:hover {
    background-color: var(--ro-sidebar-hover-bg);
}
.nav-section-header:focus-visible {
    outline: var(--ro-sidebar-focus-ring);
    outline-offset: 2px;
}
.nav-section-header small {
    display: flex;
    align-items: center;
    gap: var(--ro-space-2);
    color: var(--ro-sidebar-section-text) !important;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.nav-section-header:hover small {
    color: #FFFFFF !important;
}
.nav-section-header i.bi {
    font-size: 0.625rem;
    transition: transform 0.2s;
    color: var(--ro-accent);
}

/* Section divider line above each section */
.nav-section + .nav-section {
    border-top: 1px solid var(--ro-chrome-line);
    margin-top: var(--ro-space-2);
    padding-top: var(--ro-space-1);
}
.nav-section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease-out;
}
.nav-section-content.show {
    max-height: 2000px;
    transition: max-height 0.4s ease-in;
}

/* ============================================================
   CONTENT AREA
   ============================================================ */

.content {
    padding-top: var(--ro-space-6);
    padding-bottom: var(--ro-space-8);
    flex: 1;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ro-space-4);
    margin-bottom: var(--ro-space-6);
    flex-wrap: wrap;
}
.page-header h1 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--ro-space-3);
    color: var(--ro-text);
    padding-bottom: var(--ro-space-2);
    border-bottom: 2px solid var(--ro-accent);
}
.page-header h1 i {
    color: var(--ro-text-muted);
    font-size: var(--ro-text-xl);
}
.page-header-actions {
    display: flex;
    align-items: center;
    gap: var(--ro-space-2);
}

/* Admin Chip */
.admin-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--ro-space-1);
    background-color: var(--ro-warning-bg);
    border: 1px solid var(--ro-warning);
    color: var(--ro-warning-text);
    font-size: var(--ro-text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px var(--ro-space-2);
    border-radius: var(--ro-radius-sm);
}

/* ============================================================
   DRILL CONTEXT BAR
   ============================================================ */

.drill-context-container {
    background-color: var(--ro-panel-header-bg);
    border-bottom: 1px solid var(--ro-border);
    padding: var(--ro-space-2) var(--ro-space-6);
}

.drill-context-bar {
    display: flex;
    align-items: center;
    gap: var(--ro-space-4);
    flex-wrap: wrap;
    font-size: var(--ro-text-sm);
}
.drill-context-bar .context-item {
    display: flex;
    align-items: center;
    gap: var(--ro-space-2);
}
.drill-context-bar .context-item label {
    font-weight: 600;
    color: var(--ro-text-secondary);
    margin-bottom: 0;
    white-space: nowrap;
    font-size: var(--ro-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.drill-context-bar .context-item select,
.drill-context-bar .context-item input {
    min-width: 140px;
    font-size: var(--ro-text-sm);
    height: 2rem;
    padding: 0 var(--ro-space-2);
}
.drill-context-bar .context-info {
    margin-left: auto;
}
.drill-context-bar .context-details {
    margin-left: auto;
}
.drill-context-bar .badge {
    font-size: var(--ro-text-xs);
    font-weight: 500;
    padding: 3px var(--ro-space-2);
    border-radius: var(--ro-radius-sm);
}

/* Context badge — reads as an instrument value, not a label */
.ctx-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--ro-space-1);
    font-family: var(--ro-font-mono);
    font-size: var(--ro-text-xs);
    font-weight: 500;
    padding: 2px var(--ro-space-2);
    border-radius: var(--ro-radius-sm);
    background-color: var(--ro-surface);
    color: var(--ro-text);
    border: 1px solid var(--ro-border);
}

/* ============================================================
   BUTTONS (Bootstrap Overrides)
   ============================================================ */

.btn {
    font-size: var(--ro-text-sm);
    font-weight: 500;
    border-radius: var(--ro-radius);
    padding: var(--ro-space-2) var(--ro-space-4);
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: var(--ro-space-2);
    line-height: 1.4;
}
.btn-sm {
    padding: var(--ro-space-1) var(--ro-space-3);
    font-size: var(--ro-text-xs);
    border-radius: var(--ro-radius-sm);
    min-height: 1.75rem;
}

.btn-primary {
    background-color: var(--ro-primary);
    border-color: var(--ro-primary);
    color: #fff;
}
.btn-primary:hover {
    background-color: var(--ro-primary-dark);
    border-color: var(--ro-primary-dark);
}

.btn-success {
    background-color: var(--ro-success);
    border-color: var(--ro-success);
}
.btn-danger {
    background-color: var(--ro-danger);
    border-color: var(--ro-danger);
}
.btn-info {
    background-color: var(--ro-info);
    border-color: var(--ro-info);
    color: #fff;
}

.btn-outline-primary {
    color: var(--ro-primary);
    border-color: var(--ro-primary);
}
.btn-outline-primary:hover {
    background-color: var(--ro-primary);
    color: #fff;
}

.btn-outline-secondary {
    color: var(--ro-text-secondary);
    border-color: var(--ro-border);
}
.btn-outline-secondary:hover {
    background-color: var(--ro-bg);
    color: var(--ro-text);
    border-color: var(--ro-text-secondary);
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
    border: 1px solid var(--ro-border);
    border-radius: var(--ro-radius-lg);
    box-shadow: var(--ro-shadow-sm);
    background-color: var(--ro-surface);
    margin-bottom: var(--ro-space-4);
}
.card-header {
    background-color: var(--ro-panel-header-bg);
    font-weight: 600;
    border-bottom: 1px solid var(--ro-border);
    border-left: 2px solid var(--ro-accent);
    padding: var(--ro-space-2) var(--ro-space-4);
    font-size: var(--ro-text-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ro-text-secondary);
    border-radius: var(--ro-radius-lg) var(--ro-radius-lg) 0 0;
}
.card-body {
    padding: var(--ro-space-4);
}

/* ============================================================
   KPI / DASHBOARD CARDS
   ============================================================ */

.kpi-card {
    border: 1px solid var(--ro-border);
    border-radius: var(--ro-radius-lg);
    background: var(--ro-surface);
    box-shadow: var(--ro-shadow-sm);
    padding: var(--ro-space-4) var(--ro-space-5);
    display: flex;
    align-items: flex-start;
    gap: var(--ro-space-4);
    transition: border-color 0.15s;
}
.kpi-card:hover {
    border-color: var(--ro-text-muted);
}
/* Neutral by default. The value is the hero, not the icon — so the icon
   only takes on colour when it is reporting an actual operational state. */
.kpi-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--ro-radius-sm);
    border: 1px solid var(--ro-border);
    background: var(--ro-bg);
    color: var(--ro-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.0625rem;
    flex-shrink: 0;
}
.kpi-icon.success   { color: var(--ro-success); border-color: rgba(21,127,61,0.40);  background: var(--ro-success-bg); }
.kpi-icon.warning   { color: var(--ro-warning); border-color: rgba(140,105,8,0.40);  background: var(--ro-warning-bg); }
.kpi-icon.danger    { color: var(--ro-danger);  border-color: rgba(179,38,30,0.40);  background: var(--ro-danger-bg); }

.kpi-content { flex: 1; min-width: 0; }
.kpi-label {
    font-size: var(--ro-text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ro-text-secondary);
    margin-bottom: 2px;
}
.kpi-card-hero .kpi-value {
    font-size: var(--ro-text-3xl);
}

.kpi-value {
    font-size: var(--ro-text-2xl);
    font-weight: 700;
    color: var(--ro-text);
    line-height: 1.2;
}
.kpi-meta {
    font-size: var(--ro-text-xs);
    color: var(--ro-text-muted);
    margin-top: 2px;
}

/* ============================================================
   TABLES
   ============================================================ */

.table {
    font-size: var(--ro-text-sm);
    margin-bottom: 0;
}
.table > thead > tr > th {
    background-color: var(--ro-table-header-bg);
    color: var(--ro-table-header-text);
    font-weight: 700;
    font-size: var(--ro-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--ro-table-header-rule);
    padding: var(--ro-space-2) var(--ro-space-3);
    vertical-align: middle;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}
.table.table-light > thead > tr > th,
.table thead.table-light > tr > th {
    background-color: var(--ro-table-header-bg);
    color: var(--ro-table-header-text);
}
.table.table-dark > thead > tr > th,
.table thead.table-dark > tr > th {
    background-color: var(--ro-chrome);
    color: #E8EEF4;
    border-bottom-color: var(--ro-chrome-dark);
}
.table > tbody > tr > td {
    padding: var(--ro-space-2) var(--ro-space-3);
    vertical-align: middle;
    border-bottom: 1px solid var(--ro-border-light);
    color: var(--ro-text);
}
.table > tbody > tr:last-child > td {
    border-bottom: none;
}
.table-hover > tbody > tr:hover > td {
    background-color: var(--ro-table-hover-bg);
}
.table-striped > tbody > tr:nth-of-type(odd) > td {
    background-color: #FAFBFC;
}
.table-striped > tbody > tr:nth-of-type(odd):hover > td {
    background-color: var(--ro-table-hover-bg);
}

/* Current-row highlight */
.table > tbody > tr.table-primary > td {
    background-color: var(--ro-accent-light);
    border-left: 2px solid var(--ro-accent);
}

/* Empty state */
.table-empty {
    text-align: center;
    padding: var(--ro-space-10) var(--ro-space-4);
    color: var(--ro-text-muted);
}
.table-empty i {
    font-size: 2.5rem;
    display: block;
    margin-bottom: var(--ro-space-3);
    opacity: 0.4;
}

/* ============================================================
   FORMS
   ============================================================ */

.form-label {
    font-weight: 500;
    font-size: var(--ro-text-sm);
    color: var(--ro-text);
    margin-bottom: 2px;
}
.form-control,
.form-select {
    border: 1px solid var(--ro-border);
    border-radius: var(--ro-radius);
    font-size: var(--ro-text-sm);
    color: var(--ro-text);
    background-color: var(--ro-surface);
    padding: var(--ro-space-1) var(--ro-space-3);
    height: 2rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
textarea.form-control {
    height: auto;
}
.form-control::placeholder {
    color: var(--ro-text-muted);
}
.form-text {
    font-size: var(--ro-text-xs);
    color: var(--ro-text-muted);
}

/* Compact form rows: same vertical rhythm in both container types. */
.card-body .mb-3,
.form-fieldset .mb-3 {
    margin-bottom: var(--ro-space-2) !important;
}
.card-body .row,
.form-fieldset .row {
    --bs-gutter-y: 0;
}

/* Form section headings */
.form-section-title {
    font-size: var(--ro-text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ro-text-secondary);
    padding: var(--ro-space-2) var(--ro-space-3);
    margin-bottom: var(--ro-space-3);
    margin-top: var(--ro-space-4);
    background-color: var(--ro-panel-header-bg);
    border-left: 2px solid var(--ro-accent);
    border-bottom: 1px solid var(--ro-border);
    border-radius: var(--ro-radius-sm);
    display: flex;
    align-items: center;
    gap: var(--ro-space-2);
}
.form-section-title:first-child {
    margin-top: 0;
}

/* Form fieldsets and grid-style data entry tables.

   Some pages group fields in a .card with a .card-header, others in a
   <fieldset> with a <legend>. Both are styled to render identically here,
   so a form looks the same regardless of which container it was built
   with. The negative legend margin cancels the fieldset's own padding so
   the legend spans the full width like a card header. */
.form-fieldset {
    background-color: var(--ro-surface);
    border: 1px solid var(--ro-border) !important;
    border-radius: var(--ro-radius-lg) !important;
    padding: var(--ro-space-4) !important;
}
.form-fieldset > legend {
    display: block;
    float: none;
    width: calc(100% + var(--ro-space-4) * 2) !important;
    margin: calc(var(--ro-space-4) * -1) calc(var(--ro-space-4) * -1) var(--ro-space-4);
    padding: var(--ro-space-2) var(--ro-space-4);
    background-color: var(--ro-panel-header-bg);
    border-bottom: 1px solid var(--ro-border);
    border-left: 2px solid var(--ro-accent);
    border-radius: var(--ro-radius-lg) var(--ro-radius-lg) 0 0;
    font-size: var(--ro-text-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.45;
    color: var(--ro-text-secondary);
}

.form-panel-body {
    background-color: var(--ro-surface);
}
/* Row-based entry grid sitting on a tinted fieldset: the grid itself stays
   white so the data reads against the panel behind it. */
.form-grid-table {
    background-color: var(--ro-surface);
}

.form-data-table {
    background-color: var(--ro-surface);
}
.form-data-table > tbody > tr > td:first-child {
    background-color: var(--ro-table-row-label-bg);
    color: var(--ro-text-secondary);
    font-weight: 600;
    border-right: 1px solid var(--ro-border);
}

/* Ensure multi-column even at smaller widths */
@media (min-width: 576px) and (max-width: 767.98px) {
    .card-body .col-md-3 { flex: 0 0 50%; max-width: 50%; }
    .card-body .col-md-4 { flex: 0 0 50%; max-width: 50%; }
    .card-body .col-md-6 { flex: 0 0 50%; max-width: 50%; }
}

/* Required indicator */
.required-indicator {
    color: var(--ro-danger);
    font-weight: 600;
}

/* Form action bar */
.form-actions {
    display: flex;
    align-items: center;
    gap: var(--ro-space-3);
    padding-top: var(--ro-space-4);
    margin-top: var(--ro-space-4);
    border-top: 1px solid var(--ro-border-light);
}

/* ============================================================
   BADGES / STATUS
   ============================================================ */

.badge {
    font-size: var(--ro-text-xs);
    font-weight: 500;
    padding: 3px var(--ro-space-2);
    border-radius: var(--ro-radius-sm);
    letter-spacing: 0.01em;
}
.badge.bg-primary { background-color: var(--ro-primary) !important; }
.badge.bg-success { background-color: var(--ro-success) !important; }
.badge.bg-warning { background-color: var(--ro-warning) !important; color: #fff !important; }
.badge.bg-danger  { background-color: var(--ro-danger) !important; }
.badge.bg-info    { background-color: var(--ro-info) !important; color: #fff !important; }

/* Status badges (soft variant) */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--ro-space-2);
    padding: 2px var(--ro-space-2);
    border-radius: var(--ro-radius-sm);
    border: 1px solid transparent;
    font-size: var(--ro-text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-active  { background: var(--ro-success-bg); color: #0F5F2D; border-color: rgba(21,127,61,0.35); }
.status-active::before  { background-color: var(--ro-success); }
.status-inactive { background: var(--ro-bg); color: var(--ro-offline); border-color: var(--ro-border); }
.status-inactive::before { background-color: var(--ro-offline); }
.status-warning { background: var(--ro-warning-bg); color: var(--ro-warning-text); border-color: rgba(140,105,8,0.35); }
.status-warning::before { background-color: var(--ro-warning); }
.status-danger  { background: var(--ro-danger-bg); color: #8A1D17; border-color: rgba(179,38,30,0.35); }
.status-danger::before  { background-color: var(--ro-danger); }

/* ============================================================
   ALERTS
   ============================================================ */

.alert {
    border-radius: var(--ro-radius);
    font-size: var(--ro-text-sm);
    padding: var(--ro-space-3) var(--ro-space-4);
    border-width: 0;
    border-left-width: 3px;
}
.alert-info {
    background-color: var(--ro-info-bg);
    border-color: var(--ro-info);
    color: #124F66;
}
.alert-warning {
    background-color: var(--ro-warning-bg);
    border-color: var(--ro-warning);
    color: var(--ro-warning-text);
}
.alert-success {
    background-color: var(--ro-success-bg);
    border-color: var(--ro-success);
    color: #0D5628;
}
.alert-danger {
    background-color: var(--ro-danger-bg);
    border-color: var(--ro-danger);
    color: #7C1A14;
}

/* Context well-info banner */
.well-context-banner {
    display: flex;
    align-items: center;
    gap: var(--ro-space-4);
    flex-wrap: wrap;
    background: var(--ro-surface);
    border: 1px solid var(--ro-border);
    border-left: 2px solid var(--ro-accent);
    border-radius: var(--ro-radius);
    padding: var(--ro-space-3) var(--ro-space-4);
    margin-bottom: var(--ro-space-4);
    font-size: var(--ro-text-sm);
}
.well-context-banner strong {
    color: var(--ro-text);
}

/* ============================================================
   TOP BAR ACTIONS & USER INFO
   ============================================================ */

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: var(--ro-space-3);
    padding-right: var(--ro-space-2);
}
.top-bar-actions .btn {
    white-space: nowrap;
    font-size: var(--ro-text-xs);
    padding: var(--ro-space-1) var(--ro-space-3);
}
.top-bar-actions .btn-outline-secondary {
    color: rgba(255,255,255,0.9);
    border-color: rgba(255,255,255,0.35);
    background: transparent;
}
.top-bar-actions .btn-outline-secondary:hover {
    background-color: rgba(255,255,255,0.15);
    color: #FFFFFF;
    border-color: rgba(255,255,255,0.55);
}

.user-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--ro-space-2);
    padding: var(--ro-space-1) var(--ro-space-3);
    border-radius: var(--ro-radius);
    transition: background-color 0.15s;
    border: 1px solid rgba(255,255,255,0.30);
    font-size: var(--ro-text-sm);
    color: #FFFFFF;
    background: rgba(255,255,255,0.10);
}
.user-dropdown-toggle:hover {
    background-color: rgba(255,255,255,0.20);
    border-color: rgba(255,255,255,0.50);
}
.user-dropdown-toggle .bi-person-circle { font-size: 1.125rem; color: rgba(255,255,255,0.9); }
.user-dropdown-toggle .bi-chevron-down { font-size: 0.625rem; color: rgba(255,255,255,0.65); }

.user-email {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--ro-text-sm);
    color: #FFFFFF;
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    z-index: 1040;
}
.dropdown.show { z-index: 1050; }

.dropdown-menu {
    min-width: 240px;
    border-radius: var(--ro-radius-lg);
    padding: var(--ro-space-2) 0;
    box-shadow: var(--ro-shadow-lg);
    border: 1px solid var(--ro-border);
    display: none;
    background-color: var(--ro-surface) !important;
    opacity: 1 !important;
    z-index: 1050 !important;
    position: absolute;
}
.dropdown-menu.show {
    display: block;
    background-color: var(--ro-surface) !important;
}
.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    background-color: var(--ro-surface);
    border-radius: var(--ro-radius-lg);
    z-index: -1;
}
.dropdown-menu * { opacity: 1 !important; }
.dropdown-menu li { background-color: transparent; opacity: 1; }

.dropdown-header {
    padding: var(--ro-space-3) var(--ro-space-4);
    background-color: var(--ro-panel-header-bg) !important;
    border-bottom: 1px solid var(--ro-border-light);
    margin-bottom: var(--ro-space-1);
}
.dropdown-header .fw-bold { color: var(--ro-text); font-weight: 600; font-size: var(--ro-text-sm); }
.dropdown-header .text-muted { color: var(--ro-text-muted) !important; font-size: var(--ro-text-xs); }

.dropdown-item {
    padding: var(--ro-space-2) var(--ro-space-4);
    display: flex;
    align-items: center;
    gap: var(--ro-space-2);
    font-size: var(--ro-text-sm);
    color: var(--ro-text);
    transition: background-color 0.1s;
}
.dropdown-item i { width: 1.125rem; text-align: center; font-size: 0.9375rem; color: var(--ro-text-secondary); }
.dropdown-item:hover {
    background-color: var(--ro-bg) !important;
    color: var(--ro-text);
}
.dropdown-item.text-danger { color: var(--ro-danger); }
.dropdown-item.text-danger i { color: var(--ro-danger); }
.dropdown-item.text-danger:hover { background-color: var(--ro-danger-bg) !important; }

.dropdown-divider {
    margin: var(--ro-space-1) 0;
    border-top: 1px solid var(--ro-border-light);
}
.dropdown-item-form { padding: 0; margin: 0; }
.dropdown-item form { width: 100%; margin: 0; }
.dropdown-item button {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
    font: inherit;
    display: flex;
    align-items: center;
    gap: var(--ro-space-2);
}
.dropdown-item button:hover { background: none; }
.dropdown-item button:focus { outline: none; }

@media (max-width: 991px) {
    .user-email { display: none !important; }
    .user-dropdown-toggle { padding: var(--ro-space-1) var(--ro-space-2); }
}

/* ============================================================
   MODALS
   ============================================================ */

.modal.show { display: block !important; }

.modal-content {
    border-radius: var(--ro-radius-xl);
    border: 1px solid var(--ro-border);
    box-shadow: var(--ro-shadow-lg);
}
.modal-header {
    border-bottom: 1px solid var(--ro-border-light);
    padding: var(--ro-space-4);
}
.modal-header .modal-title {
    font-size: var(--ro-text-md);
    font-weight: 600;
}
.modal-header.bg-danger {
    background-color: var(--ro-danger) !important;
    border-radius: var(--ro-radius-xl) var(--ro-radius-xl) 0 0;
}
.modal-body { padding: var(--ro-space-4); }
.modal-footer {
    border-top: 1px solid var(--ro-border-light);
    padding: var(--ro-space-3) var(--ro-space-4);
}

/* ============================================================
   TABS
   ============================================================ */

.nav-tabs {
    border-bottom: 1px solid var(--ro-border);
}
.nav-tabs .nav-link {
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: var(--ro-space-2) var(--ro-space-4);
    color: var(--ro-text-secondary);
    font-size: var(--ro-text-sm);
    font-weight: 500;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.nav-tabs .nav-link:hover {
    border-bottom-color: var(--ro-border);
    background-color: transparent;
    color: var(--ro-text);
}
.nav-tabs .nav-link.active {
    color: var(--ro-text);
    background-color: transparent;
    border-bottom-color: var(--ro-accent);
    font-weight: 700;
}
.nav-tabs .nav-item { margin-bottom: -1px; }

/* ============================================================
   PROGRESS BARS
   ============================================================ */

.progress {
    height: 0.375rem;
    border-radius: var(--ro-radius-sm);
    background-color: var(--ro-border-light);
}
.progress-bar {
    background-color: var(--ro-accent);
    border-radius: var(--ro-radius-sm);
    font-size: 0;
}

/* ============================================================
   LOADING / SPINNER
   ============================================================ */

.spinner-border { color: var(--ro-primary); }

.loading-placeholder {
    text-align: center;
    padding: var(--ro-space-10);
    color: var(--ro-text-muted);
}
.loading-placeholder .spinner-border {
    width: 2rem;
    height: 2rem;
    margin-bottom: var(--ro-space-3);
}

/* ============================================================
   EMPTY STATES
   ============================================================ */

.empty-state {
    text-align: center;
    padding: var(--ro-space-10) var(--ro-space-4);
    color: var(--ro-text-muted);
}
.empty-state-icon {
    font-size: 3rem;
    opacity: 0.25;
    margin-bottom: var(--ro-space-3);
    display: block;
}
.empty-state-text {
    font-size: var(--ro-text-base);
    margin-bottom: var(--ro-space-4);
}

/* ============================================================
   PRINT
   ============================================================ */

.jalali-date-picker,
.jalali-month-picker {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.jalali-date-picker .form-select,
.jalali-month-picker .form-select {
    min-width: 4.5rem;
}

.jalali-date-picker-inline .form-select {
    min-width: 4rem;
}

.jalali-date-display {
    white-space: nowrap;
}

.report-viewer-frame {
    display: block;
    width: 100%;
    min-height: 75vh;
    height: calc(100vh - 14rem);
    border: 0;
    background: #f8f9fa;
}

@media print {
    .sidebar, .top-row, .drill-context-container,
    .sidebar-toggle, .btn, .page-header-actions { display: none !important; }
    .page { flex-direction: column !important; }
    main { overflow: visible !important; }
    .content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; }
}

.bha-item-thumb {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border: 1px solid var(--ro-border, #dee2e6);
    border-radius: var(--ro-radius-sm, 0.25rem);
    background: #fff;
}

.bha-item-preview {
    max-width: 120px;
    max-height: 120px;
    object-fit: contain;
    border: 1px solid var(--ro-border, #dee2e6);
    border-radius: var(--ro-radius-sm, 0.25rem);
    background: #fff;
    padding: 0.25rem;
}

.analytics-shell {
    --an-canvas: #E8EEF2;
    --an-surface: #F7FAFB;
    --an-raised: #FFFFFF;
    --an-border: #B4C3CC;
    --an-text: #142028;
    --an-muted: #4A5D68;
    --an-action: #1A8F84;
    --an-source: #2B6CB0;
    --an-gate: #C4841A;
    --an-critical: #C43C3C;
    --an-selected: #D4EBE8;
    --an-gate-bg: #F8F1DE;
    background: var(--an-canvas);
    color: var(--an-text);
    padding: 4px 4px 32px;
}

.analytics-shell[data-theme="dark"] {
    --an-canvas: #0C141B;
    --an-surface: #141F28;
    --an-raised: #1B2A35;
    --an-border: #3E5462;
    --an-text: #E9F1F5;
    --an-muted: #9AAFBB;
    --an-action: #2CC2B2;
    --an-source: #4B91D6;
    --an-gate: #F4AF41;
    --an-critical: #E75B5B;
    --an-selected: #18373A;
    --an-gate-bg: #3A3014;
    --ro-bg: var(--an-canvas);
    --ro-surface: var(--an-surface);
    --ro-border: var(--an-border);
    --ro-border-light: var(--an-border);
    --ro-text: var(--an-text);
    --ro-text-secondary: var(--an-muted);
    --ro-text-muted: var(--an-muted);
    --ro-warning-bg: var(--an-gate-bg);
    --ro-warning-text: #F3E2A0;
    background: var(--an-canvas);
    color: var(--an-text);
}

.analytics-shell .page-header {
    align-items: flex-end;
    margin-bottom: 16px;
}

.analytics-shell .page-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--an-border);
    color: var(--an-text);
}

.analytics-shell .page-header-actions .btn {
    background: var(--an-raised);
    color: var(--an-text);
    border: 1px solid var(--an-border);
    border-radius: 4px;
}

.analytics-question {
    max-width: 68ch;
    margin: 8px 0 0;
    color: var(--an-muted);
    font-size: 0.9375rem;
    line-height: 1.45;
}

.analytics-period {
    margin: 12px 0 0;
    color: var(--an-muted);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}

.analytics-filter {
    background: var(--an-surface);
    border: 1px solid var(--an-border);
    border-radius: 4px;
    padding: 12px 16px;
}

.analytics-filter-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    margin: 0;
}

.analytics-filter-grid label,
.analytics-search {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--an-muted);
    min-width: 9.5rem;
}

.analytics-shell .form-select,
.analytics-shell .form-control {
    background: var(--an-raised);
    color: var(--an-text);
    border-color: var(--an-border);
    border-radius: 4px;
    min-height: 2rem;
}

.analytics-demo {
    margin: 12px 0 0;
    padding: 8px 12px;
    border: 1px solid var(--an-gate);
    border-radius: 4px;
    background: var(--an-gate-bg);
    color: var(--an-text);
    font-size: 0.8125rem;
    line-height: 1.4;
}

.analytics-shell .kpi-card {
    background: var(--an-surface);
    border: 1px solid var(--an-border);
    border-radius: 4px;
    box-shadow: none;
    padding: 16px;
    min-height: 100%;
}

.analytics-shell .kpi-card:hover {
    border-color: var(--an-border);
}

.analytics-shell .kpi-label {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--an-muted);
}

.analytics-shell .kpi-value {
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: var(--an-text);
    font-size: 1.5rem;
}

.analytics-shell .kpi-card-hero .kpi-value {
    font-size: 2.5rem;
}

.analytics-shell .kpi-meta {
    margin-top: 8px;
    color: var(--an-muted);
    font-size: 0.75rem;
    line-height: 1.4;
}

.analytics-shell .kpi-tone-source { border-top: 2px solid var(--an-source); }
.analytics-shell .kpi-tone-action { border-top: 2px solid var(--an-action); }
.analytics-shell .kpi-tone-gate { border-top: 2px solid var(--an-gate); }

.analytics-panel {
    border: 1px solid var(--an-border);
    border-radius: 4px;
    background: var(--an-surface);
    padding: 16px;
    margin-bottom: 0;
}

.analytics-panel h2,
.analytics-block-title,
.analytics-later h2 {
    margin: 0 0 12px;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--an-text);
}

.analytics-panel-head h2 { margin: 0; }

.analytics-block-title {
    margin: 8px 0 12px;
}

.analytics-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.analytics-panel-head .btn {
    background: var(--an-raised);
    color: var(--an-text);
    border: 1px solid var(--an-border);
    border-radius: 4px;
}

.analytics-note {
    margin: 0 0 8px;
    color: var(--an-muted);
    font-size: 0.8125rem;
    line-height: 1.4;
}

.analytics-chart {
    width: 100%;
    height: 320px;
}

.analytics-chart-short { height: 168px; }
.analytics-chart-hero { height: 420px; }

.analytics-toggle {
    display: inline-flex;
    gap: 4px;
    margin-bottom: 8px;
    padding: 4px;
    border: 1px solid var(--an-border);
    border-radius: 4px;
    background: var(--an-raised);
}

.analytics-shell .analytics-toggle .btn {
    border: 0;
    border-radius: 3px;
    color: var(--an-text);
    background: transparent;
}

.analytics-shell .analytics-toggle .btn-secondary {
    background: var(--an-selected);
    color: var(--an-text);
    box-shadow: inset 0 0 0 1px var(--an-action);
}

.analytics-insights {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

.analytics-insights li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 12px 0;
    border-top: 1px solid var(--an-border);
    line-height: 1.45;
}

.analytics-shell .btn-link {
    color: var(--an-source);
    text-decoration: underline;
    text-underline-offset: 2px;
    white-space: nowrap;
}

.analytics-shell .alert {
    border-radius: 4px;
    border: 1px solid var(--an-border);
    background: var(--an-raised);
    color: var(--an-text);
}

.analytics-shell .alert-warning {
    border-color: var(--an-gate);
    background: var(--an-gate-bg);
}

.analytics-shell .alert-danger {
    border-color: var(--an-critical);
    color: var(--an-text);
}

.analytics-shell .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--an-text);
    --bs-table-border-color: var(--an-border);
    margin-bottom: 0;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    color: var(--an-text);
}

.analytics-shell .table thead th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--an-muted);
    border-bottom-width: 1px;
    white-space: nowrap;
}

.analytics-data summary {
    margin-top: 8px;
    color: var(--an-muted);
    font-size: 0.8125rem;
    cursor: pointer;
}

.analytics-pager {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.analytics-detail {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: 12px;
}

.analytics-detail dt {
    font-size: 0.75rem;
    color: var(--an-muted);
}

.analytics-later {
    margin-top: 24px;
    border: 1px dashed var(--an-border);
    border-radius: 4px;
    padding: 16px;
    color: var(--an-muted);
}

.analytics-definitions { margin-top: 16px; }

.analytics-shell :focus-visible {
    outline: 2px solid var(--an-gate);
    outline-offset: 2px;
}

@media (max-width: 991.98px) {
    .analytics-shell .kpi-card-hero .kpi-value { font-size: 2rem; }
    .analytics-insights li { flex-direction: column; align-items: flex-start; }
    .analytics-chart { height: 280px; }
    .analytics-chart-short { height: 160px; }
    .analytics-chart-hero { height: 300px; }
}


