/**
 * Ex Nihilo Admin Console - Design System
 * 
 * Performance-optimized CSS variable system for theming and consistency.
 * Zero runtime cost, native browser support, live theme updates.
 * 
 * Architecture: Primitives → Semantic Tokens → Component Tokens
 */

:root {
  /* ============================================
     COLOR PRIMITIVES
     ============================================ */
  
  /* Grayscale */
  --gray-950: #0d1117;
  --gray-900: #161b22;
  --gray-850: #1c2128;
  --gray-800: #21262d;
  --gray-700: #30363d;
  --gray-500: #6e7681;
  --gray-400: #8b949e;
  --gray-300: #c9d1d9;
  
  /* Blue Spectrum */
  --blue-500: #58a6ff;
  --blue-600: #4895e8;
  --blue-700: #388bfd;
  
  /* Purple Spectrum */
  --purple-500: #bc8cff;
  --purple-600: #a876e8;
  
  /* Green Spectrum */
  --green-500: #3fb950;
  --green-600: #34a045;
  
  /* Red Spectrum */
  --red-500: #f85149;
  --red-600: #d63e36;
  
  /* Yellow Spectrum */
  --yellow-500: #d29922;
  --yellow-600: #b8851e;
  
  /* Cyan Spectrum */
  --cyan-500: #8be9fd;
  
  /* Pink Spectrum */
  --pink-500: #ff79c6;
}

/* Shake animation for error states */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
  20%, 40%, 60%, 80% { transform: translateX(10px); }
}

