/* Ads (owner only; public/ads.js). Prefix ad-. Colours only through tokens (public/tokens.css), both themes. The approved
   mockup inside the shell: a quiet totals line, an auto-fill grid of ad cards (min 340px), a detail sheet (UI.sheet: a
   600px side panel on desktop and tablet, a bottom sheet on phones) with the path bars and the 7-day chart.
   A verdict is a tone (Working success, Watch warn, Losing money danger, Too early and Not running info, Not tracked
   quiet): its tint, its mark and a word, never colour alone. Orange marks only selection and focus here (Ember Means
   Act): never a verdict, never a chart series. No side stripes. Breakpoints: phone <=767, tablet 768-1099, desktop
   >=1100; 44px targets on coarse pointers; no horizontal page scroll at 375px. */

/* position:relative keeps the sr-only chart table inside #main's scroll area */
.ad{position:relative;max-width:1180px;margin:0 auto;padding-bottom:24px}

/* ---------- tones: one variable pair per verdict tone ---------- */
.ad-tone-success{--tone:var(--success);--tone-tint:var(--success-tint)}
.ad-tone-warn{--tone:var(--warn);--tone-tint:var(--warn-tint)}
.ad-tone-danger{--tone:var(--danger);--tone-tint:var(--danger-tint)}
.ad-tone-info{--tone:var(--info);--tone-tint:var(--info-tint)}
.ad-tone-quiet{--tone:var(--muted);--tone-tint:var(--raised)}

/* ---------- header: title and freshness, then Period, Show and Refresh ---------- */
.ad-head{align-items:flex-end;margin-bottom:20px}
.ad-head>.screen-head-main{flex:1 1 360px}
.ad-fresh{font:400 13px/18px var(--font)}
.ad-live{display:inline-flex;align-items:center;gap:6px;color:var(--text-2)}
.ad-live-dot{position:relative;flex:none;width:7px;height:7px;border-radius:50%;background:var(--success)}
.ad-live-dot::after{content:"";position:absolute;inset:0;border-radius:50%;background:var(--success);opacity:0;animation:ad-pulse 2.4s ease-out infinite}
@keyframes ad-pulse{from{opacity:.55;transform:scale(1)}to{opacity:0;transform:scale(2.4)}}
.ad-live.is-off .ad-live-dot{background:var(--muted)}
.ad-live.is-off .ad-live-dot::after{animation:none;display:none}
.ad-fake{color:var(--warn)}
.ad-controls{flex:0 1 auto;display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:10px}
.ad-controls-row{display:flex;align-items:center;gap:10px}
.ad-head .seg{flex:none}

/* ---------- the Meta connection banner, the stale strip, the Today note ---------- */
.ad-banner{margin:0 0 16px}
.ad-banner .banner-text>span{margin-right:4px}
.ad-link{display:inline-flex;align-items:center;min-height:32px;margin:-6px 0;padding:0;border:0;background:none;color:var(--text);font:500 14px/20px var(--font);text-align:left;text-decoration:underline;text-decoration-color:var(--line-strong);text-underline-offset:3px;cursor:pointer;-webkit-tap-highlight-color:transparent}
.ad-link:hover{color:var(--text-strong);text-decoration-color:var(--text-2)}
.ad-stale{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:0 0 16px;padding:10px 14px;border-radius:var(--r);border:1px solid color-mix(in srgb,var(--warn) 25%,transparent);background:var(--warn-tint);color:var(--warn);font:500 13px/18px var(--font)}
.ad-stale>.ad-stale-text{flex:1 1 200px}
.ad-period-note{display:flex;align-items:flex-start;gap:8px;margin:-4px 2px 16px;font:400 13px/18px var(--font);color:var(--muted)}
.ad-period-note[hidden]{display:none}
/* The Tabular Figures Rule: the `font:` shorthands on this screen reset font-variant-numeric, so its .tnum is restated at a
   higher specificity (the screen and its detail sheet). */
.ad .tnum,.ad-sheet .tnum{font-variant-numeric:tabular-nums}

