/* Smart Search dropdown -- Stage 3 Task 3 (static/js/smart_search/dropdown.js).
   Portaled to <body>, position:fixed -- Stage 1's fix for two real production
   bugs: an ancestor's overflow:hidden clipping the old dropdown, and a later
   sticky bar out-stacking it at the same z-index (see
   static/js/instant-search.js's positionDropdown()). This selector must stay
   a direct child of <body>: a position:fixed element re-anchors to any
   ancestor with its own transform/filter/backdrop-filter, which is exactly
   what the portal exists to avoid.

   Logical properties throughout so RTL (dir="rtl") mirrors row layout for
   free via inheritance from <html dir="rtl">; only the fixed box's own
   left/top/bottom/width are physical, and those are computed in JS because
   position:fixed placement has no logical equivalent.

   Visual language matches templates/catalog/partials/_home_search_panel.html
   (static/catalog/css/search_panel.css's .sugg block): white card, 16px
   radius, soft shadow, small-caps section labels, tinted icon tiles. */

.ss {
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--ag-z-overlay, 100);
  display: none;
  flex-direction: column;
  background: var(--ag-color-bg-surface, #fff);
  border: 1px solid var(--ag-color-border-subtle, rgba(46, 116, 184, 0.14));
  border-radius: 16px;
  box-shadow: var(--ag-shadow-xl, 0 24px 50px rgba(15, 23, 42, 0.16));
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-family: var(--ag-font-sans, inherit);
  font-size: var(--ag-font-size-md, 14px);
  color: var(--ag-color-text-body, #2A2A55);
}
.ss.ss--open { display: flex; }

.ss__sr-only,
.ss__live {
  position: absolute !important;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- sections ---- */
.ss__section + .ss__section {
  margin-block-start: 4px;
  border-block-start: 1px solid var(--ag-color-border-subtle, rgba(46, 116, 184, 0.12));
  padding-block-start: 4px;
}
.ss__section-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 4px;
}
.ss__section-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ag-color-text-muted, #6B7491);
}
.ss__clear {
  margin-inline-start: auto;
  border: 0;
  background: transparent;
  color: var(--ag-color-brand-primary, #2E74B8);
  font: inherit;
  font-weight: 600;
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.ss__clear:hover,
.ss__clear:focus-visible { background: var(--ag-color-interactive-hover, rgba(46, 116, 184, 0.08)); }

/* ---- rows ----
   The row (role="option") is a plain container; the navigable link/label
   area (.ss__row-link) and the auxiliary buttons (.ss__star/.ss__remove)
   are its SIBLINGS, never ancestor and descendant -- a <button> nested
   inside an <a> is invalid HTML and unreliable for assistive tech (fix
   round 1, task-3-review.md finding 2). */
.ss__row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 11px;
  transition: background 90ms ease;
}
.ss__row:hover,
.ss__row.is-active { background: var(--ag-color-bg-surface-alt, #F5F8FD); }
.ss__row.is-active { box-shadow: inset 0 0 0 1.5px var(--ag-color-brand-primary, #2E74B8); }

.ss__row-link {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-inline-size: 0;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.ss__thumb {
  inline-size: 40px;
  block-size: 32px;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 auto;
}
.ss__icon {
  display: inline-grid;
  place-items: center;
  inline-size: 32px;
  block-size: 32px;
  border-radius: 10px;
  flex: 0 0 auto;
  color: var(--ag-color-brand-primary, #2E74B8);
  background: var(--ag-color-brand-primary-softer, rgba(46, 116, 184, 0.12));
}
.ss__icon svg { inline-size: 16px; block-size: 16px; }

.ss__body {
  flex: 1;
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ss__title {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ss__title mark {
  background: #fef3c7;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.ss__subtitle {
  font-size: 11.5px;
  color: var(--ag-color-text-muted, #6B7491);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ss__star {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--ag-color-text-muted, #6B7491);
  font-size: 15px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
}
.ss__star.is-pinned { color: #f59e0b; }
.ss__star:hover,
.ss__star:focus-visible { background: var(--ag-color-interactive-hover, rgba(46, 116, 184, 0.08)); }

.ss__remove {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--ag-color-text-muted, #6B7491);
  font-size: 16px;
  line-height: 1;
  inline-size: 24px;
  block-size: 24px;
  border-radius: 50%;
  cursor: pointer;
}
.ss__remove:hover,
.ss__remove:focus-visible {
  background: var(--ag-color-interactive-hover, rgba(46, 116, 184, 0.08));
  color: var(--ag-color-text-body, #2A2A55);
}

/* ---- footer ---- */
.ss__footer {
  display: block;
  margin-block-start: 4px;
  padding: 10px 12px;
  border-block-start: 1px solid var(--ag-color-border-subtle, rgba(46, 116, 184, 0.12));
  text-align: center;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--ag-color-brand-primary, #2E74B8);
  text-decoration: none;
  border-radius: 0 0 12px 12px;
}
.ss__footer:hover,
.ss__footer:focus-visible { background: var(--ag-color-interactive-hover, rgba(46, 116, 184, 0.08)); }

/* ---- empty / loading / error ---- */
.ss__empty,
.ss__error {
  padding: 16px 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--ag-color-text-muted, #6B7491);
}
.ss__error { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ss__retry {
  border: 1px solid var(--ag-color-border, rgba(46, 116, 184, 0.28));
  background: var(--ag-color-bg-surface, #fff);
  color: var(--ag-color-brand-primary, #2E74B8);
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.ss__retry:hover,
.ss__retry:focus-visible { background: var(--ag-color-brand-primary-softer, rgba(46, 116, 184, 0.12)); }

.ss__shimmer {
  margin: 6px 10px;
  block-size: 40px;
  border-radius: 10px;
  background: linear-gradient(
    90deg,
    var(--ag-color-bg-surface-alt, #F5F8FD) 25%,
    var(--ag-color-bg-page-alt, #EEF2F8) 37%,
    var(--ag-color-bg-surface-alt, #F5F8FD) 63%
  );
  background-size: 400% 100%;
  animation: ss-shimmer 1.4s ease infinite;
}
@keyframes ss-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---- phone sheet (<=600px) ---- */
.ss__sheet-head { display: none; }
.ss--phone {
  position: fixed;
  inset: 0;
  border-radius: 0;
  max-height: none;
  box-shadow: none;
  border: 0;
  padding: 0;
}
.ss--phone .ss__sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-block-start: max(10px, env(safe-area-inset-top, 10px));
  border-block-end: 1px solid var(--ag-color-border-subtle, rgba(46, 116, 184, 0.12));
  position: sticky;
  top: 0;
  background: var(--ag-color-bg-surface, #fff);
  z-index: 1;
}
.ss--phone .ss__back {
  flex: 0 0 auto;
  inline-size: 36px;
  block-size: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 0;
  background: var(--ag-color-bg-surface-alt, #F5F8FD);
  color: var(--ag-color-text-body, #2A2A55);
  font-size: 20px;
  cursor: pointer;
}
.ss--phone .ss__sheet-input {
  flex: 1;
  min-inline-size: 0;
  block-size: 40px;
  border: 1px solid var(--ag-color-border, rgba(46, 116, 184, 0.24));
  border-radius: 999px;
  padding-inline: 14px;
  font-size: 16px; /* prevents iOS zoom on focus */
  background: var(--ag-color-bg-surface-alt, #F5F8FD);
  color: inherit;
}
.ss--phone .ss__list { padding-block-end: env(safe-area-inset-bottom, 0); }

/* Set on <html> while the phone sheet is open -- mirrors the .ag-pop-open
   convention in static/catalog/css/search_panel.css. */
html.ss-scroll-lock,
html.ss-scroll-lock body { overflow: hidden; }

/* ---- dark / glass modifier (globe) ---- */
.ss--dark {
  background: rgba(15, 23, 42, 0.92);
  border-color: rgba(255, 255, 255, 0.14);
  color: #E7ECF7;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.ss--dark .ss__section-label,
.ss--dark .ss__subtitle,
.ss--dark .ss__clear,
.ss--dark .ss__star,
.ss--dark .ss__empty,
.ss--dark .ss__error { color: rgba(231, 236, 247, 0.68); }
.ss--dark .ss__star.is-pinned { color: #fbbf24; }
.ss--dark .ss__row:hover,
.ss--dark .ss__row.is-active { background: rgba(255, 255, 255, 0.08); }
.ss--dark .ss__icon {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}
.ss--dark .ss__title mark {
  background: rgba(250, 204, 21, 0.35);
  color: #fff;
}
.ss--dark .ss__section + .ss__section,
.ss--dark .ss__footer { border-color: rgba(255, 255, 255, 0.14); }
.ss--dark .ss__footer { color: #93c5fd; }
.ss--dark .ss__retry {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.28);
  color: #93c5fd;
}
.ss--dark.ss--phone,
.ss--dark .ss__sheet-head { background: rgba(15, 23, 42, 0.98); }
.ss--dark .ss__sheet-head { border-color: rgba(255, 255, 255, 0.14); }
.ss--dark .ss__back { background: rgba(255, 255, 255, 0.12); color: #fff; }
.ss--dark .ss__sheet-input {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .ss__row { transition: none; }
  .ss__shimmer { animation: none; }
}