.shake {
  animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

/* 2FA Modal Styles */
.totp-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.totp-overlay.visible {
  opacity: 1;
}

.totp-modal {
  background: var(--bg-primary, #161b22);
  border: 1px solid var(--border-color, #30363d);
  border-radius: var(--radius, 8px);
  padding: var(--space-6, 2rem);
  min-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  transition: all 0.3s ease;
}

.totp-modal.error-state {
  border-color: var(--red-500, #f85149);
  box-shadow: 0 0 20px rgba(248, 81, 73, 0.3);
}

.totp-modal h3 {
  margin: 0 0 var(--space-2, 0.5rem) 0;
  color: var(--text-primary, #c9d1d9);
  font-size: var(--font-xl, 1.25rem);
  text-align: center;
}

.totp-modal p {
  margin: 0 0 var(--space-4, 1rem) 0;
  color: var(--text-secondary, #8b949e);
  text-align: center;
  font-size: var(--font-sm, 0.875rem);
}

.totp-boxes {
  display: flex;
  gap: var(--space-2, 0.5rem);
  justify-content: center;
  margin-bottom: var(--space-4, 1rem);
}

.totp-digit {
  width: 50px;
  height: 60px;
  text-align: center;
  font-size: var(--font-2xl, 1.5rem);
  font-weight: var(--font-weight-semibold, 600);
  background: var(--bg-secondary, #0d1117);
  border: 2px solid var(--border-color, #30363d);
  border-radius: var(--radius, 8px);
  color: var(--text-primary, #c9d1d9);
  transition: all 0.2s ease;
}

.totp-digit:focus {
  outline: none;
  border-color: var(--accent-blue, #58a6ff);
  background: var(--bg-primary, #161b22);
}

.totp-digit.error {
  border-color: var(--red-500, #f85149);
  background: rgba(248, 81, 73, 0.1);
}

.totp-actions {
  text-align: center;
  margin-top: var(--space-3, 0.75rem);
}

.backup-link {
  color: var(--accent-blue, #58a6ff);
  text-decoration: none;
  font-size: var(--font-sm, 0.875rem);
  transition: color 0.2s ease;
}

.backup-link:hover {
  color: var(--blue-600, #4895e8);
  text-decoration: underline;
}

:root {
  /* ============================================
     SEMANTIC TOKENS
     ============================================ */
  
  /* Backgrounds */
  --bg-primary: var(--gray-950);
  --bg-secondary: var(--gray-900);
  --bg-tertiary: var(--gray-850);
  --bg-hover: var(--gray-800);
  
  /* Borders */
  --border-color: var(--gray-700);
  
  /* Text */
  --text-primary: var(--gray-300);
  --text-secondary: var(--gray-400);
  --text-muted: var(--gray-500);
  
  /* Accent Colors (Theme-able) */
  --accent-primary: var(--blue-500);
  --accent-primary-hover: var(--blue-600);
  --accent-secondary: var(--purple-500);
  --accent-secondary-hover: var(--purple-600);
  
  /* Semantic Colors */
  --accent-success: var(--green-500);
  --accent-success-hover: var(--green-600);
  --accent-danger: var(--red-500);
  --accent-danger-hover: var(--red-600);
  --accent-warning: var(--yellow-500);
  --accent-warning-hover: var(--yellow-600);
  --accent-info: var(--cyan-500);
  --accent-highlight: var(--pink-500);
  
  /* Backward Compatibility Aliases */
  --accent-blue: var(--blue-500);
  --accent-purple: var(--purple-500);
  --accent-green: var(--green-500);
  --accent-red: var(--red-500);
  --accent-yellow: var(--yellow-500);
  
  /* ============================================
     SPACING SCALE (8-point grid, slim preference)
     ============================================ */
  
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 40px;
  
  /* Spacing Multiplier (for theme variants) */
  --space-multiplier: 1;
  
  /* ============================================
     TYPOGRAPHY SCALE
     ============================================ */
  
  /* Font Sizes */
  --font-size-xs: 0.75rem;    /* 12px */
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-base: 1rem;     /* 16px */
  --font-size-lg: 1.125rem;   /* 18px */
  --font-size-xl: 1.25rem;    /* 20px */
  --font-size-2xl: 1.5rem;    /* 24px */
  --font-size-3xl: 2rem;      /* 32px */
  
  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  
  /* Line Heights */
  --line-height-tight: 1.2;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.8;
  
  /* ============================================
     BORDER RADIUS
     ============================================ */
  
  --radius-sm: 6px;   /* Buttons, inputs, small elements */
  --radius-md: 8px;   /* Cards, containers */
  --radius-lg: 12px;  /* Modals, major sections */
  
  /* ============================================
     TRANSITIONS
     ============================================ */
  
  --transition-fast: all 0.15s ease;
  --transition-base: all 0.3s ease-in-out;
  --transition-slow: all 0.5s ease-out;
  
  /* ============================================
     SHADOWS
     ============================================ */
  
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 0 3px rgba(88, 166, 255, 0.1);
  
  /* Legacy backward compatibility */
  --shadow: var(--shadow-md);
  
  /* ============================================
     Z-INDEX LAYERS
     ============================================ */
  
  --z-base: 1;
  --z-nav: 100;
  --z-dropdown: 1000;
  --z-modal: 10000;
  
  /* ============================================
     COMPONENT TOKENS
     ============================================ */
  
  /* Buttons */
  --btn-font-primary: var(--font-size-base);
  --btn-font-secondary: var(--font-size-sm);
  --btn-font-tertiary: var(--font-size-xs);
  
  --btn-padding-primary: var(--space-3) var(--space-5);
  --btn-padding-secondary: var(--space-2) var(--space-3);
  --btn-padding-tertiary: var(--space-1) var(--space-2);
  
  --btn-radius: var(--radius-sm);
  
  --btn-bg: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  --btn-bg-hover: linear-gradient(135deg, var(--accent-primary-hover), var(--accent-secondary-hover));
  --btn-bg-active: linear-gradient(135deg, var(--accent-warning), var(--accent-danger));
  
  /* Inputs */
  --input-padding: var(--space-3) var(--space-4);
  --input-radius: var(--radius-sm);
  --input-border: 1px solid var(--border-color);
  --input-bg: var(--bg-tertiary);
  
  /* Cards */
  --card-padding: var(--space-5);
  --card-radius: var(--radius-md);
  --card-border: 1px solid var(--border-color);
  --card-bg: var(--bg-secondary);
  
  /* Modals */
  --modal-padding: var(--space-6) var(--space-7);
  --modal-radius: var(--radius-lg);
  --modal-bg: var(--bg-secondary);
  --modal-shadow: var(--shadow-lg);
  
  /* Navbar */
  --navbar-height: 60px;
  --navbar-padding: var(--space-1) var(--space-5);
  --navbar-bg: var(--bg-secondary);
  --navbar-border: 1px solid var(--border-color);
  
  /* Scrollbars */
  --scrollbar-width: 10px;
  --scrollbar-track: var(--bg-tertiary);
  --scrollbar-thumb: var(--border-color);
  --scrollbar-thumb-hover: var(--text-muted);
}

/* ============================================
   THEME VARIANTS
   ============================================ */

/* Purple Theme */
body.accent-purple {
  --accent-primary: var(--purple-500);
  --accent-primary-hover: var(--purple-600);
  --accent-secondary: var(--blue-500);
  --accent-secondary-hover: var(--blue-600);
}

/* Green Theme */
body.accent-green {
  --accent-primary: var(--green-500);
  --accent-primary-hover: var(--green-600);
  --accent-secondary: var(--cyan-500);
  --accent-secondary-hover: var(--cyan-500);
}

/* Red Theme */
body.accent-red {
  --accent-primary: var(--red-500);
  --accent-primary-hover: var(--red-600);
  --accent-secondary: var(--pink-500);
  --accent-secondary-hover: var(--pink-500);
}

/* ============================================
   SPACING VARIANTS
   ============================================ */

/* Tight Spacing (75%) */
body.spacing-tight {
  --space-multiplier: 0.75;
  --navbar-height: 50px;
}

/* Comfortable Spacing (125%) */
body.spacing-comfortable {
  --space-multiplier: 1.25;
  --navbar-height: 70px;
}

/* ============================================
   FONT SIZE VARIANTS
   ============================================ */

/* Small Text */
body.text-small {
  --font-size-base: 0.875rem;  /* 14px */
  --font-size-sm: 0.75rem;     /* 12px */
  --font-size-xs: 0.6875rem;   /* 11px */
}

/* Large Text */
body.text-large {
  --font-size-base: 1.125rem;  /* 18px */
  --font-size-sm: 1rem;        /* 16px */
  --font-size-xs: 0.875rem;    /* 14px */
}

/* ============================================
   DARK/LIGHT MODE VARIANTS
   ============================================ */

/* Light Mode */
body.light-mode {
  /* Light mode overrides */
  --gray-950: #ffffff;
  --gray-900: #f6f8fa;
  --gray-850: #eaeef2;
  --gray-800: #d0d7de;
  --gray-700: #afb8c1;
  --gray-500: #6e7781;
  --gray-400: #57606a;
  --gray-300: #24292f;
  
  /* Semantic tokens auto-update via cascade */
  --bg-primary: var(--gray-950);
  --bg-secondary: var(--gray-900);
  --bg-tertiary: var(--gray-850);
  --bg-hover: var(--gray-800);
  --border-color: var(--gray-700);
  --text-primary: var(--gray-300);
  --text-secondary: var(--gray-400);
  --text-muted: var(--gray-500);
  
  /* Adjust shadows for light mode */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);
}

/* Dark Mode (explicit class for clarity, same as default) */
body.dark-mode {
  /* Dark mode is the default, explicitly set for clarity */
  --bg-primary: var(--gray-950);
  --bg-secondary: var(--gray-900);
  --bg-tertiary: var(--gray-850);
}

/* ============================================
   LIGHT MODE
   ============================================ */

body.light {
  /* Backgrounds - Light (Softer, Not Harsh White) */
  --bg-primary: #f8f9fa;
  --bg-secondary: #e9ecef;
  --bg-tertiary: #dee2e6;
  --bg-hover: #ced4da;
  
  /* Borders - Light */
  --border-color: #adb5bd;
  
  /* Text - Light (Higher Contrast) */
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #6c757d;
  
  /* Accent Colors - Slightly Darker for Light Mode */
  --accent-primary: #0969da;
  --accent-secondary: #8250df;
  
  /* Update component tokens for light mode */
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --navbar-bg: #ffffff;
  --scrollbar-track: #dee2e6;
  --scrollbar-thumb: #adb5bd;
  --scrollbar-thumb-hover: #6c757d;
  
  /* Button gradients for light mode */
  --btn-bg: linear-gradient(135deg, #0969da, #8250df);
  --btn-bg-hover: linear-gradient(135deg, #0550ae, #6639ba);
}

/* ============================================
   ANIMATION VARIANTS
   ============================================ */

/* Reduced Motion (Accessibility) */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-fast: none;
    --transition-base: none;
    --transition-slow: none;
  }
}

/* No Animations (User Preference) */
body.animations-none * {
  animation: none !important;
  transition: none !important;
}

/* Reduced Animations */
body.animations-reduced {
  --transition-fast: all 0.1s ease;
  --transition-base: all 0.15s ease;
  --transition-slow: all 0.2s ease;
}

/* ============================================
   MOBILE OVERRIDES
   ============================================ */

@media (max-width: 768px) {
  :root {
    --navbar-height: 120px;
    --space-6: 24px;
    --space-7: 32px;
  }
  
  body.spacing-tight {
    --navbar-height: 100px;
  }
  
  body.spacing-comfortable {
    --navbar-height: 140px;
  }
}

@media (max-width: 480px) {
  :root {
    --font-size-base: 0.9375rem;  /* 15px - slightly smaller on small screens */
  }
}

