:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --ink: #17211d;
  --muted: #64706a;
  --line: #dce3df;
  --primary: #0b6b48;
  --primary-dark: #075238;
  --primary-soft: #e7f4ee;
  --amber: #9a5a00;
  --amber-soft: #fff4dc;
  --red: #a13535;
  --red-soft: #fbeaea;
  --blue: #2f5d8c;
  --shadow: 0 12px 32px rgba(23, 33, 29, 0.08);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: max-content;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 17px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #fff;
  background: var(--primary);
  border-radius: 6px;
}

.nav { display: flex; align-items: stretch; align-self: stretch; gap: 4px; }
.nav button {
  min-width: 92px;
  padding: 0 16px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
}
.nav button:hover, .nav button.active { color: var(--ink); border-bottom-color: var(--primary); }

.account-button {
  justify-self: end;
  min-height: 44px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.app-shell { width: min(1160px, calc(100% - 40px)); margin: 30px auto 64px; }
.loading { padding: 56px 0; color: var(--muted); text-align: center; }

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}
.page-head h1, .detail-title h1 { margin: 2px 0 4px; font-size: 26px; line-height: 1.25; }
.page-head p, .detail-title p { margin: 0; color: var(--muted); }
.eyebrow { margin: 0; color: var(--primary); font-size: 12px; font-weight: 700; text-transform: uppercase; }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.metric { min-width: 0; padding: 18px 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 5px; font-size: 24px; line-height: 1.1; }

.section { margin-top: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 17px; }
.section-head p { margin: 0; color: var(--muted); }

.task-list { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.task-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) repeat(4, minmax(80px, .55fr)) 112px;
  align-items: center;
  gap: 16px;
  min-height: 76px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.task-row:last-child { border-bottom: 0; }
