:root {
  --bg: #0a0a0a;
  --card-bg: rgba(18, 18, 20, 0.72);
  --card-solid: #131316;
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --text-dim: rgba(245, 245, 247, 0.7);
  --text-muted: rgba(245, 245, 247, 0.45);
  --accent: #ff3b6b;
  --accent-hover: #ff5280;
  --muted: rgba(255, 255, 255, 0.06);
  --muted-hover: rgba(255, 255, 255, 0.1);
  --danger: #ff4444;
  --danger-hover: #ff6262;
  --success: #30d158;
  --border: #2c2c2e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  background: rgba(255,255,255,0.06);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ---------- Age gate ---------- */
.gate-body {
  min-height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-body::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.8) 100%);
  z-index: 0;
}

.gate-card {
  position: relative;
  z-index: 1;
  max-width: 440px;
  width: 100%;
  background: var(--card-bg);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 40px 32px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.gate-card .icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ff7a5c);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.gate-card h1 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.gate-card p {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 28px;
}

.gate-actions { display: flex; flex-direction: column; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  font-family: inherit;
  color: var(--text);
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--muted); }
.btn-secondary:hover { background: var(--muted-hover); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(255,68,68,0.3); }
.btn-danger:hover { background: rgba(255,68,68,0.1); }

.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 8px; }

.disclaimer {
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.denied { text-align: center; }
.denied h1 { color: var(--danger); }

/* ---------- IG escape overlay ---------- */
.ig-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.ig-overlay .box {
  max-width: 360px; width: 100%;
  background: #1c1c1e;
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
}
.ig-overlay h2 { font-size: 20px; margin-bottom: 12px; }
.ig-overlay p { color: var(--text-dim); font-size: 14px; line-height: 1.5; margin-bottom: 16px; }
.ig-overlay .steps {
  background: #000;
  border-radius: 10px;
  padding: 16px;
  font-size: 13px;
  line-height: 1.6;
  text-align: left;
  color: var(--text-dim);
  margin-bottom: 18px;
}
.ig-overlay .steps strong { color: var(--text); }
.ig-overlay .copy-row { display: flex; gap: 8px; margin-bottom: 10px; }
.ig-overlay .copy-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a0a0a;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

/* ---------- Homepage ---------- */
.home-body {
  min-height: 100%;
  background: radial-gradient(1200px 600px at 50% -20%, rgba(255,59,107,0.15), transparent 60%), var(--bg);
  padding: 48px 20px 80px;
}
.home-hero {
  text-align: center;
  max-width: 680px;
  margin: 0 auto 36px;
}
.home-title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #fff, #999);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.home-sub { color: var(--text-dim); font-size: 16px; }
.home-grid {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.home-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
}
.model-tile {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  overflow: hidden;
  display: block;
  background: #1c1c1e;
  background-size: cover;
  background-position: center;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--card-border);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.model-tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.model-tile-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.15) 30%, rgba(0,0,0,0.85) 100%);
}
.model-tile-content {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
}
.model-tile-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- Admin shell (sidebar + content) ---------- */
.admin-shell {
  background: var(--bg);
  min-height: 100vh;
}

.fullscreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#appView {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0e0e10;
  border-right: 1px solid var(--card-border);
  padding: 24px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 20px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--card-border);
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #ff7a5c);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
}
.brand-name {
  font-weight: 700;
  letter-spacing: -0.01em;
}

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-section {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  padding: 12px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active {
  background: rgba(255,59,107,0.12);
  color: var(--accent);
}
.nav-item.nav-dim { opacity: 0.5; cursor: default; }
.nav-icon {
  width: 18px;
  text-align: center;
  font-size: 14px;
  opacity: 0.8;
}
.nav-count {
  margin-left: auto;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.nav-item.active .nav-count {
  background: rgba(255,59,107,0.2);
  color: var(--accent);
}

.sidebar-foot {
  padding: 12px 10px 0;
  border-top: 1px solid var(--card-border);
  margin-top: 10px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}

.content {
  padding: 32px 36px 64px;
  max-width: 1100px;
  overflow-x: auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-header .subtitle { margin: 4px 0 0; }

.view { animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* responsive — sidebar becomes top bar on small screens */
@media (max-width: 720px) {
  #appView { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 12px;
    overflow-x: auto;
  }
  .brand { border-bottom: none; padding: 0 10px 0 0; margin-bottom: 0; }
  .nav { flex-direction: row; gap: 4px; flex-wrap: nowrap; }
  .nav-section { display: none; }
  .nav-item { padding: 6px 10px; white-space: nowrap; }
  .sidebar-foot { display: none; }
  .content { padding: 20px; }
}

/* Legacy admin styles kept for internal views */
.admin-body { background: var(--bg); min-height: 100%; padding: 32px 20px 64px; }
.admin-container { max-width: 760px; margin: 0 auto; }

.admin-container h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}
.admin-container h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}
.admin-container .subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 16px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.header-row .subtitle { margin-bottom: 0; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.card {
  background: var(--card-solid);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}
.section-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 16px;
}

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field .hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  line-height: 1.5;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0a0a0a;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease;
}
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field textarea { min-height: 84px; resize: vertical; }

