/* ========================================
   Cineva AI Chat Widget Styles
======================================== */

/* Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    font-family: 'Outfit', sans-serif;
}

/* Floating Chat Bubble */
.chat-bubble {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 4px 24px rgba(0, 0, 0, 0.2),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset,
        0 1px 1px rgba(255, 255, 255, 0.1) inset;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.3s ease,
                background 0.3s ease,
                border-color 0.3s ease;
}

.chat-bubble:hover {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset,
        0 1px 2px rgba(255, 255, 255, 0.15) inset;
}

.chat-bubble svg {
    width: 22px;
    height: 22px;
    color: rgba(255, 255, 255, 0.9);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.3s ease;
}

.chat-bubble .chat-icon {
    position: absolute;
}

.chat-bubble .close-icon {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.8);
}

.chat-widget.is-open .chat-bubble .chat-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.8);
}

.chat-widget.is-open .chat-bubble .close-icon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Chat Panel */
.chat-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 520px;
    background: #0a0a0a;
    border: 1px solid #222222;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.3s ease,
                visibility 0.3s ease,
                transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
}

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

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: #111111;
    border-bottom: 1px solid #222222;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #ffffff;
    color: #0a0a0a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 1rem;
}

.chat-header-text {
    display: flex;
    flex-direction: column;
}

.chat-title {
    font-family: 'Syne', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    color: #ffffff;
}

.chat-subtitle {
    font-size: 0.75rem;
    color: #888888;
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-close,
.chat-reset {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid #333333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-close:hover,
.chat-reset:hover {
    background: #222222;
    border-color: #444444;
}

.chat-close svg,
.chat-reset svg {
    width: 16px;
    height: 16px;
    color: #888888;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    padding-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0; /* Important for flex shrinking */
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #333333;
    border-radius: 2px;
}

/* Chat Message */
.chat-message {
    display: flex;
    max-width: 85%;
}

.chat-message-user {
    align-self: flex-end;
}

.chat-message-assistant {
    align-self: flex-start;
}

.chat-message-content {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.5;
}

.chat-message-user .chat-message-content {
    background: #ffffff;
    color: #0a0a0a;
    border-bottom-right-radius: 4px;
}

.chat-message-assistant .chat-message-content {
    background: #1a1a1a;
    color: #ffffff;
    border-bottom-left-radius: 4px;
}

/* Markdown styles in messages */
.chat-message-content strong {
    font-weight: 600;
    color: #ffffff;
}

.chat-message-content em {
    font-style: italic;
}

.chat-message-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.85em;
}

.chat-message-content a {
    color: #ffffff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-message-content a:hover {
    opacity: 0.8;
}

.chat-message-user .chat-message-content a {
    color: #0a0a0a;
}

/* Streaming cursor effect */
.chat-message.is-streaming .chat-message-content::after {
    content: '▊';
    animation: blink 1s infinite;
    margin-left: 2px;
    color: #888888;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Typing Indicator */
.chat-typing .chat-message-content {
    padding: 0.75rem 1.25rem;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #555555;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        background: #555555;
    }
    30% {
        transform: translateY(-4px);
        background: #888888;
    }
}

/* Chat Actions (Quick Action Buttons) */
.chat-actions {
    display: none;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #0f0f0f;
    border-top: 1px solid #1a1a1a;
    flex-wrap: wrap;
    flex-shrink: 0; /* Don't shrink the actions bar */
}

.chat-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #1a1a1a;
    border: 1px solid #333333;
    border-radius: 20px;
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-action-btn:hover {
    background: #252525;
    border-color: #444444;
}

.chat-action-btn svg {
    flex-shrink: 0;
    color: #888888;
}

.chat-action-btn .action-value {
    color: #888888;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* System Messages */
.chat-message-system {
    align-self: center;
    max-width: 90%;
}

.chat-message-system .chat-message-content {
    background: transparent;
    color: #888888;
    font-size: 0.8rem;
    text-align: center;
    padding: 0.5rem 1rem;
    border: 1px dashed #333333;
    border-radius: 8px;
}

.chat-message-system.chat-message-warning .chat-message-content {
    color: #f0ad4e;
    border-color: #5c4a1e;
    background: rgba(240, 173, 78, 0.1);
}

/* Chat Input Form */
.chat-input-form {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    background: #111111;
    border-top: 1px solid #222222;
}

.chat-input-wrapper {
    flex: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-right: 3rem;
    background: #1a1a1a;
    border: 1px solid #333333;
    border-radius: 24px;
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-char-counter {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: #555555;
    display: none;
    pointer-events: none;
}

.chat-char-counter.warning {
    color: #f0ad4e;
}

.chat-char-counter.error {
    color: #dc3545;
}

.chat-input::placeholder {
    color: #555555;
}

.chat-input:focus {
    border-color: #555555;
}

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

.chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.chat-send:hover {
    transform: scale(1.05);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-send svg {
    width: 18px;
    height: 18px;
    color: #0a0a0a;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 1rem;
        right: 1rem;
    }

    .chat-bubble {
        width: 48px;
        height: 48px;
    }

    .chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }

    .chat-widget.is-open .chat-bubble {
        opacity: 0;
        pointer-events: none;
    }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .chat-bubble,
    .chat-panel,
    .chat-bubble svg,
    .chat-message.is-streaming .chat-message-content::after {
        transition: none;
        animation: none;
    }
    
    .typing-dots span {
        animation: none;
    }
}
