/*
 * CookinBreak : page de recherche (/search). Préfixe cbs-, lit uniquement les tokens de ds/tokens.css (mode sombre automatique).
 * Balisage : app/views/search/page.php, cartes : app/lib/search_view.php · comportement : js/pages/search.js
 */

.cbs.ds-shell { padding-top: var(--ds-space-6); }
.cbs .ds-container { max-width: 1240px; }

/* ------------------------------------------------------------------
 * En-tête et champ de recherche
 * ------------------------------------------------------------------ */
.cbs-head { margin: 0 0 var(--ds-space-5); }
.cbs-title {
  margin: 0; font-family: var(--ds-font-display); font-weight: 500; line-height: 1.2;
  font-size: clamp(1.4rem, 1.1rem + 1.4vw, 2.1rem); color: var(--ds-text); overflow-wrap: anywhere;
}
.cbs-title span { color: var(--ds-primary-text); }
.cbs-count { margin: var(--ds-space-2) 0 0; color: var(--ds-text-2); font-size: var(--ds-text-sm); }
.cbs-count strong { color: var(--ds-text); font-weight: 600; }

.cbs-search { margin: 0 0 var(--ds-space-4); }
.cbs-field {
  position: relative; display: flex; align-items: center; gap: var(--ds-space-2);
  min-height: 64px; padding: 6px 6px 6px var(--ds-space-5);
  background: var(--ds-surface); border: 1.5px solid var(--ds-border); border-radius: var(--ds-radius-md);
  box-shadow: var(--ds-shadow-sm);
  transition: border-color var(--ds-duration) var(--ds-ease), box-shadow var(--ds-duration) var(--ds-ease);
}
.cbs-field:focus-within { border-color: var(--ds-primary); box-shadow: var(--ds-focus-ring), var(--ds-shadow-sm); }
.cbs-field__icon { flex: none; color: var(--ds-text-3); font-size: 1.05rem; }
.cbs-field__input {
  flex: 1; min-width: 0; height: 50px; padding: 0; border: 0; outline: none; background: transparent;
  color: var(--ds-text); font-family: var(--ds-font-body); font-size: 1.05rem; -webkit-appearance: none; appearance: none;
}
.cbs-field__input::placeholder { color: var(--ds-text-3); }
.cbs-field__input::-webkit-search-cancel-button { display: none; }
.cbs .cbs-field__input:focus-visible { box-shadow: none; }
.cbs-field__clear {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 50%; background: var(--ds-surface-2); color: var(--ds-text-2); font-size: 0.85rem; text-decoration: none;
  transition: background var(--ds-duration) var(--ds-ease);
}
.cbs-field__clear:hover { background: var(--ds-border); }
.cbs-field__go { flex: none; min-height: 50px; padding: 0 var(--ds-space-5); }

/* Suggestions sous le champ (le HTML vient de /search-suggest : classes cbh-… de site-header.css) */
.cbs-suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 8px); z-index: 30; max-height: min(70vh, 560px); overflow-y: auto; padding: 8px;
  background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md); box-shadow: var(--ds-shadow-lg);
}
.cbs-suggest[hidden] { display: none; }
.cbs-suggest a { color: var(--ds-text); text-decoration: none; }
.cbs-suggest a.cbh-all { color: var(--ds-primary-text); }

/* ------------------------------------------------------------------
 * Barre d'outils (filtres, tri), filtres actifs, remarques
 * ------------------------------------------------------------------ */
.cbs-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3); margin: 0 0 var(--ds-space-4); }
.cbs-filterbtn { gap: 8px; }
.cbs-badge-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--ds-radius-pill); background: var(--ds-primary); color: var(--ds-on-primary); font-size: 0.7rem;
}
.cbs-sort { display: flex; align-items: center; gap: var(--ds-space-2); margin-left: auto; }
.cbs-sort__label { color: var(--ds-text-3); font-size: var(--ds-text-sm); }
.cbs-sort .ds-select { min-height: 40px; width: auto; padding: 0 36px 0 var(--ds-space-3); font-size: var(--ds-text-sm); font-weight: 500; }
@media (max-width: 560px) {
  .cbs-field { padding-left: var(--ds-space-4); }
  .cbs-field__go span { display: none; }
  .cbs-field__go { padding: 0 var(--ds-space-4); }
  .cbs-sort__label { display: none; }
}

