/* Species Card Styles */
.speciesItemFirstImage {
  height: 150px;
  cursor: pointer;
  position: relative;
}

.speciesItemFirstImage img,
.speciesItemImage {
  max-height: 150px;
  max-width: 150px;
  min-height: 150px;
  min-width: 150px;
  margin-bottom: 1em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Touch feedback for mobile */
.speciesItemFirstImage:active img,
.speciesItemFirstImage img:active,
.speciesItemImage:active {
  transform: scale(0.95);
}

@media (hover: hover) {
  .speciesItemFirstImage:hover img,
  .speciesItemFirstImage img:hover,
  .speciesItemImage:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }
}

/* Visual feedback for clickable area */
.speciesItemFirstImage:active {
  opacity: 0.9;
}

.miniImageDisplay img#rootImage {
  opacity: 0;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.miniImageDisplay img#rootImage.visible {
  opacity: 1;
}

.speciesItemDetails {
  padding: 0.5em;
  position: relative;
}

.speciesItemDetails article {
  color: var(--primary_txt_color);
  font-size: calc(var(--min-font-size) + 2px);
}

.insectsListDiv a,
.speciesItemDetails a,
.speciesItemDetails p {
  color: var(--secondary_txt_color);
  font-size: calc(var(--min-font-size) + 2px);
  text-decoration: none;
}

.insectsListDiv {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

.insectsListDiv a {
  text-decoration: none;
  cursor: pointer;
  padding: 0.1em 0;
  display: inline-block;
  position: relative;
  z-index: 1;
}

.insectsListDiv a:hover {
  color: #1976d2;
  text-decoration: underline;
}

/* Species Hub Root Container */
#rootItems {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5em;
  padding: 1em;
}

/* Species Detail Modal Carousel */
.speciesDetailView .carousel {
  width: 100%;
  height: auto;
}

.speciesDetailView .carousel-cell {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.speciesDetailView .carousel-cell img {
  max-width: 100%;
  height: auto;
}

/* Carousel navigation buttons */
.speciesDetailView .flickity-button {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.speciesDetailView .flickity-button:hover {
  background: white;
}

.speciesDetailView .flickity-button:active {
  opacity: 0.7;
}

/* Page dots */
.speciesDetailView .flickity-page-dots {
  bottom: 10px;
}

.speciesDetailView .flickity-page-dots .dot {
  width: 12px;
  height: 12px;
  margin: 0 6px;
  background: rgba(255, 255, 255, 0.5);
  border: 2px solid rgba(0, 0, 0, 0.3);
}

.speciesDetailView .flickity-page-dots .dot.is-selected {
  background: white;
  border-color: rgba(0, 0, 0, 0.5);
}

/* Available Inventory Section */
.available-inventory-item {
  transition: all 0.2s ease;
}

.available-inventory-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.available-inventory-item:active {
  transform: translateX(2px);
}

/* Mobile adjustments for available inventory */
@media (max-width: 767px) {
  #availableInventorySection {
    margin-bottom: 1.5em;
  }

  #availableInventorySection h3 {
    font-size: 1.1rem;
  }

  .available-inventory-item {
    padding: 0.6em !important;
    font-size: 0.9rem;
  }

  .available-inventory-item div[style*="font-weight: 600"] {
    font-size: 0.85rem !important;
  }

  .available-inventory-item div[style*="font-size: 0.9em"] {
    font-size: 0.8em !important;
  }
}

@media (max-width: 600px) {
  #availableInventorySection h3 {
    font-size: 1rem;
  }

  .available-inventory-item {
    padding: 0.5em !important;
  }
}

@media (max-width: 374px) {
  #availableInventorySection h3 {
    font-size: 0.9rem;
  }

  .available-inventory-item {
    padding: 0.4em !important;
    font-size: 0.85rem;
  }
}

