/* =========================================================================
   DESIGN WAREHOUSE — browse.css
   The catalogue: search, facet rail, result grid, detail overlay.
   Loaded after motion.css; shared tokens and components come from there.
   ========================================================================= */

/* ================================================================
   PAGE SHELL
   ================================================================ */
.browse {
  background: var(--bg);
  color: var(--fg);
  padding-top: var(--topbar-h);
  min-height: 100vh;
}

.browse__head {
  padding-block: clamp(40px, 7vh, 96px) clamp(28px, 4vh, 56px);
  border-bottom: 1px solid var(--hair);
}

.browse__title {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 7vw, 5.4rem);
  line-height: 0.95;
  letter-spacing: var(--ls-display);
  margin-block: 14px 18px;
}

.browse__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px var(--s-5);
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--muted);
}

.browse__meta b {
  color: var(--fg);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ================================================================
   LAYOUT — rail + results
   ================================================================ */
.browse__layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: clamp(28px, 4vw, 64px);
  align-items: start;
  padding-block: clamp(28px, 4vh, 52px) clamp(72px, 12vh, 140px);
}

@media (max-width: 1020px) {
  .browse__layout { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------- no JavaScript
   The rail, the result count and the pager are all filled by catalogue.js.
   Without scripting they are an empty column and a permanent "Loading…", so
   they step aside for the <noscript> notice in the markup. The layout drops to
   block flow as well, or the results column would fall into the rail's track. */
html:not(.js) .browse__layout { display: block; }
html:not(.js) .filters,
html:not(.js) .results__bar,
html:not(.js) .pager { display: none; }

/* ================================================================
   SEARCH
   ================================================================ */
.search {
  position: relative;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--hair-strong);
  transition: border-color var(--dur-2) var(--ease-out-quart);
}

.search:focus-within { border-bottom-color: var(--clay); }

.search__icon {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  color: var(--muted);
  margin-right: 10px;
}

.search input {
  flex: 1 1 auto;
  min-width: 0;
  background: none;
  border: 0;
  padding: 12px 0;
  font-size: 0.9375rem;
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
}

.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search__clear {
  flex: 0 0 auto;
  padding: 4px 6px;
  font-size: var(--fs-meta);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color var(--dur-1) linear;
  /* "Clear" is 47px wide, "مسح" is 35 — the same control, one language short of
     the 44x24 floor. The label stays where it is; the box grows around it. */
  min-width: 44px;
}
.search__clear:hover { color: var(--fg); }
.search__clear[hidden] { display: none; }

/* ================================================================
   FACET RAIL
   ================================================================ */
.filters {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 6px;
}

/* The drawer's own way out. This has to be declared *before* the drawer's media
   query below: an equal-specificity rule later in the file would win at every
   width and the button would never appear. */
.filters__done { display: none; }

@media (max-width: 1020px) {
  .filters {
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: var(--z-topbar);
    background: var(--bg);
    max-height: none;
    padding: var(--s-5) var(--gutter) var(--s-9);
    overflow-y: auto;
    transform: translateY(-101%);
    visibility: hidden;
    transition: transform var(--dur-4) var(--ease-out-expo),
                visibility var(--dur-4) linear;
  }
  .filters.is-open { transform: translateY(0); visibility: visible; }

  /* The drawer covers the results bar, and with it the button that opened it,
     so the way out lives inside the drawer — pinned to its top edge, because
     the facet list is long enough to scroll the head away. */
  .filters__head {
    position: sticky;
    top: calc(var(--s-5) * -1);
    z-index: 1;
    margin-top: calc(var(--s-5) * -1);
    padding: var(--s-5) 0 var(--s-4);
    background: var(--bg);
  }

  .filters__done { display: inline-flex; }
}

.filters__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
  padding-bottom: var(--s-4);
}

