/* ==================== Global Styles - Apple Design Principles ==================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* User Provided Palette Variables */
    --olive-leaf: #606c38ff;
    --black-forest: #283618ff;
    --cornsilk: #fefae0ff;
    --sunlit-clay: #dda15eff;
    --copperwood: #bc6c25ff;

    /* Functional Mappings */

    /* Backgrounds */
    --background-primary: var(--cornsilk);
    /* Main background - Warm Cream */
    --background-secondary: #FFFFFF;
    /* Cards - White for contrast */
    --background-tertiary: rgba(96, 108, 56, 0.1);
    /* Inputs/Secondary areas - Light Olive tint */
    --background-hover: rgba(96, 108, 56, 0.2);
    /* Hover states */
    --background-sidebar: var(--olive-leaf);
    /* New Sidebar Background */

    /* Primary Branding (Sidebar etc) */
    --primary-color: var(--olive-leaf);
    /* Main Brand Color */
    --primary-dark: var(--black-forest);
    /* Darkest Brand Color */
    --primary-light: var(--sunlit-clay);
    /* Lighter Brand Color */
    --primary-accent: var(--copperwood);
    /* Bright Accent */

    /* Text Colors */
    --text-primary: var(--black-forest);
    /* Darkest for main text */
    --text-secondary: var(--olive-leaf);
    /* Brand color for secondary */
    --text-tertiary: var(--copperwood);
    /* Accent for tertiary */
    --text-muted: rgba(40, 54, 24, 0.6);
    /* Muted forest */
    --text-inverse: var(--cornsilk);
    /* Cream text on dark backgrounds */

    /* Status Colors */
    --success-color: var(--olive-leaf);
    --success-light: #E8F5E9;
    --success-dark: var(--black-forest);

    --warning-color: var(--sunlit-clay);
    --warning-light: #FFF8E1;
    --warning-dark: var(--copperwood);

    --danger-color: #BC4749;
    --danger-light: #F2E8E8;
    --danger-dark: #6A040F;

    /* Borders */
    --border-color: rgba(96, 108, 56, 0.2);
    /* Subtle Olive */
    --border-light: rgba(96, 108, 56, 0.1);
    /* Very Light Olive */
    --border-dark: var(--olive-leaf);
    /* Medium Olive */
    --border-active: var(--copperwood);
    /* Active Border */

    /* Shadows - Tinted with Black Forest */
    --shadow-sm: 0 1px 2px 0 rgba(40, 54, 24, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(40, 54, 24, 0.1), 0 2px 4px -1px rgba(40, 54, 24, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(40, 54, 24, 0.1), 0 4px 6px -2px rgba(40, 54, 24, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(40, 54, 24, 0.1), 0 10px 10px -5px rgba(40, 54, 24, 0.04);

    /* Gradients */
    --primary-gradient: linear-gradient(135deg, var(--olive-leaf) 0%, var(--black-forest) 100%);
    --gradient-sunset: linear-gradient(135deg, var(--sunlit-clay) 0%, var(--copperwood) 100%);
    --gradient-subtle: linear-gradient(180deg, #FFFFFF 0%, var(--cornsilk) 100%);

    /* Spacing — names match values. */
    --spacing-4:  4px;
    --spacing-8:  8px;
    --spacing-12: 12px;
    --spacing-16: 16px;
    --spacing-20: 20px;
    --spacing-24: 24px;
    --spacing-32: 32px;
    --spacing-48: 48px;

    /* Typography scale (Apple-inspired, dense-UI tuned). */
    --text-xs:   11px;   /* timestamps, metadata, tab pills */
    --text-sm:   12px;   /* table cells, badges, helper text */
    --text-base: 13px;   /* body, buttons, inputs, labels */
    --text-md:   14px;   /* section subtitles */
    --text-lg:   15px;   /* card titles, panel labels */
    --text-xl:   18px;   /* panel titles */
    --text-2xl:  20px;   /* page H2 */
    --text-3xl:  24px;   /* card primary metric */

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    /* Transitions — easeOutExpo for purposeful entries, ease-out for hovers */
    --easing-emphasized: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-fast: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s var(--easing-emphasized);

    /* Borders — tokens that earlier code referenced but never defined. */
    --border-medium: rgba(40, 54, 24, 0.18);

    /* Background-aliases used by older selectors. */
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-secondary: var(--background-secondary);
    --bg-elevated: var(--background-secondary);
    --bg-elevated-hover: var(--background-hover);
}

body {
    margin: 0;
    padding: 0;
    /* Inter is loaded by every page's <head>; put it first so we actually use it
       (was previously declared but missing from this stack). */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--background-primary);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: var(--text-base);   /* 14px — was 10px (root cause of cramping) */
    font-feature-settings: 'cv11', 'ss01', 'ss03';   /* Inter stylistic tweaks */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Global focus ring — every keyboard-reachable interactive element gets one.
   Uses the brand olive against any background, with a soft outer halo. */
:focus-visible {
    outline: 2px solid var(--olive-leaf);
    outline-offset: 2px;
    border-radius: inherit;
}

/* Reduced-motion: collapse animation/transition durations so the UI stays
   functional but doesn't move for users who prefer that. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--spacing-24);
}

/* ==================== Header ==================== */

.detail-header {
    background: var(--background-tertiary);
    padding: var(--spacing-16) var(--spacing-20);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header {
    background: var(--background-primary);
    border-bottom: 1px solid var(--border-light);
    padding: 0 var(--spacing-16);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    height: 48px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-16);
    width: 100%;
}

.logo-section {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.logo {
    font-size: var(--text-base);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 0;
    white-space: nowrap;
}

.header-divider {
    color: var(--text-tertiary);
    font-weight: 400;
}

.header-tenant {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subtitle {
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0;
}

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.header-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-right: var(--spacing-8);
    white-space: nowrap;
    font-feature-settings: 'tnum';
}

/* ==================== Toggle Switch - Apple Style ==================== */

.sample-data-toggle {
    display: flex;
    align-items: center;
    gap: var(--spacing-12);
    padding: var(--spacing-8) var(--spacing-16);
    background: var(--background-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--background-tertiary);
    border: 1px solid var(--border-light);
    transition: var(--transition-normal);
    border-radius: 20px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: var(--transition-normal);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--primary-gradient);
    border-color: var(--primary-color);
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(16px);
}

.toggle-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: -0.1px;
    user-select: none;
}


/* ==================== Buttons - Apple Style ==================== */

.btn {
    padding: 5px 11px;
    border: 1px solid transparent;
    border-radius: 7px;
    font-weight: 600;
    font-size: var(--text-sm);
    letter-spacing: -0.005em;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast),
                box-shadow var(--transition-fast),
                transform 0.08s ease-out,
                filter var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 28px;
    text-decoration: none;
    white-space: nowrap;
}

/* Apple-style press affordance — slight scale-down instead of float-up. */
.btn:active:not(:disabled) {
    transform: scale(0.98);
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    /* Forest-tinted shadow (was iOS blue, wrong palette). */
    box-shadow: 0 1px 2px rgba(40, 54, 24, 0.08),
                0 2px 8px rgba(40, 54, 24, 0.18);
}

.btn-primary:hover {
    filter: brightness(1.06);
    box-shadow: 0 2px 4px rgba(40, 54, 24, 0.10),
                0 4px 14px rgba(40, 54, 24, 0.22);
}

.btn-secondary {
    background: var(--background-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: var(--background-hover);
    border-color: var(--border-medium);
}

.btn-tertiary,
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
    padding: 9px 10px;
}
.btn-tertiary:hover,
.btn-ghost:hover {
    background: var(--background-hover);
    color: var(--text-primary);
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.icon {
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ==================== Filters - Compact inline toolbar ==================== */

.filters-section {
    padding: 6px var(--spacing-12);
    background: var(--background-primary);
    border-bottom: 1px solid var(--border-light);
}

.filters-card {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
}

.filters-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-8);
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-group label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}

.filter-group.filter-actions {
    margin-left: var(--spacing-8);
}

.filter-input {
    padding: 4px 8px;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: inherit;
    min-height: 28px;
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast),
                background-color var(--transition-fast);
}

