/**
 * Search styles for the coaching platform
 */

/* Search form */
.navbar .search-form {
  position: relative;
}

/* Fix for mobile zoom on input focus */
input.coaching-search-input {
  font-size: 16px !important; /* Minimum font size to prevent iOS zoom */
}

/* On mobile, make the font size smaller after focus */
@media (max-width: 767px) {
  input.coaching-search-input:focus {
    font-size: 16px !important; /* Keep the same size on focus */
  }

  /* Visually make it look smaller with transform */
  .mobile-search-form .form-control {
    transform: scale(0.875);
  }
}

/* Overlay element */
#search-overlay {
  position: fixed;
  top: 90px;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 9000; /* High z-index but lower than search results */
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none; /* Allow clicks to pass through */
}

#search-overlay.active {
  display: block;
  opacity: 1;
}

/* Search results container - positioned at the highest z-index */
#search-results-container {
  position: fixed;
  top: 66px; /* Default for desktop */
  left: 0;
  width: 100%;
  background-color: #fff;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  z-index: 9999; /* Extremely high z-index to ensure it's above everything */
  display: none;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#search-results-container.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

/* Search results - Fixed height to show first row and half of second row */
.search-results {
  padding: 20px;
  padding-bottom: 60px; /* Add extra padding at the bottom for the button */
  width: 100%;
  margin: 0 auto;
  position: relative;
  max-height: 350px; /* Set a fixed height to show first row and part of second */
  overflow: hidden;
  transition: max-height 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.search-results.expanded {
  max-height: 2000px; /* Large enough value to accommodate all content */
  overflow: visible;
}

/* Loading, error, and no results messages */
.search-loading,
.search-error,
.search-no-results {
  padding: 20px;
  text-align: center;
  color: #6c757d;
}

/* Grid layout */
.search-grid {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: relative;
}

/* Row layout */
.search-grid-row {
  display: flex;
  width: 100%;
  margin-bottom: 20px;
  transition: opacity 0.5s ease;
  justify-content: flex-start;
  flex-wrap: wrap;
}

/* Hide rows beyond the first one initially */
.search-results:not(.expanded) .search-grid-row:nth-child(n + 2) {
  opacity: 0.3;
}

/* Show all rows when expanded */
.search-results.expanded .search-grid-row {
  opacity: 1;
  transition: opacity 0.6s ease 0.2s; /* Delay the fade-in of rows */
}

/* Search item - Grid layout - 3 items per row on desktop (changed from 4) */
.search-item {
  flex: 0 0 calc(33.333% - 15px) !important; /* Changed to 33.333% for 3 items per row */
  margin: 0 7.5px 15px;
  background-color: #f7f7f7;
  border-radius: 24px;
  overflow: hidden;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Changed to two-column layout within each item */
.search-item-inner {
  display: flex;
  flex-direction: row;
  height: 100%;
}

.search-item-image {
  width: 30%;
  height: auto;
  border-radius: 24px 0 0 24px;
  overflow: hidden;
  position: relative;
}

.search-item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-item-content {
  width: 70%;
  padding: 15px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.search-item-header {
  margin-bottom: 8px;
}

.search-item-title {
  font-size: 1rem;
  font-weight: 500 !important;
  margin: 0 0 6px;
  color: #333;
}

.search-item-categories {
  margin: 0 0 8px;
}

/* Update category badges to match button style */
.search-item-categories .badge {
  padding: 4px 8px;
  font-size: 0.65rem;
  background-color: transparent !important;
  color: #2687db;
  border: 1px solid #2687db;
  border-radius: 24px;
  margin-right: 5px;
  font-weight: 400;
}

.search-item-excerpt {
  margin: 6px 0;
  font-size: 0.85rem;
  color: #555;
  line-height: 1.4;
  flex-grow: 1;
}

.search-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
}

/* Date and time styling */
.search-item-date {
  font-weight: 600;
  color: #2687db;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 5px;
}

.search-item-date .badge {
  padding: 5px 8px;
  border: 1px solid #2687db;
  background-color: transparent;
  color: #2687db;
  border-radius: 4px;
  font-weight: 400;
}

.more-dates-indicator {
  font-size: 10px;
  color: #2687db;
  background-color: rgba(38, 135, 219, 0.1);
  border-radius: 12px;
  padding: 2px 6px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Make the Zum Coaching button smaller */
.search-item-button {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background-color: transparent;
  color: #2687db;
  border: 1px solid #2687db;
  border-radius: 24px;
  text-decoration: none;
  transition: all 0.3s ease;
  font-size: 0.75rem;
}

.search-item-button:hover {
  background-color: #2687db;
  color: white;
  text-decoration: none;
}

.search-item-button i {
  margin-right: 6px;
  font-size: 0.75rem;
}

/* Fade effect for second row */
.search-results::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100px; /* Adjust based on your row height */
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 50%,
    rgba(255, 255, 255, 0.9) 75%,
    rgba(255, 255, 255, 1) 90%
  );
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.6s ease 0.1s; /* Slightly delay the fade-out of gradient */
}

.search-results.expanded::after {
  opacity: 0;
}

/* Change Show more button to blue background */
.search-show-more {
  display: block;
  text-align: center;
  margin: 0 auto;
  padding: 8px 20px;
  background-color: #2687db;
  color: white;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease, transform 0.3s ease;
  position: absolute;
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.search-show-more:hover {
  background-color: #1a6cb8;
}

/* Add custom focus styles to override Bootstrap defaults */
.search-show-more:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(38, 135, 219, 0.3);
  background-color: #2687db;
  color: white;
  border-color: #2687db;
}

/* Remove Bootstrap's default focus styles */
.search-show-more:focus-visible {
  outline: none;
}

.search-show-more i {
  margin-left: 5px;
  transition: transform 0.5s ease;
}

/* Rotate the icon when expanded */
.search-results.expanded + .search-show-more i.fa-chevron-up {
  transform: rotate(180deg);
}

/* When expanded, change button to relative positioning so it flows after content */
.search-results.expanded .search-show-more {
  position: relative;
  bottom: auto;
  left: auto;
  transform: none;
  margin: 20px auto 0;
}

/* Animation for expanding/collapsing */
.search-results.animating {
  pointer-events: none; /* Prevent interaction during animation */
}

/* Responsive styles */
@media (max-width: 1200px) {
  .search-item {
    flex: 0 0 calc(50% - 15px) !important; /* Keep 3 items per row on medium screens */
  }
}

@media (max-width: 992px) {
  .search-item {
    flex: 0 0 calc(50% - 15px) !important; /* 2 items per row on smaller screens */
  }
}

@media (max-width: 767px) {
  /* Change search results container position on mobile */
  #search-results-container {
    top: 59px;
  }

  /* Fixed mobile container to prevent scrolling */
  .search-results {
    padding: 5px;
    max-height: 400px; /* Accommodate exactly 4 items (2 rows) plus button */
    overflow: hidden; /* Changed from overflow-y: auto to prevent scrolling */
    -webkit-overflow-scrolling: touch; /* Keep for when expanded */
  }

  /* On mobile, hide items beyond the first 4 initially */
  .search-results:not(.expanded) .search-item:nth-child(n + 5) {
    display: none;
  }

  /* Show all items when expanded */
  .search-results.expanded .search-item {
    display: flex;
  }

  /* Allow scrolling only when expanded */
  .search-results.expanded {
    overflow-y: auto;
    max-height: 80vh; /* Limit expanded height to viewport */
  }

  /* Remove the gradient overlay on mobile since we're using display:none */
  .search-results::after {
    display: none;
  }

  /* Reduce title font size */
  .search-item-title {
    font-size: 0.7rem;
  }

  /* Reduce category badge font size */
  .search-item-categories .badge {
    font-size: 0.55rem;
    padding: 3px 6px;
  }

  /* Hide excerpt on mobile */
  .search-item-excerpt {
    display: none;
  }

  /* Hide dates on mobile */
  .search-item-date {
    display: none;
  }

  /* Reduce button size and align left */
  .search-item-button {
    padding: 2px 8px;
    font-size: 0.7rem;
  }

  .search-item-button i {
    font-size: 0.7rem;
    margin-right: 4px;
  }

  /* Adjust footer spacing and align button to the left */
  .search-item-footer {
    justify-content: flex-start;
    margin-top: 5px;
  }

  /* Reduce padding in the content area */
  .search-item-content {
    padding: 10px;
  }

  /* Stack the image and content on mobile */
  .search-item-inner {
    flex-direction: column;
  }

  .search-item-image {
    width: 100%;
    height: 100px; /* Reduced height for the image */
    border-radius: 24px 24px 0 0;
  }

  .search-item-content {
    width: 100%;
    padding: 8px; /* Reduced padding */
  }

  /* Reduce show more button font size on mobile */
  .search-show-more {
    font-size: 0.7rem;
    padding: 6px 16px;
  }
}

/* Add a rule to prevent the blur effect on the search form */
body.search-active .navbar .search-form {
  position: relative;
  z-index: 10000; /* Higher than the overlay */
  pointer-events: auto; /* Ensure it's clickable */
}

/* Custom scrollbar for expanded search results */
.search-results.expanded::-webkit-scrollbar {
  width: 4px;
}

.search-results.expanded::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 2px;
}

.search-results.expanded::-webkit-scrollbar-thumb {
  background: rgba(38, 135, 219, 0.3);
  border-radius: 2px;
  transition: background 0.3s ease;
}

.search-results.expanded::-webkit-scrollbar-thumb:hover {
  background: rgba(38, 135, 219, 0.6);
}

.search-results.expanded::-webkit-scrollbar-thumb:active {
  background: #2687db;
}

/* Firefox scrollbar styling */
.search-results.expanded {
  scrollbar-width: thin;
  scrollbar-color: rgba(38, 135, 219, 0.3) rgba(0, 0, 0, 0.05);
}
