/* Estilos generales de la aplicación admin */

/* Navbar */
.navbar-brand {
    font-weight: bold;
}

/* Tablas */
.table th {
    background-color: #f8f9fa;
    border-top: none;
}

.table {
    font-size: 14px;
}

/* Header fijo dentro del contenedor scrolleable de la tabla */
.table-responsive.table-responsive-sticky-header {
    max-height: calc(100vh - 220px);
    overflow: auto;
}

.table-responsive.table-responsive-sticky-header .table.table-sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background-color: #f8f9fa;
    box-shadow: inset 0 -1px 0 #dee2e6;
}

/* Tabla de usuarios: congelar primeras 4 columnas */
.users-table {
    --users-col-1-width: 72px;
    --users-col-2-width: 140px;
    --users-col-3-width: 220px;
    --users-col-4-width: 180px;
    table-layout: fixed;
}

/*
 * Anchos de las 4 columnas sticky: solo <col> (table-layout: fixed).
 * Si width/max-width van también en th/td, el contenido (p. ej. nombre largo) puede imponer un mínimo distinto por columna.
 */
.users-table th:nth-child(1),
.users-table td:nth-child(1),
.users-table th:nth-child(2),
.users-table td:nth-child(2),
.users-table th:nth-child(3),
.users-table td:nth-child(3),
.users-table th:nth-child(4),
.users-table td:nth-child(4) {
    min-width: 0;
    box-sizing: border-box;
}

/* Nombre: el <strong> es inline y puede impedir compresión; forzar bloque con ellipsis */
.users-table td:nth-child(3) strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.users-table th,
.users-table td {
    position: relative;
    min-width: 0;
    box-sizing: border-box;
}

/* Filas más compactas que el .table por defecto de Bootstrap */
.table.users-table > thead > tr > th {
    padding: 0.3rem 0.5rem;
}

/* Menos padding inferior que superior (el “aire” debajo del select/botones molestaba) */
.table.users-table > tbody > tr > td {
    padding: 0.2rem 0.5rem 0.05rem;
    vertical-align: middle;
}

/*
 * Alto de fila: lo marcan sobre todo los botones de la 1ª columna y los form-select.
 * Unos ~5–6px menos que el btn-sm / form-select-sm por defecto.
 */
.table.users-table td:nth-child(1) .btn.btn-sm {
    padding: 0.1rem 0.32rem;
    line-height: 1;
}

.table.users-table td:nth-child(1) .btn.btn-sm i {
    font-size: 0.85em;
    vertical-align: middle;
}

.table.users-table .form-select.form-select-sm {
    padding-top: 0.16rem;
    padding-bottom: 0.12rem;
    min-height: 1.6rem;
    line-height: 1.15;
    font-size: 0.8125rem;
    margin-bottom: 0;
}

/* Columna acciones: no recortar iconos */
.users-table th:nth-child(1),
.users-table td:nth-child(1) {
    overflow: visible;
    white-space: nowrap;
}

