/* Creative Lab UI. Also used by the creatives-testing.cwi.re landing page. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --line: #e3e6eb;
  --line-strong: #cfd4dc;
  --fg: #16181d;
  --fg-2: #4b5260;
  --fg-3: #858c99;
  --accent: #6d28d9;
  --accent-2: #8b5cf6;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --ok: #059669;
  --warn: #d97706;
  --err: #dc2626;
  --stage: #e9ecf1;
  --stage-dots: #d6dae1;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 8%);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[data-ui="dark"] {
  --bg: #0e0f13;
  --panel: #16181e;
  --panel-2: #1d2027;
  --line: #262a33;
  --line-strong: #353a45;
  --fg: #e8eaee;
  --fg-2: #a9afbb;
  --fg-3: #6f7685;
  --accent: #a78bfa;
  --accent-2: #c4b5fd;
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --stage: #0a0b0e;
  --stage-dots: #1c1f26;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 28px rgb(0 0 0 / 45%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; letter-spacing: -.01em; white-space: nowrap; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 800;
}
.brand small { font-weight: 500; color: var(--fg-3); }
.tabs { display: flex; gap: 2px; background: var(--panel-2); padding: 3px; border-radius: 9px; border: 1px solid var(--line); }
.tabs button {
  border: 0; background: transparent; padding: 5px 14px; border-radius: 6px; cursor: pointer; color: var(--fg-2); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / 12%); }
.spacer { flex: 1; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--fg-2); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.badge.cdn i { background: var(--accent); }
.badge.custom i { background: var(--warn); }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); width: 300px; padding: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 30;
}
.menu-panel h6 { margin: 8px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-3); }
.menu-panel a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--fg); }
.menu-panel a:hover { background: var(--panel-2); text-decoration: none; }
.menu-panel .muted { color: var(--fg-3); font-size: 12px; padding: 6px 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 1px solid var(--line-strong); border-radius: 7px; background: var(--panel); cursor: pointer; font-weight: 600; color: var(--fg); white-space: nowrap;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 30px; padding: 0; justify-content: center; }
.btn svg { width: 15px; height: 15px; }

/* ---------- Layout ---------- */
.workspace { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: calc(100vh - 52px); }
.controls { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); padding-bottom: 32px; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---------- Controls ---------- */
.section { padding: 14px 16px 6px; border-bottom: 1px solid var(--line); }
.section > h3 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--fg-3); font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
}
.field { margin-bottom: 12px; }
.field > label, .field > .label { display: block; font-weight: 600; color: var(--fg-2); margin-bottom: 5px; font-size: 12px; }
.field .hint { color: var(--fg-3); font-size: 11.5px; margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
select, input[type="text"], input[type="number"], input[type="url"] {
  width: 100%; height: 32px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--panel); outline: none;
}
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: 999px; cursor: pointer; user-select: none;
  background: var(--panel); color: var(--fg-2); font-weight: 600; font-size: 12px; line-height: 1.2;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:hover { border-color: var(--accent-2); }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--accent-soft); }
.chip small { font-weight: 500; color: var(--fg-3); }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; }
.segmented label { text-align: center; padding: 5px 4px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--fg-2); position: relative; font-size: 12px; white-space: nowrap; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / 14%); }

.cards { display: grid; gap: 6px; }
.card-opt { display: grid; grid-template-columns: 16px 1fr; gap: 2px 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.card-opt:hover { border-color: var(--line-strong); }
.card-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.card-opt input { margin: 2px 0 0; accent-color: var(--accent); }
.card-opt b { font-size: 12.5px; }
.card-opt span { grid-column: 2; color: var(--fg-3); font-size: 11.5px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; font-weight: 500; color: var(--fg-2); }
.check input { accent-color: var(--accent); }

/* ---------- Stage ---------- */
.stage-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 47px;
}
.stage-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-title small { color: var(--fg-3); font-weight: 500; margin-left: 6px; }
.status { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--fg-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: color-mix(in srgb, var(--ok) 9%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 9%, transparent); }
.pill.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, transparent); background: color-mix(in srgb, var(--err) 9%, transparent); }

.stage {
  flex: 1; min-height: 0; overflow: auto; position: relative;
  background-color: var(--stage);
  background-image: radial-gradient(var(--stage-dots) 1px, transparent 1px);
  background-size: 16px 16px;
  display: flex; justify-content: center; align-items: flex-start; padding: 24px;
}
.stage.fill { padding: 0; }
.device {
  position: relative; flex: none; background: #fff; border-radius: 14px; overflow: hidden;
  box-shadow: 0 0 0 1px var(--line-strong), var(--shadow);
}
.stage.fill .device { border-radius: 0; box-shadow: none; width: 100% !important; height: 100% !important; }
.device-label { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); font: 600 11px var(--mono); color: var(--fg-3); }
/* Strategies may resize parent frames; the stage keeps its geometry regardless. */
.device > iframe.host {
  border: 0; display: block; transform-origin: 0 0;
  width: var(--vw) !important; height: var(--vh) !important; max-width: none !important; max-height: none !important;
}
.stage.fill .device > iframe.host { width: 100% !important; height: 100% !important; }