.bg-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0a0a0a;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 13px;
}

.actions-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
  flex-wrap: wrap;
}

.status {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 12px;
  display: none;
}
.status.show { display: block; }
.status.ok { background: rgba(48, 209, 88, 0.12); color: var(--success); }
.status.err { background: rgba(255, 68, 68, 0.12); color: var(--danger); }

.login-card { max-width: 380px; margin: 80px auto 0; }

/* ---------- Model list ---------- */
.model-row, .account-row, .link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card-solid);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  margin-bottom: 8px;
}

.model-row-main, .account-row-main, .link-row-main {
  flex: 1;
  min-width: 0;
}
.model-slug, .account-user, .link-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}
.model-dest, .account-meta, .link-url {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-url { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.model-row-actions, .account-row-actions, .link-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.stat-box {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.stat-box.accent { border-color: rgba(255,59,107,0.4); }
.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.breakdown { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 520px) { .breakdown { grid-template-columns: 1fr; } }

.breakdown-title {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.breakdown-bars { display: flex; flex-direction: column; gap: 6px; }
.breakdown-row {
  display: grid;
  grid-template-columns: 72px 1fr 32px;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.breakdown-label {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breakdown-bar {
  height: 6px;
  background: var(--muted);
  border-radius: 3px;
  overflow: hidden;
}
.breakdown-fill {
  height: 100%;
  background: var(--accent);
}
.breakdown-count { color: var(--text-dim); text-align: right; }
.breakdown-empty { color: var(--text-muted); font-size: 13px; }

/* ---------- Events list ---------- */
.events-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--card-border);
  border-radius: 8px;
}
.event-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 10px;
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--card-border);
  align-items: center;
}
.event-row:last-child { border-bottom: none; }
.event-type {
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-align: center;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.event-view { background: rgba(100,100,110,0.25); color: var(--text-dim); }
.event-denied { background: rgba(255,68,68,0.15); color: var(--danger); }
.event-redirect_direct { background: rgba(48,209,88,0.15); color: var(--success); }
.event-redirect_intent { background: rgba(48,209,88,0.15); color: var(--success); }
.event-escape_shown { background: rgba(255,149,0,0.15); color: #ff9f0a; }
.event-meta { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-time { color: var(--text-muted); font-size: 11px; }
.event-empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---------- Per-source table ---------- */
.src-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 4px;
}
.src-table th, .src-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--card-border);
}
.src-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.src-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.src-table tr:last-child td { border-bottom: none; }
.src-name-direct { color: var(--text-muted); font-style: italic; }

/* ---------- Role badges ---------- */
.role-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 6px;
}
.role-owner    { background: rgba(255,59,107,0.18);  color: var(--accent); }
.role-admin    { background: rgba(255,149,0,0.18);   color: #ff9f0a; }
.role-creator  { background: rgba(100,149,237,0.18); color: #6aa5ff; }
.role-observer { background: rgba(120,120,128,0.22); color: var(--text-dim); }
.role-pending  { background: rgba(120,120,128,0.15); color: var(--text-muted); }

.role-select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a0a0a;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.role-select:disabled { opacity: 0.5; cursor: not-allowed; }
.role-fixed {
  font-size: 11px;
  color: var(--text-dim);
  padding: 6px 10px;
}

.readonly-note {
  background: rgba(120,120,128,0.12);
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}

/* ---------- Dashboard models table ---------- */
.card-table { padding: 0; overflow: hidden; }
.models-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.models-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 18px;
  border-bottom: 1px solid var(--card-border);
  background: #0e0e10;
}
.models-table thead th.num { text-align: right; }
.models-table tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--card-border);
  vertical-align: middle;
}
.models-table tbody tr:last-child td { border-bottom: none; }
.models-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.models-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.cell-link { display: flex; align-items: center; gap: 8px; }
.cell-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.cell-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  padding: 0;
}
.cell-dim { color: var(--text-dim); font-size: 13px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-actions { text-align: right; width: 1%; white-space: nowrap; }
.col-actions .btn { margin-left: 6px; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 2px 7px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.1s ease;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}

/* Aggregate stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  padding: 18px;
}
.stat-pill {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-pill .stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-pill .stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}
