/* 分流规则 (Rules hub) — Networking. Warm-ivory / dark via shared theme vars only.
   No blue/purple gradients, no font-weight > 600, low-saturation accents.
   Aligns badge/button/card language with on-list.css. */
#rulesView { padding: 18px; }
#rulesView.active { display: block; }
#rulesRoot { display: flex; flex-direction: column; gap: 16px; max-width: 1400px; }
#rulesRoot > * { min-width: 0; }

/* ---- semantic theme tokens ----
   Translucent state tints, the accent-button foreground and the light-theme
   card shadow aren't in styles.css, so they live here as named tokens — the
   ONLY place a raw color value appears. Every selector below references a
   var(). Dark and light blocks are defined symmetrically and explicitly. */
:root, :root[data-theme="dark"] {
  --rules-ok-bg: rgba(110, 231, 168, .08);
  --rules-warn-bg: rgba(244, 184, 105, .1);
  --rules-direct-bg: rgba(110, 231, 168, .12);
  --rules-reject-bg: rgba(244, 119, 119, .12);
  --rules-other-bg: rgba(127, 141, 153, .14);
  --rules-card-shadow: none;
  --rules-on-accent: #fff;
}
:root[data-theme="light"] {
  --rules-ok-bg: rgba(82, 123, 112, .1);
  --rules-warn-bg: rgba(184, 151, 100, .12);
  --rules-direct-bg: rgba(82, 123, 112, .12);
  --rules-reject-bg: rgba(184, 65, 58, .1);
  --rules-other-bg: rgba(118, 128, 137, .14);
  --rules-card-shadow: 0 1px 2px rgba(54, 45, 30, .04), 0 8px 24px rgba(54, 45, 30, .035);
  --rules-on-accent: #fff;
}

/* ---- header / sync badge ---- */
.rh-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.rh-toolbar .eyebrow { margin: 0 0 5px; }
.rh-toolbar h1 { margin: 3px 0; font: 500 28px/1.1 Georgia, "Times New Roman", serif; }
.rh-sub { margin: 0; max-width: 64ch; color: var(--muted); font-size: 11px; line-height: 1.55; }
.rh-sync { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border: 1px solid var(--line);
  border-radius: 999px; font-size: 11px; white-space: nowrap; }
.rh-sync i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.rh-sync-ok { color: var(--green); background: var(--rules-ok-bg); }
.rh-sync-stalled { color: var(--amber); background: var(--rules-warn-bg); }

/* ---- stat cards ---- */
.rh-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.rh-stat { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--rules-card-shadow); }
.rh-stat span { color: var(--muted); font-size: 9px; letter-spacing: .1em; text-transform: uppercase; }
.rh-stat strong { font-size: 24px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.rh-stat small { color: var(--muted); font-size: 10.5px; line-height: 1.4; }

/* ---- client config + login ---- */
.rh-client { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: start; }
.rh-cfg-card { display: flex; flex-direction: column; gap: 9px; min-width: 0; padding: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--rules-card-shadow); }
.rh-cfg-eye { color: var(--cyan); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; margin: 0; }
.rh-cfg-card h3 { margin: 0; font: 500 15px/1.3 Georgia, "Times New Roman", serif; }
.rh-cfg-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.rh-cfg-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

.rh-login-card { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; padding: 18px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--rules-card-shadow); }
.rh-login-eyebrow { color: var(--cyan); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; margin: 0; }
.rh-login-title { margin: 0; font: 500 16px/1.3 Georgia, "Times New Roman", serif; }
.rh-login-desc { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.rh-login-card input { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel2); color: var(--text); font-size: 13px; }
.rh-login-card input:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.rh-login-card button[type=submit] { align-self: flex-start; padding: 9px 20px; border: 0; border-radius: 8px;
  background: var(--gold); color: var(--rules-on-accent); font: 500 12px/1 inherit; cursor: pointer; }
.rh-login-card button[type=submit]:hover { background: var(--gold-light); }
.rh-login-error { margin: 0; color: var(--red); font-size: 11px; min-height: 14px; }

/* ---- shared button / pill ---- */
.rh-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--panel2); color: var(--muted); font: 500 11px/1.3 inherit;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: border-color .18s ease, color .18s ease, background-color .18s ease; }
.rh-btn:hover { border-color: var(--gold); color: var(--text); }
.rh-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.rh-btn[disabled] { opacity: .5; cursor: not-allowed; }
.rh-btn[disabled]:hover { border-color: var(--line); color: var(--muted); }

/* ---- rule card grid ---- */
.rh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; align-items: start; }
.rh-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--rules-card-shadow); }
.rh-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.rh-group { margin: 0; font: 500 14px/1.3 Georgia, "Times New Roman", serif; overflow-wrap: anywhere; }
.rh-policy { flex-shrink: 0; padding: 4px 9px; border-radius: 999px; font-size: 9.5px; font-weight: 600;
  letter-spacing: .04em; white-space: nowrap; }
.rh-policy-direct { background: var(--rules-direct-bg); color: var(--green); }
.rh-policy-reject { background: var(--rules-reject-bg); color: var(--red); }
.rh-policy-other { background: var(--rules-other-bg); color: var(--muted); }
.rh-desc { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; display: -webkit-box;
  -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.rh-sources { margin: 0; color: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.rh-url { display: block; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel2); color: var(--cyan); font-size: 10.5px; word-break: break-all; overflow-wrap: anywhere; }
.rh-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---- detail table ---- */
.rh-table-wrap { padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--rules-card-shadow); }
.rh-table-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.rh-table-head .eyebrow { margin: 0 0 4px; }
.rh-table-head h2 { margin: 0; font: 500 15px Georgia, "Times New Roman", serif; }
.rh-table-note { color: var(--muted); font-size: 10px; white-space: nowrap; }
.rh-table-scroll { overflow-x: auto; }
.rh-table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
.rh-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 0 8px 9px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
.rh-table th[data-sort] { cursor: pointer; user-select: none; }
.rh-table th[data-sort]:hover { color: var(--text); }
.rh-table th[data-sort].active { color: var(--cyan); }
.rh-table td { border-top: 1px solid var(--line); padding: 8px; color: var(--text); vertical-align: middle; }
.rh-table td.group { font-weight: 500; overflow-wrap: anywhere; }
.rh-table td.num { text-align: right; }
.rh-table td.muted { color: var(--muted); }
.rh-table .rh-policy { font-size: 9px; }

/* ---- empty / error state ---- */
.rh-empty { display: grid; place-items: center; min-height: 160px; padding: 24px;
  border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 11px; text-align: center; }
.rh-error-bar { margin: 0; padding: 10px 14px; border: 1px solid var(--red); border-radius: 8px;
  background: var(--rules-reject-bg); color: var(--red); font-size: 11px; line-height: 1.5; }

/* ---- responsive: 900 / 760 / 390 ---- */
@media (max-width: 900px) {
  .rh-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rh-client { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  #rulesView { padding: 18px 10px; }
  .rh-toolbar h1 { font-size: 22px; }
  .rh-table-wrap { padding: 12px; }
  .rh-stat strong { font-size: 21px; }
}
@media (max-width: 390px) {
  .rh-stats { grid-template-columns: minmax(0, 1fr); }
  .rh-stat { padding: 13px; }
}
@media (prefers-reduced-motion: reduce) { .rh-btn, .rh-login-card button[type=submit] { transition: none; } }
