:root {
  --bg: #0e0f12;
  --surface: #16181d;
  --surface-2: #1c1f26;
  --border: #262a31;
  --border-2: #2c313a;
  --text: #e7e9ee;
  --text-dim: #9aa0ad;
  --text-faint: #6b7280;
  --accent: #6c8cff;
  --accent-text: #fff;
  --ok: #7bdca0;
  --warn: #e0a23b;
  --err: #ff8095;
  --live: #33b9a6;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
html[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e2e5ea;
  --border-2: #d6dae1;
  --text: #1d2127;
  --text-dim: #5b616e;
  --text-faint: #8a909c;
  --accent: #4f6cff;
  --shadow: 0 8px 30px rgba(20,30,60,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
input, textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--text-dim); margin: 12px 0 5px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; cursor: pointer; }
label.inline input { width: auto; }

.btn {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px;
  padding: 9px 14px; font-weight: 600;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--err); border: 1px solid var(--border-2); }
.btn.danger:hover { background: rgba(255,128,149,.08); }
.btn.sm { padding: 6px 10px; font-size: .85rem; }

/* ---- Auth screens ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.2rem; margin: 0 0 4px; }
.auth-card .sub { margin: 0 0 16px; color: var(--text-dim); font-size: .9rem; }
.auth-card .btn { width: 100%; margin-top: 18px; }

/* ---- App shell ---- */
.shell { max-width: 1080px; margin: 0 auto; padding: 0 20px 60px; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 10; }
.brand { font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; }
.brand small { display: block; font-weight: 500; font-size: .7rem; color: var(--text-faint); letter-spacing: 0; }
.spacer { flex: 1; }
.topbar .iconbtn { background: transparent; border: 1px solid var(--border-2); border-radius: 8px; color: var(--text-dim); padding: 7px 10px; }
.topbar .iconbtn:hover { color: var(--text); background: var(--surface-2); }

.tabs { display: flex; gap: 6px; margin: 18px 0 4px; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--text-dim); padding: 8px 4px; margin-right: 14px; font-weight: 600; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.toolbar { display: flex; align-items: center; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 160px; }
.toolbar .spacer { flex: 1; }

/* ---- Ad cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card .thumb { aspect-ratio: 16/9; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb .ph { color: var(--text-faint); font-size: .8rem; }
.card .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .row { display: flex; align-items: center; gap: 8px; }
.card .ttl { font-weight: 700; font-size: .98rem; }
.card .game { font-size: .72rem; color: var(--text-faint); }
.card .desc { color: var(--text-dim); font-size: .85rem; min-height: 1.2em; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .78rem; color: var(--text-dim); }
.card .stats { display: flex; gap: 14px; font-size: .8rem; color: var(--text-dim); border-top: 1px solid var(--border); padding-top: 8px; }
.card .stats b { color: var(--text); }
.card .actions { display: flex; gap: 8px; }

.chip { display: inline-block; font-size: .68rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text-dim); }
.chip.tag { background: rgba(108,140,255,.12); border-color: transparent; color: var(--accent); }
.badge { font-size: .68rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.live { background: rgba(51,185,166,.14); color: var(--live); }
.badge.paused { background: rgba(154,160,173,.14); color: var(--text-dim); }
.badge.scheduled { background: rgba(108,140,255,.14); color: var(--accent); }
.badge.expired { background: rgba(255,128,149,.12); color: var(--err); }

/* ---- Toggle ---- */
.toggle { position: relative; width: 38px; height: 22px; flex: 0 0 auto; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle .track { position: absolute; inset: 0; background: var(--border-2); border-radius: 999px; transition: background .15s; }
.toggle .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform .15s; }
.toggle input:checked + .track { background: var(--live); }
.toggle input:checked + .track::after { transform: translateX(16px); }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: .88rem; }
th { color: var(--text-dim); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.empty { padding: 40px; text-align: center; color: var(--text-faint); }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.modal header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal header h2 { margin: 0; font-size: 1.05rem; }
.modal .content { padding: 8px 20px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.modal .x { margin-left: auto; background: transparent; border: 0; color: var(--text-dim); font-size: 1.3rem; line-height: 1; }

.field-row { display: flex; gap: 14px; }
.field-row > div { flex: 1; }
.hint { font-size: .74rem; color: var(--text-faint); margin-top: 4px; }
.placement-grid { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 6px; }

.preview { aspect-ratio: 16/9; background: var(--surface-2); border: 1px dashed var(--border-2); border-radius: 8px; display: grid; place-items: center; overflow: hidden; margin-top: 6px; }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview .ph { color: var(--text-faint); font-size: .82rem; }

.msg { font-size: .85rem; min-height: 1.2em; margin-top: 6px; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }
.msg.warn { color: var(--warn); }

.token-secret { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--bg); border: 1px solid var(--border-2); border-radius: 8px; padding: 10px; word-break: break-all; font-size: .82rem; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; word-break: break-all; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .85em; }

@media (max-width: 560px) {
  .field-row { flex-direction: column; gap: 0; }
  .cards { grid-template-columns: 1fr; }
}
