/* StoryLab Web UI 主样式 */
:root {
    --bg-primary: #0f1419;
    --bg-secondary: #1a1f2e;
    --bg-tertiary: #242b3d;
    --bg-hover: #2d3548;
    --border: #2d3548;
    --text-primary: #e6e9ef;
    --text-secondary: #9ca3b8;
    --text-muted: #6b7280;
    --accent: #6366f1;
    --accent-hover: #7c7ff5;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* 亮色皮肤：通过 <html data-theme="light"> 全局生效 */
[data-theme="light"] {
    --bg-primary: #f4f6fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef1f7;
    --bg-hover: #e6eaf3;
    --border: #e2e6ef;
    --text-primary: #1f2430;
    --text-secondary: #4b5366;
    --text-muted: #8a94a6;
    --shadow: 0 4px 12px rgba(31, 36, 48, 0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
}

.layout {
    display: block;
    min-height: 100vh;
    position: relative;
}

.layout > .content {
    display: block;
}

.footer {
    position: relative;
    left: 0;
    right: 0;
    padding: 14px 32px;
    margin-top: 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    z-index: 10;
}

.footer p {
    margin: 0;
}

/* ========== 顶部导航栏 ========== */
.topnav {
    display: flex;
    align-items: center;
    gap: 18px;
    height: 56px;
    padding: 0 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topnav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.topnav-logo { font-size: 20px; line-height: 1; }
.topnav-title { font-size: 17px; font-weight: 700; color: var(--accent); }
.topnav-brand .version { font-size: 11px; color: var(--text-muted); }
.topnav-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}
.topnav-nav::-webkit-scrollbar { height: 0; }
.topnav-nav .nav-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    margin: 0;
    border-radius: var(--radius);
    font-size: 13.5px;
    white-space: nowrap;
    border-left: none;
}
.topnav-nav .nav-item .icon { font-size: 15px; width: auto; }
.topnav-nav .nav-item.active {
    margin-left: 0;
    padding-left: 13px;
    border-left: none;
    border-radius: var(--radius);
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent) !important;
    font-weight: 600;
}
.topnav-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    margin-left: auto;
}
.theme-toggle {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    gap: 0 !important;
    padding: 0 !important;
    margin-top: 0 !important;
    flex-shrink: 0;
    transition: background .15s, transform .15s;
}
.theme-toggle .icon { font-size: 16px; margin: 0 !important; }
.theme-toggle:hover { background: var(--bg-hover); transform: rotate(20deg); }

/* 报告导出主按钮：醒目强调 */
.export-main .btn-primary {
    background: linear-gradient(135deg, var(--accent), #22d3ee);
    border: none;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    padding: 7px 16px;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4);
}
.export-main .btn-primary:hover {
    background: linear-gradient(135deg, #4f46e5, #1fb6d6);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.55);
}
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
}

.logo {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.logo .version {
    font-size: 12px;
    color: var(--text-muted);
}

.nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    margin-bottom: 4px;
    font-size: 14px;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent) !important;
    font-weight: 600;
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-left: -12px;
    padding-left: 17px;
}

.nav-item.active .icon {
    color: var(--accent) !important;
}

.nav-item .icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-indicator .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
}

.status-indicator.online .dot {
    background: var(--success);
}

.status-indicator.offline .dot {
    background: var(--error);
}

/* ========== 主内容区 ========== */
.content {
    margin-left: 0;
    padding: 24px 28px 40px;
    max-width: 100%;
    overflow: visible;
    height: auto;
    min-height: calc(100vh - 56px);
    position: relative;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ========== 卡片 ========== */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

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

/* ========== 表单 ========== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group .hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="url"],
select,
textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 100px;
    font-family: "Cascadia Code", "Consolas", "Monaco", monospace;
    font-size: 13px;
    line-height: 1.5;
}

textarea.prompt-editor {
    min-height: 300px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

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

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

.btn-warning {
    background: #f59e0b;
    border-color: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-info {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

.btn-info:hover {
    background: #2563eb;
}

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

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* ========== 标签页 ========== */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab {
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
    white-space: nowrap;
}

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

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========== 表格 ========== */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:hover {
    background: var(--bg-tertiary);
}

/* ========== 徽章 ========== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.badge-success { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.badge-error { background: rgba(239, 68, 68, 0.2); color: var(--error); }
.badge-info { background: rgba(59, 130, 246, 0.2); color: var(--info); }
.badge-default { background: var(--bg-hover); color: var(--text-secondary); }

.grade-badge {
    display: inline-block;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
}

.grade-S { background: #f59e0b; color: white; }
.grade-A { background: #10b981; color: white; }
.grade-B { background: #3b82f6; color: white; }
.grade-C { background: #6b7280; color: white; }
.grade-D { background: #ef4444; color: white; }

/* ========== 进度条 ========== */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s;
}

