/* ============================================================
   NEXUS UI — Futuristic Dark Theme
   Full Rewrite: Clean Syntax, Mobile-First, Unified Design
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700;800;900&family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ============================================================
   CSS RESET
   ============================================================ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  /* --- Base Backgrounds --- */
  --bg-void:       #04040a;
  --bg-primary:    #07070f;
  --bg-secondary:  #0d0d1a;
  --bg-tertiary:   #111120;
  --bg-card:       #0e0e1c;
  --bg-card-hover: #141428;
  --bg-elevated:   #181830;
  --bg-active:     #1e1e38;

  /* --- Neon Palette --- */
  --cyan:    #00f5ff;
  --blue:    #0088ff;
  --purple:  #a020f0;
  --magenta: #ff00cc;
  --green:   #00ff88;
  --orange:  #ff6a00;
  --red:     #ff2255;
  --yellow:  #ffd500;

  /* --- Semantic Colors --- */
  --success:         #00ff88;
  --success-dim:     rgba(0, 255, 136, 0.12);
  --success-border:  rgba(0, 255, 136, 0.35);

  --warning:         #ffd500;
  --warning-dim:     rgba(255, 213, 0, 0.12);
  --warning-border:  rgba(255, 213, 0, 0.35);

  --danger:          #ff2255;
  --danger-dim:      rgba(255, 34, 85, 0.12);
  --danger-border:   rgba(255, 34, 85, 0.35);

  --info:            #0088ff;
  --info-dim:        rgba(0, 136, 255, 0.12);
  --info-border:     rgba(0, 136, 255, 0.35);

  /* --- Text --- */
  --text-primary:   #f0f0ff;
  --text-secondary: #9090b8;
  --text-muted:     #5a5a80;
  --text-disabled:  #3a3a55;

  /* --- Borders --- */
  --border:         rgba(255, 255, 255, 0.07);
  --border-subtle:  rgba(255, 255, 255, 0.04);
  --border-hover:   rgba(0, 245, 255, 0.25);
  --border-focus:   rgba(0, 245, 255, 0.55);

  /* --- Glow Effects --- */
  --glow-cyan:    0 0 16px rgba(0, 245, 255, 0.45), 0 0 40px rgba(0, 245, 255, 0.18);
  --glow-blue:    0 0 16px rgba(0, 136, 255, 0.45), 0 0 40px rgba(0, 136, 255, 0.18);
  --glow-purple:  0 0 16px rgba(160, 32, 240, 0.45), 0 0 40px rgba(160, 32, 240, 0.18);
  --glow-green:   0 0 16px rgba(0, 255, 136, 0.45), 0 0 40px rgba(0, 255, 136, 0.18);
  --glow-red:     0 0 16px rgba(255, 34, 85, 0.45), 0 0 40px rgba(255, 34, 85, 0.18);
  --glow-yellow:  0 0 16px rgba(255, 213, 0, 0.45), 0 0 40px rgba(255, 213, 0, 0.18);

  /* --- Shadows --- */
  --shadow-xs: 0 1px 4px  rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.55);
  --shadow:    0 4px 20px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.65);
  --shadow-xl: 0 16px 60px rgba(0, 0, 0, 0.75);

  /* --- Border Radius --- */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius:    10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;

  /* --- Transitions --- */
  --ease-fast:  150ms cubic-bezier(0.4, 0, 0.2, 1);
  --ease:       250ms cubic-bezier(0.4, 0, 0.2, 1);
  --ease-slow:  400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* --- Spacing Scale --- */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-5:  1.25rem;
  --sp-6:  1.5rem;
  --sp-8:  2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;

  /* --- Typography --- */
  --font-display: 'Orbitron', monospace;
  --font-body:    'Space Grotesk', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* --- Layout --- */
  --navbar-h: 64px;
  --content-max: 1600px;
}

