/* ═══════════════════════════════════════════════════════════════════════════
   AI MarketLens — Design System v2.0
   Premium dark theme with glassmorphism, gradients, and micro-animations
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── Design Tokens — Dark (default) ───────────────────────────────────────── */
:root,
:root[data-theme="dark"] {
  /* Backgrounds */
  --bg-primary: #06080f;
  --bg-secondary: #0d1117;
  --bg-tertiary: #161b22;
  --bg-elevated: #1c2333;

  /* Text */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-heading: #ffffff;

  /* Accent — Teal */
  --accent-primary: #00a8b8;
  --accent-secondary: #6366f1;
  --accent-color: var(--accent-primary);

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #00a8b8 0%, #00d4aa 100%);
  --gradient-accent: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --gradient-warm: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
  --gradient-hero: linear-gradient(135deg, #06080f 0%, #0d1a2d 50%, #0a1628 100%);

  /* Semantic Colors */
  --success-color: #4ade80;
  --warning-color: #fbbf24;
  --error-color: #f87171;
  --info-color: #60a5fa;

  /* Borders */
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  /* Glassmorphism */
  --glass-bg: rgba(13, 17, 23, 0.6);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-blur: 16px;

  /* Shadows */
  --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --card-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow-teal: 0 0 20px rgba(0, 168, 184, 0.15);
  --shadow-glow-indigo: 0 0 20px rgba(99, 102, 241, 0.15);

  /* Spacing Scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* Legacy aliases (backward compat) */
  --spacing-xs: var(--space-2);
  --spacing-sm: var(--space-3);
  --spacing-md: var(--space-5);
  --spacing-lg: var(--space-6);
  --spacing-xl: var(--space-7);

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

  /* Card aliases */
  --card-bg: var(--bg-secondary);
}

/* ── Design Tokens — Light ────────────────────────────────────────────────── */
:root[data-theme="light"] {
  --bg-primary: #f6f8fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f3f6;
  --bg-elevated: #ffffff;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-heading: #111827;

  --accent-primary: #0891b2;
  --accent-secondary: #4f46e5;

  --success-color: #22c55e;
  --warning-color: #f59e0b;
  --error-color: #ef4444;
  --info-color: #3b82f6;

  --border-color: #e5e7eb;
  --border-hover: #d1d5db;

  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-blur: 16px;

  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
  --card-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.1), 0 8px 32px rgba(0, 0, 0, 0.06);
  --shadow-glow-teal: 0 0 20px rgba(8, 145, 178, 0.1);

  --gradient-hero: linear-gradient(135deg, #f6f8fa 0%, #e8f4f8 50%, #f0f3f6 100%);

  --card-bg: var(--bg-secondary);
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

html {
  scroll-behavior: smooth;
}

/* ── Typography ───────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-heading);
  letter-spacing: -0.02em;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p {
  color: var(--text-secondary);
  line-height: 1.7;
}

.gradient-text {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Links ────────────────────────────────────────────────────────────────── */
a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.2s ease, opacity 0.2s ease;
}

a:hover {
  opacity: 0.85;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button, .btn {
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.btn-primary {
  background: var(--gradient-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(0, 168, 184, 0.25);
  border: none;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 168, 184, 0.35);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 14px;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--glass-border);
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-shadow-hover);
  border-color: var(--border-hover);
}

.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
}

/* ── Navigation ───────────────────────────────────────────────────────────── */
.navbar {
  background: rgba(6, 8, 15, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  padding: 0;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
}

:root[data-theme="light"] .navbar {
  background: rgba(255, 255, 255, 0.85);
}

.nav-container {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.nav-brand a {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-heading);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  text-decoration: none;
}

.nav-menu {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

.nav-link {
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

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

.nav-link.active {
  color: #ffffff;
  background: var(--accent-primary);
  box-shadow: var(--shadow-glow-teal);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-left: auto;
}

/* Hamburger Toggle (hidden on desktop) */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  flex-direction: column;
  gap: 5px;
  z-index: 1001;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: all 0.3s ease;
}

.nav-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.nav-toggle.active span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ── Theme Toggle ─────────────────────────────────────────────────────────── */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow-teal);
  transform: scale(1.08);
}

/* ── Search ───────────────────────────────────────────────────────────────── */
.search-container {
  display: flex;
  align-items: center;
  position: relative;
}

.search-input {
  margin-bottom: 0 !important;
  height: 36px;
  font-size: 0.85rem;
  border-radius: var(--radius-full);
  padding: 0 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  transition: all 0.25s ease;
  width: 180px;
}

.search-input:focus {
  width: 240px;
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow-teal);
  outline: none;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
input, select, textarea {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: all 0.25s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 184, 0.12);
}

/* ── Filter Buttons ───────────────────────────────────────────────────────── */
.filter-btn {
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}

.filter-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.filter-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 168, 184, 0.25);
}

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-success {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success-color);
  border: 1px solid rgba(74, 222, 128, 0.2);
}

.badge-warning {
  background: rgba(251, 191, 36, 0.12);
  color: var(--warning-color);
  border: 1px solid rgba(251, 191, 36, 0.2);
}

