/* --- VARIABLES GLOBALES Y RESET --- */
:root {
    --primary: #2c3e50;
    --secondary: #18bc9c;
    --secondary-hover: #149a80;
    --bg: #f8f9fa;
    --dark: #343a40;
    --danger: #e74c3c;
    --warning: #f39c12;
    --gray-light: #f1f2f6;
    --border: #ddd;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    margin: 0;
    display: flex;
}

/* --- MENÚ LATERAL (SIDEBAR) --- */
.sidebar {
    width: 260px;
    background: var(--primary);
    height: 100vh;
    color: white;
    position: fixed;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    font-weight: bold;
    font-size: 18px;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-menu li a {
    display: block;
    padding: 15px 20px;
    color: #ecf0f1;
    text-decoration: none;
    border-left: 4px solid transparent;
    transition: all 0.2s;
}

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

.sidebar-toggle,
.sidebar-backdrop {
    display: none;
}

/* --- CONTENEDOR PRINCIPAL E INTERFAZ --- */
.main-content {
    margin-left: 260px;
    padding: 40px;
    width: calc(100% - 260px);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 15px;
}

.container-flex {
    display: flex;
    gap: 30px;
    margin-top: 20px;
}

.box {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.form-box {
    width: 35%;
    height: fit-content;
}

/* --- FORMULARIOS --- */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--primary);
}

.form-group .usuario-activo-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
}

.form-group .usuario-activo-input {
    width: auto;
    margin: 0;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--secondary);
    outline: none;
}

/* --- BOTONES Y COMPONENTES --- */
.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    transition: background 0.2s, transform 0.1s;
    font-size: 14px;
}

.btn:active {
    transform: scale(0.98);
}

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

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

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

.btn-warning:hover {
    background: #d38409;
}

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

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

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

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

.btn-logout {
    background: var(--danger);
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    text-decoration: none;
    font-weight: bold;
}

/* --- TABLAS --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th,
td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--gray-light);
    color: var(--primary);
}

.table-search {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin: 0 0 16px auto;
    color: var(--dark);
    font-size: 14px;
    font-weight: 600;
}

.table-search input {
    width: min(100%, 280px);
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
    font: inherit;
}

.table-search input:focus {
    border-color: var(--secondary);
    outline: none;
}

.visibility-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    color: var(--dark);
    font-size: 14px;
    font-weight: 600;
}

.visibility-filter select {
    min-width: 150px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
    font: inherit;
}

.acciones-gap {
    display: flex;
    gap: 5px;
}

.badge {
    background: #e2e8f0;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    color: var(--primary);
}

.status-protected {
    color: #aaa;
    font-size: 12px;
}

code {
    background: var(--gray-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    color: #c7254e;
}

/* --- ALERTAS --- */
.alert {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 14px;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border-left: 4px solid #28a745;
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid var(--danger);
}

/* --- MATRIZ ROL / PERMISOS --- */
.tabs {
    display: flex;
    gap: 10px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 25px;
    margin-top: 15px;
}

.tab-link {
    padding: 10px 20px;
    background: #e2e8f0;
    color: #555;
    text-decoration: none;
    border-radius: 5px;
    font-weight: bold;
    transition: background 0.2s;
}

.tab-link.active {
    background: var(--primary);
    color: white;
}

.grid-permisos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.modulo-permisos {
    margin-bottom: 28px;
}

.modulo-permisos h2 {
    margin: 0 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 18px;
}

.permiso-card {
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 6px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #fafafa;
    cursor: pointer;
    transition: all 0.2s;
}

.permiso-card:hover {
    border-color: var(--secondary);
    background: #f0fdfa;
}

.permiso-card input {
    transform: scale(1.3);
    margin-top: 3px;
    cursor: pointer;
}

.permiso-card label {
    cursor: pointer;
    font-size: 14px;
}

.btn-save {
    background: var(--secondary);
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(24, 188, 156, 0.2);
    transition: background 0.2s;
}

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

