:root {
  color-scheme: dark;
  --bg: #101113;
  --surface: #181a1f;
  --surface-2: #20232a;
  --line: #323641;
  --text: #f4f6f8;
  --muted: #a3aab5;
  --accent: #2fb673;
  --accent-2: #35a7ff;
  --warn: #f0b43a;
  --danger: #ff6470;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --line: #d9dde4;
  --text: #171a1f;
  --muted: #616a76;
  --shadow: 0 18px 50px rgba(24, 31, 40, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% -10%, rgba(47, 182, 115, .16), transparent 34rem),
    radial-gradient(circle at 100% 10%, rgba(53, 167, 255, .12), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 64px;
  padding: 12px clamp(16px, 4vw, 44px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 25%);
  background: color-mix(in srgb, var(--bg), transparent 8%);
  backdrop-filter: blur(18px);
}

.brand, .top-actions, .panel-head, .summary-band, .api-key-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand { font-weight: 800; }
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 28px auto 64px;
}

.auth-only {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
}

.auth-card, .card, .summary-band {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 3%);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(760px, 100%);
  margin: 9vh auto 0;
  padding: clamp(18px, 4vw, 34px);
  border-radius: 8px;
}

.card, .summary-band {
  border-radius: 8px;
  padding: 22px;
}

.summary-band {
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 18px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 4vw, 42px); letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 19px; letter-spacing: 0; }
.eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}
.muted, small { color: var(--muted); }

.segmented {
  display: flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segment {
  border: 0;
  color: var(--muted);
  background: transparent;
  padding: 9px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.segment.active {
  color: white;
  background: var(--accent);
}

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

.form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}
textarea {
  min-height: 96px;
  resize: vertical;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 78%);
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.primary {
  color: white;
  background: var(--accent);
  font-weight: 800;
}
.primary:disabled { opacity: .55; cursor: not-allowed; }
.ghost, .ghost-link, .icon-btn {
  border-color: var(--line);
  color: var(--text);
  background: var(--surface-2);
}
.ghost-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 9px 14px;
  border-radius: 8px;
}
.icon-btn {
  width: 42px;
  padding: 0;
}
.full { width: 100%; }

.workspace { display: grid; gap: 18px; }
.hidden { display: none !important; }
.grid-two, .grid-three {
  display: grid;
  gap: 18px;
}
.grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  min-height: 78px;
  display: grid;
  align-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: color-mix(in srgb, var(--surface), transparent 3%);
  box-shadow: var(--shadow);
}
.stat-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.stat-card strong {
  font-size: 26px;
  color: var(--text);
}
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
.row-actions input,
.row-actions select {
  width: auto;
  min-width: 130px;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}
.divider-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.stat {
  min-width: 150px;
  display: grid;
  gap: 2px;
  text-align: right;
}
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { font-size: 34px; color: var(--warn); }

