/**
 * Search & Command Palette Styles
 * @countermeasure/web-components
 *
 * Search input with dropdown results and command palette overlay.
 */

/* ============================================================================
   SEARCH COMPONENT
   ============================================================================ */
.cmm-search {
  position: relative;
  width: 100%;
}

.cmm-search__input-wrapper {
  position: relative;
}

.cmm-search__icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}

.cmm-search__input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  font-size: 0.875rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background-color: hsl(var(--card));
  color: hsl(var(--foreground));
  transition: border-color var(--transition-fast, 150ms),
              box-shadow var(--transition-fast, 150ms);
}

.cmm-search__input::placeholder {
  color: hsl(var(--muted-foreground));
}

.cmm-search__input:focus {
  outline: none;
  border-color: hsl(var(--focus-ring));
  box-shadow: 0 0 0 2px hsl(var(--focus-ring) / 0.2);
}

.cmm-search__clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms),
              color var(--transition-fast, 150ms);
}

.cmm-search__clear:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--foreground));
}

/* ============================================================================
   SEARCH RESULTS DROPDOWN
   ============================================================================ */
.cmm-search__results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: var(--z-dropdown, 50);
  margin-top: 0.25rem;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background-color: hsl(var(--card));
  box-shadow: var(--shadow-lg);
  scrollbar-width: thin;
}

.cmm-search__result {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms);
}

.cmm-search__result:hover {
  background-color: hsl(var(--accent));
}

.cmm-search__result--active {
  background-color: hsl(var(--accent));
}

.cmm-search__result + .cmm-search__result {
  border-top: 1px solid hsl(var(--border) / 0.5);
}

.cmm-search__result-label {
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  font-weight: 500;
}

.cmm-search__result-description {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  line-height: 1.4;
}

.cmm-search__group {
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  user-select: none;
}

.cmm-search__no-results {
  padding: 1.5rem;
  text-align: center;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}

/* Highlight matched text */
.cmm-search__highlight {
  background-color: hsl(var(--info) / 0.2);
  color: hsl(var(--info));
  border-radius: 1px;
}

/* ============================================================================
   COMMAND PALETTE
   ============================================================================ */
.cmm-command-palette {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal, 400);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}

.cmm-command-palette__overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5); /* TODO(phase-1): tokenize — backdrop overlay */
  backdrop-filter: blur(4px);
  animation: cmm-command-palette-backdrop-in var(--transition-fast, 150ms) ease-out;
}

@keyframes cmm-command-palette-backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.cmm-command-palette__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 36rem;
  margin: 0 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  background-color: hsl(var(--card));
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: cmm-command-palette-in var(--transition-normal, 200ms) ease-out;
}

@keyframes cmm-command-palette-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.cmm-command-palette__input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
}

.cmm-command-palette__input-icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  color: hsl(var(--muted-foreground));
}

.cmm-command-palette__input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: hsl(var(--foreground));
  outline: none;
}

.cmm-command-palette__input::placeholder {
  color: hsl(var(--muted-foreground));
}

/* ============================================================================
   COMMAND PALETTE RESULTS
   ============================================================================ */
.cmm-command-palette__results {
  max-height: 360px;
  overflow-y: auto;
  padding: 0.375rem;
  scrollbar-width: thin;
}

.cmm-command-palette__group {
  padding: 0.5rem 0.625rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  user-select: none;
}

.cmm-command-palette__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms);
}

.cmm-command-palette__item:hover {
  background-color: hsl(var(--accent));
}

.cmm-command-palette__item--active {
  background-color: hsl(var(--accent));
}

.cmm-command-palette__item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  color: hsl(var(--muted-foreground));
}

.cmm-command-palette__item-label {
  flex: 1;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmm-command-palette__item-description {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

/* ============================================================================
   KEYBINDING HINTS
   ============================================================================ */
.cmm-command-palette__keybinding {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
  flex-shrink: 0;
}

.cmm-command-palette__keybinding kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.375rem;
  height: 1.375rem;
  padding: 0 0.375rem;
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: 500;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  background-color: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
}

/* ============================================================================
   COMMAND PALETTE EMPTY STATE
   ============================================================================ */
.cmm-command-palette__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}

/* ============================================================================
   COMMAND PALETTE FOOTER
   ============================================================================ */
.cmm-command-palette__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-top: 1px solid hsl(var(--border));
  font-size: 0.6875rem;
  color: hsl(var(--muted-foreground));
}

.cmm-command-palette__footer-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.cmm-command-palette__footer-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.25rem;
  font-family: inherit;
  font-size: 0.625rem;
  border: 1px solid hsl(var(--border));
  border-radius: 3px;
  background-color: hsl(var(--secondary));
}
