/* =========================================================
   TEKMA - Botones flotantes (Tekki IA + WhatsApp guiado)
   ========================================================= */

:root {
    --tkw-orange: #F25C05;
    --tkw-orange-2: #FF7A2F;
    --tkw-green: #25D366;
    --tkw-green-dark: #128C7E;
    --tkw-ink: #15161b;
    --tkw-muted: #6b6f7a;
    --tkw-line: #ececf0;
    --tkw-bg: #ffffff;
    --tkw-soft: #f5f6f8;
    --tkw-font: 'Rubik', system-ui, -apple-system, sans-serif;
}

/* ---------- Botones redondos ---------- */
.tk-fab {
    position: fixed;
    right: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: 0;
    padding: 0;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 2000000;
    text-decoration: none !important;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    font-family: var(--tkw-font);
}
.tk-fab:hover { transform: translateY(-3px) scale(1.04); }
.tk-fab:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.tk-fab-wa {
    bottom: 24px;
    background: linear-gradient(145deg, #2fe077, var(--tkw-green-dark));
    color: #fff !important;
    box-shadow: 0 12px 28px -8px rgba(18, 140, 126, 0.75);
}
.tk-fab-wa svg { width: 32px; height: 32px; position: relative; z-index: 1; }
/* Onda que "late" alrededor del botón de WhatsApp */
.tk-fab-ping {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--tkw-green);
    animation: tkPing 2.4s ease-out infinite;
}
.tk-fab-wa.is-open .tk-fab-ping { display: none; }

.tk-fab-tekki {
    bottom: 100px;
    background: linear-gradient(145deg, var(--tkw-orange-2), var(--tkw-orange));
    box-shadow: 0 12px 28px -8px rgba(242, 92, 5, 0.75);
    padding: 3px;
}
.tk-fab-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.9);
    background: #fff;
}
.tk-fab-dot {
    position: absolute;
    right: 2px;
    bottom: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #2ecc71;
    border: 2px solid #fff;
}
.tk-fab.is-open { transform: scale(0.92); }

/* Etiqueta que aparece al lado del botón */
.tk-fab-tip {
    position: absolute;
    right: calc(100% + 14px);
    top: 50%;
    transform: translate(8px, -50%);
    white-space: nowrap;
    background: var(--tkw-ink);
    color: #fff;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.2;
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    text-transform: none;
    letter-spacing: 0;
}
.tk-fab-tip b { color: var(--tkw-orange-2); font-weight: 600; }
.tk-fab-wa .tk-fab-tip b { color: #5cf09a; }
.tk-fab-tip:after {
    content: "";
    position: absolute;
    right: -6px;
    top: 50%;
    width: 12px;
    height: 12px;
    background: var(--tkw-ink);
    transform: translateY(-50%) rotate(45deg);
    border-radius: 2px;
}
.tk-fab:hover .tk-fab-tip,
.tk-fab.show-tip .tk-fab-tip {
    opacity: 1;
    transform: translate(0, -50%);
}
.tk-fab.is-open .tk-fab-tip { opacity: 0; }

/* ---------- Panel de chat (común a Tekki y WhatsApp) ---------- */
.tk-panel {
    position: fixed;
    right: 100px;
    bottom: 24px;
    width: 380px;
    height: min(600px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--tkw-bg);
    border-radius: 22px;
    box-shadow: 0 30px 70px -20px rgba(15, 16, 20, 0.45), 0 0 0 1px rgba(15, 16, 20, 0.06);
    overflow: hidden;
    z-index: 2000001;
    font-family: var(--tkw-font);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}
.tk-panel.active {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.tk-panel-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 16px 18px;
    color: #fff;
    background: linear-gradient(135deg, #1b1c22 0%, #2a2b33 100%);
    position: relative;
}
.tk-tekki .tk-panel-head:after,
.tk-wa .tk-panel-head:after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--tkw-orange), var(--tkw-orange-2));
}
.tk-wa .tk-panel-head { background: linear-gradient(135deg, #075E54 0%, var(--tkw-green-dark) 100%); }
.tk-wa .tk-panel-head:after { background: linear-gradient(90deg, var(--tkw-green), #5cf09a); }

.tk-head-avatar { position: relative; flex: 0 0 auto; }
.tk-head-avatar img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.85);
    background: #fff;
    display: block;
}
.tk-head-avatar i {
    position: absolute;
    right: -1px;
    bottom: 1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #2ecc71;
    border: 2px solid #1b1c22;
}
.tk-head-avatar i.off { background: #f1c40f; }
.tk-head-who { flex: 1; min-width: 0; line-height: 1.25; }
.tk-head-who strong { display: block; font-size: 16px; font-weight: 600; }
.tk-head-who span { font-size: 12.5px; opacity: 0.8; }
.tk-head-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 0;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
    flex: 0 0 auto;
}
.tk-head-btn:hover { background: rgba(255, 255, 255, 0.25); }

.tk-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background:
        radial-gradient(circle at 20% 10%, rgba(242, 92, 5, 0.05), transparent 40%),
        var(--tkw-soft);
    scroll-behavior: smooth;
}
.tk-wa .tk-panel-body {
    background:
        radial-gradient(circle at 80% 0%, rgba(37, 211, 102, 0.08), transparent 45%),
        #efeae2;
}

.tk-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: tkPop 0.25s ease;
}
.tk-msg-ai {
    align-self: flex-start;
    background: #fff;
    color: var(--tkw-ink);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 6px rgba(15, 16, 20, 0.06);
}
.tk-msg-user {
    align-self: flex-end;
    color: #fff;
    background: linear-gradient(135deg, var(--tkw-orange-2), var(--tkw-orange));
    border-bottom-right-radius: 4px;
}
.tk-wa .tk-msg-user { background: #d9fdd3; color: var(--tkw-ink); }
.tk-msg a { color: var(--tkw-orange); text-decoration: underline; }
.tk-msg strong { font-weight: 600; }

/* Puntos de "escribiendo…" */
.tk-typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.tk-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b8bcc6;
    animation: tkDots 1.2s infinite ease-in-out;
}
.tk-typing span:nth-child(2) { animation-delay: 0.15s; }
.tk-typing span:nth-child(3) { animation-delay: 0.3s; }

