:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-hover: #EEF1F4;
  --border: #E1E4EA;
  --text: #1A1F29;
  --text-muted: #6B7280;
  --accent: #0D8C82;
  --accent-soft: #DAF4F0;
  --active: #15803D;
  --active-soft: #DCFCE7;
  --paused: #B45309;
  --paused-soft: #FEF3C7;
  --review: #6D28D9;
  --review-soft: #EDE6FC;
  --hold: #475569;
  --hold-soft: #E2E8F0;
  --shadow: rgba(20, 24, 31, 0.07);

  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-head: "IBM Plex Sans Condensed", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1319;
    --surface: #171C24;
    --surface-hover: #1F2530;
    --border: #2A313D;
    --text: #E8EBF0;
    --text-muted: #8891A0;
    --accent: #5EEAD4;
    --accent-soft: rgba(94, 234, 212, 0.12);
    --active: #4ADE80;
    --active-soft: rgba(74, 222, 128, 0.14);
    --paused: #FBBF24;
    --paused-soft: rgba(251, 191, 36, 0.14);
    --review: #A78BFA;
    --review-soft: rgba(167, 139, 250, 0.14);
    --hold: #94A3B8;
    --hold-soft: rgba(148, 163, 184, 0.14);
    --shadow: rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 8px; order: 2; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--active);
  animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--active-soft); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.brand-label {
  font-family: var(--font-head); font-weight: 700; font-size: 12px;
  letter-spacing: 0.14em; color: var(--active);
}

.title-block { order: 1; flex: 1 1 auto; min-width: 240px; }

h1 {
  margin: 0 0 4px; font-family: var(--font-head); font-weight: 700;
  font-size: clamp(24px, 3.4vw, 30px); letter-spacing: -0.01em; text-wrap: balance;
}

.subtitle { margin: 0; color: var(--text-muted); font-size: 14px; }

.sync-block { order: 3; text-align: right; display: flex; flex-direction: column; gap: 2px; }

.sync-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }

.sync-value {
  font-family: var(--font-mono); font-size: 13px;
  font-variant-numeric: tabular-nums; color: var(--text);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 1px 2px var(--shadow);
}

.stat-label {
  font-family: var(--font-head); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-mono); font-size: 22px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.stat-value.tone-active { color: var(--active); }
.stat-value.tone-paused { color: var(--paused); }
.stat-value.tone-review { color: var(--review); }
.stat-value.tone-accent { color: var(--accent); }

.split {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

.board {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; box-shadow: 0 1px 2px var(--shadow);
}

.board-title {
  padding: 14px 18px; font-family: var(--font-head); font-weight: 700; font-size: 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; gap: 8px;
}

.board-subtitle { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); font-weight: 400; }

.board-hint {
  margin-left: auto; font-size: 11px; color: var(--text-muted); font-weight: 400;
  text-transform: uppercase; letter-spacing: 0.05em;
}

.board-scroll { overflow-x: auto; max-height: 480px; overflow-y: auto; }

.followers-table { width: 100%; border-collapse: collapse; min-width: 320px; }

.followers-table th {
  text-align: left; font-family: var(--font-head); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted);
  padding: 8px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}

.followers-table td {
  padding: 8px 18px; font-family: var(--font-mono); font-size: 13px;
  font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--border);
}

.followers-table tr:last-child td { border-bottom: none; }

.delta-up { color: var(--active); }
.delta-down { color: var(--paused); }
.delta-flat { color: var(--text-muted); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 18px 0; }

.tab {
  font-family: var(--font-head); font-weight: 600; font-size: 12.5px;
  background: transparent; color: var(--text-muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; cursor: pointer;
}

.tab:hover { background: var(--surface-hover); color: var(--text); }

.tab.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.ads-rows { padding: 6px 0; min-width: 480px; }

.ad-row {
  display: grid;
  grid-template-columns: 38px 1.7fr 0.7fr 0.7fr 1fr;
  align-items: center; gap: 10px;
  padding: 8px 18px; border-bottom: 1px solid var(--border);
}

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

.ad-row.is-hidden { display: none; }

.ad-thumb {
  width: 34px; height: 34px; border-radius: 7px; object-fit: cover;
  background: var(--surface-hover); border: 1px solid var(--border);
  flex: 0 0 auto;
}

.ad-thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-size: 11px; font-weight: 700; color: var(--text-muted);
}

.ad-row > span:nth-child(2) { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

.ad-name {
  font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ad-campaign {
  font-size: 11.5px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ad-row-head {
  font-family: var(--font-head); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.ad-row-head .ad-metric { color: var(--text-muted); }

.board-legend {
  padding: 8px 18px 12px; font-size: 11px; color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.ad-metric {
  font-family: var(--font-mono); font-size: 12.5px; font-variant-numeric: tabular-nums;
  color: var(--text-muted); text-align: right;
}

.ad-metric strong { color: var(--text); font-weight: 500; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px;
  border-radius: 999px; font-family: var(--font-head); font-size: 11px; font-weight: 600;
  white-space: nowrap;
}

.pill-dot { width: 6px; height: 6px; border-radius: 50%; }

.pill.status-active { background: var(--active-soft); color: var(--active); }
.pill.status-active .pill-dot { background: var(--active); animation: pulse 2s ease-out infinite; }

.pill.status-paused { background: var(--paused-soft); color: var(--paused); }
.pill.status-paused .pill-dot { background: var(--paused); }

.pill.status-campaign { background: var(--review-soft); color: var(--review); }
.pill.status-campaign .pill-dot { background: var(--review); }

.pill.status-adset { background: var(--hold-soft); color: var(--hold); }
.pill.status-adset .pill-dot { background: var(--hold); }

.empty-row { padding: 18px; color: var(--text-muted); font-size: 13px; }

.footnote { font-size: 11.5px; color: var(--text-muted); }

@media (prefers-reduced-motion: reduce) {
  .live-dot, .pill.status-active .pill-dot { animation: none; }
}
