.dashboard-page { background: var(--canvas); color: var(--ink); }

:root { --history-width: clamp(360px, 30vw, 460px); }
.history-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 60;
  display: flex;
  flex-direction: column;
  width: var(--history-width);
  height: 100dvh;
  border-left: 1px solid var(--line);
  background: var(--canvas);
  box-shadow: -4px 0 16px rgba(21, 32, 47, .08);
}
.history-drawer[hidden] { display: none; }
.history-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.history-drawer-head h2 { margin: 0; font: 700 21px/1.4 Arial, "PingFang SC", "Microsoft YaHei", sans-serif; }
.history-drawer-head button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--soft);
  color: var(--ink);
  font-size: 26px;
}
.history-drawer-head button:hover { border-color: var(--primary); }
.history-drawer-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; padding: 18px; scrollbar-gutter: stable; }
.history-drawer-note { margin: 0 0 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.history-drawer .dashboard-card { padding: 0; border: 0; background: none; box-shadow: none; }
.history-drawer .record-list { gap: 18px; }
.history-drawer .history-record { padding: 16px; background: var(--surface); border-radius: 4px; }
.history-drawer .history-heading strong { font-size: 15px; }
.history-drawer .record-meta { font-size: 11px; }
.history-drawer .history-preview img,
.history-drawer .history-preview video { max-height: min(560px, 65dvh); }
.history-drawer .record-actions { flex-wrap: wrap; justify-content: flex-start; }
.history-drawer .dashboard-message { margin-top: 0; }
.history-toggle {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 61;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 40px;
  min-height: 124px;
  padding: 14px 9px;
  border: 1px solid var(--primary);
  border-right: 0;
  border-radius: 4px 0 0 4px;
  color: #fff;
  background: var(--primary);
  box-shadow: none;
  transform: translateY(-50%);
  font-size: 13px;
  font-weight: 700;
}
.history-toggle:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.history-toggle-label { writing-mode: vertical-rl; letter-spacing: .12em; }
.history-toggle-icon { display: block; width: 16px; height: 16px; }
.history-open .history-toggle { right: var(--history-width); }
.history-open .history-toggle-icon { transform: rotate(180deg); }
@media (min-width: 1100px) {
  body.history-open { padding-right: var(--history-width); }
  .history-open .workbench { grid-template-columns: minmax(280px, .95fr) minmax(0, 1fr); }
  .history-open .tool-page-head { grid-template-columns: 1fr; gap: 8px; }
  .history-open .brand-note, .history-open .retention-badge { display: none; }
}
@media (max-width: 540px) {
  :root { --history-width: 100%; }
  .history-open .history-toggle { display: none; }
  .history-toggle { top: auto; right: 14px; bottom: 14px; flex-direction: row; min-width: 44px; min-height: 44px; padding: 8px 12px; border-right: 1px solid var(--primary); border-radius: 3px; transform: none; }
  .history-toggle-label { writing-mode: horizontal-tb; letter-spacing: 0; }
  .page-shell { padding-bottom: 80px; }
  .history-drawer-head { padding: max(14px, env(safe-area-inset-top)) 16px 14px; }
  .history-drawer-body { padding: 14px 14px max(14px, env(safe-area-inset-bottom)); }
}
@media (min-width: 541px) and (max-width: 1099px) {
  .history-open .topbar .home-link,
  .history-open .topbar .retention-badge,
  .history-open .account-nav .account-link:not(.account-balance):not(.account-signin):not(.account-ml):not(.account-avatar) { display: none; }
}

.dashboard-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 48px 0 80px;
}

.dashboard-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}

.dashboard-head h1 { margin: 4px 0 0; font-size: clamp(30px, 4vw, 40px); letter-spacing: -0.035em; }
.dashboard-head p { margin: 0; color: var(--muted); }

