/* CPACF — Asistente virtual */
:root {
    --cpacf-navy: #001A5A;
    --cpacf-navy-light: #0a2d7a;
    --cpacf-gray-bar: #4c4c4c;
    --cpacf-accent: #343434;
    --cpacf-bg: #f7f8fa;
    --cpacf-white: #ffffff;
    --cpacf-shadow: 0 12px 40px rgba(0, 26, 90, 0.18);
    --cpacf-radius: 14px;
}

#cpacf-chat-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
}

#cpacf-chat-toggle {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--cpacf-navy) 0%, var(--cpacf-navy-light) 100%);
    color: var(--cpacf-white);
    box-shadow: var(--cpacf-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    outline: none;
}

#cpacf-chat-toggle:hover {
    transform: scale(1.06);
    box-shadow: 0 16px 48px rgba(0, 26, 90, 0.28);
}

#cpacf-chat-toggle.is-open {
    transform: rotate(0deg) scale(0.95);
}

#cpacf-chat-toggle .cpacf-chat-toggle-close {
    display: none;
}

#cpacf-chat-toggle.is-open .cpacf-chat-toggle-open {
    display: none;
}

#cpacf-chat-toggle.is-open .cpacf-chat-toggle-close {
    display: block;
}

#cpacf-chat-panel {
    position: absolute;
    bottom: 78px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: var(--cpacf-white);
    border-radius: var(--cpacf-radius);
    box-shadow: var(--cpacf-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
    transition: opacity 0.28s ease, transform 0.28s ease, visibility 0.28s;
    border: 1px solid rgba(0, 26, 90, 0.08);
}

#cpacf-chat-panel.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

#cpacf-chat-header {
    background: linear-gradient(135deg, var(--cpacf-navy) 0%, var(--cpacf-navy-light) 100%);
    color: var(--cpacf-white);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}

#cpacf-chat-header::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 18px;
    width: 72px;
    height: 3px;
    background: rgba(255, 255, 255, 0.35);
}

#cpacf-chat-header .cpacf-chat-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    padding: 3px;
    flex-shrink: 0;
}

#cpacf-chat-header-text h3 {
    margin: 0;
    font-family: Oswald, sans-serif;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.3px;
    line-height: 1.2;
}

#cpacf-chat-header-text p {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.82;
    line-height: 1.3;
}

.cpacf-chat-ws-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.cpacf-chat-ws-status.is-connected {
    background: #4cd964;
    box-shadow: 0 0 6px rgba(76, 217, 100, 0.6);
}

.cpacf-chat-ws-status.is-disconnected {
    background: rgba(255, 255, 255, 0.35);
}

#cpacf-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    background: var(--cpacf-bg);
    scroll-behavior: smooth;
}

#cpacf-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#cpacf-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 26, 90, 0.2);
    border-radius: 3px;
}

.cpacf-chat-welcome {
    text-align: center;
    padding: 24px 12px 8px;
    color: #5a6478;
}

.cpacf-chat-welcome i {
    font-size: 32px;
    color: var(--cpacf-navy);
    opacity: 0.7;
    margin-bottom: 10px;
}

.cpacf-chat-welcome h4 {
    font-family: Oswald, sans-serif;
    color: var(--cpacf-navy);
    font-size: 16px;
    margin: 0 0 6px;
}

.cpacf-chat-welcome p {
    font-size: 13px;
    margin: 0 0 14px;
    line-height: 1.45;
}

.cpacf-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 4px;
}

.cpacf-chat-suggestion {
    background: var(--cpacf-white);
    border: 1px solid rgba(0, 26, 90, 0.15);
    color: var(--cpacf-navy);
    font-size: 12px;
    padding: 7px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-family: Oswald, sans-serif;
    letter-spacing: 0.2px;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
    line-height: 1.2;
}

.cpacf-chat-suggestion:hover:not(:disabled) {
    background: var(--cpacf-navy);
    color: var(--cpacf-white);
    border-color: var(--cpacf-navy);
    transform: translateY(-1px);
}

.cpacf-chat-suggestion:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cpacf-chat-bubble-row {
    display: flex;
    margin-bottom: 12px;
    animation: cpacfChatFadeIn 0.3s ease;
}

.cpacf-chat-bubble-row.is-user {
    justify-content: flex-end;
}

