/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f6fa;
    --sidebar-bg: #1a1d29;
    --sidebar-text: #a0a3b1;
    --sidebar-active: #fff;
    --card-bg: #fff;
    --text: #2d3142;
    --text-secondary: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #f0f0ff;
    --green: #10b981;
    --red: #ef4444;
    --blue: #3b82f6;
    --gray: #9ca3af;
    --border: #e5e7eb;
    --surface-muted: #f3f4f6;
    --surface-hover: #fafbfc;
    --track: #e5e7eb;
    --radius: 8px;
    color-scheme: light;
}

/* 深色模式：仅覆盖随主题变化的变量；
 * 品牌色 / 语义色 / 几何常量（--primary / --primary-hover / --green / --red /
 * --blue / --gray / --sidebar-text / --radius）有意跨主题共享，
 * 通过 CSS 级联从上方 :root 继承，不在此重复声明（避免双重维护）。
 * 注：--sidebar-text 未覆盖是因为 sidebar 两种主题下都是深底，浅灰文字对比度足够。
 */
:root[data-theme="dark"] {
    --bg: #0f1117;
    --sidebar-bg: #0a0c14;
    --card-bg: #1a1d29;
    --text: #e5e7eb;
    --text-secondary: #9ca3af;
    --primary-soft: rgba(79, 70, 229, 0.20);
    --border: #2d3142;
    --surface-muted: #232735;
    --surface-hover: #1e2230;
    --track: #2d3142;
    color-scheme: dark;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    line-height: 1.6;
}

