/* Presentation: original CSS, borrowing GUIChallenges' fixed action regions,
   native dialog semantics, focus-visible treatment and motion preference. */
#fabric-picker[data-hp-enhanced] {
  --hp-paper: #fbfaf6;
  --hp-surface: #f1f0e9;
  --hp-ink: #30372d;
  --hp-muted: #7a7d73;
  --hp-line: #e2e4da;
  --hp-selected: #ebeee4;
  width: min(920px, calc(100vw - 40px));
  height: min(850px, calc(100dvh - 40px));
  max-height: calc(100dvh - 40px);
  padding: 0 !important;
  border: 1px solid var(--hp-line);
  border-radius: 18px !important;
  background: var(--hp-paper);
  color: var(--hp-ink);
  box-shadow: 0 24px 90px #20291b20;
  overflow: hidden;
  font-family: "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

#fabric-picker[data-hp-enhanced]::backdrop {
  background: #20271f70;
  backdrop-filter: blur(5px);
}

#fabric-picker[data-hp-enhanced] .fabric-picker-head {
  flex: none;
  gap: 16px;
  margin: 0;
  padding: 20px 24px 17px;
  border-bottom: 1px solid var(--hp-line);
}

#fabric-picker[data-hp-enhanced] .fabric-picker-head h2 {
  font-size: 20px;
  line-height: 1.4;
  font-weight: 500;
  letter-spacing: .035em;
  color: var(--hp-ink);
}

#fabric-picker[data-hp-enhanced] #close-fabric {
  flex: none;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--hp-line);
  border-radius: 7px !important;
  background: transparent;
  color: var(--hp-muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
}

#fabric-picker[data-hp-enhanced] .fabrics {
  min-height: 0;
  padding: 18px 24px 0 !important;
  background: transparent !important;
  box-shadow: none;
}

#fabric-picker[data-hp-enhanced] .fabrics > label[for="search"] {
  margin-bottom: 5px;
  color: var(--hp-muted);
  font-size: 11px;
}

#fabric-picker[data-hp-enhanced] :is(input[type="search"], select) {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--hp-line);
  border-radius: 7px;
  background: #fffefa;
  color: var(--hp-ink);
  box-shadow: none;
  font-size: 14px;
  line-height: 1.5;
}

#fabric-picker[data-hp-enhanced] .catalog-search-field {
  min-height: 44px;
  border: 1px solid var(--hp-line);
  border-radius: 7px;
  background: #fffefa;
}

#fabric-picker[data-hp-enhanced] .catalog-search-field input {
  border: 0;
  background: transparent;
}

#fabric-picker[data-hp-enhanced] .filters {
  gap: 12px;
  margin-top: 12px;
}

#fabric-picker[data-hp-enhanced] .filters label {
  color: var(--hp-muted);
  font-size: 11px;
}

#fabric-picker[data-hp-enhanced] .tryon-color-chips {
  gap: 6px;
  margin-top: 5px;
  padding-bottom: 3px;
}

#fabric-picker[data-hp-enhanced] .tryon-color-chips button {
  gap: 5px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--hp-muted);
  font-size: 11px;
  line-height: 1.4;
}

#fabric-picker[data-hp-enhanced] .tryon-color-chips button[aria-pressed="true"] {
  border-color: #c8cebd;
  background: var(--hp-selected);
  color: var(--hp-ink);
}

#fabric-picker[data-hp-enhanced] .results-line {
  flex: none;
  gap: 12px;
  min-height: 36px;
  margin: 7px 0 9px;
  color: var(--hp-muted);
  font-size: 11px;
  line-height: 1.5;
}

#fabric-picker[data-hp-enhanced] #reset {
  flex: none;
  min-height: 36px;
  padding: 4px 0 4px 8px;
  color: var(--hp-muted);
  font-size: 11px;
  text-underline-offset: 4px;
}

#fabric-picker[data-hp-enhanced] .series-back {
  min-height: 38px;
  padding: 3px 0 10px;
  color: var(--hp-ink);
  text-align: left;
  font-size: 12px;
}

