/* Shared styles for every page. Page-specific rules live in each page's <style>.
   Look: an AI analytics console. Deep navy (or soft white) canvas with a faint data grid,
   glassy cards, and an indigo -> cyan "AI" gradient reserved for brand and primary actions.
   Data colours (--scale/--watch/--test/--kill) are the validated recommendation palette. */
:root {
  color-scheme: light;
  --page: #f4f6fb;
  --glow-1: rgba(99, 102, 241, 0.12);
  --glow-2: rgba(6, 182, 212, 0.10);
  --grid-line: rgba(15, 23, 42, 0.035);
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --surface-2: #eef1f8;
  --control: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #94a3b8;
  --grid: #e6e9f2;
  --border: rgba(15, 23, 42, 0.09);
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.10);
  --ai-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #0891b2 100%);
  --ai-glow: rgba(99, 102, 241, 0.35);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 32px -12px rgba(15, 23, 42, 0.14);
  --scale: #008300;
  --watch: #eda100;
  --test: #2a78d6;
  --kill: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #060912;
    --glow-1: rgba(99, 102, 241, 0.20);
    --glow-2: rgba(34, 211, 238, 0.10);
    --grid-line: rgba(148, 163, 184, 0.045);
    --surface: rgba(15, 20, 35, 0.78);
    --surface-solid: #0f1423;
    --surface-2: rgba(148, 163, 184, 0.08);
    --control: #0b1020;
    --ink: #f1f5f9;
    --ink-2: #a3aec2;
    --muted: #64748b;
    --grid: rgba(148, 163, 184, 0.12);
    --border: rgba(148, 163, 184, 0.16);
    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, 0.14);
    --ai-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #06b6d4 100%);
    --ai-glow: rgba(99, 102, 241, 0.45);
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.02) inset, 0 16px 40px -16px rgba(0, 0, 0, 0.6);
    --scale: #008300;
    --watch: #c98500;
    --test: #3987e5;
    --kill: #e66767;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 520px at 8% -8%, var(--glow-1), transparent 60%),
    radial-gradient(760px 480px at 100% 0%, var(--glow-2), transparent 60%),
    var(--page);
  background-attachment: fixed;
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
/* A faint data grid that fades out down the page. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 80%);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 80%);
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 24px 48px; }
.wrap.narrow { max-width: 960px; }
@media (max-width: 640px) { .wrap { padding: 16px 16px 40px; } }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; }
.sub { margin: 4px 0 0; color: var(--ink-2); }
.back { display: inline-block; margin-bottom: 8px; font-size: 13px; color: var(--ink-2); text-decoration: none; }
.back:hover { color: var(--ink); }

/* Brand: gradient mark + name */
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: var(--ai-gradient); box-shadow: 0 10px 28px -10px var(--ai-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.brand-mark svg { width: 24px; height: 24px; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: -0.015em; margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.ai-chip {
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.06em; padding: 2px 7px; border-radius: 6px;
  color: #ffffff; background: var(--ai-gradient);
}
.grad-text { background: var(--ai-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }

.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-2); background: var(--surface); display: inline-flex; align-items: center; gap: 6px; }
.badge.demo { color: var(--ink); border-color: var(--watch); }

/* A small live dot, e.g. "AI ready" */
.pulse { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--scale); color: var(--scale); flex: none; }
.pulse::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid currentColor; color: inherit; opacity: 0; animation: pulse-ring 2s ease-out infinite; }
.pulse.off { background: var(--muted); }
.pulse.off::after { display: none; }
@keyframes pulse-ring { 0% { transform: scale(0.5); opacity: 0.6; } 100% { transform: scale(1.6); opacity: 0; } }

