.tr-ai-search-widget {
  --tr-gold: #ddbb68;
  --tr-gold-dark: #b89646;
  --tr-ink: #1a1a1a;
  max-width: 100%;
  margin: 0 0 32px;
  padding: 28px clamp(16px, 4vw, 40px);
  font-family: inherit;
  box-sizing: border-box;
  background: linear-gradient(180deg, #fbfaf7 0%, #f6f4ee 100%);
  border-top: 1px solid #e7e0cf;
  border-bottom: 1px solid #e7e0cf;
  text-align: center;
}
.tr-ai-search-widget * { box-sizing: border-box; }

/* Force-hide anything marked [hidden] regardless of the theme's own resets — some
   themes give form controls (esp. input[type=file]) an explicit `display` that beats
   the browser's default `[hidden] { display: none }`, leaving the native file picker
   and the empty photo-preview row visibly stuck open. */
.tr-ai-search-widget [hidden] { display: none !important; }

/* Desktop: trigger/backdrop/close are drawer-only chrome, hidden here; panel is just
   a plain wrapper around the same inline content as before. */
.tr-ai-search__trigger,
.tr-ai-search__backdrop,
.tr-ai-search__close { display: none; }

body.tr-ai-search-body-lock { overflow: hidden; }

.tr-ai-search__label {
  display: block;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--tr-gold-dark);
  margin-bottom: 10px;
  font-weight: 600;
}

.tr-ai-search-widget.tr-ai-search--loading .tr-ai-search__form {
  opacity: .6;
  pointer-events: none;
}

.tr-ai-search__spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #e2d6b3;
  border-top-color: var(--tr-gold-dark);
  border-radius: 50%;
  vertical-align: -2px;
  animation: tr-ai-search-spin .7s linear infinite;
}
@keyframes tr-ai-search-spin {
  to { transform: rotate(360deg); }
}

.tr-ai-search__form {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
  text-align: left;
}

/* height/padding/box-sizing/margin are !important on all three controls below
   (input, photo-btn, submit) — this theme's own form-control CSS overrides plain
   padding/line-height-driven sizing with enough specificity that the three ended up
   visibly different heights (measured live: 37px / 48px / 37px). A fixed, forced
   height is the only sizing that survives that. */
.tr-ai-search__input {
  flex: 1 1 auto;
  height: 48px !important;
  padding: 0 22px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  font-size: 16px;
  border: 1px solid #ddd6c2;
  border-radius: 999px;
  background: #fff;
  min-width: 0;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.tr-ai-search__input:focus {
  outline: none;
  border-color: var(--tr-gold);
  box-shadow: 0 0 0 3px rgba(221, 187, 104, .18);
}
.tr-ai-search__input::placeholder { color: #a9a291; }

.tr-ai-search__photo-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px !important;
  height: 48px !important;
  padding: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  background: #fff;
  color: var(--tr-ink);
  border: 1px solid #ddd6c2;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease;
}
.tr-ai-search__photo-btn:hover { border-color: var(--tr-gold); background: #fbfaf7; }
/* !important because this theme's own CSS resets sometimes give SVG icons a default
   fill/width/height that beats our own rules (seen live: width computed to 0, making
   the icon invisible even though its stroke color was correct) — same class of bug
   as the [hidden] override above. Pin the full box on the svg itself. */
.tr-ai-search__photo-btn svg {
  display: block !important;
  width: 20px !important;
  height: 20px !important;
  fill: none !important;
  stroke: var(--tr-ink) !important;
}

.tr-ai-search__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.tr-ai-search__photo-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 720px;
  margin: 10px auto 0;
}
.tr-ai-search__photo-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e7e0cf;
}
.tr-ai-search__photo-remove {
  font-size: 12px;
  background: none;
  border: none;
  color: #8a8370;
  cursor: pointer;
  padding: 0;
  border-bottom: 1px solid currentColor;
}