.filters__clear {
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--muted);
  transition: color var(--dur-1) linear;
  /* Same trick as the footer links: 20px of text plus 6px is a 26px target
     without moving the rail's header. */
  padding-block: 3px;
}
.filters__clear:hover { color: var(--accent-text); }
.filters__clear[hidden] { display: none; }

.facet { border-top: 1px solid var(--hair); }

.facet__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  width: 100%;
  padding: 15px 0;
  font-size: var(--fs-meta);
  font-weight: 500;
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--fg);
  text-align: left;
}

.facet__toggle:hover { color: var(--accent-text); }

.facet__chevron {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform var(--dur-2) var(--ease-out-expo);
}

.facet__toggle[aria-expanded="false"] .facet__chevron {
  transform: rotate(-45deg) translate(-1px, 1px);
}

.facet__body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--dur-3) var(--ease-out-expo);
}
.facet__toggle[aria-expanded="false"] + .facet__body { grid-template-rows: 0fr; }

.facet__inner { overflow: hidden; }

.facet__list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-bottom: var(--s-5);
}

.facet__option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.8125rem;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--dur-1) linear;
}

.facet__option:hover { color: var(--fg); }
.facet__option.is-active { color: var(--fg); }

.facet__option input {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border: 1px solid var(--hair-strong);
  position: relative;
  cursor: pointer;
  transition: border-color var(--dur-1) linear, background var(--dur-1) linear;
}

.facet__option input:checked {
  background: var(--clay);
  border-color: var(--clay);
}

.facet__option input:checked::after {
  content: "";
  position: absolute;
  left: 3.5px;
  top: 0.5px;
  width: 4px;
  height: 8px;
  border: solid var(--paper);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(42deg);
}

.facet__option input:focus-visible { outline: 2px solid var(--clay); outline-offset: 2px; }

.facet__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.facet__count {
  flex: 0 0 auto;
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

.facet__option.is-empty { opacity: 0.34; }
.facet__option.is-empty input { cursor: not-allowed; }

/* ================================================================
   RESULTS BAR
   ================================================================ */
.results__bar {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  flex-wrap: wrap;
  padding-bottom: var(--s-5);
  border-bottom: 1px solid var(--hair);
  margin-bottom: var(--s-7);
}

.results__count {
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--muted);
  margin-right: auto;
}

.results__count b {
  color: var(--fg);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Shown only by the <noscript> block, so it never coexists with the results. */
.results__notice {
  max-width: 62ch;
  padding: var(--s-5) var(--s-6);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: var(--fs-small);
}

.results__notice a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.results__sort {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--muted);
}

.results__sort select {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--hair-strong);
  color: var(--fg);
  font-size: var(--fs-meta);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 20px 5px 0;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 9px) calc(50% + 1px), calc(100% - 4px) calc(50% + 1px);
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.results__sort select:focus-visible { outline: 2px solid var(--clay); outline-offset: 2px; }

.results__filter-toggle { display: none; }

@media (max-width: 1020px) {
  .results__filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }
}

/* ================================================================
   ACTIVE FILTER CHIPS
   ================================================================ */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--s-6);
}
.chips:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 12px;
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius-pill);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg);
  transition: border-color var(--dur-1) linear, background var(--dur-1) linear;
}
.chip:hover { border-color: var(--clay); background: rgba(192, 96, 58, 0.07); }

.chip__x {
  font-size: 0.8125rem;
  line-height: 1;
  color: var(--muted);
}
.chip:hover .chip__x { color: var(--accent-text); }

/* ================================================================
   RESULT GRID
   ================================================================ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: clamp(20px, 2.6vw, 38px) clamp(16px, 2vw, 30px);
}

.grid__skeleton {
  aspect-ratio: 1 / 1;
  background: var(--bg-alt);
  animation: skeleton 1400ms ease-in-out infinite;
}

@keyframes skeleton {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 0.9; }
}

.card { min-width: 0; }

.card__link { display: block; }

.card__frame {
  position: relative;
  aspect-ratio: 1 / 1;
  /* Each plate is painted with the colour of its own photograph's ground
     (set inline per card), so a contained image reads as one surface rather
     than a picture stuck on a differently-coloured card. */
  background: var(--bg-alt);
  overflow: hidden;
  border: 1px solid transparent;
  transition: border-color var(--dur-3) var(--ease-out-quart);
}

