@layer components {
  /*
   * Search command-palette dialog.
   *
   * Builds on the core dialog base (app-shell.css → dialog, dialog > article)
   * and the shared tier system (app-dialog.css → app-dialog-lg).
   * Only search-specific overrides live here.
   */

  /* ── Dialog positioning: top-aligned instead of centered ─────────────── */

  dialog[data-app-search-dialog] {
    align-items: flex-start;
    padding-top: clamp(2rem, 10vh, 8rem);
  }

  /* ── Article: flex column so body scrolls, header/footer stay fixed ──── */

  .app-search-dialog {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ── Header: search input row ────────────────────────────────────────── */

  .app-search-dialog-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .app-search-dialog-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    margin: 0;
  }

  .app-search-dialog-icon {
    color: var(--app-muted-color);
    font-size: var(--text-base);
    flex-shrink: 0;
  }

  .app-search-dialog-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: var(--text-base);
    color: var(--app-color);
    outline: none;
    padding: 0.25rem 0;
    margin: 0;
    height: auto;
    box-shadow: none;
  }

  .app-search-dialog-input:focus {
    box-shadow: none;
    border-color: transparent;
  }

  .app-search-dialog-header .close {
    flex-shrink: 0;
  }

  /* ── Body: scrollable area between header and footer ─────────────────── */

  .app-search-dialog-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* ── Empty / loading / error states ──────────────────────────────────── */

  .app-search-dialog-empty-state,
  .app-search-dialog-loading,
  .app-search-dialog-error {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--app-muted-color);
    font-size: var(--text-sm);
  }

  .app-search-dialog-empty-state p,
  .app-search-dialog-loading p,
  .app-search-dialog-error p {
    margin: 0 0 0.25rem;
  }

  /* ── Results list ────────────────────────────────────────────────────── */

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

  /* ── Category group ──────────────────────────────────────────────────── */

  .app-search-dialog-category {
    list-style: none;
    margin-bottom: 1rem;
  }

  .app-search-dialog-category-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--app-muted-color);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    padding: 0.25rem 0.75rem;
  }

  .app-search-dialog-category-heading::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--app-border);
  }

  /* ── Individual result items ─────────────────────────────────────────── */

  .app-search-dialog-category-items {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .app-search-dialog-item {
    border-radius: var(--app-border-radius);
    transition: background var(--app-transition);
    cursor: pointer;
    list-style: none;
  }

  .app-search-dialog-item a {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--app-color);
    text-decoration: none;
    font-size: var(--text-base);
    padding: 0.5rem 0.75rem;
    border-radius: var(--app-border-radius);
  }

  .app-search-dialog-item-icon {
    color: var(--app-muted-color);
    font-size: var(--text-base);
    flex-shrink: 0;
  }

  .app-search-dialog-item-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .app-search-dialog-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .app-search-dialog-item-subtitle {
    font-size: var(--text-sm);
    color: var(--app-muted-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .app-search-dialog-item mark {
    padding: 0;
    border-radius: 2px;
  }

  .app-search-dialog-item:hover,
  .app-search-dialog-item-active {
    background: color-mix(in srgb, var(--app-contrast) 8%, transparent);
  }

  .app-search-dialog-item-active a {
    color: var(--app-primary);
  }

  /* ── "View all" item (last item in category) ─────────────────────────── */

  .app-search-dialog-item-view-all a {
    color: var(--app-muted-color);
  }

  .app-search-dialog-item-view-all .app-search-dialog-item-title {
    font-size: var(--text-sm);
  }

  .app-search-dialog-item-view-all:hover a,
  .app-search-dialog-item-view-all.app-search-dialog-item-active a {
    color: var(--app-primary);
  }

  /* ── Footer ──────────────────────────────────────────────────────────── */

  .app-search-dialog-footer {
    justify-content: space-between;
    font-size: var(--text-xs);
    color: var(--app-muted-color);
  }

  .app-search-dialog-view-all {
    color: var(--app-primary);
    text-decoration: none;
    font-weight: var(--font-medium);
  }

  .app-search-dialog-view-all:hover {
    text-decoration: underline;
  }

  .app-search-dialog-footer-hint kbd {
    margin-right: 0.15rem;
  }

  .app-search-dialog-footer-hint kbd:not(:first-child) {
    margin-left: 0.5rem;
  }

  /* ── Mobile ──────────────────────────────────────────────────────────── */

  @media (max-width: 576px) {
    dialog[data-app-search-dialog] {
      padding-top: 1rem;
    }
  }

  /* ── Full search results page (Grid.js) ──────────────────────────────── */

  .search-result-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
  }

  .search-result-title-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }

  .search-result-avatar,
  .search-result-avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--app-border);
    background: var(--app-card-background-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--app-muted-color);
    flex-shrink: 0;
    object-fit: cover;
  }

  .search-result-title {
    font-weight: var(--font-semibold);
    text-decoration: none;
  }

  .search-result-desc {
    margin: 0;
    color: var(--app-muted-color);
    font-size: var(--text-sm);
  }

  .search-result-type {
    color: var(--app-muted-color);
    font-weight: var(--font-semibold);
  }
}
