/* =========================================
   DESIGN SYSTEM - Clustering Trainer
   ========================================= */

/* Custom Properties - Unique Color Palette */
:root {
  /* Primary: Deep Indigo (not generic blue) */
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --primary-200: #c7d2fe;
  --primary-300: #a5b4fc;
  --primary-400: #818cf8;
  --primary-500: #6366f1;
  --primary-600: #4f46e5;
  --primary-700: #4338ca;
  
  /* Accent: Vibrant Teal */
  --accent-400: #2dd4bf;
  --accent-500: #14b8a6;
  --accent-600: #0d9488;
  
  /* Background: Warm dark tones */
  --bg-base: #0c0a09;
  --bg-elevated: #1c1917;
  --bg-surface: #292524;
  --bg-muted: #44403c;
  
  /* Text */
  --text-primary: #fafaf9;
  --text-secondary: #d6d3d1;
  --text-muted: #a8a29e;
  --text-disabled: #78716c;
  
  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.15);
  
  /* Status Colors */
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  
  /* Typography */
  --font-main: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  /* Spacing */
  --nav-height: 70px;
  
  /* Effects */
  --glow-primary: 0 0 40px rgba(99, 102, 241, 0.3);
  --glow-accent: 0 0 40px rgba(20, 184, 166, 0.3);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-elevated: 0 8px 40px rgba(0, 0, 0, 0.5);
}

/* Reset & Base */
html {
  overflow-x: hidden;
  background-color: var(--bg-base);
  background-image: 
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 80% 60%, rgba(20, 184, 166, 0.1), transparent);
  background-attachment: fixed;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  background-image: 
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 80% 60%, rgba(20, 184, 166, 0.1), transparent);
  background-attachment: fixed;
}

/* =========================================
   GRADIENT ORBS
   ========================================= */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.3;
  pointer-events: none;
  z-index: -1;
}

.bg-orb--primary {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--primary-500) 0%, transparent 70%);
  top: 10%;
  right: 5%;
  animation: float-slow 20s ease-in-out infinite;
}

.bg-orb--accent {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, var(--accent-500) 0%, transparent 70%);
  bottom: 10%;
  left: 5%;
  animation: float-slow 25s ease-in-out infinite reverse;
}

@keyframes float-slow {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -20px) scale(1.05); }
}

/* =========================================
   NAVBAR - Glass Morphism Floating
   ========================================= */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--nav-height);
  padding: 0 2rem;
  background: rgba(28, 25, 23, 0.4);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  width: calc(100% - 48px);
  max-width: 1600px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  margin-left: -8px;
}

/* Logo Image */
.logo-img {
  width: 70px;
  height: 70px;
  object-fit: contain;
}

.brand-text {
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-links {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-item {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  position: relative;
}

.nav-item:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: var(--text-primary);
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: linear-gradient(90deg, var(--primary-500), var(--accent-500));
  border-radius: 2px;
}

.nav-auth {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.nav-auth .nav-admin-btn {
  margin-left: 0.5rem;
}

/* =========================================
   BUTTONS - Modern & Unique
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  text-decoration: none;
  line-height: 1.25;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

.btn:hover::before {
  opacity: 1;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  color: white;
  border: none;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}

.btn-secondary:hover {
  background: var(--bg-muted);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent-500), var(--accent-600));
  color: white;
  box-shadow: 0 2px 10px rgba(20, 184, 166, 0.3);
}

.btn-accent:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(20, 184, 166, 0.4);
}

.btn-sm {
  padding: 0.375rem 0.875rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* =========================================
   PAGE TRANSITIONS
   ========================================= */
.main-content {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-top: calc(var(--nav-height) + 16px);
}

/* Класс для анимации ухода со страницы */
.page-leaving {
  opacity: 0 !important;
  transition: opacity 0.15s ease-out;
}

/* Graph page and simulator use full height - no padding */
.main-content:has(.graph-page-container),
.main-content:has(.simulator-container) {
  padding-top: 0;
}

/* =========================================
   PARTICLES CANVAS
   ========================================= */
#particles-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* =========================================
   TOAST NOTIFICATIONS
   ========================================= */
.toast-wrap {
  position: fixed;
  top: calc(var(--nav-height) + 32px);
  right: 16px;
  z-index: 10000;
  max-width: 380px;
  width: calc(100% - 32px);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: var(--shadow-elevated);
  border: 1px solid;
  animation: toast-slide-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  background: var(--bg-elevated);
}

@keyframes toast-slide-in {
  from { 
    opacity: 0; 
    transform: translateX(100%) scale(0.9); 
  }
  to { 
    opacity: 1; 
    transform: translateX(0) scale(1); 
  }
}

.toast-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.85rem;
}

.toast-text {
  margin: 0;
  flex: 1;
  padding-right: 8px;
}

.toast-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  transition: all 0.2s;
}

.toast-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

.toast-success {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), var(--bg-elevated));
  border-color: rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
}

.toast-success .toast-icon {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
}

.toast-warning {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), var(--bg-elevated));
  border-color: rgba(245, 158, 11, 0.3);
  color: #fde68a;
}

