@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

:root {
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #0ea5e9;
    --dark: #0f172a;
    --light: #f8fafc;
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --card-shadow-hover: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --border-radius-lg: 1rem;
    --border-radius-md: 0.75rem;
    --border-radius-sm: 0.5rem;
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--gray-50);
    color: var(--gray-700);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1 0 auto;
}

.footer {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(10px);
    border-top: 3px solid var(--primary) !important;
}
h1, h2, h3, h4, h5, h6 {
    font-family: 'Outfit', sans-serif;
    color: var(--dark);
    font-weight: 700;
}

/* ------------------------ */
/* NAVBAR & TOPBAR          */
/* ------------------------ */
.topbar {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--gray-200) !important;
    height: 70px;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030; /* Above sidebar on scroll, below off-canvas sidebar on mobile */
}

.dropdown-menu {
    border: 0;
    border-radius: var(--border-radius-md);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    z-index: 1100; /* Above everything */
    margin-top: 0.5rem !important;
}

/* ------------------------ */
/* SIDEBAR (Premium Original Look) */
/* ------------------------ */
.sidebar {
    background: #0f172a;
    background-image: radial-gradient(ellipse at 50% 0%, #1e293b 0%, #0f172a 80%);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    display: block; /* Native block stacking to resolve flexbox overflow-y scroll limit calculation bugs */
    z-index: 1045; /* Higher than topbar (1030) */
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.sidebar-header {
    padding: 2rem 1.5rem 0.75rem;
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #64748b;
}

.sidebar a {
    font-weight: 500;
    padding: 0.75rem 1rem;
    margin: 0.2rem 1rem;
    border-radius: 0.5rem;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    border: 1px solid transparent;
}

.sidebar a i {
    width: 22px;
    text-align: center;
    font-size: 1.05rem;
    transition: all 0.3s ease;
}

.sidebar a:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--white);
    transform: translateX(4px);
    border-color: rgba(255, 255, 255, 0.05);
}

.sidebar a.active {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.15) 0%, rgba(37, 99, 235, 0.01) 100%);
    color: var(--white);
    font-weight: 600;
    border-color: rgba(37, 99, 235, 0.2);
}

.sidebar a.active::before {
    content: '';
    position: absolute;
    left: -1rem;
    top: 15%;
    height: 70%;
    width: 4px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 12px rgba(37, 99, 235, 0.6);
}

.sidebar a.active i {
    color: #60a5fa; /* A nice bright blue for the icon */
}

.sidebar h4 {
    padding: 1.5rem 1rem;
    font-family: 'Outfit', sans-serif;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.5rem;
    white-space: nowrap;
}

.sidebar h4 i {
    background: linear-gradient(135deg, #60a5fa 0%, #a855f7 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.6rem;
    transition: transform 0.3s ease;
}

.sidebar h4:hover i {
    transform: scale(1.1);
}

/* Mobile Sidebar Header */
.sidebar-header-mobile {
    display: none;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: center;
    justify-content: space-between;
}

.sidebar-header-mobile .close-sidebar {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--white);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Sidebar Profile Card */
.sidebar-user {
    padding: 0.75rem 1rem;
    margin: 1.5rem 1rem 5.5rem; /* Natural margin flow to ensure flawless scrolling height calculations */
    background: #1e293b; /* A beautiful solid slate blue contrast background */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    gap: 0.85rem;
    transition: var(--transition);
    position: relative; /* Scrolls naturally inline with other sidebar links */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* Natural standard drop shadow */
}

.sidebar-user:hover {
    background: #334155; /* Slate hover highlight */
    border-color: rgba(255, 255, 255, 0.2);
}

.sidebar-user img {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    object-fit: cover;
    border: 2px solid var(--primary); /* A nice primary blue border for active contrast! */
}

.sidebar-user-info {
    overflow: hidden;
    line-height: 1.2;
    flex-grow: 1; /* Allow info to take remaining space */
}

.sidebar-user-name {
    display: block;
    color: #f8fafc; /* Sleek light white */
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    display: block;
    color: #38bdf8; /* Sky-blue for outstanding dark mode contrast and premium vibe! */
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Collapsed Sidebar User */
.sidebar.collapsed .sidebar-user {
    padding: 1.25rem 0;
    justify-content: center;
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}

.sidebar.collapsed .sidebar-user-info {
    display: none;
}

/* ------------------------ */
/* CARD STYLING             */
/* ------------------------ */
.card {
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
}

.card.no-hover:hover {
    transform: none;
    box-shadow: var(--card-shadow);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--gray-100);
    padding: 1.25rem 1.5rem;
    font-weight: 600;
}

/* ------------------------ */
/* BUTTONS                  */
/* ------------------------ */
.btn {
    font-weight: 600;
    border-radius: var(--border-radius-md);
    padding: 0.6rem 1.25rem;
    transition: var(--transition);
}

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.1);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: scale(1.02);
}

