/* ============================================================================
   Reports page — macro performance scanner across Meta accounts.
   Redesign 2026-05-19: state-of-the-art data dashboard treatment
   modeled on Linear / Stripe / Vercel — strict hierarchy, generous
   whitespace, sticky toolbar, tabular numerals, refined micro-pills.
   ============================================================================ */

/* ---------- Design tokens ---------------------------------------------------
   Single source of truth for the whole Reports surface. Everything below
   references these — change a token once, the whole page updates. */
.reports-page {
    --rp-bg:            #f7f7fb;
    --rp-surface:       #ffffff;
    --rp-surface-2:     #fafafd;
    --rp-border:        #ececf3;
    --rp-border-strong: #d4d4e0;
    --rp-text:          #0e0e1f;
    --rp-text-2:        #4a4a6a;
    --rp-text-3:        #6e6e8a;
    --rp-text-muted:    #9494a8;

    --rp-accent:        #5B53E8;
    --rp-accent-bg:     rgba(99,102,241,0.06);
    --rp-accent-strong: #4f46e5;

    --rp-good:          #047857;
    --rp-good-bg:       #ecfdf5;
    --rp-good-border:   #bbf7d0;
    --rp-warn:          #c2410c;
    --rp-warn-bg:       #fff7ed;
    --rp-warn-border:   #fed7aa;
    --rp-bad:           #b91c1c;
    --rp-bad-bg:        #fef2f2;
    --rp-bad-border:    #fecaca;
    --rp-info:          #1d4ed8;
    --rp-info-bg:       #eff6ff;
    --rp-info-border:   #bfdbfe;
    --rp-mauve:         #86198f;
    --rp-mauve-bg:      #fdf4ff;
    --rp-mauve-border:  #f5d0fe;

    --rp-radius-sm:     6px;
    --rp-radius:        10px;
    --rp-radius-lg:     14px;
    --rp-shadow-1:      0 1px 2px rgba(0,0,0,0.04);
    --rp-shadow-2:      0 4px 16px rgba(15, 15, 30, 0.04);
    --rp-shadow-hover:  0 8px 28px rgba(15, 15, 30, 0.08);

    /* Page chrome — centered 1320px content column (DESIGN_SYSTEM.md standing
       rule: every non-full-width page, Reports included, uses max-width 1320px
       + margin auto; only the editor/Studio work surfaces are full-bleed). */
    max-width: 1320px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 28px 80px;
    font-size: 13px;
    color: var(--rp-text);
    box-sizing: border-box;
    font-feature-settings: "tnum" 1, "ss01" 1;
}

/* ---------- Header (title + sub) ------------------------------------------- */
.reports-header {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}
.reports-title h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0 0 4px 0;
    color: var(--rp-text);
    line-height: 1.15;
}
.reports-sub {
    font-size: 13px;
    color: var(--rp-text-3);
    line-height: 1.55;
    max-width: 720px;
    margin: 0;
}

/* ---------- KPI summary strip ----------------------------------------------
   4 cards across — Cost 7d · Rev 7d · Blended ROAS · Smart-tag breakdown.
   Lead with the high-level "are we OK?" answer before the user has to
   scan the table. Mirrors the Stripe Dashboard / Linear analytics
   pattern of leading with summary KPIs. */
.reports-kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.reports-kpi-card {
    background: var(--rp-surface);
    border: 1px solid var(--rp-border);
    border-radius: var(--rp-radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--rp-shadow-1);
    transition: box-shadow 0.18s, border-color 0.18s;
}
.reports-kpi-card:hover {
    box-shadow: var(--rp-shadow-2);
    border-color: var(--rp-border-strong);
}

/* Per-account fatigue rollup — one row per Meta account; reuses the fatigue
   badge tints (--rp-bad/--rp-warn) so the worst account is obvious at a glance. */
