/* CodeArts2API 管理面板 · 主样式
   设计口径与 workbuddy2api 面板对齐：
   - 双主题（data-theme 切换），变量集中定义，组件只引用变量
   - 左侧固定导航 + 右侧滚动主区
   - 表格用 data-l 属性承载列名，窄屏由 mobile.css 转成卡片
*/

:root {
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --nav-w: 218px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0e14;
  --surface: #14171f;
  --surface-2: #1a1e28;
  --raise: #202531;
  --line: #262c3a;
  --line-soft: #1e232e;
  --ink: #e8ebf2;
  --ink-2: #a8b0c2;
  --ink-3: #6b7488;
  --accent: #5b7cfa;
  --accent-ink: #ffffff;
  --accent-soft: rgba(91, 124, 250, 0.13);
  --ok: #3ddc97;
  --ok-soft: rgba(61, 220, 151, 0.12);
  --warn: #f5b544;
  --warn-soft: rgba(245, 181, 68, 0.12);
  --bad: #f0655f;
  --bad-soft: rgba(240, 101, 95, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --grid: rgba(255, 255, 255, 0.06);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f3f6fb;
  --raise: #ffffff;
  --line: #e3e9f2;
  --line-soft: #eef2f8;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #8a97ab;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --accent-soft: rgba(59, 91, 219, 0.09);
  --ok: #12855c;
  --ok-soft: rgba(18, 133, 92, 0.1);
  --warn: #a86400;
  --warn-soft: rgba(168, 100, 0, 0.1);
  --bad: #c0342e;
  --bad-soft: rgba(192, 52, 46, 0.09);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -14px rgba(15, 23, 42, 0.18);
  --grid: rgba(15, 23, 42, 0.07);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13.5px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--ink-3); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 12% -10%, var(--accent-soft), transparent),
    radial-gradient(700px 400px at 90% 110%, var(--ok-soft), transparent);
}
.login-box {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-box h1 { margin: 0; font-size: 18px; letter-spacing: .2px; }
.login-box p { margin: 4px 0 0; color: var(--ink-3); font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }

.input, .select, .textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; min-height: 320px; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }

/* ---------- 品牌 ---------- */
.logo {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--ok)));
  color: #fff; font-family: var(--mono); font-weight: 700; font-size: 13px;
  letter-spacing: -.5px;
}

/* ---------- 布局 ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }

.nav {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px 12px;
  z-index: 50;
}
.nav-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 16px; }
.nav-brand h1 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: .2px; }
.nav-brand p { margin: 1px 0 0; font-size: 11px; color: var(--ink-3); }

.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-size: 13px; font-weight: 500;
  cursor: pointer; user-select: none;
  transition: background .14s, color .14s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 16px; text-align: center; font-size: 14px; opacity: .9; }
.nav-item .badge-dot { margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--bad); }

.nav-foot { border-top: 1px solid var(--line-soft); padding-top: 10px; margin-top: 10px; }
.nav-foot .kv { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); padding: 2px 6px; }
.nav-foot .kv b {
  color: var(--ink-2); font-weight: 500; font-family: var(--mono);
  max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 22px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .2px; }
.topbar .sub { color: var(--ink-3); font-size: 12px; margin-left: 2px; }
.topbar .spacer { flex: 1; }

.hamburger { display: none; }

.view { padding: 18px 22px 64px; max-width: 1440px; width: 100%; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background .14s, border-color .14s, color .14s, transform .1s;
}
.btn:hover { background: var(--raise); border-color: var(--ink-3); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 8px; font-size: 12px; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.card-h {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--line-soft);
}
.card-h h3 { margin: 0; font-size: 13.5px; font-weight: 620; }
.card-h .spacer { flex: 1; }
.card-b { padding: 14px 15px; }
.card-b.flush { padding: 0; }

/* ---------- 表单（配置视图） ---------- */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid2 + .grid2, .grid3 + .grid2, .grid2 + .grid3 { margin-top: 14px; }

.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld .lb { font-size: 12px; font-weight: 620; color: var(--ink-2); }
.fld .hint, .hint { font-size: 11px; color: var(--ink-3); line-height: 1.5; }
.fld .input, .fld .select { padding: 7px 10px; font-size: 12.5px; }

.inline { display: flex; gap: 6px; align-items: center; }
.inline .input { flex: 1; min-width: 0; }

