:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #151a2d;
  --muted: #6b7186;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --ok: #138a4c;
  --ok-bg: #e5f6ec;
  --warn: #a35d00;
  --warn-bg: #fff2de;
  --bad: #c62a2a;
  --bad-bg: #fde9e9;
  --info: #2f5bea;
  --info-bg: #e8eefe;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1220;
    --surface: #161b2c;
    --surface-2: #1d2337;
    --border: #2a3149;
    --text: #e7e9f2;
    --muted: #949bb3;
    --accent: #5b7fff;
    --ok: #4cd38a; --ok-bg: #133325;
    --warn: #f0b35a; --warn-bg: #3a2a12;
    --bad: #ff7676; --bad-bg: #3d1a1d;
    --info: #8aa3ff; --info-bg: #1c2650;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h3 { font-size: 16px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
small { font-size: 12px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; white-space: pre; margin: 8px 0 0; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.side { width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
        padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--info-bg);
       color: var(--info); padding: 2px 7px; border-radius: 99px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
nav a { color: var(--text); padding: 9px 10px; border-radius: 8px; font-weight: 500; }
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { background: var(--info-bg); color: var(--info); }
.main { flex: 1; min-width: 0; padding: 0 28px 40px; }
.top { display: flex; align-items: center; gap: 14px; padding: 20px 0; }
.top h1 { flex: 1; }
.btn.menu { display: none; }

@media (max-width: 860px) {
  .side { position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.nav-open .side { transform: none; }
  .btn.menu { display: inline-flex; }
  .main { padding: 0 16px 32px; }
  .top #who { display: none; }
}

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
              border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { padding: 0 0 6px; font-size: 18px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
       border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
       cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.success { color: var(--ok); border-color: var(--ok); }
.btn.success:hover { background: var(--ok-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.tiny { padding: 3px 9px; font-size: 13px; }
.btn.block { width: 100%; }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
                          border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 500; }
.field > small { font-weight: 400; }
.form { display: flex; flex-direction: column; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row { grid-template-columns: 1fr; } }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { max-width: 320px; }
.toolbar.filters select, .toolbar.filters input { width: auto; flex: 1 1 170px; max-width: 260px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ---------- cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.panel { padding: 20px; margin-bottom: 20px; }
.panel > h3 { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.grid2 > .panel { margin-bottom: 0; }
.section { margin: 26px 0 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.secret { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px dashed var(--border);
          border-radius: 8px; padding: 10px 12px; word-break: break-all; }
.secret code { flex: 1; }
.note { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.qr-img { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }

/* ---------- tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td:first-child { white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .muted { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.more { text-align: center; margin-top: 14px; }

@media (max-width: 720px) {
  .toolbar.filters select, .toolbar.filters input, .toolbar input[type="search"] { max-width: none; flex-basis: 100%; }
  .table-wrap { background: transparent; border: 0; box-shadow: none; }
  table, tbody, tr, td { display: block; }
  thead { display: none; }
  tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  td { border: 0; padding: 6px 14px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  td.num { text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex-shrink: 0; }
  td[data-label=""]::before { content: none; }
}

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; text-transform: capitalize;
         background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.b-success, .b-active, .b-on, .b-approved { background: var(--ok-bg); color: var(--ok); }
.b-pending, .b-open { background: var(--info-bg); color: var(--info); }
.b-review { background: var(--warn-bg); color: var(--warn); }
.b-failed, .b-rejected, .b-suspended, .b-disabled { background: var(--bad-bg); color: var(--bad); }
.amount-in { color: var(--ok); }
.amount-out { color: var(--bad); }

/* ---------- modal & toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 24, .55); display: flex; align-items: flex-start; justify-content: center;
           padding: 8vh 16px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 480px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-body { padding: 16px 20px 0; }
.modal .error { padding: 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 20px; }
.x { border: 0; background: none; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; }
#toast { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; }
.toast.err { background: var(--bad); color: #fff; }
