/**
 * GridView Theme System
 * Core styles that consume CSS custom properties from theme files
 * This file applies the theme variables to actual UI elements
 */

/* ============================================
   TRANSITIONS - Smooth theme switching
   ============================================ */
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition: 
    background-color 0.4s ease,
    background 0.4s ease,
    border-color 0.4s ease,
    color 0.3s ease,
    box-shadow 0.4s ease,
    fill 0.3s ease !important;
}

/* ============================================
   BASE STYLES
   ============================================ */
body {
  background: var(--theme-gradient-body);
  color: var(--theme-text-primary);
  font-family: var(--theme-font-body, 'Inter', system-ui, sans-serif);
  letter-spacing: var(--theme-body-letter-spacing, 0);
  min-height: 100vh;
}

/* ============================================
   TYPOGRAPHY - Theme-aware headings
   ============================================ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--theme-font-heading, 'Inter', system-ui, sans-serif);
  font-weight: var(--theme-heading-weight, 700);
  letter-spacing: var(--theme-heading-letter-spacing, -0.01em);
  text-shadow: var(--theme-heading-shadow, none);
}

/* Hero title special treatment */
h1 {
  font-weight: var(--theme-heading-weight, 800);
}

/* Monospace elements */
code, pre, .font-mono {
  font-family: var(--theme-font-mono, 'JetBrains Mono', monospace);
}

/* ============================================
   HEADER & NAVIGATION
   ============================================ */
header {
  position: relative;
  background: var(--theme-bg-base);
}

header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--theme-gradient-hero);
  pointer-events: none;
}

nav {
  position: relative;
  z-index: 10;
}

nav a {
  color: var(--theme-text-secondary);
  transition: color 0.2s ease;
}

nav a:hover {
  color: var(--theme-text-primary);
}

/* Logo styling */
.gridview-logo {
  color: var(--theme-text-primary);
  font-weight: 700;
}

.gridview-logo-icon {
  background-color: var(--theme-primary);
}

/* Nav buttons */
.nav-btn {
  background: var(--theme-btn-secondary-bg);
  border: 1px solid var(--theme-border-subtle);
  color: var(--theme-text-secondary);
  transition: all 0.2s ease;
}

.nav-btn:hover {
  border-color: rgba(var(--theme-primary-rgb), 0.5);
  background: var(--theme-btn-secondary-hover);
}

/* ============================================
   CARDS - Major visual element
   ============================================ */
.theme-card {
  background: var(--theme-bg-card);
  border: 1px solid var(--theme-border-subtle);
  transition: all 0.25s ease;
}

.theme-card:hover {
  transform: translateY(-2px);
  border-color: rgba(var(--theme-primary-rgb), 0.4);
  box-shadow: var(--theme-shadow-hover);
}

