:root {
    /* Paleta de Colores Premium - Dark Mode */
    --bg-dark: #0f172a;
    /* Slate 900 */
    --bg-card: #1e293b;
    /* Slate 800 */
    --bg-hover: #334155;
    /* Slate 700 */

    --primary-color: #3b82f6;
    /* Blue 500 */
    --primary-hover: #2563eb;
    /* Blue 600 */
    --accent-color: #0ea5e9;
    /* Sky 500 */

    --text-main: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */

    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);

    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --header-height: 64px;
    --transition-speed: 0.3s;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Layout Container */
.admin-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

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

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-speed);
    z-index: 50;
    flex-shrink: 0;
    position: relative;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--glass-border);
    justify-content: space-between;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    white-space: nowrap;
}

.logo-img {
    height: 36px;
    width: auto;
    filter: brightness(1.2);
}

.logo-text {
    font-weight: 700;
    font-size: 1.1rem;
    color: white;
    opacity: 1;
    transition: opacity 0.2s;
}

.sidebar.collapsed .logo-text {
    opacity: 0;
    display: none;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover {
    color: white;
    background: var(--bg-hover);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-color);
}


/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 60px;
    /* Increased spacing significantly */
    flex-wrap: wrap;
    gap: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.page-title {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Cards & Grid */
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    margin-top: 20px;
}

.app-card {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    min-height: 250px;
}

.app-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.3);
    border-color: rgba(59, 130, 246, 0.3);
}

.app-icon-box {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    margin-bottom: 10px;
}

.app-title {
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 5px;
}

/* Forms */
.form-control {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
    font-size: 0.95rem;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-size: 0.95rem;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #fff;
}

/* Collapsible Section */
.collapsible-section {
    display: none;
    margin-top: 30px;
    animation: slideDown 0.3s ease-out;
}

.collapsible-section.active {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 40px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th {
    background: rgba(15, 23, 42, 0.8);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 20px 30px;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

td {
    padding: 20px 30px;
    border-bottom: 1px solid var(--glass-border);
    color: var(--text-main);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.badge-secondary {
    background: rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.3);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 30px;
}

/* Utilities */
.logo-glow:hover {
    filter: brightness(1.3);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 260px;
        /* Mantener ancho completo cuando está abierto */
    }

    .admin-container {
        position: relative;
        overflow-x: hidden;
    }

    /* Sidebar Overlay Mode */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
    }

    .sidebar.active {
        transform: translateX(0);
        width: var(--sidebar-width);
    }

    /* Backdrop */
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(3px);
        z-index: 900;

        .top-bar .date-display {
            display: none;
            /* Ocultar fecha en móvil */
        }

        .btn-portal-text {
            display: none;
            /* Ocultar texto "Volver al Portal" */
        }

        .btn-primary {
            padding: 8px 12px;
            /* Botones más compactos */
        }

        .user-info span {
            display: none;
            /* Ocultar nombre de usuario */
        }

        /* Content Area */
        .content-scroll {
            padding: 20px 15px;
        }

        .page-header {
            flex-direction: column;
            align-items: flex-start;
            gap: 15px;
            margin-bottom: 30px;
        }

        .page-header>div,
        .page-header form {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }

        .page-header .btn-primary,
        .page-header .btn-secondary,
        .page-header input[type="text"] {
            flex: 1;
            width: 100% !important;
            /* Override inline styles */
            justify-content: center;
            font-size: 0.85rem;
            padding: 10px;
        }

        /* Tables */
        .table-container {
            width: 100%;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            display: block;
        }

        table {
            min-width: 800px;
            /* Forzar scroll horizontal */
            width: 100%;
        }

        ```css transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 40px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th {
    background: rgba(15, 23, 42, 0.8);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 20px 30px;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

td {
    padding: 20px 30px;
    border-bottom: 1px solid var(--glass-border);
    color: var(--text-main);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.badge-secondary {
    background: rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.3);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 30px;
}

/* Utilities */
.logo-glow:hover {
    filter: brightness(1.3);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 260px;
        /* Mantener ancho completo cuando está abierto */
    }

    .admin-container {
        position: relative;
        overflow-x: hidden;
    }

    /* Sidebar Overlay Mode */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
    }

    .sidebar.active {
        transform: translateX(0);
        width: var(--sidebar-width);
    }

    /* Backdrop */
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(3px);
        z-index: 900;
    }

    .top-bar .date-display {
        display: none;
        /* Ocultar fecha en móvil */
    }

    .btn-portal-text {
        display: none;
        /* Ocultar texto "Volver al Portal" */
    }

    .btn-primary {
        padding: 8px 12px;
        /* Botones más compactos */
    }

    .user-info span {
        display: none;
        /* Ocultar nombre de usuario */
    }

    /* Content Area */
    .content-scroll {
        padding: 20px 15px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        margin-bottom: 30px;
    }

    .page-header>div,
    .page-header form {
        width: 100%;
        gap: 10px;
    }

    /* Mobile-specific adjustments */
    .page-header .btn-primary,
    .page-header .btn-secondary,
    .page-header input[type="text"] {
        flex: 1;
        width: 100% !important;
        /* Override inline styles */
        justify-content: center;
        font-size: 0.85rem;
        padding: 10px;
    }

    /* Tables */
    .table-container {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
    }

    table {
        min-width: 800px;
        /* Forzar scroll horizontal */
        width: 100%;
    }

    th,
    td {
        padding: 12px 15px;
        font-size: 0.85rem;
    }
}

/* --- Global Components (Must be outside media query) --- */

/* Logout Button Styles */
.btn-logout {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: rgba(239, 68, 68, 0.5);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.btn-logout:active {
    transform: translateY(1px) scale(0.96);
    background: rgba(239, 68, 68, 0.3);
    box-shadow: none;
}

.btn-logout.loading {
    opacity: 0.7;
    pointer-events: none;
    cursor: wait;
}

/* Modal Styles - Global */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Force display when active */
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-main);
}

.modal-text {
    color: var(--text-muted);
    margin-bottom: 25px;
    font-size: 0.95rem;
}

.modal-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
}

.btn-primary:hover {
    filter: brightness(110%);
}

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

.btn-secondary:hover {
    color: var(--text-main);
}

/* App Viewer Overlay - Global */
.app-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    z-index: 2000;
    display: none;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
}

.app-viewer.active {
    display: flex;
    transform: translateY(0);
}

.viewer-header {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.viewer-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

.viewer-controls {
    display: flex;
    gap: 10px;
}

/* Spinner Animation - FORCED */
/* Spinner Animation - FORCED */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes pulseText {

    0%,
    100% {
        opacity: 1;
    }

}

/* Global Content Spacing - FORCED */
.content-scroll {
    padding: 30px !important;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .content-scroll {
        padding: 20px 15px !important;
    }
}