:root, [data-theme="dark"] {
  --bg: #0b0f19;
  --surface: #111827;
  --surface-2: #1a2333;
  --border: #243044;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-hover: #059669;
  --danger: #f43f5e;
  --warn: #f59e0b;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #059669;
  --accent-hover: #047857;
  --danger: #e11d48;
  --warn: #d97706;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

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

.tabular, .money {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
body.discreet-mode .money {
  filter: blur(8px);
  user-select: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.nav-link {
  color: var(--muted);
  text-decoration: none;
  padding: 0.42rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-link:hover, .nav-link.active {
  color: var(--text);
  background: var(--surface-2);
}

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3.5rem;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 1.25rem;
  align-items: center;
  margin-bottom: 1.25rem;
}
@media (max-width: 820px) {
  .hero-card { grid-template-columns: 1fr; padding: 1rem; }
}

.kpi-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.kpi-total {
  font-size: clamp(1.85rem, 4vw, 2.55rem);
  font-weight: 800;
  margin: 0.2rem 0 0.45rem;
}
.kpi-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.84rem;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.78rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.pill-pos { color: var(--accent); }
.pill-neg { color: var(--danger); }
.pill-warn { color: var(--warn); border-color: var(--warn); }

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.48rem 0.85rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger {
  border-color: color-mix(in srgb, var(--danger) 50%, var(--border));
  color: var(--danger);
}
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

.svg-area-chart { width: 100%; height: 128px; display: block; }
.svg-axis-label { fill: var(--muted); font-size: 10px; font-family: inherit; }

.entities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 1rem;
}
@media (max-width: 600px) {
  .entities-grid { grid-template-columns: 1fr; }
}

.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.entity-header {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: color-mix(in srgb, var(--surface-2) 55%, var(--surface));
}
.entity-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 0.98rem;
}
.color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.entity-subtotal { font-weight: 700; font-size: 1.05rem; }

.account-row {
  padding: 0.8rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease;
}
.account-row:last-child { border-bottom: none; }
.account-row:hover { background: var(--surface-2); }

.acc-main { min-width: 0; }
.acc-name {
  font-weight: 600;
  font-size: 0.93rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.acc-meta {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.15rem;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-ok { background: #10b981; }
.status-warn { background: #f59e0b; }
.status-error { background: #f43f5e; }

.acc-right { text-align: right; flex-shrink: 0; }
.acc-balance { font-weight: 700; font-size: 1rem; }
.acc-balance.neg { color: var(--danger); }
.acc-delta { font-size: 0.75rem; color: var(--muted); }

/* Slide-over Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  z-index: 60;
  display: none;
  justify-content: flex-end;
}
.drawer-backdrop.open { display: flex; }
.drawer-panel {
  width: min(520px, 100vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1.25rem;
  overflow-y: auto;
}

.alert-ok, .alert-err, .alert-warn {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  font-weight: 500;
}
.alert-ok { background: rgba(16, 185, 129, 0.14); border: 1px solid var(--accent); }
.alert-err { background: rgba(244, 63, 94, 0.14); border: 1px solid var(--danger); }
.alert-warn { background: rgba(245, 158, 11, 0.14); border: 1px solid var(--warn); }

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem;
  margin-bottom: 1.2rem;
}
.section-card h2 { margin: 0 0 0.35rem; font-size: 1.08rem; }
.section-sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 1rem; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.48rem 0.7rem;
  font-size: 0.88rem;
  font-family: inherit;
}
textarea { width: 100%; min-height: 92px; font-family: ui-monospace, monospace; font-size: 0.8rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td {
  text-align: left;
  padding: 0.65rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.text-right { text-align: right; }
