/*
 * krakryp/assets/css/asistente.css
 * Asistente Virtual del sitio público.
 *
 * Identidad de Krakryp: dorado (#DAA520 → #FFD700) sobre azul marino
 * (#2c3e50 → #1a1a2e), la misma pareja que usan la cabecera y el pie.
 * Todo va prefijado con .kr- para no interferir con Bootstrap ni con styles.css.
 */

#krAsistente {
    --kr-gold:     #DAA520;
    --kr-gold-2:   #FFD700;
    --kr-gold-soft:#fdf6e3;
    --kr-navy:     #2c3e50;
    --kr-navy-2:   #34495e;
    --kr-navy-3:   #1a1a2e;
    --kr-ink:      #1f2733;
    --kr-ink-soft: #5b6677;
    --kr-ink-faint:#8a94a6;
    --kr-line:     #e6e9f2;
    --kr-surface:  #ffffff;
    --kr-surface-2:#f6f8fa;

    position: fixed;
    right: 30px;
    bottom: 30px;
    z-index: 10000;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* El botón de Telegram del pie sube para dejar sitio al asistente. */
.floating-call-uss { bottom: 108px !important; }

/* ============================================================
   BOTÓN FLOTANTE
   ============================================================ */
.kr-launcher {
    position: relative;
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--kr-gold-2), var(--kr-gold));
    color: var(--kr-navy);
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(44, 62, 80, .28);
    transition: transform .25s ease, box-shadow .25s ease;
}
.kr-launcher:hover  { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(44, 62, 80, .34); }
.kr-launcher:active { transform: translateY(-1px); }
.kr-launcher:focus-visible {
    outline: 3px solid var(--kr-navy);
    outline-offset: 3px;
}
.kr-launcher::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(218, 165, 32, .45);
    animation: kr-halo 2.6s ease-out infinite;
}
@keyframes kr-halo {
    0%   { transform: scale(1);    opacity: .8; }
    70%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

.kr-launcher-close { display: none; }
#krAsistente.is-open .kr-launcher-open  { display: none; }
#krAsistente.is-open .kr-launcher-close { display: block; }
#krAsistente.is-open .kr-launcher::after { animation: none; opacity: 0; }

/* Aviso de respuesta nueva */
.kr-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e74c3c;
    border: 2px solid #fff;
}

/* ============================================================
   PANEL
   ============================================================ */
.kr-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
    background: var(--kr-surface);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 18px 48px rgba(26, 26, 46, .28);
    transform-origin: bottom right;
    animation: kr-in .22s ease-out;
}
.kr-panel[hidden] { display: none; }
@keyframes kr-in {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Cabecera --- */
.kr-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .95rem 1rem;
    background: linear-gradient(120deg, var(--kr-navy-3) 0%, var(--kr-navy) 60%, var(--kr-navy-2) 100%);
    color: #fff;
    border-bottom: 3px solid var(--kr-gold);
}
.kr-avatar {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--kr-gold-2), var(--kr-gold));
    color: var(--kr-navy-3);
}
.kr-head-text { flex: 1 1 auto; min-width: 0; }
.kr-head-text h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -.01em;
    color: #fff;
}
.kr-status {
    margin: 0;
    font-size: .76rem;
    color: #c7d0de;
    display: flex;
    align-items: center;
    gap: .35rem;
}
.kr-online {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 0 3px rgba(46, 204, 113, .2);
}
.kr-close {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 9px;
    background: rgba(255, 255, 255, .1);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background .15s ease;
}
.kr-close:hover { background: rgba(255, 255, 255, .2); }
.kr-close:focus-visible { outline: 2px solid var(--kr-gold-2); outline-offset: 2px; }

/* --- Conversación --- */
.kr-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1.1rem 1rem;
    background: var(--kr-surface-2);
    scroll-behavior: smooth;
}
.kr-thread::-webkit-scrollbar { width: 8px; }
.kr-thread::-webkit-scrollbar-thumb { background: #d8dde6; border-radius: 8px; }

.kr-msg { display: flex; margin-bottom: .7rem; }
.kr-msg:last-child { margin-bottom: 0; }
.kr-msg.bot, .kr-msg.agente { justify-content: flex-start; }
.kr-msg.yo { justify-content: flex-end; }

.kr-bubble {
    max-width: 85%;
    padding: .7rem .9rem;
    border-radius: 16px;
    font-size: .88rem;
    line-height: 1.55;
    color: var(--kr-ink);
    background: var(--kr-surface);
    border: 1px solid var(--kr-line);
    box-shadow: 0 1px 2px rgba(31, 39, 51, .04);
    white-space: pre-line;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.kr-msg.bot .kr-bubble {
    border-left: 3px solid var(--kr-gold);
    border-bottom-left-radius: 5px;
}
/* Saludo de bienvenida: la primera burbuja de la visita. */
.kr-bubble.kr-saludo {
    background: linear-gradient(135deg, #fffaf0, var(--kr-gold-soft));
    border-color: rgba(218, 165, 32, .45);
}
.kr-bubble.kr-saludo strong {
    display: block;
    color: var(--kr-navy);
    font-size: .95rem;
    margin-bottom: .2rem;
}
.kr-msg.agente .kr-bubble {
    background: var(--kr-gold-soft);
    border-color: rgba(218, 165, 32, .4);
    border-bottom-left-radius: 5px;
}
.kr-msg.yo .kr-bubble {
    background: var(--kr-navy);
    border-color: var(--kr-navy);
    color: #eef2f8;
    border-bottom-right-radius: 5px;
}
.kr-msg.sistema { justify-content: center; }
.kr-msg.sistema .kr-bubble {
    background: transparent;
    border: 1px dashed var(--kr-line);
    color: var(--kr-ink-faint);
    font-size: .8rem;
    text-align: center;
    box-shadow: none;
}
.kr-tag {
    display: block;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--kr-gold);
    margin-bottom: .25rem;
}
.kr-time {
    display: block;
    font-size: .68rem;
    color: var(--kr-ink-faint);
    margin-top: .3rem;
}
.kr-msg.yo .kr-time { color: #b6c1d0; text-align: right; }

/* Puntos de "escribiendo" */
.kr-typing { display: inline-flex; gap: 4px; padding: 2px 0; }
.kr-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--kr-gold);
    animation: kr-bounce 1.2s infinite ease-in-out;
}
.kr-typing span:nth-child(2) { animation-delay: .15s; }
.kr-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes kr-bounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: .45; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* --- Sugerencias --- */
.kr-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    padding: 0 1rem .6rem;
    background: var(--kr-surface-2);
}
.kr-chips:empty { display: none; }
.kr-chip {
    padding: .35rem .75rem;
    border-radius: 20px;
    border: 1px solid rgba(218, 165, 32, .5);
    background: var(--kr-surface);
    color: var(--kr-navy);
    font-size: .78rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}