/* Desktop - 3 column grid */
@media (min-width: 1200px) {
  #rootItems {
    grid-template-columns: repeat(3, 1fr);
    gap: 2em;
    padding: 2em;
  }
}

/* Tablet - 2 column grid */
@media (min-width: 768px) and (max-width: 1199px) {
  #rootItems {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5em;
    padding: 1.5em;
  }

  .inventoryItemMain {
    padding: 1em;
  }

  .speciesItemDetails {
    padding: 0.75em;
  }
}

/* Mobile - Single column */
@media (max-width: 767px) {
  #rootItems {
    grid-template-columns: 1fr;
    gap: 1em;
    padding: 0.75em;
  }

  .inventoryItemMain {
    padding: 0.75em;
    margin-bottom: 0.5em;
    /* Add subtle shadow for depth */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
  }

  .inventoryItemMain:active {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  }

  .speciesItemFirstImage {
    height: auto;
    /* Make entire image area tappable */
    min-height: 44px;
  }

  .speciesItemFirstImage img,
  .speciesItemImage {
    max-width: 120px;
    max-height: 120px;
    min-width: 100px;
    min-height: 100px;
    /* Ensure image is centered and tappable */
    display: block;
    margin: 0 auto 1em auto;
  }

  /* Make entire image container clickable */
  .speciesItemFirstImage {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(76, 175, 80, 0.2);
  }

  .speciesItemDetails {
    padding: 0.5em;
  }

  .speciesItemDetails article,
  .speciesItemDetails p,
  .speciesItemDetails a {
    font-size: 0.9rem;
  }

  /* Modal adjustments for mobile */
  .ui-dialog {
    width: 95% !important;
    max-width: 95% !important;
    margin: 0 auto;
  }

  .speciesDetailView {
    padding: 0.5em;
  }

  .speciesDetailView h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75em;
  }

  .speciesDetailView section {
    margin-bottom: 1.5em;
  }

  .speciesDetailView .grid {
    grid-template-columns: auto 1fr !important;
    gap: 0.5em 1em !important;
    font-size: 0.9rem;
  }

  .speciesDetailView article {
    font-size: 0.85rem !important;
  }

  .speciesDetailView p {
    font-size: 0.85rem;
  }

  /* Carousel height for mobile */
  .speciesDetailView .miniImageDisplay {
    margin-bottom: 1em;
  }

  .speciesDetailView .carousel-cell {
    min-height: 250px;
  }

  .speciesDetailView .carousel-cell img {
    max-height: 300px;
  }

  /* Touch-friendly buttons */
  .ui-dialog .ui-button {
    min-height: 44px;
    padding: 0.75em 1em;
    font-size: 1rem;
  }
}

/* Small phones - Optimize further */
@media (max-width: 600px) {
  #rootItems {
    padding: 0.5em;
    gap: 0.75em;
  }

  .inventoryItemMain {
    padding: 0.5em;
  }

  .speciesItemFirstImage img,
  .speciesItemImage {
    max-width: 100px;
    max-height: 100px;
    min-width: 80px;
    min-height: 80px;
  }

  .speciesItemDetails {
    padding: 0.35em;
  }

  .speciesItemDetails article,
  .speciesItemDetails p,
  .speciesItemDetails a {
    font-size: 0.85rem;
    line-height: 1.4;
  }

  /* Modal */
  .speciesDetailView h3 {
    font-size: 1rem;
    padding-bottom: 0.35em;
    margin-bottom: 0.5em;
  }

  .speciesDetailView section {
    margin-bottom: 1em;
  }

  .speciesDetailView .grid {
    font-size: 0.85rem;
    gap: 0.35em 0.75em !important;
  }

  .speciesDetailView article {
    font-size: 0.8rem !important;
  }

  .speciesDetailView p {
    font-size: 0.8rem;
  }

  .speciesDetailView .carousel-cell {
    min-height: 200px;
  }

  .speciesDetailView .carousel-cell img {
    max-height: 250px;
  }
}