/* ============================================================
   BASE
   ============================================================ */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Grid-line background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(90deg, rgba(0, 245, 255, 0.025) 1px, transparent 1px),
    linear-gradient(rgba(0, 245, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

/* Ambient glow orbs */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(0, 136, 255, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 50% 35% at 80% 85%, rgba(160, 32, 240, 0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Ensure content sits above pseudo-elements */
#login-screen,
#main-app {
  position: relative;
  z-index: 1;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-active);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 245, 255, 0.3);
}

/* ============================================================
   SCREEN MANAGEMENT
   ============================================================ */
.screen {
  display: none !important;
  visibility: hidden;
  opacity: 0;
}

.screen.active {
  display: flex !important;
  visibility: visible;
  opacity: 1;
}

#login-screen.screen:not(.active),
#main-app.screen:not(.active) {
  display: none !important;
  position: absolute;
  pointer-events: none;
}

#main-app.screen.active {
  display: flex !important;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
#login-screen.screen.active {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  padding: var(--sp-6);
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(0, 136, 255, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(160, 32, 240, 0.12) 0%, transparent 60%),
    var(--bg-void);
}

.login-container {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-12) var(--sp-10);
  box-shadow: var(--shadow-xl), 0 0 80px rgba(0, 136, 255, 0.08);
  position: relative;
  overflow: hidden;
}

/* Top accent bar */
.login-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--blue), var(--purple), transparent);
  animation: shimmer 3s ease infinite;
}

/* Corner accent */
.login-container::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle at bottom right, rgba(160, 32, 240, 0.15), transparent 70%);
}

.login-container h1 {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 1.75rem);
  font-weight: 700;
  text-align: center;
  margin-bottom: var(--sp-2);
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--cyan) 0%, var(--blue) 50%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: var(--sp-8);
  letter-spacing: 0.03em;
}

#login-form {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navbar-h);
  background: rgba(7, 7, 15, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-6);
  gap: var(--sp-4);
  z-index: 1000;
}

.navbar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 245, 255, 0.2), transparent);
}

.nav-brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--cyan);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
  white-space: nowrap;
  text-shadow: var(--glow-cyan);
}

.nav-brand::before {
  content: '◆';
  color: var(--blue);
  font-size: 0.75rem;
  animation: pulse-glow 2.5s ease infinite;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.nav-links::-webkit-scrollbar { display: none; }

.nav-link {
  padding: var(--sp-2) var(--sp-4);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: all var(--ease-fast);
  white-space: nowrap;
  letter-spacing: 0.03em;
  position: relative;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(0, 245, 255, 0.06);
  border-color: var(--border-hover);
}

.nav-link.active {
  color: var(--cyan);
  background: rgba(0, 245, 255, 0.1);
  border-color: rgba(0, 245, 255, 0.3);
  box-shadow: 0 0 12px rgba(0, 245, 255, 0.15);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 20%;
  width: 60%;
  height: 2px;
  background: var(--cyan);
  border-radius: var(--radius-full);
  box-shadow: var(--glow-cyan);
}

/* Mobile hamburger toggle */
.nav-toggle {
  display: none;
  width: 2.5rem;
  height: 2.5rem;
  padding: var(--sp-2);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all var(--ease-fast);
  flex-shrink: 0;
}
.nav-toggle:hover {
  border-color: var(--border-hover);
  color: var(--cyan);
}
.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: all var(--ease-fast);
}

#logout-btn {
  margin-left: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--ease-fast);
  white-space: nowrap;
  flex-shrink: 0;
}
#logout-btn:hover {
  background: var(--danger-dim);
  border-color: var(--danger-border);
  color: var(--danger);
}

/* ============================================================
   MAIN APP
   ============================================================ */
#main-app {
  min-height: 100vh;
  padding-top: var(--navbar-h);
}

