/* ═══════════════════════════════════════════════════════════════
   FACEBOOK ADS — Campaign Management & CAPI Dashboard
   ═══════════════════════════════════════════════════════════════ */

.fb-wrap { padding: var(--space-6); max-width: var(--content-max-width); }

/* ─── Stats Row ─── */
.fb-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); margin-bottom: var(--space-6); }
.fb-stat-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: var(--space-5);
  transition: border-color var(--duration-normal);
}
.fb-stat-card:hover { border-color: var(--border-default); }
.fb-stat-label { font-size: var(--text-xs); color: var(--text-tertiary); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: var(--weight-medium); margin-bottom: var(--space-1); }
.fb-stat-value { font-size: var(--text-2xl); font-weight: var(--weight-semibold); }
.fb-stat-value.accent { color: var(--accent-text); }
.fb-stat-value.success { color: var(--success); }
.fb-stat-value.warning { color: var(--warning); }
.fb-stat-value.error { color: var(--error); }
.fb-stat-sub { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: var(--space-1); }

@media (max-width: 1024px) { .fb-stats { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .fb-stats { grid-template-columns: 1fr; } }

/* ─── View Tabs ─── */
.fb-view-tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-4);
  background: var(--bg-elevated); padding: var(--space-1); border-radius: var(--radius-md); width: fit-content; }
.fb-view-tab {
  padding: var(--space-2) var(--space-4); font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--text-tertiary); background: transparent; border: none;
  border-radius: var(--radius-sm); cursor: pointer; font-family: var(--font-sans);
  transition: all var(--duration-fast);
}
.fb-view-tab:hover { color: var(--text-secondary); }
.fb-view-tab.active { color: var(--text-primary); background: var(--bg-surface); box-shadow: var(--shadow-sm); }

/* ─── Toolbar ─── */
.fb-toolbar {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  margin-bottom: var(--space-4); padding: var(--space-4);
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.fb-toolbar select { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); min-width: 140px; }
.fb-toolbar-actions { display: flex; gap: var(--space-2); margin-left: auto; }

/* ─── Campaign Table ─── */
.fb-table-wrap {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); overflow: hidden;
}
.fb-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.fb-table thead th {
  text-align: left; padding: var(--space-3) var(--space-4); color: var(--text-tertiary);
  font-weight: var(--weight-medium); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.05em; border-bottom: 1px solid var(--border-default);
  background: var(--bg-elevated); position: sticky; top: 0; z-index: 1;
}
.fb-table thead th.sortable { cursor: pointer; user-select: none; }
.fb-table thead th.sortable:hover { color: var(--text-primary); }
.fb-table tbody td {
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary); vertical-align: middle;
}
.fb-table tbody tr:hover td { background: var(--bg-hover); }
.fb-table tbody tr:last-child td { border-bottom: none; }
.fb-table .text-right { text-align: right; }
.fb-table .text-center { text-align: center; }
.fb-table .fb-name-cell { color: var(--text-primary); font-weight: var(--weight-medium); max-width: 280px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Status Badge ─── */
.fb-status {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  border-radius: var(--radius-full); text-transform: uppercase; letter-spacing: 0.03em;
}
.fb-status-active { background: var(--success-muted); color: var(--success); }
.fb-status-paused { background: var(--warning-muted); color: var(--warning); }
.fb-status-archived { background: var(--bg-elevated); color: var(--text-muted); }

.fb-status-dot { width: 6px; height: 6px; border-radius: 50%; }
.fb-status-active .fb-status-dot { background: var(--success); }
.fb-status-paused .fb-status-dot { background: var(--warning); }
.fb-status-archived .fb-status-dot { background: var(--text-muted); }

/* ─── Toggle Switch ─── */
.fb-toggle { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
.fb-toggle input { opacity: 0; width: 0; height: 0; }
.fb-toggle-slider {
  position: absolute; inset: 0; background: var(--bg-elevated); border: 1px solid var(--border-default);
  border-radius: 10px; transition: all var(--duration-fast);
}
.fb-toggle-slider::before {
  content: ''; position: absolute; height: 14px; width: 14px; left: 2px; bottom: 2px;
  background: var(--text-tertiary); border-radius: 50%; transition: all var(--duration-fast);
}
.fb-toggle input:checked + .fb-toggle-slider { background: var(--accent-muted); border-color: var(--accent); }
.fb-toggle input:checked + .fb-toggle-slider::before { transform: translateX(16px); background: var(--accent); }

/* ─── Chart Container ─── */
.fb-chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); margin-bottom: var(--space-6); }
@media (max-width: 1024px) { .fb-chart-row { grid-template-columns: 1fr; } }

.fb-chart-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: var(--space-5);
}
.fb-chart-title { font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--text-secondary); margin-bottom: var(--space-4); }
.fb-chart-canvas { width: 100%; height: 200px; position: relative; }

/* ─── SVG Bar Chart ─── */
.fb-bar { fill: var(--accent); transition: opacity var(--duration-fast); cursor: pointer; }
.fb-bar:hover { opacity: 0.8; }
.fb-bar-label { fill: var(--text-tertiary); font-size: 10px; font-family: var(--font-sans); }
.fb-axis-line { stroke: var(--border-subtle); stroke-width: 1; }
.fb-grid-line { stroke: var(--border-subtle); stroke-width: 0.5; stroke-dasharray: 4,4; }
.fb-bar-value { fill: var(--text-secondary); font-size: 9px; font-family: var(--font-mono); }

