/* ===========================================================
   Tag Grid System — v1.6.1 (Fixed Responsive 2-6 Column Layout)
   2 columns mobile → 6 columns desktop
   =========================================================== */

/* --- Search Input --- */
.tag-grid-page .tag-search-wrapper {
  position: relative;
  z-index: 102;
  max-width: 400px;
  margin: 0 auto 20px;
  padding: 0 12px;
}

.tag-grid-page #tagSearchInput {
  position: relative;
  z-index: 103;
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  background-color: #fff;
  color: #111827;
  transition: border-color 0.3s, box-shadow 0.3s;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
}

.tag-grid-page #tagSearchInput:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* --- Tag Grid Container --- */
.tag-grid-wrapper {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 10px;
  margin: 20px auto;
  padding: 0 12px;
  max-width: 1200px;
  position: relative;
  z-index: 1;
  min-height: 200px;
  contain: layout paint;
  opacity: 1;
  transition: opacity 0.4s ease;
  box-sizing: border-box;
}

/* Fade-in only when JS runs */
.js .tag-grid-wrapper {
  opacity: 0;
}
.js .tag-grid-wrapper.loaded {
  opacity: 1;
}

/* --- Tag Items --- */
.tag-grid-item {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  background-color: #f3f4f6;
  color: #111827;
  text-align: center;
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, opacity 0.2s ease;
  cursor: pointer;
  word-break: break-word;
  min-height: 44px;
  box-sizing: border-box;
}

.tag-grid-item:hover,
.tag-grid-item:focus {
  background-color: #2563eb;
  color: #fff;
  border-color: #1d4ed8;
  outline: none;
}

.tag-grid-item:active {
  transform: scale(0.98);
}

/* Hidden state */
.tag-grid-item.hidden,
.tag-grid-item.search-hidden {
  display: none !important;
}

/* --- Load More Button --- */
.tag-load-more-btn {
  background-color: #2563eb;
  color: #ffffff;
  border-color: #1d4ed8;
  grid-column: 1 / -1;
  max-width: 200px;
  margin: 10px auto 0;
  justify-self: center;
}

.tag-load-more-btn:hover,
.tag-load-more-btn:focus {
  background-color: #1d4ed8;
  color: #ffffff;
}

/* --- No Results Message --- */
.no-results-message {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  color: #6b7280;
  font-size: 1rem;
  display: none;
}

.no-results-message.visible {
  display: block;
}

/* --- Prevent overlay interference --- */
.tag-grid-page *::before,
.tag-grid-page *::after {
  pointer-events: none;
}

/* ===========================================================
   RESPONSIVE BREAKPOINTS
   =========================================================== */

/* Small phones (up to 359px) - 2 columns */
@media screen and (max-width: 359px) {
  .tag-grid-wrapper {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
    padding: 0 8px;
  }

  .tag-grid-item {
    padding: 8px 10px;
    font-size: 13px;
  }
}

/* Phones (360px - 575px) - 2 columns */
@media screen and (min-width: 360px) and (max-width: 575px) {
  .tag-grid-wrapper {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
  }

  .tag-grid-item {
    font-size: 14px;
    padding: 10px 12px;
  }
}

/* Large phones / Small tablets (576px - 767px) - 3 columns */
@media screen and (min-width: 576px) {
  .tag-grid-wrapper {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 12px;
    padding: 0 16px;
  }

  .tag-grid-item {
    font-size: 15px;
    padding: 10px 14px;
  }
}

/* Tablets (768px - 991px) - 4 columns */
@media screen and (min-width: 768px) {
  .tag-grid-wrapper {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 12px;
    padding: 0 20px;
  }

  .tag-grid-item {
    font-size: 15px;
    padding: 10px 14px;
  }

  .tag-grid-page .tag-search-wrapper {
    max-width: 450px;
  }
}

/* Small desktops (992px - 1199px) - 5 columns */
@media screen and (min-width: 992px) {
  .tag-grid-wrapper {
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 14px;
    padding: 0 24px;
  }

  .tag-grid-item {
    font-size: 16px;
    padding: 12px 16px;
  }

  .tag-grid-page .tag-search-wrapper {
    max-width: 500px;
  }
}

/* Large desktops (1200px+) - 6 columns */
@media screen and (min-width: 1200px) {
  .tag-grid-wrapper {
    grid-template-columns: repeat(6, 1fr) !important;
    gap: 14px;
    padding: 0 24px;
    max-width: 1200px;
  }

  .tag-grid-item {
    font-size: 17px;
    padding: 12px 16px;
  }

  .tag-grid-page .tag-search-wrapper {
    max-width: 500px;
  }

  .tag-load-more-btn {
    max-width: 220px;
  }
}

/* ===========================================================
   ACCESSIBILITY & PERFORMANCE
   =========================================================== */

/* Touch device optimization */
@media (hover: none) and (pointer: coarse) {
  .tag-grid-item {
    min-height: 48px;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .tag-grid-wrapper,
  .tag-grid-item,
  .tag-grid-page #tagSearchInput {
    transition: none;
  }
}