:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #dce3ee;
  --ink: #172033;
  --muted: #65728a;
  --brand: #1769e0;
  --brand-2: #0f9f8f;
  --danger: #d93535;
  --warn: #c97913;
  --ok: #12805c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login form,
.panel,
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(23, 32, 51, 0.08);
}

.login form {
  width: min(420px, 100%);
  padding: 28px;
}

.login h1,
.login p {
  margin: 0;
}

.login h1 {
  font-size: 24px;
}

.login p {
  margin-top: 8px;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 16px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
}

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

.shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  font-weight: 800;
}

.brand strong {
  display: block;
}

.brand span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.brand strong,
.brand span {
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.content {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px;
  width: 100%;
}

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

.metric,
.panel {
  padding: 16px;
  min-width: 0;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.panel {
  margin-bottom: 16px;
}

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

.panel-head h2 {
  font-size: 18px;
  margin: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 9px 12px;
  border-radius: 6px;
  background: #edf3ff;
  color: var(--brand);
  font-weight: 650;
}

.button.primary {
  background: var(--brand);
  color: #fff;
}

.button.danger {
  background: #fff0f0;
  color: var(--danger);
}

.button.ghost {
  background: transparent;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #edf3ff;
  color: var(--brand);
}

.status.ok {
  background: #eaf8f2;
  color: var(--ok);
}

.status.warn {
  background: #fff7e8;
  color: var(--warn);
}

.status.danger {
  background: #fff0f0;
  color: var(--danger);
}

.relay-agent-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.mobile-agent-title {
  margin: 18px 0 0;
}

.relay-agent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

.relay-agent-row .button {
  flex: 0 0 auto;
}

.relay-agent-row.selected {
  border-color: #3a8f6f;
  background: #f1faf6;
}

.relay-agent-info {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.mobile-node-toolbar,
.mobile-node-head,
.mobile-node-checks {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mobile-node-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.mobile-node-summary .button {
  margin-left: auto;
}

.mobile-node-list {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.mobile-node-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8fafc;
}

.mobile-node-auto-entry {
  margin: 0;
  padding: 7px 9px;
  border-radius: 6px;
  background: #eef5ff;
  color: #315b91;
}

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

.mobile-node-editable {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 760px;
}

.mobile-node-managed {
  margin: -3px 0 0;
}

.mobile-node-upstream {
  overflow-wrap: anywhere;
}

.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px 10px;
  color: var(--text);
}

.relay-agent-info span {
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  min-width: 0;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

td strong {
  display: block;
}

td small {
  color: var(--muted);
}

.progress {
  height: 8px;
  background: #edf1f7;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 7px;
}

.progress b {
  display: block;
  height: 100%;
  width: var(--value);
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

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

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
}

.check input {
  width: auto;
}

.events {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.event {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.usage-block {
  min-width: 0;
}

.usage-block h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.usage-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.usage-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.usage-main,
.usage-total {
  min-width: 0;
}

.usage-main strong,
.usage-total strong {
  display: block;
}

.usage-main code {
  max-width: 240px;
  margin-top: 5px;
}

.usage-item small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
}

.usage-total {
  text-align: right;
  white-space: nowrap;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 28, 45, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 10;
}

.modal {
  width: min(720px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 18px;
}

.modal h2 {
  margin: 0 0 12px;
}

.qr-modal {
  width: min(420px, 100%);
}

.qr-box {
  display: grid;
  place-items: center;
  padding: 14px;
  margin: 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.qr-box img {
  display: block;
  width: min(280px, 100%);
  height: auto;
}

.diag-modal {
  width: min(860px, 100%);
}

.diag-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.diag-form .field {
  margin-top: 0;
}

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

.diag-stat {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
}

.diag-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.diag-stat strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.route-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.route-head h3 {
  margin: 0;
  font-size: 16px;
}

.route-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.route-hop {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 84px;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.route-hop.timeout {
  background: #fbfcfe;
}

.hop-no {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #edf3ff;
  color: var(--brand);
  font-weight: 800;
  font-size: 13px;
}

.hop-ips {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.ip-line {
  display: grid;
  grid-template-columns: minmax(112px, 180px) minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  min-width: 0;
}

.ip-line code {
  max-width: 100%;
}

.ip-line span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.hop-rtt {
  color: var(--ink);
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.diag-raw {
  margin-top: 12px;
}

.diag-raw summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 700;
}

.diag-raw pre {
  max-height: 240px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #101828;
  color: #e8edf7;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #172033;
  color: #fff;
  padding: 11px 13px;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

code {
  display: block;
  max-width: 480px;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 7px 8px;
  background: #f2f5fa;
  border-radius: 6px;
  color: #30405c;
}

@media (max-width: 860px) {
  .grid,
  .two,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .content {
    padding: 14px;
  }

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .actions .button {
    flex: 1 1 auto;
  }

  .diag-form,
  .diag-stats,
  .usage-grid {
    grid-template-columns: 1fr;
  }

  .route-head {
    align-items: stretch;
    flex-direction: column;
    gap: 4px;
  }
}

@media (max-width: 700px) {
  body {
    font-size: 14px;
  }

  .content {
    padding: 8px;
  }

  .topbar {
    gap: 8px;
    padding: 9px 10px;
  }

  .panel,
  .metric {
    padding: 10px;
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 17px;
  }

  h3 {
    font-size: 15px;
  }

  .button,
  .field select,
  input,
  textarea {
    min-height: 36px;
    padding: 7px 9px;
    font-size: 13px;
  }

  .button.compact {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .relay-agent-row {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
    padding: 9px;
  }

  .relay-agent-row > .button,
  .relay-agent-row > .status {
    align-self: flex-start;
  }

  .mobile-node-card {
    gap: 9px;
    padding: 10px;
  }

  .mobile-node-grid {
    grid-template-columns: 1fr;
  }

  .mobile-node-toolbar,
  .mobile-node-head,
  .mobile-node-checks {
    align-items: stretch;
    flex-direction: column;
  }

  .mobile-node-summary {
    align-items: stretch;
    flex-direction: column;
  }

  .mobile-node-summary .button {
    margin-left: 0;
    align-self: flex-start;
  }
  .login {
    align-items: start;
    padding: 14px;
    padding-top: 28px;
  }

  .login form {
    padding: 20px;
  }

  .mark {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand span {
    display: block;
    max-width: calc(100vw - 88px);
    line-height: 1.45;
  }

  .grid {
    gap: 10px;
    margin-bottom: 12px;
  }

  .metric,
  .panel {
    padding: 12px;
    border-radius: 7px;
  }

  .metric strong {
    font-size: 20px;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .panel-head .button {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    overflow: hidden;
  }

  td {
    position: relative;
    display: block;
    min-height: 50px;
    padding: 11px 11px 11px 96px;
    border-bottom: 1px solid var(--line);
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    position: absolute;
    top: 12px;
    left: 11px;
    width: 72px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
  }

  td:nth-child(1)::before {
    content: "用户";
  }

  td:nth-child(2)::before {
    content: "状态";
  }

  td:nth-child(3)::before {
    content: "流量";
  }

  td:nth-child(4)::before {
    content: "订阅";
  }

  td:nth-child(5)::before {
    content: "最近";
  }

  td:nth-child(6)::before {
    content: "操作";
  }

  td > * {
    min-width: 0;
    max-width: 100%;
  }

  td > * + * {
    margin-top: 6px;
  }

  td small {
    display: block;
    overflow-wrap: anywhere;
  }

  .row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .status {
    width: fit-content;
  }

  .row-actions .button {
    min-width: 0;
    padding-inline: 8px;
    white-space: nowrap;
  }

  .route-hop {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    padding: 9px;
  }

  .hop-no {
    width: 28px;
    height: 28px;
  }

  .hop-rtt {
    grid-column: 2;
    text-align: left;
  }

  .ip-line {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .usage-item {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .usage-main code {
    max-width: 100%;
  }

  .usage-total {
    text-align: left;
    white-space: normal;
  }

  .two,
  .settings-grid {
    gap: 8px;
  }

  .overlay {
    align-items: start;
    padding: 12px;
  }

  .modal {
    width: 100%;
    max-height: calc(100vh - 24px);
    padding: 14px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
}

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

  .actions .button {
    width: 100%;
    min-width: 0;
    padding-inline: 8px;
  }

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