/* SEARCH MODULE STYLES */

.search-surface {
  background: transparent;
  border: none;
  border-radius: 0;
  overflow: visible;
  max-width: 720px;
  margin: 0 auto;
}

.search-head {
  margin-bottom: 14px;
}

.search-box {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

#view-search .search-box {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

/* Search input row: mobile back button + input. On desktop the back button is
   hidden, leaving this a plain wrapper around the input (no visual change). */
.search-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-input-row .input-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

/* Mobile-only back-to-Home affordance for the full-page Search screen. */
.search-mobile-back {
  display: none;
}

/* Clean entry sheet (mobile): until the user types (or arrives via a ?q= /
   ?category= deep link), the Search screen shows only back button + input —
   no filter row, no auto-loaded results. Toggled by search.js via
   .search-entry-mode on #view-search. Desktop never enters this mode. */
.search-entry-hint {
  display: none;
}

@media (max-width: 720px) {

  /* !important needed on the filters row only: it counters the existing
     `.mobile-filters { display: flex !important }` show rule above (state
     attribute interop per the override policy). Applies to both pre-commit
     stages: entry (empty) and suggest (typing). */
  #view-search.search-entry-mode .search-mobile-filters,
  #view-search.search-suggest-mode .search-mobile-filters {
    display: none !important;
  }

  #view-search.search-entry-mode .search-results-label,
  #view-search.search-entry-mode .search-people,
  #view-search.search-entry-mode #searchResults,
  #view-search.search-entry-mode #searchResultsFooter,
  #view-search.search-suggest-mode .search-results-label,
  #view-search.search-suggest-mode .search-people,
  #view-search.search-suggest-mode #searchResults,
  #view-search.search-suggest-mode #searchResultsFooter {
    display: none;
  }

  /* Reddit-style full-screen search: on mobile the search screen REPLACES the
     site top bar. Hide the shared header (logo/location/menu) for the whole
     search view — the back-button + input row becomes the top app bar. */
  body.view-search .topbar-wrap {
    display: none;
  }

  /* Zero the shell's top + side gutters so the search view fills the screen
     edge-to-edge. (Negative margins were used before, but they let long
     non-wrapping suggestion text push the view WIDER than the viewport, causing
     horizontal overflow — the input and rows spilled off the right edge.) */
  body.view-search .layout-wrapper {
    padding-top: 0;
    padding-left: 0;
    padding-right: 0;
  }

  /* CRITICAL: .page is a grid item (layout-wrapper is display:grid). Grid items
     default to min-width:auto, which refuses to shrink below their content's
     min-content width — the nowrap suggestion text then forces .page (and the
     whole search view) WIDER than the 1fr track, spilling off the right edge.
     min-width:0 lets it shrink back to the viewport so text can ellipsize. */
  body.view-search .page {
    min-width: 0;
  }

  body.view-search #view-search {
    margin: 0;
    padding-top: 0;
    min-width: 0;
    background: #fff;
    min-height: 100vh;
    /* Belt-and-braces: never let a stray wide child scroll the sheet sideways. */
    overflow-x: hidden;
  }

  #view-search .search-suggest-item {
    min-width: 0;
  }

  /* The input row IS the sticky top app bar (back arrow + search field). */
  #view-search .search-head {
    /* NOT sticky: the filter row lives inside this app bar, and pinning it while
       scrolling would eat a big chunk of the screen and hide results (Reddit
       lets the whole search+filters bar scroll away). So it stays in normal
       flow — scroll up to bring the search bar back. */
    position: static;
    margin: 0;
    background: #fff;
    /* 16px sides = the shared content gutter (matches results label + posts).
       The filter row lives inside this app bar, so it inherits this inset. */
    padding: max(10px, env(safe-area-inset-top)) 16px 10px;
    border-bottom: 1px solid #F1F5F9;
  }

  /* Suggest stage: Reddit-style plain rows under the input. */
  .search-suggest-list {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Rows go full-bleed and flat on the white sheet (no card/menu look). */
  #view-search.search-suggest-mode .search-suggest-item {
    border-radius: 0;
    padding: 14px 16px;
  }

  #view-search.search-suggest-mode .search-suggest-section {
    padding: 14px 16px 4px;
  }

  /* Results stage: the app bar + suggestion sheet are intentionally full-bleed,
     but now that the shell side gutters are removed the RESULTS content would
     hug the screen edges. Give it back the same 16px gutter (posts already
     inset by 16px; the filter row inherits its inset from the app bar). */
  #view-search .search-results-label,
  #view-search .search-people-heading,
  #view-search .search-people-list,
  #view-search .search-results-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* The result count sits directly under the filter row / separator line — give
     it clear breathing room above so it isn't cramped against the divider. */
  #view-search .search-results-label {
    margin-top: 16px;
    margin-bottom: 14px;
  }

  .search-suggest-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    /* border-box so 100% width + padding can't push past the right edge. */
    box-sizing: border-box;
    padding: 14px 8px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    border-radius: 10px;
  }

  .search-suggest-item:hover,
  .search-suggest-item:active {
    background: #F8FAFC;
  }

  .search-suggest-item-icon {
    display: inline-flex;
    color: var(--muted);
    flex-shrink: 0;
  }

  .search-suggest-item-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* "People" section label between query rows and profile rows. */
  .search-suggest-section {
    padding: 12px 8px 4px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
  }

  /* Profile suggestion rows: avatar + name + handle (Reddit-style). */
  .search-suggest-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
  }

  .search-suggest-avatar--fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #E2E8F0;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
  }

  .search-suggest-person-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .search-suggest-person-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .search-suggest-person-handle {
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #view-search.search-entry-mode .search-entry-hint {
    display: block;
    padding: 56px 16px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
  }

  .search-entry-hint p {
    margin: 0;
  }
}

