/* style.css —— 现代学术型深色界面（避免娱乐化与过度装饰） */
:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #5b8ff9;
  --accent-2: #5ad8a6;
  --warn: #f6bd16;
  --danger: #e8684a;
  --up: #e8684a;   /* 中国习惯：涨=红（本平台用于“大/警示”，负误差绝对值） */
  --down: #5ad8a6;
  --radius: 8px;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px; line-height: 1.6;
}

/* 顶栏 */
.topbar { height: 62px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1680px; margin: 0 auto; height: 100%; padding: 0 22px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), #9270ca); border-radius: 8px; font-size: 22px; font-weight: 700; }
.brand-title { font-size: 15px; font-weight: 600; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* 用户信息区（阶段四） */
.user-area { display: flex; align-items: center; gap: 6px; padding-left: 10px; border-left: 1px solid var(--border); }
.user-info { font-size: 12px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info.logged-in { color: var(--accent-2); font-weight: 500; }

/* 布局 */
.layout { max-width: 1680px; margin: 0 auto; display: flex; min-height: calc(100vh - 62px); }
.sidebar { width: 244px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border); padding: 18px 14px; position: sticky; top: 62px; height: calc(100vh - 62px); overflow-y: auto; }
.nav-group-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 4px 8px 10px; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-caption { font-size: 10px; letter-spacing: .5px; color: var(--muted); padding: 10px 10px 4px; margin-top: 4px; border-top: 1px dashed var(--border); }
.nav-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 10px; margin-bottom: 4px; border-radius: var(--radius); cursor: pointer; border: 1px solid transparent; transition: .15s; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: rgba(91,143,249,.12); border-color: rgba(91,143,249,.4); }
.nav-num { width: 22px; height: 22px; flex-shrink: 0; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.nav-item.active .nav-num { background: var(--accent); color: #fff; border-color: var(--accent); }
.nav-text { flex: 1; min-width: 0; }
.nav-text .t { font-size: 13px; font-weight: 500; line-height: 1.4; }
.nav-kind { display: inline-block; font-size: 10px; font-weight: 600; color: var(--accent); background: rgba(91,143,249,.12); border-radius: 4px; padding: 0 4px; margin-right: 4px; vertical-align: 1px; }
.nav-text .d { font-size: 11px; color: var(--muted); line-height: 1.45; }
.nav-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; font-size: 10px; }
.nav-state { color: var(--muted); white-space: nowrap; }
.nav-state.in_progress { color: var(--warn); }
.nav-state.done { color: var(--accent-2); }
.nav-sub { color: var(--accent); white-space: nowrap; }
.nav-status { display: inline-block; width: 7px; height: 7px; line-height: 0; font-size: 0; border-radius: 50%; background: var(--border); vertical-align: middle; }
.nav-status.in_progress { background: var(--warn); }
.nav-status.done { background: var(--accent-2); }
.nav-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 10px; color: var(--muted); margin-top: 10px; }
.nav-legend span { white-space: nowrap; }
.progress-wrap { padding: 4px 10px; }
.progress-bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.progress-text { font-size: 11px; color: var(--muted); margin-top: 8px; }
.sidebar-foot { margin-top: 28px; padding: 12px 10px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); line-height: 1.8; }

.main { flex: 1; padding: 26px 30px; min-width: 0; }
.view { max-width: 1320px; }

/* 通用组件 */
.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; transition: .15s; font-family: inherit; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4a7de0; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; }
.badge-muted { color: var(--muted); border: 1px solid var(--border); }
.badge-ok { color: var(--accent-2); border: 1px solid rgba(90,216,166,.4); background: rgba(90,216,166,.08); }
.badge-warn { color: var(--warn); border: 1px solid rgba(246,189,22,.4); background: rgba(246,189,22,.08); }

