/*
 * The header search (views/partials/navbar.ejs, public/js/globalSearch.js): the box in the bar,
 * and the results panel the script appends to <body>. On <body> rather than in the bar because
 * .navbar-header has a backdrop-filter (adminModern.css), which would make a fixed panel inside
 * it fixed to the bar instead of the window.
 *
 * Every colour is a theme token (style.css), so dark mode follows on its own. The theme resets
 * every element (`all: unset`), so kbd, mark and button are styled from nothing here.
 * Classes are prefixed .hk-gs-.
 */

/* --- The box in the bar -------------------------------------------------- */

.navbar-search.hk-gs input {
  padding-inline-end: 4.5rem;
}

.navbar-search.hk-gs input::placeholder {
  color: var(--text-secondary-light);
  opacity: 0.85;
}

.hk-gs-kbd {
  position: absolute;
  top: 50%;
  inset-inline-end: 0.625rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.125rem 0.4375rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  background: var(--white);
  color: var(--text-secondary-light);
  font-family: var(--hk-display, inherit);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  pointer-events: none;
  white-space: nowrap;
}

.navbar-search.hk-gs input:focus ~ .hk-gs-kbd {
  opacity: 0;
}

/* The search button that stands in for the box below 992px, where the theme hides the box. */
.hk-gs-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--neutral-200);
  color: var(--text-primary-light);
  font-size: 1.25rem;
  cursor: pointer;
}

.hk-gs-open:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media (min-width: 992px) {
  .hk-gs-open {
    display: none;
  }
}

/* --- The panel ----------------------------------------------------------- */

/*
 * The highlighted row. Not --primary-50: adminModern.css sets that light blue on :root after the
 * theme's dark value, so in dark mode it stayed light under white text.
 */
.hk-gs-panel {
  --hk-gs-active: #eef2fb;
}

[data-theme="dark"] .hk-gs-panel {
  --hk-gs-active: rgba(80, 118, 205, 0.24);
}


.hk-gs-panel {
  position: fixed;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  max-height: min(70vh, 640px);
  background: var(--white);
  color: var(--text-primary-light);
  border: 1px solid var(--border-color);
  border-radius: 0.875rem;
  box-shadow: 0 12px 40px rgba(16, 36, 96, 0.16), 0 2px 6px rgba(16, 36, 96, 0.06);
  overflow: hidden;
  font-size: 0.875rem;
}

.hk-gs-panel[hidden],
.hk-gs-backdrop[hidden] {
  display: none !important;
}

.hk-gs-progress {
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.15s;
}

.hk-gs-progress::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  background: var(--brand);
  animation: hk-gs-slide 1s ease-in-out infinite;
}

.hk-gs-panel.is-loading .hk-gs-progress {
  opacity: 1;
}

@keyframes hk-gs-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

.hk-gs-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.375rem;
}

/* Results kept on screen while the next answer is on its way read as provisional. */
.hk-gs-panel.is-loading .hk-gs-body.is-stale {
  opacity: 0.6;
}

/* --- Groups and rows ----------------------------------------------------- */

.hk-gs-group + .hk-gs-group {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border-color);
}

.hk-gs-group-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem 0.25rem;
  color: var(--text-secondary-light);
  font-family: var(--hk-display, inherit);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hk-gs-group-head iconify-icon {
  font-size: 0.9375rem;
}

.hk-gs-group-head .hk-gs-viewall {
  margin-inline-start: auto;
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.hk-gs-group-head .hk-gs-viewall:hover {
  text-decoration: underline;
}

.hk-gs-group-note {
  padding: 0.25rem 0.625rem 0.5rem;
  color: var(--text-secondary-light);
  font-size: 0.8125rem;
}

.hk-gs-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  scroll-margin: 0.375rem;
}

.hk-gs-item:hover {
  background: var(--neutral-50);
}

.hk-gs-item.is-active {
  background: var(--hk-gs-active);
  box-shadow: inset 2px 0 0 var(--brand);
}

.hk-gs-item-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  background: var(--neutral-100);
  color: var(--text-secondary-light);
  font-size: 1rem;
}

.hk-gs-item.is-active .hk-gs-item-icon {
  background: var(--brand);
  color: #fff;
}

.hk-gs-item-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
}

.hk-gs-item-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
  font-weight: 600;
  color: var(--text-primary-light);
}

.hk-gs-item-title > .hk-gs-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hk-gs-item-meta {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary-light);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 500;
}

.hk-gs-item-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary-light);
  font-size: 0.8125rem;
}

