:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-subtle: #f7f8f9;
  --surface-hover: #f1f4f3;
  --text: #1d2427;
  --text-strong: #101719;
  --muted: #657076;
  --line: #dce1e3;
  --line-strong: #c9d0d3;
  --accent: #176a50;
  --accent-hover: #10573f;
  --accent-soft: #e3f1eb;
  --danger: #a43d38;
  --danger-soft: #fae9e7;
  --warning: #865710;
  --warning-soft: #fff1d5;
  --sidebar: #1d2527;
  --sidebar-hover: #2b3538;
  --sidebar-text: #d6ddda;
  --radius: 6px;
  --sidebar-width: 232px;
  font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* 登录 */
.login-shell { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: #edf0f1; }
.login-panel { width: min(412px, 100%); padding: 40px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 48px rgba(27, 37, 40, .09); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: var(--radius); background: var(--accent); color: #f5fff9; font-weight: 700; font-size: 20px; }
.brand-mark.small { width: 34px; height: 34px; font-size: 16px; }
.product-name { margin: 16px 0 34px; color: var(--muted); font-size: 13px; font-weight: 600; }
.login-panel h1 { margin: 0; color: var(--text-strong); font-size: 26px; font-weight: 700; letter-spacing: 0; }
.login-copy { margin: 8px 0 26px; color: var(--muted); line-height: 1.65; }

/* 表单与按钮 */
label { display: block; margin: 15px 0 7px; color: var(--text); font-size: 13px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 40px; padding: 9px 11px; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); outline: none; }
textarea { resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #7d878c; }
input:hover, select:hover, textarea:hover { border-color: #aeb8bc; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 106, 80, .13); }
input:disabled { color: var(--muted); background: var(--surface-subtle); }
.form-error { min-height: 20px; margin: 10px 0; color: var(--danger); font-size: 13px; line-height: 1.5; }
.primary, .secondary, .danger-button { min-height: 38px; padding: 8px 14px; border: 1px solid transparent; border-radius: var(--radius); font-weight: 600; white-space: nowrap; }
.primary { color: #f5fff9; background: var(--accent); border-color: var(--accent); }
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.secondary { color: var(--text); background: var(--surface); border-color: var(--line-strong); }
.secondary:hover { background: var(--surface-hover); border-color: #aeb8bc; }
.danger-button { color: var(--danger); background: var(--surface); border-color: #d9aaa6; }
.danger-button:hover { background: var(--danger-soft); border-color: #ca8d88; }
.wide { width: 100%; min-height: 42px; }

/* 应用骨架 */
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; padding: 22px 14px 16px; color: var(--sidebar-text); background: var(--sidebar); }
.brand-row { display: flex; gap: 11px; align-items: center; min-height: 44px; padding: 0 8px 25px; }
.brand-row strong, .brand-row span { display: block; }
.brand-row strong { color: #f1f5f3; font-size: 14px; font-weight: 650; }
.brand-row span { margin-top: 3px; color: #8f9c98; font-size: 12px; }
nav { display: grid; gap: 3px; }
nav button, .logout-button { min-height: 40px; padding: 9px 12px; color: #b9c4c0; background: transparent; border: 0; border-radius: var(--radius); text-align: left; }
nav button:hover { color: #f4f7f6; background: var(--sidebar-hover); }
nav button.active { color: #ffffff; background: #344043; font-weight: 650; }
.logout-button { margin-top: auto; padding-top: 15px; border-top: 1px solid #354043; border-radius: 0; }
.logout-button:hover { color: #ffffff; }
.workspace { min-width: 0; max-width: 1680px; width: 100%; padding: 27px 32px 48px; }
.topbar { min-height: 58px; display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.topbar p { margin: 0 0 5px; color: var(--muted); font-size: 12px; font-weight: 600; }
.topbar h1 { margin: 0; color: var(--text-strong); font-size: 25px; font-weight: 720; letter-spacing: 0; }
.account { display: flex; gap: 10px; align-items: center; padding-top: 2px; font-size: 13px; }
.account-role { padding: 5px 8px; color: var(--accent); background: var(--accent-soft); border-radius: var(--radius); font-weight: 650; }
.notice { margin: -4px 0 18px; padding: 11px 13px; color: #164f3c; background: var(--accent-soft); border: 1px solid #b8d8cc; border-radius: var(--radius); font-size: 13px; }
.notice.error { color: var(--danger); background: var(--danger-soft); border-color: #e1b8b4; }

/* 概览 */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(170px, 1fr)); overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.metric { min-height: 108px; padding: 21px 23px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric:nth-child(3n) { border-right: 0; }
.metric:nth-last-child(-n+3) { border-bottom: 0; }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 12px; color: var(--text-strong); font-size: 27px; font-weight: 680; font-variant-numeric: tabular-nums; }
.boundary-copy { padding: 29px 20px; color: var(--muted); text-align: center; line-height: 1.7; }

/* 数据工作区 */
.section-block { margin-top: 20px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.section-head { min-height: 60px; display: flex; gap: 18px; align-items: center; justify-content: space-between; padding: 10px 14px 10px 16px; border-bottom: 1px solid var(--line); }
.section-head h2 { flex: 0 0 auto; margin: 0; color: var(--text-strong); font-size: 15px; font-weight: 680; }
.section-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; min-width: 0; }
.filter-actions input, .filter-actions select { min-height: 38px; }
.search { width: 260px; }
.status-filter { width: 128px; }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: var(--surface-subtle); font-size: 12px; font-weight: 650; text-align: left; }
th, td { height: 49px; padding: 10px 13px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-hover); }
td strong { color: var(--text-strong); font-weight: 650; }
.cell-subtext { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.note-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.row-actions { display: flex; align-items: center; gap: 1px; }
.status { display: inline-block; padding: 4px 7px; border-radius: var(--radius); font-size: 12px; font-weight: 650; }
.status.active, .status.fulfilled, .status.paid { color: #146047; background: var(--accent-soft); }
.status.disabled, .status.revoked, .status.refunded { color: var(--danger); background: var(--danger-soft); }
.status.pending, .status.expired { color: var(--warning); background: var(--warning-soft); }
.link-button { min-height: 30px; padding: 4px 7px; color: var(--accent); background: transparent; border: 0; border-radius: 4px; font-weight: 650; }
.link-button:hover { background: var(--accent-soft); }
.link-button.danger { color: var(--danger); }
.link-button.danger:hover { background: var(--danger-soft); }
.empty, .loading { padding: 48px 20px; color: var(--muted); text-align: center; }
.loading-bar { display: block; width: 92px; height: 3px; margin: 0 auto 15px; background: var(--accent); border-radius: 2px; opacity: .72; }
.error-state { display: grid; justify-items: center; gap: 9px; padding: 50px 20px; color: var(--muted); }
.error-state strong { color: var(--text); }
.error-state button { margin-top: 8px; }
.pagination { min-height: 54px; display: flex; justify-content: flex-end; gap: 8px; align-items: center; padding: 9px 14px; color: var(--muted); background: var(--surface-subtle); border-top: 1px solid var(--line); font-size: 13px; }

/* 弹窗 */
dialog { width: min(540px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 24px 72px rgba(23, 32, 35, .24); }
dialog::backdrop { background: rgba(17, 24, 26, .48); }
.dialog-head { position: sticky; top: 0; z-index: 2; min-height: 62px; display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.dialog-head strong { color: var(--text-strong); font-size: 16px; }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; color: var(--muted); background: var(--surface-subtle); border: 0; border-radius: var(--radius); font-size: 20px; }
.icon-button:hover { color: var(--text); background: var(--surface-hover); }
#modal-content { padding: 5px 20px 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.field-help { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.dialog-copy { margin: 16px 0 4px; color: var(--text); line-height: 1.7; }

@media (max-width: 1100px) {
  :root { --sidebar-width: 196px; }
  .workspace { padding: 25px 22px 42px; }
  .section-head { align-items: stretch; flex-direction: column; }
  .section-actions { justify-content: flex-start; width: 100%; }
  .search { flex: 1; width: auto; min-width: 180px; }
}

@media (max-width: 760px) {
  :root { --sidebar-width: 168px; }
  .sidebar { padding-inline: 9px; }
  .brand-row { padding-inline: 4px; }
  .brand-row strong { font-size: 13px; }
  nav button { font-size: 13px; }
  .workspace { padding: 22px 16px 38px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(3n) { border-right: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-last-child(-n+3) { border-bottom: 1px solid var(--line); }
  .metric:nth-last-child(-n+2) { border-bottom: 0; }
  .filter-actions { flex-wrap: wrap; }
  .filter-actions .search { flex: 1 1 100%; }
}

@media (max-width: 620px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; top: 0; z-index: 5; width: 100%; height: auto; padding: 9px 10px; }
  .brand-row, .logout-button { display: none; }
  nav { display: flex; overflow-x: auto; padding-bottom: 2px; }
  nav button { flex: 0 0 auto; min-width: 94px; text-align: center; font-size: 12px; }
  .workspace { padding: 17px 12px 34px; }
  .topbar { min-height: 54px; margin-bottom: 14px; }
  .topbar h1 { font-size: 22px; }
  .account { display: none; }
  .metrics { grid-template-columns: 1fr; }
  .metric, .metric:nth-child(2n), .metric:nth-child(3n) { min-height: 92px; border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .section-head { gap: 12px; }
  .section-actions { flex-wrap: wrap; }
  .search { flex: 1 1 100%; width: 100%; }
  .status-filter { flex: 1; min-width: 118px; }
  .pagination { justify-content: center; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  dialog { max-height: calc(100dvh - 20px); }
}

@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color .14s ease, border-color .14s ease, color .14s ease, transform .08s ease; }
  button:active { transform: translateY(1px); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a1c;
    --surface: #202628;
    --surface-subtle: #272e30;
    --surface-hover: #293133;
    --text: #e8edeb;
    --text-strong: #f4f7f6;
    --muted: #a4aeaa;
    --line: #394245;
    --line-strong: #4b565a;
    --accent: #68b99f;
    --accent-hover: #79c8ae;
    --accent-soft: #203d34;
    --danger: #ef918b;
    --danger-soft: #422a2a;
    --warning: #e4b863;
    --warning-soft: #40351f;
    --sidebar: #111719;
  }
  .login-shell { background: #151a1c; }
  .login-panel { box-shadow: none; }
  input::placeholder, textarea::placeholder { color: #8f9995; }
  .primary { color: #10251e; }
  .account-role { color: #9bd8c4; }
  .notice { color: #a7dcc9; }
}
