/* 配色取自已通过校验的数据可视化调色板：
   亮/暗两套色都跑过 validate_palette，正常=蓝(slot 1)、污染=critical 状态色，
   两者最差相邻 CVD ΔE 75.7（阈值 ≥12），对比度均 ≥3:1。
   注意：数值文字一律用文本色，不穿数据色 —— 颜色只由进度条承担。 */

:root {
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --surface-sunken:  #f2f1ed;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);

  --accent:          #2a78d6;   /* 正常解析 —— 数据色 */
  --track-normal:    #cde2fb;   /* 蓝色 ramp 100，同色系轨道 */
  --critical:        #d03b3b;   /* 污染地址 —— 状态色 */
  --critical-soft:   #f7dcdc;
  --good:            #0ca30c;

  /* 状态徽章用的浅底深字，文字对比度均 > 6:1 */
  --chip-ip-bg:      #e8f1fd;  --chip-ip-fg:      #184f95;
  --chip-total-bg:   #e4f5e4;  --chip-total-fg:   #006300;
  --chip-timeout-bg: #fbe6e6;  --chip-timeout-fg: #a32a2a;

  --radius:   10px;
  --radius-s: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page:            #0d0d0d;
    --surface:         #1a1a19;
    --surface-sunken:  #232322;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --gridline:        #2c2c2a;
    --baseline:        #383835;
    --border:          rgba(255, 255, 255, 0.10);

    --accent:          #3987e5;
    --track-normal:    #184f95;
    --critical:        #d03b3b;
    --critical-soft:   #4a2020;

    --chip-ip-bg:      #16304f;  --chip-ip-fg:      #9ec5f4;
    --chip-total-bg:   #12331a;  --chip-total-fg:   #6ddc6d;
    --chip-timeout-bg: #40201f;  --chip-timeout-fg: #f0a0a0;
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* 必须放在所有组件规则之前生效的位置：类选择器上的 display（如 .alert 的 flex、
   .chip 的 inline-flex）优先级高于 UA 样式表里的 [hidden]{display:none}，
   不加这条的话 JS 设 hidden 会被 CSS 的 display 顶掉，元素永远藏不住。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------- 页头 ---------------- */

.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 28px 0 24px;
}
.masthead h1 { margin: 0 0 6px; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.lede { margin: 0 0 18px; color: var(--text-secondary); font-size: 14px; max-width: 62ch; }
.lede code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em; background: var(--surface-sunken);
  padding: 1px 5px; border-radius: 4px; color: var(--text-primary);
}

.query { display: flex; gap: 10px; max-width: 620px; }
.query input {
  flex: 1; min-width: 0;
  padding: 11px 14px;
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-s);
  transition: border-color .15s, box-shadow .15s;
}
.query input::placeholder { color: var(--text-muted); }
.query input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.query button {
  padding: 11px 22px;
  font: inherit; font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0; border-radius: var(--radius-s);
  cursor: pointer;
  transition: filter .15s;
}
.query button:hover:not(:disabled) { filter: brightness(1.08); }
.query button:disabled { opacity: .55; cursor: default; }

.form-error { margin: 10px 0 0; color: var(--critical); font-size: 14px; }

/* ---------------- 面板 ---------------- */

main { padding: 24px 20px 8px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
  margin-bottom: 16px;
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.panel-meta { color: var(--text-muted); font-size: 13px; margin-left: auto; }

/* ---------------- 统计徽章 ---------------- */

.stat-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
}
.chip b { font-size: 15px; font-weight: 650; }
.chip-ip      { background: var(--chip-ip-bg);      color: var(--chip-ip-fg); }
.chip-total   { background: var(--chip-total-bg);   color: var(--chip-total-fg); }
.chip-timeout { background: var(--chip-timeout-bg); color: var(--chip-timeout-fg); }
.chip-timeout.is-zero { background: var(--surface-sunken); color: var(--text-muted); }

/* ---------------- 告警 ---------------- */

.alert {
  display: flex; gap: 11px;
  padding: 13px 15px;
  margin-bottom: 16px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
}
.alert-danger { background: var(--critical-soft); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }
.alert-icon { flex: none; width: 20px; height: 20px; margin-top: 1px; fill: var(--critical); }
.alert-body strong { display: block; font-size: 14px; color: var(--text-primary); }
.alert-body p { margin: 4px 0 0; font-size: 13px; color: var(--text-secondary); }

/* ---------------- 筛选 ---------------- */

.filter-row { margin-bottom: 14px; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.switch input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ---------------- IP 卡片 ---------------- */

.ip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
  gap: 10px;
}
.more .ip-grid { margin-top: 10px; }

