@layer components {
  .search-form { display: flex; flex-wrap: wrap; gap: 8px; }
  .search-form input[type="search"] { flex: 1 1 260px; min-width: 0; }
  .search-summary { margin: 0; }
  .search-results {
    list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg, 12px);
    background: var(--background); overflow: hidden;
  }
  .search-result + .search-result { border-top: 1px solid var(--border); }
  .search-result-link {
    display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; color: var(--foreground); text-decoration: none;
  }
  .search-result-link:is(:hover, :active) { background: var(--surface); text-decoration: none; }
  .search-result-link:focus-visible { outline: 2px solid var(--jx-accent); outline-offset: -2px; }
  .search-result-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 13px; }
  .search-result-conversation { font-weight: 600; }
  .search-result-author, .search-result-head time { color: var(--muted-foreground); }
  .search-result-excerpt { margin: 0; font-size: 14px; line-height: 1.5; color: var(--muted-foreground); overflow-wrap: anywhere; }
  .search-result mark { background: var(--jx-accent-soft); color: var(--foreground); border-radius: 3px; padding: 0 2px; font-weight: 500; }

  /* The row of filters under the field (Ui::SearchFiltersComponent): a pill per filter, its menu a native popover. */
  .search-filters { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
  .search-filter {
    display: inline-flex; align-items: center; max-width: 100%;
    border: 1px solid var(--border); border-radius: 999px; background: var(--background);
  }
  .search-filter.is-on { border-color: var(--jx-accent-line); background: var(--jx-accent-soft); }
  .search-filter-button {
    display: inline-flex; align-items: center; gap: 6px; min-width: 0; height: 32px; padding: 0 10px 0 12px;
    border: 0; border-radius: 999px; background: none; color: var(--foreground); font: inherit; font-weight: 500;
    cursor: pointer;
  }
  .search-filter.is-on .search-filter-button { padding-right: 4px; font-weight: 600; }
  .search-filter-button svg { color: var(--muted-foreground); flex: none; }
  .search-filter-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .search-filter-button:focus-visible, .search-filter-remove:focus-visible { outline: 2px solid var(--jx-accent); outline-offset: 2px; }
  .search-filter-remove {
    display: grid; place-items: center; width: 24px; height: 24px; margin-right: 4px; border-radius: 50%;
    color: var(--muted-foreground);
  }
  .search-filter-remove:is(:hover, :active) { background: var(--muted); color: var(--foreground); }
  .search-filters-clear { margin-left: 4px; color: var(--jx-accent); font-weight: 500; text-decoration: none; }

  .search-filter-menu {
    inset: auto; margin: 0; width: 300px; max-height: min(420px, 70dvh); overflow: auto; padding: 6px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--foreground);
    box-shadow: var(--shadow-lg);
  }
  .search-filter-menu-title { display: none; }
  .search-filter-find { width: 100%; margin-bottom: 6px; }
  .search-filter-group { margin: 8px 10px 4px; color: var(--muted-foreground); font-size: 13px; font-weight: 600; }
  .search-filter-option {
    display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
    cursor: pointer;
  }
  .search-filter-option:is(:hover, :focus-within) { background: var(--muted); }
  .search-filter-option[hidden], .search-filter-group[hidden] { display: none; }
  .search-filter-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .search-filter-count { color: var(--muted-foreground); }
  .search-filter-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px 10px 8px; }
  .search-filter-dates label { display: flex; flex-direction: column; gap: 2px; color: var(--muted-foreground); font-size: 13px; }
  .search-filter-dates .button { grid-column: 1 / -1; justify-self: end; }

  /* A filter is drawn 32-36 px tall and answers a finger on --tap. */
  @media (pointer: coarse) {
    .search-filter-button, .search-filter-remove { position: relative; }
    .search-filter-button::after, .search-filter-remove::after {
      content: ""; position: absolute; inset: min(0px, calc((100% - var(--tap)) / 2));
    }
  }

  /* On a phone the row scrolls sideways and a menu is a sheet at the bottom, rows at finger size. */
  @media (max-width: 767px) {
    .search-filters {
      flex-wrap: nowrap; overflow-x: auto; margin-inline: calc(-1 * var(--gutter)); padding: 4px var(--gutter);
      scrollbar-width: none;
    }
    .search-filter { flex: none; }
    .search-filter-button { min-height: 36px; }
    .search-filter-menu {
      inset: auto 0 0; width: 100%; max-width: none; max-height: 80dvh; padding: 8px 16px 24px;
      border-radius: 14px 14px 0 0; border-width: 1px 0 0;
    }
    .search-filter-menu::backdrop { background: oklch(0 0 0 / .45); }
    .search-filter-menu-title { display: block; margin: 4px 0 8px; font-size: 1.0625rem; font-weight: 600; }
    .search-filter-option { min-height: var(--tap); font-size: var(--text-body); }
  }

  /* On a phone the results run edge to edge, at the body's text size. */
  @media (max-width: 767px) {
    .search-results { margin-inline: calc(-1 * var(--gutter)); border-inline: 0; border-radius: 0; }
    .search-result-link { padding-inline: var(--gutter); }
    .search-result-excerpt { font-size: var(--text-body); }
  }

  .search-cancel { display: none; }

  /* The phone's header is the field and Annuler: the title stays for assistive technology, the button is the keyboard's. */
  @media (max-width: 767px) {
    .search-page > .page-header { display: contents; }
    .search-page-title {
      position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
      overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
    }
    .search-form { flex-wrap: wrap; align-items: center; }
    .search-form input[type="search"] { flex: 1 1 0; height: 44px; font-size: 16px; }
    .search-form .button { display: none; }
    .search-cancel {
      display: inline-flex; align-items: center; min-height: 44px; font-size: 16px; color: var(--jx-accent); text-decoration: none;
    }
    /* No floating bar here: its reserve of space goes too. */
    body.search-screen .tab-bar { display: none; }
    body.search-screen .app-main { padding-bottom: 20px; }
  }

}