/* ------------------------ */
/* TABLES                   */
/* ------------------------ */
.table thead th {
    background-color: var(--gray-50);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 1.5rem;
}

.table tbody td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
}

/* ------------------------ */
/* UTILITIES                */
/* ------------------------ */
.badge {
    padding: 0.4em 0.8em;
    font-weight: 600;
    border-radius: 20px;
    font-size: 0.75rem;
}

.badge.bg-success-subtle { background-color: #dcfce7 !important; color: #166534 !important; }
.badge.bg-primary-subtle { background-color: #dbeafe !important; color: #1e40af !important; }
.badge.bg-warning-subtle { background-color: #fef9c3 !important; color: #854d0e !important; }
.badge.bg-danger-subtle { background-color: #fee2e2 !important; color: #991b1b !important; }
.badge.bg-info-subtle { background-color: #e0f2fe !important; color: #075985 !important; }

.stat-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 1.25rem;
}

/* ------------------------ */
/* RESPONSIVE DESIGN        */
/* ------------------------ */

/* Tablet & Desktop */
@media (min-width: 992px) {
    .sidebar { width: 260px; position: fixed; top: 0; left: 0; height: 100vh; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1); overflow-x: hidden; }
    .content { margin-left: 260px; padding: 2rem; transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
    .footer { margin-left: 260px; transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
    
    .sidebar.collapsed { width: 80px; }
    .sidebar.collapsed span { display: none; opacity: 0; }
    .sidebar.collapsed .sidebar-header { display: none; opacity: 0; }
    .sidebar.collapsed a { justify-content: center; padding: 0.85rem 0; margin: 0.25rem 0.6rem; border-radius: 0.5rem; }
    .sidebar.collapsed a i { margin: 0; font-size: 1.3rem; }
    .sidebar.collapsed h4 { padding: 1.5rem 0; }
    .sidebar.collapsed h4 i { font-size: 1.8rem; }
    
    .content.collapsed { margin-left: 80px; }
    .footer.collapsed { margin-left: 80px; }
}

/* Mobile & Tablet Small */
@media (max-width: 991.98px) {
    .sidebar {
        left: -280px;
        width: 280px;
        box-shadow: 20px 0 50px rgba(0,0,0,0.2);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1050; /* Higher than overlay (1040) */
        position: fixed;
        height: 100vh;
        top: 0;
        padding-bottom: 20% !important; /* Extremely generous padding to bottom for smaller screens! */
    }
    .sidebar-user {
        margin-bottom: 20% !important;
    }
    .sidebar.show {
        left: 0;
    }
    .sidebar-header-mobile {
        display: flex;
    }
    .sidebar h4 {
        padding: 1rem;
    }
    .content {
        margin-left: 0 !important;
        padding: 1rem !important;
    }
    .topbar {
        padding: 0 0.75rem;
        height: 60px;
    }
    .stat-widget h2 {
        font-size: 1.5rem;
    }
}

/* Very Small Screens */
@media (max-width: 575.98px) {
    .card-body { padding: 1rem !important; }
    .stat-icon { width: 40px; height: 40px; font-size: 1rem; }
    .btn { padding: 0.5rem 1rem; font-size: 0.9rem; }
}

/* Overlay / Backdrop */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1040;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

/* Responsive Tables */
.table-responsive {
    border-radius: var(--border-radius-md);
    border: 1px solid var(--gray-200);
}

/* Stacked Table for Mobile */
@media (max-width: 767.98px) {
    .table-stack thead {
        display: none; /* Hide headers */
    }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td {
        display: block;
        width: 100%;
    }
    .table-stack tr {
        margin-bottom: 1rem;
        border: 1px solid var(--gray-200);
        border-radius: var(--border-radius-md);
        background: var(--white);
        overflow: hidden;
    }
    .table-stack td {
        text-align: right;
        padding-left: 50% !important;
        position: relative;
        border-bottom: 1px solid var(--gray-100);
    }
    .table-stack td:last-child {
        border-bottom: 0;
    }
    .table-stack td::before {
        content: attr(data-label);
        position: absolute;
        left: 1.5rem;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--gray-500);
        text-transform: uppercase;
        font-size: 0.7rem;
    }
    .table-stack.small td {
        font-size: 0.85rem;
    }
}

/* ============================== */
/* ANALYTICS PAGE                 */
/* ============================== */

/* KPI Cards */
.analytics-kpi {
    border-top: 3px solid var(--kpi-accent, var(--primary)) !important;
    border-radius: var(--border-radius-lg) !important;
    transition: var(--transition);
    animation: kpiFadeIn 0.5s ease both;
}

.analytics-kpi:hover {
    transform: translateY(-6px);
    box-shadow: var(--card-shadow-hover);
}

.analytics-kpi .kpi-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.analytics-kpi .kpi-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
}

.analytics-kpi .kpi-value .kpi-total {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-400);
    margin-left: 0.2rem;
}

.analytics-kpi .kpi-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

@keyframes kpiFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.analytics-kpi:nth-child(1) { animation-delay: 0.0s; }
.analytics-kpi:nth-child(2) { animation-delay: 0.06s; }
.analytics-kpi:nth-child(3) { animation-delay: 0.12s; }
.analytics-kpi:nth-child(4) { animation-delay: 0.18s; }
.analytics-kpi:nth-child(5) { animation-delay: 0.24s; }
.analytics-kpi:nth-child(6) { animation-delay: 0.30s; }

/* Chart Cards */
.chart-card {
    border-radius: var(--border-radius-lg) !important;
    box-shadow: var(--card-shadow);
}

.chart-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
}

.chart-container {
    position: relative;
    height: 280px;
    width: 100%;
}

.chart-container-sm {
    position: relative;
    height: 260px;
    width: 100%;
}

/* Analytics Responsive */
@media (max-width: 1199.98px) {
    .analytics-kpi .kpi-value { font-size: 1.35rem; }
}

@media (max-width: 767.98px) {
    .chart-container { height: 220px; }
    .chart-container-sm { height: 220px; }
    .analytics-kpi .kpi-value { font-size: 1.2rem; }
    .analytics-kpi .kpi-icon { width: 34px; height: 34px; font-size: 0.85rem; }
}

/* ------------------------ */
/* PREMIUM UTILITIES        */
/* ------------------------ */
.glass-card {
    background: rgba(255, 255, 255, 0.7) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

.bg-premium-gradient {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%) !important;
}

.text-gradient {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.animate-hover:hover {
    transform: scale(1.02);
    transition: var(--transition);
}

/* ------------------------ */
/* MODAL & BACKDROP STABILITY */
/* ------------------------ */
.modal-backdrop {
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
}

/* Fix for possible flickering during transitions */
.modal.fade .modal-dialog {
    transition: transform 0.3s ease-out;
}

/* Prevent layout shift */
body.modal-open {
    padding-right: 0 !important;
    overflow: hidden !important;
}

/* Utility from admin.css */
.last-child-no-border:last-child {
    border-right: 0 !important;
}


