:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --code-bg: #0f172a;
  --code-fg: #e2e8f0;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 30px -10px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  letter-spacing: -0.02em;
  color: var(--text);
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.89rem;
}

.small-note {
  font-size: 0.83rem;
  margin: 6px 0;
}

/* === AUTH & CHECKOUT CENTERING === */
.auth-shell,
.checkout-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card,
.checkout-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: var(--shadow-md);
}

.checkout-card {
  text-align: center;
}

.brand-logo-box {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.18);
}

.auth-card h1 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 1.38rem;
}

.auth-sub {
  text-align: center;
  margin-top: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-sm {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  display: block;
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.15;
  color: var(--text);
}

.brand-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.brand-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 10px;
}

.tab-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 18px 0 16px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* === FORMS & INPUTS === */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stack-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-soft);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="email"],
select,
textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  cursor: pointer;
}

.checkbox-row input {
  width: auto;
  accent-color: var(--primary);
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

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

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-soft);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fee2e2;
}

.error-text {
  color: var(--danger);
  font-size: 0.86rem;
  margin: 10px 0 0;
}

.auth-meta {
  margin-top: 14px;
  font-size: 0.78rem;
  text-align: center;
}

/* === APP SHELL & SIDEBAR === */
.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-user-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  display: flex;
  gap: 8px;
}

.sidebar-footer .btn {
  flex: 1;
}

.sidebar-nav-scroll {
  display: flex;
  flex-direction: column;
}

.nav-group-label {
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 12px 8px 6px;
}

.nav-group-label:first-child {
  margin-top: 2px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-soft);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s;
}

.nav-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* === MAIN CONTENT & CARDS === */
.main-content {
  padding: 26px 30px;
  max-width: 1120px;
  width: 100%;
  min-width: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.section-head h2 {
  margin: 0 0 3px;
  font-size: 1.32rem;
}

.section-head p {
  margin: 0;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.pill-ok {
  color: #065f46;
  background: #d1fae5;
}

.pill-warn {
  color: #92400e;
  background: #fef3c7;
}

.pill-bad {
  color: #991b1b;
  background: #fee2e2;
}

.method-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-right: 6px;
  vertical-align: middle;
}

.method-get {
  background: #e0f2fe;
  color: #0369a1;
}

.method-post {
  background: #fef3c7;
  color: #b45309;
}

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

.kpi-card,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.card + .card {
  margin-top: 16px;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
}

.kpi-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 0.76rem;
  color: var(--muted);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.two-col .card + .card {
  margin-top: 0;
}

.two-col-tight {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-kv {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-kv > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  font-size: 0.89rem;
}

.summary-kv > div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.provider-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.prov-card-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color 0.15s, background 0.15s;
}

.prov-card-btn:hover {
  border-color: var(--border-strong);
}

.prov-card-btn span {
  font-size: 0.79rem;
  color: var(--muted);
}

.prov-card-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* === WEBHOOKS & CODE BLOCKS === */
.webhook-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.webhook-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.webhook-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.webhook-item-sig {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.copy-row .code-line {
  flex: 1;
  margin-bottom: 0;
}

.code-line {
  display: block;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.82rem;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 7px;
  margin-bottom: 8px;
  color: var(--text);
}

.code-pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.55;
  margin: 10px 0 0;
}

/* === QR PREVIEW & CHECKOUT === */
.qr-preview-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.qr-preview-box img,
.checkout-qr-img {
  width: 232px;
  height: 232px;
  background: #fff;
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 14px;
  margin: 6px auto;
  box-shadow: var(--shadow-sm);
}

.qr-meta,
.checkout-meta-box {
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checkout-meta-box > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.checkout-amount {
  font-size: 2.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  margin: 6px 0 8px;
  color: var(--text);
}

.status-banner {
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  margin: 12px 0;
}

.status-banner.paid {
  background: #d1fae5;
  color: #065f46;
}

.status-banner.expired {
  background: #fee2e2;
  color: #991b1b;
}

.empty-box,
.info-box,
.pairing-box {
  padding: 12px 14px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  font-size: 0.86rem;
  margin-bottom: 12px;
  color: var(--text-soft);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.inline-form input {
  flex: 1;
  min-width: 160px;
}

/* === TABLES === */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #fafbfd;
}

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

.checkout-card .row-actions {
  justify-content: center;
  margin-bottom: 10px;
}

/* === TOAST === */
.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--code-bg);
  color: #fff;
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
}

.toast.ok {
  border-left: 4px solid var(--success);
}

.toast.err {
  border-left: 4px solid var(--danger);
}

/* === MOBILE & TABLET RESPONSIVE === */
@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: auto;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px 10px;
    gap: 10px;
  }

  .sidebar-brand-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .brand-sub {
    display: none;
  }

  .sidebar-user-actions {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }

  .user-chip {
    max-width: 140px;
    padding: 5px 8px;
    font-size: 0.76rem;
  }

  .sidebar-footer {
    gap: 6px;
  }

  .sidebar-footer .btn {
    flex: initial;
    padding: 5px 9px;
    font-size: 0.76rem;
  }

  .sidebar-nav-scroll {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .sidebar-nav-scroll::-webkit-scrollbar {
    display: none;
  }

  .nav-group-label {
    display: none;
  }

  .nav-list {
    display: contents;
  }

  .nav-btn {
    padding: 6px 12px;
    font-size: 0.82rem;
    border: 1px solid var(--border);
    background: var(--surface);
  }

  .nav-btn.active {
    border-color: rgba(79, 70, 229, 0.25);
  }

  .main-content {
    padding: 18px 16px 28px;
  }

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

  .two-col,
  .two-col-tight,
  .provider-tabs {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .user-chip {
    display: none;
  }

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

  .kpi-value {
    font-size: 1.12rem;
  }
}