.card:hover .card__frame,
.card__link:focus-visible .card__frame { border-color: var(--hair-strong); }

.card__img {
  width: 100%;
  height: 100%;
  /* Contain, not cover: these are catalogue photographs of whole objects, and
     a square crop of a 2.3:1 bench removes most of the bench. */
  object-fit: contain;
  object-position: center;
  transition: transform 900ms var(--ease-out-expo), opacity var(--dur-4) linear;
  opacity: 0;
}

.card__img.is-loaded { opacity: 1; }
.card:hover .card__img { transform: scale(1.035); }

/* Corner registration marks, matching the work plates on the front page. */
.card__frame::before,
.card__frame::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1px solid var(--paper);
  opacity: 0;
  z-index: 2;
  transition: opacity var(--dur-3) var(--ease-out-quart);
}
.card__frame::before { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
.card__frame::after { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }
.card:hover .card__frame::before,
.card:hover .card__frame::after { opacity: 0.85; }

.card__body {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
  margin-top: 13px;
}

.card__name {
  font-family: var(--font-display);
  font-size: 1.1875rem;
  line-height: 1.18;
  letter-spacing: -0.01em;
  min-width: 0;
}

.card__meta {
  margin-top: 5px;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card__period {
  flex: 0 0 auto;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ================================================================
   EMPTY STATE
   ================================================================ */
.empty {
  border: 1px solid var(--hair);
  padding: clamp(40px, 8vh, 88px) var(--s-6);
  text-align: center;
}

.empty__title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  margin-bottom: 12px;
}

.empty__body { color: var(--muted); font-size: var(--fs-small); margin-bottom: var(--s-6); }

/* ================================================================
   PAGINATION
   ================================================================ */
.pager {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  justify-content: center;
  margin-top: clamp(40px, 7vh, 80px);
  padding-top: var(--s-6);
  border-top: 1px solid var(--hair);
}

.pager__pages { display: flex; align-items: center; gap: 2px; }

.pager__page {
  /* 44 wide, not 34: a page number is a control you tap, and the wider box
     costs nothing at the sizes involved. */
  min-width: 44px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  border: 1px solid transparent;
  transition: color var(--dur-1) linear, border-color var(--dur-1) linear;
}

.pager__page:hover { color: var(--fg); border-color: var(--hair-strong); }
.pager__page.is-current { color: var(--fg); border-color: var(--fg); }
.pager__gap { color: var(--muted); padding-inline: 4px; }

.pager__step {
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--muted);
  transition: color var(--dur-1) linear;
  /* Tall enough to be a target: 20px of text plus padding either side. */
  min-height: 30px;
  /* And wide enough, for the same reason the page numbers are: "Next →" clears
     44px on its own, "التالي ←" comes to 43 and fails the rule by a pixel. */
  min-width: 44px;
  padding-inline: 4px;
}
.pager__step:hover { color: var(--fg); }
.pager__step[disabled] { opacity: 0.3; pointer-events: none; }

/* ================================================================
   DETAIL OVERLAY
   ================================================================ */
.detail {
  position: fixed;
  inset: 0;
  z-index: var(--z-curtain);
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vh, 40px) clamp(12px, 3vw, 40px);
}
.detail[hidden] { display: none; }

.detail__scrim {
  position: absolute;
  inset: 0;
  background: rgba(11, 11, 12, 0.72);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity var(--dur-4) var(--ease-out-quart);
}
.detail.is-open .detail__scrim { opacity: 1; }