/* Ultra-small phones (iPhone SE, small Android) */
@media (max-width: 374px) {
  #rootItems {
    padding: 0.35em;
    gap: 0.5em;
  }

  .inventoryItemMain {
    padding: 0.35em;
  }

  .speciesItemFirstImage {
    height: auto;
  }

  .speciesItemFirstImage img,
  .speciesItemImage {
    max-width: 80px;
    max-height: 80px;
    min-width: 70px;
    min-height: 70px;
  }

  .inventoryItemHeader {
    padding: 0.35em !important;
    font-size: 0.9rem;
  }

  .speciesItemDetails {
    padding: 0.25em;
  }

  .speciesItemDetails article,
  .speciesItemDetails p,
  .speciesItemDetails a {
    font-size: 0.8rem;
    line-height: 1.3;
  }

  /* Modal on very small screens */
  .ui-dialog {
    width: 98% !important;
    max-width: 98% !important;
  }

  .speciesDetailView {
    padding: 0.35em;
  }

  .speciesDetailView h3 {
    font-size: 0.9rem;
    padding-bottom: 0.3em;
    margin-bottom: 0.4em;
  }

  .speciesDetailView section {
    margin-bottom: 0.75em;
  }

  .speciesDetailView .grid {
    font-size: 0.8rem;
    gap: 0.25em 0.5em !important;
  }

  .speciesDetailView article {
    font-size: 0.75rem !important;
  }

  .speciesDetailView p {
    font-size: 0.75rem;
    line-height: 1.3;
  }

  .speciesDetailView .miniImageDisplay {
    margin-bottom: 0.75em;
  }

  .speciesDetailView .carousel-cell {
    min-height: 180px;
  }

  .speciesDetailView .carousel-cell img {
    max-height: 200px;
  }

  .ui-dialog .ui-button {
    font-size: 0.9rem;
    padding: 0.6em 0.8em;
  }

  .ui-dialog .ui-button-text {
    padding: 0;
  }
}

/* Species modal scroll fix - ensure content is always scrollable */
.ui-dialog:has(.speciesDetailView) .ui-dialog-content {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
}

/* Ensure links in species modal are clickable */
.speciesDetailView a {
  pointer-events: auto !important;
  position: relative;
  z-index: 1;
}

.speciesDetailView .insectsListDiv a {
  color: #1976d2;
  font-weight: 500;
}

/* Mobile dialog enhancements */
.mobile-dialog.ui-dialog {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  margin: 0 !important;
  border-radius: 0 !important;
}

.mobile-dialog .ui-dialog-content {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  padding: 1em !important;
}

.mobile-dialog .ui-dialog-titlebar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: white;
  border-bottom: 1px solid #ddd;
}

/* Touch-friendly close button */
@media (max-width: 767px) {
  .mobile-dialog .ui-dialog-titlebar-close {
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .mobile-dialog .ui-dialog-buttonpane {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid #ddd;
    padding: 0.75em;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  }

  .mobile-dialog .ui-dialog-buttonpane .ui-button {
    margin: 0.25em;
    flex: 1;
  }

  .mobile-dialog .ui-dialog-buttonset {
    display: flex;
    gap: 0.5em;
  }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .speciesDetailView .carousel-cell {
    min-height: 150px !important;
  }

  .speciesDetailView .carousel-cell img {
    max-height: 180px !important;
  }

  .speciesDetailView section {
    margin-bottom: 0.75em;
  }

  .ui-dialog:not(.mobile-dialog) {
    max-height: 90vh !important;
  }

  .mobile-dialog .speciesDetailView h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5em;
  }
}

/* Prevent pull-to-refresh on mobile during carousel interaction */
@media (max-width: 767px) {
  .speciesDetailView .carousel {
    overscroll-behavior-y: contain;
    touch-action: pan-y pinch-zoom;
  }

  .mobile-dialog {
    overscroll-behavior: contain;
  }
}
