:root {
  --bg: #0b0e13;
  --surface: #12161d;
  --surface-2: #181d26;
  --border: #242b37;
  --border-strong: #2f3846;
  --text: #e8ecf2;
  --text-dim: #9aa4b2;
  --text-faint: #6b7483;
  --accent: #5b8def;
  --accent-soft: rgba(91, 141, 239, 0.14);
  --green: #3ecf8e;
  --green-soft: rgba(62, 207, 142, 0.12);
  --red: #f0616d;
  --red-soft: rgba(240, 97, 109, 0.12);
  --amber: #f2b94b;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

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

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 7px;
  font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4a7ee6; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }

/* Login */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
}
.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.login-sub { color: var(--text-dim); margin-bottom: 22px; }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 10px 12px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 12px; }

/* App shell */
.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.brand h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { color: var(--text-dim); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Controls */
.period-dropdown {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.period-dropdown:hover { border-color: var(--accent); }

.controls {
  margin-bottom: 20px;
}
.custom-range {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 10px;
}
.custom-range input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  color-scheme: dark;
}
.range-sep { color: var(--text-faint); }
.period-label { margin-left: auto; color: var(--text-dim); font-size: 13px; }

/* Status bar */
.status {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  color: var(--text-dim);
}
.status.error { border-left-color: var(--red); color: var(--red); }

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 92px;
}
.card-accent { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--surface)); }
.card-spend { border-color: rgba(91, 141, 239, 0.4); background: linear-gradient(180deg, rgba(91, 141, 239, 0.08), var(--surface)); }
.card-contact { border-color: rgba(242, 185, 75, 0.4); background: linear-gradient(180deg, rgba(242, 185, 75, 0.08), var(--surface)); }
.card-purchase { border-color: rgba(62, 207, 142, 0.4); background: linear-gradient(180deg, rgba(62, 207, 142, 0.08), var(--surface)); }
.card-revenue { border-color: rgba(46, 204, 113, 0.4); background: linear-gradient(180deg, rgba(46, 204, 113, 0.06), var(--surface)); }
.card-label { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.card-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.card-note { font-size: 11px; color: var(--text-faint); }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 15px; font-weight: 600; }
.panel-meta { color: var(--text-faint); font-size: 13px; }
.panel-note { padding: 14px 20px; color: var(--text-dim); font-size: 13px; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-dim); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-spend { background: var(--accent); }
.dot-purchase { background: var(--green); }
.dot-contact { background: var(--amber); }

.chart-wrap {
  position: relative;
  height: 280px;
  padding: 16px 20px 20px;
}
.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { padding: 5px 8px; text-align: left; white-space: nowrap; }
thead th {
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
thead th[data-sort] { cursor: pointer; }
thead th[data-sort]:hover { color: var(--text); }
thead th.sorted::after { content: " \2193"; color: var(--accent); }
thead th.sorted.asc::after { content: " \2191"; }
tbody td { border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.015); }
tfoot td {
  border-top: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-weight: 600;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.name { max-width: none; overflow: visible; text-overflow: clip; }
#activity-table th:nth-child(3), #activity-table td:nth-child(3),
#activity-table th:nth-child(5), #activity-table td:nth-child(5),
#activity-table th:nth-child(6), #activity-table td:nth-child(6) {
  width: 1%;
  white-space: nowrap;
}
td.dim { color: var(--text-dim); }
td.mono { font-family: var(--mono); font-size: 11px; }
.empty { text-align: center; color: var(--text-faint); padding: 24px 16px !important; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
}
.pill-on { background: var(--green-soft); color: var(--green); }
.pill-off { background: var(--red-soft); color: var(--red); }
.pill-muted { background: rgba(154,164,178,0.12); color: var(--text-dim); }
.obj-type {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(154,164,178,0.10);
  color: var(--text-faint);
  vertical-align: 1px;
}
.pill-budget { background: rgba(91,141,239,0.12); color: var(--accent); }
.pill-status { background: var(--green-soft); color: var(--green); }
.pill-targeting { background: rgba(242,185,75,0.12); color: var(--amber); }
.pill-bid { background: rgba(155,89,182,0.12); color: #bb8fce; }
.pill-name { background: rgba(52,152,219,0.12); color: #5dade2; }
.pill-create { background: rgba(46,204,113,0.12); color: #58d68d; }
.pill-billing { background: rgba(231,76,60,0.12); color: #ec7063; }
.pill-other { background: rgba(154,164,178,0.12); color: var(--text-dim); }


.roas-good { color: var(--green); font-weight: 600; }
.roas-ok { color: var(--amber); font-weight: 600; }
.roas-bad { color: var(--red); font-weight: 600; }

@media (max-width: 720px) {
  .app { padding: 20px 14px 48px; }
  .topbar { flex-direction: column; }
  .period-label { margin-left: 0; width: 100%; }
  .chart-wrap { height: 220px; }
}

/* Tabs */
.view-tabs {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 4px;
  margin-bottom: 20px;
}
.tab-btn {
  background: transparent;
  border: 0;
  padding: 8px 18px;
  border-radius: 6px;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 13px;
  transition: color .15s, background .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--surface-2); color: var(--text); }

.panel-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); }

/* Drill-down rows */
tr.row-campaign td.name { cursor: pointer; }
tr.row-campaign td.name::before,
tr.row-adset td.name::before {
  content: "\25B8";
  display: inline-block;
  width: 14px;
  color: var(--text-faint);
  transition: transform .15s;
}
tr.expanded td.name::before { transform: rotate(90deg); color: var(--accent); }
tr.row-adset td { background: rgba(255, 255, 255, 0.02); }
tr.row-adset td.name { padding-left: 34px; cursor: pointer; }
tr.row-ad td { background: rgba(255, 255, 255, 0.035); }
tr.row-ad td.name { padding-left: 62px; }
tr.row-ad td.name::before { content: "\2014"; color: var(--text-faint); width: 14px; display: inline-block; }
tr.row-loading td { color: var(--text-faint); font-style: italic; }
tr.row-loading td.name { padding-left: 34px; }
tr.row-ad.row-loading td.name { padding-left: 62px; }
.filter-select {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 12px;
  max-width: 220px;
  text-overflow: ellipsis;
}