.main-content {
  padding: var(--sp-8);
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ============================================================
   PAGES
   ============================================================ */
.page {
  display: none;
}

.page.active {
  display: block;
  animation: fade-up 0.3s var(--ease-slow) both;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
  padding-bottom: var(--sp-6);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.page-header h1::before {
  content: '/';
  color: var(--cyan);
  font-family: var(--font-mono);
  opacity: 0.8;
}

.page-header-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-wrap: wrap;
}

/* ============================================================
   STATS GRID
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-5);
  margin-bottom: var(--sp-8);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-6);
  position: relative;
  overflow: hidden;
  transition: all var(--ease);
}

/* Left accent stripe */
.stat-card::before {
  content: '';
  position: absolute;
  inset-block: 0;
  left: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--cyan), var(--blue));
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

/* Ambient corner glow */
.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle at top right, rgba(0, 245, 255, 0.06), transparent 70%);
}

.stat-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow), 0 0 30px rgba(0, 245, 255, 0.07);
}

.stat-card h3 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
  font-family: var(--font-mono);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 700;
  color: var(--cyan);
  line-height: 1;
}

/* Stat variants */
.stat-card.success::before { background: linear-gradient(180deg, var(--green), #00cc6a); }
.stat-card.success .stat-value { color: var(--green); }

.stat-card.warning::before { background: linear-gradient(180deg, var(--yellow), #ccaa00); }
.stat-card.warning .stat-value { color: var(--yellow); }

.stat-card.danger::before { background: linear-gradient(180deg, var(--red), #cc1a44); }
.stat-card.danger .stat-value { color: var(--red); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--ease-fast);
  white-space: nowrap;
  text-decoration: none;
  position: relative;
  overflow: hidden;
  min-height: 36px;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--ease-fast);
}

.btn:hover::before { opacity: 1; }

.btn:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-elevated);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  pointer-events: none;
}

/* Primary */
.btn-primary {
  background: linear-gradient(135deg, rgba(0, 245, 255, 0.14), rgba(0, 136, 255, 0.14));
  color: var(--cyan);
  border-color: rgba(0, 245, 255, 0.4);
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.08);
}
.btn-primary:hover {
  background: linear-gradient(135deg, rgba(0, 245, 255, 0.22), rgba(0, 136, 255, 0.22));
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
  color: var(--cyan);
}

/* Secondary */
.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Danger */
.btn-danger {
  background: var(--danger-dim);
  color: var(--red);
  border-color: var(--danger-border);
}
.btn-danger:hover {
  background: rgba(255, 34, 85, 0.2);
  border-color: var(--red);
  box-shadow: var(--glow-red);
  color: var(--red);
}

/* Success */
.btn-success {
  background: var(--success-dim);
  color: var(--green);
  border-color: var(--success-border);
}
.btn-success:hover {
  background: rgba(0, 255, 136, 0.2);
  border-color: var(--green);
  box-shadow: var(--glow-green);
  color: var(--green);
}

/* Sizes */
.btn-sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: 0.78rem;
  min-height: 30px;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: var(--sp-2);
  aspect-ratio: 1;
  min-width: 36px;
  min-height: 36px;
}
.btn-icon svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  flex-shrink: 0;
}
.btn-icon.copied {
  background: var(--success-dim);
  border-color: var(--success-border);
  color: var(--green);
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  margin-bottom: var(--sp-6);
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
}

/* Labels that wrap checkboxes get flex layout */
.form-group label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--font-body);
  font-size: 0.875rem;
  cursor: pointer;
  user-select: none;
  padding: var(--sp-2) 0;
  margin-bottom: 0;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: all var(--ease-fast);
  appearance: none;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(0, 245, 255, 0.08), var(--glow-cyan);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-disabled);
}

.form-group select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.form-group select[multiple] {
  min-height: 90px;
  padding: var(--sp-2);
}

.form-group select[multiple] option {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-xs);
  margin-bottom: 2px;
}

