/* ─────────────────────────────────────────────
 * Módulo Usuarios
 * ───────────────────────────────────────────── */

.hidden { display: none; }
.pwd-form-gap { margin-bottom: 16px; }

/* ── Cabecera del módulo ── */
.mod-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 12px;
}

.mod-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

/* ── Botones ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    border: none;
    font-size: 0.875rem;
    font-family: var(--font-primary);
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition-speed), opacity var(--transition-speed);
    white-space: nowrap;
}

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

.btn-primary { background-color: var(--color-accent); color: #ffffff; }
.btn-primary:hover:not(:disabled) { background-color: var(--primary-hover); }

.btn-ghost {
    background-color: transparent;
    color: var(--color-text);
    border: 1px solid var(--border-medium);
}
.btn-ghost:hover:not(:disabled) { background-color: var(--background-secondary); }

/* ── Tarjetas de estadísticas (4 columnas) ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #ffffff;
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-left: 4px solid var(--color-accent);
}

.stat-card--green  { border-left-color: var(--success); }
.stat-card--red    { border-left-color: var(--danger); }
.stat-card--yellow { border-left-color: var(--warning); }

.stat-card--ghost {
    min-height: 88px;
    background: var(--background-secondary);
    border-left: none;
    animation: stat-pulse 1.2s ease-in-out infinite;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
}

/* ── Alerta de módulo ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 16px;
}

.alert--success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success);
}

.alert--error {
    background-color: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid var(--danger);
}

/* ── Barra de búsqueda ── */
.table-toolbar {
    margin-bottom: 16px;
}

.search-input {
    padding: 8px 14px;
    border: 1px solid #d1d5db;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    color: var(--color-text);
    background: #ffffff;
    outline: none;
    width: 100%;
    max-width: 360px;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(72, 147, 198, 0.15);
}

/* ── Tabla ── */
.table-wrapper {
    background: #ffffff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    background: var(--background-soft);
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border-light);
    transition: background-color var(--transition-speed);
}

.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background-color: var(--background-secondary); }

.data-table tbody td {
    padding: 12px 16px;
    color: var(--color-text);
    vertical-align: middle;
}

.table-placeholder {
    text-align: center;
    padding: 48px 16px;
    color: #9ca3af;
    font-size: 0.9375rem;
}

.cell-actions { white-space: nowrap; }

/* ── Indicador "tú" y muted ── */
.tag-self {
    font-size: 0.7rem;
    color: #6b7280;
    font-weight: 400;
}

.muted { color: #9ca3af; }

/* ── Botones de fila (iconos) ── */
.btn-row {
    padding: 4px 11px;
    border-radius: 4px;
    border: none;
    font-size: 0.75rem;
    font-family: var(--font-primary);
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition-speed);
    margin-right: 6px;
}

.btn-row:last-child { margin-right: 0; }
.btn-row:disabled   { opacity: 0.4; cursor: not-allowed; }

.btn-row-edit       { background-color: var(--info-bg); color: var(--info-text); }
.btn-row-edit:hover:not(:disabled) { background-color: var(--accent-light); }

.btn-row-pwd        { background-color: var(--surface-blue); color: var(--primary-dark); }
.btn-row-pwd:hover:not(:disabled) { background-color: var(--background-soft); }

.btn-row-inactivar  { background-color: var(--warning-bg); color: var(--warning-text); }
.btn-row-inactivar:hover:not(:disabled) { background-color: var(--warning); color: var(--text-on-primary); }

.btn-row-activar    { background-color: var(--success-bg); color: var(--success-text); }
.btn-row-activar:hover:not(:disabled) { background-color: var(--success); color: var(--text-on-primary); }

/* ── Badges de rol ── */
.rol-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    text-transform: capitalize;
}