/* ---------- Inspector ---------- */
.inspector { height: 220px; border-top: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.inspector.collapsed { height: 38px; }
.inspector.collapsed .inspector-tabs [role="tab"], .inspector.collapsed #clear-log, .inspector.collapsed .inspector-body { display: none; }
.inspector-summary {
  display: none; flex: 1; min-width: 0; align-items: center; gap: 6px; height: 100%; padding: 0 4px;
  border: 0; background: none; cursor: pointer; text-align: left; color: var(--fg-2); font-size: 12px; white-space: nowrap; overflow: hidden;
}
.inspector.collapsed .inspector-summary { display: flex; }
.inspector-summary .count { padding: 0 6px; border-radius: 999px; background: var(--panel-2); color: var(--fg-2); font-size: 11px; }
.inspector-summary .tag { padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font: 600 11px/1.6 var(--mono); }
.inspector-summary .muted, .inspector-summary .sep { color: var(--fg-3); }
.inspector-tabs { display: flex; align-items: center; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); height: 38px; flex: none; }
.inspector-tabs button { border: 0; background: none; padding: 9px 10px; cursor: pointer; font-weight: 600; color: var(--fg-3); border-bottom: 2px solid transparent; }
.inspector-tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.inspector-tabs .count { margin-left: 5px; font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--panel-2); color: var(--fg-2); }
.inspector-body { flex: 1; overflow: auto; font: 12px/1.5 var(--mono); }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 74px 1fr; gap: 10px; padding: 5px 12px; border-bottom: 1px solid var(--line); }
.log li.err { color: var(--err); }
.log time { color: var(--fg-3); }
.log details summary { cursor: pointer; }
.log details pre { margin: 6px 0 2px; padding: 8px; background: var(--panel-2); border-radius: 6px; overflow: auto; max-height: 260px; }
.log .tag { display: inline-block; padding: 0 6px; margin-right: 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.log .tag.live { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.empty { padding: 18px; color: var(--fg-3); font-family: var(--sans); }
pre.params { margin: 0; padding: 12px; }

/* ---------- Matrix ---------- */
.matrix-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.matrix-bar .spacer { flex: 1; }
.matrix-bar .times { color: var(--fg-3); }
#matrix-count { color: var(--fg-2); font-weight: 600; white-space: nowrap; }
.axis { display: flex; align-items: center; gap: 6px; }
.axis > b { color: var(--fg-3); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.axis select { width: auto; max-width: 190px; height: 30px; }
.axis .combo { width: 220px; }
.axis .combo-value { height: 30px; }
.axis .combo-panel { min-width: 220px; }
.combo-actions { display: flex; gap: 6px; padding: 4px 4px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.combo-actions .btn { height: 26px; }
.matrix-scroll { flex: 1; overflow: auto; background: var(--stage); }
.matrix { display: grid; gap: 12px; padding: 16px; align-items: start; }
.matrix .col-head, .matrix .row-head { font-weight: 700; color: var(--fg-2); font-size: 12px; }
.matrix .col-head { position: sticky; top: 0; z-index: 2; background: var(--stage); padding: 4px 2px; }
.matrix .row-head { position: sticky; left: 0; z-index: 1; background: var(--stage); padding: 8px 4px; writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; align-self: stretch; }
.cell { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cell-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); min-height: 34px; }
.cell-head .status { flex: 1; }
.cell-frame { position: relative; overflow: hidden; background: #fff; }
.cell-frame iframe { border: 0; display: block; transform-origin: 0 0; }
.warning { margin: 0; padding: 8px 12px; color: var(--warn); font-weight: 600; }

/* ---------- Landing (creatives-testing.cwi.re) ---------- */
.landing { max-width: 1080px; margin: 0 auto; padding: 48px 24px 80px; }
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 32px; align-items: center; margin-bottom: 40px; }
.hero h1 { font-size: 38px; line-height: 1.1; letter-spacing: -.02em; margin: 0 0 12px; }
.hero p { color: var(--fg-2); font-size: 15px; margin: 0 0 20px; }
.hero-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.hero-card ul { margin: 0; padding-left: 18px; color: var(--fg-2); display: grid; gap: 6px; }
.tool-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tool-group { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.tool-group h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--fg-3); margin: 0 0 8px; }
.tool-group a { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: var(--fg); font-weight: 600; }
.tool-group a:hover { background: var(--panel-2); text-decoration: none; }
.tool-group a::after { content: "→"; color: var(--fg-3); }
@media (max-width: 800px) {
  .hero { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; height: auto; }
  .controls { max-height: none; border-right: 0; }
  .main { height: 90vh; }
}

/* ---------- Ladybug / debugger + modals ---------- */
.ladybug { width: 18px; height: 18px; flex: none; color: var(--fg); }
.btn .ladybug { width: 17px; height: 17px; }
.modal {
  width: min(560px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--fg); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgb(10 10 16 / 45%); backdrop-filter: blur(2px); }
.modal form { margin: 0; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 16px 8px; }
.modal-head > div { flex: 1; }
.modal-head .ladybug { width: 40px; height: 40px; }
.modal-head h2 { margin: 0 0 2px; font-size: 16px; }
.modal-head p { margin: 0; color: var(--fg-2); }
.modal-body { padding: 8px 16px 12px; }
.modal-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal .muted { color: var(--fg-3); font-size: 12px; }
.modal code { font: 12px var(--mono); padding: 1px 5px; border-radius: 4px; background: var(--panel-2); }
.steps { margin: 8px 0 12px; padding-left: 20px; display: grid; gap: 12px; }
.steps li > .muted { display: block; margin-top: 4px; }
.modal textarea {
  width: 100%; min-height: 220px; resize: vertical; padding: 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel-2); color: var(--fg); font: 12px/1.5 var(--mono); outline: none;
}
.modal textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Prebid tester pages (tester.js) ---------- */
.tester-stage { flex-direction: column; justify-content: flex-start; align-items: safe center; gap: 12px; }
.tester-slot {
  flex: none; padding: 16px; border-radius: 12px;
  background: #fff; color: #1d1f24; box-shadow: 0 0 0 1px var(--line-strong), var(--shadow);
}
.tester-note { margin: 0; color: var(--fg-3); font-size: 12.5px; }
.tester-inspector { height: 300px; }
.tester-inspector.collapsed { height: 38px; }
.tester-inspector.collapsed .inspector-body { display: none; }
.tester-bar { flex-wrap: wrap; row-gap: 6px; }
.tester-bar .stage-title { flex: 0 1 auto; min-width: 120px; }
.combo { position: relative; }
.combo-value {
  list-style: none; cursor: pointer; display: flex; align-items: center; height: 32px; padding: 0 28px 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
}
.combo-value::-webkit-details-marker { display: none; }
.combo-value::after { content: "▾"; position: absolute; right: 10px; color: var(--fg-3); }
.combo[open] .combo-value { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.combo-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; max-height: 300px; overflow: auto; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.combo-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.combo-opt:hover { background: var(--panel-2); }
.combo-opt input { accent-color: var(--accent); margin: 0; }
.combo-opt span { font: 600 12px var(--mono); min-width: 64px; }
.combo-opt small { color: var(--fg-3); }
.slot-section .times { flex: none; color: var(--fg-3); }
.slot-info { color: var(--fg-3); }
.slot-info.warn { color: var(--warn); font-weight: 600; }
.tester-slot.resizable > div { resize: both; overflow: hidden; outline: 1px dashed var(--accent); }
.creative-box { display: flex; align-items: center; gap: 6px; flex: none; }
.creative-box > span { font-size: 12px; font-weight: 600; color: var(--fg-2); white-space: nowrap; }
.creative-box input { width: 96px; height: 30px; }
.creative-box .btn { height: 30px; }
.log.calls li { grid-template-columns: 64px 48px 40px 64px minmax(0, 1fr); }
.log.calls a { color: var(--fg-2); overflow-wrap: anywhere; }
.log.calls .method { font-weight: 700; }
.log.calls .s2 .code { color: var(--ok); }
.log.calls .s3 .code { color: var(--accent); }
.log.calls .s4 .code, .log.calls .s0 .code { color: var(--warn); }
.log.calls .s5 .code { color: var(--err); }

/* ---------- Lab sidebar: folding sections, live creative ---------- */
details.section > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; padding-bottom: 8px; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary h3 { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--fg-3); font-weight: 700; }
details.section > summary h3::before { content: "▸"; display: inline-block; width: 12px; transition: transform .15s; }
details.section[open] > summary h3::before { transform: rotate(90deg); }
details.section > summary .fold-sum { flex: 1; min-width: 0; text-align: right; color: var(--fg-3); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.section[open] > summary .fold-sum { visibility: hidden; }
.live-hint { color: var(--fg-2); }
.live-hint b { color: var(--accent); }
.creative-box:has(input:not(:placeholder-shown)) input { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.menu-item { display: block; width: 100%; text-align: left; padding: 7px 8px; border: 0; border-radius: 6px; background: none; color: var(--fg); font-weight: 600; cursor: pointer; }
.menu-item:hover { background: var(--panel-2); }
.stage-bar .menu-panel { right: 0; left: auto; min-width: 180px; }
.checks { display: grid; gap: 2px; }
.feature-check { display: flex; align-items: flex-start; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.feature-check:hover { background: var(--panel-2); }
.feature-check input { margin: 2px 0 0; accent-color: var(--accent); }
.feature-check span { display: grid; }
.feature-check code { font: 600 12px var(--mono); color: var(--fg); }
.feature-check small { color: var(--fg-3); font-size: 11px; }
.feature-check:has(input:checked) code { color: var(--accent); }
