:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  --bg: #f4f5f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --line: #dfe3e6;
  --text: #171a1c;
  --muted: #687078;
  --accent: #176b54;
  --accent-strong: #0f5743;
  --blue: #235fa4;
  --warning: #9b650d;
  --danger: #a83232;
  --shadow: 0 14px 40px rgb(20 30 35 / 10%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(14px);
}

.topbar-inner,
.page-shell {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand-lockup { display: flex; align-items: center; gap: 14px; }
.brand-lockup h1 { margin: 0; font-size: 1.35rem; line-height: 1.2; }
.brand-lockup p { margin: 4px 0 0; color: var(--muted); }
.brand-lockup.compact h1 { font-size: 1.05rem; }
.brand-lockup.compact p { font-size: .8rem; margin-top: 2px; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #171a1c;
  color: #fff;
  font-weight: 800;
  font-size: .82rem;
}

.service-line { display: flex; align-items: center; gap: 8px; }
.service-line form, .action-row form, .danger-actions form { margin: 0; }
.service-pill {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .78rem;
  background: var(--surface-2);
}
.service-pill.ok { border-color: #b7d7ca; color: var(--accent); background: #eef8f4; }
.service-pill.bad { border-color: #e6bbbb; color: var(--danger); background: #fff2f2; }

.page-shell { padding: 28px 0 56px; }

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

.metric {
  min-height: 102px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.metric span { color: var(--muted); font-size: .86rem; }
.metric strong { font-size: 1.65rem; line-height: 1; }

.band { margin-top: 30px; }
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.section-heading h2 { margin: 0; font-size: 1.05rem; }
.section-heading span { display: block; margin-top: 4px; color: var(--muted); font-size: .82rem; }

.egress-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.egress-item { min-width: 0; padding: 18px; border-right: 1px solid var(--line); }
.egress-item:last-child { border-right: 0; }
.egress-title { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #a9afb4; flex: 0 0 auto; }
.status-dot.ok { background: #1e8a68; }
.status-dot.bad { background: #bd3a3a; }
.egress-node { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); min-height: 20px; }
.egress-item dl { display: flex; gap: 28px; margin: 16px 0 0; }
.egress-item dl div { min-width: 0; }
.egress-item dt { color: var(--muted); font-size: .76rem; }
.egress-item dd { margin: 3px 0 0; font-weight: 650; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.users-table { width: 100%; min-width: 1100px; border-collapse: collapse; }
.users-table th,
.users-table td { padding: 14px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.users-table th { color: var(--muted); font-size: .76rem; font-weight: 650; background: var(--surface-2); }
.users-table tbody tr:last-child td { border-bottom: 0; }
.users-table td > strong,
.users-table td > span { display: block; }
.subtle { margin-top: 4px; color: var(--muted); font-size: .76rem; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.policy-cell span { display: block; font-size: .78rem; line-height: 1.55; }
.actions-cell { text-align: right !important; }
.action-row { display: flex; justify-content: flex-end; gap: 6px; }
.online-value { color: var(--accent); font-weight: 650; }
.state-label { display: inline-block !important; padding: 4px 7px; border-radius: 4px; font-size: .74rem; font-weight: 650; }
.state-label.on { color: var(--accent); background: #eaf7f2; }
.state-label.off { color: var(--muted); background: #eceff1; }
.state-label.blocked { color: var(--danger); background: #fff0f0; }
.empty-state { text-align: center !important; color: var(--muted); padding: 48px !important; }

.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #cfd4d7;
  border-radius: 6px;
  padding: 7px 12px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { border-color: #9ca4a9; background: #f9fafb; }
.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
.button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.button.small { min-height: 30px; padding: 4px 8px; font-size: .76rem; }
.button.warning { color: var(--warning); border-color: #ddc694; }
.button.danger { color: var(--danger); border-color: #dfb0b0; }
.button.wide { width: 100%; }

.flash { margin-bottom: 14px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.flash.success { border-color: #a8d2c2; color: var(--accent); background: #eff9f5; }
.flash.error { border-color: #e0afaf; color: var(--danger); background: #fff3f3; }

.modal {
  width: min(760px, calc(100% - 28px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgb(17 22 24 / 48%); backdrop-filter: blur(2px); }
.modal-header,
.modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; }
.modal-header { border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 1rem; }
.modal-footer { border-top: 1px solid var(--line); justify-content: flex-end; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; font-size: 1.55rem; line-height: 1; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--surface-2); color: var(--text); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px; overflow-y: auto; }
.field { display: block; min-width: 0; }
.field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .78rem; }
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #ccd2d5;
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  outline: 0;
}
.field textarea { resize: vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgb(35 95 164 / 12%); }
.wide-field { grid-column: 1 / -1; }

.subscription-layout { padding: 20px; display: grid; grid-template-columns: 270px 1fr; gap: 22px; }
.qr-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-content: start; }
.qr-pair figure, .public-qr-grid figure { margin: 0; text-align: center; }
.qr-pair img, .public-qr-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.qr-pair figcaption, .public-qr-grid figcaption { margin-top: 7px; color: var(--muted); font-size: .76rem; }
.link-list { display: grid; gap: 14px; align-content: start; }
.copy-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.copy-field input { min-width: 0; border-radius: 5px 0 0 5px; }
.copy-field button { border: 1px solid #ccd2d5; border-left: 0; border-radius: 0 5px 5px 0; background: var(--surface-2); padding: 0 12px; cursor: pointer; }
.danger-actions { justify-content: space-between; }

.login-page,
.subscription-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-shell,
.subscription-shell { width: min(420px, 100%); }
.login-shell .brand-lockup,
.subscription-shell .brand-lockup { margin-bottom: 28px; }
.login-form { display: grid; gap: 16px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.login-form label span { display: block; color: var(--muted); font-size: .8rem; margin-bottom: 6px; }
.login-form input { width: 100%; height: 42px; border: 1px solid #ccd2d5; border-radius: 5px; padding: 8px 10px; }
.public-qr-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.public-links { display: grid; gap: 10px; }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .egress-grid { grid-template-columns: 1fr; }
  .egress-item { border-right: 0; border-bottom: 1px solid var(--line); }
  .egress-item:last-child { border-bottom: 0; }
  .subscription-layout { grid-template-columns: 1fr; }
  .qr-pair { max-width: 330px; }
}

@media (max-width: 620px) {
  .topbar-inner, .page-shell { width: min(100% - 24px, 1480px); }
  .topbar-inner { min-height: 64px; }
  .brand-lockup.compact p { display: none; }
  .service-pill { display: none; }
  .page-shell { padding-top: 18px; }
  .metrics { gap: 8px; }
  .metric { min-height: 86px; padding: 14px; }
  .metric strong { font-size: 1.25rem; }
  .toolbar-heading { align-items: center; }
  .section-heading span { max-width: 210px; }
  .form-grid { grid-template-columns: 1fr; padding: 16px; }
  .wide-field { grid-column: auto; }
  .modal-header, .modal-footer { padding: 14px 16px; }
  .subscription-layout { padding: 16px; }
  .danger-actions { align-items: stretch; }
  .table-wrap { overflow: visible; }
  .users-table { min-width: 0; }
  .users-table thead { display: none; }
  .users-table tbody,
  .users-table tr,
  .users-table td { display: block; width: 100%; }
  .users-table tbody tr { padding: 13px 16px; border-bottom: 1px solid var(--line); }
  .users-table tbody tr:last-child { border-bottom: 0; }
  .users-table td {
    padding: 7px 0;
    border-bottom: 0;
    text-align: left !important;
  }
  .users-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 650;
  }
  .users-table td:first-child::before { display: none; }
  .action-row { justify-content: flex-start; flex-wrap: wrap; }
  .subtle { max-width: 100%; }
}
