/* ========================================
   AI Prompt 调试台 - 开发者风格
   深色模式 + 等宽字体 + 侧边栏 + 调试面板
   ======================================== */

/* === 调试台主布局：左侧对话 + 右侧调试面板 === */
.ai-chat-section {
    margin-top: 60px;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
}

/* 扫描线背景 */
.ai-chat-section::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg, transparent, transparent 2px,
        rgba(0, 212, 255, 0.015) 2px, rgba(0, 212, 255, 0.015) 4px
    );
    pointer-events: none;
    z-index: 0;
}

/* === 左侧：对话主区域 === */
.ai-chat-main {
    padding: 28px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

/* 标题区域 - 开发者风 */
.ai-chat-title {
    margin-bottom: 20px;
}

.ai-chat-title h2 {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 400;
    color: var(--accent-primary);
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.ai-chat-title h2::before {
    content: '> ';
    color: var(--text-muted);
}

.ai-chat-title p {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

/* 模型选择器 - 紧凑横排 */
.ai-model-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.ai-model-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: var(--font-mono);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ai-model-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(0, 212, 255, 0.05);
}

.ai-model-btn.active {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(0, 212, 255, 0.1);
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.15);
}

.ai-model-btn .model-icon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
}

.ai-model-btn .free-badge {
    font-size: 0.6rem;
    padding: 0px 4px;
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* 模型信息 - 单行状态栏 */
.ai-model-info {
    margin-bottom: 12px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 212, 255, 0.1);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-family: var(--font-mono);
    display: none;
}

.ai-model-info.visible {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-model-info .model-name {
    color: var(--accent-primary);
    font-weight: 600;
}

.ai-model-info .api-status {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.6rem;
    font-weight: 600;
}

.ai-model-info .api-status.direct {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.ai-model-info .api-status.redirect {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

/* 对话输入区域 - 开发者终端风 */
.ai-chat-input-area {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

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

.ai-chat-input textarea {
    width: 100%;
    min-height: 48px;
    max-height: 160px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 0.85rem;
    font-family: var(--font-mono);
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.2s;
}

.ai-chat-input textarea::placeholder {
    color: var(--text-muted);
}

.ai-chat-input textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* 发送按钮 */
.ai-chat-send {
    padding: 10px 20px;
    background: var(--accent-primary);
    border: none;
    border-radius: 8px;
    color: #0a0a0a;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 48px;
}

.ai-chat-send:hover {
    background: #33e0ff;
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
}

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

.ai-chat-send svg {
    width: 14px;
    height: 14px;
}

/* 对话消息区域 - 终端输出风 */
.ai-chat-messages {
    margin-top: 16px;
    flex: 1;
    max-height: 420px;
    overflow-y: auto;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: none;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.ai-chat-messages.visible {
    display: block;
}

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

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* 消息 - 紧凑终端风 */
.chat-message {
    margin-bottom: 10px;
    display: flex;
    gap: 8px;
    animation: message-in 0.2s ease-out;
}

@keyframes message-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-message.user .chat-avatar {
    background: #7c3aed;
    color: white;
}

.chat-message.assistant .chat-avatar {
    background: #0d9488;
    color: white;
}

.chat-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    line-height: 1.6;
    word-break: break-word;
}

.chat-message.user .chat-bubble {
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.2);
    color: #c4b5fd;
    border-bottom-right-radius: 2px;
}

.chat-message.assistant .chat-bubble {
    background: rgba(13, 148, 136, 0.08);
    border: 1px solid rgba(13, 148, 136, 0.15);
    color: #ccfbf1;
    border-bottom-left-radius: 2px;
}

/* 加载动画 */
.chat-loading {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-loading .dot {
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: dot-pulse 1.4s ease-in-out infinite;
}

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

@keyframes dot-pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* 跳转提示 */
.chat-redirect-notice {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 6px;
    color: #f59e0b;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 错误消息 */
.chat-error {
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    color: #ef4444;
    font-size: 0.75rem;
    margin-top: 6px;
}

/* === 右侧：调试面板（侧边栏） === */
.ai-chat-sidebar {
    padding: 20px 16px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.15);
}

/* 调试面板标题 */
.sidebar-section {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(0, 212, 255, 0.05);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}

.sidebar-header:hover {
    background: rgba(0, 212, 255, 0.08);
}

.sidebar-header h3 {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent-primary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar-header .toggle-icon {
    color: var(--text-muted);
    font-size: 12px;
    transition: transform 0.2s;
}

.sidebar-header.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.sidebar-body {
    padding: 12px;
    transition: all 0.2s;
}

.sidebar-body.collapsed {
    display: none;
}

/* System Message 编辑 */
.system-msg-textarea {
    width: 100%;
    min-height: 80px;
    max-height: 200px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: #fbbf24;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.2s;
}

.system-msg-textarea:focus {
    outline: none;
    border-color: #fbbf24;
}

.system-msg-hint {
    margin-top: 6px;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Token 消耗统计 */
.token-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.token-stat-item {
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    text-align: center;
}

.token-stat-item .label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.token-stat-item .value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.token-stat-item .value.warning {
    color: #f59e0b;
}

.token-stat-item .unit {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-left: 2px;
}

/* 原始 JSON 查看器 */
.json-viewer {
    max-height: 260px;
    overflow-y: auto;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    line-height: 1.5;
    color: #94a3b8;
    white-space: pre-wrap;
    word-break: break-all;
}

.json-viewer::-webkit-scrollbar {
    width: 3px;
}

.json-viewer::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.json-viewer .json-key { color: #7c3aed; }
.json-viewer .json-string { color: #10b981; }
.json-viewer .json-number { color: #f59e0b; }
.json-viewer .json-bool { color: #ec4899; }
.json-viewer .json-null { color: var(--text-muted); }

.json-empty {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-family: var(--font-mono);
    font-style: italic;
}

/* JSON 复制按钮 */
.json-copy-btn {
    margin-top: 6px;
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.6rem;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.2s;
}

.json-copy-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* 调试参数 */
.debug-params {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.debug-param-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.debug-param-row label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    min-width: 70px;
    text-transform: uppercase;
}

.debug-param-row input,
.debug-param-row select {
    flex: 1;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.7rem;
    font-family: var(--font-mono);
}

.debug-param-row input:focus,
.debug-param-row select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.debug-param-row select {
    cursor: pointer;
}

.debug-param-row select option {
    background: #0f172a;
}

/* === 响应式 === */
@media (max-width: 900px) {
    .ai-chat-section {
        grid-template-columns: 1fr;
    }

    .ai-chat-main {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .ai-chat-sidebar {
        max-height: 400px;
    }
}

@media (max-width: 768px) {
    .ai-chat-section {
        margin-top: 40px;
        border-radius: 12px;
    }

    .ai-chat-main {
        padding: 16px;
    }

    .ai-chat-title h2 {
        font-size: 0.95rem;
    }

    .ai-model-btn {
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .ai-chat-input-area {
        flex-direction: column;
    }

    .ai-chat-send {
        width: 100%;
        justify-content: center;
    }

    .chat-bubble {
        max-width: 92%;
    }

    .ai-chat-sidebar {
        padding: 12px;
    }
}
.ai-model-btn-disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.5); }
