/* ==========================================================================
   PageShield — shared design system
   Organized top to bottom as: tokens -> reset/base -> typography ->
   layout primitives -> components -> auth pages -> responsive overrides.
   Component class names are unchanged from the previous version —
   dashboard.js / admin.js generate markup using these same classes, so this
   file is a like-for-like visual replacement, not a markup rewrite.
   Theme switching is done via html[data-theme="light"|"dark"], set by
   js/theme.js. Default follows the OS preference; admin.css re-points the
   same variable names to a warm amber palette for the admin area. ==========================================================================
*/

/* ---------------------------------------------------------------------- */
/* 1. TOKENS                                                               */
/* ---------------------------------------------------------------------- */

:root,
:root[data-theme="light"] {
  /* neutral scale */
  --bg: #f6f7fb;
  --bg-alt: #eef0f7;
  --surface: #ffffff;
  --surface-2: #f3f4fa;
  --surface-3: #e9ebf3;
  --border: #e2e4ef;
  --border-strong: #cdd0e2;

  --text: #14151f;
  --text-muted: #5b5e72;
  --text-faint: #8b8ea3;

  /* brand */
  --primary: #6a5bef;
  --primary-hover: #5b4ce0;
  --primary-active: #4c3ecf;
  --primary-soft: rgba(106, 91, 239, 0.1);
  --primary-soft-text: #4c3ecf;
  --primary-glow: rgba(106, 91, 239, 0.25);
  --accent-2: #3d6df0;

  /* status */
  --danger: #d92a56;
  --danger-soft: rgba(217, 42, 86, 0.09);
  --danger-border: rgba(217, 42, 86, 0.28);
  --danger-text: #b81f46;
  --success: #0f9d70;
  --success-soft: rgba(15, 157, 112, 0.1);
  --warning: #b56a05;
  --warning-soft: rgba(181, 106, 5, 0.1);
  --warning-border: rgba(181, 106, 5, 0.3);
  --primary-border-soft: rgba(106, 91, 239, 0.3);

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(20, 21, 40, 0.05);
  --shadow-md: 0 14px 34px -16px rgba(20, 21, 40, 0.18);
  --shadow-glow: 0 0 0 1px rgba(106, 91, 239, 0.06), 0 10px 26px -12px rgba(106, 91, 239, 0.2);

  color-scheme: light;
}

:root[data-theme="dark"] {
  /* neutral scale */
  --bg: #07080c;
  --bg-alt: #0a0b11;
  --surface: #121319;
  --surface-2: #191b23;
  --surface-3: #21232e;
  --border: #24262f;
  --border-strong: #34374a;

  --text: #f3f4f8;
  --text-muted: #9497a8;
  --text-faint: #656a7c;

  /* brand */
  --primary: #7c6ef4;
  --primary-hover: #8f83f6;
  --primary-active: #6a5ce6;
  --primary-soft: rgba(124, 110, 244, 0.16);
  --primary-soft-text: #c3baff;
  --primary-glow: rgba(124, 110, 244, 0.35);
  --accent-2: #5b8cff;

  /* status */
  --danger: #fb4570;
  --danger-soft: rgba(251, 69, 112, 0.14);
  --danger-border: rgba(251, 69, 112, 0.3);
  --danger-text: #ff8aa8;
  --success: #2dd4a7;
  --success-soft: rgba(45, 212, 167, 0.14);
  --warning: #f5a623;
  --warning-soft: rgba(245, 166, 35, 0.14);
  --warning-border: rgba(245, 166, 35, 0.3);
  --primary-border-soft: rgba(124, 110, 244, 0.3);

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 16px 40px -16px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 0 1px rgba(255, 255, 255, 0.03) inset, 0 12px 32px -14px var(--primary-glow);

  color-scheme: dark;
}

:root {
  /* shape */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  /* spacing scale (4px increments) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;
  --space-10: 64px;

  /* type */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-heading: 'Space Grotesk', var(--font);
  --mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  /* motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 170ms var(--ease);

  /* layout */
  --sidebar-width: 252px;
  --sidebar-width-rail: 76px;
  --topbar-height: 56px;
  --content-max-width: 1160px;
}

