/* Core Design System - Modern Slate & Indigo */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #64748b;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --sidebar-bg: #0f172a;
    --sidebar-text: #f1f5f9;
    --sidebar-active: #1e293b;
    --border-color: #e2e8f0;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --header-height: 64px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 0px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    letter-spacing: -0.01em;
}

#app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow-y: auto;
}

.logo-container {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-container img {
    height: 32px;
}

.logo-text {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.05em;
}

.menu-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.menu-label {
    padding: 1rem 1.5rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.nav {
    list-style: none;
}

.nav li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s ease;
    opacity: 0.8;
}

.nav li a:hover {
    opacity: 1;
    background-color: var(--sidebar-active);
}

.nav li a svg {
    width: 18px;
    height: 18px;
}

.nav-second-level {
    background-color: rgba(0,0,0,0.1);
}

.nav-second-level li a {
    padding-left: 3.5rem;
    font-size: 0.875rem;
}

/* Main Panel Styling */
.panel {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevent flex children from overflowing */
}

.header {
    height: var(--header-height);
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 900;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}

.header .row {
    width: 100%;
    align-items: center;
}

.page-name .h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.main-content {
    padding: 2rem;
    padding-bottom: 5rem; /* Ensure space at the bottom for all screens */
    flex: 1;
}

/* Card Enhancements */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header .title {
    font-weight: 600;
    font-size: 1rem;
}

.card-body {
    padding: 1.5rem;
}

/* Form Styling */
.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.form-control {
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
    outline: none;
}

/* Glassmorphism Utilities */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

.glass-dark {
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Animation Utilities */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease forwards;
}

.btn {
    border-radius: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

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

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

/* Table Styling */
.table {
    margin-bottom: 0;
}

.table thead th {
    background-color: var(--bg-main);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-top: none;
    padding: 0.75rem 1rem;
}

.table tbody td {
    padding: 1rem;
    font-size: 0.875rem;
    vertical-align: middle;
}

/* Mobile Toggle Button */
.sidebar-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-main);
    padding: 0.5rem;
    margin-right: 1rem;
    cursor: pointer;
}

.sidebar-toggle i {
    width: 24px;
    height: 24px;
}

/* Responsive Overrides */
@media (max-width: 992px) {
    .sidebar {
        left: -100%;
        transform: none !important;
        width: 280px;
        box-shadow: none;
    }

    .sidebar.show {
        left: 0;
        background-color: #0f172a !important;
        box-shadow: 20px 0 50px rgba(0,0,0,0.4);
        z-index: 1001;
    }
    
    .panel {
        margin-left: 0 !important;
        width: 100vw !important;
        max-width: 100vw;
        overflow-x: clip; 
        padding-bottom: 100px; /* Increased space for bottom nav + footer */
    }
    
    .header {
        padding: 0 1rem;
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
    }

    .main-content {
        padding: 0.75rem;
        padding-bottom: 2rem;
    }

    .card-body {
        padding: 0.875rem;
    }

    .header {
        padding: 0 0.5rem;
        height: auto;
        min-height: var(--header-height);
    }

    .page-name .h1 {
        font-size: 0.9rem;
    }

    .menuright {
        gap: 0.25rem;
    }

    /* Shrink icon buttons on mobile */
    .menuright .item a {
        padding: 0.35rem;
    }

    /* Force table horizontal scroll on mobile */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: 0;
        margin-bottom: 1rem;
    }

    .table-responsive .table {
        margin-bottom: 0;
        min-width: 800px; /* Force overflow trigger for data tables */
    }

    /* Sub-nav tabs scroll horizontally instead of wrapping */
    .sub-menu-tab .nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .sub-menu-tab .nav::-webkit-scrollbar {
        display: none;
    }

    .sub-menu-tab .nav-link {
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
    }

    /* Card header: stack text and avatar on mobile */
    .card-header .avatar-header {
        flex-shrink: 0;
        margin-left: 0.5rem;
    }

    .card-header h4 {
        font-size: 1rem;
    }

    .display-1 { font-size: 3rem; }
    .display-2 { font-size: 2.5rem; }
    .display-3 { font-size: 2rem; }
    .display-4 { font-size: 1.75rem; }
}

/* User Profile & Action Bar in Header */
.menuright {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
}

.menuright .item {
    display: flex;
    align-items: center;
    color: var(--text-muted);
}

.menuright .item a {
    color: inherit;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.menuright .item a:hover {
    background-color: var(--bg-main);
    color: var(--primary);
}

.search-bar {
    position: relative;
    max-width: 300px;
    width: 100%;
}

.search-bar input {
    padding-left: 2.5rem !important;
}

.search-bar span {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

/* Sub-menu tab bar */
.sub-menu-tab {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.sub-menu-tab::-webkit-scrollbar {
    display: none;
}

.sub-menu-tab .nav {
    flex-wrap: nowrap;
    white-space: nowrap;
    padding: 0 1rem;
}

.sub-menu-tab .nav-link {
    white-space: nowrap;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.sub-menu-tab .nav-link.active,
.sub-menu-tab .nav-link:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

/* Card header avatar */
.avatar-header img {
    flex-shrink: 0;
}

/* Utility: background primary soft */
.bg-primary-soft {
    background-color: rgba(79, 70, 229, 0.1);
}

/* Sidebar backdrop overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* Prevent body scroll when sidebar is open on mobile */
body.sidebar-open {
    overflow: hidden;
}

/* Bottom Navigation for Mobile */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    z-index: 950;
    border-top: 1px solid var(--border-color);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    transition: all 0.2s ease;
    flex: 1;
}

.bottom-nav-item i {
    width: 20px;
    height: 20px;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item.active i {
    stroke-width: 2.5px;
}

/* Compact stat cards on all screens */
.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

@media (max-width: 576px) {
    .stat-card-value {
        font-size: 1.5rem;
    }
}