/* Google Fonts import */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700&display=swap');

:root {
  --primary-color: #6d3991;
  --secondary-color: #516da7;
  --accent-color: #ffffff;
  --success-color: #28a745;
  --danger-color: #dc3545;
  --text-light: #ffffff;
  --text-dark: #333333;
  --bg-light: #f8f9fa;
  --bg-dark: #212529;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --border-radius: 8px;
  --gradient: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

body {
  color: var(--text-dark);
  background-color: var(--bg-light);
  font-family: 'Tajawal', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  font-size: 1.6em;
  font-weight: 400;
  letter-spacing: .01em;
  line-height: 1.6;
  margin: 0;
  padding: 0;
}

.wrapper {
  min-height: 100vh;
  background: var(--gradient);
  padding: 2rem 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

.title {
  color: var(--text-light);
  text-align: center;
  margin-bottom: 2rem;
  font-size: 2.4rem;
  font-weight: 700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.language-nav {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

/* RTL support for language navigation */
[dir="rtl"] .language-nav {
  flex-direction: row-reverse;
}

.button {
  background: var(--gradient);
  border: none;
  color: var(--text-light);
  padding: 1rem 2rem;
  border-radius: var(--border-radius);
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
  font-weight: 500;
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  opacity: 0.9;
}

.button-small {
  padding: 0.5rem 1rem;
  font-size: 0.9em;
}

.button-outline {
  background: transparent;
  border: 2px solid var(--text-light);
  color: var(--text-light);
}

.button-outline:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: var(--text-light);
  color: var(--text-light);
}

.scanner-container {
  background-color: var(--text-light);
  border-radius: var(--border-radius);
  padding: 2rem;
  margin: 2rem 0;
  box-shadow: var(--shadow);
}

.description {
  text-align: center;
  color: var(--text-dark);
  margin-bottom: 2rem;
  font-size: 1.1em;
  font-weight: 400;
}

.scan-controls {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  justify-content: center;
}

/* RTL support for scan controls */
[dir="rtl"] .button-small span,
[dir="rtl"] .scan-button {
  display: inline-flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 0.5rem;
}

.scan-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.8rem 1.5rem;
  background: var(--gradient);
  color: var(--text-light);
  border: none;
  border-radius: var(--border-radius);
  font-size: 1.1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 140px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.scan-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(109, 57, 145, 0.2);
}

.scan-button:active {
  transform: translateY(1px);
}

.scan-button.reset {
  background: transparent;
  border: 2px solid var(--danger-color);
  color: var(--danger-color);
}

.scan-button.reset:hover {
  background-color: var(--danger-color);
  color: var(--text-light);
}

.scan-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.scan {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}

/* Tablet layout */
@media (min-width: 768px) and (max-width: 1023px) {
  .scan {
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
  }
}

/* Desktop layout */
@media (min-width: 1024px) {
  .scan {
    grid-template-columns: 3fr 2fr;
    gap: 2rem;
  }
}

.video-container {
  background-color: var(--bg-dark);
  padding: 1rem;
  border-radius: var(--border-radius);
  border: 2px solid var(--primary-color);
  overflow: hidden; /* Prevent content from overflowing */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#sourceSelectPanel {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: var(--border-radius);
  width: 100%;
}

#sourceSelectPanel label {
  color: var(--text-light);
  font-weight: 500;
  margin-bottom: 0.5rem;
  display: block;
}

#sourceSelect {
  width: 100%;
  padding: 0.5rem;
  border-radius: var(--border-radius);
  border: 1px solid var(--primary-color);
  background-color: rgba(255, 255, 255, 0.9);
  color: var(--text-dark);
  margin-bottom: 1rem;
  font-family: 'Tajawal', sans-serif;
}

/* Fix dropdown arrow position in RTL mode */
[dir="rtl"] select {
  background-position: left 0.5rem center;
  padding-right: 0.5rem;
  padding-left: 3rem;
}

video {
  width: 100%;
  max-width: 720px;
  height: auto;
  border-radius: var(--border-radius);
  border: 3px solid var(--secondary-color);
  box-shadow: var(--shadow);
  object-fit: contain; /* Changed from cover to contain to prevent overflow */
  background-color: #000; /* Dark background while camera loads */
}

.results {
  background-color: rgba(255, 255, 255, 0.95);
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--primary-color);
}