/* ---------- totals: one quiet line, not tiles ---------- */
.ad-totals{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));margin:0 0 20px}
.ad-totals[hidden]{display:none}
.ad-tot{min-width:0;padding:16px 20px}
.ad-tot+.ad-tot{border-left:1px solid var(--line)}
.ad-totals>.ad-tot:only-child{grid-column:1/-1}
.ad-k{font:500 12px/16px var(--font);color:var(--muted)}
.ad-v{margin-top:4px;font:400 26px/32px var(--font-display);color:var(--text-strong);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ad-s{margin-top:2px;min-height:16px;font:400 12px/16px var(--font);color:var(--muted)}

/* ---------- the grid of cards ----------
   Desktop: cards at least 440px, so the four numbers sit in one row with their full names (two cards across the 1180px
   frame); tablet: the mock's 340px minimum with the numbers 2 x 2; phone: one column, 2 x 2. */
.ad-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(440px,1fr));gap:16px}
.ad-card{position:relative;display:flex;flex-direction:column;gap:14px;min-width:0;padding:16px;cursor:pointer;transition:border-color var(--dur-quick) ease,transform var(--dur-press) var(--ease-out-soft)}
.ad-card:hover{border-color:var(--line-strong)}
.ad-card:has(.ad-open:active){transform:scale(.99)}
.ad-card:has(.ad-open:focus-visible){outline:2px solid var(--focus-ring);outline-offset:2px}
.ad-skel{min-height:248px;cursor:default;gap:10px;justify-content:center}
.ad-skel:hover{border-color:var(--hairline)}
.ad-skel .skeleton-line:nth-child(2){width:70%}
.ad-skel .skeleton-line:nth-child(3){width:45%}
.ad-empty{grid-column:1/-1;margin:0;padding:40px 16px;border:1px dashed var(--line-strong);border-radius:var(--r-lg);text-align:center;font:400 14px/20px var(--font);color:var(--muted)}
.ad-empty-wrap{grid-column:1/-1}

/* card top: thumbnail, name and subtitle, the Running / Paused chip */
.ad-c-top{display:flex;align-items:flex-start;gap:12px;min-width:0}
.ad-thumb{position:relative;flex:none;display:grid;place-items:center;width:52px;height:72px;border-radius:var(--r-sm);overflow:hidden;background:var(--raised);border:1px solid var(--hairline)}
.ad-thumb img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block}
.ad-thumb img[hidden]{display:none}
.ad-thumb-code{padding:4px;font:500 10px/12px var(--font-display);color:var(--muted);text-align:center;overflow-wrap:anywhere}
.ad-thumb-lg{width:60px;height:84px}
.ad-c-name{flex:1;min-width:0}
.ad-name{margin:0;font:400 17px/22px var(--font-display);color:var(--text-strong);overflow-wrap:anywhere}
.ad-open{margin:0;padding:0;border:0;background:none;color:inherit;font:inherit;letter-spacing:inherit;text-align:left;cursor:pointer;-webkit-tap-highlight-color:transparent}
.ad-open:focus-visible{outline:none}
/* the whole card is the title button's target (the card itself stays an article with a heading) */
.ad-open::after{content:"";position:absolute;inset:0;border-radius:var(--r-lg)}
.ad-sub{margin:3px 0 0;font:400 12px/16px var(--font);color:var(--muted)}
.ad-c-note{display:flex;align-items:flex-start;gap:6px;margin:4px 0 0;font:400 12px/16px var(--font);color:var(--text-2)}
.ad-status{flex:none;display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 10px;border-radius:var(--r-pill);background:var(--raised);color:var(--text-2);font:600 11px/16px var(--font);white-space:nowrap}
.ad-dot{flex:none;width:6px;height:6px;border-radius:50%;background:var(--muted)}
.ad-status.is-on{background:var(--success-tint);color:var(--success)}
.ad-status.is-on .ad-dot,.ad-status-word.is-on .ad-dot{background:var(--success)}

/* the verdict: tint, a mark on the tone, the word and its reason */
.ad-verdict{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:var(--r);background:var(--tone-tint,var(--raised))}
.ad-vi{flex:none;display:grid;place-items:center;width:26px;height:26px;border-radius:50%;background:var(--tone,var(--muted));color:var(--surface)}
.ad-vt{min-width:0}
.ad-vt strong{display:block;font:500 15px/20px var(--font-display);color:var(--text-strong)}
.ad-vt small{display:block;font:400 13px/18px var(--font);color:var(--text-2)}