.filter-input:focus {
    outline: none;
    border-color: var(--olive-leaf);
    background: var(--background-secondary);
    box-shadow: 0 0 0 3px rgba(96, 108, 56, 0.15);
}

/* ==================== Dashboard Layout - Sidebar + Content ==================== */

.dashboard-container {
    display: flex;
    min-height: calc(100vh - 48px);
    gap: 0;
}

/* ==================== Sidebar Navigation ==================== */

.sidebar {
    width: 168px;
    background: var(--background-sidebar);
    border-right: 1px solid var(--border-light);
    padding: var(--spacing-8) 6px;
    overflow-y: auto;
    height: calc(100vh - 48px);
    transition: width var(--transition-normal);
    position: relative;
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: 64px;
    padding: var(--spacing-16) var(--spacing-8);
}

.sidebar-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: var(--spacing-8);
    padding: 0 4px;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0;
}

.sidebar-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-inverse);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

.tab-navigation {
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tab-button {
    width: 100%;
    padding: 5px 9px;
    margin-bottom: 0;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    color: var(--text-inverse);
    font-size: var(--text-sm);
    font-weight: 500;
    letter-spacing: -0.005em;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--transition-fast),
                color var(--transition-fast),
                border-color var(--transition-fast);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.8;
}

.tab-button::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--cornsilk);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.tab-button:hover {
    background: rgba(254, 250, 224, 0.1);
    color: var(--text-inverse);
    opacity: 1;
}