/* 720px = the mobile-web breakpoint where the desktop left nav / filter sidebar
   is hidden and Search becomes a full-page screen, so the back button appears. */
@media (max-width: 720px) {
  .search-mobile-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    margin-left: -6px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    cursor: pointer;
  }

  .search-mobile-back:hover {
    background: #F1F5F9;
  }
}

.input-wrap {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #94A3B8;
  z-index: 2;
  pointer-events: none;
}

.input {
  width: 100%;
  min-height: 52px;
  padding: 12px 40px 12px 42px;
  /* indent for icon */
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  outline: none;
  box-shadow: none;
}

.input:focus {
  border-color: #94a3b8;
  box-shadow: none;
}

.search-clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: #64748b;
  border-radius: 999px;
  cursor: pointer;
}

.search-clear-btn[hidden] {
  display: none !important;
}

.search-clear-btn:hover {
  background: #f1f5f9;
  color: #334155;
}

.search-clear-btn:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 1px;
}

.filters {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-mobile-filters {
  margin-top: 12px;
}

.search-mobile-loc-trigger {
  width: 150px;
  cursor: pointer;
}

.search-mobile-cat-filter {
  width: 130px;
}

.search-dynamic-filters-mobile {
  display: none;
  width: 100%;
  margin-top: 10px;
}

select.filter-input,
input.filter-input {
  appearance: none;
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
}

select.filter-input {
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, #94A3B8 50%),
    linear-gradient(135deg, #94A3B8 50%, transparent 50%);
  background-position:
    calc(100% - 14px) calc(50% - 2.5px),
    calc(100% - 9px) calc(50% - 2.5px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

select.filter-input:hover,
input.filter-input:hover {
  background-color: #F8FAFC;
  border-color: #CBD5E1;
}

select.filter-input:focus,
input.filter-input:focus {
  outline: none;
  border-color: var(--brand-dark);
}

.search-results-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 12px;
}

body.view-search #view-search .search-surface #searchResults {
  background: transparent;
  border: 0;
  border-radius: 0;
  gap: 16px;
  overflow: visible;
  padding-bottom: 80px;
}

.search-results-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0 0;
}

.search-results-footer[hidden] {
  display: none !important;
}

.search-results-loading {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid var(--border, #e2e8f0);
  color: var(--muted, #64748b);
  font-size: 13px;
  font-weight: 600;
}

.search-results-loading[hidden] {
  display: none !important;
}

.search-results-spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid #cbd5e1;
  border-top-color: #0ea5e9;
  animation: search-results-spin 0.8s linear infinite;
}

.search-empty-state {
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 14px;
  padding: 22px 18px;
  text-align: center;
  color: var(--muted, #64748b);
}

.search-empty-state-icon {
  display: none;
}

.search-empty-state-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text, #0f172a);
}

.search-empty-state-copy {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.45;
}

body.view-search #view-search .search-surface #searchResults>.post {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  border: 0;
  border-radius: 18px;
  box-shadow: none;
  padding: 14px 26px 0;
  transition: background-color 60ms linear;
}

body.view-search #view-search .search-surface #searchResults>.post::after {
  left: 26px;
  right: 26px;
}

