:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #e8804a;
  --accent-2: #f0a276;
  --danger: #e05555;
  --ok: #4caf7d;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 12px; }

/* ---- Login ---- */
.login-screen {
  height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 56px;
  text-align: center;
}
.login-card h1 { margin-bottom: 8px; font-size: 22px; }
.login-card .muted { margin-bottom: 24px; }
#gsi-button { display: flex; justify-content: center; }

/* ---- Shell ---- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.brand { padding: 20px; font-weight: 700; font-size: 16px; color: var(--accent-2); }
#nav { flex: 1; padding: 8px; }
#nav a {
  display: block; padding: 10px 12px; margin-bottom: 2px;
  color: var(--muted); text-decoration: none; border-radius: 8px;
}
#nav a:hover { background: var(--panel-2); color: var(--text); }
#nav a.active { background: var(--panel-2); color: var(--accent-2); font-weight: 600; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.whoami { font-size: 12px; color: var(--muted); margin-bottom: 8px; word-break: break-all; }
.whoami b { color: var(--text); display: block; }
.main { flex: 1; overflow-y: auto; padding: 24px 28px; }

/* ---- Toolbar / controls ---- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h2 { font-size: 18px; margin-right: auto; }
input[type="text"], input[type="search"], select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="search"] { width: 260px; }

.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #16100b; font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { background: none; border: none; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }
td .thumb { width: 60px; height: 34px; object-fit: cover; border-radius: 4px; display: block; background: var(--panel-2); }
td .title-cell { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .sub { font-size: 12px; color: var(--muted); }
.chip {
  display: inline-block; padding: 1px 8px; margin: 1px 2px 1px 0;
  font-size: 11px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.chip.role-ADMIN { color: var(--accent-2); border-color: var(--accent); }
.badge-inactive { color: var(--danger); font-size: 11px; }
.row-actions { white-space: nowrap; text-align: right; }

/* ---- Pagination ---- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.pager .muted { font-size: 12px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; width: 480px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; font-size: 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select { width: 100%; }
.cat-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.cat-checks label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 18px; z-index: 100; box-shadow: 0 4px 24px rgba(0,0,0,.4);
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

/* ---- Stats row ---- */
.stats { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 18px; font-size: 13px; color: var(--muted);
}
.stat b { color: var(--text); font-size: 16px; display: block; }

/* Ad Reels: colour overrides + the live button/title preview. */
.field-color { display: flex; align-items: center; gap: 12px; }
.field-color input[type=color] { width: 48px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.ad-preview { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px; border-radius: 10px; margin-bottom: 12px;
  background: linear-gradient(160deg, #2a2118, #0d0b09); }
.ad-preview span { font-weight: 700; font-size: 1.05rem; }
.ad-preview button { border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 700; cursor: default; }
.sub.ok { color: #1a7f4b; }
.sub.error { color: #b3261e; }

/* Toggle switch — used for live/paused state, where a button ("Pause") states the
   ACTION and a switch states the STATE. For something you scan down a column of,
   the state is what matters. */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { position: relative; width: 38px; height: 22px; border-radius: 999px; flex: none;
  background: #cfcac2; transition: background .18s ease; }
.switch__knob { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.28); transition: transform .18s cubic-bezier(.22,1,.36,1); }
.switch input:checked + .switch__track { background: linear-gradient(135deg, #37b26b, #1f9d57); }
.switch input:checked + .switch__track .switch__knob { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid #f7a62b; outline-offset: 2px; }
.switch input:disabled + .switch__track { opacity: .45; }
.switch input:disabled ~ .switch__label { opacity: .55; }
.switch__label { font-size: .82rem; font-weight: 600; min-width: 46px; }

/* Paywall Plans */
.tier-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 14px; margin-bottom: 14px; }
.tier-card.tier-hidden { opacity: .6; }
.tier-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.tier-head .chip { margin-left: 6px; }
.section-title { font-size: 15px; margin: 22px 0 10px; }
