:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1a1d23; --muted: #6b7280; --border: #e2e5ea;
  --primary: #2563eb; --primary-text: #fff; --on: #16a34a; --on-bg: #dcfce7; --off: #6b7280; --off-bg: #eceef1;
  --danger: #dc2626; --danger-bg: #fee2e2; --warn-bg: #fef3c7; --warn: #92400e; --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #181b21; --text: #e8eaee; --muted: #9aa1ad; --border: #2a2f38;
    --primary: #3b82f6; --on: #4ade80; --on-bg: #14351f; --off: #9aa1ad; --off-bg: #23272f;
    --danger: #f87171; --danger-bg: #3b1818; --warn-bg: #3a2c0b; --warn: #fbbf24;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.4rem; margin: 0; } h2 { font-size: 1.1rem; margin: 0; } h3 { font-size: 1rem; margin: 0; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.hidden { display: none !important; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1000px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.nav a.active, .nav a:hover { background: var(--off-bg); color: var(--text); text-decoration: none; }

.container { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; display: grid; gap: 16px; }
.container > *, .grid > *, .card { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.muted-card { opacity: .8; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }

.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--off-bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: .85rem; }

input[type=text], input[type=password], select { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
label.field { display: grid; gap: 4px; margin-bottom: 12px; font-size: .9rem; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--off-bg); color: var(--off); white-space: nowrap; }
.badge.on { background: var(--on-bg); color: var(--on); }
.badge.off { background: var(--off-bg); color: var(--off); }
.badge.bad { background: var(--danger-bg); color: var(--danger); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }

.switch { position: relative; width: 46px; height: 26px; border-radius: 999px; border: 0; padding: 0; background: #b6bcc6; cursor: pointer; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--on); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.switch-label { font-weight: 600; min-width: 2.2em; }

.banner { padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: .9rem; }
.banner.bad { background: var(--danger-bg); color: var(--danger); }

.platform-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.ad-row { padding: 12px 0; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.ad-row:last-child { border-bottom: 0; }
.ad-row.dirty { background: linear-gradient(90deg, var(--warn-bg), transparent 40%); }
.ad-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ad-name { font-weight: 600; flex: 1 1 auto; }
.ad-edit { display: flex; gap: 8px; }
.effective { font-size: .82rem; padding: 2px 9px; border-radius: 999px; }
.effective.live { background: var(--on-bg); color: var(--on); font-weight: 600; }
.effective.blocked { background: var(--off-bg); color: var(--muted); }
.unit-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }

pre.preview { margin: 0; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; overflow: auto; font-size: .82rem; max-height: 380px; }
.tabs { display: flex; gap: 6px; }
.tabs .btn[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; word-break: break-all; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toasts { position: fixed; right: 12px; bottom: 12px; left: 12px; display: grid; gap: 8px; justify-items: end; z-index: 100; pointer-events: none; }
.toast { pointer-events: auto; padding: 10px 14px; border-radius: 8px; background: #1f2937; color: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 420px; }
.toast.success { background: #166534; } .toast.error { background: #991b1b; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 380px); }
.login-card h1 { margin-bottom: 4px; }
.error-text { color: var(--danger); min-height: 1.4em; font-size: .9rem; margin: 0 0 8px; }

@media (max-width: 520px) {
  .container { padding: 14px 12px 60px; }
  .ad-edit { flex-direction: column; }
  .ad-edit .btn { width: 100%; }
}