/* ---------------------------------------------------------------------- */
/* 2. RESET / BASE                                                         */
/* ---------------------------------------------------------------------- */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.55;
  transition: background var(--transition), color var(--transition);
}

::selection { background: var(--primary-glow); color: var(--text); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }

/* ---------------------------------------------------------------------- */
/* 3. TYPOGRAPHY                                                           */
/* ---------------------------------------------------------------------- */

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

p { line-height: 1.6; }

a { color: var(--primary-soft-text); }

code {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.85em;
  color: var(--primary-soft-text);
}

/* ---------------------------------------------------------------------- */
/* 4. LAYOUT PRIMITIVES                                                    */
/* ---------------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

:root[data-theme="light"] .app { background: var(--bg); }
:root[data-theme="dark"] .app {
  background:
    radial-gradient(1200px circle at 100% 0%, rgba(255, 255, 255, 0.03), transparent 55%),
    radial-gradient(900px circle at 0% 100%, rgba(255, 255, 255, 0.02), transparent 55%),
    var(--bg);
}

.sidebar {
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: var(--space-6) var(--space-4);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  transition: background var(--transition), border-color var(--transition);
}

.sidebar .brand { padding: 0 var(--space-2); margin-bottom: var(--space-8); }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  color: var(--text-muted);
  text-decoration: none;
  padding: 9px 12px 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.sidebar nav a .nav-link-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar nav a .nav-link-main > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar nav a svg {
  width: 17px;
  height: 17px;
  flex: none;
  color: var(--text-faint);
  transition: color var(--transition);
}

.sidebar nav a.active {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: 600;
  border-left-color: var(--primary);
}

.sidebar nav a.active svg { color: var(--primary-soft-text); }

.sidebar nav a:hover:not(.active) { background: var(--surface-2); color: var(--text); }
.sidebar nav a:hover:not(.active) svg { color: var(--text-muted); }

.badge {
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
  flex: none;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.sidebar-footer .user-email {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 8px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer .sidebar-footer-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sidebar-footer .sidebar-footer-row button.secondary { flex: 1; }

/* generic small square icon button, used for the theme toggle and the
   mobile hamburger */
.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

.main {
  padding: var(--space-8) var(--space-9) var(--space-10);
  max-width: var(--content-max-width);
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.page-header h1 { font-size: 25px; margin: 0 0 4px; }
.page-header .page-subtitle { color: var(--text-muted); font-size: 13.5px; margin: 0; }
.page-header .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* mobile top bar: hidden by default, shown under the tablet breakpoint */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-4);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.mobile-topbar .brand-name { font-size: 15px; }
.mobile-topbar .brand-mark { width: 26px; height: 26px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 35;
}
.sidebar-backdrop.visible { display: block; }

/* ---------------------------------------------------------------------- */
/* 5. COMPONENTS                                                           */
/* ---------------------------------------------------------------------- */

/* -- brand / logo -- */
.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent-2));
  border-radius: 10px;
  color: white;
  box-shadow: 0 4px 14px -4px var(--primary-glow);
}

.brand-name {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* -- form fields -- */
label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 16px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="datetime-local"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

input[type="checkbox"] { width: auto; }

/* Inline unit label inside a text/number field, e.g. the "%" on a
   percentage input — keeps the same field height/padding as every other
   input instead of a separate label element next to it. */
.input-suffix-group { position: relative; }
.input-suffix-group input { padding-right: 32px; }
.input-suffix-group .input-suffix {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 13px;
  pointer-events: none;
  display: flex;
  align-items: center;
}
/* Lock icon on a plan-locked field (e.g. Activate redirect starting at) —
   same muted, thin-stroke lucide icon language as the sidebar nav, not a
   colorful emoji glyph, to stay consistent with the rest of the platform. */
.input-suffix-group .input-suffix svg {
  width: 13px;
  height: 13px;
  color: var(--text-faint);
}

input:disabled, select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  /* Was var(--surface-1, var(--surface-2)) — --surface-1 was never defined
     anywhere, so that fallback silently resolved to var(--surface-2), the
     exact same background as an *enabled* field. That left opacity as the
     only disabled signal, which is barely visible on a field like the
     scheduled-activation datetime input: an empty <input type="datetime-
     local"> already renders its unfilled mm/dd/yyyy segments in a pale
     native gray, so dimming already-pale text reads as no different from
     enabled-and-empty. --surface-3 (one step darker than the normal
     --surface-2 field background) gives every disabled field real
     background contrast regardless of what's inside it. */
  background: var(--surface-3);
}

