/* Real ROAS admin. Served with style-src 'self': no inline styles anywhere. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202e;
  --muted: #4a5464;
  --border: #d3d8e0;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-text: #ffffff;
  --focus: #2563eb;
  --ok-bg: #e5f5ea;
  --ok-text: #14532d;
  --ok-border: #8cc9a0;
  --warn-bg: #fff4e0;
  --warn-text: #6b3a00;
  --warn-border: #e9bf75;
  --err-bg: #fdecec;
  --err-text: #8f1c1c;
  --err-border: #eba3a3;
  --info-bg: #e9f0ff;
  --info-text: #1e3a8a;
  --info-border: #a9c0f5;
  --off-bg: #eceff3;
  --off-text: #3b4350;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #161d27;
    --surface-2: #1d2531;
    --text: #e7ecf3;
    --muted: #aab4c2;
    --border: #303b4a;
    --primary: #6c9cf5;
    --primary-hover: #8db2f8;
    --primary-text: #0b1220;
    --focus: #8ab4ff;
    --ok-bg: #11301e;
    --ok-text: #a9e6bc;
    --ok-border: #2f6b45;
    --warn-bg: #36280c;
    --warn-text: #f5d58f;
    --warn-border: #7a5a1c;
    --err-bg: #3a1618;
    --err-text: #fbb7b7;
    --err-border: #7f3133;
    --info-bg: #15244a;
    --info-text: #bcd0fb;
    --info-border: #34508f;
    --off-bg: #242d3a;
    --off-text: #c6cfdb;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  overflow-wrap: anywhere;
}

a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
code { background: var(--surface-2); border-radius: 4px; padding: 1px 5px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 1.2rem; margin: 0 0 8px; }
h3 { font-size: 1.05rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1:focus-visible, main:focus-visible { outline-offset: 4px; }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: 6px; box-shadow: var(--shadow);
}
.skip:focus { top: 12px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1160px; margin: 0 auto; padding: 10px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.logo img { width: 24px; height: 24px; }
.logo span { font-weight: 500; color: var(--muted); }
.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; }
.nav a {
  padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--info-bg); color: var(--info-text); }
.who { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .925rem; }
.who-email { font-weight: 600; }

/* ---------- layout ---------- */
main { max-width: 1160px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { margin-bottom: 18px; }
.page-head p { color: var(--muted); max-width: 70ch; }
.back { display: inline-block; margin-bottom: 10px; }
section + section, .card + .card, .stack > * + * { margin-top: 16px; }
.section-title { margin: 28px 0 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 40px auto 0; }
.card > :last-child { margin-bottom: 0; }

.grid, .grid-2 { margin-bottom: 16px; }
#onetime:not(:empty) { margin-bottom: 16px; }
h1[tabindex="-1"]:focus { outline: none; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid > .card { margin-top: 0; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); align-items: start; }
.grid-2 > .card { margin-top: 0; }

/* ---------- brand cards ---------- */
.brand-card h2 { font-size: 1.15rem; margin-bottom: 4px; }
.brand-card h2 a { text-decoration: none; }
.brand-card h2 a:hover { text-decoration: underline; }
.facts { margin: 8px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* ---------- chips ---------- */
.chips { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: .82rem; font-weight: 600; line-height: 1.6;
  border: 1px solid transparent;
}
.chip.on { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-border); }
.chip.inherit { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }
.chip.off { background: var(--off-bg); color: var(--off-text); border-color: var(--border); }
.chip.warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.chip.err { background: var(--err-bg); color: var(--err-text); border-color: var(--err-border); }
.chip.role { background: var(--surface-2); color: var(--text); border-color: var(--border); }

/* ---------- forms ---------- */
form { margin: 0; }
.fields { display: grid; gap: 14px 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label, legend { font-weight: 600; font-size: .95rem; }
.req { font-weight: 400; color: var(--muted); }
.help { color: var(--muted); font-size: .85rem; margin: 0; }
.stored { font-size: .85rem; margin: 0; color: var(--muted); }
.stored.yes { color: var(--ok-text); }
.field-error { color: var(--err-text); font-size: .875rem; font-weight: 600; margin: 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #8a94a3;
  border-radius: 7px;
  padding: 9px 11px;
  min-height: 42px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
[aria-invalid="true"] { border-color: var(--err-text) !important; }
input[readonly] { background: var(--surface-2); }
input[type="file"] { font: inherit; max-width: 100%; }
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; }

fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px 12px; margin: 0; min-width: 0; }
fieldset.checks .check { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
fieldset.checks .check label { font-weight: 400; }

.inline-input { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-input > input { flex: 1 1 200px; min-width: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem;
  min-height: 40px; padding: 8px 16px;
  border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--err-text); border-color: var(--err-border); }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: .875rem; }
.btn.link { border: 0; background: none; color: var(--primary); padding: 4px 6px; min-height: 0; text-decoration: underline; font-weight: 500; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }

/* ---------- messages ---------- */
.alert { border-radius: 8px; padding: 10px 14px; border: 1px solid; margin: 0 0 12px; }
.alert.err { background: var(--err-bg); color: var(--err-text); border-color: var(--err-border); }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-border); }
.alert.info { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }
.alert.warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.alert > :last-child { margin-bottom: 0; }
.form-error { margin-top: 12px; }

