/* ============================================================================
 * Ads-from-winners wizard — `afw-` prefix.
 *
 * Modal that opens from the Studio winners tray and from the Library
 * multi-select bar. 5-step flow with a stepper, swappable step body,
 * sticky Back/Next footer.
 *
 * Design tokens are scoped to .afw-modal so the wizard is fully self-
 * contained and won't drift when other modal styles change.
 * ============================================================================ */

.afw-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
    /* Allow tapping outside to close — the JS guards the in-progress
       create step. */
}

.afw-modal-wide {
    /* The 3-step rewrite uses a wider modal so step 1's setup form (3
     * sections + brief textarea + URL) doesn't feel cramped, and step 2's
     * parallel preview grid has room for 3-4 cards side by side.
     *
     * Bumped to 1280px (was 920) so step 2's image-left + body-right
     * preview card has room for 10 variant rows per field WITHOUT
     * cramping each row's input. The body column now gets ~880px of
     * usable width even after the image cell and the side rails. */
}
.afw-modal-wide.afw-modal { width: 1280px; }

.afw-modal {
    /* Tokens — scoped, won't leak. */
    --afw-bg:        #ffffff;
    --afw-soft:      #fafbfc;
    --afw-border:    rgba(15, 23, 42, 0.08);
    --afw-border-2:  rgba(15, 23, 42, 0.12);
    --afw-text:      #0f172a;
    --afw-text-mid:  #4b5563;
    --afw-text-mut:  #6b7280;
    --afw-accent:    #5B53E8;
    --afw-accent-soft: rgba(99, 102, 241, 0.08);
    --afw-accent-ring: rgba(99, 102, 241, 0.16);
    --afw-ok:        #15803d;
    --afw-ok-soft:   #dcfce7;
    --afw-warn:      #b45309;
    --afw-warn-soft: #fef3c7;
    --afw-danger:    #b91c1c;
    --afw-danger-soft: #fee2e2;
    --afw-fb:        #0866FF;

    width: 760px;
    max-width: 100%;
    max-height: calc(100vh - 32px);
    background: var(--afw-bg);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--afw-text);
    font-family: inherit;
}

/* ============================================================================
 * Header
 * ============================================================================ */
.afw-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--afw-border);
}
.afw-head-title {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex: 1;
    min-width: 0;
}
.afw-head-title h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--afw-text);
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.afw-head-sub {
    font-size: 12px;
    color: var(--afw-text-mut);
    white-space: nowrap;
}

/* ============================================================================
 * Stepper
 * ============================================================================ */