/* Form controls */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
select, input[type="email"], input[type="password"], input[type="text"], input[type="number"], .btn {
  font: inherit; color: var(--ink); background: var(--control);
  border: 1px solid var(--border); border-radius: 10px; height: 38px; padding: 0 12px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
select:hover, input:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
select:focus-visible, input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="email"], input[type="password"], input[type="text"] { width: 100%; font-size: 14px; }
input::placeholder { color: var(--muted); }
.btn { cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary {
  background: var(--ai-gradient); color: #ffffff; border-color: transparent; font-weight: 600;
  box-shadow: 0 8px 22px -10px var(--ai-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn.primary:hover { filter: brightness(1.08); background: var(--ai-gradient); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.link-btn { display: inline-block; font: inherit; font-size: 13px; background: none; border: 0; padding: 4px 6px; color: var(--accent); cursor: pointer; border-radius: 4px; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--kill); }

.error { border: 1px solid var(--kill); background: var(--surface-solid); padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; display: flex; gap: 10px; }
.notice { border: 1px solid var(--border); border-left: 3px solid var(--scale); background: var(--surface-2); border-radius: 10px; padding: 12px 16px; margin-top: 16px; }
.notice dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 12px; }
.notice dt { color: var(--ink-2); }
.notice dd { margin: 0; font-family: ui-monospace, Consolas, monospace; word-break: break-all; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px; min-width: 0;
  box-shadow: var(--shadow); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.note { color: var(--ink-2); margin: 4px 0 0; }
.label { font-size: 13px; color: var(--ink-2); }
.foot { margin-top: 24px; font-size: 12px; color: var(--ink-2); max-width: 90ch; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 16px -20px -20px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-top: 1px solid var(--grid); vertical-align: top; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
thead th { border-top: 0; font-weight: 600; color: var(--ink-2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--accent-soft); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Account menu */
.menu { position: relative; }
.menu > summary {
  list-style: none; display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px 0 4px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 13px;
}
.menu > summary::-webkit-details-marker { display: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--ai-gradient); color: #ffffff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.menu-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .menu-email { display: none; } .menu > summary { padding-right: 4px; } }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 230px;
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.35); padding: 6px; display: flex; flex-direction: column;
}
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--grid); margin-bottom: 4px; display: flex; flex-direction: column; }
.menu-head span { font-size: 12px; color: var(--ink-2); }
.menu-list a, .menu-list button {
  font: inherit; font-size: 13px; text-align: left; background: none; border: 0;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); text-decoration: none;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }

/* Sign-in and single-form pages */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.stack-form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.stack-form .btn.primary { height: 42px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Shared by the dashboard, Creatives and Actions pages: stat tiles, ranked bars, chips and pills. */
.tile {
  position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.tile::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 2px; background: var(--ai-gradient); opacity: 0.55; }
.tile-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile-icon { width: 30px; height: 30px; flex: none; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.icon { width: 16px; height: 16px; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 8px; letter-spacing: -0.02em; }
.tile .tile-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.h-icon { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); margin-right: 8px; vertical-align: middle; }
.h-icon svg { width: 15px; height: 15px; }
.aud-panel { padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); min-width: 0; }
.aud-panel h3 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }
.aud-panel .aud-sub { font-size: 11.5px; color: var(--ink-2); margin: 0 0 10px; }
.aud-rows { display: flex; flex-direction: column; gap: 10px; }
.aud-row { display: grid; grid-template-columns: minmax(96px, 34%) 1fr auto; gap: 4px 10px; align-items: center; }
.aud-label { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aud-bar { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.aud-bar > span { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
.aud-val { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.aud-val small { font-weight: 400; color: var(--ink-2); margin-left: 4px; }
.aud-meta { grid-column: 1 / -1; font-size: 11.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); padding: 4px 10px; border-radius: 999px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chip[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); border-color: var(--ink-2); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; padding: 2px 9px 2px 7px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }

/* Tabs between the dashboard, Creatives and Actions pages */
.tabs { display: flex; gap: 4px; margin: -6px 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; color: var(--ink-2); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs .icon { width: 15px; height: 15px; }

/* Filter bar, working bar and AI card, shared by the dashboard, Creatives and Actions pages */
/* Thin "working" bar along the top of the window */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 50; overflow: hidden; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.progress::before { content: ""; position: absolute; top: 0; bottom: 0; left: -40%; width: 40%; border-radius: 3px; background: var(--ai-gradient); box-shadow: 0 0 12px var(--ai-glow); animation: progress-slide 1.2s ease-in-out infinite; }
.progress.on { opacity: 1; }
@keyframes progress-slide { from { left: -40%; } to { left: 100%; } }
.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 18px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.filters select { min-width: 190px; }
.filters .btn { display: inline-flex; align-items: center; gap: 6px; }
.ai-card {
  border: 1px solid transparent;
  background: linear-gradient(var(--surface-solid), var(--surface-solid)) padding-box, var(--ai-gradient) border-box;
  box-shadow: 0 24px 60px -30px var(--ai-glow);
}
.ai-title { display: flex; align-items: center; gap: 12px; }
.ai-title h2 { font-size: 16px; }
.ai-icon { width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center; color: #ffffff; background: var(--ai-gradient); box-shadow: 0 8px 20px -8px var(--ai-glow); }
.ai-icon svg { width: 21px; height: 21px; }
.ai-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
