/* Nythrix ADE — Global Theme
   Aligned with nythrixgroup.com branding */

:root {
  /* Nythrix brand colors */
  --nx-blue: #2563eb;
  --nx-blue-dark: #1d4ed8;
  --nx-blue-light: #3b82f6;
  --nx-blue-subtle: rgba(37, 99, 235, 0.12);
  --nx-blue-glow: rgba(37, 99, 235, 0.25);

  /* Backgrounds — slate palette */
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #334155;
  --panel3: #475569;
  --card: #1e293b;   /* alias of --panel — some pages (decoy-forge,
                        exposure-analysis, decoy-lab, executive-report)
                        reference --card; keep both in sync. */

  /* Text */
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;

  /* Borders */
  --border: #334155;
  --border-hover: #475569;

  /* Semantic */
  --green: #22c55e;
  --green-subtle: rgba(34, 197, 94, 0.15);
  --yellow: #eab308;
  --yellow-subtle: rgba(234, 179, 8, 0.15);
  --red: #ef4444;
  --red-subtle: rgba(239, 68, 68, 0.15);
  --orange: #f97316;
  --orange-subtle: rgba(249, 115, 22, 0.15);
  --accent: var(--nx-blue-light);

  /* Alert classifications */
  --cls-tripwire: #ef4444;
  --cls-tripwire-subtle: rgba(239, 68, 68, 0.15);
  --cls-decoy: #eab308;
  --cls-decoy-subtle: rgba(234, 179, 8, 0.15);
  --cls-dual: #f97316;
  --cls-dual-subtle: rgba(249, 115, 22, 0.15);
  --cls-ot: #a855f7;
  --cls-ot-subtle: rgba(168, 85, 247, 0.15);

  /* Sizing */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

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

body {
  font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--nx-blue-light); text-decoration: none; }
a:hover { color: var(--nx-blue); }
code { font-family: 'Geist Mono', 'SF Mono', Consolas, monospace; font-size: 11px; color: var(--nx-blue-light); }
pre code { color: inherit; }

