/* Reset y estilos base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

.container {
    flex: 1;
    margin-left: 250px;
    padding: 20px;
}

/* Header */
.main-header {
    background-color: #2c3e50;
    color: white;
    padding: 15px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 24px;
    font-weight: bold;
}

.main-nav {
    display: flex;
    gap: 20px;
}

.main-nav a {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.main-nav a:hover {
    background-color: rgba(255,255,255,0.1);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Botones */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.3s;
}

.btn-primary {
    background-color: #0066FF;
    color: white;
}

.btn-primary:hover {
    background-color: #0052CC;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-success {
    background-color: #27ae60;
    color: white;
}

.btn-success:hover {
    background-color: #229954;
}

/* Login page */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.login-box h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 10px;
}

.login-box h2 {
    text-align: center;
    color: #7f8c8d;
    font-size: 18px;
    font-weight: normal;
    margin-bottom: 30px;
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #0066FF;
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

/* Mensajes */
.error-message {
    background-color: #e74c3c;
    color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.success-message {
    background-color: #27ae60;
    color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 20px;
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.dashboard-card {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    text-align: center;
}

.dashboard-card h3 {
    color: #2c3e50;
    margin-bottom: 10px;
}

.dashboard-card p {
    color: #7f8c8d;
    margin-bottom: 20px;
}

/* Tablas */
.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-top: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background-color: #2c3e50;
    color: white;
}

th, td {
    padding: 12px;
    text-align: left;
}

tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

tbody tr:hover {
    background-color: #e9ecef;
}

/* Acciones de tabla */
.table-actions {
    display: flex;
    gap: 10px;
}

.table-actions .btn {
    padding: 5px 10px;
    font-size: 12px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-close {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
}

.modal-close:hover {
    color: #000;
}

/* Sidebar - Azul electrico y blanco puro */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 250px;
    height: 100vh;
    background: linear-gradient(180deg, #0066FF 0%, #0052CC 100%);
    color: #FFFFFF;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 102, 255, 0.2);
    z-index: 100;
}

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

.sidebar-header h2 {
    font-size: 24px;
    margin-bottom: 5px;
    color: #FFFFFF;
}

.sidebar-header .user-info {
    font-size: 13px;
    color: #FFFFFF;
    margin: 5px 0 0 0;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: #FFFFFF;
    text-decoration: none;
    transition: all 0.3s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background-color: rgba(255,255,255,0.15);
    color: #FFFFFF;
    border-left-color: #FFFFFF;
}

.sidebar-link.active {
    background-color: rgba(255, 255, 255, 0.25);
    color: #FFFFFF;
    border-left-color: #FFFFFF;
    font-weight: 600;
}

.sidebar-icon {
    margin-right: 12px;
    font-size: 18px;
    width: 24px;
    text-align: center;
}

/* ========================================
   SELECTOR DE EMPRESA
   ======================================== */

.company-selector {
    margin: 15px;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    position: relative;
}

.company-current {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    transition: background 0.3s;
    border-radius: 8px;
}

.company-current:hover {
    background: rgba(255,255,255,0.15);
}

.company-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.company-label {
    font-size: 10px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.7);
    margin-bottom: 2px;
}

.company-name {
    font-size: 14px;
    font-weight: 600;
    color: #FFFFFF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.company-arrow {
    font-size: 10px;
    color: rgba(255,255,255,0.7);
    transition: transform 0.3s;
}

.company-selector.open .company-arrow {
    transform: rotate(180deg);
}

.company-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #FFFFFF;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 1000;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s;
    opacity: 0;
}

.company-selector.open .company-dropdown {
    max-height: 300px;
    opacity: 1;
    overflow-y: auto;
}

.company-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    color: #333;
    text-decoration: none;
    transition: background 0.2s;
    border-bottom: 1px solid #eee;
}

.company-option:hover {
    background: #f5f5f5;
}

.company-option.active {
    background: #e3f2fd;
    border-left: 3px solid #0066FF;
}

.company-option-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.company-default-badge {
    font-size: 10px;
    background: #28a745;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
}

.company-role-badge {
    font-size: 10px;
    background: #6c757d;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
    text-transform: capitalize;
}

.company-empty {
    padding: 15px;
    text-align: center;
    color: #6c757d;
    font-size: 13px;
}

