/* ============================================================
   CREATIVE DASHBOARD v4 — soft premium
   Світло-сіре полотно, білі картки, що "floating" з мʼякою
   тінню. Більше повітря, скруглені кути.
   Бренд indigo #221EC4. Inter (UI + заголовки) · JetBrains Mono
   (усі дані й цифри).
   ============================================================ */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f3f4f7;
  --surface-3: #e8e9ee;
  --line: #e9e9ee;
  --line-2: #dadae1;

  /* soft elevation tokens */
  --shadow-sm: 0 1px 2px rgba(16,16,20,0.04), 0 1px 3px rgba(16,16,20,0.05);
  --shadow: 0 1px 2px rgba(16,16,20,0.04), 0 12px 28px -16px rgba(16,16,20,0.18);
  --shadow-md: 0 2px 6px rgba(16,16,20,0.05), 0 18px 40px -20px rgba(16,16,20,0.22);
  --shadow-lg: 0 30px 70px -24px rgba(16,16,20,0.30);

  --ink: #101014;
  --ink-2: #4d4d57;
  --ink-3: #80808c;

  --accent: #221ec4;
  --accent-ink: #ffffff;
  --accent-soft: #ebeafc;
  --accent-text: #1b18a0;

  --ok: #1f9d5b;
  --bad: #d4574e;
  --warn: #c08a1d;

  --t-winner: #1f9d5b;
  --t-strong: #221ec4;
  --t-average: #c08a1d;
  --t-weak: #d4574e;
  --t-retest: #7a5af0;
  --t-untested: #5b6b86;
  --t-other: #5b6b86;

  --r: 14px;
  --r-sm: 10px;
  --r-pill: 999px;

  /* one sans family across headings + UI (distinction via weight/size/tracking, not a 2nd font) */
  --brand: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ui: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  /* numbers use the same Inter, with tabular figures — no separate "terminal" font */
  --mono: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.microlabel {
  font-family: var(--ui);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.muted { color: var(--ink-3); font-size: 12.5px; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  height: 38px;
  padding: 0 18px;
  border-radius: var(--r-pill);
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.13s, border-color 0.13s;
  white-space: nowrap;
}
.btn { transition: background 0.13s, border-color 0.13s, box-shadow 0.13s, transform 0.13s; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px rgba(34,30,196,0.18), 0 8px 20px -10px rgba(34,30,196,0.45); }
.btn.primary:hover { background: #1b18a0; box-shadow: 0 2px 4px rgba(34,30,196,0.22), 0 12px 26px -10px rgba(34,30,196,0.5); transform: translateY(-1px); }
.btn.primary:disabled { background: var(--surface-3); color: var(--ink-3); cursor: default; box-shadow: none; transform: none; }
.btn.line { border: 1px solid var(--line-2); background: var(--surface); box-shadow: var(--shadow-sm); }
.btn.line:hover { background: var(--surface-2); }
.btn.line:disabled { color: var(--ink-3); cursor: default; background: var(--surface); }
.danger-text { color: var(--bad); }
.kebab {
  width: 38px;
  height: 38px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  font-size: 16px;
  display: grid;
  place-items: center;
}
.kebab:hover { background: var(--surface-2); }
.small-btn {
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.small-btn:hover { background: var(--surface-2); }
.small-action { height: 34px; }
.reset { font-size: 12.5px; color: var(--accent-text); font-weight: 600; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark, .wm .mk {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--brand);
  font-weight: 700;
  font-size: 16px;
}
.brand-title, .wm h1 {
  margin: 0;
  font-family: var(--brand);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-subtitle, .wm p { margin: 1px 0 0; font-size: 11px; color: var(--ink-3); }

/* ---------- login gate ---------- */
.login-gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 30px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.login-card label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.login-card .brand { margin-bottom: 6px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], input[type="search"], select {
  height: 36px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 0 11px;
  font-size: 13.5px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- app shell ---------- */
.app { min-height: 100vh; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 18px; padding: 16px 28px 12px; flex-wrap: wrap; }
.wm { display: flex; align-items: center; gap: 12px; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 480px; }
.search input {
  width: 100%;
  height: 36px;
  border-radius: var(--r-pill);
  padding: 0 14px 0 38px;
  font-size: 13.5px;
}
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.top-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }

/* account pill + menu */
.acct-wrap { position: relative; }
.acct {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
}
.acct:hover { background: var(--surface-2); }
.acct #accountPillLabel { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.acct .caret { color: var(--ink-3); }
.acct-menu {
  position: absolute;
  top: 44px;
  right: 0;
  z-index: 30;
  width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 12px 32px rgba(16, 16, 20, 0.12);
}
.acct-menu-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 13px; }

.checkbox-list { display: grid; gap: 6px; }
.account-item {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.account-item .item-title { display: block; font-weight: 600; font-size: 13px; }
.account-item .item-meta { display: block; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

.advanced-toggle, .compact-toggle {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 12.5px;
}
.advanced-toggle strong { display: block; font-size: 13px; }
.advanced-toggle small { color: var(--ink-3); }

/* ---------- run banner ---------- */
.run-banner {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 4px 28px;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.run-banner-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.run-stage { font-weight: 600; font-size: 13px; }
.run-meta { font-size: 12px; color: var(--ink-3); }
.run-banner-progress { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 200px; flex: 1; max-width: 420px; }
.progress-track { flex: 1; height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.run-percent { font-size: 12px; color: var(--ink-2); }
.run-banner[data-status="error"] .progress-fill { background: var(--bad); }
.run-banner[data-status="complete"] .progress-fill { background: var(--ok); }

/* ---------- ⋯ actions menu ---------- */
.menu-wrap { position: relative; }
.menu-actions { width: 248px; gap: 4px; padding: 8px; }
.menu-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 500; color: var(--ink);
}
.menu-item:hover { background: var(--surface-2); }
.menu-item:disabled { color: var(--ink-3); cursor: default; background: none; }
.menu-item.danger-text { color: var(--bad); }
.menu-item.danger-text:disabled { color: var(--ink-3); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 6px; }

/* ---------- filter bar (single row) ---------- */
.filterbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 28px 0;
  flex-wrap: wrap;
}
.fb-left { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.fb-right { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.fb-field { display: grid; gap: 5px; }
.fb-field select, .fb-field input { height: 36px; min-width: 150px; max-width: 230px; border-radius: var(--r-pill); }
/* native selects clip long option text with an ellipsis instead of overflowing */
.fb-field select { text-overflow: ellipsis; }
.fb-field.fb-sort select { min-width: 168px; max-width: 200px; }
.rail-dates { display: inline-flex; align-items: center; gap: 6px; }
.rail-dates input { height: 36px; min-width: 0; }
.rail-sep { color: var(--ink-3); }
.filter-status { font-size: 12px; }

/* "Більше фільтрів" trigger + popover */
.filter-wrap { position: relative; align-self: flex-end; }
.filter-more {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: var(--r-pill);
  background: var(--surface); box-shadow: var(--shadow-sm);
  font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.filter-more:hover { background: var(--surface-2); }
.filter-more.has-active { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.filter-more .caret { color: var(--ink-3); }
.fcount {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: var(--r-pill);
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
}
.filters-popover {
  top: 46px; left: 0; right: auto; width: 288px;
  grid-template-columns: 1fr; gap: 12px;
}
.filters-popover .fb-field select, .filters-popover .fb-field input { width: 100%; min-width: 0; max-width: none; }

/* ---------- tier tabs ---------- */
/* results bar: tier tabs (left) + summary metrics (right) in one band */
.resultsbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding: 16px 28px 4px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}
.tab:hover { background: var(--surface-2); }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; }
.tab .c { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.tab.on { background: var(--ink); color: #fff; }
.tab.on .c { color: rgba(255, 255, 255, 0.65); }

/* ---------- summary strip ---------- */
.summary { display: flex; align-items: center; gap: 14px; padding: 0; flex-wrap: wrap; color: var(--ink-2); }
.summary-count { font-weight: 600; font-size: 13px; }
.summary-sep { color: var(--line-2); }
.summary-metric { display: inline-flex; align-items: baseline; gap: 6px; }
.summary-metric strong { font-size: 13.5px; }

/* ---------- gallery ---------- */
.wrap { padding: 10px 28px 70px; position: relative; }
.results { display: grid; gap: 12px; }

.tier-section { margin: 6px 0 8px; }
.tier-section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 6;
  /* tinted colored header — matches the client report. Opaque --bg base so
     cards don't show through while it's sticky. */
  background: linear-gradient(90deg, color-mix(in srgb, var(--tier-color, #000) 9%, transparent), transparent), var(--bg);
  border-left: 4px solid var(--tier-color, var(--ink-3));
  border-radius: 0 10px 10px 0;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.tier-section-head h3 {
  margin: 0;
  font-family: var(--brand);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--tier-color, var(--ink));
}
.tier-section-head span { font-family: var(--mono); font-size: 12.5px; color: var(--ink-3); }
.tier-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tier-color, var(--ink-3)); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
.tier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(182px, 1fr)); gap: 16px; }

.result-card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s, box-shadow 0.16s, transform 0.16s;
}
.result-card:hover { border-color: color-mix(in srgb, var(--accent) 28%, var(--line-2)); box-shadow: var(--shadow-md); transform: translateY(-3px); }
.result-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 4:5 preview box — matches the dominant creative format; portrait ads show in full. */
.thumb { aspect-ratio: 4 / 5; background: var(--surface-2); display: grid; place-items: center; position: relative; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-empty { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.media-badge {
  position: absolute;
  top: 9px;
  left: 9px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: var(--r-pill);
  background: rgba(16, 16, 20, 0.78);
  color: #fff;
}

.plate { padding: 10px 11px 11px; transition: background 0.14s; }
.prow { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 2.5px 0; }
.prow .pl {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
  min-width: 0;            /* allow long result nouns to wrap, not overflow the card */
  overflow-wrap: anywhere;
}
.prow .pv { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; flex: 0 0 auto; }
.prow.cpa .pv { font-size: 17px; font-weight: 700; }
.prow.cpa { padding-bottom: 5px; margin-bottom: 3px; border-bottom: 1px solid var(--line); }
.prow .pv.mut { color: var(--ink-3); font-weight: 500; }
.pmeta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.load-more { margin: 18px auto 0; display: flex; }

.empty-state { padding: 60px 0; text-align: center; color: var(--ink-3); }
.empty-state h2 { font-family: var(--brand); font-weight: 600; }

/* ---------- busy ---------- */
.workspace-busy {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 40px 0;
  justify-content: center;
  background: rgba(255, 255, 255, 0.82);
}
.workspace-busy strong { display: block; }
.workspace-busy span { color: var(--ink-3); font-size: 12.5px; }
.busy-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- drawers ---------- */
.drawer-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(16, 16, 20, 0.38); }
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 50;
  display: grid;
  width: min(760px, 100vw);
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 18px 20px;
}
.drawer-head h2 { margin: 0; font-family: var(--brand); font-weight: 600; font-size: 20px; }
.drawer-body { overflow-y: auto; padding: 18px 20px 24px; }
.settings-body { display: grid; gap: 14px; }

/* panels (inside settings) */
.panel { display: grid; gap: 10px; border: 1px solid var(--line); border-radius: var(--r); padding: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
.panel > label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; }
.panel-title-row h2 { margin: 0; font-family: var(--brand); font-weight: 600; font-size: 15px; }
.runs-quota { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--ink-3); margin-left: 4px; }
.runs-quota.is-full { color: var(--bad); }
.runs-quota-bar { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; margin: 2px 0 4px; }
.runs-quota-bar span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.runs-quota-bar.is-full span { background: var(--bad); }

.compact-list { display: grid; gap: 9px; }
.list-item, .run-item, .user-item { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; background: var(--surface); box-shadow: var(--shadow-sm); }
.item-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.item-title { font-weight: 600; font-size: 13px; }
.item-meta { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.inline-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.run-item.active { border-color: var(--accent); background: var(--accent-soft); }
.mini-progress { margin-top: 8px; height: 4px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.mini-progress span { display: block; height: 100%; background: var(--accent); }
.session-panel { gap: 12px; }
.session-email { font-weight: 600; }
.session-role { font-size: 12px; color: var(--ink-3); }
.session-actions { display: flex; gap: 8px; }
.password-panel { display: grid; gap: 10px; }
.user-list { display: grid; gap: 10px; }
.user-row-head { display: flex; justify-content: space-between; gap: 10px; }
.user-access-note { font-size: 11.5px; }
.bulk-access-actions, .user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.is-granted { border-color: var(--accent); color: var(--accent-text); }
.probe-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.probe-grid label { display: grid; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.probe-result { display: grid; gap: 8px; }
.probe-card { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px; }
.probe-card.good { border-color: var(--ok); }
.probe-card.warning { border-color: var(--warn); }
.probe-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.probe-stat span { display: block; font-size: 10px; color: var(--ink-3); text-transform: uppercase; }
.probe-stat strong { font-family: var(--mono); }
.system-status { display: grid; gap: 6px; }
.status-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.status-row:last-child { border-bottom: 0; }
.status-row strong { font-family: var(--mono); }
.status-row.warning strong { color: var(--warn); }
.status-row.danger strong { color: var(--bad); }
.diagnostic-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- detail drawer ---------- */
.detail-tier { min-height: 22px; }
.detail-layout { display: grid; gap: 16px; }
.detail-media { display: grid; min-height: 240px; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); }
.detail-media img { display: block; max-width: 100%; max-height: 560px; object-fit: contain; }
.detail-empty, .detail-loading { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); padding: 16px; color: var(--ink-3); text-align: center; }
.detail-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.detail-metric { border-radius: var(--r-sm); background: var(--surface-2); padding: 10px; min-width: 0; }
.detail-metric span { display: block; color: var(--ink-3); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.detail-metric strong { display: block; margin-top: 3px; font-family: var(--mono); font-size: 17px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.detail-section-title { margin: 4px 0 0; font-family: var(--brand); font-weight: 600; font-size: 15px; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; height: 26px; padding: 0 11px; border-radius: var(--r-pill); border: 1px solid var(--line-2); background: var(--surface); font-size: 12px; }
.pill.good { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }

.runs-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-sm); }
.runs-table { width: 100%; min-width: 640px; border-collapse: collapse; background: #fff; }
.runs-table th, .runs-table td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: left; vertical-align: top; }
.runs-table th { color: var(--ink-3); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.runs-table td { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.runs-table tr:last-child td { border-bottom: 0; }

.run-hier { display: grid; gap: 4px; max-width: 340px; font-family: var(--ui); }
.run-hier-row { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 8px; align-items: baseline; }
.run-hier-label { color: var(--ink-3); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
.run-hier-value { font-weight: 600; overflow-wrap: anywhere; }
.run-id-chip {
  justify-self: start;
  margin-top: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink-3);
  padding: 2px 7px;
  font-family: var(--mono);
  font-size: 11px;
}
.run-id-chip:hover { color: var(--ink); }

/* ---------- detail: ad selector + selected ad ---------- */
.ad-selector { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.ad-chip {
  flex: 0 0 auto;
  display: grid;
  gap: 2px;
  min-width: 140px;
  max-width: 220px;
  text-align: left;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 8px 10px;
}
.ad-chip:hover { background: var(--surface-2); }
.ad-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.ad-chip-num { font-family: var(--mono); font-size: 10px; color: var(--ink-3); }
.ad-chip-name { font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-chip-spend { font-size: 11px; color: var(--ink-2); }

.ad-panel { display: grid; gap: 12px; }
.hier-block { display: grid; border: 1px solid var(--line-2); border-radius: var(--r-sm); overflow: hidden; }
.hier-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); align-items: baseline; }
.hier-row:nth-child(odd) { background: var(--surface-2); }
.hier-row:last-of-type { border-bottom: 0; }
.hier-label { font-size: 10px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-text); }
.hier-value { font-weight: 600; overflow-wrap: anywhere; }
.hier-block .run-id-chip { margin: 8px 12px 10px; }
.ad-account { font-size: 12px; }
.ad-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.creative-text { display: grid; gap: 8px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); padding: 12px 14px; }
.ct-headline { font-family: var(--brand); font-weight: 600; font-size: 15px; }
.ct-primary { font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; }
.ct-desc { font-size: 12.5px; color: var(--ink-2); }
.ct-link { font-family: var(--mono); font-size: 12px; color: var(--accent-text); overflow-wrap: anywhere; }

.official-preview { display: grid; gap: 8px; justify-items: center; width: 100%; padding: 8px; }
.official-preview-frame { width: 100%; display: grid; place-items: center; overflow: auto; }
.official-preview-frame iframe { max-width: 100%; border: 0; }

/* ---------- client PDF report (hidden on screen, shown only when printing) ---------- */
.client-report { display: none; }

@media print {
  body > *:not(#clientReport) { display: none !important; }
  .client-report { display: block !important; }
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  /* Print background colors + images (creative previews) faithfully. */
  #clientReport, #clientReport * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* Dashboard-style cards, sized for A4. */
  #clientReport .tier-section-head { position: static; padding: 8px 0 6px; margin-bottom: 8px; }
  #clientReport .tier-section-head h3 { font-size: 16px; }
  #clientReport .tier-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  #clientReport .result-card { break-inside: avoid; box-shadow: none; }
  #clientReport .result-card:hover { border-color: var(--line); }
  /* keep the soft look but drop heavy shadows so the PDF stays clean */
  #clientReport .cr-filters, #clientReport .cr-overview, #clientReport .cr-head { box-shadow: none; }
}

.cr-page { font-family: var(--ui); color: #101014; }
/* soft premium hero header — accent wash, no hard rule */
.cr-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, #fff), color-mix(in srgb, var(--accent) 3%, #fff));
  border: 1px solid color-mix(in srgb, var(--accent) 16%, var(--line-2)); border-radius: 18px;
  padding: 26px 28px; margin-bottom: 22px; }
.cr-brand { display: inline-block; font-family: var(--brand); font-weight: 600; color: var(--accent-text);
  background: color-mix(in srgb, var(--accent) 12%, #fff); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; }
.cr-head h1 { font-family: var(--brand); font-weight: 700; font-size: 30px; line-height: 1.1; letter-spacing: -0.025em; margin: 12px 0 0; }
.cr-meta { text-align: right; font-size: 12px; color: var(--ink-2); line-height: 1.6; white-space: nowrap; }
.cr-kpis { display: flex; gap: 14px; margin: 16px 0; }
.cr-kpi { flex: 1; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 14px; }
.cr-kpi span { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
.cr-kpi strong { display: block; margin-top: 4px; font-family: var(--mono); font-size: 20px; }
.cr-note { font-size: 11px; color: var(--ink-3); margin: 0 0 8px; }

/* intro / explanation block — light, modern, generous whitespace */
.cr-intro { margin: 18px 0 4px; }
.cr-lead { font-size: 14px; line-height: 1.6; margin: 0 0 10px; }
.cr-method { font-size: 12.5px; line-height: 1.6; color: var(--ink-2); margin: 0 0 16px; }
.cr-intro h3 { font-family: var(--brand); font-weight: 600; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; margin: 0 0 14px; color: var(--ink-3); }
.cr-filters, .cr-overview { background: #fff; border: 1px solid var(--line-2); border-radius: 16px; padding: 20px 22px; margin-bottom: 16px; break-inside: avoid; box-shadow: 0 1px 2px rgba(16,16,20,0.04), 0 10px 30px -18px rgba(16,16,20,0.18); }
/* filters as wrapping chips — scales to any number of filters */
.cr-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cr-chip { display: inline-flex; align-items: baseline; gap: 7px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 999px; padding: 6px 13px; font-size: 12.5px; line-height: 1.2; }
.cr-chip span { color: var(--ink-3); }
.cr-chip b { font-weight: 600; overflow-wrap: anywhere; }
/* tier distribution mini bar chart */
.cr-tstats { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.cr-bar { display: grid; grid-template-columns: 116px 1fr 30px; align-items: center; gap: 10px; font-size: 12.5px; }
.cr-bar-label { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; white-space: nowrap; }
.cr-bar-track { height: 9px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.cr-bar-fill { display: block; height: 100%; border-radius: 999px; min-width: 3px; }
.cr-bar-n { font-family: var(--mono); font-size: 14px; text-align: right; }
.cr-gallery-title { font-family: var(--brand); font-weight: 600; font-size: 17px; margin: 22px 0 10px; }
/* tinted, colored tier headers inside the report */
#clientReport .tier-section { margin-bottom: 14px; }
#clientReport .tier-section-head { border-bottom: 0; border-left: 4px solid var(--tier-color, var(--ink-3)); padding: 6px 0 6px 12px; margin-bottom: 12px; background: linear-gradient(90deg, color-mix(in srgb, var(--tier-color, #000) 8%, transparent), transparent); border-radius: 0 8px 8px 0; }
#clientReport .result-card { border-radius: var(--r); border: 1px solid var(--line-2); box-shadow: 0 1px 2px rgba(16,16,20,0.04), 0 8px 24px -16px rgba(16,16,20,0.16); overflow: hidden; }
#clientReport .thumb { border-radius: 0; }
#clientReport .cr-gallery-title { font-size: 19px; letter-spacing: -0.01em; margin: 26px 0 12px; }
.cr-table { width: 100%; border-collapse: collapse; }
.cr-table td { border-bottom: 1px solid var(--line); padding: 8px 6px; vertical-align: middle; }
.cr-table tr { break-inside: avoid; }
.cr-idx { width: 24px; color: var(--ink-3); font-family: var(--mono); font-size: 11px; }
.cr-thumb { width: 66px; }
.cr-thumb img { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.cr-noimg { width: 60px; height: 60px; border-radius: 6px; background: var(--surface-2); }
.cr-tier { font-weight: 700; font-size: 13px; }
.cr-period { font-family: var(--mono); font-size: 10px; color: var(--ink-3); }
.cr-num { text-align: right; white-space: nowrap; }
.cr-num .cr-lbl { display: block; font-size: 9px; font-weight: 700; text-transform: uppercase; color: var(--ink-3); }
.cr-num b { font-family: var(--mono); font-size: 14px; }
.cr-foot { margin-top: 16px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 10px; color: var(--ink-3); text-align: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 40px));
  border-radius: var(--r-sm);
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  font-weight: 600;
}

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .topbar, .rail, .rail-filters, .tabs, .summary, .wrap, .run-banner { padding-left: 16px; padding-right: 16px; }
  .run-banner { margin-left: 16px; margin-right: 16px; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .detail-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