.hk-gs-item-side {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.hk-gs-item-date {
  color: var(--text-secondary-light);
  font-size: 0.75rem;
  white-space: nowrap;
}

.hk-gs-badge {
  display: inline-block;
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  background: var(--neutral-100);
  color: var(--text-secondary-light);
}

.hk-gs-badge.tone-success { background: var(--success-focus); color: var(--success-main); }
.hk-gs-badge.tone-warning { background: var(--warning-focus); color: #b26a00; }
.hk-gs-badge.tone-danger { background: var(--danger-focus); color: var(--danger-main); }
.hk-gs-badge.tone-info { background: var(--info-focus); color: var(--info-main); }

[data-theme="dark"] .hk-gs-badge.tone-warning { color: var(--warning-main); }
[data-theme="dark"] .hk-gs-badge.tone-info { color: #7aa2ff; }

.hk-gs-mark {
  background: rgba(255, 192, 45, 0.32);
  color: inherit;
  border-radius: 0.1875rem;
  padding: 0 0.0625rem;
}

[data-theme="dark"] .hk-gs-mark {
  background: rgba(255, 192, 45, 0.28);
}

.hk-gs-more {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  width: 100%;
  margin-top: 0.125rem;
  padding: 0.4375rem 0.625rem 0.4375rem 3.375rem;
  border-radius: 0.5rem;
  color: var(--brand);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.hk-gs-more:hover,
.hk-gs-more.is-active {
  background: var(--hk-gs-active);
}

.hk-gs-more[aria-busy="true"] {
  opacity: 0.6;
  cursor: progress;
}

/* --- Empty, hint and error states ---------------------------------------- */

.hk-gs-state {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-secondary-light);
}

.hk-gs-state iconify-icon {
  display: block;
  margin: 0 auto 0.5rem;
  font-size: 1.75rem;
  color: var(--neutral-400);
}

.hk-gs-state strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--text-primary-light);
  font-weight: 600;
}

.hk-gs-hint {
  padding: 0.75rem 0.625rem 0.5rem;
  color: var(--text-secondary-light);
  font-size: 0.8125rem;
}

.hk-gs-recent {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0 0.625rem 0.625rem;
}

.hk-gs-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-primary-light);
  font-size: 0.8125rem;
  cursor: pointer;
}

.hk-gs-chip:hover,
.hk-gs-chip.is-active {
  border-color: var(--brand);
  background: var(--hk-gs-active);
}

.hk-gs-skeleton {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem;
}

.hk-gs-skeleton span {
  display: block;
  border-radius: 0.375rem;
  background: linear-gradient(90deg, var(--neutral-100) 25%, var(--neutral-50) 50%, var(--neutral-100) 75%);
  background-size: 200% 100%;
  animation: hk-gs-shimmer 1.2s linear infinite;
}

.hk-gs-skeleton .sk-icon { width: 2rem; height: 2rem; flex: 0 0 auto; border-radius: 0.5rem; }
.hk-gs-skeleton .sk-lines { flex: 1; display: flex; flex-direction: column; gap: 0.375rem; background: none; animation: none; }
.hk-gs-skeleton .sk-line { height: 0.625rem; }
.hk-gs-skeleton .sk-line.short { width: 55%; }

@keyframes hk-gs-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* --- Footer -------------------------------------------------------------- */

.hk-gs-foot {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.5rem 0.875rem;
  border-top: 1px solid var(--border-color);
  background: var(--neutral-50);
  color: var(--text-secondary-light);
  font-size: 0.75rem;
}

.hk-gs-foot kbd {
  display: inline-block;
  min-width: 1.25rem;
  margin-inline-end: 0.25rem;
  padding: 0 0.3125rem;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  /* Both set: Bootstrap draws a <kbd> as white text on a dark key. */
  background: var(--white);
  color: var(--text-primary-light);
  font-family: var(--hk-display, inherit);
  font-size: 0.6875rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
}

.hk-gs-foot .hk-gs-count {
  margin-inline-start: auto;
}

/* --- Phones and tablets: a sheet over the page, with its own box ---------- */

.hk-gs-sheetbar {
  display: none;
}

.hk-gs-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1079;
  background: rgba(16, 24, 40, 0.45);
}

.hk-gs-panel.is-sheet {
  inset: 0;
  width: auto !important;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.hk-gs-panel.is-sheet .hk-gs-sheetbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.hk-gs-sheetbar-field {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
}

.hk-gs-sheetbar-field iconify-icon {
  position: absolute;
  inset-inline-start: 0.75rem;
  font-size: 1.125rem;
  color: var(--text-secondary-light);
  pointer-events: none;
}

.hk-gs-sheet-input {
  width: 100%;
  height: 2.75rem;
  padding: 0 0.75rem 0 2.5rem;
  border: 1px solid var(--input-form-light);
  border-radius: 0.625rem;
  background: var(--neutral-50);
  color: var(--text-primary-light);
  /* 16px: anything smaller and iOS zooms the page when the box is focused. */
  font-size: 1rem;
}

.hk-gs-sheet-input:focus {
  border-color: var(--brand);
  outline: none;
}

.hk-gs-close {
  flex: 0 0 auto;
  padding: 0.5rem 0.25rem;
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
}

.hk-gs-panel.is-sheet .hk-gs-foot {
  display: none;
}

@media (max-width: 575.98px) {
  .hk-gs-item-side .hk-gs-item-date {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hk-gs-progress::after,
  .hk-gs-skeleton span {
    animation: none;
  }
}
