/* Sonar Search - Custom Theme
 * Clean, professional design
 */

/* ============================================
   Global - Prevent Horizontal Overflow
   ============================================ */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* ============================================
   CSS Custom Properties - Monochrome Theme
   ============================================ */
:root {
  --sonar-primary: #1a1a1a;
  --sonar-primary-hover: #333333;
  --sonar-accent: #555555;

  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-hover: #f5f5f5;
  --bg-footer: #1a1a1a;

  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #888888;
  --text-inverse: #ffffff;

  --border-color: #e0e0e0;
  --border-radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

.theme-dark {
  --sonar-primary: #ffffff;
  --sonar-primary-hover: #e0e0e0;
  --sonar-accent: #aaaaaa;

  --bg-primary: #121212;
  --bg-secondary: #1a1a1a;
  --bg-hover: #252525;
  --bg-footer: #0a0a0a;

  --text-primary: #f5f5f5;
  --text-secondary: #b0b0b0;
  --text-muted: #707070;
  --text-inverse: #1a1a1a;

  --border-color: #333333;
}

/* ============================================
   Homepage
   ============================================ */
.index_endpoint {
  background: var(--bg-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.index_endpoint #links_on_top {
  position: absolute;
  top: 0;
  right: 0;
}

.index_endpoint footer {
  margin-top: auto;
}

.index {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 2rem 1rem;
  margin-top: -3rem; /* Offset to visually center accounting for footer */
}

/* Logo */
.index .title {
  background: none !important;
  margin-bottom: 0.5rem;
}

.index .title h1 {
  visibility: visible !important;
  font-size: 0;
}

.index .title img {
  max-width: 500px;
  width: 90vw;
  height: auto;
  aspect-ratio: 840 / 236; /* Reserve space to prevent layout shift */
}

/* Homepage search form - contains both search input and categories */
.index .search_box {
  width: 90vw;
  max-width: 800px;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  white-space: normal !important;
}

.index .search_box:focus-within {
  border-color: transparent !important;
  box-shadow: none !important;
}

/* Force input and button to stay together on same line */
.index #q {
  flex: 1 1 auto !important;
  min-width: 200px !important;
  max-width: calc(100% - 70px) !important;
  font-size: 1.1rem !important;
  padding: 1rem 1.25rem !important;
  background: var(--bg-primary) !important;
  border: 2px solid var(--border-color) !important;
  border-radius: 10px 0 0 10px !important;
  border-right: none !important;
  transition: border-color 0.2s !important;
}

.index #q:focus {
  outline: none !important;
  border-color: var(--sonar-primary) !important;
}

.index #send_search {
  flex: 0 0 auto !important;
  padding: 0.875rem 1.5rem !important;
  margin: 0 !important;
  border-radius: 0 10px 10px 0 !important;
  border: 2px solid var(--border-color) !important;
  border-left: none !important;
}

.index .search_box:focus-within #send_search {
  border-color: var(--sonar-primary) !important;
}

/* ============================================
   Landing Page Categories - Custom Implementation
   ============================================ */
.landing-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1.25rem;
  width: 100%;
  flex: 0 0 100%;
}

.landing-category {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: #f0f0f0;
  border: 1px solid #d0d0d0;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.landing-category:hover {
  background: #e5e5e5;
  border-color: #999999;
  color: var(--text-primary);
}

.landing-category.active {
  background: var(--sonar-primary);
  border-color: var(--sonar-primary);
  color: var(--text-inverse);
}

.landing-category svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   Search Box - All Pages
   ============================================ */
.search_box {
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search_box:focus-within {
  border-color: var(--sonar-primary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.theme-dark .search_box:focus-within {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

/* Search input */
#q {
  font-size: 1rem;
  color: var(--text-primary);
  background: transparent;
  border: none;
  padding: 0.875rem 1rem;
}

#q::placeholder {
  color: var(--text-muted);
}

/* Search button */
#send_search {
  background: var(--sonar-primary);
  border: none;
  border-radius: 8px;
  margin: 5px;
  padding: 0.75rem 1.25rem;
  color: var(--text-inverse);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#send_search svg {
  color: var(--text-inverse);
  fill: var(--text-inverse);
  stroke: var(--text-inverse);
}

#send_search:hover {
  background: var(--sonar-primary-hover);
}

#send_search:active {
  transform: scale(0.98);
}

/* Clear button - circular X matching landing page */
#clear_search {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 24px !important;
  height: 24px !important;
  padding: 0 !important;
  margin-right: 0.5rem !important;
  background: #e5e5e5 !important;
  border: none !important;
  border-radius: 50% !important;
  color: var(--text-secondary) !important;
  cursor: pointer !important;
}

#clear_search:hover {
  background: #d5d5d5 !important;
  color: var(--text-primary) !important;
}

#clear_search svg {
  width: 14px !important;
  height: 14px !important;
}

/* ============================================
   Category Tabs
   ============================================ */
#categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 1rem 0 0;
  padding: 0 1rem 1.5rem;
  overflow: visible;
}

/* Note: .index #categories styles removed - using custom .landing-categories instead */