.cpacf-chat-bubble-row.is-assistant {
    justify-content: flex-start;
}

.cpacf-chat-bubble {
    max-width: 85%;
    padding: 11px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.cpacf-chat-bubble-row.is-user .cpacf-chat-bubble {
    background: var(--cpacf-navy);
    color: var(--cpacf-white);
    border-bottom-right-radius: 4px;
}

.cpacf-chat-bubble-row.is-assistant .cpacf-chat-bubble {
    background: var(--cpacf-white);
    color: #2c3345;
    border: 1px solid #e4e8ef;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    white-space: normal;
}

.cpacf-chat-bubble a {
    color: var(--cpacf-navy);
    text-decoration: underline;
    word-break: break-word;
}

.cpacf-chat-bubble a:hover {
    color: var(--cpacf-navy-light);
}

.cpacf-chat-bubble strong {
    font-weight: 700;
}

.cpacf-chat-bubble-row.is-assistant {
    flex-direction: column;
    align-items: flex-start;
}

.cpacf-chat-feedback {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    margin-left: 4px;
}

.cpacf-chat-feedback-btn {
    background: transparent;
    border: 1px solid #d5dbe5;
    color: #6b7280;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.cpacf-chat-feedback-btn:hover:not(:disabled) {
    color: var(--cpacf-navy);
    border-color: var(--cpacf-navy);
    background: rgba(0, 26, 90, 0.04);
}

.cpacf-chat-feedback-btn.is-selected {
    color: var(--cpacf-navy);
    border-color: var(--cpacf-navy);
    background: rgba(0, 26, 90, 0.08);
}

.cpacf-chat-feedback-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

.cpacf-chat-feedback-thanks {
    font-size: 11px;
    color: #6b7280;
    font-style: italic;
}

.cpacf-chat-disclaimer {
    margin: 8px 0 0;
    font-size: 10.5px;
    color: #8a93a3;
    line-height: 1.35;
    text-align: center;
}

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

#cpacf-chat-toggle:focus,
#cpacf-chat-send:focus,
#cpacf-chat-input:focus,
#cpacf-chat-new:focus,
.cpacf-chat-suggestion:focus,
.cpacf-chat-feedback-btn:focus {
    outline: 2px solid var(--cpacf-navy);
    outline-offset: 2px;
}

.cpacf-chat-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: var(--cpacf-white);
    border: 1px solid #e4e8ef;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.cpacf-chat-typing span {
    width: 7px;
    height: 7px;
    background: var(--cpacf-navy);
    border-radius: 50%;
    opacity: 0.35;
    animation: cpacfChatBounce 1.2s infinite ease-in-out;
}

.cpacf-chat-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.cpacf-chat-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

#cpacf-chat-footer {
    padding: 12px 14px 14px;
    background: var(--cpacf-white);
    border-top: 1px solid #e8ecf2;
    flex-shrink: 0;
}

#cpacf-chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#cpacf-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #d5dbe5;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.4;
    max-height: 100px;
    min-height: 42px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

#cpacf-chat-input:focus {
    border-color: var(--cpacf-navy);
    box-shadow: 0 0 0 3px rgba(0, 26, 90, 0.1);
}

#cpacf-chat-send {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 10px;
    background: var(--cpacf-navy);
    color: var(--cpacf-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
}

#cpacf-chat-send:hover:not(:disabled) {
    background: var(--cpacf-navy-light);
    transform: scale(1.04);
}

#cpacf-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

#cpacf-chat-error {
    display: none;
    margin-top: 8px;
    padding: 8px 10px;
    background: #fff0f0;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    color: #842029;
    font-size: 12px;
    line-height: 1.4;
}

#cpacf-chat-error.is-visible {
    display: block;
}

#cpacf-chat-new {
    position: absolute;
    top: 14px;
    right: 14px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: var(--cpacf-white);
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    font-family: Oswald, sans-serif;
    letter-spacing: 0.3px;
    transition: background 0.2s;
}

#cpacf-chat-new:hover {
    background: rgba(255, 255, 255, 0.28);
}

@keyframes cpacfChatFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cpacfChatBounce {
    0%, 80%, 100% {
        transform: scale(0.7);
        opacity: 0.35;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 480px) {
    #cpacf-chat-root {
        bottom: 16px;
        right: 16px;
    }

    #cpacf-chat-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        bottom: 72px;
    }
}
