/* ════════════════════════════════════════════════════════════════
   Market POS — componentes del sistema de diseño.
   Todo sale de tokens.css: aquí NO debe aparecer ningún hex suelto.
   Los nombres de clase heredados (.input-form, .modal, .modal-caja,
   .autocomplete-*) se conservan y se re-apuntan a tokens para que las
   vistas existentes sigan funcionando y hereden el tema oscuro gratis.
   ════════════════════════════════════════════════════════════════ */

/* ── base ───────────────────────────────────────────────────────── */
body, body * { font-family: var(--font); }
code, pre, .mono { font-family: ui-monospace, Consolas, monospace; }

body {
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--a-200); color: var(--a-700); }

:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ── tipografía ─────────────────────────────────────────────────── */
.titulo-vista {
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -.015em;
    color: var(--color-text);
}
.kicker {
    font-size: 10.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--n-500);
}
.ayuda { font-size: 11.5px; color: var(--n-500); }
.meta  { font-size: 11px;   color: var(--n-500); }
.numero-kpi {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -.02em;
    color: var(--color-text);
}

/* ── botones ────────────────────────────────────────────────────── */
.btn, .btn-pag, .btn-mini, .btn-icono {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-align: left;
    transition: background-color .12s, border-color .12s, color .12s;
    white-space: nowrap;
}
.btn:disabled, .btn-pag:disabled, .btn-mini:disabled, .btn-icono:disabled {
    opacity: .45;
    cursor: not-allowed;
}

/* primario — UNO por zona */
.btn {
    background: var(--color-accent);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    padding: 10px 18px;
}
.btn:hover:not(:disabled) { background: var(--color-accent-hover); }

/* secundario */
.btn-pag {
    background: var(--color-surface);
    border-color: var(--n-300);
    color: var(--n-700);
    font-size: 13px;
    font-weight: 600;
    padding: 9px 16px;
}
.btn-pag:hover:not(:disabled) { border-color: var(--n-500); background: var(--n-100); }

/* mini — acciones dentro de filas de tabla */
.btn-mini {
    background: var(--color-surface);
    border-color: var(--n-300);
    color: var(--n-700);
    font-size: 11.5px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 8px;
    gap: var(--space-1);
}
.btn-mini:hover:not(:disabled) { border-color: var(--n-500); background: var(--n-100); }

/* solo icono */
.btn-icono {
    width: 34px;
    height: 34px;
    justify-content: center;
    background: var(--color-surface);
    border-color: var(--n-300);
    color: var(--n-600);
    padding: 0;
    gap: 0;
}
.btn-icono:hover:not(:disabled) { border-color: var(--n-500); color: var(--color-text); }

/* destructivo — SIEMPRE fantasma, nunca relleno rojo */
.btn-rojo, .btn.btn-rojo, .btn-mini.btn-rojo {
    background: transparent;
    border-color: var(--rojo);
    color: var(--rojo);
}
.btn-rojo:hover:not(:disabled), .btn.btn-rojo:hover:not(:disabled) {
    background: var(--rojo);
    color: var(--color-surface);
}

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

/* ── campos ─────────────────────────────────────────────────────── */
.campo-form { display: flex; flex-direction: column; gap: 5px; }
.campo-form > label, .etiqueta-campo {
    font-size: 10.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--n-600);
}
.campo-form .ayuda { margin-top: 2px; }

.input-form,
.campo-form input:not([type="checkbox"]):not([type="radio"]),
.campo-form select,
.campo-form textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--n-300);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    color: var(--color-text);
    background: var(--color-surface);
    outline: none;
    transition: border-color .12s, box-shadow .12s;
}
.input-form:focus,
.campo-form input:focus,
.campo-form select:focus,
.campo-form textarea:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--a-200);
    outline: none;
}
.input-form::placeholder { color: var(--n-500); }
.input-error { border-color: var(--rojo) !important; }

/* búsqueda: sin borde, se aclara al focus */
.input-busqueda {
    background: var(--n-200);
    border-color: transparent;
}
.input-busqueda:focus { background: var(--color-surface); }

/* ── paneles ────────────────────────────────────────────────────── */
.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
}
.panel-aviso       { border-left: 3px solid var(--color-accent); }
.panel-recomendado { border-top: 3px solid var(--color-accent); }