/* Series cards - Primary interaction elements */
.series-card {
  background: var(--theme-bg-card) !important;
  border: 1px solid var(--theme-border-subtle) !important;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.series-card:hover {
  border-color: rgba(var(--theme-primary-rgb), 0.5) !important;
  box-shadow: var(--theme-shadow-hover) !important;
  transform: translateY(-2px);
}

.series-card.active {
  border-color: var(--theme-primary) !important;
  box-shadow: var(--theme-glow) !important;
  background: var(--theme-gradient-card) !important;
}

.series-card.active .card-icon {
  background-color: rgba(var(--theme-primary-rgb), 0.3) !important;
}

.card-icon {
  background-color: var(--theme-bg-base);
  transition: background-color 0.2s ease;
}

.series-card:hover .card-icon {
  background-color: rgba(var(--theme-primary-rgb), 0.2);
}

/* ============================================
   DATA TABLES & ROWS
   ============================================ */
.data-row {
  transition: background-color 0.15s ease;
}

.data-row:hover {
  background-color: var(--theme-bg-hover);
}

.data-row:nth-child(even) {
  background-color: rgba(var(--theme-primary-rgb), 0.03);
}

/* ============================================
   POSITION BADGES - Podium styling
   ============================================ */
.position-badge {
  min-width: 2rem;
  text-align: center;
  font-weight: 600;
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
}

.position-1 {
  background: var(--theme-pos-1-bg);
  color: var(--theme-pos-1-text);
}

.position-2 {
  background: var(--theme-pos-2-bg);
  color: var(--theme-pos-2-text);
}

.position-3 {
  background: var(--theme-pos-3-bg);
  color: var(--theme-pos-3-text);
}

/* ============================================
   BUTTONS - Primary & Secondary
   ============================================ */
.btn-primary {
  background: var(--theme-btn-primary-bg);
  color: var(--theme-btn-primary-text);
  border: 1px solid var(--theme-primary);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: var(--theme-btn-primary-hover);
  box-shadow: var(--theme-glow);
}

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

.btn-secondary:hover {
  background: var(--theme-btn-secondary-hover);
  border-color: var(--theme-primary);
}

/* Tab buttons - Important for navigation */
.tab-btn {
  transition: all 0.2s ease;
  border: 1px solid var(--theme-border);
  color: var(--theme-text-secondary);
  background: transparent;
}

.tab-btn.active {
  background-color: rgba(var(--theme-primary-rgb), 0.2);
  color: var(--theme-primary);
  border-color: var(--theme-primary);
  box-shadow: 0 0 10px rgba(var(--theme-primary-rgb), 0.2);
}

.tab-btn:hover:not(.active) {
  background-color: var(--theme-bg-hover);
  border-color: rgba(var(--theme-primary-rgb), 0.3);
}

/* ============================================
   LIVE INDICATOR - Attention-grabbing
   ============================================ */
.live-pulse {
  animation: pulse 2s ease-in-out infinite;
  background-color: var(--theme-live-color) !important;
  box-shadow: 0 0 8px var(--theme-live-color);
}

.live-text {
  color: var(--theme-live-color);
}

@keyframes pulse {
  0%, 100% { 
    opacity: 1;
    box-shadow: 0 0 8px var(--theme-live-color);
  }
  50% { 
    opacity: 0.6;
    box-shadow: 0 0 15px var(--theme-live-color);
  }
}

/* ============================================
   BORDERS & DIVIDERS
   ============================================ */
.theme-border {
  border-color: var(--theme-border);
}

.theme-divider {
  background-color: var(--theme-border);
}

/* ============================================
   TEXT COLORS - Theme-aware
   ============================================ */
.text-theme-primary {
  color: var(--theme-text-primary);
}

.text-theme-secondary {
  color: var(--theme-text-secondary);
}

.text-theme-muted {
  color: var(--theme-text-muted);
}

.text-theme-accent {
  color: var(--theme-text-accent);
}

/* ============================================
   AD SLOTS
   ============================================ */
.ad-slot {
  background: var(--theme-gradient-card);
  border: 1px dashed var(--theme-border);
  color: var(--theme-text-muted);
}

/* ============================================
   SCROLLBARS
   ============================================ */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--theme-scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--theme-scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--theme-scrollbar-hover);
}

/* Firefox scrollbar support */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--theme-scrollbar-thumb, #4a4a55) var(--theme-scrollbar-track, #16161d);
}

/* ============================================
   ACCENT PATTERNS
   ============================================ */
.checkered-accent {
  background-image: var(--theme-accent-pattern);
  background-size: 8px 8px;
}

/* Hero stripe decoration */
.hero-stripe {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--theme-stripe-pattern);
  opacity: 0.8;
}

/* ============================================
   THEME SWITCHER UI - Critical for usability
   ============================================ */
.theme-switcher {
  position: relative;
  z-index: 100;
}

.theme-switcher-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: var(--theme-btn-secondary-bg);
  border: 1px solid var(--theme-border-subtle);
  border-radius: 0.5rem;
  color: var(--theme-text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-switcher-btn:hover {
  border-color: rgba(var(--theme-primary-rgb), 0.5);
  background: var(--theme-btn-secondary-hover);
  color: var(--theme-text-primary);
}

/* Mode toggle button (light/dark) */
.mode-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  background: var(--theme-btn-secondary-bg);
  border: 1px solid var(--theme-border-subtle);
  border-radius: 0.5rem;
  color: var(--theme-text-secondary);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-toggle-btn:hover {
  border-color: rgba(var(--theme-primary-rgb), 0.5);
  background: var(--theme-btn-secondary-hover);
  transform: scale(1.05);
}

.mode-toggle-btn:active {
  transform: scale(0.95);
}

.mode-icon {
  transition: transform 0.3s ease;
}

.mode-toggle-btn:hover .mode-icon {
  transform: rotate(15deg);
}

.mode-icon.mode-transitioning {
  animation: mode-spin 0.3s ease;
}

@keyframes mode-spin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

/* Dialog element - uses browser's top-layer (guaranteed above everything) */
.theme-dialog {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  overflow: visible;
}

.theme-dialog::backdrop {
  background: transparent;
}

.theme-dropdown {
  position: fixed;
  top: auto;
  right: 1rem;
  margin-top: 0.5rem;
  min-width: 220px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--theme-bg-base, #0a0a0f);
  border: 1px solid var(--theme-border);
  border-radius: 0.75rem;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.8);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) scale(0.95);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* THEME OPTIONS - Must be clearly clickable! */
