/* AIK Next — 克制的运维工作台：中性底色、细边框、单一蓝色强调 */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f1f3f6;
  --fg: #191b20;
  --muted: #666c78;
  --line: #e3e6ec;
  --line-strong: #cfd4dd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-weak: #e8effe;
  --ok: #15803d;
  --ok-weak: #e8f5ec;
  --err: #b42318;
  --err-weak: #fdeceb;
  --warn: #a15c07;
  --warn-weak: #fdf3e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 20, 28, .04);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0f1216;
  --panel: #161a20;
  --panel-soft: #1c212a;
  --fg: #e6e9ee;
  --muted: #9aa2b1;
  --line: #262c36;
  --line-strong: #3a4250;
  --accent: #6f9cf7;
  --accent-hover: #93b6ff;
  --accent-weak: #1d2a44;
  --ok: #5fce8a;
  --ok-weak: #16301f;
  --err: #f0837a;
  --err-weak: #351b19;
  --warn: #e3b25f;
  --warn-weak: #33270f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 -apple-system, "PingFang SC", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
code, .mono, time { font-family: var(--mono); }
b, strong { font-weight: 600; }
button, input, select { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 顶栏 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; height: 32px; padding: 0 8px;
  border-radius: 8px; background: var(--accent); color: #fff;
  font-weight: 700; font-size: 13px; letter-spacing: 1px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text b { font-size: 14px; }
.brand-text span { color: var(--muted); font-size: 12px; }
.topmeta { margin: 0 0 0 auto; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topactions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── 按钮 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel); color: var(--fg);
  font-size: 13px; text-decoration: none; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; border-color: var(--line); color: var(--muted); }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); color: #fff; }

/* ── 骨架 ── */
.shell {
  display: grid; grid-template-columns: 1fr;
  gap: 16px; max-width: 1440px; margin: 0 auto;
  padding: 16px 16px 40px;
}
main { min-width: 0; }
.side { display: flex; gap: 6px; overflow-x: auto; }
.nav-link {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px;
  border-radius: 8px; color: var(--muted); text-decoration: none;
  font-size: 13px; white-space: nowrap;
}
.nav-link:hover { background: var(--panel-soft); color: var(--fg); }
.nav-link.is-active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.side-note { display: none; margin: 18px 4px 0; color: var(--muted); font-size: 12px; line-height: 1.8; }
.side-note code { font-size: 12px; background: var(--panel-soft); padding: 1px 4px; border-radius: 4px; }

@media (min-width: 1200px) {
  .shell { grid-template-columns: 200px minmax(0, 1fr); gap: 24px; padding: 20px 24px 48px; }
  .side {
    position: sticky; top: 80px; align-self: start;
    flex-direction: column; overflow: visible; gap: 2px;
  }
  .nav-link { padding: 0 12px; }
  .side-note { display: block; }
}

/* ── 卡片 ── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-h {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 16px 10px;
}
.card-h h2 { margin: 0; font-size: 14px; font-weight: 600; }
.card-h p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.badge {
  flex-shrink: 0; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent);
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}

/* ── 筛选条 ── */
.filterbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 12px;
}
.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--panel-soft); border-radius: 9px;
}
.seg button {
  min-height: 40px; padding: 0 12px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--fg); }
.seg button.is-on { background: var(--panel); color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }
html[data-theme="dark"] .seg button.is-on { background: var(--accent-weak); }

.range-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.field-range {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 12px;
}
input[type="datetime-local"] {
  min-height: 40px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel); color: var(--fg); font-size: 13px;
}
.field { display: inline-flex; align-items: center; gap: 8px; }
.field > span { color: var(--muted); font-size: 12px; }
select {
  min-height: 40px; min-width: 150px; padding: 0 30px 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel); color: var(--fg); font-size: 13px;
}
select:hover { border-color: var(--accent); }
.tznote { margin-left: auto; color: var(--muted); font-size: 12px; }

/* 手机端：筛选折叠、排名前 3、摘要紧凑 */
.filter-main, .filter-extra { display: contents; }
.filter-toggle { display: none; }
.filter-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; margin-left: 5px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.rank-foot { display: none; }

/* ── 摘要 ── */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.kpi {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: 12px 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.kpi-k {
  font-size: 22px; font-weight: 650; letter-spacing: -.3px;
  font-variant-numeric: tabular-nums; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kpi-l { color: var(--muted); font-size: 12px; }
.kpi-s { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; overflow-wrap: normal; }
.kpi-s .seg-part { white-space: nowrap; }
.scope { margin: 8px 2px 0; color: var(--muted); font-size: 12px; }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; } }