.afw-stepper-host {
    flex-shrink: 0;
    padding: 14px 24px;
    background: var(--afw-soft);
    border-bottom: 1px solid var(--afw-border);
}
.afw-stepper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.afw-step {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.afw-step-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e5e7eb;
    color: var(--afw-text-mut);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11.5px;
    font-weight: 700;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.afw-step-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--afw-text-mut);
    white-space: nowrap;
    transition: color 0.2s, font-weight 0.2s;
}
.afw-step.is-current .afw-step-dot {
    background: var(--afw-accent);
    color: #fff;
    box-shadow: 0 0 0 4px var(--afw-accent-ring);
}
.afw-step.is-current .afw-step-label { color: var(--afw-text); font-weight: 600; }
.afw-step.is-done .afw-step-dot { background: var(--afw-ok); color: #fff; }
.afw-step.is-done .afw-step-label { color: var(--afw-ok); }
.afw-step-bar {
    flex: 1;
    height: 2px;
    background: rgba(15, 23, 42, 0.08);
    border-radius: 1px;
    min-width: 16px;
}

/* ============================================================================
 * Body — scrollable region
 * ============================================================================ */
/* Duplicate-publish guard — amber awareness banner shown between the stepper and
 * the body when a selected creative already has live Meta ads. Aligns to the
 * body's 24px horizontal inset. */
.afw-dup-warn { display: flex; gap: 10px; align-items: flex-start; margin: 10px 24px 0; padding: 10px 14px; border-radius: 10px; background: #FEF3E2; border: 1px solid #FBBF77; color: #92400E; font-size: 13px; line-height: 1.45; }
.afw-dup-warn-icon { font-size: 15px; line-height: 1.3; flex: 0 0 auto; }
.afw-dup-warn-text strong { font-weight: 700; }
.afw-dup-warn-link { margin-left: 6px; color: #B45309; font-weight: 700; white-space: nowrap; }
.afw-dup-warn-link:hover { text-decoration: underline; }

/* "Remember these settings as my Meta defaults" opt-in on the publish step. */
.afw-savedef-row { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-size: 12.5px; color: var(--text-secondary, #5b6472); cursor: pointer; line-height: 1.4; }
.afw-savedef-row input { margin-top: 2px; flex: 0 0 auto; }

.afw-body {
    flex: 1;
    min-height: 280px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 22px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
/* The body is a flex COLUMN used purely to STACK a step's blocks with a 16px rhythm.
 * Flex items default to flex-shrink:1, so when a step is taller than the body the column
 * COMPRESSES its shrinkable children instead of letting the body scroll — which clipped the
 * per-video card and cut off the "Override copy for all ads" panel at the bottom (its overflow
 * never extended scrollHeight, so you couldn't even scroll to it). Pinning every direct child
 * to its natural height makes the overflow honest, so .afw-body's overflow-y:auto actually
 * scrolls. (Grid/auto blocks like .afw-destination-shell are content-height already — no-op there.) */
.afw-body > * { flex-shrink: 0; }

.afw-intro {
    margin: 0 0 4px;
}
.afw-intro h3 {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 700;
    color: var(--afw-text);
    letter-spacing: -0.005em;
}
.afw-intro p {
    margin: 0;
    font-size: 13px;
    color: var(--afw-text-mut);
    line-height: 1.55;
}

/* ============================================================================
 * Mode toggle (existing / new)
 * ============================================================================ */
.afw-mode-toggle {
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 999px;
    padding: 4px;
    gap: 2px;
}
.afw-mode-btn {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 8px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    color: var(--afw-text-mut);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.afw-mode-btn:hover { color: var(--afw-text); }
.afw-mode-btn.is-active {
    background: #fff;
    color: var(--afw-text);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

/* ============================================================================
 * Pick list (campaigns / ad sets / connections)
 * ============================================================================ */
.afw-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* Scrolling is handled by the parent .afw-body, so don't add a second
       overflow context here — would create nested scroll surfaces that
       feel wrong on touchpads. */
}
/* Campaign-list search box (shared by the image + video ad wizards). Mirrors
   .afw-input but with a leading magnifier so it reads as a filter, not a field. */
.afw-search {
    appearance: none;
    -webkit-appearance: none;
    border: 1.5px solid #d1d5db;
    background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>") no-repeat 11px 50%;
    color: var(--afw-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    padding: 9px 12px 9px 36px;
    border-radius: 9px;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.afw-search:focus {
    outline: none;
    border-color: var(--afw-accent);
    box-shadow: 0 0 0 3px var(--afw-accent-ring);
}
.afw-search::-webkit-search-cancel-button { cursor: pointer; }
/* Group heading inside the campaign list ("Recently pushed to" / "All campaigns"). */
.afw-list-group-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b7280;
    margin: 0 2px;
}
.afw-search-empty { padding: 6px 2px; }
.afw-pick-card {
    appearance: none;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 16px;
    background: #fff;
    border: 1.5px solid var(--afw-border-2);
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
    min-height: 64px;
}
.afw-pick-card:hover {
    border-color: var(--afw-accent);
    background: var(--afw-accent-soft);
}
.afw-pick-card.is-selected {
    border-color: var(--afw-accent);
    background: var(--afw-accent-soft);
    box-shadow: 0 0 0 3px var(--afw-accent-ring);
}
.afw-pick-radio {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    background: #fff;
    transition: border-color 0.12s, background 0.12s;
    position: relative;
}
.afw-pick-card.is-selected .afw-pick-radio {
    border-color: var(--afw-accent);
    background: var(--afw-accent);
}
.afw-pick-card.is-selected .afw-pick-radio::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: #fff;
}
.afw-pick-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.afw-pick-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--afw-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.afw-pick-subtitle {
    font-size: 12px;
    color: var(--afw-text-mut);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.afw-pick-badge {
    flex-shrink: 0;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    border-radius: 999px;
    line-height: 1;
}
.afw-pick-badge.is-ok      { background: var(--afw-ok-soft);     color: var(--afw-ok); }
.afw-pick-badge.is-warn    { background: var(--afw-warn-soft);   color: var(--afw-warn); }
.afw-pick-badge.is-bad     { background: var(--afw-danger-soft); color: var(--afw-danger); }
.afw-pick-badge.is-neutral { background: #f3f4f6;                color: var(--afw-text-mid); }

/* ============================================================================
 * Forms (create-new + ad copy)
 * ============================================================================ */
.afw-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.afw-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.afw-field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--afw-text-mid);
    letter-spacing: 0.2px;
}
.afw-field-hint {
    font-size: 11.5px;
    color: var(--afw-text-mid);
    line-height: 1.4;
    opacity: 0.85;
    margin-top: 2px;
}
.afw-input,
.afw-textarea {
    appearance: none;
    border: 1.5px solid #d1d5db;
    background: #fff;
    color: var(--afw-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    padding: 10px 13px;
    border-radius: 9px;
    width: 100%;
    transition: border-color 0.12s, box-shadow 0.12s;
    box-sizing: border-box;
}
.afw-textarea {
    resize: vertical;
    min-height: 80px;
}
.afw-input:focus,
.afw-textarea:focus {
    outline: none;
    border-color: var(--afw-accent);
    box-shadow: 0 0 0 3px var(--afw-accent-ring);
}
select.afw-input {
    cursor: pointer;
    /* Custom chevron — replaces the OS native dropdown arrow which
       inherits the OS theme and looks out of place. */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='1 1 6 7 11 1'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    background-color: #fff;   /* override system default */
}

/* === datetime-local input ============================================
 *
 * Native `<input type="datetime-local">` is functional but visually
 * hard to read at a glance:
 *   - The calendar/clock icon is tiny (~12px) and gray
 *   - The text reads like any other text field, so users don't see
 *     "this opens a picker"
 *   - No hover state — feels like a plain input
 *
 * The styling below:
 *   - Adds an obvious "click to open calendar" cursor
 *   - Beefs up the right-side icon zone (32px column with a slightly
 *     darker accent strip) so users see the affordance
 *   - Hover + focus states match the rest of the wizard (blue ring)
 *     plus a slightly lifted bg so the input reads as interactive
 *   - Spinner buttons (the up/down arrows for typing the date with
 *     keyboard) stay hidden by default — they're rarely useful and
 *     visually noisy. Keyboard users still get arrow-key navigation.
 *
 * The JS-side helper (_datetimeInput in ads-from-winners.js) also
 * intercepts clicks on the LEFT 80% of the input and calls
 * showPicker() so the entire input behaves like the calendar button.
 * Without that, only the small right icon would trigger the picker.
 * =================================================================== */
.afw-input-datetime {
    cursor: pointer;
    /* Reserve room on the right for the native icon + give it a soft
       background strip so the user reads it as "calendar button." */
    padding-right: 40px;
    background-color: #fff;
    background-image: linear-gradient(to right, transparent calc(100% - 36px), rgba(99, 102, 241, 0.06) calc(100% - 36px));
    /* Slightly heavier border for the date input so it pops a bit
       more than a plain text field. Same color so it doesn't fight
       with the rest of the form visually. */
    border-color: #c2c8d0;
}
.afw-input-datetime:hover {
    border-color: var(--afw-accent);
    background-image: linear-gradient(to right, transparent calc(100% - 36px), rgba(99, 102, 241, 0.12) calc(100% - 36px));
}
.afw-input-datetime:focus {
    /* Standard focus ring inherited via .afw-input:focus, but we also
       brighten the icon strip so the field reads "active." */
    background-image: linear-gradient(to right, transparent calc(100% - 36px), rgba(99, 102, 241, 0.16) calc(100% - 36px));
}
/* Native calendar icon — Chrome / Safari / Firefox each implement it
   as a different pseudo-element. We scale + recolor what we can. */
.afw-input-datetime::-webkit-calendar-picker-indicator {
    cursor: pointer;
    /* Slightly bigger and tinted to match the wizard accent */
    width: 18px;
    height: 18px;
    opacity: 0.7;
    filter: invert(38%) sepia(20%) saturate(1200%) hue-rotate(213deg);
    margin-right: -4px;
    transition: opacity 0.12s;
}
.afw-input-datetime:hover::-webkit-calendar-picker-indicator,
.afw-input-datetime:focus::-webkit-calendar-picker-indicator {
    opacity: 1;
}
/* Hide the keyboard-spinner up/down chevrons — they're rarely useful
   and visually noisy. Keyboard users keep arrow-key navigation. */
.afw-input-datetime::-webkit-inner-spin-button,
.afw-input-datetime::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}
.afw-number-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.afw-input-hint {
    font-size: 11.5px;
    color: var(--afw-text-mut);
    font-style: italic;
}
.afw-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
@media (max-width: 540px) {
    .afw-row { grid-template-columns: 1fr; }
}

/* Advanced (collapsible audience basics on Create-new ad set form) */
.afw-advanced {
    margin-top: 4px;
    padding: 0 14px;
    background: var(--afw-soft);
    border: 1px solid var(--afw-border);
    border-radius: 10px;
    font-size: 13px;
}
.afw-advanced > summary {
    cursor: pointer;
    color: var(--afw-text-mid);
    font-weight: 500;
    list-style: none;
    padding: 12px 0;
    user-select: none;
}
.afw-advanced > summary::-webkit-details-marker { display: none; }
.afw-advanced > summary::before {
    content: '▸';
    color: var(--afw-text-mut);
    margin-right: 8px;
    display: inline-block;
    transition: transform 0.15s;
}
.afw-advanced[open] > summary::before {
    transform: rotate(90deg);
}
.afw-advanced-body {
    padding-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================================================
 * Banner preview strip (step 4)
 * ============================================================================ */
.afw-banner-strip-wrap {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--afw-border);
}
.afw-strip-title {
    margin: 0 0 10px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--afw-text-mid);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.afw-banner-strip {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 8px;
}
.afw-banner-tile {
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    background: #f3f4f6;
    border: 1px solid var(--afw-border);
}
.afw-banner-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ============================================================================
 * Summary (step 5 review)
 * ============================================================================ */
.afw-summary {
    background: var(--afw-soft);
    border: 1px solid var(--afw-border);
    border-radius: 12px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.afw-summary-row {
    display: flex;
    align-items: baseline;
    gap: 14px;
    font-size: 13px;
}
.afw-summary-label {
    width: 120px;
    flex-shrink: 0;
    color: var(--afw-text-mut);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.afw-summary-value {
    flex: 1;
    color: var(--afw-text);
    overflow: hidden;
    word-break: break-all;
    line-height: 1.45;
    font-weight: 500;
}

/* ============================================================================
 * Result (after push)
 * ============================================================================ */
.afw-result-banner {
    padding: 16px 18px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
}
.afw-result-banner.is-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #14532d;
}
.afw-result-banner.is-partial {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}
/* Result-info — secondary message after the main success banner. Used
   for the "adset may take 30 min to appear" notice and any other
   informational post-publish note. Same blue-ish tone as the form-level
   .afw-notice so users learn the visual language across the wizard. */
.afw-result-info {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a;
}
.afw-result-cause {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.45;
    opacity: 0.8;
}
.afw-result-info code {
    background: rgba(30, 58, 138, 0.08);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
}
/* Form-level notice — used in step 1 next to "Create new adset" and
   wherever else a heads-up belongs inside an editable form. Same
   palette as .afw-result-info for visual consistency. */
.afw-notice {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a;
    margin-bottom: 10px;
}
.afw-result-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.afw-result-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border: 1px solid var(--afw-border);
    border-radius: 10px;
    background: #fff;
}
.afw-result-row.is-ok   { border-color: #bbf7d0; background: rgba(240, 253, 244, 0.5); }
.afw-result-row.is-fail { border-color: #fecaca; background: rgba(254, 242, 242, 0.6); }
.afw-result-thumb {
    width: 56px;
    height: 56px;
    object-fit: contain;
    background: #f1f2f5;
    border-radius: 8px;
    flex-shrink: 0;
}
.afw-result-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.afw-result-text strong {
    font-size: 13.5px;
    color: var(--afw-text);
}
.afw-result-meta {
    font-size: 11.5px;
    color: var(--afw-text-mut);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* ============================================================================
 * Loading / error / empty states
 * ============================================================================ */
.afw-loading,
.afw-error,
.afw-empty {
    padding: 28px 22px;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
    color: var(--afw-text-mut);
    line-height: 1.55;
}
.afw-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
.afw-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--afw-danger);
}
.afw-empty {
    background: var(--afw-soft);
    border: 1px dashed var(--afw-border-2);
}

/* Cache-age indicator at the top of campaign / adset / pages lists.
   Tells the user whether they're looking at a fresh Meta response or
   a 5-min-old snapshot, with a one-click "Refresh now" escape hatch. */
.afw-cache-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    margin-bottom: 8px;
}
.afw-cache-pill-cache {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}
.afw-cache-pill-live {
    background: #ecfdf5;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.afw-cache-pill-stale {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}
.afw-cache-pill-label {
    flex: 1;
    font-weight: 500;
}
.afw-cache-pill-refresh {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--afw-accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 5px;
    transition: background 0.15s;
}
.afw-cache-pill-refresh:hover:not(:disabled) {
    background: rgba(99, 102, 241, 0.08);
}
.afw-cache-pill-refresh:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.afw-empty h4 {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 700;
    color: var(--afw-text);
    letter-spacing: -0.005em;
}
.afw-empty p {
    margin: 0 auto 14px;
    line-height: 1.55;
    max-width: 460px;
}
.afw-empty .btn {
    display: inline-flex;
}

/* Spinner override — works with the .spinner class from app.css */
.afw-loading .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--afw-accent);
    border-radius: 50%;
    animation: afw-spin 0.7s linear infinite;
}
@keyframes afw-spin {
    to { transform: rotate(360deg); }
}

/* ============================================================================
 * Footer — sticky, primary action right-aligned
 * ============================================================================ */
.afw-footer {
    flex-shrink: 0;
    padding: 14px 24px;
    border-top: 1px solid var(--afw-border);
    background: var(--afw-bg);
    display: flex;
    align-items: center;
    gap: 10px;
}
/* The wizard uses the global .btn / .btn-primary classes from app.css —
 * those already inherit the project's button styling. We just ensure
 * the wizard's primary CTA gets enough visual weight at the bottom. */
.afw-modal .btn {
    font-size: 13.5px;
    padding: 9px 18px;
    border-radius: 9px;
}
.afw-modal .btn.btn-primary {
    background: var(--afw-accent);
    border-color: var(--afw-accent);
    color: #fff;
    font-weight: 600;
}
.afw-modal .btn.btn-primary:hover:not(:disabled) {
    background: #4f46e5;
    border-color: #4f46e5;
}
.afw-modal .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================================
 * Studio tray "Create Meta Ads" button (sibling of "Edit in Canvas").
 *
 * Visually identical to its sibling — same .btn .btn-primary
 * .studio-tray-composer-btn class chain handles padding, height,
 * border-radius, primary background, and hover state (width: 100%, so the
 * two footer actions STACK edge-aligned; the old margin-left: 6px was a
 * side-by-side-era leftover that pushed this one 6px out of line —
 * removed 2026-07-14).
 * ============================================================================ */
.studio-tray-ads-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.studio-tray-ads-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Library multi-select styles moved to css/library.css to keep them
 * co-located with the rest of the tile geometry rules and to leverage
 * higher specificity (`.library-grid .library-tile.is-selected`). The
 * old rules here had specificity collisions with `.library-tile:hover`
 * that occasionally won the cascade. */

/* ============================================================================
 * Step 1 — SETUP form sections
 * ============================================================================ */
.afw-section {
    background: var(--afw-bg);
    border: 1px solid var(--afw-border);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 14px;
}

/* ============================================================================
 * Step 3 — REVIEW: big publish-mode radios + advanced-feature toggles.
 * ============================================================================ */
.afw-radio-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
@media (max-width: 720px) {
    .afw-radio-group { grid-template-columns: 1fr; }
}
.afw-bigradio {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    text-align: left;
    font-family: inherit;
}
.afw-bigradio:hover {
    border-color: #c7d2fe;
}
.afw-bigradio.is-active {
    border-color: #5B53E8;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
    background: #f5f7ff;
}
.afw-bigradio-dot {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border: 2px solid #cbd5e1;
    border-radius: 50%;
    margin-top: 2px;
    position: relative;
    transition: all 0.15s;
}
.afw-bigradio.is-active .afw-bigradio-dot {
    border-color: #5B53E8;
    background: #5B53E8;
}
.afw-bigradio.is-active .afw-bigradio-dot::after {
    content: '';
    position: absolute;
    inset: 3px;
    background: #fff;
    border-radius: 50%;
}
.afw-bigradio-text {
    flex: 1;
    min-width: 0;
}
.afw-bigradio-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.afw-bigradio-title {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
}
.afw-bigradio-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 999px;
}
.afw-bigradio-badge.is-ok {
    background: #dcfce7;
    color: #166534;
}
.afw-bigradio-badge.is-warn {
    background: #fef3c7;
    color: #92400e;
}
.afw-bigradio-sub {
    font-size: 12.5px;
    color: #4b5563;
    line-height: 1.45;
}

/* Advanced toggle row — title + sub on the left, switch on the right. */
.afw-advtoggle {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 0;
    border-top: 1px solid #f1f5f9;
}
.afw-advtoggle:first-child {
    border-top: none;
    padding-top: 4px;
}
.afw-advtoggle.is-disabled {
    opacity: 0.55;
}
.afw-advtoggle-text {
    flex: 1;
    min-width: 0;
}
.afw-advtoggle-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 2px;
}
.afw-advtoggle-sub {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.45;
}

/* ============================================================================
 * Step 4 — PUSH: variant generation progress grid.
 *
 * One row per banner, one column per variant size. Each cell shows a
 * status pill that flips through queued → generating → ready (or
 * failed). Uses a CSS grid because the column count is small + fixed
 * (currently 2: Story + Landscape) and the rows align cleanly.
 * ============================================================================ */
.afw-variant-progress {
    margin: 12px 0 18px;
}
.afw-variant-grid {
    display: grid;
    /* Banner column + 3 size columns (square / story / landscape) —
     * was repeat(2,…) when we only generated story + landscape;
     * bumped to 3 now that the wizard auto-detects source aspect
     * and generates whichever placements are missing. The 3rd
     * column is the source-reused cell for the matching aspect. */
    /* Column count follows the sizes actually shown (JS sets --afw-variant-cols: 4 for
       square + 4:5 feed + story + reels, 1 for a carousel) — a fixed repeat(3) misaligned every row. */
    grid-template-columns: minmax(150px, 1fr) repeat(var(--afw-variant-cols, 3), minmax(120px, 1fr));
    gap: 8px;
    background: #fafbfc;
    border: 1px solid var(--afw-border);
    border-radius: 12px;
    padding: 12px;
}
/* Per-ad creation grid — same look as the variant grid but only ONE
 * status column (no per-size split, since each call covers all of an
 * ad's sizes server-side). Lets us reuse all the .afw-variant-cell
 * status styles. */
.afw-adcreate-grid {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) minmax(min(220px, 100%), 2fr);
    gap: 8px;
    background: #fafbfc;
    border: 1px solid var(--afw-border);
    border-radius: 12px;
    padding: 12px;
    margin-top: 12px;
}
.afw-variant-corner {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
    align-self: center;
}
.afw-variant-col-head {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #4b5563;
    align-self: center;
    padding-left: 4px;
}
.afw-variant-row-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px;
}
.afw-variant-thumb {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: #e5e7eb;
}
.afw-variant-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.afw-variant-row-num {
    font-size: 12.5px;
    font-weight: 600;
    color: #111827;
}
.afw-variant-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: #fff;
    transition: background 0.18s, border-color 0.18s;
}
.afw-variant-cell-status {
    font-size: 12px;
    font-weight: 600;
}
/* Per-cell variant thumbnail — appears in the source-aspect cell
   (always) and in generated cells once the fal.ai resize completes
   (via setState(..., 'done', url)). Clickable to open the zoom
   lightbox so the user can visually confirm the re-frame before
   shipping to Meta. */
.afw-variant-cell-thumb {
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    background: #f3f4f6;
    border: 1px solid rgba(15, 23, 42, 0.08);
    flex-shrink: 0;
}
.afw-variant-cell-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #ffffff;
}
.afw-variant-cell-thumb-zoomable {
    cursor: zoom-in;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.afw-variant-cell-thumb-zoomable:hover {
    transform: scale(1.04);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}
/* Manual retry button — appears inside a failed variant cell after
   the two auto-attempts both failed. Uses the same .btn .btn-primary
   palette as the wizard's Next/Back buttons so it reads as a
   first-class action, just sized smaller to fit inside the cell. */
.afw-variant-cell-retry {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    margin-top: 4px;
    line-height: 1.2;
    cursor: pointer;
}
.afw-variant-cell-retry:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* "Continue with source-image fallback" block — appears below the
   variant matrix when at least one variant is permanently failed.
   Lets the user proceed to publish without endlessly retrying. */
.afw-variant-continue-wrap {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: 10px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}
.afw-variant-continue-hint {
    font-size: 13px;
    color: #78350f;
    line-height: 1.5;
}
.afw-variant-continue-btn {
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 8px;
    background: #f59e0b;
    color: #fff;
    border: none;
    font-weight: 600;
    cursor: pointer;
}
.afw-variant-continue-btn:hover:not(:disabled) {
    background: #d97706;
}
.afw-variant-continue-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
/* Also make the per-banner source thumbnail (left column) zoomable.
   Same affordance, same hover lift — single visual language across the
   whole matrix. */
.afw-variant-thumb-zoomable {
    cursor: zoom-in;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.afw-variant-thumb-zoomable:hover {
    transform: scale(1.04);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

/* Zoom lightbox — fullscreen overlay opened from any zoomable thumb
   in the push step's variant matrix. Dismissed by clicking the
   backdrop, the × button, or pressing Escape. */
.afw-zoom-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.86);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    animation: afw-zoom-fade 0.14s ease;
}
@keyframes afw-zoom-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.afw-zoom-inner {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.afw-zoom-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.afw-zoom-img {
    max-width: 92vw;
    max-height: 72vh;     /* trimmed to leave room for thumbnail strip */
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
    background: #ffffff;
    display: block;
}
/* Prev / Next arrows — flank the main image vertically centered. */
.afw-zoom-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 0;
    background: rgba(15, 23, 42, 0.55);
    color: #ffffff;
    font-size: 36px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
    backdrop-filter: blur(4px);
    user-select: none;
    z-index: 2;
}
.afw-zoom-nav:hover {
    background: rgba(15, 23, 42, 0.8);
    transform: translateY(-50%) scale(1.06);
}
.afw-zoom-nav-prev { left: -64px; }
.afw-zoom-nav-next { right: -64px; }
@media (max-width: 900px) {
    /* On narrow viewports the arrows would clip off-screen; pull them
       inside the image bounds and dim the bg less. */
    .afw-zoom-nav-prev { left: 8px; }
    .afw-zoom-nav-next { right: 8px; }
}
/* Thumbnail strip — horizontally scrollable on overflow. */
.afw-zoom-strip {
    display: flex;
    gap: 6px;
    max-width: 92vw;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 4px 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}
.afw-zoom-strip::-webkit-scrollbar {
    height: 6px;
}
.afw-zoom-strip::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}
.afw-zoom-strip-thumb {
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
    padding: 0;
    transition: border-color 0.15s, transform 0.12s;
}
.afw-zoom-strip-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.afw-zoom-strip-thumb:hover {
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.04);
}
.afw-zoom-strip-thumb.is-active {
    border-color: var(--afw-accent, #5B53E8);
    transform: scale(1.04);
}
.afw-zoom-caption {
    color: #f9fafb;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    padding: 4px 12px;
}
/* Zoom close = the shared .cb-close.cb-close--on-dark (app.css); this rule only parks it ABOVE
   the image, outside the picture, instead of the default in-header placement. */
.cb-close.afw-zoom-close {
    position: absolute;
    top: -50px;
    right: -8px;
    margin: 0;
}

/* Video-ads wizard zoom (video-ads-wizard.js _openVideoZoom / _openImageZoom) — it had no styles
   at all, so the overlay rendered unpositioned at the bottom of the page. Minimal lightbox shell;
   its close is the shared .cb-close--float.cb-close--on-dark. */
.vaw-zoom-overlay {
    position: fixed;
    inset: 0;
    z-index: 10060;
    background: rgba(12, 12, 14, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.vaw-zoom-box {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.vaw-zoom-img,
.vaw-zoom-video {
    display: block;
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 10px;
}
.vaw-zoom-frame {
    width: min(92vw, 1080px);
    aspect-ratio: 16 / 9;
    max-height: 88vh;
    border: 0;
    border-radius: 10px;
    background: #000;
}
.vaw-zoom-empty { color: #fff; font-size: 14px; padding: 40px; }
.afw-variant-cell.is-pending {
    color: #646B78;
    background: #f9fafb;
    border-style: dashed;
}
.afw-variant-cell.is-running {
    color: #4338ca;
    background: linear-gradient(90deg, #eef2ff 0%, #f5f3ff 100%);
    border-color: #c7d2fe;
    /* Subtle pulse so the cell visibly "works" even when the label
     * doesn't change for a few seconds. */
    animation: afw-variant-pulse 1.6s ease-in-out infinite;
}
@keyframes afw-variant-pulse {
    0%, 100% { background: #eef2ff; }
    50%      { background: #e0e7ff; }
}
/* Retrying — distinct yellow so the user sees the difference between
 * "still working" (purple pulse) and "first attempt failed, having
 * another go" (yellow pulse). The faster pulse rate communicates a
 * brief recovery window, not a long wait. */
.afw-variant-cell.is-retrying {
    color: #92400e;
    background: #fef3c7;
    border-color: #fcd34d;
    animation: afw-variant-retry-pulse 0.9s ease-in-out infinite;
}
@keyframes afw-variant-retry-pulse {
    0%, 100% { background: #fef3c7; }
    50%      { background: #fde68a; }
}
.afw-variant-cell.is-done {
    color: #166534;
    background: #dcfce7;
    border-color: #bbf7d0;
}
.afw-variant-cell.is-error {
    color: #b91c1c;
    background: #fee2e2;
    border-color: #fecaca;
}

/* On narrow widths, stack the rows so each banner still reads cleanly. */
@media (max-width: 640px) {
    .afw-variant-grid {
        grid-template-columns: 1fr 1fr;
    }
    .afw-variant-corner,
    .afw-variant-row-head {
        grid-column: 1 / -1;
    }
}

/* iOS-style switch (used for advanced toggles + the URL tracking toggle). */
.afw-switch {
    flex-shrink: 0;
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    cursor: pointer;
}
.afw-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.afw-switch-knob {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 999px;
    transition: background 0.18s;
}
.afw-switch-knob::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    transition: transform 0.18s;
}
.afw-switch input:checked + .afw-switch-knob {
    background: #5B53E8;
}
.afw-switch input:checked + .afw-switch-knob::before {
    transform: translateX(16px);
}
.afw-switch input:disabled + .afw-switch-knob {
    background: #e5e7eb;
    cursor: not-allowed;
}
.afw-section-head {
    margin-bottom: 14px;
    /* Allow inline buttons (like .afw-section-refresh) to sit in the
       top-right corner alongside the h4 + sub. flex-row with title
       block on the left, action(s) on the right. */
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px 12px;
}
.afw-section-head > h4,
.afw-section-head > p {
    /* h4 + p form the title block — they take their own row at the
       top, then siblings (buttons) wrap to a second row on narrow
       widths or sit beside on wide. */
    flex: 1 1 100%;
}
.afw-section-head h4 {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 700;
    color: var(--afw-text);
    letter-spacing: -0.005em;
}
.afw-section-head p {
    margin: 0;
    font-size: 12.5px;
    color: var(--afw-text-mut);
    line-height: 1.5;
}
.afw-section-refresh {
    /* Small "↻ Refresh" button in the destination card header. Sits
       to the right of the section title, gets a subtle outline that
       fills indigo on hover. Pulls the connection list from the
       server, busting the 12h module cache. */
    flex: 0 0 auto;
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--afw-border-2, #e2e8f0);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--afw-text-mut, #64748b);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    align-self: flex-start;
}
.afw-section-refresh:hover {
    background: var(--afw-accent, #4f46e5);
    color: #fff;
    border-color: var(--afw-accent, #4f46e5);
}
.afw-section-refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.afw-section-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.afw-list-compact { gap: 6px; }
.afw-hint {
    font-size: 12.5px;
    color: var(--afw-text-mut);
    font-style: italic;
    padding: 8px 0;
}

/* Multi-size toggle row — checkbox + dual-line label */
.afw-toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--afw-soft);
    border: 1px solid var(--afw-border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}
.afw-toggle-row:hover { border-color: var(--afw-accent); }
.afw-toggle-row input[type="checkbox"] {
    margin-top: 2px;
    width: 18px;
    height: 18px;
    accent-color: var(--afw-accent);
    flex-shrink: 0;
}
.afw-toggle-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}
.afw-toggle-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--afw-text);
}
.afw-toggle-sub {
    font-size: 12px;
    color: var(--afw-text-mut);
    line-height: 1.5;
}

/* Catalog product link (step 1, below the approval-link toggle) — js/shared/catalog-product-picker.js.
   Same card chrome as .afw-toggle-row; results list is IN FLOW (not absolute) so the modal's
   scrolling body can never clip it. */
.afw-plink {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
    background: var(--afw-soft);
    border: 1px solid var(--afw-border);
    border-radius: 10px;
}
.afw-plink-search { display: flex; flex-direction: column; gap: 6px; }
.afw-plink-input {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    font: inherit;
    font-size: 13px;
    color: var(--afw-text);
    background: var(--afw-bg);
    border: 1px solid var(--afw-border);
    border-radius: 8px;
    box-sizing: border-box;
}
.afw-plink-input:focus { outline: none; border-color: var(--afw-accent); box-shadow: 0 0 0 3px var(--afw-accent-ring); }
.afw-plink-list {
    display: flex;
    flex-direction: column;
    max-height: 288px;
    overflow-y: auto;
    background: var(--afw-bg);
    border: 1px solid var(--afw-border);
    border-radius: 8px;
}
.afw-plink-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 10px;
    font: inherit;
    text-align: left;
    background: none;
    border: 0;
    border-bottom: 1px solid var(--afw-border);
    cursor: pointer;
}
.afw-plink-row:last-child { border-bottom: 0; }
.afw-plink-row:hover, .afw-plink-row.is-active { background: var(--afw-accent-soft); }
.afw-plink-thumb {
    flex: 0 0 auto;
    border-radius: 6px;
    overflow: hidden;
    background: #eef0f4;
}
.afw-plink-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.afw-plink-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.afw-plink-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--afw-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.afw-plink-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 11.5px; color: var(--afw-text-mut); }
.afw-plink-stock { font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; }
.afw-plink-stock--in-stock { color: var(--afw-ok); background: var(--afw-ok-soft); }
.afw-plink-stock--out-of-stock { color: var(--afw-danger); background: var(--afw-danger-soft); }
.afw-plink-stock--unknown { color: var(--afw-text-mut); background: #eef0f4; }
.afw-plink-empty, .afw-plink-more { padding: 10px 12px; font-size: 12px; color: var(--afw-text-mut); }
.afw-plink-more { border-top: 1px solid var(--afw-border); }
/* "Auto-pause bad ads" (js/shared/bad-ads-rule-ui.js) — conditions use the Rules chrome (css/rules.css) */
.afw-badrule-slot { margin-top: 12px; }
.afw-badrule { border: 1px solid var(--afw-border); border-radius: 10px; padding: 12px 14px; background: #fff; }
.afw-badrule.is-on { border-color: rgba(99, 102, 241, 0.35); }
/* Card-header toggle (interests, auto-pause): checkbox on the SAME line as the title, sub-text under the title. */
.afw-toggle {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
}
.afw-toggle input[type="checkbox"] {
    margin: 1px 0 0;
    width: 18px;
    height: 18px;
    accent-color: var(--afw-accent);
    flex-shrink: 0;
    cursor: pointer;
}
.afw-badrule-head { margin: 0; }
.afw-badrule-att { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.afw-badrule-att__label { font-size: 12px; font-weight: 600; color: var(--afw-text-mut); }
.afw-badrule-seg .afw-mode-btn { padding: 5px 14px; font-size: 12.5px; }
.afw-badrule-cond .rules-leaf__del { margin-left: auto; }
/* Auto scaling step: the cards stack; "Auto-increase budget" ends with its action line. */
.afw-scaling-slot + .afw-scaling-slot { margin-top: 14px; }
.afw-scalerule-thenwrap { margin-top: 10px; }
.afw-scalerule-then { flex-wrap: wrap; row-gap: 6px; font-size: 13px; color: var(--afw-text); }
.afw-scalerule-then__lbl { font-weight: 600; }
.afw-scalerule-then .rules-leaf__value-input { width: 64px; }
.afw-scalerule-then .rules-leaf__value-input.afw-scalerule-cap { width: 96px; }
.afw-scalerule-ccy { color: var(--afw-text-mut); }
/* Auto scaling step: "pause or change them in Automation → Rules" */
.afw-rule-manage { margin: -4px 0 14px; font-size: 12.5px; color: var(--afw-text-mut); }
.afw-rule-manage a { color: var(--afw-accent); font-weight: 600; text-decoration: none; }
.afw-rule-manage a:hover { text-decoration: underline; }
/* Result screen: "Rules for these ads" (js/shared/rule-links.js) */
.afw-rule-links { margin: 14px 0; padding: 12px 14px; border: 1px solid var(--afw-border); border-radius: 10px; background: #fff; }
.afw-rule-links__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.afw-rule-links__title { font-size: 14px; font-weight: 600; color: var(--afw-text); }
.afw-rule-links__all { font-size: 12.5px; font-weight: 600; color: var(--afw-accent); text-decoration: none; }
.afw-rule-links__sub { margin-top: 3px; font-size: 12px; line-height: 1.5; color: var(--afw-text-mut); }
.afw-rule-link { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; padding: 9px 12px; border: 1px solid var(--afw-border); border-radius: 8px; background: var(--afw-soft); }
.afw-rule-link.is-error { border-color: #fca5a5; background: #fef2f2; }
.afw-rule-link__text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 220px; min-width: 0; }
.afw-rule-link__kind { font-size: 13px; font-weight: 600; color: var(--afw-text); }
.afw-rule-link__meta { font-size: 12px; color: var(--afw-text-mut); overflow-wrap: anywhere; }
.afw-rule-link__open { flex: 0 0 auto; text-decoration: none; }
.afw-badrule-cond { margin-top: 10px; }
.afw-badrule-cond .rules-leaf { flex-wrap: wrap; }
.afw-badrule-cond .rules-leaf__value-input { width: 64px; }
.afw-badrule-cond .rules-leaf__value-input.afw-badrule-amount { width: 96px; }
.afw-badrule-cond .rules-leaf__value { flex-wrap: wrap; row-gap: 6px; }
.afw-badrule-foot { margin-top: 8px; font-size: 11.5px; line-height: 1.45; color: var(--afw-text-mut); }

/* "Suggest interests automatically" (js/shared/interest-picker.js) */
.afw-int-slot { margin-top: 12px; }
.afw-int { border: 1px solid var(--afw-border); border-radius: 10px; padding: 12px 14px; background: #fff; }
.afw-int-head { margin: 0; }
.afw-int-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.afw-int-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 999px; background: var(--afw-accent-soft); color: var(--afw-text); font-size: 12px; font-weight: 600; max-width: 100%; }
.afw-int-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.afw-int-aud { font-size: 10.5px; font-weight: 600; color: var(--afw-text-mut); }
.afw-int-x { width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--afw-text-mut); font-size: 15px; line-height: 1; cursor: pointer; }
.afw-int-x:hover { background: var(--afw-danger-soft); color: var(--afw-danger); }
.afw-int-msg { font-size: 12px; color: var(--afw-text-mut); }
.afw-int-tools { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; flex-wrap: wrap; }
.afw-int-search { flex: 1 1 240px; min-width: 0; }
.afw-int-list { margin-top: 4px; border: 1px solid var(--afw-border); border-radius: 8px; background: #fff; max-height: 260px; overflow-y: auto; box-shadow: 0 8px 22px rgba(17, 24, 39, .10); }
.afw-int-row { display: flex; align-items: baseline; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-bottom: 1px solid var(--afw-border); background: transparent; text-align: left; font: inherit; font-size: 12.5px; cursor: pointer; }
.afw-int-row:last-child { border-bottom: 0; }
.afw-int-row:hover { background: var(--afw-accent-soft); }
.afw-int-row .afw-int-name { font-weight: 600; color: var(--afw-text); }
.afw-int-path { flex: 1; min-width: 0; font-size: 11px; color: var(--afw-text-mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.afw-int-empty { padding: 9px 10px; font-size: 12px; color: var(--afw-text-mut); }
.afw-int-refresh { flex: 0 0 auto; padding: 8px 12px; border: 1px solid var(--afw-border); border-radius: 8px; background: #fff; color: var(--afw-accent); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.afw-int-refresh:hover { border-color: var(--afw-accent); }
/* SUGGEST is the action (the switch no longer runs anything on its own — 2026-11-04). */
.afw-int-suggest { background: var(--afw-accent); border-color: var(--afw-accent); color: #fff; }
.afw-int-suggest:hover { filter: brightness(1.06); border-color: var(--afw-accent); }
.afw-int-suggest:disabled { opacity: .65; cursor: progress; }
/* Who the AI decided the ad is for — the reason behind the interest chips. */
.afw-int-audience { margin: 8px 0 2px; padding: 7px 10px; border-radius: 8px; background: #F4F3FE; color: #3A33B8; font-size: 12.5px; line-height: 1.4; }
@media (prefers-color-scheme: dark) { .afw-int-audience { background: #26234A; color: #C9C5FA; } }
.afw-int-foot { margin-top: 8px; font-size: 11.5px; color: var(--afw-text-mut); }
.afw-plink-note {
    margin: 2px 0 6px;
    padding: 6px 10px;
    border-radius: 7px;
    background: var(--afw-ok-soft);
    color: var(--afw-ok);
    font-size: 12px;
    font-weight: 600;
}
.afw-plink-chosen {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--afw-bg);
    border: 1px solid var(--afw-accent);
    border-radius: 8px;
}
.afw-plink-btn {
    flex: 0 0 auto;
    height: 30px;
    padding: 0 12px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--afw-accent);
    background: var(--afw-accent-soft);
    border: 0;
    border-radius: 7px;
    cursor: pointer;
}
.afw-plink-x {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    font-size: 18px;
    line-height: 1;
    color: var(--afw-text-mut);
    background: none;
    border: 0;
    border-radius: 7px;
    cursor: pointer;
}
.afw-plink-x:hover { color: var(--afw-danger); background: var(--afw-danger-soft); }

/* ============================================================================
 * Step 2 — PARALLEL PREVIEW grid
 *
 * Side-scrolls horizontally on narrow screens, wraps to a grid on desktop.
 * Each card is fixed-width (280px) so shrinking the modal doesn't squish
 * cards into unreadable narrow strips.
 * ============================================================================ */
/* SOTA preview — wider cards with image-left / body-right split so
   the copy editor has real estate to breathe. Uses auto-fit so a
   single banner gets a single full-width card (no phantom empty
   second column), and 2+ banners flow into 2- or 3-up rows on
   wider viewports. On narrow screens the card stacks (image on
   top, body below) via the .afw-preview-card media query. */
.afw-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(640px, 100%), 1fr));
    gap: 18px;
    padding-bottom: 8px;
    margin: 0;
}
@media (max-width: 700px) {
    .afw-preview-grid {
        grid-template-columns: 1fr;
    }
}
.afw-preview-card {
    background: var(--afw-bg);
    border: 1.5px solid var(--afw-border-2);
    border-radius: 14px;
    /* NO overflow:hidden on the card — it was the silent killer of
       `position: sticky` on the image cell. With overflow:hidden the
       card creates a clipping context that, in some browser/grid
       combinations, prevents the sticky element from translating
       within its grid track. The image cell still clips its own
       content via overflow:hidden (.afw-preview-img), so the rounded
       corners stay clean. */
    display: grid;
    grid-template-columns: minmax(min(280px, 100%), 38%) 1fr;
    /* `align-items: start` lets the image cell stay at its natural
       aspect-ratio height while the body cell grows to fit its
       content (5 variants × 3 fields can easily exceed 600px). The
       default `stretch` was forcing the body to the image's height
       and clipping the variant inputs via overflow:hidden.
       NOTE: with align-items:start, each grid item sits at its
       natural height; the GRID ROW is sized to the tallest item
       (body cell). That gives the sticky image plenty of vertical
       travel within the card. */
    align-items: start;
    /* Positioning context for descendants — belt-and-braces so the
       sticky image's containing-block resolution doesn't escape up
       to .afw-body in some browsers. */
    position: relative;
    transition: box-shadow 0.18s, border-color 0.18s;
}
.afw-preview-card:hover {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    border-color: var(--afw-accent-2, #c7d2fe);
}
@media (max-width: 700px) {
    /* Stacked on narrow screens — image full-width on top, body below. */
    .afw-preview-card {
        grid-template-columns: 1fr;
        min-height: 0;
    }
}
/* Remove-image (✕) control on each Copy-step preview card. */
.afw-preview-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 999px;
    background: rgba(17, 17, 20, 0.62);
    color: #fff;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    transition: background 0.12s, opacity 0.12s;
}
.afw-preview-remove:hover { background: #d33; opacity: 1; }
.afw-preview-remove:disabled { opacity: 0.3; cursor: not-allowed; }

.afw-preview-img {
    /* The frame matches the banner's TRUE aspect ratio (set inline per image
       in _previewCard from sourceW/sourceH, default 1:1 below). object-fit
       :contain on the img keeps it un-cropped; max-height caps very tall
       ratios (9:16) so the modal stays usable. */
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 72vh;
    /* Inner radius matches the card's outer radius minus its border
       width so corner-rounding looks clean now that .afw-preview-card
       no longer has overflow:hidden clipping the children. */
    border-top-left-radius: 12.5px;
    background:
        linear-gradient(45deg, #ececf1 25%, transparent 25%),
        linear-gradient(-45deg, #ececf1 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ececf1 75%),
        linear-gradient(-45deg, transparent 75%, #ececf1 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-color: #f7f7fa;
    overflow: hidden;
    position: relative;   /* anchor for .afw-preview-remove */
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--afw-border-2);
    /* Sticky inside the preview card — the image pins to the top of
       the card while the user scrolls the (often-tall) editable copy
       body next to it. The sticky element is constrained by its
       parent (.afw-preview-card), so once the card's bottom edge
       reaches the scroll viewport top, the image scrolls away with
       the card — naturally giving way to the NEXT card's image.
       `align-self: start` keeps the cell at its natural 360 px height
       instead of stretching to the body's full height (the prior
       behaviour, before sticky, that would have pinned a 600 px
       blank cell to the top).
       Skip on narrow viewports where the layout stacks vertically —
       sticky on a stacked image would awkwardly cover the body
       below it. */
    position: sticky;
    top: 12px;
    align-self: start;
    z-index: 1;
}
@media (max-width: 700px) {
    .afw-preview-img {
        border-right: 0;
        border-bottom: 1px solid var(--afw-border-2);
        max-height: 60vh;
        /* On narrow screens the card stacks vertically (image above
           body), so sticky would awkwardly cover the body input fields
           when the user scrolls. Drop sticky here — the image just
           sits at the top of the stacked card like before. */
        position: static;
    }
}
.afw-preview-img img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}
.afw-preview-body {
    padding: 20px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;        /* lets long lines wrap instead of forcing a grow */
    /* Intentionally NO overflow:hidden — variant editor rows can grow
       past the image cell's height, and we want the body cell to grow
       to fit them. The card's outer overflow:hidden + border-radius
       handles the rounded clipping at the card edges. */
}

/* Bigger / cleaner inputs inside the preview cards specifically.
   Bumping the global .afw-input would change every form in the
   wizard; scoping under .afw-preview-body keeps the change targeted
   to the editor cards where reading clarity matters most. */
.afw-preview-body .afw-input,
.afw-preview-body .afw-textarea {
    font-size: 14.5px;
    line-height: 1.55;
    padding: 11px 14px;
    border-radius: 10px;
}
.afw-preview-body .afw-textarea {
    min-height: 92px;
}
.afw-preview-body .afw-field.is-compact .afw-input,
.afw-preview-body .afw-field.is-compact .afw-textarea {
    font-size: 14px;
    padding: 10px 13px;
}

/* --- Multi-variant editor blocks (headlines / primary texts / descriptions) --- */
.afw-variant-block {
    display: flex;
    flex-direction: column;
    gap: 9px;
    border-top: 1px solid var(--afw-border-2, #eaeaef);
    padding-top: 14px;
    margin-top: 4px;
}
.afw-variant-block:first-of-type {
    border-top: 0;
    padding-top: 0;
    margin-top: 0;
}
.afw-variant-block-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 2px;
}
.afw-variant-block-label {
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-primary, #1a1a2e);
}
.afw-variant-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--afw-accent, #5B53E8);
    background: var(--afw-accent-soft, rgba(99, 102, 241, 0.12));
    padding: 3px 9px;
    border-radius: 999px;
    cursor: help;
    letter-spacing: 0.3px;
}
/* Over-cap state — turns red when the user has selected more than
   Meta's 5-per-field limit so they notice and trim before dispatch. */
.afw-variant-count.is-over-cap {
    color: #b91c1c;
    background: #fee2e2;
}

.afw-variant-select {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    margin-top: 11px;
    cursor: pointer;
    accent-color: var(--afw-accent, #5B53E8);
}
/* Visually dim unselected rows so the "shipping to Meta" set is
   instantly scannable. The user can still edit unselected rows
   in case they want to tweak before selecting. */
.afw-variant-row.is-unselected .afw-variant-input,
.afw-variant-row.is-unselected .afw-variant-row-num,
.afw-variant-row.is-unselected .afw-variant-provider-badge {
    opacity: 0.55;
}
.afw-variant-row.is-unselected .afw-variant-input {
    background: var(--bg-tertiary, #f7f7fa);
}
/* Divider between selected top-5 and unselected bottom-5 — only
   rendered when the dual-parallel ranker produced more than 5
   variants per field, so the user can see WHY rows 6-10 are dimmed
   and HOW to swap one in. */
.afw-variant-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0 2px;
    padding: 0 2px;
}
.afw-variant-divider::before,
.afw-variant-divider::after {
    content: '';
    flex: 1 1 auto;
    height: 1px;
    background: var(--afw-border, rgba(15, 23, 42, 0.08));
}
.afw-variant-divider-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--afw-text-mut, #6b7280);
    letter-spacing: 0.2px;
    text-transform: uppercase;
    white-space: nowrap;
}
.afw-variant-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.afw-variant-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.afw-variant-row-num {
    flex: 0 0 28px;
    font-size: 11px;
    font-weight: 700;
    color: var(--afw-accent, #5B53E8);
    background: var(--afw-accent-soft, rgba(99, 102, 241, 0.12));
    padding: 8px 0;
    text-align: center;
    border-radius: 7px;
    line-height: 1.2;
    margin-top: 1px;
    letter-spacing: 0.3px;
}

/* Provider badge — only rendered when the variants have multiple
   sources (dual-provider parallel mode). Tiny chip on the left of
   the input that names the model that wrote this row, so the user
   picks winners knowing the source. */
.afw-variant-provider-badge {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 6px 8px;
    border-radius: 6px;
    margin-top: 1px;
    line-height: 1.2;
    cursor: help;
    border: 1px solid transparent;
}
.afw-variant-provider-badge.prov-claude {
    /* Anthropic warmth */
    background: #fef3e7;
    color: #b45309;
    border-color: #fde2bd;
}
.afw-variant-provider-badge.prov-openai {
    /* OpenAI green */
    background: #ecfdf5;
    color: #047857;
    border-color: #bef0d6;
}

/* Result-panel warning row — shown when an ad shipped without all 3
   size variants (square / story / landscape). Highlights that Meta
   will auto-crop one image across all placements instead of serving
   the right-aspect image per placement. */
.afw-result-warn {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde2bd;
    font-size: 12px;
    line-height: 1.5;
}
.afw-result-warn strong {
    display: block;
    margin-bottom: 2px;
}

/* Brand kit preview — appears inline below the kit picker when a kit
   is selected. Shows the user EXACTLY what voice / instructions / CTAs
   the AI will pick up, so the kit choice is concrete instead of
   "trust me". */
.afw-brand-preview {
    margin-top: 10px;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--afw-accent-soft, rgba(99, 102, 241, 0.06));
    border: 1px solid rgba(99, 102, 241, 0.15);
}
.afw-brand-preview-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--afw-accent, #5B53E8);
    margin-bottom: 6px;
    letter-spacing: 0.3px;
}
.afw-brand-preview-line {
    font-size: 12px;
    color: var(--afw-text, #1a1a2e);
    line-height: 1.5;
    margin-bottom: 3px;
    word-break: break-word;
}
.afw-brand-preview-line:last-child { margin-bottom: 0; }
.afw-variant-input {
    flex: 1;
    min-width: 0;
    /* Variant inputs match the upgraded preview-body input rhythm. */
    font-size: 14.5px !important;
    line-height: 1.55 !important;
    padding: 11px 14px !important;
}
.afw-variant-input.afw-textarea {
    min-height: 78px !important;
}
/* Live length counter under every primary text / headline / description box (js/shared/ad-text-limits.js). */
.afw-text-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.afw-text-wrap > .afw-variant-input,
.afw-text-wrap > .afw-input,
.afw-text-wrap > textarea { width: 100%; box-sizing: border-box; }
.afw-variant-input.afw-textarea.is-primary-text {
    min-height: 132px !important;
    resize: vertical;
}
.afw-text-count {
    font-size: 11.5px;
    line-height: 1.4;
    color: var(--text-muted, #6b7280);
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.afw-text-count[data-state="long"] { color: #b45309; }
.afw-text-count[data-state="over"] { color: #b91c1c; font-weight: 600; }
.afw-variant-input.is-over-limit,
.afw-input.is-over-limit { border-color: #dc2626 !important; }

/* Primary text style toolbar (js/shared/text-styler.js): Unicode bold / italic / strike, bullets, emoji, symbols. */
.afw-ts { display: flex; flex-direction: column; gap: 6px; width: 100%; min-width: 0; }
.afw-ts > textarea { width: 100%; box-sizing: border-box; }
.afw-ts-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
    padding: 3px; border: 1px solid var(--afw-border-2, #eaeaef); border-radius: 8px;
    background: var(--bg-secondary, #fafafb);
}
.afw-ts-btn {
    min-width: 30px; height: 28px; padding: 0 7px;
    border: 0; border-radius: 6px; background: transparent;
    font: 600 13.5px/1 'IBM Plex Sans', system-ui, sans-serif; color: var(--text-primary, #1a1a2e);
    cursor: pointer;
}
.afw-ts-btn:hover { background: rgba(91, 83, 232, 0.10); }
.afw-ts-btn:focus-visible { outline: 2px solid var(--accent, #5B53E8); outline-offset: 1px; }
.afw-ts-btn sub { font-size: 9px; }
.afw-ts-btn--emoji { font-size: 15px; }
.afw-ts-sep { width: 1px; height: 18px; margin: 0 4px; background: var(--afw-border-2, #eaeaef); }
.afw-ts-pop {
    position: fixed; z-index: 100000; width: 320px; max-height: 340px; overflow-y: auto;
    padding: 10px 12px 12px; border: 1px solid var(--afw-border-2, #eaeaef); border-radius: 12px;
    background: var(--bg-primary, #fff); box-shadow: 0 12px 32px rgba(17, 17, 39, 0.16);
}
.afw-ts-pop-h { margin: 6px 44px 4px 2px; font-size: 11px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; color: var(--text-muted, #6b7280); }
.afw-ts-pop-h + .afw-ts-grid { margin-bottom: 4px; }
.afw-ts-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.afw-ts-cell {
    height: 32px; border: 0; border-radius: 6px; background: transparent; cursor: pointer;
    font-size: 18px; line-height: 1; color: var(--text-primary, #1a1a2e);
}
.afw-ts-cell:hover, .afw-ts-cell:focus-visible { background: rgba(91, 83, 232, 0.10); outline: none; }
.afw-variant-remove {
    flex: 0 0 32px;
    width: 32px;
    height: 38px;
    margin-top: 1px;
    padding: 0;
    border: 1px solid var(--afw-border-2, #eaeaef);
    background: var(--bg-secondary, #fff);
    color: var(--text-muted, #9aa0a6);
    border-radius: 7px;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.12s;
}
.afw-variant-remove:hover:not(:disabled) {
    color: #b91c1c;
    border-color: #fca5a5;
    background: #fee2e2;
}
.afw-variant-remove:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.afw-variant-add {
    align-self: flex-start;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    border: 1px dashed var(--afw-border-2, #e0e0e6);
    border-radius: 7px;
    background: transparent;
    color: var(--text-secondary, #5f6368);
    cursor: pointer;
    transition: all 0.12s;
    margin-top: 2px;
}
.afw-variant-add:hover {
    color: var(--afw-accent, #5B53E8);
    border-color: var(--afw-accent, #5B53E8);
    background: var(--afw-accent-soft, rgba(99, 102, 241, 0.06));
}

/* =================================================================
   Per-banner ad-creation progress cards. Replaces the legacy
   one-line-per-banner cell with a richer card showing thumbnail,
   4-stage strip (queued → uploading → creating → published),
   animated progress bar, and a status pill. Gives users an
   unambiguous "this is still running" signal during the 5-15s
   Meta upload + creative-build window.
   ================================================================= */
.afw-adcreate-wrap {
    width: 100%;
    margin-top: 12px;
}
.afw-adcreate-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
    gap: 12px;
}
.afw-adcreate-card {
    background: var(--bg-secondary, #fff);
    border: 1px solid var(--border-subtle, #eaeaef);
    border-radius: 10px;
    padding: 12px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.afw-adcreate-card.is-running,
.afw-adcreate-card.is-retrying {
    border-color: var(--afw-accent, #5B53E8);
    box-shadow: 0 0 0 3px var(--afw-accent-soft, rgba(99, 102, 241, 0.10));
}
.afw-adcreate-card.is-done {
    border-color: #10b981;
    background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 60%);
}
.afw-adcreate-card.is-error {
    border-color: #fca5a5;
    background: #fef2f2;
}

.afw-adcreate-head {
    display: flex;
    align-items: center;
    gap: 10px;
}
.afw-adcreate-thumb {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-tertiary, #f0f0f2);
    border: 1px solid var(--border-subtle, #eaeaef);
}
.afw-adcreate-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.afw-adcreate-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.afw-adcreate-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1a1a2e);
}
.afw-adcreate-pill {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted, #9aa0a6);
    align-self: flex-start;
}
.afw-adcreate-card.is-running   .afw-adcreate-pill,
.afw-adcreate-card.is-retrying  .afw-adcreate-pill { color: var(--afw-accent, #5B53E8); }
.afw-adcreate-card.is-done      .afw-adcreate-pill { color: #047857; }
.afw-adcreate-card.is-error     .afw-adcreate-pill { color: #b91c1c; }

/* 4-stage strip — dot + label per stage, joined by a hairline that
   colors as stages complete. */
.afw-adcreate-stages {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    position: relative;
}
.afw-adcreate-stages::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 12.5%;
    right: 12.5%;
    height: 1px;
    background: var(--border-subtle, #eaeaef);
    z-index: 0;
}
.afw-adcreate-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
    z-index: 1;
}
.afw-adcreate-dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--bg-tertiary, #f0f0f2);
    border: 2px solid var(--border, #e0e0e6);
    transition: all 0.18s;
}
.afw-adcreate-stage-label {
    font-size: 10px;
    color: var(--text-muted, #9aa0a6);
    text-align: center;
    line-height: 1.1;
    transition: color 0.18s;
}
.afw-adcreate-stage.is-active .afw-adcreate-dot {
    background: var(--afw-accent, #5B53E8);
    border-color: var(--afw-accent, #5B53E8);
    box-shadow: 0 0 0 0 var(--afw-accent, #5B53E8);
    animation: afwStagePulse 1.2s ease-in-out infinite;
}
.afw-adcreate-stage.is-active .afw-adcreate-stage-label {
    color: var(--afw-accent, #5B53E8);
    font-weight: 600;
}
.afw-adcreate-stage.is-done .afw-adcreate-dot {
    background: #10b981;
    border-color: #10b981;
    position: relative;
}
.afw-adcreate-stage.is-done .afw-adcreate-dot::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background: #10b981 url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12"><path fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M2.5 6.5 5 9l5-5.5"/></svg>') no-repeat center / 65%;
}
.afw-adcreate-stage.is-done .afw-adcreate-stage-label { color: #047857; }
@keyframes afwStagePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.5); }
    50%      { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0); }
}

/* Indeterminate-style progress bar — width is set by JS per stage,
   but a moving stripe overlay gives the "still alive" signal even
   when the width is static. */
.afw-adcreate-bar {
    height: 5px;
    background: var(--bg-tertiary, #f0f0f2);
    border-radius: 3px;
    overflow: hidden;
}
.afw-adcreate-bar-fill {
    height: 100%;
    width: 0;
    background: var(--afw-accent, #5B53E8);
    background-image: linear-gradient(45deg,
        rgba(255,255,255,0.18) 25%, transparent 25%,
        transparent 50%, rgba(255,255,255,0.18) 50%,
        rgba(255,255,255,0.18) 75%, transparent 75%, transparent);
    background-size: 14px 14px;
    transition: width 0.4s ease-out, background-color 0.2s;
    animation: afwBarStripes 0.9s linear infinite;
}
.afw-adcreate-card.is-done .afw-adcreate-bar-fill {
    background-color: #10b981;
    animation: none;
}
.afw-adcreate-card.is-error .afw-adcreate-bar-fill {
    background-color: #ef4444;
    animation: none;
}
.afw-adcreate-card.is-pending .afw-adcreate-bar-fill { animation: none; }
@keyframes afwBarStripes {
    from { background-position: 0 0; }
    to   { background-position: 14px 0; }
}

.afw-adcreate-status {
    font-size: 11.5px;
    color: var(--text-secondary, #5f6368);
    line-height: 1.4;
    min-height: 16px;
}
.afw-adcreate-card.is-error .afw-adcreate-status { color: #b91c1c; }
.afw-adcreate-card.is-done  .afw-adcreate-status { color: #047857; }

/* Skeleton shimmer while the generator is writing copy. Three bars
   gives the user a clear "5 slots being filled in" signal. */
.afw-variant-skeleton {
    height: 26px;
    border-radius: 5px;
    background: linear-gradient(90deg, var(--bg-tertiary, #f0f0f2) 0%, var(--bg-hover, #ededf0) 50%, var(--bg-tertiary, #f0f0f2) 100%);
    background-size: 200% 100%;
    animation: afwShimmer 1.4s ease-in-out infinite;
}
@keyframes afwShimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}
.afw-preview-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
    padding-bottom: 4px;
    /* divider removed — the gap between the head row and the first
       variant block reads as enough separation; the extra horizontal
       rule felt heavy under the small ✓ READY pill. */
}
.afw-preview-num {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--afw-accent);
    background: var(--afw-accent-soft);
    padding: 4px 10px;
    border-radius: 7px;
    letter-spacing: 0.4px;
    flex-shrink: 0;
}
.afw-preview-status {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex: 1;
}
.afw-preview-status.is-pending { color: var(--afw-accent); }
.afw-preview-status.is-ok      { color: var(--afw-ok); }
.afw-preview-status.is-err     { color: var(--afw-danger); }
.afw-preview-regen {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--afw-text-mut);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.afw-preview-regen:hover:not(:disabled) {
    background: var(--afw-accent-soft);
    color: var(--afw-accent);
    border-color: var(--afw-accent-ring);
}
.afw-preview-regen:disabled { opacity: 0.4; cursor: not-allowed; }

.afw-preview-err-msg {
    font-size: 11.5px;
    color: var(--afw-danger);
    background: var(--afw-danger-soft);
    padding: 6px 10px;
    border-radius: 6px;
    line-height: 1.4;
}

/* Compact field variant — used inside preview cards */
.afw-field.is-compact { gap: 4px; }
.afw-field.is-compact .afw-field-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.afw-field.is-compact .afw-input,
.afw-field.is-compact .afw-textarea {
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 7px;
}
.afw-field.is-compact .afw-textarea {
    min-height: 60px;
    resize: vertical;
}
.afw-input:disabled,
.afw-textarea:disabled {
    background: #f9fafb;
    color: var(--afw-text-mut);
    cursor: not-allowed;
}

/* Bulk action row above the grid */
.afw-bulk-row {
    display: flex;
    justify-content: flex-end;
    margin: -4px 0 4px;
}

/* ============================================================================
 * Step 3 — PUSH progress + result
 * ============================================================================ */
.afw-push-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 40px 24px;
    background: var(--afw-soft);
    border: 1px solid var(--afw-border);
    border-radius: 12px;
    font-size: 14px;
    color: var(--afw-text-mid);
    min-height: 120px;
}
.afw-push-status .spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--afw-accent);
    border-radius: 50%;
    animation: afw-spin 0.7s linear infinite;
    flex-shrink: 0;
}

/* Per-banner result block (shows source banner + each variant outcome) */
.afw-result-source {
    display: flex;
    gap: 14px;
    padding: 14px;
    background: var(--afw-bg);
    border: 1px solid var(--afw-border);
    border-radius: 12px;
    margin-bottom: 10px;
}
.afw-result-source-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.afw-result-source-text strong {
    font-size: 13.5px;
    color: var(--afw-text);
}
/* Header row inside the result tile — banner label on the left,
   "Open in Ads Manager ↗" link on the right. flex-row so the link
   is right-aligned next to the title, with comfortable spacing. */
.afw-result-source-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.afw-result-ad-link {
    font-size: 12px;
    font-weight: 600;
    color: var(--afw-accent, #4f46e5);
    text-decoration: none;
    padding: 4px 9px;
    border-radius: 6px;
    border: 1px solid var(--afw-border-2, #e2e8f0);
    background: var(--afw-bg-2, #f7f7fa);
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
}
.afw-result-ad-link:hover {
    background: var(--afw-accent, #4f46e5);
    color: #fff;
    border-color: var(--afw-accent, #4f46e5);
}
.afw-result-variants {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.afw-result-variant {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 12px;
}
.afw-result-variant.is-ok   { background: rgba(22, 163, 74, 0.08);  color: var(--afw-ok); }
.afw-result-variant.is-fail { background: rgba(220, 38, 38, 0.08);  color: var(--afw-danger); }
.afw-result-variant-label {
    font-weight: 600;
    flex-shrink: 0;
    min-width: 140px;
}
.afw-result-variant-meta {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* ============================================================================
 * Step 1 (Setup) — Destination + Campaign + Ad set as a 3-COLUMN shell.
 *
 * LEFT  = destination/account sidebar (with search at the top).
 * MIDDLE = campaign list.
 * RIGHT = adset (heaviest content — form for budget, audience, etc.).
 * Brief & destination URL stays below the shell as a full-width card.
 *
 * Widths: 260px sidebar + 1fr campaigns + 1.5fr adset. The adset gets
 * the largest share because its form is the densest of the three.
 *
 * Responsive collapse:
 *   ≥1100px → 3 columns as above
 *   880-1100 → 2 columns: [sidebar | campaign+adset stacked]
 *   <880    → 1 column: [sidebar / campaign / adset stacked]
 *
 * The sidebar is sticky-positioned so it stays visible as the user
 * scrolls the right pane(s); the `.afw-dest-list` inside it caps its
 * own height so 30 linked accounts don't blow it out.
 * ============================================================================ */

.afw-destination-shell {
    display: grid;
    grid-template-columns: minmax(min(240px, 100%), 260px) minmax(0, 1fr) minmax(0, 1.5fr);
    gap: 14px;
    margin-bottom: 14px;
    align-items: start;
}
@media (max-width: 1100px) {
    /* Two-column fallback: sidebar on the left, campaign + adset stacked
       on the right. The right column carries `subgrid`-like stacking via
       a flex column on each pane. We add a span to the campaign pane to
       keep it labeled cleanly at this breakpoint. */
    .afw-destination-shell {
        grid-template-columns: minmax(min(260px, 100%), 300px) minmax(0, 1fr);
    }
    .afw-destination-pane--mid,
    .afw-destination-pane--right {
        grid-column: 2;
    }
}
@media (max-width: 760px) {
    .afw-destination-shell {
        grid-template-columns: 1fr;
    }
    .afw-destination-pane--mid,
    .afw-destination-pane--right {
        grid-column: 1;
    }
}
/* One ad account per project → no picker: the sidebar is hidden, Campaign + Ad set take the row,
   and .afw-acct-bar above names the account. */
.afw-destination-shell.is-single-account {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
}
.afw-destination-shell.is-single-account .afw-destination-pane--left { display: none; }
.afw-destination-shell.is-single-account .afw-destination-pane--mid,
.afw-destination-shell.is-single-account .afw-destination-pane--right { grid-column: auto; }
@media (max-width: 1100px) {
    .afw-destination-shell.is-single-account { grid-template-columns: minmax(0, 1fr); }
}
.afw-destination-shell[hidden] { display: none; }
/* Meta connection missing / expired / unfinished — top of the popup, with a direct link to the fix
   (js/shared/meta-connection-alert.js). */
.afw-conn-alert {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin: 0 0 14px;
    padding: 12px 14px;
    border: 1px solid #fca5a5;
    border-left: 4px solid #dc2626;
    border-radius: 10px;
    background: #fef2f2;
}
.afw-conn-alert--setup { border-color: #fcd34d; border-left-color: #d97706; background: #fffbeb; }
.afw-conn-alert--none  { border-color: #c7d2fe; border-left-color: var(--afw-accent, #5B53E8); background: #eef2ff; }
.afw-conn-alert__text { flex: 1 1 260px; min-width: 0; }
.afw-conn-alert__title { font-size: 14px; font-weight: 600; color: var(--afw-text, #111827); }
.afw-conn-alert__body { margin-top: 3px; font-size: 12.5px; line-height: 1.5; color: #4b5563; overflow-wrap: anywhere; }
.afw-conn-alert__cta { flex: 0 0 auto; text-decoration: none; white-space: nowrap; }
.afw-acct-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 0 14px;
    padding: 10px 14px;
    border: 1px solid var(--afw-border, #e5e7eb);
    border-radius: 10px;
    background: #fff;
}
.afw-acct-bar[hidden] { display: none; }
.afw-acct-bar__label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b7280;
}
.afw-acct-bar__main {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
    flex: 1 1 auto;
}
.afw-acct-bar__name {
    font-size: 14px;
    font-weight: 600;
    color: var(--afw-text, #111827);
    overflow-wrap: anywhere;
}
.afw-acct-bar__meta {
    font-size: 12.5px;
    color: #6b7280;
    overflow-wrap: anywhere;
}
.afw-acct-bar__refresh { margin-left: auto; }
.afw-destination-pane {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}
.afw-destination-pane--left {
    /* Sticky height — the account list never crowds the rest of the
       wizard. The internal `.afw-dest-list` handles its own overflow
       scroll. */
    position: sticky;
    top: 0;
    align-self: start;
}
.afw-destination-pane--mid,
.afw-destination-pane--right {
    min-width: 0;
}
/* The destination card itself loses its bottom margin inside the shell
   — the shell's grid gap handles spacing now. Same for campaign + adset. */
.afw-destination-shell .afw-section {
    margin-bottom: 0;
}
/* Destination card — compact padding inside the sidebar so the list of
   accounts sees the most vertical space. */
.afw-destination-card {
    padding: 14px 14px 10px;
}
.afw-destination-card .afw-section-head {
    margin-bottom: 8px;
}

/* Search input above the account list. Hidden by JS when there are ≤3
   linked accounts (the list is a single-glance scan; the search is
   noise in that case). */
.afw-dest-search-wrap {
    margin: 0 0 8px;
}
.afw-dest-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--afw-border, #e5e7eb);
    border-radius: 8px;
    background: #fff;
    font-size: 13px;
    color: var(--afw-text, #111827);
    transition: border-color 0.12s, box-shadow 0.12s;
    box-sizing: border-box;
}
.afw-dest-search::placeholder {
    color: #9ca3af;
}
.afw-dest-search:focus {
    outline: none;
    border-color: var(--afw-accent, #5B53E8);
    box-shadow: var(--focus-ring);
}
/* Account list inside the sidebar — vertical scroll cap so 30 linked
   accounts don't blow out the sidebar height. */
.afw-dest-list {
    max-height: 460px;
    overflow-y: auto;
    /* Reserve room for the scrollbar so cards don't shift sideways
       when the list grows past the cap. */
    padding-right: 2px;
}
/* When inside the sidebar, the pick cards get tighter padding so more
   accounts fit on screen. Title + subtitle WRAP (rather than ellipsing)
   so long account names stay fully readable — the narrow sidebar would
   otherwise truncate them to one character. */
.afw-destination-card .afw-pick-card {
    padding: 10px 12px;
    align-items: flex-start;
}
.afw-destination-card .afw-pick-title {
    /* Allow long custom_name to wrap onto a second line instead of
       ellipsing in the narrow sidebar column. */
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    word-break: break-word;
    line-height: 1.25;
}
.afw-destination-card .afw-pick-subtitle {
    /* Same treatment for the subtitle (email · ad account · id) so the
       user can see WHICH ad account / which login this row represents.
       Cap at two lines via line-clamp so the card height stays bounded
       on accounts with very long subtitles. */
    white-space: normal;
    overflow: hidden;
    text-overflow: clip;
    word-break: break-word;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ── Video "Edit copy" card — video on the LEFT, copy fields on the RIGHT
   (afw-vaw-*; the image flow's analog is the side-by-side preview grid). Two
   columns on desktop; stacks under ~760px so it stays usable on narrow modals. ── */
.afw-vaw-copy {
    display: flex;
    flex-direction: row;   /* override .afw-section-body's column */
    /* flex-start, NOT stretch: stretch tied the video's height to the fields
       column, so every extra headline/description suggestion made the poster
       taller. The video's size should depend on the video, not on how much copy
       the AI happened to return. */
    align-items: flex-start;
    gap: 20px;
}
.afw-vaw-copy-thumb {
    flex: 0 0 232px;
    width: 232px;
    /* Fixed, predictable frame. 9:16 is the Meta video default (Reels/Stories),
       so at 232px wide this lands ~412px tall; max-height caps it for any other
       ratio, and the poster is object-fit:cover either way. */
    align-self: flex-start;
    aspect-ratio: 9 / 16;
    max-height: 420px;
    min-height: 220px;
    /* Follow the scroll inside .afw-body so the video stays visible while the
       user works down a long list of suggestions. sticky also establishes the
       containing block that the absolutely-positioned play button and inline
       player rely on, so it replaces the old `position: relative` rather than
       being added alongside it. */
    position: sticky;
    top: 12px;
    border-radius: 12px;
    overflow: hidden;
    background: #0b0b0f;
    cursor: pointer;
}
.afw-vaw-copy-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.afw-vaw-copy-thumb.is-empty {
    background: repeating-linear-gradient(45deg, #f1f1f4, #f1f1f4 10px, #e9e9ee 10px, #e9e9ee 20px);
}
.afw-vaw-copy-thumb.is-empty::after {
    content: '🎬'; position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center; font-size: 30px; opacity: .45;
}
.afw-vaw-copy-thumb .afw-vaw-play {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 54px; height: 54px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .55); color: #fff;
    pointer-events: none; backdrop-filter: blur(1px);
    transition: background .15s, transform .15s;
}
.afw-vaw-copy-thumb .afw-vaw-play svg { width: 24px; height: 24px; margin-left: 3px; }
.afw-vaw-copy-thumb:hover .afw-vaw-play { background: rgba(0, 0, 0, .72); transform: translate(-50%, -50%) scale(1.06); }
/* Once playing, the poster + badge are swapped out for the player, which fills the same box. */
.afw-vaw-copy-thumb.is-playing { cursor: default; }
.afw-vaw-copy-thumb .afw-vaw-inline-frame,
.afw-vaw-copy-thumb .afw-vaw-inline-video {
    display: block; width: 100%; height: 100%; border: 0;
    object-fit: contain; background: #0b0b0f;
}
.afw-vaw-fields { flex: 1 1 auto; min-width: 0; }
/* "What is this video about?" — the copy-brief panel (describe → generate → pick).
   A soft accent-tinted card groups the textarea + Generate action so the source
   of the AI copy is visually one unit, distinct from the pickers below it. */
.afw-vaw-copy-prompt {
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: rgba(91, 83, 232, 0.04);
}
.afw-vaw-copy-prompt .afw-textarea { resize: vertical; min-height: 54px; }
.afw-vaw-genrow { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.afw-vaw-gen { white-space: nowrap; }
.afw-vaw-gen:disabled { opacity: .55; cursor: not-allowed; }
.afw-vaw-genhint { font-size: 12px; color: #6b7280; line-height: 1.45; flex: 1 1 240px; margin: 0; }
/* Pre-generation placeholder — shown INSTEAD of the three variant editors until
   copy exists (generated, CSV-provided, or the user opts into manual writing). */
.afw-vaw-copy-placeholder {
    border: 1px dashed #d1d5db;
    border-radius: 10px;
    padding: 18px 14px;
    text-align: center;
    color: #6b7280;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.afw-vaw-copy-placeholder-title { font-weight: 600; color: #374151; font-size: 13px; }
.afw-vaw-copy-placeholder-sub { font-size: 12px; max-width: 460px; line-height: 1.5; }
.afw-vaw-manual { margin-top: 4px; font-size: 12px; padding: 4px 10px; }
.afw-vaw-linkrow { display: flex; gap: 8px; align-items: stretch; }
.afw-vaw-linkrow > :first-child { flex: 1 1 auto; min-width: 0; }
.afw-vaw-fromlink { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 760px) {
    .afw-vaw-copy { flex-direction: column; }
    .afw-vaw-copy-thumb {
        width: 100%;
        flex-basis: auto;
        /* Stacked, the video sits ABOVE the fields, so sticky would pin it over
           the copy the user is editing. It also drops the 9:16 ratio: at full
           modal width that would be a very tall poster, and max-height alone
           would letterbox it. */
        position: relative;
        aspect-ratio: auto;
        height: 260px;
        max-height: 320px;
        min-height: 200px;
    }
}

/* ── "Override copy for all ads" panel — shared by the image + video wizards
   (js/studio/copy-override.js). Deliberately highlighted (accent border + tint)
   so it reads as a powerful batch action, but kept clean + compact. ── */
.copy-override {
    margin-top: 18px;
    border: 1.5px solid var(--accent, #5B53E8);
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
    /* .afw-body is a flex COLUMN; without this the panel (a flex child) gets shrunk to fit and its
       overflow:hidden CLIPS the editor — keep its natural content height so the body scrolls instead. */
    flex: 0 0 auto;
}
.copy-override-head {
    display: flex; align-items: flex-start; gap: 14px;
    padding: 13px 16px;
    background: rgba(99, 102, 241, 0.08);
    cursor: default;               /* the APPLY switch is the show/hide control, not the bar */
}
.copy-override-head:focus-visible { outline: 2px solid var(--accent, #5B53E8); outline-offset: -2px; }
/* show/hide chevron — points down when open, rotates to ▸ when collapsed */
.copy-override-chevron {
    flex: 0 0 auto; align-self: center; font-size: 12px; line-height: 1;
    color: var(--accent, #4f46e5); transition: transform .15s; user-select: none;
}
.copy-override.is-collapsed .copy-override-chevron { transform: rotate(-90deg); }
/* Collapsed → slim bar (just the title + apply switch + chevron); the editor body
   and the explanatory sub-line are hidden until the user opens it. */
.copy-override.is-collapsed .copy-override-body { display: none; }
.copy-override.is-collapsed .copy-override-sub  { display: none; }
.copy-override-titles { flex: 1 1 auto; min-width: 0; }
.copy-override-title { font-size: 14px; font-weight: 700; color: var(--accent, #4f46e5); letter-spacing: 0.01em; }
.copy-override-sub { font-size: 12px; color: #6b7280; margin-top: 3px; line-height: 1.45; }
/* toggle switch */
.copy-override-switch { position: relative; flex: 0 0 auto; width: 44px; height: 24px; cursor: pointer; margin-top: 2px; }
.copy-override-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.copy-override-slider { position: absolute; inset: 0; border-radius: 999px; background: #cbd5e1; transition: background 0.15s; }
.copy-override-slider::before {
    content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px;
    background: #fff; border-radius: 50%; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.copy-override-switch input:checked + .copy-override-slider { background: var(--accent, #5B53E8); }
.copy-override-switch input:checked + .copy-override-slider::before { transform: translateX(20px); }
/* Body is always shown (no fixed height → it grows to full content + the modal scrolls).
   The FIELD ROWS are dimmed + non-interactive until the toggle is ON (so the overrides are
   DISCOVERABLE but opt-in); the AI helper above stays fully usable, and generating auto-flips
   the toggle. Dimming the field rows (not the whole body) keeps the AI box clickable. */
.copy-override-body { display: block; padding: 4px 16px 16px; }
.copy-override-field { margin-top: 12px; opacity: .5; pointer-events: none; transition: opacity .15s; }
.copy-override.is-on .copy-override-field { opacity: 1; pointer-events: auto; }
.copy-override-label { display: block; font-size: 11.5px; font-weight: 600; color: #374151; margin-bottom: 5px; }
.copy-override-input {
    width: 100%; box-sizing: border-box; border: 1px solid #d1d5db; border-radius: 8px;
    padding: 8px 10px; font-size: 13px; font-family: inherit; resize: vertical; background: #fff;
}
textarea.copy-override-input { min-height: 80px; line-height: 1.5; overflow: hidden; }   /* auto-grows via JS (autogrow) */
.copy-override-input:focus { outline: none; border-color: var(--accent, #5B53E8); box-shadow: 0 0 0 2px rgba(99,102,241,0.15); }

/* AI writer — a ChatGPT-style prompt box that drafts all three fields. Always interactive
   (lives above the dimmed fields); shown only when the wizard passes an onGenerate callback. */
.copy-override-ai { margin-top: 6px; padding: 12px; border: 1px dashed #c7c2f5; border-radius: 10px; background: #faf9ff; }
.copy-override-ai-label { font-size: 12px; font-weight: 700; color: var(--accent, #4f46e5); margin-bottom: 7px; }
.copy-override-aiprompt {
    width: 100%; box-sizing: border-box; border: 1px solid #d8d4f5; border-radius: 8px;
    padding: 9px 11px; font-size: 13px; font-family: inherit; line-height: 1.5; resize: none;
    min-height: 64px; overflow: hidden; background: #fff;   /* auto-grows via JS */
}
.copy-override-aiprompt:focus { outline: none; border-color: var(--accent, #5B53E8); box-shadow: 0 0 0 2px rgba(99,102,241,0.15); }
.copy-override-ai-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.copy-override-aibtn {
    flex: 0 0 auto; border: 0; border-radius: 8px; padding: 8px 16px; cursor: pointer;
    background: var(--accent, #5B53E8); color: #fff; font-size: 12.5px; font-weight: 700;
}
.copy-override-aibtn:hover { filter: brightness(1.05); }
.copy-override-aibtn:disabled { opacity: .6; cursor: default; }
.copy-override-ai-status { font-size: 11.5px; color: #6b7280; }
.copy-override-ai-status.is-err { color: #dc2626; }


/* ============================================================================
 * No-pixel banner (destination step)
 * Loud on purpose: without a pixel every conversions campaign is unpublishable,
 * and the user needs to know that BEFORE generating banners — not from Meta's
 * "Please select a promoted object for your ad set" after the credits are spent.
 * ========================================================================== */
.afw-nopixel {
    margin: 0 0 18px;
    padding: 16px 18px;
    border-radius: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid var(--afw-danger, #dc2626);
}
.afw-nopixel-title {
    font-size: 14.5px;
    font-weight: 700;
    color: var(--afw-danger, #dc2626);
    margin-bottom: 7px;
}
.afw-nopixel-body {
    font-size: 12.5px;
    line-height: 1.6;
    color: #7f1d1d;
}
.afw-nopixel-body + .afw-nopixel-body { margin-top: 6px; }
.afw-nopixel-fix {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #fecaca;
    font-size: 12.5px;
    line-height: 1.6;
    font-weight: 600;
    color: #7f1d1d;
}

/* ── Ad format: one ad per creative / one carousel ad (js/shared/ad-format.js) ── */
.afw-format { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.afw-format-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--afw-text-mut); }
.afw-format-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 720px) { .afw-format-row { grid-template-columns: 1fr; } }
.afw-format-opt {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; cursor: pointer;
    background: var(--afw-soft); border: 1px solid var(--afw-border); border-radius: 10px;
    transition: border-color .12s, background .12s, box-shadow .12s;
}
.afw-format-opt:hover { border-color: var(--afw-accent); }
.afw-format-opt.is-on { border-color: var(--afw-accent); background: var(--afw-accent-soft); box-shadow: 0 0 0 3px var(--afw-accent-ring); }
.afw-format-opt.is-disabled { cursor: not-allowed; opacity: .65; }
.afw-format-opt.is-disabled:hover { border-color: var(--afw-border); }
.afw-format-opt input[type="radio"] { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--afw-accent); flex-shrink: 0; }
.afw-format-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.afw-format-name { font-size: 13.5px; font-weight: 600; color: var(--afw-text); }
.afw-format-sub { font-size: 12px; line-height: 1.5; color: var(--afw-text-mut); }
.afw-format-note { margin: 0 0 14px; padding: 12px 14px; border: 1px solid var(--afw-accent-ring); background: var(--afw-accent-soft); border-radius: 10px; }
.afw-format-note-title { font-size: 13px; font-weight: 600; color: var(--afw-text); margin-bottom: 4px; }
.afw-format-note-body { font-size: 12.5px; line-height: 1.55; color: var(--afw-text-mid); }
.afw-format-note-warn { margin-top: 6px; font-size: 12px; line-height: 1.5; color: #8a5a00; }
/* carousel card order (drag & drop) */
.afw-order { margin: 10px 0 2px; }
.afw-order-title { font-size: 12px; font-weight: 600; color: var(--afw-text); margin-bottom: 8px; }
.afw-order-strip { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; }
.afw-order-card { touch-action: pan-y; flex: 0 0 116px; display: flex; flex-direction: column; gap: 6px; padding: 6px; background: var(--afw-bg, #fff); border: 1px solid var(--afw-border); border-radius: 10px; cursor: grab; user-select: none; transition: border-color .12s, box-shadow .12s, opacity .12s; }
.afw-order-card:active { cursor: grabbing; }
.afw-order-card.is-dragging { opacity: .45; }
.afw-order-card.is-over { border-color: var(--afw-accent); box-shadow: 0 0 0 3px var(--afw-accent-ring); }
.afw-order-media { position: relative; width: 100%; aspect-ratio: 1 / 1; border-radius: 7px; overflow: hidden; background: var(--afw-soft); }
.afw-order-media img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.afw-order-num { position: absolute; top: 5px; left: 5px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--afw-accent); color: #fff; font-size: 11.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.afw-order-video { position: absolute; right: 5px; bottom: 5px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; display: flex; align-items: center; justify-content: center; }
.afw-order-label { font-size: 11.5px; line-height: 1.35; color: var(--afw-text-mid); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 31px; }
.afw-order-btns { display: flex; gap: 4px; }
.afw-order-btn { flex: 1; height: 24px; border: 1px solid var(--afw-border); background: var(--afw-soft); border-radius: 6px; font-size: 12px; cursor: pointer; color: var(--afw-text); }
.afw-order-btn:hover:not(:disabled) { border-color: var(--afw-accent); }
.afw-order-btn:disabled { opacity: .35; cursor: default; }
.afw-order-opt { display: flex; align-items: flex-start; gap: 8px; margin-top: 6px; font-size: 12px; line-height: 1.5; color: var(--afw-text-mid); cursor: pointer; }
.afw-order-opt input { margin-top: 2px; accent-color: var(--afw-accent); }
/* carousel: ONE primary text above the cards */
.afw-carousel-primary { margin: 12px 0 4px; }
.afw-carousel-primary-input { width: 100%; box-sizing: border-box; min-height: 64px; resize: vertical; font: inherit; font-size: 13px; padding: 8px 10px; border: 1px solid var(--afw-border); border-radius: 8px; background: var(--afw-bg, #fff); color: var(--afw-text); }
.afw-carousel-primary-input:focus { outline: none; border-color: var(--afw-accent); box-shadow: 0 0 0 3px var(--afw-accent-ring); }
.afw-carousel-primary-row { margin-top: 6px; }
.afw-carousel-suggest-btn { flex: none; padding: 0 10px; width: auto; }
.afw-carousel-suggest-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.afw-carousel-suggest { text-align: left; padding: 8px 10px; font: inherit; font-size: 12.5px; line-height: 1.45; color: var(--afw-text); background: var(--afw-bg, #fff); border: 1px solid var(--afw-border); border-radius: 8px; cursor: pointer; }
.afw-carousel-suggest:hover { border-color: var(--afw-accent); background: var(--afw-accent-soft); }

/* Instant form picker (js/shared/lead-form.js) — Leads ad sets that collect the lead on the ad. */
.afw-leadform-body { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.afw-leadform-body .afw-input { width: 100%; }
.afw-leadform-msg { font-size: 12.5px; line-height: 1.45; color: var(--afw-warn); background: var(--afw-warn-soft); border-radius: 8px; padding: 8px 10px; }
.afw-leadform-msg a { color: inherit; text-decoration: underline; }
.afw-leadform-reload { padding: 2px 8px; font-size: 12px; }
