/* General Styles */
body { 
  margin: 0; 
  padding: 0; 
  font-family: Arial, sans-serif; 
  background: linear-gradient(135deg, #e0f7fa, #b2ebf2);
  min-height: 100vh;
  font-size: 16px; /* Base font size for better mobile scaling */
  line-height: 1.5; /* Improved line height for readability */
}

.main-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  z-index: 2; /* Above flying sheep */
  min-height: calc(100vh - 200px); /* Ensure content takes up space above footer */
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 3rem;
  color: #00796b;
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.navigation {
  text-align: center;
  margin-bottom: 30px;
}

.nav-link {
  display: inline-block;
  background: #004d40;
  color: white;
  padding: 14px 28px; /* Increased padding for better touch targets */
  border-radius: 8px;
  text-decoration: none;
  font-weight: bold;
  margin: 0 10px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 77, 64, 0.3);
  border: 2px solid #004d40;
  min-height: 44px; /* Ensure minimum touch target size */
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-link:hover {
  background: #00251a;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 77, 64, 0.4);
  border-color: #00251a;
}

.nav-link.active {
  background: #00acc1;
  border-color: #00acc1;
}

/* Language Selector Styles */
.language-selector {
  text-align: center;
  margin-bottom: 20px;
}

.language-select {
  background: #ffffff;
  color: #004d40;
  padding: 8px 16px;
  border: 2px solid #004d40;
  border-radius: 6px;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(0, 77, 64, 0.2);
}

.language-select:hover {
  background: #f0f0f0;
  border-color: #00251a;
  box-shadow: 0 3px 15px rgba(0, 77, 64, 0.3);
}

.language-select:focus {
  outline: none;
  background: #e8f5e8;
  border-color: #00acc1;
  box-shadow: 0 0 0 3px rgba(0, 172, 193, 0.2);
}

/* Sheep Discovery Page Styles */
.sheep-discovery {
  text-align: center;
  padding: 40px 20px;
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 2; /* Above flying sheep */
}

.sheep-discovery h1 {
  font-size: 3rem;
  color: #00796b;
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.sheep-discovery p {
  font-size: 1.3rem;
  color: #004d40;
  margin: 15px 0;
  max-width: 600px;
}

.sheep-discovery a {
  color: #00796b;
  text-decoration: none;
  font-weight: bold;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.sheep-discovery a:hover {
  background-color: rgba(0, 121, 107, 0.1);
}

.back-to-map {
  display: inline-block;
  background: #004d40;
  color: white;
  padding: 15px 30px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: bold;
  font-size: 1.1rem;
  margin-top: 25px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 77, 64, 0.3);
  border: 2px solid #004d40;
}

.back-to-map:hover {
  background: #00251a;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 77, 64, 0.4);
  border-color: #00251a;
}

/* Map Styles */
#map { 
  height: 600px; 
  border-radius: 8px; 
  box-shadow: 0 4px 20px rgba(0,0,0,0.15); 
  background: white;
}

/* Gallery Styles */
#gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
  /* Ensure proper stacking context for gallery */
  position: relative;
  z-index: 1;
}

.gallery-item {
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  background: white;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
  position: relative;
  /* Create stacking context for proper z-index behavior */
  z-index: 2;
  transform: translateZ(0);
}

.gallery-item:hover {
  transform: translateY(-5px) translateZ(0);
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
  /* Ensure hovered item appears above others */
  z-index: 1000;
}

/* Image description tooltip styles - significantly higher z-index */
.gallery-item .image-description {
  position: fixed;
  background: rgba(0, 0, 0, 0.95);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.4;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
  transform: translateY(10px);
  /* Use extremely high z-index to ensure it's above everything */
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Arrow for tooltip */
.gallery-item .image-description::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.95);
  z-index: 10000;
}

/* Show description on hover */
.gallery-item:hover .image-description {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  z-index: 10000;
}

/* Ensure non-hovered items stay below */
.gallery-item:not(:hover) {
  z-index: 2;
}

/* Multi-line description support */
.gallery-item .image-description.multiline {
  white-space: normal;
  max-width: 250px;
  text-align: center;
}

.gallery-image-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
}

.gallery-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.gallery-item:hover .gallery-image-container img {
  transform: scale(1.05);
}

.gallery-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: white;
  padding: 20px 15px 15px;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 5;
}

.gallery-item:hover .gallery-overlay {
  transform: translateY(0);
}

.gallery-info {
  font-size: 0.9rem;
}

.gallery-desc {
  font-weight: bold;
  margin-bottom: 5px;
}

