/* Beezifi Payments — main stylesheet (tokens follow Persona's palette) */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1; --primary-dark: #4f46e5; --primary-soft: #eef2ff;
  --sidebar-bg: #0f0f23; --sidebar-hover: #1a1a3e; --sidebar-active: #252550; --sidebar-text: #a5a8c8;
  --bg: #f1f5f9; --surface: #ffffff; --surface-2: #f8fafc; --border: #e2e8f0;
  --text: #0f172a; --text-muted: #64748b; --text-light: #94a3b8;
  --success: #10b981; --success-soft: #ecfdf5; --warning: #f59e0b; --warning-soft: #fffbeb;
  --danger: #ef4444; --danger-soft: #fef2f2;
  --radius: 8px; --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary-soft: #1e1b4b; --bg: #0b0d17; --surface: #141726; --surface-2: #1a1e30; --border: #262b42;
    --text: #e5e7f0; --text-muted: #9aa1b8; --text-light: #6b7290;
    --success-soft: #052e22; --warning-soft: #2e2205; --danger-soft: #2e0b0b;
    --shadow: 0 1px 3px rgba(0,0,0,.4); --shadow-lg: 0 10px 25px rgba(0,0,0,.5);
  }
}

html, body { min-height: 100%; font-family: 'Inter', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── Forms & buttons ── */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.18); }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; font: inherit; font-weight: 600; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.w-full { width: 100%; }

