/* ==========================================================================
   1. VARIABLES & CONFIGURACIÓN BASE
   ========================================================================== */
:root {
    --brand-blue: #1E3A8A;
    --brand-red: #C1121F;
    --brand-grad: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-red) 100%);
    --ink: #111;
    --muted: #6c757d;
    --card-bg: #ffffff;
}

body {
    margin: 0;
    font-family: Open Sans, sans-serif;
    background-color: #f8f9fe !important;
}

/* ==========================================================================
   2. NAVBAR & HEADER
   ========================================================================== */
.navbar-gradient {
    background: linear-gradient(135deg, #1E3A8A 0%, #C1121F 100%) !important;
}

.navbar-gradient .navbar-nav .nav-link {
    color: rgba(255, 255, 255, .9);
}

.navbar-gradient .navbar-nav .nav-link:hover,
.navbar-gradient .navbar-nav .nav-link:focus {
    color: #fff;
}

.navbar-gradient .navbar-brand,
.navbar-gradient .navbar-text {
    color: #fff;
}

.navbar-gradient.border-bottom {
    border-bottom-color: rgba(255, 255, 255, .15) !important;
}

/* Encabezados de Modales */
.grad-header {
    background: var(--brand-grad) !important;
    color: #fff !important;
    border-bottom: 0 !important;
}

.grad-header .modal-title {
    color: #fff !important;
}

/* ==========================================================================
   3. COMPONENTES UI (Botones, Cards, Tablas)
   ========================================================================== */
/* Botones */
.btn-exec {
    background: var(--brand-grad);
    color: #fff !important;
    border: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
    transition: transform .04s ease, box-shadow .12s ease;
}

.btn-exec:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .16);
}

.btn-ghost {
    background: #fff;
    color: var(--brand-blue);
    border: 1px solid rgba(0, 0, 0, .08);
}

/* Cards Generales & Utilidades */
.card.elev-1 {
    box-shadow: 0 4px 12px rgba(0, 0, 0, .06);
}

.badge-neutral {
    background: #eef2ff;
    color: var(--brand-blue);
    font-weight: 600;
}

.meta-note {
    color: var(--muted);
    font-size: .875rem;
}

/* Tablas de Reporte */
.table-report th {
    background: #f5f6f8;
    color: #0f172a;
    border-top: 0;
}

.table-report td, .table-report th {
    padding: 6px 8px;
}

.table-report tbody tr:nth-child(even) {
    background: #fafafa;
}

/* ==========================================================================
   4. PLUGINS (Spinner, Select2, Notyf)
   ========================================================================== */
/* Spinner de Carga */
.app-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2050;
}

.app-spinner.is-active {
    display: flex;
}

.app-spinner__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(17, 24, 39, .55);
}

.app-spinner__body {
    position: relative;
    z-index: 1;
    text-align: center;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
}

.app-spinner__fallback {
    width: 3rem;
    height: 3rem;
    border: .3rem solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: appspin .75s linear infinite;
}

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

/* Select2 Overrides */
.select2-container {
    width: auto !important;
    min-width: 1% !important;
    flex: 1 1 auto !important;
    display: block !important;
}

.select2-container--default .select2-selection--single {
    height: 43px !important;
    padding: 0.375rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    background-color: #fff;
    display: flex;
    align-items: center;
    font-size: 0.9375rem;
    color: #495057;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.select2-container--default .select2-selection--single:hover {
    border-color: #b5bbc2;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #5e72e4;
    box-shadow: 0 0 0 0.15rem rgba(94, 114, 228, 0.25);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    display: flex;
    align-items: center;
    color: #495057;
}

.select2-dropdown {
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
    z-index: 9999;
}

.select2-results__option {
    padding: 8px 12px;
    font-size: 0.9rem;
    color: #495057;
    cursor: pointer;
}

.select2-results__option--highlighted {
    background-color: #5e72e4;
    color: #fff;
}

/* Notyf (Toast Notifications) */
.notyf__toast {
    border-radius: 0.6rem !important;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .12) !important;
}

.notyf__message {
    font-weight: 500;
}

.notyf__icon {
    width: 28px !important;
    height: 28px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
}

.notyf__icon i {
    font-size: 1.25rem !important;
    color: #fff !important;
    display: inline-block !important;
}

