:root {
    /* --- COLOR PALETTE (Premium SaaS) --- */
    /* Primary Brand - Deep Navy & Crisp White */
    --primary: #001F3F;
    --primary-hover: #003366;
    --primary-light: #F0F4F8;
    --primary-subtle: #E1E8F0;

    /* Accent - Professional Red */
    --accent: #E31C25;
    --accent-hover: #C41820;
    --accent-light: #FEF2F2;
    --accent-subtle: #FEE2E2;

    /* Neutrals - Calm & Clean */
    --bg-body: #F4F6F8;       /* Main background */
    --bg-surface: #FFFFFF;    /* Cards, Sidebar */
    --bg-subtle: #F8FAFC;     /* Table headers, secondary areas */
    
    --text-primary: #1E293B;  /* Main text (Slate 800) */
    --text-secondary: #64748B;/* Subtitles (Slate 500) */
    --text-tertiary: #94A3B8; /* Disabled/Meta (Slate 400) */
    --text-on-dark: #FFFFFF;

    /* Borders */
    --border-light: #E2E8F0;
    --border-medium: #CBD5E0;
    --border-focus: #001F3F;

    /* Semantic Colors */
    --success: #10B981;
    --success-bg: #ECFDF5;
    --warning: #F59E0B;
    --warning-bg: #FFFBEB;
    --danger: #EF4444;
    --danger-bg: #FEF2F2;
    --info: #3B82F6;
    --info-bg: #EFF6FF;

    /* --- SHADOWS (Elevation) --- */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    
    /* --- SPACING SYSTEM (4px Base) --- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* --- LAYOUT CONSTANTS --- */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --header-height: 64px;
    --bottom-nav-height: 60px;
    --container-max: 1440px; /* Wider for enterprise dashboard */
    
    /* --- RADIUS --- */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* --- TYPOGRAPHY --- */
    --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --- RESET & BASE --- */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 14px; /* Enterprise standard */
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0 0 var(--space-3) 0; font-weight: 600; line-height: 1.2; color: var(--text-primary); }
h1 { font-size: 1.875rem; letter-spacing: -0.025em; }
h2 { font-size: 1.5rem; letter-spacing: -0.025em; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em; }

p { margin-bottom: var(--space-3); }
a { text-decoration: none; color: inherit; transition: color 0.2s; }
ul { list-style: none; padding: 0; margin: 0; }
img { max-width: 100%; display: block; }

/* --- GRID SYSTEM (12-Column Flexbox) --- */
.container-fluid {
    width: 100%;
    padding-right: var(--space-6);
    padding-left: var(--space-6);
    margin-right: auto;
    margin-left: auto;
    max-width: var(--container-max);
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: calc(-1 * var(--space-3));
    margin-left: calc(-1 * var(--space-3));
}

.row > * {
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    padding-right: var(--space-3);
    padding-left: var(--space-3);
}

.g-0, .gx-0 { --bs-gutter-x: 0; }
.g-1, .gx-1 { --bs-gutter-x: 0.25rem; }
.g-2, .gx-2 { --bs-gutter-x: 0.5rem; }
.g-3 { margin-right: calc(-1 * var(--space-3)); margin-left: calc(-1 * var(--space-3)); }
.g-3 > * { padding-right: var(--space-3); padding-left: var(--space-3); padding-top: var(--space-3); }
.g-4 { margin-right: calc(-1 * var(--space-4)); margin-left: calc(-1 * var(--space-4)); }
.g-4 > * { padding-right: var(--space-4); padding-left: var(--space-4); padding-top: var(--space-4); }

/* Column Sizes */
.col-12 { flex: 0 0 auto; width: 100%; }
.col-6 { flex: 0 0 auto; width: 50%; }
.col-4 { flex: 0 0 auto; width: 33.33333333%; }
.col-3 { flex: 0 0 auto; width: 25%; }

@media (min-width: 768px) {
    .col-md-12 { flex: 0 0 auto; width: 100%; }
    .col-md-6 { flex: 0 0 auto; width: 50%; }
    .col-md-4 { flex: 0 0 auto; width: 33.33333333%; }
    .col-md-3 { flex: 0 0 auto; width: 25%; }
    .d-md-flex { display: flex !important; }
    .d-md-block { display: block !important; }
    .d-md-none { display: none !important; }
}

@media (min-width: 1024px) {
    .col-lg-12 { flex: 0 0 auto; width: 100%; }
    .col-lg-9 { flex: 0 0 auto; width: 75%; }
    .col-lg-8 { flex: 0 0 auto; width: 66.66666667%; }
    .col-lg-6 { flex: 0 0 auto; width: 50%; }
    .col-lg-4 { flex: 0 0 auto; width: 33.33333333%; }
    .col-lg-3 { flex: 0 0 auto; width: 25%; }
    .d-lg-flex { display: flex !important; }
    .d-lg-block { display: block !important; }
}

/* --- COMPONENTS --- */