/* the four numbers */
.ad-stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px}
.ad-stat{min-width:0}
.ad-stat-k{display:flex;align-items:center;gap:5px;min-width:0;font:500 12px/16px var(--font);color:var(--muted);white-space:nowrap}
.ad-stat-k>span:not(.sr-only){min-width:0;overflow:hidden;text-overflow:ellipsis}
.ad-stat-k .icon{flex:none}
.ad-stat-k [title]{position:relative;z-index:1;cursor:help}
.ad-stat-wa .ad-stat-k{color:var(--whatsapp-text)}
.ad-stat-v{margin-top:2px;font:400 22px/28px var(--font-display);color:var(--text-strong);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ad-stat-s{font:400 12px/16px var(--font);color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ad-c-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:auto;padding-top:12px;border-top:1px solid var(--line);font:400 12px/16px var(--font);color:var(--muted)}
.ad-more{display:inline-flex;align-items:center;gap:4px;color:var(--text-2)}
.ad-card:hover .ad-more{color:var(--text-strong)}

/* ---------- the detail sheet ---------- */
.ui-sheet.ad-sheet[data-variant="side"]{width:min(600px,100vw)}
.ad-d{display:flex;flex-direction:column;gap:20px;padding-bottom:8px}
.ad-d-head{display:flex;align-items:flex-start;gap:12px}
.ad-d-id{display:flex;flex-direction:column;align-items:flex-start;gap:8px;min-width:0}
.ad-d-sub{margin:0;font:400 13px/18px var(--font);color:var(--muted)}
.ad-d-period{display:flex;align-items:flex-start;gap:8px;margin:0;font:400 13px/18px var(--font);color:var(--text-2)}
.ad-d-period .icon{flex:none;margin-top:1px;color:var(--muted)}
.ad-d-wait .skeleton-line:nth-child(2){width:80%}
.ad-d-wait .skeleton-line:nth-child(3){width:55%}
.ad-stats-detail{gap:12px}
.ad-stats-detail .ad-stat-v{font-size:24px;line-height:30px}
.ad-info{display:inline-grid;place-items:center;flex:none;width:24px;height:24px;margin:-4px -4px -4px -2px;padding:0;border:0;border-radius:var(--r-xs);background:none;color:var(--muted);cursor:pointer}
.ad-info:hover{color:var(--text)}
.ad-info[aria-expanded="true"]{color:var(--text-strong)}
.ad-plays{margin:-8px 0 0;padding:10px 12px;border-radius:var(--r);background:var(--well);font:400 13px/18px var(--font);color:var(--text-2)}
.ad-plays[hidden]{display:none}
.ad-sec{min-width:0}
.ad-h{margin:0 0 10px;font:600 12px/16px var(--font);color:var(--text-2)}
.ad-h-sub{margin:-6px 0 10px;font:400 12px/16px var(--font);color:var(--muted)}
.ad-quiet{margin:0;font:400 13px/18px var(--font);color:var(--muted)}

/* the path from a play to a won deal: solid bars on a raised track (data marks never faded) */
/* one grid for every step, so each bar's track has the same width (the numbers column fits its widest "% of above") */
.ad-path{display:grid;grid-template-columns:120px minmax(0,1fr) auto;align-items:center;gap:6px 10px}
.ad-path-src{grid-column:1/-1;margin:6px 0 0;font:500 11px/16px var(--font);color:var(--muted)}
.ad-path-src:first-child{margin-top:0}
.ad-step{display:contents}
.ad-step-l{font:400 13px/18px var(--font);color:var(--text-2)}
.ad-bar{position:relative;height:22px;border-radius:var(--r-xs);background:var(--raised);overflow:hidden}
.ad-bar-fill{position:absolute;inset:0 auto 0 0;border-radius:var(--r-xs);background:var(--chart-actual)}
.ad-bar-wa .ad-bar-fill{background:var(--whatsapp-text)}
.ad-bar-crm .ad-bar-fill{background:var(--chart-actual)}
.ad-bar-won .ad-bar-fill{background:var(--success)}
.ad-step-n{min-height:28px;font:400 15px/20px var(--font-display);color:var(--text-strong);text-align:right;white-space:nowrap}
.ad-step-pct{display:block;font:400 11px/14px var(--font);color:var(--muted)}

/* the last 7 days: spend bars and the WhatsApp-leads line; orange is never a series. The bars are a quiet raised-2 fill
   with a muted 1px edge: the edge is the mark that clears 3:1 on the sheet, so the line stays the thing to read. */
.ad-chart{width:100%;min-height:156px}
.ad-c{display:block}
.ad-c-base{stroke:var(--line-strong);stroke-width:1}
.ad-c-bar{fill:var(--raised-2);stroke:var(--chart-plan);stroke-width:1}
.ad-c-line{fill:none;stroke:var(--whatsapp-text);stroke-width:2;stroke-linejoin:round;stroke-linecap:round}
.ad-c-dot{fill:var(--whatsapp-text)}
.ad-c-label{fill:var(--muted);font-family:var(--font);font-size:11px}
.ad-c-hit{fill:transparent}
.ad-legend{display:flex;flex-wrap:wrap;gap:6px 16px;margin:6px 0 0;padding:0;list-style:none;font:400 12px/16px var(--font);color:var(--muted)}
.ad-legend li{display:inline-flex;align-items:center;gap:6px}
.ad-key{display:inline-block;flex:none}
.ad-key-bar{width:8px;height:12px;background:var(--raised-2);box-shadow:inset 0 0 0 1px var(--chart-plan)}
.ad-key-line{width:12px;height:3px;border-radius:var(--r-pill);background:var(--whatsapp-text)}

/* where Meta showed it, the ads in the card */
.ad-table{width:100%;border-collapse:separate;border-spacing:0;border:1px solid var(--line);border-radius:var(--r);font:400 13px/18px var(--font)}
.ad-table th,.ad-table td{padding:9px 12px;text-align:right;white-space:nowrap}
.ad-table thead th{padding-block:7px;font:500 11px/16px var(--font);color:var(--muted)}
.ad-table th[scope="row"],.ad-table thead th:first-child{text-align:left;font-weight:400;color:var(--text);white-space:normal}
.ad-table thead th:first-child{font-weight:500;color:var(--muted)}
.ad-table td{color:var(--text-2)}
.ad-table td:last-child{color:var(--text-strong);font-weight:500}
.ad-table tbody tr>*{border-top:1px solid var(--line)}
.ad-list{display:flex;flex-direction:column;margin:0;padding:0;list-style:none;border:1px solid var(--line);border-radius:var(--r)}
.ad-list-row{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:10px 12px}
.ad-list-row+.ad-list-row{border-top:1px solid var(--line)}
.ad-list-main{display:flex;flex-direction:column;gap:2px;min-width:0}
.ad-list-name{font:500 14px/20px var(--font);color:var(--text);overflow-wrap:anywhere}
.ad-list-sub{font:400 12px/16px var(--font);color:var(--muted)}
.ad-status-word{display:inline-flex;align-items:center;gap:5px;color:var(--text-2)}
.ad-status-word.is-on{color:var(--success)}
.ad-list-nums{display:flex;flex-direction:column;align-items:flex-end;flex:none;font:400 13px/18px var(--font);color:var(--text-2);white-space:nowrap}
.ad-list-spend{color:var(--text-strong);font-weight:500}
.ad-how{padding:12px 14px;border-radius:var(--r);background:var(--well)}
.ad-how p{margin:0;font:400 13px/19px var(--font);color:var(--text-2)}
.ad-how strong{color:var(--text);font-weight:600}
.ad-how .ad-link{margin-top:6px;font-size:13px;line-height:18px}

/* ---------- tablet (768-1099): the mock's 340px cards, the numbers 2 x 2 ---------- */
@media (max-width:1099px){
 .ad-grid{grid-template-columns:repeat(auto-fill,minmax(340px,1fr))}
 .ad-card .ad-stats{grid-template-columns:repeat(2,minmax(0,1fr));row-gap:12px}
}

/* ---------- phone (<=767): one column, 2 x 2 numbers, a bottom sheet ---------- */
@media (max-width:767px){
 .ad-head{margin-bottom:16px;gap:12px}
 .ad-head>.screen-head-main,.ad-controls{flex:1 1 100%}
 .ad-controls{flex-direction:column;align-items:stretch;gap:8px}
 .ad-controls .seg{display:flex;width:100%}
 .ad-controls-row>.seg{flex:1 1 auto;width:auto}
 .ad-controls .seg-btn{flex:1 1 0;padding-inline:8px}
 .ad-totals{grid-template-columns:repeat(2,minmax(0,1fr))}
 .ad-tot{padding:14px 16px}
 .ad-tot:nth-child(3){border-left:0}
 .ad-tot:nth-child(n+3){border-top:1px solid var(--line)}
 .ad-v{font-size:22px;line-height:28px}
 .ad-grid{grid-template-columns:minmax(0,1fr);gap:12px}
 .ad-stats{grid-template-columns:repeat(2,minmax(0,1fr));row-gap:12px}
 .ad-path{grid-template-columns:96px minmax(0,1fr) auto}
 .ad-sheet .ad-d{gap:18px}
}

/* ---------- touch: 44px targets ---------- */
@media (pointer:coarse){
 .ad-link{min-height:44px;margin:-12px 0}
 .ad-info{width:44px;height:44px;margin:-14px -12px -14px -10px}
}

/* ---------- reduced motion: the live pulse and the press scale on cards stop (buttons keep theirs) ---------- */
@media (prefers-reduced-motion:reduce){
 .ad-live-dot::after{animation:none}
 .ad-card{transition:none}
}
