/* ═══════════════════════════════════════════
   BuJoBox Smart Search Widget
   ═══════════════════════════════════════════ */

:root {
  --bbx-accent: #92D1D9;
  --bbx-accent-dark: #5bb8c4;
  --bbx-accent-bg: #F6FBFC;
  --bbx-accent-mid: #D9ECF2;
  --bbx-text: #1a1a2e;
  --bbx-text-muted: #6b7280;
  --bbx-text-hint: #9ca3af;
  --bbx-border: #e5e7eb;
  --bbx-bg: #ffffff;
  --bbx-bg-hover: #f9fafb;
  --bbx-shadow: 0 8px 48px rgba(0,0,0,0.14), 0 2px 12px rgba(0,0,0,0.06);
  --bbx-radius: 14px;
  --bbx-radius-sm: 8px;
  --bbx-tr: 150ms ease;
}

/* ─── OVERLAY ─────────────────────────────── */
.bbx-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 50px 16px 16px;
  box-sizing: border-box;
}
.bbx-overlay.active { display: flex; }

.bbx-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,15,30,0.4);
  backdrop-filter: blur(3px);
  animation: bbxFadeIn 180ms ease forwards;
}
@keyframes bbxFadeIn { from{opacity:0} to{opacity:1} }

/* ─── BOX ─────────────────────────────────── */
.bbx-box {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1420px;
  background: var(--bbx-bg);
  border-radius: var(--bbx-radius);
  box-shadow: var(--bbx-shadow);
  overflow: hidden;
  animation: bbxSlideIn 200ms cubic-bezier(0.34,1.2,0.64,1) forwards;
  max-height: calc(100vh - 70px);
  display: flex;
  flex-direction: column;
}
@keyframes bbxSlideIn {
  from { opacity:0; transform:translateY(-10px) scale(0.98); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}

/* ─── HEADER ──────────────────────────────── */
.bbx-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--bbx-border);
  flex-shrink: 0;
}
.bbx-icon-search { color: var(--bbx-text-muted); flex-shrink: 0; display: flex; }

.bbx-input-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  height: 28px;
  display: flex;
  align-items: center;
}
.bbx-input {
  position: absolute;
  inset: 0;
  width: 100%;
  font-size: 17px;
  font-family: inherit;
  color: var(--bbx-text);
  border: none;
  outline: none;
  background: transparent;
  z-index: 1;
}
.bbx-input::placeholder { color: var(--bbx-text-hint); }

/* Ghost autocomplete — показує тільки суфікс після курсора */
.bbx-ghost {
  position: absolute;
  top: 0; bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  font-size: 17px;
  font-family: inherit;
  pointer-events: none;
  white-space: pre;
  overflow: hidden;
  z-index: 0;
  color: var(--bbx-text-hint);
  /* padding-left виставляється динамічно через JS (ширина введеного тексту) */
}

.bbx-btn-clear,
.bbx-btn-close {
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--bbx-radius-sm);
  transition: background var(--bbx-tr);
  flex-shrink: 0;
}
.bbx-btn-clear { color: var(--bbx-text-muted); padding: 6px; }
.bbx-btn-clear:hover { background: var(--bbx-bg-hover); }
.bbx-btn-close { font-size: 13px; color: var(--bbx-text-muted); border: 1px solid var(--bbx-border); }
.bbx-btn-close:hover { background: var(--bbx-bg-hover); }
.bbx-btn-close kbd {
  font-size: 10px; background: var(--bbx-bg-hover);
  border: 1px solid var(--bbx-border); border-radius: 4px;
  padding: 1px 5px; font-family: inherit;
}

/* ─── PROGRESS ────────────────────────────── */
.bbx-progress { height: 2px; background: transparent; flex-shrink: 0; }
.bbx-progress--active {
  background: linear-gradient(90deg, transparent, var(--bbx-accent) 50%, transparent);
  background-size: 200% 100%;
  animation: bbxProgress 900ms linear infinite;
}
@keyframes bbxProgress { from{background-position:200% 0} to{background-position:-200% 0} }

/* ─── BODY ────────────────────────────────── */
.bbx-body { overflow-y: auto; overscroll-behavior: contain; flex: 1; background: var(--bbx-accent-bg); }

/* ─── RESULTS WRAP ────────────────────────── */
.bbx-results-wrap { padding: 16px 20px 0; }