.company-manage-link {
    display: block;
    padding: 12px 15px;
    text-align: center;
    color: #0066FF;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

.company-manage-link:hover {
    background: #e9ecef;
}

/* View Mode Toggle (Superadmin/User) */
.view-mode-toggle {
    margin: 10px 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    padding: 3px;
}

.view-mode-switch {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    background: rgba(255,255,255,0.15);
    border-radius: 6px;
    transition: all 0.3s;
}

.view-mode-switch:hover {
    background: rgba(255,255,255,0.25);
}

.view-mode-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-mode-icon {
    font-size: 18px;
}

.view-mode-label {
    font-size: 12px;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.view-mode-toggle-btn {
    display: flex;
    align-items: center;
}

.toggle-track {
    width: 40px;
    height: 22px;
    background: rgba(0,0,0,0.3);
    border-radius: 11px;
    position: relative;
    transition: all 0.3s;
}

.toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-thumb.active {
    left: 20px;
    background: #ffd700;
}

.view-mode-indicator.superadmin .view-mode-label {
    color: #ffd700;
}

.view-mode-indicator.user .view-mode-label {
    color: #fff;
}

/* Sidebar Section Title */
.sidebar-section-title {
    padding: 10px 20px 5px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.5);
    margin-top: 5px;
}

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

.logout-link {
    color: #FFFFFF;
}

.logout-link:hover {
    color: #FF4444;
    border-left-color: #FF4444;
}

/* Sidebar Dropdown Menu */
.sidebar-dropdown {
    position: relative;
}

.sidebar-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    color: #FFFFFF;
    text-decoration: none;
    transition: all 0.3s;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.sidebar-dropdown-toggle:hover {
    background-color: rgba(255,255,255,0.15);
    color: #FFFFFF;
    border-left-color: #FFFFFF;
}

.sidebar-dropdown-toggle.active {
    background-color: rgba(255, 255, 255, 0.25);
    color: #FFFFFF;
    border-left-color: #FFFFFF;
}

.dropdown-arrow {
    font-size: 12px;
    transition: transform 0.3s;
}

.sidebar-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.sidebar-dropdown-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: rgba(0,0,0,0.2);
}

.sidebar-dropdown.open .sidebar-dropdown-menu {
    max-height: 500px;
}

.sidebar-dropdown-menu .sidebar-link {
    padding-left: 56px;
    font-size: 14px;
}

.sidebar-dropdown-menu .sidebar-link .sidebar-icon {
    font-size: 16px;
}

/* ========================================
   RESPONSIVE: BOTÓN HAMBURGUESA Y MÓVIL
   ======================================== */

/* Botón hamburguesa (oculto en desktop) - Azul eléctrico */
.hamburger-btn {
    display: none; /* Oculto por defecto */
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #0066FF 0%, #0052CC 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0, 102, 255, 0.3);
    transition: all 0.3s ease;
}

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 3px;
    background: white;
    border-radius: 3px;
    transition: all 0.3s ease;
}

.hamburger-btn:hover {
    box-shadow: 0 6px 16px rgba(0, 102, 255, 0.5);
    transform: translateY(-2px);
}

.hamburger-btn:active {
    transform: translateY(0);
}