/* === Sidebar === */
.sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 24px 0;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.sidebar-header h2 { font-size: 18px; color: #fff; font-weight: 600; }
.version { font-size: 11px; color: var(--sidebar-text); opacity: 0.6; }
.sidebar-footer { margin-top: auto; padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.pid-info { font-size: 11px; opacity: 0.5; margin-top: 10px; }
.user-info { display: flex; flex-direction: column; gap: 4px; }
.user-info .user-name { font-size: 13px; color: #fff; font-weight: 500; }
.user-info .user-role {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--sidebar-text); opacity: 0.7;
}
.logout-form { margin-top: 6px; }
.logout-btn { background: rgba(255,255,255,0.08); color: var(--sidebar-text); border: 1px solid rgba(255,255,255,0.1); width: 100%; }
.logout-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }

.nav-links { list-style: none; margin-top: 16px; flex: 1; }
.nav-links a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px; color: var(--sidebar-text);
    text-decoration: none; font-size: 14px; transition: all 0.15s;
}
.nav-links a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-links a.active { background: rgba(79,70,229,0.25); color: #fff; border-right: 3px solid var(--primary); }
.nav-links .icon { font-size: 16px; width: 20px; text-align: center; }

/* === Main Content === */
.content { margin-left: 220px; padding: 28px 32px; flex: 1; max-width: 1100px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 22px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* === Cards === */
.card {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 20px 24px; margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--text); }

/* === Badges === */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.tag { display: inline-block; padding: 1px 6px; background: var(--primary-soft); color: var(--primary); border-radius: 4px; font-size: 11px; margin: 1px; }

/* === Buttons === */
.btn {
    display: inline-block; padding: 8px 16px; border-radius: 6px;
    font-size: 13px; font-weight: 500; text-decoration: none;
    border: none; cursor: pointer; transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-danger { background: var(--red); color: #fff; border: none; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-secondary { background: var(--surface-muted); color: var(--text); }
.btn-secondary:hover { background: var(--track); }
.btn-success { background: var(--green) !important; color: #fff !important; }
.btn-success:hover { filter: brightness(0.94); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.pagination { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pagination-meta { font-size: 13px; color: var(--text-secondary); }

.latest-agent-times { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.latest-agent-times-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px; }
.agent-complete-line { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.agent-complete-line:last-child { border-bottom: none; }
.agent-complete-line .agent-name { font-weight: 500; color: var(--text); }
.agent-complete-line .agent-time { color: var(--text-secondary); font-variant-numeric: tabular-nums; text-align: right; }

/* === Tables === */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border); color: var(--text-secondary); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--surface-hover); }

/* === Progress Bar === */
.progress-bar-container {
    width: 100%; height: 8px; background: var(--track);
    border-radius: 4px; overflow: hidden; margin-bottom: 12px;
}
.progress-bar {
    height: 100%; background: linear-gradient(90deg, var(--primary), var(--blue));
    border-radius: 4px; transition: width 0.5s ease;
}
.progress-info {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 13px; color: var(--text-secondary); margin-bottom: 16px;
}
.token-badge {
    font-size: 11px; background: var(--primary-soft); color: var(--primary);
    padding: 2px 8px; border-radius: 8px;
}

/* === Pipeline Progress Steps === */
.pipeline-progress { display: flex; align-items: center; justify-content: center; padding: 12px 0; }
.agent-step { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.step-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--track); transition: all 0.3s; }
.agent-step span { font-size: 11px; color: var(--text-secondary); }
.agent-step.completed .step-dot { background: var(--green); }
.agent-step.running .step-dot { background: var(--blue); animation: pulse 1.5s infinite; }
.step-line { width: 48px; height: 2px; background: var(--track); margin: 0 4px; margin-bottom: 24px; }
.status-text { text-align: center; font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59,130,246,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(59,130,246,0); }
}

/* === Score Bar (results page) === */
.score-bar {
    position: relative; width: 80px; height: 22px;
    background: var(--surface-muted); border-radius: 4px; overflow: hidden;
}
.score-fill {
    height: 100%; border-radius: 4px;
    background: linear-gradient(90deg, #fbbf24, var(--green));
    transition: width 0.3s;
}
.score-bar span {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    font-size: 12px; font-weight: 600; color: var(--text);
}
.reason-cell { max-width: 300px; font-size: 12px; line-height: 1.5; }
.result-table td { vertical-align: middle; }

/* === Info Grid === */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.info-item label { display: block; font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.info-item span { font-size: 14px; font-weight: 500; }

/* === Forms === */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-group input, .form-group select {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 14px; transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.form-group .hint { display: block; font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
.time-input { display: flex; align-items: center; gap: 4px; font-weight: 600; }
.time-input input { width: 60px !important; text-align: center; }
.form-actions { margin-top: 8px; }

/* === 仪表盘「大模型」：与系统配置页相同的原生 select；单列加宽（避免多列表格只占一窄列）=== */
.card-profile-picker {
    position: relative;
    z-index: 20;
    overflow: visible;
}
.card-profile-picker .form-grid-profile {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: min(100%, 720px);
}
.card-profile-picker .form-group {
    width: 100%;
    min-width: 0;
}
.card-profile-picker .form-group select {
    width: 100%;
    max-width: 100%;
    min-height: 42px;
}

/* === Alerts === */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* === Report Layout === */
.report-layout { display: flex; gap: 20px; }
.report-sidebar { width: 220px; flex-shrink: 0; }
.report-sidebar h4 { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.report-nav { list-style: none; }
.report-nav a { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 6px; text-decoration: none; color: var(--text); font-size: 13px; transition: all 0.15s; }
.report-nav a:hover { background: var(--surface-muted); }
.report-nav a.active { background: rgba(79,70,229,0.08); color: var(--primary); font-weight: 500; }
.report-content { flex: 1; min-width: 0; }

/* === Markdown Body === */
.markdown-body { font-size: 14px; line-height: 1.7; }
.markdown-body h1 { font-size: 20px; margin: 24px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 17px; margin: 20px 0 10px; }
.markdown-body h3 { font-size: 15px; margin: 16px 0 8px; }
.markdown-body p { margin: 8px 0; }
.markdown-body table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.markdown-body th, .markdown-body td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.markdown-body th { background: var(--surface-muted); font-weight: 500; }
.markdown-body code { background: var(--surface-muted); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.markdown-body pre { background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: 8px; overflow-x: auto; margin: 12px 0; }
.markdown-body pre code { background: none; color: inherit; padding: 0; }
.markdown-body blockquote { border-left: 3px solid var(--primary); padding-left: 16px; color: var(--text-secondary); margin: 12px 0; }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin: 8px 0; }

.empty-state { text-align: center; padding: 40px; color: var(--text-secondary); font-size: 14px; }

/* === Theme Switcher (sidebar footer) === */
.theme-switcher {
    margin-top: 12px;
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}
.theme-btn {
    width: 30px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--sidebar-text);
    border: none;
    border-radius: 5px;
    font-size: 13px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.theme-btn:hover { background: rgba(255, 255, 255, 0.09); color: #fff; }
.theme-btn.active {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* === Dark-mode tweaks === */
:root[data-theme="dark"] .card {
    border: 1px solid var(--border);
    box-shadow: none;
}
:root[data-theme="dark"] .btn-secondary { color: var(--text); }
:root[data-theme="dark"] .form-group input,
:root[data-theme="dark"] .form-group select {
    background: var(--card-bg);
    color: var(--text);
}
:root[data-theme="dark"] .markdown-body pre {
    background: #0b1220;
    color: #dbe3f0;
    border: 1px solid var(--border);
}
:root[data-theme="dark"] .alert-success { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
:root[data-theme="dark"] .alert-error { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
:root[data-theme="dark"] .badge-green { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
:root[data-theme="dark"] .badge-red { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
:root[data-theme="dark"] .badge-blue { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
:root[data-theme="dark"] .badge-gray { background: rgba(156, 163, 175, 0.18); color: #d1d5db; }
:root[data-theme="dark"] .score-bar span { color: var(--text); }
:root[data-theme="dark"] .progress-bar-container,
:root[data-theme="dark"] .score-bar { background: var(--surface-muted); }
:root[data-theme="dark"] body { background: var(--bg); }
