/* =====================================================
   Site-wide Search - Full Screen Overlay
   ===================================================== */

/* Full-screen overlay - covers entire viewport */
/* iOS Layout Fix: Extend modal to bottom of viewport with padding for safe area */
.rd-search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(82, 197, 255, 1);
  z-index: 999999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* iOS: Account for safe areas */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Inline mode: top and height set dynamically via JS to position below header */
.rd-search-overlay.rd-inline-mode .rd-search-header {
  display: none;
}

.rd-search-overlay.rd-inline-mode .rd-search-close {
  position: absolute;
  top: 0.75rem;
  right: 1.5rem;
}

/* Inner container - full width, scrollable */
.rd-search-overlay-inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* =====================================================
   Search Header (shown in overlay mode)
   ===================================================== */
.rd-search-header {
  flex-shrink: 0;
  padding: 1.5rem 2rem;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.rd-search-input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
}

.rd-search-input-wrapper svg.rd-search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: #888;
  pointer-events: none;
  width: 20px;
  height: 20px;
}

.rd-search-input-wrapper input.rd-search-input,
input.rd-search-input[type="text"] {
  width: 100%;
  padding: 1rem 6rem 1rem 3rem !important;
  font-size: 1.25rem;
  border: none;
  border-radius: 8px;
  background: #fff;
  outline: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.rd-search-input-wrapper input.rd-search-input:focus {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.rd-search-input-wrapper input.rd-search-input::placeholder {
  color: #999;
}

.rd-search-count {
  position: absolute;
  right: 4rem;
  top: 50%;
  transform: translateY(-50%);
  color: #666;
  font-size: 0.9rem;
  white-space: nowrap;
  pointer-events: none;
}

/* Clear button inside search input */
.rd-search-input-clear {
  position: absolute;
  right: 5.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: #ccc;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  transition: background-color 0.2s;
}

.rd-search-input-clear:hover {
  background: #999;
}

.rd-search-input-clear svg {
  width: 12px;
  height: 12px;
}

/* =====================================================
   Close Button
   ===================================================== */
.rd-search-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  cursor: pointer;
  padding: 0.75rem;
  color: #fff;
  border-radius: 50%;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rd-search-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.rd-search-close svg {
  width: 24px;
  height: 24px;
  display: block;
}

/* =====================================================
   Results Area
   ===================================================== */
.rd-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}

.rd-search-results-grid {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

/* Placeholder / Loading / Error states */
.rd-search-placeholder,
.rd-search-loading,
.rd-search-no-results,
.rd-search-error {
  text-align: center;
  padding: 4rem 2rem;
  color: rgba(255, 255, 255, 0.6);
  font-size: 1.1rem;
  max-width: 1400px;
  margin: 0 auto;
}

.rd-search-error {
  color: #ff6b6b;
}

/* No Results - friendly message */
.rd-search-no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.rd-search-no-results-image {
  width: 100%;
  max-width: 800px;
  height: auto;
  border-radius: 12px;
  margin-bottom: 1rem;
}

.rd-search-no-results-text {
  font-size: 1.25rem;
  color: #fff;
  margin: 0;
}

.rd-search-no-results-hint {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.7);
  margin: 0.5rem 0 1rem;
}

.rd-search-no-results-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.rd-search-suggestion-btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  background: #fff;
  color: #333;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.95rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.rd-search-suggestion-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* =====================================================
   Search Result Cards
   ===================================================== */
.rd-search-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.rd-search-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}

/* Card Image */
.rd-search-card-image {
  height: 140px;
  background-size: cover;
  background-position: center;
  background-color: #e0e0e0;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.5rem;
  gap: 0.5rem;
}

.rd-search-card-image.rd-no-image {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Badges */
.rd-search-card-type-badge {
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rd-search-card-cat-badge {
  background: #2271b1;
  color: #fff;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
}

/* Card Content */
.rd-search-card-content {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.rd-search-card-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #333;
  line-height: 1.3;
}

.rd-search-card-excerpt {
  color: #666;
  font-size: 0.85rem;
  margin: 0;
  flex: 1;
  line-height: 1.4;
}

.rd-search-card-date {
  font-size: 0.75rem;
  color: #999;
  margin-top: 0.75rem;
}

/* =====================================================
   Load More
   ===================================================== */
.rd-search-load-more {
  flex-shrink: 0;
  display: none; /* Hidden by default, shown via JS when has_more */
  justify-content: center;
  padding: 1.5rem 2rem 2rem;
  background: transparent;
}

.rd-search-load-more.rd-visible {
  display: flex;
}

.rd-search-more-btn {
  padding: 0.75rem 2.5rem;
  background: #fff;
  color: #333;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.2s, transform 0.2s;
}

.rd-search-more-btn:hover {
  background: #f0f0f0;
  transform: translateY(-1px);
}

/* =====================================================
   Keyboard Hint
   ===================================================== */
.rd-search-hint {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.8rem;
}

.rd-search-hint kbd {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-family: inherit;
  margin: 0 0.2rem;
}

/* =====================================================
   Inline Search Field (for header integration)
   ===================================================== */
.rd-inline-search-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.rd-inline-search-wrapper input.rd-inline-search-input,
input.rd-inline-search-input[type="text"] {
  padding: 0.6rem 1rem 0.6rem 35px !important;
  font-size: 0.95rem;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #f5f5f5;
  outline: none;
  width: 220px;
  transition: all 0.2s ease;
}

.rd-inline-search-wrapper input.rd-inline-search-input:focus,
input.rd-inline-search-input[type="text"]:focus {
  width: 300px;
  background: #fff;
  border-color: #2271b1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.rd-inline-search-wrapper input.rd-inline-search-input::placeholder {
  color: #888;
}

.rd-inline-search-wrapper svg.rd-inline-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  pointer-events: none;
  width: 16px;
  height: 16px;
  transition: color 0.2s;
}

.rd-inline-search-wrapper:focus-within svg.rd-inline-search-icon {
  color: #2271b1;
}

/* Clear button inside inline search */
.rd-inline-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  background: #999;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  transition: background-color 0.2s;
}