/* ─── CATEGORY PILLS ──────────────────────── */
.bbx-cats-row {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px;
}
.bbx-cat-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--bbx-border);
  border-radius: 20px;
  background: var(--bbx-bg);
  cursor: pointer; font-size: 13px;
  color: var(--bbx-text-muted);
  font-family: inherit;
  transition: border-color var(--bbx-tr), background var(--bbx-tr), color var(--bbx-tr);
  white-space: nowrap;
}
.bbx-cat-pill:hover { border-color: var(--bbx-accent-dark); color: var(--bbx-accent-dark); }
.bbx-cat-pill--active {
  border-color: var(--bbx-accent-dark);
  background: var(--bbx-accent-mid);
  color: var(--bbx-accent-dark);
  font-weight: 500;
}
.bbx-cnt {
  font-size: 11px; background: rgba(0,0,0,0.06);
  padding: 1px 6px; border-radius: 10px; min-width: 20px; text-align: center;
}
.bbx-cat-pill--active .bbx-cnt { background: rgba(146,209,217,0.3); }

/* ─── 3-COLUMN GRID ───────────────────────── */
.bbx-cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
}
.bbx-col {
  padding: 0 20px 20px 0;
  border-right: 1px solid var(--bbx-border);
  min-width: 0;
  background: var(--bbx-bg);
  margin-right: 1px;
}
.bbx-col:last-child,
.bbx-col:nth-child(3n) { border-right: none; padding-right: 0; margin-right: 0; }
.bbx-col:nth-child(n+2) { padding-left: 20px; }
.bbx-col:nth-child(3n+1) { padding-left: 0; }

/* Column title */
.bbx-col-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--bbx-text-muted);
  margin-bottom: 10px; padding: 12px 0 8px;
  border-bottom: 1px solid var(--bbx-border);
  text-decoration: none;
}
a.bbx-col-title--link { color: var(--bbx-text-muted); transition: color var(--bbx-tr); }
a.bbx-col-title--link svg { opacity: 0; transition: opacity var(--bbx-tr); flex-shrink: 0; }
a.bbx-col-title--link:hover { color: var(--bbx-accent-dark); }
a.bbx-col-title--link:hover svg { opacity: 1; }

/* ─── ITEM ────────────────────────────────── */
.bbx-col-items { display: flex; flex-direction: column; gap: 1px; }

.bbx-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; text-decoration: none; color: inherit;
  border-radius: var(--bbx-radius-sm);
  transition: background var(--bbx-tr);
}
.bbx-item:hover, .bbx-item--active { background: var(--bbx-accent-bg); }

.bbx-item-img {
  position: relative; width: 60px; height: 60px;
  flex-shrink: 0; border-radius: 6px; background: #f5f5f5;
  /* overflow: hidden перенесено на img щоб ::after міг виходити за межі */
}
.bbx-item-img img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  border-radius: 6px;
  transition: transform 200ms ease;
}

/* Icon badge — top left */
.bbx-icon-badge {
  position: absolute; top: 3px; left: 3px;
  font-size: 9px; font-weight: 700;
  padding: 2px 5px; border-radius: 3px;
  line-height: 1.2; z-index: 2; white-space: nowrap;
}

/* Discount badge — bottom left */
.bbx-discount-badge {
  position: absolute; bottom: 3px; left: 3px;
  font-size: 9px; font-weight: 700;
  background: #ff3b49; color: #fff;
  padding: 2px 5px; border-radius: 3px;
  line-height: 1.2; z-index: 2;
}

