/* * MODERN UI DESIGN SYSTEM - MATERIAL 3 INSPIRED
 * Based on 12-modern-ui-design-system.md
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* --- Level 1: Neutral Foundation --- */
    --surface-1: #FFFFFF;
    --surface-2: #F7F9FC;
    /* Dashboard Background */
    --surface-3: #EFF3F8;
    /* Card Background */
    --surface-4: #E4EAF0;

    --text-primary: rgba(0, 0, 0, 0.87);
    --text-secondary: rgba(0, 0, 0, 0.60);
    --text-tertiary: rgba(0, 0, 0, 0.38);

    --border-light: rgba(0, 0, 0, 0.08);
    --border-medium: rgba(0, 0, 0, 0.12);

    /* --- Level 2: Semantic Colors --- */
    --success-main: #10B981;
    --success-bg: #ECFDF5;
    --success-text: #065F46;

    --warning-main: #F59E0B;
    --warning-bg: #FFFBEB;
    --warning-text: #92400E;

    --error-main: #EF4444;

    /* --- Level 3: Dynamic Tenant Accent (Defaults, overridden by Layout) --- */
    --accent-primary: #1e3a8a;
    /* Tenant Primary */
    --accent-primary-light: #3b82f6;
    --accent-primary-subtle: #eff6ff;
    --accent-on-primary: #FFFFFF;

    /* --- Elevation & Shadows --- */
    --elevation-1: 0px 1px 2px rgba(0, 0, 0, 0.06), 0px 1px 3px rgba(0, 0, 0, 0.10);
    --elevation-2: 0px 2px 4px rgba(0, 0, 0, 0.06), 0px 4px 6px rgba(0, 0, 0, 0.10);
    --elevation-3: 0px 4px 6px rgba(0, 0, 0, 0.06), 0px 10px 15px rgba(0, 0, 0, 0.10);

    /* --- Spacing & Sizing --- */
    --radius-md: 12px;
    --radius-lg: 16px;
    --header-height: 64px;
    --sidebar-width: 260px;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--surface-2);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 0.9375rem;
    /* 15px */
}

/* --- Layout Structure --- */
.main-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface-1);
    border-right: 1px solid var(--border-light);
    position: fixed;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
}

/* --- Sticky Header --- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: transparent;
    border-bottom: none;
    padding: 0.75rem 1.25rem;
    border-radius: 16px;
    pointer-events: none;
}

.app-header>* {
    pointer-events: auto;
}

.app-header .dropdown-toggle::after {
    display: none;
}

.header-icon-btn {
    width: 40px;
    height: 40px;
}

/* --- Navigation Items --- */
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: var(--text-secondary);
    font-weight: 500;
    border-radius: 0 24px 24px 0;
    margin-right: 16px;
    transition: all 0.2s;
}

.nav-link:hover {
    background-color: var(--surface-2);
    color: var(--accent-primary);
}

.nav-link.active {
    background-color: var(--accent-primary-subtle);
    color: var(--accent-primary);
    font-weight: 600;
}

.nav-link i {
    width: 20px;
    text-align: center;
}

/* --- Stat Cards (Material 3) --- */
.stat-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface-1);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--elevation-1);
    border: 1px solid var(--border-light);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--elevation-2);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* --- Modern Tables --- */
.table-container {
    background: var(--surface-1);
    border-radius: var(--radius-lg);
    box-shadow: var(--elevation-1);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.table-modern {
    width: 100%;
    border-collapse: collapse;
}

.table-modern thead {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-medium);
}

.table-modern th {
    padding: 1rem 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
}

.table-modern td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    vertical-align: middle;
}

.table-modern tr:last-child td {
    border-bottom: none;
}

/* --- Badges --- */
.badge-modern {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.badge-danger {
    background: #FEE2E2;
    color: #991B1B;
}

.badge-secondary {
    background: var(--surface-4);
    color: var(--text-secondary);
}

/* --- Mobile --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content .d-flex.justify-content-between.align-items-center {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .main-content .table,
    .main-content .table-modern {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .main-content .table th,
    .main-content .table td,
    .main-content .table-modern th,
    .main-content .table-modern td {
        white-space: nowrap;
    }

    .sidebar-footer {
        display: none;
    }
}

/* --- Global Preloader & Loading State --- */
body.is-loading {
    overflow: hidden;
}

.page-preloader {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    background: var(--surface-2);
    z-index: 9999;
    opacity: 1;
    visibility: visible;
    transition: opacity 300ms ease, visibility 300ms ease;
}

body.is-loaded .page-preloader {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.page-preloader-spinner {
    width: 48px;
    height: 48px;
    border-radius: 9999px;
    border: 3px solid rgba(0, 0, 128, 0.2);
    /* Fallback color */
    border-color: var(--accent-primary-subtle);
    border-top-color: var(--accent-primary);
    animation: spin 0.8s linear infinite;
}

.page-preloader-text {
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--accent-primary);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* --- Sidebar Overlay (Mobile) --- */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 200ms ease, visibility 200ms ease;
    z-index: 900;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}