:root {
  --bg: #0f1218;
  --surface: #171b24;
  --surface-2: #1f2533;
  --border: #2b3346;
  --text: #e6ebf5;
  --muted: #8f9bb3;
  --primary: #4f8cff;
  --primary-hover: #3b77ea;
  --success: #2ea86b;
  --success-hover: #258d59;
  --warn: #e09f3e;
  --danger: #e05263;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}

code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.warn-text { color: var(--warn); }
.error-text { color: var(--danger); margin: 8px 0; font-size: 13px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--success));
  box-shadow: 0 0 12px rgba(79, 140, 255, 0.5);
}
.brand h1 { margin: 0; font-size: 18px; }
.subtitle { font-size: 12px; color: var(--muted); }
.topbar-meta { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.count-badge {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text);
  padding: 1px 7px;
  border-radius: 12px;
  font-size: 11px;
  margin-left: 4px;
}

.container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 26px; font-weight: 700; margin: 4px 0; }
.stat-sub { font-size: 12px; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 8px; font-size: 17px; }
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.panel-header-inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 18px;
}
.sub-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 12px;
}
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
input[type="text"], input[type="password"], input[type="date"], input[type="number"],
input[type="search"], input[type="file"], select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}
.check-inline {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.check-inline input { width: auto; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.form-row.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.form-row.three { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-row.four { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.form-row.checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 12px 0;
}
.form-group { margin: 12px 0; }
.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}
.label-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 8px;
}
.account-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
}
.account-chip input { margin-top: 3px; width: auto; }
.account-chip-title { font-weight: 600; color: var(--text); font-size: 13px; }
.account-chip-sub { font-size: 11px; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: #273043; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover { background: var(--success-hover); }
.btn.warn { background: rgba(224, 159, 62, 0.2); border-color: var(--warn); color: #f6c473; }
.btn.warn:hover { background: rgba(224, 159, 62, 0.34); }
.btn.danger { background: rgba(224, 82, 99, 0.16); border-color: var(--danger); color: #ff8c9a; }
.btn.danger:hover { background: rgba(224, 82, 99, 0.28); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.xs { padding: 3px 8px; font-size: 11px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.inline-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.pill.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.ok { background: rgba(46, 168, 107, 0.18); color: #5ee39c; }
.pill.info { background: rgba(79, 140, 255, 0.18); color: #8cb7ff; }
.pill.warn { background: rgba(224, 159, 62, 0.2); color: #f6c473; }
.pill.danger { background: rgba(224, 82, 99, 0.2); color: #ff8c9a; }

.banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
}
.banner.ok { border-color: var(--success); background: rgba(46, 168, 107, 0.12); }
.banner.warn { border-color: var(--warn); background: rgba(224, 159, 62, 0.12); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pill {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
.filter-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.toolbar-controls { display: flex; gap: 8px; align-items: center; }
.toolbar-controls select, .toolbar-controls input { width: auto; min-width: 170px; }

.bulk-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 12px;
}
.export-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.export-controls select { width: auto; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

.split-mini {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 2px 0;
}
.split-mini .amt { font-family: ui-monospace, monospace; white-space: nowrap; }
.amt.pos { color: #5ee39c; }
.amt.neg { color: #ff9aa6; }
.raw-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.reason-sub { font-size: 11px; color: var(--muted); margin-top: 4px; max-width: 240px; }

.items-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-wrap: wrap;
  gap: 10px;
}

.kv-list { display: grid; gap: 6px; font-size: 13px; }
.kv-row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--border); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}
.modal-card.small { max-width: 400px; }
.modal-card.wide { max-width: 880px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-header h2 { margin: 0; font-size: 18px; }
.icon-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 24px; cursor: pointer; line-height: 1;
}
.icon-btn:hover { color: var(--text); }
.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}

.raw-info-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 12px;
}
.candidates-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(79, 140, 255, 0.08);
  border: 1px solid rgba(79, 140, 255, 0.25);
  border-radius: 8px;
}
.candidate-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 4px 6px 0 0;
  padding: 4px 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.candidate-btn:hover { border-color: var(--primary); }

.splits-editor {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
}
.splits-rows { display: flex; flex-direction: column; gap: 8px; }
.split-row {
  display: grid;
  grid-template-columns: 2.3fr 1fr 1.2fr 0.8fr 32px;
  gap: 8px;
  align-items: center;
}
.rule-split-row {
  display: grid;
  grid-template-columns: 2.2fr 0.9fr 0.8fr 1.1fr 0.8fr 32px;
  gap: 8px;
  align-items: center;
}
@media (max-width: 720px) {
  .split-row, .rule-split-row { grid-template-columns: 1fr; }
}

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 13px;
  max-width: 380px;
}
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