/* ─── Line Chart ─── */
.fb-line { fill: none; stroke: var(--accent); stroke-width: 2; }
.fb-line-area { fill: var(--accent-muted); }
.fb-line-dot { fill: var(--accent); r: 3; cursor: pointer; }
.fb-line-dot:hover { r: 5; }
.fb-line-secondary { stroke: var(--warning); }

/* ─── Ad Sets / Ads Cards ─── */
.fb-adset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--space-4); }
.fb-adset-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: var(--space-5);
  transition: border-color var(--duration-normal);
}
.fb-adset-card:hover { border-color: var(--border-default); }
.fb-adset-name { font-size: var(--text-base); font-weight: var(--weight-semibold);
  color: var(--text-primary); margin-bottom: var(--space-2); }
.fb-adset-meta { font-size: var(--text-xs); color: var(--text-tertiary); margin-bottom: var(--space-3); }
.fb-adset-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.fb-adset-metric-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.05em; }
.fb-adset-metric-value { font-size: var(--text-base); font-weight: var(--weight-semibold);
  color: var(--text-primary); }

/* ─── Budget Editor ─── */
.fb-budget-editor {
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.fb-budget-input {
  width: 90px; padding: var(--space-1) var(--space-2); font-size: var(--text-sm);
  text-align: right; font-family: var(--font-mono);
}
.fb-budget-save {
  padding: var(--space-1) var(--space-2); font-size: var(--text-xs);
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  cursor: pointer; font-family: var(--font-sans); font-weight: var(--weight-medium);
}
.fb-budget-save:hover { background: var(--accent-hover); }

/* ─── CAPI Event Log ─── */
.fb-event-log {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); overflow: hidden;
}
.fb-event-log-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-4); border-bottom: 1px solid var(--border-subtle);
}
.fb-event-log-header h3 { font-size: var(--text-base); font-weight: var(--weight-semibold); }
.fb-event-list { max-height: 500px; overflow-y: auto; }
.fb-event-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
}
.fb-event-item:last-child { border-bottom: none; }
.fb-event-item:hover { background: var(--bg-hover); }
.fb-event-name { font-weight: var(--weight-medium); color: var(--text-primary); min-width: 140px; }
.fb-event-id { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.fb-event-time { color: var(--text-tertiary); font-size: var(--text-xs); min-width: 130px; }
.fb-event-status { margin-left: auto; }
.fb-event-success { color: var(--success); }
.fb-event-failed { color: var(--error); }

/* ─── Top Ads View ─── */
.fb-top-ads { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }
.fb-ad-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: var(--space-5);
  transition: border-color var(--duration-normal);
}
.fb-ad-card:hover { border-color: var(--accent); }
.fb-ad-rank { font-size: var(--text-3xl); font-weight: var(--weight-bold);
  color: var(--accent-text); margin-bottom: var(--space-2); }
.fb-ad-name { font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--text-primary); margin-bottom: var(--space-3); }
.fb-ad-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }

/* ─── Loading / Empty ─── */
.fb-loading {
  display: flex; align-items: center; justify-content: center; gap: var(--space-3);
  padding: var(--space-16); color: var(--text-tertiary);
}
.fb-spinner {
  width: 24px; height: 24px; border: 2px solid var(--border-default);
  border-top-color: var(--accent); border-radius: 50%;
  animation: fbSpin 0.6s linear infinite;
}
@keyframes fbSpin { to { transform: rotate(360deg); } }

.fb-empty {
  text-align: center; padding: var(--space-12) var(--space-8);
}
.fb-empty-icon { font-size: 48px; margin-bottom: var(--space-4); opacity: 0.3; }
.fb-empty-title { font-size: var(--text-lg); font-weight: var(--weight-semibold);
  color: var(--text-secondary); margin-bottom: var(--space-2); }
.fb-empty-desc { font-size: var(--text-sm); color: var(--text-tertiary); max-width: 400px; margin: 0 auto; }

/* ─── Error Banner ─── */
.fb-error-banner {
  background: var(--error-muted); border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4); font-size: var(--text-sm); color: var(--error);
  display: flex; align-items: center; gap: var(--space-2);
}
.fb-error-banner .fb-error-dismiss {
  margin-left: auto; background: none; border: none; color: var(--error);
  cursor: pointer; font-size: var(--text-base); padding: 2px 6px;
}

/* ─── Token Status ─── */
.fb-token-status {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); color: var(--text-tertiary);
  padding: var(--space-1) var(--space-3); background: var(--bg-elevated);
  border-radius: var(--radius-full);
}
.fb-token-dot { width: 6px; height: 6px; border-radius: 50%; }
.fb-token-dot.connected { background: var(--success); }
.fb-token-dot.expired { background: var(--error); }

/* ─── Section Headers ─── */
.fb-section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--space-4);
}
.fb-section-title { font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text-primary); }
.fb-section-subtitle { font-size: var(--text-xs); color: var(--text-tertiary); }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .fb-wrap { padding: var(--space-4); }
  .fb-stats { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
  .fb-view-tabs { flex-wrap: wrap; width: 100%; }
  .fb-toolbar { flex-direction: column; align-items: stretch; }
  .fb-toolbar-actions { margin-left: 0; justify-content: flex-end; }
  .fb-chart-row { grid-template-columns: 1fr; }
  .fb-table { font-size: var(--text-xs); }
  .fb-table thead th, .fb-table tbody td { padding: var(--space-2) var(--space-3); }
}
