/* Copiloto interno (public/js/tenant-copilot.js). Claro por defecto; html.dark lo oscurece.
   Diseño 2026-11-02: cabecera con degradado azul, avatar con robot, burbujas con borde sutil, sugerencias en píldora,
   «¿Te sirvió?» y caja de escribir tipo píldora con el micrófono y el botón de enviar dentro. */
.sfp-cp {
    --cp-brand: #1d4ed8; --cp-brand-2: #2563eb; --cp-brand-3: #3b82f6; --cp-on-brand: #fff;
    --cp-bg: #ffffff; --cp-bg-2: #f5f7fc; --cp-text: #111827; --cp-muted: #64748b; --cp-line: #e2e8f0;
    --cp-bot: #ffffff; --cp-bot-line: #e2e8f0; --cp-chip: rgba(37, 99, 235, .06); --cp-warn: #fff7ed; --cp-warn-line: #fed7aa;
    --cp-ok: #22c55e; --cp-shadow: 0 30px 80px rgba(15, 23, 42, .28);
    font-family: inherit;
}
html.dark .sfp-cp {
    --cp-brand: #2563eb; --cp-brand-2: #3b82f6; --cp-brand-3: #60a5fa;
    --cp-bg: #0f172a; --cp-bg-2: #0b1222; --cp-text: #e5e7eb; --cp-muted: #94a3b8; --cp-line: #1f2a44;
    --cp-bot: #162036; --cp-bot-line: #26324f; --cp-chip: rgba(59, 130, 246, .12); --cp-warn: #3b2a12; --cp-warn-line: #7c4a12;
    --cp-shadow: 0 30px 80px rgba(0, 0, 0, .55);
}
.sfp-cp button, .sfp-cp textarea { font-family: inherit; }
.sfp-cp svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Botón flotante */
.sfp-cp__btn {
    position: fixed; right: 20px; bottom: 20px; z-index: 1040; display: inline-flex; align-items: center; gap: 8px;
    height: 48px; padding: 0 18px 0 7px; border: 0; border-radius: 999px; cursor: pointer;
    background: linear-gradient(135deg, var(--cp-brand) 0%, var(--cp-brand-3) 100%); color: var(--cp-on-brand);
    font-family: inherit; font-size: 14px; font-weight: 600; line-height: 1; box-shadow: 0 10px 30px rgba(37, 99, 235, .35), 0 2px 6px rgba(0, 0, 0, .15);
    transition: transform .15s ease, box-shadow .15s ease;
}
.sfp-cp__btn:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(37, 99, 235, .45), 0 2px 6px rgba(0, 0, 0, .15); }
.sfp-cp__btn:focus-visible { outline: 3px solid rgba(37, 99, 235, .4); outline-offset: 2px; }
.sfp-cp__btn-ic { width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: inline-flex; align-items: center; justify-content: center; }
.sfp-cp--open .sfp-cp__btn { display: none; }

/* Panel */
.sfp-cp__panel {
    position: fixed; right: 20px; bottom: 20px; z-index: 1041; width: 400px; max-width: calc(100vw - 16px);
    height: min(660px, calc(100vh - 32px)); display: flex; flex-direction: column; overflow: hidden;
    background: var(--cp-bg); color: var(--cp-text); border: 1px solid var(--cp-line); border-radius: 20px; box-shadow: var(--cp-shadow);
}
.sfp-cp__panel[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) {
    .sfp-cp__panel:not([hidden]) { animation: sfp-cp-in .2s ease-out; }
    .sfp-cp__row { animation: sfp-cp-msg .18s ease-out; }
}
@keyframes sfp-cp-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sfp-cp-msg { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.sfp-cp__head {
    display: flex; align-items: center; gap: 10px; padding: 12px 10px 12px 14px; flex: none; color: #fff;
    background: linear-gradient(135deg, #1e3a8a 0%, var(--cp-brand) 45%, var(--cp-brand-3) 100%);
}
.sfp-cp__avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .2); color: #fff; }
.sfp-cp__avatar svg { width: 22px; height: 22px; }
.sfp-cp__avatar--sm { width: 28px; height: 28px; align-self: flex-start; margin-top: 2px; background: linear-gradient(135deg, var(--cp-brand), var(--cp-brand-3)); }
.sfp-cp__avatar--sm svg { width: 16px; height: 16px; }
.sfp-cp__title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.sfp-cp__title b { font-size: 15px; font-weight: 700; }
.sfp-cp__title small { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sfp-cp__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cp-ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .3); flex: none; }
.sfp-cp__icon { flex: none; width: 34px; height: 34px; border: 0; border-radius: 10px; background: transparent; color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; opacity: .88; }
.sfp-cp__icon:hover, .sfp-cp__icon:focus-visible, .sfp-cp__icon[aria-pressed="true"] { background: rgba(255, 255, 255, .18); opacity: 1; outline: none; }