.badge-error {
  background: rgba(248, 113, 113, 0.12);
  color: var(--error-color);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.badge-info {
  background: rgba(0, 168, 184, 0.1);
  color: var(--accent-primary);
  border: 1px solid rgba(0, 168, 184, 0.2);
}

/* ── Loading States ───────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    rgba(255, 255, 255, 0.04) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s infinite ease-in-out;
  border-radius: var(--radius-md);
}

.loading-state {
  text-align: center;
  padding: var(--space-7) var(--space-5);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--text-secondary);
  font-size: 1rem;
}

.error-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--error-color);
  font-size: 1rem;
}

.error-state button {
  margin-top: var(--space-4);
  padding: 10px 20px;
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 600;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.6; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Animation utility classes */
.animate-in {
  animation: fadeInUp 0.5s ease-out both;
}

.animate-fade {
  animation: fadeIn 0.4s ease-out both;
}

.animate-slide {
  animation: slideInLeft 0.4s ease-out both;
}

/* Stagger children */
.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.1s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.2s; }
.stagger > *:nth-child(5) { animation-delay: 0.25s; }
.stagger > *:nth-child(6) { animation-delay: 0.3s; }

/* ── Container ────────────────────────────────────────────────────────────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  margin-top: var(--space-7);
  padding: 0 var(--space-6);
}

/* ── Utility Classes ──────────────────────────────────────────────────────── */
.text-center  { text-align: center; }
.text-left    { text-align: left; }
.text-right   { text-align: right; }

.mt-sm { margin-top: var(--space-3); }
.mt-md { margin-top: var(--space-5); }
.mt-lg { margin-top: var(--space-6); }
.mb-sm { margin-bottom: var(--space-3); }
.mb-md { margin-bottom: var(--space-5); }
.mb-lg { margin-bottom: var(--space-6); }

.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-center  { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-3); }
.gap-md { gap: var(--space-5); }
.gap-lg { gap: var(--space-6); }

/* ── Responsive ───────────────────────────────────────────────────────────── */

/* Tablet (≤1024px) */
@media (max-width: 1024px) {
  .nav-menu {
    gap: var(--space-1);
  }
  .nav-link {
    font-size: 0.8rem;
    padding: 5px 8px;
  }
  .search-input {
    width: 140px;
  }
}

/* Mobile (≤768px) */
@media (max-width: 768px) {
  .nav-toggle {
    display: flex;
  }

  .nav-menu {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    flex-direction: column;
    padding: var(--space-6);
    gap: var(--space-2);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
    overflow-y: auto;
  }

  .nav-menu.open {
    transform: translateX(0);
  }

  .nav-link {
    font-size: 1rem;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    width: 100%;
  }

  .search-input {
    width: 140px;
  }

  .search-input:focus {
    width: 160px;
  }

  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.375rem; }
  h3 { font-size: 1.125rem; }

  .container {
    padding: 0 var(--space-4);
    margin-top: var(--space-5);
  }
}

/* Small phone (≤480px) */
@media (max-width: 480px) {
  .nav-actions {
    gap: var(--space-2);
  }

  h1 { font-size: 1.5rem; }

  .card {
    padding: var(--space-4);
  }
}

/* ── Smooth theme transitions ─────────────────────────────────────────────── */
body,
.navbar,
.card,
.glass-card,
input,
select,
textarea,
.nav-link,
.badge,
.btn,
.filter-btn {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ── ET-253: Real-Time Price Flash Animations ─────────────────────────── */
.price-flash-up {
  animation: flashGreen 0.6s ease;
}
.price-flash-down {
  animation: flashRed 0.6s ease;
}
@keyframes flashGreen {
  0%   { background: rgba(16, 185, 129, 0.3); }
  100% { background: transparent; }
}
@keyframes flashRed {
  0%   { background: rgba(239, 68, 68, 0.3); }
  100% { background: transparent; }
}

/* ── Alert Toast Notification ─────────────────────────────────────────── */
.alert-toast {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 10000;
  background: var(--glass-bg, rgba(30,41,59,0.95));
  border: 1px solid rgba(99,102,241,0.4);
  border-radius: 12px;
  padding: 16px 20px;
  min-width: 300px;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  backdrop-filter: blur(12px);
  animation: slideInRight 0.4s ease;
}
.alert-toast-exit {
  animation: slideOutRight 0.4s ease forwards;
}
.alert-toast-content {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary, #e2e8f0);
  font-size: 0.85rem;
  line-height: 1.4;
}
.alert-toast-icon {
  font-size: 1.5rem;
}
@keyframes slideInRight {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideOutRight {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

/* ── CSV Export Button ────────────────────────────────────────────────── */
.btn-export-csv {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-primary, #00a8b8);
  background: rgba(0, 168, 184, 0.1);
  border: 1px solid rgba(0, 168, 184, 0.25);
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-export-csv:hover {
  background: rgba(0, 168, 184, 0.2);
  border-color: rgba(0, 168, 184, 0.5);
}