.rol-admin         { background: var(--warning-bg); color: var(--warning-text); }
.rol-analista      { background: var(--info-bg); color: var(--info-text); }
.rol-desarrollador { background: var(--success-bg); color: var(--success-text); }
.rol-tester        { background: #f3e8ff; color: #7e22ce; }
.rol-supervisor    { background: #fce7f3; color: #9d174d; }
.rol-consultor     { background: var(--surface-blue); color: var(--primary-dark); }
.rol-default       { background: var(--background-secondary); color: var(--text-secondary); }

/* ── Badges de estado activo ── */
.badge-activo {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--success-bg);
    color: var(--success-text);
    white-space: nowrap;
}

.badge-inactivo {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--background-secondary);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal-overlay.hidden { display: none; }

.modal-box {
    background: #ffffff;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-box--sm { max-width: 420px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    background: var(--background-soft);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #9ca3af;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    border-radius: 4px;
    transition: color var(--transition-speed);
}

.modal-close:hover { color: var(--color-text); }

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

/* ── Formulario ── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-full { grid-column: 1 / -1; }

.form-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.req { color: var(--danger); }

.form-group input,
.form-group select {
    padding: 8px 12px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    color: var(--color-text);
    background: #ffffff;
    outline: none;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(72, 147, 198, 0.15);
}

.form-group--check {
    justify-content: flex-end;
    padding-bottom: 4px;
}

.form-group--check label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
}

.field-error {
    font-size: 0.75rem;
    color: var(--danger);
    min-height: 1em;
}

.pwd-divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 20px 0 16px;
}

/* ── Roles nuevos: editor y lector ── */
.rol-editor { background: #e0f2fe; color: #0369a1; }
.rol-lector { background: #f0fdf4; color: #166534; }

/* ── Botón de fila Accesos ── */
.btn-row-accesos       { background-color: #fef9c3; color: #854d0e; }
.btn-row-accesos:hover:not(:disabled) { background-color: #fef08a; }

/* ── Modal ancho (accesos) ── */
.modal-box--lg { max-width: 800px; }

/* ── Tabs ── */
.tab-nav {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border-light);
    margin-bottom: 24px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 0.875rem;
    font-family: var(--font-primary);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-speed), border-color var(--transition-speed);
    white-space: nowrap;
}

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

.tab-btn--active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
    font-weight: 600;
}

/* ── Tab Roles y permisos ── */
.permisos-toolbar {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 20px;
}

.permisos-rol-wrap {
    flex: 0 0 220px;
}

.permisos-rol-wrap select {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    color: var(--color-text);
    background: #ffffff;
    outline: none;
    width: 100%;
    transition: border-color var(--transition-speed);
}

.permisos-rol-wrap select:focus { border-color: var(--color-accent); }

.perm-placeholder {
    text-align: center;
    padding: 40px 16px;
    color: #9ca3af;
    font-size: 0.9375rem;
}

.perm-error { color: #ef4444; }

.perm-th-check,
.perm-td-check {
    text-align: center;
    width: 80px;
}

.perm-td-mod { font-weight: 500; }

.perm-check {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--color-accent);
}

/* ── Modal Accesos: accordion de clientes ── */
.accesos-desc {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 16px;
    line-height: 1.5;
}

.accesos-loading {
    text-align: center;
    padding: 32px 16px;
    color: #9ca3af;
    font-size: 0.9375rem;
}

.accesos-lista {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.accesos-cliente-item {
    border: 1px solid #e5e7eb;
    border-radius: var(--radius);
    overflow: hidden;
}

.accesos-cliente-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    background: #f9fafb;
    transition: background-color var(--transition-speed);
}

.accesos-cliente-label:hover { background: #f3f4f6; }

.accesos-cliente-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--color-accent);
    flex-shrink: 0;
}

.accesos-cliente-nombre {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
}

.accesos-modulos-wrap {
    padding: 12px 16px 16px 42px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}

.accesos-modulos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px 16px;
}

.accesos-mod-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.8125rem;
    color: var(--color-text);
    cursor: pointer;
}

.accesos-mod-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--color-accent);
    flex-shrink: 0;
}

