:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-muted: #f0ede6;
  --line: #ded8cb;
  --line-strong: #c8bead;
  --text: #1d2b27;
  --muted: #66706b;
  --brand: #17443b;
  --brand-soft: #e5eee9;
  --gold: #9a6b23;
  --gold-soft: #f4ead7;
  --red: #b42318;
  --red-soft: #f8dfdc;
  --blue: #2f5f98;
  --blue-soft: #e1ebf7;
  --shadow: 0 16px 40px rgba(28, 38, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  background: #fcfbf8;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 14px;
  border-bottom: 1px solid var(--line);
}

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

.brand-name {
  font-weight: 800;
  font-size: 17px;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 700;
}

.nav-item:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--brand);
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1f8a54;
}

.main {
  min-width: 0;
  padding: 22px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.control {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.control input,
.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

.control input:focus,
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

#api-base-input {
  width: 220px;
}

.token-control input {
  width: 154px;
}

.button {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 13px;
  font-weight: 800;
}

.button.compact {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

.button.primary {
  background: var(--brand);
  color: #fff;
}

.button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.button.warning {
  background: var(--gold);
  color: #fff;
}

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

.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.status-bar {
  min-height: 36px;
  margin-bottom: 14px;
}

.alert {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.alert.error {
  border-color: #efb2aa;
  background: var(--red-soft);
  color: var(--red);
}

.alert.ok {
  border-color: #b8d2c6;
  background: var(--brand-soft);
  color: var(--brand);
}

.view {
  display: grid;
  gap: 14px;
}

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

.stat-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 94px;
  padding: 14px;
  display: grid;
  gap: 8px;
  align-content: center;
}

.stat-label {
  color: var(--muted);
  font-weight: 700;
}

.stat-value {
  font-size: 26px;
  font-weight: 850;
}

.panel {
  overflow: hidden;
}

.panel-header {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  margin: 0;
  font-size: 16px;
}

.panel-body {
  padding: 14px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.pagination {
  min-height: 46px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fdfbf7;
}

.pagination-summary,
.pagination-current {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.pagination-size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pagination-size select {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 4px 8px;
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #faf8f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

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

.cell-main {
  font-weight: 800;
}

.cell-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-muted);
  color: var(--muted);
  white-space: nowrap;
}

.chip.pass,
.chip.published,
.chip.active,
.chip.available,
.chip.approved,
.chip.local_dev {
  background: var(--brand-soft);
  color: var(--brand);
}

.chip.warning,
.chip.waiting,
.chip.reviewing,
.chip.pending,
.chip.draft,
.chip.expired,
.chip.provider_not_configured,
.chip.source_not_ready {
  background: var(--gold-soft);
  color: var(--gold);
}

.chip.blocked,
.chip.blocker,
.chip.archived,
.chip.rejected,
.chip.refunded,
.chip.failed,
.chip.closed,
.chip.reversed,
.chip.disabled {
  background: var(--red-soft);
  color: var(--red);
}

.chip.created,
.chip.paid,
.chip.used,
.chip.withdrawn {
  background: var(--blue-soft);
  color: var(--blue);
}

.issue-list {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
}

.issue-list li + li {
  margin-top: 4px;
}

.empty {
  padding: 36px 12px;
  text-align: center;
  color: var(--muted);
}

.split {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.listbox {
  display: grid;
  gap: 8px;
}

.listbox-button {
  width: 100%;
  min-height: 54px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.listbox-button.is-active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

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

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field.full {
  grid-column: 1 / -1;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--text);
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.notice-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

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

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

  .nav-item {
    text-align: center;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

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

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

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

  .pagination-controls {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

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

  .topbar-actions,
  .control,
  #api-base-input,
  .token-control input {
    width: 100%;
  }

  .button {
    width: 100%;
  }

  .stats-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