#categories label,
#categories button {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: #f0f0f0;
  border: 1px solid #d0d0d0;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

#categories label:hover,
#categories button:hover {
  background: #e5e5e5;
  border-color: #999999;
  color: var(--text-primary);
}

#categories input:checked + label,
#categories button.active,
#categories label.active {
  background: var(--sonar-primary);
  border-color: var(--sonar-primary);
  color: var(--text-inverse);
}

#categories svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   Results Page Header
   ============================================ */

/* Position About/Preferences in top-right - consistent on all pages */
/* Uses absolute positioning relative to the body (endpoint class) */
.results_endpoint #links_on_top {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 100;
}


/* Search header - uses relative positioning for independent logo placement */
#search_header {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.5rem 0;
  width: 100%;
  position: relative;
}

/* Row container: just for search box centering */
.search_row {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* Sonar wordmark - absolutely positioned left relative to header */
#search_logo {
  position: absolute;
  left: 1.5rem;
  top: 1rem;
  display: flex;
  align-items: center;
}

#search_logo .search-wordmark,
#search_logo .search-signet {
  height: 90px;
  width: auto;
  object-fit: contain;
}

/* Hide the default SVG logo */
#search_logo svg {
  display: none;
}

/* Search view container - centered */
#search_view {
  display: flex;
  justify-content: center;
}

/* Results page search box - matches landing page style */
.results-search-box {
  display: flex !important;
  align-items: stretch !important;
  width: 750px;
}

.results-search-box #q {
  flex: 1 1 auto !important;
  font-size: 1rem !important;
  padding: 0.875rem 1rem !important;
  background: var(--bg-primary) !important;
  border: 2px solid var(--border-color) !important;
  border-radius: 10px 0 0 10px !important;
  border-right: none !important;
  transition: border-color 0.2s !important;
  outline: none !important;
}

.results-search-box #q:focus {
  border-color: var(--sonar-primary) !important;
}

.results-search-box #send_search {
  flex: 0 0 auto !important;
  padding: 0.875rem 1.25rem !important;
  margin: 0 !important;
  border-radius: 0 10px 10px 0 !important;
  border: 2px solid var(--border-color) !important;
  border-left: none !important;
  background: var(--sonar-primary) !important;
  color: var(--text-inverse) !important;
}

.results-search-box:focus-within #q {
  border-color: var(--sonar-primary) !important;
}

.results-search-box:focus-within #send_search {
  border-color: var(--sonar-primary) !important;
}

/* Hide the old search_box wrapper if present */
#search_header .search_box {
  display: none;
}

/* Categories centered */
#search_header #categories {
  width: 100%;
  justify-content: center;
  margin: 0.75rem 0;
  padding: 0;
}

#search_header #categories_container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

/* ============================================
   Filter Bar - 3-Column Layout
   ============================================ */
form#search {
  margin: 0;
  padding: 0;
  width: 100%;
}

#search form .search_filters,
form#search .search_filters,
.search_filters {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  width: 100%;
  margin: 0;
  padding: 0.5rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  box-sizing: border-box;
  min-height: 44px;
}

/* Left section - filters aligned left */
.filters-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-start;
}

/* Center section - results count centered */
.filters-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Right section - download buttons aligned right */
.filters-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Filter dropdowns - pill button style */
.filters-left select,
.search_filters select,
form#search .search_filters select,
#search .filters-left select,
select#language,
select[name="language"],
select[name="time_range"],
select[name="safesearch"] {
  padding: 0.5rem 1rem 0.5rem 1rem !important;
  padding-right: 1.75rem !important;
  font-size: 0.75rem !important;
  color: var(--text-secondary) !important;
  background: var(--bg-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 20px !important;
  cursor: pointer !important;
  outline: none !important;
  box-shadow: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 0.625rem center !important;
  transition: all 0.15s !important;
  max-width: none !important;
  min-width: 0 !important;
  width: auto !important;
  text-overflow: ellipsis;
}

.filters-left select:hover,
.filters-left select:focus,
.search_filters select:hover,
.search_filters select:focus {
  background-color: var(--bg-hover);
  border-color: var(--sonar-primary);
  color: var(--text-primary);
  box-shadow: none;
  outline: none;
}

/* Remove any wrapper styling that might add outline */
.filter,
.search-filter,
[class*="filter"] > div {
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  background: transparent !important;
}

/* Pill button style for right section elements */
.filters-right a,
.filters-right button,
.filters-right .btn,
.filters-right .format-btn {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.filters-right a:hover,
.filters-right button:hover,
.filters-right .format-btn:hover {
  background: var(--bg-hover);
  border-color: var(--sonar-primary);
  color: var(--text-primary);
}


/* Results count in center */
.filters-center #result_count,
.filters-center .result-count,
#result_count {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
  white-space: nowrap;
}


/* ============================================
   Search Results
   ============================================ */
#main_results {
  background: var(--bg-secondary);
}

#results {
  max-width: 850px;
  margin: 0 auto;
  padding: 1rem;
}

/* Answer box / Wikipedia excerpt at top */
#answers,
.answer,
#results > .answer,
#urls ~ div:first-of-type:not(article) {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