.panel-cabecera {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}
.panel-cabecera .caja-icono {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: var(--radius-sm);
    background: var(--a-100);
    color: var(--a-600);
    display: flex;
    align-items: center;
    justify-content: center;
}
.panel-cabecera h3, .panel-titulo {
    font-size: 13.5px;
    font-weight: 800;
    color: var(--color-text);
}

/* ── KPIs: celdas iguales dentro de UN contenedor ───────────────── */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.stats > * {
    padding: var(--space-4);
    border-right: 1px solid var(--color-divider);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}
.stats > *:last-child { border-right: 0; }
.stats .caja-icono {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--a-100);
    color: var(--a-600);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-1);
}

/* ── chips y badges ─────────────────────────────────────────────── */
.cv-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--n-300);
    background: var(--color-surface);
    color: var(--n-700);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.cv-chip:hover { background: var(--a-100); }
.cv-chip.activo {
    background: var(--n-900);
    border-color: var(--n-900);
    color: var(--color-bg);
}

.chip-estado {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 11.5px;
    font-weight: 600;
}
.chip-estado::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}
.chip-ok        { background: var(--a-100);   color: var(--a-600); }
.chip-pendiente { background: var(--amb-100); color: var(--amb-700); }
.chip-error     { background: color-mix(in srgb, var(--rojo) 12%, transparent); color: var(--rojo); }
.chip-neutro    { background: var(--n-200);   color: var(--n-600); }

.cv-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px; /* separa el icono del texto cuando el badge lleva uno */
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 9.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--n-200);
    color: var(--n-600);
}
.badge-ok        { background: var(--a-100);   color: var(--a-600); }
.badge-pendiente { background: var(--amb-100); color: var(--amb-700); }
.badge-error     { background: color-mix(in srgb, var(--rojo) 12%, transparent); color: var(--rojo); }

/* ── pestañas de configuración ──────────────────────────────────── */
.tabs-config {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--color-divider);
    border-radius: var(--radius);
    background: var(--color-surface);
}
.tab-config {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 8px 14px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--n-600);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .12s, color .12s;
}
.tab-config:hover { background: var(--n-100); color: var(--color-text); }
.tab-config.activo {
    background: var(--a-100);
    color: var(--a-600);
    font-weight: 800;
}

@media (max-width: 860px) {
    /* Se deslizan en horizontal en vez de repartirse el ancho: con cuatro
       pestañas ("Facturas y boletas", "Guías de remisión"…) a flex:1 el texto
       se parte en tres líneas y no se lee ninguna. */
    .tabs-config {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .tabs-config::-webkit-scrollbar { display: none; }
    .tab-config { flex: 0 0 auto; justify-content: center; padding: 8px 12px; white-space: nowrap; }
}

/* ── chips-filtro (semáforo de documentos emitidos) ─────────────────
   Cuentan y filtran a la vez: el número es la señal ("3 PENDIENTE") y el
   clic acota la tabla a ese estado. El color de fondo lo pone la clase de
   utilidad que trae cada chip; acá va solo la forma.

   OJO: no reutilizar `.chip-estado` — ese es la etiqueta con puntito de
   Caja, Configuración y el POS, y pisarlo rompe media aplicación. */
.chip-filtro {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--n-600);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .12s, box-shadow .12s;
}
.chip-filtro b { font-weight: 800; }
.chip-filtro:hover { border-color: var(--color-divider); }
/* El seleccionado se marca con el borde, no con el relleno: el relleno ya
   está ocupado codificando el estado. */
.chip-filtro.activo {
    border-color: var(--a-600);
    box-shadow: 0 0 0 1px var(--a-600) inset;
}

/* ── avatar ─────────────────────────────────────────────────────── */
.avatar {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
}
.avatar-entidad { border-radius: 10px; }

