:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --emerald: #10b981;
  --rose: #f43f5e;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-badge {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #10b981);
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px; color: #fff;
}
.brand h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: 0.85rem; color: var(--muted); }

.topbar-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #273549; }
.btn-sync {
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}
.btn-sync:hover { background: rgba(16, 185, 129, 0.24); }

.sync-banner {
  margin-bottom: 18px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  border: 1px solid var(--border);
  background: var(--surface);
}
.sync-banner.hidden { display: none; }
.sync-banner.ok {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.1);
  color: #6ee7b7;
}
.sync-banner.err {
  border-color: rgba(244, 63, 94, 0.35);
  background: rgba(244, 63, 94, 0.1);
  color: #fda4af;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.filter-label { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.pill:hover { color: var(--text); border-color: #334155; }
.pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.kpi-sub { font-size: 0.82rem; color: var(--muted); }
.pos { color: var(--emerald); }
.neg { color: var(--rose); }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 18px;
  margin-bottom: 22px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.chart-wide { grid-column: span 8; }
.chart-card:not(.chart-wide):not(.chart-full) { grid-column: span 4; }
.chart-full { grid-column: span 12; }

@media (max-width: 960px) {
  .chart-wide, .chart-card:not(.chart-wide):not(.chart-full) { grid-column: span 12; }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.card-header h2 { font-size: 1.02rem; font-weight: 600; }
.card-sub { font-size: 0.82rem; color: var(--muted); }

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

.search-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  min-width: 220px;
}

.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.type-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--surface-2);
}
.actions-col { text-align: right; white-space: nowrap; }
.action-link {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  cursor: pointer;
  margin-left: 6px;
}
.action-link:hover { background: var(--surface-2); }
.action-link.danger { color: var(--rose); border-color: rgba(244, 63, 94, 0.3); }

/* Modals */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, 0.75); backdrop-filter: blur(4px); }
.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(540px, 92vw);
  padding: 22px;
  z-index: 1;
}
.modal-sm { width: min(400px, 92vw); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 1.5rem; cursor: pointer; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; color: var(--muted); }
.form-grid label.full { grid-column: span 2; }
.form-grid input, .form-grid select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.9rem;
}
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