.users-table th:nth-child(n+2),
.users-table td:nth-child(n+2) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Código: fila con botones puede ser ancha; permitir compresión */
.users-table td:nth-child(2) .editable-code {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.users-table td:nth-child(2) .editable-code .code-display {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
}

.users-table td:nth-child(2) .editable-code .code-input {
    min-width: 0;
    flex: 1 1 auto;
}

.users-table td:nth-child(2) .editable-code .save-btn,
.users-table td:nth-child(2) .editable-code .cancel-btn {
    flex: 0 0 auto;
}

/* Vendedor: mismo layout inline que Código */
.users-table td:nth-child(8) .editable-code {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.users-table td:nth-child(8) .editable-code .code-display {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
}

.users-table td:nth-child(8) .editable-code .code-input {
    min-width: 0;
    flex: 1 1 auto;
}

.users-table td:nth-child(8) .editable-code .save-btn,
.users-table td:nth-child(8) .editable-code .cancel-btn {
    flex: 0 0 auto;
}
.users-table td:nth-child(4) .text-muted {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Permitir achicar columnas sticky aunque el contenido sea largo */
.users-table th:nth-child(-n+4),
.users-table td:nth-child(-n+4) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.users-table th:nth-child(-n+4),
.users-table td:nth-child(-n+4) {
    position: sticky;
    background-clip: padding-box;
}

.users-table th:nth-child(1),
.users-table td:nth-child(1) { left: 0; }

.users-table th:nth-child(2),
.users-table td:nth-child(2) { left: var(--users-col-1-width); }

.users-table th:nth-child(3),
.users-table td:nth-child(3) { left: calc(var(--users-col-1-width) + var(--users-col-2-width)); }

.users-table th:nth-child(4),
.users-table td:nth-child(4) { left: calc(var(--users-col-1-width) + var(--users-col-2-width) + var(--users-col-3-width)); }

.users-table thead th:nth-child(-n+4) {
    z-index: 999;
    background-color: #f8f9fa;
}

/* Encabezados: deben poder achicarse igual que las celdas (el texto se recorta). */
.users-table thead th {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.users-table tbody td:nth-child(-n+4) {
    z-index: 999;
    background-color: #fff;
}

.users-table thead th:nth-child(n+5) {
    z-index: 3;
}

.users-table tbody td:nth-child(n+5) {
    z-index: 1;
}

.users-table thead th:nth-child(4),
.users-table tbody td:nth-child(4) {
    box-shadow: 1px 0 0 #dee2e6;
}

.users-table tbody tr:hover td:nth-child(-n+4) {
    background-color: #f8f9fa;
}

/*
 * Filas por prefijo de código: rgba solo en columnas que hacen scroll.
 * Sticky (1–4): color opaco equivalente sobre #fff, si no se ve el texto de detrás al desplazar.
 */
.table.users-table tbody tr.user-row-code-cavalieri > td:nth-child(n+5) {
    background-color: rgba(26, 95, 63, 0.22);
}

.table.users-table tbody tr.user-row-code-cavalieri > td:nth-child(-n+4) {
    background-color: #cddbd5;
}

.table.users-table tbody tr.user-row-code-cavalieri:hover > td:nth-child(n+5) {
    background-color: rgba(26, 95, 63, 0.34);
}

.table.users-table tbody tr.user-row-code-cavalieri:hover > td:nth-child(-n+4) {
    background-color: #b1c8bd;
}

.table.users-table tbody tr.user-row-code-cli > td:nth-child(n+5) {
    background-color: rgba(8, 66, 152, 0.18);
}

.table.users-table tbody tr.user-row-code-cli > td:nth-child(-n+4) {
    background-color: #d3dcec;
}

.table.users-table tbody tr.user-row-code-cli:hover > td:nth-child(n+5) {
    background-color: rgba(8, 66, 152, 0.28);
}

.table.users-table tbody tr.user-row-code-cli:hover > td:nth-child(-n+4) {
    background-color: #bacae2;
}

.table.users-table tbody tr.user-row-code-app > td:nth-child(n+5) {
    background-color: rgba(108, 117, 125, 0.07);
}

.table.users-table tbody tr.user-row-code-app > td:nth-child(-n+4) {
    background-color: #f5f5f6;
}

.table.users-table tbody tr.user-row-code-app:hover > td:nth-child(n+5) {
    background-color: rgba(108, 117, 125, 0.12);
}

.table.users-table tbody tr.user-row-code-app:hover > td:nth-child(-n+4) {
    background-color: #edeeef;
}

.table tbody tr {
    cursor: pointer;
    transition: background-color 0.2s;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

.status-badge {
    font-size: 0.8em;
}

/* Código editable */
.editable-code {
    cursor: pointer;
    padding: 5px 10px;
    border: 1px solid transparent;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.editable-code:hover {
    background-color: #f8f9fa;
    border-color: #dee2e6;
}

.editable-code.editing {
    background-color: #fff;
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.code-input {
    border: none;
    background: transparent;
    width: 100%;
    font-size: inherit;
    font-weight: inherit;
}

.code-input:focus {
    outline: none;
}

.save-btn, .cancel-btn {
    display: none;
    margin-left: 5px;
}

.save-btn.show, .cancel-btn.show {
    display: inline-block;
}

/* Tabla responsive con scroll horizontal */
.table-responsive {
    overflow-x: scroll;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: auto;
    scrollbar-color: #6c757d #e9ecef;
    padding-bottom: 2px;
}

/* Estilos para hacer la barra de scroll siempre visible en Chrome/Safari/Edge */
.table-responsive::-webkit-scrollbar {
    height: 14px;
    -webkit-appearance: none;
}

.table-responsive::-webkit-scrollbar-track {
    background: #e9ecef;
    border-radius: 7px;
    border: 1px solid #dee2e6;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #6c757d;
    border-radius: 7px;
    border: 2px solid #e9ecef;
    min-width: 20px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #5a6268;
}

.table-responsive::-webkit-scrollbar-thumb:active {
    background: #495057;
}

/* Indicador visual de que hay más contenido a la derecha */
.table-responsive-wrapper {
    position: relative;
}

.table-responsive-wrapper::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 12px;
    width: 30px;
    background: linear-gradient(to right, transparent, rgba(248, 249, 250, 0.9));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 1;
}

.table-responsive-wrapper.scrollable::after {
    opacity: 1;
}

.table-responsive table {
    min-width: 100%;
    width: max-content;
}

/* Tabla de usuarios: NO usar max-content (rompe table-layout:fixed + <col> y vuelve a imponer mínimos por texto). */
.table-responsive table.users-table {
    width: auto;
    min-width: 0;
    max-width: none;
}

/* No aplicar a .users-table: el resizer y <col> controlan anchos (nth-child(3) era min 200px y trababa “Nombre”). */
.table:not(.users-table) th,
.table:not(.users-table) td {
    white-space: nowrap;
    min-width: 120px;
}

.table:not(.users-table) th:nth-child(1),
.table:not(.users-table) td:nth-child(1) {
    min-width: 120px;
}

.table:not(.users-table) th:nth-child(2),
.table:not(.users-table) td:nth-child(2) {
    min-width: 150px;
}

.table:not(.users-table) th:nth-child(3),
.table:not(.users-table) td:nth-child(3) {
    min-width: 200px;
}

.table:not(.users-table) th:nth-child(9),
.table:not(.users-table) td:nth-child(9) {
    min-width: 220px;
}

.table:not(.users-table) th:nth-child(11),
.table:not(.users-table) td:nth-child(11) {
    min-width: 180px;
}

.table:not(.users-table) th:nth-child(12),
.table:not(.users-table) td:nth-child(12) {
    min-width: 150px;
}

.table:not(.users-table) th:nth-child(13),
.table:not(.users-table) td:nth-child(13) {
    min-width: 200px;
}

.table:not(.users-table) th:nth-child(14),
.table:not(.users-table) td:nth-child(14) {
    min-width: 250px;
}

/* Estilos específicos para pedidos */
.purchase-row {
    cursor: pointer;
}

.modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

.item-row {
    border-bottom: 1px solid #dee2e6;
    padding: 10px 0;
}

.item-row:last-child {
    border-bottom: none;
}

/* Botón de carrito en tabla de usuarios */
.btn-cart-icon {
    color: #495057;
    border: 1px solid #495057;
    background-color: #fff;
}

.btn-cart-icon:hover {
    color: #fff;
    background-color: #495057;
    border-color: #495057;
}

.btn-cart-icon .badge {
    font-size: 0.7em;
    padding: 0.2em 0.4em;
}

/* Botón eliminar usuario (tachito rojo, mismo estilo que carrito) */
.btn-delete-icon {
    color: #dc3545;
    border: 1px solid #dc3545;
    background-color: #fff;
}

.btn-delete-icon i,
.btn-delete-icon .fas {
    color: inherit;
}

.btn-delete-icon:hover {
    color: #fff;
    background-color: #dc3545;
    border-color: #dc3545;
}

.btn-delete-icon:hover i,
.btn-delete-icon:hover .fas {
    color: inherit;
}

/* Botón primario Cavalieri (Iniciar sesión, Agregar al carrito, etc.) */
.btn-cavalieri-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.5;
    color: #fff;
    text-align: center;
    font-family: inherit;
    border: none;
    border-radius: 9999px;
    background-color: #166534;
    transition: background-color 0.2s;
}

.btn-cavalieri-primary:hover {
    color: #fff;
    background-color: #14532d;
}

.btn-cavalieri-primary:focus {
    outline: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 0 0 4px rgba(22, 101, 52, 0.5);
}

.btn-cavalieri-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Cards con tabla admin: ancho completo del viewport en pantallas anchas */
@media (min-width: 1200px) {
    .admin-fullwidth-table-card {
        width: calc(100vw - 48px);
        max-width: calc(100vw - 48px);
        margin-left: calc(50% - 50vw + 24px);
        margin-right: calc(50% - 50vw + 24px);
    }
}

