:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #0f1216;
  --muted: #5f6672;
  --line: #e3e6ea;
  --accent: #ffcd00;
  --accent-ink: #0f1216;
  --ok: #1a7f37;
  --warn: #b35c00;
  --err: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 18, 22, 0.06), 0 4px 16px rgba(15, 18, 22, 0.04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
h1 { font-size: clamp(1.4rem, 2.5cqi + 1rem, 2rem); margin: 0 0 .25rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: #f0f1f3; padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { color: var(--warn); margin: .25rem 0; }

/* Layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem clamp(1rem, 3vw, 2rem);
  background: var(--ink); color: #fff;
}
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a { color: #d6d9de; text-decoration: none; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; text-decoration: none; color: #fff !important; letter-spacing: .01em; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); display: inline-block; }
.page { flex: 1; width: min(1200px, 100%); margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); container-type: inline-size; container-name: page; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.page-head p { margin: 0; }
.crumbs { font-size: .85rem; color: var(--muted); }
.crumbs a { text-decoration: none; }
.head-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); container-type: inline-size; }
.card + .card, section.card { margin-top: 1rem; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.card-head p { margin: 0; }

.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@container page (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.cards { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@container page (min-width: 700px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@container page (min-width: 1050px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.client-card h2 a { text-decoration: none; }
.card-actions { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }

.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem 1rem; margin: .5rem 0; }
@container (min-width: 420px) { .facts { grid-template-columns: repeat(4, 1fr); } }
.facts div { display: flex; flex-direction: column; }
.facts dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { max-width: 48ch; margin: .5rem auto 1.25rem; color: var(--muted); }

/* Status */
.status { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eef0f3; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.status-ok { background: #e3f5e8; color: var(--ok); }
.status-partial { background: #fff1e0; color: var(--warn); }
.status-failed { background: #fde7e5; color: var(--err); }
.status-running { background: #e6efff; color: #1d4ed8; }
.status-skipped { background: #eef0f3; }
.errors { font-size: .85rem; color: var(--err); margin: .5rem 0 0; padding-left: 1.2rem; max-height: 16rem; overflow: auto; }
.history { margin-top: .75rem; }
.history table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: .5rem; }
.history th, .history td { text-align: left; padding: .35rem .5rem; border-top: 1px solid var(--line); }
details summary { cursor: pointer; color: var(--muted); }

/* Flash */
.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #e3f5e8; border-color: #bfe6cb; color: var(--ok); }
.flash.err { background: #fde7e5; border-color: #f5c2bd; color: var(--err); }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 9px; border: 1px solid transparent; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: .9rem; text-decoration: none; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { filter: brightness(.96); }
.btn-small { padding: .35rem .7rem; font-size: .8rem; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-danger { background: transparent; border-color: #f5c2bd; color: var(--err); }
.btn.copied { background: #e3f5e8; color: var(--ok); border-color: #bfe6cb; }
form.inline { display: inline-flex; gap: .5rem; align-items: center; }
.check { display: inline-flex; gap: .35rem; align-items: center; font-size: .85rem; color: var(--muted); white-space: nowrap; }

.form-grid { display: grid; gap: .9rem; grid-template-columns: 1fr; }
@container (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: span 2; } }
label > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
input, select, textarea { width: 100%; font: inherit; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; min-height: 10rem; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: .75rem; margin-top: 1rem; }
.danger-row { display: flex; justify-content: flex-end; margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--line); }

/* Copy rows */
.copy-row { display: flex; gap: .5rem; align-items: center; margin: .4rem 0; min-width: 0; }
.copy-row code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

/* Template editor + live preview */
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.tab { padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; font-size: .85rem; }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs input { width: 9rem; padding: .3rem .6rem; font-size: .85rem; }

.editor { display: grid; gap: 1rem; grid-template-columns: 1fr; margin-top: .75rem; }
@container (min-width: 820px) { .editor { grid-template-columns: minmax(0, 1.2fr) minmax(280px, 1fr); } }
.editor-form textarea { min-height: 24rem; width: 100%; }
.preview-controls { display: grid; gap: .5rem; grid-template-columns: 1fr; margin-bottom: .75rem; align-items: center; }
@container (min-width: 360px) { .preview-controls { grid-template-columns: minmax(0, 1fr) auto auto; } }
.preview-frame { background: repeating-conic-gradient(#eceef1 0 25%, #fff 0 50%) 0 0 / 20px 20px; border: 1px solid var(--line); border-radius: 10px; min-height: 240px; display: grid; place-items: center; overflow: hidden; }
.preview-frame img { max-width: 100%; max-height: 640px; display: block; }
.preview-frame img:not([src]) { display: none; }
.preview-frame.loading { opacity: .6; }
.preview-frame .preview-error { color: var(--err); padding: 1rem; font-size: .85rem; }

/* Creatives grid */
.creatives { display: grid; gap: .9rem; grid-template-columns: repeat(2, 1fr); }
@container (min-width: 560px) { .creatives { grid-template-columns: repeat(3, 1fr); } }
@container (min-width: 820px) { .creatives { grid-template-columns: repeat(4, 1fr); } }
@container (min-width: 1100px) { .creatives { grid-template-columns: repeat(5, 1fr); } }
.creative { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fafbfc; }
.creative img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #e6e8eb; }
.creative.pending img { opacity: .35; }
.creative figcaption { padding: .5rem .6rem; display: flex; flex-direction: column; font-size: .8rem; line-height: 1.3; }
.creative figcaption span { color: var(--muted); }
.creative figcaption .price { color: var(--ink); font-weight: 600; }
.creative figcaption a.small, .creative figcaption .small { color: var(--muted); }

/* Login */
.login-wrap { display: grid; place-items: center; min-height: 60dvh; }
.login { width: min(420px, 100%); }
.login h1 { font-size: 1.4rem; margin: .25rem 0; }
.login label { display: block; margin: .9rem 0; }
.login-brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; }
.btn-wide { width: 100%; margin-top: .5rem; }
.link-btn { background: none; border: 0; color: #d6d9de; font: inherit; cursor: pointer; padding: 0; }

/* Designer */
.subtabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; }
.subtab { background: none; border: 0; border-bottom: 2px solid transparent; padding: .5rem .8rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.subtab.active { color: var(--ink); border-bottom-color: var(--accent); }
.pane { display: none; }
.pane.active { display: block; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .75rem .9rem .9rem; margin: 0 0 .9rem; min-width: 0; }
legend { font-weight: 600; font-size: .85rem; padding: 0 .35rem; }
.hint { font-size: .8rem; color: var(--muted); margin: .4rem 0 0; }
.lbl { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.ctrl-grid { display: grid; gap: .7rem .9rem; grid-template-columns: 1fr; }
@container (min-width: 480px) { .ctrl-grid { grid-template-columns: 1fr 1fr; } .ctrl-grid .span-2 { grid-column: span 2; } }
.ctrl-grid label > span { display: flex; justify-content: space-between; gap: .5rem; }
.ctrl-grid label > span output { color: var(--muted); font-weight: 500; }
label.color { display: flex; align-items: center; gap: .6rem; }
label.color > span { display: inline; font-weight: 500; }
label.color input[type=color] { width: 44px; height: 32px; padding: 2px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; flex: none; }
label.range input[type=range] { width: 100%; padding: 0; accent-color: var(--ink); }
.check-row { display: flex; align-items: center; gap: .5rem; align-self: end; font-size: .9rem; }
.check-row input { width: auto; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; cursor: pointer; background: #fff; user-select: none; }
.chip:has(input:checked) { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip small { opacity: .65; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
#subtitle-order { margin-top: .5rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.presets { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .7rem; }
.preset { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; background: linear-gradient(135deg, var(--b) 50%, var(--a) 50%); }
.preset:hover { transform: scale(1.08); }
.label-maps details { border-top: 1px solid var(--line); padding: .5rem 0; }
.label-maps summary { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; color: var(--ink); }
.kv { display: grid; gap: .35rem; margin: .5rem 0; }
.kv-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: .4rem; align-items: center; }
.kv-row input { padding: .35rem .5rem; font-size: .85rem; }
.kv-row .kv-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
.kv-del { border: 0; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 0 .3rem; }
.kv-del:hover { color: var(--err); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: .4rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: #fff; }
.preview { position: sticky; top: 1rem; align-self: start; }
.preview-frame { position: relative; }
.preview-spinner { display: none; position: absolute; inset: 0; margin: auto; width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(15,18,22,.15); border-top-color: var(--ink); animation: spin .8s linear infinite; }
.preview-frame.loading .preview-spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
