:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --success: #059669;
  --danger: #dc2626;
  --border: #dbe3ef;
  --shadow: 0 14px 35px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #f5f7fb 0%, #edf1f7 100%);
  color: var(--text);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.brand h1,
.brand h2 {
  margin: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 12px 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: rgba(37, 99, 235, 0.65);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.helper {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.btn {
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
}

.btn.secondary {
  color: var(--text);
  background: #eef2ff;
}

.btn.ghost {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
}

.btn.danger {
  color: #fff;
  background: linear-gradient(135deg, var(--danger), #b91c1c);
}

.btn.success {
  color: #fff;
  background: linear-gradient(135deg, var(--success), #047857);
}

.btn.small {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.login-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.login-actions .btn {
  flex: 1;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 14px 16px;
  border-radius: 14px;
  color: #fff;
  background: rgba(15, 23, 42, 0.88);
  box-shadow: var(--shadow);
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
  width: 100%;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar .site-name {
  font-size: 20px;
  font-weight: 800;
}

.sidebar .site-desc {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
  line-height: 1.5;
}

.sidebar .mini-card {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
}

.sidebar .mini-card .label {
  color: var(--muted);
  font-size: 12px;
}

.sidebar .mini-card .value {
  margin-top: 6px;
  font-weight: 700;
  word-break: break-all;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  border: 1px solid transparent;
}

.nav button.active {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.nav button span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.main {
  padding: 26px;
  min-width: 0;
  max-width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-title h1 {
  margin: 0;
  font-size: 28px;
}

.page-title p {
  margin: 6px 0 0;
  color: var(--muted);
}

.content {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
  max-width: 100%;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric {
  background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 16px;
}

.metric .label {
  color: var(--muted);
  font-size: 13px;
}

.metric .value {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 800;
}

.metric .hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.row .field {
  flex: 1 1 200px;
  min-width: 180px;
}

.row.tight .field {
  flex: 1 1 150px;
}

.table-wrap {
  overflow: auto;
  width: 100%;
  max-width: 100%;
  max-height: 520px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
}

.table-wrap.list-scroll {
  max-height: 560px;
}

.table-wrap.compact-scroll {
  max-height: 360px;
}

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

.small-select {
  width: auto;
  min-width: 120px;
  padding: 8px 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1040px;
}

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid #edf2f7;
  font-size: 14px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f8fbff;
  color: #475569;
  font-weight: 700;
}

td .muted {
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.tag.active {
  color: #047857;
  background: rgba(5, 150, 105, 0.12);
}

.tag.disabled,
.tag.revoked {
  color: #b91c1c;
  background: rgba(220, 38, 38, 0.12);
}

.tag.expired {
  color: #92400e;
  background: rgba(245, 158, 11, 0.14);
}

.tag.pending {
  color: #1d4ed8;
  background: rgba(37, 99, 235, 0.12);
}

.tag.neutral {
  color: #475569;
  background: rgba(148, 163, 184, 0.14);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.logs-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.log-item {
  display: grid;
  grid-template-columns: 140px 160px 1fr;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}

.log-item .time {
  color: var(--muted);
  font-size: 13px;
}

.log-item .action {
  font-weight: 700;
}

.log-item .detail {
  color: var(--muted);
  line-height: 1.5;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: #fff;
}

.section {
  display: none;
  min-width: 0;
  max-width: 100%;
}

.section.active {
  display: block;
}

.split {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
}

.info-grid {
  display: grid;
  gap: 10px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.info-row span:first-child {
  color: var(--muted);
}

.footer-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

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

.billing-price-grid {
  margin-bottom: 16px;
}

.compact-table table {
  min-width: 820px;
}

.billing-ledger-head {
  margin-bottom: 10px;
}

.billing-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.billing-tabs button {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}

.billing-tabs button.active {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.billing-panel {
  display: none;
}

.billing-panel.active {
  display: block;
}

.billing-list-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 190px) minmax(120px, 150px) auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.billing-page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}

.price-history-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 6px 14px;
  min-width: 420px;
}

.price-history-grid span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  font-size: 12px;
}

.price-history-grid b {
  color: var(--muted);
  font-weight: 600;
}

.credit-positive {
  color: var(--success);
  font-weight: 700;
}

.credit-negative {
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 1500px) {
  .billing-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .billing-list-toolbar {
    grid-template-columns: minmax(220px, 1fr) minmax(150px, 180px) minmax(120px, 150px);
  }

  .billing-page-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

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

  .main {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}

.refund-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.checkbox-label input,
input[data-refund-select] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(280px, 1fr);
    align-items: start;
    gap: 10px 16px;
    padding: 16px 18px;
  }

  .sidebar .site-name,
  .sidebar .site-desc {
    grid-column: 1;
  }

  .sidebar .mini-card {
    grid-column: 2;
  }

  .sidebar .nav,
  .sidebar > .footer-note {
    grid-column: 1 / -1;
  }

  .sidebar .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .grid-4,
  .split {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 760px) {
  .billing-metrics,
  .billing-list-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #billingSearchInput,
  .billing-page-actions {
    grid-column: 1 / -1;
  }

  .main,
  .sidebar {
    padding: 14px;
  }

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

  .sidebar .site-name,
  .sidebar .site-desc,
  .sidebar .nav,
  .sidebar > .footer-note {
    grid-column: 1 / -1;
  }

  .sidebar .mini-card {
    grid-column: auto;
  }

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

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

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

@media (max-width: 520px) {
  .billing-metrics,
  .billing-list-toolbar {
    grid-template-columns: 1fr;
  }

  .billing-page-actions {
    flex-wrap: wrap;
  }

  .sidebar,
  .sidebar .nav {
    grid-template-columns: 1fr;
  }

  .sidebar .mini-card {
    grid-column: 1;
  }
}


.hidden {
  display: none !important;
}

.totp-setup {
  margin: 16px 0;
  padding: 14px;
  border-radius: 16px;
  border: 1px dashed rgba(37, 99, 235, 0.45);
  background: rgba(37, 99, 235, 0.07);
}

.totp-title {
  font-weight: 800;
  margin-bottom: 8px;
}

.totp-secret {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  font-family: Consolas, "Courier New", monospace;
  font-weight: 700;
  letter-spacing: 1px;
  word-break: break-all;
  user-select: all;
}