/* Custom checkbox */
.form-group label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 1.1rem;
  height: 1.1rem;
  border: 1.5px solid var(--border-hover);
  border-radius: var(--radius-xs);
  background: var(--bg-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--ease-fast);
  position: relative;
  margin: 0;
  padding: 0;
}

.form-group label input[type="checkbox"]:checked {
  background: rgba(0, 245, 255, 0.2);
  border-color: var(--cyan);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%2300f5ff' d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/%3E%3C/svg%3E");
  background-size: 75%;
  background-repeat: no-repeat;
  background-position: center;
  box-shadow: 0 0 8px rgba(0, 245, 255, 0.3);
}

.form-group label input[type="checkbox"]:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 245, 255, 0.12);
}

.form-help {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--sp-1);
  line-height: 1.5;
}

.error-message {
  display: none;
  color: var(--red);
  font-size: 0.85rem;
  font-weight: 500;
  padding: var(--sp-3) var(--sp-4);
  background: var(--danger-dim);
  border: 1px solid var(--danger-border);
  border-left: 3px solid var(--red);
  border-radius: var(--radius);
  margin-top: var(--sp-3);
}

.error-message.show {
  display: block;
  animation: fade-up 0.25s var(--ease) both;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius);
  border: 1px solid;
  border-left-width: 3px;
  margin-bottom: var(--sp-5);
  font-size: 0.875rem;
  animation: fade-up 0.3s var(--ease) both;
}

.alert-info {
  background: var(--info-dim);
  border-color: var(--info-border);
  color: #6ab0ff;
}
.alert-success {
  background: var(--success-dim);
  border-color: var(--success-border);
  color: var(--green);
}
.alert-warning {
  background: var(--warning-dim);
  border-color: var(--warning-border);
  color: var(--yellow);
}
.alert-danger {
  background: var(--danger-dim);
  border-color: var(--danger-border);
  color: var(--red);
}

/* ============================================================
   FILTERS BAR
   ============================================================ */
.filters {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: var(--sp-6);
  padding: var(--sp-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filters input,
.filters select {
  flex: 1;
  min-width: 140px;
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  transition: border-color var(--ease-fast);
  appearance: none;
  -webkit-appearance: none;
}

.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* ============================================================
   TABLES
   ============================================================ */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table thead {
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.data-table th {
  padding: var(--sp-4) var(--sp-5);
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  white-space: nowrap;
}

.data-table td {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--ease-fast);
}

.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Table states */
.data-table .loading,
.data-table .empty,
.data-table .error {
  text-align: center;
  padding: var(--sp-12) var(--sp-8);
  color: var(--text-muted);
  font-size: 0.875rem;
}
.data-table .error { color: var(--red); }

/* ============================================================
   OTP CELL
   ============================================================ */
.otp-cell {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.otp-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--cyan);
  letter-spacing: 0.1em;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px var(--sp-3);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-full);
  border: 1px solid;
  white-space: nowrap;
  vertical-align: middle;
}

/* Dot indicator */
.badge::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-active {
  background: var(--success-dim);
  color: var(--green);
  border-color: var(--success-border);
}
.badge-active::before { background: var(--green); box-shadow: 0 0 6px var(--green); }

.badge-inactive {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  border-color: var(--border);
}
.badge-inactive::before { background: var(--text-muted); }

.badge-new {
  background: var(--info-dim);
  color: #6ab0ff;
  border-color: var(--info-border);
}
.badge-new::before { background: var(--blue); }

.badge-used {
  background: rgba(0, 245, 255, 0.08);
  color: var(--cyan);
  border-color: rgba(0, 245, 255, 0.25);
}
.badge-used::before { background: var(--cyan); }

.badge-expired {
  background: var(--danger-dim);
  color: var(--red);
  border-color: var(--danger-border);
}
.badge-expired::before { background: var(--red); }

.badge-deleted {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  border-color: var(--border);
}
.badge-deleted::before { background: var(--text-muted); }