/* --- DASHBOARD CARDS --- */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.card {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card h3 {
    margin: 0;
    color: #7f8c8d;
    font-size: 14px;
    text-transform: uppercase;
}

.card .number {
    font-size: 32px;
    font-weight: bold;
    color: var(--dark);
    margin-top: 5px;
}

.card .icon {
    font-size: 40px;
    color: var(--secondary);
    opacity: 0.7;
}

.crud-actions {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.crud-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.btn-crud {
    display: block;
    text-align: center;
    padding: 15px;
    border: 0;
    background: #e2e8f0;
    color: var(--dark);
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s;
}

button.btn-crud {
    width: 100%;
    cursor: pointer;
}

.btn-crud:hover {
    background: var(--secondary);
    color: white;
    transform: translateY(-2px);
}

.module-card {
    display: flex;
    min-height: 150px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    text-align: left;
}

.module-card-icon {
    font-size: 30px;
    line-height: 1;
}

.module-card span:last-child {
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
}

.printer-test-status {
    white-space: pre-line;
}

/* --- PANTALLA DE LOGIN --- */
.login-body {
    background: #eef2f3;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.login-container {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    box-sizing: border-box;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header h2 {
    margin: 0;
    color: var(--primary);
}

.login-header p {
    color: #7f8c8d;
    margin: 5px 0 0 0;
    font-size: 14px;
}

/* --- LOGIN TÁCTIL CON TECLADO NUMÉRICO (PIN) --- */
.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-top: 15px;
}

.user-touch-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 10px;
    touch-action: manipulation;
}

.selected-user-title {
    text-align: center;
    font-weight: bold;
    margin-bottom: 10px;
}

.pin-dots {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
}

.pin-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid currentColor;
}

.pin-dot.filled {
    background-color: currentColor;
}

.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.num-btn {
    padding: 18px 0;
    font-size: 22px;
    touch-action: manipulation;
}

.btn-cambiar-usuario {
    width: 100%;
    touch-action: manipulation;
}

/* --- ALINEACIÓN PERFECTA DE MULTI-ROLES EN FORMULARIOS --- */
.roles-checkbox-container {
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 6px;
    max-height: 160px;
    overflow-y: auto;
    background: #fafafa;
}

.rol-checkbox-row {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    /* Alinea verticalmente al centro el checkbox y el texto */
    gap: 10px;
    /* Separación horizontal uniforme */
    cursor: pointer;
}

/* Forzar que los inputs tipo checkbox no tengan márgenes raros que los muevan */
.rol-checkbox-row input[type="checkbox"] {
    width: auto !important;
    /* Evita que herede el width: 100% de los inputs comunes */
    margin: 0 !important;
    /* Elimina cualquier margen residual del navegador */
    transform: scale(1.2);
    /* Hace el checkbox ligeramente más grande y usable */
    cursor: pointer;
}

.rol-checkbox-row label {
    font-weight: normal !important;
    cursor: pointer;
    margin: 0 !important;
    font-size: 14px;
    line-height: 1;
    /* Sincroniza la altura de línea con el tamaño del elemento */
}

@media (max-width: 900px) {

    body {
        display: block;
    }

    .sidebar-toggle {
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 102;
        display: flex;
        width: 48px;
        height: 48px;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        padding: 12px;
        border: 0;
        border-radius: 4px;
        background: var(--primary);
        cursor: pointer;
    }

    .sidebar-toggle span {
        display: block;
        width: 24px;
        height: 2px;
        background: white;
    }

    .sidebar {
        width: min(280px, 85vw);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 99;
        border: 0;
        background: rgba(0, 0, 0, 0.45);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .main-content {
        width: 100%;
        margin-left: 0;
        padding: 76px 20px 24px;
    }

    body:has(#tpvApp) .sidebar-toggle,
    body:has(#tpvApp) .sidebar-backdrop {
        display: none;
    }

    .cards-grid,
    .crud-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {

    .cards-grid,
    .crud-grid {
        grid-template-columns: 1fr;
    }

    .table-search {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
    }

    .table-search input {
        width: 100%;
    }
}