:root {
  --bg: #0e1116;
  --panel: #171b22;
  --panel-2: #1e2430;
  --line: #2a3342;
  --text: #e8edf5;
  --muted: #93a0b5;
  --accent: #3d9cff;
  --ok: #2fbf71;
  --bad: #e45757;
  --warn: #e0a106;
  --radius: 12px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, #1a2740 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #1b1830 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(14,17,22,.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { color: var(--text); font-weight: 700; letter-spacing: .02em; text-decoration: none; }
.brand span { color: var(--accent); font-weight: 600; }
.topbar nav { display: flex; gap: 16px; align-items: center; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: 14px; }
.topbar nav a:hover { color: var(--text); }

.wrap { width: min(1100px, calc(100% - 32px)); margin: 24px auto 64px; }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.page-head h1 { margin: 0 0 6px; font-size: 28px; }
.muted { color: var(--muted); margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat strong { font-size: 24px; }
.stat.ok strong { color: var(--ok); }
.stat.bad strong { color: var(--bad); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: rgba(255,255,255,.02); }
.truncate { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); text-transform: lowercase; }
.badge.works, .badge-ok { color: #9ef0c1; background: rgba(47,191,113,.12); border-color: rgba(47,191,113,.35); }
.badge.failed, .badge.blocked, .badge-fail, .badge-block { color: #ffb4b4; background: rgba(228,87,87,.12); border-color: rgba(228,87,87,.35); }
.badge.needs_review, .badge.unknown, .badge-review, .badge-unknown { color: #ffd58a; background: rgba(224,161,6,.12); border-color: rgba(224,161,6,.35); }
.badge.audience-gay { color: #9ef0c1; }
.badge.audience-bi { color: #9ec8f0; background: rgba(80,140,200,.12); border-color: rgba(80,140,200,.35); }
.badge.audience-straight, .badge.audience-trans { color: #ffd58a; }
.btn-mini { display: inline-flex; align-items: center; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); border-radius: 8px; padding: 3px 8px; font: inherit; font-size: 12px; cursor: pointer; margin-left: 6px; }
.btn-mini:hover { color: var(--text); }
.btn-mini.danger { color: #ffb4b4; border-color: rgba(228,87,87,.4); }
.btn-ghost { background: transparent; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; margin: 0; padding: 16px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; }
.panel h2 { margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 16px; }
.panel > p, .panel > .table, .panel > details, .panel > form { margin: 14px 16px; }
.add-box { margin: 14px 16px 18px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }
.add-box summary { cursor: pointer; color: var(--muted); }
.form { display: grid; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }
.inline { display: inline; }
.crumb { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.url-cell { max-width: 420px; word-break: break-all; }
.clip { max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.danger-zone { border-color: rgba(228,87,87,.35); }
.flash-ok { background: rgba(47,191,113,.12); border-color: rgba(47,191,113,.35); }
.flash-error { background: rgba(228,87,87,.12); border-color: rgba(228,87,87,.35); }
.stack { display: grid; gap: 12px; margin-top: 18px; }

.btn, button.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: #3b465a; }
.btn.primary { background: var(--accent); border-color: transparent; color: #041018; font-weight: 600; }
.btn.danger { background: rgba(228,87,87,.15); border-color: rgba(228,87,87,.4); color: #ffb4b4; }
.btn.small { padding: 6px 9px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; background: #0f131a; color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
.form-actions { padding: 0 16px 16px; display: flex; gap: 8px; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid var(--line); }
.flash.ok { background: rgba(47,191,113,.12); border-color: rgba(47,191,113,.35); }
.flash.error { background: rgba(228,87,87,.12); border-color: rgba(228,87,87,.35); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card h1 { margin: 0 0 6px; font-size: 24px; }
.login-card .stack { display: grid; gap: 12px; margin-top: 18px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 160px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

.nav-main { display:flex; flex-wrap:wrap; gap:10px 14px; align-items:center; max-width:72vw; justify-content:flex-end; }
.toolbar { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:14px; align-items:center; }
.toolbar .grow, .toolbar input[type=search] { flex:1; min-width:180px; }
.stat-grid.dense { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat-grid a.stat { text-decoration:none; color:inherit; }
.stat-grid a.stat:hover { border-color:#3b465a; }
.pager { display:flex; gap:6px; flex-wrap:wrap; margin:12px 0 24px; }
.pager a { padding:6px 10px; border:1px solid var(--line); border-radius:8px; color:var(--muted); }
.pager a.active { color:var(--text); border-color:var(--accent); }
.table.sticky thead th { position:sticky; top:56px; background:var(--panel); z-index:5; }
.creative-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(180px,1fr)); gap:12px; padding:16px; }
.creative-card { display:grid; gap:6px; padding:12px; border:1px solid var(--line); border-radius:12px; color:inherit; text-decoration:none; background:var(--panel-2); }
.creative-card:hover { border-color:#3b465a; text-decoration:none; }
.creative-thumb { aspect-ratio:16/10; display:grid; place-items:center; background:#0f131a; border-radius:8px; color:var(--muted); font-size:12px; }
.inline-form { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }
.inline-form input, .inline-form select { width:auto; min-width:0; padding:6px 8px; }
.wrap { width: min(1200px, calc(100% - 32px)); }

/* Link Library */
.wrap.wide, body:has(.lib-program) .wrap { width: min(1380px, calc(100% - 24px)); }
.saved-views { display:flex; flex-wrap:wrap; gap:8px; margin:0 0 14px; }
.saved-views a {
  padding:6px 11px; border:1px solid var(--line); border-radius:999px;
  color:var(--muted); font-size:13px; text-decoration:none; background:var(--panel);
}
.saved-views a:hover { color:var(--text); text-decoration:none; border-color:#3b465a; }
.saved-views a.active { color:#041018; background:var(--accent); border-color:transparent; font-weight:600; }
.library-filters select, .library-filters input[type=search] { min-width:0; }
.library-filters .filter-site { flex:1; min-width:180px; margin:0; }
.library-filters .filter-site input { width:100%; }
.library-filters .check.tight { margin:0; color:var(--muted); white-space:nowrap; }
.bulk-bar {
  display:flex; flex-wrap:wrap; gap:8px; align-items:center;
  padding:10px 12px; margin-bottom:12px; border:1px solid var(--line);
  border-radius:var(--radius); background:var(--panel-2); position:sticky; top:58px; z-index:12;
}
.bulk-bar .bulk-select, .bulk-bar .bulk-tag, .bulk-bar .bulk-site-id { width:auto; min-width:120px; padding:6px 8px; }
.bulk-bar .bulk-site-id { width:100px; }
.lib-program, .lib-site {
  background:var(--panel); border:1px solid var(--line); border-radius:var(--radius);
  margin-bottom:12px;
}
.lib-site { margin:8px 12px 12px; background:var(--panel-2); }
.lib-program > summary, .lib-site > summary {
  display:flex; flex-wrap:wrap; gap:10px; align-items:center;
  padding:12px 14px; cursor:pointer; list-style:none; user-select:none;
}
.lib-program > summary::-webkit-details-marker,
.lib-site > summary::-webkit-details-marker { display:none; }
.lib-prog-name { font-weight:700; font-size:16px; }
.lib-site-name { font-weight:600; }
.lib-site .table-wrap { padding:0 0 4px; }
.lib-table { margin:0; }
.lib-table thead th {
  position:static; top:auto; background:var(--panel-2); z-index:1;
  color:var(--muted); border-bottom:1px solid var(--line);
}
.lib-table tbody td { color:var(--text); background:transparent; }
.lib-table th.col-check, .lib-table td:first-child { width:36px; }
.lib-table .lib-short { margin-top:2px; font-size:11px; color:var(--muted); }
.lib-actions { white-space:nowrap; }
.lib-actions .btn-mini { margin:2px 0 2px 4px; }
.tiny { font-size:11px; margin-top:2px; }
.break { word-break:break-all; }
.link-drawer[hidden] { display:none !important; }
.link-drawer { position:fixed; inset:0; z-index:40; }
.link-drawer-backdrop { position:absolute; inset:0; background:rgba(0,0,0,.45); }
.link-drawer-panel {
  position:absolute; top:0; right:0; height:100%; width:min(480px,100%);
  background:var(--panel); border-left:1px solid var(--line);
  display:flex; flex-direction:column; box-shadow:-12px 0 40px rgba(0,0,0,.35);
}
.link-drawer-head {
  display:flex; justify-content:space-between; align-items:center;
  padding:14px 16px; border-bottom:1px solid var(--line);
}
.link-drawer-head h2 { margin:0; font-size:16px; }
.link-drawer-body { overflow:auto; padding:8px 0 24px; flex:1; }
.link-drawer-body h3 { margin:18px 16px 8px; font-size:13px; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; }
.link-drawer-body ul { margin:0 16px; padding-left:18px; }
.link-drawer-body .table { margin:0; }
.drawer-kv { grid-template-columns:120px 1fr; }

@media (max-width: 860px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .nav-main { max-width:100%; justify-content:flex-start; }
  .topbar { flex-direction:column; align-items:flex-start; gap:10px; }
  .lib-actions { white-space:normal; }
}
