:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --ink: #14162b;
  --ink-soft: #5a5f7a;
  --ink-faint: #9aa0bd;
  --line: #e7e9f4;
  --primary: #5b3df5;
  --primary-soft: #ece8ff;
  --accent: #00bfa6;
  --warn: #f5a623;
  --danger: #ef4361;
  --shadow: 0 1px 2px rgba(20, 22, 43, 0.04), 0 8px 24px rgba(20, 22, 43, 0.06);
  --radius: 16px;
  --radius-sm: 11px;
}

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

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

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 22px 48px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 46px; height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, #6d4bff, #5b3df5 60%, #3a1fd1);
  color: #fff;
  font-weight: 800; font-size: 24px;
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(91, 61, 245, 0.32);
}
.brand-text h1 {
  font-size: 19px; font-weight: 800; letter-spacing: -0.4px;
}
.brand-dot { color: var(--primary); }
.brand-text p {
  font-size: 12.5px; color: var(--ink-soft); font-weight: 500; margin-top: 1px;
}
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.updated {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  background: var(--surface);
  padding: 8px 13px; border-radius: 999px;
  border: 1px solid var(--line);
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(0, 191, 166, 0.5);
  animation: pulse 2.2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 191, 166, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(0, 191, 166, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 191, 166, 0); }
}
.btn-refresh {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: inherit; font-size: 12px; font-weight: 700; color: #fff;
  background: var(--primary); border: 0; border-radius: 999px;
  padding: 8px 15px; cursor: pointer; transition: 0.15s;
  box-shadow: 0 4px 12px rgba(91, 61, 245, 0.28);
}
.btn-refresh:hover { background: #4a2fe0; transform: translateY(-1px); }
.btn-refresh:active { transform: translateY(0); }
.btn-refresh:disabled { opacity: 0.65; cursor: default; transform: none; }
.btn-refresh.loading .rf-icon { animation: spin 0.8s linear infinite; }

.daterange {
  display: flex; align-items: center; gap: 6px; position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 5px 12px 5px 13px;
}
.daterange .dr-icon { color: var(--primary); flex: none; }
.dr-field {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  font-family: inherit; background: transparent; border: 0; cursor: pointer;
  padding: 4px 8px; border-radius: 9px; transition: 0.15s;
}
.dr-field:hover { background: var(--primary-soft); }
.dr-field:focus-visible { outline: 2px solid var(--primary); }
.dr-cap { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-faint); }
.dr-val { font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.dr-arrow { color: var(--ink-faint); font-size: 13px; }
.dr-native {
  position: absolute; bottom: 2px; left: 40px; width: 1px; height: 1px;
  opacity: 0; pointer-events: none; border: 0; padding: 0; margin: 0;
}

/* ---------- Filters ---------- */
.filters {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.filters-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px;
}
.filters-head h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.7px; color: var(--ink-soft); }
.filters-actions { display: flex; gap: 7px; }
.chip-ctrl {
  font-family: inherit; font-size: 11.5px; font-weight: 600;
  color: var(--ink-soft); background: transparent;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; transition: 0.15s;
}
.chip-ctrl:hover { border-color: var(--primary); color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); background: #fafbff;
  border: 1.5px solid var(--line); border-radius: 11px;
  padding: 8px 13px; cursor: pointer; transition: 0.15s;
}
.chip:hover { border-color: #cfc7ff; }
.chip .dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.chip .ch-meta { font-size: 11px; font-weight: 500; color: var(--ink-faint); }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--ink); }
.chip.on .ch-meta { color: var(--primary); }