/* ── estado vacío ───────────────────────────────────────────────── */
.vacio {
    text-align: center;
    color: var(--n-500);
    font-size: 13px;
    padding: var(--space-8) var(--space-4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
}
.vacio .caja-icono {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    background: var(--n-200);
    color: var(--n-500);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── avisos ─────────────────────────────────────────────────────── */
.aviso        { font-size: 12.5px; font-weight: 600; color: var(--n-600); }
.aviso.ok     { color: var(--a-600); }
.aviso.error  { color: var(--rojo); }

/* ── skeleton ───────────────────────────────────────────────────── */
.skeleton {
    background: var(--n-200);
    border-radius: var(--radius-sm);
    animation: pulso 1.4s ease-in-out infinite;
}
@keyframes pulso { 0%, 100% { opacity: .6 } 50% { opacity: 1 } }

/* ── modal (nombres heredados) ──────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(17, 24, 39, .5);
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}
.modal.modal-visible { opacity: 1; pointer-events: auto; }
.modal-caja {
    background: var(--color-surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-md);
    transform: translateY(14px) scale(.98);
    transition: transform .15s ease;
    /* Ancla de la X, que va absoluta en la esquina. */
    position: relative;
}

/* Cerrar el modal: la ÚNICA salida junto a Cancelar. El clic en el fondo se
   quitó porque cerraba formularios a medio llenar de un manotazo. */
.modal-x {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--n-500);
    cursor: pointer;
    z-index: 2;
    transition: background-color .12s, color .12s;
}
.modal-x:hover { background: var(--n-200); color: var(--color-text); }
/* CLAVE: sin transform cuando está visible — un ancestro con transform
   rompe las coordenadas del desplegable de Select2 */
.modal-visible .modal-caja { transform: none; }
.modal-caja-ancha { max-width: 52rem; }
.modal-caja h2 { font-size: 15px; font-weight: 800; color: var(--color-text); }

/* ── toast ──────────────────────────────────────────────────────── */
.toast-pos {
    position: fixed;
    right: var(--space-6);
    bottom: var(--space-6);
    z-index: 80;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--n-900);
    color: var(--color-bg);
    font-size: 12.5px;
    font-weight: 600;
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    animation: toast-entra .18s ease;
}
@keyframes toast-entra { from { opacity: 0; transform: translateY(8px) } }

/* ── dropdown ───────────────────────────────────────────────────── */
.dropdown {
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: var(--space-1);
    min-width: 180px;
}
.dropdown a, .dropdown button {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
    color: var(--n-700);
    border-radius: 8px;
    background: none;
    border: 0;
    cursor: pointer;
    text-align: left;
}
.dropdown a:hover, .dropdown button:hover { background: var(--n-100); }
.dropdown .destructivo { color: var(--rojo); }

/* ── autocompletar (heredado) ───────────────────────────────────── */
.autocomplete-lista {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 40;
    margin-top: 4px;
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 300px;
    overflow-y: auto;
}
.autocomplete-item {
    padding: 9px 13px;
    font-size: 13px;
    color: var(--color-text);
    cursor: pointer;
    border-bottom: 1px solid var(--n-200);
}
.autocomplete-item:last-child { border-bottom: 0; }
.autocomplete-item:hover { background: var(--a-100); }

/* ── shell: sidebar ─────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    inset-block: 0;
    left: 0;
    z-index: 40;
    width: var(--sidebar-ancho);
    background: var(--color-surface);
    border-right: 1px solid var(--color-divider);
    display: flex;
    flex-direction: column;
    transition: transform .2s ease, width .2s ease;
}
.sidebar-marca {
    height: var(--topbar-alto);
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--color-divider);
}
.sidebar-marca .caja-icono {
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: 9px;
    background: var(--color-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-marca b { font-size: 13.5px; font-weight: 800; color: var(--color-text); display: block; line-height: 1.2; }
.sidebar-marca span { font-size: 10.5px; color: var(--n-500); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3) var(--space-2);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.sidebar-grupo > p { padding: 0 var(--space-3); margin-bottom: 5px; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 8px var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--n-700);
    transition: background-color .12s, color .12s;
}
.sidebar-nav a:hover { background: var(--n-100); color: var(--color-text); }
.sidebar-nav a.activo {
    background: var(--a-100);
    color: var(--a-600);
    font-weight: 800;
}
.sidebar-nav a .icono { flex: none; }

.sidebar-pie {
    flex: none;
    border-top: 1px solid var(--color-divider);
    padding: var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.sidebar-pie .datos { min-width: 0; flex: 1; }
.sidebar-pie .datos b {
    display: block;
    font-size: 12.5px;
    font-weight: 800;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-pie .btn-icono:hover { color: var(--rojo); border-color: var(--rojo); }

/* comprimido: solo iconos. El pie NO se oculta, se apila. */
body.sidebar-comprimido .sidebar { width: var(--sidebar-rail); }
body.sidebar-comprimido .sidebar-marca { padding: 0; justify-content: center; }
body.sidebar-comprimido .sidebar-marca .texto,
body.sidebar-comprimido .sidebar-grupo > p,
body.sidebar-comprimido .sidebar-nav a span,
body.sidebar-comprimido .sidebar-pie .datos { display: none; }
body.sidebar-comprimido .sidebar-nav a { justify-content: center; padding: 9px 0; }
body.sidebar-comprimido .sidebar-pie { flex-direction: column; gap: var(--space-2); padding: var(--space-2); }
body.sidebar-comprimido .contenido-shell { padding-left: var(--sidebar-rail); }