.results label {
  display: block;
  color: var(--primary-color);
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.results pre {
  background-color: var(--bg-light);
  padding: 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 1.5rem;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid rgba(109, 57, 145, 0.2);
}

.statusSpan {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  font-weight: bold;
  margin: 0.5rem 0;
}

.statusSpan[style*="green"] {
  background-color: var(--success-color);
  color: var(--text-light);
}

.statusSpan[style*="red"] {
  background-color: var(--danger-color);
  color: var(--text-light);
}

.settings-panel {
  background-color: var(--bg-light);
  padding: 1.5rem;
  border-radius: var(--border-radius);
  margin-bottom: 1.5rem;
  border: 1px solid rgba(109, 57, 145, 0.2);
}

select {
  width: 100%;
  padding: 0.5rem;
  border-radius: var(--border-radius);
  border: 1px solid var(--primary-color);
  background-color: var(--text-light);
  margin-top: 0.5rem;
  font-family: 'Tajawal', sans-serif;
  font-size: 1em;
  color: var(--text-dark);
}

select:focus {
  outline: none;
  border-color: var(--secondary-color);
  box-shadow: 0 0 0 2px rgba(81, 109, 167, 0.2);
}

.result-panel, .history-panel {
  margin-top: 1.5rem;
}

.logo-container {
  text-align: right;
  margin-bottom: 2rem;
}

.logo {
  max-width: 120px;
  height: auto;
}

@media (max-width: 768px) {
  .logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0.25rem auto;
    width: 100%;
    text-align: center;
  }
  
  .logo {
    max-width: 100px;
    margin: 0 auto;
  }
}

.result-panel pre,
.history-panel pre {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 150px;
  max-height: 250px;
  overflow-y: auto;
  padding: 0.5rem;
}

#history {
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#history li {
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  margin: 0;
}

.footer {
  text-align: center;
  color: var(--text-light);
  margin-top: 4rem;
  padding: 2rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.footer a {
  color: var(--text-light);
  text-decoration: none;
  font-weight: 500;
  opacity: 0.9;
}

.footer a:hover {
  text-decoration: none;
  opacity: 1;
}

/* Small device specific styles */
@media (max-width: 480px) {
  .title {
    font-size: 1.5rem;
  }

  .scan-button {
    width: 100%;
    max-width: 100%;
    margin-bottom: 0.5rem;
  }

  .scan-controls {
    flex-direction: column;
  }

  .video-container {
    padding: 0.25rem;
  }

  video {
    max-height: 90vh;
  }

  .results pre {
    max-height: 150px;
    font-size: 0.85em;
  }

  /* Optimize for portrait orientation on mobile */
  @media (orientation: portrait) {
    .video-container {
      height: auto;
      max-height: 80vh;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }

    video {
      max-height: 80vh;
    }
  }

  /* Optimize for landscape orientation on mobile */
  @media (orientation: landscape) {
    .scan {
      grid-template-columns: 1fr 1fr;
      gap: 0.5rem;
    }

    .video-container {
      height: 60vh;
    }

    video {
      max-height: 80vh;
    }
  }
}

/* RTL Specific Styles */
[dir="rtl"] .language-nav,
[dir="rtl"] .scan-controls {
  flex-direction: row-reverse;
}

[dir="rtl"] .results label {
  text-align: right;
}

/* Ensure RTL works well on mobile */
@media (max-width: 768px) {
  [dir="rtl"] .scan-controls {
    flex-direction: row-reverse;
    flex-wrap: wrap;
  }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.scan {
  animation: fadeIn 0.5s ease-in-out;
}

/* History List Styling */
#history {
  list-style: none;
  padding: 0;
}

#history li {
  padding: 0.8rem;
  border-bottom: 1px solid rgba(109, 57, 145, 0.1);
  transition: background-color 0.3s ease;
}

#history li:hover {
  background-color: rgba(81, 109, 167, 0.05);
}

#history li:last-child {
  border-bottom: none;
}

/* Mobile Styles */
@media (max-width: 768px) {
  body {
    font-size: 1.4em; /* Slightly smaller base font size for mobile */
  }

  .wrapper {
    padding: 1rem 0;
  }

  .container {
    padding: 0.5rem;
    width: 100%;
    max-width: 100%;
  }
  
  .title {
    font-size: 1.8rem;
    margin-bottom: 1rem;
  }

  .scanner-container {
    padding: 1rem;
    margin: 1rem 0;
  }
  
  .scan-controls {
    flex-direction: row;
    gap: 0.5rem;
    flex-wrap: wrap; /* Allow buttons to wrap on very small screens */
    justify-content: center;
  }
  
  .scan-button {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    min-width: 120px;
    flex: 1;
    max-width: 45%;
  }
  
  .results {
    padding: 1rem;
  }
  
  .result-panel pre,
  .history-panel pre {
    min-height: 100px;
    max-height: 180px;
    font-size: 0.9em;
  }

  /* Improve touch targets for mobile */
  select, button {
    min-height: 44px; /* Minimum touch target size */
  }

  /* Make video container more prominent on mobile */
  .video-container {
    padding: 0.5rem;
    margin-bottom: 1rem;
  }

  video {
    max-height: 50vh; /* Limit height on mobile to prevent excessive space usage */
    object-fit: cover;
  }
}