.task-row:hover { background: var(--surface-muted); }
.task-name { min-width: 0; }
.task-name strong, .task-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-name span, .cell-label { color: var(--muted); font-size: 12px; }
.cell-value { display: block; margin-top: 2px; font-weight: 650; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 650;
  text-decoration: none;
}
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: var(--ink); background: var(--surface); border-color: var(--line); }
.button.secondary:hover { border-color: #aebbb4; }
.button.danger { color: var(--red); background: var(--red-soft); }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.status {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 24px;
  padding: 2px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: #edf0ee;
  font-size: 12px;
  font-weight: 650;
}
.status.green { color: var(--primary-dark); background: var(--primary-soft); }
.status.amber { color: var(--amber); background: var(--amber-soft); }
.status.red { color: var(--red); background: var(--red-soft); }

.empty { padding: 44px 24px; color: var(--muted); text-align: center; background: var(--surface); border: 1px dashed #c9d1cd; border-radius: 6px; }
.notice { padding: 12px 14px; color: var(--blue); background: #edf4fa; border-left: 3px solid var(--blue); }
.notice.warning { color: var(--amber); background: var(--amber-soft); border-left-color: var(--amber); }
.notice.error { color: var(--red); background: var(--red-soft); border-left-color: var(--red); }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 24px; align-items: start; }
.detail-main, .detail-side { min-width: 0; }
.detail-title { margin-bottom: 20px; }
.panel { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.panel + .panel { margin-top: 16px; }
.panel h2 { margin: 0 0 14px; font-size: 17px; }
.panel h3 { margin: 18px 0 8px; font-size: 14px; }
.panel p { margin: 7px 0; }
.panel .muted { color: var(--muted); }
.key-value { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 10px 16px; margin: 0; }
.key-value dt { color: var(--muted); }
.key-value dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-weight: 600; }

.progress { height: 10px; overflow: hidden; margin: 14px 0 8px; background: #e5eae7; border-radius: 5px; }
.progress > span { display: block; height: 100%; background: var(--primary); transition: width .2s ease; }
.countdown { font-variant-numeric: tabular-nums; font-size: 30px; font-weight: 750; }

.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
label { display: grid; gap: 6px; color: #34423b; font-weight: 600; }
input, select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd4cf;
  border-radius: 5px;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11, 107, 72, .12); }
.checkbox { display: grid; grid-template-columns: 18px 1fr; align-items: start; gap: 9px; font-weight: 400; }
.checkbox input { width: 18px; min-height: 18px; margin-top: 2px; }
.code-row { display: grid; grid-template-columns: minmax(0, 1fr) 116px; gap: 10px; align-items: end; }
.form-hint { min-height: 20px; margin: 0; color: var(--muted); font-size: 12px; }
.development-block { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.official-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 16px;
}
.choice-card {
  display: grid;
  gap: 8px;
  min-height: 108px;
  padding: 16px;
  text-align: left;
  color: inherit;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.choice-card strong { font-size: 15px; }
.choice-card span { color: var(--muted); font-size: 13px; font-weight: 400; }
.choice-card.recommended { border-color: var(--primary); background: var(--primary-soft); }
.choice-card.recommended:hover:not(:disabled) { background: #d9eee4; }
.choice-badge { width: max-content; padding: 2px 7px; color: var(--primary-dark) !important; background: #fff; border-radius: 999px; font-size: 11px !important; font-weight: 700 !important; }
.choice-card:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.choice-card:disabled { cursor: not-allowed; opacity: .55; }
.registration-device-notice { margin: 10px 0 14px; }
.registration-device-notice strong { display: block; font-size: 14px; }
.registration-device-notice p { margin: 5px 0 0; }
#proxyConsentPanel { margin-top: 12px; display: grid; gap: 12px; }
#proxyConsentPanel[hidden] { display: none; }
.kyc-qr {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: 18px 0 12px;
  padding: 16px;
  background: var(--surface-muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}
.kyc-qr img { width: min(220px, 100%); height: auto; background: #fff; }
.kyc-qr figcaption { margin: 0; color: var(--muted); font-size: 13px; }
.relay-frame {
  width: 100%;
  min-height: 520px;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.upstream-form { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.workflow-list { margin: 10px 0 20px; padding-left: 22px; color: var(--muted); }
.workflow-list li + li { margin-top: 7px; }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs button { padding: 10px 14px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--primary); }

.dialog { width: min(440px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(15, 22, 19, .45); }
.dialog-head { display: flex; align-items: start; justify-content: space-between; padding: 22px 24px 12px; }
.dialog-head h2 { margin: 2px 0 0; font-size: 21px; }
.dialog .form-stack { padding: 12px 24px 24px; }
.auth-methods {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 4px;
  margin: 0 24px;
  padding: 4px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.auth-tab {
  min-height: 36px;
  padding: 6px 4px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
  font-weight: 650;
  white-space: nowrap;
}
.auth-tab.active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 3px rgba(23, 33, 29, .12); }
.icon-close { width: 34px; height: 34px; color: var(--muted); background: transparent; border: 0; font-size: 24px; line-height: 1; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(420px, calc(100% - 32px)); padding: 12px 16px; color: #fff; background: #202b26; border-radius: 6px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

.admin-controls { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 10px; max-width: 520px; }
.admin-login-form { max-width: 520px; }
.admin-toolbar { justify-content: flex-end; margin-bottom: 12px; }
.section-rule { margin: 24px 0; border: 0; border-top: 1px solid var(--line); }
.admin-order { padding: 18px 0; border-bottom: 1px solid var(--line); }
.admin-order:last-child { border-bottom: 0; }
.admin-order-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.admin-order-head h3 { margin: 0; }
.assignment-table { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 13px; }
.assignment-table th, .assignment-table td { padding: 9px 8px; text-align: left; border-top: 1px solid var(--line); }
.assignment-table th { color: var(--muted); font-weight: 600; }
.copy-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.copy-field input { font-family: Consolas, monospace; }

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0 16px; }
  .brand span:last-child { display: none; }
  .nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; height: 58px; justify-content: space-around; background: #fff; border-top: 1px solid var(--line); }
  .nav button { flex: 1; min-width: 0; padding: 0 4px; border-top: 2px solid transparent; border-bottom: 0; }
  .nav button:hover, .nav button.active { border-top-color: var(--primary); border-bottom-color: transparent; }
  .account-button { grid-column: 2; }
  .app-shell { width: min(100% - 28px, 720px); margin-top: 22px; margin-bottom: 84px; }
  .detail-layout { grid-template-columns: 1fr; }
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .task-row { grid-template-columns: minmax(0, 1fr) repeat(2, 70px); gap: 10px; }
  .task-row > :nth-child(4), .task-row > :nth-child(5) { display: none; }
  .task-row > .button { padding: 0 10px; }
}

@media (max-width: 540px) {
  .page-head { align-items: start; flex-direction: column; }
  .page-head h1, .detail-title h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .code-row { grid-template-columns: 1fr; }
  .official-actions { display: grid; grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr; }
  .panel { padding: 17px; }
  .task-row { grid-template-columns: minmax(0, 1fr) 64px 82px; padding: 12px; }
  .task-row > :nth-child(3) { display: none; }
  .key-value { grid-template-columns: 86px minmax(0, 1fr); }
  .admin-controls { grid-template-columns: 1fr; }
  .assignment-table { display: block; overflow-x: auto; }
  .auth-methods { margin-right: 17px; margin-left: 17px; }
  .auth-tab { font-size: 12px; }
}
