/* ============================================================
   Turing IA — estilos del chatbot
   Prefijo .tia- para no chocar con nada legacy.
   Usa las variables del design system v2 (--bg-surface, --fg-1, etc.)
   ============================================================ */

.tia-root { position: fixed; right: 18px; bottom: 18px; z-index: 9500; }

/* ---------- Burbuja flotante ---------- */
.tia-bubble {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 6px 14px 6px 6px;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border-strong, #d0d7e1);
    border-radius: 999px;
    box-shadow: 0 10px 28px rgba(10, 14, 39, .18);
    color: var(--fg-1, #0a0e27);
    cursor: pointer;
    font-size: 13px; font-weight: 600;
    transition: transform .12s ease, box-shadow .12s ease;
}
.tia-bubble:hover { transform: translateY(-1px); box-shadow: 0 14px 32px rgba(10, 14, 39, .22); }
.tia-bubble:active { transform: translateY(0); }

.tia-bubble__avatar {
    position: relative;
    width: 40px; height: 40px; border-radius: 50%; overflow: visible;
    flex: 0 0 40px;
}
.tia-bubble__avatar img { width: 100%; height: 100%; border-radius: 50%; display: block; }
.tia-bubble__label { white-space: nowrap; }

/* ---------- Indicador "en línea" ---------- */
.tia-online {
    position: absolute; right: -1px; bottom: -1px;
    width: 12px; height: 12px; border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--bg-surface, #fff);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, .5);
    animation: tia-pulse 2s infinite;
}
.tia-online--sm { width: 10px; height: 10px; border-width: 2px; right: -2px; bottom: -2px; }

@keyframes tia-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); }
    70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ---------- Panel de conversación ---------- */