.upgrade-hint {
  color: var(--text-faint);
  font-size: 11.5px;
  margin-top: 5px;
}
.upgrade-hint a { font-weight: 600; }

/* -- buttons -- */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font);
  transition: background var(--transition), border-color var(--transition), color var(--transition),
    opacity var(--transition), transform var(--transition), box-shadow var(--transition);
}

button.primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 10px -2px var(--primary-glow);
}
button.primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 6px 18px -4px var(--primary-glow); }
button.primary:active { background: var(--primary-active); transform: translateY(0); }

button.block { width: 100%; margin-top: 22px; }

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--surface-3); border-color: var(--border-strong); transform: translateY(-1px); }
button.secondary:active { transform: translateY(0); }

button.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  padding: 8px 10px;
}
button.ghost:hover { background: var(--surface-2); color: var(--text); }

button.danger {
  background: var(--danger-soft);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}
button.danger:hover { background: var(--danger-border); transform: translateY(-1px); }

button.primary, button.secondary, button.danger, button.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
button.primary svg, button.secondary svg, button.danger svg, button.ghost svg { width: 15px; height: 15px; flex: none; }

button.sm { padding: 6px 11px; font-size: 12.5px; }

button:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.error {
  color: var(--danger-text);
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 12px;
}

.link-row {
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.link-row a { color: var(--primary-soft-text); text-decoration: none; font-weight: 600; }
.link-row a:hover { text-decoration: underline; }

/* -- modal (generic — first user is the "Create profile" dialog, but
   reusable for any future centered-dialog need) --
   Same rgba(0,0,0,0.5) backdrop convention as .sidebar-backdrop, but a
   higher z-index (100 vs. the sidebar's 40) since a modal must sit above
   everything, including the sidebar itself. */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.modal-overlay.visible { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-6);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.modal-header h3 { margin: 0; font-size: 16px; }

/* -- cards -- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.card h3 {
  font-size: 14.5px;
  margin: 0 0 var(--space-4);
  font-family: var(--font-heading);
  letter-spacing: -0.01em;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}

/* -- stat tiles -- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.stat-tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.stat-tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary-glow), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}

.stat-tile:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}
.stat-tile:hover::before { opacity: 1; }

.stat-tile .stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-tile .stat-label svg { width: 14px; height: 14px; color: var(--text-faint); }

.stat-tile .stat-value {
  font-family: var(--font-heading);
  font-size: 30px;
  font-weight: 650;
  margin-top: 8px;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-tile .stat-trend {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
  margin-top: 12px;
}
.stat-tile .stat-trend .bar {
  flex: 1;
  background: var(--primary-soft);
  border-radius: 3px 3px 1px 1px;
  min-height: 3px;
  transition: background var(--transition);
}
.stat-tile .stat-trend .bar.bar-active { background: var(--primary); }

.stat-tile .stat-foot {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-faint);
}

/* -- detection rows / lists -- */
.detection-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  gap: 16px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.detection-row:hover { background: var(--surface-2); }
.detection-row:last-child { border-bottom: none; }
.detection-row .host { font-weight: 650; }
.detection-row .meta { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; line-height: 1.5; }
.detection-row .right { text-align: right; flex: none; }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-muted);
  display: inline-block;
}

/* Which channel caught a detection — "via script" is the default/plain
   look (reuses .tag); "via pixel" gets the brand-purple treatment since
   it's the Pro/Business-only fallback layer, so it reads as "this paid
   feature is actively catching something the primary beacon might have
   missed" rather than blending into the rest of the row. */