/* ---------- KPIs ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 13px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  position: relative;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--kc, var(--primary));
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.kpi .k-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 7px; }
.kpi .k-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--ink-faint);
}
.kpi .k-value { font-size: 22px; font-weight: 800; letter-spacing: -0.6px; }

/* info + tooltip */
.k-info {
  width: 16px; height: 16px; flex: none;
  border-radius: 50%; background: #eef0f7; color: var(--ink-faint);
  font-size: 10px; font-weight: 800; line-height: 16px; text-align: center;
  cursor: help; position: relative; user-select: none; transition: 0.15s;
}
.k-info:hover, .k-info:focus-visible { background: var(--primary); color: #fff; outline: none; }
.k-tip {
  position: absolute; top: calc(100% + 9px); right: -7px; z-index: 30;
  width: 212px; background: #14162b; color: #fff;
  font-size: 11.5px; font-weight: 500; line-height: 1.45; letter-spacing: 0;
  text-transform: none; padding: 10px 12px; border-radius: 10px;
  box-shadow: 0 10px 28px rgba(20, 22, 43, 0.24);
  opacity: 0; visibility: hidden; transform: translateY(-4px); transition: 0.16s;
  pointer-events: none;
}
.k-tip::before {
  content: ''; position: absolute; top: -5px; right: 11px;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-bottom: 5px solid #14162b;
}
.k-info:hover .k-tip, .k-info:focus-visible .k-tip { opacity: 1; visibility: visible; transform: translateY(0); }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h3 { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.panel-head .hint { font-size: 11.5px; color: var(--ink-faint); font-weight: 500; }
.muted { color: var(--ink-faint); font-weight: 600; font-size: 13px; }

.metric-toggle { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.leg { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.leg-dot { width: 11px; height: 11px; border-radius: 4px; flex: none; }
.metric-toggle button {
  font-family: inherit; font-size: 11.5px; font-weight: 600;
  color: var(--ink-soft); background: #fafbff;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 11px; cursor: pointer; transition: 0.15s;
}
.metric-toggle button:hover { border-color: #cfc7ff; }
.metric-toggle button.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.chart-wrap { padding: 18px; height: 320px; }

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid thead th {
  text-align: right; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px; color: var(--ink-faint);
  padding: 12px 14px; white-space: nowrap; cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--line); background: #fbfcff;
}
table.grid thead th:first-child { text-align: left; }
table.grid thead th:hover { color: var(--primary); }
table.grid thead th .arrow { opacity: 0.5; font-size: 9px; margin-left: 3px; }
table.grid thead th.sorted .arrow { opacity: 1; color: var(--primary); }
table.grid tbody td {
  text-align: right; padding: 12px 14px; white-space: nowrap;
  border-bottom: 1px solid #f1f2f9; font-weight: 600; font-variant-numeric: tabular-nums;
}
table.grid tbody td:first-child { text-align: left; }
table.grid tr.camp-row { cursor: pointer; transition: 0.12s; }
table.grid tr.camp-row:hover { background: #fafbff; }
table.grid tr.camp-row.open { background: var(--primary-soft); }
.camp-name { display: flex; align-items: center; gap: 10px; }
.camp-name .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.camp-name .nm { font-weight: 700; }
.camp-name .pd {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  background: var(--primary-soft); color: var(--primary);
  padding: 2px 7px; border-radius: 6px;
}
.camp-name .caret { color: var(--ink-faint); transition: 0.18s; font-size: 11px; }
tr.camp-row.open .caret { transform: rotate(90deg); color: var(--primary); }
tr.sub-row td { background: #fcfcff; font-weight: 500; color: var(--ink-soft); }
tr.sub-row td:first-child { padding-left: 34px; }
tr.sub-row .sub-kind {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase; color: var(--ink-faint);
  letter-spacing: 0.4px; margin-right: 6px;
}
tr.grand td { border-top: 2px solid var(--line); font-weight: 800; color: var(--ink); background: #fbfcff; }

/* ---------- Loading / states ---------- */
.loading { display: grid; place-items: center; gap: 14px; padding: 80px 0; color: var(--ink-soft); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty strong { display: block; font-size: 16px; color: var(--ink); margin-bottom: 6px; }
.banner-error {
  background: #fff3f5; border: 1px solid #ffd5dd; color: #b3243d;
  padding: 11px 15px; border-radius: 11px; font-size: 12.5px; font-weight: 600; margin-bottom: 16px;
}

/* ---------- Footer ---------- */
.foot {
  display: flex; align-items: center; gap: 9px; justify-content: center;
  font-size: 11.5px; color: var(--ink-faint); font-weight: 500; margin-top: 8px;
}
.foot strong { color: var(--ink-soft); font-weight: 700; }
.foot-sep { opacity: 0.5; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .app { padding: 16px 14px 40px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .k-value { font-size: 19px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .brand-text h1 { font-size: 17px; }
  .chart-wrap { height: 260px; }
}