#answers p,
.answer p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin: 0 0 0.75rem;
}

#answers a,
.answer a {
  color: var(--sonar-primary);
  text-decoration: none;
}

#answers a:hover,
.answer a:hover {
  text-decoration: underline;
}

/* Result cards */
article.result {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

article.result:hover {
  border-color: var(--sonar-primary);
  box-shadow: var(--shadow-sm);
}

/* Result title */
article.result h3,
article.result .result_title {
  margin: 0 0 0.375rem;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

article.result h3 a,
article.result .result_title a {
  color: var(--sonar-primary);
  text-decoration: none;
}

article.result h3 a:hover,
article.result .result_title a:hover {
  text-decoration: underline;
}

/* Result URL */
article.result .url_wrapper,
article.result .result_url,
article.result .url {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Result content */
article.result .content,
article.result p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

/* Engine badges */
article.result .engines {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

article.result .engines span {
  font-size: 0.6875rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-secondary);
  border-radius: 4px;
  color: var(--text-muted);
}

/* ============================================
   Sidebar Area
   ============================================ */
#sidebar {
  padding: 0 1rem;
}

/* Number of results */
#result_count,
.result-count {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ============================================
   Infobox Sidebar
   ============================================ */
#infoboxes {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

#infoboxes .title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  background: none !important;
}

#infoboxes .infobox {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1rem;
}

#infoboxes .infobox h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

#infoboxes img {
  border-radius: 6px;
  margin-bottom: 0.75rem;
  max-width: 100%;
}

#infoboxes p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0 0 0.75rem;
}

#infoboxes ul {
  margin: 0.75rem 0;
  padding-left: 1.25rem;
}

#infoboxes li {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

#infoboxes a {
  color: var(--sonar-primary);
  text-decoration: none;
}

#infoboxes a:hover {
  text-decoration: underline;
}

/* ============================================
   Navigation
   ============================================ */
#links_on_top {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  justify-content: flex-end;
}

#links_on_top a {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

#links_on_top a:hover {
  background: var(--bg-hover);
  color: var(--sonar-primary);
}

#links_on_top svg {
  width: 18px;
  height: 18px;
}

/* ============================================
   Pagination
   ============================================ */
#pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem 1rem;
  flex-wrap: wrap;
}

/* Page number links - force monochrome on ALL states */
#pagination a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  font-size: 0.875rem;
  color: #4a4a4a !important;
  text-decoration: none !important;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

#pagination a:link,
#pagination a:visited,
#pagination a:active {
  color: #4a4a4a !important;
  text-decoration: none !important;
}

#pagination a:hover {
  background: var(--bg-hover);
  color: #1a1a1a !important;
}

#pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  font-size: 0.875rem;
  color: #4a4a4a !important;
}

/* Current page number */
#pagination .page-number-active,
#pagination .active,
#pagination span.page-number-active,
#pagination a.active {
  font-weight: 600;
  color: var(--text-primary) !important;
}

/* Pagination buttons - outline style to match other UI buttons */
#pagination form button,
#pagination button {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  color: #4a4a4a !important;
  background: #ffffff !important;
  border: 1px solid #e0e0e0 !important;
}

#pagination form button:hover,
#pagination button:hover {
  background: #f5f5f5 !important;
  border-color: #1a1a1a !important;
  color: #1a1a1a !important;
}

/* Previous page button - on left */
#pagination form:first-of-type {
  order: -1;
  margin-right: 0.5rem;
}

/* Next page button - on right */
#pagination form:last-of-type {
  order: 999;
  margin-left: 0.5rem;
}

/* ============================================
   Footer
   ============================================ */
footer {
  background: var(--bg-primary);
  padding: 0.5rem 1rem 0.75rem !important;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  border: none !important;
  border-top: none !important;
  box-shadow: none !important;
  line-height: 1;
  margin: 0 !important;
  min-height: 0 !important;
  height: auto !important;
}

footer p {
  margin: 0 !important;
  padding: 0 !important;
}

footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

footer a:hover {
  color: var(--text-primary);
}

/* ============================================
   Responsive
   ============================================ */

/* Results page header - stack logo above search on narrow screens */
@media (max-width: 900px) {
  #search_header {
    padding-top: 0.75rem;
  }

  #search_logo {
    position: static;
    transform: none;
    margin-bottom: 0.75rem;
  }

  #search_logo .search-wordmark,
  #search_logo .search-signet {
    height: 60px;
  }

  .search_row {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .index .title img {
    max-width: 340px;
  }

  .index .search_box {
    max-width: 100%;
  }

  .index #q {
    font-size: 1rem;
    padding: 0.875rem 1rem;
  }

  #categories {
    gap: 0.375rem;
  }

  #categories label,
  #categories button {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }

  #links_on_top a span {
    display: none;
  }

  article.result {
    padding: 1rem;
  }

  /* Filter bar responsive - stack on narrow screens */
  #search form .search_filters,
  form#search .search_filters {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .filters-left,
  .filters-center,
  .filters-right {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .index .title img {
    max-width: 280px;
  }

  .index #q {
    font-size: 0.9375rem;
  }
}
