@import url("https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&family=Fira+Sans:wght@300;400;500;600;700&display=swap");

:root {
  --color-primary: #0b1120;
  --color-on-primary: #ffffff;
  --color-secondary: #111a2c;
  --color-surface: #0d1524;
  --color-accent: #34d399;
  --color-accent-strong: #10b981;
  --color-background: #050912;
  --color-foreground: #f8fafc;
  --color-muted: #94a3b8;
  --color-border: #22314a;
  --color-border-soft: #1a2539;
  --color-destructive: #f87171;
  --space: 8px;
  --radius: 14px;
  --shadow-soft: 0 18px 40px -24px rgba(0, 0, 0, 0.9);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Fira Sans", sans-serif;
  background:
    radial-gradient(1100px 520px at 12% -12%, rgba(52, 211, 153, 0.1), transparent 65%),
    radial-gradient(900px 460px at 100% 0%, rgba(59, 130, 246, 0.09), transparent 60%),
    var(--color-background);
  background-attachment: fixed;
  color: var(--color-foreground);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(52, 211, 153, 0.32); }
.mono, .metric, th, td.mono { font-family: "Fira Code", monospace; }
a { color: var(--color-accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: #6ee7b7; }
h1, h2 { margin: 0 0 8px; letter-spacing: -0.02em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.top, main { max-width: 1200px; margin: 0 auto; }
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: rgba(5, 9, 18, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-border-soft);
}
.top h1 { font-size: 22px; margin: 0; }
.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-accent);
}
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a {
  position: relative;
  color: #cbd5e1;
  text-decoration: none;
  padding: 8px 12px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 15px;
  transition: background 180ms var(--ease), color 180ms var(--ease), border-color 180ms var(--ease);
}
.nav a:hover { background: rgba(148, 163, 184, 0.08); color: #fff; }
.nav a.active { color: var(--color-accent); background: rgba(52, 211, 153, 0.1); border-color: rgba(52, 211, 153, 0.35); }
main { padding: 24px 20px 96px; }
.muted { color: var(--color-muted); font-size: 13px; }
.name { font-weight: 600; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 28px;
}
.metrics article, .login-card, .table-wrap, .card {
  background: linear-gradient(180deg, rgba(17, 26, 44, 0.96), rgba(13, 21, 36, 0.96));
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}
.metrics article {
  padding: 16px 18px;
  transition: transform 220ms var(--ease), border-color 220ms var(--ease);
}
.metrics article:hover { transform: translateY(-2px); border-color: #2f4364; }
.metric { font-size: 26px; margin: 4px 0 0; color: var(--color-accent); letter-spacing: -0.03em; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px 24px;
  flex-wrap: wrap;
  margin: 32px 0 14px;
}
.section-head > div:first-child { min-width: 260px; }
.section-head p { margin: 4px 0 0; max-width: 68ch; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--color-border-soft); vertical-align: middle; }
thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  font-weight: 600;
  background: rgba(148, 163, 184, 0.05);
}
tbody tr { transition: background 160ms var(--ease); }
tbody tr:hover { background: rgba(148, 163, 184, 0.05); }
tbody tr:last-child td { border-bottom: 0; }
.empty { text-align: center; color: var(--color-muted); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--color-border);
  white-space: nowrap;
}
.pill.custom { color: #6ee7b7; border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.08); }
.pill.list { color: #cbd5e1; }
.pill.live { color: #6ee7b7; border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.08); }
.pill.hidden { color: #fbbf24; border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.08); }

.toolbar { display: flex; gap: 8px; align-items: center; margin: 0; flex-wrap: wrap; }
.price-form, .inline { display: flex; gap: 8px; align-items: center; margin: 0; flex-wrap: wrap; }
.card { padding: 18px; margin: 16px 0; }
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; }
.dl dt { color: var(--color-muted); }

select, textarea, input {
  background: var(--color-background);
  color: var(--color-foreground);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  min-height: 44px;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
input { width: 110px; }
select { width: min(520px, 100%); }
textarea { min-height: 96px; width: 100%; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #334a6b; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
input::placeholder, textarea::placeholder { color: #64748b; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

.status { text-transform: lowercase; }
.status.delivered { color: var(--color-accent); }
.status.failed, .status.fulfillment_error { color: var(--color-destructive); }
.status.paid, .status.processing { color: #fbbf24; }
.bar {
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  height: 10px;
  width: 160px;
  overflow: hidden;
}
.bar span { display: block; height: 100%; background: linear-gradient(90deg, #10b981, #34d399); }
.wallet-list { display: grid; gap: 8px; }
.wallet-list code { word-break: break-all; }

.btn {
  background: linear-gradient(180deg, #34d399, #10b981);
  color: #04231a;
  border: 1px solid rgba(16, 185, 129, 0.5);
  border-radius: 10px;
  padding: 10px 15px;
  min-height: 42px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms var(--ease), filter 160ms var(--ease), background 160ms var(--ease), border-color 160ms var(--ease);
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.99); }
.btn.ghost {
  background: rgba(148, 163, 184, 0.06);
  color: var(--color-foreground);
  border: 1px solid var(--color-border);
  font-weight: 500;
}
.btn.ghost:hover { background: rgba(148, 163, 184, 0.12); border-color: #334a6b; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.banner { padding: 12px 14px; border-radius: 10px; margin: 0 0 16px; border: 1px solid transparent; }
.banner.ok { background: rgba(16, 185, 129, 0.12); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.35); }
.banner.err { background: rgba(248, 113, 113, 0.12); color: #fca5a5; border-color: rgba(248, 113, 113, 0.35); }

.stack { display: grid; gap: 8px; margin-top: 16px; }
.stack input { width: 100%; }
.card input { width: min(220px, 100%); }
.helper { margin: 0; color: var(--color-muted); font-size: 12px; }
.field input, .field select, .field textarea { width: 100%; }
select.compact { width: auto; min-width: 150px; min-height: 42px; }
.btn.disabled { opacity: 0.4; pointer-events: none; }
.btn:disabled { pointer-events: none; }

/* Products accordion */
.search { width: 220px; }
.product-list { display: grid; gap: 10px; }
.product {
  background: linear-gradient(180deg, rgba(17, 26, 44, 0.97), rgba(13, 21, 36, 0.97));
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: border-color 200ms var(--ease), transform 200ms var(--ease);
}
.product:hover { border-color: #2f4364; }
.product[open] { border-color: rgba(52, 211, 153, 0.4); }
.product.hidden { opacity: 0.72; }
.product summary {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.product summary::-webkit-details-marker { display: none; }
.product summary:hover { background: rgba(148, 163, 184, 0.04); }
.product-heading { display: grid; gap: 2px; min-width: 0; }
.product-heading .name { font-size: 16px; }
.product-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.price-range { font-family: "Fira Code", monospace; font-size: 14px; color: var(--color-foreground); }
.chev {
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--color-muted);
  border-bottom: 2px solid var(--color-muted);
  transform: rotate(-45deg);
  transition: transform 220ms var(--ease), border-color 220ms var(--ease);
  margin-left: 4px;
}
.product[open] .chev { transform: rotate(45deg); border-color: var(--color-accent); }
.product-body {
  padding: 4px 18px 18px;
  border-top: 1px solid var(--color-border-soft);
  animation: reveal 240ms var(--ease);
}
@keyframes reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.bulk-form { display: grid; gap: 16px; padding-top: 16px; }
.copy-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; }
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-size: 13px; font-weight: 500; color: #cbd5e1; }
.field input, .field textarea { width: 100%; }
.variant-wrap { border: 1px solid var(--color-border-soft); border-radius: 12px; }
.variant-table { min-width: 640px; }
.variant-table th, .variant-table td { padding: 10px 12px; }
.variant-table tbody tr:last-child td { border-bottom: 0; }
.price-input { position: relative; display: inline-flex; align-items: center; }
.price-input .prefix {
  position: absolute;
  left: 10px;
  color: var(--color-muted);
  font-family: "Fira Code", monospace;
  font-size: 13px;
  pointer-events: none;
}
.price-input input { width: 128px; padding-left: 24px; font-family: "Fira Code", monospace; }
.stars { color: var(--color-muted); font-size: 13px; white-space: nowrap; }
.stock-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  background: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.14);
}
.stock-dot.off { background: var(--color-destructive); box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.14); }
.bulk-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bulk-actions .muted { margin: 0; }
.bulk-actions .muted.dirty { color: #fbbf24; }
.product-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border-soft);
}
.product-tools .muted { margin-left: auto; }
.empty-state { text-align: center; padding: 36px 20px; }
.empty-state .name { font-size: 17px; }

.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.login-body .login-card { width: min(420px, 100%); padding: 32px; }
.totp-setup { display: grid; gap: 12px; justify-items: center; margin: 8px 0 16px; }
.totp-setup img { background: #fff; border-radius: 12px; padding: 8px; }
.totp-secret { font-size: 13px; letter-spacing: 0.08em; word-break: break-all; text-align: center; }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .copy-grid { grid-template-columns: 1fr; }
  .top { position: static; }
}
@media (max-width: 640px) {
  .metrics { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
  .product summary { grid-template-columns: 20px 1fr; }
  .product-meta { grid-column: 1 / -1; justify-content: flex-start; padding-left: 32px; }
  .search { width: 100%; }
  .toolbar { width: 100%; }
  .toolbar .search { flex: 1 1 100%; }
  .product-tools .muted { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Quick actions */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 8px;
}
.quick-actions a {
  display: grid;
  gap: 2px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: rgba(148, 163, 184, 0.04);
  color: var(--color-foreground);
  text-decoration: none;
  transition: transform 200ms var(--ease), border-color 200ms var(--ease), background 200ms var(--ease);
}
.quick-actions a:hover { transform: translateY(-2px); border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.06); }
.qa-title { font-weight: 600; }

/* Orders filters */
.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin: 0 0 14px;
}
.filters .field { min-width: 150px; }
.filters .field.grow { flex: 1 1 220px; }
.filters .field.grow input,
.filters .field input,
.filters .field select { width: 100%; }
.filters .field.actions { display: flex; gap: 8px; min-width: auto; }
.filters .btn { min-width: 96px; }
.order-count { margin: 0 0 10px; }
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 18px 0 0;
  flex-wrap: wrap;
}
.orders-table table { min-width: 960px; }
.orders-table td { word-break: break-word; }
@media (max-width: 860px) {
  .orders-table { overflow: visible; }
  .orders-table table { min-width: 0; }
  .orders-table thead { display: none; }
  .orders-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border-soft);
  }
  .orders-table tbody td {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 0;
    border: 0;
  }
  .orders-table tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-muted);
    font-weight: 600;
  }
  .orders-table tbody td[data-label="Product"],
  .orders-table tbody td[data-label="Keys"] { grid-column: 1 / -1; }
  .filters .field { flex: 1 1 140px; min-width: 0; }
}

/* Stats */
.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: rgba(148, 163, 184, 0.05);
}
.tabs .tab {
  padding: 7px 13px;
  border-radius: 9px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 14px;
  transition: background 180ms var(--ease), color 180ms var(--ease);
}
.tabs .tab:hover { background: rgba(148, 163, 184, 0.1); color: #fff; }
.tabs .tab.active { background: rgba(52, 211, 153, 0.16); color: var(--color-accent); }
.chart-card { padding: 20px 18px 12px; }
.rev-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 170px;
  padding-top: 8px;
}
.rev-bar {
  position: relative;
  flex: 1 1 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.rev-fill {
  width: 100%;
  max-width: 46px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, #34d399, #0f766e);
  min-height: 4px;
  transition: filter 180ms var(--ease);
}
.rev-bar:hover .rev-fill { filter: brightness(1.2); }
.rev-label {
  font-family: "Fira Code", monospace;
  font-size: 10px;
  color: var(--color-muted);
  transform: rotate(-38deg);
  transform-origin: center;
  white-space: nowrap;
}

/* Product adjust + sticky save */
.adjust-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px dashed var(--color-border);
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.03);
}
.adjust-row label { font-size: 13px; font-weight: 500; color: #cbd5e1; }
.adjust-row .muted { margin: 0; }
.suffix-input input { width: 92px; padding-right: 26px; }
.suffix-input .suffix {
  position: absolute;
  right: 10px;
  color: var(--color-muted);
  font-family: "Fira Code", monospace;
  font-size: 13px;
  pointer-events: none;
}
.bulk-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 0 -18px -18px;
  padding: 12px 18px;
  background: rgba(13, 21, 36, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--color-border-soft);
  border-radius: 0 0 var(--radius) var(--radius);
  transition: background 200ms var(--ease);
}
.bulk-actions.is-dirty { background: rgba(52, 211, 153, 0.1); }
.result-count { margin: 0 0 10px; }
.empty-filter { text-align: center; padding: 28px; }
.product-tools .btn[data-copy] { font-family: "Fira Code", monospace; font-size: 13px; }

