/* ============================================================================
   Quick Search — command palette (Ctrl+K)
   Markup: app/common_templates/base.html (#quickSearch)
   Script: app/static/js/quick_search.js
   Shares the workbench language: brand blue, soft tags, quiet surfaces.
   ============================================================================ */

body {
  --qs-accent: var(--gsk-blue, #0077A8);
  --qs-accent-soft: var(--gsk-blue-soft, #E6F5FB);
  --qs-accent-line: var(--gsk-blue-line, #BFE3F2);
  --qs-ink: #0f172a;
  --qs-mute: #64748b;
  --qs-faint: #718096;
  --qs-line: #e5e9f0;
  --qs-surface: #ffffff;
  --qs-ground: #f8fafc;
  --qs-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- backdrop -------------------------------------------------------- */
.qs-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1060;
  background: rgba(15, 23, 42, 0.42);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.qs-backdrop.is-on { opacity: 1; pointer-events: auto; }

body.quick-search-open { overflow: hidden; }

/* ---- dialog ---------------------------------------------------------- */
.qs-dialog {
  position: fixed;
  left: 50%;
  top: 11vh;
  z-index: 1061;
  width: min(720px, calc(100vw - 32px));
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  background: var(--qs-surface);
  color: var(--qs-ink);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.24), 0 0 0 1px rgba(15, 23, 42, 0.06);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -10px) scale(0.985);
  transition: opacity 0.2s ease, transform 0.26s var(--qs-ease), visibility 0s linear 0.26s;
}
.qs-dialog.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, 0) scale(1);
  transition: opacity 0.2s ease, transform 0.26s var(--qs-ease), visibility 0s;
}

.qs-progress {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--qs-accent), transparent);
  background-size: 40% 100%;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.qs-dialog.is-loading .qs-progress { opacity: 1; animation: qsProgress 1s linear infinite; }
@keyframes qsProgress { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* ---- search field ---------------------------------------------------- */
.qs-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--qs-line);
}
.qs-top:focus-within { box-shadow: inset 0 -2px var(--qs-accent); }
.qs-top-icon { color: var(--qs-accent); font-size: 18px; flex: 0 0 auto; }
.qs-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
  color: var(--qs-ink);
}
.qs-input::placeholder { color: var(--qs-faint); }
.qs-clear,
.qs-esc {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--qs-faint);
  min-width: 32px;
  min-height: 32px;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.qs-clear:hover, .qs-esc:hover { color: var(--qs-ink); background: var(--qs-ground); }
.qs-clear[hidden] { display: none; }

.qs-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid #d5dde8;
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  box-shadow: inset 0 -1px 0 #e2e8f0;
  font-family: inherit;
}

/* ---- type tabs ------------------------------------------------------- */
.qs-tabs {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 5px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--qs-line);
  overflow-x: auto;
  scrollbar-width: none;
}
.qs-tabs::-webkit-scrollbar { display: none; }
.qs-tabs:empty { display: none; }
.qs-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: #475569;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.qs-tab .n { color: var(--qs-faint); font-size: 11px; font-weight: 400; }
.qs-tab:hover { background: var(--qs-ground); color: var(--qs-ink); }
.qs-tab.is-on { background: var(--qs-accent-soft); color: var(--qs-accent); border-color: var(--qs-accent-line); }
.qs-tab.is-on .n { color: var(--qs-accent); }
.qs-tab.is-empty .n { color: var(--qs-faint); }

/* ---- results --------------------------------------------------------- */
.qs-body {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  padding: 6px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  transition: opacity 0.15s ease;
}
.qs-dialog.is-loading .qs-body { opacity: 0.55; }
.qs-body:focus { outline: none; }

.qs-sec {
  padding: 12px 12px 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--qs-faint);
  display: flex;
  align-items: center;
  gap: 8px;
}
.qs-sec .qs-sec-line { flex: 1; }

.qs-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 66px;
  padding: 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.qs-row:hover { background: var(--qs-ground); }
