/* ============================================================
   Chatbot Cívico – Widget Flotante
   Accesible · Responsive · prefers-reduced-motion
   ============================================================ */

/* ── Variables (sobrescritas por JS) ────────────────────────── */
:root {
    --cc-primary:       #1d4ed8;
    --cc-primary-dark:  #1e40af;
    --cc-primary-lt:    #eff6ff;
    --cc-on-primary:    #ffffff;
    --cc-bg:            #ffffff;
    --cc-bg-alt:        #f8fafc;
    --cc-user-bg:       var(--cc-primary);
    --cc-user-fg:       var(--cc-on-primary);
    --cc-bot-bg:        #f1f5f9;
    --cc-bot-fg:        #1e293b;
    --cc-border:        #e2e8f0;
    --cc-shadow:        0 8px 32px rgba(0,0,0,.18);
    --cc-radius-lg:     16px;
    --cc-radius-sm:     10px;
    --cc-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --cc-z:             999999;
    --cc-btn-size:      58px;
    --cc-win-w:         370px;
    --cc-win-h:         520px;
    --cc-anim-dur:      .28s;
}

/* ════════════════════════════════════════════════════════════
   Root container
   ════════════════════════════════════════════════════════════ */
#civic-chatbot-root {
    position: fixed;
    z-index: var(--cc-z);
    font-family: var(--cc-font);
    font-size: 15px;
    line-height: 1.5;
    box-sizing: border-box;
}
#civic-chatbot-root *,
#civic-chatbot-root *::before,
#civic-chatbot-root *::after { box-sizing: inherit; }

/* ── Positions ── */
.cc-widget--bottom-right { bottom: 24px; right: 24px; }
.cc-widget--bottom-left  { bottom: 24px; left:  24px; }

/* ════════════════════════════════════════════════════════════
   Botón flotante
   ════════════════════════════════════════════════════════════ */
.cc-toggle-btn {
    width:  var(--cc-btn-size);
    height: var(--cc-btn-size);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--cc-primary);
    color: var(--cc-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(29,78,216,.45);
    transition:
        transform var(--cc-anim-dur) ease,
        background var(--cc-anim-dur) ease,
        box-shadow var(--cc-anim-dur) ease;
    position: relative;
    z-index: 1;
    /* Ripple */
    overflow: hidden;
}
.cc-toggle-btn::after {
    content: '';
    position: absolute;
    inset: -0;
    border-radius: 50%;
    border: 2px solid var(--cc-primary);
    opacity: .5;
    animation: cc-pulse 2.5s infinite;
}
.cc-toggle-btn:hover {
    background: var(--cc-primary-dark);
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(29,78,216,.55);
}
.cc-toggle-btn:focus-visible {
    outline: 3px solid var(--cc-primary);
    outline-offset: 3px;
}

@keyframes cc-pulse {
    0%   { transform: scale(1);   opacity: .5; }
    70%  { transform: scale(1.5); opacity: 0;  }
    100% { transform: scale(1.5); opacity: 0;  }
}

/* ════════════════════════════════════════════════════════════
   Ventana de chat
   ════════════════════════════════════════════════════════════ */
.cc-chat-window {
    position: absolute;
    bottom: calc(var(--cc-btn-size) + 14px);
    width: var(--cc-win-w);
    height: var(--cc-win-h);
    background: var(--cc-bg);
    border-radius: var(--cc-radius-lg);
    box-shadow: var(--cc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Hidden state */
    opacity: 0;
    pointer-events: none;
    transform: translateY(24px) scale(.96);
    transform-origin: bottom center;
    transition:
        opacity var(--cc-anim-dur) ease,
        transform var(--cc-anim-dur) ease;
}
.cc-widget--bottom-right .cc-chat-window { right: 0; }
.cc-widget--bottom-left  .cc-chat-window { left:  0; }

/* Visible */
.cc-chat-window--open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0) scale(1);
}

/* ── Header ── */
.cc-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--cc-primary);
    color: var(--cc-on-primary);
    flex-shrink: 0;
}
.cc-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.18);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.cc-header-title    { font-weight: 700; font-size: .95rem; }
.cc-header-subtitle { font-size: .72rem; opacity: .82; }
.cc-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.cc-close-btn, .cc-clear-btn {
    background: transparent;
    border: none;
    color: var(--cc-on-primary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    opacity: .8;
    transition: opacity .15s, background .15s;
}
.cc-close-btn:hover, .cc-clear-btn:hover { opacity: 1; background: rgba(255,255,255,.2); }
.cc-close-btn:focus-visible, .cc-clear-btn:focus-visible { outline: 2px solid rgba(255,255,255,.6); }

/* ── Área de mensajes ── */
.cc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--cc-border) transparent;
    background: var(--cc-bg-alt);
}
.cc-messages::-webkit-scrollbar       { width: 4px; }
.cc-messages::-webkit-scrollbar-thumb { background: var(--cc-border); border-radius: 4px; }

/* ── Burbujas de mensaje ── */
.cc-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: cc-msg-in .2s ease both;
}
.cc-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.cc-msg--bot  { align-self: flex-start; }

@keyframes cc-msg-in {
    from { opacity: 0; transform: translateY(8px) scale(.96); }
    to   { opacity: 1; transform: none; }
}