/* 首页 */
.hero { padding: 34px 38px; background: linear-gradient(135deg, #161b22 0%, #1c2128 100%); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 22px; }
.hero h1 { margin: 0 0 6px; font-size: 27px; font-weight: 650; }
.hero .subtitle { font-size: 16px; color: var(--accent); margin-bottom: 18px; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 22px; color: var(--muted); font-size: 13px; }
.hero .meta b { color: var(--text); }
.hero .lead { margin-top: 18px; max-width: 900px; color: #c9d1d9; }
.hero-actions { margin-top: 24px; display: flex; gap: 12px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.card p { margin: 0; color: var(--muted); font-size: 13px; }
.section-title { font-size: 18px; margin: 30px 0 14px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.section-title::before { content: ''; width: 3px; height: 18px; background: var(--accent); border-radius: 2px; }
.kv-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 24px; }
.kv { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding: 6px 0; font-size: 13px; }
.kv span { color: var(--muted); }

/* 任务页 */
.task-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 18px; }
.task-head h1 { margin: 0 0 4px; font-size: 22px; }
.task-head .stage { font-size: 12px; color: var(--accent); }
.task-head .time { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 9px 16px; cursor: pointer; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel-block { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px 22px; margin-bottom: 16px; }
.panel-block h2 { font-size: 16px; margin: 0 0 12px; }
.panel-block h3 { font-size: 14px; margin: 18px 0 8px; color: var(--accent); }
.panel-block p, .panel-block li { color: #c9d1d9; font-size: 13.5px; }
.panel-block ul, .panel-block ol { padding-left: 22px; }
.formula { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 18px; margin: 12px 0; overflow-x: auto; text-align: center; }
.note { background: rgba(91,143,249,.08); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 4px; font-size: 13px; color: #c9d1d9; margin: 12px 0; }
.note.warn { background: rgba(246,189,22,.08); border-left-color: var(--warn); }

/* 表单与交互区 */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 13px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.matrix-input { width: 100%; font-family: var(--mono); font-size: 12px; resize: vertical; min-height: 120px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 14px 0; }
.metric { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.metric .label { font-size: 11px; color: var(--muted); }
.metric .value { font-size: 18px; font-family: var(--mono); margin-top: 4px; word-break: break-all; }
.metric .value.good { color: var(--accent-2); }
.metric .value.bad { color: var(--danger); }
.table-wrap { overflow-x: auto; margin: 12px 0; }
table.data { border-collapse: collapse; width: 100%; font-size: 12px; }
table.data th, table.data td { border: 1px solid var(--border); padding: 6px 10px; text-align: right; font-family: var(--mono); white-space: nowrap; }
table.data th { background: var(--panel-2); color: var(--muted); font-family: inherit; position: sticky; top: 0; }
table.data td:first-child, table.data th:first-child { text-align: left; }
.chart-box { width: 100%; height: 360px; margin: 12px 0; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.step-control { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 12px; color: var(--muted); }
.step-control input[type=range] { flex: 1; }
.think-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px 18px; margin-top: 12px; }
.think-box h3 { color: var(--warn); margin-top: 0; }
.status-line { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* AI 抽屉 */
.ai-drawer { position: fixed; right: 0; top: 0; width: 400px; max-width: 100vw; height: 100vh; background: var(--panel); border-left: 1px solid var(--border); z-index: 40; transform: translateX(100%); transition: transform .25s; display: flex; flex-direction: column; }
.ai-drawer.open { transform: translateX(0); }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; display: none; }
.drawer-backdrop.open { display: block; }
.ai-head { display: flex; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.ai-title { font-weight: 600; }
.ai-subtitle { font-size: 11px; color: var(--muted); margin-top: 3px; }
.ai-messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 10px; font-size: 13px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 2px; }
.msg.ai { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.msg.ai .katex { color: var(--text); }
/* AI 回复的 Markdown 渲染样式（覆盖 .msg 的 pre-wrap，避免公式/缩进竖排） */
.msg.ai { white-space: normal; }
.msg.ai p { margin: 6px 0; }
.msg.ai h1, .msg.ai h2, .msg.ai h3, .msg.ai h4 { margin: 12px 0 6px; line-height: 1.35; color: var(--text); }
.msg.ai h1 { font-size: 1.25em; } .msg.ai h2 { font-size: 1.15em; } .msg.ai h3 { font-size: 1.06em; } .msg.ai h4 { font-size: 1em; }
.msg.ai ul, .msg.ai ol { margin: 6px 0; padding-left: 22px; }
.msg.ai li { margin: 3px 0; }
.msg.ai blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--muted); background: rgba(127,127,127,.08); }
.msg.ai code { background: rgba(127,127,127,.15); padding: 1px 5px; border-radius: 4px; font-family: Consolas, Monaco, monospace; font-size: .92em; }
.msg.ai pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.msg.ai pre code { background: none; padding: 0; }
.msg.ai table { border-collapse: collapse; margin: 8px 0; font-size: .95em; }
.msg.ai th, .msg.ai td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.msg.ai .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.msg.ai .katex { font-size: 1.02em; }
/* 逐字流式输出时的打字光标 */
.msg.ai.streaming::after { content: '\2581'; color: var(--accent); animation: sc-blink .8s steps(2,start) infinite; }
@keyframes sc-blink { to { visibility: hidden; } }
.ai-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px 10px; }
.ai-quick button { font-size: 11px; padding: 4px 8px; background: transparent; border: 1px solid var(--border); border-radius: 14px; color: var(--muted); cursor: pointer; }
.ai-quick button:hover { border-color: var(--accent); color: var(--text); }
.ai-input-wrap { display: flex; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--border); }
.ai-input-wrap textarea { flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-family: inherit; font-size: 13px; resize: none; }
.ai-foot { display: flex; justify-content: space-between; align-items: center; padding: 0 18px 12px; font-size: 11px; color: var(--muted); }
.ai-unavailable { color: var(--warn); text-align: center; padding: 20px; font-size: 12px; }

.hidden { display: none !important; }
@media (max-width: 1000px) {
  .sidebar { width: 200px; }
  .chart-row { grid-template-columns: 1fr; }
  .main { padding: 18px; }
}
@media (max-width: 760px) {
  /* 窄屏不隐藏导航：改为可横向滚动的任务条，避免“找不到任务入口” */
  .layout { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; overflow: hidden; border-right: none; border-bottom: 1px solid var(--border); padding: 10px; }
  .nav-list { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .nav-item { min-width: 168px; margin-bottom: 0; }
  .nav-caption, .progress-wrap, .sidebar-foot { display: none; }
}