.rd-inline-search-clear:hover {
  background: #666;
}

.rd-inline-search-clear svg {
  width: 10px;
  height: 10px;
}

/* Adjust input padding when clear button is visible */
.rd-inline-search-wrapper input.rd-inline-search-input {
  padding-right: 35px !important;
}

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 768px) {
  /* Mobile: Keep normal order, just style the header at bottom using fixed positioning */
  .rd-search-overlay {
    flex-direction: column;
  }

  .rd-search-overlay-inner {
    flex-direction: column;
    padding-bottom: 80px; /* Space for fixed search bar at bottom */
  }

  /* Fixed search bar at bottom on mobile */
  .rd-search-header {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    border-bottom: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    background: rgba(0, 0, 0, 0.3);
    z-index: 1000002;
  }

  /* Search input wrapper with close button inline */
  .rd-search-input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: center;
  }

  .rd-search-input-wrapper input.rd-search-input,
  input.rd-search-input[type="text"] {
    flex: 1;
    padding: 0.875rem 1rem 0.875rem 2.75rem !important;
    font-size: 1rem;
  }

  /* Hide count on mobile - not enough space */
  .rd-search-count {
    display: none;
  }

  /* Close button inline with search on mobile */
  .rd-search-close {
    position: relative;
    top: auto;
    right: auto;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.2);
  }

  .rd-search-close svg {
    width: 20px;
    height: 20px;
  }

  .rd-search-icon {
    left: 0.875rem;
    width: 18px;
    height: 18px;
  }

  .rd-search-results {
    padding: 1rem;
    padding-top: 0.5rem;
  }

  .rd-search-results-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
  }

  .rd-search-card-image {
    height: 120px;
  }

  .rd-inline-search-input {
    width: 160px;
  }

  .rd-inline-search-input:focus {
    width: 200px;
  }

  /* Hide keyboard hint on mobile */
  .rd-search-hint {
    display: none;
  }
}

@media (max-width: 480px) {
  .rd-search-results-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  /* Compact horizontal card layout for mobile */
  .rd-search-card {
    flex-direction: row;
    height: auto;
    min-height: 72px;
  }

  .rd-search-card-image {
    width: 72px;
    min-width: 72px;
    height: 72px;
    flex-shrink: 0;
    padding: 0;
  }

  /* Hide badges on compact cards */
  .rd-search-card-type-badge,
  .rd-search-card-cat-badge {
    display: none;
  }

  .rd-search-card-content {
    padding: 0.5rem 0.75rem;
    justify-content: center;
    min-width: 0; /* Allow text truncation */
  }

  .rd-search-card-title {
    font-size: 0.875rem;
    margin: 0 0 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .rd-search-card-excerpt {
    font-size: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
  }

  .rd-search-card-date {
    display: none;
  }

  /* Reduce padding on results area */
  .rd-search-results {
    padding: 0.5rem;
  }
}

/* =====================================================
   Input Position Classes (top vs bottom)
   Controls where search input appears based on trigger source
   ===================================================== */

/* Input at bottom (default for mobile, triggered from bottom bar) */
.rd-search-overlay.rd-input-bottom .rd-search-overlay-inner {
  flex-direction: column;
  padding-bottom: 80px;
}

.rd-search-overlay.rd-input-bottom .rd-search-header {
  position: fixed;
  bottom: 0;
  top: auto;
  left: 0;
  right: 0;
  padding: 1rem;
  border-bottom: none;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  background: var(--rd-search-header-bg, rgba(255, 255, 255, 0.98));
  z-index: 1000002;
}

/* Input at top (triggered from top bar) */
.rd-search-overlay.rd-input-top .rd-search-overlay-inner {
  flex-direction: column;
  padding-top: 0;
  padding-bottom: 0;
}

.rd-search-overlay.rd-input-top .rd-search-header {
  position: relative;
  top: auto;
  bottom: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  border-top: none;
}
