:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #607080;
  --line: #dfe5ea;
  --brand: #176b87;
  --brand-dark: #0f4c5c;
  --sidebar: #12263a;
  --sidebar-soft: #1d3d5f;
  --danger: #b42318;
  --ok: #137333;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  background: var(--brand-dark);
}

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

button.secondary {
  background: #e8eef2;
  color: var(--text);
}

button.secondary:hover {
  background: #dce5ea;
}

button.compact {
  min-height: 32px;
  padding: 7px 10px;
  font-size: 13px;
  white-space: nowrap;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

h1,
h2,
p {
  margin-top: 0;
}

.shell {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

body.dashboard-mode .shell {
  width: 100%;
  min-height: 100vh;
  padding: 0;
}

body.dashboard-mode .topbar {
  display: none;
}

.topbar,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.topbar h1 {
  margin-bottom: 4px;
  font-size: 28px;
}

.topbar p,
.panel p {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

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

.auth-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.startup-panel {
  min-height: 120px;
  display: grid;
  align-content: center;
  text-align: center;
}

.startup-panel p {
  margin: 0;
}

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

.wechat-auth-panel {
  display: grid;
  gap: 14px;
  justify-items: center;
  text-align: center;
}

.wechat-auth-panel h2,
.wechat-auth-panel p {
  margin-bottom: 0;
}

.auth-context {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #d7e8ef;
  border-radius: 8px;
  color: var(--brand-dark);
  background: #f2f8fb;
  text-align: left;
}

.auth-fallback {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.auth-fallback summary {
  cursor: pointer;
  padding: 14px 16px;
  color: var(--muted);
  font-weight: 700;
}

.auth-fallback .auth-grid {
  padding: 0 14px 14px;
}

form {
  display: grid;
  gap: 14px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: 28px 18px;
  background: var(--sidebar);
  color: #fff;
}

.brand {
  display: grid;
  gap: 8px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand strong {
  font-size: 30px;
  line-height: 1.15;
  word-break: break-word;
}

.brand span {
  color: #9fb3c7;
  font-size: 15px;
  word-break: break-word;
}

.side-nav {
  display: grid;
  gap: 8px;
  align-content: start;
}

.side-nav button {
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  color: #dbe8f3;
  background: transparent;
}

.side-nav button:hover,
.side-nav button.active {
  background: var(--sidebar-soft);
}

.content {
  min-width: 0;
  padding: 30px 28px;
  display: grid;
  gap: 18px;
  align-content: start;
}

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

.content-head h2 {
  margin-bottom: 4px;
  font-size: 28px;
}

.content-head p {
  color: var(--muted);
  margin-bottom: 0;
}

.content-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.product-picker {
  min-width: 240px;
  color: var(--muted);
}

.product-picker select {
  min-height: 42px;
  color: var(--text);
}

.app-section {
  display: none;
}

.app-section.active {
  display: block;
}

.status-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(280px, 1fr) minmax(240px, 0.85fr);
  gap: 16px;
}

.product-status-panel {
  display: grid;
  align-content: start;
  gap: 8px;
}

.rating-panel {
  margin-top: 16px;
}

.compact-head {
  align-items: center;
}

.star-row {
  display: inline-flex;
  gap: 4px;
}

.star-button {
  min-height: 34px;
  width: 34px;
  padding: 0;
  border-radius: 6px;
  color: #7a8795;
  background: #edf2f7;
  font-size: 20px;
  line-height: 1;
}

.star-button.active,
.star-button:hover {
  color: #7a4b00;
  background: #fff3c4;
}

.notice {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid #f2c2bd;
  border-radius: 8px;
  color: var(--danger);
  background: #fff4f2;
}

.account-line {
  margin: 0;
  font-weight: 700;
  color: var(--text) !important;
}

.account-copy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.account-copy-row strong,
.account-copy-row p {
  min-width: 0;
  word-break: break-word;
}

.account-settings-row {
  margin: 10px 0 14px;
}

.bind-panel {
  margin: 16px 0;
  padding: 16px;
  border: 1px solid #f2c2bd;
  border-radius: 8px;
  background: #fff7f5;
}

.bind-panel strong {
  display: block;
  margin-bottom: 6px;
  color: var(--danger);
  font-size: 18px;
  line-height: 1.3;
}

.bind-panel .hint {
  margin-bottom: 14px;
  line-height: 1.55;
}

.bind-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 12px;
}

.bind-form label {
  color: #3f5163;
}

.bind-form input {
  min-height: 48px;
  border-color: #d5dde5;
  background: #fff;
}

.bind-form input:focus {
  outline: 2px solid rgba(23, 107, 135, 0.18);
  border-color: var(--brand);
}

.bind-form .payment-actions {
  justify-content: flex-start;
  margin-top: 2px;
}

.bind-form .payment-actions button {
  min-height: 46px;
}

.bind-panel [data-bind-email-msg] {
  margin: 10px 0 0;
  line-height: 1.45;
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.summary strong {
  display: block;
  font-size: 22px;
}

.summary .status-large {
  margin-top: 8px;
  color: var(--brand);
  font-size: 36px;
  line-height: 1.15;
}

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

.plan {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.plan strong {
  display: block;
  font-size: 18px;
  margin-bottom: 8px;
}

.price {
  font-size: 24px;
  font-weight: 700;
  margin: 12px 0;
}

.pay-buttons,
.payment-actions,
.order-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

button.wechat {
  background: #16883f;
}

button.wechat:hover {
  background: #106b31;
}

.other-payments {
  width: 100%;
}

.other-payments summary {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.other-payments summary:hover {
  color: var(--brand);
}

.other-payment-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.other-payment-list button {
  min-height: 32px;
  padding: 7px 11px;
  font-size: 13px;
}

.auth-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.orders {
  display: grid;
  gap: 10px;
}

.agent-content {
  display: grid;
  gap: 16px;
}

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

.agent-stat,
.agent-profile,
.agent-link-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

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

.agent-stat strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.agent-links {
  display: grid;
  gap: 10px;
}

.agent-link-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 14px;
  align-items: center;
}

.agent-link-card > div {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.agent-link-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.agent-link-actions button {
  min-height: 38px;
}

.agent-link-card code,
.agent-profile code {
  padding: 6px 8px;
  border-radius: 6px;
  background: #edf2f7;
  color: var(--text);
  word-break: break-all;
}

.agent-qr {
  display: block;
  width: 112px;
  height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
}

.order {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(23, 32, 42, 0.45);
  overflow: auto;
}

.modal-panel {
  width: min(620px, 100%);
  max-height: calc(100vh - 28px);
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 20px;
  box-shadow: 0 24px 70px rgba(23, 32, 42, 0.24);
}

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

.payment-layout {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 260px);
  gap: 14px;
  align-items: center;
}

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

.qr-box {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.qr-pattern {
  display: grid;
  grid-template-columns: repeat(11, 10px);
  grid-template-rows: repeat(11, 10px);
  gap: 3px;
  padding: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.qr-pattern.has-image {
  display: block;
}

.qr-pattern.is-loading {
  display: none;
  padding: 0;
  border: 0;
  background: transparent;
}

.qr-pattern img {
  display: block;
  width: min(260px, 58vw);
  height: min(260px, 58vw);
  max-width: 100%;
  object-fit: contain;
}

.qr-pattern i,
.qr-pattern b {
  display: block;
  width: 10px;
  height: 10px;
}

.qr-pattern i {
  background: var(--text);
}

.qr-pattern b {
  background: #fff;
}

.payment-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.captcha-row {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 8px;
  align-items: stretch;
}

.captcha-image {
  min-height: 44px;
  padding: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
}

.captcha-image img {
  display: block;
  width: 100%;
  height: 44px;
  object-fit: cover;
}

.order:first-child {
  border-top: 0;
  padding-top: 0;
}

.tag {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  background: #edf2f7;
  font-size: 12px;
}

.tag.ok {
  color: var(--ok);
  background: #e7f4ea;
}

.tag.bad {
  color: var(--danger);
  background: #fdecea;
}

.error {
  color: var(--danger);
  min-height: 20px;
}

.ok-text {
  color: var(--ok);
}

@media (max-width: 760px) {
  .auth-grid,
  .summary,
  .plans,
  .status-grid,
  .agent-summary,
  .agent-link-card,
  .bind-form {
    grid-template-columns: 1fr;
  }

  .agent-qr {
    width: 140px;
    height: 140px;
  }

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

  .sidebar {
    position: sticky;
    z-index: 2;
    height: auto;
    grid-template-rows: auto auto;
    padding: 18px;
  }

  .side-nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }

  .side-nav button {
    white-space: nowrap;
  }

  .content {
    padding: 18px;
  }

  .topbar,
  .section-head,
  .content-head,
  .content-actions,
  .order,
  .payment-layout {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .modal {
    align-items: start;
  }

  .qr-pattern img {
    width: min(240px, 72vw);
    height: min(240px, 72vw);
  }

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