/* CCTXV Chat Widget — shared styles (no Tailwind). */

#cctxv-chat-root {
    --ccx-primary: #2563eb;
    --ccx-primary-dark: #1d4ed8;
    --ccx-primary-darker: #1e40af;
    --ccx-bg: #ffffff;
    --ccx-bg-soft: #f8fafc;
    --ccx-text: #111827;
    --ccx-text-soft: #4b5563;
    --ccx-border: #e5e7eb;
    --ccx-bot-bubble: #f3f4f6;
    --ccx-input-bg: #ffffff;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    position: fixed;
    inset: auto 0 0 auto;
    z-index: 60;
    pointer-events: none;
}

/* Self-contained reset: do not depend on the host page's box-sizing */
#cctxv-chat-root,
#cctxv-chat-root *,
#cctxv-chat-root *::before,
#cctxv-chat-root *::after { box-sizing: border-box; }
#cctxv-chat-root h3,
#cctxv-chat-root p { margin: 0; }
#cctxv-chat-root button,
#cctxv-chat-root input { font: inherit; }

html.dark #cctxv-chat-root {
    --ccx-bg: #0f172a;
    --ccx-bg-soft: #1e293b;
    --ccx-text: #f1f5f9;
    --ccx-text-soft: #cbd5e1;
    --ccx-border: #334155;
    --ccx-bot-bubble: #1e293b;
    --ccx-input-bg: #1e293b;
}

#cctxv-chat-root > * { pointer-events: auto; }

#cctxv-chat-root .ccx-hidden { display: none !important; }

/* ---------- Launcher ---------- */
#cctxv-chat-toggle {
    position: fixed; bottom: 20px; right: 20px;
    width: 56px; height: 56px; border-radius: 999px;
    background: var(--ccx-primary); color: #fff; border: 0; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; box-shadow: 0 10px 25px rgba(37, 99, 235, .35);
    transition: transform .2s, background .2s;
}
#cctxv-chat-toggle:hover { background: var(--ccx-primary-dark); transform: scale(1.05); }
#cctxv-chat-toggle:active { transform: scale(.95); }
#cctxv-chat-toggle:focus-visible { outline: 3px solid rgba(37, 99, 235, .45); outline-offset: 2px; }

.ccx-toggle-badge { position: absolute; top: 2px; right: 2px; width: 14px; height: 14px; display: flex; }
.ccx-toggle-dot {
    position: relative; width: 14px; height: 14px; border-radius: 999px;
    background: #22c55e; border: 2px solid var(--ccx-bg);
}
.ccx-ping {
    position: absolute; inset: 0; border-radius: 999px; background: #4ade80;
    opacity: .75; animation: ccx-ping 1.6s cubic-bezier(0, 0, .2, 1) infinite;
}
@keyframes ccx-ping { 75%, 100% { transform: scale(2); opacity: 0; } }

/* ---------- Floating prompt bubble ---------- */
#cctxv-chat-bubble {
    position: fixed; bottom: 88px; right: 20px;
    display: flex; align-items: center; gap: 8px;
    background: var(--ccx-bg); color: var(--ccx-text);
    border: 1px solid var(--ccx-border); border-radius: 16px;
    padding: 8px 14px; font-size: 12px; font-weight: 600;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .15);
    cursor: pointer; transition: opacity .25s, transform .25s;
}
#cctxv-chat-bubble:hover { box-shadow: 0 16px 36px rgba(15, 23, 42, .2); }
#cctxv-chat-bubble button {
    background: none; border: 0; color: var(--ccx-text-soft); cursor: pointer;
    font-size: 16px; line-height: 1; padding: 0 0 0 4px;
    min-width: 24px; min-height: 24px; display: inline-flex;
    align-items: center; justify-content: center;
}
.ccx-dot { width: 9px; height: 9px; border-radius: 999px; background: #22c55e; display: inline-block; }
.ccx-dot--pulse { animation: ccx-pulse 1.8s ease-in-out infinite; }
@keyframes ccx-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Window ---------- */
#cctxv-chat-window {
    position: fixed; bottom: calc(88px + env(safe-area-inset-bottom, 0px)); right: 20px;
    width: 390px; max-width: calc(100vw - 24px);
    height: 550px; max-height: min(82vh, 82dvh);
    background: var(--ccx-bg); color: var(--ccx-text);
    border: 1px solid var(--ccx-border); border-radius: 16px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; transform: translateY(10px) scale(.97); transform-origin: bottom right;
    transition: opacity .25s ease, transform .25s ease;
}
#cctxv-chat-window.ccx-open { opacity: 1; transform: translateY(0) scale(1); }

