/* NISearch search form: field, "Найти" button, autocomplete, category tabs and the sticky results header.
   Shared by the home page (home.css sets its sizes) and the results page. */

/* Field */
.search_box {
  position: relative;
  display: flex;
  align-items: center;
  height: var(--nis-header-search-height);
  padding-right: var(--nis-space-1);
  background: var(--nis-surface-raised);
  border: 1px solid var(--nis-border-strong);
  border-radius: var(--nis-radius-lg);
  box-shadow: var(--nis-shadow-card);
  transition: border-color var(--nis-motion-fast) var(--nis-motion-easing);
}

.search_box:focus-within {
  border-color: var(--nis-focus);
  outline: 2px solid var(--nis-focus);
  outline-offset: 0;
}

.search_box input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0 var(--nis-space-4);
  border: 0;
  outline: none;
  background: transparent;
  color: var(--nis-text);
  font-size: var(--nis-font-lg);
  text-overflow: ellipsis;
}

.search_box input[type="text"]:focus-visible {
  outline: none;
}

.search_box input[type="text"]::placeholder {
  color: var(--nis-text-subtle);
  opacity: 1;
}

/* Clear (x): visible only while the field has text (nisearch.js toggles .has-text). */
.clear_button {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--nis-radius-full);
  color: var(--nis-text-subtle);
  transition: background-color var(--nis-motion-fast) var(--nis-motion-easing),
              color var(--nis-motion-fast) var(--nis-motion-easing);
}

.search_box.has-text .clear_button {
  display: flex;
}

.clear_button:active {
  background: var(--nis-surface-active);
}

@media (hover: hover) {
  .clear_button:hover {
    background: var(--nis-surface-hover);
    color: var(--nis-text);
  }
}

/* "Найти" button inside the field, on the right. */
.send_button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--nis-space-2);
  flex: none;
  height: calc(100% - 8px);
  min-width: 44px;
  margin-left: var(--nis-space-1);
  padding: 0 var(--nis-space-4);
  border-radius: var(--nis-radius-md);
  background: var(--nis-accent);
  color: var(--nis-accent-fg);
  font-size: var(--nis-font-md);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background-color var(--nis-motion-fast) var(--nis-motion-easing);
}

@media (prefers-reduced-motion: no-preference) {
  .send_button {
    transition: background-color var(--nis-motion-fast) var(--nis-motion-easing),
                transform 150ms ease-out;
  }

  .send_button:not(:disabled):active {
    transform: scale(0.96);
  }
}

@media (hover: hover) {
  .send_button:not(:disabled):hover {
    background: var(--nis-accent-hover);
  }
}

.send_button:disabled {
  opacity: 0.5;
  cursor: default;
}

.send_icon {
  display: inline-flex;
}

.send_icon .sxng-icon-set-big {
  width: 18px;
  height: 18px;
}

/* Autocomplete: upstream toggles .open; items are 40 px tall, the active one has a hover fill.
   The matched prefix stays regular, the completion (.ac_rest) is 600. */
.autocomplete {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  overflow: hidden;
  background: var(--nis-surface-raised);
  border-radius: var(--nis-radius-lg);
  box-shadow: var(--nis-shadow-popover);
  text-align: left;
}

.autocomplete.open {
  display: block;
}

.autocomplete:has(> ul:empty) {
  display: none;
}

.autocomplete ul {
  margin: 0;
  padding: var(--nis-space-1) 0;
  list-style: none;
}

.autocomplete li {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 var(--nis-space-4);
  overflow: hidden;
  color: var(--nis-text);
  font-size: var(--nis-font-lg);
  font-weight: 400;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}

.autocomplete li.active {
  background: var(--nis-surface-hover);
}

@media (hover: hover) {
  .autocomplete li:hover {
    background: var(--nis-surface-hover);
  }
}

.autocomplete li .ac_rest {
  font-weight: 600;
}

.autocomplete li.no-item-found {
  color: var(--nis-text-muted);
  cursor: default;
}

/* Category tabs (results page). Chips on the home page are styled in home.css. */
.search_categories {
  min-width: 0;
}

.tabs_list {
  display: flex;
  align-items: stretch;
  height: 40px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tabs_list::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: none;
  height: 100%;
  padding: 0 var(--nis-space-3);
  color: var(--nis-text-muted);
  font-size: var(--nis-font-md);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--nis-motion-fast) var(--nis-motion-easing);
}

.tab::after {
  content: "";
  position: absolute;
  left: var(--nis-space-3);
  right: var(--nis-space-3);
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: transparent;
}

.tab.selected {
  color: var(--nis-text);
}

.tab.selected::after {
  background: var(--nis-accent);
}

@media (hover: hover) {
  .tab:hover {
    color: var(--nis-text);
  }
}

/* No-JS fallback with checkboxes (only when search_on_category_select is off). */
.checkboxes .category_checkbox {
  position: relative;
  flex: none;
}

.checkboxes .category_checkbox input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkboxes .category_checkbox input:checked + .tab {
  color: var(--nis-text);
}

.checkboxes .category_checkbox input:checked + .tab::after {
  background: var(--nis-accent);
}

.checkboxes .category_checkbox input:focus-visible + .tab {
  outline: 2px solid var(--nis-focus);
  outline-offset: -2px;
}

/* Results header: one sticky block (logo, field, actions, tabs). Layout:
   column 1 = logo (152 px), column 2 = field (max 720 px), column 4 = actions.
   The results column and filters start at the same x (see .search_filters). */
#main_results > #search {
  display: contents;
}

#main_results #search_header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 152px minmax(0, 720px) minmax(0, 1fr) auto;
  align-items: center;
  column-gap: var(--nis-space-4);
  padding: var(--nis-space-3) var(--nis-space-5) 0;
  background: var(--nis-surface);
  border-bottom: 1px solid var(--nis-border);
}

#main_results #search_logo {
  grid-column: 1;
}

#main_results #search_view {
  grid-column: 2;
  min-width: 0;
}

#main_results #search_view .search_box {
  height: var(--nis-header-search-height);
}

#main_results #search_view .search_box input[type="text"] {
  font-size: var(--nis-font-lg);
}

#main_results #categories {
  grid-column: 2 / -1;
  grid-row: 2;
  min-width: 0;
}

.header_actions {
  display: flex;
  align-items: center;
  gap: var(--nis-space-1);
}

#main_results .header_actions {
  grid-column: 4;
}

/* Filters row under the header (time, language, safe search). T3 styles the controls. */
.search_filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--nis-space-2);
  padding: var(--nis-space-3) var(--nis-space-5) 0 calc(var(--nis-space-5) + 152px + var(--nis-space-4));
}

@media (max-width: 719px) {
  #main_results #search_header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    column-gap: var(--nis-space-2);
    padding: var(--nis-space-2) var(--nis-space-3) 0;
  }

  #main_results #search_logo .logo_word {
    display: none;
  }

  #main_results #search_logo {
    grid-column: 1;
  }

  #main_results #search_view {
    grid-column: 2;
  }

  #main_results .header_actions {
    grid-column: 3;
  }

  #main_results .header_actions .theme_toggle {
    display: none;
  }

  #main_results #categories {
    grid-column: 1 / -1;
    grid-row: 2;
    margin: 0 calc(-1 * var(--nis-space-3));
    padding: 0 var(--nis-space-3);
  }

  .search_filters {
    padding: var(--nis-space-2) var(--nis-space-3) 0;
  }
}

@media (max-width: 599px) {
  #search_view .send_text {
    display: none;
  }

  #search_view .send_button {
    min-width: 40px;
    padding: 0 var(--nis-space-3);
  }
}