/* Arabic Text Styles */
[dir="rtl"] {
  text-align: right;
}

.statusSpan, .loginStatusSpan {
  display: inline-block;
  margin: 0 0.5rem;
  font-weight: bold;
}

/* Toggle Switch Styles */
.controls-table {
  display: table;
  width: 100%;
  margin-bottom: 1rem;
  border-spacing: 0 0.5rem;
}

.controls-row {
  display: table-row;
}

.control-cell {
  display: table-cell;
  padding: 0.25rem 0.5rem;
  vertical-align: middle;
  height: 45px; /* Match the height of controls */
}

.labels-row .control-cell {
  font-weight: 500;
  color: var(--text-light);
  white-space: nowrap;
  padding-bottom: 0.5rem;
}

.control-cell select,
.control-cell .toggle-container {
  width: 100%;
  min-width: 150px;
  box-sizing: border-box;
}

/* Ensure both select and toggle match the global select styling */
.control-cell select,
.control-cell .toggle-container {
  height: 45px;
  border: 1px solid var(--primary-color);
  border-radius: var(--border-radius);
  background-color: rgba(255, 255, 255, 0.1);
  vertical-align: middle;
  font-family: 'Tajawal', sans-serif;
}

/* Stylish Toggle Switch with Icons - Based on the movement from mobinkakei */
.toggle-container {
  position: relative;
  display: inline-block;
  height: 45px;
  width: 70px;
  border-radius: var(--border-radius);
  background: linear-gradient(to right, #be9bff, #8ceeff);
  border: 1px solid var(--primary-color);
  cursor: pointer;
  padding: 0;
  margin: 0;
} 

.toggle-container input[type="checkbox"] {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: var(--border-radius);
  transition: 0.4s cubic-bezier(0.85, 0.05, 0.18, 1.35);
}

/* Icons inside the toggle */
.login-icon, .logout-icon {
  position: absolute;
  width: 32px; /* Increased by 10% from 25px */
  height: 32px; /* Increased by 10% from 25px */
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  transition: all 0.4s cubic-bezier(0.85, 0.05, 0.18, 1.35);
  background-color: white;
  border-radius: calc(var(--border-radius) - 2px);
  padding: 3px;
  box-sizing: border-box;
  border: 1px solid var(--primary-color);
}

/* Initial state */
.login-icon {
  left: 4px;
  opacity: 1;
}

.logout-icon {
  right: -30px; /* Start outside the visible area */
  opacity: 0;
}

/* Checked state - login icon moves out, logout icon moves in */
.toggle-container input[type="checkbox"]:checked ~ .login-icon {
  left: -30px; /* Move out of visible area */
  opacity: 0;
}

.toggle-container input[type="checkbox"]:checked ~ .logout-icon {
  right: 4px; /* Move into visible area */
  opacity: 1;
}

/* Focus state for accessibility */
input[type="checkbox"]:focus {
  outline: 2px solid rgba(109, 57, 145, 0.3);
  outline-offset: 2px;
}

/* RTL support for toggle */
[dir="rtl"] .login-icon {
  left: auto;
  right: 4px;
}

[dir="rtl"] .logout-icon {
  right: auto;
  left: +30px; /* Start outside the visible area */
}

[dir="rtl"] .toggle-container input[type="checkbox"]:checked ~ .login-icon {
  right: +30px; /* Move out of visible area */
  left: auto;
}

[dir="rtl"] .toggle-container input[type="checkbox"]:checked ~ .logout-icon {
  left: 4px; /* Move into visible area */
  right: auto;
}

/* Mobile adjustments for scan mode UI */
@media (max-width: 768px) {
  .scan-mode-indicators {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .mode-indicator {
    padding: 0.4rem 0.8rem;
    font-size: 0.9em;
  }
}

select {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-dark);
  border: 1px solid var(--primary-color);
  padding: 0.5rem;
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 250px;
  font-family: 'Tajawal', sans-serif;
}
