:root {
  --bg: #0b1220;
  --bg2: #121a2b;
  --card: #162033;
  --line: #243149;
  --text: #e8eef7;
  --muted: #8fa3bf;
  --accent: #4f8cff;
  --accent2: #2dd4bf;
  --danger: #f07178;
  --ok: #34d399;
  --warn: #fbbf24;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  --radius: 14px;
  --font: "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a2b4d 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #12353a 0%, transparent 50%),
    var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: rgba(11,18,32,.85);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; letter-spacing: .02em; margin-bottom: 6px; }
.brand span { color: var(--accent2); }
.side .sub { color: var(--muted); font-size: .8rem; margin-bottom: 22px; }
.nav a {
  display: block; padding: 10px 12px; border-radius: 10px;
  color: var(--text); margin-bottom: 4px;
}
.nav a.active, .nav a:hover { background: var(--card); text-decoration: none; }
.main { padding: 24px 28px 48px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
h1 { margin: 0; font-size: 1.35rem; }
.muted { color: var(--muted); font-size: .85rem; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card {
  background: linear-gradient(180deg, #182338, var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat .val { font-size: 1.6rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: .72rem;
  background: #243149; color: var(--muted);
}
.badge.on { background: #123528; color: var(--ok); }
.badge.off { background: #3a1f24; color: #ff8a96; }
.badge.warn { background: #3a2f14; color: var(--warn); }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 10px; padding: 9px 14px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; font-size: .85rem;
}
.btn.secondary { background: #243149; color: var(--text); }
.btn.danger { background: #8b2e38; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn:hover { filter: brightness(1.08); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
form.stack label { display: block; font-size: .78rem; color: var(--muted); margin: 12px 0 6px; }
form.stack input, form.stack select, form.stack textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
}
.alert {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px;
  border: 1px solid var(--line); background: #1a2438; color: var(--muted); font-size: .9rem;
}
.alert.warn { background: #2a2114; border-color: #4a3a1a; color: var(--warn); }
.alert.ok { background: #123528; border-color: #1f4a38; color: var(--ok); }
.alert.err { background: #3a1f24; border-color: #5a2a32; color: #ff8a96; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.op-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.badge.status-unassigned { background: #2a2f3a; color: var(--muted); }
.badge.status-unmatched_trader { background: #3a2f14; color: var(--warn); }
.badge.status-held { background: #2a2438; color: #c4b5fd; }
.badge.status-queued { background: #1a2f4a; color: #7eb6ff; }
.badge.status-awaiting_receipt, .badge.status-issued, .badge.status-receipt_ready {
  background: #3a2f14; color: var(--warn);
}
.badge.status-completed { background: #123528; color: var(--ok); }
.badge.status-cancelled, .badge.status-confirm_failed { background: #3a1f24; color: #ff8a96; }
.badge.status-expired { background: #3a2f14; color: var(--warn); }
.badge.bank { background: #1e2a44; color: #9ec1ff; margin-top: 4px; }
.badge.rem { background: #1a2f3a; color: #7dd3c0; }
.badge.rem-processing, .badge.rem-pending, .badge.rem-active {
  background: #1a2f4a; color: #7eb6ff;
}
.badge.rem-expired { background: #3a2f14; color: var(--warn); }
.badge.rem-rejected, .badge.rem-cancelled, .badge.rem-canceled {
  background: #3a1f24; color: #ff8a96;
}
.badge.rem-completed, .badge.rem-success, .badge.rem-paid {
  background: #123528; color: var(--ok);
}
.badge.rem-missing_from_active { background: #2a2f3a; color: var(--muted); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab {
  padding: 8px 14px; border-radius: 10px; color: var(--muted);
  background: transparent; border: 1px solid var(--line); font-size: .85rem; font-weight: 600;
}
.tab.active, .tab:hover { background: var(--card); color: var(--text); text-decoration: none; border-color: #35507a; }

/* —— Filters —— */
.filters-panel {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 16px; padding: 14px 16px;
  background: linear-gradient(180deg, rgba(24,35,56,.95), rgba(22,32,51,.9));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.filters-search {
  position: relative; display: flex; align-items: center;
}
.filters-search-icon {
  position: absolute; left: 14px; color: var(--muted);
  display: flex; pointer-events: none;
}
.filters-search-input {
  width: 100%; padding: 12px 40px 12px 42px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text);
  font-size: .92rem; outline: none; transition: border-color .15s, box-shadow .15s;
}
.filters-search-input::placeholder { color: #6b7f99; }
.filters-search-input:focus {
  border-color: #3d6eb8;
  box-shadow: 0 0 0 3px rgba(79,140,255,.18);
}
.filters-search-clear {
  position: absolute; right: 12px; width: 24px; height: 24px;
  display: grid; place-items: center; border-radius: 8px;
  color: var(--muted); font-size: .75rem; text-decoration: none;
}
.filters-search-clear:hover { background: #243149; color: var(--text); text-decoration: none; }
.filters-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
.filter-field {
  display: flex; flex-direction: column; gap: 5px; min-width: 160px; flex: 1;
}
.filter-label {
  font-size: .7rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .05em; font-weight: 600;
}
.filter-field select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  font-size: .85rem; cursor: pointer; outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238fa3bf' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}
.filter-field select:focus {
  border-color: #3d6eb8;
  box-shadow: 0 0 0 3px rgba(79,140,255,.18);
}
.filters-actions {
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
  padding-bottom: 1px;
}
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px; font-size: .75rem;
  background: #1a2f4a; color: #9ec1ff; border: 1px solid #2a4468;
}
.filter-chip strong { color: #e8eef7; font-weight: 600; }

.list-meta {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 10px; font-size: .82rem; color: var(--muted);
}
.list-meta strong { color: var(--text); font-weight: 600; }

/* —— Pagination —— */
.pagination {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: 6px; margin-top: 18px;
}
.page-btn {
  min-width: 36px; height: 36px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid var(--line);
  background: rgba(22,32,51,.85); color: var(--text);
  font-size: .85rem; font-weight: 600; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
}
.page-btn:hover { background: #1e2d48; border-color: #35507a; text-decoration: none; }
.page-btn.current {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 4px 14px rgba(79,140,255,.35);
  pointer-events: none;
}
.page-btn.disabled {
  opacity: .35; pointer-events: none; cursor: default;
}
.page-ellipsis {
  min-width: 28px; text-align: center; color: var(--muted); font-weight: 600;
}
.empty-state {
  text-align: center; padding: 36px 16px !important; color: var(--muted);
}

.table-wrap { padding: 0; overflow: auto; }
.payouts-table { font-size: .82rem; }
.payouts-table th, .payouts-table td { padding: 8px 10px; }
.amt-cell .amt-big { font-size: 1.15rem; font-weight: 700; letter-spacing: .01em; }
.amt-cell .amt-sub { color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.card-num { letter-spacing: .02em; }
.recipient { max-width: 180px; word-break: break-word; }
.countdown {
  display: inline-block; min-width: 4.5rem;
  font-weight: 700; font-variant-numeric: tabular-nums;
  color: #f6b84b; background: #3a2f14; padding: 3px 8px; border-radius: 8px; font-size: .78rem;
}
.countdown.urgent { color: #ff9f43; background: #4a2810; }
.countdown.expired { color: #ff8a96; background: #3a1f24; }
.btn-xs { padding: 5px 8px; font-size: .72rem; }
.btn.ok { background: #1f7a4d; }
.action-btns { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.action-btns form { margin: 0; }
.action-btns .btn { width: 100%; }
.reject-comment {
  width: 100%; margin-bottom: 4px; padding: 5px 7px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: .72rem;
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .filters-row { flex-direction: column; align-items: stretch; }
  .filter-field { min-width: 0; }
  .filters-actions { width: 100%; }
  .filters-actions .btn { flex: 1; }
  .list-meta { flex-direction: column; align-items: flex-start; }
}

/* —— Teams / detail —— */
.team-block {
  margin: 12px 0 16px; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: rgba(11,18,32,.35);
}
.team-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.op-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 120px; }
.op-actions .btn { width: 100%; }
.payout-row { cursor: pointer; }
.payout-row:hover { background: rgba(79,140,255,.06); }
.comment-preview {
  margin-top: 4px; font-size: .72rem; color: #ffb4bc; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.detail-grid {
  display: grid; gap: 14px; grid-template-columns: 1fr 1.1fr;
}
@media (max-width: 980px) {
  .detail-grid { grid-template-columns: 1fr; }
}
.detail-section-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; margin-bottom: 12px;
}
.detail-dl { display: grid; gap: 10px; margin: 0; }
.detail-dl > div { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: start; }
.detail-dl dt { margin: 0; color: var(--muted); font-size: .78rem; }
.detail-dl dd { margin: 0; }
.comment-box {
  margin-top: 16px; padding: 12px 14px; border-radius: 12px;
  background: #3a1f24; border: 1px solid #5a2a32; color: #ffb4bc;
}
.comment-box.warn { background: #3a2f14; border-color: #4a3a1a; color: var(--warn); }
.comment-box p { margin: 8px 0 0; }
.receipt-grid { display: flex; flex-direction: column; gap: 8px; }
.receipt-card {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg2);
  color: var(--text); text-decoration: none;
}
.receipt-card:hover { border-color: #35507a; text-decoration: none; }
.receipt-icon { font-size: 1.4rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid; grid-template-columns: 150px 1fr; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.tl-time { color: var(--muted); font-size: .72rem; }
.tl-comment {
  margin-top: 4px; padding: 6px 8px; border-radius: 8px;
  background: #3a1f24; color: #ffb4bc; font-size: .8rem;
}
.plain-list { margin: 0; padding-left: 18px; color: var(--muted); }
.plain-list li { margin-bottom: 4px; }
