/* 设计变量沿用旧版 newapi-stats：三级文字色、细描边承担分界、
   阴影只留一层极浅的贴地投影 —— 卡片不"漂浮"。
   旧版那套供应商序列色（--s-1..6）这次没有按供应商拆分的图表，不再需要。 */
:root {
  --bg: #f7f8fa; --card: #fff;
  --text: #10121a; --text2: #5b6070; --text3: #8b90a0;
  --border: #e9ebf0; --border-strong: #d9dce4;
  --accent: #2a78d6; --accent-light: #eef4fd;
  --danger: #d03b3b;
  --ok: #1baf7a;
  --hover: rgba(16,18,26,.035);
  --shadow: 0 1px 2px rgba(16,24,40,.05);
  --shadow-lg: 0 24px 60px -20px rgba(16,24,40,.28);
  --r-sm: 5px; --r-md: 9px; --r-lg: 14px;

  /* 模型序列色：10 个槽位 + 折叠桶的灰。旧项目的 --s-1..6 是给 6 家供应商
     用的，这里模型数更多，需要更长的一串。挑色时优先保证「相邻槽位」可分辨
     （堆叠图里相邻的段才会贴在一起），并避开纯红——红留给错误态。 */
  --m-1: #2a78d6; --m-2:  #eb6834; --m-3: #1baf7a; --m-4:  #eda100; --m-5:  #8b5cf6;
  --m-6: #e87ba4; --m-7:  #0e9aa7; --m-8: #b45309; --m-9:  #6366f1; --m-10: #65a30d;
  --m-other: #b6bac6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.container { max-width: 1180px; margin: 0 auto; padding: 36px 24px 56px; }

.header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
h1 { font-size: 27px; font-weight: 650; letter-spacing: -.025em; line-height: 1.25; }
.subtitle { font-size: 13.5px; color: var(--text2); margin-top: 4px; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 表单控件 */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--text3); letter-spacing: .01em; }
.field select, .field input {
  height: 36px; padding: 0 11px; border: 1px solid var(--border-strong);
  border-radius: var(--r-md); background: var(--card); color: var(--text);
  font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field select:hover, .field input:hover { border-color: var(--text3); }
.field select:focus-visible, .field input:focus-visible,
.form-group input:focus-visible {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light);
}

.btn {
  height: 36px; padding: 0 15px; border: 1px solid transparent; border-radius: var(--r-md);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, opacity .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .88; }
.btn-outline { background: var(--card); color: var(--text2); border-color: var(--border-strong); }
.btn-outline:hover { color: var(--text); border-color: var(--text3); background: var(--hover); }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn-icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* 状态条：刷新间隔 + 上次更新时间 */
.statusbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 20px; font-size: 13px; color: var(--text2);
}
.statusbar .spacer { flex: 1; }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  display: inline-block; margin-right: 7px; vertical-align: middle;
}
.live-dot.paused { background: var(--text3); }
.live-dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.interval-picker { display: inline-flex; gap: 2px; padding: 3px; background: var(--hover); border-radius: var(--r-md); }
.interval-picker button {
  height: 26px; padding: 0 10px; background: transparent; color: var(--text2);
  border: none; border-radius: 7px; font-size: 12.5px; cursor: pointer;
  transition: background-color .15s, color .15s;
}
.interval-picker button:hover { color: var(--text); }
.interval-picker button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.interval-picker button.active { background: var(--card); color: var(--text); font-weight: 500; box-shadow: var(--shadow); }