/* Filtres actifs : une ligne de texte, pas de pastilles */
.cbs-active { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--ds-space-4); margin: 0 0 var(--ds-space-4); font-size: var(--ds-text-sm); color: var(--ds-text-2); }
.cbs-active::before { content: "Filtres :"; color: var(--ds-text-3); }
.cbs .cbs-x { display: inline-flex; align-items: center; gap: 6px; color: var(--ds-text); font-weight: 600; text-decoration: none; }
.cbs-x .cb-icon { font-size: 0.75rem; color: var(--ds-text-3); transition: color var(--ds-duration) var(--ds-ease); }
.cbs-x:hover .cb-icon { color: var(--ds-danger); }
.cbs .cbs-clear { color: var(--ds-text-2); text-decoration: underline; text-underline-offset: 3px; }

.cbs-note { margin: 0 0 var(--ds-space-4); color: var(--ds-text-2); font-size: var(--ds-text-sm); line-height: 1.5; }
.cbs-note strong { color: var(--ds-text); font-weight: 600; }
.cbs-note a { color: var(--ds-primary-text); font-weight: 600; }
.cbs-note > .cb-icon { margin-right: 6px; color: var(--ds-text-3); }

/* ------------------------------------------------------------------
 * Résultats : cartes et grille du design system (css/ds/recipe-card.css)
 * ------------------------------------------------------------------ */
.cbs-sep { display: flex; align-items: center; gap: var(--ds-space-3); margin: 0; color: var(--ds-text-3); font-size: var(--ds-text-sm); font-weight: 600; }
.cbs-sep::before, .cbs-sep::after { content: ""; flex: 1; height: 1px; background: var(--ds-border); }

.cbs-more { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--ds-space-3); margin: var(--ds-space-8) 0 0; }
.cbs-more small { color: var(--ds-text-3); font-weight: 500; margin-left: 4px; }
.cbs-more .ds-btn[aria-busy="true"] { opacity: 0.6; pointer-events: none; }

/* ------------------------------------------------------------------
 * États vides et blocs d'exploration
 * ------------------------------------------------------------------ */
.cbs-empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--ds-space-3); max-width: 560px; margin: var(--ds-space-8) auto var(--ds-space-10);
  text-align: center;
}
.cbs-empty__icon {
  display: inline-flex; align-items: center; justify-content: center; width: 72px; height: 72px; border-radius: 50%;
  background: var(--ds-primary-soft); color: var(--ds-primary-text); font-size: 1.6rem;
}
.cbs-empty h2 { margin: 0; font-family: var(--ds-font-display); font-weight: 500; font-size: var(--ds-text-xl); line-height: 1.25; overflow-wrap: anywhere; }
.cbs-empty p { margin: 0; color: var(--ds-text-2); }
.cbs-empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--ds-space-3); margin-top: var(--ds-space-2); }

.cbs-block { margin: var(--ds-space-8) 0 0; }
.cbs-block__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--ds-space-3); margin: 0 0 var(--ds-space-4); }
.cbs-block__head h2 { margin: 0; font-family: var(--ds-font-display); font-size: var(--ds-text-lg); font-weight: 500; }

.cbs-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: var(--ds-space-6) var(--ds-space-8); margin: var(--ds-space-6) 0 0; }
.cbs-list { min-width: 0; }
.cbs-list__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--ds-space-3); padding-bottom: var(--ds-space-2); border-bottom: 1px solid var(--ds-border); }
.cbs-list__head h2 { margin: 0; font-family: var(--ds-font-body); font-size: var(--ds-text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ds-text-3); }
.cbs-list__head a, .cbs-link { font-size: var(--ds-text-sm); font-weight: 600; background: none; border: 0; padding: 0; cursor: pointer; color: var(--ds-primary-text); font-family: inherit; text-decoration: none; }
.cbs-list ul { margin: 0; padding: 0; list-style: none; }
.cbs-list li { position: relative; display: flex; align-items: center; border-bottom: 1px solid var(--ds-border); }
.cbs .cbs-row { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--ds-space-3); padding: 13px 0; color: var(--ds-text); font-size: var(--ds-text-base); text-decoration: none; }
.cbs-row .cb-icon { flex: none; color: var(--ds-text-3); font-size: 1rem; }
.cbs-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cbs-row:hover span { color: var(--ds-primary-text); }
.cbs-row__x { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--ds-text-3); font-size: 0.75rem; cursor: pointer; }
.cbs-row__x:hover { background: var(--ds-surface-2); color: var(--ds-text); }

