/* =============================================================================
   SITE SEARCH
   -----------------------------------------------------------------------------
   Two surfaces, one component: the header control and the panel it opens. The
   /search page's own field is here too, because a visitor who lands on that
   page and one who opens the panel are looking at the same control and it must
   not be two.

   WHAT IS NOT HERE, DELIBERATELY: the result row. A result is a .row-item, the
   same component every other list on the site uses, so it inherits the hover
   fill, the stretched link and the reduced-motion rule from sdeira-sections.css
   rather than carrying a second definition that drifts. Only the panel's own
   scroll container is styled below.

   No borders anywhere: separation is tonal, which is the system's one answer.
   ========================================================================== */

/* ---- The header control ---------------------------------------------------
   It is the language control's twin, geometry and all - they sit next to each
   other in the bar and anything less than the same numbers drifts the moment
   either is retuned. .lang's own rules are in the two chrome stylesheets, so
   the shared values are restated here rather than reached for across files.

   COLOUR IS PART OF "geometry and all", and it was the one number this file
   left out. `color: inherit` on a control that sits inside a transparent bar
   over a photograph resolves to the document ink, so the glyph painted
   #414042 on a dark header - measured on the English homepage and on all 32
   generated pages, beside a language control that was rgba(255,255,255,.84).
   The four states below are .lang's four, restated for the same reason the
   geometry is. */
.nav-search {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 44, not the 36 this was: the icon controls in the bar are one set and an
     odd box out puts uneven air between the glyphs (measured 28px on one side
     of this control and 32px on the other). 44 is also the WCAG 2.5.8 target
     the burger beside it already carries. Stated here rather than in the
     homepage sheets because this file loads after them and would otherwise
     win - and because it is the one file that owns this control on all 33
     pages that have it. */
  min-inline-size: 44px;
  min-block-size: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: rgba(255, 255, 255, .84);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

.nav-search:is(:hover, :focus-visible) {
  color: var(--brand-white);
  background: rgba(255, 255, 255, .12);
}

/* The bar goes opaque and light past the scroll threshold. Written against
   #hd, the header's id on every page that carries this control, because the
   homepage sheets key this off `header.scrolled` and the sub-page sheet off
   `#hd.scrolled` - the id matches both without stating the pair. */
#hd.scrolled .nav-search {
  color: var(--muted);
}

/* --accent-strong, not --accent-text: the solid-fill ink is White on the
   brand sites and vanished on this pale wash (Eskan, 24 Sep 2026). */
#hd.scrolled .nav-search:is(:hover, :focus-visible) {
  color: var(--accent-strong);
  background: var(--accent-wash);
}

