:root {
    --primary-color: #2c6cb0;
    --primary-dark: #1a4b80;
    --secondary-color: #e9c46a;
    --text-color: #2c3e50;
    --light-bg: #f5f7fa;
    --sidebar-width: 250px;
    --header-height: 60px;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-bg);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* Layout */
.admin-wrapper {
    display: flex;
    min-height: 100vh;
    position: relative; /* Added for mobile overlay context */
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-color);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: all 0.3s;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    background-color: var(--primary-dark);
    font-weight: bold;
    font-size: 1.2rem;
}

.sidebar-header i {
    margin-right: 10px;
    color: var(--secondary-color);
}

.sidebar-menu {
    list-style: none;
    padding: 20px 0;
    margin: 0;
    flex-grow: 1;
}

.sidebar-menu li a {
    display: block;
    padding: 12px 20px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 4px solid transparent;
}

.sidebar-menu li a:hover, .sidebar-menu li a.active {
    background-color: rgba(255,255,255,0.1);
    color: white;
    border-left-color: var(--secondary-color);
}

.sidebar-menu li a i {
    width: 25px;
    text-align: center;
    margin-right: 10px;
}

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

.user-info {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
}

.user-details {
    font-size: 0.9rem;
}

.user-role {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s;
    width: 100%; /* Ensure width is handled */
}

.top-header {
    height: var(--header-height);
    background-color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 999;
}

.page-content {
    padding: 30px;
    flex-grow: 1;
}

.page-header {
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-title {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin: 0;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border: none;
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    background-color: white;
    border-bottom: 1px solid #eee;
    padding: 15px 20px;
    font-weight: 600;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 20px;
}

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

.table th {
    border-top: none;
    font-weight: 600;
    color: #666;
    background-color: #f8f9fa;
}

.table td {
    vertical-align: middle;
}

/* Responsive & Toggling */

/* Desktop: Sidebar active means HIDDEN (collapsed) - but we want it always open on desktop */
@media (min-width: 769px) {
    #sidebarToggle {
        display: none !important;
    }
    .sidebar.active {
        margin-left: 0; /* Override collapse behavior if any */
    }
    .main-content.active {
        margin-left: var(--sidebar-width);
    }
}

/* Mobile: Sidebar default HIDDEN, active means SHOWN */
@media (max-width: 768px) {
    .sidebar {
        left: calc(var(--sidebar-width) * -1);
    }
    
    .sidebar.active {
        left: 0 !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
    
    /* Overlay effect when sidebar is open on mobile */
    .sidebar.active + .main-content::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 998; /* Below sidebar, above content */
    }
    
    .top-header {
        padding: 0 15px;
    }
    
    .page-content {
        padding: 15px;
    }
}

/* Utility for mobile visibility */
@media (max-width: 768px) {
    .d-mobile-none {
        display: none !important;
    }
}

/* Fix for background colors in cards - Specificity fix */
.card.bg-primary { background-color: var(--primary-color) !important; color: white !important; }
.card.bg-info { background-color: var(--info-color) !important; color: white !important; }
.card.bg-success { background-color: var(--success-color) !important; color: white !important; }
.card.bg-warning { background-color: var(--warning-color) !important; color: white !important; }
.card.bg-danger { background-color: var(--danger-color) !important; color: white !important; }

/* Ensure text is white in these cards */
.card.text-white h5, .card.text-white p, .card.text-white i {
    color: white !important;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 998;
}

@media (max-width: 768px) {
    .admin-wrapper.sidebar-open .sidebar-overlay {
        display: block;
    }
    html {
        font-size: 13px;
    }
    .top-header {
        height: 50px;
        padding: 0 12px;
    }
    .page-title {
        font-size: 1.2rem;
    }
    .page-content {
        padding: 12px;
    }
    .table th, .table td {
        padding: 6px 8px;
        font-size: 0.9rem;
    }
    .btn-action {
        padding: 4px 8px;
        font-size: 0.85rem;
    }
}
@media (max-width: 768px) {

    /* Sidebar oculta por defecto */
    .sidebar {
        position: fixed;
        left: -250px;
        top: 0;
        height: 100%;
        width: 250px;
        transition: left 0.3s ease;
        z-index: 1000;
    }

    /* Sidebar visible */
    .sidebar.active {
        left: 0;
    }

    /* Contenido ocupa todo el ancho */
    .content,
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 15px;
    }
}
@media (max-width: 768px) {

    .sidebar {
        position: fixed;
        left: -250px;
        top: 0;
        height: 100%;
        width: 250px;
        transition: left 0.3s ease;
        z-index: 1050;
    }

    .sidebar.active {
        left: 0;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        display: none;
        z-index: 1040;
    }

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

    .main-content {
        margin-left: 0 !important;
    }
}