.ccx-header {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 12px 14px; color: #fff;
    background: linear-gradient(120deg, var(--ccx-primary-darker), var(--ccx-primary), var(--ccx-primary-darker));
    user-select: none;
}
.ccx-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ccx-avatar {
    position: relative; width: 36px; height: 36px; border-radius: 999px; flex: 0 0 auto;
    background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .22);
    display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.ccx-avatar-dot {
    position: absolute; right: 0; bottom: 0; width: 9px; height: 9px; border-radius: 999px;
    background: #4ade80; border: 2px solid var(--ccx-primary-darker);
}
.ccx-header h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccx-status { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #dbeafe; font-weight: 500; }
.ccx-status .ccx-dot { width: 6px; height: 6px; background: #4ade80; }
.ccx-header-actions { display: flex; align-items: center; gap: 2px; }
.ccx-header-actions a,
.ccx-header-actions button {
    width: 30px; height: 30px; border-radius: 8px; border: 0; cursor: pointer;
    background: none; color: rgba(255, 255, 255, .9);
    display: flex; align-items: center; justify-content: center; font-size: 12px;
    text-decoration: none;
}
.ccx-header-actions a:hover,
.ccx-header-actions button:hover { background: rgba(255, 255, 255, .16); color: #fff; }

.ccx-quickbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 12px; font-size: 11px;
    background: var(--ccx-bg-soft); border-bottom: 1px solid var(--ccx-border);
    color: var(--ccx-text-soft);
}
.ccx-quickbar a { text-decoration: none; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.ccx-quickbar-sms { color: #2563eb; }
.ccx-quickbar-tel { color: var(--ccx-primary); }
.ccx-sep { color: var(--ccx-border); }

#cctxv-chat-messages {
    flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 14px;
    display: flex; flex-direction: column; gap: 10px;
    font-size: 14px; scroll-behavior: smooth;
}
.ccx-msg { display: flex; flex-direction: column; animation: ccx-in .22s ease both; }
@keyframes ccx-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.ccx-msg--user { align-items: flex-end; }
.ccx-msg--bot { align-items: flex-start; }
.ccx-msg-bubble {
    max-width: 88%; padding: 9px 13px; line-height: 1.5;
    border-radius: 16px; box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
    overflow-wrap: anywhere;
}
.ccx-msg--user .ccx-msg-bubble {
    background: var(--ccx-primary); color: #fff;
    border-top-right-radius: 4px; max-width: 85%;
}
.ccx-msg--bot .ccx-msg-bubble {
    background: var(--ccx-bot-bubble); color: var(--ccx-text);
    border-top-left-radius: 4px; border: 1px solid var(--ccx-border);
}

.ccx-link { color: var(--ccx-primary); font-weight: 600; text-decoration: underline; }
.ccx-link--sms,
.ccx-link--tel {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--ccx-primary); color: #fff !important; text-decoration: none !important;
    padding: 5px 11px; margin: 2px 0; border-radius: 9px; font-size: 12px; font-weight: 600;
}
.ccx-link--sms { background: #2563eb; }
.ccx-link--tel { background: var(--ccx-primary-dark); }

#cctxv-chat-chips {
    display: flex; gap: 6px; padding: 4px 12px 8px;
    overflow-x: auto; white-space: nowrap; scrollbar-width: none;
}
#cctxv-chat-chips::-webkit-scrollbar { display: none; }
.ccx-chip {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 500; padding: 5px 10px;
    border-radius: 999px; cursor: pointer; text-decoration: none;
    background: var(--ccx-bg-soft); color: var(--ccx-text-soft);
    border: 1px solid var(--ccx-border);
}
.ccx-chip:hover { background: var(--ccx-border); }
.ccx-chip:focus-visible, .ccx-quickbar a:focus-visible, .ccx-header-actions a:focus-visible,
.ccx-header-actions button:focus-visible { outline: 2px solid var(--ccx-primary); outline-offset: 2px; }
.ccx-chip--primary { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
html.dark .ccx-chip--primary { background: rgba(37, 99, 235, .18); color: #93c5fd; border-color: rgba(37, 99, 235, .4); }
.ccx-chip--sms { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

#cctxv-chat-typing {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 14px 6px; font-size: 12px; font-style: italic; color: var(--ccx-text-soft);
}
.ccx-typing-dots { display: inline-flex; gap: 3px; }
.ccx-typing-dots span {
    width: 5px; height: 5px; border-radius: 999px; background: var(--ccx-primary);
    animation: ccx-bounce 1.2s infinite;
}
.ccx-typing-dots span:nth-child(2) { animation-delay: -.15s; }
.ccx-typing-dots span:nth-child(3) { animation-delay: -.3s; }
@keyframes ccx-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .6; } 40% { transform: translateY(-4px); opacity: 1; } }

#cctxv-chat-form {
    display: flex; align-items: center; gap: 8px;
    padding: 10px; border-top: 1px solid var(--ccx-border);
    background: var(--ccx-bg-soft);
}
#cctxv-chat-input {
    flex: 1 1 auto; min-width: 0;
    padding: 8px 12px; font-size: 14px;
    background: var(--ccx-input-bg); color: var(--ccx-text);
    border: 1px solid var(--ccx-border); border-radius: 12px; outline: none;
}
#cctxv-chat-input::placeholder { color: #9ca3af; }
#cctxv-chat-input:focus { border-color: var(--ccx-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
#cctxv-chat-send {
    flex: 0 0 auto;
    width: 38px; height: 38px; border-radius: 12px; border: 0; cursor: pointer;
    background: var(--ccx-primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 13px;
}
#cctxv-chat-send:hover { background: var(--ccx-primary-dark); }
#cctxv-chat-send:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 480px) {
    #cctxv-chat-window {
        right: 12px; bottom: calc(84px + env(safe-area-inset-bottom, 0px));
        width: calc(100vw - 24px); height: 78vh; height: 78dvh;
    }
    #cctxv-chat-bubble { right: 12px; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 90px); }
    #cctxv-chat-toggle { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
    /* objetivos táctiles de 44px en móvil */
    .ccx-header-actions a, .ccx-header-actions button { width: 44px; height: 44px; font-size: 14px; }
    /* SMS/tel ya están en la barra de abajo: liberamos espacio para el título */
    .ccx-header-actions a { display: none; }
    .ccx-chip { min-height: 44px; padding: 10px 13px; }
    #cctxv-chat-send { width: 44px; height: 44px; }
    #cctxv-chat-input { min-height: 44px; font-size: 16px; } /* 16px evita el zoom de iOS */
}

@media (prefers-reduced-motion: reduce) {
    #cctxv-chat-window, #cctxv-chat-toggle, #cctxv-chat-bubble { transition: none; }
    .ccx-ping, .ccx-dot--pulse, .ccx-typing-dots span { animation: none; }
}

#cctxv-chat-messages::-webkit-scrollbar { width: 8px; }
#cctxv-chat-messages::-webkit-scrollbar-thumb { background: var(--ccx-border); border-radius: 999px; }
#cctxv-chat-messages::-webkit-scrollbar-track { background: transparent; }
