:root {
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --ink: #18202E;
  --muted: #5A6478;
  --line: #DCE1E9;
  --accent: #2B4EE6;
  --accent-ink: #FFFFFF;
  --accent-soft: #E6EBFD;
  --live: #13855C;
  --live-soft: #DDF3E9;
  --warn: #9A6200;
  --warn-soft: #FBF0D9;
  --danger: #C2362B;
  --idle-soft: #E9ECF1;
  --radius: 8px;
  --font: 'Manrope', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161F; --surface: #19202C; --ink: #E7EBF2; --muted: #98A2B5; --line: #2A3342;
    --accent: #6E8BFF; --accent-ink: #0D1220; --accent-soft: #232D4A; --live: #44C98F; --live-soft: #173326;
    --warn: #E5B45C; --warn-soft: #3A2E17; --danger: #FF7A70; --idle-soft: #242C39;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1 { font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; font-weight: 800; margin: 0 0 4px; }
h2 { font-size: 19px; letter-spacing: -0.01em; font-weight: 700; margin: 0; }
.muted { color: var(--muted); margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code, pre { font-family: var(--mono); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.brand b { font-weight: 800; color: var(--accent); }
.mark { width: 22px; height: 18px; border: 2.5px solid currentColor; border-radius: 3px; position: relative; }
.mark::after { content: ''; position: absolute; width: 7px; height: 7px; border-radius: 50%; background: var(--live); top: -5px; right: -5px; box-shadow: 0 0 0 2.5px var(--surface); }
.brand-lg { font-size: 22px; }

/* buttons */
.btn { font: 600 14px/1 var(--font); border: 1px solid transparent; border-radius: 6px; padding: 10px 16px; cursor: pointer; background: none; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-ghost { border-color: var(--line); background: var(--surface); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-danger-ghost { color: var(--danger); padding-left: 0; }
.btn.icon { padding: 8px 11px; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; font: 400 15px/1.4 var(--font); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px;
}
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.form-error { color: var(--danger); font-size: 14px; margin: 0; min-height: 1em; }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 0; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); width: 100%; max-width: 360px; padding: 32px; border-radius: 12px; display: grid; gap: 16px; box-shadow: 0 1px 2px rgba(24,32,46,.06), 0 12px 32px -12px rgba(24,32,46,.18); }
.login-card .btn { justify-content: center; padding: 12px; }

/* layout */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.main { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; }
.filters { display: flex; gap: 10px; margin-bottom: 14px; }
.filters input { flex: 1; margin: 0; }
.filters select { width: auto; margin: 0; }

/* table */
.table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 110px 90px 70px 168px; gap: 16px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.row-head { border-top: 0; font-size: 12px; font-weight: 600; color: var(--muted); padding-block: 10px; background: var(--bg); }
.row:not(.row-head):hover { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.ad-cell { display: flex; align-items: center; gap: 14px; min-width: 0; cursor: pointer; }
.thumb { width: 64px; height: 44px; flex: none; border-radius: 4px; background: var(--idle-soft) center/cover no-repeat; display: grid; place-items: center; font: 500 11px var(--mono); color: var(--muted); outline: 1px solid rgba(0,0,0,.06); outline-offset: -1px; }
.ad-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 99px; background: var(--idle-soft); color: var(--muted); }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.live { background: var(--live-soft); color: var(--live); }
.pill.scheduled { background: var(--warn-soft); color: var(--warn); }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.actions .btn { padding: 7px 10px; font-size: 13px; }

.empty { text-align: center; padding: 56px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); margin-top: -1px; }
.empty p { max-width: 440px; margin: 8px auto 20px; }

/* editor */
.editor { width: min(1040px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px -16px rgba(10,16,30,.4); }
.editor::backdrop { background: rgba(14,20,32,.5); }
.editor[open] { animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .editor[open] { animation: none; } }
.editor form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.editor-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.editor-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); overflow: auto; }
.fields { padding: 24px; display: grid; gap: 16px; align-content: start; }
.fields > div { display: grid; gap: 16px; }
.pair { display: grid !important; grid-template-columns: 1fr 1fr; gap: 12px !important; }
.seg { border: 0; padding: 0; margin: 0; display: flex; gap: 0; }
.seg legend { font-weight: 600; font-size: 13px; padding: 0; margin-bottom: 6px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; width: 1px; }
.seg span { display: block; text-align: center; padding: 9px; border: 1px solid var(--line); font-weight: 600; font-size: 14px; cursor: pointer; }
.seg label:first-of-type span { border-radius: 6px 0 0 6px; }
.seg label:last-of-type span { border-radius: 0 6px 6px 0; border-left: 0; }
.seg input:checked + span { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 20px; text-align: center; display: grid; gap: 4px; cursor: pointer; font-size: 14px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.sizes { display: flex !important; flex-wrap: wrap; gap: 6px !important; margin-top: -8px; }
.sizes button { font: 500 12px var(--mono); border: 1px solid var(--line); background: none; color: var(--muted); border-radius: 4px; padding: 4px 7px; cursor: pointer; }
.sizes button:hover { color: var(--accent); border-color: var(--accent); }

/* posição no site */
.place { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; display: grid; gap: 12px; }
.place legend { font-weight: 700; font-size: 13px; padding: 0 6px; margin-left: -6px; }
.place > select { margin-top: 0; }
.place .hint { margin: 0; }
.place-pick { display: grid; gap: 12px; }
.pick-row { display: flex; gap: 8px; margin-top: 6px; }
.pick-row input { margin: 0; flex: 1; min-width: 0; }
.pick-row .btn { flex: none; }
.pick-ok { color: var(--live); font-weight: 600; }
.embed-hint { margin: -2px 0 8px; }

/* miniatura da página com a posição do anúncio */
.mock { position: relative; height: 150px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; padding: 14px 16px; display: grid; align-content: start; gap: 7px; }
.mock i { display: block; height: 7px; border-radius: 4px; background: var(--idle-soft); }
.mock i.h { height: 12px; width: 45%; margin-bottom: 4px; }
.mock b { display: block; background: var(--accent); border-radius: 3px; height: 18px; width: 52%; justify-self: center; }
.mock b.pick { outline: 2px dashed var(--accent); outline-offset: 2px; }
.mock b.bar { position: absolute; left: 0; right: 0; width: auto; height: 16px; border-radius: 0; }
.mock b.bar.bottom { bottom: 0; }
.mock b.bar.top { top: 0; }
.mock b.corner { position: absolute; bottom: 10px; width: 26%; height: 30px; }
.mock b.corner.right { right: 10px; }
.mock b.corner.left { left: 10px; }

/* the memorable part: preview + tag */
.side { background: var(--bg); padding: 24px; display: grid; gap: 22px; align-content: start; border-left: 1px solid var(--line); }
.side-title { display: block; font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.preview {
  min-height: 220px; border-radius: var(--radius); display: grid; place-items: center; padding: 20px; overflow: auto;
  background-color: var(--surface);
  background-image: linear-gradient(45deg, var(--idle-soft) 25%, transparent 25%, transparent 75%, var(--idle-soft) 75%), linear-gradient(45deg, var(--idle-soft) 25%, transparent 25%, transparent 75%, var(--idle-soft) 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}
.preview .frame { position: relative; line-height: 0; max-width: 100%; }
.preview img { max-width: 100%; height: auto; display: block; }
.preview iframe { border: 0; max-width: 100%; background: #fff; }
.preview .lbl { position: absolute; top: 0; right: 0; font: 500 10px/1 system-ui, sans-serif; color: #fff; background: rgba(0,0,0,.45); padding: 3px 5px; border-bottom-left-radius: 3px; }
.embed pre { margin: 0 0 10px; padding: 14px; background: var(--ink); color: #DCE4FF; border-radius: 6px; white-space: pre-wrap; word-break: break-all; line-height: 1.6; }
@media (prefers-color-scheme: dark) { .embed pre { background: #0B0F16; } }
.embed-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-nums { display: flex; gap: 24px; margin-bottom: 8px; }
.stat-nums div { font-size: 13px; color: var(--muted); }
.stat-nums strong { display: block; font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
#chart { width: 100%; height: 80px; display: block; }
.editor-foot { display: flex; align-items: center; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--line); }
.editor-foot .form-error { flex: 1; text-align: right; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 6px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* responsive */
@media (max-width: 860px) {
  .row { grid-template-columns: minmax(0, 1fr) auto; }
  .row-head { display: none; }
  .row > .num, .row > .actions { display: none; }
  .editor-body { grid-template-columns: 1fr; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 560px) {
  .topbar, .main { padding-inline: 16px; }
  .head { flex-direction: column; align-items: stretch; }
  .head .btn { justify-content: center; }
  .filters { flex-wrap: wrap; }
  .filters input { flex-basis: 100%; }
  .filters select { flex: 1; }
  .editor { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; margin: 0; height: 100vh; }
  .editor form { max-height: 100vh; height: 100%; }
  .editor-foot { flex-wrap: wrap; }
}