.contenido-shell {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding-left: var(--sidebar-ancho);
    transition: padding-left .2s ease;
}

/* ── shell: topbar ──────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-alto);
    flex: none;
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-divider);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-6);
}
.topbar-titulo { font-size: 15px; font-weight: 800; color: var(--color-text); }
.topbar-lema {
    font-size: 12px;
    color: var(--n-500);
    padding-left: var(--space-3);
    border-left: 1px solid var(--color-divider);
}

.main-shell {
    flex: 1;
    padding: var(--space-6);
    max-width: 1600px;
    width: 100%;
    transition: opacity .12s;
}

.pie-shell {
    flex: none;
    padding: var(--space-3) var(--space-6);
    border-top: 1px solid var(--color-divider);
    background: var(--color-surface);
    font-size: 11px;
    color: var(--n-500);
    display: flex;
    justify-content: space-between;
}

/* ── tabla propia ───────────────────────────────────────────────── */
.dt-tabla-scroll { overflow-x: auto; min-width: 0; }
.dt-tabla-scroll table { min-width: 560px; }

table.dataTable { border-collapse: collapse !important; width: 100% !important; }
table.dataTable thead th {
    background: var(--n-100);
    color: var(--n-500);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 10px 13px;
    border-bottom: 1px solid var(--color-divider);
    text-align: left;
}
table.dataTable tbody td {
    background: var(--color-surface) !important;
    padding: 10px 13px;
    font-size: 13px;
    color: var(--n-700);
    border-bottom: 1px solid var(--n-200);
}
table.dataTable tbody tr:hover td { background: var(--n-100) !important; }
table.dataTable tbody tr.selected td { background: var(--a-100) !important; }

div.dt-container .dt-search input,
div.dt-container .dt-length select {
    border: 1px solid var(--n-300);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--color-surface);
    color: var(--color-text);
    outline: none;
}
div.dt-container .dt-search input:focus { border-color: var(--color-accent); }
div.dt-container .dt-info,
div.dt-container .dt-length,
div.dt-container .dt-search { font-size: 12px; color: var(--n-600); padding: 8px 0; }
div.dt-container .dt-paging .dt-paging-button {
    border-radius: 8px;
    padding: 5px 11px;
    margin-left: 2px;
    font-size: 12px;
    color: var(--n-700) !important;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
}
div.dt-container .dt-paging .dt-paging-button.current {
    background: var(--color-accent) !important;
    color: #fff !important;
    border-color: var(--color-accent);
}
div.dt-container .dt-paging .dt-paging-button:hover:not(.disabled):not(.current) {
    background: var(--a-100) !important;
    color: var(--a-600) !important;
}
div.dt-container .dt-processing {
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    color: var(--a-600);
}

/* ── Select2 alineado a .input-form ─────────────────────────────── */
.select2-container--default .select2-selection--single {
    height: 38px;
    border: 1px solid var(--n-300);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    display: flex;
    align-items: center;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px;
    font-size: 13.5px;
    color: var(--color-text);
    padding-left: 12px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 36px; }
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--a-200);
}
.select2-dropdown {
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    overflow: hidden;
}
.select2-container--default .select2-results__option { color: var(--color-text); font-size: 13.5px; }
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background: var(--color-accent);
    color: #fff;
}
.select2-search--dropdown .select2-search__field {
    border: 1px solid var(--n-300) !important;
    border-radius: 8px;
    padding: 6px 10px;
    background: var(--color-surface);
    color: var(--color-text);
    outline: none;
}

