/*!
 * 3DX Admin panel
 * Copyright (c) 2026 BLUEXPLUS Pty Ltd. All rights reserved.
 */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg: #f0f2f5;
  --ink: #0f1117;
  --muted: #6b7380;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --edge: #e5e8ee;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --r-md: 6px;
  --r-lg: 8px;
}
:root.theme-dark {
  --bg: #14161c;
  --ink: #e8eaf0;
  --muted: #8b93a3;
  --panel: #1a1d23;
  --panel-2: #20242c;
  --edge: #2a2e38;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over class rules like
   `.denied { display: flex }` — otherwise hiding the 404 overlay fails. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* 404 / denied state */
.denied {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}
.denied h1 { font-size: 64px; margin: 0; font-weight: 600; }
.denied p { color: var(--muted); margin: 0; }
.denied a { color: var(--accent); margin-top: 12px; text-decoration: none; }
.denied a:hover { text-decoration: underline; }

/* Panel */
.panel { max-width: 1100px; margin: 0 auto; padding: 28px 20px 64px; }

.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.admin-head h1 { font-size: 24px; font-weight: 600; margin: 0; }
.admin-head .sub { color: var(--muted); margin: 4px 0 0; font-size: 14px; }
.head-actions { display: flex; gap: 8px; }

.btn {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--edge);
}
.btn-ghost:hover { background: var(--panel-2); }

/* Summary cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  padding: 16px 18px;
}
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 28px; font-weight: 600; margin-top: 6px; }

/* Tables */
.block { margin-bottom: 32px; }
.block h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--edge);
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
}
th.num, td.num { text-align: right; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td.mono { font-family: 'DM Mono', monospace; font-size: 12.5px; color: var(--muted); }
tr.user-row { cursor: pointer; }
tr.user-row.is-selected td { background: var(--accent-light, rgba(37, 99, 235, 0.12)); }
tr.user-row.is-selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.empty { color: var(--muted); padding: 24px 14px; text-align: center; }
.badge-anon { color: var(--muted); }

/* Login activity drawer (slides in from the right) */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 40;
}
.drawer-backdrop.open { opacity: 1; }
.drawer-backdrop[hidden] { display: none; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(640px, 92vw);
  background: var(--bg);
  border-left: 1px solid var(--edge);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 41;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer[hidden] { display: none; }

.drawer-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--edge);
}
.drawer-hdr h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drawer-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-md);
}
.drawer-close:hover { background: var(--panel-2); color: var(--ink); }
.drawer-body { padding: 16px 18px; overflow: auto; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  text-transform: capitalize;
}

/* ── Users filter bar ─────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.filter-input,
.filter-select {
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  background: var(--panel);
  color: var(--ink);
}
.filter-input { min-width: 220px; flex: 1 1 220px; max-width: 320px; }
.filter-input:focus,
.filter-select:focus { outline: none; border-color: var(--accent); }
.filter-count { color: var(--muted); font-size: 13px; margin-left: auto; }

/* ── Plan badge + status pill (table + drawer) ────────────────────────── */
.plan-badge,
.status-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
/* Plan colors mirror the paywall pills: grey / blue / purple. */
.plan-free { background: var(--panel-2); border-color: var(--edge); color: var(--muted); }
.plan-pro  { background: rgba(37, 99, 235, 0.12); border-color: rgba(37, 99, 235, 0.30); color: var(--accent); }
.plan-ai   { background: rgba(124, 58, 237, 0.14); border-color: rgba(124, 58, 237, 0.32); color: #7c3aed; }
:root.theme-dark .plan-ai { color: #a78bfa; }

.status-pill { text-transform: capitalize; }
.status-active   { background: rgba(22, 163, 74, 0.14); border-color: rgba(22, 163, 74, 0.30); color: #16a34a; }
.status-past_due { background: rgba(217, 119, 6, 0.15); border-color: rgba(217, 119, 6, 0.32); color: #d97706; }
.status-canceled { background: var(--panel-2); border-color: var(--edge); color: var(--muted); }
.status-admin    { background: rgba(37, 99, 235, 0.10); border-color: rgba(37, 99, 235, 0.26); color: var(--accent); }
.status-other    { background: var(--panel-2); border-color: var(--edge); color: var(--ink); }
:root.theme-dark .status-active { color: #4ade80; }
:root.theme-dark .status-past_due { color: #fbbf24; }
td .muted, .sd-v.muted { color: var(--muted); }

/* ── Drawer subscription detail block ─────────────────────────────────── */
.drawer-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 24px 0 10px;
}
.sub-detail {
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  background: var(--panel);
  padding: 16px 18px;
  margin-bottom: 8px;
}
.sub-detail:empty { display: none; }
.sd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
}
.sd-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sd-field.sd-wide { grid-column: 1 / -1; }
.sd-k {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sd-v { font-size: 14px; }
.sd-v.mono { font-family: 'DM Mono', monospace; font-size: 12.5px; word-break: break-all; }

.sd-actions {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--edge);
}
.sd-action { display: flex; flex-direction: column; gap: 6px; }
.sd-action-row { display: flex; gap: 8px; align-items: center; }
.sd-action select,
.sd-action input {
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  background: var(--panel);
  color: var(--ink);
}
.sd-action input { width: 110px; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.sd-msg { width: 100%; margin: 4px 0 0; font-size: 13px; color: #16a34a; }
.sd-msg.err { color: #dc2626; }

/* ── Drawer credit-ledger mini table ──────────────────────────────────── */
.sd-ledger td.pos { color: #16a34a; }
.sd-ledger td.neg { color: #dc2626; }
:root.theme-dark .sd-ledger td.pos { color: #4ade80; }
:root.theme-dark .sd-ledger td.neg { color: #f87171; }

/* ── Sign-in funnel summary ───────────────────────────────────────────── */
.funnel-summary { margin: 0 0 14px; }
.funnel-steps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.funnel-step {
  flex: 0 0 auto;
  min-width: 96px;
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  background: var(--panel-2);
  text-align: center;
}
.funnel-step-n { font-size: 1.4rem; font-weight: 600; color: var(--accent); line-height: 1.1; }
.funnel-step-l { font-size: 0.82rem; margin-top: 2px; }
.funnel-step-sub { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
.funnel-arrow { color: var(--muted); font-size: 1.1rem; flex: 0 0 auto; }
.funnel-conv { margin-top: 10px; font-size: 0.9rem; color: var(--muted); }
.funnel-conv b { color: var(--ink); font-size: 1rem; }