/* Animación del botón hamburguesa cuando está activo */
.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* Overlay oscuro (oculto en desktop) */
.sidebar-overlay {
    display: none; /* Oculto por defecto */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Botón cerrar dentro del sidebar (solo móvil) */
.sidebar-close-btn {
    display: none; /* Oculto por defecto */
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.3s;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* ========================================
   MEDIA QUERIES: TABLET Y MÓVIL
   ======================================== */

/* Tablet (< 1024px) */
@media (max-width: 1024px) {
    .container {
        margin-left: 250px; /* Mantener sidebar visible */
    }
}

/* Móvil y Tablet pequeño (< 768px) */
@media (max-width: 768px) {
    /* Mostrar botón hamburguesa */
    .hamburger-btn {
        display: flex;
    }

    /* Mostrar overlay cuando esté activo */
    .sidebar-overlay {
        display: block;
    }

    /* Mostrar botón cerrar dentro del sidebar */
    .sidebar-close-btn {
        display: block;
    }

    /* Sidebar oculto por defecto en móvil */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    /* Sidebar visible cuando tiene clase 'open' */
    .sidebar.open {
        transform: translateX(0);
    }

    /* Ajustar container para no tener margin-left */
    .container {
        margin-left: 0;
        padding: 80px 15px 20px 15px; /* Más padding-top para el botón hamburguesa */
    }

    /* Ajustar header del sidebar */
    .sidebar-header {
        padding: 30px 60px 30px 20px; /* Espacio para botón cerrar */
    }

    /* Tablas responsive */
    .table-container {
        overflow-x: auto;
    }

    table {
        min-width: 600px;
    }

    /* Dashboard grid más compacto */
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    /* Formularios más compactos */
    .modal-content {
        padding: 20px;
        width: 95%;
    }
}

/* Móvil muy pequeño (< 480px) */
@media (max-width: 480px) {
    /* Botón hamburguesa más pequeño */
    .hamburger-btn {
        width: 45px;
        height: 45px;
        top: 15px;
        left: 15px;
    }

    .hamburger-btn span {
        width: 20px;
    }

    /* Container más compacto */
    .container {
        padding: 70px 10px 15px 10px;
    }

    /* Sidebar header más compacto */
    .sidebar-header h2 {
        font-size: 20px;
    }

    .sidebar-header .user-info {
        font-size: 12px;
    }

    /* Links del sidebar más compactos */
    .sidebar-link {
        padding: 10px 15px;
        font-size: 14px;
    }

    .sidebar-icon {
        font-size: 16px;
        width: 20px;
    }

    /* Dropdown menu más compacto */
    .sidebar-dropdown-menu .sidebar-link {
        padding-left: 45px;
        font-size: 13px;
    }

    /* Botones más pequeños */
    .btn {
        padding: 8px 15px;
        font-size: 13px;
    }

    /* Tablas aún más compactas */
    th, td {
        padding: 8px;
        font-size: 13px;
    }
}

/* Landscape móvil */
@media (max-height: 500px) and (max-width: 900px) {
    .sidebar {
        max-height: 100vh;
    }

    .sidebar-nav {
        padding: 10px 0;
    }

    .sidebar-link {
        padding: 8px 20px;
    }
}

/* ==================== UPLOAD MODAL ==================== */

.upload-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

.upload-modal-overlay.active {
    display: flex;
}

.upload-modal {
    background: white;
    border-radius: 12px;
    width: 680px;
    max-width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.upload-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.upload-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #2c3e50;
}

.upload-modal-progress {
    padding: 16px 24px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
}

.upload-modal-progress-text {
    font-size: 14px;
    color: #495057;
    margin-bottom: 8px;
    font-weight: 500;
}

.upload-modal-progress-bar {
    width: 100%;
    height: 6px;
    background: #e9ecef;
    border-radius: 3px;
    overflow: hidden;
}

.upload-modal-progress-bar-fill {
    height: 100%;
    background: #0066FF;
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    max-height: 400px;
}

.upload-file-row {
    display: flex;
    align-items: center;
    padding: 10px 24px;
    gap: 12px;
    border-bottom: 1px solid #f1f3f5;
    transition: background 0.2s;
}

.upload-file-row.active {
    background: #f0f7ff;
}

.upload-file-row-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.upload-file-row-info {
    flex: 1;
    min-width: 0;
}

.upload-file-row-name {
    font-size: 13px;
    font-weight: 500;
    color: #2c3e50;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-file-row-detail {
    font-size: 12px;
    color: #868e96;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-file-row-detail.success {
    color: #2b8a3e;
}

.upload-file-row-detail.error {
    color: #c92a2a;
}

.upload-status-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

.upload-status-badge.waiting {
    background: #f1f3f5;
    color: #868e96;
}

.upload-status-badge.processing {
    background: #dbe4ff;
    color: #364fc7;
}

.upload-status-badge.success {
    background: #d3f9d8;
    color: #2b8a3e;
}

.upload-status-badge.error {
    background: #ffe3e3;
    color: #c92a2a;
}

.upload-modal-summary {
    padding: 16px 24px;
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    display: none;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.upload-modal-summary.visible {
    display: flex;
}

.upload-summary-stats {
    display: flex;
    gap: 16px;
    font-size: 14px;
}

.upload-summary-stats span {
    font-weight: 600;
}

.upload-summary-stats .stat-ok {
    color: #2b8a3e;
}

.upload-summary-stats .stat-err {
    color: #c92a2a;
}

.upload-summary-stats .stat-time {
    color: #868e96;
}

.spinner-small {
    width: 18px;
    height: 18px;
    border: 2.5px solid #dbe4ff;
    border-top-color: #364fc7;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== UPLOAD HISTORY MODAL ==================== */

.upload-history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.upload-history-table th {
    text-align: left;
    padding: 8px 12px;
    background: #f8f9fa;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
}

.upload-history-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f3f5;
    vertical-align: top;
}

.upload-history-table tr:hover td {
    background: #f8f9fa;
}

.upload-history-items {
    padding: 8px 12px 8px 24px;
    background: #f8f9fa;
    font-size: 12px;
}

.upload-history-items table {
    width: 100%;
    border-collapse: collapse;
}

.upload-history-items td {
    padding: 4px 8px;
    border-bottom: 1px solid #e9ecef;
}

.btn-expand {
    background: none;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 12px;
    color: #495057;
}

.btn-expand:hover {
    background: #e9ecef;
}