.ip-card {
  position: relative;
  padding: 12px 14px 13px;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
.ip-card.is-suspect { background: var(--critical-soft); }

.ip-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 9px; }
.ip-addr {
  flex: 1; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}
.ip-count {
  font-size: 14px; font-weight: 650; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.ip-percent {
  font-size: 12.5px; color: var(--text-secondary); min-width: 50px; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* 进度条：细杆 + 数据端 4px 圆角，轨道是同色系浅色步进，
   所以「这条是高是低」在整条上都读得出来，而不是只看填充部分。 */
.meter { height: 8px; border-radius: 4px; background: var(--track-normal); overflow: hidden; }
.is-suspect .meter { background: var(--critical-soft); }
.meter-fill {
  height: 100%; min-width: 3px;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
  transition: width .45s cubic-bezier(.4, 0, .2, 1);
}
.is-suspect .meter-fill { background: var(--critical); }

.ip-reason {
  display: flex; align-items: center; gap: 5px;
  margin: 9px 0 0;
  font-size: 12px; font-weight: 600; color: var(--critical);
}
.ip-reason svg { flex: none; width: 13px; height: 13px; fill: currentColor; }

.no-answer { margin: 4px 0 0; color: var(--text-secondary); font-size: 14px; }

/* ---------------- 折叠区 ---------------- */

details.more { margin-top: 14px; }
details.more > summary,
details.nodes > summary {
  cursor: pointer; list-style: none;
  font-size: 13px; color: var(--text-secondary);
  padding: 7px 0;
}
details.more > summary::-webkit-details-marker,
details.nodes > summary::-webkit-details-marker { display: none; }
details.more > summary::before,
details.nodes > summary::before {
  content: "▸"; display: inline-block; width: 14px; color: var(--text-muted);
  transition: transform .15s;
}
details[open] > summary::before { transform: rotate(90deg); }
details.more > summary:hover, details.nodes > summary:hover { color: var(--text-primary); }

details.nodes > summary {
  display: flex; align-items: center; gap: 4px;
  padding: 0; font-size: 15px;
}
.summary-title { font-weight: 650; color: var(--text-primary); }

/* ---------------- 节点表 ---------------- */

.table-scroll { overflow-x: auto; margin-top: 14px; }
.nodes-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.nodes-table th, .nodes-table td {
  text-align: left; padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--gridline);
  vertical-align: top;
}
.nodes-table th {
  font-weight: 600; color: var(--text-muted); font-size: 12px;
  text-transform: none; white-space: nowrap;
}
.nodes-table td { color: var(--text-secondary); }
.nodes-table .num { text-align: right; padding-right: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nodes-table tbody tr:last-child td { border-bottom: 0; }

.node-name { color: var(--text-primary); font-weight: 600; white-space: nowrap; }
.node-region { color: var(--text-muted); font-size: 12px; }
.node-ips {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; overflow-wrap: anywhere;
}
.node-fail { color: var(--critical); }
.pill {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  background: var(--surface-sunken); color: var(--text-secondary);
}
/* 虚线下划线是「可悬浮查看说明」的暗示，只有可疑地址才有说明文字，
   所以只给可疑地址加，否则是假交互暗示。 */
.ip-tag.is-suspect { color: var(--critical); cursor: help; border-bottom: 1px dotted var(--critical); }

/* ---------------- 空状态 / 页脚 ---------------- */

.empty {
  padding: 40px 20px; text-align: center;
  color: var(--text-muted); font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.foot { padding: 8px 20px 40px; }
.foot p { margin: 0; color: var(--text-muted); font-size: 12.5px; }

/* 重新检测时保留上一次结果并降低透明度，避免骨架屏闪烁和布局跳动 */
#result.is-loading { opacity: .45; transition: opacity .12s; }

/* ---------------- 悬浮提示 ---------------- */

.tip {
  position: fixed; z-index: 50;
  max-width: 300px;
  padding: 8px 11px;
  background: var(--text-primary);
  color: var(--page);
  font-size: 12px; line-height: 1.5;
  border-radius: var(--radius-s);
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
.tip b { font-weight: 650; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 640px) {
  .masthead { padding: 20px 0 18px; }
  .query { flex-direction: column; }
  .query button { width: 100%; }
  .panel { padding: 15px 15px 16px; }
  .panel-meta { margin-left: 0; width: 100%; }
  .ip-grid { grid-template-columns: 1fr; }
  .nodes-table th:nth-child(2), .nodes-table td:nth-child(2) { display: none; }
}

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