/* Base Styles and CSS Reset */
:root {
  /* Color System */
  --color-primary: #007AFF;
  --color-primary-dark: #0062CC;
  --color-primary-light: #4CA5FF;
  
  --color-secondary: #8E8E93;
  --color-secondary-dark: #636366;
  --color-secondary-light: #AEAEB2;
  
  --color-accent: #FF3B30;
  --color-accent-dark: #D70015;
  --color-accent-light: #FF6961;
  
  --color-success: #34C759;
  --color-warning: #FF9500;
  --color-error: #FF3B30;
  
  --color-background: #FFFFFF;
  --color-background-secondary: #F2F2F7;
  --color-text: #000000;
  --color-text-secondary: #3C3C43;
  --color-text-tertiary: #8E8E93;
  --color-border: #D1D1D6;
  
  /* Spacing System (8px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Border Radius */
  --radius-small: 6px;
  --radius-medium: 10px;
  --radius-large: 16px;
  
  /* Shadows */
  --shadow-small: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-medium: 0 4px 8px rgba(0, 0, 0, 0.1);
  --shadow-large: 0 8px 16px rgba(0, 0, 0, 0.1);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-medium: 300ms ease;
  --transition-slow: 500ms ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  color: var(--color-text);
  background-color: var(--color-background-secondary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: var(--space-2);
}

h1 {
  font-size: 1.75rem;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

p {
  margin-bottom: var(--space-2);
}

.subtitle {
  color: var(--color-text-tertiary);
  font-size: 0.9rem;
}

/* Header */
.app-header {
  background-color: var(--color-background);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4) 0;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-small);
}

.app-header h1 {
  margin-bottom: var(--space-1);
}

/* Scanner UI */
.scanner-ui {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner-ui.hidden {
  display: none;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner-region {
  width: 80%;
  max-width: 300px;
  aspect-ratio: 1;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-medium);
  position: relative;
}

.scanner-region::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: var(--color-primary);
  opacity: 0.5;
  animation: scan 2s linear infinite;
}

@keyframes scan {
  from { transform: translateY(-100px); }
  to { transform: translateY(100px); }
}

.close-scanner {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  background-color: var(--color-background);
  color: var(--color-text);
  border: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-medium);
  font-weight: 600;
  cursor: pointer;
  z-index: 1001;
}

.scan-button {
  background-color: var(--color-primary);
  color: white;
  border: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-medium);
  font-weight: 600;
  cursor: pointer;
  margin-top: var(--space-2);
  transition: background-color var(--transition-fast);
}

.scan-button:hover {
  background-color: var(--color-primary-dark);
}

/* Product List */
.product-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

.product-card {
  background-color: var(--color-background);
  border-radius: var(--radius-medium);
  overflow: hidden;
  box-shadow: var(--shadow-small);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
}

.product-card:hover, .product-card:focus {
  transform: translateY(-4px);
  box-shadow: var(--shadow-medium);
}

.product-card:active {
  transform: translateY(-2px);
  box-shadow: var(--shadow-small);
}

.product-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-bottom: 1px solid var(--color-border);
}

.product-card-content {
  padding: var(--space-2);
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.product-card h3 {
  font-size: 0.9rem;
  margin-bottom: var(--space-1);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-card-price {
  font-weight: 600;
  color: var(--color-primary);
  margin-top: auto;
}

/* Loading State */
.loading {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-5) 0;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(0, 122, 255, 0.2);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: var(--space-3);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Modal */
.product-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: visibility var(--transition-medium), opacity var(--transition-medium);
}

.product-modal.active {
  visibility: visible;
  opacity: 1;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-container {
  position: relative;
  width: 90%;
  /* max-width: 500px; */
  max-height: 90vh;
  background-color: var(--color-background);
  border-radius: var(--radius-large);
  overflow: hidden;
  overflow-y: auto;
  box-shadow: var(--shadow-large);
  transform: translateY(20px);
  transition: transform var(--transition-medium);
  -webkit-overflow-scrolling: touch;
}

.product-modal.active .modal-container {
  transform: translateY(0);
}

.modal-header {
  position: absolute;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2);
  background-color: rgba(0, 0, 0, 0.6);
  border-bottom: 1px solid var(--color-border);
  z-index: 1;
  width: 100%;
  color: #fff;
}

.close-button {
  background: none;
  border: none;
  color: var(--color-text-tertiary);
  font-size: 1.5rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
}

.close-button:hover {
  background-color: var(--color-background-secondary);
}

.modal-content {
  padding:0;
}

.product-image-container {
  margin-bottom: var(--space-3);
  border-radius: var(--radius-medium);
  overflow: hidden;
}

.product-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.product-price {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}

.product-barcode {
  font-size: 0.8rem;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-3);
}

.product-description {
  margin-bottom: var(--space-4);
  line-height: 1.6;
}

/* Video section */
.product-video {
  margin-top: 0;
}

.video-container {
  position: relative;
  border-radius: var(--radius-medium);
  overflow: hidden;
  background-color: #000;
  aspect-ratio: 9/16;
  margin-top: 0;
}

#video-placeholder {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #000;
}

.video-play-button {
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.video-play-button:hover {
  transform: scale(1.1);
}

#video-iframe-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#video-iframe-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.hidden {
  display: none;
}

/* Footer */
.app-footer {
  background-color: var(--color-background);
  border-top: 1px solid var(--color-border);
  padding: var(--space-4) 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-text-tertiary);
  margin-top: var(--space-4);
}

/* Responsive Adjustments */
@media (max-width: 480px) {
  .product-list {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-2);
  }
  
  h1 {
    font-size: 1.5rem;
  }
  
  .modal-container {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }
}

@media (min-width: 768px) {
  .product-list {
    grid-template-columns: repeat(3, 1fr);
  }
  
  h1 {
    font-size: 2rem;
  }
}

@media (min-width: 1024px) {
  .product-list {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Animation Classes */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.fade-in {
  animation: fadeIn var(--transition-medium) forwards;
}

.slide-up {
  animation: slideUp var(--transition-medium) forwards;
}