/* ------------------------------------------------------------------
 * Filtres : volet à droite sur ordinateur, feuille en bas sur mobile
 * ------------------------------------------------------------------ */
.cbs-sheet {
  inset: 0 0 0 auto; margin: 0; width: min(480px, 100vw); max-width: none; height: 100dvh; max-height: none; padding: 0; border: 0;
  border-radius: var(--ds-radius-lg) 0 0 var(--ds-radius-lg); background: var(--ds-bg); color: var(--ds-text); box-shadow: var(--ds-shadow-lg);
  font-family: var(--ds-font-body); overflow: hidden;
}
.cbs-sheet[open] { display: flex; animation: cbs-sheet-in 360ms var(--ds-ease); }
.cbs-sheet::backdrop { background: var(--ds-overlay); animation: cbs-fade 260ms var(--ds-ease); }
@keyframes cbs-sheet-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes cbs-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes cbs-fade { from { opacity: 0; } to { opacity: 1; } }
.cbs-sheet *, .cbs-sheet *::before, .cbs-sheet *::after { box-sizing: border-box; }
.cbs-sheet__form { display: flex; flex-direction: column; width: 100%; min-height: 0; }

.cbs-sheet__head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3); padding: var(--ds-space-5) var(--ds-space-6) var(--ds-space-4); background: var(--ds-surface); border-bottom: 1px solid var(--ds-border); }
.cbs-sheet__head h2 { margin: 0; font-family: var(--ds-font-display); font-weight: 500; font-size: var(--ds-text-xl); line-height: 1.2; }
.cbs-sheet__sub { margin: 2px 0 0; color: var(--ds-text-3); font-size: var(--ds-text-sm); }
.cbs-sheet__close { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border: 0; border-radius: 50%; background: var(--ds-surface-2); color: var(--ds-text-2); cursor: pointer; transition: background var(--ds-duration) var(--ds-ease); }
.cbs-sheet__close:hover { background: var(--ds-border); }

.cbs-sheet__body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--ds-space-2) var(--ds-space-6) var(--ds-space-6); overscroll-behavior: contain; }
.cbs-sheet__foot {
  flex: none; display: flex; align-items: center; gap: var(--ds-space-3); padding: var(--ds-space-4) var(--ds-space-6) calc(var(--ds-space-4) + env(safe-area-inset-bottom, 0px));
  background: var(--ds-surface); border-top: 1px solid var(--ds-border);
}
.cbs-sheet__foot .ds-btn--primary { flex: 1; }

/* Une rubrique : titre, puis les choix */
.cbs-fs { min-width: 0; margin: 0; padding: var(--ds-space-5) 0; border: 0; border-bottom: 1px solid var(--ds-border); }
.cbs-fs:last-child { border-bottom: 0; }
.cbs-fs legend { float: left; display: flex; align-items: center; gap: var(--ds-space-2); width: 100%; padding: 0 0 var(--ds-space-3); font-size: var(--ds-text-sm); font-weight: 600; color: var(--ds-text); }
.cbs-fs legend + * { clear: both; }
.cbs-fs__n { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--ds-radius-pill); background: var(--ds-primary); color: var(--ds-on-primary); font-size: 0.7rem; font-weight: 600; }
.cbs-fs__n[hidden] { display: none; }
.cbs-fs .ds-hint { margin: var(--ds-space-3) 0 0; }

