/* DeepSeek 用量路由 · 管理后台样式 —— 主题令牌式（浅/深），图表令牌与 dataviz 规范一致 */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f4f4f0;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --good: #0ca30c; --good-ink: #006300;
  --warn: #fab219; --warn-ink: #8a5a00;
  --serious: #ec835a; --serious-ink: #9c3f1d;
  --critical: #d03b3b; --critical-ink: #a02a2a;
  --shadow: 0 1px 2px rgba(11,11,11,.05), 0 4px 16px rgba(11,11,11,.06);
  --radius: 10px;
  --series-1: #2a78d6;
  --chart-surface: #fcfcfb;
}
[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255,255,255,0.10);
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-soft: #184f95;
  --good: #0ca30c; --good-ink: #0ca30c;
  --warn: #fab219; --warn-ink: #fab219;
  --serious: #ec835a; --serious-ink: #ec835a;
  --critical: #d03b3b; --critical-ink: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --series-1: #3987e5;
  --chart-surface: #1a1a19;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
/* 文本防溢出：任何容器都不允许内容横向冲出边界 */
.card, .tile, .modal, .login-card, .toast, .filter-row { min-width: 0; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.key-text { overflow-wrap: anywhere; word-break: break-all; }
table.grid { table-layout: auto; }
table.grid th, table.grid td { overflow-wrap: break-word; word-break: break-word; max-width: 0; /* 允许单元格压缩换行 */ }
.tile .val { overflow-wrap: anywhere; }
input, select, textarea { max-width: 100%; }
.chart-tip { max-width: min(340px, 90vw); white-space: normal; text-align: center; overflow-wrap: anywhere; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--page); color: var(--ink);
  font-size: 14px; line-height: 1.55;
}
.hidden { display: none !important; }
button { font: inherit; }
a { color: var(--accent); }

/* ---------- 登录 ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 500px at 70% -10%, var(--accent-soft), transparent 60%), var(--page);
}
.login-card {
  width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 28px 30px 26px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { font-size: 19px; text-align: center; letter-spacing: .2px; }
.login-sub { text-align: center; color: var(--ink-2); font-size: 12.5px; margin-top: -8px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--ink-2); font-size: 13px; }
.login-card input, .field input, .field select {
  background: var(--surface); border: 1px solid var(--axis); border-radius: 8px;
  color: var(--ink); padding: 8px 10px; font-size: 14px; outline: none; width: 100%;
}
.login-card input:focus, .field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.form-error { color: var(--critical-ink); font-size: 13px; min-height: 18px; }

/* ---------- 框架 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 22px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand em { font-style: normal; color: var(--ink-2); font-weight: 400; font-size: 13px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 15px; letter-spacing: .5px;
}
.brand-mark.sm { width: 26px; height: 26px; font-size: 12px; border-radius: 7px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.clock { color: var(--ink-muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.user { color: var(--ink-2); font-size: 13px; }
.badge {
  background: var(--serious); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 11.5px; font-weight: 600;
}
.nav {
  display: flex; gap: 2px; padding: 0 22px; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.nav-item {
  border: 0; background: none; color: var(--ink-2); padding: 10px 14px; cursor: pointer;
  font-size: 13.5px; border-bottom: 2px solid transparent; white-space: nowrap;
}
.nav-item:hover { color: var(--ink); }
.nav-item.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.nav-item .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--critical); margin-left: 5px; vertical-align: 1px;
}
.content { padding: 18px 22px 30px; max-width: 1280px; margin: 0 auto; }
.foot { padding: 8px 22px 16px; color: var(--ink-muted); font-size: 11.5px; text-align: center; }

/* ---------- 通用组件 ---------- */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 7px 14px; font-size: 13.5px;
  cursor: pointer; background: var(--surface-2); color: var(--ink); transition: filter .12s;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--critical); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--axis); }
.btn.sm { padding: 3px 10px; font-size: 12.5px; border-radius: 6px; }
.btn.block { width: 100%; padding: 10px; }
.btn.icon { padding: 3px 8px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: baseline; gap: 8px; }
.card-title .sub { font-weight: 400; color: var(--ink-muted); font-size: 12px; }
.card-title .spacer { flex: 1; }

table.grid {
  width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums;
}
table.grid th {
  text-align: left; color: var(--ink-2); font-weight: 500; font-size: 12px;
  border-bottom: 1px solid var(--border); padding: 6px 10px; white-space: nowrap;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--grid); font-size: 13px; vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid .num { text-align: right; }
table.grid th.num { text-align: right; }
.table-scroll { overflow: auto; max-height: 560px; }

