/* Sarlavhadagi lupa ochadigan qidiruv modali.
   ------------------------------------------------------------------------
   Markup: templates/includes/search_modal.html + news/_search_results.html,
   xatti-harakat: assets/js/search-modal.js.

   Asosiy qoida: modaldagi kartochka BARCHA bo'limlar uchun bir xil — bosh
   sahifadagi turli o'lchamdagi Figma kadrlari bu yerda takrorlanmaydi.
   Bo'limni faqat rang ajratib turadi: guruh `--sm-accent` o'zgaruvchisini
   turning HEX rangi bilan o'rnatadi, ichkaridagi nuqta, chiziq va havola
   o'shani meros qilib oladi.

   Holatlar `.search-modal` dagi atributlarda:
     [data-idle]     — hali yozilmagan: `.sm-idle` ko'rinadi, ro'yxat yo'q;
     [data-loading]  — so'rov ketyapti: spinner aylanadi, ro'yxat susayadi.

   Modal `.page` dan tashqarida (base.html), shuning uchun sahifaga xos
   `position`/`zoom` resetlari unga tegmaydi. */

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0s linear 0.18s;
  font-family: 'Helvetica Neue', 'HelveticaNeue', Helvetica, Arial, sans-serif;
  color: #132745;

  --sm-line: #eaeef3;
  --sm-muted: #6b7785;
  --sm-faint: #9aa5b1;
  --sm-brand: #ff800a;
}
.search-modal[data-open] {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}
.search-modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(12, 24, 42, 0.5);
  backdrop-filter: blur(6px);
}

.search-modal-panel {
  position: absolute;
  /* Markazlashtirish `margin: 0 auto` bilan — `left: 50%` + `translate(-50%)`
     emas: `transform` faqat ochilish animatsiyasi uchun qoladi, ya'ni u
     qo'llanmasa ham panel joyida turadi. */
  left: 0;
  right: 0;
  top: 84px;
  margin: 0 auto;
  transform: translateY(-10px) scale(0.985);
  width: min(1240px, calc(100vw - 40px));
  max-height: calc(100vh - 140px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  border: 1px solid rgba(19, 39, 69, 0.06);
  border-radius: 18px;
  box-shadow:
    0 1px 2px rgba(19, 39, 69, 0.06),
    0 12px 28px rgba(19, 39, 69, 0.14),
    0 42px 80px rgba(19, 39, 69, 0.22);
  overflow: hidden;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
.search-modal[data-open] .search-modal-panel { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .search-modal, .search-modal-panel { transition: none; }
}

/* ===================== 1. Qidiruv qatori ===================== */

.sm-form {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
}

/* Kiritish maydoni — yumaloq "pill": lupa ichida, o'ng chekkasida spinner va
   tozalash tugmasi. Fokusda rangli halqa CHIQMAYDI: maydon oqarib, ramkasi
   bir oz to'qlashadi — shu holat belgisi sifatida yetarli. */
.sm-field {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 12px 0 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background-color: #f3f5f8;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.sm-field:focus-within {
  background-color: #ffffff;
  border-color: #dde3ea;
  box-shadow: 0 1px 2px rgba(19, 39, 69, 0.04);
}
.sm-field-icon { flex: none; display: flex; color: var(--sm-faint); }
.sm-field:focus-within .sm-field-icon { color: var(--sm-muted); }

.sm-input {
  flex: 1 1 0%;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 17px;
  color: #132745;
}
.sm-input::placeholder { color: var(--sm-faint); }
/* Brauzerning o'z "x" tugmasi — o'rnida `.sm-clear` turadi. */
.sm-input::-webkit-search-cancel-button { display: none; }

.sm-spinner {
  flex: none;
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 128, 10, 0.25);
  border-top-color: var(--sm-brand);
  border-radius: 50%;
  animation: sm-spin 0.6s linear infinite;
}
.search-modal[data-loading] .sm-spinner { display: block; }
@keyframes sm-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sm-spinner { animation-duration: 2s; } }

