:root {
  --ink: #101a2c;
  --ink-2: #1b2940;
  --ink-3: #2a3a55;
  --gold: #f2b33d;
  --gold-soft: #fff4dc;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --line: #e3e6ec;
  --text: #172033;
  --muted: #667085;
  --green: #12805c;
  --green-soft: #e3f5ee;
  --red: #c0362c;
  --red-soft: #fdecea;
  --blue: #2556c4;
  --blue-soft: #e8eefc;
  --amber: #9a6200;
  --amber-soft: #fff3d6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 26, 44, .06), 0 4px 16px rgba(16, 26, 44, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: "Cascadia Mono", Consolas, ui-monospace, monospace; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.boot { padding: 40px; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-hero {
  background: radial-gradient(circle at 20% 10%, #253a5e 0, transparent 55%), var(--ink);
  color: #e8ecf3; padding: 56px 64px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
}
.auth-hero h1 { font-size: 2.4rem; color: #fff; max-width: 14ch; margin-top: 56px; }
.auth-hero h1 em { font-style: normal; color: var(--gold); }
.auth-hero p { color: #b9c3d4; max-width: 44ch; font-size: 1.05rem; }
.steps { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 14px; }
.steps li { display: flex; gap: 14px; align-items: flex-start; color: #d5dce8; }
.steps b { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--ink-3); color: var(--gold); display: grid; place-items: center; font-size: .85rem; }
.sample-code { display: inline-block; margin-top: 8px; padding: 6px 12px; border: 1px dashed #4b5d7c; border-radius: 8px; color: var(--gold); letter-spacing: .08em; }
.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 430px; }
.auth-card h2 { font-size: 1.5rem; margin-bottom: 4px; }
.auth-card form { margin-top: 24px; }
.auth-switch { margin-top: 20px; text-align: center; color: var(--muted); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .01em; }
.brand-logo { height: 44px; width: auto; display: block; flex: none; }
.auth-hero .brand-logo { height: 72px; }
.auth-hero .brand { gap: 14px; font-size: 1.45rem; line-height: 1.2; }
.auth-hero .brand small { font-size: 1.05rem; color: #b9c3d4; margin-top: 2px; }
.sidebar .brand-logo { height: 52px; }
.brand small { display: block; font-weight: 400; color: #8e9ab0; font-size: .75rem; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .85rem; font-weight: 600; color: #344054; }
.field .hint { font-size: .8rem; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%; padding: 9px 12px; border: 1px solid #cfd5df; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(242, 179, 61, .35); border-color: #d99a22; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; margin: 6px 0 18px; }
.check input { width: auto; margin-top: 4px; }

.btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn:hover { background: var(--ink-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: #e6a52c; }
.btn-ghost { background: #fff; color: var(--text); border-color: #cfd5df; }
.btn-ghost:hover { background: #f1f3f6; }
.btn-danger { background: #fff; color: var(--red); border-color: #f0c4bf; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.form-error { background: var(--red-soft); color: var(--red); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: .9rem; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--ink); color: #cdd5e2; padding: 22px 14px; display: flex; flex-direction: column; gap: 26px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { color: #fff; padding: 0 8px; }
.nav { display: grid; gap: 2px; }
.nav a { color: #b9c3d4; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--ink-3); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: #6f7d95; padding: 0 12px 6px; }
.sidebar-user { margin-top: auto; border-top: 1px solid var(--ink-3); padding: 16px 8px 0; font-size: .85rem; }
.sidebar-user .name { color: #fff; font-weight: 600; }
.sidebar-user button { margin-top: 10px; background: transparent; color: #b9c3d4; border: 1px solid var(--ink-3); }
.sidebar-user button:hover { background: var(--ink-2); color: #fff; }

.main { padding: 32px 40px 64px; max-width: 1240px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.stack { display: grid; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }

.banner { border-radius: 10px; padding: 12px 16px; font-size: .92rem; }
.banner-warn { background: var(--amber-soft); color: var(--amber); }
.banner-info { background: var(--blue-soft); color: var(--blue); }

/* ---------- code card ---------- */
.code-card {
  background: linear-gradient(120deg, var(--ink) 0%, #1f3050 100%); color: #d5dce8; border-radius: var(--radius);
  padding: 24px 28px; display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap;
}
.code-card .label { font-size: .8rem; text-transform: uppercase; letter-spacing: .12em; color: #8e9ab0; }
.code-card .code { font-size: 2.3rem; font-weight: 750; color: var(--gold); letter-spacing: .08em; line-height: 1.2; margin: 4px 0; }
.code-card p { margin: 0; color: #aab5c8; font-size: .9rem; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { padding: 16px 18px; }
.stat .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.highlight { background: var(--gold-soft); border-color: #f3dca8; }
.stats-inline .stat { padding: 10px 0 14px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 10px 16px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 16px; border-bottom: 1px solid #eef0f4; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.sub { display: block; color: var(--muted); font-size: .8rem; }
th.num { text-align: right; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; text-transform: capitalize; }
.b-earned, .b-paid, .b-active { background: var(--green-soft); color: var(--green); }
.b-reversed, .b-rejected, .b-suspended, .b-disabled { background: var(--red-soft); color: var(--red); }
.b-pending { background: var(--amber-soft); color: var(--amber); }
.b-approved { background: var(--blue-soft); color: var(--blue); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 150px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { font: inherit; font-size: .88rem; border: 1px solid transparent; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.active { background: var(--ink); color: #fff; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); gap: 12px; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.rules { margin: 0; padding-left: 18px; color: var(--muted); font-size: .88rem; display: grid; gap: 4px; }

/* ---------- modal & toasts ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 26, 44, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 480px; padding: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal h2 { margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.secret { background: var(--ink); color: var(--gold); padding: 12px; border-radius: 8px; word-break: break-all; margin: 12px 0; }

.toasts { position: fixed; left: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 90; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; font-size: .9rem; }
.toast.error { background: var(--red); }

.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- public pages (FAQ for visitors) ---------- */
.public-page { min-height: 100vh; }
.public-head { background: var(--ink); color: #fff; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 24px; flex-wrap: wrap; }
.public-head .brand { color: #fff; text-decoration: none; }
.public-head nav { display: flex; gap: 8px; }
.public-main { margin: 0 auto; max-width: 900px; }

/* ---------- FAQ ---------- */
.faq-search input { padding: 12px 14px; font-size: 1rem; border-radius: 10px; box-shadow: var(--shadow); }
.faq-cat h2 { margin: 6px 0 10px; }
.faq-group { overflow: hidden; }
.faq-item { border-bottom: 1px solid #eef0f4; }
.faq-item:last-child { border-bottom: 0; }
.faq-item summary { cursor: pointer; list-style: none; padding: 14px 44px 14px 20px; font-weight: 600; position: relative; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; position: absolute; right: 20px; top: 12px; font-size: 1.2rem; color: var(--muted); font-weight: 400; }
.faq-item[open] summary::after { content: "−"; }
.faq-item summary:hover { background: #fafbfc; }
.faq-item summary:focus-visible { outline: 3px solid rgba(242, 179, 61, .45); outline-offset: -3px; }
.faq-a { padding: 0 20px 16px; color: #344054; }
.faq-a p, .help-msg p, .tour-body p { margin: 0 0 8px; }
.faq-a p:last-child, .help-msg p:last-child, .tour-body p:last-child { margin-bottom: 0; }
.faq-a ul, .faq-a ol, .help-msg ul, .help-msg ol { margin: 4px 0 8px; padding-left: 20px; }
code { font-family: "Cascadia Mono", Consolas, ui-monospace, monospace; background: #f1f3f6; padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---------- help assistant ---------- */
.help-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 60; display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 650; background: var(--ink); color: #fff; border: 0; border-radius: 999px;
  padding: 10px 18px 10px 10px; cursor: pointer; box-shadow: 0 8px 24px rgba(16, 26, 44, .28);
}
.help-fab:hover { background: var(--ink-2); }
.help-fab-icon { width: 26px; height: 26px; border-radius: 50%; background: var(--gold); color: var(--ink); display: grid; place-items: center; font-weight: 800; }
.help-panel {
  position: fixed; right: 20px; bottom: 76px; z-index: 61; width: 380px; max-width: calc(100vw - 32px); height: min(600px, calc(100vh - 110px));
  background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 60px rgba(16, 26, 44, .25);
  display: flex; flex-direction: column; overflow: hidden;
}
.help-head { background: var(--ink); color: #fff; padding: 14px 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.help-head .sub { color: #aab5c8; }
.icon-btn { background: transparent; border: 0; color: inherit; font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 4px; border-radius: 6px; }
.icon-btn:hover { background: var(--ink-3); }
.help-quick { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chip {
  font: inherit; font-size: .8rem; font-weight: 600; background: #f1f3f6; color: var(--text); border: 1px solid #e3e6ec;
  border-radius: 999px; padding: 5px 11px; cursor: pointer; text-decoration: none; text-align: left;
}
.chip:hover { background: var(--gold-soft); border-color: #f3dca8; text-decoration: none; }
.help-log { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; background: #fafbfc; }
.help-msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: .9rem; line-height: 1.45; }
.help-msg.bot { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.help-msg.user { background: var(--ink); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.help-note { display: block; margin-top: 6px; font-size: .72rem; color: var(--muted); }
.help-sugg { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.help-sugg:empty { display: none; }
.help-form { display: flex; gap: 8px; padding: 10px 12px 12px; }
.help-form input { border-radius: 999px; padding: 8px 14px; }
.typing { display: flex; gap: 4px; padding: 12px 14px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #9aa4b5; animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- tour ---------- */
.tour { position: fixed; inset: 0; z-index: 80; }
.tour-shade { position: fixed; background: rgba(16, 26, 44, .62); }
.tour-spot { position: fixed; border-radius: 8px; box-shadow: 0 0 0 3px var(--gold), 0 0 24px rgba(242, 179, 61, .45); pointer-events: none; }
.tour-center { background: rgba(16, 26, 44, .62); }
.tour-center .tour-spot, .tour-center .tour-shade { display: none; }
.tour-pop {
  position: fixed; width: 340px; max-width: calc(100vw - 24px); background: #fff; border-radius: 14px; padding: 18px 18px 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); transition: top .2s ease, left .2s ease;
}
.tour-center .tour-pop { top: 50% !important; left: 50% !important; transform: translate(-50%, -50%); }
.tour-count { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #b07a10; margin-bottom: 4px; }
.tour-pop h3 { font-size: 1.05rem; margin-bottom: 6px; }
.tour-body { color: #344054; font-size: .92rem; }
.tour-actions { display: flex; align-items: center; gap: 6px; margin-top: 14px; }
@media (prefers-reduced-motion: reduce) {
  .tour-pop { transition: none; }
  .typing span { animation: none; opacity: .6; }
}

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 24px; }
  .auth-hero h1 { margin-top: 24px; font-size: 1.9rem; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px 16px; gap: 12px; }
  .nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; }
  .nav-label { display: none; }
  .sidebar-user { margin-top: 0; padding-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .sidebar-user button { margin-top: 0; }
  .main { padding: 20px 16px 48px; }
  .code-card .code { font-size: 1.8rem; }
}
@media (max-width: 640px) {
  .help-fab { right: 14px; bottom: 14px; }
  .help-panel { right: 8px; left: 8px; bottom: 70px; width: auto; max-width: none; height: calc(100vh - 90px); }
  .public-head { padding: 12px 16px; }
}
@media (max-width: 520px) {
  .stats, .row, .row3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
