/* Chatbot widget — Damian Colombo
   Container fija abajo a la derecha, con burbuja minimizada y panel expandido. */

.cb-widget {
    --cb-bordo: #770000;
    --cb-bordo-dark: #5a0000;
    --cb-bg: #ffffff;
    --cb-fg: #2a2a2a;
    --cb-muted: #888;
    --cb-border: #e5e5e5;
    --cb-bg-soft: #fafafa;
    --cb-radius: 12px;
    --cb-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ============ BUBBLE (estado cerrado) ============ */
.cb-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--cb-bordo);
    color: white;
    border: none;
    box-shadow: var(--cb-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    padding: 0;
}
.cb-bubble:hover { background: var(--cb-bordo-dark); transform: scale(1.05); }
.cb-bubble svg { width: 28px; height: 28px; fill: currentColor; }
.cb-bubble.cb-hidden { display: none; }

/* ============ PANEL (estado abierto) ============ */
.cb-panel {
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 60px);
    background: var(--cb-bg);
    border-radius: var(--cb-radius);
    box-shadow: var(--cb-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: cb-fade-in 0.2s ease;
}
.cb-panel.cb-hidden { display: none; }

@keyframes cb-fade-in {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============ HEADER ============ */
.cb-header {
    background: var(--cb-bordo);
    color: white;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.cb-header-info { display: flex; flex-direction: column; }
.cb-header-title { font-weight: 600; font-size: 15px; }
.cb-header-subtitle { font-size: 11px; opacity: 0.85; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.cb-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3); }
.cb-header-actions { display: flex; gap: 4px; }
.cb-header button {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.85;
    border-radius: 4px;
    line-height: 1;
}
.cb-header button:hover { opacity: 1; background: rgba(255, 255, 255, 0.1); }

/* ============ MESSAGES ============ */
.cb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--cb-bg-soft);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cb-message {
    max-width: 85%;
    padding: 10px 13px;
    border-radius: 14px;
    line-height: 1.45;
    font-size: 14px;
    word-wrap: break-word;
}
.cb-message.user {
    background: var(--cb-bordo);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.cb-message.bot {
    background: white;
    color: var(--cb-fg);
    border: 1px solid var(--cb-border);
    border-bottom-left-radius: 4px;
}
.cb-message.bot p { margin: 0 0 8px 0; }
.cb-message.bot p:last-child { margin-bottom: 0; }
.cb-message.bot ul,
.cb-message.bot ol { margin: 4px 0 8px 0; padding-left: 22px; }
.cb-message.bot li { margin-bottom: 3px; }
.cb-message.bot h1,
.cb-message.bot h2,
.cb-message.bot h3,
.cb-message.bot h4 { margin: 10px 0 6px; font-weight: 600; font-size: 14px; }
.cb-message.bot hr { border: none; border-top: 1px solid var(--cb-border); margin: 10px 0; }
.cb-message.bot a { color: var(--cb-bordo); text-decoration: underline; }
.cb-message.bot strong { font-weight: 600; }
.cb-message.bot code { background: #f3f3f3; padding: 1px 5px; border-radius: 3px; font-size: 12px; }

.cb-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: white;
    border: 1px solid var(--cb-border);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    align-items: center;
}
.cb-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cb-muted);
    animation: cb-pulse 1.4s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: 0.2s; }
.cb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cb-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40%           { opacity: 1;   transform: scale(1); }
}

.cb-error {
    background: #fee;
    color: #900;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
}

/* ============ FORM ============ */
.cb-form {
    border-top: 1px solid var(--cb-border);
    padding: 12px;
    display: flex;
    gap: 8px;
    background: var(--cb-bg);
    flex-shrink: 0;
}
.cb-input {
    flex: 1;
    border: 1px solid var(--cb-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
}
.cb-input:focus  { border-color: var(--cb-bordo); }
.cb-input:disabled { background: #f5f5f5; }

.cb-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--cb-bordo);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.cb-send:hover { background: var(--cb-bordo-dark); }
.cb-send:disabled { background: #ccc; cursor: not-allowed; }
.cb-send svg { width: 18px; height: 18px; fill: currentColor; }

.cb-footer-text {
    text-align: center;
    padding: 6px 12px;
    font-size: 10px;
    color: var(--cb-muted);
    background: var(--cb-bg);
    border-top: 1px solid var(--cb-border);
    flex-shrink: 0;
}

/* ============ MOBILE ============ */
@media (max-width: 480px) {
    .cb-widget { bottom: 16px; right: 16px; }
    .cb-panel {
        position: fixed;
        bottom: 0; right: 0; left: 0; top: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}
