:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #5f6b7a;
  --primary: #0f766e;
  --danger: #b91c1c;
  --border: #d7deea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  scroll-behavior: smooth;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
}

.app-shell.app-shell-guest {
  grid-template-columns: minmax(0, 1fr);
}

.site-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 14px;
  background: #0b1220;
  color: #fff;
  border-right: 1px solid #1f2a44;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.site-brand {
  margin: 0;
  font-size: 21px;
}

.site-brand a {
  color: #fff;
  text-decoration: none;
}

.site-user {
  margin: 0;
  color: #cbd5e1;
  font-size: 14px;
}

.site-nav {
  display: grid;
  gap: 8px;
}

.site-nav-link {
  display: block;
  color: #e2e8f0;
  text-decoration: none;
  border: 1px solid #1f2a44;
  border-radius: 8px;
  padding: 10px 12px;
  background: #111b31;
}

.site-nav-link:hover {
  background: #18243f;
  border-color: #334a78;
}

.site-nav-link.active {
  background: #1f3b67;
  border-color: #4f6ea4;
  color: #fff;
}

.site-main {
  min-width: 0;
}

.site-content {
  width: min(1280px, calc(100% - 20px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.guest-topbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}

.hero h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 30px;
}

.hero p {
  margin-top: 0;
  color: var(--muted);
  max-width: 760px;
}

.narrow {
  max-width: 460px;
  margin-left: auto;
  margin-right: auto;
}

.form {
  display: grid;
  gap: 12px;
}

label {
  font-weight: 600;
}

label:not([hidden]) {
  display: grid;
  gap: 6px;
}

[hidden] {
  display: none !important;
}

input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 15px;
}

select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 15px;
  background: #fff;
}

button,
.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 9px 14px;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}

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

button.secondary {
  background: #334155;
}

button:disabled,
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.secondary {
  background: #334155;
}

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

.dashboard-mode-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
  margin: 10px 0 14px;
}

.dashboard-mode-form label {
  min-width: 220px;
}

.captcha-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 124px;
  gap: 10px;
  align-items: center;
}

.captcha-img {
  width: 124px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #edf2fb;
  cursor: pointer;
}

.helper {
  color: var(--muted);
}

.tag {
  background: #d1fae5;
  color: #065f46;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
}

.tag-ok {
  background: #d1fae5;
  color: #065f46;
}

.tag-warn {
  background: #fef3c7;
  color: #92400e;
}