/* Opciones del menú guiado */
.tk-options { display: flex; flex-direction: column; gap: 7px; align-self: stretch; animation: tkPop 0.25s ease; }
.tk-option {
    text-align: left;
    background: #fff;
    border: 1px solid var(--tkw-line);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--tkw-font);
    color: var(--tkw-ink);
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}
.tk-wa .tk-option:hover { border-color: var(--tkw-green); background: #f3fff7; transform: translateX(3px); }

/* Sugerencias rápidas de Tekki */
.tk-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 14px;
    background: #fff;
    border-top: 1px solid var(--tkw-line);
    scrollbar-width: none;
}
.tk-chips::-webkit-scrollbar { display: none; }
.tk-chip {
    flex: 0 0 auto;
    border: 1px solid rgba(242, 92, 5, 0.3);
    background: #fff7f2;
    color: #b54304;
    border-radius: 999px;
    padding: 7px 13px;
    font-size: 13px;
    font-family: var(--tkw-font);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}
.tk-chip:hover { background: var(--tkw-orange); color: #fff; }

/* Caja de texto de Tekki */
.tk-panel-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid var(--tkw-line);
}
.tk-panel-form input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--tkw-line);
    background: var(--tkw-soft);
    border-radius: 999px;
    padding: 11px 16px;
    font-size: 14.5px;
    font-family: var(--tkw-font);
    color: var(--tkw-ink);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.tk-panel-form input:focus { border-color: var(--tkw-orange); box-shadow: 0 0 0 3px rgba(242, 92, 5, 0.12); }
.tk-panel-form button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 0;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--tkw-orange-2), var(--tkw-orange));
    transition: transform 0.2s ease;
}
.tk-panel-form button:hover { transform: scale(1.06); }
.tk-panel-note {
    font-size: 11.5px;
    color: var(--tkw-muted);
    text-align: center;
    padding: 0 14px 10px;
    background: #fff;
}

/* Pie del chat de WhatsApp */
.tk-panel-foot:empty { display: none; }
.tk-panel-foot { padding: 12px 14px 14px; background: #fff; border-top: 1px solid var(--tkw-line); }
.tk-wa-free { display: flex; gap: 8px; align-items: flex-end; }
.tk-wa-free textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--tkw-line);
    border-radius: 14px;
    padding: 10px 12px;
    font-family: var(--tkw-font);
    font-size: 14px;
    outline: none;
}
.tk-wa-free textarea:focus { border-color: var(--tkw-green); }
.tk-send-mini {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 0;
    background: var(--tkw-green);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}
.tk-wa-final { display: flex; flex-direction: column; gap: 10px; }
.tk-wa-preview {
    font-size: 13px;
    line-height: 1.45;
    background: #d9fdd3;
    color: var(--tkw-ink);
    border-radius: 12px 12px 4px 12px;
    padding: 10px 12px;
    max-height: 120px;
    overflow-y: auto;
    white-space: pre-line;
}
.tk-wa-name {
    border: 1px solid var(--tkw-line);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: var(--tkw-font);
    outline: none;
}
.tk-wa-name:focus { border-color: var(--tkw-green); }
.tk-wa-go {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 13px;
    border-radius: 14px;
    background: linear-gradient(135deg, #2fe077, var(--tkw-green-dark));
    color: #fff !important;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none !important;
    box-shadow: 0 10px 24px -10px rgba(18, 140, 126, 0.8);
    transition: transform 0.2s ease;
}
.tk-wa-go:hover { transform: translateY(-2px); }
.tk-wa-go svg { width: 20px; height: 20px; }

/* ---------- Animaciones ---------- */
@keyframes tkPing {
    0% { transform: scale(1); opacity: 0.7; }
    80%, 100% { transform: scale(1.55); opacity: 0; }
}
@keyframes tkDots {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-5px); opacity: 1; }
}
@keyframes tkPop {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .tk-fab-ping, .tk-msg, .tk-options { animation: none; }
}

/* ---------- Tablet y móvil ---------- */
@media only screen and (max-width: 600px) {
    .tk-fab { right: 16px; width: 56px; height: 56px; }
    .tk-fab-wa { bottom: 18px; }
    .tk-fab-tekki { bottom: 86px; }
    .tk-fab-wa svg { width: 28px; height: 28px; }
    .tk-fab-tip { font-size: 13px; }

    /* El chat ocupa la parte baja de la pantalla como hoja deslizante */
    .tk-panel {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: min(86vh, 640px);
        border-radius: 22px 22px 0 0;
        transform: translateY(40px);
    }
    body:has(.tk-panel.active) .tk-fab { opacity: 0; pointer-events: none; }
}