.sm-clear {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-color: #e3e8ee;
  color: #55606d;
  cursor: pointer;
}
.sm-clear:hover { background-color: #d5dce4; color: #132745; }

.sm-close {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--sm-muted);
  cursor: pointer;
}
.sm-close:hover { background-color: #f3f5f8; color: #132745; }

/* Klaviatura fokusi havola va tugmalarda ko'rinadi; kiritish maydonida esa
   YO'Q — u yerda halqa o'rniga `.sm-field` ning o'z holati ishlaydi
   (foydalanuvchi so'roviga ko'ra sariq ramka olib tashlangan). */
.search-modal :is(a, button):focus-visible {
  outline: 2px solid var(--sm-brand);
  outline-offset: 2px;
}
.sm-input:focus, .sm-input:focus-visible { outline: none; box-shadow: none; }

/* ===================== 2. Bo'lim tugmachalari ===================== */

/* Barcha ruknlar (menyudagi 7 tasi emas) BITTA qatorda turadi — modal eni
   shunga qarab tanlangan. Ular sig'masa (uzunroq nomlar yoki tor oyna)
   qator ikkiga bo'linmaydi, yon tomonga siljiydi. */
.sm-chips-row {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 14px;
  border-bottom: 1px solid var(--sm-line);
}
.sm-chips-label {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sm-faint);
}
.sm-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.sm-chips::-webkit-scrollbar { display: none; }
/* Tor oynada panel ham torayadi — «RUKNLAR» yozuvi olib tashlanib, o'sha joy
   tugmachalarga beriladi (ular bir qatorda qolishi uchun). */
@media (max-width: 1319.98px) {
  .sm-chips-label { display: none; }
}
.sm-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--sm-line);
  border-radius: 999px;
  font-size: 13px;
  line-height: 1;
  color: #132745;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.sm-chip:hover {
  background-color: #fbfcfe;
  border-color: var(--sm-accent, var(--sm-line));
}
.sm-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--sm-accent, var(--sm-faint));
}

/* ===================== 3. Tana: bo'sh holat / natijalar ===================== */

.sm-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Boshlang'ich (bo'sh) holat — hech narsa yuklanmagan. */
.sm-idle {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 52px 24px 56px;
  text-align: center;
}
.search-modal[data-idle] .sm-idle { display: flex; }
.search-modal[data-idle] :is(.sm-results, .sm-status) { display: none; }
.sm-idle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: 6px;
  border-radius: 50%;
  background-color: #f3f5f8;
  color: var(--sm-faint);
}
.sm-idle-title { margin: 0; font-size: 16px; font-weight: 700; color: #132745; }
.sm-idle-note { margin: 0; max-width: 360px; font-size: 13px; line-height: 1.5; color: var(--sm-muted); }

.sm-status {
  flex: none;
  margin: 0;
  padding: 12px 18px 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sm-faint);
}
.sm-status:empty { display: none; }

.sm-results {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 18px 16px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.sm-results:focus { outline: none; }
.search-modal[data-loading] .sm-results { opacity: 0.45; }

/* ---- Guruh (rukn) ---- */

/* Guruh sarlavhasi ro'yxat bilan siljiydi va tepada yopishib qoladi — uzun
   ro'yxatda ham qaysi bo'lim ko'rilayotgani ko'rinib turadi. Shu sababli
   kartochkaning ichida tur nishoni takrorlanmaydi. */
.sm-group + .sm-group { margin-top: 6px; }
.sm-group-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0 8px;
  background-color: #ffffff;
  border-bottom: 1px solid var(--sm-line);
}
.sm-group-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--sm-accent, var(--sm-faint));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sm-accent, #afafaf) 18%, transparent);
}
.sm-group-name {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #132745;
}
.sm-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background-color: #f3f5f8;
  font-size: 11px;
  font-weight: 700;
  color: var(--sm-muted);
}
.sm-group-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  font-size: 12px;
  color: var(--sm-accent, var(--sm-muted));
  text-decoration: none;
  opacity: 0.9;
}
.sm-group-link:hover { text-decoration: underline; }

.sm-list { display: flex; flex-direction: column; }

/* ---- Kartochka — modaldagi YAGONA ko'rinish ---- */

.sm-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 10px 12px 13px;
  border-bottom: 1px solid #f4f6f8;
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.12s ease;
}
/* Bo'lim rangi har bir qatorda ingichka chiziqcha bilan ko'rinib turadi —
   guruh sarlavhasi ekrandan chiqib ketganda ham material qaysi bo'limdan
   ekani bilinadi. Ramka emas, `::before`: kartochka radiusi buzilmaydi. */
