:root {
  --bg: hsl(235 30% 7%);
  --panel: hsla(0 0% 100% / 0.08);
  --border: hsla(0 0% 100% / 0.1);
  --text: hsl(220 26% 93%);
  --muted: hsl(224 16% 72%);
  --primary: hsl(264 91% 69%);
  --primary-2: hsl(196 91% 62%);
  --success: hsl(152 74% 59%);
  --warning: hsl(38 94% 65%);
  --danger: hsl(357 87% 67%);
  --shadow: 0 25px 70px hsla(240 60% 3% / 0.42);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background:
    radial-gradient(circle at top left, hsla(280 92% 60% / 0.18), transparent 30%),
    radial-gradient(circle at top right, hsla(195 95% 55% / 0.16), transparent 26%),
    linear-gradient(180deg, hsl(236 34% 9%), hsl(230 31% 6%));
  color: var(--text);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: linear-gradient(hsla(0 0% 100% / 0.02) 1px, transparent 1px), linear-gradient(90deg, hsla(0 0% 100% / 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.85), transparent);
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; border: 0; }

.app-shell {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 0%, hsla(267 94% 66% / 0.14), transparent 34%);
}

/* ─── MOBILE TAB BAR ─── */
.mobile-tabs {
  display: none;
}

/* ─── TOPBAR ─── */
.topbar, .dashboard {
  position: relative;
  z-index: 1;
  max-width: 1680px;
  margin: 0 auto;
}

.topbar {
  display: block;
  padding: 12px clamp(12px, 3vw, 24px) 8px;
}

.topbar__actions {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
  width: 100%;
}

.topbar__actions--full {
  width: 100%;
}

.buyer-select {
  min-height: 36px;
  min-width: 0;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: hsla(231 26% 12% / 0.95);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: border-color 180ms ease;
}

.buyer-select:focus {
  border-color: hsla(267 90% 68% / 0.62);
}

/* ─── AUTH OVERLAY ─── */
body.auth-locked {
  overflow: hidden;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, hsla(267 94% 66% / 0.22), transparent 30%),
    linear-gradient(180deg, hsla(235 40% 6% / 0.95), hsla(230 34% 5% / 0.96));
  backdrop-filter: blur(14px);
}

.auth-overlay.is-hidden {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  padding: 28px;
  border-radius: 24px;
  box-shadow: 0 35px 100px hsla(240 70% 2% / 0.58);
}

.auth-card__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.auth-card__text {
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 16px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-input {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: hsla(231 26% 12% / 0.95);
  color: var(--text);
  padding: 0 14px;
  outline: none;
}

.auth-input:focus {
  border-color: hsla(267 90% 68% / 0.62);
  box-shadow: 0 0 0 4px hsla(267 90% 68% / 0.12);
}

.auth-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 0.82rem;
  display: none;
}

.auth-error.is-visible {
  display: block;
}

.topbar__actions .primary-button--sm,
.topbar__actions .secondary-button--sm,
.topbar__actions .ghost-button--sm {
  min-width: 0;
  min-height: 36px;
  padding: 0 10px;
  text-align: center;
  justify-content: center;
  white-space: nowrap;
  font-size: 0.78rem;
  width: 100%;
}

#logout-btn,
#debug-btn {
  position: relative;
  z-index: 2;
}

.dashboard { padding: 8px clamp(14px, 4vw, 42px) 40px; }

/* ─── GLASS ─── */
.glass-panel {
  background: linear-gradient(180deg, hsla(0 0% 100% / 0.1), hsla(0 0% 100% / 0.045));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.metric-card, .price-card, .purchase-card, .analysis-card, .endpoint-card-panel, .raw-card {
  padding: 20px;
}

/* ─── STATUS STRIP ─── */
.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card {
  background: linear-gradient(180deg, hsla(0 0% 100% / 0.08), hsla(0 0% 100% / 0.04));
  padding: 14px 16px;
}

.metric-card__label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 6px;
}

.metric-card strong { font-size: 1.1rem; }

/* ─── WORKSPACE 2-COL ─── */
.workspace-grid, .debug-grid {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.workspace-grid {
  grid-template-columns: minmax(0, 1.55fr) minmax(400px, 0.95fr);
}

.side-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-content: start;
}

