/* CSS Variables for Theme Support */
:root {
    /* Light theme */
    --bg-app: #f6f7f8;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --text-primary: #111418;
    --text-secondary: #617589;
    --text-muted: #9ca3af;
    --border-color: #e5e7eb;
    --primary: #137fec;
    --primary-hover: #0b6ed0;
    --primary-soft: rgba(19, 127, 236, 0.1);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-app: #101922;
    --bg-card: #1a242f;
    --bg-sidebar: #1a242f;
    --text-primary: #f7fafc;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border-color: #2d3748;
    --primary-soft: rgba(19, 127, 236, 0.15);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color var(--transition), color var(--transition);
    min-height: 100vh;
}

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

/* Sidebar Overhaul */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1000;
}

/* Solo aplicar transición después de que la página cargue para evitar el "flash" */
.sidebar.ready {
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
    width: 80px;
}

/* Estado inicial instantáneo basado en el atributo del head */
[data-sidebar-init-collapsed="true"] .sidebar {
    width: 80px;
}
[data-sidebar-init-collapsed="true"] .main-content {
    margin-left: 80px;
    width: calc(100vw - 80px);
}

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

.sidebar.collapsed .sidebar-header {
    padding: 16px 0;
    height: auto;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: transform 0.2s;
    overflow: hidden;
}

.logo:hover {
    transform: scale(1.02);
}

.sidebar-nav {
    flex: 1;
    padding: 24px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none !important;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.nav-link span {
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-icon, .nav-link svg {
    color: var(--text-secondary);
}

.nav-link:hover svg, .nav-link.active svg {
    color: var(--primary);
}

.logout svg {
    color: var(--danger);
}

.nav-link:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: rgba(19, 127, 236, 0.2);
}

.sidebar.collapsed .nav-link span:last-child,
.sidebar.collapsed .logo-text,
.sidebar.collapsed .user-info-text,
.sidebar.collapsed .credits-badge,
.sidebar.collapsed .theme-toggle span:last-child {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px;
    width: 48px;
    margin: 0 auto;
}

.sidebar-footer {
    padding: 20px 12px;
    border-top: 1px solid var(--border-color);
    background: rgba(0,0,0,0.02);
}

[data-theme="dark"] .sidebar-footer {
    background: rgba(255,255,255,0.02);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-info-text {
    flex: 1;
    min-width: 0;
}

.user-name {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.credits-badge {
    display: inline-block;
    font-size: 11px;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 2px 8px;
    border-radius: 20px;
    margin-top: 2px;
    font-weight: 600;
}

.collapse-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 12px;
}

.collapse-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    transform: scale(1.1);
}

/* Eliminamos la rotación de CSS para que el JS controle el sentido de la flecha */

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px;
    min-height: 100vh;
    width: calc(100vw - 260px);
    max-width: 100%;
}

.main-content.ready {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content.sidebar-collapsed {
    margin-left: 80px;
    width: calc(100vw - 80px);
}

.main-content.full-width {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0;
}

/* Fix for PDF overflow */
.document-viewer {
    background: #525659;
    border-radius: var(--radius-lg);
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: auto;
    width: 100%;
}

.pdf-container {
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    background: white;
    max-width: 100%; /* No se sale del contenedor */
}

#pdfCanvas {
    display: block;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 14px;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--transition), border-color var(--transition);
}

.card h3 {
    font-size: 16px;
    margin-bottom: 12px;
}

.card-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.card-subtitle {
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-app);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    transition: all var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-input::placeholder {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(19, 127, 236, 0.4);
}

.btn-secondary {
    background: var(--bg-app);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

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

.btn-full {
    width: 100%;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.table tbody tr:hover {
    background: var(--primary-soft);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-info {
    background: var(--primary-soft);
    color: var(--primary);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* Auth Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    font-size: 40px;
    margin-bottom: 16px;
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--text-secondary);
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* Error Page */
.error-container {
    text-align: center;
    padding: 60px 20px;
}

.error-icon {
    font-size: 64px;
    margin-bottom: 24px;
}

.error-title {
    font-size: 24px;
    margin-bottom: 16px;
}

.error-message {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        padding: 24px 16px;
    }
    
    .card {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .btn {
        width: 100%;
    }
    
    .auth-card {
        padding: 0;
    }
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: 0.2s ease;
    backdrop-filter: blur(4px);
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 24px;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-md);
    transform: translateY(20px);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

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

.modal-title {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}