/* Select2 MÚLTIPLE (roles y sedes del formulario de usuario). Su hoja propia
   fija background:white sin declarar color, así que en tema oscuro el texto
   —que sí hereda var(--color-text), claro— quedaba invisible sobre blanco. */
.select2-container--default .select2-selection--multiple {
    background: var(--color-surface);
    border: 1px solid var(--n-300);
    border-radius: var(--radius-sm);
    min-height: 38px;
}
.select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--a-200);
}
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: var(--a-100);
    border: 1px solid var(--a-200);
    color: var(--a-600);
    border-radius: 6px;
    font-size: 12.5px;
    padding: 1px 8px;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: var(--a-600);
    margin-right: 5px;
}
.select2-container--default .select2-selection--multiple .select2-search__field {
    color: var(--color-text);
    background: transparent;
}
/* La opción ya elegida en el desplegable: su gris fijo #ddd deja el texto claro ilegible. */
.select2-container--default .select2-results__option[aria-selected="true"],
.select2-container--default .select2-results__option--selected {
    background: var(--n-200);
    color: var(--color-text);
}

/* SweetAlert por ENCIMA del modal; Select2 por encima de todo */
.swal2-container { z-index: 60 !important; }
.select2-container--open .select2-dropdown { z-index: 70; }
.swal2-popup {
    background: var(--color-surface) !important;
    color: var(--color-text) !important;
    border-radius: var(--radius) !important;
}
.swal2-title, .swal2-html-container { color: var(--color-text) !important; }

/* ── detalles ───────────────────────────────────────────────────── */
.icono { display: inline-block; vertical-align: middle; flex: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--n-400); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--n-500); }

/* ── responsive ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    body.sidebar-abierto .sidebar { transform: none; }
    .contenido-shell { padding-left: 0; }
    body.sidebar-comprimido .contenido-shell { padding-left: 0; }
}

@media (max-width: 860px) {
    .topbar { padding: 0 var(--space-4); }
    .topbar-lema { display: none; }
    .main-shell { padding: var(--space-4); }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stats > *:nth-child(2n) { border-right: 0; }
    .modal { padding: var(--space-4) var(--space-3); }
    .toast-pos { right: var(--space-3); left: var(--space-3); bottom: var(--space-3); }
}

/* ── formularios y filtros en teléfono ───────────────────────────
   Dos reglas que arreglan de una vez lo que se repetía en veinte vistas.

   1) Los formularios de los modales se apilan. Casi todos usan rejillas de
      2 o 3 columnas pensadas para escritorio; a 390 px eso deja campos de
      110 px donde no entra ni la etiqueta. Las que ya declaran `sm:` no se
      ven afectadas: ese prefijo solo actúa de 640 px para arriba.

   2) Las barras de filtros de las cabeceras (fechas, buscadores, selects)
      dejan de tener ancho fijo y se reparten la fila. Un `!w-72` en un
      teléfono se sale del margen y arrastra toda la página en horizontal. */
@media (max-width: 640px) {
    .modal-caja [class*="grid-cols-"] { grid-template-columns: 1fr !important; }
    /* Y con la rejilla en una sola columna hay que soltar los `col-span-N`:
       un `span 2` sobre una única columna hace que el navegador CREE la
       segunda, y el modal termina más ancho que la pantalla. */
    .modal-caja [class*="col-span-"] { grid-column: auto !important; }

    .barra-filtros {
        width: 100%;
        flex-wrap: wrap;
    }
    /* `!important` porque los anchos de Tailwind vienen con `!w-…`. */
    .barra-filtros > *,
    .barra-filtros > * > .input-form {
        width: 100% !important;
        min-width: 0;
        flex: 1 1 140px;
    }
}

/* ── POS en teléfono ─────────────────────────────────────────────
   La barra de cobro fija abajo. En escritorio no existe: allí el botón
   COBRAR (F2) ya está a la vista en su columna. */
