/* ==========================================================================
   StudyDump - Search Modal Styles
   Command Palette: Clean, Keyboard-First, Academic Index
   ========================================================================== */

.search-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 100%;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: clamp(16px, 10vh, 100px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.search-dialog[open] {
  opacity: 1;
  pointer-events: auto;
}

.search-dialog::backdrop {
  background-color: rgba(24, 24, 22, 0.4);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

[data-theme="dark"] .search-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.75);
}

.search-panel {
  width: min(600px, calc(100% - 32px));
  max-width: calc(100% - 32px);
  max-height: calc(100dvh - 32px);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  background-color: var(--bg-surface);
}

.search-icon {
  width: 17px;
  height: 17px;
  stroke: var(--text-tertiary);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 1rem; /* 16px prevents iOS Safari auto-zoom */
  color: var(--text-primary);
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration,
.search-input::-webkit-search-results-button,
.search-input::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.search-input::placeholder {
  color: var(--text-tertiary);
  font-size: 0.9375rem;
}

.search-clear-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  min-width: 26px;
  padding: 0;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  cursor: pointer;
  touch-action: manipulation;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.search-clear-btn.visible {
  display: inline-flex !important;
}

.search-clear-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-surface);
  border-color: var(--border-hover);
}

.search-clear-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.search-clear-btn svg {
  width: 12px;
  height: 12px;
}

.search-esc-hint {
  font-family: var(--font-mono);
  font-size: var(--text-3xs);
  padding: 2px 6px;
  background-color: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xs);
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
  user-select: none;
}

.search-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: var(--radius-xs);
  color: var(--text-tertiary);
  cursor: pointer;
  touch-action: manipulation;
  transition: all var(--transition-fast);
}

.search-close-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-surface-subtle);
}

.search-close-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.search-close-btn svg {
  width: 16px;
  height: 16px;
}

/* Quick Scope Filter Bar */
.search-filters-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background-color: var(--bg-surface-subtle);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.search-filters-bar::-webkit-scrollbar {
  display: none;
}

.search-filter-pill {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  touch-action: manipulation;
  transition: all var(--transition-fast);
}

.search-filter-pill:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.search-filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.search-results-area {
  max-height: 52vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-2) 0;
}

/* Results Grouping */
.search-group {
  margin-bottom: var(--space-3);
}

.search-group:last-child {
  margin-bottom: 0;
}

.search-group-title {
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-3xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--accent);
}

.search-results-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px 16px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  border-left: 2.5px solid transparent;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.search-result-item:hover {
  background-color: var(--bg-surface);
  border-left-color: var(--border-hover);
}

.search-result-item.selected {
  background-color: rgba(56, 189, 248, 0.1);
  border-left-color: var(--accent);
}

[data-theme="light"] .search-result-item.selected {
  background-color: rgba(2, 132, 199, 0.08);
}

.result-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.result-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-item.selected .result-title {
  color: var(--accent);
}

.result-path {
  font-family: var(--font-mono);
  font-size: var(--text-3xs);
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

.result-snippet {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.result-arrow {
  width: 14px;
  height: 14px;
  stroke: var(--text-tertiary);
  opacity: 0;
  flex-shrink: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.search-result-item.selected .result-arrow {
  opacity: 1;
  stroke: var(--accent);
  transform: translateX(2px);
}

/* Empty State */
.search-empty {
  padding: var(--space-10) var(--space-4);
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* Footer Keycap Hints */
.search-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: var(--text-3xs);
  color: var(--text-tertiary);
  letter-spacing: 0.04em;
}

.search-shortcuts {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.shortcut-pair {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.shortcut-key {
  padding: 1px 4px;
  background-color: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: 2px;
}

.search-touch-hint {
  display: none;
}

@media (max-width: 640px) {
  .search-dialog {
    padding-top: 8px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .search-panel {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 16px);
  }

  .search-input-wrapper {
    padding: 10px 12px;
  }

  .search-esc-hint {
    display: none;
  }

  .search-shortcuts {
    display: none;
  }

  .search-touch-hint {
    display: inline;
  }

  .search-results-area {
    max-height: calc(100dvh - 125px);
  }

  .search-result-item {
    padding: 10px 12px;
  }

  .search-footer {
    padding: 8px 12px;
  }
}