/* ─── SECTION HEADS ─── */
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.section-head--compact h2 {
  margin-top: 4px;
  font-size: 1.2rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: hsla(0 0% 100% / 0.08);
  border: 1px solid hsla(0 0% 100% / 0.08);
  font-size: 0.78rem;
}

.pill--sm { padding: 6px 10px; font-size: 0.72rem; }
.pill--warning { color: var(--warning); background: hsla(38 94% 65% / 0.08); }

/* ─── TOOLBAR ─── */
.toolbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar-info, .purchase-preview, .warning-box, .balance-display, .balance-inline, .result-card {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  line-height: 1.65;
  font-size: 0.85rem;
}

.purchase-preview {
  margin-top: 14px;
  margin-bottom: 6px;
}

.toolbar-info, .purchase-preview, .balance-display, .balance-inline, .result-card {
  background: hsla(0 0% 100% / 0.05);
  border: 1px solid hsla(0 0% 100% / 0.08);
  color: var(--muted);
}

.purchase-balance-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.balance-inline strong { color: var(--text); }

.warning-box {
  margin-bottom: 12px;
  background: linear-gradient(180deg, hsla(357 87% 67% / 0.11), hsla(38 94% 65% / 0.08));
  border: 1px solid hsla(357 87% 67% / 0.2);
  color: hsl(25 90% 88%);
  font-size: 0.82rem;
}

/* ─── FORM ─── */
.control-grid {
  display: grid;
  gap: 12px;
}
.control-grid--2col { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-size: 0.78rem; }

.field input, .field select {
  min-height: 42px;
  width: 100%;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid hsla(0 0% 100% / 0.08);
  background: hsla(231 26% 12% / 0.95);
  color: var(--text);
  outline: none;
  font-size: 0.88rem;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.field input:focus, .field select:focus {
  border-color: hsla(267 90% 68% / 0.62);
  box-shadow: 0 0 0 3px hsla(267 90% 68% / 0.14);
}

/* ─── BUTTONS ─── */
.actions-row {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.primary-button, .secondary-button, .ghost-button, .table-action {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  transition: transform 180ms ease, opacity 180ms ease, background 180ms ease;
}

.primary-button--sm, .secondary-button--sm, .ghost-button--sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.78rem;
  border-radius: 10px;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  box-shadow: 0 12px 24px hsla(270 80% 55% / 0.3);
}

.primary-button--danger {
  background: linear-gradient(135deg, hsl(356 84% 65%), hsl(21 95% 60%));
}

.secondary-button, .table-action {
  background: hsla(0 0% 100% / 0.09);
  color: var(--text);
  border: 1px solid hsla(0 0% 100% / 0.1);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid hsla(0 0% 100% / 0.1);
}

.primary-button:hover, .secondary-button:hover, .ghost-button:hover, .table-action:hover {
  transform: translateY(-2px);
}

/* ─── TABLE (desktop) ─── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid hsla(0 0% 100% / 0.08);
}

.table-wrap table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  background: hsla(231 24% 11% / 0.82);
  table-layout: fixed;
}

th, td {
  padding: 11px 10px;
  text-align: left;
  border-bottom: 1px solid hsla(0 0% 100% / 0.06);
  vertical-align: top;
  word-break: break-word;
  font-size: 0.82rem;
}

th {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

tbody tr:hover { background: hsla(0 0% 100% / 0.03); }
.empty-cell { text-align: center; color: var(--muted); }

.price-card th:nth-child(1), .price-card td:nth-child(1) { width: 28%; }
.price-card th:nth-child(2), .price-card td:nth-child(2) { width: 22%; }
.price-card th:nth-child(3), .price-card td:nth-child(3),
.price-card th:nth-child(4), .price-card td:nth-child(4),
.price-card th:nth-child(5), .price-card td:nth-child(5),
.price-card th:nth-child(6), .price-card td:nth-child(6) { width: 12.5%; }

/* ─── PRODUCT CARDS (mobile) ─── */
.product-list {
  display: none;
}

.product-list.active-grid {
  display: none;
}

.product-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: hsla(0 0% 100% / 0.04);
  border: 1px solid hsla(0 0% 100% / 0.07);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-item__name {
  font-weight: 600;
  font-size: 0.78rem;
  margin-bottom: 5px;
  line-height: 1.3;
}

.product-item__meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
  font-size: 0.68rem;
  color: var(--muted);
}

