/**
 * API 测试管理页面样式
 * 紧凑三栏布局，最大化信息密度
 */

/* 主题变量 */
:root {
    --primary: #7c3aed;
    --primary-light: #a78bfa;
    --bg-base: #0a0a0f;
    --bg-panel: #12121a;
    --bg-elevated: #1a1a25;
    --bg-input: #22222e;
    --bg-hover: #2a2a38;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #2a2a35;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
}

[data-theme="light"] {
    --bg-base: #f1f5f9;
    --bg-panel: #ffffff;
    --bg-elevated: #f8fafc;
    --bg-input: #e2e8f0;
    --bg-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 顶部工具栏 */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.top-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.top-center {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: center;
}

.base-url-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.base-url-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: 'Fira Code', monospace;
    width: 480px;
}

.base-url-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* API 连通性状态图标 */
.api-status {
    font-size: 1rem;
    margin-left: 6px;
    cursor: pointer;
    transition: transform 0.3s;
}

.api-status.checking {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.logo {
    font-weight: 600;
    font-size: 1rem;
    color: var(--primary);
}

.env-selector {
    display: flex;
    gap: 2px;
    background: var(--bg-input);
    padding: 2px;
    border-radius: 6px;
}

.env-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}

.env-btn:hover {
    color: var(--text-primary);
}

.env-btn.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.env-btn.active[data-env="local"] .env-dot {
    background: var(--success);
}

.env-btn.active[data-env="prod"] .env-dot {
    background: var(--primary);
}

.env-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
}

.api-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.top-right {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s;
    text-decoration: none;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* 主容器 */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 主布局 - 三栏 */
.main-layout {
    flex: 1;
    display: flex;
    gap: 1px;
    background: var(--border);
    overflow: hidden;
    min-height: 0;
}

/* 底部字段配置区 */
.field-config-panel {
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    height: 160px;
    display: flex;
    flex-direction: column;
}

.config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.config-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.config-header .mode-tabs {
    display: flex;
    gap: 8px;
}

.config-header .mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.config-header .mode-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary-light);
}

.config-header .mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

.mode-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.config-header .mode-btn.active .mode-name {
    color: white;
}

.mode-desc {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.config-header .mode-btn.active .mode-desc {
    color: rgba(255, 255, 255, 0.7);
}

.config-content {
    flex: 1;
    margin: 8px 16px;
    padding: 10px;
    background: var(--bg-input);
    border-radius: 6px;
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow: auto;
    white-space: pre-wrap;
}

/* 面板通用 */
.panel {
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

/* 左栏：API 列表 */
.panel-list {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.panel-list .panel-header {
    flex-shrink: 0;
}

.panel-list .panel-header input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text-primary);
    font-size: 0.8rem;
}

.panel-list .panel-header input:focus {
    outline: none;
    border-color: var(--primary);
}

.api-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    min-height: 0;
    /* 关键：允许 flex 子元素收缩并滚动 */
}

.api-group {
    margin-bottom: 8px;
}

.group-header {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary-light);
    padding: 4px 8px;
    text-transform: uppercase;
}

.api-item {
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}

.api-item:hover {
    background: var(--bg-elevated);
}

.api-item.active {
    background: var(--bg-elevated);
    border-color: var(--primary);
}

.api-item-name {
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 2px;
}

.api-item-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loading,
.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* 中栏：参数与配置 */
.panel-params {
    flex: 1;
    min-width: 400px;
    display: flex;
    flex-direction: column;
}

.panel-params .panel-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.config-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.api-title h2 {
    font-size: 1rem;
    font-weight: 600;
}

.api-path {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

.section {
    margin-bottom: 16px;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 参数网格 */
.params-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.param-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.param-item label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 2px;
}

.param-item .required {
    color: var(--danger);
}

.param-item input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--text-primary);
    font-size: 0.8rem;
}

.param-item input:focus {
    outline: none;
    border-color: var(--primary);
}

.param-item input::placeholder {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.params-actions {
    display: flex;
    gap: 8px;
}

/* 按钮 */
.btn {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-hover);
}

/* 字段配置 */
.mode-tabs {
    display: flex;
    gap: 4px;
}

.mode-btn {
    padding: 3px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.15s;
}

.mode-btn:hover {
    background: var(--bg-hover);
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.config-preview {
    background: var(--bg-input);
    border-radius: 6px;
    padding: 10px;
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    flex: 1;
    min-height: 120px;
    overflow: auto;
    color: var(--text-secondary);
    white-space: pre-wrap;
    margin: 0;
}

/* 右栏：响应结果 */
.panel-response {
    flex: 1;
    min-width: 350px;
}

/* 响应区 Tab 切换 */
.response-tabs {
    display: flex;
    gap: 4px;
}

.response-tab {
    padding: 4px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}

.response-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.response-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.response-meta {
    display: flex;
    gap: 10px;
    font-size: 0.75rem;
}

.response-meta .status {
    color: var(--text-muted);
}

.response-meta .status.success {
    color: var(--success);
}

.response-meta .status.error {
    color: var(--danger);
}

.response-meta .time {
    color: var(--text-muted);
}

.response-body {
    flex: 1;
    background: var(--bg-base);
    border-radius: 6px;
    padding: 10px;
    margin: 10px;
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    overflow: auto;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 16px;
    right: 16px;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 0.85rem;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: var(--success);
    color: white;
}

.toast.error {
    background: var(--danger);
    color: white;
}

.toast.warning {
    background: var(--warning);
    color: #1a1a2e;
}

/* 滚动条 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-input);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* 响应式 */
@media (max-width: 1200px) {
    .panel-list {
        width: 200px;
    }
}

@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }

    .panel-list {
        width: 100%;
        height: 200px;
    }

    .panel-params,
    .panel-response {
        min-width: 0;
    }
}