/* Tipografía en PÍXELES ABSOLUTOS, a propósito, y no en rem.
 *
 * Bootstrap 3.3.7 trae `html{font-size:10px}` y ningún archivo del sistema lo
 * redefine, así que en esta aplicación 1rem NO son 16px sino 10. Las burbujas
 * decían `font-size:1rem` y se pintaban a 10px, y el renglón de herramientas a
 * 7,8px: por eso el chat se leía tan chico. Con px el widget deja de depender
 * de un root que vale la mitad de lo normal.
 *
 * La base son 15px para el texto de los mensajes, que es el tamaño con el que
 * se lee un chat (WhatsApp Web usa ~14,2px). El resto baja o sube desde ahí
 * guardando la proporción que ya tenía el archivo.
 *
 * Tampoco usar `em`: `.tg-tools code` está dentro de `.tg-tools`, y dos `em`
 * anidados se multiplican.
 */
/* =============================================================================
 * turing.css — Turing IA: burbuja flotante y panel de chat.
 *
 * Vive en todo el sistema (se monta desde plantilla.php), así que todo va
 * prefijado con .tg- para no chocar con AdminLTE ni con las vistas.
 *
 * Usa las variables de tema de app-modern.css, de modo que sigue al tema claro
 * y oscuro sin reglas duplicadas.
 * ========================================================================== */

