:root {
  --canvas: #eef1ef;
  --surface: #ffffff;
  --surface-soft: #f7f9f8;
  --ink: #19231f;
  --muted: #66736d;
  --line: #d8dfdc;
  --line-strong: #bdc9c4;
  --accent: #176b52;
  --accent-bright: #21a67a;
  --accent-soft: #e0f2eb;
  --amber: #a76a0a;
  --amber-soft: #fff2d7;
  --danger: #b23a3a;
  --danger-soft: #fde8e7;
  --charcoal: #23302b;
  --shadow: 0 16px 44px rgba(25, 35, 31, 0.1);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; background: var(--canvas); }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  letter-spacing: 0;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:not(:disabled), label[for], select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid rgba(33, 166, 122, 0.28);
  outline-offset: 2px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 32px;
  color: #fff;
  background: var(--charcoal);
  border-bottom: 1px solid #31423b;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 6px;
  font: 700 13px/38px "Segoe UI", sans-serif;
  text-align: center;
}

.brand-mark span:first-child { color: #173f35; background: #f3f7f4; }
.brand-mark span:last-child { color: #fff; background: var(--accent-bright); }
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 16px; }
.brand-copy small { color: #aebdb7; font: 600 9px/1 "Segoe UI", sans-serif; }

.service-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #c8d3cf;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #91a19b;
  box-shadow: 0 0 0 4px rgba(145,161,155,.12);
}
.status-dot.is-online { background: #4ad19d; box-shadow: 0 0 0 4px rgba(74,209,157,.14); }
.status-dot.is-offline { background: #e96961; box-shadow: 0 0 0 4px rgba(233,105,97,.14); }
.status-dot.is-checking { animation: status-pulse 1.4s ease-in-out infinite; }

@keyframes status-pulse { 50% { opacity: .35; transform: scale(.82); } }

.view-tabs {
  height: 54px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.view-tab {
  height: 54px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 18px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.view-tab:hover { color: var(--ink); }
.view-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.view-tab span { font-size: 18px; }

.public-main, .admin-main {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 36px 0 64px;
}

.workspace-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font: 700 10px/1.2 "Segoe UI", sans-serif;
  letter-spacing: 1.2px;
}

h1, h2, h3, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 28px; line-height: 1.25; }
h2 { margin: 0; font-size: 22px; line-height: 1.3; }
h3 { margin: 0; font-size: 16px; line-height: 1.4; }

.step-rail { display: flex; align-items: center; gap: 0; }
.step {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 98px;
  color: #8a9691;
  font-size: 12px;
}
.step:not(:last-child)::after {
  content: "";
  height: 1px;
  flex: 1;
  margin: 0 8px;
  background: var(--line-strong);
}
.step b {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font: 700 11px/1 "Segoe UI", sans-serif;
}
.step.is-current, .step.is-done { color: var(--accent); }
.step.is-current b { color: #fff; background: var(--accent); border-color: var(--accent); }
.step.is-done b { color: var(--accent); background: var(--accent-soft); border-color: #98cdb9; }

.redeem-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr);
  min-height: 590px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tool-frame { padding: 32px; background: var(--surface); }
.redeem-form { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.field-block + .field-block { margin-top: 24px; }
.field-block > label, .field-heading > label:first-child, .history-search > label, .admin-field label {
  display: block;
  margin-bottom: 9px;
  color: #34413c;
  font-size: 13px;
  font-weight: 700;
}
.label-note { margin-left: 7px; color: var(--muted); font-size: 11px; font-weight: 500; }

.field-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-heading > label:first-child { margin-bottom: 9px; }
.file-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input, select { height: 46px; padding: 0 13px; }
textarea { min-height: 120px; padding: 13px; resize: vertical; line-height: 1.6; }
input:hover, textarea:hover, select:hover { border-color: #91a39b; }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent-bright);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(33,166,122,.13);
}
input::placeholder, textarea::placeholder { color: #9aa5a0; }

.field-meta {
  min-height: 27px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}
.text-button {
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.text-button:hover { color: #0d4f3b; text-decoration: underline; }

.inspect-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 24px 0 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}
.inspect-strip > div { padding: 13px 12px; border-right: 1px solid var(--line); }
.inspect-strip > div:last-child { border-right: 0; }
.inspect-strip span { display: block; color: var(--muted); font-size: 10px; }
.inspect-strip strong { display: block; margin-top: 3px; font: 700 19px/1.2 "Segoe UI", sans-serif; }

.inline-message {
  margin-bottom: 14px;
  padding: 11px 12px;
  border-left: 3px solid var(--amber);
  border-radius: 4px;
  background: var(--amber-soft);
  color: #704605;
  font-size: 12px;
  line-height: 1.55;
}
.inline-message.is-error { border-left-color: var(--danger); background: var(--danger-soft); color: #812929; }
.inline-message.is-success { border-left-color: var(--accent); background: var(--accent-soft); color: #0f5540; }

.primary-button, .secondary-button, .download-button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 6px;
  font-weight: 700;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.primary-button:hover:not(:disabled) { background: #115c46; transform: translateY(-1px); }
.primary-button.compact { min-height: 42px; padding: 0 18px; }
.secondary-button { min-height: 44px; padding: 0 18px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); }
.secondary-button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.button-arrow { margin-left: auto; padding-right: 16px; font-size: 19px; }
.button-label { margin-left: auto; }
.redeem-form > .primary-button { width: 100%; margin-top: auto; }
.is-loading .button-label::after { content: " ···"; animation: loading-dots 1s steps(3,end) infinite; }
@keyframes loading-dots { 50% { opacity: .4; } }

.result-stage {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 38px;
  background: #f4f7f5;
}
.result-empty, .result-ready { width: 100%; text-align: center; }
.result-empty img { width: min(100%, 320px); height: auto; display: block; margin: 0 auto 14px; }
.result-empty strong { display: block; font-size: 17px; }
.result-empty span { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.result-ready { animation: ready-enter .35s ease both; }
@keyframes ready-enter { from { opacity: 0; transform: translateY(8px); } }
.success-seal {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 21px;
  border: 1px solid #79bca3;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 31px;
  font-weight: 800;
}
.result-count { margin: 16px 0 22px; color: var(--muted); }
.result-count strong { color: var(--ink); font: 800 29px/1 "Segoe UI", sans-serif; }
.result-facts { margin: 0 0 24px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-facts div { display: flex; justify-content: space-between; gap: 20px; padding: 11px 3px; }
.result-facts div + div { border-top: 1px solid var(--line); }
.result-facts dt { color: var(--muted); font-size: 12px; }
.result-facts dd { max-width: 210px; margin: 0; overflow: hidden; text-overflow: ellipsis; font: 600 12px/1.4 "Segoe UI", sans-serif; }
.download-button { width: 100%; border: 1px solid var(--charcoal); background: var(--charcoal); color: #fff; }
.download-button:hover { background: #121b17; transform: translateY(-1px); }
.download-button span:first-child { font-size: 20px; }
.client-pack-note { margin: 9px 0 0; color: var(--muted); font-size: 10px; }
.result-reset { margin-top: 18px; }

.history-search {
  max-width: 860px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.history-query-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}
.history-field { display: grid; gap: 9px; }
.history-field label { color: #34413c; font-size: 13px; font-weight: 700; }
.history-query-grid .secondary-button { height: 46px; }
.history-list { margin-top: 22px; border-top: 1px solid var(--line); }
.history-row {
  display: grid;
  grid-template-columns: minmax(190px, 1.25fr) minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 22px;
  align-items: center;
  padding: 18px 4px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}
.history-row strong { display: block; font-size: 13px; }
.history-row small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.type-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge, .state-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
}
.badge { color: #0e6046; background: var(--accent-soft); }
.badge.is-team { color: #704605; background: var(--amber-soft); }
.state-badge { color: #315f4d; border: 1px solid #9bc9b7; background: #f0faf6; }
.empty-table { min-height: 230px; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-table span { font-size: 32px; }
.empty-table p { margin: 8px 0 0; font-size: 12px; }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: grid; gap: 8px; }
.toast {
  width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(25,35,31,.16);
  font-size: 12px;
  animation: toast-in .2s ease both;
}
.toast.is-error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(25,35,31,.54);
}
.support-modal {
  position: relative;
  width: min(440px, 100%);
  padding: 34px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0,0,0,.24);
  text-align: center;
  animation: modal-in .22s ease both;
}
@keyframes modal-in { from { opacity: 0; transform: scale(.98) translateY(6px); } }
.modal-close { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 22px; }
.support-icon { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 16px; border: 1px solid #8dc5af; border-radius: 50%; color: var(--accent); font-size: 26px; }
.support-modal > p:not(.eyebrow) { margin: 9px 0 24px; color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Admin */
.admin-page { background: #edf0ee; }
.admin-shell { min-height: calc(100vh - 72px); display: grid; grid-template-columns: 220px 1fr; }
.admin-sidebar { padding: 24px 16px; background: #fff; border-right: 1px solid var(--line); }
.admin-nav { display: grid; gap: 5px; }
.admin-nav-button {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 600;
}
.admin-nav-button:hover { background: var(--surface-soft); color: var(--ink); }
.admin-nav-button.is-active { background: var(--accent-soft); color: var(--accent); }
.admin-nav-button span { width: 20px; text-align: center; font-size: 17px; }
.admin-logout { width: 100%; margin-top: 26px; }
.admin-main { width: min(1320px, calc(100% - 48px)); margin: 0 auto; }
.admin-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.admin-heading p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.admin-section + .admin-section { margin-top: 26px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; }
.metric {
  min-height: 112px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.metric span { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin-top: 13px; font: 800 28px/1 "Segoe UI", sans-serif; }
.metric small { display: block; margin-top: 8px; color: var(--accent); font-size: 10px; }
.admin-band { padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.admin-band-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.admin-band-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.admin-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.admin-field + .admin-field { margin-top: 16px; }
.admin-field small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; }
.file-drop {
  min-height: 180px;
  display: grid;
  place-content: center;
  gap: 7px;
  padding: 20px;
  border: 1px dashed #8da39a;
  border-radius: 6px;
  background: var(--surface-soft);
  text-align: center;
}
.file-drop.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.file-drop strong { font-size: 14px; }
.file-drop span { color: var(--muted); font-size: 11px; }
.file-drop .drop-symbol { color: var(--accent); font-size: 27px; }
.action-row { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.action-row .primary-button { min-width: 150px; padding: 0 18px; }
.generated-output { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.generated-output textarea { min-height: 220px; font-family: Consolas, monospace; font-size: 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
.data-table { width: 100%; border-collapse: collapse; background: #fff; font-size: 11px; }
.data-table th { height: 40px; padding: 0 12px; background: #f3f6f4; color: #53615b; text-align: left; white-space: nowrap; }
.data-table td { min-height: 42px; padding: 11px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.data-table td code { font: 11px/1.4 Consolas, monospace; }
.data-table .truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-action { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--danger); }
.search-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 160px 140px 140px auto; gap: 9px; margin-bottom: 16px; }
.search-toolbar .secondary-button { height: 46px; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--charcoal); }
.login-panel { width: min(410px, 100%); padding: 32px; border-radius: 8px; background: #fff; box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.login-panel .brand { margin-bottom: 28px; color: var(--ink); }
.login-panel .brand-copy small { color: var(--muted); }
.login-panel .admin-field { margin: 24px 0 16px; }
.login-panel .primary-button { width: 100%; }

@media (max-width: 900px) {
  .redeem-layout { grid-template-columns: 1fr; }
  .redeem-form { border-right: 0; border-bottom: 1px solid var(--line); }
  .result-stage { min-height: 440px; }
  .step-rail { display: none; }
  .history-row { grid-template-columns: 1fr 1fr; }
  .admin-shell { grid-template-columns: 1fr; }
  .admin-sidebar { position: sticky; top: 0; z-index: 20; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-nav { grid-template-columns: repeat(4, 1fr); }
  .admin-nav-button { justify-content: center; padding: 0 8px; font-size: 11px; }
  .admin-logout { display: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .search-toolbar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .topbar { min-height: 64px; padding: 0 17px; }
  .brand-copy strong { font-size: 14px; }
  .brand-mark { width: 34px; height: 34px; line-height: 34px; }
  .service-state span:last-child { display: none; }
  .view-tabs { padding: 0 12px; }
  .view-tab { flex: 1; justify-content: center; padding: 0 10px; }
  .public-main, .admin-main { width: calc(100% - 24px); padding: 24px 0 40px; }
  .workspace-intro { margin-bottom: 17px; }
  h1 { font-size: 23px; }
  .redeem-layout { min-height: 0; }
  .tool-frame { padding: 20px 16px; }
  .inspect-strip { grid-template-columns: repeat(2, 1fr); }
  .inspect-strip > div:nth-child(2) { border-right: 0; }
  .inspect-strip > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .result-stage { min-height: 390px; padding: 24px 18px; }
  .history-query-grid { grid-template-columns: 1fr; }
  .history-search { padding: 18px; }
  .history-row { grid-template-columns: 1fr; gap: 9px; padding: 16px 4px; }
  .modal-actions { grid-template-columns: 1fr; }
  .support-modal { padding: 30px 20px 22px; }
  .admin-nav-button { display: grid; place-items: center; gap: 2px; height: 50px; line-height: 1.1; }
  .metric-grid, .admin-grid, .admin-grid.three { grid-template-columns: 1fr; }
  .admin-band { padding: 18px 14px; }
  .admin-heading { align-items: start; flex-direction: column; }
  .search-toolbar { grid-template-columns: 1fr; }
  .action-row { flex-wrap: wrap; }
  .action-row > * { flex: 1 1 140px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