.tab-button.active {
    background: var(--cornsilk);
    border-left-color: var(--cornsilk);
    color: var(--olive-leaf);
    font-weight: 700;
    opacity: 1;
}

.sidebar.collapsed .tab-button {
    padding: var(--spacing-12) var(--spacing-8);
    justify-content: center;
}

.sidebar.collapsed .tab-label {
    display: none;
}

.sidebar.collapsed .tab-icon {
    margin: 0;
    font-size: 18px;
}

.tab-button.active::before {
    opacity: 1;
}

.tab-icon {
    font-size: 13px;
    width: 18px;
    text-align: center;
    line-height: 1;
}

.tab-label {
    flex: 1;
}

/* ==================== Main Content Area ==================== */

.main-content {
    flex: 1;
    padding: var(--spacing-12);
    background: var(--background-secondary);
    overflow-y: auto;
    /* 48px header — height matches the .header rule above. */
    height: calc(100vh - 48px);
    min-width: 0; /* allow tables to shrink instead of overflowing */
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.content-header {
    margin-bottom: var(--spacing-8);
    display: flex;
    align-items: baseline;
    gap: var(--spacing-12);
    flex-wrap: wrap;
}

.content-header h2 {
    font-size: var(--text-base);
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

.content-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: 400;
    margin: 0;
}

.detail-content-wrapper {
    background: var(--background-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--spacing-12);
    min-height: 160px;
}

/* ==================== Summary Cards - Compact ==================== */

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--spacing-8);
}

.summary-card {
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast),
                transform 0.08s ease-out;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-gradient);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.summary-card:hover::before {
    opacity: 1;
}

.summary-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-medium);
}

.summary-card.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.card-title {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.card-status {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.card-status.pass {
    background: var(--success-light);
    color: var(--success-dark);
    font-weight: 500;
}

.card-status.fail {
    background: var(--danger-light);
    color: var(--danger-dark);
    font-weight: 500;
}

.card-status.na {
    background: var(--background-tertiary);
    color: var(--text-tertiary);
}

.card-note {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--spacing-12);
    padding-top: var(--spacing-8);
    border-top: 1px dashed var(--border-light);
    line-height: 1.5;
}

.card-status.warning {
    background: var(--warning-light);
    color: var(--warning-dark);
    font-weight: 500;
}

.card-metric {
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.05;
    margin: 0 0 1px;
    color: var(--text-primary);
    font-feature-settings: 'tnum';
}

.card-metric-label {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.card-details {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-light);
}

.card-detail-item {
    text-align: center;
    flex: 1;
}

.card-detail-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.card-detail-value {
    font-size: var(--text-base);
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    font-feature-settings: 'tnum';
}

.card-detail-value.success {
    color: var(--success-color);
}

.card-detail-value.danger {
    color: var(--danger-color);
}

.detail-content-inner {
    padding: var(--spacing-24);
}

/* ==================== Tables - Clean Apple Style ==================== */

/* Wrapper enables horizontal scroll when there are too many columns to fit
   the panel. Without it, the table bleeds past the rounded panel border. */
.data-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: var(--spacing-8);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--background-primary);
    /* No `min-width: max-content` — let cells share width and wrap header
       labels onto two lines when the table would otherwise overflow. */
}