/* Keep the renderer's real grid and button order, including lazy-load scroll. */
#fabric-picker[data-hp-enhanced] #fabric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px 12px;
  min-height: 0;
  max-height: none !important;
  padding: 3px 3px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: #d0d5c7 transparent;
  align-content: start;
  align-items: start;
  scroll-padding-block: 6px;
}

#fabric-picker[data-hp-enhanced] #fabric-grid .fabric {
  position: relative;
  min-width: 0;
  padding: 5px;
  border: 1px solid var(--hp-line);
  border-radius: 9px;
  background: #fffefa;
  color: var(--hp-ink);
  text-align: left;
  box-shadow: none;
  touch-action: manipulation;
}

#fabric-picker[data-hp-enhanced] #fabric-grid .fabric[aria-pressed="true"] {
  padding: 5px;
  border: 1px solid #68735a;
  background: var(--hp-selected);
  box-shadow: 0 0 0 1px #68735a;
}

#fabric-picker[data-hp-enhanced] .fabric[aria-pressed="true"]::after {
  content: "✓ " attr(data-hp-selected-label);
  position: absolute;
  top: 11px;
  right: 11px;
  max-width: calc(100% - 22px);
  padding: 4px 7px;
  border: 1px solid #ffffff70;
  border-radius: 4px;
  background: #30372def;
  color: #fffefa;
  font-size: 10px;
  line-height: 1.35;
  font-weight: 500;
  pointer-events: none;
}

#fabric-picker[data-hp-enhanced] .fabric > img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  border-radius: 5px;
  object-fit: cover;
}

#fabric-picker[data-hp-enhanced] .tryon-series-mosaic {
  gap: 2px;
  border-radius: 5px;
}

#fabric-picker[data-hp-enhanced] .tryon-series-mosaic img {
  display: block;
  border-radius: 0;
}

#fabric-picker[data-hp-enhanced] .tryon-series-mosaic em {
  right: 4px;
  bottom: 4px;
  padding: 2px 4px;
  border-radius: 3px;
  background: #30372dc9;
  font-size: 10px;
  line-height: 1.3;
}

#fabric-picker[data-hp-enhanced] .fabric .tryon-fabric-title {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 5px 5px;
}

#fabric-picker[data-hp-enhanced] .fabric .tryon-fabric-title > span {
  display: block;
  padding: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: .015em;
  overflow-wrap: anywhere;
}

#fabric-picker[data-hp-enhanced] .fabric .hp-picker-colour-code {
  display: block;
  padding: 0;
  color: var(--hp-muted);
  font-size: 10px;
  font-weight: 400;
  line-height: 1.5;
}

#fabric-picker[data-hp-enhanced] .fabric .tryon-series-summary {
  display: block;
  padding: 0 5px 6px;
  color: var(--hp-muted);
  font-size: 10px;
  font-weight: 400;
  line-height: 1.5;
}

#fabric-picker[data-hp-enhanced] .fabric .tryon-summary-full {
  display: inline;
  padding: 0;
  font: inherit;
}

#fabric-picker[data-hp-enhanced] .fabric :is(.tryon-summary-compact, .tryon-card-action, .tryon-series-category) {
  display: none;
}

#fabric-picker[data-hp-enhanced] #more {
  flex: none;
  min-height: 40px;
  margin: 3px 0 6px;
  padding: 8px 12px;
  border: 1px solid var(--hp-line);
  border-radius: 6px;
  background: transparent;
  color: var(--hp-muted);
  font-size: 12px;
}

#fabric-picker[data-hp-enhanced] #more[hidden] { display: none !important; }
#fabric-picker[data-hp-enhanced] .more-feedback { flex: none; margin: 0 0 5px; font-size: 10px; }

#fabric-picker[data-hp-enhanced] .hp-picker-footer {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px 24px;
  border-top: 1px solid var(--hp-line);
  background: var(--hp-paper);
}

#fabric-picker[data-hp-enhanced] .hp-picker-summary {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

#fabric-picker[data-hp-enhanced] .hp-picker-summary-swatch {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 3px;
  border: 1px solid var(--hp-line);
  border-radius: 6px;
  background: var(--hp-surface);
  overflow: hidden;
}

