/* ============================================================
   Chatbot público de Tekmer (0.95.38)
   Botón flotante + panel de conversación. Usa los tokens del
   tema público cuando existen y cae a valores seguros.
   ============================================================ */

.chatbot-fab {
    position: fixed;
    right: 1.25rem;
    /* +20px sobre la posición original + safe-area iOS. */
    bottom: calc(1.25rem + 20px + env(safe-area-inset-bottom, 0px));
    z-index: 1080;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .7rem 1rem;
    border: 0;
    border-radius: 999px;
    background: var(--zen-primary, #416513);
    color: #fff;
    font: 600 .875rem/1.1 inherit;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .22);
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
.chatbot-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(15, 23, 42, .28); }
.chatbot-fab:focus-visible { outline: 2px solid var(--zen-primary, #416513); outline-offset: 3px; }
.chatbot-fab .bi { font-size: 1.1rem; }
.chatbot-fab.is-hidden { opacity: 0; pointer-events: none; transform: scale(.9); }

.chatbot-panel {
    position: fixed;
    right: 1.25rem;
    /* +20px sobre la posición original + safe-area iOS. */
    bottom: calc(1.25rem + 20px + env(safe-area-inset-bottom, 0px));
    z-index: 1085;
    display: flex;
    flex-direction: column;
    width: min(390px, calc(100vw - 2rem));
    /* Se descuentan los 20px de elevación para conservar el margen superior. */
    max-height: min(600px, calc(100vh - 3.75rem));
    max-height: min(600px, calc(100dvh - 3.75rem));
    border-radius: 1rem;
    overflow: hidden;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #1c1c21);
    border: 1px solid color-mix(in srgb, var(--bs-body-color, #1c1c21) 12%, transparent);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .30);
    transform-origin: bottom right;
    animation: chatbotIn .22s ease both;
}
.chatbot-panel[hidden] { display: none; }
@keyframes chatbotIn {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

.chatbot-head {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .8rem 1rem;
    background: var(--zen-primary, #416513);
    color: #fff;
}
.chatbot-head-avatar {
    width: 34px; height: 34px;
    border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .18);
    flex-shrink: 0;
}
.chatbot-head-title { font-weight: 600; font-size: .95rem; line-height: 1.2; }
.chatbot-head-sub { font-size: .72rem; opacity: .85; }
.chatbot-close {
    margin-left: auto;
    border: 0; background: transparent; color: #fff;
    width: 44px; height: 44px; border-radius: .5rem;
    cursor: pointer; line-height: 1;
    transition: background .15s ease;
}
.chatbot-close:hover { background: rgba(255, 255, 255, .16); }

.chatbot-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    background: color-mix(in srgb, var(--bs-body-bg, #fff) 96%, var(--zen-primary, #416513));
}

.chatbot-msg {
    max-width: 88%;
    padding: .55rem .8rem;
    border-radius: .9rem;
    font-size: .875rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    animation: chatbotMsg .18s ease both;
}
@keyframes chatbotMsg { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chatbot-msg.bot {
    align-self: flex-start;
    background: var(--bs-tertiary-bg, #f3f3f5);
    color: var(--bs-body-color, #1c1c21);
    border-bottom-left-radius: .25rem;
}
.chatbot-msg.user {
    align-self: flex-end;
    background: var(--zen-primary, #416513);
    color: #fff;
    border-bottom-right-radius: .25rem;
}
.chatbot-msg.error {
    align-self: flex-start;
    background: color-mix(in srgb, #dc3545 12%, transparent);
    color: #b02a37;
    border: 1px solid color-mix(in srgb, #dc3545 30%, transparent);
}

.chatbot-ai-activar {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    margin-top: .45rem;
    padding: .2rem .55rem;
    border: 1px solid color-mix(in srgb, var(--zen-primary, #416513) 45%, transparent);
    border-radius: 999px;
    background: transparent;
    color: var(--zen-primary, #416513);
    font: 600 .72rem/1.2 inherit;
    cursor: pointer;
}
.chatbot-ai-activar:hover { background: color-mix(in srgb, var(--zen-primary, #416513) 12%, transparent); }
.chatbot-ai-activar:disabled { opacity: .6; cursor: default; }

.chatbot-ai-badge {
    display: inline-block;
    margin-left: .4rem;
    padding: .05rem .35rem;
    border-radius: 999px;
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .04em;
    vertical-align: middle;
    background: color-mix(in srgb, var(--zen-primary, #416513) 16%, transparent);
    color: var(--zen-primary, #416513);
}

.chatbot-msg.bot ul, .chatbot-msg.bot ol { margin: .3rem 0 .3rem 1.1rem; padding-left: .9rem; }
.chatbot-msg.bot li { margin: .1rem 0; }
.chatbot-msg.bot code {
    background: color-mix(in srgb, currentColor 12%, transparent);
    padding: .05rem .28rem; border-radius: .25rem; font-size: .85em;
}
.chatbot-msg.bot pre.chatbot-code {
    background: #1e1e2e; color: #cdd6f4; border-radius: .45rem;
    padding: .5rem .65rem; overflow-x: auto; font-size: .78rem; margin: .35rem 0;
}
.chatbot-msg.bot pre.chatbot-code code { background: transparent; color: inherit; padding: 0; }
.chatbot-msg.bot a { color: inherit; text-decoration: underline; }
.chatbot-msg.bot strong.chatbot-h { display: block; margin: .35rem 0 .15rem; }

.chatbot-sources {
    margin-top: .5rem;
    padding-top: .45rem;
    border-top: 1px dashed color-mix(in srgb, currentColor 25%, transparent);
    display: flex;
    flex-direction: column;
    gap: .18rem;
    font-size: .75rem;
}
.chatbot-sources-title {
    font-weight: 700;
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    opacity: .65;
}
.chatbot-sources a {
    color: var(--zen-primary, #416513);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chatbot-sources a:hover { text-decoration: underline; }

.chatbot-typing { display: inline-flex; gap: .25rem; align-items: center; }
.chatbot-typing span {
    width: 6px; height: 6px; border-radius: 999px;
    background: currentColor; opacity: .45;
    animation: chatbotDot 1s infinite ease-in-out;
}
.chatbot-typing span:nth-child(2) { animation-delay: .15s; }
.chatbot-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatbotDot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.chatbot-foot {
    border-top: 1px solid color-mix(in srgb, var(--bs-body-color, #1c1c21) 10%, transparent);
    padding: .65rem .75rem .55rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    background: var(--bs-body-bg, #fff);
}
.chatbot-form { display: flex; gap: .5rem; align-items: flex-end; }
.chatbot-input {
    flex: 1 1 auto;
    resize: none;
    max-height: 110px;
    min-height: 40px;
    padding: .5rem .7rem;
    border-radius: .7rem;
    border: 1px solid color-mix(in srgb, var(--bs-body-color, #1c1c21) 16%, transparent);
    background: var(--bs-body-bg, #fff);
    color: inherit;
    font: .875rem/1.35 inherit;
}
.chatbot-input:focus { outline: 2px solid color-mix(in srgb, var(--zen-primary, #416513) 45%, transparent); outline-offset: 1px; }
.chatbot-send {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    border: 0; border-radius: .7rem;
    background: var(--zen-primary, #416513);
    color: #fff; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: filter .15s ease, opacity .15s ease;
}
.chatbot-send:hover { filter: brightness(1.08); }
.chatbot-send:disabled { opacity: .5; cursor: default; }
.chatbot-note {
    font-size: .68rem;
    text-align: center;
    color: var(--bs-secondary-color, #6c757d);
    margin: 0;
}
.chatbot-note .bi { font-size: .7rem; }

@media (max-width: 575.98px) {
    .chatbot-panel { right: .5rem; left: .5rem; bottom: calc(.5rem + 20px + env(safe-area-inset-bottom, 0px)); width: auto; max-height: calc(100vh - 2.25rem); max-height: calc(100dvh - 2.25rem); }
    .chatbot-fab { right: .75rem; bottom: calc(.75rem + 20px + env(safe-area-inset-bottom, 0px)); padding: .65rem .85rem; }
    .chatbot-fab span { display: none; }
    .chatbot-input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-panel, .chatbot-msg, .chatbot-fab { animation: none; transition: none; }
    .chatbot-typing span { animation: none; opacity: .7; }
}

/* Salvaguarda: bloqueo temporal del asistente por insistencia técnica. */
.chatbot-form.is-blocked { opacity: .6; }
.chatbot-blocked-note {
    margin: .55rem 0 0;
    padding: .55rem .7rem;
    border: 1px solid color-mix(in srgb, var(--bs-danger) 35%, transparent);
    border-radius: .55rem;
    background: color-mix(in srgb, var(--bs-danger) 8%, transparent);
    color: var(--bs-danger);
    font-size: .78rem;
    line-height: 1.4;
}
