/* ============================================================================
   Guides Page Styles
   ============================================================================ */

.guides-page {
  padding: 2rem 1rem;
  padding-top: 8rem; /* Account for fixed navigation header */
  min-height: 80vh;
}

@media (min-width: 768px) {
  .guides-page {
    padding-top: 9rem; /* More space on larger screens */
  }
}

@media (min-width: 1024px) {
  .guides-page {
    padding-top: 10rem; /* Extra space on desktop */
  }
}

.container-custom {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header Section */
.guides-header {
  margin-bottom: 2rem;
  text-align: left;
}

.guides-header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text-primary, #111827);
  margin-bottom: 0.5rem;
}

.guides-intro {
  font-size: 1rem;
  color: var(--color-text-secondary, #374151);
  line-height: 1.6;
  margin-top: 0.5rem;
}

.guides-intro strong {
  font-weight: 600;
  color: var(--color-text-primary, #111827);
}

/* Search Bar */
.guides-search {
  margin-bottom: 1.5rem;
}

.search-wrapper {
  position: relative;
  max-width: 32rem;
}

.search-wrapper {
  position: relative;
  max-width: 32rem;
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  color: var(--color-text-tertiary, #6b7280);
  pointer-events: none;
  z-index: 1;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  padding-left: 3.5rem !important; /* 1rem (icon left) + 1.25rem (icon width) + 1.25rem (gap) = 3.5rem */
  padding-right: 1rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 0.5rem;
  font-size: 1rem;
  color: var(--color-text-primary, #111827);
  background-color: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.search-input:focus {
  outline: none;
  border-color: var(--color-primary, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-input::placeholder {
  color: var(--color-text-tertiary, #9ca3af);
}

/* Category Filters */
.guides-filters {
  margin-bottom: 2%;
}

/* Reduce gap when filters are followed by guide sections (All view) */
.guides-filters + #guides-content > .guide-section:first-of-type {
  margin-top: 0rem;
}

.filter-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.filter-buttons::-webkit-scrollbar {
  height: 4px;
}

.filter-buttons::-webkit-scrollbar-track {
  background: transparent;
}

.filter-buttons::-webkit-scrollbar-thumb {
  background: var(--color-border, #e5e7eb);
  border-radius: 2px;
}

.filter-btn {
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  background-color: var(--color-gray-100, #f3f4f6);
  color: var(--color-text-secondary, #374151);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-btn:hover {
  background-color: var(--color-gray-200, #e5e7eb);
}

.filter-btn.active {
  background-color: var(--color-primary, #2563eb);
  color: #fff;
}

.filter-btn:focus {
  outline: 2px solid var(--color-primary, #2563eb);
  outline-offset: 2px;
}

/* Hide select on desktop by default */
.filter-select {
  display: none;
}

/* Mobile-optimized filter - use dropdown instead of buttons */
@media (max-width: 640px) {
  .filter-buttons {
    display: none !important; /* Hide buttons on mobile */
  }

  .guides-filters {
    margin-bottom: 1rem; /* Reduce spacing on mobile */
  }

  .filter-select {
    display: block !important;
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 0.75rem;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    background-color: #fff;
    color: var(--color-text-primary, #111827);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
    line-height: 1.5;
  }

  .filter-select:hover {
    border-color: var(--color-gray-300, #d1d5db);
    background-color: var(--color-gray-50, #f9fafb);
  }

  .filter-select:focus {
    outline: none;
    border-color: var(--color-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background-color: #fff;
  }

  .filter-select:active {
    border-color: var(--color-primary, #2563eb);
  }

  /* Style option elements */
  .filter-select option {
    padding: 0.5rem;
    font-weight: 500;
    color: var(--color-text-primary, #111827);
  }

  .filter-select option:checked {
    background-color: var(--color-primary, #2563eb);
    color: #fff;
  }
}

/* Guide Sections */
#guides-content .guide-section {
  margin-bottom: 0 !important;
  margin-top: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  scroll-margin-top: 2rem;
  opacity: 0;
  transform: translateY(30px);
  animation: fadeInUp 0.7s ease-out forwards;
  width: 100%;
  max-width: 100%;
}

/* Ensure all guide sections have consistent alignment */
#guides-content .guide-section[data-category="Application-Specific"] .guide-cards-grid,
#guides-content .guide-section[data-category="Basics"] .guide-cards-grid,
#guides-content .guide-section[data-category="Process"] .guide-cards-grid,
#guides-content .guide-section[data-category="Material-Specific"] .guide-cards-grid,
#guides-content .guide-section[data-category="Troubleshooting"] .guide-cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: stretch; /* Stretch cards to fill grid cells */
}

@media (min-width: 768px) {
  #guides-content .guide-section[data-category="Application-Specific"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Basics"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Process"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Material-Specific"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Troubleshooting"] .guide-cards-grid {
    grid-template-columns: repeat(2, 1fr);
    align-items: stretch; /* Stretch cards to fill grid cells */
  }
}

@media (min-width: 1024px) {
  #guides-content .guide-section[data-category="Application-Specific"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Basics"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Process"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Material-Specific"] .guide-cards-grid,
  #guides-content .guide-section[data-category="Troubleshooting"] .guide-cards-grid {
    grid-template-columns: repeat(3, 1fr);
    align-items: stretch; /* Stretch cards to fill grid cells */
  }
}

/* Add spacing between sections using adjacent sibling selector */
#guides-content .guide-section + .guide-section {
  margin-top: 2rem !important;
}

/* Stagger section animations */
.guide-section:nth-of-type(1) { animation-delay: 0.05s; }
.guide-section:nth-of-type(2) { animation-delay: 0.15s; }
.guide-section:nth-of-type(3) { animation-delay: 0.25s; }
.guide-section:nth-of-type(4) { animation-delay: 0.35s; }
.guide-section:nth-of-type(5) { animation-delay: 0.45s; }
.guide-section:nth-of-type(n+6) { animation-delay: 0.55s; }

.guide-section:first-of-type {
  margin-top: 0;
  padding-top: 0;
}

/* Reduce gap for first section when showing all guides */
#guides-content {
  margin-top: 0;
  padding-top: 0;
}

#guides-content > .guide-section:first-of-type {
  margin-top: 0;
  padding-top: 0;
}

.guide-section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.guide-section-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text-primary, #111827);
  margin: 0;
}

.guide-section-count {
  font-size: 0.875rem;
  color: var(--color-text-tertiary, #6b7280);
}

.guide-section-description {
  font-size: 0.875rem;
  color: var(--color-text-secondary, #374151);
  margin-bottom: 0.5rem;
  max-width: 48rem;
  line-height: 1.6;
}

/* Guide Cards Grid */
.guide-cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: stretch; /* Stretch cards to fill grid cells */
}

@media (min-width: 768px) {
  .guide-cards-grid {
    grid-template-columns: repeat(2, 1fr);
    align-items: stretch; /* Stretch cards to fill grid cells */
  }
}

@media (min-width: 1024px) {
  .guide-cards-grid {
    grid-template-columns: repeat(3, 1fr);
    align-items: stretch; /* Stretch cards to fill grid cells */
  }
}

/* Guide Card */
.guide-card {
  background: #fff;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 0.75rem;
  overflow: hidden;
  transition: all 0.2s, transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.6s ease-out forwards;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%; /* Ensure cards fill grid cell height */
}

/* Stagger animation delays for cards */
.guide-card:nth-child(1) { animation-delay: 0.05s; }
.guide-card:nth-child(2) { animation-delay: 0.1s; }
.guide-card:nth-child(3) { animation-delay: 0.15s; }
.guide-card:nth-child(4) { animation-delay: 0.2s; }
.guide-card:nth-child(5) { animation-delay: 0.25s; }
.guide-card:nth-child(6) { animation-delay: 0.3s; }
.guide-card:nth-child(n+7) { animation-delay: 0.35s; }

.guide-card:hover {
  border-color: var(--color-gray-300, #d1d5db);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.guide-card-link {
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  height: 100%;
  min-height: 0;
}

.guide-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.guide-card-icons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.guide-icon {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--color-primary, #2563eb);
  flex-shrink: 0;
}

.guide-microstructure {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  overflow: hidden;
}

.guide-microstructure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Ensure images display properly */
.guide-card img,
.guide-image {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Ensure all guide cards have consistent width and alignment */
#guides-content .guide-section .guide-card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Ensure grid items don't overflow */
.guide-cards-grid > * {
  min-width: 0;
  width: 100%;
}

.difficulty-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-beginner {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-intermediate {
  background-color: #dbeafe;
  color: #1e40af;
}

.badge-advanced {
  background-color: #e9d5ff;
  color: #6b21a8;
}

.read-time {
  font-size: 0.75rem;
  color: var(--color-text-tertiary, #6b7280);
  white-space: nowrap;
}

.guide-card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text-primary, #111827);
  margin-bottom: 0.5rem;
  line-height: 1.4;
  transition: color 0.2s;
}

.guide-card:hover .guide-card-title {
  color: var(--color-primary, #2563eb);
}

.guide-card-description {
  font-size: 0.875rem;
  color: var(--color-text-secondary, #374151);
  line-height: 1.6;
  margin-bottom: 1rem;
  flex-grow: 1;
  /* Limit to 4 lines with ellipsis */
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: calc(0.875rem * 1.6 * 4); /* 4 lines: font-size * line-height * 4 */
  max-height: calc(0.875rem * 1.6 * 4);
}

.guide-card-link-text {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-primary, #2563eb);
  transition: gap 0.2s;
}

.guide-card:hover .guide-card-link-text {
  gap: 0.5rem;
}

.link-arrow {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s;
}

.guide-card:hover .link-arrow {
  transform: translateX(2px);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-secondary, #374151);
}

/* CTA Section */
.guides-cta {
  position: relative;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 40%, #111827 70%, #0f172a 100%);
  border-radius: 1rem;
  margin-top: 4rem;
  text-align: center;
  padding: 3rem 1.5rem 2.5rem;
  color: white;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.guides-cta .cta-hexagons {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.guides-cta .cta-glow {
  position: absolute;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 70%;
  background: radial-gradient(ellipse at center, rgba(37, 99, 235, 0.12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.guides-cta .cta-accent {
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 3px;
  background: linear-gradient(90deg, transparent, #2563eb, #3b82f6, #2563eb, transparent);
  border-radius: 0 0 2px 2px;
  z-index: 1;
}

.guides-cta h2,
.guides-cta .cta-description,
.guides-cta .cta-buttons {
  position: relative;
  z-index: 1;
}

@media (min-width: 768px) {
  .guides-cta {
    padding: 4.5rem 2rem 4rem;
  }
}

.guides-cta h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

@media (min-width: 768px) {
  .guides-cta h2 {
    font-size: 2.25rem;
  }
}

.cta-description {
  font-size: 1.125rem;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.7;
  margin-bottom: 2rem;
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
}

.cta-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
}

@media (min-width: 640px) {
  .cta-buttons {
    flex-direction: row;
  }
}

.guides-cta .btn-primary,
.guides-cta .btn-tertiary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: auto;
  padding: 0.625rem 1.25rem;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 0.9375rem;
  text-decoration: none;
  transition: all 0.3s;
  white-space: nowrap;
}

.guides-cta .btn-primary {
  background: white;
  color: #111827;
  border: none;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.guides-cta .btn-primary:hover {
  background: #f0f7ff;
  color: #111827;
  transform: translateY(-3px);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 20px rgba(37, 99, 235, 0.15);
}

.guides-cta .btn-tertiary {
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.guides-cta .btn-tertiary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  color: white;
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .guides-header h1 {
    font-size: 1.75rem;
  }

  .guide-section-title {
    font-size: 1.25rem;
  }

  .guides-cta {
    padding: 2rem 1rem 1.5rem;
  }

  .guides-cta h2 {
    font-size: 1.25rem;
  }

  .cta-description {
    font-size: 0.9375rem;
  }

  .guides-cta .cta-accent {
    left: 5%;
    right: 5%;
  }
}

/* Loading state */
.guides-content[aria-busy="true"] {
  opacity: 0.6;
  pointer-events: none;
}

/* ============================================================================
   Entry Animations
   ============================================================================ */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reset animations when filtering changes */
.guide-card,
.guide-section {
  animation-fill-mode: both;
}

/* When animating, reset and re-trigger animations */
#guides-content.animating .guide-card,
#guides-content.animating .guide-section {
  animation: none !important;
  opacity: 0;
  transform: translateY(20px);
}

/* Re-trigger animations after content is set */
#guides-content:not(.animating) .guide-card {
  animation: fadeInUp 0.6s ease-out forwards;
}

#guides-content:not(.animating) .guide-section {
  animation: fadeInUp 0.7s ease-out forwards;
}

/* Ensure hover transforms work with animations */
.guide-card:hover {
  transform: translateY(-2px) !important;
}

