/* Marketing Agent web UI. System fonts only: no third-party requests. */
:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e3e6ef;
  --text: #161a2b;
  --text-muted: #5d6478;
  --text-faint: #8a90a3;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-contrast: #ffffff;
  --success: #12805c;
  --success-soft: #e3f6ee;
  --warning: #a15c00;
  --warning-soft: #fff3df;
  --danger: #c4314b;
  --danger-soft: #fde8ec;
  --info: #1f6fd1;
  --info-soft: #e5f0ff;
  --p-google: #1a73e8;
  --p-gbp: #188038;
  --p-facebook: #1877f2;
  --p-instagram: #c13584;
  --p-tiktok: #111111;
  --p-linkedin: #0a66c2;
  --series-1: #2a78d6; /* chart series (validated vs light surface) */
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1018;
    --surface: #161925;
    --surface-2: #1d2130;
    --border: #2a2f42;
    --text: #e9ebf3;
    --text-muted: #a2a8bc;
    --text-faint: #737a91;
    --accent: #8b85ff;
    --accent-hover: #a29dff;
    --accent-soft: #23234a;
    --accent-contrast: #0e1018;
    --success: #4cc79a;
    --success-soft: #133328;
    --warning: #f0b252;
    --warning-soft: #3a2a10;
    --danger: #ff7a90;
    --danger-soft: #3d1720;
    --info: #7fb2ff;
    --info-soft: #162a47;
    --p-tiktok: #e9ebf3;
    --p-linkedin: #70b5f9;
    --series-1: #3987e5; /* chart series (validated vs dark surface) */
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
pre, code { font-family: var(--mono); font-size: .85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.05rem; padding: 4px 10px 18px; color: var(--text); }
.logo img { width: 28px; height: 28px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { background: var(--accent); color: var(--accent-contrast); border-radius: 999px; font-size: .72rem; padding: 1px 8px; font-weight: 700; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 16px 12px 6px; }
.sidebar .me { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 10px 0; font-size: .85rem; }
.me .email { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .org { color: var(--text-muted); margin-bottom: 8px; }

.main { padding: 28px 36px 64px; max-width: 1240px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); margin-top: 4px; }
.crumbs { font-size: .85rem; color: var(--text-muted); margin-bottom: -10px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 2px; }
  .logo { padding: 4px 8px 4px 0; }
  .nav-section { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar .me { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; align-items: center; gap: 8px; }
  .me .email, .me .org { display: none; }
  .main { padding: 20px 16px 48px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stack > * + * { margin-top: 16px; }
/* Page sections: consistent vertical rhythm without margins leaking into grids. */
.main > div, .main > div > div:only-child { display: flex; flex-direction: column; gap: 16px; }
.main .page-head { margin-bottom: 4px; }
.main .tabs { margin-bottom: 0; }
.card > h2, .card > h3 { margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); font-size: .85rem; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); }
@media (max-width: 860px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.block { width: 100%; }

.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.platform { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 650; padding: 2px 10px 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.platform .dot { width: 9px; height: 9px; }
.p-google_ads { color: var(--p-google); }
.p-google_business { color: var(--p-gbp); }
.p-meta_facebook { color: var(--p-facebook); }
.p-meta_instagram { color: var(--p-instagram); }
.p-tiktok { color: var(--p-tiktok); }
.p-linkedin { color: var(--p-linkedin); }

.chip { display: inline-block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: .82rem; margin: 0 6px 6px 0; }

/* stat tiles */
.stat { padding: 18px 20px; }
.stat .label { color: var(--text-muted); font-size: .85rem; font-weight: 550; }
.stat .value { font-size: 1.9rem; font-weight: 750; letter-spacing: -.02em; margin-top: 4px; }
.meter { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter.warn > span { background: var(--warning); }
.meter.over > span { background: var(--danger); }

/* forms */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-weight: 600; font-size: .88rem; }
.field .hint { color: var(--text-faint); font-size: .8rem; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.check { display: flex; gap: 10px; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; background: var(--surface); }
.check input { width: auto; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .9rem; }
.error-box ul { margin: 4px 0 0; padding-left: 18px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* brand cards */
.brand-card { display: block; color: var(--text); transition: border-color .15s, transform .15s; }
.brand-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.avatar { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-weight: 750; background: var(--accent-soft); color: var(--accent); flex: none; }
.avatar.sm { width: 32px; height: 32px; border-radius: 50%; font-size: .85rem; }

/* run progress */
.progress-card { display: flex; gap: 16px; align-items: center; background: var(--info-soft); border: 1px solid transparent; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* allocation bars */
.alloc { display: grid; grid-template-columns: 170px 1fr 90px; gap: 12px; align-items: center; padding: 8px 0; }
.alloc .bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.alloc .bar span { display: block; height: 100%; border-radius: 999px; background: currentColor; }
@media (max-width: 600px) { .alloc { grid-template-columns: 1fr 70px; } .alloc .bar { grid-column: 1 / -1; grid-row: 2; } }

/* markdown-ish summary */
.prose h3, .prose h4 { margin: 14px 0 6px; }
.prose ul { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin: 3px 0; }

/* ---------- ad previews ---------- */
.draft-card { display: flex; flex-direction: column; gap: 12px; }
.draft-card .meta { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.preview { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px; font-size: .92rem; }
.serp .sponsored { font-size: .78rem; font-weight: 700; color: var(--text); }
.serp .url { font-size: .82rem; color: var(--text-muted); margin: 2px 0 4px; }
.serp .headline { color: #1a0dab; font-size: 1.12rem; line-height: 1.3; }
@media (prefers-color-scheme: dark) { .serp .headline { color: #8ab4f8; } }
.serp .desc { color: var(--text-muted); margin-top: 4px; }
.social-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.social-head .name { font-weight: 650; }
.social-head .sub { font-size: .78rem; color: var(--text-faint); }
.hashtags { color: var(--accent); }
.creative { margin: 10px -14px; background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, var(--bg) 10px, var(--bg) 20px); border-block: 1px solid var(--border); padding: 22px 18px; color: var(--text-muted); font-size: .85rem; }
.creative:last-child { margin-bottom: -14px; border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
.creative strong { color: var(--text); display: block; margin-bottom: 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.cta-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--surface-2); margin: 0 -14px -14px; padding: 10px 14px; border-radius: 0 0 var(--radius) var(--radius); }
.cta-bar .h { font-weight: 650; }
.phone { width: 220px; aspect-ratio: 9 / 16; border-radius: 22px; background: linear-gradient(160deg, #262a3f, #0b0d14); color: #fff; padding: 16px; display: flex; flex-direction: column; justify-content: space-between; margin: 0 auto; box-shadow: var(--shadow-lg); }
.phone .hook { font-weight: 750; font-size: 1.05rem; line-height: 1.3; background: rgba(0,0,0,.35); padding: 8px; border-radius: 8px; }
.phone .cap { font-size: .78rem; opacity: .9; max-height: 6.5em; overflow: hidden; }
.scenes { margin: 0; padding-left: 20px; }
.scenes li { margin: 4px 0; }
.charcount { font-size: .75rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.charcount.over { color: var(--danger); font-weight: 700; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.issues { margin: 0; padding-left: 18px; font-size: .88rem; }
.payload { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; max-height: 420px; overflow: auto; white-space: pre; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: linear-gradient(150deg, #4f46e5, #7c3aed 55%, #c13584); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; gap: 20px; }
.auth-hero h1 { font-size: 2.2rem; color: #fff; }
.auth-hero ul { padding-left: 20px; margin: 0; opacity: .95; }
.auth-hero li { margin: 8px 0; }
.auth-panel { display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-panel.gate { min-height: 100vh; }
.auth-card.wide { max-width: 560px; }
.code-input { font-family: var(--mono); font-size: 1.35rem; letter-spacing: .2em; text-align: center; }
.qr-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.qr { width: 200px; height: 200px; border-radius: var(--radius-sm); background: #fff; padding: 6px; border: 1px solid var(--border); }
.secret { display: inline-block; margin-top: 6px; padding: 6px 10px; background: var(--surface-2); border-radius: var(--radius-sm); word-break: break-all; }
.steps-list { margin: 0; padding-left: 20px; }
.steps-list li { margin: 4px 0; }
.recovery { list-style: none; padding: 14px; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 20px; background: var(--surface-2); border-radius: var(--radius-sm); }
.recovery code { font-size: .95rem; }
@media (max-width: 860px) { .auth-wrap { grid-template-columns: 1fr; } .auth-hero { display: none; } }

/* ---------- overlays ---------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(10, 12, 20, .5); }
#toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 36px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: .9rem; max-width: 420px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
.loading { padding: 60px; text-align: center; color: var(--text-muted); }

/* platform connect */
.connect-buttons { margin-bottom: 14px; }
.connect-meta { border-color: var(--p-facebook); color: var(--p-facebook); }
.connect-google { border-color: var(--p-google); color: var(--p-google); }
.connect-tiktok { border-color: var(--p-tiktok); color: var(--p-tiktok); }
.connect-linkedin { border-color: var(--p-linkedin); color: var(--p-linkedin); }
.pick-group { display: grid; gap: 8px; margin: 0; }
.pick-group legend { padding: 0 6px; }

/* generated creatives */
.creatives { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 12px; }
.creative-item { display: grid; gap: 6px; align-content: start; }
.creative-item .row { justify-content: space-between; }
.media { display: block; width: 100%; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.media.thumb { aspect-ratio: 1 / 1; object-fit: cover; }
video.media.thumb { aspect-ratio: 9 / 16; }
.media.placeholder { display: grid; place-items: center; color: var(--text-faint); font-size: 1.4rem; }
.preview-media { margin: 10px 0; max-height: 520px; object-fit: contain; }
dialog.wide { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto; }

/* charts: one measure per chart; thin columns from a single baseline; recessive grid */
.viz-wrap { position: relative; }
.viz { display: block; width: 100%; height: auto; overflow: visible; }
.viz-bar { fill: var(--series-1); }
.viz-grid { stroke: var(--border); stroke-width: 1; }
.viz-base { stroke: var(--text-faint); stroke-width: 1; }
.viz-axis { fill: var(--text-muted); font-size: 12px; font-family: var(--font); }
.viz-hit { fill: transparent; cursor: default; }
.viz-hit:focus { outline: none; fill: var(--accent-soft); fill-opacity: .5; }
.viz-tip { position: absolute; transform: translate(-50%, calc(-100% - 8px)); background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; font-size: .8rem; pointer-events: none;
  box-shadow: var(--shadow-lg); white-space: nowrap; z-index: 2; }
details > summary { cursor: pointer; color: var(--accent); margin: 8px 0; }
