/*
Below is a companion CSS file adjusted for the new UX and accessibility improvements.
Save as: meili-search.refactor.css
*/

/* ===== meili-search.refactor.css ===== */

/* base input remains same - keep your theme styles if you like */
#meili-search-input {
  position: relative;
  z-index: 10;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  width: 100%;
  max-width: 420px;
}

/* container states */
#meili-search-results {
  display: none;
}
#meili-search-results.meili-open {
  display: block;
}
#meili-search-results.meili-mobile {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  z-index: 99999;
  overflow: hidden;
}

.meili-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.36);
  z-index: 99998;
  opacity: 0;
  transition: opacity 200ms ease;
}

.meili-results-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: auto;
  width: 100%; /* match input width */
  background: #fff;
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(11, 23, 39, 0.08);
  margin-top: 8px;
  padding: 8px;
  max-height: 420px;
  overflow: auto;
  z-index: 99999;
}

.meili-search-box {
  position: relative;
  display: inline-block; /* keeps wrapper shrink-to-fit the input */
  width: 100%; /* optional, if you want full-width input */
  max-width: 420px; /* matches your input max width */
}

/* In mobile state, list becomes fullscreen scrollable area (below sticky header) */
#meili-search-results.meili-mobile .meili-results-list {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  max-height: calc(100% - 56px);
  border-radius: 0;
  box-shadow: none;
  border: none;
  padding: 0;
}

.meili-result-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 8px;
  border-bottom: 1px solid #f3f3f3;
  outline: none;
}
.meili-result-item:last-child {
  border-bottom: none;
}

.meili-result-item:focus,
.meili-result-item[tabindex="0"]:focus {
  box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.12);
  background: #fbfbfe;
}

.meili-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  flex: 0 0 64px;
  background: #fafafa;
}

.meili-meta {
  flex: 1;
  min-width: 0;
}
.meili-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meili-price {
  font-size: 13px;
  color: #1a7f37;
  margin-bottom: 8px;
}

.meili-add-container {
  margin-bottom: 6px;
}
.meili-add-btn {
  display: inline-block;
  background: #0073aa;
  color: #fff;
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.meili-add-btn[disabled],
.meili-add-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.meili-cart-info {
  font-size: 12px;
  color: #666;
}
.meili-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.meili-view-link {
  font-size: 13px;
  color: #0073aa;
  text-decoration: none;
}

/* skeleton loading */
.meili-skeleton .skeleton {
  background: linear-gradient(90deg, #f2f2f2 25%, #e9e9e9 37%, #f2f2f2 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s linear infinite;
}
.s-line {
  height: 12px;
  border-radius: 6px;
  margin-bottom: 8px;
}
.s-title {
  width: 70%;
  height: 16px;
}
.s-price {
  width: 40%;
}
.s-btn {
  width: 110px;
  height: 32px;
}
@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.meili-added {
  animation: meiliAdded 700ms ease;
}
@keyframes meiliAdded {
  0% {
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.2);
  }
  100% {
    box-shadow: 0 0 0 6px rgba(46, 204, 113, 0);
  }
}

/* mobile overlay header */
.meili-overlay-header {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  background: #fff;
  padding: 10px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 999999;
}
.meili-overlay-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 15px;
}
.meili-overlay-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #333;
}

/* responsive adjustments */
@media (max-width: 600px) {
  .meili-thumb {
    width: 56px;
    height: 56px;
  }
  .meili-result-item {
    padding: 12px;
  }
}

/* focus-visible for keyboard users */
.meili-result-item:focus:not(:focus-visible) {
  box-shadow: none;
}

/* small helper for the no-results message */
.no-results {
  padding: 16px;
  text-align: center;
  color: #666;
}