#fabric-picker[data-hp-enhanced] .hp-picker-summary-swatch::before {
  content: "";
  position: absolute;
  inset: 11px;
  border: 1px dashed #bec4b5;
  border-radius: 2px;
}

#fabric-picker[data-hp-enhanced] .has-selection .hp-picker-summary-swatch::before { display: none; }
#fabric-picker[data-hp-enhanced] .hp-picker-summary-swatch img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 3px;
  object-fit: cover;
}

#fabric-picker[data-hp-enhanced] .hp-picker-summary-copy { min-width: 0; }
#fabric-picker[data-hp-enhanced] .hp-picker-summary-label {
  display: block;
  margin-bottom: 2px;
  color: var(--hp-muted);
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: .04em;
}

#fabric-picker[data-hp-enhanced] .hp-picker-summary strong {
  display: block;
  color: var(--hp-ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

#fabric-picker[data-hp-enhanced] .hp-picker-done {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  min-height: 46px;
  margin: 0;
  padding: 10px 22px;
  border: 1px solid var(--hp-ink);
  border-radius: 7px;
  background: var(--hp-ink);
  color: #fffefa;
  font: 500 14px/1.5 "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: .05em;
  box-shadow: 0 2px 3px #20291b08;
  touch-action: manipulation;
}

#fabric-picker[data-hp-enhanced] :is(button, input, select):focus-visible {
  outline: 2px solid #68735a;
  outline-offset: 3px;
}

@media (hover: hover) {
  #fabric-picker[data-hp-enhanced] .fabric:hover { border-color: #b7bfaa; }
  #fabric-picker[data-hp-enhanced] .hp-picker-done:hover:not(:disabled) { background: #454e3f; }
  #fabric-picker[data-hp-enhanced] #close-fabric:hover { background: var(--hp-surface); color: var(--hp-ink); }
  #fabric-picker[data-hp-enhanced] #reset:hover { text-decoration: underline; }
}

@media (prefers-reduced-motion: no-preference) {
  #fabric-picker[data-hp-enhanced] :is(.fabric, .hp-picker-done, #close-fabric) {
    transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
  }
}

@media (max-width: 760px) {
  #fabric-picker[data-hp-enhanced] {
    width: calc(100vw - 24px);
    height: calc(100dvh - 28px);
    max-height: calc(100dvh - 28px);
    border-radius: 15px !important;
  }
  #fabric-picker[data-hp-enhanced] .fabric-picker-head { padding: 17px 17px 14px; }
  #fabric-picker[data-hp-enhanced] .fabric-picker-head h2 { font-size: 19px; }
  #fabric-picker[data-hp-enhanced] .fabrics { padding: 14px 16px 0 !important; }
  #fabric-picker[data-hp-enhanced] .catalog-search-row { min-height: 44px; }
  #fabric-picker[data-hp-enhanced] .catalog-search-toggle { min-width: 42px; min-height: 44px; }
  #fabric-picker[data-hp-enhanced] .catalog-search-field input { width: 100%; font-size: 16px; }
  #fabric-picker[data-hp-enhanced] :is(input[type="search"], select) { font-size: 16px; }
  #fabric-picker[data-hp-enhanced] input[type="search"]::placeholder { font-size: 12px; }
  #fabric-picker[data-hp-enhanced] .filters { grid-template-columns: 1fr; gap: 8px; margin-top: 10px; }
  #fabric-picker[data-hp-enhanced] .filters > label:first-child { gap: 10px; }
  #fabric-picker[data-hp-enhanced] .filters > label:last-child { font-size: 0; }
  #fabric-picker[data-hp-enhanced] .filters select { min-height: 40px; }
  #fabric-picker[data-hp-enhanced] .tryon-color-chips {
    flex-wrap: nowrap;
    margin-top: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  #fabric-picker[data-hp-enhanced] .tryon-color-chips button { flex: none; min-height: 34px; padding: 6px 9px; }
  #fabric-picker[data-hp-enhanced] .results-line { margin: 5px 0; font-size: 10px; }
  #fabric-picker[data-hp-enhanced] #fabric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
  #fabric-picker[data-hp-enhanced] .fabric .tryon-fabric-title > span { font-size: 14px; }
  #fabric-picker[data-hp-enhanced] .hp-picker-footer { gap: 12px; padding: 13px 16px calc(13px + env(safe-area-inset-bottom)); }
  #fabric-picker[data-hp-enhanced] .hp-picker-done { min-width: 101px; min-height: 46px; padding-inline: 18px; }
}