/* ── Animación skeleton ── */
@keyframes stat-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid  { grid-template-columns: 1fr; }
    .form-full  { grid-column: 1; }
    .modal-box  { max-height: 95vh; }

    .data-table thead th:nth-child(5),
    .data-table tbody td:nth-child(5) { display: none; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }

    .mod-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .btn.btn-primary {
        width: 100%;
        justify-content: center;
    }

    .data-table thead th:nth-child(4),
    .data-table tbody td:nth-child(4) { display: none; }
}

/* ════════════════════════════════════════════
 * Tab — Registro de actividad
 * ════════════════════════════════════════════ */

.act-toolbar {
    margin-bottom: 16px;
}

.act-filtros {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.act-filtros-btns {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding-bottom: 1px;
    margin-top: 8px;
}

.act-filtro-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.act-filtro-group label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--color-text-muted, #6b7280);
    white-space: nowrap;
}

.act-input {
    height: 36px;
    padding: 0 10px;
    border: 1px solid #d1d5db;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    color: var(--color-text);
    background: #fff;
    outline: none;
    min-width: 110px;
    transition: border-color var(--transition-speed);
}

.act-input:focus { border-color: var(--color-accent); }

.act-count {
    font-size: 0.8rem;
    color: var(--color-text-muted, #6b7280);
    margin-bottom: 8px;
    min-height: 1.2em;
}

/* Celdas con ancho fijo para columnas cortas */
.act-td-fecha { white-space: nowrap; font-size: 0.82rem; }
.act-td-ip    { font-size: 0.78rem; color: #6b7280; white-space: nowrap; }
.act-td-desc  { max-width: 260px; font-size: 0.82rem; color: #374151;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Badge módulo */
.act-badge-modulo {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--info-bg);
    color: var(--info-text);
    font-size: 0.76rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Badge dispositivo */
.act-badge-disp {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.76rem;
    font-weight: 600;
    white-space: nowrap;
}

.act-badge-disp--pc {
    background: var(--success-bg);
    color: var(--success-text);
}

.act-badge-disp--movil {
    background: var(--warning-bg);
    color: var(--warning-text);
}

/* Responsive actividad */
@media (max-width: 768px) {
    .act-filtros    { gap: 8px; }
    .act-input      { min-width: 90px; }
    .act-td-ip,
    .act-td-desc    { display: none; }
}

@media (max-width: 480px) {
    .act-filtro-group { width: calc(50% - 4px); }
    .act-input        { width: 100%; min-width: 0; box-sizing: border-box; }
}

/* ── Botón ojo en tabla de actividad ── */
.act-td-ojo { width: 40px; text-align: center; }

.btn-act-ojo {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.55;
    transition: opacity 0.15s;
}

.btn-act-ojo:hover { opacity: 1; }

/* ── Modal detalle de actividad ── */
.modal-act-detalle {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    width: 100%;
    max-width: 480px;
    overflow: hidden;
}

.modal-act-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 14px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
}

.modal-act-titulo {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--color-text);
}

.btn-cerrar-act {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: #6b7280;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s;
}

.btn-cerrar-act:hover { color: var(--color-text); }

.act-detalle-dl {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 0;
    margin: 0;
    padding: 8px 0;
}

.act-detalle-dl dt,
.act-detalle-dl dd {
    padding: 9px 20px;
    margin: 0;
    font-size: 0.875rem;
    border-bottom: 1px solid #f1f5f9;
}

.act-detalle-dl dt {
    font-weight: 600;
    color: #6b7280;
    background: #f8fafc;
}

.act-detalle-dl dd {
    color: var(--color-text);
    word-break: break-word;
}

.act-detalle-dl dt:last-of-type,
.act-detalle-dl dd:last-of-type { border-bottom: none; }

.act-sin-desc {
    color: #9ca3af;
    font-style: italic;
}

/* Badge de compañía en tabla de usuarios */
.empresa-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--background-secondary, #f3f4f6);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-secondary, #6b7280);
    white-space: nowrap;
}