.cc-msg-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--cc-primary-lt);
    color: var(--cc-primary);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.cc-msg-bubble {
    padding: 10px 14px;
    border-radius: var(--cc-radius-sm);
    font-size: .9rem;
    line-height: 1.55;
    word-break: break-word;
}
.cc-msg--user .cc-msg-bubble {
    background: var(--cc-user-bg);
    color: var(--cc-user-fg);
    border-bottom-right-radius: 4px;
}
.cc-msg--bot .cc-msg-bubble {
    background: var(--cc-bot-bg);
    color: var(--cc-bot-fg);
    border-bottom-left-radius: 4px;
}

.cc-msg-text { margin: 0; white-space: pre-wrap; }

/* ── Fuentes / Source attribution ── */
.cc-sources { margin-top: 10px; border-top: 1px solid rgba(0,0,0,.08); padding-top: 8px; }
.cc-sources-title { font-size: .75rem; font-weight: 600; color: var(--cc-primary); margin: 0 0 4px; }
.cc-sources-list  { margin: 0; padding-left: 16px; list-style: disc; }
.cc-sources-list li { font-size: .75rem; margin-bottom: 2px; }
.cc-sources-list a  {
    color: var(--cc-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.cc-sources-list a:hover  { color: var(--cc-primary-dark); }
.cc-sources-list a:focus-visible {
    outline: 2px solid var(--cc-primary);
    border-radius: 2px;
    outline-offset: 1px;
}

/* ── Indicador de escritura ── */
.cc-typing {
    padding: 12px 16px;
    display: flex;
    gap: 5px;
    align-items: center;
}
.cc-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--cc-primary);
    opacity: .4;
    animation: cc-dot-bounce .9s ease infinite;
}
.cc-typing span:nth-child(2) { animation-delay: .15s; }
.cc-typing span:nth-child(3) { animation-delay: .30s; }

@keyframes cc-dot-bounce {
    0%, 80%, 100% { transform: translateY(0);   opacity: .4; }
    40%           { transform: translateY(-6px); opacity: 1;  }
}

/* ════════════════════════════════════════════════════════════
   Formulario de entrada
   ════════════════════════════════════════════════════════════ */
.cc-form {
    padding: 10px 12px 12px;
    background: var(--cc-bg);
    border-top: 1px solid var(--cc-border);
    flex-shrink: 0;
}
.cc-input-area {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.cc-input {
    flex: 1;
    padding: 9px 13px;
    border: 1.5px solid var(--cc-border);
    border-radius: 22px;
    font-family: var(--cc-font);
    font-size: .9rem;
    line-height: 1.45;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color .2s;
    background: var(--cc-bg-alt);
    color: var(--cc-bot-fg);
}
.cc-input:focus {
    outline: none;
    border-color: var(--cc-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.cc-input::placeholder { color: #94a3b8; }

.cc-send-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--cc-primary);
    color: var(--cc-on-primary);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .2s, transform .15s;
}
.cc-send-btn:hover:not(:disabled) {
    background: var(--cc-primary-dark);
    transform: scale(1.07);
}
.cc-send-btn:disabled { background: var(--cc-border); cursor: not-allowed; }
.cc-send-btn:focus-visible {
    outline: 3px solid var(--cc-primary);
    outline-offset: 2px;
}

.cc-char-counter {
    font-size: .7rem;
    color: #94a3b8;
    text-align: right;
    margin-top: 4px;
    padding-right: 4px;
}

/* ── Sugerencias Autocomplete ── */
.cc-suggestions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    background: var(--cc-bg);
    border-top: 1px solid var(--cc-border);
    max-height: 150px;
    overflow-y: auto;
}
.cc-suggestion-item {
    padding: 6px 10px;
    background: var(--cc-bot-bg);
    border-radius: var(--cc-radius-sm);
    font-size: .8rem;
    cursor: pointer;
    transition: background .2s, transform .1s;
    border: 1px solid transparent;
}
.cc-suggestion-item:hover {
    background: var(--cc-primary-lt);
    border-color: var(--cc-primary);
    color: var(--cc-primary);
    transform: translateX(4px);
}
.cc-suggestion-item:active { transform: scale(.98); }

/* ════════════════════════════════════════════════════════════
   Responsive – pantalla completa en móvil
   ════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .cc-widget--bottom-right,
    .cc-widget--bottom-left {
        bottom: 0;
        right:  0;
        left:   0;
    }
    .cc-toggle-btn {
        position: fixed;
        bottom: 20px;
        right:  20px;
    }
    .cc-widget--bottom-left .cc-toggle-btn {
        right: auto;
        left: 20px;
    }
    .cc-chat-window {
        position: fixed;
        inset: 0;
        width:  100%;
        height: 100%;
        border-radius: 0;
        bottom: auto;
    }
    .cc-messages { padding: 12px; }
}

/* ════════════════════════════════════════════════════════════
   prefers-reduced-motion
   ════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    .cc-toggle-btn,
    .cc-toggle-btn::after,
    .cc-chat-window,
    .cc-msg,
    .cc-send-btn { animation: none !important; transition: none !important; }
    .cc-typing span { animation: none !important; opacity: .7; }
}

/* ════════════════════════════════════════════════════════════
   High-contrast / forced-colors
   ════════════════════════════════════════════════════════════ */
@media (forced-colors: active) {
    .cc-toggle-btn { forced-color-adjust: none; }
    .cc-msg--user .cc-msg-bubble { border: 1px solid ButtonText; }
}
