/* HSG Search — header panel + course results/sort. Scoped to avoid Header/Footer bleed. */

/* ========== Header search panel ========== */
body.hsg-ui .header-search-input-wrap.hsg-header-search-ready {
  position: fixed;
  left: 0;
  right: 0;
  bottom: auto;
  width: 100%;
  height: auto;
  max-width: 100%;
  overflow: visible;
  z-index: 10050;
  display: none;
  box-sizing: border-box;
  animation: none;
  -webkit-animation: none;
  margin: 0;
  padding: 12px 16px 14px;
  background: var(--hsg-surface);
  border-bottom: 1px solid var(--hsg-line);
  box-shadow: 0 10px 28px rgba(25, 43, 75, 0.08);
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready.is-open {
  display: block;
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready .header-search-overlay {
  display: none;
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready > .container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0;
  width: 100%;
}

body.hsg-ui .hsg-header-search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}

body.hsg-ui .hsg-header-search-field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  min-height: var(--hsg-btn-min-h);
  padding: 0 12px 0 14px;
  border: 1px solid var(--hsg-line-strong);
  border-radius: var(--hsg-radius-btn);
  background: var(--hsg-surface);
  box-shadow: 0 1px 2px rgba(25, 43, 75, 0.04);
}

body.hsg-ui .hsg-header-search-field:focus-within {
  border-color: var(--hsg-primary);
  box-shadow: 0 0 0 3px var(--hsg-blue-soft);
}

body.hsg-ui .hsg-header-search-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-right: 10px;
  color: var(--hsg-muted);
  pointer-events: none;
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready .search-wrap,
body.hsg-ui .header-search-input-wrap.hsg-header-search-ready .search.docent-top-search,
body.hsg-ui .header-search-input-wrap.hsg-header-search-ready .sp_search_input.docent-search-wrapper {
  position: static;
  width: 100%;
  margin: 0;
  padding: 0;
  float: none;
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready form.docent-header-search {
  width: 100%;
  margin: 0;
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready .hsg-header-search-field .form-control,
body.hsg-ui .header-search-input-wrap.hsg-header-search-ready #searchword {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  height: auto;
  margin: 0;
  padding: 10px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  -webkit-box-shadow: none;
  font-family: var(--hsg-font);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--hsg-ink);
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready #searchword::placeholder {
  color: var(--hsg-muted);
  font-weight: 400;
  opacity: 1;
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready .docent-course-search-icons {
  display: none;
}

body.hsg-ui .hsg-header-search-clear {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-left: 6px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--hsg-muted);
  cursor: pointer;
}

body.hsg-ui .hsg-header-search-clear[hidden] {
  display: none;
}

body.hsg-ui .hsg-header-search-clear:hover,
body.hsg-ui .hsg-header-search-clear:focus-visible {
  background: var(--hsg-blue-soft);
  color: var(--hsg-primary);
  outline: none;
}

body.hsg-ui .hsg-header-search-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--hsg-btn-min-h);
  padding: 10px 16px;
  border: 1px solid var(--hsg-line-strong);
  border-radius: var(--hsg-radius-btn);
  background: var(--hsg-surface);
  color: var(--hsg-ink);
  font-family: var(--hsg-font);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  cursor: pointer;
  white-space: nowrap;
}

body.hsg-ui .hsg-header-search-close:hover,
body.hsg-ui .hsg-header-search-close:focus-visible {
  background: #f1f5f9;
  border-color: var(--hsg-line-strong);
  color: var(--hsg-ink);
  outline: none;
}

body.hsg-ui .header-search-input-wrap.hsg-header-search-ready button[type="submit"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Hide theme close icon when HSG panel is ready — Đóng handles close. */
body.hsg-ui .header-search-wrap .docent-search.search-close-icon {
  display: none;
}

body.hsg-ui .docent-course-search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 2;
  max-height: min(60vh, 420px);
  overflow: auto;
  background: var(--hsg-surface);
  border: 1px solid var(--hsg-line);
  border-radius: var(--hsg-radius-btn);
  box-shadow: var(--hsg-shadow);
}

body.hsg-ui .docent-course-search-results:empty {
  display: none;
}

/* ========== Results bar + sort dropdown ========== */
/*
 * .subtitle-cover bị Additional CSS thu về 0 → bù khoảng cách dưới header
 * để heading không dính masthead (kể cả lúc chưa sticky).
 */
body.hsg-courses-archive .tutor-wrap.tutor-courses-wrap {
  padding-top: 28px;
  box-sizing: border-box;
}

body.hsg-ui .tutor-course-filter-wrap.hsg-course-search-bar,
body.hsg-courses-archive .tutor-course-filter-wrap.hsg-course-search-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px 24px;
  float: none;
  clear: both;
  width: 100%;
  max-width: 100%;
  margin: 0 0 28px;
  padding: 12px 0 20px;
  border-bottom: 0;
  direction: ltr;
  box-sizing: border-box;
}

body.hsg-ui .hsg-course-search-bar__info {
  flex: 1 1 240px;
  min-width: 0;
  float: none;
  width: auto;
  text-align: left;
  direction: ltr;
  padding: 0;
}

body.hsg-ui .hsg-course-search-bar__title {
  margin: 0 0 6px;
  font-family: var(--hsg-font);
  font-size: clamp(22px, 2.4vw, 28px);
  font-weight: 800;
  line-height: 1.28;
  letter-spacing: -0.02em;
  color: var(--hsg-ink);
  text-transform: none;
}