.bbx-item-meta { flex: 1; min-width: 0; }
.bbx-item-sku {
  font-size: 10px;
  color: var(--bbx-text-hint);
  letter-spacing: .02em;
  margin-bottom: 1px;
  line-height: 1.2;
}
.bbx-item-name {
  font-size: 13px; line-height: 1.35; color: var(--bbx-text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-bottom: 3px;
}
.bbx-item-name mark { background: none; color: var(--bbx-accent-dark); font-weight: 600; }
.bbx-item-prices { display: flex; align-items: baseline; gap: 5px; }
.bbx-price-old { font-size: 11px; color: var(--bbx-text-hint); text-decoration: line-through; }
.bbx-price { font-size: 13px; font-weight: 600; color: var(--bbx-text); }
.bbx-price--sale { color: #ff3b49; }
.bbx-oos { font-size: 11px; color: var(--bbx-text-hint); margin-top: 2px; }
.bbx-oos-inline {
  font-size: 11px;
  color: var(--bbx-text-hint);
  white-space: nowrap;
}
.bbx-oos-inline::before { content: "/ "; }

/* ─── MORE LINK ───────────────────────────── */
.bbx-more-link {
  display: inline-block; margin-top: 8px; margin-left: 8px;
  font-size: 12px; color: var(--bbx-accent-dark);
  background: none; border: none; cursor: pointer;
  font-family: inherit; padding: 0;
  transition: color var(--bbx-tr), text-decoration var(--bbx-tr);
}
.bbx-more-link:hover { text-decoration: underline; }

/* ─── FOOTER BAR ──────────────────────────── */
.bbx-footer-bar {
  padding: 12px 0 16px;
  border-top: 1px solid var(--bbx-border);
  margin-top: 12px;
  background: var(--bbx-accent-bg);
}
.bbx-view-all {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 11px;
  border: 1.5px solid var(--bbx-accent-mid);
  border-radius: var(--bbx-radius-sm);
  background: var(--bbx-bg);
  cursor: pointer; font-size: 14px; font-weight: 500;
  color: var(--bbx-text); font-family: inherit;
  transition: border-color var(--bbx-tr), background var(--bbx-tr), color var(--bbx-tr);
}
.bbx-view-all:hover {
  border-color: var(--bbx-accent-dark);
  background: var(--bbx-accent-mid);
  color: var(--bbx-accent-dark);
}

/* ─── EXPANDED CATEGORY ───────────────────── */
.bbx-expanded-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 1px solid var(--bbx-border);
}
.bbx-back-btn {
  display: flex; align-items: center; gap: 4px;
  background: none; border: 1px solid var(--bbx-border);
  border-radius: 20px; padding: 5px 12px;
  font-size: 13px; color: var(--bbx-text-muted);
  cursor: pointer; font-family: inherit;
  transition: border-color var(--bbx-tr), color var(--bbx-tr);
}
.bbx-back-btn:hover { border-color: var(--bbx-accent-dark); color: var(--bbx-accent-dark); }
.bbx-expanded-title {
  font-size: 15px; font-weight: 600; color: var(--bbx-text);
  display: flex; align-items: center; gap: 8px; flex: 1;
}
.bbx-cat-link-btn {
  font-size: 13px; color: var(--bbx-accent-dark);
  text-decoration: none; margin-left: auto;
  transition: text-decoration var(--bbx-tr);
}
.bbx-cat-link-btn:hover { text-decoration: underline; }

/* Назва розгорнутої категорії як посилання на розділ */
a.bbx-expanded-title--link {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  font-weight: 600;
  color: var(--bbx-text);
  text-decoration: none;
  transition: color var(--bbx-tr);
}
a.bbx-expanded-title--	 svg {
  color: var(--bbx-text-muted);
  opacity: 0;
  transition: opacity var(--bbx-tr), color var(--bbx-tr);
  flex-shrink: 0;
}
a.bbx-expanded-title--link:hover { color: var(--bbx-accent-dark); }
a.bbx-expanded-title--link:hover svg { opacity: 1; color: var(--bbx-accent-dark); }

.bbx-expanded-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
}
.bbx-expanded-grid .bbx-item {
  border-bottom: 1px solid var(--bbx-border);
}

/* ─── PAGINATION ──────────────────────────── */
.bbx-pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; padding: 16px 0 8px;
}
.bbx-page-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px solid var(--bbx-accent-mid);
  background: var(--bbx-bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--bbx-accent-dark);
  transition: background var(--bbx-tr), border-color var(--bbx-tr);
}
.bbx-page-btn:hover:not(:disabled) { background: var(--bbx-accent-mid); }
.bbx-page-btn:disabled { opacity: 0.35; cursor: default; }
.bbx-page-info { font-size: 13px; color: var(--bbx-text-muted); min-width: 60px; text-align: center; }

