/* === CSS Custom Properties === */
:root {
    --primary-dark: #2F5597;
    --primary: #4472C4;
    --primary-light: #8DB4E2;
    --primary-lighter: #BDD7EE;
    --orange: #ED7D31;
    --orange-light: #F4B183;
    --green: #70AD47;
    --red: #FF0000;
    --yellow: #FFC000;
    --gray: #A5A5A5;
    --gray-light: #D9D9D9;
    --gray-lighter: #F2F2F2;
    --white: #FFFFFF;
    --bg: #F5F5F5;
    --text: #333333;
    --text-light: #666666;
    --border: #E0E0E0;
    --sidebar-width: 280px;
    --topbar-height: 48px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "Consolas", "Liberation Mono", Menlo, monospace;
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.4;
    overflow-x: hidden;
}

/* === Top Bar === */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--primary-dark);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 300;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-title {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

/* Hamburger button */
.hamburger-btn {
    display: flex;
    align-items: center;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.85);
    padding: 4px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    z-index: 300;
}
.hamburger-btn:hover {
    color: #fff;
}

/* Slide-in nav panel */
.page-tabs {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100dvh;
    height: 100vh; /* fallback for older browsers */
    height: 100dvh;
    background: var(--primary-dark);
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: calc(var(--topbar-height) + 12px) 0 calc(20px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    z-index: 250;
    transition: left 0.3s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
}
.page-tabs.open {
    left: 0;
}

.tab {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    padding: 12px 24px;
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    text-align: left;
    width: 100%;
    border-radius: 0;
}

.tab:hover {
    background: rgba(255,255,255,0.08);
    color: var(--white);
}

.tab.active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-weight: 600;
}

/* Spacer pushes logout to bottom of nav */
.nav-spacer {
    flex: 1;
}

/* Logout button inside slide-in nav */
.nav-logout-btn {
    background: transparent;
    border: none;
    border-top: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.7);
    padding: 14px 24px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background 0.15s, color 0.15s;
}
.nav-logout-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

/* Nav overlay backdrop */
.nav-overlay {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.35);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.nav-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.btn-filter-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--white);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font);
}

.btn-filter-toggle:hover {
    background: rgba(255,255,255,0.25);
}

/* === Main Layout === */
.main-layout {
    display: grid;
    grid-template-columns: 1fr var(--sidebar-width);
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
}

.content-area {
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - var(--topbar-height));
}

/* === Loading Screen === */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    gap: 16px;
    color: var(--text-light);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error {
    color: var(--red);
    font-weight: 600;
}

/* === Common Components === */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 16px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
}

.page-grid {
    display: grid;
    gap: 16px;
}

.page-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.page-grid-3col {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

.chart-container {
    width: 100%;
    min-height: 300px;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    color: var(--text-light);
}

.placeholder h2 {
    text-transform: capitalize;
    margin-bottom: 8px;
}

/* === KPI Cards === */
.kpi-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.kpi-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px 16px;
    min-width: 140px;
    flex: 1;
}

.kpi-label {
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary-dark);
    margin-top: 4px;
}

.kpi-sub {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 2px;
}

/* === Summary Table (Style A/P/S/Supply) === */
.summary-table-container {
    margin-top: 12px;
}

/* === Cross-Filter Bar === */
.xf-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #FFF8E1;
    border: 1px solid #FFD54F;
    border-radius: 4px;
    font-size: 12px;
    color: #333;
}

.xf-clear-btn {
    margin-left: auto;
    background: none;
    border: 1px solid #FFD54F;
    border-radius: 3px;
    padding: 2px 10px;
    cursor: pointer;
    font-size: 11px;
    color: #666;
    font-family: var(--font);
}

.xf-clear-btn:hover {
    background: #FFD54F;
    color: #333;
}

/* Clickable rows in cross-filtered tables */
.matrix-table tr.xf-clickable td {
    cursor: pointer;
}

.matrix-table tr.xf-selected td {
    background: #FFF8E1 !important;
    box-shadow: inset 3px 0 0 #FFD54F;
}

/* === Drill-Through === */
.drill-context-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #E3F2FD;
    border: 1px solid #90CAF9;
    border-radius: 4px;
    font-size: 12px;
    color: #333;
}

.drill-link {
    color: var(--primary);
    text-decoration: underline;
    text-decoration-style: dotted;
    cursor: pointer;
}

.drill-link:hover {
    color: var(--primary-dark);
    text-decoration-style: solid;
}

/* === Pager Buttons === */
.pager-btn {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 3px 10px;
    cursor: pointer;
    font-size: 11px;
    font-family: var(--font);
    color: var(--text);
}

.pager-btn:hover:not(:disabled) {
    background: var(--gray-lighter);
}

.pager-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* === Admin Layout === */
.admin-layout {
    display: flex;
    min-height: calc(100vh - var(--topbar-height) - 32px);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: visible;
}

.admin-sidebar {
    width: 200px;
    min-width: 200px;
    background: #1e293b;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, min-width 0.2s ease;
    overflow: hidden;
    border-radius: 6px 0 0 6px;
}

.admin-sidebar.collapsed {
    width: 52px;
    min-width: 52px;
}

.admin-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    min-height: 48px;
}

.admin-sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.15s;
}

.admin-sidebar.collapsed .admin-sidebar-title {
    opacity: 0;
    width: 0;
}

.admin-sidebar-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: color 0.15s;
}

.admin-sidebar-toggle:hover {
    color: #fff;
}

.admin-nav {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    flex: 1;
    overflow-y: auto;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.65);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    white-space: nowrap;
    text-align: left;
    transition: background 0.15s, color 0.15s;
    width: 100%;
}

.admin-nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.admin-nav-item.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-weight: 600;
    border-left: 3px solid var(--primary-light);
    padding-left: 11px;
}

.admin-nav-item svg {
    flex-shrink: 0;
}

.admin-nav-label {
    overflow: hidden;
    transition: opacity 0.15s;
}

.admin-sidebar.collapsed .admin-nav-label {
    opacity: 0;
    width: 0;
}

.admin-sidebar.collapsed .admin-nav-item {
    justify-content: center;
    padding: 10px;
}

.admin-sidebar.collapsed .admin-nav-item.active {
    padding-left: 7px;
}

.admin-content {
    flex: 1;
    min-width: 0;
    padding: 20px;
    overflow-y: auto;
    max-height: calc(100vh - var(--topbar-height) - 32px);
}

.admin-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.admin-mobile-bar {
    display: none;
}

.admin-sidebar-overlay {
    display: none;
}