.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line);
}
.switch .lb { font-size: 12px; font-weight: 560; color: var(--ink-2); }
.switch input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 34px; height: 19px; border-radius: 99px; flex: 0 0 34px;
  background: var(--line); position: relative; cursor: pointer;
  transition: background .16s;
}
.switch input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .16s;
}
.switch input[type="checkbox"]:checked { background: var(--accent); }
.switch input[type="checkbox"]:checked::after { transform: translateX(15px); }

.hr { height: 1px; background: var(--line-soft); margin: 14px 0; }

@media (max-width: 1000px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.kpi .k { color: var(--ink-3); font-size: 11.5px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.kpi .v { font-size: 24px; font-weight: 680; letter-spacing: -.6px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.kpi.accent .v { color: var(--accent); }
.kpi.ok .v { color: var(--ok); }
.kpi.bad .v { color: var(--bad); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
table.table th, table.table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.table th {
  font-size: 11px; font-weight: 650; letter-spacing: .4px; text-transform: uppercase;
  color: var(--ink-3);
  background: var(--surface-2);
  white-space: nowrap;
}
table.table tbody tr:hover td { background: var(--surface-2); }
table.table tbody tr:last-child td { border-bottom: none; }
table.table td.r, table.table th.r { text-align: right; }
.cell-main { font-weight: 560; color: var(--ink); }
.cell-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }

/* 长错误文本必须夹在固定宽度里：td 里的裸文本会把整张表撑开，
   结果是「操作」列被推到屏幕外，用户以为按钮消失了。 */
.clamp2 {
  max-width: 250px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

/* ---------- 状态标签 ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 650; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
}
.tag::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--accent-soft); color: var(--accent); }
.tag.plain::before { display: none; }

/* 健康色条 */
.health { display: inline-block; width: 3px; height: 26px; border-radius: 2px; background: var(--line); margin-right: 8px; vertical-align: middle; }
.health.ok { background: var(--ok); }
.health.warn { background: var(--warn); }
.health.bad { background: var(--bad); }

/* 迷你进度条 */
.bar { height: 5px; border-radius: 99px; background: var(--line-soft); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }

/* ---------- 图表 ---------- */
.chart-box { position: relative; }
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--ink-3); padding: 0 2px 8px; }
.chart-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 20;
  background: var(--raise); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px;
  font-size: 12px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .1s; white-space: nowrap;
}
.tooltip.show { opacity: 1; }
.tooltip b { font-variant-numeric: tabular-nums; }
.tooltip .row { display: flex; justify-content: space-between; gap: 14px; }

/* ---------- 分段控件 ---------- */
.segment { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.segment button {
  border: none; background: transparent; color: var(--ink-3);
  padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 560;
}
.segment button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- 工具条 ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filters .input, .filters .select { width: auto; min-width: 110px; padding: 6px 9px; font-size: 12.5px; }

/* ---------- 提示 ---------- */
.empty { padding: 34px 16px; text-align: center; color: var(--ink-3); font-size: 13px; }
.empty .big { font-size: 22px; display: block; margin-bottom: 6px; opacity: .55; }
.notice {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--ink-2);
  font-size: 12.5px; border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 28%, transparent); }
.notice.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 28%, transparent); }

/* ---------- toast ---------- */
#toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast-item {
  background: var(--raise); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 13px; font-size: 12.5px;
  box-shadow: var(--shadow); max-width: 420px;
  animation: toast-in .18s ease-out;
}
.toast-item.ok { border-left-color: var(--ok); }
.toast-item.bad { border-left-color: var(--bad); }
.toast-item.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 弹层 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(6, 8, 13, .55);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 18px;
}
.modal {
  width: min(560px, 100%);
  max-height: 88vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
}
.modal-h { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line-soft); }
.modal-h h3 { margin: 0; font-size: 14px; }
.modal-h .spacer { flex: 1; }
.modal-b { padding: 14px 16px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line-soft); }

/* ---------- 代码块 ---------- */
.code {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px;
  font-family: var(--mono); font-size: 12px;
  word-break: break-all; user-select: all;
}
.url-row { display: flex; gap: 8px; align-items: center; }
.url-row .code { flex: 1; }

/* ---------- 模型 chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-2);
}
.chip.benefit { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); color: var(--warn); }
.chip .ctx { color: var(--ink-3); font-size: 10.5px; }

@media (max-width: 1100px) {
  .view { padding: 14px 14px 60px; }
  .topbar { padding: 10px 14px; }
}

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