:root {
  --bg: #0f1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3fb950;
  --accent2: #2ea043;
  --danger: #f85149;
  --ok: #3fb950;
  --sidebar-w: 220px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: #010409;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  z-index: 40;
}
#sideNav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.brand {
  padding: 1rem 1rem 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
}
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 0.72rem; margin-top: 0.25rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--text); background: #161b22; }
.nav-item.active { color: var(--text); background: #161b22; border-left-color: var(--accent); }
.nav-group {
  border-top: 1px solid var(--border);
  margin-top: 0.35rem;
  padding-top: 0.15rem;
}
.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.65rem 1rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-family: inherit;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  text-align: left;
}
.nav-group-toggle:hover,
.nav-group-toggle.active { color: var(--text); background: #161b22; }
.nav-group-toggle.active { border-left-color: var(--accent); }
.nav-group-chevron {
  flex-shrink: 0;
  opacity: 0.7;
  transition: transform 0.15s ease;
}
.nav-group.open .nav-group-chevron { transform: rotate(180deg); }
.nav-sub { display: none; }
.nav-group.open .nav-sub { display: block; }
.nav-sub-item {
  padding-left: 1.35rem;
  font-size: 0.84rem;
}
.sidebar-foot {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}
.sidebar-version {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: center;
  font-variant-numeric: tabular-nums;
  user-select: text;
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; margin-left: var(--sidebar-w); min-height: 100vh; }
.topbar {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.topbar h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.topbar p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.85rem; }
.content { padding: 1.25rem 1.5rem 3rem; flex: 1; }
.btn {
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: #21262d; border: 1px solid var(--border); color: var(--text); }
.btn.purple,
.btn.green { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.78rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; align-items: center; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.domain-card h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.domain-card .meta { color: var(--muted); font-size: 0.8rem; }
.domain-card .actions { margin-top: 0.75rem; display: flex; gap: 0.35rem; justify-content: flex-end; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
table.data th, table.data td {
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.5rem;
  text-align: left;
}
table.data th { color: var(--muted); font-weight: 600; }
.toggle {
  width: 38px;
  height: 20px;
  border-radius: 10px;
  background: #484f58;
  position: relative;
  cursor: pointer;
  display: inline-block;
  vertical-align: middle;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: left 0.15s;
}
.toggle.on::after { left: 20px; }
.toggle.toggle-saving {
  opacity: 0.55;
  pointer-events: none;
}

.ad-save-status {
  margin: 0.65rem 0 0.25rem;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  background: #161b22;
  border: 1px solid var(--border);
  color: var(--muted);
}

.ad-save-status-ok {
  color: #3fb950;
  border-color: rgba(63, 185, 80, 0.35);
  background: rgba(63, 185, 80, 0.08);
}

.ad-save-status-err {
  color: #f85149;
  border-color: rgba(248, 81, 73, 0.35);
  background: rgba(248, 81, 73, 0.08);
}

.ad-save-status-pending {
  color: var(--accent);
  border-color: rgba(63, 185, 80, 0.35);
}
.filters { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.filter-tab {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
}
.filter-tab:hover { color: var(--text); border-color: #484f58; background: #161b22; }
.filter-tab.active { background: #21262d; color: var(--text); border-color: var(--accent); }
input, select, textarea {
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  font-size: 0.85rem;
  width: 100%;
}
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
textarea { min-height: 100px; font-family: inherit; }
label { display: block; font-size: 0.78rem; color: var(--muted); margin: 0.65rem 0 0.25rem; }
label.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.45;
  cursor: pointer;
}
label.check-row input[type="checkbox"],
label.check-row input[type="radio"] {
  margin-top: 0.2rem;
}
.check-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0 0.5rem;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .form-row { grid-template-columns: 1fr; } }
.pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-backdrop.show { display: flex; }
body.modal-open .layout,
body.modal-open .fab {
  pointer-events: none;
}
body.modal-open .modal-backdrop {
  pointer-events: auto;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  padding: 1.25rem;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.chip-list { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0; }
.chip {
  background: #21262d;
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.chip button { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; }
.fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.fab-icon-svg {
  width: 26px;
  height: 26px;
  display: block;
}

.fab:hover {
  filter: brightness(1.08);
}
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 0.8rem; }
.content a:not(.btn),
.modal a:not(.btn),
.hint a {
  color: var(--accent);
  text-decoration: none;
}
.content a:not(.btn):hover,
.modal a:not(.btn):hover,
.hint a:hover {
  color: var(--accent2);
  text-decoration: underline;
}
.content a:not(.btn):visited,
.modal a:not(.btn):visited,
.hint a:visited {
  color: var(--accent);
}
.empty { text-align: center; color: var(--muted); padding: 2rem; }
.switch-row { display: flex; flex-wrap: wrap; gap: 1rem; margin: 0.75rem 0; }
.switch-item { display: flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; }
.country-rule-default {
  margin: 1rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #161b22;
}
.country-rule-default h3 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.country-rule-card {
  margin: 0.75rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1117;
}
.country-rule-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.empty-country { margin: 0.75rem 0; }
.cfg-status-card {
  margin-top: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1117;
}
.cfg-status-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.cfg-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.ok { background: #3fb950; box-shadow: 0 0 6px rgba(63, 185, 80, 0.6); }
.status-dot.err { background: var(--danger); }
.cfg-linked-list { margin: 0; padding-left: 1.2rem; font-size: 0.82rem; }
.status-preview { font-size: 0.78rem; margin-top: 0.35rem; }
.status-preview .url-cell { word-break: break-all; white-space: normal; }
.country-picker {
  position: relative;
  max-width: 420px;
  margin: 0.35rem 0 0.75rem;
}
.country-picker input {
  width: 100%;
  box-sizing: border-box;
}
.country-picker input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(63, 185, 80, 0.25);
}
.country-picker-dropdown {
  display: none;
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 280px;
  overflow: auto;
  background: #161b22;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.country-picker-dropdown.open { display: block; }
.country-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.country-picker-item:hover,
.country-picker-item.active {
  background: #21262d;
}
.country-picker-name {
  flex: 1;
  font-size: 0.88rem;
}
.country-picker-code {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
.country-picker-empty {
  padding: 0.85rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.traffic-filters label { font-size: 0.78rem; color: var(--muted); margin-right: 0.25rem; }
.traffic-chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.35rem; }
.traffic-chip-row select {
  background: #21262d;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
  margin-right: 0.75rem;
}
.traffic-chip {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: #21262d;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  cursor: pointer;
  user-select: none;
}
.traffic-chip.on { background: #238636; border-color: #2ea043; color: #fff; }
.traffic-totals { font-size: 0.88rem; line-height: 1.6; }
.traffic-totals strong { margin-right: 0.5rem; }
.traffic-realtime-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}
.traffic-rt-card h4 { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--accent); }
.traffic-rt-card div { font-size: 0.85rem; line-height: 1.5; }

/* Statistics — 对齐原版统计表 */
.stats-toolbar { padding: 0.85rem 1rem; }
.stats-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
}
.stats-toolbar-left,
.stats-toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.stats-toolbar-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
}
.stats-select {
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}
.stats-groupby { min-width: 140px; }
.stats-search {
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  min-width: 160px;
}
.stats-table th.num,
.stats-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table tfoot .stats-total-row {
  background: #161b22;
  border-top: 2px solid var(--border);
  font-weight: 600;
}
.stats-tabs { margin-bottom: 0.75rem; }

.global-tag {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-family: ui-monospace, Menlo, monospace;
  background: rgba(63, 185, 80, 0.18);
  border: 1px solid rgba(63, 185, 80, 0.55);
  color: #56d364;
  white-space: nowrap;
}
.asset-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.75rem;
}
@media (max-width: 720px) {
  .asset-pair { grid-template-columns: 1fr; }
}
.asset-block {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}
.asset-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.asset-block .hint { margin: 0.35rem 0 0; }
.ad-bind-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0.35rem 0 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  max-height: 220px;
  overflow: auto;
}
.ad-bind-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.86rem;
  cursor: pointer;
}
.ad-bind-item input { margin-top: 0.2rem; }

/* Monitoring */
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.monitor-card {
  margin: 0;
  border: 1px solid var(--border);
}
.monitor-card.ok { border-color: rgba(63, 185, 80, 0.45); }
.monitor-card.warn { border-color: #d29922; }
.monitor-card.fail { border-color: var(--danger); }
.monitor-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}
.monitor-status.ok { background: rgba(63,185,80,0.15); color: var(--ok); }
.monitor-status.warn { background: rgba(210,153,34,0.15); color: #d29922; }
.monitor-status.fail { background: rgba(248,81,73,0.15); color: var(--danger); }
.monitor-uptime-bar {
  height: 8px;
  border-radius: 999px;
  background: #21262d;
  overflow: hidden;
  margin-top: 0.5rem;
}
.monitor-uptime-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px;
}
.monitor-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow: auto;
}
.monitor-timeline li {
  display: flex;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
}
.monitor-timeline li:last-child { border-bottom: none; }
.monitor-ts { color: var(--muted); min-width: 140px; font-size: 0.78rem; }
.monitor-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 0.5rem;
}
.monitor-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: #30363d;
}
.monitor-dot.ok { background: var(--ok); }
.monitor-dot.fail { background: var(--danger); }

