/* ============================================================================
   Trakelt — Chatbot de demos (widget de la landing)
   Clases con prefijo .tk-chat- para no colisionar con Bootstrap/landing.
   ========================================================================== */

.tk-chat {
    --tk-primary: #3b82f6;
    --tk-primary-dark: #2563eb;
    --tk-accent: #06b6d4;
    --tk-ink: #0f172a;
    --tk-muted: #64748b;
    --tk-line: #e2e8f0;
    --tk-bot-bg: #f1f5f9;
    --tk-surface: #ffffff;
    --tk-radius: 16px;
    --tk-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 2147483000;
}

.tk-chat *, .tk-chat *::before, .tk-chat *::after { box-sizing: border-box; }

/* ── Launcher flotante ─────────────────────────────────────────────────── */
.tk-chat-launcher {
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
    cursor: pointer;
    padding: 13px 20px 13px 16px;
    border-radius: 999px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--tk-primary), var(--tk-accent));
    box-shadow: 0 10px 28px rgba(59, 130, 246, 0.45);
    transition: transform .18s ease, box-shadow .18s ease;
}
.tk-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(59, 130, 246, 0.55); }
.tk-chat-launcher svg { width: 22px; height: 22px; flex: 0 0 auto; }
.tk-chat-launcher__label { white-space: nowrap; }

.tk-chat--open .tk-chat-launcher { display: none; }

/* Badge de aviso opcional */
.tk-chat-launcher__dot {
    position: absolute; top: -2px; right: -2px;
    width: 14px; height: 14px; border-radius: 50%;
    background: #ef4444; border: 2px solid #fff;
}

/* ── Panel ─────────────────────────────────────────────────────────────── */
.tk-chat-panel {
    display: none;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 90px);
    background: var(--tk-surface);
    border-radius: var(--tk-radius);
    box-shadow: var(--tk-shadow);
    overflow: hidden;
    animation: tk-pop .22s ease;
}
.tk-chat--open .tk-chat-panel { display: flex; }

@keyframes tk-pop {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ────────────────────────────────────────────────────────────── */
.tk-chat-header {
    background: linear-gradient(135deg, var(--tk-primary), var(--tk-accent));
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.tk-chat-header__avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex: 0 0 auto;
}
.tk-chat-header__meta { flex: 1 1 auto; min-width: 0; }
.tk-chat-header__title { font-size: 15px; font-weight: 700; }
.tk-chat-header__status { font-size: 12px; opacity: .9; display: flex; align-items: center; gap: 6px; }
.tk-chat-header__status::before {
    content: ''; width: 8px; height: 8px; border-radius: 50%;
    background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .35);
}
.tk-chat-header__actions { display: flex; gap: 4px; }
.tk-chat-iconbtn {
    background: rgba(255,255,255,0.12); border: none; color: #fff;
    width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s ease;
}
.tk-chat-iconbtn:hover { background: rgba(255,255,255,0.25); }
.tk-chat-iconbtn svg { width: 16px; height: 16px; }

/* ── Body / mensajes ───────────────────────────────────────────────────── */
.tk-chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px 16px 8px;
    background: #fafbfc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.tk-chat-row { display: flex; }
.tk-chat-row--bot { justify-content: flex-start; }
.tk-chat-row--user { justify-content: flex-end; }