.api-key-box {
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.code-output, .docs-code {
  width: 100%;
  margin-top: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.product-item {
  min-height: 170px;
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface-2);
}
.product-item footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.claim-count {
  width: 78px;
  min-height: 42px;
}
.price { color: var(--warn); font-size: 24px; font-weight: 900; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
}

.history-list {
  display: grid;
  gap: 12px;
}
.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-2);
}
.batch-item {
  display: grid;
  gap: 12px;
}
.batch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-toggle {
  flex: 1 1 320px;
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  white-space: normal;
}
.detail-toggle::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .18s ease;
}
.detail-toggle[aria-expanded="true"]::before {
  transform: rotate(45deg);
}
.detail-toggle:hover .batch-title strong {
  color: var(--accent);
}
.batch-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.batch-title strong,
.batch-title small {
  overflow-wrap: anywhere;
}
.summary-tools,
.batch-order-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.summary-tools {
  justify-content: flex-end;
}
.detail-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  background: color-mix(in srgb, var(--surface), transparent 18%);
}
.batch-orders {
  display: grid;
  gap: 10px;
}
.batch-order {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.batch-order-head {
  justify-content: space-between;
}
.batch-order-head > div {
  display: grid;
  gap: 4px;
}
.batch-order:first-child {
  border-top: 0;
  padding-top: 0;
}
.history-query {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.history-query label {
  display: grid;
  gap: 6px;
  min-width: 180px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.order-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.last-claim-bundle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toast, .notice {
  border-radius: 8px;
  padding: 12px 14px;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: 420px;
  color: white;
  background: #222831;
  box-shadow: var(--shadow);
}
.notice.danger { background: color-mix(in srgb, var(--danger), transparent 82%); color: var(--danger); }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
  table-layout: auto;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
  max-width: 360px;
}
td code {
  word-break: break-all;
}
.admin-shell {
  width: min(1420px, calc(100vw - 28px));
}
.admin-shell .card {
  padding: 18px;
}
.admin-shell .summary-band {
  min-height: 110px;
}
.admin-shell .summary-band h1 {
  font-size: 30px;
}
.admin-shell .stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.admin-shell .stat-card {
  box-shadow: none;
}
.admin-shell table {
  min-width: 900px;
}
.admin-shell th,
.admin-shell td {
  font-size: 13px;
}
.admin-shell .name-cell {
  min-width: 150px;
  max-width: 240px;
  overflow-wrap: anywhere;
}
.admin-shell .table-wrap {
  max-height: 620px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.admin-shell .table-wrap table {
  min-width: 980px;
}
.admin-shell thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
}
.content-preview {
  width: min(520px, 48vw);
  max-width: 100%;
}
.content-preview code,
.content-preview pre {
  display: block;
  width: 100%;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  word-break: break-all;
}
.content-preview code {
  max-height: 82px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: var(--surface);
  color: var(--muted);
}
.content-preview pre {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
}
.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.mini-actions button {
  min-height: 34px;
  padding: 6px 10px;
}
.amount-plus {
  color: var(--accent);
  font-weight: 900;
}
.amount-minus {
  color: var(--danger);
  font-weight: 900;
}
.compact-history {
  display: grid;
  gap: 6px;
}
.table-actions {
  min-width: 220px;
}
.table-actions button {
  margin: 2px;
}
.tight-actions {
  min-width: 130px;
}
.danger-action {
  border-color: color-mix(in srgb, var(--danger), transparent 35%);
  color: var(--danger);
}
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-2);
}
.status-active,
.status-available {
  border-color: color-mix(in srgb, var(--accent), transparent 45%);
  color: var(--accent);
}
.status-inactive,
.status-void {
  border-color: color-mix(in srgb, var(--danger), transparent 45%);
  color: var(--danger);
}
.status-claimed {
  border-color: color-mix(in srgb, var(--warn), transparent 45%);
  color: var(--warn);
}
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}
.pager button {
  min-height: 34px;
  padding: 6px 12px;
}
.pager button:disabled {
  opacity: .45;
  cursor: not-allowed;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}
td code, .docs code {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--surface-2);
}

.docs { display: grid; gap: 18px; }
.steps { line-height: 1.9; }
.endpoint-list {
  display: grid;
  gap: 10px;
}
.endpoint-list div {
  display: grid;
  grid-template-columns: 70px minmax(170px, 1fr) 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}
.endpoint-list strong { color: var(--accent); }

@media (max-width: 860px) {
  .grid-two, .grid-three, .inline-form, .stats-grid { grid-template-columns: 1fr; }
  .summary-band, .panel-head { align-items: flex-start; flex-direction: column; }
  .stat { text-align: left; }
  .auth-card { margin-top: 28px; }
  .topbar { align-items: flex-start; gap: 12px; flex-direction: column; }
  .top-actions { flex-wrap: wrap; }
  .endpoint-list div { grid-template-columns: 1fr; }
  .row-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }
  .row-actions input,
  .row-actions select,
  .row-actions button {
    width: 100%;
  }
}

@media (min-width: 861px) and (max-width: 1180px) {
  .admin-shell .grid-three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .admin-shell .grid-three > .card:last-child {
    grid-column: 1 / -1;
  }
}