/* Cases à cocher et choix uniques : cases invisibles, c'est l'étiquette qui change d'état */
.cbs-tile input, .cbs-pill input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.cbs-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ds-space-2); }
.cbs-tile, .cbs-pill { position: relative; cursor: pointer; }
.cbs-tile span {
  display: flex; align-items: center; gap: var(--ds-space-3); min-height: 52px; padding: 0 var(--ds-space-4);
  background: var(--ds-surface); border: 1.5px solid var(--ds-border); border-radius: var(--ds-radius-sm); font-size: var(--ds-text-sm); font-weight: 500;
  transition: background var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease), box-shadow var(--ds-duration) var(--ds-ease);
}
.cbs-tile__ico { flex: none; display: inline-flex; font-size: 1.1rem; }
.cbs-tile:hover span { border-color: var(--ds-border-strong); }
.cbs-tile input:checked + span { background: var(--ds-primary-soft); border-color: var(--ds-primary); box-shadow: inset 0 0 0 1px var(--ds-primary); font-weight: 600; }
.cbs-tile input:focus-visible + span, .cbs-pill input:focus-visible + span { box-shadow: var(--ds-focus-ring); }

.cbs-pills { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }
.cbs-pill span {
  display: inline-flex; align-items: center; height: 40px; padding: 0 var(--ds-space-4); background: var(--ds-surface); border: 1.5px solid var(--ds-border);
  border-radius: var(--ds-radius-pill); font-size: var(--ds-text-sm); font-weight: 500; white-space: nowrap;
  transition: background var(--ds-duration) var(--ds-ease), border-color var(--ds-duration) var(--ds-ease), color var(--ds-duration) var(--ds-ease);
}
.cbs-pill:hover span { border-color: var(--ds-border-strong); }
.cbs-pill input:checked + span { background: var(--ds-primary); border-color: var(--ds-primary); color: var(--ds-on-primary); font-weight: 600; }
.cbs-pill input:checked + span:hover { background: var(--ds-primary-hover); }
/* « Peu importe » : choisi par défaut, il ne doit pas ressembler à un filtre actif */
.cbs-pill input[value=""]:checked + span { background: var(--ds-primary-soft); border-color: var(--ds-primary); color: var(--ds-primary-text); }
.cbs-pill input[value=""]:checked + span:hover { background: var(--ds-primary-soft); }

/* Familles de types de plat : dépliables */
.cbs-group { border-top: 1px solid var(--ds-border); }
.cbs-group:first-of-type { border-top: 0; }
.cbs-group summary {
  display: flex; align-items: center; gap: var(--ds-space-2); min-height: 48px; cursor: pointer; list-style: none;
  font-size: var(--ds-text-sm); font-weight: 600; color: var(--ds-text-2);
}
.cbs-group summary::-webkit-details-marker { display: none; }
.cbs-group summary > .cb-icon { margin-left: auto; font-size: 0.75rem; color: var(--ds-text-3); transition: transform var(--ds-duration) var(--ds-ease); }
.cbs-group[open] summary > .cb-icon { transform: rotate(180deg); }
.cbs-group[open] summary { color: var(--ds-text); }
.cbs-group summary:focus-visible { outline: none; border-radius: var(--ds-radius-xs); box-shadow: var(--ds-focus-ring); }
.cbs-group .cbs-pills { padding: 0 0 var(--ds-space-4); }

@media (max-width: 640px) {
  .cbs-sheet { inset: auto 0 0 0; width: 100%; height: auto; max-height: 92dvh; border-radius: var(--ds-radius-lg) var(--ds-radius-lg) 0 0; }
  .cbs-sheet[open] { animation-name: cbs-sheet-up; }
  .cbs-sheet__head { padding: var(--ds-space-5) var(--ds-space-5) var(--ds-space-3); position: relative; }
  .cbs-sheet__head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--ds-border-strong); }
  .cbs-sheet__body { padding: var(--ds-space-1) var(--ds-space-5) var(--ds-space-5); }
  .cbs-sheet__foot { padding-left: var(--ds-space-5); padding-right: var(--ds-space-5); }
}
@media (prefers-reduced-motion: reduce) {
  .cbs-sheet[open], .cbs-sheet::backdrop { animation: none; }
}
