/* ============================================================
   Movi Player — AI Chat Panel Styles (YouTube Live Chat Style)
   File: styles/ai-chat.css
   ============================================================ */

/* ── Container Layout when AI Chat is visible ── */
.container.ai-chat-active {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 12px;
    padding: 12px;
    box-sizing: border-box;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

.container.ai-chat-active #video-container {
    flex: 1;
    min-width: 0;
    height: 100%;
    margin-bottom: 0;
    position: relative;
}

/* Hide the original floating settings gear when the chat is active */
body:has(.container.ai-chat-active) > .top-settings-btn {
    display: none !important;
}

/* ── Panel Drawer ── */
#ai-chat-panel {
    display: none;
    width: 340px;
    min-width: 280px;
    max-width: 400px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #13151e 0%, #0f1117 100%);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    z-index: 90;
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1),
                min-width 0.4s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.35s ease;
    position: relative;
}

.container.ai-chat-active #ai-chat-panel {
    display: flex;
}

/* ── Collapsed State ── */
.ai-chat-collapsed-strip {
    display: none; /* hidden when NOT collapsed */
}

#ai-chat-panel.ai-chat-collapsed {
    width: 36px;
    min-width: 36px;
    background: linear-gradient(180deg, #13151e 0%, #0f1117 100%);
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

#ai-chat-panel.ai-chat-collapsed > *:not(.ai-chat-collapsed-strip) {
    display: none !important;
}

#ai-chat-panel.ai-chat-collapsed .ai-chat-collapsed-strip {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: flex-start;
    padding-top: 16px;
    gap: 16px;
    color: #6b7280;
}

.ai-chat-collapsed-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s ease;
    color: inherit;
}

.ai-chat-collapsed-btn:hover {
    color: #a5b4fc;
}

.ai-chat-collapsed-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ── Header ── */
.ai-chat-header {
    height: 48px;
    min-height: 48px;
    padding: 0 12px 0 14px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    user-select: none;
}

.ai-chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-header-icon {
    width: 18px;
    height: 18px;
    fill: #818cf8;
}

.ai-chat-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #e5e7eb;
    letter-spacing: -0.01em;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-chat-icon-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #d1d5db;
}

.ai-chat-icon-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ── Subtitle Context Banner ── */
.ai-context-banner {
    padding: 5px 14px;
    background: rgba(16, 185, 129, 0.06);
    border-bottom: 1px solid rgba(16, 185, 129, 0.1);
    display: flex;
    align-items: center;
    font-size: 0.72rem;
    color: #34d399;
    flex-shrink: 0;
}

.ai-context-banner-text {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-context-banner-text svg {
    width: 13px;
    height: 13px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ── Messages Body ── */
.ai-chat-messages {
    flex: 1;
    padding: 16px 14px;
    box-sizing: border-box;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    min-height: 0;
}

/* Empty state */
.ai-chat-messages:empty::after,
.ai-chat-empty-state {
    color: #4b5563;
    text-align: center;
    font-size: 0.82rem;
    line-height: 1.5;
}

.ai-chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    padding: 32px 24px;
}

.ai-chat-empty-state svg {
    width: 40px;
    height: 40px;
    fill: #374151;
    opacity: 0.6;
}

.ai-chat-empty-state .ai-empty-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #6b7280;
}

.ai-chat-empty-state .ai-empty-desc {
    font-size: 0.78rem;
    color: #4b5563;
    max-width: 220px;
}

/* Scrollbar */
.ai-chat-messages::-webkit-scrollbar {
    width: 5px;
}
.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ── Message Rows ── */
.ai-msg-row {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: aiFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.ai-msg-row.user {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-msg-row.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

/* ── Bubbles ── */
.ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.84rem;
    line-height: 1.55;
    word-break: break-word;
}

.ai-msg-row.user .ai-msg-bubble {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.ai-msg-row.assistant .ai-msg-bubble {
    background: rgba(255, 255, 255, 0.04);
    color: #d1d5db;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-bottom-left-radius: 4px;
}

.ai-msg-meta {
    font-size: 0.65rem;
    color: #4b5563;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
}

.ai-msg-badge {
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    color: #6b7280;
}

/* ── Markdown inside bubbles ── */
.ai-msg-bubble p {
    margin: 0 0 6px 0;
}
.ai-msg-bubble p:last-child {
    margin-bottom: 0;
}

.ai-msg-bubble code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 5px;
    border-radius: 4px;
    color: #a5b4fc;
}

.ai-msg-bubble pre {
    background: #090a0f;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px;
    overflow-x: auto;
    margin: 6px 0;
    position: relative;
}

.ai-msg-bubble pre code {
    background: transparent;
    padding: 0;
    color: #e2e8f0;
    display: block;
}

.ai-code-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #6b7280;
    font-size: 0.65rem;
    padding: 2px 7px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.ai-code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #d1d5db;
}

/* ── Typing indicator ── */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background: #818cf8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40%           { transform: scale(1); opacity: 1; }
}

/* ── Footer / Input ── */
.ai-chat-footer {
    padding: 10px 12px 12px;
    background: rgba(0, 0, 0, 0.15);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

/* Toolbar row */
.ai-chat-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-toolbar-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Icon-only toggle buttons */
.ai-toggle-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
}

.ai-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #d1d5db;
    border-color: rgba(255, 255, 255, 0.12);
}

.ai-toggle-btn.active {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
    border-color: rgba(99, 102, 241, 0.35);
}

.ai-toggle-btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.ai-toggle-btn svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

/* Model badge (in footer toolbar) */
.ai-chat-model-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0 10px;
    height: 30px;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.1);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.2);
    white-space: nowrap;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    user-select: none;
}

/* Input row */
.ai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 6px 6px 6px 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-input-row:focus-within {
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.08);
}

.ai-chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e5e7eb;
    font-size: 0.85rem;
    line-height: 1.45;
    padding: 5px 0;
    resize: none;
    max-height: 90px;
    min-height: 24px;
    font-family: inherit;
}

.ai-chat-input::placeholder {
    color: #4b5563;
}

.ai-send-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: #6366f1;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.ai-send-btn:hover {
    background: #4f46e5;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.ai-send-btn:disabled {
    background: rgba(255, 255, 255, 0.06);
    color: #4b5563;
    cursor: not-allowed;
    box-shadow: none;
}

.ai-send-btn svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

/* ── API Key Missing Notice (legacy) ── */
.ai-key-missing-notice {
    padding: 16px;
    background: rgba(239, 68, 68, 0.06);
    border: 1px solid rgba(239, 68, 68, 0.15);
    border-radius: 10px;
    margin: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: #fca5a5;
    font-size: 0.82rem;
}

.ai-key-missing-btn {
    background: #ef4444;
    color: #fff;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.78rem;
    align-self: flex-start;
}
.ai-key-missing-btn:hover {
    background: #dc2626;
}

/* ── Responsive (mobile) ── */
@media (max-width: 900px) {
    .container.ai-chat-active {
        flex-direction: column;
        padding: 0;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .container.ai-chat-active #video-container {
        height: auto;
    }

    #ai-chat-panel {
        width: 100% !important;
        max-width: none;
        min-width: 0;
        height: 400px;
        border-radius: 14px 14px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }
}
