/* CTV Chat Widget — floating assistant panel */

.ctv-chat-fab {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 2100;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    border: none;
    background: var(--gradient, linear-gradient(135deg, #3b82f6, #2563eb));
    color: #fff;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.45);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ctv-chat-fab:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 24px rgba(59, 130, 246, 0.55);
}

.ctv-chat-fab.is-hidden {
    display: none;
}

.ctv-chat-panel {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 2100;
    width: 380px;
    max-width: calc(100vw - 1.5rem);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 8px 40px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ctv-chat-panel.is-hidden {
    display: none;
}

.ctv-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    background: var(--gradient, linear-gradient(135deg, #3b82f6, #2563eb));
    color: #fff;
    flex-shrink: 0;
}

.ctv-chat-header-title {
    font-weight: 600;
    font-size: 0.9375rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ctv-chat-header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
}

.ctv-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

.ctv-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 200px;
    max-height: calc(85vh - 160px);
    background: #f8fafc;
}

.ctv-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0.5rem 0.25rem 0.25rem;
    gap: 0.75rem;
}

.ctv-chat-welcome[hidden] {
    display: none !important;
}

.ctv-chat-welcome-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    color: var(--primary, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.ctv-chat-welcome-text {
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: #475569;
    max-width: 100%;
}

.ctv-chat-msg {
    max-width: 85%;
    padding: 0.625rem 0.875rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.ctv-chat-msg--user {
    align-self: flex-end;
    background: var(--primary, #3b82f6);
    color: #fff;
    border-bottom-right-radius: 0.25rem;
}

.ctv-chat-msg--bot {
    align-self: flex-start;
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 0.25rem;
}

.ctv-chat-msg--error {
    align-self: center;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    font-size: 0.8125rem;
    max-width: 95%;
    text-align: center;
}

.ctv-chat-loading {
    align-self: flex-start;
    display: flex;
    gap: 0.3rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    border-bottom-left-radius: 0.25rem;
}

.ctv-chat-loading span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #94a3b8;
    animation: ctv-chat-bounce 1.2s infinite ease-in-out;
}

.ctv-chat-loading span:nth-child(2) {
    animation-delay: 0.2s;
}

.ctv-chat-loading span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ctv-chat-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.ctv-chat-footer {
    padding: 0.75rem;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}

.ctv-chat-input-wrap {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.ctv-chat-textarea {
    flex: 1;
    resize: none;
    border: 1.5px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.4;
    max-height: 120px;
    font-family: inherit;
    transition: border-color 0.15s;
}

.ctv-chat-textarea:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
}

.ctv-chat-textarea:disabled {
    background: #f1f5f9;
    cursor: not-allowed;
}

.ctv-chat-send-btn {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.75rem;
    background: var(--primary, #3b82f6);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
}

.ctv-chat-send-btn:hover:not(:disabled) {
    background: var(--primary-dark, #2563eb);
}

.ctv-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ctv-chat-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: #94a3b8;
}

.ctv-chat-meta .ctv-chat-warn {
    color: #d97706;
}

.ctv-chat-meta .ctv-chat-over {
    color: #dc2626;
}

@media (max-width: 480px) {
    .ctv-chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 1rem 1rem 0 0;
        max-height: 90vh;
    }

    .ctv-chat-fab {
        bottom: 1rem;
        right: 1rem;
    }
}