/* ------------------------------ Burbuja -------------------------------- */
.tg-fab{
    /* --tg-fab-bottom: la pantalla que tiene una barra fija abajo la sube
       por encima de su barra en vez de taparle los botones. Hoy lo hace la
       orden de taller (taller.css, con su pie pegajoso). Crear venta y el
       cierre de caja, que tienen su barra de abajo por debajo de 1200 px, la
       suben con su propia regla (venta.css y cierre.css: bottom 88px) y la
       apartan con su JS cuando cae sobre algo (.cv-fab-apartado y
       .cc-fab-apartado). */
    position:fixed; right:22px; bottom:var(--tg-fab-bottom, 22px); z-index:1040;
    width:58px; height:58px; border:none; border-radius:50%;
    background:linear-gradient(135deg,#4f46e5,#4338ca);
    box-shadow:0 12px 28px -8px rgba(79,70,229,.65), 0 2px 8px rgba(15,23,42,.2);
    cursor:pointer; display:flex; align-items:center; justify-content:center;
    transition:transform .18s ease, box-shadow .18s ease;
}
.tg-fab:hover{ transform:translateY(-2px) scale(1.04); box-shadow:0 18px 36px -10px rgba(79,70,229,.75); }
.tg-fab:focus-visible{ outline:3px solid #fff; outline-offset:3px; }
.tg-fab svg{ width:30px; height:30px; }
.tg-fab .tg-pc{ fill:#fff; }
.tg-fab .tg-w{ fill:none; stroke:rgba(255,255,255,.75); stroke-width:9; stroke-linecap:round; }

/* Punto de "sin leer" / novedad. */
.tg-fab .tg-dot{
    position:absolute; top:4px; right:4px; width:12px; height:12px;
    background:#22c55e; border:2px solid #fff; border-radius:50%; display:none;
}
.tg-fab.has-news .tg-dot{ display:block; }

/* Al abrir el panel la burbuja se esconde en móvil (el panel ocupa todo). */
.tg-open .tg-fab{ transform:scale(.9); opacity:.6; }

/* ------------------------------- Panel --------------------------------- */
.tg-panel{
    position:fixed; right:22px; bottom:92px; z-index:1041;
    width:430px; max-width:calc(100vw - 32px);
    height:min(620px, calc(100vh - 130px));
    display:none; flex-direction:column; overflow:hidden;
    background:var(--surface,#fff); color:var(--text,#0f172a);
    border:1px solid var(--border,#e3e8f2); border-radius:16px;
    box-shadow:0 30px 70px -24px rgba(15,23,42,.5), 0 4px 14px -6px rgba(15,23,42,.25);
}
.tg-panel.is-open{ display:flex; animation:tg-in .18s ease-out; }
@keyframes tg-in{ from{ opacity:0; transform:translateY(10px) scale(.98); } to{ opacity:1; transform:none; } }

.tg-head{
    display:flex; align-items:center; gap:10px; padding:12px 14px;
    background:linear-gradient(135deg,#4f46e5,#4338ca); color:#fff; flex:0 0 auto;
}
.tg-head svg{ width:26px; height:26px; flex:0 0 auto; }
.tg-head .tg-pc{ fill:#fff; }
.tg-head .tg-w{ fill:none; stroke:rgba(255,255,255,.7); stroke-width:9; stroke-linecap:round; }
.tg-title{ font-weight:700; font-size:16px; line-height:1.1; }
.tg-sub{ font-size:12px; opacity:.85; line-height:1.1; }
.tg-head-actions{ margin-left:auto; display:flex; gap:2px; }
.tg-icon-btn{
    background:transparent; border:none; color:#fff; opacity:.85;
    width:30px; height:30px; border-radius:8px; cursor:pointer; font-size:16px; line-height:1;
}
.tg-icon-btn:hover{ opacity:1; background:rgba(255,255,255,.16); }
.tg-icon-btn:focus-visible{ outline:2px solid #fff; outline-offset:1px; }

/* ------------------------------ Mensajes ------------------------------- */
.tg-body{ flex:1 1 auto; overflow-y:auto; padding:14px; background:var(--bg-2,#f6f8fc); }
.tg-msg{ display:flex; margin-bottom:10px; }
.tg-msg.me{ justify-content:flex-end; }
.tg-bubble{
    max-width:84%; padding:9px 12px; border-radius:13px;
    font-size:15px; line-height:1.45; white-space:pre-wrap; overflow-wrap:anywhere;
}
.tg-msg.bot .tg-bubble{
    background:var(--surface,#fff); border:1px solid var(--border,#e3e8f2);
    color:var(--text,#0f172a); border-bottom-left-radius:4px;
}
.tg-msg.me .tg-bubble{
    background:#4f46e5; color:#fff; border-bottom-right-radius:4px;
}
.tg-msg.err .tg-bubble{
    background:rgba(220,38,38,.10); border:1px solid rgba(220,38,38,.35); color:var(--danger,#dc2626);
}

/* Tarjeta de confirmación de una acción preparada. */
.tg-action{
    margin-top:10px; padding:11px 12px; border-radius:11px;
    background:var(--surface-2,#f4f6fb); border:1px solid var(--border,#e3e8f2);
}
.tg-action-t{ font-weight:700; font-size:14.5px; margin-bottom:7px; }
.tg-action-r{
    display:flex; justify-content:space-between; gap:10px;
    font-size:13.5px; padding:4px 0; color:var(--text-muted,#475569);
}
.tg-action-r b{ color:var(--text,#0f172a); font-weight:600; text-align:right; }
.tg-action-l{ border-top:1px dashed var(--border,#e3e8f2); }
.tg-action-tot{
    border-top:1px solid var(--border,#e3e8f2); margin-top:5px; padding-top:7px;
    font-size:15px;
}
.tg-action-tot b{ font-size:17px; font-weight:800; }
.tg-action-w{ font-size:12.5px; color:#b45309; padding:2px 0 0 4px; }
:root[data-theme="dark"] .tg-action-w{ color:#fbbf24; }
.tg-action-n{
    font-size:12.5px; color:var(--text-muted,#475569); margin-top:8px;
    line-height:1.45; border-left:2px solid var(--border,#e3e8f2); padding-left:8px;
}
.tg-action-b{
    display:block; width:100%; margin-top:10px; padding:9px;
    border:none; border-radius:9px; background:#4f46e5; color:#fff;
    font-weight:700; font-size:14px; cursor:pointer;
}
.tg-action-b:hover{ background:#4338ca; }
.tg-action-b:focus-visible{ outline:2px solid #4f46e5; outline-offset:2px; }

/* Archivos generados (PDF, Excel, gráfico). */
.tg-files{ display:flex; flex-direction:column; gap:6px; margin-top:9px; }
.tg-file{
    display:inline-block; padding:8px 11px; border-radius:9px;
    background:rgba(79,70,229,.09); border:1px solid rgba(79,70,229,.32);
    color:#4f46e5 !important; font-size:14px; font-weight:600;
    text-decoration:none; overflow-wrap:anywhere;
}
.tg-file:hover{ background:rgba(79,70,229,.16); text-decoration:none; }
.tg-file:focus-visible{ outline:2px solid #4f46e5; outline-offset:2px; }
:root[data-theme="dark"] .tg-file{ color:#a5b4fc !important; border-color:rgba(129,140,248,.42); }

/* Qué consultó, para que se pueda auditar de dónde salió el dato. */
.tg-tools{ margin-top:7px; font-size:12px; color:var(--text-muted,#475569); }
.tg-tools code{ background:var(--surface-2,#f4f6fb); padding:1px 5px; border-radius:5px; font-size:12px; }

/* Puntos de "escribiendo". */
.tg-typing{ display:flex; gap:4px; padding:11px 13px; }
.tg-typing i{
    width:7px; height:7px; border-radius:50%; background:var(--text-soft,#94a3b8);
    animation:tg-blink 1.2s infinite;
}
.tg-typing i:nth-child(2){ animation-delay:.18s; }
.tg-typing i:nth-child(3){ animation-delay:.36s; }
@keyframes tg-blink{ 0%,60%,100%{ opacity:.25; } 30%{ opacity:1; } }

/* Sugerencias de arranque. */
.tg-chips{ display:flex; flex-wrap:wrap; gap:6px; margin-top:10px; }
.tg-chip{
    background:var(--surface,#fff); border:1px solid var(--border,#e3e8f2);
    color:var(--text,#0f172a); border-radius:999px; padding:6px 11px;
    font-size:13px; cursor:pointer; text-align:left;
}
.tg-chip:hover{ border-color:var(--primary); color:var(--link); }

/* ------------------------------ Redacción ------------------------------ */
.tg-foot{
    flex:0 0 auto; display:flex; gap:8px; padding:10px;
    border-top:1px solid var(--border,#e3e8f2); background:var(--surface,#fff);
}
.tg-input{
    flex:1; resize:none; max-height:150px; min-height:46px;
    border:1px solid var(--border,#e3e8f2); border-radius:10px;
    padding:11px 13px; font-size:15px; font-family:inherit;
    background:var(--surface-2,#f4f6fb); color:var(--text,#0f172a);
}
.tg-input:focus{ outline:none; border-color:#4f46e5; box-shadow:0 0 0 3px rgba(79,70,229,.18); }
/* En el celular y en táctil, 16 px: con menos, el iPhone agranda la página al
   tocar el campo y no la devuelve (el viewport ya no trae maximum-scale, que
   lo impedía). El panel va en el <body>, fuera de .content-wrapper y de los
   modales, así que la regla de los campos de app-modern.css no lo alcanza. */
@media (max-width:767px), (pointer:coarse){
    .tg-input{ font-size:16px; }
}
.tg-send{
    flex:0 0 auto; width:46px; height:46px; border:none; border-radius:10px;
    background:#4f46e5; color:#fff; cursor:pointer; font-size:16px;
}
.tg-send:hover{ background:#4338ca; }
.tg-send:disabled{ opacity:.45; cursor:not-allowed; }
.tg-send:focus-visible{ outline:2px solid #4f46e5; outline-offset:2px; }

/* El micrófono. Mismo tamaño y misma esquina que el botón de enviar —son
   hermanos en la misma fila— pero apagado hasta que se usa: el que manda es
   enviar, este es el atajo. Lo monta turingVoz.js y SOLO si el navegador puede
   escuchar, así que en Safari o Firefox esta regla no pinta nada. */
.tg-mic{
    flex:0 0 auto; width:46px; height:46px; border-radius:10px; cursor:pointer;
    border:1px solid var(--border,#e3e8f2);
    background:var(--surface-2,#f4f6fb); color:var(--text,#0f172a);
    font-size:18px; line-height:1;
}
.tg-mic:hover{ border-color:#4f46e5; }
.tg-mic:disabled{ opacity:.45; cursor:not-allowed; }
.tg-mic:focus-visible{ outline:2px solid #4f46e5; outline-offset:2px; }

/* ESCUCHANDO. El cajero tiene que saber, sin pensarlo, si el micrófono está
   abierto: hablarle a un botón apagado y que no pase nada es la forma más
   rápida de que nadie lo vuelva a usar. Rojo y latiendo, que es lo que todo el
   mundo ya sabe leer. */
.tg-mic.is-listening{
    background:#dc2626; border-color:#dc2626; color:#fff;
    animation:tg-latido 1.1s ease-in-out infinite;
}
@keyframes tg-latido{
    0%,100%{ box-shadow:0 0 0 0 rgba(220,38,38,.55); }
    70%    { box-shadow:0 0 0 9px rgba(220,38,38,0); }
}
/* Quien pidió menos movimiento no tiene por qué aguantar un latido. */
@media (prefers-reduced-motion: reduce){
    .tg-mic.is-listening{ animation:none; }
}

/* Tableta (táctil, hasta 1199 px): también de 48 px. Con el menú plegado a
   los íconos el contenido llega hasta el borde derecho, donde está la burbuja. */
@media (max-width:1199px) and (pointer:coarse){
    .tg-fab{ right:14px; width:48px; height:48px; }
    .tg-fab svg{ width:26px; height:26px; }
}

/* ------------------------------ Responsive -----------------------------
 * En móvil el panel pasa a pantalla completa: a 390px de ancho fijo quedaba
 * cortado y el teclado virtual tapaba el campo de escritura. */
@media (max-width:600px){
    .tg-panel{
        right:0; left:0; bottom:0; top:0;
        width:100%; max-width:100%; height:100%;
        border-radius:0; border:none;
    }
    /* Más chica en el celular (era de 58 px y tapaba lo que quedaba en la
       esquina de abajo a la derecha: KPIs, encabezados, el último botón). */
    .tg-fab{ right:12px; bottom:var(--tg-fab-bottom, 14px); width:48px; height:48px; }
    .tg-fab svg{ width:26px; height:26px; }
    .tg-open .tg-fab{ display:none; }
    .tg-bubble{ max-width:90%; }
    /* Lo último de cada pantalla se puede subir por encima de la burbuja. */
    .content-wrapper{ padding-bottom:72px; }
}

/* Respeta a quien pidió menos animación. */
@media (prefers-reduced-motion:reduce){
    .tg-panel.is-open{ animation:none; }
    .tg-fab{ transition:none; }
    .tg-typing i{ animation:none; opacity:.6; }
}

/* Botón de una acción ya aprobada: queda deshabilitado y en verde para que se
   note que se ejecutó y no se intente de nuevo. */
.tg-action-b.tg-action-ok,
.tg-action-b.tg-action-ok:hover{ background:#15803d; cursor:default; }
.tg-action-b:disabled{ opacity:.75; cursor:not-allowed; }