.product-item__meta strong { color: var(--text); }

.product-item__action {
  margin-top: 6px;
}

.product-item__action .table-action {
  font-size: 0.72rem;
  min-height: 32px;
  width: 100%;
}

/* ─── OTHER ─── */
.bullet-list {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  line-height: 1.7;
  font-size: 0.82rem;
}

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

.endpoint-card {
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid hsla(0 0% 100% / 0.08);
  background: hsla(0 0% 100% / 0.04);
  font-size: 0.82rem;
}

.endpoint-card__method {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
  font-size: 0.7rem;
  font-weight: 700;
}
.endpoint-card__method--get { color: var(--success); background: hsla(152 74% 59% / 0.1); }
.endpoint-card__method--post { color: var(--warning); background: hsla(38 94% 65% / 0.12); }
/* ─── HISTORY ─── */
.history-section {
  margin-top: 18px;
}

.history-card {
  padding: 20px;
}

.history-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.buyer-select--sm {
  min-height: 30px;
  padding: 0 8px;
  font-size: 0.72rem;
}

.ghost-button--danger {
  color: var(--danger);
  border-color: hsla(357 87% 67% / 0.25) !important;
}

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

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

.history-actions .buyer-select,
.history-actions .ghost-button {
  min-height: 36px;
}

.history-entry {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: hsla(0 0% 100% / 0.04);
  border: 1px solid hsla(0 0% 100% / 0.07);
  font-size: 0.82rem;
  line-height: 1.6;
}

.history-entry--success {
  border-left: 3px solid var(--success);
}

.history-entry--fail {
  border-left: 3px solid var(--danger);
}

.history-entry__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.history-entry__badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
}

.history-entry__badge--ok {
  color: var(--success);
  background: hsla(152 74% 59% / 0.12);
}

.history-entry__badge--fail {
  color: var(--danger);
  background: hsla(357 87% 67% / 0.12);
}

.history-entry__tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-entry__time {
  font-size: 0.7rem;
  color: var(--muted);
}

.history-entry__delete {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid hsla(357 87% 67% / 0.28);
  border-radius: 999px;
  background: hsla(357 87% 67% / 0.08);
  color: var(--danger);
  font-size: 0.72rem;
  font-weight: 600;
}

.history-entry__details {
  color: var(--muted);
  font-size: 0.78rem;
}

.history-entry__details strong {
  color: var(--text);
}

.debug-grid { grid-template-columns: 0.9fr 1.5fr; }

.code-view {
  margin: 0;
  min-height: 300px;
  max-height: 550px;
  overflow: auto;
  padding: 14px;
  border-radius: var(--radius-lg);
  background: hsl(231 28% 10%);
  border: 1px solid hsla(0 0% 100% / 0.08);
  color: hsl(195 86% 78%);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.78rem;
}

.result-card__label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-success { color: var(--success); }
.status-error { color: var(--danger); }
.status-warn { color: var(--warning); }

