:root {
  --bg: #0f1419;
  --bg-alt: #151b23;
  --panel: #1a222c;
  --border: #26313d;
  --text: #d7e0ea;
  --muted: #8594a6;
  --accent: #3fb6ff;
  --accent-2: #7ee787;
  --danger: #ff6b6b;
  --warn: #ffb454;
  /* 中文字型用系統內建的，不載入任何字型檔：Latin 字型在前、中文字型在後，
     generic family 一定放最後（generic 先出現時，Windows 會直接用該語系預設，
     monospace → 細明體，後面的中文字型就不會被採用）。 */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "PingFang SC",
    "Noto Sans CJK TC", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "DejaVu Sans Mono",
    "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "Noto Sans CJK TC",
    monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* layout */
.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1200;
}
.brand { font-weight: 700; font-size: 15px; margin-right: 16px; color: #fff; }
.brand .dot { color: var(--accent-2); }
.topbar nav { display: flex; gap: 2px; flex-wrap: wrap; }
.topbar nav a {
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
}
.topbar nav a:hover { color: var(--text); text-decoration: none; background: var(--panel); }
.topbar nav a.active { color: #fff; background: var(--panel); border: 1px solid var(--border); }

.container { max-width: 1240px; margin: 0 auto; padding: 24px 20px 80px; }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.sub { color: var(--muted); margin-bottom: 20px; }

/* cards / stats */
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .grid.two { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.stat .value { font-size: 28px; font-weight: 700; color: #fff; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
table.data tr:hover td { background: rgba(255,255,255,0.02); }
.mono { font-family: var(--mono); font-size: 12px; }
code, kbd, samp { font-family: var(--mono); }

/* badges / tags */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--border);
  color: var(--text);
}
.badge.ok { background: rgba(126,231,135,.15); color: var(--accent-2); }
.badge.warn { background: rgba(255,180,84,.15); color: var(--warn); }
.badge.danger { background: rgba(255,107,107,.15); color: var(--danger); }
.badge.accent { background: rgba(63,182,255,.15); color: var(--accent); }

/* 表單元件不繼承字型，需明確指定 */
input, select, textarea, button {
  font-family: inherit;
}
input, select {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
}
button, .btn {
  background: var(--accent);
  color: #04283f;
  border: 0;
  border-radius: 6px;
  padding: 7px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
button:hover { filter: brightness(1.1); }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }

/* pagination */
.pagination { display: flex; gap: 6px; margin-top: 16px; align-items: center; }
.pagination a { padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; }
.pagination .cur { color: #fff; background: var(--panel); }

/* code / pre blocks */
pre {
  background: #0b0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 480px;
  overflow-y: auto;
}
.kv { display: grid; grid-template-columns: 220px 1fr; gap: 0; }
.kv .k { color: var(--muted); padding: 4px 8px; border-bottom: 1px solid var(--border); }
.kv .v { padding: 4px 8px; border-bottom: 1px solid var(--border); word-break: break-word; font-family: var(--mono); font-size: 12px; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } }

.empty { color: var(--muted); padding: 24px; text-align: center; }

footer { color: var(--muted); font-size: 12px; padding: 20px; text-align: center; }

/* attack map */
.container.wide { max-width: none; padding-left: 16px; padding-right: 16px; }

.stats-bar { display: flex; gap: 26px; align-items: baseline; margin-bottom: 12px; flex-wrap: wrap; }
.stat-item { display: flex; align-items: baseline; gap: 8px; }
.stat-item .s-value { font-size: 26px; font-weight: 700; color: #fff; }
.stat-item .s-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-item.hint { color: var(--muted); font-size: 12px; margin-left: auto; }
/* Public dashboard notice after a bounce from a login-protected page. */
.auth-note { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

/* GeoIP misconfiguration banner (no local database => empty map). */
.geoip-warning {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--warn);
  border-radius: 6px;
  background: rgba(255, 180, 84, .08);
  color: var(--warn);
  font-size: 13px;
}
.geoip-warning code { color: inherit; }

/* ECharts 會清空容器，所以按鈕/圖例/提示放在外層 .map-shell（絕對定位疊在 canvas 上）。
   高度取 40vw 讓地圖框接近世界地圖 2.5:1 的比例，contain 貼合後幾乎沒有留白。 */
.map-shell {
  position: relative;
  /* 39.5vw ≈ 世界地圖 2.55:1 的高度，contain 貼合後幾乎沒有上下留白；
     窄螢幕用 210px 下限，避免地圖框比地圖本身高太多。 */
  height: clamp(210px, 39.5vw, calc(100vh - 240px));
  border-radius: 12px; border: 1px solid var(--border);
  background: radial-gradient(120% 130% at 50% 42%, #101922 0%, #0a0e13 68%);
  overflow: hidden;
}
#map { position: absolute; inset: 0; }
/* 縮放/平移由 geo.roam 處理：無圖磚、無外部請求 */
#map canvas { outline: none; }

/* 縮放 / 重設視野 */
.map-tools { position: absolute; left: 12px; top: 12px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
.map-btn {
  width: 30px; height: 30px; padding: 0; display: grid; place-items: center;
  border: 1px solid #2a3441; border-radius: 6px; background: rgba(13, 17, 23, .82);
  color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer;
}
.map-btn:hover { color: #fff; border-color: var(--accent); background: rgba(13, 17, 23, .95); }
.map-btn:active { transform: translateY(1px); }

/* 圖例：光點顏色 = 該來源 IP 的攻擊次數 */
.map-legend {
  position: absolute; right: 12px; top: 12px; z-index: 5;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 10px; border: 1px solid #222c37; border-radius: 8px;
  background: rgba(11, 15, 20, .72); color: var(--muted); font-size: 11px;
}
.map-legend .lg-head { color: #97a6b8; letter-spacing: .03em; }
.map-legend .lg-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.map-legend .lg-item i {
  width: 9px; height: 9px; border-radius: 50%; background: var(--c);
  box-shadow: 0 0 7px var(--c);
}
.map-legend .lg-item.hp { border-left: 1px solid #26313d; padding-left: 9px; }
@media (max-width: 720px) { .map-legend .lg-head { display: none; } }

/* tooltip 內的文字層級 */
.tt-sub { color: #8594a6; }
.tt-hot { color: #fff; font-weight: 600; }
.map-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; pointer-events: none;
}
.map-hint[hidden] { display: none; }
.map-tip {
  position: absolute; left: 12px; bottom: 8px; z-index: 5;
  font-size: 11px; color: var(--muted); opacity: .55; pointer-events: none;
  letter-spacing: .01em;
}

.flag { width: 20px; height: 15px; vertical-align: -2px; margin-right: 6px; border-radius: 2px; object-fit: cover; }
.loc .city { color: var(--muted); }
.tt-flag { width: 18px; height: 13px; vertical-align: -2px; margin-right: 5px; border-radius: 2px; object-fit: cover; }

.feed td { vertical-align: top; }
.feed td.nowrap { white-space: nowrap; }
.feed td.path { max-width: 240px; word-break: break-all; }
.feed td.post { max-width: 320px; }
/* 固定高度的捲動區：padding 留在外層，捲動交給 .feed，內容才不會蓋到 sticky 表頭 */
.feed-card { padding: 0; overflow: hidden; }
.feed { max-height: 480px; overflow: auto; }
/* border-collapse: collapse 會讓 WebKit 的 sticky 表頭偏移，改用 separate */
.feed table.data { border-collapse: separate; border-spacing: 0; }
.feed thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #1a222c;
}
.feed table.data th:first-child,
.feed table.data td:first-child { padding-left: 16px; }
.feed table.data th:last-child,
.feed table.data td:last-child { padding-right: 16px; }

/* POST 資料彈出視窗 */
.detail-btn {
  background: var(--bg-alt);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
}
.detail-btn:hover { border-color: var(--accent); color: #fff; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 13, .62);
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  max-height: 80vh;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 14px;
}
.modal-close {
  background: transparent; color: var(--muted); border: 0;
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 8px; border-radius: 6px;
}
.modal-close:hover { color: #fff; background: var(--border); }
.modal-body {
  margin: 0; padding: 14px 16px; overflow: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-all; color: var(--text);
}
body.modal-open { overflow: hidden; }