.gallery-date, .gallery-location {
  font-size: 0.8rem;
  opacity: 0.9;
  margin-bottom: 3px;
}

/* Progressive Image Loading Styles */
.image-progressive {
  position: relative;
  overflow: hidden;
  background-color: #f0f0f0;
}

.image-progressive .blur-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, #e0e0e0 25%, transparent 25%), 
              linear-gradient(-45deg, #e0e0e0 25%, transparent 25%), 
              linear-gradient(45deg, transparent 75%, #e0e0e0 75%), 
              linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  filter: blur(2px);
  transition: opacity 0.3s ease;
  z-index: 1;
}

.image-progressive .blur-placeholder.fade-out {
  opacity: 0;
}

.image-progressive img {
  position: relative;
  z-index: 2;
  transition: opacity 0.3s ease;
  opacity: 0;
}

.image-progressive img.loaded {
  opacity: 1;
}

/* Optimized loading spinner */
.loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #00796b;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 3;
}

@keyframes spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Performance optimizations */
.image-optimized {
  will-change: transform;
  backface-visibility: hidden;
  transform: translateZ(0);
}

/* Flying Sheep Animation */
.sheep {
  position: fixed;
  width: 50px;
  height: 50px;
  background-image: url('https://emojicdn.elk.sh/🐑');
  background-size: cover;
  z-index: 0; /* Behind all content */
  pointer-events: none;
}

/* Loading, Error and Stats States */
#loading { 
  text-align: center; 
  padding: 20px; 
  background: rgba(255, 255, 255, 0.9); 
  border-radius: 8px; 
  margin-bottom: 20px;
  display: none;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

#error { 
  text-align: center; 
  padding: 20px; 
  background: #ffebee; 
  color: #c62828; 
  border-radius: 8px; 
  margin-bottom: 20px;
  display: none;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.stats {
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 15px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-weight: bold;
  color: #004d40;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Leaflet Popup Styles */
.leaflet-popup-content { 
  max-width: 320px !important; 
  max-height: 400px !important;
  overflow-y: auto !important;
}

.popup-container {
  max-height: 350px;
  overflow-y: auto;
  padding-right: 5px;
}

.popup-header {
  position: sticky;
  top: 0;
  background: white;
  z-index: 100;
  padding: 5px 0;
  border-bottom: 1px solid #eee;
  margin-bottom: 8px;
  font-weight: bold;
  font-size: 0.9em;
  color: #333;
}

.popup-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.leaflet-popup-content img { 
  width: 100%;
  max-width: 100px;
  height: 75px;
  object-fit: cover;
  margin: 0;
  display: block; 
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.2s;
}

.clickable-map-image {
  cursor: pointer !important;
}

.leaflet-popup-content img:hover { 
  transform: scale(1.05); 
}

.popup-entry { 
  text-align: center; 
  margin-bottom: 8px;
  break-inside: avoid;
}

.popup-desc { 
  font-size: 0.8em; 
  color: #333; 
  margin-top: 4px; 
}

.popup-date { 
  font-size: 0.7em; 
  color: #666; 
  margin-top: 2px; 
}

.image-error { 
  width: 100%;
  max-width: 100px;
  height: 75px;
  background: #f0f0f0; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  border-radius: 4px; 
  color: #999; 
  font-size: 0.7em;
}

/* Modal for Full-Size Images */
.modal {
  display: none;
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.9);
  cursor: pointer;
}

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 95vw;
  max-height: 85vh; /* Nearly fullscreen, leaving space for info */
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  object-fit: contain;
}

.modal-info {
  color: white;
  text-align: center;
  padding: 15px 20px;
  max-width: 600px;
  margin: 0 auto;
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 40px);
  max-width: 600px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.9);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-info h3 {
  margin-top: 0;
  margin-bottom: 10px;
  color: #00acc1;
  font-size: 1.3rem;
}

.modal-info p {
  margin: 8px 0;
  line-height: 1.4;
  font-size: 0.95rem;
}

.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  z-index: 10001;
}

.close:hover,
.close:focus {
  color: #00acc1;
  text-decoration: none;
}

/* Navigation arrows for modal */
.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: none;
  font-size: 24px;
  padding: 15px 20px;
  cursor: pointer;
  border-radius: 50%;
  z-index: 10002;
  transition: all 0.3s ease;
  user-select: none;
}

.modal-nav:hover {
  background: rgba(0, 172, 193, 0.8);
  transform: translateY(-50%) scale(1.1);
}

