/* AI Assistant Chat Tab — Creator AI light theme */

/* Container */
.ai-chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 160px);
    max-height: 720px;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    overflow: hidden;
    background: #ffffff;
}

/* ── Welcome state ── */
.ai-chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 40px 24px;
    text-align: center;
    background: linear-gradient(180deg, #f0f7ff 0%, #ffffff 60%);
}

.ai-chat-welcome .welcome-icon {
    width: 56px; height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, #007AFF, #5856D6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.25);
}

.ai-chat-welcome h3 {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    color: #1e293b;
}

.ai-chat-welcome p {
    color: #64748b;
    font-size: 14px;
    margin: 0;
    max-width: 480px;
    line-height: 1.6;
}

.ai-chat-welcome .quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    justify-content: center;
}

.ai-chat-welcome .quick-action-btn {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    max-width: 220px;
    text-align: left;
    line-height: 1.4;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ai-chat-welcome .quick-action-btn:hover {
    background: #f0f7ff;
    color: #007AFF;
    border-color: #bfdbfe;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.1);
}

/* ── Messages area ── */
.ai-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f8fafc;
}

.ai-chat-messages::-webkit-scrollbar { width: 6px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.ai-chat-messages::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.ai-chat-messages .load-more {
    text-align: center;
    padding: 8px;
}

.ai-chat-messages .load-more button {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #64748b;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.ai-chat-messages .load-more button:hover {
    background: #f0f7ff;
    color: #007AFF;
    border-color: #bfdbfe;
}

/* ── Message rows ── */
.ai-msg-row {
    display: flex;
    gap: 10px;
    max-width: 700px;
    animation: aiChatFadeIn 0.2s ease;
}

.ai-msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.ai-msg-row.assistant { align-self: flex-start; }

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

.ai-msg-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.ai-msg-row.assistant .ai-msg-avatar {
    background: linear-gradient(135deg, #007AFF, #5856D6);
    color: #fff;
    font-size: 13px;
}

.ai-msg-row.user .ai-msg-avatar {
    background: #e2e8f0;
    color: #475569;
}

.ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    max-width: 600px;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    user-select: text;
    position: relative;
}

.ai-msg-row.user .ai-msg-bubble {
    background: #007AFF;
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 122, 255, 0.2);
}