@media (max-width: 360px) {
  #fabric-picker[data-hp-enhanced] .fabrics { padding-inline: 12px !important; }
  #fabric-picker[data-hp-enhanced] #fabric-grid { column-gap: 10px; }
  #fabric-picker[data-hp-enhanced] .hp-picker-footer { padding-inline: 13px; }
  #fabric-picker[data-hp-enhanced] .hp-picker-summary { gap: 8px; }
  #fabric-picker[data-hp-enhanced] .hp-picker-done { min-width: 84px; padding-inline: 14px; }
}

@media (max-height: 540px) and (orientation: landscape) {
  #fabric-picker[data-hp-enhanced] .fabric-picker-head { padding-block: 10px; }
  #fabric-picker[data-hp-enhanced] .fabrics { padding-top: 10px !important; }
  #fabric-picker[data-hp-enhanced] .hp-picker-footer { padding-block: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  #fabric-picker[data-hp-enhanced],
  #fabric-picker[data-hp-enhanced] *,
  #fabric-picker[data-hp-enhanced]::backdrop {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Revision 3: keep real search/select controls inside their mobile panel. */
#fabric-picker[data-hp-enhanced] .catalog-search-row,
#fabric-picker[data-hp-enhanced] .filters {
  flex-shrink: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}
#fabric-picker[data-hp-enhanced] .catalog-search {
  display: flex !important;
  align-items: center;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 44px !important;
  min-height: 44px !important;
  padding: 0 !important;
  border: 1px solid #dedad3 !important;
  border-radius: 7px !important;
  background: #fffefa !important;
  box-shadow: none !important;
  overflow: hidden;
}
#fabric-picker[data-hp-enhanced] .catalog-search-toggle {
  flex: 0 0 42px !important;
  width: 42px;
  min-width: 42px !important;
  height: 42px !important;
  min-height: 42px !important;
  margin: 0;
  border: 0 !important;
  background: transparent !important;
}
#fabric-picker[data-hp-enhanced] .catalog-search-field {
  flex: 1 1 0%;
  min-width: 0;
  height: 42px !important;
  min-height: 42px !important;
  margin: 0;
  padding: 0;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}
#fabric-picker[data-hp-enhanced] .catalog-search-field #search {
  box-sizing: border-box;
  display: block;
  width: 100% !important;
  max-width: 100%;
  height: 42px !important;
  min-height: 42px !important;
  margin: 0;
  padding: 8px 10px !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #56504a !important;
  font-size: 16px !important;
  line-height: 24px !important;
}
#fabric-picker[data-hp-enhanced] .catalog-search:focus-within {
  border-color: #8a7664 !important;
  box-shadow: 0 0 0 2px #8a76641a !important;
}
#fabric-picker[data-hp-enhanced] .catalog-search-field #search:focus-visible {
  outline: none !important; /* The complete parent control carries the focus ring. */
}
@media (max-width: 760px) {
  #fabric-picker[data-hp-enhanced] .filters {
    grid-template-columns: minmax(0, 1fr);
  }
  #fabric-picker[data-hp-enhanced] .filters > label {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  #fabric-picker[data-hp-enhanced] .filters > label:first-child {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }
  #fabric-picker[data-hp-enhanced] .filters #series {
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0;
    max-width: 100%;
    height: 46px !important;
    min-height: 46px !important;
    margin: 0;
    padding: 8px 12px !important;
    border: 1px solid #dedad3 !important;
    border-radius: 7px !important;
    background: #fffefa !important;
    color: #56504a !important;
    font-size: 16px !important;
    line-height: 24px !important;
    appearance: auto !important;
  }
  #fabric-picker[data-hp-enhanced] .tryon-color-chips { min-width: 0; max-width: 100%; }
}
