/*
 * TrackSorter Bootstrap 5 Custom Styles
 * Shared across all TrackSorter interfaces
 * Compatible with dark/light themes
 */

/* ===================================
   CSS Variables (Theme-aware)
   =================================== */
:root {
  /* Bootstrap Color Overrides - TrackSorter Palette */
  --bs-primary: #6EA8FE;
  --bs-primary-rgb: 110, 168, 254;
  --bs-success: #198754;
  --bs-success-rgb: 25, 135, 84;
  --bs-warning: #FFC107;
  --bs-warning-rgb: 255, 193, 7;
  --bs-info: #00ffff;
  --bs-info-rgb: 0, 255, 255;

  /* TrackSorter Custom Variables */
  --ts-card-radius: 16px;
  --ts-transition-speed: 0.2s;
  --ts-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
  --ts-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --ts-shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.15);
}

[data-bs-theme="dark"] {
  --ts-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --ts-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --ts-shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.5);
}

/* ===================================
   Card Components
   =================================== */
.card {
  border-radius: var(--ts-card-radius);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  border: 1px solid var(--bs-border-color);
  transition: transform var(--ts-transition-speed) ease,
              box-shadow var(--ts-transition-speed) ease;
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--ts-shadow-md);
}

/* ===================================
   Hero Section (Gradient background)
   =================================== */
.ts-hero {
  border-radius: 18px;
  padding: 3rem;
  background-color: var(--bs-body-bg);
  background-image:
    radial-gradient(1200px 400px at 10% -10%, color-mix(in oklab, var(--bs-success) 30%, transparent), transparent 60%),
    radial-gradient(1200px 400px at 100% 0%, color-mix(in oklab, var(--bs-primary) 25%, transparent), transparent 60%);
  border: 1px solid var(--bs-border-color);
}

/* ===================================
   Link Tiles (Interactive cards)
   =================================== */
.ts-link-tile {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform var(--ts-transition-speed) ease;
}

.ts-link-tile:hover {
  transform: translateY(-2px);
  color: inherit;
}

/* ===================================
   Badges (Theme-aware)
   =================================== */
.badge-active {
  background: var(--bs-success);
  color: white;
}

.badge-expired {
  background: var(--bs-danger);
  color: white;
}

.badge-warning {
  background: var(--bs-warning);
  color: var(--bs-dark);
}

/* ===================================
   Tables (Enhanced styling)
   =================================== */
.table thead th {
  background-color: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
  border-bottom: 1px solid var(--bs-border-color);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.875rem;
  letter-spacing: 0.5px;
}

.table tbody tr {
  transition: background-color var(--ts-transition-speed) ease;
}

.table tbody tr:hover {
  background-color: var(--bs-tertiary-bg);
}

/* ===================================
   Navbar (Sticky with blur)
   =================================== */
.navbar {
  background: var(--bs-body-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.navbar .nav-link {
  transition: color var(--ts-transition-speed) ease;
}

.navbar .nav-link.active {
  color: var(--bs-emphasis-color);
  font-weight: 500;
}

/* ===================================
   Buttons (Enhanced states)
   =================================== */
.btn {
  transition: all var(--ts-transition-speed) ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--ts-shadow-sm);
}

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

/* btn-primary override for correct TrackSorter blue */
.btn-primary {
  --bs-btn-bg: #6EA8FE;
  --bs-btn-border-color: #6EA8FE;
  --bs-btn-hover-bg: #9ec5fe;
  --bs-btn-hover-border-color: #9ec5fe;
  --bs-btn-active-bg: #5a9bd4;
  --bs-btn-active-border-color: #5a9bd4;
  --bs-btn-disabled-bg: #6EA8FE;
  --bs-btn-disabled-border-color: #6EA8FE;
}

/* btn-outline-primary override */
.btn-outline-primary {
  --bs-btn-color: #6EA8FE;
  --bs-btn-border-color: #6EA8FE;
  --bs-btn-hover-color: #000;
  --bs-btn-hover-bg: #6EA8FE;
  --bs-btn-hover-border-color: #6EA8FE;
  --bs-btn-active-color: #000;
  --bs-btn-active-bg: #6EA8FE;
  --bs-btn-active-border-color: #6EA8FE;
}

/* ===================================
   Alerts (Theme colors)
   =================================== */
.alert-info {
  --bs-alert-color: #6EA8FE;
  --bs-alert-bg: rgba(110, 168, 254, 0.15);
  --bs-alert-border-color: #6EA8FE;
  color: #6EA8FE;
  background-color: rgba(110, 168, 254, 0.15);
  border-color: #6EA8FE;
}

.alert-info .btn-primary,
.alert-info .btn-info {
  background-color: #6EA8FE;
  border-color: #6EA8FE;
  color: #fff;
}

.alert-info .btn-primary:hover,
.alert-info .btn-info:hover {
  background-color: #5a9bd4;
  border-color: #5a9bd4;
}

.alert-info .alert-link {
  color: #5a9bd4;
}

.alert-success {
  --bs-alert-color: #198754;
  --bs-alert-bg: rgba(25, 135, 84, 0.15);
  --bs-alert-border-color: #198754;
  color: #198754;
  background-color: rgba(25, 135, 84, 0.15);
  border-color: #198754;
}

.alert-success .btn-success {
  background-color: #198754;
  border-color: #198754;
  color: #fff;
}

.alert-success .btn-success:hover {
  background-color: #157347;
  border-color: #157347;
}

.alert-success .alert-link {
  color: #157347;
}

.alert-warning {
  --bs-alert-color: #FFC107;
  --bs-alert-bg: rgba(255, 193, 7, 0.15);
  --bs-alert-border-color: #FFC107;
  color: #FFC107;
  background-color: rgba(255, 193, 7, 0.15);
  border-color: #FFC107;
}

.alert-warning .btn-warning {
  background-color: #FFC107;
  border-color: #FFC107;
  color: #000;
}

.alert-warning .btn-warning:hover {
  background-color: #e0a800;
  border-color: #e0a800;
}

.alert-danger {
  --bs-alert-color: #DC3545;
  --bs-alert-bg: rgba(220, 53, 69, 0.15);
  --bs-alert-border-color: #DC3545;
  color: #DC3545;
  background-color: rgba(220, 53, 69, 0.15);
  border-color: #DC3545;
}

.alert-danger .btn-danger {
  background-color: #DC3545;
  border-color: #DC3545;
  color: #fff;
}

.alert-danger .btn-danger:hover {
  background-color: #bb2d3b;
  border-color: #bb2d3b;
}

/* ===================================
   Form Controls (Consistent styling)
   =================================== */
.form-control:focus,
.form-select:focus {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}

/* ===================================
   Progress Bars
   =================================== */
.progress {
  height: 8px;
  border-radius: 4px;
  background-color: var(--bs-secondary-bg);
}

.progress-bar {
  transition: width 0.6s ease;
  border-radius: 4px;
}

/* ===================================
   Loading States
   =================================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-spinner {
  width: 3rem;
  height: 3rem;
}

/* ===================================
   Empty States
   =================================== */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--bs-secondary-color);
}