/* Mensajes */
.sfp-cp__body { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 12px; background: var(--cp-bg-2); scrollbar-width: thin; scrollbar-color: rgba(100, 116, 139, .45) transparent; }
.sfp-cp__body::-webkit-scrollbar { width: 6px; }
.sfp-cp__body::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, .45); border-radius: 999px; }
.sfp-cp__row { display: flex; gap: 8px; align-items: flex-start; }
.sfp-cp__row--me { justify-content: flex-end; }
.sfp-cp__msg { max-width: 84%; padding: 10px 13px; border-radius: 16px; font-size: 14px; line-height: 1.5; word-wrap: break-word; }
.sfp-cp__msg p { margin: 0 0 6px; }
.sfp-cp__msg p:last-child { margin-bottom: 0; }
.sfp-cp__msg ul { margin: 4px 0; padding-left: 18px; }
.sfp-cp__msg--bot { background: var(--cp-bot); color: var(--cp-text); border: 1px solid var(--cp-bot-line); border-top-left-radius: 5px; box-shadow: 0 2px 8px rgba(15, 23, 42, .05); }
.sfp-cp__msg--me { background: linear-gradient(135deg, var(--cp-brand), var(--cp-brand-2)); color: var(--cp-on-brand); border-top-right-radius: 5px; box-shadow: 0 4px 14px rgba(37, 99, 235, .25); }
/* Lo que escribe el usuario va en <p>/<li>: el tema les pone su propio color (p { color: #777 } en claro y
   html.dark p { … !important } en el Punto de venta), que gana al color heredado de la burbuja. Dentro de la burbuja
   azul todo es blanco, también la etiqueta «Dictado por voz»; con .sfp-cp delante para ganarle a html.dark p. */
.sfp-cp .sfp-cp__msg--me, .sfp-cp .sfp-cp__msg--me p, .sfp-cp .sfp-cp__msg--me li, .sfp-cp .sfp-cp__msg--me ul, .sfp-cp .sfp-cp__msg--me ol,
.sfp-cp .sfp-cp__msg--me strong, .sfp-cp .sfp-cp__msg--me b, .sfp-cp .sfp-cp__msg--me em, .sfp-cp .sfp-cp__msg--me i, .sfp-cp .sfp-cp__msg--me span,
.sfp-cp .sfp-cp__msg--me code, .sfp-cp .sfp-cp__msg--me a, .sfp-cp .sfp-cp__msg--me .sfp-cp__voice { color: var(--cp-on-brand) !important; }
.sfp-cp .sfp-cp__msg--me a { text-decoration: underline; }
/* La respuesta del asistente, con el color de su burbuja (no el gris #777 de los párrafos del tema). */
.sfp-cp .sfp-cp__msg--bot p, .sfp-cp .sfp-cp__msg--bot li { color: inherit; }
.sfp-cp__msg--warn { background: var(--cp-warn); border-color: var(--cp-warn-line); }
.sfp-cp__msg--wait { display: inline-flex; align-items: center; padding: 12px 14px; }
.sfp-cp__voice { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; font-size: 11px; opacity: .85; }
.sfp-cp__voice svg { width: 13px; height: 13px; }
.sfp-cp__dots { display: inline-flex; gap: 4px; }
.sfp-cp__dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--cp-brand-2); animation: sfp-cp-dot 1.2s ease-in-out infinite; }
.sfp-cp__dots i:nth-child(2) { animation-delay: .2s; }
.sfp-cp__dots i:nth-child(3) { animation-delay: .4s; }
@keyframes sfp-cp-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sfp-cp__dots i { animation: none; } }

