:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --grid: #e8e6e1;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #8a5a00;
  --critical: #d03b3b;
  --critical-ink: #b02a2a;
  --danger-bg: #fdecec;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --grid: #2a2a28;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8e8d86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #0ca30c;
    --series-7: #9085e9;
    --series-8: #e66767;
    --good-ink: #4cc74c;
    --warning-ink: #fab219;
    --critical-ink: #ef7272;
    --danger-bg: #3a1d1d;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2b;
  --grid: #2a2a28;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8e8d86;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #0ca30c;
  --series-7: #9085e9;
  --series-8: #e66767;
  --good-ink: #4cc74c;
  --warning-ink: #fab219;
  --critical-ink: #ef7272;
  --danger-bg: #3a1d1d;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }

/* 顶栏 */
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.controls { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.controls .seg button { padding: 6px 14px; font-size: 14px; }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
.brand img { width: 32px; height: 32px; }
.brand h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: .01em; }
.brand .sub { color: var(--text-muted); font-size: 13px; }
.btn {
  border: 1px solid var(--border); background: var(--surface-1); border-radius: 999px;
  padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); background: var(--accent); }
.btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: none; }
.busy .spin { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-line { color: var(--text-secondary); font-size: 13px; margin: -8px 0 16px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.banner { background: var(--danger-bg); color: var(--critical-ink); border-radius: 12px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.banner[hidden] { display: none; }

/* 用量卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 14px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.card-head .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { margin-left: auto; font-size: 12px; padding: 2px 8px; border-radius: 999px; display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; background: var(--surface-2); }
.chip.good { color: var(--good-ink); }
.chip.warning { color: var(--warning-ink); }
.chip.critical { color: var(--critical-ink); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.warning .dot { background: var(--warning); }
.chip.critical .dot { background: var(--critical); }
.chip.good .dot { background: var(--good); }
.big { font-size: 40px; font-weight: 650; line-height: 1.1; margin: 10px 0 12px; letter-spacing: -.01em; }
.big small { font-size: 18px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; min-width: 2px; transition: width .4s ease; }
.reset { margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.reset b { color: var(--text-primary); font-weight: 600; }

/* 面板 */
.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h2 { font-size: 16px; margin: 0; font-weight: 620; }
.panel-head > .seg, .panel-head > #statusAge { margin-left: auto; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 4px 12px; border-radius: 999px; cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .endlabel { font-size: 11px; fill: var(--text-secondary); }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hoverdot { stroke: var(--surface-1); stroke-width: 2; }
.empty { color: var(--text-muted); text-align: center; padding: 48px 0; font-size: 14px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.14); min-width: 150px; z-index: 2;
}
.tooltip[hidden] { display: none; }
.tooltip .t { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip .row b { margin-left: auto; padding-left: 10px; color: var(--text-primary); font-weight: 600; }

details.table-view { margin-top: 10px; }
details.table-view summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.table-scroll { overflow-x: auto; max-height: 320px; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: right; padding: 5px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }

/* 状态面板 */
.muted { color: var(--text-muted); font-size: 12px; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 12px; }
.status-block { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.status-block h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 0; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); overflow-wrap: anywhere; }
.mcp { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.mcp li { display: flex; align-items: flex-start; gap: 10px; padding: 5px 0; min-width: 0; }
.mcp .who { min-width: 0; display: flex; flex-direction: column; }
.mcp .n { overflow-wrap: anywhere; }
.mcp .h { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcp .chip { flex: none; margin-left: 0; min-width: 5.6em; }
.banner-line { font-size: 13px; color: var(--text-primary); font-weight: 600; margin: -2px 0 8px; }
.doctor-sum { margin-top: 10px; }
.doctor-sum .chip { margin-left: 0; white-space: normal; }
.doctor-item { margin-top: 6px; font-size: 13px; color: var(--text-secondary); overflow-wrap: anywhere; }
.status-err { color: var(--critical-ink); font-size: 12px; margin-top: 6px; white-space: pre-wrap; word-break: break-word; }

pre.details { margin: 0; white-space: pre-wrap; word-break: break-word; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace; color: var(--text-secondary); }
.foot { color: var(--text-muted); font-size: 12px; text-align: center; margin-top: 8px; }

/* 登录页 */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 20px; padding: 28px 24px; box-shadow: var(--shadow); text-align: center; }
.login img { width: 48px; height: 48px; }
.login h1 { font-size: 20px; margin: 10px 0 4px; }
.login p { color: var(--text-secondary); font-size: 14px; margin: 0 0 18px; }
.login input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-primary); font: inherit; margin-bottom: 12px;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }
.login .err { color: var(--critical-ink); font-size: 13px; min-height: 20px; margin-top: 10px; }

@media (max-width: 520px) {
  .big { font-size: 34px; }
  .brand .sub { display: none; }
  .top { gap: 10px; }
  .controls { width: 100%; justify-content: flex-end; }
  .controls .seg { margin-right: auto; }
  .brand { gap: 8px; }
  .brand img { width: 28px; height: 28px; }
  .brand h1 { font-size: 17px; white-space: nowrap; }
  .top .btn { padding: 6px 11px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .meter > span { transition: none; }
  .spin { animation-duration: 2s; }
}

/* 使用统计 */
:root { --heat-0: var(--surface-2); --heat-1: #b7d3f6; --heat-2: #6da7ec; --heat-3: #2a78d6; --heat-4: #184f95; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --heat-1: #184f95; --heat-2: #256abf; --heat-3: #5598e7; --heat-4: #9ec5f4; }
}
:root[data-theme="dark"] { --heat-1: #184f95; --heat-2: #256abf; --heat-3: #5598e7; --heat-4: #9ec5f4; }
.stats-section { margin-top: 14px; }
.stats-section:first-child { margin-top: 0; }
.stats-section h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 0 0 8px; }
.heatmap { overflow-x: auto; }
.heatmap svg { display: block; width: 100%; min-width: 560px; height: auto; }
.heatmap text { fill: var(--text-muted); font-size: 9px; }
.heatmap .l0 { fill: var(--heat-0); } .heatmap .l1 { fill: var(--heat-1); } .heatmap .l2 { fill: var(--heat-2); }
.heatmap .l3 { fill: var(--heat-3); } .heatmap .l4 { fill: var(--heat-4); }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.heat-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 10px; padding: 9px 12px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--text-muted); }
.tile .v { font-size: 17px; font-weight: 620; overflow-wrap: anywhere; }
.stats-note { font-size: 12px; color: var(--text-muted); margin-top: 8px; font-style: italic; }
pre.ascii { margin: 0; font: 11px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text-secondary); overflow-x: auto; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.daily svg { display: block; width: 100%; height: auto; overflow: visible; }
.daily text { fill: var(--text-muted); font-size: 11px; }
.daily .gridline { stroke: var(--grid); }
.daily .baseline { stroke: var(--border); }
.daily-wrap { position: relative; }
.ascii-legend { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.models { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 8px; margin-top: 10px; }
.model { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.model .top { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.model .top b { margin-left: auto; font-weight: 620; }
.model .bar { height: 6px; background: var(--surface-1); border-radius: 999px; overflow: hidden; margin: 7px 0; }
.model .bar span { display: block; height: 100%; border-radius: 999px; min-width: 2px; }
.model .sub { font-size: 12px; color: var(--text-secondary); }

/* 服务器资源 */
.sys { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 10px; margin-bottom: 16px; }
.sys-tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "head spark" "val spark" "meter meter" "sub sub"; column-gap: 10px; }
.sys-head { grid-area: head; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.sys-head .chip { margin-left: 4px; }
.sys-val { grid-area: val; font-size: 24px; font-weight: 650; line-height: 1.2; }
.sys-val small { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-left: 1px; }
.sys-spark { grid-area: spark; align-self: center; }
.sys-spark svg { display: block; width: 110px; height: 34px; }
.sys-spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.sys-spark .area { fill: var(--accent); opacity: .12; stroke: none; }
.sys-tile .meter { grid-area: meter; margin-top: 8px; height: 6px; }
.sys-sub { grid-area: sub; margin-top: 6px; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.fill-good { background: var(--accent); } .fill-warning { background: var(--warning); } .fill-critical { background: var(--critical); }
.check-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.check-list li { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; min-width: 0; }
.check-list .cn { font-weight: 600; flex: none; min-width: 5.5em; }
.check-list .cm { color: var(--text-secondary); overflow-wrap: anywhere; min-width: 0; }
details.more { margin-top: 8px; font-size: 13px; }
details.more summary { cursor: pointer; color: var(--text-secondary); }
@media (max-width: 520px) {
  .sys { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .sys-tile { padding: 9px 10px; grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "val" "meter" "sub"; }
  .sys-spark { display: none; }
  .sys-val { font-size: 19px; }
  .sys-sub { font-size: 11px; }
}
