:root {
  --bg: #0b1220;
  --surface: #131c31;
  --surface-alt: #1b2742;
  --border: #263556;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #22c55e;
  --red: #f87171;
  --amber: #f59e0b;
  --radius: 14px;
}

body.light {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #e2e8f0;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --accent: #0284c7;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

code {
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.9em;
}

.muted { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.error-text { color: var(--red); font-size: 0.9rem; margin-top: 8px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.warn { color: var(--amber); }

.unlock-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.unlock-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
}

.brand-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.unlock-card h1 { margin: 4px 0 8px; font-size: 1.4rem; }

.unlock-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--muted);
}

.text-input, .select-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  min-width: 0;
}

.text-input.small { width: 120px; }

.btn-primary, .btn-secondary, .btn-ghost {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #061322; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); padding: 7px 10px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.topbar-title { display: flex; align-items: center; gap: 10px; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.subline { font-size: 0.75rem; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; }

.tab-bar {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: #061322;
  border-color: var(--accent);
}

.content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card h3 { margin: 0 0 12px; font-size: 1rem; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.section-head h2, .section-head h3 { margin: 0; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-grid.compact { margin-bottom: 0; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.kpi-label { font-size: 0.78rem; color: var(--muted); }
.kpi-value { font-size: 1.25rem; font-weight: 700; margin-top: 4px; }
.kpi-sub { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.cat-bars { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.cat-bar-row { display: grid; grid-template-columns: 145px 1fr 85px; align-items: center; gap: 10px; font-size: 0.85rem; }
.bar-track { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.filters-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

.delta-banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.9rem;
}

.chart-wrap {
  position: relative;
  height: 300px;
  width: 100%;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: #061322; border-color: var(--accent); font-weight: 600; }

.accordion-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.person-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.person-summary {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}

.person-meta { font-size: 0.78rem; color: var(--muted); }
.person-balance { font-weight: 700; text-align: right; white-space: nowrap; }

.person-ops {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
}

.op-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}

.op-row:last-child { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--text);
}

.draft-drawer {
  background: var(--bg);
  border: 1px dashed var(--accent);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.draft-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.draft-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.draft-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.84rem;
}

.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tx-main { min-width: 0; }
.tx-title { font-weight: 600; word-break: break-word; }
.tx-sub { font-size: 0.78rem; color: var(--muted); margin-top: 3px; }
.tx-right { text-align: right; white-space: nowrap; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.tx-amount { font-weight: 700; font-size: 1rem; }
.load-more-wrap { display: flex; justify-content: center; margin-top: 10px; }

.edits-banner {
  border-color: var(--accent);
}

.patch-preview {
  width: 100%;
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

.edit-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.badge-edited {
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(2, 6, 23, 0.72);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.5);
}

.edit-meta {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 12px;
  word-break: break-word;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-form > label:not(.checkbox-row) {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.84rem;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

@media (max-width: 600px) {
  .cat-bar-row { grid-template-columns: 110px 1fr 75px; font-size: 0.8rem; }
  .chart-wrap { height: 250px; }
}