.nav-search:focus-visible {
  /* --accent, not --brand-razeen: review V3 slide 9 note 01 (22 Sep 2026)
     unifies the accent. --brand-razeen measures 1.98 on White, under the 3.0
     WCAG 1.4.11 asks of a focus indicator; --accent measures 9.35 there. */
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---- The panel ------------------------------------------------------------
   Fixed, full-viewport, and it IS the backdrop - a click that lands on it
   rather than on the sheet is a click outside, which is what the script tests.
   A separate backdrop element would be a second thing to keep in step with the
   panel's own open state. */
.site-search {
  position: fixed;
  inset: 0;
  margin: 0;
  border: 0;
  max-inline-size: none;
  max-block-size: none;
  inline-size: auto;
  block-size: auto;
  color: inherit;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: clamp(72px, 12vh, 140px) clamp(16px, 4vw, 40px) 40px;
  background: rgba(var(--image-overlay-rgb), .86);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

/* THE CLOSED PANEL MUST NOT BE ON THE PAGE AT ALL.
   The script closes it with `panel.hidden = true`, and the attribute's whole
   meaning comes from the browser's own `[hidden] { display: none }` - which is
   a user-agent rule, so the `display: grid` above beat it. The panel therefore
   stayed laid out on every page that has search: position: fixed, inset: 0,
   z-index 120, and merely transparent.

   Nothing looked wrong. But a full-viewport layer over the document swallows
   the pointer, so text could not be SELECTED anywhere on those 33 pages - drag
   across a paragraph and the mousedown landed on the panel instead. That was
   the reported symptom, and it is why the Arabic homepage was unaffected: it
   has no search panel to cover it.

   Restated here rather than relying on the UA rule, because any author
   `display` on this selector would silently defeat it again. */
.site-search[hidden] { display: none; }

/* The native modal layer contains focus and covers all page controls. */
.site-search::backdrop { background: transparent; }

.site-search.is-open { opacity: 1; }

/* The sheet enters from above rather than fading in place: the control that
   opened it is in the header, so the panel arrives from where it was asked for.
   translate only - nothing here resizes, so the pointer never chases it. */
.site-search-sheet {
  inline-size: min(100%, 720px);
  max-block-size: calc(100dvh - clamp(112px, 16vh, 180px));
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  padding: clamp(18px, 2vw, 26px);
  border-radius: var(--r);
  background: var(--surface-raised);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translate3d(0, -12px, 0);
  transition: transform var(--dur-base) var(--ease-out);
}

.site-search.is-open .site-search-sheet { transform: none; }

/* ---- The field, on both surfaces ------------------------------------------
   The panel's field and the results page's field are one rule. The box is the
   sunken surface and the input inside it is transparent, the same arrangement
   the assistant's composer and the form fields use: one visible surface, the
   control drawn on it, no outline. */
.site-search-field,
.search-field {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--surface-sunken);
  transition: background-color var(--dur-fast) var(--ease-out);
}

.site-search-field:focus-within,
.search-field:focus-within {
  background: var(--surface-sunken-strong);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.site-search-field > i.ph,
.search-field > i.ph { color: var(--icon); }

.site-search-field input,
.search-field input {
  flex: 1 1 auto;
  min-inline-size: 0;
  padding: 8px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  caret-color: var(--accent);
  font: inherit;
  font-size: var(--type-action);
}

/* Safari draws its own clear button inside type=search and it lands on the
   wrong surface. The close control is the panel's own. */
.site-search-field input::-webkit-search-decoration,
.site-search-field input::-webkit-search-cancel-button,
.search-field input::-webkit-search-decoration,
.search-field input::-webkit-search-cancel-button { appearance: none; }

.site-search-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  inline-size: 32px;
  block-size: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--icon);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.site-search-close:is(:hover, :focus-visible) {
  background: var(--surface-raised);
  color: var(--ink);
}

.site-search-close:focus-visible {
  /* --accent, not --brand-razeen: review V3 slide 9 note 01 (22 Sep 2026)
     unifies the accent. --brand-razeen measures 1.98 on White, under the 3.0
     WCAG 1.4.11 asks of a focus indicator; --accent measures 9.35 there. */
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Count, results, empty state ------------------------------------------ */
.site-search-count,
.search-count {
  margin: 14px 0 0;
  color: var(--label);
  font-size: var(--type-meta);
}

/* The search panel has a useful first state: established C5 route rows, not a
   second button system or an empty dialog. They disappear as soon as a query
   is present, leaving the existing live-result flow unchanged.
   NO TITLE RULE ABOVE THEM (site owner, 15 Sep 2026): a label reading "ابدأ من
   هنا" over rows that name themselves was one more line telling the reader
   what the rows already said. */
.site-search-start {
  margin-block-start: 10px;
}
/* .row-list is display: grid, which beats the hidden attribute: the start rows
   stayed on screen above the results while typing. */
:is(.site-search-start, .site-search-results, .site-search-count, .site-search-empty)[hidden] { display: none; }

.site-search-start .row-item {
  background: var(--surface-sunken);
}

/* A thin scrollbar of its own, the pattern the dropdown lists and the
   assistant panel use, never the operating system's bar with arrows. */
:is(.site-search-sheet, .site-search-results) { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
:is(.site-search-sheet, .site-search-results)::-webkit-scrollbar { width: 4px; }
:is(.site-search-sheet, .site-search-results)::-webkit-scrollbar-track { background: transparent; }
:is(.site-search-sheet, .site-search-results)::-webkit-scrollbar-thumb { border-radius: var(--r); background: var(--line); }
:is(.site-search-sheet, .site-search-results)::-webkit-scrollbar-button { display: none; }

/* The panel's list is what scrolls, not the sheet: the field and the count stay
   put while the results move under them. min-block-size: 0 on the flex child is
   what actually lets it shrink - without it a long list pushes the sheet past
   its own max height instead of scrolling inside it. */
.site-search-results {
  flex: 1 1 auto;
  min-block-size: 0;
  margin-block-start: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* MEASURED, NOT DEFENSIVE. .row-list is display: grid, and this is the same
     element - so the moment the flex parent gave it a definite height, its auto
     rows stopped sizing to their content and were distributed across that
     height instead: eight rows at exactly 588/8 = 64.8px each, with every row's
     title and description overflowing a box two-thirds too short. The list
     looked like eight empty labels. align-content: start is what stops the
     distribution; grid-auto-rows keeps each row on its own content whatever the
     container's height turns out to be. */
  align-content: start;
  grid-auto-rows: min-content;
}

.site-search-empty,
.search-empty {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: var(--type-body);
}

/* ---- The results page -----------------------------------------------------
   The FIELD is measured, the RESULTS are not. A search field wider than about
   720px reads as a form the page is built around rather than as a control, and
   nobody types a line that long; a result row is a card and takes the section's
   own width like every other list on the site. Capping both would have left the
   results in a narrow column with half the section empty beside them. */
.search-panel { display: grid; }

.search-panel .search-field { max-inline-size: 720px; }

.search-results { margin-block-start: clamp(20px, 2.4vw, 32px); }

/* Four ways on rather than a dead end, per the spec's No Results section. It is
   the shared row list, so the suggestions answer the pointer exactly like the
   results they replace. */
.search-suggestions { margin-block-start: clamp(20px, 2.4vw, 32px); }

@media (max-width: 720px) {
  .site-search { padding-block-start: 64px; }
  .site-search-sheet { max-block-size: calc(100dvh - 96px); }
}

@media (prefers-reduced-motion: reduce) {
  .site-search,
  .site-search-sheet {
    transition: none;
  }

  .site-search-sheet { transform: none; }
}

/* ---- Result rows on the panel's own ground --------------------------------
   The sheet is --surface-raised and so is .row-item's default, so the rows
   arrived invisible: the right colour on the wrong ground, which looks like
   working code and reads as a broken list. The sheet is a raised surface, so
   its rows step DOWN, exactly as .pad--raised already makes them do inside a
   section. Stated here rather than by adding .pad--raised to the sheet, which
   would also drag that ground's padding and section rules onto a panel. */
.site-search-results .row-item { background: var(--surface-sunken); }
/* The hover wipe is the brand's own card fill, the one every linked card on the
   site uses, so the copy's white tone-flip lands on a colour it can be read
   on. The panel had its own --surface-sunken-strong fill here, which is White
   on every brand: the title turned white on white (owner, 16 Nov 2026). */

/* The type label leads the row on this surface. In a result set the visitor is
   scanning for WHAT a thing is as much as what it is called - it is the one
   thing the spec names for these rows - so it sits above the title rather than
   under the description where the shared component puts it. */
.site-search-results .row-item-meta,
.search-results .row-item-meta {
  order: -1;
  color: var(--accent-text);
}