.pos-barra-movil { display: none; }

@media (max-width: 860px) {
    .pos-barra-movil {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 40;
        padding: 10px var(--space-4);
        /* El área segura del iPhone: sin esto el botón queda debajo de la
           barra de gestos y no se puede pulsar. */
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        background: var(--color-surface);
        border-top: 1px solid var(--color-divider);
        box-shadow: 0 -6px 20px rgb(0 0 0 / .08);
    }
    /* Que la barra no tape la última tarjeta al llegar abajo del todo. */
    body:has(.pos-barra-movil) .main-shell { padding-bottom: 92px; }

    /* El ticket deja de ser tabla y pasa a tarjetas: con `min-width: 560px`
       en un teléfono había que leerlo arrastrando de lado. */
    .tabla-ticket,
    .tabla-ticket thead,
    .tabla-ticket tbody,
    .tabla-ticket tr,
    .tabla-ticket td { display: block; width: auto; min-width: 0; }

    .dt-tabla-scroll:has(.tabla-ticket) { overflow-x: visible; }
    .tabla-ticket { min-width: 0 !important; }
    .tabla-ticket thead { display: none; }

    .tabla-ticket tbody tr {
        border: 1px solid var(--color-divider);
        border-radius: var(--radius-sm);
        padding: var(--space-3);
        margin-bottom: var(--space-2);
    }
    /* El nombre del producto manda: ocupa su propia línea, sin rótulo. */
    .tabla-ticket tbody td:first-child {
        font-weight: 700;
        font-size: 14px;
        padding-bottom: var(--space-2);
        margin-bottom: var(--space-2);
        border-bottom: 1px solid var(--color-divider);
    }
    .tabla-ticket tbody td:not(:first-child) {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        padding: 3px 0;
        text-align: left !important;
    }
    .tabla-ticket tbody td:not(:first-child)::before {
        content: attr(data-etiqueta);
        font-size: 10.5px;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--n-500);
    }
    /* Las celdas sin rótulo (el botón de quitar) no dibujan la fila vacía. */
    .tabla-ticket tbody td:not([data-etiqueta]):empty { display: none; }
    .tabla-ticket tbody td input { max-width: 130px; }
    /* El selector de presentación (caja/saco) vive bajo el nombre del producto:
       ahí manda el ancho de la tarjeta, no el de los campos numéricos. Con el
       tope de 130 px quedaba cortado justo donde dice de cuántas unidades es. */
    .tabla-ticket tbody td:first-child select { max-width: 100%; font-weight: 400; }
    /* La fila de "ticket vacío" sigue siendo un mensaje centrado. */
    .tabla-ticket tbody tr#pos-ticket-vacio { border: 0; padding: 0; }
    .tabla-ticket tbody tr#pos-ticket-vacio td { text-align: center; border: 0; font-weight: 400; }
}

/* ── impresión ──────────────────────────────────────────────────
   El papel siempre es blanco: si el usuario tiene el tema oscuro, imprimir
   la constancia de abono saldría en blanco sobre blanco. Se fuerzan los
   tokens claros y se quita el armazón de la aplicación.                   */
@media print {
    html, html[data-tema="oscuro"] {
        --color-bg: #fff;
        --color-surface: #fff;
        --color-text: #111827;
        --color-divider: #e5e9ef;
        --a-100: #f0fdfa;
        --a-200: #ccfbf1;
        --a-600: #0f766e;
        --n-100: #f8fafc;
        --n-200: #eef2f6;
        --n-300: #dde3ea;
        --n-400: #b8c0cb;
        --n-500: #6b7684;
        --n-600: #4b5563;
        --n-700: #374151;
        --rojo: #b91c1c;
        color-scheme: light;
    }

    .sidebar,
    #sidebar-fondo,
    .topbar,
    .pie-shell,
    .btn,
    .btn-pag,
    .btn-icono,
    .btn-mini,
    .modal,
    .toast-pos { display: none !important; }

    .contenido-shell { padding-left: 0 !important; }
    .main-shell { padding: 0 !important; max-width: none !important; }

    .panel {
        border: 1px solid var(--color-divider) !important;
        box-shadow: none !important;
        break-inside: avoid;
    }

    body { background: #fff !important; }
}