.detail__panel {
  position: relative;
  width: min(1180px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(18px);
  transition: opacity var(--dur-4) var(--ease-out-quart),
              transform var(--dur-4) var(--ease-out-expo);
}

.detail.is-open .detail__panel { opacity: 1; transform: none; }

/* The panel is focused programmatically when the overlay opens, so that the
   dialog owns the keyboard. It is a container, not a control, and a ring
   around the whole panel would say nothing a visitor needs to know. */
.detail__panel:focus { outline: none; }

/* The piece title is focused so that a screen reader announces which record
   opened — but a heading is not a control, and Chromium treats a programmatic
   focus with no pointer interaction behind it as keyboard focus, so a visitor
   arriving on a shared /furniture/:slug link was greeted by an accent ring
   around a title they had not touched. The controls inside the dialog keep
   their rings; this one does not need one. */
.detail__name:focus,
.detail__name:focus-visible { outline: none; }

.detail__close {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper);
  transition: color var(--dur-1) linear;
}
.detail__close:hover { color: var(--clay-ink); }

.detail__layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 0;
  /* Stretch, so the media column's ground runs the full height of the panel
     instead of stopping part-way down and leaving a visible edge. */
  align-items: stretch;
}

@media (max-width: 860px) {
  .detail__layout { grid-template-columns: minmax(0, 1fr); }
}

.detail__media {
  background: var(--paper-deep);
  padding: clamp(20px, 4%, 56px);
  display: grid;
  place-items: center;
  min-height: 320px;
}

.detail__media img {
  width: 100%;
  height: auto;
  max-height: 74vh;
  object-fit: contain;
}

.detail__body { padding: clamp(24px, 3.4vw, 54px); }

.detail__eyebrow {
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: var(--clay-ink);
  margin-bottom: 14px;
}

.detail__name {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3.6vw, 3rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.detail__fulltitle {
  font-size: var(--fs-small);
  color: rgba(11, 11, 12, 0.62);
  margin-bottom: var(--s-6);
}

.detail__specs { border-top: 1px solid var(--hair-light); margin-bottom: var(--s-6); }

.detail__spec {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: var(--s-4);
  padding-block: 11px;
  border-bottom: 1px solid var(--hair-light);
  font-size: var(--fs-small);
  align-items: baseline;
}

.detail__spec dt {
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: rgba(11, 11, 12, 0.62);
}

.detail__spec dd { line-height: 1.55; }

.detail__credit {
  border-left: 2px solid var(--clay);
  padding-left: var(--s-4);
  font-size: 0.75rem;
  line-height: 1.6;
  color: rgba(11, 11, 12, 0.72);
}

.detail__credit a { color: var(--clay-ink); text-decoration: underline; text-underline-offset: 2px; }

.detail__related {
  margin-top: var(--s-7);
  padding-top: var(--s-5);
  border-top: 1px solid var(--hair-light);
}

.detail__related h3 {
  font-size: var(--fs-meta);
  letter-spacing: var(--ls-meta);
  text-transform: uppercase;
  color: rgba(11, 11, 12, 0.62);
  font-family: var(--font-text);
  font-weight: 500;
  margin-bottom: var(--s-4);
}

.detail__related ul {
  display: flex;
  flex-direction: column;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.detail__related a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  font-size: var(--fs-small);
  border-bottom: 1px solid var(--hair-light);
  transition: color var(--dur-1) linear, padding-left var(--dur-2) var(--ease-out-expo);
}
.detail__related a:hover { color: var(--clay-ink); padding-left: 6px; }

.detail__related img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  flex: 0 0 auto;
  background: var(--paper-deep);
}

/* ================================================================
   LOADING STATE
   ================================================================ */
.results.is-busy { opacity: 0.55; transition: opacity var(--dur-2) linear; }

/* ================================================================
   REDUCED MOTION
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  .card__img { opacity: 1; }
  .grid__skeleton { animation: none; }
  .detail__scrim,
  .detail__panel { opacity: 1; transform: none; }
  .filters { transition: none; }
}