body.view-search #view-search .search-surface #searchResults>.post:hover {
  background: #F4F6F8;
  box-shadow: none;
}

body.view-search #view-search .search-surface #searchResults>.post .p-head {
  margin-bottom: 8px;
}

body.view-search #view-search .search-surface #searchResults>.post .p-user {
  gap: 7px;
  align-items: center;
}

body.view-search #view-search .search-surface #searchResults>.post .avatar {
  width: 26px;
  height: 26px;
}

body.view-search #view-search .search-surface #searchResults>.post .who {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  flex-wrap: wrap;
  line-height: 1.2;
}

body.view-search #view-search .search-surface #searchResults>.post .who .name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: #0F1A1C;
}

body.view-search #view-search .search-surface #searchResults>.post .meta-line {
  font-size: 12px;
  font-weight: 400;
  gap: 5px;
  margin-top: 0;
  color: #576F76;
  line-height: 1.2;
}

body.view-search #view-search .search-surface #searchResults>.post .title {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.32;
  letter-spacing: 0;
  color: #101214;
  margin: 0 0 8px 0 !important;
}

body.view-search #view-search .search-surface #searchResults>.post .desc {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.48;
  color: #1f2933;
  margin: 0 0 12px 0 !important;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body.view-search #view-search .search-surface #searchResults>.post[data-has-media="true"] .desc {
  display: none;
}

body.view-search #view-search .search-surface #searchResults>.post .post-foot {
  justify-content: flex-start !important;
  gap: 12px;
  margin-left: -26px;
  margin-right: -26px;
  padding-left: 26px;
  padding-right: 26px;
}

body.view-search #view-search .search-surface #searchResults>.post .post-foot>div:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

body.view-search #view-search .search-surface #searchResults>.post .posts-card-actions {
  margin-left: auto;
}

body.view-search #view-search .search-surface #searchResults>.post .posts-card-actions--full {
  gap: 0;
}

/* Like / Views / Share / Comments styling lives in the single-source
   `.post-foot` block in posts-card.css — do not re-add per-surface copies. */

body.view-search #view-search .search-surface #searchResults>.post .posts-meta-chip,
body.view-search #view-search .search-surface #searchResults>.post .posts-recommendation-chip {
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
}

body.view-search #view-search .search-surface #searchResults>.post .posts-recommendation-chip {
  background: rgba(37, 99, 235, 0.06);
  border-color: rgba(37, 99, 235, 0.12);
}

@keyframes search-results-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Sidebar Widget Styles */
/* Back to previous page — the nav rail is hidden on Search, so this is the
   return affordance in the left column. */
.search-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 8px;
  margin: 0 0 10px -4px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.search-back-btn:hover {
  background: #F1F5F9;
  color: var(--text);
}

/* Desktop: the top-bar search is the single search entry, so the in-page box
   is hidden (results still render below). Mobile web (<=720px): the top-bar
   search is hidden there, and this in-page box IS the full-page search sheet
   input (back button + focused field), so it must stay visible. */
@media (min-width: 721px) {
  #view-search .search-head {
    display: none;
  }
}

.search-sidebar-widget {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
}

.widget-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 16px 0;
}

.widget-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

/* Sidebar Specific Overrides */
.search-sidebar-widget .filter-input {
  width: 100%;
}

.search-sidebar-widget .date-picker-wrapper {
  width: 100%;
}

.search-sidebar-widget .date-picker-trigger {
  width: 100%;
  justify-content: space-between;
}

.search-sidebar-dynamic-filters {
  display: none;
  flex-direction: column;
  gap: 12px;
}