.notyf__toast.success .notyf__icon i { color: #fff; }
.notyf__toast.error .notyf__icon i { color: #fff; }
.notyf__toast.warning .notyf__icon i { color: #212529; }
.notyf__toast.info .notyf__icon i { color: #fff; }

/* ==========================================================================
   5. MÓDULO REMISIONES (Estilos Específicos)
   ========================================================================== */
.cliente-contacto-card {
    background-color: #f8fafc;
}

.cliente-contacto-card .badge {
    font-weight: 600;
}

.signature-card {
    border: 1px dashed rgba(30, 58, 138, .3);
}

.logo-inline-preview {
    max-height: 64px;
    width: auto;
}

.signature-preview {
    width: 220px;
    height: 120px;
    border: 1px solid rgba(0, 0, 0, .08);
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: .5rem;
}

.signature-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.signature-canvas-wrapper {
    border: 1px solid rgba(0, 0, 0, .12);
    border-radius: .375rem;
    overflow: hidden;
    background: #fff;
}

.signature-canvas-wrapper canvas {
    width: 100%;
    height: 220px;
    display: block;
    cursor: crosshair;
}

/* ==========================================================================
   6. MODAL MULTI-ITEM (Generador de Combinaciones)
   ========================================================================== */

/* --- Estilo de Tarjetas del Modal (Resaltado/Pop-up) --- */
#multiItemModal .card {
    background-color: #fff;
    /* Borde gris azulado suave para definir el límite */
    border: 1px solid #cbd5e1 !important;
    /* Sombra más pronunciada y difusa para dar efecto de elevación */
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04) !important;
}

/* --- Títulos de Sección --- */
.modal-step-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--brand-blue);
    margin-bottom: 1rem;
    padding: 0.5rem 0.75rem;
    background-color: #f8fafc; /* Fondo sutil en título */
    border-radius: 0.375rem;
    border-left: 4px solid var(--brand-blue); /* Acento lateral */
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Contenedor de Botones (Marcas/Tallas) */
.selection-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* --- Botones "Tiles" (Marcas y Tallas) --- */
.btn-select-tile {
    position: relative;
    cursor: pointer;
    margin: 0;
    padding: 0;
}

.btn-select-tile input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.btn-select-tile .tile-content {
    /* Estilo Base */
    border: 1px solid #cfd8dc;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    background-color: #fff;
    border-radius: 0.375rem;
    color: #495057;
    font-size: 0.9rem;
    font-weight: 500;
    /* Layout */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    min-width: 60px;
    /* Nitidez */
    transition: all 0.15s ease-out;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
}

.btn-select-tile:hover .tile-content {
    border-color: #adb5bd;
    background-color: #f8f9fa;
    transform: translateY(-1px);
}

/* Estado Seleccionado (CHECKED) - Nitidez mejorada con border sólido */
.btn-select-tile input[type="checkbox"]:checked + .tile-content {
    background-color: #e3f2fd;
    border: 2px solid var(--brand-blue);
    /* Compensación de padding para que el borde extra (2px vs 1px) no cambie el tamaño */
    padding: calc(0.5rem - 1px) calc(1rem - 1px);
    color: var(--brand-blue);
    font-weight: 700;
    box-shadow: 0 4px 6px rgba(30, 58, 138, 0.15);
}

/* Variante pequeña (Tallas) */
.btn-select-tile.tile-sm .tile-content {
    padding: 0.35rem 0.75rem;
    min-width: 45px;
}

.btn-select-tile.tile-sm input[type="checkbox"]:checked + .tile-content {
    padding: calc(0.35rem - 1px) calc(0.75rem - 1px);
}

/* --- Matriz de Cantidades (Tabla) --- */
.matrix-card {
    width: 100%;
    /* No poner overflow aquí, ya lo maneja el table-responsive */
}

.matrix-card .card-header {
    background: linear-gradient(to right, #f8fafc, #fff);
    border-bottom: 1px solid #f1f5f9;
}

.matrix-card .card-header .font-weight-bold {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

/* --- SOLUCIÓN DE SCROLL HORIZONTAL --- */

/* 1. Forzar ancho mínimo en inputs para obligar a la tabla a crecer */
.matrix-table input.matrix-input {
    min-width: 80px !important;
    width: 100%;
}

/* 2. Celdas que no se rompen */
.matrix-table th,
.matrix-table td {
    white-space: nowrap;
    vertical-align: middle;
    text-align: center;
    padding: 0.5rem !important;
}

.matrix-table input:focus {
    background-color: #fff;
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

/* 3. Estilo para la barra de desplazamiento (Scrollbar) */
.table-responsive::-webkit-scrollbar {
    height: 8px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-track {
    background-color: rgba(0,0,0,0.05);
}

/* Wrappers y Empty States */
.multi-matrices-wrapper {
    width: 100%;
}

.empty-state-box {
    text-align: center;
    padding: 2rem 1rem;
    background-color: #f8f9fe;
    border: 2px dashed #e2e8f0;
    border-radius: 0.5rem;
    color: #64748b;
}

.empty-state-box i {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    display: block;
    opacity: 0.5;
}

/* Chips de color (Fallback / Legacy) */
.color-chip {
    border: 1px solid #dee2e6;
    display: inline-flex;
    align-items: center;
    margin: 0 0.35rem 0.35rem 0;
    padding: 0.25rem .4rem;
}
.color-chip.active {
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 0.15rem rgba(30, 58, 138, .2);
}
.color-chip__dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .1);
    display: inline-block;
}

/* ==========================================================================
   7. MEDIA QUERIES & RESPONSIVE
   ========================================================================== */

/* Ajustes para Móvil (Pantallas < 768px) */
@media (max-width: 767.98px) {
    /* Forzar que los campos de la cabecera del Modal ocupen todo el ancho */
    #multiItemModal .form-row {
        display: flex;
        flex-direction: column;
    }

    #multiItemModal .form-row > [class*="col-"] {
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin-bottom: 0.75rem;
    }

    .modal-step-title {
        font-size: 0.8rem;
        margin-bottom: 0.75rem;
    }

    #multiItemModal .modal-body {
        padding: 1rem;
    }

    /* Ajustes generales */
    #opciones-productos .btn {
        margin-top: .75rem;
    }
}

/* Ajustes para Móvil Pequeño (Pantallas < 576px) */
@media (max-width: 575.98px) {
    .matrix-table th,
    .matrix-table td {
        font-size: 0.75rem !important;
        padding: .35rem !important;
    }

    .matrix-table input {
        min-width: 60px !important; /* Permitir un poco más pequeño en pantallas muy chicas */
        font-size: 0.8rem !important;
    }

    .card.matrix-card {
        margin-bottom: 1rem;
    }

    .matrix-card .card-header {
        flex-wrap: wrap;
        text-align: center;
        gap: .5rem;
    }
}