.mono, code, .key-text {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px;
}
.key-text {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; word-break: break-all; user-select: all;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px;
  padding: 1px 9px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border);
}
.chip.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); border-color: transparent; }
.chip.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn-ink); border-color: transparent; }
.chip.serious { background: color-mix(in srgb, var(--serious) 16%, transparent); color: var(--serious-ink); border-color: transparent; }
.chip.critical { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical-ink); border-color: transparent; }
.chip.muted { background: var(--surface-2); color: var(--ink-muted); }
.chip .ico { font-size: 11px; line-height: 1; }

/* 统计卡 */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 12px; box-shadow: var(--shadow);
}
.tile .lbl { color: var(--ink-2); font-size: 12.5px; }
.tile .val { font-size: 26px; font-weight: 600; margin-top: 2px; letter-spacing: -0.2px; }
.tile.hero .val { font-size: 38px; }
.tile .sub { color: var(--ink-muted); font-size: 12px; margin-top: 1px; }
.tile .val .unit { font-size: 13px; font-weight: 400; color: var(--ink-2); margin-left: 3px; }

/* 仪表盘：顶部 hero + 指标行 + 图表/排行双栏 */
.dash-stack { display: flex; flex-direction: column; gap: 14px; }
.dash-hero { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 26px; }
.dash-hero .hm { flex: 1 1 300px; }
.dash-hero .hm .val { font-size: 34px; font-weight: 650; letter-spacing: -0.3px; }
.dash-hero .hm .val .unit { font-size: 14px; font-weight: 400; color: var(--ink-2); margin-left: 4px; }
.dash-mini { display: flex; gap: 28px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.dash-mini .k { color: var(--ink-2); font-size: 12px; }
.dash-mini .v { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dash-mini .v small { font-weight: 400; color: var(--ink-muted); font-size: 12px; margin-left: 3px; }
.dash-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.dash-tiles .tile { padding: 12px 16px 10px; }
.dash-cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 1040px) { .dash-cols { grid-template-columns: minmax(0, 1fr); } }

/* 单元格主值/副行（用量明细表用） */
.cell-main { display: block; }
.cell-sub { display: block; color: var(--ink-muted); font-size: 11.5px; margin-top: 1px; }
.cell-sub .sep { margin: 0 5px; color: var(--axis); }
td.num .cell-sub { text-align: right; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label, .field > span.l { color: var(--ink-2); font-size: 12.5px; }
.field .hint { color: var(--ink-muted); font-size: 11.5px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filter-row .field { min-width: 130px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--ink-2); font-size: 13px; }

/* 提示 */
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--ink); color: var(--page); border-radius: 8px; padding: 9px 14px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 380px; animation: slidein .18s ease;
}
.toast.err { background: var(--critical); color: #fff; }
.toast.ok { background: var(--good-ink); color: #fff; }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 弹窗 */
#modal-root { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; }
#modal-root.open { display: flex; }
.modal-wrap { position: relative; z-index: 2; }   /* 弹窗必须在遮罩之上（遮罩为后置兄弟节点） */
.modal-backdrop { position: absolute; inset: 0; z-index: 1; background: rgba(0,0,0,.45); }
.modal {
  position: relative; background: var(--surface); border-radius: 14px; border: 1px solid var(--border);
  width: min(600px, calc(100vw - 40px)); max-height: 86vh; overflow: auto;
  box-shadow: var(--shadow); padding: 20px 22px;
}
.modal h3 { font-size: 15.5px; margin-bottom: 12px; }
.modal .m-body { display: flex; flex-direction: column; gap: 12px; }
.modal .m-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.warn-note {
  background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn-ink);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: 8px; padding: 9px 12px; font-size: 12.8px;
}
.info-note {
  background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 12.8px;
}

/* 图表 */
.chart-card { padding: 16px 18px 10px; }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { display: block; width: 100%; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--page);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px; box-shadow: var(--shadow);
  z-index: 5; white-space: nowrap; transform: translate(-50%, calc(-100% - 8px));
}
.chart-tip .v { font-weight: 700; font-size: 13.5px; }
.chart-tip .k { opacity: .8; font-size: 11.5px; }
.meter { height: 6px; border-radius: 4px; background: var(--axis); overflow: hidden; min-width: 60px; }
.meter > i {
  display: block; height: 100%; border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}
.meter > i.warn { background: var(--warn); }
.meter > i.crit { background: var(--critical); }
.empty { color: var(--ink-muted); text-align: center; padding: 34px 0; font-size: 13px; }
.section-note { color: var(--ink-muted); font-size: 12px; margin: -6px 0 10px; }
input[type="number"] { font-variant-numeric: tabular-nums; }
