:root {
  --bg: oklch(0.992 0.002 264);
  --fg: oklch(0.18 0.018 260);
  --card: #fff;
  --muted: oklch(0.5 0.012 260);
  --line: oklch(0.92 0.006 260);
  --primary: oklch(0.45 0.18 258);
  --primary-fg: #fff;
  --soft: oklch(0.965 0.005 260);
  --ok: oklch(0.55 0.14 155);
  --warn: oklch(0.62 0.15 65);
  --danger: oklch(0.58 0.2 25);
  --shadow: 0 1px 2px oklch(0.2 0.02 260 / 0.04), 0 8px 24px oklch(0.2 0.02 260 / 0.04);
  --radius: 12px;
  color-scheme: light;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--fg);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  height: 56px; display: flex; align-items: center; gap: 16px;
  padding: 0 28px;
  background: oklch(0.992 0.002 264 / 0.72);
  backdrop-filter: blur(28px) saturate(1.4);
  border-bottom: 1px solid transparent;
}
.logo { font-size: 19px; font-weight: 800; letter-spacing: -0.03em; flex: 0 0 auto; }
.logo em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 8px; }
.nav {
  position: relative; display: flex; gap: 2px; min-width: 0;
  overflow-x: auto; flex: 1; justify-content: center;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  position: relative; padding: 8px 12px; border-radius: 8px;
  color: var(--muted); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.nav a:hover { color: var(--fg); background: oklch(0.96 0.005 260 / 0.7); }
.nav a.active { color: var(--fg); }
.nav-indicator {
  position: absolute; bottom: 2px; height: 2px; border-radius: 99px;
  background: var(--primary); transition: left .2s ease, width .2s ease;
  pointer-events: none;
}
.who { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; font-size: 13px; color: var(--muted); }

main { max-width: 1440px; margin: 0 auto; padding: 80px 28px 48px; }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -0.03em; font-weight: 700; }
.page-head p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.metrics { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 16px; }
.metric, .card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.metric { padding: 14px 16px; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 6px; font-size: 22px; letter-spacing: -0.03em; font-weight: 700; }
.metric.ok strong { color: var(--ok); }
.metric.warn strong { color: var(--warn); }
.metric.danger strong { color: var(--danger); }
.metric.info strong { color: var(--primary); }