.modal-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  background: rgba(0, 0, 0, 0.3);
}

.modal-nav:disabled:hover {
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.3);
}

.modal-prev {
  left: 20px;
}

.modal-next {
  right: 20px;
}

/* Hide navigation arrows when not in gallery mode */
.modal:not(.gallery-mode) .modal-nav {
  display: none;
}

/* Responsive Design */

/* Small Mobile Devices (up to 480px) */
@media (max-width: 480px) {
  .main-container { 
    padding: 8px; 
  }
  
  .page-header h1 {
    font-size: 1.8rem;
    margin-bottom: 15px;
    line-height: 1.2;
  }
  
  .nav-link {
    display: block;
    margin: 8px 0;
    padding: 16px 20px; /* Increased for better touch targets (min 44px height) */
    font-size: 1.1rem;
    min-height: 44px; /* Accessibility guideline for touch targets */
    box-sizing: border-box;
  }
  
  .navigation {
    margin-bottom: 20px;
  }
  
  #map { 
    height: 350px; 
    border-radius: 8px;
  }
  
  #gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    padding: 10px;
  }
  
  .gallery-item {
    border-radius: 8px;
    overflow: hidden;
  }
  
  .gallery-overlay {
    transform: translateY(0);
    background: rgba(0,0,0,0.9);
    padding: 15px;
    font-size: 0.9rem;
    line-height: 1.4;
  }
  
  .modal-content {
    max-width: 98vw;
    max-height: 85vh;
    margin: 2vh auto;
  }
  
  .modal-nav {
    font-size: 24px;
    padding: 16px 20px; /* Increased touch target */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .modal-prev {
    left: 5px;
  }
  
  .modal-next {
    right: 5px;
  }
  
  .modal-info {
    position: fixed;
    bottom: 5px;
    left: 5px;
    right: 5px;
    transform: none;
    width: auto;
    max-width: none;
    font-size: 0.85rem;
    padding: 15px;
    line-height: 1.4;
    border-radius: 8px;
  }
  
  .leaflet-popup-content { 
    max-width: 260px !important;
    font-size: 0.9rem;
  }
  
  .popup-images-grid { 
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); 
    gap: 8px;
  }
  
  .leaflet-popup-content img { 
    max-width: 70px; 
    height: 55px; 
    border-radius: 4px;
  }
  
  .image-error { 
    max-width: 70px; 
    height: 55px; 
    font-size: 0.7em; 
    border-radius: 4px;
  }
  
  .sheep-discovery h1 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    line-height: 1.2;
  }
  
  .sheep-discovery p {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 15px;
  }
  
  .language-select {
    padding: 12px 20px;
    font-size: 1rem;
    min-height: 44px; /* Better touch target */
  }
  
  #stats {
    font-size: 1rem;
    padding: 10px;
    margin-bottom: 15px;
  }
  
  /* Improved mobile tooltip positioning */
  .gallery-item .image-description {
    position: fixed;
    top: 15px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    max-width: calc(100vw - 30px);
    z-index: 10000;
    white-space: normal;
    text-align: center;
    font-size: 0.9rem;
  }
  
  .gallery-item:hover .image-description {
    transform: translateX(-50%) !important;
  }
  
  .gallery-item .image-description::after {
    display: none; /* Hide arrow on mobile for cleaner look */
  }
}

/* Medium Mobile Devices and Small Tablets (481px to 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  .main-container { 
    padding: 15px; 
  }
  
  .page-header h1 {
    font-size: 2.2rem;
    line-height: 1.2;
  }
  
  .nav-link {
    display: inline-block;
    margin: 8px 5px;
    padding: 14px 24px;
    min-height: 44px; /* Accessibility guideline */
    box-sizing: border-box;
  }
  
  #map { 
    height: 450px; 
    border-radius: 8px;
  }
  
  #gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
  }
  
  .modal-nav {
    font-size: 22px;
    padding: 14px 18px;
    min-width: 44px;
    min-height: 44px;
  }
  
  .leaflet-popup-content { 
    max-width: 300px !important; 
  }
  
  .popup-images-grid { 
    grid-template-columns: repeat(auto-fit, minmax(85px, 1fr)); 
  }
  
  .leaflet-popup-content img { 
    max-width: 85px; 
    height: 65px; 
  }
  
  .gallery-item .image-description {
    position: fixed;
    top: 20px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    max-width: calc(100vw - 40px);
    z-index: 10000;
    white-space: normal;
    text-align: center;
  }
}

