:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #6b746f;
  --line: #dce3dd;
  --line-strong: #c3cec6;
  --accent: #0d7a5f;
  --accent-dark: #095d49;
  --warn: #b65b13;
  --danger: #b83232;
  --ok: #0a7355;
  --shadow: 0 24px 80px rgba(23, 32, 27, 0.11);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(23, 32, 27, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(23, 32, 27, 0.045) 1px, transparent 1px),
    radial-gradient(circle at top left, rgba(13, 122, 95, 0.14), transparent 34rem),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto, auto;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

button:hover {
  background: var(--accent-dark);
  box-shadow: 0 10px 24px rgba(13, 122, 95, 0.2);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
  box-shadow: none;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfcfb;
  outline: none;
  transition:
    border 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

input {
  min-height: 48px;
  padding: 0 14px;
}

textarea {
  resize: vertical;
  padding: 12px 14px;
  line-height: 1.6;
}

input:focus,
textarea:focus {
  border-color: rgba(13, 122, 95, 0.7);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(13, 122, 95, 0.1);
}

label {
  color: var(--muted);
  font-size: 14px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.public-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.redeem-shell {
  width: min(100%, 760px);
}

.login-shell {
  display: grid;
  width: 100%;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.redeem-panel,
.login-panel,
.tool-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.redeem-panel {
  padding: clamp(24px, 5vw, 52px);
}

.login-panel {
  width: min(100%, 440px);
  margin: 0;
  padding: 32px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-mark {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark.has-image {
  overflow: hidden;
  border: 1px solid var(--line);
  background: #fff;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.purchase-link {
  min-height: auto;
  border: 0;
  padding: 0;
  color: #d12b2b;
  background: transparent;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.purchase-link:hover {
  color: #a91515;
  background: transparent;
  box-shadow: none;
  transform: none;
}

.admin-link,
.ghost-link {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
}

.page-title {
  margin: 54px 0 28px;
}

.public-title {
  margin: 46px 0 30px;
}

.public-title h1 {
  display: grid;
  gap: 12px;
  line-height: 1;
}

.brand-title-main,
.brand-title-sub {
  display: block;
}

.brand-title-main {
  font-size: clamp(46px, 8vw, 76px);
  font-weight: 900;
}

.brand-title-sub {
  width: fit-content;
  border-top: 1px solid var(--line-strong);
  padding-top: 14px;
  color: var(--accent-dark);
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 800;
  line-height: 1.18;
}

.page-title.compact {
  margin: 34px 0 22px;
}

.page-title.compact h1 {
  font-size: clamp(34px, 4vw, 46px);
  line-height: 1.08;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(32px, 8vw, 62px);
  line-height: 1;
}

h2 {
  font-size: 18px;
}

.redeem-form {
  display: grid;
  gap: 10px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.input-row button {
  min-width: 132px;
  padding: 0 22px;
}

.result-box {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  padding: 18px;
  background: #fbfcfb;
}

.result-box.error {
  border-left-color: var(--danger);
}

.result-box.warn {
  border-left-color: var(--warn);
}

.modal-overlay {
  display: grid;
  position: fixed;
  z-index: 20;
  inset: 0;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 27, 0.38);
}

.purchase-modal {
  position: relative;
  width: min(100%, 460px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #fff;
  box-shadow: var(--shadow);
}

.purchase-modal h2 {
  padding-right: 42px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-grid;
  width: 34px;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  font-size: 20px;
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
  background: var(--ink);
}

.purchase-modal-image {
  display: block;
  width: 100%;
  max-height: 340px;
  margin-top: 18px;
  border-radius: 8px;
  object-fit: contain;
}

.purchase-modal-text {
  margin: 16px 0 0;
  color: var(--ink);
  line-height: 1.7;
  white-space: normal;
}

.result-title {
  margin: 0 0 8px;
  font-weight: 800;
}

.result-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.code-stack {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.code-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  word-break: break-all;
}

.code-display span {
  min-width: 88px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.code-display strong {
  flex: 1;
}

.copy-button,
.small-button,
.copy-all-button {
  min-height: 36px;
  padding: 0 12px;
  white-space: nowrap;
}

.copy-all-button {
  justify-self: start;
}

.ghost-button,
.danger-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.ghost-button:hover {
  color: #fff;
  background: var(--ink);
}

.danger-button {
  color: var(--danger);
}

.danger-button:hover {
  color: #fff;
  background: var(--danger);
}

.form-message {
  min-height: 20px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.form-message.error {
  color: var(--danger);
}

.form-message.ok {
  color: var(--ok);
}

.stack-form {
  display: grid;
  gap: 10px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.segment-button {
  min-height: 38px;
  border: 1px solid var(--line);
  padding: 0 8px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  white-space: nowrap;
}

.segment-button:hover,
.segment-button.is-active {
  color: #fff;
  background: var(--accent);
  box-shadow: none;
}

.dashboard {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  padding: 24px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
}

.sidebar-brand {
  justify-content: flex-start;
  font-weight: 800;
}

.sidebar-brand span:last-child {
  line-height: 1.25;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-group-label {
  padding: 8px 14px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.nav-tab {
  justify-content: flex-start;
  border: 1px solid transparent;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav-tab:hover,
.nav-tab.is-active {
  border-color: var(--line);
  color: var(--ink);
  background: #fff;
  box-shadow: none;
}

.nav-subtab {
  min-height: 38px;
  margin-left: 12px;
  padding-left: 18px;
  font-size: 14px;
}

#logoutButton {
  margin-top: auto;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.workspace-header h1 {
  font-size: 36px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: #fff;
}

.summary-card span {
  color: var(--muted);
  font-size: 14px;
}

.summary-card strong {
  display: block;
  margin-top: 10px;
  font-size: 34px;
  line-height: 1;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(280px, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.compact-layout {
  grid-template-columns: 1fr;
}

.tool-panel {
  padding: 18px;
  box-shadow: none;
}

.tool-panel h2 {
  margin-bottom: 12px;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
  box-shadow: none;
}

.code-search-panel {
  grid-template-columns: repeat(3, minmax(180px, 1fr)) auto auto;
}

.search-field {
  display: grid;
  gap: 8px;
}

.code-tables-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.code-list-section {
  min-width: 0;
}

.list-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
}

.muted-count {
  color: var(--muted);
  font-size: 13px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 460px));
  gap: 16px;
  align-items: start;
}

.settings-form {
  max-width: none;
}

.wide-settings-form {
  grid-column: 1 / -1;
  max-width: 720px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.form-actions button {
  min-width: 120px;
  padding: 0 16px;
}

.upload-preview {
  display: grid;
  min-height: 96px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: #fbfcfb;
}

.logo-preview {
  justify-items: start;
}

.purchase-preview {
  min-height: 150px;
}

.purchase-preview img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  object-fit: contain;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mini-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfb;
}

.mini-stat span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8faf8;
  font-size: 13px;
  font-weight: 700;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  background: #fbfcfb;
  font-size: 13px;
  white-space: nowrap;
}

.status-pill.ok {
  border-color: rgba(13, 122, 95, 0.24);
  color: var(--ok);
  background: rgba(13, 122, 95, 0.08);
}

.status-pill.warn {
  border-color: rgba(182, 91, 19, 0.24);
  color: var(--warn);
  background: rgba(182, 91, 19, 0.08);
}

.status-pill.danger {
  border-color: rgba(184, 50, 50, 0.24);
  color: var(--danger);
  background: rgba(184, 50, 50, 0.08);
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .public-page {
    place-items: start center;
  }

  .input-row,
  .dashboard,
  .split-layout,
  .settings-grid,
  .search-panel,
  .code-search-panel,
  .code-tables-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-group {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-group-label {
    grid-column: 1 / -1;
  }

  .nav-subtab {
    margin-left: 0;
  }

  .workspace {
    padding: 20px;
  }

  .workspace-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace-header h1 {
    font-size: 30px;
  }

  .wide-settings-form {
    grid-column: auto;
    max-width: none;
  }
}

@media (max-width: 480px) {
  body {
    background-size: 24px 24px, 24px 24px, auto, auto;
  }

  .public-page,
  .login-shell,
  .workspace {
    padding: 14px;
  }

  .redeem-panel,
  .login-panel {
    padding: 22px;
  }

  .page-title {
    margin-top: 38px;
  }

  .public-title {
    margin-top: 34px;
  }

  .brand-title-main {
    font-size: 42px;
  }

  .brand-title-sub {
    font-size: 23px;
  }

  .segmented-control {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .code-display {
    align-items: stretch;
    flex-direction: column;
  }

  .code-display span {
    min-width: 0;
  }
}