.tag.method-pixel { background: var(--primary-soft); color: var(--primary-soft-text); border-color: transparent; }
.tag.redirected-yes { background: var(--success-soft); color: var(--success); border-color: transparent; }
.tag.redirect-pending { background: var(--warning-soft); color: var(--warning); border-color: transparent; }

/* Classification Result badge (server/utils/classify.js — a heuristic,
   never a certain determination). 'bot' gets the same warning treatment
   as a redirect-pending state (worth a second look, not necessarily
   bad — could be a legitimate crawler); 'human' gets the success/green
   treatment; 'unknown' is left as the plain, uncolored .tag base. */
.tag.classification-bot { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.tag.classification-human { background: var(--success-soft); color: var(--success); border-color: transparent; }
.pill.unread { background: var(--danger-soft); color: var(--danger-text); }
.pill.read { background: var(--success-soft); color: var(--success); }

/* Installation heartbeat status — a small dot + pill, distinct from the
   read/unread pill above so it can't be confused with detection status. */
.heartbeat-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px 3px 8px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.heartbeat-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.heartbeat-pill.live { background: var(--success-soft); color: var(--success); }
.heartbeat-pill.stale { background: var(--warning-soft); color: var(--warning); }
.heartbeat-pill.lost { background: var(--danger-soft); color: var(--danger-text); }

/* Toggle switch — checkbox-driven, no JS needed for the visual state
   itself. The thumb stays a fixed light color in both themes (it sits on a
   colored track either way, so it doesn't need to theme). Sized up from a
   default browser-scale control (46x26 track, 22px thumb) so it reads as
   a deliberate, tactile control rather than a form checkbox; the ON state
   reuses --primary + --primary-glow, the same combo button.primary uses
   (see "Create profile"), so it visually reads as the same brand action
   rather than a generic gray/blue switch. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  transition: transform var(--transition);
}
.switch:hover { transform: scale(1.04); }
.switch:has(input:disabled) { cursor: not-allowed; }
.switch:has(input:disabled):hover { transform: none; }

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  flex: none;
  width: 46px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  position: relative;
  transition: background var(--transition), box-shadow var(--transition);
}
.switch:hover input:not(:disabled) + .switch-track {
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform var(--transition), box-shadow var(--transition);
}
.switch-thumb svg {
  width: 12px;
  height: 12px;
  color: var(--text-faint);
  transition: color var(--transition);
}

.switch input:checked + .switch-track {
  background: var(--primary);
  box-shadow: 0 2px 10px -2px var(--primary-glow);
}
.switch:hover input:checked:not(:disabled) + .switch-track {
  box-shadow: 0 2px 10px -2px var(--primary-glow), 0 0 0 4px var(--primary-soft);
}
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); }
.switch input:checked + .switch-track .switch-thumb svg { color: var(--primary); }

.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--primary-soft); }
.switch input:disabled + .switch-track { opacity: 0.5; cursor: not-allowed; }
.switch input:disabled ~ .switch-label { opacity: 0.6; cursor: not-allowed; }
.switch-label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.switch-label .switch-label-sub { display: block; font-size: 11.5px; font-weight: 500; color: var(--text-muted); margin-top: 1px; }

/* -- tables --
   Row dividers use exactly one mechanism everywhere: border-bottom on
   every <th>/<td>, with border-collapse merging each row's per-cell
   borders into a single line. Every cell in a table MUST stay a plain
   table-cell box (default `display`) for that line to land on the same
   edge across the whole row — never set `display: flex/grid/block` (or
   anything else) directly on a <td>/<th>, since that pulls just that one
   cell out of the row's shared box model and is what caused the
   misaligned/broken dividers previously. Cells that need flex content
   (e.g. a row of icon buttons) get an inner wrapper div instead — see
   .cell-actions-inner below. */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }

/* numeric columns (counts, amounts) read better right-aligned */
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Long free-text columns (referrer URLs, user-agent strings) that would
   otherwise force the whole table wider than its container under the
   nowrap rule above — clipped with an ellipsis, full value on hover via
   the cell's title attribute. Needs its own overflow:hidden since the
   nowrap alone doesn't clip; text-overflow only kicks in with that. */