/* ─── HISTORY PANEL ───────────────────────── */
.bbx-history-panel { padding: 20px 24px; background: var(--bbx-bg); }
.bbx-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.bbx-panel-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--bbx-text-hint);
}
.bbx-panel-action {
  font-size: 12px; color: var(--bbx-accent-dark);
  background: none; border: none; cursor: pointer;
  font-family: inherit; padding: 4px 8px;
  border-radius: 6px; transition: background var(--bbx-tr);
}
.bbx-panel-action:hover { background: var(--bbx-accent-mid); }
.bbx-hist-list { display: flex; flex-wrap: wrap; gap: 8px; }
.bbx-hist-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--bbx-border);
  border-radius: 40px; background: none; cursor: pointer;
  font-size: 13px; color: var(--bbx-text); font-family: inherit;
  transition: border-color var(--bbx-tr), background var(--bbx-tr), color var(--bbx-tr);
}
.bbx-hist-item svg { color: var(--bbx-text-hint); }
.bbx-hist-arrow { margin-left: 2px; opacity: 0; transition: opacity var(--bbx-tr); }
.bbx-hist-item:hover { border-color: var(--bbx-accent-dark); background: var(--bbx-accent-mid); color: var(--bbx-accent-dark); }
.bbx-hist-item:hover .bbx-hist-arrow { opacity: 1; }
.bbx-hist-item:hover svg { color: var(--bbx-accent-dark); }

/* ─── EMPTY / ERROR ───────────────────────── */
.bbx-empty-state, .bbx-error {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 24px; text-align: center;
  color: var(--bbx-text-muted); gap: 12px;
  background: var(--bbx-bg);
}
.bbx-empty-state svg, .bbx-error svg { color: var(--bbx-text-hint); }
.bbx-empty-state p, .bbx-error p { margin: 0; font-size: 15px; color: var(--bbx-text); }
.bbx-empty-state span { font-size: 13px; color: var(--bbx-text-hint); }

/* ─── MOBILE ──────────────────────────────── */
@media (max-width: 900px) {
  .bbx-overlay { padding: 0; align-items: flex-start; }
  .bbx-box { border-radius: 0 0 var(--bbx-radius) var(--bbx-radius); max-height: 85vh; width: 100%; }

  /* Ghost не потрібен на мобільному — клавіатура займає пів екрану */
  .bbx-ghost { display: none; }

  .bbx-cols, .bbx-expanded-grid {
    grid-template-columns: 1fr;
  }
  .bbx-col { border-right: none; padding: 0 0 12px 0 !important; border-bottom: 1px solid var(--bbx-border); }
  .bbx-col:last-child { border-bottom: none; }

  .bbx-cats-row { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; scrollbar-width: none; }
  .bbx-cats-row::-webkit-scrollbar { display: none; }
  .bbx-results-wrap { padding: 12px 16px 0; }
  .bbx-btn-close { font-size: 0; padding: 8px; }
  .bbx-btn-close kbd { display: none; }
  .bbx-item-img { width: 50px; height: 50px; }
}

@media (min-width: 901px) and (max-width: 1200px) {
  .bbx-cols { grid-template-columns: repeat(2, 1fr); }
  .bbx-expanded-grid { grid-template-columns: repeat(2, 1fr); }
  .bbx-col:nth-child(2n) { border-right: none; padding-right: 0; }
  .bbx-col:nth-child(2n+1) { padding-left: 0; }
  .bbx-col:nth-child(2n) { padding-left: 20px; }
  .bbx-col:nth-child(3n) { border-right: 1px solid var(--bbx-border); }
  .bbx-col:nth-child(2n):last-child,
  .bbx-col:nth-child(3n):nth-child(2n) { border-right: none; }
}

/* ─── EXACT ARTICLE MATCH ────────────────────────────────── */
.bbx-exact-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--bbx-text-hint);
  margin-bottom: 8px;
}
.bbx-exact-item .bbx-item {
  padding: 12px 8px;
}
.bbx-exact-item .bbx-item-img {
  width: 80px;
  height: 80px;
}
.bbx-exact-item .bbx-item-name {
  font-size: 14px;
}

/* ─── ZOOM TOOLTIP ────────────────────────────────────────
   Збільшене зображення при hover на мініатюру товару.
   Тільки десктоп — JS перевіряє matchMedia (hover: hover). */
.bbx-zoom-tip {
  display: none;
  position: fixed;
  z-index: 9999999;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 12px 40px rgba(0,0,0,0.22), 0 2px 8px rgba(0,0,0,0.10);
  pointer-events: none;
  animation: bbxZoomIn 150ms ease forwards;
}
@keyframes bbxZoomIn {
  from { opacity: 0; transform: scale(0.88); }
  to   { opacity: 1; transform: scale(1); }
}
