/* style.css */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f9;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 950px;
    display: none;
    /* Ocultar por defecto */
}

.container.active {
    display: block;
    /* Mostrar el contenedor activo */
}

#login-container {
    max-width: 400px;
}

h1,
h2 {
    color: #333;
    text-align: center;
    margin-bottom: 20px;
}

input,
select,
button {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border-radius: 4px;
    border: 1px solid #ddd;
    box-sizing: border-box;
}

button {
    background-color: #007bff;
    color: white;
    font-size: 16px;
    border: none;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #0056b3;
}

.error-message {
    color: #dc3545;
    font-size: 14px;
    text-align: center;
}

.success-message {
    color: #28a745;
    font-size: 14px;
    text-align: center;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.header h1 {
    margin: 0;
}

.admin-section,
#users-list-section {
    margin-bottom: 30px;
    border: 1px solid #e0e0e0;
    padding: 20px;
    border-radius: 5px;
}

/* Ocultar elementos específicos por defecto */
#create-user-section {
    display: none;
}

#sales-points-section {
    display: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th,
td {
    padding: 12px;
    border: 1px solid #ddd;
    text-align: left;
}

th {
    background-color: #f2f2f2;
}

/* =============================== */
/* === BARRA DE NAVEGACIÓN (NAVBAR) === */
/* =============================== */

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #1f1f1f;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #444;
    margin-bottom: 10px;

}

.nav-section {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-item {
    color: #f0f0f0;
    text-decoration: none;
    font-size: 16px;
    margin: 0;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background-color 0.2s;
    cursor: pointer;
}

.nav-item:hover {
    background-color: #333;
}

.nav-logout-btn {
    background-color: #dc3545;
    font-weight: bold;
}

.nav-logout-btn:hover {
    background-color: #c82333;
}

/* ================================================= */
/* === ESTILOS PARA LOS INTERRUPTORES (SWITCH)   === */
/* ================================================= */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: #28a745;
}

input:checked+.slider:before {
    transform: translateX(26px);
}

/* ================================================= */
/* === MENÚ DESPLEGABLE (CORREGIDO)              === */
/* ================================================= */

.nav-item.dropdown {
    position: relative;
}

.dropdown-content {
    /* No usamos display: none para poder aplicar transiciones */
    display: block;
    visibility: hidden;
    opacity: 0;

    position: absolute;
    top: 100%;
    left: 0;
    background-color: #2a2a2a;
    min-width: 200px;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    border-radius: 5px;
    overflow: visible;
    /* Permitir el puente invisible */
    border: 1px solid #444;

    /* REGLA DE ORO: Un delay de 0.2s al ocultarse para evitar flickering */
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

/* El puente invisible: Rellena el espacio entre el botón y el menú */
.dropdown-content::before {
    content: "";
    position: absolute;
    top: -15px;
    left: 0;
    right: 0;
    height: 15px;
    background: transparent;
}

.dropdown-content a {
    color: white;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
    font-size: 14px;
    transition: background 0.2s;
}

.dropdown-content a:hover {
    background-color: #444;
}

/* Mostrar el menú con hover suave */
.dropdown:hover .dropdown-content {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
    /* Aparece al instante al entrar */
}

/* ================================================= */

/* ESTILOS PARA LAS CELDAS DE ESTADO Y ACCIONES */
td:nth-last-child(1),
td:nth-last-child(2),
td:nth-last-child(3) {
    vertical-align: middle;
    text-align: center;
}

.status-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    min-width: 120px;
}

.status-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.status.active {
    color: #28a745;
    font-weight: bold;
}

.status.inactive {
    color: #dc3545;
    font-weight: bold;
}

.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========================================================== */
/* ===         CONTROLES DE VISIBILIDAD POR ROL           === */
/* ========================================================== */

.role-only,
.superadmin-only,
.admin-only {
    display: none !important;
}

body.user-is-superadmin .superadmin-only {
    display: block !important;
}

body.user-is-superadmin .superadmin-only-table-cell {
    display: table-cell !important;
}

body.user-is-admin .admin-only {
    display: block !important;
}

body.user-is-admin .admin-only-table-cell {
    display: table-cell !important;
}

body.user-is-admin #create-user-section.admin-only {
    display: block !important;
}

/* ========================================================== */
/* ===     ESTILOS DEL MODAL (VERSIÓN ÚNICA)               === */
/* ========================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

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

.modal-content {
    background: #2a2a2a;
    color: #e0e0e0;
    border-radius: 8px;
    border: 1px solid #555;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    padding: 0;
    overflow-y: auto;
}

.modal-content h2 {
    font-size: 1.6em;
    font-weight: 300;
    color: #e0e0e0;
    margin: 0;
    padding: 20px 25px;
    border-bottom: 1px solid #444;
    text-align: left;
    flex-shrink: 0;
}

.modal-content h2 strong {
    color: #00aaff;
    font-weight: 500;
}

#config-form {
    overflow-y: auto;
    padding: 0 25px;
    flex-grow: 1;
}

.config-section {
    background: #1f1f1f;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
    border: 1px solid #444;
}

.config-section label {
    display: block;
    font-size: 14px;
    color: #ddd;
    font-weight: 500;
    margin-bottom: 8px;
    margin-top: 15px;
}

.modal-actions {
    display: flex;
    gap: 15px;
    padding: 20px 25px;
    border-top: 1px solid #444;
    background-color: #2a2a2a;
    border-radius: 0 0 8px 8px;
    flex-shrink: 0;
}

.modal-cancel-btn {
    background-color: #6c757d;
}

.switch-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #333;
}

/* ========================================================== */
/* ===     ESTILOS PARA MODALES DE ACCIÓN RÁPIDA          === */
/* ========================================================== */

#balance-modal .modal-content,
#password-modal .modal-content {
    background: #1f1f1f;
    border: 1px solid #555;
}

#balance-modal p strong,
#password-modal p strong {
    color: #ffc107;
}

#balance-modal input,
#balance-modal select,
#balance-modal textarea,
#password-modal input {
    background-color: #333 !important;
    border: 1px solid #555 !important;
    color: #e0e0e0 !important;
    padding: 12px !important;
    border-radius: 5px !important;
}

/* ========================================================== */
/* ===        RESPONSIVIDAD GLOBAL (MÓVILES)              === */
/* ========================================================== */

@media (max-width: 768px) {
    body {
        padding: 10px;
        display: block;
    }

    .container {
        padding: 15px;
        width: 100% !important;
        margin: 0 auto;
    }

    .navbar {
        flex-direction: column;
        gap: 15px;
        height: auto;
    }

    .nav-section {
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        gap: 8px;
    }

    .nav-item {
        flex-grow: 1;
        text-align: center;
        background-color: #333;
        padding: 12px;
        font-size: 14px;
    }

    .dropdown-content {
        position: static;
        /* En móviles es mejor que se expanda hacia abajo */
        width: 100%;
        opacity: 1;
        visibility: visible;
        display: none;
        /* Volvemos a display para el flujo de móvil */
    }

    .dropdown:hover .dropdown-content {
        display: block;
    }

    .table-container {
        border: 1px solid #ddd;
    }

    table {
        min-width: 700px;
    }

    .modal-content {
        max-height: 85vh;
    }

    .modal-actions {
        flex-direction: column;
        gap: 10px;
    }
}