:root {
  --canvas: #faf7ef;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --ink: #2f352f;
  --muted: #6f756f;
  --quiet: #92958f;
  --line: #e9e4d9;
  --green: #5e8d79;
  --green-strong: #39794f;
  --green-soft: #e9f2e9;
  --gold: #c48b2b;
  --gold-soft: #fdf0d2;
  --danger: #a54943;
  --danger-soft: #f9e7e4;
  --shadow: 0 8px 24px rgba(71, 65, 49, 0.08);
  --radius-large: 22px;
  --radius-medium: 15px;
  --sidebar-width: 252px;
  color: var(--ink);
  font-family:
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden],
dialog:not([open]) {
  display: none !important;
}

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

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

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button,
summary,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(57, 121, 79, 0.42);
  outline-offset: 3px;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
  padding: 8px 14px;
}

button:hover:not(:disabled) {
  border-color: #c9d5ca;
  background: #fbfdf9;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #dcd8ce;
  border-radius: 11px;
  background: #fff;
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

label > span,
fieldset legend {
  display: block;
  margin-bottom: 7px;
  color: #505750;
  font-size: 14px;
  font-weight: 650;
}

fieldset {
  margin: 0;
  border: 0;
  padding: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  line-height: 1.25;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(25px, 2.2vw, 34px);
  letter-spacing: -0.02em;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 100;
  transform: translateY(-160%);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 9px 13px;
}

.skip-link:focus {
  transform: translateY(0);
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.auth-layout {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 430px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: clamp(28px, 6vw, 48px);
}

.auth-mascot {
  width: 82px;
  height: 82px;
  margin-bottom: 18px;
  border-radius: 50%;
}

.auth-copy {
  margin: 12px 0 28px;
  color: var(--muted);
}

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

.full-button {
  width: 100%;
}

.primary-button {
  border-color: var(--green-strong);
  background: var(--green-strong);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover:not(:disabled) {
  border-color: #2e6841;
  background: #2e6841;
}

.secondary-button {
  background: #f7f4ec;
  color: #495049;
}

.danger-button {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
  font-weight: 700;
}

.danger-button:hover:not(:disabled) {
  border-color: #8c3934;
  background: #8c3934;
}

.form-error {
  margin: 0;
  border-radius: 9px;
  background: var(--danger-soft);
  color: #843832;
  padding: 10px 12px;
  font-size: 14px;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fffdf9;
  padding: 28px 18px 20px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 20px;
}

.brand-lockup img {
  width: 58px;
  height: 58px;
  border-radius: 50%;
}

.brand-lockup strong,
.brand-lockup span {
  display: block;
}

.brand-lockup strong {
  font-size: 20px;
}

.brand-lockup span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.environment-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border: 1px solid #dfcf9f;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #76551a;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
}

.sidebar > .environment-badge {
  margin: 0 10px 20px;
}

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

.nav-item {
  display: flex;
  min-height: 52px;
  align-items: center;
  gap: 12px;
  border-color: transparent;
  background: transparent;
  color: #596059;
  padding: 10px 13px;
  text-align: left;
}

.nav-item img {
  width: 23px;
  height: 23px;
  object-fit: contain;
  opacity: 0.72;
}

.nav-item.is-active {
  border-color: #d9e6d9;
  background: var(--green-soft);
  color: var(--green-strong);
  font-weight: 750;
}

.nav-item.is-active img {
  opacity: 1;
}

.sidebar-note {
  margin-top: auto;
  color: var(--muted);
  padding: 20px 12px 0;
  text-align: center;
}

.sidebar-note img {
  width: 120px;
  max-height: 112px;
  object-fit: contain;
}

.sidebar-note p {
  margin: 8px 0 0;
  font-size: 12px;
}

.main-content {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: 0 clamp(20px, 3vw, 46px) 48px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  min-height: 96px;
  grid-template-columns: minmax(190px, 1fr) minmax(300px, 420px) auto;
  align-items: center;
  gap: 22px;
  border-bottom: 1px solid rgba(224, 219, 208, 0.88);
  background: rgba(250, 247, 239, 0.96);
  padding: 18px 0;
}

.global-search {
  display: flex;
  gap: 8px;
}

.global-search input {
  min-width: 0;
}

.global-search button,
.filter-row > button[type="submit"] {
  border-color: var(--green);
  color: var(--green-strong);
  font-weight: 700;
}

.admin-menu {
  position: relative;
}

.admin-menu summary {
  display: flex;
  list-style: none;
  align-items: center;
  gap: 9px;
  border-radius: 12px;
  padding: 7px 9px;
}

.admin-menu summary::-webkit-details-marker {
  display: none;
}

.admin-menu summary img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.admin-menu strong,
.admin-menu small {
  display: block;
  white-space: nowrap;
}

.admin-menu small {
  color: var(--muted);
  font-size: 11px;
}

.admin-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  display: grid;
  gap: 5px;
  min-width: 130px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 7px;
}

.admin-menu-panel button {
  width: 100%;
  border-color: transparent;
  text-align: left;
}

.mobile-header {
  display: none;
}

.page-section {
  padding-top: 26px;
}

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

.kpi-card {
  position: relative;
  min-height: 142px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-medium);
  background: var(--paper-strong);
  box-shadow: var(--shadow);
  padding: 22px;
}