.kr-chip:hover {
    background: linear-gradient(135deg, var(--kr-gold-2), var(--kr-gold));
    color: var(--kr-navy-3);
    transform: translateY(-1px);
}
.kr-chip:focus-visible { outline: 2px solid var(--kr-navy); outline-offset: 2px; }

/* --- Paso a una persona --- */
.kr-handoff {
    padding: .9rem 1rem;
    border-top: 1px solid var(--kr-line);
    background: var(--kr-surface);
}
.kr-handoff[hidden] { display: none; }
.kr-handoff-title {
    margin: 0 0 .6rem;
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--kr-navy);
}
.kr-field { display: block; margin-bottom: .55rem; }
.kr-field span {
    display: block;
    font-size: .72rem;
    font-weight: 600;
    color: var(--kr-ink-faint);
    margin-bottom: .2rem;
}
.kr-field input,
.kr-field textarea {
    width: 100%;
    padding: .5rem .65rem;
    border: 1px solid var(--kr-line);
    border-radius: 10px;
    font-family: inherit;
    font-size: .85rem;
    color: var(--kr-ink);
    background: var(--kr-surface);
    resize: vertical;
}
.kr-field input:focus,
.kr-field textarea:focus,
.kr-composer textarea:focus {
    outline: none;
    border-color: var(--kr-gold);
    box-shadow: 0 0 0 3px rgba(218, 165, 32, .2);
}
.kr-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.kr-handoff-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .3rem; }
.kr-btn {
    padding: .45rem .9rem;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--kr-gold-2), var(--kr-gold));
    color: var(--kr-navy-3);
    font-size: .82rem;
    font-weight: 700;
    cursor: pointer;
    transition: filter .15s ease;
}
.kr-btn:hover { filter: brightness(.95); }
.kr-btn:disabled { opacity: .6; cursor: default; }
.kr-btn.ghost {
    background: transparent;
    border: 1px solid var(--kr-line);
    color: var(--kr-ink-soft);
    font-weight: 600;
}
.kr-btn:focus-visible { outline: 2px solid var(--kr-navy); outline-offset: 2px; }

/* --- Redacción --- */
.kr-composer {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding: .7rem .8rem;
    border-top: 1px solid var(--kr-line);
    background: var(--kr-surface);
}
.kr-composer[hidden] { display: none; }
.kr-composer textarea {
    flex: 1 1 auto;
    max-height: 110px;
    padding: .55rem .75rem;
    border: 1px solid var(--kr-line);
    border-radius: 14px;
    font-family: inherit;
    font-size: .88rem;
    line-height: 1.45;
    color: var(--kr-ink);
    resize: none;
    overflow-y: auto;
}
.kr-send {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--kr-gold-2), var(--kr-gold));
    color: var(--kr-navy-3);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: filter .15s ease, transform .15s ease;
}
.kr-send:hover { filter: brightness(.95); transform: translateY(-1px); }
.kr-send:disabled { opacity: .5; cursor: default; transform: none; }
.kr-send:focus-visible { outline: 2px solid var(--kr-navy); outline-offset: 2px; }

/* --- Pie --- */
.kr-foot {
    padding: .5rem 1rem .65rem;
    text-align: center;
    font-size: .7rem;
    color: var(--kr-ink-faint);
    background: var(--kr-surface);
    border-top: 1px solid var(--kr-line);
}
.kr-foot .kr-ref { color: var(--kr-navy); font-weight: 600; }

.kr-sr {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   MÓVIL
   ============================================================ */
@media (max-width: 480px) {
    #krAsistente { right: 16px; bottom: 16px; }
    .floating-call-uss { bottom: 90px !important; right: 16px !important; }

    .kr-launcher { width: 54px; height: 54px; }
    .kr-panel {
        width: calc(100vw - 24px);
        right: -4px;
        bottom: 66px;
        height: calc(100vh - 110px);
        max-height: 600px;
        border-radius: 18px;
    }
    .kr-bubble { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
    .kr-launcher::after { animation: none; }
    .kr-panel { animation: none; }
    .kr-typing span { animation: none; opacity: .7; }
    .kr-thread { scroll-behavior: auto; }
    .kr-launcher, .kr-chip, .kr-send { transition: none; }
}
