:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #d8e0ea;
  --text: #1b2430;
  --muted: #5f6b7a;
  --primary: #0f766e;
  --primary-hover: #0b5f58;
  --danger: #b42318;
  --danger-hover: #8c1a12;
  --ok: #166534;
  --warning: #92400e;
  --shadow: 0 12px 34px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
  background: linear-gradient(170deg, #eef4fb 0%, #f7f5ee 100%);
  color: var(--text);
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(16px);
  opacity: 0.35;
}

.bg-shape-a {
  width: 340px;
  height: 340px;
  top: -120px;
  left: -80px;
  background: #7ec8c4;
}

.bg-shape-b {
  width: 360px;
  height: 360px;
  right: -120px;
  bottom: -120px;
  background: #f8c27a;
}

.container {
  width: min(1680px, 97vw);
  margin: 20px auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.hidden {
  display: none !important;
}

h1,
h2 {
  margin: 0 0 10px;
  letter-spacing: 0.2px;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.subtext {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.ops-guide {
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid #efcfab;
  border-radius: 10px;
  background: #fff8ef;
  color: #7a4a00;
  font-size: 13px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tab {
  border: 1px solid var(--line);
  background: #f8fbff;
  color: #243447;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: all 140ms ease;
}

.tab:hover {
  border-color: #8ea4be;
}

.tab.active {
  background: #e4f2f1;
  border-color: #84c2bd;
  color: #084d48;
  font-weight: 600;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  background: linear-gradient(180deg, #ffffff 0%, #f6fafc 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.metric-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
}

.metric-value-sm {
  font-size: 20px;
}

.content-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.5fr);
  gap: 12px;
  align-items: start;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.inline-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.inline-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.inline-grid-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.editor-password-field {
  min-width: 0;
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-actions-nowrap {
  flex-wrap: nowrap;
}

.editor-password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.editor-password-row input {
  min-width: 0;
}

.editor-password-row .btn {
  white-space: nowrap;
}

.editor-lock-row {
  grid-template-columns: minmax(0, 1fr);
}

.editor-top-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: end;
}

.editor-meta-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.grid-form {
  display: grid;
  gap: 10px;
}

hr {
  border: none;
  border-top: 1px dashed #ccd8e5;
  margin: 14px 0;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #344154;
}

.checkbox-line {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.checkbox-line input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d2de;
  border-radius: 9px;
  padding: 10px 11px;
  background: #fcfdff;
  color: #1d2633;
  font-size: 14px;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #93d3cd;
  border-color: #7fbeb9;
}

.btn {
  border: 1px solid #c7d4e2;
  background: #f8fbff;
  border-radius: 9px;
  padding: 9px 13px;
  font-size: 14px;
  cursor: pointer;
  color: #253445;
  transition: all 120ms ease;
}

.btn:hover {
  border-color: #93abc5;
  background: #f1f6fc;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn.danger {
  background: #fff5f4;
  color: var(--danger);
  border-color: #efc3bf;
}

.btn.danger:hover {
  color: #fff;
  border-color: var(--danger-hover);
  background: var(--danger-hover);
}

.btn.link {
  border: none;
  background: transparent;
  color: #0f5fb9;
  padding: 0;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.cell-clip {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid #e7edf5;
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
}

thead th {
  background: #f3f8fd;
  color: #334155;
}

tbody tr:hover {
  background: #fbfdff;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  border: 1px solid;
}

.status-active,
.status-unused {
  color: var(--ok);
  border-color: #9fd8b2;
  background: #edf9f0;
}

.status-banned,
.status-disabled {
  color: var(--danger);
  border-color: #efc3bf;
  background: #fff5f4;
}

.status-used {
  color: var(--warning);
  border-color: #efcfab;
  background: #fff8ef;
}

.status-expired {
  color: #7a4a00;
  border-color: #f0d39d;
  background: #fff7e7;
}

.actions {
  display: flex;
  gap: 6px;
}

.result-box,
.code-box {
  margin-top: 10px;
  border: 1px solid #c7d8e9;
  border-radius: 10px;
  padding: 10px;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
  background: #f8fbff;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  max-height: 320px;
  line-height: 1.45;
}

.code-box.compact {
  max-height: 170px;
}

.code-box.tall {
  max-height: 480px;
}

.code-details {
  margin-top: 10px;
  border: 1px solid #c7d8e9;
  border-radius: 10px;
  background: #f8fbff;
}

.code-details > summary {
  cursor: pointer;
  padding: 8px 10px;
  font-size: 13px;
  color: #334155;
  user-select: none;
}

.code-details[open] > summary {
  border-bottom: 1px solid #c7d8e9;
  background: #eef4fb;
  border-radius: 10px 10px 0 0;
}

.code-details .code-box {
  margin: 0;
  border: none;
  border-radius: 0 0 10px 10px;
  background: #ffffff;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 80;
  width: min(420px, calc(100vw - 28px));
  border: 1px solid #b2d6cf;
  background: #e8f6f4;
  color: #084a45;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}

.toast.error {
  border-color: #efc3bf;
  background: #fff5f4;
  color: #9b271f;
}

.auth-panel {
  max-width: 460px;
  margin: 90px auto 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 20, 32, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}

.modal-card {
  width: min(1180px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: #ffffff;
  border: 1px solid #d6e1eb;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 18px 54px rgba(15, 23, 42, 0.22);
}

.policy-split {
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr);
  align-items: start;
}

.policy-topbar {
  margin: 10px 0;
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(220px, 280px) minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}

.policy-inline-label {
  min-width: 220px;
}

.policy-sync-line {
  align-items: center;
  margin-bottom: 10px;
}

.policy-bulk {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.policy-rules-wrap {
  max-height: 520px;
}

.policy-rule-input {
  min-width: 260px;
}

.policy-port-input {
  min-width: 120px;
  max-width: 180px;
}

.policy-empty {
  text-align: center;
  color: var(--muted);
}

.policy-overview-card .table-wrap {
  max-height: 520px;
}

.proxy-add-form {
  margin: 10px 0 12px;
  display: grid;
  grid-template-columns: minmax(160px, 0.9fr) minmax(120px, 0.55fr) minmax(240px, 1fr) minmax(120px, 0.55fr) minmax(180px, 0.8fr) auto;
  gap: 10px;
  align-items: end;
}

.proxy-upstream-box {
  margin: 10px 0 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
}

.proxy-upstream-box h3 {
  margin: 0;
  font-size: 16px;
}

.proxy-upstream-grid {
  grid-template-columns: minmax(180px, 220px) minmax(220px, 1fr) minmax(220px, 1fr);
}

.proxy-add-form .btn {
  white-space: nowrap;
}

.proxy-listen-input,
.proxy-upstream-port-input {
  width: 120px;
}

.proxy-host-input {
  min-width: 240px;
}

[data-route-policy-profile] {
  min-width: 160px;
}

.user-log-table-wrap {
  max-height: 320px;
}

.raw-log-cell {
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
}

.log-feed {
  max-height: 260px;
  overflow: auto;
  line-height: 1.45;
  background: #0d1724;
  color: #d9e4f2;
  border-color: #22354b;
}

.log-summary-line {
  margin: 6px 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
  color: #334155;
  font-size: 13px;
}

.log-filter-core {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.status-code-stack {
  display: grid;
  gap: 2px;
  min-width: 116px;
}

.status-code-detail,
.status-code-empty {
  color: var(--muted);
  font-size: 11px;
  white-space: normal;
  line-height: 1.35;
}

.log-time-filter {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
}

.log-time-filter > summary {
  cursor: pointer;
  padding: 8px 10px;
  color: #334155;
  font-size: 13px;
}

.log-time-row {
  padding: 0 10px 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.log-feed-details > summary {
  cursor: pointer;
  color: #243447;
  font-weight: 600;
}

.log-metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 14px;
}

.log-table-wrap {
  max-height: 640px;
}

.log-table-wrap table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef4fb;
}

.log-select-col {
  width: 56px;
  min-width: 56px;
  text-align: center;
}

.log-row-select {
  width: 18px;
  height: 18px;
}

.log-autoscroll {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
}

.pager {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.pager-label {
  min-width: 88px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.pager-jump {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager-jump input {
  width: 88px;
}

.tools-grid {
  grid-template-columns: minmax(360px, 0.92fr) minmax(560px, 1.38fr);
  grid-template-areas:
    "publish proxy"
    "backup proxy"
    "export proxy"
    "runtime runtime";
}

.tools-publish-card {
  grid-area: publish;
}

.tools-export-card {
  grid-area: export;
}

.tools-backup-card {
  grid-area: backup;
}

.tools-proxy-card {
  grid-area: proxy;
}

.tools-runtime-card {
  grid-area: runtime;
}

.runtime-headline {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #f2f8f6 100%);
}

.runtime-headline-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.runtime-headline-sub {
  color: var(--muted);
  font-size: 13px;
}

.runtime-listeners {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.listener-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fbff;
  font-size: 13px;
}

.listener-pill-port {
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  color: #31435a;
}

.listener-pill-state {
  font-weight: 600;
}

.listener-pill-on {
  background: #edf9f0;
  border-color: #9fd8b2;
  color: var(--ok);
}

.listener-pill-off {
  background: #fff5f4;
  border-color: #efc3bf;
  color: var(--danger);
}

.listener-pill-muted {
  color: var(--muted);
}

.runtime-facts {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.runtime-fact {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.runtime-fact-label {
  color: var(--muted);
  font-size: 12px;
}

.runtime-fact-value {
  color: #1f2937;
  font-size: 15px;
  line-height: 1.35;
}

.runtime-notes {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #344154;
  line-height: 1.55;
}

.detect-grid {
  grid-template-columns: minmax(420px, 1fr) minmax(640px, 1.4fr);
}

.hub-split-grid {
  grid-template-columns: minmax(420px, 1.1fr) minmax(420px, 1fr);
}

.hub-table-wrap {
  max-height: 420px;
}

.hub-intro-card,
.hub-online-card,
.hub-audit-card {
  margin-bottom: 12px;
}

.hub-metric-grid {
  margin-bottom: 12px;
}

.hub-detail-tabs {
  margin: 18px 0 20px;
}

.hub-detail-tab {
  min-width: 88px;
}

.hub-detail-pane {
  display: none;
}

.hub-detail-pane.active {
  display: block;
}

.hub-section-head {
  margin: 16px 0 10px;
}

.hub-node-enabled-line {
  padding-top: 28px;
}

.hub-row-note {
  margin-top: 4px;
}

.hub-node-row-selected {
  background: #f3f8fd;
}

.detect-tergame-card {
  grid-column: 1 / -1;
}

.detect-tergame-metrics {
  margin-bottom: 10px;
}

.detect-tergame-feed-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.firewall-grid {
  grid-template-columns: minmax(520px, 1fr) minmax(520px, 1fr);
}

.ip-risk-config-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.firewall-config-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.firewall-list-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.risk-policy-actions {
  margin-bottom: 10px;
}

.risk-event-table-wrap {
  max-height: 360px;
}

.ip-risk-table-wrap {
  max-height: 620px;
}

.ip-risk-table {
  min-width: 1320px;
  table-layout: fixed;
}

.ip-risk-table th,
.ip-risk-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.ip-risk-table th:nth-child(1),
.ip-risk-table td:nth-child(1) {
  width: 120px;
}

.ip-risk-table th:nth-child(2),
.ip-risk-table td:nth-child(2) {
  width: 92px;
}

.ip-risk-table th:nth-child(3),
.ip-risk-table td:nth-child(3) {
  width: 72px;
}

.ip-risk-table th:nth-child(4),
.ip-risk-table td:nth-child(4) {
  width: 330px;
}

.ip-risk-table th:nth-child(5),
.ip-risk-table td:nth-child(5) {
  width: 220px;
}

.ip-risk-table th:nth-child(6),
.ip-risk-table td:nth-child(6) {
  width: 80px;
}

.ip-risk-table th:nth-child(7),
.ip-risk-table td:nth-child(7) {
  width: 80px;
}

.ip-risk-table th:nth-child(8),
.ip-risk-table td:nth-child(8) {
  width: 56px;
}

.ip-risk-table th:nth-child(9),
.ip-risk-table td:nth-child(9) {
  width: 70px;
}

.ip-risk-table th:nth-child(10),
.ip-risk-table td:nth-child(10) {
  width: 138px;
}

.ip-risk-table th:nth-child(11),
.ip-risk-table td:nth-child(11) {
  width: 180px;
}

.cell-clip {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1400px) {
  .inline-grid-5 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ip-risk-config-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1080px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .log-metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-grid {
    grid-template-columns: 1fr;
  }

  .proxy-add-form {
    grid-template-columns: 1fr;
  }

  .proxy-upstream-grid {
    grid-template-columns: 1fr;
  }

  .log-filter-core {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .log-time-row {
    grid-template-columns: 1fr;
  }

  .tools-grid {
    grid-template-columns: 1fr;
    grid-template-areas: none;
  }

  .tools-grid > .content-card {
    grid-area: auto;
  }

  .runtime-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detect-grid {
    grid-template-columns: 1fr;
  }

  .firewall-grid {
    grid-template-columns: 1fr;
  }

  .policy-topbar {
    grid-template-columns: 1fr;
  }

  .inline-grid {
    grid-template-columns: 1fr;
  }

  .inline-grid-4 {
    grid-template-columns: 1fr;
  }

  .inline-grid-5 {
    grid-template-columns: 1fr;
  }

  .ip-risk-config-grid {
    grid-template-columns: 1fr;
  }

  .firewall-config-grid {
    grid-template-columns: 1fr;
  }

  .firewall-list-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .log-filter-core {
    grid-template-columns: 1fr;
  }

  .runtime-facts {
    grid-template-columns: 1fr;
  }
}
