/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--grad-mesh);
    background-size: cover;
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

/* App Container - Dynamic Layout */
.app-container {
    height: 100%;
    width: 100%;
    margin: 0 auto;
    position: relative;
    background-color: var(--bg-color);
    overflow-y: auto;
}

/* Default Mobile Mode (Auxiliar) */
.app-container:not(.admin-mode) {
    max-width: 600px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    background: white;
}

/* Desktop Admin Mode Layout */
.app-container.admin-mode {
    max-width: 100%;
    background-color: #f8fafc;
}

#admin-layout {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar Styles */
.admin-sidebar {
    width: 280px;
    background: rgba(0, 59, 145, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: white;
    height: 100vh;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-footer {
    padding: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 40px;
    background: #f8fafc;
}

/* Mobile Header */
.admin-mobile-header {
    display: none !important;
    height: 60px;
    background: rgba(0, 59, 145, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 1001;
    color: white;
}

.admin-mobile-header .icon-btn {
    color: white !important;
}

.mobile-logo {
    font-weight: 700;
    color: white;
    font-size: 1.1rem;
}

/* Responsive Rules */
@media (max-width: 1024px) {
    .admin-mobile-header {
        display: flex !important;
        background: var(--primary-dark);
        backdrop-filter: blur(10px);
    }

    .admin-sidebar {
        display: none !important;
        position: fixed !important;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.3);
        z-index: 2000 !important;
        background: var(--primary-dark) !important;
    }

    .admin-sidebar.mobile-open {
        display: flex !important;
        transform: translateX(0);
    }

    .admin-content {
        padding: 20px 12px !important;
    }

    /* Sidebar Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(4px);
        z-index: 950;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Stack Grids */
    div[style*="grid-template-columns: repeat(3, 1fr)"],
    div[style*="grid-template-columns: 2fr 1fr"],
    div[style*="grid-template-columns: 1.5fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    .card {
        padding: 20px;
    }

    /* Stats display stacking */
    div[style*="grid-template-columns: repeat(4, 1fr)"] {
        grid-template-columns: 1fr 1fr !important;
    }
}

@media (max-width: 640px) {
    div[style*="grid-template-columns: repeat(4, 1fr)"] {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    header[style*="display: flex"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 16px !important;
    }

    header[style*="display: flex"]>div[style*="width"] {
        width: 100% !important;
    }

    header[style*="display: flex"]>div[style*="display: flex"] {
        width: 100% !important;
    }

    header[style*="display: flex"] .btn {
        flex-grow: 1;
    }

    .card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 700px;
    }
}

/* Utilities */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-sm {
    gap: var(--spacing-sm);
}

.gap-md {
    gap: var(--spacing-md);
}

.text-center {
    text-align: center;
}

.w-full {
    width: 100%;
}

.mt-md {
    margin-top: var(--spacing-md);
}

.mb-md {
    margin-bottom: var(--spacing-md);
}

/* Typography */
h1 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.5px;
}

h2 {
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--primary-dark);
}

h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: inherit;
    /* Allow inheritance or use a dark slate */
}

p {
    color: var(--text-secondary);
}

small {
    font-size: var(--font-size-sm);
    color: var(--text-light);
}

/* Custom Scrollbar for Admin */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* --- FINAL ADMIN LAYOUT STABILITY --- */
.admin-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background: #f8fafc;
}

.admin-main-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    flex-direction: row !important;
    /* Force row on desktop */
}

.admin-sidebar {
    width: 280px !important;
    background: var(--primary-color) !important;
    color: white !important;
    height: 100% !important;
    flex-shrink: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 100;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 32px 24px 24px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.sidebar-logo span {
    color: var(--secondary-accent);
    font-size: 32px;
    filter: drop-shadow(0 0 10px var(--secondary-glow));
}

.sidebar-logo h2 {
    color: white !important;
    font-size: 1.25rem;
    margin: 0;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.sidebar-header small {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    display: block;
}

#admin-nav {
    flex-grow: 1;
    padding: 20px 12px !important;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-link {
    display: flex !important;
    align-items: center !important;
    gap: 12px;
    padding: 12px 16px;
    color: rgba(255, 255, 255, 0.7) !important;
    border-radius: 8px;
    text-decoration: none !important;
    transition: 0.2s;
    font-size: 0.95rem;
    font-weight: 500;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white !important;
}

.sidebar-link.active {
    color: white !important;
    background: rgba(255, 255, 255, 0.12) !important;
    border-left: 4px solid var(--accent-color);
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-footer {
    padding: 24px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    background: var(--accent-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
}

.user-name {
    color: white !important;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
}

.btn-logout {
    margin-top: 16px;
    background: rgba(239, 68, 68, 0.1) !important;
    color: #ef4444 !important;
    border: 1px solid rgba(239, 68, 68, 0.15) !important;
    height: 40px;
    width: 100%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.2) !important;
}

@media (max-width: 1024px) {
    .admin-main-wrapper {
        flex-direction: column !important;
    }

    .admin-sidebar {
        display: none !important;
        position: fixed !important;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.3);
        z-index: 2000 !important;
    }

    .admin-sidebar.mobile-open {
        display: flex !important;
        transform: translateX(0);
    }
}