/* 设计语言沿用兄弟站 /data/www/wwwroot/ping/static/style.css：同一套配色变量、
   同一套 .panel / .chip / 表格约定，两站并排看不会像两个产品。

   配色取自已通过校验的数据可视化调色板：正常=蓝(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;
  --accent-soft:     #e8f1fd;
  --track-normal:    #cde2fb;
  --critical:        #d03b3b;
  --critical-soft:   #f7dcdc;
  --warn:            #b06a00;
  --warn-soft:       #fdf0dc;
  --good:            #0ca30c;

  --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;
    --accent-soft:     #16304f;
    --track-normal:    #184f95;
    --critical:        #d03b3b;
    --critical-soft:   #4a2020;
    --warn:            #e0a458;
    --warn-soft:       #3a2c14;

    --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: 66ch; }
.lede strong { color: var(--text-primary); font-weight: 650; }

.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; }
.degrade { margin: 10px 0 0; color: var(--warn); font-size: 13px; }

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

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; }

/* 标题 + 图标 + 帮助圆点 */
.panel-title { display: inline-flex; align-items: center; gap: 7px; }
.panel-icon { width: 19px; height: 19px; fill: var(--text-primary); flex: none; }
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; flex: none;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--surface);
  font-size: 11px; font-weight: 700; line-height: 1;
  cursor: help;
}
.help:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 计数徽章（截图里 IP 数旁边那个浅蓝方块） */
.count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 24px; padding: 0 9px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-s);
  font-size: 14px; font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.copy-btn {
  padding: 3px 6px;
  font: inherit; font-size: 13px;
  color: var(--text-muted);
  background: none; border: 0; border-radius: 4px;
  cursor: pointer;
  transition: color .15s, background-color .15s;
}
.copy-btn:hover { color: var(--accent); background: var(--surface-sunken); }
.copy-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------- 运营商筛选 ---------------- */

.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.filter-label { color: var(--text-primary); font-size: 14px; font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; }

.tab {
  padding: 6px 16px;
  font: inherit; font-size: 14px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.tab:hover { border-color: var(--accent); color: var(--accent); }
.tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab-count { opacity: .72; font-size: 12.5px; margin-left: 5px; font-variant-numeric: tabular-nums; }
.tab.is-suspect[aria-selected="true"] { background: var(--critical); border-color: var(--critical); }
.tab.is-suspect:hover { border-color: var(--critical); color: var(--critical); }

/* ---------------- IP 占比列表（对齐参考站截图的观感） ---------------- */

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

/* 竖排：第一行是 IP + 百分比（对齐截图的观感），
   可疑地址的下方再补一行原因。归属、ASN、来源数这些放进悬浮提示，
   不占版面 —— 否则一格里挤四行，读起来比截图那种两栏差很多。 */
.ip-ratio-item {
  display: flex; flex-direction: column; gap: 6px;
  padding: 11px 14px;
  background: var(--surface-sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-s);
}
.ip-ratio-item.is-suspect {
  background: var(--critical-soft);
  border-color: color-mix(in srgb, var(--critical) 30%, transparent);
}

.ip-ratio-main { display: flex; align-items: baseline; gap: 12px; }

.ip-ratio-addr {
  flex: 1; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}
.ip-ratio-item.is-suspect .ip-ratio-addr { color: var(--critical); font-weight: 600; }

.ip-ratio-percent {
  flex: none;
  color: var(--accent);
  font-size: 14px; font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.ip-ratio-item.is-suspect .ip-ratio-percent { color: var(--critical); }

.ip-reason {
  display: flex; align-items: center; gap: 5px;
  margin: 0;
  font-size: 12px; font-weight: 600; color: var(--critical);
}
/* 图标必须显式给尺寸：SVG 没有 width/height 会按容器撑满，
   实测直接变成一个占满整格的巨大三角。 */
.ip-reason svg { flex: none; width: 13px; height: 13px; fill: currentColor; }

/* ---------------- 徽章 ---------------- */

.stat-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-sunken);
}
.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); }
.chip-ecs     { background: var(--chip-ip-bg);      color: var(--chip-ip-fg); }

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

.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-warn   { background: var(--warn-soft);     border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert-icon { flex: none; width: 20px; height: 20px; margin-top: 1px; fill: var(--critical); }
.alert-warn .alert-icon { fill: var(--warn); }
.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); }

.notice {
  margin: 0 0 14px; padding: 10px 13px;
  background: var(--surface-sunken);
  border-radius: var(--radius-s);
  color: var(--text-secondary); font-size: 12.5px;
}

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

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; overflow-wrap: anywhere;
}
.cell-strong { color: var(--text-primary); font-weight: 600; }
.cell-muted { color: var(--text-muted); font-size: 12px; }

.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);
  white-space: nowrap;
}
.pill-icmp { background: var(--chip-total-bg); color: var(--chip-total-fg); }
.pill-tcp  { background: var(--warn-soft); color: var(--warn); }
.pill-ipv6 { background: var(--chip-ip-bg); color: var(--chip-ip-fg); }
.pill-cross { background: var(--warn-soft); color: var(--warn); }

.method-note { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* 虚线下划线是「可悬浮查看说明」的暗示，只有真有说明的才加，
   否则是假交互暗示。 */
.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; max-width: 90ch; }
.foot strong { color: var(--text-secondary); }

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

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

.tip {
  position: fixed; z-index: 50;
  max-width: 320px;
  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; }

.toast {
  position: fixed; z-index: 60;
  left: 50%; bottom: 28px; transform: translateX(-50%);
  padding: 9px 16px;
  background: var(--text-primary); color: var(--page);
  font-size: 13px; border-radius: var(--radius-s);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

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

@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-ratio-grid { grid-template-columns: 1fr; }
  .data-table th:nth-child(2), .data-table td:nth-child(2) { display: none; }
}

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