.reports-acct-health-strip { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.reports-acct-health-strip:empty { display: none; margin-bottom: 0; }
.reports-acct-health {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: var(--rp-surface);
    border: 1px solid var(--rp-border);
    border-radius: var(--rp-radius);
}
.reports-acct-health-name {
    flex: 0 0 auto;
    min-width: 120px;
    max-width: 240px;
    font-size: 13px;
    font-weight: 600;
    color: var(--rp-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* now a click-to-filter button → show all of this account's ads */
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}
.reports-acct-health-name:hover { color: var(--rp-accent-strong, #4f46e5); text-decoration: underline; }
.reports-acct-health-name:focus-visible { outline: 2px solid var(--rp-accent, #5B53E8); outline-offset: 2px; border-radius: 4px; }
.reports-acct-health-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.reports-acct-health-chip {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 10px;
    white-space: nowrap;
    /* click-to-filter buttons → jump to this account + problem */
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.45;
    transition: filter .12s ease, box-shadow .12s ease;
}
.reports-acct-health-chip:hover { filter: brightness(0.95); }
.reports-acct-health-chip:focus-visible { outline: 2px solid var(--rp-accent, #5B53E8); outline-offset: 1px; }
.reports-acct-health-chip--errors,
.reports-acct-health-chip--kill,
.reports-acct-health-chip--severe { background: var(--rp-bad-bg, #fef2f2); color: var(--rp-bad, #b91c1c); }
.reports-acct-health-chip--moderate { background: var(--rp-warn-bg, #fff7ed); color: var(--rp-warn, #c2410c); }
.reports-acct-health-chip--mild,
.reports-acct-health-chip--atrisk { background: var(--rp-surface-2, #f4f4f6); color: var(--rp-text-3, #6e6e8a); }
.reports-acct-health-chip--atrisk { font-weight: 600; }
.reports-acct-health-ok { font-size: 12px; font-weight: 600; color: var(--rp-good, #15803d); }
.reports-kpi-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--rp-text-muted);
}
.reports-kpi-value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--rp-text);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.reports-kpi-meta {
    font-size: 11px;
    color: var(--rp-text-3);
    line-height: 1.4;
    font-weight: 500;
}
.reports-kpi-roas-good   { color: var(--rp-good);  }
.reports-kpi-roas-warn   { color: var(--rp-warn);  }
.reports-kpi-roas-bad    { color: var(--rp-bad);   }

/* Smart-tag breakdown card — 4 mini-segments stacked horizontally inside
   the value slot. Each segment shows its tag count colored by tag class. */
.reports-kpi-tag-segments {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.reports-kpi-tag-seg {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 4px 9px;
    border-radius: 8px;
    font-size: 11.5px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    background: var(--rp-surface-2);
    color: var(--rp-text-2);
    border: 1px solid var(--rp-border);
}
.reports-kpi-tag-seg-num {
    font-size: 14px;
    font-weight: 800;
    color: var(--rp-text);
}
.reports-kpi-tag-seg-kill   .reports-kpi-tag-seg-num { color: var(--rp-bad);  }
.reports-kpi-tag-seg-scale  .reports-kpi-tag-seg-num { color: var(--rp-good); }
.reports-kpi-tag-seg-watch  .reports-kpi-tag-seg-num { color: var(--rp-warn); }
.reports-kpi-tag-seg-hold   .reports-kpi-tag-seg-num { color: var(--rp-info); }

/* ---------- Sticky toolbar -------------------------------------------------
   Sits above the chips + table. Sticks to the top on scroll so filters
   stay reachable as the user scrolls through long tables. */
.reports-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: var(--rp-surface);
    border: 1px solid var(--rp-border);
    border-radius: var(--rp-radius);
    box-shadow: var(--rp-shadow-1);
    position: sticky;
    top: 0;
    z-index: 10;
}
.reports-tool-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.reports-tool-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--rp-text-muted);
    white-space: nowrap;
}
.reports-segmented {
    display: inline-flex;
    background: var(--rp-bg);
    padding: 3px;
    border-radius: 8px;
    gap: 0;
    border: 1px solid var(--rp-border);
}
.reports-seg-btn {
    background: transparent;
    border: none;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--rp-text-3);
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}
.reports-seg-btn:hover { color: var(--rp-text); }
.reports-seg-btn.active {
    background: var(--rp-surface);
    color: var(--rp-accent);
    box-shadow: var(--rp-shadow-1);
}
.reports-input {
    background: var(--rp-surface);
    border: 1px solid var(--rp-border-strong);
    border-radius: var(--rp-radius-sm);
    padding: 6px 10px;
    font-size: 12.5px;
    color: var(--rp-text);
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.reports-input:focus {
    outline: none;
    border-color: var(--rp-accent);
    box-shadow: var(--focus-ring);
}
.reports-input-num { width: 64px; text-align: right; }
.reports-input-select { min-width: 200px; }
/* Toolbar search + sort (2026-07 polish). Sort stays compact — the option
   labels carry the direction; search clears via the native ✕ / Esc. */
.reports-input-search { width: 190px; }
.reports-input-search::-webkit-search-cancel-button { cursor: pointer; }
.reports-input-sort { min-width: 170px; }
.reports-tool-suffix {
    font-size: 11.5px;
    color: var(--rp-text-3);
    font-weight: 500;
}

/* Toolbar right cluster — cache pill + rebuild button sit together. */
.reports-toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}
.reports-cache-pill {
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 600;
    background: var(--rp-surface-2);
    color: var(--rp-text-3);
    white-space: nowrap;
    border: 1px solid var(--rp-border);
}
.reports-cache-pill.reports-cache-fresh {
    background: var(--rp-good-bg);
    color: var(--rp-good);
    border-color: var(--rp-good-border);
}
.reports-cache-pill.reports-cache-cached {
    background: var(--rp-info-bg);
    color: var(--rp-info);
    border-color: var(--rp-info-border);
}
.reports-cache-pill.reports-cache-stale {
    background: var(--rp-bad-bg);
    color: var(--rp-bad);
    border-color: var(--rp-bad-border);
}
.reports-cache-pill:empty { display: none; }

/* Data-sync health pill — same shape as the cache pill; shown only on problems.
   Clickable → the detail popover below it. */
.reports-sync-wrap { position: relative; display: inline-flex; }
.reports-sync-pill {
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid var(--rp-border, #e5e7eb);
    background: var(--rp-surface-2, #f4f4f6);
    color: var(--rp-text-3, #6b7280);
}
.reports-sync-pill:hover { filter: brightness(0.97); }
.reports-sync-pill.reports-sync-error {
    background: var(--rp-warn-bg, #fff4e6);
    color: var(--rp-warn, #b4640a);
    border-color: var(--rp-warn-border, #ffe2bf);
}
.reports-sync-pill.reports-sync-relink {
    background: var(--rp-bad-bg, #fdecea);
    color: var(--rp-bad, #c0392b);
    border-color: var(--rp-bad-border, #f5c6cb);
}
.reports-sync-pill:empty { display: none; }

/* Per-account detail popover (anchored under the pill) */
.reports-sync-pop {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 60;
    width: 290px;
    max-height: 340px;
    overflow-y: auto;
    padding: 10px;
    background: var(--rp-surface, #fff);
    border: 1px solid var(--rp-border, #e5e7eb);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.reports-sync-pop.open { display: block; }
.reports-sync-pop-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--rp-text-3, #6b7280);
    margin-bottom: 8px;
}
.reports-sync-pop-list { display: flex; flex-direction: column; gap: 8px; }
.reports-sync-pop-item {
    padding: 8px 10px;
    border: 1px solid var(--rp-border, #e5e7eb);
    border-radius: 8px;
    background: var(--rp-surface-2, #f9fafb);
}
.reports-sync-pop-row1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}
.reports-sync-pop-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--rp-text, #111827);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reports-sync-pop-badge {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    white-space: nowrap;
}
.reports-sync-pop-badge.is-relink { background: var(--rp-bad-bg, #fdecea); color: var(--rp-bad, #c0392b); }
.reports-sync-pop-badge.is-error { background: var(--rp-warn-bg, #fff4e6); color: var(--rp-warn, #b4640a); }
.reports-sync-pop-msg { font-size: 12px; color: var(--rp-text-3, #6b7280); line-height: 1.35; }
.reports-sync-pop-meta { font-size: 11px; color: var(--rp-text-3, #9ca3af); margin-top: 4px; }
.reports-sync-pop-relink {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--rp-accent, #2433ff);
    text-decoration: none;
}
.reports-sync-pop-relink:hover { text-decoration: underline; }

/* Fix-it attention banner — above the table when a problem filter is active.
   Amber for fatigue, red for kill; reuses the --rp-warn / --rp-bad palette. */
.reports-attention-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
    border: 1px solid var(--rp-border, #e5e7eb);
    border-left-width: 3px;
    border-radius: 10px;
    background: var(--rp-surface, #fff);
}
.reports-attention-banner.is-fatigue {
    border-left-color: var(--rp-warn, #b4640a);
    background: var(--rp-warn-bg, #fff4e6);
}
.reports-attention-banner.is-kill {
    border-left-color: var(--rp-bad, #c0392b);
    background: var(--rp-bad-bg, #fdecea);
}
/* At-risk = early warning (not failing yet) → quiet muted-gray tone, matching the
   at-risk chip/badge/ETA-hint treatment. Deliberately calmer than fatigue/kill. */
.reports-attention-banner.is-atrisk {
    border-left-color: var(--rp-text-3, #6e6e8a);
    background: var(--rp-surface-2, #fafafd);
}
.reports-attention-icon { flex: 0 0 auto; display: flex; }
.reports-attention-banner.is-fatigue .reports-attention-icon { color: var(--rp-warn, #b4640a); }
.reports-attention-banner.is-kill .reports-attention-icon { color: var(--rp-bad, #c0392b); }
.reports-attention-banner.is-atrisk .reports-attention-icon { color: var(--rp-text-3, #6e6e8a); }
.reports-attention-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.reports-attention-text strong { font-size: 14px; color: var(--rp-text, #111827); }
.reports-attention-sub { font-size: 12px; color: var(--rp-text-3, #6b7280); line-height: 1.35; }
.reports-attention-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.reports-attention-btn {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    color: #fff;
    white-space: nowrap;
    background: var(--rp-warn, #b4640a);
}
.reports-attention-banner.is-kill .reports-attention-btn { background: var(--rp-bad, #c0392b); }
.reports-attention-banner.is-atrisk .reports-attention-btn { background: var(--rp-text-3, #6e6e8a); }
.reports-attention-btn:hover { filter: brightness(0.95); }
/* Secondary (ghost) bulk action — sits beside the primary refresh button */
.reports-attention-btn-ghost {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--rp-border, #e5e7eb);
    background: var(--rp-surface, #fff);
    color: var(--rp-text, #111827);
    white-space: nowrap;
}
.reports-attention-btn-ghost:hover { background: var(--rp-surface-2, #f4f4f6); }
.reports-attention-btn-ghost:disabled { opacity: 0.6; cursor: default; }

/* "Needs attention" triage summary (All view) — accent-tinted attention-banner so
   it reads as the overview/lead, distinct from the red/amber/gray per-filter alarms.
   The count pills carry the per-problem tints + jump to each filter on click. */
.reports-attention-banner.reports-triage-summary {
    border-left-color: var(--rp-accent, #5B53E8);
    background: var(--rp-accent-bg, rgba(99,102,241,0.06));
}
.reports-attention-banner.reports-triage-summary .reports-attention-icon { color: var(--rp-accent, #5B53E8); }
.reports-triage-pills { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.reports-triage-pill {
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    padding: 5px 11px;
    border-radius: 999px;
    border: 1px solid transparent;
    white-space: nowrap;
    transition: filter 0.12s ease;
}
.reports-triage-pill:hover { filter: brightness(0.96); }
.reports-triage-pill--errors  { background: var(--rp-bad-bg,   #fef2f2); color: var(--rp-bad,   #b91c1c); border-color: var(--rp-bad-border,   #fecaca); }
.reports-triage-pill--kill    { background: var(--rp-bad-bg,   #fef2f2); color: var(--rp-bad,   #b91c1c); border-color: var(--rp-bad-border,   #fecaca); }
.reports-triage-pill--fatigue { background: var(--rp-mauve-bg, #fdf4ff); color: var(--rp-mauve, #86198f); border-color: var(--rp-mauve-border, #f5d0fe); }
.reports-triage-pill--atrisk  { background: var(--rp-surface-2, #fafafd); color: var(--rp-text-3, #6e6e8a); border-color: var(--rp-border, #ececf3); }

.reports-refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: var(--rp-text);
    color: #fff;
    border: 1px solid var(--rp-text);
    border-radius: var(--rp-radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.12s;
    font-family: inherit;
}
.reports-refresh-btn:hover {
    background: #1a1a2e;
    transform: translateY(-1px);
}
.reports-refresh-btn:active { transform: translateY(0); }
.reports-refresh-btn svg { display: block; }

/* Export CSV — secondary ghost variant of the toolbar button (sits left of Rebuild). */
.reports-export-btn {
    background: #fff;
    color: var(--rp-text);
    border-color: var(--rp-border-strong);
}
.reports-export-btn:hover {
    background: var(--rp-bg);
}

/* ---------- Tag filter chips (refined micro-pills) -------------------------
   Smaller, lighter, less shouty. Active state uses a colored border + tint
   instead of a heavy filled background. */
.reports-chipbar {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    flex-wrap: wrap;
    align-items: center;
}
.reports-chipbar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--rp-text-muted);
    margin-right: 4px;
}
.reports-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    background: var(--rp-surface);
    border: 1px solid var(--rp-border);
    border-radius: 18px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--rp-text-3);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.reports-chip:hover {
    border-color: var(--rp-border-strong);
    color: var(--rp-text);
}
.reports-chip-count {
    background: var(--rp-bg);
    color: var(--rp-text-3);
    padding: 0 7px;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 18px;
    text-align: center;
}
.reports-chip-all.active        { background: var(--rp-text); color: #fff; border-color: var(--rp-text); }
.reports-chip-all.active        .reports-chip-count { background: rgba(255,255,255,0.18); color: #fff; }
.reports-chip-errors.active     { background: var(--rp-bad-bg);   color: var(--rp-bad);   border-color: var(--rp-bad-border);   }
.reports-chip-errors.active     .reports-chip-count { background: var(--rp-bad-border);   color: var(--rp-bad);   }
.reports-chip-kill.active       { background: var(--rp-bad-bg);   color: var(--rp-bad);   border-color: var(--rp-bad-border);   }
.reports-chip-kill.active       .reports-chip-count { background: var(--rp-bad-border);   color: var(--rp-bad);   }
.reports-chip-watch.active      { background: var(--rp-warn-bg);  color: var(--rp-warn);  border-color: var(--rp-warn-border);  }
.reports-chip-watch.active      .reports-chip-count { background: var(--rp-warn-border);  color: var(--rp-warn);  }
.reports-chip-scale.active      { background: var(--rp-good-bg);  color: var(--rp-good);  border-color: var(--rp-good-border);  }
.reports-chip-scale.active      .reports-chip-count { background: var(--rp-good-border);  color: var(--rp-good);  }
.reports-chip-hold.active       { background: var(--rp-info-bg);  color: var(--rp-info);  border-color: var(--rp-info-border);  }
.reports-chip-hold.active       .reports-chip-count { background: var(--rp-info-border);  color: var(--rp-info);  }
.reports-chip-fatigue.active    { background: var(--rp-mauve-bg); color: var(--rp-mauve); border-color: var(--rp-mauve-border); }
.reports-chip-fatigue.active    .reports-chip-count { background: var(--rp-mauve-border); color: var(--rp-mauve); }
/* At-risk = early warning. Muted gray (matches the at-risk badge/ETA hint
   treatment — deliberately quiet, not an alarm), filled like the All chip so
   it still reads as the active selection. */
.reports-chip-atrisk.active     { background: var(--rp-text-3); color: #fff; border-color: var(--rp-text-3); }
.reports-chip-atrisk.active     .reports-chip-count { background: rgba(255,255,255,0.20); color: #fff; }

/* Row-count summary sitting between chips and table — "Showing 47 of 128
   entities · Filter: Losing money". Light, informational, easy to scan. */
.reports-rowcount {
    font-size: 11.5px;
    color: var(--rp-text-3);
    margin-bottom: 8px;
    padding: 0 4px;
    font-weight: 500;
}
.reports-rowcount strong {
    color: var(--rp-text);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ---------- Fatigue badge (entity cell) ------------------------------------ */
.reports-fatigue-badge {
    margin-top: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    background: var(--rp-mauve-bg);
    color: var(--rp-mauve);
    border: 1px solid var(--rp-mauve-border);
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 700;
}
.reports-fatigue-badge::before { content: '⚡'; font-size: 11px; }
/* Severity tints (escalating): mild = neutral gray, moderate = amber, severe = red.
   The small leading chip names the tier. Reuses the shared --rp-warn/--rp-bad palette. */
.reports-fatigue-badge--mild {
    background: var(--rp-surface-2, #f4f4f6);
    color: var(--rp-text-3, #6b7280);
    border-color: var(--rp-border, #e5e7eb);
}
.reports-fatigue-badge--moderate {
    background: var(--rp-warn-bg, #fff7ed);
    color: var(--rp-warn, #c2410c);
    border-color: var(--rp-warn-border, #ffe2bf);
}
.reports-fatigue-badge--severe {
    background: var(--rp-bad-bg, #fef2f2);
    color: var(--rp-bad, #b91c1c);
    border-color: var(--rp-bad-border, #f5c6cb);
}
.reports-fatigue-sev {
    text-transform: uppercase;
    font-size: 8.5px;
    letter-spacing: 0.04em;
    font-weight: 800;
    padding: 1px 5px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.08);
}
/* "fatiguing N days" duration chip (from the cron's fatigue history) — a trailing
   pill in the same tinted-chip style as the severity tier chip; the flowads-style
   "how long" signal. Hidden until reports.php emits row.fatigue_days. */
.reports-fatigue-dur {
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.08);
}
/* Delivery-issue badge — Meta effective_status problems (disapproved / limited /
   in-review / billing). Same chip language as the fatigue badge; tinted by kind
   (bad=red, warn=amber, info=neutral). Reuses the shared --rp-warn/--rp-bad palette. */
.reports-delivery-badge {
    margin-top: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 700;
    cursor: help;
}
.reports-delivery-badge::before { content: '⚠'; font-size: 11px; }
.reports-delivery-badge--bad {
    background: var(--rp-bad-bg, #fef2f2);
    color: var(--rp-bad, #b91c1c);
    border: 1px solid var(--rp-bad-border, #f5c6cb);
}
.reports-delivery-badge--warn {
    background: var(--rp-warn-bg, #fff7ed);
    color: var(--rp-warn, #c2410c);
    border: 1px solid var(--rp-warn-border, #ffe2bf);
}
.reports-delivery-badge--info {
    background: var(--rp-surface-2, #f4f4f6);
    color: var(--rp-text-3, #6b7280);
    border: 1px solid var(--rp-border, #e5e7eb);
}
/* Early-warning "days until fatigue" — a MUTED heads-up, not an alarm. */
.reports-fatigue-eta {
    margin-top: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--rp-text-3, #6e6e8a);
    cursor: help;
}
.reports-fatigue-eta::before {
    content: '⧗';
    font-size: 11px;
    opacity: 0.85;
}

/* ---------- Loading / empty / error ---------------------------------------- */
.reports-loading {
    text-align: center;
    padding: 22px 16px;
    color: var(--rp-text-3);
    font-size: 13px;
    background: var(--rp-surface);
    border: 1px solid var(--rp-border);
    border-radius: var(--rp-radius);
}

/* Skeleton loading rows — animated bones matching the real table layout.
   Fades in/out via a subtle keyframe so the page never looks "stuck". */
.reports-skeleton {
    background: var(--rp-surface);
    border: 1px solid var(--rp-border);
    border-radius: var(--rp-radius);
    overflow: hidden;
    box-shadow: var(--rp-shadow-1);
}
.reports-skel-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--rp-border);
    align-items: center;
}
.reports-skel-row:last-child { border-bottom: none; }
.reports-skel-bone {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #ececf3 0%, #f7f7fb 50%, #ececf3 100%);
    background-size: 200% 100%;
    animation: reports-skel-shimmer 1.6s linear infinite;
}
.reports-skel-bone-tall { height: 28px; }
.reports-skel-bone-narrow { width: 60%; }
@keyframes reports-skel-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.reports-empty {
    text-align: center;
    padding: 48px 24px;
    background: var(--rp-surface);
    border: 1px solid var(--rp-border);
    border-radius: var(--rp-radius);
    box-shadow: var(--rp-shadow-1);
}
.reports-empty-icon {
    width: 56px; height: 56px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: var(--rp-accent-bg);
    display: flex; align-items: center; justify-content: center;
    color: var(--rp-accent);
}
.reports-empty h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--rp-text);
    margin: 0 0 6px 0;
}
.reports-empty p {
    font-size: 13px;
    color: var(--rp-text-3);
    line-height: 1.5;
    margin: 0 auto;
    max-width: 480px;
}
.reports-empty p a {
    color: var(--rp-accent);
    font-weight: 600;
    text-decoration: none;
}
.reports-empty p a:hover { text-decoration: underline; }

.reports-error {
    background: var(--rp-bad-bg);
    border-color: var(--rp-bad-border);
    color: var(--rp-bad);
}

/* ---------- Table ---------------------------------------------------------- */
.reports-table-host {
    overflow-x: auto;
    border-radius: var(--rp-radius);
    border: 1px solid var(--rp-border);
    box-shadow: var(--rp-shadow-1);
    background: var(--rp-surface);
}
.reports-table {
    width: 100%;
    background: var(--rp-surface);
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12.5px;
}
.reports-table thead th {
    text-align: left;
    padding: 14px 16px;
    background: var(--rp-surface-2);
    border-bottom: 1px solid var(--rp-border);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--rp-text-muted);
    white-space: nowrap;
    position: sticky;
    top: 56px;        /* slides under the sticky toolbar */
    z-index: 5;
}
.reports-table td {
    padding: 16px 16px;
    border-bottom: 1px solid var(--rp-border);
    vertical-align: middle;
}
.reports-table tr:last-child td { border-bottom: none; }
.reports-table tr.reports-row { transition: background 0.15s; }
.reports-table tr.reports-row:hover { background: var(--rp-surface-2); }
/* Subtle striping to help the eye track rows on long tables. */
.reports-table tbody tr:nth-child(even):not(:hover) {
    background: rgba(247, 247, 251, 0.5);
}

/* Left-edge tag accent — a 3px colored bar on hover only (cleaner than
   the previous always-on 4px). */
.reports-table tr.reports-row-tag-kill  td:first-child { box-shadow: inset 3px 0 0 var(--rp-bad);   }
.reports-table tr.reports-row-tag-scale td:first-child { box-shadow: inset 3px 0 0 var(--rp-good);  }
.reports-table tr.reports-row-tag-watch td:first-child { box-shadow: inset 3px 0 0 var(--rp-warn);  }
.reports-table tr.reports-row-tag-hold  td:first-child { box-shadow: inset 3px 0 0 #cbd5e1;         }

/* Entity cell */
.reports-td-entity {
    min-width: 240px;
    max-width: 360px;
    padding-left: 20px !important;
}
.reports-entity-name {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--rp-text);
    margin-bottom: 4px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reports-entity-context {
    font-size: 11px;
    line-height: 1.45;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--rp-text-muted);
    margin-top: 2px;
}
.reports-entity-acct {
    /* Indigo pill matching the briefing treatment so the account name
       reads as the grouping key at a glance. */
    display: inline-block;
    background: var(--rp-accent-strong);
    color: #fff;
    font-weight: 700;
    padding: 1px 9px;
    border-radius: 10px;
    font-size: 10.5px;
    letter-spacing: 0.01em;
    vertical-align: 1px;
}
.reports-entity-context-sep {
    color: var(--rp-border-strong);
    margin: 0 6px;
}
.reports-entity-parents-inline { color: var(--rp-text-muted); }

/* Window cells — vertical hierarchy: Cost (big), CPA/ROAS pills, tertiary line. */
.reports-td-window {
    width: 180px;
    padding: 12px 14px;
    vertical-align: middle;
    position: relative;
}
.reports-th-window-3d, .reports-td-window-3d {
    background: var(--rp-accent-bg);
}
.reports-th-window-7d, .reports-td-window-7d {
    background: rgba(99,102,241,0.025);
}
.reports-th-window-30d, .reports-td-window-30d { background: transparent; }
.reports-table tr.reports-row:hover .reports-td-window-3d { background: rgba(99,102,241,0.10); }
.reports-table tr.reports-row:hover .reports-td-window-7d { background: rgba(99,102,241,0.04); }

.reports-window-primary {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.reports-metric-main {
    font-size: 17px;
    font-weight: 800;
    color: var(--rp-text);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.reports-metric-rev {
    font-size: 11.5px;
    color: var(--rp-text-2);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-bottom: 6px;
    line-height: 1.3;
}
.reports-metric-rev-lbl,
.reports-metric-cost-lbl {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--rp-text-muted);
    font-weight: 700;
    margin-right: 4px;
}
.reports-window-secondary {
    display: flex; gap: 5px; flex-wrap: wrap;
    margin-bottom: 6px;
}
.reports-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 10.5px;
    font-weight: 600;
    background: var(--rp-bg);
    color: var(--rp-text-2);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    border: 1px solid transparent;
}
.reports-pill-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.65;
    font-weight: 700;
}
.reports-pill-val { font-weight: 800; }
.reports-pill-good    { background: var(--rp-good-bg); color: var(--rp-good); border-color: var(--rp-good-border); }
.reports-pill-warn    { background: var(--rp-warn-bg); color: var(--rp-warn); border-color: var(--rp-warn-border); }
.reports-pill-bad     { background: var(--rp-bad-bg);  color: var(--rp-bad);  border-color: var(--rp-bad-border);  }
.reports-pill-neutral { background: var(--rp-bg);      color: var(--rp-text-2); }

.reports-window-tertiary {
    font-size: 10.5px;
    color: var(--rp-text-3);
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
}
.reports-tertiary-sep { color: var(--rp-border-strong); }
.reports-freq-high {
    color: var(--rp-bad);
    font-weight: 700;
}

/* Trend arrows */
.reports-trend {
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}
.reports-trend-good { color: var(--rp-good); }
.reports-trend-bad  { color: var(--rp-bad);  }
.reports-trend-flat { color: var(--rp-text-muted); }

/* Tag cell */
.reports-td-tag { width: 180px; }
.reports-tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
    border: 1px solid transparent;
    text-transform: uppercase;
}
.reports-tag-pill::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}
.reports-tag-kill  { background: var(--rp-bad-bg);  color: var(--rp-bad);  border-color: var(--rp-bad-border);  }
.reports-tag-watch { background: var(--rp-warn-bg); color: var(--rp-warn); border-color: var(--rp-warn-border); }
.reports-tag-scale { background: var(--rp-good-bg); color: var(--rp-good); border-color: var(--rp-good-border); }
.reports-tag-hold  { background: var(--rp-info-bg); color: var(--rp-info); border-color: var(--rp-info-border); }
.reports-tag-reason {
    font-size: 11px;
    color: var(--rp-text-2);
    line-height: 1.5;
}

/* B7 — trust signals next to the verdict pill. Deliberately quieter than the pill:
   the pill is the call, these explain how much to believe it. */
.reports-tag-learning,
.reports-tag-conf {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    margin: 0 4px 6px 0;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
    white-space: nowrap;
    cursor: help;
}
/* LEARNING borrows the warning palette — it is the one that stops you acting. */
.reports-tag-learning {
    background: var(--rp-warn-bg);
    color: var(--rp-warn);
    border-color: var(--rp-warn-border);
    text-transform: uppercase;
}
.reports-tag-conf {
    background: var(--rp-info-bg);
    color: var(--rp-info);
    border-color: var(--rp-info-border);
}
/* ≥95% — the threshold at which we are willing to suggest an action at all. */
.reports-tag-conf.is-strong {
    background: var(--rp-good-bg);
    color: var(--rp-good);
    border-color: var(--rp-good-border);
}
.reports-tag-held {
    font-size: 10.5px;
    font-style: italic;
    color: var(--rp-text-2);
    line-height: 1.45;
    margin-top: 2px;
}

/* Actions cell */
.reports-td-actions {
    width: 170px;
    text-align: right;
    white-space: nowrap;
}
.reports-action-btn {
    display: inline-block;
    padding: 6px 11px;
    background: var(--rp-surface);
    border: 1px solid var(--rp-border-strong);
    border-radius: var(--rp-radius-sm);
    font-size: 11.5px;
    font-weight: 600;
    color: var(--rp-text);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    margin: 0 0 4px 0;
    font-family: inherit;
}
.reports-action-btn:hover {
    border-color: var(--rp-accent);
    color: var(--rp-accent);
    transform: translateY(-1px);
}
.reports-action-btn:active { transform: translateY(0); }
.reports-action-btn:disabled { opacity: 0.5; cursor: progress; transform: none; }
.reports-action-pause { display: block; margin-bottom: 4px; }
.reports-action-link {
    display: block;
    font-size: 10.5px;
    color: var(--rp-text-3);
    margin-top: 10px;
}

.reports-action-budget {
    margin-top: 6px;
    font-size: 11px;
    color: var(--rp-text-2);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    line-height: 1.3;
    white-space: nowrap;
}
.reports-action-budget-lbl {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--rp-text-muted);
    font-weight: 700;
    margin-right: 3px;
}
.reports-action-budget-src {
    font-size: 9.5px;
    color: var(--rp-text-muted);
    font-weight: 500;
    margin-left: 2px;
}

/* +15% Increase button on SCALE rows. */
.reports-action-increase {
    background: var(--rp-good);
    color: #fff;
    border-color: var(--rp-good);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    display: block;
    margin-bottom: 4px;
}
.reports-action-increase:hover  {
    background: #065f46;
    border-color: #065f46;
    color: #fff;
}
.reports-action-increase:disabled { opacity: 0.6; cursor: progress; }
.reports-action-increase-done {
    background: #047857 !important;
    border-color: #047857 !important;
    color: #fff !important;
    cursor: default;
}

/* "↻ Refresh creative" one-click fix on fatigued / losing rows — mauve to tie
   it to the fatigue signal (same --rp-mauve as the Fatigue chip/badge). */
.reports-action-refresh {
    background: var(--rp-mauve, #6d4fc0);
    color: #fff;
    border-color: var(--rp-mauve, #6d4fc0);
    display: block;
    margin-bottom: 4px;
    letter-spacing: 0.01em;
}
.reports-action-refresh:hover {
    background: #59399f;
    border-color: #59399f;
    color: #fff;
}

/* ---------- Responsive ----------------------------------------------------- */
@media (max-width: 1100px) {
    .reports-kpi-strip { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
    .reports-page { padding: 18px 14px 60px; }
    .reports-kpi-strip { grid-template-columns: 1fr; }
    .reports-toolbar {
        position: static;
        flex-direction: column;
        flex-wrap: nowrap;   /* a wrapping COLUMN sizes its line to the widest child, not the card */
        align-items: stretch;
    }
    .reports-toolbar-right {
        margin-left: 0;
        justify-content: space-between;
        flex-wrap: wrap;
    }
    /* Each control row wraps inside the column: the 4-way Group-by segment (~330px) and the
       200px account select used to run past a phone's edge, cutting off "Creative". */
    .reports-tool-group { flex-wrap: wrap; min-width: 0; }
    .reports-segmented { flex-wrap: wrap; max-width: 100%; }
    .reports-input-select, .reports-input-sort, .reports-input-search { min-width: 0; flex: 1 1 160px; width: auto; max-width: 100%; }
    .reports-table thead th { position: static; }
}

/* Per-account read failures — a fact of the page, not a toast (QA 2026-09-02). */
.reports-acct-errors { margin: 0 0 14px; padding: 12px 14px; border: 1px solid #F1D9A8; border-left: 4px solid #E0A526; border-radius: 10px; background: #FFF8E8; font-size: 13px; color: #3B414C; }
.reports-acct-errors ul { margin: 6px 0 0 18px; padding: 0; }
.reports-acct-errors li { margin: 2px 0; overflow-wrap: anywhere; }
.reports-acct-errors__name { font-weight: 600; }
.reports-acct-errors p { margin: 8px 0 0; color: #5B6473; }