td.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; cursor: default; }

/* compact icon-only row actions, replacing a row of text buttons. The
   <td> itself stays a plain table-cell (only text-align changes); the
   flex row lives on this inner div instead, so it never affects the
   table's row-height/border-collapse calculations. */
td.cell-actions { text-align: right; }
.cell-actions-inner { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }

th[data-sort-key] { cursor: pointer; user-select: none; }
th[data-sort-key]:hover { color: var(--text); }
th[data-sort-key]::after {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  margin-left: 5px;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  opacity: 0.35;
  vertical-align: middle;
}
th[data-sort-key].sort-asc::after { border-bottom: 4px solid currentColor; opacity: 1; }
th[data-sort-key].sort-desc::after { border-top: 4px solid currentColor; opacity: 1; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.pagination .pagination-controls { display: flex; align-items: center; gap: 8px; }

/* -- loading / skeleton / empty states -- */
.loading-state {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-faint);
  font-size: 13px;
  padding: 24px 10px;
}

.spinner {
  width: 15px;
  height: 15px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 45%, var(--surface-2) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 150% 0; }
  100% { background-position: -50% 0; }
}
.skeleton-row { height: 44px; margin-bottom: 8px; }
.skeleton-stat { height: 92px; border-radius: var(--radius-lg); }

.empty-state {
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 40px 20px;
  text-align: center;
}
.empty-state .icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-size: 20px;
}
.empty-state .icon svg { width: 22px; height: 22px; }
.empty-state .empty-title { color: var(--text); font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.empty-state .empty-sub { color: var(--text-faint); font-size: 12.5px; max-width: 340px; margin: 0 auto; }

/* -- profile cards -- */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-4);
  transition: border-color var(--transition);
}
.profile-card:hover { border-color: var(--border-strong); }

.profile-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.profile-name { font-family: var(--font-heading); font-size: 16px; font-weight: 600; margin: 0 0 6px; }