.alert {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.alert-success {
  background: #ecfdf5;
  color: #065f46;
}

.alert-error {
  background: #fef2f2;
  color: #991b1b;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.subscriptions-table tbody tr:nth-child(odd) {
  background: #ffffff;
}

.subscriptions-table tbody tr:nth-child(even) {
  background: #edf3ff;
}

.subscriptions-table tbody tr:hover {
  background: #dbe8ff;
}

.subscriptions-table thead th {
  background: #10243f;
  color: #fff;
}

.subscriptions-table tbody tr:nth-child(odd) td {
  background: #ffffff;
}

.subscriptions-table tbody tr:nth-child(even) td {
  background: #edf3ff;
}

.subscriptions-table tbody tr:hover td {
  background: #dbe8ff;
}

.subscriptions-table th,
.subscriptions-table td {
  white-space: normal;
  word-break: break-word;
}

.subscriptions-table td code.table-code-wrap {
  display: inline-block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.cloudflare-account-table td:nth-child(5) {
  max-width: 380px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 10px 8px;
  font-size: 14px;
  vertical-align: top;
}

.inline-form {
  display: inline-block;
  margin-right: 6px;
}

.admin-subscriptions-search {
  display: grid;
  gap: 8px;
  margin: 10px 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #f8fbff;
}

.admin-subscriptions-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-subscriptions-search-row input {
  width: min(420px, 100%);
}

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

.server-table-scroll {
  overflow-x: visible;
}

.server-table {
  width: 100%;
  table-layout: auto;
}

.server-table th,
.server-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.server-table .server-log-snippet {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-table .server-actions-cell {
  width: 460px;
  min-width: 460px;
  white-space: normal;
  overflow: visible;
}

.server-table .subscription-actions {
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-start;
}

.server-table .subscription-actions button,
.server-table .subscription-actions .btn {
  padding: 6px 8px;
  font-size: 12px;
  white-space: nowrap;
}

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

.subscription-actions .inline-form {
  margin-right: 0;
}

.subscription-actions .expiry-form {
  margin: 0;
  flex-wrap: nowrap;
}

.subscription-edit-panel {
  min-width: 280px;
}

.subscription-edit-panel > summary {
  display: inline-block;
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f6f9ff;
  color: var(--text);
  user-select: none;
}

.subscription-edit-panel[open] > summary {
  margin-bottom: 8px;
}

.subscription-edit-panel .subscription-actions {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.admin-reset-password-input {
  min-width: 170px;
}

.user-edit-modal-card {
  width: min(560px, 100%);
}

.user-edit-modal-actions {
  display: grid;
  gap: 10px;
}

.user-edit-modal-actions .form {
  margin: 0;
}

.user-edit-modal-actions .admin-reset-password-input {
  width: 100%;
  min-width: 0;
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.dashboard-sidebar {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 8px;
}

.dashboard-sidebar h3 {
  margin: 0 0 4px;
}

.sidebar-link {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fbff;
  color: var(--text);
  text-decoration: none;
}

.sidebar-link:hover {
  border-color: #9fb3d3;
  background: #eef5ff;
}

.dashboard-main {
  min-width: 0;
}

.section-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title-row h3,
.section-title-row h4 {
  margin: 0;
}

.plan-create-modal-card {
  width: min(620px, 100%);
}

.guide-steps {
  margin: 0 0 8px 22px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.guide-grid {
  margin-top: 10px;
}

.guide-image-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.guide-image-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafcff;
  padding: 10px;
  margin: 0;
}

.guide-image-card img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.guide-image-card figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.stats-grid {
  margin: 10px 0 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.stats-grid-single-row {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.stats-grid-single-row .stat-item {
  min-width: 180px;
  flex: 1 0 180px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stats-grid-single-row .stat-label,
.stats-grid-single-row .stat-value {
  white-space: nowrap;
}

.stats-grid-single-row .stat-value {
  font-size: 18px;
}

.traffic-stats-wrap {
  margin: 10px 0 14px;
}

.traffic-stats-table {
  table-layout: fixed;
}

.traffic-stats-table th,
.traffic-stats-table td {
  text-align: center;
  white-space: nowrap;
}

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

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

.overview-link {
  display: grid;
  gap: 6px;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #f8fbff;
  color: var(--text);
}

.overview-link:hover {
  border-color: #9fb3d3;
  background: #edf3ff;
}

.overview-label {
  color: var(--muted);
  font-size: 13px;
}

.overview-value {
  font-size: 28px;
  line-height: 1;
}

.stat-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafcff;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  font-size: 20px;
  line-height: 1.1;
}

.expiry-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.expiry-form input[type="datetime-local"] {
  min-width: 190px;
}

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

.feature-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fafcff;
}

.feature-item h4 {
  margin: 0 0 6px;
}

.feature-item p {
  margin: 0;
  color: var(--muted);
}

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

.plan-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fafcff;
  display: grid;
  gap: 8px;
}

.plan-card h4 {
  margin: 0;
}

.plan-card p {
  margin: 0;
  color: var(--muted);
  min-height: 40px;
}

.purchase-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.purchase-plan-table th:first-child,
.purchase-plan-table td:first-child {
  width: 60px;
  text-align: center;
}

.purchase-plan-row {
  cursor: pointer;
}

.purchase-plan-row.active td {
  background: #dbe8ff !important;
}

.purchase-plan-radio {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.purchase-month-row {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
}

.plan-option-btn {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}

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

.purchase-actions {
  padding: 12px;
  display: grid;
  justify-items: end;
  gap: 8px;
}

.purchase-actions-helper {
  margin: 0;
  text-align: right;
  max-width: 460px;
}

.payment-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 1000;
}

.payment-modal[hidden] {
  display: none;
}

.payment-modal-card {
  width: min(520px, 100%);
  max-height: 92vh;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 16px;
}

.payment-modal-card h4 {
  margin-top: 0;
  margin-bottom: 8px;
}

.payment-modal-card p {
  margin: 7px 0;
}

.onboarding-modal-card {
  width: min(760px, 100%);
}

.onboarding-entry {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.onboarding-step-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 14px;
}

.onboarding-step-tab {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

.onboarding-step-tab.done {
  border-color: #86efac;
  background: #ecfdf5;
  color: #065f46;
}

.onboarding-step-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.onboarding-step-panel {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.onboarding-step-panel h5 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 17px;
}

.modal-close-x {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  line-height: 1;
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.payment-qr-wrap {
  width: 220px;
  margin: 10px auto;
}

.payment-qr-wrap-inline {
  width: 180px;
  margin: 8px 0;
}

.payment-qr-wrap img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}

body.modal-open {
  overflow: hidden;
}

.order-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafcff;
}

.order-item p {
  margin: 6px 0;
}

.tx-form {
  margin-top: 8px;
}

.tx-form-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0;
}

.order-tx-input {
  min-width: 220px;
}

code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 6px;
  word-break: break-all;
}

.table-code-wrap {
  display: inline-block;
  max-width: 260px;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 12px;
}

.online-rate {
  font-weight: 600;
  color: #0f766e;
}

.online-rate.online-rate-zero {
  color: var(--muted);
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .site-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid #1f2a44;
    gap: 10px;
  }

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

  .site-nav-link {
    text-align: center;
    padding: 9px 8px;
    font-size: 13px;
  }

  .site-content {
    width: min(1280px, calc(100% - 12px));
    padding: 14px 0 28px;
  }

  .section-title-row {
    align-items: stretch;
    flex-direction: column;
  }

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

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

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

  .hero h2 {
    font-size: 24px;
  }

  th,
  td {
    font-size: 13px;
    padding: 8px 6px;
  }

  .subscriptions-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .server-table {
    display: table;
    overflow-x: visible;
    white-space: normal;
  }

  .subscription-actions {
    align-items: stretch;
  }

  .subscription-actions .expiry-form {
    width: 100%;
  }

  .admin-subscriptions-search-row input {
    width: 100%;
  }

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

  .guide-image-grid {
    grid-template-columns: 1fr;
  }

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

  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .dashboard-sidebar {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sidebar-link {
    text-align: center;
    padding: 9px 8px;
    font-size: 13px;
  }

  .purchase-layout {
    grid-template-columns: 1fr;
  }

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

  .purchase-month-row {
    flex-wrap: wrap;
  }

  .payment-modal-card {
    padding: 14px;
  }

  .onboarding-step-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