.kpi-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--green);
  content: "";
}

.kpi-card.tone-gold::before {
  background: var(--gold);
}

.kpi-label {
  display: block;
  color: #555d55;
  font-size: 14px;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin: 9px 0 4px;
  font-size: clamp(29px, 3vw, 40px);
  line-height: 1;
}

.kpi-card small {
  color: var(--muted);
  font-size: 12px;
}

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(310px, 0.95fr);
  gap: 18px;
  margin-top: 18px;
}

.paper-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-large);
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: clamp(18px, 2vw, 25px);
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.card-heading h2 {
  font-size: 19px;
}

.heading-icon {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.trend-card,
.membership-summary {
  min-height: 390px;
}

.activity-chart {
  display: block;
  width: 100%;
  height: 300px;
}

.distribution-list {
  display: grid;
  gap: 11px;
}

.distribution-row {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  align-items: center;
  gap: 12px;
}

.distribution-progress {
  width: 100%;
  height: 9px;
  appearance: none;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #eeeae1;
}

.distribution-progress::-webkit-progress-bar {
  border-radius: 999px;
  background: #eeeae1;
}

.distribution-progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--green);
}

.distribution-progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--green);
}

.unavailable-block {
  display: grid;
  gap: 3px;
  margin-top: 22px;
  border: 1px dashed #d8d2c6;
  border-radius: 13px;
  background: #faf8f2;
  padding: 15px;
}

.unavailable-block span {
  color: var(--gold);
  font-weight: 700;
}

.unavailable-block small {
  color: var(--muted);
}

.recent-users-card {
  grid-row: span 2;
}

.quick-actions-card {
  align-self: start;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 17px;
}

.soft-action {
  display: grid;
  min-height: 96px;
  align-content: center;
  gap: 4px;
  border-color: #d6e5d4;
  background: var(--green-soft);
  color: var(--green-strong);
  text-align: left;
}

.soft-action.risk-aware {
  border-color: #ead9ac;
  background: var(--gold-soft);
  color: #7b5717;
}

.soft-action span {
  font-size: 12px;
  font-weight: 500;
}

.text-button {
  min-height: 36px;
  border-color: transparent;
  background: transparent;
  color: var(--green-strong);
  padding: 5px 8px;
  font-weight: 700;
}

.loading-panel,
.notice,
.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius-medium);
  background: var(--paper);
  padding: 24px;
}

.loading-panel {
  color: var(--muted);
}

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

.notice-error {
  border-color: #e9c4c0;
  background: var(--danger-soft);
  color: #77342f;
}

.notice button {
  margin-left: auto;
}