body.hsg-ui .hsg-course-search-bar__subtitle {
  margin: 0;
  font-family: var(--hsg-font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--hsg-muted);
}

body.hsg-ui .hsg-course-search-bar__sort,
body.hsg-ui .hsg-course-search-bar .tutor-course-archive-filters-wrap {
  flex: 0 0 auto;
  float: none;
  width: auto;
  max-width: 100%;
  text-align: left;
  direction: ltr;
  padding: 0;
}

body.hsg-ui .hsg-sort-form {
  margin: 0;
  position: relative;
}

body.hsg-ui .hsg-sort-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Kill Tutor/theme nice-select if it still appears next to our UI. */
body.hsg-ui .hsg-course-search-bar .nice-select {
  display: none;
}

body.hsg-ui .hsg-sort-dropdown {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

body.hsg-ui .hsg-sort-dropdown__trigger {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--hsg-btn-min-h);
  max-width: 100%;
  padding: 10px 14px;
  margin: 0;
  border: 1px solid #cfd8e6;
  border-radius: 10px;
  background: var(--hsg-surface);
  box-shadow: 0 2px 8px rgba(25, 43, 75, 0.06);
  color: var(--hsg-ink);
  font-family: var(--hsg-font);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

body.hsg-ui .hsg-sort-dropdown__trigger:hover {
  border-color: #b7c4d8;
  background: var(--hsg-surface);
}

body.hsg-ui .hsg-sort-dropdown__trigger:focus-visible {
  outline: none;
  border-color: var(--hsg-primary);
  box-shadow: 0 0 0 3px var(--hsg-blue-soft);
}

body.hsg-ui .hsg-sort-dropdown.is-open .hsg-sort-dropdown__trigger {
  border-color: var(--hsg-primary);
  box-shadow: 0 0 0 3px var(--hsg-blue-soft);
}

body.hsg-ui .hsg-sort-dropdown__icon,
body.hsg-ui .hsg-sort-dropdown__chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--hsg-muted);
}

body.hsg-ui .hsg-sort-dropdown.is-open .hsg-sort-dropdown__chevron {
  transform: rotate(180deg);
}

body.hsg-ui .hsg-sort-dropdown__label {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--hsg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.hsg-ui .hsg-sort-dropdown__value {
  color: var(--hsg-ink);
  font-weight: 700;
}

body.hsg-ui .hsg-sort-dropdown__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: auto;
  z-index: 40;
  min-width: 100%;
  width: max-content;
  max-width: min(320px, calc(100vw - 32px));
  margin: 0;
  padding: 8px;
  list-style: none;
  background: var(--hsg-surface);
  border: 1px solid var(--hsg-line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(25, 43, 75, 0.12);
  box-sizing: border-box;
}

body.hsg-ui .hsg-sort-dropdown__menu[hidden] {
  display: none;
}

body.hsg-ui .hsg-sort-dropdown__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--hsg-ink);
  font-family: var(--hsg-font);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
}

body.hsg-ui .hsg-sort-dropdown__option:hover,
body.hsg-ui .hsg-sort-dropdown__option:focus,
body.hsg-ui .hsg-sort-dropdown__option:focus-visible {
  background: var(--hsg-blue-soft);
  outline: none;
}

body.hsg-ui .hsg-sort-dropdown__option.is-selected {
  color: var(--hsg-primary);
  font-weight: 650;
  background: var(--hsg-blue-soft);
}

body.hsg-ui .hsg-sort-dropdown__check {
  display: none;
  color: var(--hsg-primary);
  flex: 0 0 auto;
}

body.hsg-ui .hsg-sort-dropdown__option.is-selected .hsg-sort-dropdown__check {
  display: inline-flex;
}

/* ========== Responsive ========== */
@media (max-width: 767px) {
  body.hsg-ui .header-search-input-wrap.hsg-header-search-ready {
    padding: 10px 12px 12px;
  }

  body.hsg-ui .hsg-header-search-bar {
    gap: 8px;
  }

  body.hsg-ui .hsg-header-search-close {
    padding: 10px 12px;
    font-size: 13px;
  }

  body.hsg-courses-archive .tutor-wrap.tutor-courses-wrap {
    padding-top: 20px;
  }

  body.hsg-ui .tutor-course-filter-wrap.hsg-course-search-bar,
  body.hsg-courses-archive .tutor-course-filter-wrap.hsg-course-search-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
    padding: 8px 0 12px;
  }

  body.hsg-ui .hsg-course-search-bar__sort,
  body.hsg-ui .hsg-course-search-bar .tutor-course-archive-filters-wrap,
  body.hsg-ui .hsg-sort-form,
  body.hsg-ui .hsg-sort-dropdown,
  body.hsg-ui .hsg-sort-dropdown__trigger {
    display: flex;
    width: 100%;
    max-width: 100%;
  }

  body.hsg-ui .hsg-sort-form {
    flex-direction: column;
  }

  body.hsg-ui .hsg-sort-dropdown__menu {
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 390px) {
  body.hsg-ui .hsg-course-search-bar__title {
    font-size: 20px;
  }

  body.hsg-ui .hsg-course-search-bar__subtitle {
    font-size: 14px;
  }
}