.alert { padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-error   { background: var(--danger-soft);  color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-warning { background: var(--warning-soft); color: #b45309; }
.alert-info    { background: var(--primary-soft); color: var(--primary); }

/* ── Auth page ── */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.brand-icon { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: grid; place-items: center; color: #fff; font-weight: 800; }
.brand-text { font-size: 18px; font-weight: 800; }
.auth-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 20px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-muted); }
.code-input { text-align: center; font-size: 22px; letter-spacing: 8px; font-family: ui-monospace, Menlo, monospace; }
.qr-box { text-align: center; margin: 8px 0 14px; }
.qr-box img { width: 180px; height: 180px; background: #fff; padding: 8px; border-radius: var(--radius); }
.secret { word-break: break-all; font-size: 12px; background: var(--surface-2); padding: 8px; border-radius: 6px; margin-top: 6px; }

/* ── App shell ── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 16px 10px; }
.sidebar .brand { padding: 4px 8px; margin-bottom: 20px; }
.sidebar .brand-text { color: #fff; font-size: 15px; white-space: nowrap; }
.tenant-name { font-size: 11px; color: var(--sidebar-text); font-weight: 500; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; margin-bottom: 2px;
  background: none; border: none; color: var(--sidebar-text); font: inherit; font-weight: 500;
  border-radius: var(--radius); cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid #23234a; font-size: 12px; }
.sidebar-foot .who { color: #fff; font-weight: 600; font-size: 13px; }
.sidebar-foot .btn { margin-top: 10px; color: var(--sidebar-text); border-color: #2c2c55; }
.sidebar-foot .btn:hover { background: var(--sidebar-hover); }

.main { flex: 1; min-width: 0; padding: 28px 32px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.charge-grid { display: grid; grid-template-columns: minmax(0, 460px) minmax(0, 1fr); gap: 20px; align-items: start; }
.amount-wrap { position: relative; }
.amount-wrap span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-weight: 600; }
.amount-wrap .form-control { padding-left: 26px; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card-field { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card-field.focused { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.18); }
.secure-note { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-top: 12px; justify-content: center; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
th.num { text-align: right; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty { text-align: center; color: var(--text-muted); padding: 28px 10px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: capitalize; background: var(--surface-2); color: var(--text-muted); }
.badge-succeeded, .badge-on { background: var(--success-soft); color: var(--success); }
.badge-failed, .badge-canceled, .badge-off { background: var(--danger-soft); color: var(--danger); }
.badge-pending, .badge-processing, .badge-warn { background: var(--warning-soft); color: #b45309; }
.badge-refunded, .badge-partially_refunded { background: var(--primary-soft); color: var(--primary); }
.badge-owner { background: var(--primary-soft); color: var(--primary); }
.badge-sandbox { background: #ede9fe; color: #6d28d9; }

/* ── Modal & toast ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,15,35,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 440px; padding: 24px; max-height: 90vh; overflow-y: auto; }
.modal h3 { font-size: 17px; margin-bottom: 6px; }
.modal p { color: var(--text-muted); margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 16px; border-radius: var(--radius); background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); z-index: 60; max-width: calc(100vw - 40px); }
.toast.error { background: var(--danger); color: #fff; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: none; }

/* ── Customers / saved cards ── */
.back-link { display: inline-block; font-size: 13px; margin-bottom: 4px; }
.saved-card { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.saved-card:last-child { border-bottom: none; }
.card-chip { width: 44px; height: 30px; border-radius: 5px; background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; text-transform: uppercase; flex-shrink: 0; }
.saved-card .info { flex: 1; min-width: 140px; }
.saved-card .info strong { text-transform: capitalize; }
.card-option { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; }
.card-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-muted); margin: 12px 0 4px; cursor: pointer; }
.check-row input { margin-top: 2px; flex-shrink: 0; }

/* ── Developers page ── */
.dev-facts { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin-bottom: 20px; }
.dev-copy { display: flex; align-items: center; gap: 8px; margin-top: 6px; min-width: 0; }
.dev-copy code { font: 600 14px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; white-space: nowrap; flex: 1; min-width: 0; }
.dev-ver { font-size: 20px; }
.dev-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.dev-grid > .card { margin-bottom: 20px; }
.code-block { margin-top: 12px; border-radius: var(--radius); overflow: hidden; border: 1px solid #23284a; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; background: #171a33; color: #9aa1c7; font-size: 12px; font-weight: 500; }
.code-copy { background: none; border: 1px solid #2c3260; color: #9aa1c7; font: 500 11px Inter, system-ui, sans-serif; padding: 2px 9px; border-radius: 6px; cursor: pointer; }
.code-copy:hover { color: #fff; border-color: #9aa1c7; }
.code-block pre { margin: 0; padding: 12px 14px; background: #0f1226; color: #e2e6f8; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; white-space: pre; }
.code-block pre#devInstall { white-space: pre-wrap; word-break: break-all; } /* one-liner people must read in full */

/* ── Admin console ── */
.admin-badge { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #92400e; background: #fde68a; padding: 2px 7px; border-radius: 999px; vertical-align: middle; }
.brand .admin-badge { margin-left: 6px; }
.admin-icon { background: linear-gradient(135deg, #f59e0b, #d97706) !important; }
.admin-sidebar .nav-item.active { box-shadow: inset 3px 0 0 #f59e0b; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.filters .form-control { max-width: 320px; }
.filters select.form-control { max-width: 200px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs .tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; font-weight: 600; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.tabs .tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; font-size: 13px; margin: 8px 0; }
.kv > span:nth-child(odd) { color: var(--text-muted); }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { background: #dc2626; }
.modal.modal-wide { max-width: 560px; }
textarea.form-control { resize: vertical; }

/* ── "Lost your authenticator?" help ── */
.lost-totp { margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.lost-totp summary { cursor: pointer; color: var(--primary); font-weight: 500; text-align: center; list-style: none; }
.lost-totp summary::-webkit-details-marker { display: none; }
.lost-totp[open] summary { margin-bottom: 8px; }
.lost-totp p { margin-top: 6px; line-height: 1.5; }

/* ── Responsive ── */
@media (max-width: 900px) { .charge-grid, .dev-grid, .dev-facts { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 8px 10px; overflow-x: auto; gap: 4px; }
  .sidebar .brand { margin: 0 8px 0 0; }
  .sidebar .brand-text, .tenant-name { display: none; }
  .nav-item { width: auto; white-space: nowrap; margin: 0; }
  .nav-item span { display: none; }
  .sidebar nav { display: flex; gap: 2px; }
  .sidebar-foot { margin: 0 0 0 auto; border: none; padding: 0; display: flex; gap: 4px; }
  .sidebar-foot .btn.w-full { width: auto; white-space: nowrap; }
  .sidebar-foot .who, .sidebar-foot .role { display: none; }
  .sidebar-foot .btn { margin: 0; }
  .main { padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px; }
}

/* Sandbox panel: long test keys wrap on small screens */
.sandbox-card code { word-break: break-all; white-space: normal; }

/* Server-side pager under long lists */
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pager:empty { display: none; }
.pager-info { color: var(--text-muted); font-size: 13px; margin-right: 4px; }

/* Charge page: Live / Test switch */
.mode-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; background: var(--surface, #fff); gap: 2px; }
.mode-btn { border: 0; background: none; font: inherit; font-weight: 600; font-size: 13px; padding: 6px 16px; border-radius: 999px; color: var(--text-muted); cursor: pointer; }
.mode-btn:disabled { opacity: .45; cursor: not-allowed; }
.mode-btn.active[data-mode="live"] { background: var(--success-soft); color: var(--success); }
.mode-btn.active[data-mode="test"] { background: var(--warning-soft); color: #b45309; }
.alert-live { background: var(--success-soft); color: var(--success); }
.btn.btn-primary.btn-test { background: #b45309; border-color: #b45309; }
.btn.btn-primary.btn-test:hover { background: #92400e; border-color: #92400e; }

/* Sales chart (Payments page, owner/admin) */
.sales-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.sales-range { margin: 0; border: 0; }
.sales-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 4px 0 6px; }
.sales-total { font-size: 20px; font-weight: 700; color: var(--text); }
.sales-chart { min-height: 280px; }
@media (max-width: 640px) { .sales-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .sales-head { flex-direction: column; align-items: stretch; }
  .sales-range { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; }
  .sales-range .tab { padding: 8px 2px; font-size: 12px; text-align: center; white-space: nowrap; }
}

/* Payments list: search + status filter */
.pay-toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.pay-toolbar input[type="search"] { flex: 1 1 260px; max-width: 420px; }
.pay-toolbar select { flex: 0 0 auto; width: auto; min-width: 150px; }
@media (max-width: 640px) { .pay-toolbar input[type="search"], .pay-toolbar select { flex: 1 1 100%; max-width: none; } }

.text-danger { color: var(--danger); font-weight: 600; }

/* Sidebar count badge (e.g. chargebacks needing a response) */
.nav-count { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; line-height: 16px; }

/* Clickable badge (e.g. a payment's chargeback → Chargebacks page) */
.badge-link { text-decoration: none; }
.badge-link:hover .badge { outline: 2px solid currentColor; outline-offset: 1px; }

/* Payouts */
.payout-kv { grid-template-columns: 1fr auto; max-width: 420px; }
.payout-kv .num { text-align: right; font-variant-numeric: tabular-nums; }
.payout-kv .payout-amount { font-size: 15px; }
.payout-preview { margin: 6px 0 4px; background: var(--surface-2, #f8fafc); box-shadow: none; }
.amount-wrap.pct span { left: auto; right: 12px; }
.amount-wrap.pct input { padding-left: 12px; padding-right: 28px; }
.modal.modal-xl { max-width: 880px; }

/* Sign-in page footer: copyright + version */
.auth-footer { margin-top: 20px; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: 12px; color: var(--text-light); text-align: center; }
.auth-version { font-variant-numeric: tabular-nums; }

/* Beezifi logo (yellow hexagon) */
.brand-logo { width: 36px; height: 36px; flex: 0 0 auto; display: block; object-fit: contain; }