.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.error { background: var(--error); }

/* ========== 日志 ========== */
.log-container {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    max-height: 400px;
    overflow-y: auto;
    font-family: "Cascadia Code", "Consolas", "Monaco", monospace;
    font-size: 12px;
    line-height: 1.6;
}

.log-line {
    display: flex;
    gap: 8px;
    padding: 2px 0;
}

.log-time {
    color: var(--text-muted);
    flex-shrink: 0;
}

.log-level-info { color: var(--info); }
.log-level-success { color: var(--success); }
.log-level-warning { color: var(--warning); }
.log-level-error { color: var(--error); }

.log-message {
    word-break: break-word;
    white-space: pre-wrap;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--text-primary);
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
    pointer-events: none;
}

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

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }

/* ========== 网格 ========== */
.grid {
    display: grid;
    gap: 16px;
}

.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.grid-2, .grid-3, .grid-4 {
    display: grid;
    gap: 16px;
}

/* ========== 统计卡片 ========== */
.stat-card {
    text-align: center;
    padding: 24px 16px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 8px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ========== 快速入口卡片 ========== */
.quick-card {
    text-decoration: none;
    color: inherit;
    padding: 24px 16px;
    text-align: center;
    transition: all 0.2s;
    display: block;
}

.quick-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.quick-icon {
    font-size: 36px;
    margin-bottom: 12px;
}

.quick-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}

.quick-desc {
    font-size: 12px;
    color: var(--text-muted);
}

/* ========== 标签输入 ========== */
.tag-input {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-height: 40px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--bg-hover);
    border-radius: 12px;
    font-size: 12px;
}

.tag-remove {
    cursor: pointer;
    color: var(--text-muted);
    font-weight: bold;
}

.tag-remove:hover {
    color: var(--error);
}

.tag-input-field {
    flex: 1;
    min-width: 100px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

/* ========== 加载动画 ========== */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* ========== 确认对话框 ========== */
.confirm-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}
.confirm-modal.show { display: flex; }
.confirm-modal-content {
    width: 420px;
    max-width: 90vw;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.confirm-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}
.confirm-message {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}
.confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.confirm-actions .btn { min-width: 80px; }

/* ========== 使用说明弹窗 ========== */
.help-modal-content {
    width: 640px;
    max-height: 82vh;
    overflow-y: auto;
}
.help-modal-body {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.8;
}
.help-modal-body ol {
    padding-left: 20px;
    margin: 10px 0;
}
.help-modal-body li {
    margin-bottom: 8px;
}
.help-modal-body strong {
    color: var(--text-primary);
}
.help-tip {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--bg-tertiary, rgba(127, 127, 127, 0.1));
    border-radius: var(--radius, 8px);
    font-size: 13px;
}
.help-text {
    font-size: 13px;
}
@media (max-width: 768px) {
    #helpToggle .help-text { display: none; }
}