.badge-warning {
  background: var(--warning-dim);
  color: var(--yellow);
  border-color: var(--warning-border);
}
.badge-warning::before { background: var(--yellow); }

.badge-error {
  background: var(--danger-dim);
  color: var(--red);
  border-color: var(--danger-border);
}
.badge-error::before { background: var(--red); }

/* ============================================================
   MODALS
   ============================================================ */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
}

.modal.active {
  display: flex;
  animation: fade-in 0.2s var(--ease) both;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl), 0 0 80px rgba(0, 136, 255, 0.15);
  position: relative;
  animation: slide-up 0.3s var(--ease-slow) both;
}

/* Top accent */
.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--blue), var(--purple), transparent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal-content h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: var(--sp-6) var(--sp-6) var(--sp-4);
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.modal-content form {
  padding: var(--sp-6);
}

.close {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--ease-fast);
  background: transparent;
  border: none;
}

.close:hover {
  color: var(--red);
  background: var(--danger-dim);
  transform: rotate(90deg);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast {
  position: fixed;
  bottom: var(--sp-8);
  right: var(--sp-8);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cyan);
  padding: var(--sp-4) var(--sp-6);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg), 0 0 20px rgba(0, 245, 255, 0.1);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 3000;
  opacity: 0;
  transform: translateY(16px);
  transition: all var(--ease);
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.toast::before {
  content: '✓';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--success-dim);
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--success-border);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { border-left-color: var(--green); }
.toast.success::before { background: var(--success-dim); color: var(--green); }

.toast.error {
  border-left-color: var(--red);
}
.toast.error::before {
  content: '✕';
  background: var(--danger-dim);
  color: var(--red);
  border-color: var(--danger-border);
}

/* ============================================================
   MAILBOX VIEWER
   ============================================================ */
.mailbox-page-actions {
  display: flex;
  gap: var(--sp-3);
}

.mailbox-viewer-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: var(--sp-5);
  min-height: 70vh;
}

.mailbox-sidebar,
.mailbox-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mailbox-list-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-tertiary);
}

.mailbox-message-list {
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  overflow-y: auto;
}

.mailbox-message {
  display: flex;
  flex-direction: column;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  background: transparent;
  padding: var(--sp-4) var(--sp-5);
  text-align: left;
  cursor: pointer;
  transition: background var(--ease-fast);
}

.mailbox-message:hover {
  background: var(--bg-card-hover);
}

.mailbox-message.active {
  background: var(--bg-elevated);
  border-left: 3px solid var(--cyan);
  padding-left: calc(var(--sp-5) - 3px);
}

.mailbox-message.unread .mailbox-message-from,
.mailbox-message.unread .mailbox-message-subject {
  font-weight: 700;
  color: var(--text-primary);
}

.mailbox-message-top,
.mailbox-message-subject-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.mailbox-message-top {
  margin-bottom: var(--sp-1);
}

