/* ═══════════════════════════════════════════════════════════════════
   DISEÑO GENERAL: menú lateral, barra de celular, tarjetas, botones y widget de IA
   (se carga después de tema.css, que sigue manejando el modo oscuro)
   ═══════════════════════════════════════════════════════════════════ */
:root {
    --sb-w: 248px;
    --sb-w-chico: 70px;
    --sb-bg: #101c2e;
    --sb-bg2: #16263d;
    --sb-texto: #c9d4e3;
    --acento: #3498db;
    --acento-ia: #8e6bf0;
    --radio-card: 16px;
    --sombra-suave: 0 1px 2px rgba(16,28,46,.05), 0 6px 18px rgba(16,28,46,.06);
}
html { scroll-behavior: smooth; }
body { background: #f1f4f9; -webkit-font-smoothing: antialiased; letter-spacing: .005em; }

/* ── Estructura: el contenido deja lugar al menú ── */
.app-main { min-height: 100vh; min-height: 100dvh; }
.app-main-login { margin-left: 0 !important; }
.sidebar ~ .app-main, .sidebar ~ .app-footer { }
@media (min-width: 992px) {
    .app-main, .app-footer { margin-left: var(--sb-w); transition: margin-left .22s ease; }
    .app-main-login { margin-left: 0; }
    .sb-colapsado .app-main, .sb-colapsado .app-footer { margin-left: var(--sb-w-chico); }
    .app-contenido { padding-top: .35rem; }
    #badge-sync { left: calc(var(--sb-w) + 12px) !important; }
    .sb-colapsado #badge-sync { left: calc(var(--sb-w-chico) + 12px) !important; }
}
body:not(:has(#sidebar)) .app-main, body:not(:has(#sidebar)) .app-footer { margin-left: 0; }

/* ── Menú lateral ── */
.sidebar {
    background: linear-gradient(180deg, var(--sb-bg) 0%, #0c1626 100%);
    color: var(--sb-texto);
    display: flex; flex-direction: column;
    width: var(--sb-w);
    border-right: 1px solid rgba(255,255,255,.06);
    box-shadow: 4px 0 24px rgba(0,0,0,.12);
    z-index: 1045;
}
@media (min-width: 992px) {
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transition: width .22s ease; overflow: hidden; }
    .sb-colapsado .sidebar { width: var(--sb-w-chico); }
}
@media (max-width: 991.98px) {
    .sidebar { --bs-offcanvas-width: 292px; --bs-offcanvas-bg: var(--sb-bg); --bs-offcanvas-color: var(--sb-texto); width: 292px; max-width: 86vw; }
}
.sb-head { display: flex; align-items: center; gap: .5rem; padding: 14px 12px 10px 14px; min-height: 72px; flex-shrink: 0; }
.sb-brand { display: flex; align-items: center; gap: 11px; color: #fff; text-decoration: none; min-width: 0; flex: 1; }
.sb-logo { width: 44px; height: 44px; border-radius: 12px; background: rgba(255,255,255,.07); display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; color: var(--acento); font-size: 1.5rem; }
.sb-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sb-brand-txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.sb-brand-txt strong { font-size: 1rem; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-brand-txt small { font-size: .62rem; font-weight: 700; color: var(--acento); letter-spacing: .18em; }
.sb-collapse { width: 30px; height: 30px; border-radius: 8px; border: 0; background: rgba(255,255,255,.07); color: var(--sb-texto); align-items: center; justify-content: center; flex-shrink: 0; transition: .2s; }
.sb-collapse:hover { background: rgba(255,255,255,.16); color: #fff; }
.sb-colapsado .sb-collapse i { transform: rotate(180deg); }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 10px 12px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.sb-group { font-size: .64rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: #6f84a1; padding: 16px 10px 5px; white-space: nowrap; }
.sb-link, .sb-vender {
    display: flex; align-items: center; gap: 12px; color: var(--sb-texto); text-decoration: none;
    padding: 9px 12px; border-radius: 11px; font-weight: 550; font-size: .93rem; margin-bottom: 2px; white-space: nowrap;
    transition: background .15s, color .15s, transform .1s; position: relative;
}
.sb-link i, .sb-vender i { font-size: 1.12rem; width: 22px; text-align: center; flex-shrink: 0; }
.sb-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sb-link.activo { background: linear-gradient(90deg, rgba(52,152,219,.3), rgba(52,152,219,.1)); color: #fff; box-shadow: inset 3px 0 0 var(--acento); }
.sb-link.sb-ia i { color: #b9a2ff; }
.sb-link.sb-ia.activo { background: linear-gradient(90deg, rgba(142,107,240,.32), rgba(142,107,240,.08)); box-shadow: inset 3px 0 0 var(--acento-ia); }
.sb-vender { background: linear-gradient(135deg, #2ecc71, #27ae60); color: #fff; justify-content: flex-start; font-weight: 800; letter-spacing: .05em; margin: 6px 0 4px; padding: 12px; box-shadow: 0 6px 16px rgba(39,174,96,.35); }
.sb-vender:hover { color: #fff; transform: translateY(-1px); filter: brightness(1.05); }
.sb-vender.activo { outline: 2px solid rgba(255,255,255,.55); outline-offset: 1px; }

.sb-foot { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 14px; border-top: 1px solid rgba(255,255,255,.07); background: rgba(0,0,0,.14); flex-shrink: 0; }
.sb-icon { width: 38px; height: 38px; border-radius: 10px; border: 0; background: rgba(255,255,255,.07); color: var(--sb-texto); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; transition: .15s; font-size: 1.05rem; }
.sb-icon:hover { background: rgba(255,255,255,.16); color: #fff; }
.sb-icon.sb-salir:hover { background: #dc3545; color: #fff; }
.btn-tema-d i { color: #f1c40f; }

/* menú achicado: solo íconos */
@media (min-width: 992px) {
    .sb-colapsado .sb-label { display: none !important; }
    .sb-colapsado .sb-link, .sb-colapsado .sb-vender { justify-content: center; padding: 11px 0; }
    .sb-colapsado .sb-head { flex-direction: column; padding: 14px 0 8px; gap: 8px; }
    .sb-colapsado .sb-brand { flex: 0; }
    .sb-colapsado .sb-nav { padding: 4px 8px; }
    .sb-colapsado .sb-foot { flex-direction: column; align-items: center; }
    .sb-colapsado .sb-group { display: none; }
    .sb-colapsado .sb-nav .sb-link + .sb-link { margin-top: 2px; }
}
.sidebar .dropdown-menu { font-size: .9rem; border-radius: 12px; border: 1px solid rgba(255,255,255,.1); }

/* ── Barra superior de celular ── */
.topbar { position: sticky; top: 0; z-index: 1030; display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); background: var(--sb-bg); color: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.2); }
.topbar-btn { width: 42px; height: 42px; border-radius: 11px; border: 0; background: rgba(255,255,255,.09); color: #fff; font-size: 1.5rem; display: inline-flex; align-items: center; justify-content: center; }
.topbar-btn.btn-tema-m { font-size: 1.1rem; color: #f1c40f; }
.topbar-brand { flex: 1; display: flex; align-items: center; gap: 9px; color: #fff; text-decoration: none; min-width: 0; }
.topbar-logo { width: 36px; height: 36px; border-radius: 9px; background: rgba(255,255,255,.08); display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; color: var(--acento); }
.topbar-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.topbar-nombre { font-weight: 800; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 991.98px) { .app-contenido { margin-top: .6rem !important; } }

/* ── Tarjetas, botones, tablas: un poco más modernos ── */
.card { border-radius: var(--radio-card); box-shadow: var(--sombra-suave); border: 1px solid rgba(16,28,46,.05); }
.card-header { border-top-left-radius: var(--radio-card) !important; border-top-right-radius: var(--radio-card) !important; }
.btn { transition: transform .1s, box-shadow .15s, background-color .15s, border-color .15s; }
.btn:active { transform: scale(.98); }
.btn:focus-visible, .sb-link:focus-visible, .sb-icon:focus-visible, a:focus-visible { outline: 3px solid rgba(52,152,219,.55); outline-offset: 2px; }
.btn-primary, .btn-celeste { box-shadow: 0 3px 10px rgba(52,152,219,.28); }
.table > thead > tr > th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; }
.table-hover > tbody > tr:hover > * { --bs-table-hover-bg: rgba(52,152,219,.07); }
h2, h3 { letter-spacing: -.01em; }
.form-control, .form-select { border-color: #d5dce8; }
.alert { border-radius: 12px; }
@media (max-width: 575.98px) { .btn { min-height: 40px; } .form-control, .form-select { font-size: 16px; } }
@media print { .sidebar, .topbar, .ia-fab, .ia-panel, #badge-sync { display: none !important; } .app-main, .app-footer { margin-left: 0 !important; } }

/* modo oscuro */
[data-bs-theme="dark"] body { background: #0e1522; }
[data-bs-theme="dark"] .sidebar { background: linear-gradient(180deg, #0b1220 0%, #080e18 100%); }
[data-bs-theme="dark"] .topbar { background: #0b1220; }
[data-bs-theme="dark"] .card { border-color: rgba(255,255,255,.06); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select { border-color: #2f3d52; }

/* ═══════════════ IA: botón flotante + panel de chat ═══════════════ */
.ia-fab {
    position: fixed; right: calc(18px + env(safe-area-inset-right, 0px)); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 1040;
    width: 58px; height: 58px; border-radius: 50%; border: 0; color: #fff; font-size: 1.55rem;
    background: linear-gradient(135deg, #8e6bf0, #3498db); box-shadow: 0 8px 24px rgba(88,80,220,.45);
    display: flex; align-items: center; justify-content: center; transition: transform .15s;
}
.ia-fab:hover { transform: scale(1.07); }
.ia-fab .ia-fab-punto { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #2ecc71; border: 2px solid #fff; display: none; }
/* en el punto de venta el botón sale de arriba de los botones de cobro */
@media (min-width: 768px) { body:has(.pos-row) .ia-fab { bottom: auto; top: 18px; right: auto; left: calc(var(--sb-w-chico) + 340px); width: 44px; height: 44px; font-size: 1.2rem; }
                            body:has(.pos-row) .ia-panel { bottom: 18px; } }
@media (max-width: 767.98px) { body:has(.pos-row) .ia-fab { bottom: calc(128px + env(safe-area-inset-bottom, 0px)); width: 46px; height: 46px; font-size: 1.2rem; } }
.ia-panel {
    position: fixed; right: calc(18px + env(safe-area-inset-right, 0px)); bottom: calc(88px + env(safe-area-inset-bottom, 0px)); z-index: 1041;
    width: 400px; max-width: calc(100vw - 24px); height: min(620px, calc(100vh - 120px)); height: min(620px, calc(100dvh - 120px));
    display: none; flex-direction: column; background: #fff; color: #1d2733; border-radius: 20px; overflow: hidden;
    box-shadow: 0 24px 60px rgba(10,20,40,.35); border: 1px solid rgba(0,0,0,.06);
}
.ia-panel.abierto { display: flex; animation: iaSube .22s ease; }
@keyframes iaSube { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@media (max-width: 575.98px) {
    .ia-panel { right: 0; left: 0; bottom: 0; top: 0; width: 100%; max-width: none; height: 100%; border-radius: 0; }
}
.ia-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; color: #fff; background: linear-gradient(135deg, #5b45c9, #2f7fd0); flex-shrink: 0; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.ia-head .ia-titulo { flex: 1; line-height: 1.15; }
.ia-head .ia-titulo strong { display: block; font-size: 1rem; }
.ia-head .ia-titulo small { opacity: .8; font-size: .72rem; }
.ia-head button, .ia-head a { width: 32px; height: 32px; border-radius: 9px; border: 0; background: rgba(255,255,255,.18); color: #fff; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ia-head button:hover, .ia-head a:hover { background: rgba(255,255,255,.3); color: #fff; }

.ia-chat { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.ia-mensajes { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #f6f8fc; scroll-behavior: smooth; }
.ia-msg { max-width: 92%; padding: 9px 13px; border-radius: 16px; font-size: .92rem; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; }
.ia-msg.user { align-self: flex-end; background: #3d7fe0; color: #fff; border-bottom-right-radius: 5px; white-space: pre-wrap; }
.ia-msg.bot { align-self: flex-start; background: #fff; color: #1d2733; border: 1px solid #e3e8f1; border-bottom-left-radius: 5px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.ia-msg.error { align-self: flex-start; background: #fdecee; color: #a4222f; border: 1px solid #f5c2c7; }
.ia-msg.bot p { margin: 0 0 .5rem; } .ia-msg.bot p:last-child { margin-bottom: 0; }
.ia-msg.bot ul, .ia-msg.bot ol { margin: .2rem 0 .5rem; padding-left: 1.2rem; }
.ia-msg.bot table { width: 100%; font-size: .82rem; border-collapse: collapse; margin: .3rem 0; display: block; overflow-x: auto; }
.ia-msg.bot th, .ia-msg.bot td { border: 1px solid #e3e8f1; padding: 3px 7px; white-space: nowrap; }
.ia-msg.bot th { background: #f0f3f9; }
.ia-msg.bot h4, .ia-msg.bot h5 { font-size: .95rem; margin: .4rem 0 .2rem; font-weight: 700; }
.ia-escribiendo { display: inline-flex; gap: 4px; padding: 4px 2px; }
.ia-escribiendo span { width: 7px; height: 7px; border-radius: 50%; background: #9aa7bd; animation: iaPunto 1.2s infinite ease-in-out; }
.ia-escribiendo span:nth-child(2) { animation-delay: .15s; } .ia-escribiendo span:nth-child(3) { animation-delay: .3s; }
@keyframes iaPunto { 0%,80%,100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }
.ia-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 4px 0 2px; }
.ia-chip { border: 1px solid #cdd7ea; background: #fff; color: #31456a; border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; transition: .15s; text-align: left; }
.ia-chip:hover { background: #eef3ff; border-color: #8fa8dd; }
.ia-bienvenida { text-align: center; color: #5a6a85; padding: 6px 6px 2px; font-size: .9rem; }
.ia-bienvenida .ia-ico { width: 54px; height: 54px; margin: 4px auto 8px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 1.7rem; color: #fff; background: linear-gradient(135deg, #8e6bf0, #3498db); }
.ia-entrada { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid #e3e8f1; background: #fff; flex-shrink: 0; }
.ia-entrada textarea { flex: 1; resize: none; border: 1px solid #d5dce8; border-radius: 14px; padding: 9px 13px; font-size: .93rem; max-height: 120px; min-height: 42px; line-height: 1.35; background: #fff; color: #1d2733; }
.ia-entrada textarea:focus { outline: none; border-color: #3498db; box-shadow: 0 0 0 .2rem rgba(52,152,219,.2); }
.ia-entrada button { width: 42px; height: 42px; border-radius: 12px; border: 0; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.ia-enviar { background: linear-gradient(135deg, #8e6bf0, #3498db); color: #fff; }
.ia-enviar:disabled { opacity: .5; }
.ia-adjuntar { background: #eef2f9; color: #31456a; }
.ia-adjuntar:hover { background: #dfe6f4; }
/* página completa del asistente */
.ia-pagina .ia-panel-fijo { display: flex; flex-direction: column; background: #fff; border-radius: 20px; overflow: hidden; height: calc(100vh - 150px); height: calc(100dvh - 150px); min-height: 460px; box-shadow: var(--sombra-suave); border: 1px solid rgba(0,0,0,.05); }
.ia-pagina .ia-msg { font-size: 1rem; }
@media (max-width: 991.98px) { .ia-pagina .ia-panel-fijo { height: calc(100dvh - 110px); border-radius: 14px; } }
/* IA en modo oscuro */
[data-bs-theme="dark"] .ia-panel, [data-bs-theme="dark"] .ia-pagina .ia-panel-fijo { background: #172131; color: #e4e9f1; border-color: #2a3649; }
[data-bs-theme="dark"] .ia-mensajes { background: #0f1827; }
[data-bs-theme="dark"] .ia-msg.bot { background: #1d2a3d; color: #e4e9f1; border-color: #2a3649; }
[data-bs-theme="dark"] .ia-msg.bot th { background: #243349; } [data-bs-theme="dark"] .ia-msg.bot th, [data-bs-theme="dark"] .ia-msg.bot td { border-color: #2f3d52; }
[data-bs-theme="dark"] .ia-msg.error { background: #3a1a20; color: #ffb3ba; border-color: #66303a; }
[data-bs-theme="dark"] .ia-chip { background: #1d2a3d; color: #cfe0ff; border-color: #34456b; } [data-bs-theme="dark"] .ia-chip:hover { background: #26375a; }
[data-bs-theme="dark"] .ia-entrada { background: #172131; border-color: #2a3649; }
[data-bs-theme="dark"] .ia-entrada textarea { background: #0e1522; color: #e4e9f1; border-color: #2f3d52; }
[data-bs-theme="dark"] .ia-adjuntar { background: #243349; color: #cfe0ff; }
[data-bs-theme="dark"] .ia-bienvenida { color: #9fb0c6; }

/* ═══════════════ Pantallas de IA / Pedidos ═══════════════ */
.pag-titulo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 1rem; }
.pag-titulo h2 { margin: 0; font-weight: 800; }
.pag-titulo .pag-ico { width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; color: #fff; background: linear-gradient(135deg, #8e6bf0, #3498db); }
.drop-zona { border: 2px dashed #b9c6de; border-radius: 18px; padding: 34px 16px; text-align: center; cursor: pointer; background: rgba(52,152,219,.04); transition: .2s; }
.drop-zona:hover, .drop-zona.arrastrando { border-color: #3498db; background: rgba(52,152,219,.1); }
.drop-zona .bi { font-size: 2.6rem; color: #3498db; }
[data-bs-theme="dark"] .drop-zona { border-color: #34456b; }
.tabla-ia td, .tabla-ia th { vertical-align: middle; }
.tabla-ia input.form-control, .tabla-ia select.form-select { min-width: 74px; }
.fila-baja { opacity: .5; }
.chip-estado { font-size: .72rem; padding: .25em .6em; border-radius: 999px; font-weight: 700; }
.resumen-caja { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.resumen-caja > div { background: rgba(52,152,219,.08); border-radius: 14px; padding: 10px 14px; }
.resumen-caja small { display: block; color: #6c7a90; font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; }
.resumen-caja strong { font-size: 1.25rem; }