/* ========== 响应式 ========== */
@media (max-width: 1024px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .topnav { gap: 10px; padding: 0 12px; }
    .topnav-brand .topnav-title, .topnav-brand .version { display: none; }
    .topnav-nav .nav-item span:not(.icon) { display: none; }
    .topnav-nav .nav-item { padding: 8px 10px; }
    .topnav-right .user-details { display: none; }
    .content { padding: 16px 14px 40px; }
    .form-row { grid-template-columns: 1fr; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ========== JSON 查看器 ========== */
.json-viewer {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    overflow: auto;
    max-height: 500px;
    font-family: "Cascadia Code", "Consolas", "Monaco", monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #a3e635;
}

.json-viewer .key { color: #67e8f9; }
.json-viewer .string { color: #fde047; }
.json-viewer .number { color: #fb923c; }
.json-viewer .boolean { color: #c084fc; }
.json-viewer .null { color: var(--text-muted); }

/* ========== Markdown 渲染 ========== */
.markdown-body {
    color: var(--text-primary);
    line-height: 1.7;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin: 16px 0 8px;
    color: var(--text-primary);
}

.markdown-body h1 { font-size: 22px; }
.markdown-body h2 { font-size: 18px; }
.markdown-body h3 { font-size: 16px; }

.markdown-body p { margin: 8px 0; }

.markdown-body table {
    margin: 12px 0;
}

.markdown-body code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: "Cascadia Code", "Consolas", monospace;
    font-size: 12px;
    color: #fde047;
}

.markdown-body pre {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow: auto;
    margin: 12px 0;
}

.markdown-body pre code {
    background: transparent;
    padding: 0;
}

/* ========== 开关 ========== */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 24px;
    transition: 0.3s;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.3s;
}

.switch input:checked + .switch-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .switch-slider:before {
    transform: translateX(20px);
    background: white;
}

/* ========== 评分条 ========== */
.score-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.score-bar-track {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.score-value {
    font-weight: 600;
    min-width: 36px;
    text-align: right;
}

/* ========== 上传区域 ========== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}
.upload-area:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}
.upload-area.dragover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.source-panel {
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== 文本输入块 ========== */
.text-block {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: hidden;
}
.text-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}
.text-block-label {
    font-weight: 600;
    font-size: 13px;
    color: var(--accent);
}
.text-block-content {
    width: 100%;
    min-height: 100px;
    padding: 10px 12px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
}
.text-block-content:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--accent);
}
.text-block-content::placeholder {
    color: var(--text-muted);
}

/* ========== 用户菜单 ========== */
.user-menu {
    position: relative;
    padding: 6px 8px;
    border-radius: var(--radius);
    cursor: pointer;
}
.user-menu:hover {
    background: var(--bg-hover);
}
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}
.user-details {
    flex: 1;
    min-width: 0;
}
.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    bottom: auto;
    left: auto;
    right: 0;
    width: 168px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: none;
    overflow: hidden;
    z-index: 100;
}
.user-menu.open .user-dropdown {
    display: block;
}
.dropdown-item {
    display: block;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.2s;
}
.dropdown-item:hover {
    background: var(--bg-hover);
}
.dropdown-item.danger {
    color: var(--error);
}
.dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* === Streaming UI (方案 D) === */
.stream-panel {
    background: var(--bg-secondary);
    border-radius: 18px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 24px;
    /* 不强制占满 80vh，避免与 .content 滚动容器冲突造成内容在板内被截断 */
    min-height: 0;
}

.badge {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
}
.badge-success { background: rgba(16,185,129,.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-error   { background: rgba(239,68,68,.15);  color: var(--error); }
.badge-info    { background: rgba(59,130,246,.15); color: var(--info); }
.badge-default { background: rgba(148,163,184,.15); color: var(--text-muted); }
.badge-accent  { background: rgba(99,102,241,.15); color: #a5b4fc; }

/* ============ 通用组件：状态卡 ============ */
.status-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 18px;
}
.status-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}
.status-item-label { font-size: 12px; color: var(--text-muted); }
.status-item-value { font-size: 15px; font-weight: 600; margin-top: 4px; }
.progress-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}
.progress-bar {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: rgba(148,163,184,.15);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #22d3ee);
    width: 42%;
    border-radius: 4px;
    transition: width .3s;
}
.progress-text { font-size: 13px; font-weight: 600; color: var(--text-muted); min-width: 50px; }

/* ============ 通用组件：Tab 栏 ============ */
.tab-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
    padding-bottom: 0;
}
.tab-list { display: flex; gap: 4px; }
.tab {
    padding: 10px 18px;
    border-radius: 8px 8px 0 0;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: .15s;
}
.tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
    background: rgba(99,102,241,.08);
}
.tab-hint { font-size: 11px; color: var(--text-muted); margin-left: 4px; }
.tab-actions { display: flex; gap: 6px; align-items: center; }
.tab-panel { }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    transition: .15s;
    font-family: inherit;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #4f46e5; }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-error { background: var(--error); color: #fff; border-color: var(--error); }
.split-btn {
    position: relative;
    display: inline-flex;
}
.split-btn .menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    min-width: 160px;
    box-shadow: var(--shadow);
    z-index: 10;
    display: none;
}
.split-btn.open .menu { display: block; }
.split-btn .menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    border-radius: 5px;
    background: transparent;
    border: 0;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 12px;
}
.split-btn .menu button:hover { background: var(--bg-tertiary); }