/* 站点网格 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.site-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 20px; box-shadow: var(--shadow); container-type: inline-size;
  border-left: 3px solid var(--accent);
}
.site-card.is-error { border-left-color: var(--danger); }
.site-card.is-idle { border-left-color: var(--border-strong); }
.site-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.site-name { font-size: 15px; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-host { font-size: 11.5px; color: var(--text3); flex-shrink: 0; }

/* 主位：燃烧速率。数值用 cqi 跟着卡片宽度缩放，窄屏也不会撑破 */
.burn { display: flex; align-items: baseline; gap: 7px; }
.burn .value { font-size: clamp(28px, 15cqi, 40px); font-weight: 650; line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.burn .unit { font-size: 13px; color: var(--text3); }
.burn-label { font-size: 12px; color: var(--text3); margin-top: 2px; }

.metrics { display: flex; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.metric { flex: 1; min-width: 0; position: relative; padding-right: 10px; }
.metric + .metric { padding-left: 14px; }
.metric + .metric::before { content: ''; position: absolute; left: 0; top: 2px; bottom: 2px; width: 1px; background: var(--border); }
.metric .label { font-size: 11.5px; color: var(--text3); margin-bottom: 3px; }
.metric .value { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.015em; }

.card-error { color: var(--danger); font-size: 13px; padding: 6px 0 2px; }
.card-error .hint { color: var(--text3); font-size: 12px; margin-top: 4px; }

/* 汇总条：所有站点加总 */
.totals {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow); margin-bottom: 20px; display: flex; flex-wrap: wrap;
}
.totals .stat { padding: 16px 22px; flex: 1 1 170px; min-width: 0; position: relative; }
.totals .stat + .stat::before { content: ''; position: absolute; left: 0; top: 16px; bottom: 16px; width: 1px; background: var(--border); }
.totals .label { font-size: 12px; color: var(--text3); margin-bottom: 5px; }
.totals .value { font-size: 24px; font-weight: 650; line-height: 1.1; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }

/* 模型消耗分布 */
.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 22px; box-shadow: var(--shadow); margin-top: 20px;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 4px; }
.panel-head h2 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.panel-total { font-size: 13px; color: var(--text2); margin-bottom: 16px; font-variant-numeric: tabular-nums; }
.panel-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-controls select {
  height: 30px; padding: 0 9px; border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--card); color: var(--text); font-size: 13px; outline: none; max-width: 200px;
}
.panel-controls select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

/* 图例带金额：比 Chart.js 内置图例信息量大，所以内置的关掉了 */
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 12px; }
.chart-legend .item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text2); }
.chart-legend .swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.chart-legend .amt { color: var(--text3); font-variant-numeric: tabular-nums; }
.chart-wrap { position: relative; height: 300px; }

.model-table-wrap { overflow-x: auto; margin: 18px -22px 0; padding: 0 22px; }
table.t-model { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 13px; line-height: 1.45; table-layout: fixed; }
.t-model th:nth-child(1) { width: 34%; }
.t-model th:nth-child(2) { width: 16%; }
.t-model th:nth-child(3) { width: 14%; }
.t-model th:nth-child(4) { width: 18%; }
.t-model th:nth-child(5) { width: 18%; }
.t-model thead th { text-align: left; padding: 0 12px 8px; border-bottom: 1px solid var(--border); color: var(--text3); font-weight: 500; font-size: 12px; white-space: nowrap; }
.t-model td { padding: 9px 12px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.t-model th:first-child, .t-model td:first-child { padding-left: 0; }
.t-model th:last-child, .t-model td:last-child { padding-right: 0; }
.t-model tbody tr:last-child td { border-bottom: none; }
.t-model tbody tr:hover td { background: var(--hover); }
.text-right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
.dim { color: var(--text3); }
.model-cell { display: flex; align-items: center; gap: 8px; min-width: 0; }
.model-cell .swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.panel-note { font-size: 12px; color: var(--text3); margin-top: 12px; }

.error-banner {
  background: color-mix(in srgb, var(--danger) 9%, var(--card)); color: var(--danger);
  padding: 11px 15px; border-radius: var(--r-md); margin-bottom: 16px; font-size: 13px;
}
.empty {
  text-align: center; padding: 72px 24px; color: var(--text3); font-size: 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.empty .empty-title { color: var(--text2); font-size: 14px; margin-bottom: 3px; }

/* 弹窗：站点管理。样式与旧版一致 */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 26px; width: 540px; max-width: 92vw; max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal h2 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; margin-bottom: 16px; }
.modal #formTitle { font-size: 13px; color: var(--text2); font-weight: 600; letter-spacing: .03em; }
.modal-close { float: right; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text2); line-height: 1; }
.modal-close:hover { color: var(--text); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text3); margin-bottom: 4px; }
.form-group input {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--border-strong);
  border-radius: var(--r-md); background: var(--card); color: var(--text);
  font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.form-group .help { font-size: 11.5px; color: var(--text3); margin-top: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.site-list { margin-bottom: 20px; }
.site-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 7px; }
.site-item-info { flex: 1; min-width: 0; }
.site-item-name { font-weight: 550; font-size: 14px; }
.site-item-url { font-size: 12px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-item-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.modal-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

/* 登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 30px; width: 380px; max-width: 100%; }
.login-box h1 { font-size: 20px; margin-bottom: 4px; }
.login-box .subtitle { margin-bottom: 20px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 6px; }

@media (max-width: 640px) {
  .container { padding: 20px 14px 40px; }
  .header { flex-direction: column; align-items: stretch; gap: 12px; }
  .grid { grid-template-columns: 1fr; }
  .totals .stat { flex-basis: 50%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