.dashboard-nav { display: flex; flex-wrap: wrap; gap: 8px; }
.dashboard-nav [hidden] { display: none; }
.dashboard-nav a,
.dashboard-nav button {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.dashboard-nav a:hover, .dashboard-nav button:hover { color: var(--primary); border-color: var(--primary); background: #eef2fe; }
.dashboard-nav a[aria-current="page"] { color: #fff; border-color: var(--primary); background: var(--primary); }

.dashboard-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.dashboard-card {
  grid-column: span 6;
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: none;
  overflow-wrap: anywhere;
}
.dashboard-card.wide { grid-column: 1 / -1; }
.dashboard-card h2 { margin: 0 0 18px; font-size: 20px; }
.dashboard-card h3 { margin: 0 0 8px; font-size: 16px; }
.dashboard-card p { color: var(--muted); line-height: 1.6; }

.metric { font: 700 clamp(36px, 5vw, 54px)/1 Arial, "PingFang SC", sans-serif; letter-spacing: -0.05em; }
.metric small { margin-left: 8px; color: var(--muted); font-size: 14px; letter-spacing: 0; }
.muted { color: var(--muted); }
.ml-card { border-top: 3px solid #d5b34b; scroll-margin-top: 140px; }
.ml-card h2 { display: flex; align-items: center; gap: 10px; }
.ml-card h2 img { flex: 0 0 36px; }
.ml-balance { font-size: clamp(28px, 4vw, 46px); line-height: 1.2; font-variant-numeric: tabular-nums; }
.ml-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; padding: 20px 0; border-bottom: 1px solid var(--line); }
.ml-totals dt { margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.ml-totals dd { margin: 0; font-weight: 700; line-height: 1.6; font-variant-numeric: tabular-nums; }
.ml-totals dd.record-meta { font-weight: 400; }
.ml-card h3 { margin-top: 24px; }
.ml-outlook { margin: 24px 0; padding: 20px; border-left: 3px solid #d5b34b; background: #fffbed; }
.ml-outlook h3 { margin-top: 0; }
.ml-outlook p:last-child { margin-bottom: 0; }
.ml-rules { padding-left: 22px; color: var(--muted); line-height: 1.8; }
.ml-rules li + li { margin-top: 10px; }

.record-list { display: grid; gap: 10px; }
.record {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--soft);
}
.record strong { display: block; margin-bottom: 5px; }
.record-meta { color: var(--muted); font-size: 13px; line-height: 1.5; }
.record-actions { display: flex; align-items: center; gap: 8px; }
.record > div { min-width: 0; }
.history-record { grid-template-columns: minmax(0, 1fr); gap: 14px; scroll-margin-top: 24px; }
.history-record.is-highlighted { border-color: var(--primary); outline: 2px solid var(--primary); outline-offset: 2px; }
.history-summary { overflow-wrap: anywhere; }
.history-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.history-heading strong { margin: 0; }
.history-summary .record-meta { margin-top: 4px; }
.history-summary .record-actions { margin-top: 12px; }
.history-summary .record-actions:empty { display: none; }
.dashboard-card .history-notice { margin: 12px 0; font-size: 13px; }
.history-results { display: grid; gap: 18px; }
.history-result { display: grid; gap: 12px; min-width: 0; }
.history-result + .history-result { padding-top: 18px; border-top: 1px solid var(--line); }
.history-result .record-actions { flex-wrap: wrap; }
.history-result .history-result-title { margin: 0; font-size: 14px; }
.history-online-download { display: grid; gap: 4px; margin-top: 12px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.history-online-download a { color: var(--primary); overflow-wrap: anywhere; text-decoration: underline; text-underline-offset: 3px; }
.history-online-download a:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.history-preview { display: grid; place-items: center; min-width: 0; overflow: hidden; border-radius: 3px; background: #15202f; }
.history-preview[hidden], .history-record [hidden] { display: none; }
.history-preview img, .history-preview video { display: block; width: 100%; max-height: 440px; object-fit: contain; }
.history-record button:disabled { cursor: not-allowed; }
.status-pill { display: inline-flex; padding: 5px 9px; border-radius: 3px; background: #eef2fe; color: var(--primary-hover); font-size: 12px; font-weight: 700; }
.status-pill.success { background: #e8f5ed; color: #23613d; }
.status-pill.failed { background: #fff0f0; color: #a83242; }

.dashboard-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--primary);
  border-radius: 3px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.dashboard-button:not(:disabled):hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.dashboard-button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.dashboard-button.secondary:not(:disabled):hover { background: #eef2fe; color: var(--primary); border-color: var(--primary); }
.dashboard-button:disabled { cursor: wait; opacity: .55; }

.package-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.package-option { position: relative; }
.package-option input { position: absolute; opacity: 0; pointer-events: none; }
.package-option label { display: block; padding: 18px; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.package-option input:checked + label { border-color: var(--primary); background: #eef2fe; }
.package-option input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: 3px; }
.package-option strong { display: block; font-size: 24px; }

.dashboard-field { display: grid; gap: 7px; margin: 14px 0; }
.dashboard-field label { color: var(--muted); font-size: 13px; font-weight: 700; }
.dashboard-field input,
.dashboard-field select {
  width: 100%; min-height: 46px; padding: 0 13px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--canvas); color: var(--ink); font: inherit;
}
.dashboard-field textarea { min-height: 84px; padding: 12px; resize: vertical; }

.payment-box { margin-top: 18px; padding: 18px; border: 1px solid var(--primary); border-radius: 4px; background: #eef2fe; }
.payment-terms { padding: 14px 16px; border-left: 3px solid var(--primary); background: var(--soft); font-size: 13px; line-height: 1.8; }
.reward-wallet { border-top: 3px solid var(--primary); }
.reward-balances { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.reward-balances .metric { font-size: clamp(28px, 4vw, 44px); }
.reward-convert-input { display: flex; gap: 8px; }
.reward-convert-input input { flex: 1; min-width: 0; }
.reward-convert-input button { flex-shrink: 0; color: var(--primary); }
.reward-convert-input button:disabled { cursor: not-allowed; }
.reward-quote { padding: 12px; background: var(--soft); font-variant-numeric: tabular-nums; }
.reward-withdrawal { grid-template-columns: minmax(0, 1fr); }
.reward-withdrawal code { overflow-wrap: anywhere; }
.reward-admin-form { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
@media (max-width: 540px) { .reward-balances { grid-template-columns: 1fr; gap: 8px; } }
.payment-countdown { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; margin: 12px 0; }
.payment-countdown strong { color: var(--ink); font: 700 28px/1.2 "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }
.payment-countdown.expired strong { color: #a83242; }
.payment-address { display: block; margin: 8px 0 14px; overflow-wrap: anywhere; font-family: "IBM Plex Mono", monospace; color: var(--ink); }
.payment-qr { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin: 18px 0; }
.payment-qr img { display: block; width: 222px; max-width: 100%; height: auto; background: #fff; image-rendering: pixelated; }
.payment-qr figcaption { flex: 1 1 190px; max-width: 340px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.payment-box, .payment-record { overflow-wrap: anywhere; }
.payment-box .record-actions { flex-wrap: wrap; justify-content: flex-start; }

.admin-section { margin-top: 26px; }
.admin-row { display: grid; grid-template-columns: minmax(150px, 1fr) 130px 110px auto; gap: 10px; align-items: end; padding: 12px 0; border-bottom: 1px solid var(--line); }
.admin-user-row { grid-template-columns: minmax(220px, 1fr) 120px 160px minmax(180px, 1fr) auto; }
.admin-user-row > span small,
.ledger-delta small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.ledger-delta { min-width: 100px; text-align: right; }
.dashboard-message { margin: 16px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); }
.dashboard-message.error { color: #a83242; border-color: #e2b6bd; background: #fff0f0; }

@media (max-width: 820px) {
  .dashboard-shell { width: min(100% - 24px, 680px); padding-top: 30px; }
  .dashboard-head { display: block; }
  .dashboard-head p { margin-top: 10px; }
  .dashboard-nav { margin-top: 18px; }
  .dashboard-card { grid-column: 1 / -1; padding: 19px; }
  .package-grid { grid-template-columns: 1fr; }
  .record { grid-template-columns: 1fr; }
  .record-actions { justify-content: space-between; }
  .admin-row, .admin-user-row { grid-template-columns: 1fr 1fr; }
  .admin-row > :first-child, .admin-user-row > :first-child, .admin-user-row > :nth-child(4) { grid-column: 1 / -1; }
  .ledger-delta { text-align: left; }
}

@media (max-width: 420px) {
  .dashboard-page [data-user-name] { display: none; }
}