/* Tablets (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .main-container {
    padding: 20px;
    max-width: 1000px;
  }
  
  .page-header h1 {
    font-size: 2.8rem;
  }
  
  .nav-link {
    padding: 14px 28px;
    margin: 0 8px;
    font-size: 1.1rem;
  }
  
  #map {
    height: 500px;
  }
  
  #gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
  }
  
  .modal-content {
    max-width: 90vw;
    max-height: 85vh;
  }
}

/* Legacy mobile breakpoint for compatibility */
@media (max-width: 768px) {
  .gallery-overlay {
    transform: translateY(0);
    background: rgba(0,0,0,0.8);
  }
  
  .modal-content {
    max-width: 95vw;
    max-height: 80vh;
  }
  
  .modal-info {
    position: fixed;
    bottom: 10px;
    left: 10px;
    right: 10px;
    transform: none;
    width: auto;
    max-width: none;
    font-size: 0.9rem;
    padding: 12px 15px;
  }
  
  .sheep-discovery h1 {
    font-size: 2rem;
  }
  
  .sheep-discovery p {
    font-size: 1.1rem;
  }
}

/* Sheep Footer Styles */
.sheep-footer {
  background: linear-gradient(135deg, #004d40, #00695c);
  color: #e0f2f1;
  margin-top: 40px;
  padding: 40px 0;
  position: relative;
  box-shadow: 0 -4px 20px rgba(0, 77, 64, 0.3);
}

.sheep-footer .footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 40px;
  text-align: left;
}

.footer-section {
  padding: 0 15px;
}

.footer-section h3 {
  color: #b2dfdb;
  margin-bottom: 15px;
  font-size: 1.3rem;
  border-bottom: 2px solid #4db6ac;
  padding-bottom: 8px;
  display: inline-block;
}

.sheep-footer p {
  margin: 10px 0;
  line-height: 1.6;
  color: #e0f2f1;
}

.sheep-footer a {
  color: #a7ffeb;
  text-decoration: underline;
  font-weight: bold;
}

.sheep-footer a:hover {
  color: #ffffff;
  text-decoration: none;
}

.sheep-footer .highlight {
  font-size: 1.1em;
  color: #b2dfdb;
  font-weight: bold;
}

/* Responsive footer */
@media (max-width: 480px) {
  .sheep-footer {
    padding: 25px 0;
  }
  
  .sheep-footer .footer-content {
    grid-template-columns: 1fr;
    gap: 25px;
    text-align: center;
    padding: 0 15px;
  }
  
  .footer-section {
    padding: 0;
  }
  
  .footer-section h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
  }
  
  .sheep-footer p {
    font-size: 0.95rem;
    line-height: 1.5;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .sheep-footer {
    padding: 30px 0;
  }
  
  .sheep-footer .footer-content {
    grid-template-columns: 1fr;
    gap: 30px;
    text-align: center;
  }
  
  .footer-section {
    padding: 0;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .sheep-footer .footer-content {
    grid-template-columns: repeat(3, 1fr);
    gap: 35px;
    max-width: 1000px;
  }
}

/* Legacy tablet/mobile footer */
@media (max-width: 768px) {
  .sheep-footer {
    padding: 30px 0;
  }
  
  .sheep-footer .footer-content {
    grid-template-columns: 1fr;
    gap: 30px;
    text-align: center;
  }
  
  .footer-section {
    padding: 0;
  }
}

/* Cluster Map Styles */
.sheep-cluster {
  background: linear-gradient(135deg, #00acc1, #0097a7);
  color: white;
  border: 3px solid #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 121, 107, 0.4);
  font-weight: bold;
  transition: all 0.3s ease;
}

.sheep-cluster:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 121, 107, 0.6);
  background: linear-gradient(135deg, #00b4cc, #00acc1);
}

.sheep-cluster-small {
  background: linear-gradient(135deg, #4db6ac, #26a69a);
}

.sheep-cluster-medium {
  background: linear-gradient(135deg, #00acc1, #0097a7);
}

.sheep-cluster-large {
  background: linear-gradient(135deg, #00796b, #004d40);
}

.sheep-count {
  text-align: center;
  line-height: 1.2;
  font-size: 1.5em;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* Override default cluster styles */
.marker-cluster-small {
  background-color: transparent !important;
}

.marker-cluster-medium {
  background-color: transparent !important;
}

.marker-cluster-large {
  background-color: transparent !important;
}

.marker-cluster-small div {
  background-color: transparent !important;
}

.marker-cluster-medium div {
  background-color: transparent !important;
}

.marker-cluster-large div {
  background-color: transparent !important;
}