/* «Ir a…»: tarjeta con borde azul */
.sfp-cp__go { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.sfp-cp__goto { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border: 1px solid var(--cp-brand-2); border-radius: 12px; color: var(--cp-brand-2); background: var(--cp-chip); text-decoration: none; }
.sfp-cp__goto span { display: flex; flex-direction: column; min-width: 0; }
.sfp-cp__goto b { font-weight: 600; font-size: 13.5px; }
.sfp-cp__goto small { color: var(--cp-muted); font-size: 11.5px; }
.sfp-cp__goto:hover { background: var(--cp-brand-2); color: #fff; text-decoration: none; }
.sfp-cp__goto:hover small { color: rgba(255, 255, 255, .85); }
html.dark .sfp-cp__goto { color: var(--cp-brand-3); border-color: var(--cp-brand-3); }

/* Sugerencias y «¿Te sirvió?» */
.sfp-cp__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sfp-cp__chip { padding: 5px 11px; border: 1px solid var(--cp-brand-3); border-radius: 999px; background: var(--cp-chip); color: var(--cp-text); font-size: 12.5px; line-height: 1.35; cursor: pointer; text-align: left; }
.sfp-cp__chip:hover { background: var(--cp-brand-2); border-color: var(--cp-brand-2); color: #fff; }
.sfp-cp__rate { display: flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 11.5px; color: var(--cp-muted); }
.sfp-cp__rate button { border: 0; background: transparent; color: inherit; padding: 3px; border-radius: 6px; display: inline-flex; cursor: pointer; }
.sfp-cp__rate button svg { width: 16px; height: 16px; }
.sfp-cp__rate button:hover, .sfp-cp__rate button[aria-pressed="true"] { color: var(--cp-brand-2); background: var(--cp-chip); }
.sfp-cp__rate small { margin-left: 4px; }

/* Historial */
.sfp-cp__loading, .sfp-cp__empty { color: var(--cp-muted); font-size: 13.5px; margin: 0; }
.sfp-cp__hist-head { display: flex; justify-content: space-between; align-items: center; }
.sfp-cp__hist-head b { font-size: 14px; }
.sfp-cp__hist { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 9px 12px; border: 1px solid var(--cp-line); border-radius: 12px; background: var(--cp-bot); color: var(--cp-text); text-align: left; cursor: pointer; }
.sfp-cp__hist span { font-size: 13.5px; font-weight: 600; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sfp-cp__hist small { color: var(--cp-muted); font-size: 11.5px; }
.sfp-cp__hist:hover, .sfp-cp__hist.is-current { border-color: var(--cp-brand-2); }
.sfp-cp__link { border: 0; background: none; color: var(--cp-brand-2); font-size: 13px; cursor: pointer; }

/* Caja de escribir: píldora con borde azul y los botones dentro */
.sfp-cp__form { flex: none; padding: 10px 12px 4px; background: var(--cp-bg); }
.sfp-cp__box { display: flex; align-items: flex-end; gap: 6px; padding: 6px 6px 6px 16px; border: 1.5px solid var(--cp-brand-3); border-radius: 26px; background: var(--cp-bg); transition: box-shadow .15s ease, border-color .15s ease; }
.sfp-cp__box:focus-within { border-color: var(--cp-brand-2); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.sfp-cp__input { flex: 1; min-width: 0; height: 36px; min-height: 36px; max-height: 140px; padding: 8px 0; border: 0; outline: none; resize: none; background: transparent; color: var(--cp-text); font-size: 14px; line-height: 1.45; }
.sfp-cp__input::placeholder { color: var(--cp-muted); }
.sfp-cp__mic, .sfp-cp__send { flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.sfp-cp__mic { background: transparent; color: var(--cp-muted); }
.sfp-cp__mic:hover { color: var(--cp-brand-2); background: var(--cp-chip); }
.sfp-cp__mic[hidden] { display: none; }
.sfp-cp__mic.is-rec { background: #dc2626; color: #fff; animation: sfp-cp-rec 1.2s ease-in-out infinite; }
.sfp-cp__mic.is-busy, .sfp-cp__mic:disabled { opacity: .6; cursor: default; }
@keyframes sfp-cp-rec { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .45); } 50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); } }
.sfp-cp__send { background: linear-gradient(135deg, var(--cp-brand), var(--cp-brand-3)); color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, .35); }
.sfp-cp__send svg { width: 18px; height: 18px; margin-left: -2px; }
.sfp-cp__send:disabled { opacity: .5; cursor: default; }
.sfp-cp__foot { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 12px 10px; color: var(--cp-muted); font-size: 11px; background: var(--cp-bg); text-align: center; }

@media (max-width: 600px) {
    .sfp-cp__panel { right: 0; bottom: 0; width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
    .sfp-cp__btn { right: 16px; bottom: 16px; }
}
@media print { .sfp-cp { display: none !important; } }