/* Cards */
.card, .stat-card, .decoy-card, .deploy-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Buttons */
.btn, .refresh-btn {
  background: var(--nx-blue);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover, .refresh-btn:hover { background: var(--nx-blue-dark); }
.btn-green { background: var(--green); color: #000; }
.btn-green:hover { background: #16a34a; }
.btn-red { background: var(--red); color: white; }
.btn-red:hover { background: #dc2626; }

/* Risk badges */
.risk-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.risk-critical { background: var(--red-subtle); color: var(--red); }
.risk-high { background: var(--yellow-subtle); color: var(--yellow); }
.risk-medium { background: var(--nx-blue-subtle); color: var(--nx-blue-light); }
.risk-low { background: var(--green-subtle); color: var(--green); }

/* Severity text */
.sev-critical { color: var(--red); font-weight: 600; }
.sev-high { color: var(--yellow); }
.sev-medium { color: var(--nx-blue-light); }
.sev-low { color: var(--green); }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th { text-align: left; padding: 10px 12px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); background: var(--panel2); border-bottom: 1px solid var(--border); }
td { padding: 10px 12px; font-size: 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background 0.1s; }
tr.clickable:hover { background: var(--panel2); }

/* Header bar */
.header, .topbar {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Stat cards */
.stat-card {
  padding: 16px;
}
.stat-card .label, .stat-card .l {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.stat-card .value, .stat-card .v {
  font-size: 28px;
  font-weight: 700;
  margin: 4px 0;
}
.stat-card .sub {
  font-size: 12px;
  color: var(--muted);
}
a.stat-card {
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: block;
  text-decoration: none;
  color: inherit;
}
a.stat-card:hover { border-color: var(--nx-blue); transform: translateY(-2px); box-shadow: 0 4px 12px var(--nx-blue-glow); }
a.stat-card:hover .sub { color: var(--nx-blue-light); }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 16px 24px; }
@media (max-width: 900px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; } }

/* Section */
.section { padding: 0 24px 16px; }
.section h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 16px 0 8px;
}

/* Overlays */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  justify-content: center;
  align-items: start;
  padding: 40px 20px;
  overflow-y: auto;
}
.overlay.open { display: flex; }

.detail {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 100%;
  padding: 24px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.detail h2 { font-size: 18px; margin-bottom: 4px; }
.close {
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}
.close:hover { color: var(--text); }

/* Info grids */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; }
.info-card { background: var(--panel2); padding: 10px 12px; border-radius: var(--radius-sm); }
.info-card .lbl { font-size: 9px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
.info-card .val { font-size: 13px; font-weight: 600; margin-top: 2px; }

/* Logo blend mode — lighten for dark, normal for light */
.ade-brand-logo { mix-blend-mode: lighten; }

/* ── IP action menu popup (shared.js showIPMenu) ─────────────
   Solid, opaque background in both themes — content MUST NOT
   bleed through. !important so nothing (page-level CSS, inline
   --panel overrides, etc.) can accidentally make it translucent. */
.ade-ip-menu {
  position: fixed !important;
  z-index: 10000 !important;
  background: #1e293b !important;
  background-color: #1e293b !important;
  color: #f1f5f9 !important;
  border: 1px solid #334155 !important;
  border-radius: 8px !important;
  padding: 12px 14px !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6) !important;
  font-size: 12px !important;
  min-width: 240px !important;
  max-width: 320px !important;
  opacity: 1 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
html[data-theme="light"] .ade-ip-menu {
  background: #ffffff !important;
  background-color: #ffffff !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.25) !important;
}

/* ── Light Theme ─────────────────────────────────────────────── */
/* Override inline :root vars that pages define with hardcoded dark colors.
   The html[data-theme] selector has higher specificity than inline :root. */
html[data-theme="light"] {
  --bg: #f8fafc !important;
  --panel: #ffffff !important;
  --panel2: #f1f5f9 !important;
  --panel3: #e2e8f0 !important;
  --card: #ffffff !important;
  --text: #0f172a !important;
  --text-secondary: #334155 !important;
  --muted: #64748b !important;
  --border: #e2e8f0 !important;
  --border-hover: #cbd5e1 !important;
  --nx-blue-subtle: rgba(37, 99, 235, 0.08) !important;
  --nx-blue-glow: rgba(37, 99, 235, 0.15) !important;
  --green-subtle: rgba(34, 197, 94, 0.1) !important;
  --yellow-subtle: rgba(234, 179, 8, 0.1) !important;
  --red-subtle: rgba(239, 68, 68, 0.1) !important;
  --orange-subtle: rgba(249, 115, 22, 0.1) !important;
  --cls-tripwire-subtle: rgba(239, 68, 68, 0.1) !important;
  --cls-decoy-subtle: rgba(234, 179, 8, 0.1) !important;
  --cls-dual-subtle: rgba(249, 115, 22, 0.1) !important;
  --cls-ot-subtle: rgba(168, 85, 247, 0.1) !important;
}
html[data-theme="light"] body {
  background: #f8fafc !important;
  color: #0f172a !important;
}
[data-theme="light"] .header,
[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.85);
}
[data-theme="light"] .overlay {
  background: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .detail {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}
[data-theme="light"] table {
  background: var(--panel);
  border-color: var(--border);
}
[data-theme="light"] th {
  background: var(--panel2);
  color: var(--muted);
}
[data-theme="light"] td {
  border-color: var(--border);
}
[data-theme="light"] code {
  color: var(--nx-blue);
}
[data-theme="light"] .ade-sidebar {
  background: #f1f5f9 !important;
  border-right-color: #e2e8f0 !important;
}
[data-theme="light"] .ade-sidebar-brand {
  border-bottom-color: #e2e8f0 !important;
}
[data-theme="light"] .ade-sidebar-footer {
  border-top-color: #e2e8f0 !important;
}
[data-theme="light"] .ade-nav-item {
  color: #475569;
}
[data-theme="light"] .ade-nav-item:hover {
  background: rgba(0,0,0,0.04);
  color: #0f172a;
}
[data-theme="light"] .ade-nav-item.active {
  background: rgba(37,99,235,0.1);
  color: #2563eb;
}
[data-theme="light"] .ade-nav-section {
  color: #94a3b8;
}
[data-theme="light"] .ade-brand-text {
  color: #64748b;
}
[data-theme="light"] .ade-brand-logo {
  mix-blend-mode: normal !important;
}
[data-theme="light"] .ade-hamburger {
  background: #e2e8f0;
}
[data-theme="light"] .ade-hamburger span {
  background: #334155;
}
[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
  background: #ffffff !important;
  border-color: #e2e8f0 !important;
  color: #0f172a !important;
}
[data-theme="light"] .terminal {
  background: #1e293b !important;
  color: #22c55e !important;
}
[data-theme="light"] .kpi,
[data-theme="light"] .panel,
[data-theme="light"] .stat-card,
[data-theme="light"] .card,
[data-theme="light"] .admin-card,
[data-theme="light"] .hw-card,
[data-theme="light"] .detail,
[data-theme="light"] .settings-section,
[data-theme="light"] [style*="background:var(--panel)"],
[data-theme="light"] [style*="background: var(--panel)"] {
  border-color: #cbd5e1 !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important;
}
[data-theme="light"] .topbar,
[data-theme="light"] .header {
  border-bottom-color: #cbd5e1 !important;
}
/* Ensure all borders are visible in light mode */
[data-theme="light"] [style*="border:1px solid var(--border)"],
[data-theme="light"] [style*="border: 1px solid var(--border)"] {
  border-color: #cbd5e1 !important;
}
/* Tab styles */
[data-theme="light"] .tab,
[data-theme="light"] .tabs {
  border-color: #cbd5e1 !important;
}
[data-theme="light"] .tab.active {
  background: var(--accent) !important;
  color: #ffffff !important;
  border-color: var(--accent) !important;
}
/* Ensure text contrast */
[data-theme="light"] .val,
[data-theme="light"] .kpi .val {
  color: #0f172a !important;
}

/* ── Mobile Responsiveness ──────────────────────────────────── */

/* Topbar: leave room for hamburger menu on mobile */
@media (max-width: 768px) {
  .topbar, .header {
    padding-left: 50px;
  }
  .topbar h1, .header h1 {
    font-size: 14px;
  }
  /* KPI rows: 2 columns on tablet, 1 on phone */
  .kpi-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  /* Stat rows: wrap naturally */
  .stat-row {
    gap: 6px;
  }
  .stat-row .stat-card {
    min-width: 80px;
  }
  /* Info grids go single-column on mobile */
  .info-grid {
    grid-template-columns: 1fr;
  }
  /* Form grids go single-column */
  .form-grid {
    grid-template-columns: 1fr !important;
  }
  /* Filter bars wrap */
  .filters, .filter-bar {
    gap: 6px;
  }
  /* Overlays/detail panels need full width */
  .detail, .session-detail {
    max-width: 100%;
    padding: 14px;
    margin: 0 8px;
  }
}

@media (max-width: 480px) {
  .kpi-row {
    grid-template-columns: 1fr !important;
  }
  .topbar, .header {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* Badges */
.badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.bg { background: var(--green-subtle); color: var(--green); }
.by { background: var(--yellow-subtle); color: var(--yellow); }
.br { background: var(--red-subtle); color: var(--red); }
.bb { background: var(--nx-blue-subtle); color: var(--nx-blue-light); }
.bo { background: var(--orange-subtle); color: var(--orange); }
.bp { background: var(--panel2); color: var(--muted); }

/* ── Auth gate ──────────────────────────────────────────────────
   Hide page content until authentication is confirmed. The class
   `ade-pre-auth` is added by shared.js at the top of its load and
   removed after the auth check resolves.

   Scoping to a class (not a bare `body { visibility: hidden }` rule)
   means pages that DON'T include shared.js stay visible. Critical for
   admin pages that bootstrap their own auth — admin.html,
   admin-health.html, admin-system-health.html, admin-billing.html,
   activate.html, login.html, signup.html. */
body.ade-pre-auth {
  visibility: hidden;
}

/* ── Corporate admin alert banner ───────────────────────────────
   Rendered by shared.js when a platform admin has unacknowledged
   alerts in /admin/alerts/active. Stacks below the demo banner if
   present (shared.js manages --ade-admin-banner-offset).            */
.ade-admin-alert-banner {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--ade-admin-banner-offset, 0px);
  height: 36px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px 0 18px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: #fff;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transform: translateY(-100%);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
              opacity 180ms ease;
  opacity: 0;
}
.ade-admin-alert-banner.is-visible {
  transform: translateY(0);
  opacity: 1;
}

/* Severity variants */
.ade-admin-alert-banner.is-p1 {
  background: linear-gradient(90deg, #7f1d1d 0%, #b91c1c 50%, #dc2626 100%);
}
.ade-admin-alert-banner.is-p2 {
  background: linear-gradient(90deg, #78350f 0%, #b45309 50%, #d97706 100%);
}
.ade-admin-alert-banner.is-p3 {
  background: linear-gradient(90deg, #1e293b 0%, #334155 50%, #475569 100%);
}

.ade-admin-alert-banner:hover { filter: brightness(1.08); }
.ade-admin-alert-banner:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: -3px;
}

.ade-admin-alert-banner .ade-aab-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  flex: 0 0 auto;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
  animation: ade-aab-pulse 1.6s ease-out infinite;
}
.ade-admin-alert-banner.is-p3 .ade-aab-pulse { animation: none; opacity: 0.6; }
@keyframes ade-aab-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(255,255,255,0.7); }
  70%  { box-shadow: 0 0 0 10px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0   rgba(255,255,255,0); }
}

.ade-admin-alert-banner .ade-aab-message {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
.ade-admin-alert-banner .ade-aab-message strong {
  font-weight: 700;
}
.ade-admin-alert-banner .ade-aab-arrow {
  display: inline-block;
  margin-left: 6px;
  transition: transform 180ms ease;
}
.ade-admin-alert-banner:hover .ade-aab-arrow { transform: translateX(3px); }

.ade-admin-alert-banner .ade-aab-dismiss {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  color: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 120ms ease;
}
.ade-admin-alert-banner .ade-aab-dismiss:hover { background: rgba(255, 255, 255, 0.3); }
.ade-admin-alert-banner .ade-aab-dismiss:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

/* Push the rest of the page down so the banner never overlaps. */
body.ade-admin-banner-visible { padding-top: 36px; }
body.ade-admin-banner-visible.ade-has-sidebar .ade-sidebar { top: 36px; }
