:root {
  --canvas: #f4f7fb;
  --surface: #ffffff;
  --soft: #f7f9fc;
  --text: #172033;
  --muted: #6f7b90;
  --line: #e2e8f0;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #edf3ff;
  --green: #16835b;
  --green-soft: #e9f8f1;
  --amber: #a96810;
  --amber-soft: #fff5df;
  --red: #c74343;
  --red-soft: #fff0f0;
  --radius: 7px;
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--canvas);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); text-decoration: none; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--line); padding: 22px 12px 16px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 24px; }
.brand-mark { width: 34px; height: 34px; border-radius: 7px; background: var(--blue); color: white; display: inline-grid; place-items: center; font-weight: 700; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.nav { display: grid; gap: 4px; }
.nav a { min-height: 44px; padding: 7px 10px; color: var(--muted); border-radius: 6px; display: flex; align-items: center; gap: 10px; }
.nav a:hover { background: var(--soft); color: var(--text); }
.nav a.active { background: var(--blue-soft); color: var(--blue); font-weight: 700; box-shadow: inset 3px 0 var(--blue); }
.nav a span { width: 28px; height: 28px; border-radius: 5px; background: var(--soft); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.nav a.active span { background: #dce8ff; }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--line); padding: 14px 10px 0; display: flex; justify-content: space-between; align-items: center; }
.admin-name { font-size: 12px; color: var(--muted); max-width: 105px; overflow: hidden; text-overflow: ellipsis; }
.link-button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; }
.link-button:hover { color: var(--red); }
.main { min-width: 0; }
.topbar { min-height: 78px; padding: 18px 30px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { margin: 0; font-size: 19px; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.content { padding: 24px 30px 40px; max-width: 1680px; margin: 0 auto; }
.button { min-height: 38px; padding: 0 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; white-space: nowrap; }
.button:hover { background: var(--soft); }
.button.primary { background: var(--blue); border-color: var(--blue); color: white; font-weight: 700; }
.button.primary:hover { background: var(--blue-dark); }
.button.ghost { border-color: transparent; color: var(--muted); }
.button.danger-ghost { border-color: transparent; color: var(--red); }
.button.small { min-height: 30px; padding: 0 10px; border-radius: 5px; font-size: 12px; }
.button.wide { width: 100%; }
input, select { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); padding: 0 11px; outline: none; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .10); }
label { color: var(--muted); font-size: 12px; }
label input, label select { display: block; width: 100%; margin-top: 6px; color: var(--text); font-size: 14px; }
.flash-stack { position: fixed; z-index: 20; right: 24px; top: 20px; display: grid; gap: 8px; max-width: 440px; }
.flash { padding: 11px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 8px 28px rgba(25, 36, 55, .12); }
.flash.success { color: var(--green); border-color: #bee7d5; background: var(--green-soft); }
.flash.error { color: var(--red); border-color: #f0c6c6; background: var(--red-soft); }
.metrics-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 12px; }
.metric { min-height: 118px; padding: 17px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.metric span, .metric small { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 8px 0 5px; font-size: 25px; color: var(--blue); }
.metric.warning strong { color: var(--amber); }
.section-heading { margin: 26px 0 10px; display: flex; align-items: end; justify-content: space-between; }
.section-heading h2, .panel-header h2, .form-band h2, .generated-box h2, .info-band h2 { margin: 0; font-size: 15px; }
.section-heading p, .panel-header p, .form-band p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.plan-grid { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.plan-row { min-height: 62px; padding: 10px 16px; display: grid; grid-template-columns: 1.2fr 1fr 100px 100px; align-items: center; border-bottom: 1px solid var(--line); }
.plan-row:last-child { border-bottom: 0; }
.plan-row > div { display: flex; align-items: center; gap: 10px; }
.plan-row > span { color: var(--muted); }
.plan-row b { font-size: 17px; }
.plan-icon { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; color: var(--blue); background: var(--blue-soft); font-weight: 700; }
.two-column { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-header { min-height: 55px; padding: 13px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-header a { font-size: 12px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 42px; padding: 0 13px; text-align: left; background: var(--soft); color: var(--muted); font-size: 11px; font-weight: 500; white-space: nowrap; }
td { min-height: 50px; padding: 11px 13px; border-top: 1px solid var(--line); vertical-align: middle; }
thead + tbody tr:first-child td { border-top: 0; }
td small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
td.actions, th.actions { text-align: right; }
td.actions form { display: inline-flex; margin-left: 4px; vertical-align: middle; }
.table-panel { border-radius: var(--radius); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.mono { font-family: Consolas, monospace; letter-spacing: 0; }
.subtle { color: var(--muted); }
.status { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.status.active, .status.paid, .status.redeemed { color: var(--green); background: var(--green-soft); }
.status.pending, .status.unused { color: var(--amber); background: var(--amber-soft); }
.status.disabled, .status.cancelled, .status.expired, .status.refunded { color: var(--red); background: var(--red-soft); }
.event-list { padding: 2px 16px; }
.event-list > div { min-height: 46px; display: grid; grid-template-columns: 12px 100px 1fr 145px; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.event-list > div:last-child { border-bottom: 0; }
.event-list span, .event-list time { color: var(--muted); font-size: 12px; }
.event-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); }
.form-band { margin-bottom: 16px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.form-band > div { margin-bottom: 14px; }
.inline-form { display: grid; grid-template-columns: 170px 1fr 1fr 1.2fr auto; gap: 10px; align-items: end; }
.inline-form.compact { grid-template-columns: 190px 100px 1fr auto; }
.toolbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.segments { display: inline-flex; padding: 3px; background: #e9eef5; border-radius: 7px; }
.segments a { min-height: 32px; min-width: 64px; padding: 0 12px; border-radius: 5px; color: var(--muted); display: inline-grid; place-items: center; font-size: 12px; }
.segments a.active { background: var(--surface); color: var(--blue); font-weight: 700; box-shadow: 0 1px 3px rgba(25, 36, 55, .08); }
.search { display: flex; gap: 8px; }
.search input { width: 260px; }
.masked-code { color: var(--text); font-size: 12px; }
.copy-code:hover { background: var(--blue-soft); }
.generated-box { margin-bottom: 16px; padding: 15px 17px; border: 1px solid #bed2ff; border-radius: var(--radius); background: var(--blue-soft); }
.generated-box > div { display: flex; align-items: center; justify-content: space-between; }
.generated-box pre { max-height: 180px; overflow: auto; margin: 10px 0 0; padding: 12px; border-radius: 5px; background: var(--surface); font: 13px/1.8 Consolas, monospace; }
.extend-form input { width: 64px; min-height: 30px; border-radius: 5px 0 0 5px; }
.extend-form .button { border-radius: 0 5px 5px 0; margin-left: -1px; }
.settings-layout { display: grid; grid-template-columns: minmax(420px, 620px) minmax(280px, 420px); gap: 16px; align-items: start; }
.settings-panel { padding-bottom: 18px; }
.settings-panel .stack-form { padding: 18px; max-width: 460px; }
.stack-form { display: grid; gap: 14px; }
.info-band { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.info-band dl { margin: 14px 0 0; }
.info-band dl div { min-height: 42px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.info-band dt { color: var(--muted); }
.info-band dd { margin: 0; font-weight: 700; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 0; color: var(--muted); font-size: 12px; }
.detail-grid { display: grid; grid-template-columns: minmax(360px, .9fr) minmax(480px, 1.4fr); gap: 16px; align-items: start; }
.detail-panel { margin-top: 16px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.detail-actions form { margin: 0; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--canvas); }
.login-panel { width: min(420px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 18px 55px rgba(25, 36, 55, .10); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; }
.login-panel h1 { margin: 0; font-size: 22px; }
.login-panel > p { margin: 7px 0 22px; color: var(--muted); }
.login-panel .flash { margin-bottom: 15px; box-shadow: none; }
.error-panel { text-align: center; }
.error-panel > strong { display: block; font-size: 68px; color: var(--blue); }
.error-panel h1 { margin: 0 0 22px; font-size: 20px; }
@media (max-width: 1100px) {
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .inline-form, .inline-form.compact { grid-template-columns: repeat(2, 1fr); }
  .two-column, .settings-layout, .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .sidebar-footer { display: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar { align-items: stretch; flex-direction: column; padding: 12px 0; }
  .search input { width: 100%; }
  .plan-row { grid-template-columns: 1fr 1fr; gap: 8px; }
}
