@if (open) {
  <div class="gs-overlay" (click)="close()">
    <div class="gs-modal" (click)="$event.stopPropagation()">
      <div class="gs-input-row">
        <lucide-icon [img]="Search" [size]="18" class="gs-search-icon"></lucide-icon>
        <input
          #searchInput
          type="text"
          class="gs-input"
          [placeholder]="'globalSearch.placeholder' | translate"
          [ngModel]="query"
          (ngModelChange)="onQueryChange($event)" />
        <span class="gs-kbd">ESC</span>
      </div>
      @if (results.length > 0) {
        <div class="gs-results">
          @for (r of results; track r; let i = $index) {
            <button
              class="gs-result"
              [class.active]="i === activeIndex"
              (mouseenter)="activeIndex = i"
              (click)="select(r)">
              <lucide-icon [img]="iconFor(r.kind)" [size]="16" class="gs-result-icon"></lucide-icon>
              <div class="gs-result-body">
                <div class="gs-result-title">{{ r.title }}</div>
                @if (r.subtitle) {
                  <div class="gs-result-subtitle">{{ r.subtitle }}</div>
                }
                <div class="gs-result-tag">{{ r.tag }}</div>
              </div>
            </button>
          }
        </div>
      }
      @if (!loading && query.trim().length >= 2 && results.length === 0) {
        <div class="gs-empty">
          {{ 'globalSearch.noResults' | translate }}
        </div>
      }
      @if (query.trim().length < 2) {
        <div class="gs-empty">
          {{ 'globalSearch.minChars' | translate }}
        </div>
      }
      <div class="gs-footer">
        <div class="gs-hints">
          <span><kbd>↑</kbd><kbd>↓</kbd> {{ 'globalSearch.hintNavigate' | translate }}</span>
          <span><kbd>↵</kbd> {{ 'globalSearch.hintSelect' | translate }}</span>
          <span><kbd>ESC</kbd> {{ 'globalSearch.hintClose' | translate }}</span>
        </div>
        @if (results.length > 0) {
          <span class="gs-count">
            {{ (results.length > 1 ? 'globalSearch.countPlural' : 'globalSearch.countSingular') | translate:{ count: results.length } }}
          </span>
        }
      </div>
    </div>
  </div>
}