.result { margin-top: 14px; }
.result h4 { margin: 0 0 4px; font-size: 1rem; }
.result .facts { margin-top: 6px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 40;
  max-width: 480px; margin: 0 auto;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  font-weight: 600; text-align: center;
}
.toast:empty { padding: 0; background: transparent; box-shadow: none; }

.loading { color: var(--muted); padding: 24px 0; }

/* ---------- details (collapsible add forms) ---------- */
details.card > summary {
  cursor: pointer; font-weight: 700; font-size: 1.05rem; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "+"; display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 6px; background: var(--info-bg); color: var(--info-text); font-weight: 700; }
details.card[open] > summary::before { content: "\2212"; }
details.card[open] > summary { margin-bottom: 14px; }

/* ---------- connectors ---------- */
.connector h3 { font-size: 1.1rem; }
.connector .adds { color: var(--muted); font-size: .92rem; }
.connector .status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 8px 0 14px; font-size: .9rem; }
.agency { border-color: var(--info-border); }
.file-load { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .875rem; }
.file-load label { font-weight: 500; }

/* ---------- one-time password ---------- */
.onetime { border: 2px solid var(--warn-border); background: var(--warn-bg); color: var(--warn-text); }
.onetime h2 { color: var(--warn-text); }
.onetime input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.05rem; letter-spacing: .03em; }

/* ---------- user cards ---------- */
.user-card h3 { font-size: 1.05rem; margin-bottom: 4px; }
.user-card .panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------- tables (stack on narrow screens) ---------- */
.table-wrap { width: 100%; }
table.data { width: 100%; border-collapse: collapse; font-size: .925rem; }
.data caption { text-align: left; font-weight: 600; padding-bottom: 6px; }
.data th, .data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data th { background: var(--surface-2); font-weight: 600; }
.data td.num, .data th.num { text-align: right; }
.data .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; color: var(--muted); }

.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.filter-row .field { flex: 1 1 260px; max-width: 420px; }

/* ---------- help ---------- */
.help-panel ol { padding-left: 1.3em; margin: 0; }
.help-panel li + li { margin-top: 10px; }
details.help-panel > summary::before { content: "?"; }
details.help-panel[open] > summary::before { content: "?"; }

@media (max-width: 760px) {
  h1 { font-size: 1.4rem; }
  main { padding-top: 18px; }
  .card { padding: 14px; }
  .card.narrow { margin-top: 16px; }
  .who { width: 100%; justify-content: space-between; }
  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data, .data tbody, .data tr, .data td { display: block; width: 100%; }
  .data tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; padding: 6px 10px; background: var(--surface); }
  .data td { border: 0; padding: 3px 0; display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 8px; }
  .data td.num { text-align: left; }
  .data td::before { content: attr(data-label); font-weight: 600; color: var(--muted); }
}

@media (max-width: 480px) {
  .facts { grid-template-columns: minmax(0, 40%) minmax(0, 1fr); }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .nav a, input, select, textarea { transition: background-color .12s, border-color .12s, color .12s; }
}