.empty-state i {
  font-size: 4rem;
  opacity: 0.3;
  margin-bottom: 1rem;
}

/* ===================================
   Stat Cards (Dashboard)
   =================================== */
.stat-card {
  padding: 1.5rem;
  border-radius: var(--ts-card-radius);
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  transition: all var(--ts-transition-speed) ease;
}

.stat-card:hover {
  border-color: var(--bs-primary);
  box-shadow: var(--ts-shadow-sm);
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--bs-primary);
}

.stat-card .stat-label {
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0.5rem;
}

/* ===================================
   Utility Classes
   =================================== */
.text-gradient {
  background: linear-gradient(135deg, var(--bs-primary), var(--bs-info));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.shadow-sm-hover:hover {
  box-shadow: var(--ts-shadow-sm);
}

.shadow-md-hover:hover {
  box-shadow: var(--ts-shadow-md);
}

/* ===================================
   Responsive Utilities
   =================================== */
@media (max-width: 768px) {
  .ts-hero {
    padding: 2rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-card .stat-value {
    font-size: 1.5rem;
  }
}

/* ===================================
   Dark Theme Specific Adjustments
   =================================== */
[data-bs-theme="dark"] .card {
  background: color-mix(in srgb, var(--bs-body-bg) 95%, white 5%);
}

[data-bs-theme="dark"] .navbar {
  background: rgba(var(--bs-body-bg-rgb), 0.8);
}

/* ===================================
   Light Theme Specific Adjustments
   =================================== */
[data-bs-theme="light"] .ts-hero {
  background-image:
    radial-gradient(1200px 400px at 10% -10%, color-mix(in oklab, var(--bs-success) 15%, transparent), transparent 60%),
    radial-gradient(1200px 400px at 100% 0%, color-mix(in oklab, var(--bs-primary) 12%, transparent), transparent 60%);
}

/* ===================================
   Animations
   =================================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

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

.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ===================================
   Statistics Section
   =================================== */
.stat-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;
}

.stat-number {
  line-height: 1;
  transition: transform 0.3s ease;
}

.stat-card:hover .stat-number {
  transform: scale(1.1);
}

.stat-description {
  color: var(--bs-body-color);
  font-weight: 500;
}

/* ===================================
   AI Demo Section
   =================================== */
.demo-image-wrapper {
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.demo-image-container {
  position: relative;
  width: 100%;
  min-height: 500px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.demo-image {
  width: 100%;
  height: auto;
  display: block;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.demo-image.loaded {
  opacity: 1;
}

/* Scan line animation */
.scan-line {
  position: absolute;
  top: -100%;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(110, 168, 254, 0.8) 50%,
    transparent 100%);
  box-shadow: 0 0 20px rgba(110, 168, 254, 0.8);
  opacity: 0;
  z-index: 10;
}

.demo-image-container.scanning .scan-line {
  animation: scanDown 2s ease-in-out forwards;
  opacity: 1;
}

@keyframes scanDown {
  0% {
    top: -100%;
  }
  100% {
    top: 100%;
  }
}

/* Detection boxes - inspired by workspace style */
.detection-box {
  position: absolute;
  border: 3px solid;
  border-radius: 6px;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  z-index: 5;
}

.detection-box.visible {
  opacity: 1;
  transform: scale(1);
}

.detection-box::before {
  content: attr(data-label);
  position: absolute;
  top: -32px;
  left: 0;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease 0.2s;
}

.detection-box.visible::before {
  opacity: 1;
  transform: translateY(0);
}

/* Detection box colors */
.detection-box[data-color="primary"] {
  border-color: #6EA8FE;
}

.detection-box[data-color="primary"]::before {
  background: #6EA8FE;
}

.detection-box[data-color="success"] {
  border-color: #198754;
}

.detection-box[data-color="success"]::before {
  background: #198754;
}

.detection-box[data-color="warning"] {
  border-color: #FFC107;
}

.detection-box[data-color="warning"]::before {
  background: #FFC107;
}

.detection-box[data-color="info"] {
  border-color: #00ffff;
}

.detection-box[data-color="info"]::before {
  background: #00ffff;
}

.detection-box[data-color="sponsor"] {
  border-color: #9b59b6;
}

.detection-box[data-color="sponsor"]::before {
  background: #9b59b6;
}

/* Nav pills styling */
.nav-pills .nav-link {
  color: var(--bs-body-color);
  background: transparent;
  border: 1px solid var(--bs-border-color);
  transition: all 0.3s ease;
}

.nav-pills .nav-link:hover {
  background: var(--bs-tertiary-bg);
  border-color: var(--bs-primary);
}

.nav-pills .nav-link.active {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
  color: #fff;
}

/* ===================================
   Upload & See Demo Section
   =================================== */
.upload-demo-zone {
  background: var(--bs-body-bg);
  transition: all 0.3s ease;
  cursor: not-allowed;
}

.upload-demo-zone:hover {
  border-color: var(--bs-primary) !important;
  background: var(--bs-tertiary-bg);
}

.results-demo-zone {
  background: var(--bs-body-bg);
}

.placeholder-box {
  animation: placeholderPulse 1.5s ease-in-out infinite;
}

@keyframes placeholderPulse {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.8;
  }
}

.border-dashed {
  border-style: dashed !important;
}

/* ===================================
   Pixel/Reveal Animation
   =================================== */
.demo-image-container.revealing .demo-image {
  animation: pixelReveal 1.5s ease-out forwards;
}

@keyframes pixelReveal {
  0% {
    filter: blur(20px) brightness(0.5);
    transform: scale(1.1);
  }
  100% {
    filter: blur(0) brightness(1);
    transform: scale(1);
  }
}

/* ===================================
   Responsive Adjustments
   =================================== */
@media (max-width: 768px) {
  .demo-image-container {
    min-height: 300px;
  }

  .detection-box::before {
    font-size: 11px;
    padding: 4px 8px;
    top: -26px;
  }

  .stat-number {
    font-size: 2.5rem !important;
  }

  .nav-pills .nav-link {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
  }
}

/* ===================================
   Pricing Table - Alignment & Responsive
   =================================== */
/* Base styles for strict row alignment */
.pricing-feature-row {
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  line-height: 44px !important;
  overflow: hidden;
  box-sizing: border-box;
}

/* Feature labels column - strict alignment */
.card-body .list-unstyled li[style*="height: 44px"] {
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  line-height: 44px !important;
  overflow: hidden;
  box-sizing: border-box;
}

/* Sur mobile (< lg breakpoint): afficher label a gauche, valeur a droite */
@media (max-width: 991.98px) {
  .pricing-feature-row {
    justify-content: space-between !important;
    padding: 0 8px;
  }

  .pricing-feature-label {
    max-width: 55%;
    font-size: 0.7rem !important;
    line-height: 1.2;
    text-align: left !important;
  }

  .pricing-feature-value {
    text-align: right !important;
    flex-shrink: 0;
  }

  .pricing-feature-value .fw-bold {
    font-size: 0.75rem !important;
  }

  .pricing-feature-value .text-muted {
    font-size: 0.65rem !important;
  }

  .pricing-badge-once {
    font-size: 0.5rem !important;
    padding: 1px 3px !important;
    display: inline-block;
    margin-left: 2px;
    white-space: nowrap;
    line-height: 1.2 !important;
    vertical-align: middle;
  }
}

/* Sur desktop (>= lg breakpoint): centrer les valeurs, masquer les labels */
@media (min-width: 992px) {
  .pricing-feature-row {
    justify-content: center !important;
  }

  .pricing-feature-value {
    text-align: center;
  }

  .pricing-badge-once {
    font-size: 0.6rem;
    white-space: nowrap;
    line-height: 1.2 !important;
    vertical-align: middle;
  }
}