.data-table th {
    background: var(--background-tertiary);
    padding: 5px 7px;
    text-align: left;
    font-weight: 600;
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-medium);
    white-space: normal;        /* allow 2-line header wrap when narrow */
    line-height: 1.2;
    vertical-align: middle;
}

.data-table th:first-child {
    border-top-left-radius: var(--radius-md);
}

.data-table th:last-child {
    border-top-right-radius: var(--radius-md);
}

.data-table td {
    padding: 5px 7px;
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-primary);
    letter-spacing: 0;
    font-feature-settings: 'tnum';
    line-height: 1.35;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    /* Cornsilk page bg → use a tinted black overlay (a white overlay is invisible). */
    background: rgba(40, 54, 24, 0.04);
}

/* ==================== Sortable / filterable tables ==================== */

.sortable-table th.sortable {
    user-select: none;
    white-space: nowrap;
    position: relative;  /* anchor for the absolute filter popover */
    overflow: visible;   /* let popover escape the cell */
}
.sortable-table th.sortable .th-content {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.sortable-table .th-label,
.sortable-table .th-sort-indicator {
    cursor: pointer;
}
.sortable-table .th-sort-indicator {
    font-size: 9px;
    opacity: 0.35;
    margin-left: 1px;
    transition: opacity .12s, color .12s;
}
.sortable-table th.sortable:hover .th-sort-indicator { opacity: 0.75; }
.sortable-table th.sortable.sorted .th-sort-indicator {
    opacity: 1;
    color: var(--olive-leaf);
    font-weight: 700;
}

/* Filter icon — small funnel SVG that opens a popover when clicked */
.sortable-table .th-filter-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 13px;
    height: 13px;
    margin-left: 1px;
    cursor: pointer;
    border-radius: 3px;
    color: currentColor;
    opacity: 0.3;
    font-size: 9px;
    transition: opacity .12s, background .12s, color .12s;
}
.sortable-table .th-filter-icon:hover {
    opacity: 0.85;
    background: rgba(0, 0, 0, 0.06);
}
.sortable-table .th-filter-icon.active {
    opacity: 1;
    color: var(--olive-leaf);
    background: rgba(42, 140, 110, 0.14);
}

/* Filter popover.
   Uses `position: fixed` (and a very high z-index) so it escapes the
   `overflow-y: auto` on .main-content (which would otherwise clip it and
   bury it behind the sidebar's stacking layer). Coordinates are set in JS
   from the filter icon's getBoundingClientRect(). */