.empty-state {
  display: grid;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state img {
  width: 120px;
  height: 120px;
  object-fit: contain;
}

.empty-state strong {
  color: var(--ink);
}

.data-list {
  display: grid;
  gap: 10px;
}

.data-list-header,
.data-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.1fr) minmax(130px, 1fr) minmax(130px, 1fr) minmax(155px, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.data-list-header {
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  padding: 0 12px 10px;
  font-size: 12px;
  font-weight: 700;
}

.data-row {
  border: 1px solid #ebe7dd;
  border-radius: 13px;
  background: #fff;
  padding: 13px 12px;
}

.data-cell {
  min-width: 0;
  overflow-wrap: anywhere;
}

.data-cell-label {
  display: none;
  color: var(--muted);
  font-size: 11px;
}

.support-id {
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.status-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border: 1px solid #dcd9d0;
  border-radius: 999px;
  background: #f5f3ed;
  color: #5e645e;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.is-trial {
  border-color: #e8d4a1;
  background: var(--gold-soft);
  color: #805b1b;
}

.status-badge.is-monthly,
.status-badge.is-yearly,
.status-badge.is-lifetime {
  border-color: #cfe0cf;
  background: var(--green-soft);
  color: var(--green-strong);
}

.status-badge.is-revoked {
  border-color: #e5c3bf;
  background: var(--danger-soft);
  color: var(--danger);
}

.status-badge.is-active {
  border-color: #cfe0cf;
  background: var(--green-soft);
  color: var(--green-strong);
}

.status-badge.is-upcoming {
  border-color: #e8d4a1;
  background: var(--gold-soft);
  color: #805b1b;
}

.status-badge.is-expired {
  border-color: #d8d6cf;
  background: #f1f0ec;
  color: #686d68;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.row-actions button {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
}

@media (min-width: 821px) {
  .data-list-header,
  .data-row {
    grid-template-columns:
      minmax(110px, 1.1fr)
      minmax(130px, 1fr)
      minmax(130px, 1fr)
      minmax(155px, 1fr)
      minmax(142px, auto);
    gap: 12px;
  }

  .row-actions {
    min-width: 142px;
    flex-wrap: nowrap;
  }

  .row-actions button {
    white-space: nowrap;
  }

  .recent-users-card .data-row {
    grid-template-columns:
      minmax(74px, 0.72fr)
      minmax(88px, 1fr)
      minmax(96px, 1.05fr)
      minmax(72px, 0.8fr)
      minmax(142px, auto);
    gap: 8px;
    padding: 10px 9px;
    font-size: 13px;
  }
}

.filter-row {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 18px;
}

.filter-row label {
  width: min(100%, 380px);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

.field-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.modal {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(50, 47, 37, 0.22);
  padding: clamp(20px, 4vw, 30px);
}

.modal::backdrop {
  background: rgba(42, 46, 42, 0.42);
}

.compact-modal {
  width: min(540px, calc(100vw - 32px));
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.icon-button {
  min-height: 38px;
  padding: 6px 10px;
}

.step-indicator {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
}

.step-indicator li {
  border-bottom: 3px solid #ddd8cd;
  color: var(--muted);
  padding: 0 4px 8px;
  font-size: 13px;
}

.step-indicator li.is-active {
  border-color: var(--green);
  color: var(--green-strong);
  font-weight: 750;
}

.form-step {
  display: grid;
  gap: 18px;
}

.choice-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
}

.choice-card input {
  width: auto;
}

.choice-card span,
.choice-card strong,
.choice-card small {
  display: block;
  margin: 0;
}

.choice-card small {
  color: var(--muted);
}

.change-summary {
  display: grid;
  gap: 8px;
  border: 1px solid #d6e2d5;
  border-radius: 13px;
  background: var(--green-soft);
  padding: 15px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.summary-row span {
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

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

.detail-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 13px;
}

.detail-item span,
.detail-item strong {
  display: block;
}

.detail-item span {
  color: var(--muted);
  font-size: 12px;
}

.detail-item strong {
  margin-top: 4px;
}

.audit-reason {
  color: #4e554e;
}

.inline-empty {
  margin: 0;
  border: 1px dashed #d9d5ca;
  border-radius: 12px;
  background: #fbf8f1;
  color: var(--muted);
  padding: 22px 16px;
  text-align: center;
}

.membership-plan,
.membership-plan strong,
.membership-plan small {
  display: block;
}

.membership-plan small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

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

.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(45, 49, 45, 0.36);
}

@media (max-width: 1240px) {
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .recent-users-card {
    grid-row: auto;
  }
}

@media (max-width: 1120px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    grid-template-columns: minmax(170px, 1fr) minmax(260px, 380px) auto;
  }
}

@media (max-width: 820px) {
  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 24;
    display: flex;
    min-height: 62px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    background: rgba(250, 247, 239, 0.97);
    padding: 10px 16px;
  }

  .mobile-brand {
    font-weight: 800;
  }

  .sidebar {
    width: min(82vw, 290px);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding: 0 16px 36px;
  }

  .topbar {
    position: static;
    min-height: auto;
    grid-template-columns: 1fr auto;
    padding: 22px 0 16px;
  }

  .global-search {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .admin-menu {
    grid-column: 2;
    grid-row: 1;
  }

  .admin-menu summary span {
    display: none;
  }

  .responsive-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .data-list-header {
    display: none;
  }

  .data-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .data-cell-label {
    display: block;
    margin-bottom: 3px;
  }

  .row-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    border-top: 1px solid var(--line);
    padding-top: 10px;
  }

  .filter-row {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .filter-row label {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .auth-layout {
    padding: 14px;
  }

  .auth-card {
    border-radius: 22px;
    padding: 26px 20px;
  }

  .mobile-header .environment-badge {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .kpi-grid {
    gap: 10px;
  }

  .kpi-card {
    min-height: 132px;
    padding: 17px 14px;
  }

  .kpi-card strong {
    font-size: 30px;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .paper-card {
    border-radius: 17px;
    padding: 17px 14px;
  }

  .trend-card,
  .membership-summary {
    min-height: auto;
  }

  .activity-chart {
    height: 240px;
  }

  .distribution-row {
    grid-template-columns: 82px 1fr auto;
    gap: 8px;
  }

  .global-search {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .data-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    grid-column: 1;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    border-radius: 18px;
    padding: 18px 15px;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
  }

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

  .notice button {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