.theme-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  color: var(--theme-text-primary);
  font-size: 0.875rem;
  font-weight: 500;
}

.theme-option:hover {
  background: var(--theme-bg-hover);
  padding-left: 1.25rem;
}

.theme-option:active {
  background: rgba(var(--theme-primary-rgb), 0.2);
  transform: scale(0.98);
}

.theme-option.active {
  background: rgba(var(--theme-primary-rgb), 0.2);
  border-left: 3px solid var(--theme-primary);
  padding-left: calc(1rem - 3px);
}

.theme-option.active::after {
  content: '✓';
  margin-left: auto;
  color: var(--theme-primary);
  font-weight: 700;
}

/* Theme swatches - Visual preview */
.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--theme-border);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Theme swatches - Accurate representations */
/* Dark theme swatches */
.swatch-default { 
  background: linear-gradient(135deg, #e10600 50%, #0a0a0f 50%); 
}
.swatch-gulf { 
  background: linear-gradient(135deg, #5BA3D9 50%, #F26522 50%); 
}
.swatch-marlboro { 
  background: linear-gradient(135deg, #EE1C25 50%, #1a1a1a 50%); 
}
.swatch-silk-cut { 
  background: linear-gradient(135deg, #9B59B6 50%, #D4AF37 50%); 
}
.swatch-camel { 
  background: linear-gradient(135deg, #F4C430 50%, #1E3A5F 50%); 
}
.swatch-rothmans { 
  background: linear-gradient(135deg, #0044AA 50%, #D4AF37 50%); 
}
.swatch-jps { 
  background: linear-gradient(135deg, #000000 50%, #D4AF37 50%); 
}

/* Light theme swatches */
.swatch-light { 
  background: linear-gradient(135deg, #ffffff 50%, #e10600 50%); 
}
.swatch-gulf-light { 
  background: linear-gradient(135deg, #ffffff 50%, #5BA3D9 50%); 
}
.swatch-marlboro-light { 
  background: linear-gradient(135deg, #ffffff 50%, #EE1C25 50%); 
}
.swatch-jps-light { 
  background: linear-gradient(135deg, #fffef8 50%, #D4AF37 50%); 
}
.swatch-silk-cut-light { 
  background: linear-gradient(135deg, #fdfbfe 50%, #9B59B6 50%); 
}
.swatch-camel-light { 
  background: linear-gradient(135deg, #fffef5 50%, #F4C430 50%); 
}
.swatch-rothmans-light { 
  background: linear-gradient(135deg, #f8faff 50%, #0044AA 50%); 
}
.swatch-martini { 
  background: linear-gradient(135deg, 
    #FFFFFF 0%, #FFFFFF 33%,
    #0033A0 33%, #0033A0 50%,
    #CE1126 50%, #CE1126 67%,
    #FFFFFF 67%, #FFFFFF 100%
  ); 
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .theme-dropdown {
    right: auto;
    left: 50%;
    transform: translateX(-50%) translateY(-10px) scale(0.95);
  }
  
  .theme-dropdown.open {
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

/* ============================================
   FOCUS STATES - Accessibility
   ============================================ */
.theme-option:focus-visible,
.theme-switcher-btn:focus-visible {
  outline: 2px solid var(--theme-primary);
  outline-offset: 2px;
}

/* Global focus-visible styles for all interactive elements */
button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--theme-primary);
  outline-offset: 2px;
}

/* Remove default focus ring, use focus-visible only */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================
   RACING BACKGROUND PATTERN (optional use)
   ============================================ */
.racing-pattern {
  background-image: var(--theme-accent-pattern);
}

/* ============================================
   GLOW EFFECTS
   ============================================ */
.theme-glow {
  box-shadow: var(--theme-glow);
}

.theme-glow-hover:hover {
  box-shadow: var(--theme-glow);
}