/* ── 分析区 2:1 ── */
.analysis { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 12px; }
@media (min-width: 1000px) { .analysis { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); } }

.chart-scroll { overflow-x: auto; }
.chart-inner { min-width: 100%; }
.chart {
  display: flex; align-items: flex-end; gap: 4px;
  height: 160px; padding: 8px 16px 0;
  border-bottom: 1px solid var(--line);
}
.bcol { flex: 1 1 0; min-width: 14px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bar {
  width: 100%; min-height: 3px; border-radius: 3px 3px 0 0;
  background: var(--accent); cursor: pointer;
}
.bar:hover { background: var(--accent-hover); }
.bar.is-empty { background: var(--line-strong); opacity: .45; min-height: 2px; height: 2px !important; }
.bar.is-unknown { background: transparent; border: 1px dashed var(--line-strong); height: 8px !important; min-height: 8px; }
.warn { color: var(--warn); font-weight: 600; }
.bar.is-sel { outline: 2px solid var(--warn); outline-offset: 1px; }
.axis {
  display: flex; justify-content: space-between;
  padding: 6px 16px 0; color: var(--muted); font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.chart-empty { margin: 0 16px 10px; padding: 8px 10px; border-radius: 8px;
  background: var(--panel-soft); color: var(--muted); font-size: 12px; }
.chart-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px 14px; color: var(--muted); font-size: 12px;
}
.foot-note { white-space: nowrap; }
.legend { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }

.rank { list-style: none; margin: 0; padding: 4px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.rank li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; }
.rank-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--mono); font-size: 12px;
}
.rank-val { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--fg); white-space: nowrap; }
.rank-val small { color: var(--muted); font-size: 12px; }
.rank-track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--panel-soft); overflow: hidden; }
.rank-fill { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.rank-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* ── 明细 ── */
.list-card { margin-top: 12px; }
.list-h { align-items: center; }
.count { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.state {
  margin: 0 16px 10px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); border-left: 3px solid var(--warn);
  background: var(--warn-weak); color: var(--fg); font-size: 13px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.state.is-error { border-left-color: var(--err); background: var(--err-weak); }
.state .btn { margin-left: auto; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
  padding: 10px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  white-space: nowrap; background: var(--panel-soft);
}
td {
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums; white-space: nowrap; vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: var(--panel-soft); }
th.num, td.num { text-align: right; }
td.time { color: var(--muted); font-family: var(--mono); font-size: 12px; }
td.model { font-family: var(--mono); font-size: 12px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; white-space: normal; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--panel-soft); color: var(--muted); white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.s-ok { background: var(--ok-weak); color: var(--ok); }
.pill.s-warn { background: var(--warn-weak); color: var(--warn); }
.pill.s-err { background: var(--err-weak); color: var(--err); }
.pill .kind { font-weight: 400; color: var(--muted); }

.pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 12px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
}

.cards { display: none; }

/* ── 移动端卡片 ── */
@media (max-width: 767px) {
  /* 顶栏：第一行品牌+操作，第二行只放数据时间 */
  .topbar { height: auto; min-height: 0; padding: 6px 12px; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  .brand { flex: 0 1 auto; gap: 8px; }
  .logo { min-width: 36px; height: 28px; padding: 0 7px; font-size: 12px; }
  .brand-text b { font-size: 13px; }
  .brand-text span { display: none; }
  .topactions { margin-left: auto; gap: 6px; }
  .topactions .btn { padding: 0 10px; }
  .topmeta { order: 3; flex: 1 1 100%; margin: 0; font-size: 12px; line-height: 1.35;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topmeta:empty { display: none; }

  /* 筛选：时间快捷键 + 筛选按钮一行，模型/状态折叠 */
  .only-wide { display: none; }
  .filterbar { display: block; padding: 10px; }
  .filter-main { display: flex; align-items: stretch; gap: 8px; }
  .seg { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); flex: 1 1 auto; width: auto; gap: 1px; }
  .seg button { padding: 0 2px; font-size: 12px; }
  .filter-toggle { display: inline-flex; flex: 0 0 auto; padding: 0 12px; white-space: nowrap; }
  .filter-extra { display: none; margin-top: 10px; flex-direction: column; gap: 8px; }
  .filterbar.is-open .filter-extra { display: flex; }
  .field { width: 100%; }
  .field > span { flex: 0 0 auto; }
  .field select { flex: 1; min-width: 0; }
  .filter-extra .clear { width: 100%; }
  .range-custom { margin-top: 8px; gap: 6px; }
  .field-range { flex: 1 1 100%; justify-content: space-between; }
  .field-range input { flex: 1; min-width: 0; }
  .tznote { display: none; }

  /* 摘要：2x2，收紧留白 */
  .kpis { gap: 8px; margin-top: 10px; }
  .kpi { padding: 10px 12px; gap: 1px; }
  .kpi-k { font-size: 23px; line-height: 1.25; }
  .kpi-l { font-size: 12px; }
  .kpi-s { font-size: 12px; line-height: 1.4; }
  .scope { margin: 6px 2px 0; font-size: 12px; line-height: 1.45; }

  /* 趋势：收紧头部，图高约 150px，首屏能看到图 */
  .analysis { gap: 10px; margin-top: 10px; }
  .card-h { padding: 12px 12px 8px; }
  .chart-card .card-h p { display: none; }
  .chart { height: 150px; padding: 8px 8px 0; gap: 2px; }
  .bcol { min-width: 0; }
  .chart-inner { min-width: 0; }
  .axis { padding: 4px 8px 0; font-size: 12px; }
  .chart-empty { margin: 0 12px 8px; padding: 7px 9px; }
  .chart-foot { display: block; padding: 8px 12px 12px; font-size: 12px; line-height: 1.5; }
  .chart-foot #chart-scope, .chart-foot #chart-foot-note { display: block; }
  .chart-foot #chart-foot-note { margin-top: 2px; }

  /* 模型排名：默认前 3，展开看全部 */
  .rank { padding: 2px 12px 12px; gap: 9px; }
  .rank.is-collapsed li.is-extra { display: none; }
  .rank-foot { display: block; padding: 0 12px 12px; }
  .rank-foot .rank-more { display: inline-flex; width: 100%; }

  /* 明细卡：时间/模型/状态 + 输入输出；次要指标折叠 */
  .table-wrap { display: none; }
  .cards { display: block; padding: 0 12px; }
  .call {
    border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px;
    background: var(--panel); overflow: hidden;
  }
  .call > summary {
    list-style: none; cursor: pointer; padding: 10px 12px; min-height: 56px;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; align-items: center;
  }
  .call > summary::-webkit-details-marker { display: none; }
  .call-top { display: flex; align-items: center; gap: 6px; min-width: 0; flex-wrap: wrap; }
  .call-time { color: var(--muted); font-size: 12px; font-family: var(--mono); white-space: nowrap; }
  .call-model { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
  .call-stats {
    grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 2px 14px;
    color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
  }
  .call-stats b { color: var(--fg); font-weight: 600; font-size: 13px; }
  .call-more { grid-column: 2; grid-row: 1; color: var(--accent); font-size: 12px; white-space: nowrap; padding: 4px 0 4px 8px; }
  .call dl { margin: 0; padding: 4px 12px 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
  .call dl div { min-width: 0; }
  .call dt { color: var(--muted); font-size: 12px; }
  .call dd { margin: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pager .btn { flex: 1; }
  .cards .empty { border: 1px dashed var(--line-strong); border-radius: 8px; }
}

/* 320px 级窄屏：时间快捷键分两行，避免文字溢出按键 */
@media (max-width: 359px) {
  .seg { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── 详情弹窗 ── */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 40; padding: 16px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 13, 18, .5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.sheet {
  width: min(480px, 100%); max-height: min(86vh, 720px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.sheet-h {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.sheet-h h3 { margin: 6px 0 0; font-size: 14px; font-family: var(--mono); word-break: break-all; }
.grp {
  margin: 12px 16px 0; color: var(--muted); font-size: 12px;
  letter-spacing: .4px; text-transform: uppercase;
}
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 4px 16px 0; }
.kv div { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 2px 0 0; font-size: 13px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hint { margin: 12px 16px 16px; color: var(--muted); font-size: 12px; }

/* 768–1000px：保留表格但收紧内边距，避免横向滚动条 */
@media (min-width: 768px) and (max-width: 1000px) {
  table { min-width: 0; }
  th, td { padding: 8px 8px; }
  td.model { max-width: 180px; white-space: normal; word-break: break-word; }
}

.foot {
  margin: 16px 2px 0; padding-top: 12px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; line-height: 1.7;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