.sortable-table .th-filter-popover {
    position: fixed;
    z-index: 9999;
    min-width: 180px;
    padding: 5px;
    background: var(--background-primary, #fff);
    border: 1px solid var(--border-light, #d8d6d0);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    /* placeholder coords; JS overrides */
    top: 0;
    left: 0;
}
.sortable-table .th-filter-popover[hidden] { display: none; }

.sortable-table .th-filter-row {
    display: grid;
    grid-template-columns: 76px 1fr;
    gap: 4px;
    align-items: center;
}
.sortable-table .th-filter-input,
.sortable-table .th-filter-op {
    width: 100%;
    box-sizing: border-box;
    padding: 3px 7px;
    min-height: 24px;
    font-size: 11px;
    font-family: inherit;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--background-secondary);
    color: var(--text-primary);
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}
.sortable-table .th-filter-input:focus,
.sortable-table .th-filter-op:focus {
    outline: none;
    border-color: var(--olive-leaf);
    box-shadow: 0 0 0 3px rgba(96, 108, 56, 0.15);
}
.sortable-table .th-filter-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}
.sortable-table select.th-filter-input,
.sortable-table .th-filter-op {
    cursor: pointer;
}
.sortable-table .th-filter-clear {
    margin-top: 4px;
    padding: 2px 8px;
    min-height: 22px;
    background: none;
    border: 1px solid var(--border-light, #d8d6d0);
    border-radius: 4px;
    font-size: 10px;
    color: var(--text-secondary, #888);
    cursor: pointer;
    transition: background .12s, color .12s;
    font-family: inherit;
}
.sortable-table .th-filter-clear:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary, #333);
}

/* Column-type alignment — analytics convention.
   Text dimensions left, numbers right (with tabular-nums so digits line up),
   status badges centered. Apply to both th and td. */
.data-table th.col-text,
.data-table td.col-text,
.data-table th.col-id,
.data-table td.col-id,
.data-table th.col-date,
.data-table td.col-date {
    text-align: left;
}

.data-table th.col-num,
.data-table td.col-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.data-table th.col-status,
.data-table td.col-status {
    text-align: center;
}

.data-table td.col-id {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0;
}

.badge {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    display: inline-block;
    line-height: 1.4;
}

.badge-success {
    background: #e6f7eb;
    color: #1f7a3a;
}

.badge-danger {
    background: #fde4e4;
    color: #a62525;
}

.badge-warning {
    background: #fff4e0;
    color: #8a5a00;
}

.badge-na {
    background: rgba(40, 54, 24, 0.08);
    color: var(--text-muted);
}

/* ==================== Loading Spinner - Apple Style ==================== */

.loading-text {
    margin-top: 16px;
    color: var(--text-secondary);
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px 0;
    margin-top: 8px;
}

.pagination-info {
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 500;
    min-width: 100px;
    text-align: center;
}

.result-meta {
    color: var(--text-secondary);
    font-size: 10px;
    margin-bottom: 12px;
}

.empty-state {
    text-align: center;
    color: var(--text-tertiary);
    padding: 32px;
    font-size: 11px;
}

.btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 2.5px solid var(--border-light);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    /* `linear` is correct for an `infinite` rotation — easing functions
       create visible per-revolution juddering. */
    animation: spin 0.7s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==================== Footer ==================== */

.footer {
    background: transparent;
    border-top: 1px solid var(--border-light);
    padding: 10px var(--spacing-16);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-xs);
    letter-spacing: 0;
    line-height: 1.4;
}
.footer p { margin: 0; }

/* ==================== Responsive - Apple Breakpoints ==================== */

@media (max-width: 1024px) {
    .dashboard-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        top: 0;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .tab-navigation {
        flex-direction: row;
        overflow-x: auto;
        padding: var(--spacing-12);
    }

    .tab-button {
        white-space: nowrap;
        min-width: 150px;
    }

    .main-content {
        max-height: none;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 var(--spacing-16);
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-16);
    }

    .filters-grid {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .card-metric {
        font-size: 29px;
    }

    .main-content {
        padding: var(--spacing-16);
    }

    .content-header h2 {
        font-size: 19px;
    }

    .data-table {
        font-size: 10px;
    }

    .data-table th,
    .data-table td {
        padding: var(--spacing-8) var(--spacing-12);
    }

    .tab-button {
        min-width: 120px;
        padding: var(--spacing-12) var(--spacing-16);
        font-size: 10px;
    }
}

/* ==================== Utility Classes ==================== */

.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: var(--spacing-16);
}

.mt-2 {
    margin-top: var(--spacing-24);
}

.mt-3 {
    margin-top: var(--spacing-32);
}

.mb-1 {
    margin-bottom: var(--spacing-16);
}

.mb-2 {
    margin-bottom: var(--spacing-24);
}

.mb-3 {
    margin-bottom: var(--spacing-32);
}

.text-success {
    color: var(--success-color);
}

.text-danger {
    color: var(--danger-color);
}

.text-warning {
    color: var(--warning-color);
}

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

/* ==================== Smooth Scrolling ==================== */

html {
    scroll-behavior: smooth;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-elevated-hover);
}

.filter-actions {
    justify-content: flex-end;
}