/* ============ 设计令牌（dataviz 参考调色板 · 浅色面，已验证） ============ */
:root {
  --page: #f4f5f7;          /* 页面平面 */
  --surface: #ffffff;       /* 图表/卡片面 */
  --surface-2: #eceef1;     /* 悬浮面 */
  --ink: #17181a;           /* 主墨色 */
  --ink-2: #4d5157;         /* 次级墨色 */
  --ink-3: #8a8f98;         /* 弱墨色（轴/标签） */
  --grid: #e3e5e9;          /* 网格线 */
  --base: #c9ccd3;          /* 基线/轴 */
  --border: rgba(0,0,0,0.10);
  --series-blue: #3987e5;   /* 单序列·请求数 */
  --series-orange: #d95926; /* 单序列·流量 */
  --status-good: #0a7d0a;
  --status-warning: #b07d10;
  --status-serious: #c55f38;
  --status-critical: #c23131;
  --accent: #2f6fed;        /* 操作主色（UI 按钮，非数据色） */
  --radius: 10px;
}

/* hidden 属性必须压过作者样式的 display（#modal-root / .login-wrap 都有 display:flex）。
   否则全屏遮罩从加载起永远盖在页面上：页面发暗、输入框点不中、无法登录。 */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}
h1, h2 { margin: 0; font-weight: 600; }
code { background: var(--grid); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }

/* ============ 登录 ============ */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 340px; }
.login-card h1 { font-size: 18px; margin-bottom: 6px; }
.login-card p { color: var(--ink-2); font-size: 12px; line-height: 1.6; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--grid);
  background: var(--page); color: var(--ink); font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }
button {
  padding: 8px 14px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 13px; font-family: inherit; color: var(--ink); background: var(--surface-2);
}
button:hover { filter: brightness(1.15); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .55; filter: none; }
button.primary { background: var(--accent); color: #fff; width: 100%; margin-top: 10px; }
button.ghost { background: transparent; border: 1px solid var(--border); }
button.danger { background: transparent; border: 1px solid var(--status-critical); color: var(--status-critical); }
button.small { padding: 4px 9px; font-size: 12px; }
.form-error { color: var(--status-critical); font-size: 12px; margin-top: 8px; }

/* ============ 顶栏与布局 ============ */
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 54px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; white-space: nowrap; }
#tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; min-width: 0; }
.tab { background: transparent; border: none; color: var(--ink-2); border-radius: 8px; }
.tab.active { background: var(--surface-2); color: var(--ink); }
.tab .badge {
  display: inline-block; margin-left: 5px; background: var(--status-warning); color: #000;
  border-radius: 9px; font-size: 11px; font-weight: 700; padding: 0 6px; line-height: 16px;
}
.top-actions { display: flex; gap: 8px; }
.content { max-width: 1080px; margin: 0 auto; padding: 22px 20px 60px; }

/* ============ 统计卡与图表 ============ */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 12px; margin-bottom: 6px; }
.tile .value { font-size: 26px; font-weight: 600; }
.tile .sub { color: var(--ink-3); font-size: 11px; margin-top: 4px; }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
@media (max-width: 760px) { .charts { grid-template-columns: 1fr; } }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.chart-title { font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.bar-chart { position: relative; height: 150px; display: flex; align-items: flex-end; gap: 2px; }
.bar-chart .bar {
  flex: 1; min-width: 2px; min-height: 2px; border-radius: 4px 4px 0 0;
  background: var(--series-blue); cursor: default; position: relative;
}
.bar-chart .bar.orange { background: var(--series-orange); }
.bar-chart .bar:hover { filter: brightness(1.3); }
.bar-chart .gridline { position: absolute; left: 0; right: 0; height: 1px; background: var(--grid); pointer-events: none; }
.bar-chart .baseline { position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--base); }
.bar-chart .max-label { position: absolute; right: 0; top: -4px; font-size: 10px; color: var(--ink-3); }
.x-labels { display: flex; gap: 2px; margin-top: 5px; }
.x-labels span { flex: 1; text-align: center; font-size: 10px; color: var(--ink-3); overflow: hidden; white-space: nowrap; }

#chart-tooltip {
  position: fixed; z-index: 60; pointer-events: none; display: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--ink); box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
#chart-tooltip .tip-val { font-weight: 600; }

/* ============ 表格 ============ */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; margin-bottom: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 500; font-size: 12px; background: rgba(0,0,0,0.03); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
td .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { color: var(--ink-3); text-align: center; padding: 26px; font-size: 13px; }

/* ============ 状态徽章（图标 + 标签，颜色不单独表意） ============ */
.badge-status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); }
.badge-status .dot { width: 7px; height: 7px; border-radius: 50%; }
.badge-status.good .dot { background: var(--status-good); }
.badge-status.warning { border-color: var(--status-warning); }
.badge-status.warning .dot { background: var(--status-warning); }
.badge-status.serious { border-color: var(--status-serious); }
.badge-status.serious .dot { background: var(--status-serious); }
.badge-status.critical { border-color: var(--status-critical); }
.badge-status.critical .dot { background: var(--status-critical); }
.badge-status.muted .dot { background: var(--ink-3); }

/* ============ 区块头 / 分段控件 ============ */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; }
.section-head h2 { font-size: 15px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: none; color: var(--ink-2); padding: 6px 12px; border-radius: 0; }
.seg button.active { background: var(--surface-2); color: var(--ink); }

/* ============ 弹窗 / 提示 ============ */
#modal-root { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 22px; width: 420px; max-width: 92vw; max-height: 86vh; overflow: auto; }
.modal h2 { font-size: 16px; margin-bottom: 14px; }
.modal label { display: block; font-size: 12px; color: var(--ink-2); margin: 12px 0 5px; }
.modal .modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .modal-actions button { flex: 1; }
.key-reveal { font-size: 15px; text-align: center; word-break: break-all; background: var(--page); border: 1px solid var(--grid); border-radius: 8px; padding: 12px; margin: 10px 0; }

.plan-row { display: grid; grid-template-columns: 1.2fr 90px 110px 130px 1.5fr 52px; gap: 8px; align-items: center; margin-bottom: 8px; }
.plan-row input { margin-bottom: 0; }
.plan-editor-head { display: grid; grid-template-columns: 1.2fr 90px 110px 130px 1.5fr 52px; gap: 8px; margin-bottom: 6px; color: var(--ink-2); font-size: 12px; font-weight: 500; }
@media (max-width: 760px) { .plan-row { grid-template-columns: 1fr; } }

.provider-table table { min-width: 860px; }
.provider-table .provider-url { min-width: 180px; max-width: 280px; white-space: normal; overflow-wrap: anywhere; }
.provider-note { margin: -8px 2px 18px; font-size: 12px; line-height: 1.55; }

#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.18); max-width: 480px; }
.toast.error { border-color: var(--status-critical); }
.toast.ok { border-color: var(--status-good); }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: 54px; padding: 8px 12px; gap: 10px; }
  .brand { width: 100%; }
  #tabs { width: 100%; order: 3; padding-bottom: 2px; }
  .top-actions { margin-left: auto; }
  .content { padding: 16px 12px 48px; }
  .login-card { width: min(340px, calc(100vw - 32px)); padding: 24px; }
  .modal { width: calc(100vw - 24px); max-width: none; padding: 18px; }
  .provider-table table { min-width: 760px; }
}
