:root {
  --bg: #f7f9fb;
  --card: #ffffff;
  --border: #e4e7eb;
  --muted: #7b8794;
  --text: #1f2933;
  --text-soft: #364152;
  --accent: #2454ce;
  --active: #2eb872;
  --paused: #c2c9d1;
  --bad: #d64545;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4, h5 { margin: 0 0 .4em; line-height: 1.25; }
img { max-width: 100%; display: block; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--bad); font-size: 14px; }

/* ── topbar ──────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: #fff; border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { font-weight: 700; color: var(--text); }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a {
  padding: 8px 14px; border-radius: 7px; color: var(--muted); font-weight: 500;
}
.tabs a.active, .tabs a:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.logout { color: var(--muted); padding: 6px 10px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 40px; }

/* ── login ───────────────────────────────────────────────────────── */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 80vh; padding: 16px; }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px 28px; width: 100%; max-width: 360px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { font-size: 18px; margin: 0; }
.login-card input {
  padding: 12px 14px; font-size: 18px; letter-spacing: .2em;
  border: 1px solid var(--border); border-radius: 8px; outline: none; text-align: center;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  padding: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: white; border: 0; border-radius: 8px;
}

/* ── totals ──────────────────────────────────────────────────────── */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 720px) { .totals { grid-template-columns: 1fr; } }
.total-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.total-card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-soft); margin-bottom: 12px; }
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi-grid > div { display: flex; flex-direction: column; }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 17px; font-weight: 600; }

/* ── campaigns list ──────────────────────────────────────────────── */
.campaigns { display: flex; flex-direction: column; gap: 16px; }
.campaign {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.campaign.paused { opacity: .8; }
.camp-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.camp-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.camp-title h2 { font-size: 15px; margin: 0; }
.camp-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 8px; font-size: 11px; border-radius: 4px; background: #eef1f5; color: var(--text-soft); white-space: nowrap; }
.badge.muted { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.badge.cta { background: #fef3c7; color: #92400e; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--paused); flex-shrink: 0; }
.status-dot.status-ACTIVE { background: var(--active); }
.status-dot.status-PAUSED, .status-dot.status-CAMPAIGN_PAUSED, .status-dot.status-ADSET_PAUSED { background: var(--paused); }

.camp-kpis { display: flex; gap: 24px; flex-wrap: wrap; margin: 10px 0 12px; padding: 10px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.period { display: flex; flex-direction: column; gap: 2px; }
.period h4 { font-size: 11px; text-transform: uppercase; color: var(--muted); margin: 0 0 2px; }
.period > span:first-of-type { font-weight: 600; font-size: 16px; color: var(--text); }

/* ── ads grid ────────────────────────────────────────────────────── */
.ads-wrap summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 0; }
.ads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 8px; }
.ad-card {
  background: #fafbfc; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  display: flex; flex-direction: column;
}
.ad-card.paused { opacity: .75; }
.ad-thumb { position: relative; display: block; background: #f5f7fa; }
.ad-thumb img { width: 100%; max-height: 320px; object-fit: contain; background: #f5f7fa; }
.play-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.18); color: #fff; font-size: 36px; pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.ad-thumb.has-video:hover .play-overlay { background: rgba(0,0,0,0.32); }
.ad-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.ad-status { display: flex; align-items: center; gap: 6px; }
.ad-name { font-size: 12px; color: var(--muted); margin: 0; font-weight: normal; }
.ad-title { font-size: 14px; font-weight: 600; margin: 0; }
.ad-text { font-size: 13px; color: var(--text-soft); margin: 0; }
.ad-metrics { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.ad-metrics strong { color: var(--text-soft); font-weight: 600; }
.ad-links { display: flex; gap: 12px; font-size: 12px; margin-top: 4px; flex-wrap: wrap; }

/* ── library tab ─────────────────────────────────────────────────── */
.library-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.library-head h2 { font-size: 18px; margin: 0; }
.library-head button {
  padding: 8px 14px; font-size: 13px; cursor: pointer;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
}
.library-head button:hover { background: var(--bg); }
.library-head button:disabled { opacity: .6; cursor: wait; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.lib-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column;
}
.lib-card.paused { opacity: .8; }
.lib-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; gap: 10px; }
.lib-page { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lib-pagepic { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.lib-thumb { display: block; background: #f0f0f0; }
.lib-thumb img { width: 100%; max-height: 320px; object-fit: contain; background: #f0f0f0; }
.lib-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.lib-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.lib-links { display: flex; gap: 12px; font-size: 12px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* ── footer ──────────────────────────────────────────────────────── */
.footer { max-width: 1280px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: 12px; }

/* ── anomalies banner ────────────────────────────────────────────── */
.anomalies { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.anomaly {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 8px; font-size: 14px;
  border-left: 4px solid;
}
.anomaly.sev-critical { background: #fff1f0; border-left-color: var(--bad); color: #6b1f1f; }
.anomaly.sev-warn { background: #fff8e6; border-left-color: #d8a300; color: #6b4f00; }
.anomaly.sev-info { background: #eef5ff; border-left-color: #2454ce; color: #1e3a7d; }
.sev-tag { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.08); letter-spacing: .04em; }
.more-anomalies { margin-top: 4px; }
.more-anomalies summary { cursor: pointer; padding: 4px 10px; color: var(--muted); font-size: 12px; }

/* ── advice card ─────────────────────────────────────────────────── */
.advice-card {
  background: linear-gradient(135deg, #fef9e8 0%, #fffefb 100%);
  border: 1px solid #f3e4a1; border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 20px;
}
.advice-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.advice-head h3 { margin: 0; font-size: 15px; color: #6b4f00; }
.advice-head button {
  font-size: 12px; padding: 5px 10px; border: 1px solid #d8a300; background: #fff; color: #6b4f00;
  border-radius: 6px; cursor: pointer;
}
.advice-head button:hover { background: #fef3c7; }
.advice-head button:disabled { opacity: .6; cursor: wait; }
.advice-summary { font-size: 14px; color: var(--text); margin: 0 0 8px; font-weight: 500; }
.advice-bullets { margin: 0 0 6px; padding-left: 20px; font-size: 14px; color: var(--text-soft); }
.advice-bullets li { margin: 4px 0; }

/* ── per-campagne advies + fatigue badge ─────────────────────────── */
.camp-advice {
  margin: 0 0 12px; padding: 8px 12px; background: #fef9e8; border-left: 3px solid #d8a300;
  border-radius: 4px; font-size: 13px; color: #6b4f00;
}
.badge.fatigue { background: #fef3c7; color: #6b4f00; }

/* ── library: new-badge + filter chip ────────────────────────────── */
.lib-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.filter-chip input { margin: 0; }
.lib-card.is-new { border-color: #f3e4a1; box-shadow: 0 0 0 2px rgba(216, 163, 0, 0.15); }
.new-badge {
  display: inline-block; font-size: 11px; padding: 2px 6px; background: #fef3c7; color: #6b4f00;
  border-radius: 4px; margin-left: 6px; vertical-align: middle;
}

/* ── error ───────────────────────────────────────────────────────── */
.error-wrap { padding: 40px 16px; max-width: 720px; margin: 0 auto; }
.error-wrap pre { background: #fff; border: 1px solid var(--border); padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 12px; }