.ai-msg-row.assistant .ai-msg-bubble {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* ── Copy button ── */
.ai-msg-copy-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    color: #94a3b8;
    cursor: pointer;
    font-size: 11px;
    padding: 3px 6px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 5;
}
.ai-msg-bubble:hover .ai-msg-copy-btn { opacity: 1; }
.ai-msg-copy-btn:hover { color: #007AFF; }
.ai-msg-copy-btn.copied { color: #22c55e; }

/* ── Markdown in messages ── */
.ai-msg-bubble h2 { font-size: 16px; margin: 10px 0 6px; color: #1e293b; }
.ai-msg-bubble h3 { font-size: 15px; margin: 8px 0 4px; color: #1e293b; }
.ai-msg-bubble p { margin: 0; }
.ai-msg-bubble p + p { margin-top: 6px; }
.ai-msg-bubble ul, .ai-msg-bubble ol { margin: 6px 0; padding-left: 18px; }
.ai-msg-bubble li { margin: 3px 0; }

.ai-msg-row.assistant .ai-msg-bubble a { color: #007AFF; text-decoration: none; }
.ai-msg-row.assistant .ai-msg-bubble a:hover { text-decoration: underline; }
.ai-msg-row.user .ai-msg-bubble a { color: #bfdbfe; text-decoration: underline; }

.ai-msg-bubble strong { font-weight: 600; }

.ai-msg-bubble .inline-code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: #c7254e;
}

.ai-msg-row.user .ai-msg-bubble .inline-code {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.ai-msg-bubble .code-block {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

.ai-msg-bubble .code-block code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: #e2e8f0;
}

.ai-msg-bubble img {
    max-width: 100%;
    border-radius: 8px;
    margin: 6px 0;
    cursor: pointer;
}

.ai-msg-timestamp {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 3px;
    padding: 0 4px;
}

.ai-msg-row.user .ai-msg-timestamp { text-align: right; }

/* ── Typing indicator ── */
.ai-typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    gap: 4px;
    align-items: center;
    max-width: 60px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ai-typing-indicator.show { display: flex; }

.ai-typing-dot {
    width: 7px; height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: aiTypingBounce 1.2s infinite;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Chat input ── */
.ai-chat-input-area {
    padding: 12px 16px 16px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    flex-shrink: 0;
}

.ai-chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 8px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-chat-input-wrapper:focus-within {
    border-color: #007AFF;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.ai-chat-input {
    flex: 1;
    background: none;
    border: none;
    color: #1e293b;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 22px;
    line-height: 1.5;
    padding: 3px 0;
}

.ai-chat-input::placeholder { color: #94a3b8; }

.ai-chat-send-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: #007AFF;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    font-size: 14px;
}

.ai-chat-send-btn:hover {
    background: #0056b3;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.ai-chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Connection status ── */
.ai-chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 12px;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
}

.ai-chat-status .status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #94a3b8;
}

.ai-chat-status .status-dot.connected { background: #22c55e; }
.ai-chat-status .status-dot.error { background: #ef4444; }

/* ── End of history ── */
.ai-end-of-history {
    text-align: center;
    padding: 16px;
    color: #94a3b8;
    font-size: 12px;
}

/* ── Error banner ── */
.ai-chat-error {
    padding: 10px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 13px;
    margin: 8px 16px;
    display: none;
}

.ai-chat-error.show { display: block; }

/* ── Setup / Provisioning States ── */
.ai-chat-setup {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px 24px;
    text-align: center;
    background: linear-gradient(180deg, #f0f7ff 0%, #ffffff 60%);
    transition: opacity 0.3s ease;
}

.setup-icon {
    width: 64px; height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    border-radius: 50%;
    background: #f0f7ff;
}

.setup-icon-success {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    animation: setupPop 0.4s ease;
}

.setup-icon-error {
    background: #fef2f2;
}

@keyframes setupPop {
    0% { transform: scale(0.5); opacity: 0; }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.setup-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    color: #1e293b;
}

.setup-message {
    color: #64748b;
    font-size: 14px;
    margin: 0;
    max-width: 440px;
    line-height: 1.6;
}

/* Setup steps */
.setup-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
    text-align: left;
}

.setup-step {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #64748b;
    transition: color 0.2s;
}

.setup-step[data-status="active"] {
    color: #007AFF;
    font-weight: 500;
}

.setup-step[data-status="done"] {
    color: #22c55e;
}

.step-icon {
    width: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.step-label {
    font-size: 14px;
}

/* Spinner for setup steps */
.step-spinner {
    width: 16px; height: 16px;
    border: 2px solid #e2e8f0;
    border-top-color: #007AFF;
    border-radius: 50%;
    animation: setupSpin 0.8s linear infinite;
    display: inline-block;
}

/* Large spinner for main setup icon */
.setup-spinner-lg {
    width: 40px; height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #007AFF;
    border-radius: 50%;
    animation: setupSpin 0.9s linear infinite;
    display: inline-block;
}

@keyframes setupSpin {
    to { transform: rotate(360deg); }
}

/* Retry button */
.setup-retry-btn {
    margin-top: 12px;
    background: #007AFF;
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.setup-retry-btn:hover {
    background: #0056b3;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

/* Powered by badge */
.setup-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    color: #94a3b8;
    background: #f8fafc;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
}

.badge-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #22c55e;
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Provisioning status dot */
.ai-chat-status .status-dot.provisioning {
    background: #f59e0b;
    animation: badgePulse 1s infinite;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .ai-chat-container {
        height: calc(100vh - 200px);
        max-height: none;
        border-radius: 12px;
    }
    .ai-chat-messages { padding: 12px; }
    .ai-chat-input-area { padding: 8px 12px 12px; }
    .ai-msg-bubble { max-width: calc(100vw - 100px); }
    .ai-chat-welcome .quick-actions { flex-direction: column; align-items: center; }
}