/* Cards */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: var(--space-4) var(--space-5);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: var(--space-5);
    flex: 1 1 auto;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-4);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    gap: var(--space-2);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-light {
    background-color: white;
    border-color: var(--border-light);
    color: var(--text-primary);
}
.btn-light:hover {
    background-color: var(--bg-subtle);
    border-color: var(--border-medium);
}

.btn-sm { padding: var(--space-1) var(--space-3); font-size: 0.8rem; }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: 1rem; }

/* Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-medium);
    white-space: nowrap;
}

.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    vertical-align: middle;
}

.table tr:hover td {
    background-color: var(--bg-subtle);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
}
.bg-success-light { background-color: var(--success-bg); color: var(--success); }
.bg-warning-light { background-color: var(--warning-bg); color: var(--warning); }
.bg-danger-light { background-color: var(--danger-bg); color: var(--danger); }
.bg-info-light { background-color: var(--info-bg); color: var(--info); }
.bg-primary-light { background-color: var(--primary-light); color: var(--primary); }

/* --- FORMS --- */
.form-control, .form-select {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    outline: 0;
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* --- LAYOUT STRUCTURES --- */

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1030;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease; /* Added width transition */
    box-shadow: 4px 0 24px rgba(0,0,0,0.1);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    background-color: rgba(0,0,0,0.1);
    white-space: nowrap; /* Prevent text wrap */
    overflow: hidden;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4) 0;
    overflow-x: hidden;
}

.sidebar-section {
    padding: var(--space-6) var(--space-6) var(--space-2);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.4);
    font-weight: 700;
    white-space: nowrap;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: var(--space-3) var(--space-6);
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-item:hover, .nav-item.active {
    background-color: rgba(255,255,255,0.1);
    color: white;
}
.nav-item.active { border-left-color: var(--accent); }
.nav-item i { width: 20px; margin-right: var(--space-3); text-align: center; font-size: 1.1em; }

/* Collapsed Sidebar (Desktop) */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}
.sidebar.collapsed .sidebar-header { padding: 0 var(--space-4); justify-content: center; }
.sidebar.collapsed .sidebar-header img { width: 30px; height: auto; }
.sidebar.collapsed .sidebar-section { display: none; }
.sidebar.collapsed .nav-item { padding: var(--space-3) var(--space-4); justify-content: center; }
.sidebar.collapsed .nav-item span { display: none; }
.sidebar.collapsed .nav-item i { margin-right: 0; }

/* Active Sidebar (Mobile Slide-in) */
.sidebar.active {
    transform: translateX(0);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    padding-top: var(--header-height);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.main-content.expanded {
    margin-left: var(--sidebar-collapsed-width);
}

/* Top Bar */
.top-bar {
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    position: fixed;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    transition: left 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.main-content.expanded .top-bar {
    left: var(--sidebar-collapsed-width);
}

/* Mobile Nav */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    z-index: 1040;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.7rem;
}
.bottom-nav-item.active { color: var(--primary); }

/* --- UTILITIES --- */
.text-primary { color: var(--primary) !important; }
.text-muted { color: var(--text-secondary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bg-light { background-color: var(--bg-subtle) !important; }
.bg-white { background-color: white !important; }
.bg-primary { background-color: var(--primary) !important; }
.bg-navy { background-color: var(--primary) !important; }
.text-navy { color: var(--primary) !important; }

.d-flex { display: flex !important; }
.d-none { display: none !important; }
.align-items-center { align-items: center !important; }
.justify-content-between { justify-content: space-between !important; }
.flex-grow-1 { flex-grow: 1 !important; }
.gap-2 { gap: var(--space-2) !important; }
.gap-3 { gap: var(--space-3) !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--space-1) !important; }
.mb-3 { margin-bottom: var(--space-3) !important; }
.mb-4 { margin-bottom: var(--space-4) !important; }
.mt-2 { margin-top: var(--space-2) !important; }
.p-2 { padding: var(--space-2) !important; }
.p-3 { padding: var(--space-3) !important; }
.ps-4 { padding-left: var(--space-4) !important; }
.py-3 { padding-top: var(--space-3) !important; padding-bottom: var(--space-3) !important; }
.rounded { border-radius: var(--radius-md) !important; }
.rounded-circle { border-radius: 50% !important; }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.border-0 { border: 0 !important; }
.fw-bold { font-weight: 700 !important; }
.small { font-size: 0.875rem !important; }
.h-100 { height: 100% !important; }
.w-auto { width: auto !important; }
.animate { animation-duration: 0.2s; animation-fill-mode: both; }
.slideIn { animation-name: slideIn; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width); } /* Reset width on mobile */
    .sidebar.active { transform: translateX(0); }
    .main-content { margin-left: 0; padding-bottom: var(--bottom-nav-height); }
    .top-bar { left: 0; padding: 0 var(--space-4); }
    .bottom-nav { display: flex; }
    .container-fluid { padding-left: var(--space-4); padding-right: var(--space-4); }
    
    /* Hide desktop elements */
    .d-none-mobile { display: none !important; }
}
