:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2557d6;
  --accent-text: #ffffff;
  --danger: #c62828;
  --ok-bg: #e7f6ec;
  --ok-text: #1e6b38;
  --err-bg: #fdecec;
  --err-text: #a12020;
  --warn-bg: #fff6dd;
  --warn-text: #7a5a00;
  --side: #151a23;
  --side-text: #c9d1dc;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --panel: #171b23;
    --text: #e6e9ee;
    --muted: #8b94a3;
    --line: #262c37;
    --accent: #4a7cff;
    --ok-bg: #12301f;
    --ok-text: #7fd8a0;
    --err-bg: #3a1616;
    --err-text: #ff9c9c;
    --warn-bg: #352a0c;
    --warn-text: #f0cf6b;
    --side: #0b0e13;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 28px 0 12px; }
h3 { font-size: 15px; margin: 0 0 12px; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; color: #fff; font-size: 16px; padding: 0 10px 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { color: var(--side-text); padding: 8px 10px; border-radius: 8px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .5; padding: 16px 10px 6px; }
.me { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 10px 0; display: flex; flex-direction: column; gap: 2px; }
.me a { color: #fff; }
.me form { margin: 4px 0 0; }

.content { flex: 1; min-width: 0; padding: 24px 28px 60px; max-width: 1280px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.small-head { margin-bottom: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { color: inherit; margin: 0; }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.big { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }

.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.account { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.pre { white-space: pre-wrap; }
.neg { color: var(--danger); font-weight: 600; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .empty { text-align: center; color: var(--muted); padding: 28px; }
.table .clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.row-link { cursor: pointer; }
.row-link:hover td { background: rgba(127,127,127,.06); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--text); white-space: nowrap; }
.st-new, .st-quoted { background: #e8eefc; color: #2246a8; }
.st-awaiting_payment { background: var(--warn-bg); color: var(--warn-text); }
.st-paid { background: #e4f1ff; color: #0b5cad; }
.st-payout { background: #efe7ff; color: #5b2fb8; }
.st-done { background: var(--ok-bg); color: var(--ok-text); }
.st-failed { background: var(--err-bg); color: var(--err-text); }
.st-cancelled { background: var(--line); color: var(--muted); }
.kyc-verified { background: var(--ok-bg); color: var(--ok-text); }
.kyc-pending { background: var(--warn-bg); color: var(--warn-text); }
.kyc-rejected { background: var(--err-bg); color: var(--err-text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .6; cursor: wait; }
.link { background: none; border: 0; padding: 0; color: var(--side-text); cursor: pointer; font: inherit; opacity: .7; }
.link:hover { opacity: 1; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row form { margin: 0; }
.actions > * + * { margin-top: 12px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }

.form label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 550; }
.form label input, .form label select, .form label textarea { font-weight: 400; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.narrow { max-width: 620px; }

.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.inline .grow { flex: 1; min-width: 200px; }
.inline-label { display: flex; align-items: center; gap: 6px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[name=q] { flex: 1; min-width: 220px; }
.check { display: flex; align-items: center; gap: 6px; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }
.banner { background: var(--warn-bg); color: var(--warn-text); padding: 8px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }

.msg { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; white-space: pre-wrap; margin: 0; font-family: inherit; }

.timeline { list-style: none; margin: 14px 0 0; padding: 0; }
.timeline li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; }
.timeline .ev-error span:last-child, .timeline .ev-failed span:last-child { color: var(--err-text); }
.timeline .ev-done span:last-child { color: var(--ok-text); }

.danger-zone summary { cursor: pointer; color: var(--muted); }
.danger-zone form { margin-top: 10px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 20px; }
.login p { margin: 0; }
.login label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 12px 16px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .brand { padding-bottom: 8px; }
  .nav-sep { display: none; }
  .me { flex-direction: row; align-items: center; gap: 10px; margin-top: 8px; }
  .me form { margin: 0; }
  .content { padding: 16px; }
  .grid2, .form .row { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}

.narrow-card { max-width: 680px; }
.highlight { border-color: var(--accent); }
.secret-state { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form .check.flag { flex-direction: row; align-items: center; gap: 8px; font-weight: 550; margin-bottom: 12px; }
.form .check.small { flex-direction: row; font-weight: 400; }