/* Sidebar Filters Visibility (moved from global style.css) */
.search-filters-sidebar {
  display: none;
}

body.view-search .search-filters-sidebar {
  display: block;
}

body.view-search .quick-links-widget {
  display: none;
}

/* Mobile Filters (moved from global style.css) */
.mobile-filters {
  display: none !important;
}

@media (max-width: 900px) {
  .mobile-filters {
    display: flex !important;
  }

  .search-surface {
    max-width: 100%;
  }

  .search-head {
    margin-bottom: 10px;
  }

  #view-search .input {
    min-height: 50px;
    /* Match the Home bar's Reddit-style pill shape. */
    border-radius: 999px;
  }

  body.view-search #view-search .search-surface #searchResults>.post {
    padding: 16px 16px 0;
  }

  body.view-search #view-search .search-surface #searchResults>.post::after {
    left: 16px;
    right: 16px;
  }

  body.view-search #view-search .search-surface #searchResults>.post .p-head {
    margin-bottom: 7px;
  }

  body.view-search #view-search .search-surface #searchResults>.post .p-user {
    gap: 7px;
    align-items: flex-start;
  }

  body.view-search #view-search .search-surface #searchResults>.post .who {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 2px;
  }

  body.view-search #view-search .search-surface #searchResults>.post .who .name {
    font-size: 12px;
  }

  body.view-search #view-search .search-surface #searchResults>.post .meta-line {
    font-size: 12px;
    line-height: 1.4;
  }

  body.view-search #view-search .search-surface #searchResults>.post .title {
    font-size: 16.5px;
    font-weight: 600;
    line-height: 1.32;
  }

  body.view-search #view-search .search-surface #searchResults>.post .desc {
    font-size: 14.5px;
    line-height: 1.48;
    -webkit-line-clamp: 2;
  }

  body.view-search #view-search .search-surface #searchResults>.post .post-foot {
    gap: 8px;
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* Search view input needs room for clear button */
#view-search .input {
  padding-right: 40px;
}

/* Clear button for search input */
.search-clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: #64748b;
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
}

.search-clear-btn:hover {
  background: #f1f5f9;
  color: #334155;
}

.search-clear-btn:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 1px;
}

.search-clear-btn[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .search-results-spinner {
    animation: none;
  }
}

/* Match the refined home-feed card rhythm for search results only. */
body.view-search #view-search .search-surface #searchResults>.post .title {
  margin-bottom: 6px !important;
}

body.view-search #view-search .search-surface #searchResults>.post .posts-card-desc-preview {
  display: -webkit-box !important;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0 0 10px 0 !important;
  color: #0F1A1C;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.42;
  /* Keep the author's line breaks in the clamped long-post preview (tweet-style),
     matching the home feed. */
  white-space: pre-wrap;
}

body.view-search #view-search .search-surface #searchResults>.post .post-foot {
  margin-top: 8px !important;
  padding-top: 2px !important;
}

body.view-search #view-search .search-surface #searchResults>.post:hover {
  background: #F8FAFC !important;
  box-shadow: none !important;
}

@media (max-width: 900px) {
  body.view-search #view-search .search-surface #searchResults>.post .title {
    margin-bottom: 5px !important;
  }

  body.view-search #view-search .search-surface #searchResults>.post .posts-card-desc-preview {
    -webkit-line-clamp: 2;
    margin-bottom: 8px !important;
    font-size: 13px;
    line-height: 1.42;
  }

  body.view-search #view-search .search-surface #searchResults>.post .post-foot {
    margin-top: 6px !important;
    padding-top: 2px !important;
  }
}

/* People results section (profiles), shown above post results. */
.search-people {
  margin: 0 0 18px;
}

.search-people[hidden] {
  display: none;
}

.search-people-heading {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted, #64748b);
}

.search-people-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.search-person-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.search-person-card:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.search-person-avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #e2e8f0;
}

.search-person-avatar--fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary, #0ba8d2);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.search-person-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.search-person-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 500;
  color: var(--text, #0f172a);
}

.search-person-handle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--muted, #64748b);
}

@media (max-width: 900px) {
  .search-people-list {
    grid-template-columns: 1fr;
  }
}