.tia-panel {
    position: absolute; right: 0; bottom: 60px;
    width: 380px; max-width: calc(100vw - 36px);
    height: 560px; max-height: calc(100vh - 90px);
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #e3e7ee);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(10, 14, 39, .30);
    display: flex; flex-direction: column; overflow: hidden;
    color: var(--fg-1, #0a0e27);
    animation: tia-slide-in .18s ease;
}
.tia-panel[hidden] { display: none; }

@keyframes tia-slide-in {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.tia-panel__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px;
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 60%, #2563eb 100%);
    color: #fff;
}
.tia-panel__who { display: flex; align-items: center; gap: 10px; }
.tia-panel__avatar {
    position: relative; width: 36px; height: 36px; flex: 0 0 36px;
}
.tia-panel__avatar img { width: 100%; height: 100%; border-radius: 50%; display: block; }
.tia-panel__head b { font-size: 14px; font-weight: 600; display: block; }
.tia-panel__status { font-size: 11px; opacity: .85; display: flex; align-items: center; gap: 6px; }
.tia-panel__status::before {
    content: ""; width: 7px; height: 7px; border-radius: 50%;
    background: #22c55e; display: inline-block;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, .25);
}
.tia-panel__close {
    background: transparent; border: 0; color: #fff;
    font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px;
    border-radius: 6px; opacity: .85;
}
.tia-panel__close:hover { opacity: 1; background: rgba(255, 255, 255, .15); }

/* ---------- Mensajes ---------- */
.tia-panel__body {
    flex: 1 1 auto; overflow-y: auto;
    padding: 14px; display: flex; flex-direction: column; gap: 10px;
    background: var(--bg-app, #f4f6fa);
}
.tia-msg {
    max-width: 85%; padding: 9px 12px; border-radius: 14px;
    font-size: 13.5px; line-height: 1.45; word-wrap: break-word;
    animation: tia-msg-in .15s ease;
}
@keyframes tia-msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.tia-msg--user {
    align-self: flex-end;
    background: linear-gradient(135deg, #4f46e5 0%, #2563eb 100%);
    color: #fff; border-bottom-right-radius: 4px;
}
.tia-msg--bot {
    align-self: flex-start;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--divider, #e6eaf0);
    color: var(--fg-1, #0a0e27);
    border-bottom-left-radius: 4px;
}
.tia-msg strong, .tia-msg b { font-weight: 600; }
.tia-msg em, .tia-msg i { font-style: italic; }
.tia-msg code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: rgba(0, 0, 0, .06); padding: 1px 5px; border-radius: 4px;
    font-size: 12.5px;
}
.tia-msg--user code { background: rgba(255, 255, 255, .2); color: #fff; }
.tia-msg ul, .tia-msg ol { margin: 4px 0 0; padding-left: 20px; }
.tia-msg li { margin: 2px 0; }

/* ---------- F4: tarjeta de acción (Copilot) ---------- */
.tia-action {
    align-self: flex-start; max-width: 95%;
    background: var(--bg-surface, #fff);
    border: 1.5px solid #4f46e5;
    border-radius: 14px; border-bottom-left-radius: 4px;
    padding: 12px 14px; font-size: 13px; line-height: 1.45;
    animation: tia-msg-in .15s ease;
}
.tia-action__head {
    display: flex; align-items: center; gap: 8px;
    color: #4f46e5; font-size: 13px; margin-bottom: 8px;
}
.tia-action__head i { font-size: 14px; }
.tia-action__head b { font-weight: 600; color: var(--fg-1, #0a0e27); }
.tia-action__preview {
    background: var(--bg-app, #f4f6fa);
    border-radius: 8px; padding: 8px 10px; margin-bottom: 10px;
    font-size: 12.5px;
}
.tia-action__row {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 3px 0;
}
.tia-action__row + .tia-action__row {
    border-top: 1px dashed var(--divider, #e6eaf0);
}
.tia-action__key { color: var(--fg-3, #7a8698); font-weight: 500; }
.tia-action__val { color: var(--fg-1, #0a0e27); font-weight: 600; text-align: right; }
.tia-action__btns { display: flex; gap: 8px; }
.tia-action__btn {
    flex: 1 1 50%; padding: 8px 12px; border-radius: 8px; border: 0;
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: filter .12s ease, opacity .12s ease;
}
.tia-action__btn:disabled { opacity: .6; cursor: wait; }
.tia-action__btn--ok {
    background: linear-gradient(135deg, #4f46e5, #2563eb); color: #fff;
}
.tia-action__btn--ok:hover:not(:disabled) { filter: brightness(1.1); }
.tia-action__btn--cancel {
    background: transparent; color: var(--fg-2, #4b5563);
    border: 1px solid var(--border-strong, #d0d7e1);
}
.tia-action__btn--cancel:hover:not(:disabled) { background: var(--bg-hover, #f1f5f9); }
.tia-action--done .tia-action__btns { display: none; }
.tia-action__status {
    padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
    margin-top: 2px;
}
.tia-action__status--ok  { background: #ecfdf5; color: #047857; border: 1px solid #6ee7b7; }
.tia-action__status--err { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }

[data-theme="dark"] .tia-action { background: #141821; border-color: #6366f1; }
[data-theme="dark"] .tia-action__head b { color: #e6ecf5; }
[data-theme="dark"] .tia-action__preview { background: #0f131b; }
[data-theme="dark"] .tia-action__val { color: #e6ecf5; }

/* "Escribiendo…" placeholder */
.tia-typing {
    align-self: flex-start;
    display: inline-flex; gap: 3px; padding: 10px 14px;
    background: var(--bg-surface, #fff); border: 1px solid var(--divider, #e6eaf0);
    border-radius: 14px; border-bottom-left-radius: 4px;
}
.tia-typing span {
    width: 6px; height: 6px; border-radius: 50%; background: #9aa4b5;
    animation: tia-blink 1.2s infinite both;
}
.tia-typing span:nth-child(2) { animation-delay: .2s; }
.tia-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes tia-blink {
    0%, 60%, 100% { opacity: .3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- Formulario ---------- */
.tia-panel__form {
    display: flex; gap: 8px; padding: 10px;
    border-top: 1px solid var(--divider, #e6eaf0);
    background: var(--bg-surface, #fff);
}
.tia-panel__input {
    flex: 1 1 auto; min-width: 0;
    padding: 9px 12px; font-size: 13.5px;
    border: 1px solid var(--border-strong, #d0d7e1); border-radius: 10px;
    background: var(--bg-app, #f8fafc); color: var(--fg-1, #0a0e27);
    outline: none;
}
.tia-panel__input:focus { border-color: #4f46e5; background: var(--bg-surface, #fff); }
.tia-panel__send {
    flex: 0 0 40px; width: 40px; height: 40px; border-radius: 10px; border: 0;
    background: linear-gradient(135deg, #4f46e5, #2563eb); color: #fff;
    cursor: pointer; font-size: 14px;
    display: grid; place-items: center;
    transition: filter .12s ease;
}
.tia-panel__send:hover { filter: brightness(1.08); }
.tia-panel__send:disabled { opacity: .5; cursor: not-allowed; }

.tia-panel__foot {
    padding: 7px 12px; font-size: 10.5px; color: var(--fg-3, #7a8698);
    text-align: center; background: var(--bg-surface, #fff);
    border-top: 1px solid var(--divider, #e6eaf0);
}

/* ---------- Dark mode ---------- */
[data-theme="dark"] .tia-bubble { background: #1b1f2a; border-color: #2b3040; color: #e6ecf5; }
[data-theme="dark"] .tia-panel  { background: #141821; border-color: #2b3040; color: #e6ecf5; }
[data-theme="dark"] .tia-panel__body { background: #0f131b; }
[data-theme="dark"] .tia-msg--bot { background: #1b1f2a; border-color: #2b3040; color: #e6ecf5; }
[data-theme="dark"] .tia-panel__input { background: #0f131b; border-color: #2b3040; color: #e6ecf5; }
[data-theme="dark"] .tia-panel__input:focus { background: #141821; }
[data-theme="dark"] .tia-panel__form, [data-theme="dark"] .tia-panel__foot { background: #141821; border-top-color: #2b3040; }
[data-theme="dark"] .tia-typing { background: #1b1f2a; border-color: #2b3040; }

/* ---------- Mobile ---------- */
@media (max-width: 520px) {
    .tia-root { right: 10px; bottom: 10px; }
    .tia-bubble__label { display: none; }
    .tia-bubble { padding: 4px; border-radius: 50%; }
    .tia-panel { right: 0; bottom: 60px; width: calc(100vw - 20px); height: 70vh; }
}