/* ─── CONFIRM MODAL ─── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: hsla(230 40% 5% / 0.85);
  backdrop-filter: blur(8px);
  padding: 20px;
  animation: fadeIn 180ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.confirm-box {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, hsl(232 28% 14%), hsl(230 26% 10%));
  border: 1px solid hsla(0 0% 100% / 0.12);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: 0 30px 80px hsla(0 0% 0% / 0.6);
}

.confirm-box__title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--warning);
}

.confirm-box__body {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--muted);
  margin-bottom: 20px;
}

.confirm-box__body strong {
  color: var(--text);
}

.confirm-box__actions {
  display: flex;
  gap: 12px;
}

.confirm-box__actions button {
  flex: 1;
  min-height: 44px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  transition: transform 180ms ease;
}

.confirm-box__actions button:hover {
  transform: translateY(-2px);
}

.confirm-btn--cancel {
  background: hsla(0 0% 100% / 0.09);
  color: var(--text);
  border: 1px solid hsla(0 0% 100% / 0.1) !important;
}

.confirm-btn--ok {
  background: linear-gradient(135deg, hsl(356 84% 65%), hsl(21 95% 60%));
  color: white;
  box-shadow: 0 10px 24px hsla(356 80% 55% / 0.35);
}

.desktop-only { display: block; }

/* ─── TABLET ─── */
@media (max-width: 1120px) {
  .workspace-grid, .debug-grid, .side-stack, .status-strip {
    grid-template-columns: 1fr;
  }
  .hero-card, .toolbar-row { display: flex; }
  .hero-card { flex-direction: column; align-items: flex-start; }
  .hero-actions { min-width: 0; width: 100%; flex-direction: row; }
  .status-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-wrap { overflow-x: auto; }
  .table-wrap table { min-width: 860px; table-layout: auto; }
  .purchase-balance-row { grid-template-columns: 1fr; }
  .price-card th:nth-child(1), .price-card td:nth-child(1),
  .price-card th:nth-child(2), .price-card td:nth-child(2),
  .price-card th:nth-child(3), .price-card td:nth-child(3),
  .price-card th:nth-child(4), .price-card td:nth-child(4),
  .price-card th:nth-child(5), .price-card td:nth-child(5),
  .price-card th:nth-child(6), .price-card td:nth-child(6) { width: auto; }
}

/* ─── MOBILE APP MODE ─── */
@media (max-width: 720px) {
  body { font-size: 13px; padding-bottom: 56px; }

  .mobile-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: hsl(232 30% 10%);
    border-top: 1px solid hsla(0 0% 100% / 0.08);
    padding: 6px 8px;
    gap: 6px;
  }

  .mobile-tab {
    flex: 1;
    min-height: 40px;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    border: 0;
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease;
  }

  .mobile-tab.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: white;
  }

  .topbar {
    padding: 12px 14px 6px;
  }

  .topbar__link { display: none; }

  .brand h1 { font-size: 1.1rem; }
  .brand__eyebrow { font-size: 0.58rem; }

  .primary-button--sm, .secondary-button--sm, .ghost-button--sm {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .dashboard { padding: 6px 12px 24px; }

  .status-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
  }

  .metric-card {
    padding: 10px 12px;
    border-radius: var(--radius-md);
  }

  .metric-card__label { font-size: 0.62rem; margin-bottom: 4px; }
  .metric-card strong { font-size: 0.92rem; }

  .workspace-grid {
    display: block;
    margin-top: 12px;
  }

  .side-stack { gap: 12px; }

  /* Tab-panel logic */
  .tab-panel { display: none; }
  .tab-panel.active { display: block; }

  .desktop-only { display: none !important; }
  .product-list.active-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  /* Cards */
  .price-card, .purchase-card, .analysis-card, .endpoint-card-panel, .raw-card {
    padding: 14px;
    border-radius: var(--radius-lg);
  }

  .glass-panel { border-radius: var(--radius-lg); }

  .section-head { margin-bottom: 10px; }
  .section-head--compact h2 { font-size: 1rem; }
  .eyebrow { font-size: 0.58rem; }

  .toolbar-row { margin-bottom: 10px; }
  .toolbar-info { font-size: 0.78rem; padding: 10px 12px; }

  .purchase-preview, .warning-box, .balance-inline, .result-card {
    padding: 10px 12px;
    font-size: 0.78rem;
  }

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

  .field span { font-size: 0.72rem; }
  .field input { min-height: 38px; font-size: 0.82rem; padding: 0 10px; }

  .actions-row { gap: 8px; margin-top: 10px; }

  .result-card { margin-top: 14px; }
  .analysis-card { margin-top: 14px; }

  .primary-button, .secondary-button, .ghost-button, .table-action {
    min-height: 38px;
    font-size: 0.8rem;
    flex: 1;
  }

  .purchase-balance-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }

  .debug-grid {
    grid-template-columns: 1fr;
    margin-top: 12px;
    gap: 12px;
  }

  .code-view {
    min-height: 220px;
    max-height: 360px;
    padding: 12px;
    font-size: 0.72rem;
  }

  .bullet-list { font-size: 0.76rem; line-height: 1.6; }

  .endpoint-card { padding: 10px; font-size: 0.76rem; }
  .endpoint-card__method { font-size: 0.64rem; padding: 3px 7px; }
}