.profile-flow { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); flex-wrap: wrap; }
.profile-flow .domain {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.profile-flow .arrow { color: var(--text-faint); }

.profile-meta { margin-top: 10px; display: flex; gap: 18px; font-size: 12.5px; color: var(--text-muted); flex-wrap: wrap; }
.profile-actions { display: flex; gap: 8px; flex: none; flex-wrap: wrap; }

.profile-snippet, .profile-edit-form {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* -- Traffic breakdown (profile-detail Analytics card) -- */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-6) var(--space-7);
}
.analytics-section h4 { font-size: 13px; margin: 0 0 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; font-weight: 650; }
.breakdown-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.breakdown-row .breakdown-label { flex: 0 0 110px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breakdown-row .breakdown-bar-track { flex: 1; height: 8px; border-radius: var(--radius-full); background: var(--surface-2); overflow: hidden; }
.breakdown-row .breakdown-bar-fill { height: 100%; border-radius: var(--radius-full); background: var(--primary); }
.breakdown-row .breakdown-bar-fill.classification-bot { background: var(--warning); }
.breakdown-row .breakdown-bar-fill.classification-human { background: var(--success); }
.breakdown-row .breakdown-count { flex: 0 0 32px; text-align: right; color: var(--text-muted); font-weight: 600; }

/* -- forms / misc -- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  align-items: end;
}
.form-grid .field label { margin-top: 0; }

/* Spans every column in the row — for a caption/note that belongs to the
   row above it but shouldn't be squeezed into one narrow column (and
   shouldn't stretch that column's height to match via align-items: end,
   which is what happens if a much-taller field sits inline with short
   ones — see the pixel-fallback toggle + its explanatory text). */
.field-full { grid-column: 1 / -1; }

.domain-form { display: flex; gap: 10px; margin-bottom: 4px; }
.domain-form input { flex: 1; }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

textarea.code {
  width: 100%;
  min-height: 170px;
  background: var(--bg);
  color: var(--success);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  resize: vertical;
}

.muted { color: var(--text-muted); }

canvas#chart, canvas#detectionsChart, canvas#signupsChart, canvas#revenueChart { width: 100%; height: 220px; }

.select-inline { padding: 7px 10px; font-size: 13px; width: auto; }

/* -- banners -- */
.impersonation-banner {
  background: var(--warning-soft);
  color: var(--warning);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border-bottom: 1px solid var(--warning-border);
}
.impersonation-banner button {
  background: var(--warning);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.announcement-banner {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border-bottom: 1px solid var(--primary-border-soft);
}
.announcement-banner button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

/* Trial countdown (informational, brand-colored) vs trial-expired
   (warning-colored) — same layout, different palette via a modifier class
   set in JS depending on /dashboard/plan-status. */
.trial-banner {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.trial-banner.trialing {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  border-bottom: 1px solid var(--primary-border-soft);
}
.trial-banner.expired {
  background: var(--warning-soft);
  color: var(--warning);
  border-bottom: 1px solid var(--warning-border);
}
/* Unverified account: same amber "action needed" palette as .expired,
   own modifier rather than reusing that class so its status text isn't
   coupled to the trial-expiry copy. */
.trial-banner.unverified {
  background: var(--warning-soft);
  color: var(--warning);
  border-bottom: 1px solid var(--warning-border);
}
.trial-banner a.sm, .trial-banner button.sm {
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}
.trial-banner.trialing a.sm { background: var(--primary); color: white; }
.trial-banner.expired a.sm { background: var(--warning); color: var(--bg); }
.trial-banner.unverified button.sm { background: var(--warning); color: var(--bg); }
.trial-banner.unverified button.sm:disabled { opacity: 0.6; cursor: default; }

/* Protection-lost alert — a previously-working install has gone silent.
   Deliberately red/danger (not the amber .trial-banner.expired uses):
   this is a more urgent signal than a billing nudge — something that was
   actively protecting a page may no longer be there at all. */
.protection-lost-banner {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--danger-soft);
  color: var(--danger-text);
  border-bottom: 1px solid var(--danger-border);
}
.protection-lost-banner button.sm {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

/* ---------------------------------------------------------------------- */
/* 6. AUTH PAGES                                                           */
/* ---------------------------------------------------------------------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  padding: var(--space-6);
}

:root[data-theme="light"] .auth-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(560px circle at 12% 8%, rgba(106, 91, 239, 0.1), transparent 60%),
    radial-gradient(620px circle at 88% 92%, rgba(61, 109, 240, 0.08), transparent 60%);
  pointer-events: none;
}
:root[data-theme="dark"] .auth-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(560px circle at 12% 8%, rgba(124, 110, 244, 0.16), transparent 60%),
    radial-gradient(620px circle at 88% 92%, rgba(91, 140, 255, 0.13), transparent 60%);
  pointer-events: none;
}

.auth-card {
  position: relative;
  width: 380px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 34px;
}

.auth-card.wide { width: 560px; }

.auth-card .brand { margin-bottom: 26px; }
.auth-card h1 { font-size: 21px; margin: 0 0 4px; }
.auth-card p.subtitle { color: var(--text-muted); margin: 0 0 22px; font-size: 13.5px; }

.auth-theme-toggle {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 10;
}

/* -- trial plan picker (registration) -- */
.plan-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-top: 8px;
}

.plan-option { position: relative; }

.plan-option input[type="radio"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.plan-option .plan-option-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.plan-option:hover .plan-option-card { border-color: var(--border-strong); }
.plan-option input:checked + .plan-option-card {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.plan-option input:focus-visible + .plan-option-card { box-shadow: 0 0 0 3px var(--primary-soft); }

.plan-option-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary-soft-text);
  background: var(--primary-soft);
  border-radius: var(--radius-full);
  padding: 1px 7px;
  margin-bottom: 5px;
}

.plan-option-name { font-family: var(--font-heading); font-weight: 650; font-size: 13.5px; color: var(--text); }
.plan-option-price { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.plan-picker-note { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; }

/* ---------------------------------------------------------------------- */
/* 7. RESPONSIVE OVERRIDES                                                 */
/* ---------------------------------------------------------------------- */

/* Tablet: sidebar collapses to an icon-only rail. Labels are hidden (title
   attributes on the links provide a native tooltip) but everything stays
   in the normal document flow — nothing overlays the content. */
@media (max-width: 1023px) {
  .app { grid-template-columns: var(--sidebar-width-rail) 1fr; }

  .sidebar { padding: var(--space-6) var(--space-2); align-items: center; }
  .sidebar .brand { padding: 0; margin-bottom: var(--space-7); justify-content: center; }
  .sidebar .brand-name { display: none; }

  .sidebar nav { width: 100%; align-items: center; }
  .sidebar nav a { justify-content: center; padding: 10px; width: 44px; }
  .sidebar nav a .nav-link-main > span:last-child { display: none; }
  .sidebar nav a .badge { position: absolute; margin-left: 22px; margin-top: -18px; }

  .sidebar-footer { width: 100%; display: flex; flex-direction: column; align-items: center; }
  .sidebar-footer .user-email { display: none; }
  .sidebar-footer .sidebar-footer-row { flex-direction: column; }
  .sidebar-footer .sidebar-footer-row button.secondary span:last-child { display: none; }

  .main { padding: var(--space-6); }
}

/* Mobile: sidebar becomes a full off-canvas drawer triggered by the
   hamburger button in the mobile top bar. */
@media (max-width: 767px) {
  .app { grid-template-columns: 1fr; }

  .mobile-topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
    align-items: stretch;
    padding: var(--space-6) var(--space-4);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .brand { display: none; }
  .sidebar .brand-name { display: block; }
  .sidebar nav { align-items: stretch; }
  .sidebar nav a { justify-content: space-between; width: auto; padding: 9px 12px 9px 14px; }
  .sidebar nav a .nav-link-main > span:last-child { display: inline; }
  .sidebar nav a .badge { position: static; margin: 0; }

  .sidebar-footer { align-items: stretch; }
  .sidebar-footer .user-email { display: block; }
  .sidebar-footer .sidebar-footer-row { flex-direction: row; }
  .sidebar-footer .sidebar-footer-row button.secondary span:last-child { display: inline; }

  .main { padding: var(--space-5); }
  .page-header h1 { font-size: 21px; }
  .stats-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .auth-card { padding: 28px 22px; }
}

/* Responsive data tables: below this width, wrap a table's scroll
   container in .responsive-table (in addition to .table-scroll) to render
   each row as a stacked card instead of requiring horizontal scroll.
   Selectors use child combinators throughout so a nested table — e.g. the
   login-history table inside a user's expanded detail row — is never
   affected; only the immediate outer table converts. */
@media (max-width: 860px) {
  .responsive-table > table,
  .responsive-table > table > thead,
  .responsive-table > table > tbody,
  .responsive-table > table > tbody > tr,
  .responsive-table > table > tbody > tr > td {
    display: block;
    width: 100%;
  }
  .responsive-table > table > thead { display: none; }

  .responsive-table > table > tbody > tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
  }
  /* a detail row (expanded via "View") sits flush under its card rather
     than looking like a second card */
  .responsive-table > table > tbody > tr[id^="detail-row-"] {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    margin-top: calc(-1 * var(--space-2));
  }

  .responsive-table > table > tbody > tr > td {
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
    white-space: normal;
    text-align: left;
  }
  .responsive-table > table > tbody > tr > td:last-child { border-bottom: none; padding-bottom: 0; }

  .responsive-table > table > tbody > tr > td[data-label] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }
  .responsive-table > table > tbody > tr > td[data-label]::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-faint);
    flex: none;
  }

  .responsive-table > table > tbody > tr > td.cell-actions {
    padding-top: 10px;
  }

  /* pagination controls sit as a sibling of .responsive-table, not a
     descendant — stack them the same way any time a responsive table is
     on the page (the only place .pagination is currently used) */
  .pagination { flex-direction: column; align-items: stretch; text-align: center; gap: 8px; }
}
