/* Rechercher (search.js) : la loupe en haut de la barre latérale, à droite du logo, et la fenêtre
   de recherche au centre (en plein écran sur téléphone). Couleurs par les variables de l'app (clair
   et sombre). */

/* --- La loupe --- */
/* Comme ChatGPT : le logo (ou le nom) à gauche, la loupe à droite, une icône grise sans fond, centrée
   sur la ligne du logo ; son bord droit sur celui des lignes du menu, qui défilent 6 px plus près du
   bord (style.css, .side-scroll). Logo et nom l'un sous l'autre : sur la ligne du logo. */
.side-head { display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 36px; }
.side-head > .brand { flex: 0 1 auto; padding-bottom: 2px; }
.side-head:has(.brand-logo:not([hidden])):has(.brand-name:not([hidden])) { align-items: flex-start; }
.side-icon { display: grid; flex: none; place-items: center; width: 36px; height: 36px; margin: 0 -6px 0 auto; padding: 0; border-radius: 9px; background: none; color: var(--t2); }
.side-head:has(.brand-logo:not([hidden])):has(.brand-name:not([hidden])) .side-icon { margin-top: -2px; }
:where(.side-icon):hover { background: color-mix(in srgb, var(--t1) 6%, transparent); color: var(--t1); }
.side-icon svg { width: 20px; height: 20px; }

/* --- La fenêtre --- */
dialog.search-modal {
  display: flex;
  flex-direction: column;
  width: min(640px, calc(100% - 32px));
  max-height: min(560px, calc(100% - 96px));
  margin: 12vh auto auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--t1);
  box-shadow: var(--surface-shadow);
}
dialog.search-modal:not([open]) { display: none; }
dialog.search-modal, dialog.search-modal::backdrop { transition: opacity .18s ease, transform .18s cubic-bezier(.3, .7, .2, 1); }
dialog.search-modal[open] { opacity: 1; transform: none; }
@starting-style {
  dialog.search-modal[open] { opacity: 0; transform: translateY(-6px) scale(.98); }
  dialog.search-modal[open]::backdrop { opacity: 0; }
}
dialog.search-modal.closing { animation: search-out .16s ease forwards; pointer-events: none; }
dialog.search-modal.closing::backdrop { animation: backdrop-out .16s ease forwards; }
@keyframes search-out { to { opacity: 0; transform: translateY(-6px) scale(.98); } }

.search-head { display: flex; flex: none; align-items: center; gap: 10px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.search-glass { display: grid; flex: none; color: var(--t2); }
.search-glass svg { width: 19px; height: 19px; }
.search-modal .search-input { flex: 1; min-width: 0; height: 38px; padding: 0; border: 0; border-radius: 0; background: none; font-size: 16px; }
.search-modal .search-input:focus { box-shadow: none; }
.search-close { display: grid; flex: none; place-items: center; width: 32px; height: 32px; padding: 0; border-radius: 50%; background: none; color: var(--t2); }
.search-close svg { width: 17px; height: 17px; }
:where(.search-close):hover { background: color-mix(in srgb, var(--t1) 7%, transparent); color: var(--t1); }

.search-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px 8px 8px; }
.search-note { margin: 6px 10px 6px; font-size: 12.5px; font-weight: 600; color: var(--t2); }
.search-results { display: grid; gap: 1px; margin: 0; padding: 0; list-style: none; transition: opacity .15s; }
.search-results.loading { opacity: .55; }
.search-item { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 2px 10px; padding: 9px 10px; border-radius: 11px; cursor: pointer; }
.search-item.active { background: var(--conv-active); }
.search-icon { display: grid; grid-row: span 2; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--bg2); color: var(--t2); }
.search-icon svg { width: 16px; height: 16px; }
.search-icon.planned { background: var(--run-soft); color: var(--run-text); }
.search-icon.automation { background: var(--wait-soft); color: var(--wait-text); }
.search-title { min-width: 0; padding-top: 1px; overflow: hidden; font-size: 14px; font-weight: 600; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.search-time { padding-top: 2px; font-size: 12px; color: var(--t2); white-space: nowrap; }
.search-excerpt { grid-column: 2 / 4; display: -webkit-box; min-width: 0; overflow: hidden; font-size: 13px; line-height: 1.45; color: var(--t2); -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.search-excerpt b { font-weight: 600; color: var(--t1); }
.search-modal mark { padding: 0 1px; border-radius: 3px; background: color-mix(in srgb, #f2b705 34%, transparent); color: inherit; }

.search-hint { display: flex; flex: none; flex-wrap: wrap; gap: 6px 16px; padding: 9px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--t2); }
.search-hint kbd { margin-right: 3px; padding: 0 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--raised); font: inherit; font-size: 10.5px; font-weight: 600; line-height: 1.6; }
@media (pointer: coarse) { .search-hint { display: none; } }

/* Le message trouvé, une fois la conversation ouverte : un halo qui s'efface. */
.msg.search-hit { animation: search-hit 2.2s ease-out; }
@keyframes search-hit { 0%, 45% { box-shadow: 0 0 0 3px color-mix(in srgb, #f2b705 50%, transparent); } }

/* Téléphone : la fenêtre prend tout l'écran, sous l'encoche. */
@media (max-width: 720px) {
  dialog.search-modal { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; border: 0; border-radius: 0; }
  .search-head { padding-top: max(10px, env(safe-area-inset-top)); padding-right: max(10px, env(safe-area-inset-right)); }
  .search-body { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  dialog.search-modal, dialog.search-modal::backdrop { transition: none; }
  .msg.search-hit { animation: none; }
}