.tk-chat-bubble {
    max-width: 82%;
    padding: 11px 14px;
    font-size: 14px;
    line-height: 1.45;
    border-radius: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.tk-chat-row--bot .tk-chat-bubble {
    background: var(--tk-bot-bg);
    color: var(--tk-ink);
    border-bottom-left-radius: 4px;
}
.tk-chat-row--user .tk-chat-bubble {
    background: linear-gradient(135deg, var(--tk-primary), var(--tk-primary-dark));
    color: #fff;
    border-bottom-right-radius: 4px;
}
.tk-chat-bubble a { color: inherit; text-decoration: underline; }

/* Animación de entrada de cada mensaje */
.tk-chat-row { animation: tk-fade .2s ease; }
@keyframes tk-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Indicador de escribiendo */
.tk-chat-typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.tk-chat-typing span {
    width: 7px; height: 7px; border-radius: 50%; background: #94a3b8;
    animation: tk-blink 1.2s infinite ease-in-out both;
}
.tk-chat-typing span:nth-child(2) { animation-delay: .2s; }
.tk-chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes tk-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* ── Opciones / quick replies ──────────────────────────────────────────── */
.tk-chat-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0 10px;
    align-items: flex-end;
}
.tk-chat-opt {
    background: #fff;
    border: 1.5px solid var(--tk-primary);
    color: var(--tk-primary-dark);
    padding: 9px 15px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-align: right;
    transition: background .15s ease, color .15s ease, transform .1s ease;
    max-width: 90%;
}
.tk-chat-opt:hover { background: var(--tk-primary); color: #fff; }
.tk-chat-opt:active { transform: scale(.97); }
.tk-chat-opt--ghost { border-color: var(--tk-line); color: var(--tk-muted); }
.tk-chat-opt--ghost:hover { background: var(--tk-muted); color: #fff; border-color: var(--tk-muted); }

/* ── Formularios embebidos (lead) ──────────────────────────────────────── */
.tk-chat-form { width: 100%; display: flex; flex-direction: column; gap: 9px; padding: 4px 0 12px; }
.tk-chat-input {
    width: 100%;
    border: 1.5px solid var(--tk-line);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--tk-ink);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.tk-chat-input:focus { outline: none; border-color: var(--tk-primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.tk-chat-input--error { border-color: #ef4444; }
.tk-chat-gdpr { display: flex; gap: 8px; font-size: 12.5px; color: var(--tk-muted); line-height: 1.4; }
.tk-chat-gdpr input { margin-top: 2px; flex: 0 0 auto; width: 16px; height: 16px; accent-color: var(--tk-primary); }
.tk-chat-gdpr a { color: var(--tk-primary-dark); }
.tk-chat-error { font-size: 12px; color: #ef4444; }
.tk-chat-submit {
    background: linear-gradient(135deg, var(--tk-primary), var(--tk-primary-dark));
    color: #fff; border: none; border-radius: 10px;
    padding: 11px 16px; font-size: 14px; font-weight: 700; cursor: pointer;
    transition: filter .15s ease;
}
.tk-chat-submit:hover { filter: brightness(1.06); }
.tk-chat-submit:disabled { opacity: .6; cursor: default; }

/* ── Slots de reserva ──────────────────────────────────────────────────── */
.tk-chat-slots { width: 100%; padding: 4px 0 12px; }
.tk-chat-slots__label { font-size: 12px; font-weight: 600; color: var(--tk-muted); margin: 6px 0; }
.tk-chat-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.tk-chat-chip {
    background: #fff; border: 1.5px solid var(--tk-line); color: var(--tk-ink);
    padding: 8px 13px; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: all .14s ease;
}
.tk-chat-chip:hover { border-color: var(--tk-primary); }
.tk-chat-chip--active { background: var(--tk-primary); color: #fff; border-color: var(--tk-primary); }

/* ── Footer / input libre ──────────────────────────────────────────────── */
.tk-chat-footer { display: none; border-top: 1px solid var(--tk-line); padding: 10px 12px; gap: 8px; background: #fff; }
.tk-chat--input .tk-chat-footer { display: flex; }
.tk-chat-footer__input {
    flex: 1 1 auto; border: 1.5px solid var(--tk-line); border-radius: 999px;
    padding: 10px 14px; font-size: 14px; font-family: inherit;
}
.tk-chat-footer__input:focus { outline: none; border-color: var(--tk-primary); }
.tk-chat-footer__send {
    flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
    background: linear-gradient(135deg, var(--tk-primary), var(--tk-primary-dark));
    color: #fff; display: flex; align-items: center; justify-content: center;
}
.tk-chat-footer__send svg { width: 18px; height: 18px; }
.tk-chat-footer__send:disabled { opacity: .5; cursor: default; }

/* ── Móvil: pantalla completa ──────────────────────────────────────────── */
@media (max-width: 480px) {
    .tk-chat { right: 0; bottom: 0; }
    .tk-chat--open .tk-chat-panel {
        width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0;
        position: fixed; inset: 0;
    }
    .tk-chat-launcher { margin: 0 16px 16px 0; }
}

/* Respeta usuarios con prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .tk-chat-panel, .tk-chat-row, .tk-chat-launcher { animation: none; transition: none; }
}