@media (max-width: 900px) {
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .quick-actions { grid-template-columns: 1fr; }
  .bulk-actions { margin: 0 -14px -14px; padding: 12px 14px; }
  .rev-chart { height: 130px; gap: 4px; }
  .rev-label { font-size: 9px; }
}

/* Final polish */
.product { scroll-margin-top: 88px; }
.product summary:focus-visible { outline-offset: -2px; }
.product[open] summary { border-bottom: 1px solid var(--color-border-soft); }
* { scrollbar-width: thin; scrollbar-color: #2a3b57 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a3b57; border-radius: 999px; border: 2px solid var(--color-background); }
::-webkit-scrollbar-thumb:hover { background: #37507a; }

/* Wholesale and margin */
.cost { color: #cbd5e1; }
.cost-range { font-family: "Fira Code", monospace; font-size: 12px; white-space: nowrap; }
.margin { display: inline-grid; gap: 1px; font-family: "Fira Code", monospace; font-size: 13px; white-space: nowrap; }
.margin-pct { font-size: 11px; opacity: 0.8; }
.margin.pos { color: #34d399; }
.margin.neg { color: var(--color-destructive); }
.margin.flat, .margin.na { color: var(--color-muted); }
.margin-avg.pos { color: #6ee7b7; border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.08); }
.margin-avg.neg { color: #fca5a5; border-color: rgba(248, 113, 113, 0.4); background: rgba(248, 113, 113, 0.08); }
.margin-avg.flat { color: #cbd5e1; }
.variant-table th:nth-child(3), .variant-table td:nth-child(3) { white-space: nowrap; }
