/* Global search modal — bottom-sheet dialog (mobile + tablet) / fade-in
 * centered modal (desktop ≥1024px). Header with back + input, trending
 * chips, recents (JS-driven), 1 carousel "Goleadores" in cold; hot results
 * are flat list with section headers. Mounted once per page in
 * `base.html.twig`; opened from any trigger via the `search-modal` controller.
 *
 * Animation lives on `.search-modal__wrapper` (inner element), not on
 * `<dialog>` directly — Safari iOS <17 flickers when [open] animates the
 * dialog itself. The wrapper fixes it.
 */

@layer components {
  body.search-modal-open {
    overflow: hidden;
  }

  .search-modal {
    padding: 0;
    border: 0;
    margin: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    background: transparent;
    /* `overflow: clip` (not hidden) prevents both user AND programmatic
       scroll. With `hidden`, the dialog's `scrollTop` can still be set
       by the browser (e.g. focus-into-view fallback when input.focus()
       runs on a content-overflowing dialog), which slides the header
       off-screen above the viewport with no way for the user to scroll
       it back. Seen empirically with ≥10 recents on mobile. */
    overflow: clip;
    color: var(--color-text);
    overflow: hidden;
  }

  .search-modal::backdrop {
    background: rgb(0 0 0 / 60%);
  }

  .search-modal__wrapper {
    width: 100%;
    height: 100%;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
  }

  .search-modal[open] .search-modal__wrapper {
    animation: search-modal-slide-up 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
    will-change: transform, opacity;
  }

  @keyframes search-modal-slide-up {
    from {
      transform: translate3d(0, 100%, 0);
      opacity: 0;
    }

    to {
      transform: translate3d(0, 0, 0);
      opacity: 1;
    }
  }

  @media (width >= 1024px) {
    .search-modal {
      max-width: 720px;
      max-height: 80dvh;
      margin: auto;
      border-radius: 14px;
    }

    .search-modal__wrapper {
      border-radius: 14px;
      overflow: hidden;
    }

    .search-modal[open] .search-modal__wrapper {
      animation: search-modal-fade-in 160ms ease-out;
    }

    @keyframes search-modal-fade-in {
      from {
        opacity: 0;
        transform: translate3d(0, 8px, 0);
      }

      to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
      }
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .search-modal[open] .search-modal__wrapper {
      animation: search-modal-fade-in 120ms ease-out !important;
    }
  }

  /* ── Header ─────────────────────────────────────────── */
  .search-modal__header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg);
  }

  .search-modal__back {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: var(--color-text);
    cursor: pointer;
    border-radius: 50%;
  }

  .search-modal__back:hover {
    background: var(--color-surface-hover);
  }

  .search-modal__back svg {
    width: 22px;
    height: 22px;
  }

  .search-modal__input-wrapper {
    flex: 1 1 auto;
    position: relative;
    display: flex;
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-accent);
    border-radius: 999px;
    padding: 0 14px 0 38px;
    height: 40px;
  }

  .search-modal__input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--color-text-muted);
    pointer-events: none;
  }

  .search-modal__input {
    flex: 1 1 auto;
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1;
    padding: 0;
    min-width: 0;
  }

  .search-modal__input::placeholder {
    color: var(--color-text-muted);
  }

  .search-modal__input::-webkit-search-cancel-button,
  .search-modal__input::-webkit-search-decoration {
    appearance: none;
  }

  /* ── Body (scrollable) ──────────────────────────────── */
  .search-modal__body {
    flex: 1 1 auto;
    overflow: hidden auto;
    padding: 14px 0 24px;
    scrollbar-width: none;
  }

  .search-modal__body::-webkit-scrollbar {
    display: none;
  }

  .search-modal__body[hidden] {
    display: none;
  }

  /* ── Recents (JS-driven, hidden by default) ─────────── */
  .search-cold-recents[hidden] {
    display: none;
  }

  .search-cold-recents {
    padding: 0 14px 14px;
  }

  .search-cold-recents__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
  }

  .search-cold-recents__title {
    font-family: var(--font-title);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin: 0;
  }

  .search-cold-recents__clear {
    background: transparent;
    border: 0;
    color: var(--color-accent);
    font-family: var(--font-body);
    font-size: 12px;
    cursor: pointer;
    padding: 0;
  }

  /* ── Carousel section ───────────────────────────────── */
  .search-cold-carousel {
    padding-bottom: 18px;
  }

  .search-cold-carousel__title {
    font-family: var(--font-title);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin: 0 14px 10px;
  }

  .search-cold-carousel__list {
    display: flex;
    gap: 10px;
    padding: 0 14px;
    overflow: auto hidden;
    scroll-snap-type: x proximity;
    list-style: none;
    margin: 0;
    scrollbar-width: none;
  }

  .search-cold-carousel__list::-webkit-scrollbar {
    display: none;
  }

  /* ── Player card ────────────────────────────────────── */
  .search-cold-card {
    flex: 0 0 96px;
    scroll-snap-align: start;
  }

  .search-cold-card__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    background: var(--color-surface);
    border-radius: 12px;
    text-decoration: none;
    color: var(--color-text);
    position: relative;
    transition: background 120ms;
  }

  .search-cold-card__link:hover {
    background: var(--color-surface-hover);
  }

  .search-cold-card__rank {
    position: absolute;
    top: 6px;
    left: 8px;
    font-family: var(--font-title);
    font-size: 11px;
    line-height: 1;
    color: var(--color-text-subtle);
    font-variant-numeric: tabular-nums;
  }

  .search-cold-card__photo {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--color-surface-sunken);
    flex: 0 0 auto;
  }

  .search-cold-card__photo img:first-child {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .search-cold-card__flag {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid var(--color-bg);
    box-shadow: 0 1px 2px rgb(0 0 0 / 50%);
    object-fit: cover;
  }

  .search-cold-card__name {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.15;
    color: var(--color-text);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    align-self: stretch;
  }

  .search-cold-card__team-logo {
    width: 16px;
    height: 16px;
    object-fit: contain;
    flex: 0 0 auto;
  }

  .search-cold-card__value {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    color: var(--color-accent);
    font-variant-numeric: tabular-nums;
    padding: 3px 8px;
    border-radius: 6px;
    background: color-mix(in oklab, var(--color-accent) 12%, transparent);
  }

  /* Rating tier paint when carousel is `rating`. Background tint + matching text. */
  .search-cold-card__value.rating-badge {
    color: var(--color-bg);
    background: var(--rating-color, var(--color-accent));
  }

  .search-cold-card__value.rating-elite {
    --rating-color: var(--color-rating-elite);
  }

  .search-cold-card__value.rating-excellent {
    --rating-color: var(--color-rating-excellent);
  }

  .search-cold-card__value.rating-very-good {
    --rating-color: var(--color-rating-very-good);
  }

  .search-cold-card__value.rating-good {
    --rating-color: var(--color-rating-good);
  }

  .search-cold-card__value.rating-above-avg {
    --rating-color: var(--color-rating-above-avg);
  }

  .search-cold-card__value.rating-avg {
    --rating-color: var(--color-rating-avg);
  }

  .search-cold-card__value.rating-below-avg {
    --rating-color: var(--color-rating-below-avg);
  }

  .search-cold-card__value.rating-poor {
    --rating-color: var(--color-rating-poor);
  }

  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  /* ── Cold/hot toggle ────────────────────────────────── */
  .search-modal__cold,
  .search-modal__results {
    display: block;
  }

  .search-modal__cold[hidden],
  .search-modal__results[hidden] {
    display: none;
  }

  .search-modal__results {
    padding: 6px 0 24px;
    transition: opacity 250ms ease-out;
  }

  /* ── Hot results — section + row ────────────────────── */
  .search-results__section {
    margin-bottom: 12px;
  }

  .search-results__section-header {
    font-family: var(--font-title);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin: 14px 14px 8px;
    display: flex;
    align-items: baseline;
    gap: 8px;
  }

  .search-results__section-count {
    font-family: var(--font-body);
    font-size: 11px;
    color: var(--color-text-subtle);
    font-variant-numeric: tabular-nums;
  }

  .search-results__list {
    display: flex;
    flex-direction: column;
  }

  /* Match-card + match-row spacing inside the search modal only.
     Scoped via `.search-results__list--fixture` so the home livescore
     and team-detail matches tab (which embed the same partials inside
     their own list chrome) keep their default layout untouched. */
  .search-results__list--fixture .match-card,
  .search-results__list--fixture .match-row {
    margin: 0 10px 8px;
  }

  /* Loading skeleton — placeholder rows shown on the first query out of the
     cold state so the modal body never flashes empty (black) while the fetch
     is in flight. Geometry mirrors .search-row so results swap in without a
     layout jump. Shimmer + reduced-motion come from the shared skeleton.css
     `.skeleton-shimmer` primitive. */
  .search-skeleton-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    min-height: 56px;
  }

  .search-skeleton-row__avatar {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  .search-skeleton-row__body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .search-skeleton-row__line {
    height: 12px;
    border-radius: 4px;
  }

  .search-skeleton-row__line--name {
    width: 55%;
  }

  .search-skeleton-row__line--sub {
    width: 35%;
  }

  .search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--color-text);
    background: transparent;
    transition: background 120ms;
    min-height: 56px;
  }

  .search-row:hover,
  .search-row:focus-visible {
    background: var(--color-surface-hover);
  }

  .search-row[aria-selected="true"] {
    background: var(--color-surface-hover);
  }

  .search-row__avatar {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* The avatar wrapper is just a positioning context for the flag overlay,
     so the player slot stays round but never clips. NOTE: do NOT add
     `overflow: hidden` here — that would clip the flag overlay positioned at
     `bottom: -2px; right: -2px`. The inner IMG clips itself. */
  .search-row__avatar--player {
    border-radius: 50%;
  }

  .search-row__photo {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  /* Player portrait clips itself to a circle so the avatar wrapper can
     stay overflow:visible (needed for the flag overlay). */
  .search-row--player .search-row__photo {
    object-fit: cover;
    border-radius: 50%;
  }

  .search-row__flag {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid var(--color-bg);
    box-shadow: 0 1px 2px rgb(0 0 0 / 50%);
    object-fit: cover;
  }

  .search-row__crest {
    width: 24px;
    height: 24px;
    object-fit: contain;
    position: absolute;
  }

  .search-row__crest--home {
    left: 0;
    top: 4px;
  }

  .search-row__crest--away {
    right: 0;
    bottom: 4px;
  }

  .search-row__body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .search-row__name {
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .search-row__sub {
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--color-text-muted);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Player rich-sub: team-logo + team-name · position. Mirrors the squad-row
     __meta layout so the search modal feels like the rest of the app. */
  .search-row__sub--player {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }

  .search-row__sub-logo {
    width: 14px;
    height: 14px;
    object-fit: contain;
    flex: 0 0 auto;
  }

  .search-row__sub-team {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .search-row__sub-sep {
    flex: 0 0 auto;
    color: var(--color-text-subtle);
  }

  .search-row__sub-pos {
    flex: 0 0 auto;
  }

  /* Celebratory birthday line — a third row beneath the team/position sub
     for a player whose birthday is today. Gold/yellow so the easter-egg
     reads as a delight, not a data field. */
  .search-row__birthday {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-gold-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .search-row__chevron {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    color: var(--color-text-subtle);
  }

  /* ── No-results / error states ──────────────────────── */
  .search-results__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 48px 24px;
    color: var(--color-text-muted);
  }

  .search-results__empty-icon {
    width: 36px;
    height: 36px;
    margin-bottom: 12px;
    color: var(--color-text-subtle);
  }

  .search-results__empty-title {
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 4px;
  }

  .search-results__empty-hint {
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--color-text-muted);
    margin: 0;
  }

  /* ── Tendencias cold slot ────────────────────────────
     Curated-by-popularity vertical list under recents. Reuses the
     `_row.html.twig` partial — only the section header chrome is local. */
  .search-cold-trending {
    display: flex;
    flex-direction: column;
    margin-top: 16px;
  }

  .search-cold-trending__header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 12px 16px 4px;
  }

  .search-cold-trending__title {
    font-family: var(--font-title);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin: 0;
  }

  .search-cold-trending__list {
    display: flex;
    flex-direction: column;
  }

  /* ── Per-section "Mostrar más" expander ───────────────
     Plain text link with a chevron — explicitly NOT a pill / chip.
     Lives at the end of any section whose hit count exceeds the
     INITIAL_VISIBLE threshold (5). One click reveals all overflow rows
     and removes the button. */
  .search-results__expand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: 0;
    border-top: 1px solid var(--color-border-subtle);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    transition: color 120ms ease, background 120ms ease;
  }

  .search-results__expand:hover,
  .search-results__expand:focus-visible {
    color: var(--color-text);
    background: var(--color-surface-hover);
  }

  .search-results__expand svg {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
  }

  /* ── EN VIVO AHORA cold slot ──────────────────────────
     Inserted at the top of the cold body when there are live matches in
     the index. Same row partial as the hot results, variant fixture-live. */
  .search-cold-live {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 24px;
  }

  .search-cold-live__header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 0 16px;
    margin-bottom: 4px;
  }

  .search-cold-live__title {
    font-family: var(--font-title);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin: 0;
  }

  .search-cold-live__count {
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    color: var(--color-live);
  }

  .search-cold-live__list {
    display: flex;
    flex-direction: column;
  }

  /* ── Fixture row variants ────────────────────────────
     LIVE: score-bearing line 1, minute label in --color-live on line 2.
     FINAL: score-bearing line 1, 'Final' label on line 2 (no accent). */
  .search-row__score {
    font-family: var(--font-body);
    font-weight: 700;
    color: var(--color-text);
    margin: 0 4px;
  }

  .search-row__minute-live {
    font-family: var(--font-body);
    font-weight: 700;
    color: var(--color-live);
  }

  .search-row__final {
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--color-text-muted);
  }

  .search-row--fixture-live .search-row__name,
  .search-row--fixture-final .search-row__name {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