.sm-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 3px;
  background-color: var(--sm-accent, #afafaf);
  opacity: 0.55;
  transition: opacity 0.12s ease;
}
.sm-card:hover { background-color: #f7f9fb; }
.sm-card:hover::before { opacity: 1; }

.sm-card-cover {
  flex: none;
  width: 112px;
  height: 76px;
  overflow: hidden;
  border-radius: 10px;
  background-color: #eef1f4;
}
.sm-card-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }

.sm-card-body {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sm-card-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  color: #132745;
  /* Ikki qatordan uzun sarlavha kartochka balandligini buzmasin. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sm-card:hover .sm-card-title,
.sm-card-lead {
  font-size: 13px;
  line-height: 1.5;
  color: var(--sm-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sm-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--sm-faint);
}
.sm-card-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background-color: currentColor;
}
.sm-card-views { display: inline-flex; align-items: center; gap: 4px; }
.sm-card-views img { display: block; width: 14px; height: 14px; opacity: 0.55; }

/* O'ngdagi strelka faqat ustiga kelganda / klaviatura tanlovida ko'rinadi. */
.sm-card-go {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: #ffffff;
  color: var(--sm-brand);
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.sm-card:hover .sm-card-go,

/* Topilgan so'z — matn ichida ajratilgan (news_extras.highlight). */
.search-modal mark {
  padding: 0 2px;
  border-radius: 3px;
  background-color: rgba(255, 128, 10, 0.18);
  color: inherit;
}

/* ---- Natija yo'q ---- */

.sm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 46px 24px 50px;
  text-align: center;
}
.sm-empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: 6px;
  border-radius: 50%;
  background-color: #f3f5f8;
  color: var(--sm-faint);
}
.sm-empty-title { margin: 0; font-size: 16px; font-weight: 700; color: #132745; }
.sm-empty-note { margin: 0; max-width: 360px; font-size: 13px; line-height: 1.5; color: var(--sm-muted); }

/* ---- «Ko'proq ko'rish» ---- */

/* JS tugmani `.sm-results` ning OXIRIGA ko'chiradi, ya'ni u ro'yxat bilan
   birga siljiydi: keyingi 10 ta natija shu yerda qo'shiladi. */
.sm-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin: 14px 0 4px;
  padding: 12px;
  border: 1px solid var(--sm-line);
  border-radius: 12px;
  background-color: #ffffff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #132745;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.sm-more:hover { background-color: #f7f9fb; border-color: #d9e0e8; }
.sm-more[disabled] { opacity: 0.6; cursor: default; }
.sm-more[hidden] { display: none; }
.sm-more-rest { font-weight: 400; color: var(--sm-faint); }
.sm-more-rest:empty { display: none; }

/* ===================== 4. Pastki qator ===================== */

.sm-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--sm-line);
  background-color: #fbfcfe;
}
.sm-hints { display: flex; align-items: center; gap: 14px; }
.sm-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--sm-faint);
}
.sm-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--sm-line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background-color: #ffffff;
  font-family: inherit;
  font-size: 11px;
  color: var(--sm-muted);
}


/* ===================== 5. Tor ekran ===================== */

@media (max-width: 767.98px) {
  .search-modal-panel {
    left: 0;
    top: 0;
    transform: none;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
  }
  .search-modal[data-open] .search-modal-panel { transform: none; }
  .sm-form { flex-wrap: wrap; padding: 12px 12px 10px; }
  .sm-field { order: 1; flex: 1 1 auto; height: 46px; }
  .sm-close { order: 2; }
  .sm-input { font-size: 16px; }  /* 16px dan kichigi iOS da sahifani kattalashtiradi */
  .sm-chips-row { padding: 0 12px 12px; }
  .sm-chips-label { display: none; }
  .sm-results { padding: 4px 12px 14px; }
  .sm-card { gap: 10px; padding: 10px 6px 10px 12px; }
  .sm-card-cover { width: 92px; height: 64px; }
  .sm-card-title { font-size: 15px; }
  .sm-card-lead { font-size: 12px; }
  .sm-card-go { display: none; }
  /* Klaviatura ko'rsatmalari sensorli ekranda keraksiz — butun qator olib
     tashlanadi (undan boshqa hech narsa yo'q). */
  .sm-foot { display: none; }
}
