* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #e31937;
  --red-dark: #c41230;
  --bg: #14090c;
  --card: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f5f5f5;
  --muted: #9a9a9a;
  --green: #5dd879;
  --yellow: #ffc107;
  --pink: #ff6b7a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  background: linear-gradient(145deg, #1a0a0d 0%, #2d1218 45%, #161628 100%);
  color: var(--text);
}

a { color: var(--red); text-decoration: none; }

/* Layout */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}
.topbar .brand { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.logo {
  width: 40px; height: 40px; border-radius: 10px; background: var(--red);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; box-shadow: 0 6px 18px rgba(227,25,55,.35);
}
.topbar .right { display: flex; align-items: center; gap: 14px; font-size: .9rem; color: var(--muted); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; }
.center-wrap { max-width: 420px; margin: 0 auto; padding: 48px 16px; }

/* Sidebar layout */
.admin-layout { display: flex; align-items: flex-start; }
.sidebar {
  width: 236px; flex: 0 0 236px; position: sticky; top: 69px;
  height: calc(100vh - 69px); padding: 20px 14px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.nav-menu { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: .9rem; cursor: pointer;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item .nav-ico { width: 20px; text-align: center; font-size: 1rem; }
.nav-item .nav-label { flex: 1; }
.nav-item:hover { background: rgba(255,255,255,.06); color: var(--text); }
.nav-item:focus-visible {
  outline: 2px solid rgba(255,255,255,.65); outline-offset: 2px;
}
.nav-item.active {
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  color: #fff; box-shadow: 0 6px 16px rgba(227,25,55,.3);
}
.nav-badge {
  min-width: 22px; padding: 2px 7px; border-radius: 999px;
  background: rgba(255,255,255,.12); color: var(--text);
  font-size: .72rem; font-weight: 700; text-align: center; line-height: 1.4;
}
.nav-item.active .nav-badge { background: rgba(255,255,255,.28); color: #fff; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }

.content { flex: 1; min-width: 0; padding: 26px 28px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-head h1 { font-size: 1.5rem; }
.page-head .sub { color: var(--muted); font-size: .88rem; margin-top: 3px; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.setting-row:last-child { border-bottom: none; }
.setting-row .k { color: var(--muted); }

@media (max-width: 820px) {
  .admin-layout { flex-direction: column; }
  .sidebar {
    position: static; width: 100%; flex: none; height: auto;
    flex-direction: row; overflow-x: auto; gap: 6px;
    border-right: none; border-bottom: 1px solid var(--border); padding: 12px;
  }
  .nav-menu { flex-direction: row; width: 100%; gap: 6px; }
  .nav-item { width: auto; white-space: nowrap; }
  .sidebar-foot { display: none; }
  .content { padding: 18px 14px 50px; }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  backdrop-filter: blur(12px);
  margin-bottom: 16px;
}
.card h2 { font-size: 1.05rem; margin-bottom: 16px; }
.card h3 { font-size: .95rem; margin-bottom: 12px; color: #ddd; }

/* Stat grid */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 18px;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.stat:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.2); box-shadow: 0 10px 26px rgba(0,0,0,.25); }
.stat .stat-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.stat .icon {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1rem;
  background: rgba(255,255,255,.06); border: 1px solid var(--border);
}
.stat .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 1.85rem; font-weight: 800; line-height: 1.1; }
.stat .value.money { font-size: 1.25rem; word-break: break-word; }
.stat .value.green { color: var(--green); }
.stat .value.yellow { color: var(--yellow); }
.stat.accent { background: linear-gradient(135deg, rgba(227,25,55,.16), rgba(227,25,55,.04)); border-color: rgba(227,25,55,.35); }
.stat.accent .icon { background: rgba(227,25,55,.22); border-color: rgba(227,25,55,.4); }

/* Forms */
label { display: block; font-size: .78rem; color: var(--muted); margin: 12px 0 6px; }
label:first-of-type { margin-top: 0; }
input, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 10px; background: rgba(0,0,0,.25); color: #fff; font-size: 1rem;
}
input:focus, select:focus { outline: none; border-color: var(--red); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-amount { display: grid; grid-template-columns: 1fr 110px; gap: 12px; }

.btn {
  width: 100%; padding: 13px; margin-top: 18px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--red), var(--red-dark)); color: #fff;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(227,25,55,.4); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn.secondary { background: transparent; border: 1px solid var(--border); }
.btn.secondary:hover { background: rgba(255,255,255,.05); box-shadow: none; }
.btn.small { width: auto; padding: 8px 14px; margin: 0; font-size: .82rem; border-radius: 8px; }
.btn.danger { background: linear-gradient(135deg, #dc3545, #a71d2a); }
.btn.ghost { background: transparent; border: 1px solid var(--border); width: auto; padding: 8px 14px; margin: 0; font-size: .82rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; word-break: break-all; }
.table-scroll { overflow-x: auto; }

/* Rich data table */
.data-table td { padding: 14px 12px; vertical-align: middle; }
.data-table tbody tr { transition: background .12s ease; }
.data-table tbody tr:hover { background: rgba(255,255,255,.04); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table th.right, .data-table td.right { text-align: right; }

.cell-merchant { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 11px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff; text-transform: uppercase;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  box-shadow: 0 4px 12px rgba(227,25,55,.3);
}
.avatar.muted { background: linear-gradient(135deg, #555, #333); box-shadow: none; }
.cell-merchant .m-name { font-weight: 600; }
.cell-merchant .m-sub { font-size: .74rem; color: var(--muted); margin-top: 2px; }

.pill {
  display: inline-block; padding: 4px 10px; border-radius: 8px;
  background: rgba(255,255,255,.06); border: 1px solid var(--border); font-size: .78rem;
}
.pill.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.balance-pill { font-size: .82rem; color: var(--text); }
.balance-pill--clickable { cursor: pointer; transition: border-color .15s, background .15s; }
.balance-pill--clickable:hover { border-color: var(--green); background: rgba(76,175,80,.08); }
.balance-pill[aria-disabled="true"] { cursor: default; opacity: .85; }
.pill.zero { color: var(--muted); }
.pill.default-pill { color: var(--yellow); border-color: rgba(255,193,7,.35); background: rgba(255,193,7,.10); }
.pill.green { color: var(--green); border-color: rgba(76,175,80,.35); background: rgba(76,175,80,.10); }
.pill.yellow { color: var(--yellow); border-color: rgba(255,193,7,.35); background: rgba(255,193,7,.10); }

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

.merchant-recaptcha-wrap { margin: 12px 0 16px; }
.merchant-recaptcha-wrap.hidden { display: none; }

.count-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 24px; padding: 0 9px; border-radius: 999px;
  background: rgba(255,255,255,.08); border: 1px solid var(--border);
  font-size: .8rem; font-weight: 700; color: var(--text);
}

.search { position: relative; }
.search input { width: 240px; max-width: 60vw; padding-left: 36px; }
.search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .9rem; pointer-events: none; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-state .big { font-size: 2.4rem; margin-bottom: 10px; opacity: .8; }
.empty-state .btn { width: auto; display: inline-block; margin-top: 16px; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.badge.active, .badge.paid, .badge.success, .badge.completed { background: rgba(93,216,121,.15); color: var(--green); }
.badge.pending { background: rgba(255,193,7,.15); color: var(--yellow); }
.badge.suspended, .badge.failed, .badge.expired, .badge.rejected, .badge.cancelled { background: rgba(255,107,122,.15); color: var(--pink); }
.badge.approved { background: rgba(96,165,250,.16); color: #7cb3ff; }

.qr-upload-preview { margin-top: 10px; }
.qr-upload-preview img { max-width: 180px; max-height: 180px; border-radius: 10px; border: 1px solid var(--border); display: block; }
.qr-thumb {
  width: 44px; height: 44px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); cursor: pointer; vertical-align: middle;
}
.qr-thumb:hover { opacity: .85; }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h1 { font-size: 1.4rem; }

/* Messages */
.msg { padding: 12px 14px; border-radius: 10px; margin-top: 12px; font-size: .875rem; display: none; }
.msg.visible { display: block; }
.msg.error { background: rgba(255,107,122,.12); border: 1px solid rgba(255,107,122,.3); color: var(--pink); }
.msg.ok { background: rgba(93,216,121,.12); border: 1px solid rgba(93,216,121,.3); color: var(--green); }
.msg.info { background: rgba(255,193,7,.1); border: 1px solid rgba(255,193,7,.3); color: var(--yellow); }

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Settings sub-tabs */
.settings-tabs {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px;
  border-bottom: 1px solid var(--border); padding-bottom: 2px;
}
.settings-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: .9rem; font-weight: 600; border-radius: 9px 9px 0 0;
  border-bottom: 2px solid transparent; margin-bottom: -3px; transition: color .15s, border-color .15s, background .15s;
}
.settings-tab:hover { color: var(--text); background: rgba(255,255,255,.04); }
.settings-tab.active { color: var(--text); border-bottom-color: var(--red, #e31937); }
.settings-tab .ico { font-size: 1rem; }
.settings-panel { display: none; }
.settings-panel.active { display: block; animation: fade-in .18s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.settings-section-desc { color: var(--muted); font-size: .85rem; margin: 0 0 16px; max-width: 640px; }

/* Boot splash — avoids the login screen flashing before auth is known */
.app-splash {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg, #0e0f13); z-index: 9999;
}
.app-splash .spinner { width: 28px; height: 28px; border-width: 3px; margin: 0; }
.app-splash.hidden { display: none !important; }

/* Modal */
.modal { display: none; position: fixed; inset: 0; z-index: 1000; align-items: center; justify-content: center; padding: 16px; }
.modal.visible { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(4px); }
.modal-box {
  position: relative; background: #1e1420; border: 1px solid var(--border); border-radius: 18px;
  padding: 26px; max-width: 440px; width: 100%; max-height: 90vh; overflow-y: auto;
  animation: modalIn .25s ease; box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.modal-box.narrow { max-width: 360px; text-align: center; }
.modal-box.wide { max-width: 760px; }
.modal-box.xl { max-width: 1100px; }

/* Code block */
.code-block {
  background: #0d0d12; border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; font-size: .8rem; line-height: 1.55; color: #d8d8e0;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto; margin: 6px 0 10px;
}
td.path-copy { cursor: pointer; }
td.path-copy:hover .mono { text-decoration: underline; }

/* Endpoint accordion */
.endpoint-list { display: flex; flex-direction: column; gap: 8px; }
.endpoint-item { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: rgba(255,255,255,.02); }
.endpoint-summary {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: none; border: none; cursor: pointer; text-align: left; color: var(--text);
}
.endpoint-summary:hover { background: rgba(255,255,255,.04); }
.endpoint-path { font-size: .82rem; }
.endpoint-purpose { flex: 1; font-size: .78rem; }
.endpoint-caret { transition: transform .18s ease; opacity: .7; }
.endpoint-item.open .endpoint-caret { transform: rotate(180deg); }
.endpoint-detail { display: none; padding: 0 14px 12px; }
.endpoint-item.open .endpoint-detail { display: block; }
.endpoint-block-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 4px; }
.endpoint-block-head .lbl { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.btn.tiny { padding: 3px 10px; font-size: .72rem; width: auto; }
@media (max-width: 560px) { .endpoint-purpose { display: none; } }
@keyframes modalIn { from { opacity: 0; transform: scale(.94) translateY(10px); } to { opacity: 1; transform: none; } }
.modal-box h3 { font-size: 1.2rem; margin-bottom: 14px; }
.modal-icon { width: 60px; height: 60px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 1.8rem; margin-bottom: 12px; background: rgba(93,216,121,.2); color: var(--green); border: 2px solid rgba(93,216,121,.4); }

/* QR */
.qr-frame { background: #fff; border-radius: 16px; padding: 18px; display: inline-block; margin: 0 auto 14px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.qr-frame img { display: block; width: 240px; height: 240px; }
.amount-big { font-size: 2.1rem; font-weight: 800; color: var(--red); margin: 6px 0 16px; }
.expiry { display: none; flex-direction: column; align-items: center; gap: 3px; margin: 0 auto 14px; padding: 10px 20px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.expiry.warning { background: rgba(255,193,7,.1); border-color: rgba(255,193,7,.35); }
.expiry.expired { background: rgba(255,107,122,.1); border-color: rgba(255,107,122,.35); }
.expiry .lbl { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.expiry .cd { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.expiry.warning .cd { color: var(--yellow); }
.expiry.expired .cd, .expiry.expired .lbl { color: var(--pink); }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: 8px; }
.loading-inline { display: inline-flex; align-items: center; gap: 8px; }
.loading-cell .spinner { margin-right: 0; }
.stat-loading .loading-pulse {
  display: block; height: 12px; width: 72px; border-radius: 6px;
  background: linear-gradient(90deg, rgba(255,255,255,.06) 25%, rgba(255,255,255,.12) 50%, rgba(255,255,255,.06) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite;
}
.stat-loading .loading-pulse.wide { height: 28px; width: 96px; margin-top: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

.header-center { text-align: center; margin-bottom: 24px; }
.header-center .logo { width: 56px; height: 56px; font-size: 1.4rem; border-radius: 14px; margin-bottom: 12px; }
.header-center h1 { font-size: 1.4rem; }
.header-center p { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* SweetAlert2 dark theme */
.swal2-popup { border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.5); }
.swal2-title { color: var(--text) !important; font-size: 1.25rem; }
.swal2-html-container { color: var(--muted) !important; }
.swal2-styled { border-radius: 11px !important; font-weight: 600; box-shadow: none !important; }
.swal2-styled.swal2-confirm { padding: 10px 22px; }
.swal2-styled.swal2-cancel { color: var(--text) !important; }
.swal2-styled:focus { box-shadow: none !important; }
.swal2-input, .swal2-textarea, .swal2-select {
  background: rgba(255,255,255,.08); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: none;
}
.swal2-input:focus, .swal2-textarea:focus { border-color: var(--red); box-shadow: none; }
.swal2-validation-message { background: rgba(227,25,55,.12); color: var(--pink); }
.swal2-toast { border: 1px solid var(--border); box-shadow: 0 12px 30px rgba(0,0,0,.4) !important; }
.swal2-toast .swal2-title { font-size: .92rem; }
.swal2-timer-progress-bar { background: var(--red); }
