/*
 * Учебник: подсказки под полем поиска и выдача на /uchebnik/?q=…
 * Код - mu-plugins/youit-uchebnik-search.php, поведение - youit-uchebnik-search.js.
 * Файл грузится и в статьях, где стилей главной (youit-uchebnik.css) нет, поэтому цвета - с запасными значениями.
 */
.uch-search-ready,
.uch-sr {
  --uchs-black: var(--uch-black, #0c0c0c);
  --uchs-bg: var(--uch-bg, #f5f5f6);
  --uchs-line: var(--uch-line, #e5e5ea);
  --uchs-gray: #8e8e93;
  --uchs-text: #3a3a3c;
  --uchs-green: var(--uch-green, #00b259);
  --uchs-body: var(--uch-body, "Nunito Sans", sans-serif);
  --uchs-head: var(--uch-head, "Nunito", sans-serif);
}
.uch-search-ready [data-subject],
.uch-sr [data-subject] { --uchs-c: var(--uchs-black); }
.uch-search-ready [data-subject="informatika"],
.uch-sr [data-subject="informatika"] { --uchs-c: var(--uch-purple, #bd5697); }
.uch-search-ready [data-subject="matematika"],
.uch-sr [data-subject="matematika"] { --uchs-c: var(--uch-green, #00b259); }

.uch-search-ready mark,
.uch-sr mark {
  padding: 0 1px;
  border-radius: 3px;
  background: rgba(252, 175, 23, 0.35);
  color: inherit;
}

/* ---------- Подсказки под полем ---------- */
.uch-search-ready { position: relative; }
.uch-search-raised { position: relative; z-index: 70; }
.uch-search__back { display: none; }
.uch-sugg {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 60;
  max-height: min(70vh, 600px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 16px 48px rgba(12, 12, 12, 0.18);
  text-align: left;
  font-family: var(--uchs-body);
}
.uch-sugg[hidden] { display: none; }
.uch-sugg[aria-busy="true"] { opacity: 0.7; }
.uch-sugg__item,
.uch-sugg__all {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
  border-radius: 16px;
  color: var(--uchs-black);
  text-decoration: none;
}
.uch-sugg__item:hover,
.uch-sugg__item.is-active,
.uch-sugg__all:hover,
.uch-sugg__all.is-active { background: var(--uchs-bg); color: var(--uchs-black); }
.uch-sugg__path {
  font-size: 13px;
  line-height: 18px;
  font-weight: 700;
  color: var(--uchs-c, var(--uchs-gray));
}
.uch-sugg__title { font-size: 17px; line-height: 24px; font-weight: 700; }
.uch-sugg__snippet {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 14px;
  line-height: 20px;
  color: var(--uchs-text);
}
.uch-sugg__all {
  margin-top: 4px;
  border-top: 1px solid var(--uchs-line);
  border-radius: 0 0 16px 16px;
  font-weight: 700;
  font-size: 16px;
  line-height: 24px;
  color: var(--uchs-green);
}
.uch-sugg__msg { padding: 16px; font-size: 16px; line-height: 24px; color: var(--uchs-text); }
.uch-sugg__note { padding: 8px 16px 4px; font-size: 13px; line-height: 18px; color: var(--uchs-gray); }

/* ---------- Выдача /uchebnik/?q=… ---------- */
.uch-sr { display: flex; flex-direction: column; gap: 24px; max-width: 880px; font-family: var(--uchs-body); scroll-margin-top: 24px; }
.uch-sr__head { display: flex; flex-direction: column; gap: 8px; }
.uch-sr__title { overflow-wrap: anywhere; }
.uch-sr__count { margin: 0; font-size: 18px; line-height: 28px; color: var(--uchs-black); }
.uch-sr__fixed { margin: 0; font-size: 14px; line-height: 20px; color: var(--uchs-gray); overflow-wrap: anywhere; }
.uch-sr__hint { max-width: 720px; }
.uch-sr__filters { display: flex; flex-wrap: wrap; gap: 8px; }
.uch-sr__filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--uchs-line);
  border-radius: 48px;
  background: #fff;
  font-weight: 700;
  font-size: 16px;
  line-height: 24px;
  color: var(--uchs-black);
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.uch-sr__filter:hover { border-color: var(--uchs-black); color: var(--uchs-black); }
.uch-sr__filter[aria-current="true"] { border-color: var(--uchs-black); background: var(--uchs-black); color: #fff; }
.uch-sr__filter-n { font-weight: 400; color: var(--uchs-gray); }
.uch-sr__filter[aria-current="true"] .uch-sr__filter-n { color: rgba(255, 255, 255, 0.7); }
.uch-sr__list { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.uch-sr__item { margin: 0; padding: 0; }
.uch-sr__item[hidden] { display: none; }
.uch-sr__link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 24px;
  border: 1px solid var(--uchs-line);
  border-radius: 24px;
  background: #fff;
  color: var(--uchs-black);
  text-decoration: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.uch-sr__link:hover,
.uch-sr__link:focus-visible { border-color: var(--uchs-c); box-shadow: 0 8px 24px rgba(12, 12, 12, 0.08); color: var(--uchs-black); }
.uch-sr__path { font-size: 14px; line-height: 20px; font-weight: 700; color: var(--uchs-c); }
.uch-sr__name {
  font-family: var(--uchs-head);
  font-size: 20px;
  line-height: 28px;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-position: from-font;
  transition: text-decoration-color 0.2s ease;
}
.uch-sr__link:hover .uch-sr__name { text-decoration-color: currentColor; }
.uch-sr__snippet { font-size: 16px; line-height: 24px; color: var(--uchs-text); overflow-wrap: anywhere; }

/* ---------- Телефон: поиск на весь экран ---------- */
@media (max-width: 767px) {
  html.uch-search-lock,
  html.uch-search-lock body { overflow: hidden; }
  /* оверлей живёт внутри секции: она и задаёт его слой (выше виджета чата Битрикс24 - 10150) */
  html.uch-search-lock .uch-search-raised { z-index: 100000; }

  .uch-search-ready.uch-search--open {
    position: fixed !important;
    inset: 0 !important;
    z-index: 100000 !important;
    display: flex;
    flex-direction: column;
    width: auto !important;
    max-width: none !important;
    height: 100%;
    margin: 0 !important;
    padding: 12px 16px 0;
    background: #fff;
  }
  .uch-search--open .bricks-search-form {
    display: flex;
    flex: none;
    align-items: center;
    border: 1px solid var(--uchs-line);
    background: #fff;
  }
  .uch-search--open .bricks-search-form:focus-within { border-color: var(--uchs-black); }
  .uch-search--open .bricks-search-form input[type="search"] { flex: 1; min-width: 0; outline: none; }
  .uch-search--open .uch-search__back {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-left: 4px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--uchs-black);
    cursor: pointer;
  }
  .uch-search--open .uch-sugg {
    position: static;
    flex: 1;
    max-height: none;
    margin: 8px -16px 0;
    padding: 0 8px calc(16px + env(safe-area-inset-bottom));
    border-radius: 0;
    box-shadow: none;
  }
  .uch-search--open .uch-sugg[hidden] { display: block; }

  .uch-sr { gap: 16px; }
  .uch-sr .uch-sr__title { font-size: 26px; line-height: 32px; } /* .uch-h2 из стилей главной грузится позже */
  .uch-sr__count { font-size: 16px; line-height: 24px; }
  .uch-sr__filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
  .uch-sr__filters::-webkit-scrollbar { display: none; }
  .uch-sr__link { padding: 16px; border-radius: 20px; }
  .uch-sr__name { font-size: 18px; line-height: 26px; }
  .uch-sr__snippet { font-size: 15px; line-height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .uch-sr__filter, .uch-sr__link, .uch-sr__name { transition: none; }
}