.qs-row.is-active { background: var(--qs-accent-soft); border-color: var(--qs-accent-line); }
.qs-row.is-active .qs-enter { opacity: 1; }
.qs-row.qs-row-in { animation: qsRowIn 0.22s var(--qs-ease) both; }
@keyframes qsRowIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.qs-tile {
  flex: 0 0 auto;
  width: 35px;
  height: 35px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  overflow: hidden;
}
.qs-tile.co { background: var(--gsk-blue-soft, #E6F5FB); color: var(--qs-accent); }
.qs-tile.pe { background: #efe9fb; color: #6d4fc4; }
.qs-tile.jo { background: #fff2dc; color: #b7791f; }
.qs-tile.em { background: var(--gsk-green-soft, #E3F3EE); color: var(--gsk-green, #006D4E); font-weight: 700; font-size: 12px; }
.qs-tile img { width: 100%; height: 100%; object-fit: cover; }

.qs-main { flex: 1; min-width: 0; display: block; }
.qs-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--qs-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qs-title mark, .qs-sub mark { background: var(--qs-accent-soft); color: inherit; padding: 0; border-radius: 2px; }
.qs-row.is-active mark { background: var(--qs-accent-line); }

.qs-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; margin-top: 2px; }
.qs-sub {
  display: block;
  min-width: 0;
  font-size: 12px;
  color: var(--qs-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qs-meta .qs-ref { flex: 0 0 auto; }

.qs-side { flex: 0 0 auto; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px; max-width: 35%; }
.qs-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.qs-tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.qs-tag.tone-green { background: var(--gsk-green-soft, #E3F3EE); color: var(--gsk-green, #006D4E); }
.qs-tag.tone-blue { background: var(--gsk-blue-soft, #E6F5FB); color: var(--qs-accent); }
.qs-tag.tone-amber { background: #fff2dc; color: #b7791f; }
.qs-tag.tone-red { background: #fde8e8; color: #c53030; }
.qs-tag.tone-violet { background: #efe9fb; color: #6d4fc4; }
.qs-tag.tone-grey { background: #eef2f6; color: #64748b; }
.qs-ref { font-family: ui-monospace, Consolas, "SFMono-Regular", monospace; font-size: 11px; color: var(--qs-mute); white-space: nowrap; }
.qs-enter { opacity: 0; transition: opacity 0.12s ease; }

.qs-see {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--qs-accent);
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.qs-see:hover, .qs-see.is-active { background: var(--qs-ground); color: var(--qs-accent); }

/* recent searches chips (idle state) */
.qs-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 10px 8px; }
.qs-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--qs-line);
  background: #fff;
  color: #334155;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.qs-chip i { color: var(--qs-faint); font-size: 12px; }
.qs-chip:hover, .qs-chip.is-active { border-color: #b9cee4; background: var(--qs-accent-soft); color: var(--qs-accent); }
.qs-sec-action {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--qs-faint);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}
.qs-sec-action:hover { color: var(--qs-accent); }

/* empty / error / skeleton */
.qs-empty {
  padding: 38px 20px 42px;
  text-align: center;
  color: var(--qs-mute);
  animation: qsRowIn 0.25s var(--qs-ease) both;
}
.qs-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--qs-ground);
  color: var(--qs-faint);
  font-size: 20px;
  margin-bottom: 10px;
}
.qs-empty-title { font-size: 15px; font-weight: 500; color: var(--qs-ink); margin-bottom: 5px; overflow-wrap: anywhere; }
.qs-empty-text { font-size: 12.5px; line-height: 1.5; overflow-wrap: anywhere; }
.qs-empty-text .qs-kbd { vertical-align: -3px; }
.qs-retry { margin-top: 16px; padding: 7px 13px; border: 1px solid var(--qs-accent-line); border-radius: 7px; background: var(--qs-accent-soft); color: var(--qs-accent); font: inherit; font-size: 13px; cursor: pointer; }
.qs-retry:hover { border-color: var(--qs-accent); }

.qs-skel { display: flex; align-items: center; gap: 12px; padding: 10px; }
.qs-skel .qs-tile { background: #eef2f6; }
.qs-skel-line { height: 10px; border-radius: 5px; background: linear-gradient(90deg, #eef2f6 25%, #f8fafc 37%, #eef2f6 63%); background-size: 400% 100%; animation: qsShimmer 1.2s ease-in-out infinite; }
.qs-skel-line + .qs-skel-line { margin-top: 7px; }
@keyframes qsShimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---- footer ---------------------------------------------------------- */
.qs-foot {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px 17px;
  border-top: 1px solid var(--qs-line);
  background: var(--qs-surface);
  font-size: 11.5px;
  color: var(--qs-mute);
}
.qs-foot > span { display: inline-flex; align-items: center; gap: 4px; }
.qs-foot-right { margin-left: auto; color: var(--qs-faint); }

.qs-dialog :is(button, a):focus-visible { outline: 2px solid var(--qs-accent); outline-offset: -2px; }

/* ---- top-bar trigger (next to the brand) ----------------------------- */
.navbar-custom .qs-trigger {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  flex: 0 1 300px;
  min-width: 210px;
  margin-left: 22px;
  padding: 0 10px 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.94);
  color: #365766;
  box-shadow: 0 1px 3px rgba(0, 72, 62, 0.1);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.navbar-custom .qs-trigger:hover,
.navbar-custom .qs-trigger.active {
  background: #fff;
  border-color: #fff;
  color: #244957;
}
.navbar-custom .qs-trigger:focus-visible { outline: 2px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 3px rgba(0, 72, 62, 0.3); }
.navbar-custom .qs-trigger .bi-search { font-size: 14px; line-height: 1; }
.qs-trigger-text { flex: 1; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qs-trigger-keys { display: inline-flex; gap: 3px; }
.qs-trigger .qs-kbd { background: #f1f6f7; border-color: #d3e1e6; color: #4e6875; box-shadow: none; white-space: nowrap; }

@media (max-width: 1199.98px) {
  .navbar-custom .qs-trigger { flex-basis: 190px; min-width: 170px; margin-left: 16px; }
  .qs-trigger-keys { display: none; }
}
@media (max-width: 991.98px) {
  /* Below the navbar breakpoint the pill becomes an icon beside the toggler. */
  .navbar-custom .qs-trigger { flex: 0 0 40px; min-width: 40px; margin-left: auto; margin-right: 10px; width: 40px; padding: 0; justify-content: center; }
  .qs-trigger-text { display: none; }
}

/* ---- small screens --------------------------------------------------- */
@media (max-width: 767.98px) {
  .qs-dialog {
    left: 0;
    top: 0;
    width: 100vw;
    max-height: none;
    height: 100dvh;
    border-radius: 0;
    transform: translate(0, -10px);
  }
  .qs-dialog.is-open { transform: none; }
  .qs-top { padding: 12px; gap: 9px; }
  .qs-tabs { padding: 10px; }
  .qs-row { gap: 9px; }
  .qs-side { max-width: 32%; }
  .qs-foot > span:not(.qs-foot-right) { display: none; }
  .qs-foot-right { margin-left: 0; }
}

@media (max-width: 479.98px) {
  .qs-row { align-items: flex-start; }
  .qs-title, .qs-sub { white-space: normal; overflow-wrap: anywhere; }
  .qs-side { gap: 4px; }
  .qs-tag { max-width: 100%; height: auto; min-height: 20px; white-space: normal; overflow-wrap: anywhere; padding: 2px 6px; }
  .qs-tag::before { flex-shrink: 0; }
  .qs-enter { display: none; }
}

@media (pointer: coarse) {
  .qs-clear, .qs-esc { min-width: 44px; min-height: 44px; }
  .qs-tab, .qs-chip, .qs-retry, .qs-see { min-height: 44px; }
  .navbar-custom .qs-trigger { min-width: 44px; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .qs-backdrop, .qs-dialog, .qs-row, .qs-empty, .qs-body { transition: none !important; animation: none !important; }
  .qs-row.qs-row-in { opacity: 1; }
  .qs-progress, .qs-skel-line { animation: none !important; }
}
