/*
Car Damage Detection Frontend Styles
Modern, responsive design with dark theme and glassmorphism effects
*/

/* CSS Variables for consistent theming */
:root {
  --primary-color: #1e40af;
  --secondary-color: #10b981;
  --accent-color: #f59e0b;
  --danger-color: #ef4444;
  --success-color: #22c55e;
  --warning-color: #f59e0b;
  --info-color: #06b6d4;

  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-glass: rgba(30, 41, 59, 0.8);

  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --border-color: rgba(148, 163, 184, 0.2);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  --border-radius: 0.5rem;
  --border-radius-lg: 0.75rem;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.header {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
}

.header h1 {
  color: var(--primary-color);
  font-size: 1.5rem;
  font-weight: 700;
}

.header h1 i {
  margin-right: 0.5rem;
}

/* Status Indicator */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
}

.status.connected {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success-color);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.status.disconnected {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger-color);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.status.connecting {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning-color);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Main Content */
.main {
  padding: 2rem 0;
  min-height: calc(100vh - 140px);
}

/* Camera Section */
.camera-section {
  margin-bottom: 2rem;
}

.camera-container {
  position: relative;
  max-width: 800px;
  margin: 0 auto;
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

#videoElement {
  width: 100%;
  height: auto;
  max-width: 800px;
  /* Reasonable display size limit */
  display: block;
  background: var(--bg-tertiary);
  object-fit: contain;
  /* Maintain aspect ratio */
}

#detectionCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  /* Scale with video element */
  height: 100%;
  pointer-events: none;
  z-index: 10;
  object-fit: contain;
  /* Maintain aspect ratio and sync with video */
  /* Canvas resolution (1280x720) set by JavaScript, CSS handles display scaling */
}

/* Camera Overlay */
.camera-overlay {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.camera-info {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.camera-info span {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  padding: 0.25rem 0.75rem;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border-color);
}

.processing-indicator {
  color: var(--accent-color);
  animation: pulse 2s infinite;
}

/* Permission and Error Overlays */
.permission-overlay,
.error-overlay {
  /* position: absolute; */
  inset: 0;
  background: var(--bg-glass);
  backdrop-filter: blur(10px);

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 16px;
  box-sizing: border-box;
  overflow: auto;

  z-index: 20;
}

.permission-content,
.error-content {
  text-align: center;
  padding: 2rem;
  max-width: 300px;
}

.permission-content i,
.error-content i {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.permission-content h3,
.error-content h3 {
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.permission-content p,
.error-content p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

/* Controls Section */
.controls-section {
  margin-bottom: 2rem;
}

.controls-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.control-group {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.5rem;
}

.control-group h3 {
  color: var(--text-primary);
  margin-bottom: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.control-group h3 i {
  margin-right: 0.5rem;
  color: var(--primary-color);
}

/* Control Items */
.control-item {
  margin-bottom: 1.5rem;
}

.control-item:last-child {
  margin-bottom: 0;
}

.control-item label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.slider-container input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
}

.slider-container input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--secondary-color);
  transform: scale(1.1);
}

.slider-container span {
  color: var(--accent-color);
  font-weight: 600;
  font-size: 0.875rem;
  min-width: 60px;
  text-align: center;
}

/* Performance Display */
.performance-display {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

.performance-value {
  color: var(--success-color);
  font-weight: 700;
  font-size: 1.125rem;
  text-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

.performance-detail {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 400;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  background: transparent;
  color: var(--text-primary);
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

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

.btn-secondary:hover {
  background: var(--bg-secondary);
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover {
  background: #16a34a;
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-info {
  background: var(--info-color);
  color: white;
}

.btn-info:hover {
  background: #0891b2;
}

.control-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Statistics Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.stat-item {
  text-align: center;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.stat-label {
  display: block;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  display: block;
  color: var(--accent-color);
  font-size: 1.25rem;
  font-weight: 700;
}

/* Damage Legend */
.damage-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  font-size: 0.875rem;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* Recent Detections */
.recent-detections {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.5rem;
}

.recent-detections h3 {
  color: var(--text-primary);
  margin-bottom: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.recent-detections h3 i {
  margin-right: 0.5rem;
  color: var(--primary-color);
}

.detections-list {
  max-height: 300px;
  overflow-y: auto;
}

.no-detections {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.no-detections i {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.detection-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.detection-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.detection-color {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.detection-details {
  display: flex;
  flex-direction: column;
}

.detection-class {
  font-weight: 500;
  color: var(--text-primary);
}

.detection-confidence {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.detection-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 1rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Utility Classes */
.hidden {
  display: none !important;
}

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

.pulse {
  animation: pulse 2s infinite;
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 1rem;
  }

  .camera-overlay {
    flex-direction: column;
    gap: 0.5rem;
  }

  .controls-container {
    grid-template-columns: 1fr;
  }

  .control-buttons {
    flex-direction: column;
  }

  .btn {
    justify-content: center;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .damage-legend {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Toggle Switch Styles */
.toggle-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toggle-input {
  display: none;
}

.toggle-label {
  position: relative;
  width: 48px;
  height: 24px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border-color);
}

.toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: var(--transition);
  transform: translateX(0);
}

.toggle-input:checked+.toggle-label {
  background: var(--success-color);
}

.toggle-input:checked+.toggle-label .toggle-slider {
  background: white;
  transform: translateX(22px);
}

.toggle-label:hover {
  opacity: 0.9;
}

/* Detection Gallery - Unified Recent Detections & Images */
.detection-gallery {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.5rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.section-header h3 {
  color: var(--text-primary);
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.section-header h3 i {
  margin-right: 0.5rem;
  color: var(--primary-color);
}

.gallery-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.gallery-count {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.25rem 0.75rem;
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.detections-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.detection-item-enhanced {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
}

.detection-item-enhanced:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-color);
}

.detection-thumbnail {
  position: relative;
  width: 100%;
  height: 160px;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.detection-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
}

.detection-thumbnail .no-image {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.detection-thumbnail .no-image i {
  font-size: 2rem;
  opacity: 0.5;
}

.detection-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  padding: 0.25rem 0.5rem;
  border-radius: var(--border-radius);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--success-color);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.detection-badge.not-saved {
  color: var(--text-muted);
  border-color: var(--border-color);
}

.detection-meta {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.detection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detection-class-enhanced {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  color: var(--text-primary);
}

.detection-color-enhanced {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.detection-confidence-enhanced {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent-color);
}

.detection-details-enhanced {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.detection-area {
  font-weight: 500;
}

.detection-timestamp {
  font-style: italic;
}

/* Image Modal for Full-size View */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.image-modal.active {
  display: flex;
}

.modal-content {
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
}

.modal-image {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: -3rem;
  right: 0;
  background: var(--danger-color);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  transition: var(--transition);
}

.modal-close:hover {
  background: #dc2626;
  transform: scale(1.1);
}

.modal-info {
  position: absolute;
  bottom: -4rem;
  left: 0;
  right: 0;
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  padding: 1rem;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  text-align: center;
}

@media (max-width: 480px) {
  .container {
    padding: 0 0.5rem;
  }

  .main {
    padding: 1rem 0;
  }

  .control-group {
    padding: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .damage-legend {
    grid-template-columns: 1fr;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .detections-gallery {
    grid-template-columns: 1fr;
  }

  .gallery-controls {
    width: 100%;
    justify-content: space-between;
  }
}