/* ============ 方案 A：阶段卡片（纵向时间轴） ============ */
.stage-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.stage-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    position: relative;
    transition: .15s;
}
.stage-card.running {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(99,102,241,.4), 0 8px 20px rgba(99,102,241,.12);
}
.stage-card.pending { opacity: .5; }
.stage-card.expanded .stage-body { display: block; }
.stage-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}
.stage-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.stage-indicator {
    width: 26px; height: 26px;
    border-radius: 50%;
    display: grid; place-items: center;
    font-size: 13px;
    flex-shrink: 0;
}
.ind-success { background: rgba(16,185,129,.15); color: var(--success); }
.ind-running { background: rgba(99,102,241,.2);  color: var(--accent); animation: pulse 1.5s infinite; }
.ind-pending { background: rgba(148,163,184,.15); color: var(--text-muted); }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,.4); }
    50%      { box-shadow: 0 0 0 6px rgba(99,102,241,0); }
}
.stage-name { font-size: 15px; font-weight: 600; }
.stage-meta { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.stage-actions { display: flex; gap: 6px; flex-shrink: 0; }
.stage-toggle {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 6px;
    transition: .15s;
}
.stage-toggle:hover { background: rgba(148,163,184,.15); color: var(--text-primary); }
.stage-body {
    margin-top: 14px;
    padding: 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: none;
}
.stage-loader {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    color: var(--text-muted);
    font-size: 13px;
}
.dots::after {
    content: '';
    display: inline-block;
    animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

/* 阶段内容：加载了多少基因/评分/亮点 */
.kv-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.kv-card {
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.kv-label { font-size: 11px; color: var(--text-muted); }
.kv-value { font-size: 15px; font-weight: 600; margin-top: 4px; }

.inline-list {
    margin: 10px 0 0 0;
    padding: 0;
    list-style: none;
}
.inline-list li {
    padding: 6px 10px;
    border-left: 3px solid var(--accent);
    background: rgba(99,102,241,.06);
    margin-bottom: 5px;
    border-radius: 0 6px 6px 0;
    font-size: 13px;
}

.score-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 13px;
}
.score-table th, .score-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.score-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
    background: rgba(148,163,184,.06);
}
.score-table tr:last-child td { border-bottom: 0; }

.mini-bar {
    display: inline-block;
    vertical-align: middle;
    width: 100px; height: 6px;
    background: rgba(148,163,184,.15);
    border-radius: 3px;
    overflow: hidden;
    margin-right: 8px;
}
.mini-bar > i {
    display: block; height: 100%;
    background: linear-gradient(90deg, var(--accent), #22d3ee);
    border-radius: 3px;
}

/* ============ 日志 Tab ============ */
.log-container {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.7;
    max-height: 520px;
    overflow-y: auto;
}
.log-line { display: flex; gap: 8px; padding: 2px 0; }
.log-time { color: #64748b; min-width: 70px; }
.log-level-INFO    { color: #38bdf8; min-width: 54px; font-weight: 600; }
.log-level-SUCCESS { color: #34d399; min-width: 54px; font-weight: 600; }
.log-level-WARNING { color: #fbbf24; min-width: 54px; font-weight: 600; }
.log-level-ERROR   { color: #f87171; min-width: 54px; font-weight: 600; }
.log-round-badge {
    background: rgba(99,102,241,.15);
    color: #a5b4fc;
    border-radius: 4px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}
.log-message { color: #cbd5e1; flex: 1; }

/* ============ 原始 JSON Tab ============ */
pre.raw-data {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #cbd5e1;
    max-height: 520px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============ 方案 B：左侧紧凑时间轴 + 右侧详情抽屉 ============ */
.two-col {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
}

.t-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.t-dot.success { background: var(--success); }
.t-dot.running { background: var(--accent); animation: pulse 1.5s infinite; }
.t-dot.pending { background: #475569; }

.timeline-list {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
}
.timeline-item {
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: .15s;
    position: relative;
}
.timeline-item:hover { background: rgba(148,163,184,.08); }
.timeline-item.selected { background: rgba(99,102,241,.12); border: 1px solid var(--accent); }
.timeline-item.pending .t-name { color: var(--text-muted); }
.t-row1 { display: flex; align-items: center; gap: 8px; }
.t-name { font-size: 13px; font-weight: 600; }
.t-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; padding-left: 16px; }

.detail-drawer {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    position: relative;
}
.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}
.drawer-title { font-size: 17px; font-weight: 600; }
.drawer-empty {
    display: grid; place-items: center;
    min-height: 400px;
    color: var(--text-muted);
    text-align: center;
}

/* ============ 方案 C：网格平铺 ============ */
.grid-layout {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}
.grid-stage {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    transition: .15s;
}
.grid-stage.running {
    grid-column: span 2;
    min-height: 220px;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(99,102,241,.4), 0 8px 20px rgba(99,102,241,.12);
}
.grid-stage.pending { opacity: .45; }
.grid-stage-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.grid-stage-body {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
    flex: 1;
    overflow: hidden;
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.6;
}
.truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 调度条（方案 D 顶部） */
.scheduler-bar {
    background: linear-gradient(135deg, rgba(99,102,241,.15), rgba(34,211,238,.08));
    border: 1px solid var(--accent);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 18px;
}
.scheduler-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.scheduler-title {
    font-weight: 600;
    font-size: 14px;
}
.project-tiles {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