.toast-warning .toast-icon {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

.toast-error,
.toast-danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15), var(--bg-elevated));
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.toast-error .toast-icon,
.toast-danger .toast-icon {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.toast-info {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), var(--bg-elevated));
  border-color: rgba(99, 102, 241, 0.3);
  color: #c7d2fe;
}

.toast-info .toast-icon {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-400);
}

/* =========================================
   UTILITY CLASSES
   ========================================= */
.text-gradient {
  background: linear-gradient(135deg, var(--primary-400), var(--accent-400));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.glass-card {
  background: rgba(28, 25, 23, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
}

/* =========================================
   SCROLLBAR STYLING
   ========================================= */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-muted);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-disabled);
}

/* =========================================
   SELECTION STYLING
   ========================================= */
::selection {
  background: rgba(99, 102, 241, 0.3);
  color: var(--text-primary);
}

/* =========================================
   FOCUS STYLES (Accessibility)
   ========================================= */
:focus-visible {
  outline: 2px solid var(--primary-400);
  outline-offset: 2px;
}

/* =========================================
   NAV AUTH BUTTONS
   ========================================= */
.nav-auth .btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  gap: 0.35rem;
}

.nav-auth .btn i {
  width: 14px;
  height: 14px;
}

/* Remove focus outline on nav items */
.nav-item:focus,
.nav-item:focus-visible,
.nav-item:active {
  outline: none;
  box-shadow: none;
}

/* Remove focus outline on navbar buttons but keep their original styles */
.nav-auth .btn:focus,
.nav-auth .btn:focus-visible,
.nav-auth .btn:active {
  outline: none;
  box-shadow: none;
}

/* Prevent focus ring on any navbar element when clicked */
.navbar *:focus,
.navbar *:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

/* Override focus-visible for navbar buttons specifically */
.nav-auth .btn:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}


/* Mobile menu toggle - hidden on desktop, shown on mobile via media query.
   Размеры (padding, border, icon) повторяют .nav-auth .btn на каждом брейкпоинте,
   чтобы бургер выглядел одной группой с иконочными кнопками авторизации. */
.nav-mobile-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  font-family: inherit;
  line-height: 1;
}

.nav-mobile-toggle i {
  width: 14px;
  height: 14px;
}

.nav-mobile-toggle:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.nav-mobile-toggle:focus,
.nav-mobile-toggle:focus-visible,
.nav-mobile-toggle:active {
  outline: none;
  box-shadow: none;
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
  .navbar {
    padding: 0 1rem;
    width: calc(100% - 24px);
    top: 12px;
    border-radius: 12px;
    transform: translateX(-50%);
    left: 50%;
    gap: 0.5rem;
  }

  /* Скрываем десктопные nav-links (откроются как выпадающее меню по кнопке-бургеру) */
  .nav-links {
    display: none;
  }

  .nav-links.mobile-open {
    display: flex;
    position: absolute;
    top: calc(var(--nav-height) + 8px);
    left: 0;
    right: 0;
    background: rgba(28, 25, 23, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    flex-direction: column;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
  }

  /* Бургер виден на мобильных, стоит в .nav-auth слева от кнопок авторизации */
  .nav-mobile-toggle {
    display: flex;
  }

  .nav-links.mobile-open .nav-item {
    padding: 0.75rem 1rem;
  }
}

/* Узкие мобильные экраны — типовые телефоны (≤600px) */
@media (max-width: 600px) {
  :root {
    --nav-height: 58px;
  }

  .navbar {
    padding: 0 0.75rem;
    width: calc(100% - 16px);
    top: 8px;
  }

  .logo-img {
    width: 42px;
    height: 42px;
  }

  .navbar-brand {
    margin-left: 0;
    font-size: 1rem;
    gap: 0.3rem;
    min-width: 0;
    overflow: hidden;
  }

  /* Брeнд-текст обрезается многоточием, если не помещается */
  .brand-text {
    display: inline-block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .nav-auth {
    gap: 0.4rem;
    flex-shrink: 0;
  }

  .nav-mobile-toggle {
    padding: 0.45rem 0.6rem;
    min-width: 36px;
  }

  .nav-mobile-toggle i {
    width: 18px;
    height: 18px;
  }

  .nav-auth .btn {
    padding: 0.45rem 0.6rem;
    min-width: 36px;
    justify-content: center;
  }

  .nav-auth .btn .btn-label {
    display: none;
  }

  .nav-auth .btn i {
    width: 18px;
    height: 18px;
    margin: 0;
  }

  .nav-auth .nav-admin-btn {
    margin-left: 0;
  }
}

/* Очень узкие экраны (старые телефоны / iPhone SE ≤400px) — здесь бренд-текст уже не помещается */
@media (max-width: 400px) {
  .navbar {
    padding: 0 0.5rem;
  }

  .logo-img {
    width: 36px;
    height: 36px;
  }

  /* На совсем узких экранах прячем текст, остаётся только логотип */
  .brand-text {
    display: none;
  }

  .nav-mobile-toggle {
    padding: 0.4rem 0.5rem;
    min-width: 34px;
  }

  .nav-mobile-toggle i {
    width: 16px;
    height: 16px;
  }

  .nav-auth .btn {
    padding: 0.4rem 0.5rem;
    min-width: 34px;
  }

  .nav-auth .btn i {
    width: 16px;
    height: 16px;
  }
}