/* ── Mobile / responsive ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
  -webkit-tap-highlight-color: transparent;
}
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #21262d;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.menu-toggle:hover { background: #30363d; }
.topbar-start {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}
.topbar-titles { min-width: 0; }

@media (max-width: 768px) {
  body { -webkit-text-size-adjust: 100%; }
  body.sidebar-open { overflow: hidden; }

  .menu-toggle { display: inline-flex; }
  body.sidebar-open .sidebar-overlay { display: block; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 160;
    width: min(280px, 88vw);
    max-width: 100%;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.45);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  .main { width: 100%; min-width: 0; margin-left: 0; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    padding-top: max(0.75rem, env(safe-area-inset-top, 0));
  }
  .topbar h1 { font-size: 1.05rem; line-height: 1.3; }
  .topbar p { font-size: 0.78rem; }
  #topActions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
  }
  #topActions .btn { font-size: 0.8rem; padding: 0.4rem 0.65rem; }

  .content {
    padding: 0.85rem 1rem calc(4.5rem + env(safe-area-inset-bottom, 0));
  }

  .card { padding: 0.85rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card-grid { grid-template-columns: 1fr; }
  .toolbar { gap: 0.4rem; }
  .toolbar .btn { flex: 1 1 auto; min-width: max-content; }

  table.data {
    font-size: 0.78rem;
    min-width: 520px;
  }
  table.data th,
  table.data td { padding: 0.45rem 0.4rem; }

  .domain-card .actions { flex-wrap: wrap; justify-content: flex-start; }
  .country-rule-head { flex-direction: column; align-items: flex-start; }
  .cfg-status-grid { grid-template-columns: 1fr 1fr; }
  .switch-row { flex-direction: column; gap: 0.65rem; }
  .traffic-chip-row select { margin-right: 0; width: 100%; max-width: 100%; }
  .stats-toolbar-row { flex-direction: column; align-items: stretch; }
  .stats-toolbar-left,
  .stats-toolbar-right { width: 100%; }
  .stats-search { min-width: 0; width: 100%; }
  .stats-groupby { min-width: 0; width: 100%; }

  .monitor-grid { grid-template-columns: 1fr; }
  .monitor-timeline li { flex-direction: column; align-items: flex-start; gap: 0.25rem; }
  .monitor-ts { min-width: 0; }

  .fab {
    right: max(1rem, env(safe-area-inset-right, 1rem));
    bottom: max(1rem, env(safe-area-inset-bottom, 1rem));
    width: 48px;
    height: 48px;
  }

  .modal {
    max-width: calc(100vw - 1.5rem);
    max-height: calc(100vh - 2rem - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
    padding: 1rem;
  }

  .pagination { flex-wrap: wrap; }
  .filter-tab { font-size: 0.75rem; padding: 0.3rem 0.55rem; }
}

@media (max-width: 480px) {
  .cfg-status-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .nav-item { padding: 0.75rem 1rem; font-size: 0.9rem; }
}