.mailbox-message-from {
  color: var(--text-primary);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.mailbox-message-date {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

.mailbox-message-subject {
  color: var(--text-secondary);
  font-size: 0.83rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-message-snippet {
  margin-top: var(--sp-1);
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.mailbox-detail-panel {
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}

.mailbox-detail-header {
  padding: var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.mailbox-detail-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: var(--sp-3);
  line-height: 1.4;
  color: var(--text-primary);
}

.mailbox-detail-meta {
  display: grid;
  gap: var(--sp-1);
  color: var(--text-muted);
  font-size: 0.83rem;
  font-family: var(--font-mono);
}

.mailbox-detail-body {
  padding: var(--sp-6);
  overflow: auto;
  flex: 1;
}

.mailbox-detail-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text-secondary);
  margin: 0;
}

/* Email view toggle */
.email-view-toggle {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.email-view-toggle .btn-sm {
  font-size: 0.75rem;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border-color: var(--border);
}

.email-view-toggle .btn-sm.active {
  background: rgba(0, 245, 255, 0.1);
  color: var(--cyan);
  border-color: rgba(0, 245, 255, 0.3);
}

.email-view-toggle .btn-sm:hover:not(.active) {
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

/* HTML email iframe */
.email-iframe {
  width: 100%;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

/* Raw source */
.raw-source {
  background: var(--bg-void);
  color: #c8c8e8;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  overflow-x: auto;
  max-height: 600px;
  overflow-y: auto;
}

.email-view-panel {
  animation: fade-in 0.2s var(--ease) both;
}

.mailbox-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: var(--sp-8);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ============================================================
   LIVE INDICATOR
   ============================================================ */
.live-indicator {
  animation: pulse-glow 2s ease infinite;
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-center   { text-align: center; }
.text-right    { text-align: right; }
.text-primary  { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted    { color: var(--text-muted); }
.text-cyan     { color: var(--cyan); }
.text-green    { color: var(--green); }
.text-red      { color: var(--red); }
.text-yellow   { color: var(--yellow); }

.mt-1 { margin-top: var(--sp-2); }
.mt-2 { margin-top: var(--sp-4); }
.mt-3 { margin-top: var(--sp-6); }
.mb-1 { margin-bottom: var(--sp-2); }
.mb-2 { margin-bottom: var(--sp-4); }
.mb-3 { margin-bottom: var(--sp-6); }

.d-flex   { display: flex; }
.d-grid   { display: grid; }
.gap-2    { gap: var(--sp-2); }
.gap-4    { gap: var(--sp-4); }
.flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }

.mono { font-family: var(--font-mono); }
.display-font { font-family: var(--font-display); }

/* ============================================================
   KEYFRAME ANIMATIONS
   ============================================================ */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes shimmer {
  0%   { opacity: 1; }
  50%  { opacity: 0.5; }
  100% { opacity: 1; }
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes scan-line {
  0%   { top: -2px; }
  100% { top: 100%; }
}

/* ============================================================
   RESPONSIVE — LARGE (1200px)
   ============================================================ */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mailbox-viewer-layout {
    grid-template-columns: 280px 1fr;
  }
}

/* ============================================================
   RESPONSIVE — TABLET (1024px)
   ============================================================ */
@media (max-width: 1024px) {
  .main-content {
    padding: var(--sp-6);
  }
}

/* ============================================================
   RESPONSIVE — MOBILE LANDSCAPE (900px)
   ============================================================ */
@media (max-width: 900px) {
  .mailbox-viewer-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .mailbox-message-list {
    max-height: 300px;
  }

  .mailbox-detail-panel {
    min-height: 400px;
  }

  .mailbox-page-actions {
    width: 100%;
  }

  .mailbox-page-actions .btn {
    flex: 1;
  }

  /* Responsive table → card layout */
  .data-table thead {
    display: none;
  }

  .data-table tbody tr {
    display: block;
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
    transition: background var(--ease-fast);
  }

  .data-table tbody tr:hover {
    background: var(--bg-card-hover);
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-2) 0;
    border-bottom: 1px solid var(--border-subtle);
    gap: var(--sp-3);
  }

  .data-table td:last-child {
    border-bottom: none;
    padding-top: var(--sp-3);
    flex-wrap: wrap;
    gap: var(--sp-2);
  }

  .data-table td::before {
    content: attr(data-label);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 80px;
  }

  .data-table td .otp-cell,
  .data-table td .badge {
    margin-left: auto;
  }
}

/* ============================================================
   RESPONSIVE — TABLET PORTRAIT (768px)
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --navbar-h: 60px;
  }

  /* Show hamburger, hide nav links by default */
  .nav-toggle {
    display: flex;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: var(--navbar-h);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    background: rgba(7, 7, 15, 0.98);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border);
    padding: var(--sp-3);
    gap: var(--sp-1);
    z-index: 999;
    overflow: hidden;
  }

  .nav-links.open {
    display: flex;
    animation: fade-up 0.2s var(--ease) both;
  }

  .nav-link {
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    justify-content: flex-start;
  }

  .nav-link.active::after {
    display: none;
  }

  #logout-btn {
    margin-left: 0;
  }

  .navbar {
    padding: 0 var(--sp-4);
  }

  .main-content {
    padding: var(--sp-5) var(--sp-4);
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-4);
  }

  .page-header-actions {
    width: 100%;
  }

  .page-header-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .filters {
    flex-direction: column;
  }

  .filters input,
  .filters select {
    width: 100%;
    min-width: auto;
  }

  .filters .btn {
    width: 100%;
  }

  .modal {
    padding: var(--sp-4);
    align-items: flex-end;
  }

  .modal-content {
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-width: 100%;
  }

  .toast {
    bottom: var(--sp-5);
    right: var(--sp-4);
    left: var(--sp-4);
    max-width: none;
  }

  .login-container {
    padding: var(--sp-8) var(--sp-6);
  }

  .stat-value {
    font-size: 1.6rem;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE (600px)
   ============================================================ */
@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   RESPONSIVE — SMALL MOBILE (480px)
   ============================================================ */
@media (max-width: 480px) {
  .main-content {
    padding: var(--sp-4) var(--sp-3);
  }

  .page-header h1 {
    font-size: 1rem;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .btn {
    padding: var(--sp-2) var(--sp-4);
    font-size: 0.8rem;
    min-height: 40px;
  }

  .btn-icon,
  .btn-sm {
    min-height: 40px;
    min-width: 40px;
  }

  .modal-content form {
    padding: var(--sp-4);
  }

  .data-table tbody tr {
    padding: var(--sp-3) var(--sp-4);
  }

  .mailbox-detail-header,
  .mailbox-detail-body {
    padding: var(--sp-4);
  }

  .toast {
    font-size: 0.82rem;
    padding: var(--sp-3) var(--sp-4);
  }
}

/* ============================================================
   BOTTOM NAV — EXTRA SMALL (400px)
   Turns nav into a fixed bottom tab bar for tiny phones
   ============================================================ */
@media (max-width: 400px) {
  :root { --navbar-h: 56px; }

  #main-app {
    padding-bottom: 60px;
  }

  .nav-links.open {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: var(--sp-2) var(--sp-2) env(safe-area-inset-bottom, var(--sp-2));
    border-top: 1px solid var(--border);
    border-bottom: none;
    gap: 0;
    background: rgba(7, 7, 15, 0.98);
  }

  .nav-link {
    flex-direction: column;
    font-size: 0.65rem;
    padding: var(--sp-1) var(--sp-2);
    gap: var(--sp-1);
    min-width: 52px;
    text-align: center;
    justify-content: center;
  }
}

/* ── Fix 1: Custom dropdown arrow for ALL selects (replaces removed native arrow) ── */
.form-group select,
.filters select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235a5a80' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ── Fix 2: Consistent height & baseline alignment in filters bar ── */
.filters input,
.filters select {
  height: 38px;
  line-height: 38px;
  padding-top: 0;
  padding-bottom: 0;
}

/* ── Fix 3: Mailbox viewer select takes proper width on its row ── */
#viewer-mailbox-filter {
  min-width: 220px;
  flex: 0 0 220px;
}

/* ── Fix 4: Active message border — no layout shift ── */
.mailbox-message.active {
  border-left: 3px solid var(--cyan);
  padding-left: var(--sp-5);   /* keep original padding, border is outside */
  box-sizing: border-box;
}

/* ── Fix 5: Mailbox viewer layout gap between filters and content ── */
#emails-page .filters {
  margin-bottom: var(--sp-5);
}

/* ── Fix 6: Message list item vertical rhythm ── */
.mailbox-message {
  gap: var(--sp-1);
}
.mailbox-message-snippet {
  -webkit-line-clamp: 1;   /* keep it single line in the narrow sidebar */
}