.card { padding: 16px 18px; }
.card + .card, .split { margin-top: 12px; }
.split { display: grid; grid-template-columns: 1.3fr 1fr; gap: 12px; align-items: start; }
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 650; }
.card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* 堆叠柱：按模型分色。段与段之间留 2px 表面色缝隙，不画描边。 */
.chart { position: relative; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.chart-legend i { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.chart-plot { display: flex; gap: 10px; position: relative; }
.chart-axis {
  position: relative; flex: 0 0 34px; height: 170px; margin-bottom: 22px;
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.chart-axis span { position: absolute; right: 0; transform: translateY(50%); line-height: 1; }
.chart-axis span::after { content: attr(data-v); }
.chart-grid { position: absolute; inset: 0 0 22px 44px; pointer-events: none; }
.chart-grid span { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); }
.chart-cols { display: flex; align-items: flex-end; gap: 8px; flex: 1; height: 170px; margin-bottom: 22px; position: relative; }
.chart-col {
  position: relative; flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column;
  justify-content: flex-end; align-items: center; cursor: default; outline: none;
}
.chart-col em {
  position: absolute; bottom: -20px; left: 0; right: 0; text-align: center;
  font-style: normal; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.chart-col:focus-visible .chart-stack { box-shadow: 0 0 0 2px oklch(0.55 0.16 258 / 0.45); }
.chart-stack {
  display: flex; flex-direction: column-reverse; gap: 2px;
  width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; overflow: hidden;
  min-height: 2px;
}
.chart-stack i { display: block; width: 100%; min-height: 2px; }
.chart-col:hover .chart-stack, .chart-col:focus .chart-stack { filter: brightness(1.08); }
.chart-tip {
  position: absolute; top: 26px; transform: translateX(-50%); z-index: 5;
  min-width: 190px; max-width: 260px; padding: 10px 12px; border-radius: 10px;
  background: oklch(0.22 0.015 260); color: #fff; font-size: 12px; line-height: 1.6;
  box-shadow: 0 10px 30px oklch(0.2 0.02 260 / 0.28); pointer-events: none;
}
.chart-tip b { display: block; margin-bottom: 4px; font-size: 12px; }
.chart-tip div { display: flex; align-items: center; gap: 6px; }
.chart-tip div span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-tip i { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.chart-tip .tip-total { border-bottom: 1px solid oklch(1 0 0 / 0.18); padding-bottom: 4px; margin-bottom: 4px; font-weight: 600; }
.chart-tip .tip-foot { margin-top: 4px; color: oklch(0.85 0.01 260); }
.chart-tip .tip-empty { color: oklch(0.8 0.01 260); }

.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
input, select, textarea {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; outline: none; min-width: 0;
}
textarea { width: 100%; min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: oklch(0.65 0.12 258); box-shadow: 0 0 0 3px oklch(0.55 0.16 258 / 0.15); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 8px 12px; font-size: 14px; font-weight: 600;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 5px 9px; font-size: 12px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 550; background: oklch(0.985 0.003 260); position: sticky; top: 0; }
/* 可排序表头：整格可点，当前排序列高亮，箭头由 JS 拼在文字后面 */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); background: var(--soft); }
th.sortable.active { color: var(--primary); }
th.sortable:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: oklch(0.985 0.004 260); }
td.wrap { white-space: normal; max-width: 320px; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.badge.ok { background: oklch(0.95 0.04 155); color: oklch(0.4 0.12 155); }
.badge.warn { background: oklch(0.96 0.04 75); color: oklch(0.45 0.12 65); }
.badge.danger { background: oklch(0.96 0.03 25); color: var(--danger); }
.badge.muted { background: var(--soft); color: var(--muted); }
.err { color: var(--danger); font-size: 12px; margin-top: 2px; }
.badge.info { background: oklch(0.95 0.03 258); color: var(--primary); }
.warn-card { border-color: oklch(0.85 0.08 75); background: oklch(0.98 0.02 80); }
.warn-card strong { color: oklch(0.45 0.12 65); }
.linkish { background: none; border: 0; color: var(--primary); padding: 0 6px; font-weight: 550; }
.linkish.danger { color: var(--danger); }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--muted); font-size: 13px; }
.empty { padding: 36px 12px; text-align: center; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

.log-layout { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 16px; align-items: start; }
.log-sidebar {
  position: sticky; top: 74px; display: flex; flex-direction: column; gap: 4px;
  padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.log-sidebar button {
  border: 0; border-radius: 8px; background: transparent; padding: 10px 12px;
  color: var(--muted); text-align: left; font-size: 13px; font-weight: 600;
}
.log-sidebar button:hover { background: var(--soft); color: var(--fg); }
.log-sidebar button.active { background: oklch(0.95 0.03 258); color: var(--primary); }
.log-main { min-width: 0; }
.log-table th, .log-table td { vertical-align: top; }
.generation-table { table-layout: fixed; width: 100%; }
.generation-table .col-log-time { width: 195px; }
.generation-table .col-log-status { width: 78px; }
.generation-table .col-log-elapsed { width: 64px; }
.generation-table .col-log-account { width: 120px; }
.generation-table .col-log-model { width: 170px; }
.generation-table .col-log-credit { width: 72px; }
.generation-table .col-log-error { width: 200px; }
.generation-table th, .generation-table td { white-space: normal; }
.generation-table .cell-nowrap { white-space: nowrap; }
.generation-table td.prompt {
  white-space: normal; overflow-wrap: anywhere; word-break: break-word; line-height: 1.5;
}
.generation-table .prompt-preview {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
  overflow: hidden; white-space: normal; overflow-wrap: anywhere;
  word-break: break-word; line-height: 1.5;
}
.generation-table tbody tr[data-i] { cursor: pointer; }
.generation-table td.error-reason {
  white-space: normal; overflow-wrap: anywhere; word-break: break-word; line-height: 1.5;
}
.generation-table .account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.generation-table .model-name { overflow-wrap: anywhere; }
.generation-table .params { color: var(--muted); font-size: 11px; line-height: 1.5; margin-top: 2px; }
.generation-table .task-id {
  display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--muted); font-size: 11px; margin-top: 2px;
}
.log-time { line-height: 1.45; white-space: nowrap; }
.log-time small { display: block; color: var(--muted); font-size: 11px; }
.log-detail { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13px; }
.log-detail dt { color: var(--muted); }
.log-detail dd { margin: 0; min-width: 0; word-break: break-word; }

.modal-back {
  position: fixed; inset: 0; background: oklch(0.2 0.02 260 / 0.35);
  display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; z-index: 30;
}
.modal {
  width: min(640px, 100%); background: #fff; border-radius: 16px; box-shadow: var(--shadow);
  padding: 18px 18px 16px; max-height: 80vh; overflow: auto;
}
.modal.wide { width: min(860px, 100%); }
.modal h3 { margin: 0 0 6px; font-size: 18px; }
.modal .hint { margin: 0 0 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

pre, code, .mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }
pre {
  background: oklch(0.97 0.004 260); border-radius: 10px; padding: 12px; overflow: auto;
  font-size: 12px; line-height: 1.55; margin: 0;
}
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.copy-line { display: flex; align-items: center; gap: 8px; }
.copy-line code { background: oklch(0.97 0.004 260); border-radius: 6px; padding: 4px 8px; font-size: 12px; }

.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: var(--fg); color: white; border-radius: 10px; padding: 10px 14px;
  font-size: 13px; z-index: 40; box-shadow: var(--shadow);
}

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(400px, 100%); background: #fff; border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); padding: 28px 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 27px; letter-spacing: -0.04em; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.login-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary); color: white; font-weight: 800;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form-error { color: var(--danger); font-size: 13px; }
.check { width: 16px; height: 16px; }
.model-table input, .model-table select { width: 100%; min-width: 120px; }
#alias-table td:nth-child(2) { min-width: 230px; }
#alias-table td:last-child { width: 56px; }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
  .generation-table .col-log-time { width: 160px; }
  .generation-table .col-log-status { width: 70px; }
  .generation-table .col-log-elapsed { width: 58px; }
  .generation-table .col-log-account { width: 95px; }
  .generation-table .col-log-model { width: 145px; }
  .generation-table .col-log-credit { width: 64px; }
  .generation-table .col-log-error { width: 155px; }
  .log-layout { grid-template-columns: 1fr; }
  .log-sidebar { position: static; flex-direction: row; overflow-x: auto; }
  .log-sidebar button { white-space: nowrap; }
}
@media (max-width: 900px) {
  .generation-table { font-size: 12px; }
  .generation-table .col-log-time { width: 150px; }
  .generation-table .col-log-status { width: 70px; }
  .generation-table .col-log-elapsed { width: 60px; }
  .generation-table .col-log-account { width: 90px; }
  .generation-table .col-log-model { width: 140px; }
  .generation-table .col-log-credit { width: 64px; }
  .generation-table .col-log-error { width: 130px; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 8px; }
  main { padding: 72px 12px 28px; }
  .metrics, .grid-2 { grid-template-columns: 1fr 1fr; }
  .nav { justify-content: flex-start; }
  .who span { display: none; }
}