.tr-ai-search__submit {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px !important;
  padding: 0 28px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  font-size: 14px;
  text-align: center;
  text-transform: uppercase;
  background: var(--tr-ink);
  color: #fff;
  border: 1px solid var(--tr-ink);
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}
.tr-ai-search__submit:hover:not(:disabled) {
  background: var(--tr-gold-dark);
  border-color: var(--tr-gold-dark);
}
.tr-ai-search__submit:disabled { opacity: .5; cursor: default; }

.tr-ai-search__hint {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: #8a8370;
}

.tr-ai-search__recognized { margin-top: 14px; font-size: 13px; color: #8a8370; }
.tr-ai-search__tag {
  display: inline-block;
  background: #fff;
  border: 1px solid #e7e0cf;
  border-radius: 2px;
  padding: 3px 10px;
  margin: 2px 4px 2px 0;
  color: #5c5648;
}

.tr-ai-search__notice {
  max-width: 720px;
  margin: 16px auto 0;
  padding: 12px 16px;
  background: #fff;
  border-left: 3px solid var(--tr-gold);
  font-size: 14px;
  color: #6b5a1e;
  text-align: left;
}

.tr-ai-search__status { margin-top: 16px; font-size: 14px; color: #8a8370; }

.tr-ai-search__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 24px 20px;
  max-width: 1240px;
  margin: 24px auto 0;
  text-align: left;
}

.tr-ai-search__card {
  display: flex;
  flex-direction: column;
}
.tr-ai-search__card-link { color: inherit; text-decoration: none; display: block; }
.tr-ai-search__card-img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #f0ede4;
  transition: opacity .25s ease;
}
.tr-ai-search__card-link:hover .tr-ai-search__card-img { opacity: .85; }
.tr-ai-search__card-title {
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.4;
  letter-spacing: .01em;
  color: var(--tr-ink);
}
.tr-ai-search__card-price {
  margin-top: 5px;
  font-size: 14px;
  font-weight: 600;
  color: var(--tr-gold-dark);
}
.tr-ai-search__card-sizes { margin-top: 5px; font-size: 12px; color: #8a8370; }

.tr-ai-search__explain-btn {
  margin-top: 8px;
  align-self: flex-start;
  font-size: 12px;
  background: none;
  border: none;
  color: var(--tr-gold-dark);
  cursor: pointer;
  padding: 0;
  border-bottom: 1px solid currentColor;
}
.tr-ai-search__explain-text {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: #6b654f;
  font-style: italic;
}

@media (max-width: 640px) {
  /* Compact trigger pill replaces the inline form; tapping it opens a full-screen drawer
     instead of the form living permanently in the page flow. */
  .tr-ai-search-widget {
    padding: 16px;
    text-align: left;
  }
  .tr-ai-search__trigger {
    display: block;
    width: 100%;
    padding: 14px 18px;
    font-size: 15px;
    text-align: left;
    background: #fff;
    border: 1px solid var(--tr-gold);
    border-radius: 999px;
    color: var(--tr-ink);
    cursor: pointer;
  }
  .tr-ai-search__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 8, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    z-index: 9998;
  }
  .tr-ai-search__panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    max-height: 88vh;
    max-height: 88dvh; /* dvh tracks the keyboard-shrunk viewport on modern mobile browsers; vh above is the fallback */
    overflow-y: auto;
    background: #fbfaf7;
    border-radius: 16px 16px 0 0;
    padding: 20px 16px 28px;
    transform: translateY(100%);
    transition: transform .3s ease;
    z-index: 9999;
    text-align: center;
  }
  .tr-ai-search--open .tr-ai-search__backdrop { opacity: 1; pointer-events: auto; }
  .tr-ai-search--open .tr-ai-search__panel { transform: translateY(0); }

  .tr-ai-search__close {
    display: block;
    position: absolute;
    top: 12px; right: 14px;
    width: 32px; height: 32px;
    border: none;
    background: #f0ede4;
    border-radius: 50%;
    font-size: 15px;
    color: #5c5648;
    cursor: pointer;
  }

  .tr-ai-search__form { flex-direction: column; align-items: stretch; }
  .tr-ai-search__actions .tr-ai-search__submit { flex: 1 1 auto; }
  .tr-ai-search__grid { grid-template-columns: repeat(2, 1fr); gap: 16px 12px; }
}
