/*
 * WC AJAX Live Search — modern rounded UI
 * Author: Oleg Gerasimenko — https://t.me/oleggerasimenko
 */

.wcals-wrap {
  --wcals-bg: #ffffff;
  --wcals-bg-soft: #f6f6f3;
  --wcals-text: #171717;
  --wcals-muted: #777773;
  --wcals-border: #e8e8e3;
  --wcals-accent: #171717;
  --wcals-accent-contrast: #ffffff;
  --wcals-focus: rgba(23, 23, 23, 0.1);
  --wcals-shadow: 0 24px 70px rgba(15, 15, 15, 0.16);
  --wcals-radius-xl: 24px;
  --wcals-radius-lg: 18px;
  --wcals-radius-md: 14px;

  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 760px;
  color: var(--wcals-text);
  font: inherit;
}

[data-bs-theme="dark"] .wcals-wrap,
.dark .wcals-wrap,
body.dark-mode .wcals-wrap {
  --wcals-bg: #1d1d1b;
  --wcals-bg-soft: #292927;
  --wcals-text: #f6f6f3;
  --wcals-muted: #aaa9a3;
  --wcals-border: #393936;
  --wcals-accent: #f6f6f3;
  --wcals-accent-contrast: #171717;
  --wcals-focus: rgba(255, 255, 255, 0.1);
  --wcals-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.wcals-field {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 62px;
  border: 1px solid var(--wcals-border);
  border-radius: 20px;
  background: var(--wcals-bg-soft);
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.wcals-wrap:focus-within .wcals-field {
  border-color: var(--wcals-accent);
  background: var(--wcals-bg);
  box-shadow: 0 0 0 5px var(--wcals-focus);
}

.wcals-field-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  display: inline-flex;
  width: 22px;
  height: 22px;
  color: var(--wcals-text);
  transform: translateY(-50%);
  pointer-events: none;
}

.wcals-field-icon svg,
.wcals-clear svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wcals-input {
  width: 100%;
  min-width: 0;
  height: 60px;
  margin: 0;
  padding: 0 92px 0 56px;
  border: 0 !important;
  outline: 0 !important;
  border-radius: inherit;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--wcals-text) !important;
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  appearance: none;
  -webkit-appearance: none;
}

.wcals-input::-webkit-search-cancel-button,
.wcals-input::-webkit-search-decoration {
  display: none;
  -webkit-appearance: none;
}

.wcals-input::placeholder {
  color: var(--wcals-muted);
  opacity: 1;
}

.wcals-clear {
  position: absolute;
  right: 14px;
  top: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--wcals-bg);
  color: var(--wcals-muted);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  transform: translateY(-50%);
  cursor: pointer;
  transition: color 0.18s ease, background-color 0.18s ease, transform 0.18s ease;
}

.wcals-clear:hover,
.wcals-clear:focus-visible {
  color: var(--wcals-text);
  transform: translateY(-50%) scale(1.04);
}

.wcals-clear[hidden] {
  display: none !important;
}

.wcals-loader {
  position: absolute;
  right: 24px;
  top: 50%;
  display: none;
  width: 20px;
  height: 20px;
  margin-top: -10px;
  border: 2px solid var(--wcals-border);
  border-top-color: var(--wcals-text);
  border-radius: 50%;
  animation: wcals-spin 0.75s linear infinite;
}

.wcals-wrap.is-loading .wcals-loader {
  display: block;
}

.wcals-wrap.is-loading .wcals-clear {
  display: none !important;
}

@keyframes wcals-spin {
  to { transform: rotate(360deg); }
}

.wcals-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  right: 0;
  z-index: 10060;
  padding: 8px;
  border: 1px solid var(--wcals-border);
  border-radius: var(--wcals-radius-xl);
  background: var(--wcals-bg);
  color: var(--wcals-text);
  box-shadow: var(--wcals-shadow);
  overflow: hidden;
  transform-origin: top center;
  animation: wcals-dropdown-in 0.18s ease both;
}

.wcals-dropdown[hidden] {
  display: none !important;
}

@keyframes wcals-dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.wcals-list {
  max-height: min(520px, 58vh);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--wcals-border) transparent;
}

.wcals-list::-webkit-scrollbar {
  width: 8px;
}

.wcals-list::-webkit-scrollbar-track {
  background: transparent;
}

.wcals-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 20px;
  background: var(--wcals-border);
  background-clip: padding-box;
}

.wcals-item {
  position: relative;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 90px;
  padding: 8px 12px 8px 8px;
  border: 0;
  border-radius: var(--wcals-radius-lg);
  color: inherit !important;
  text-decoration: none !important;
  transition: background-color 0.18s ease, transform 0.18s ease;
}

.wcals-item + .wcals-item {
  margin-top: 3px;
}

.wcals-item:hover,
.wcals-item:focus-visible,
.wcals-item.is-active {
  background: var(--wcals-bg-soft);
  color: inherit !important;
  outline: 0;
}

.wcals-item:active {
  transform: scale(0.995);
}

.wcals-thumb {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 74px;
  height: 74px;
  padding: 6px;
  border: 1px solid var(--wcals-border);
  border-radius: 16px;
  background: #ffffff;
  overflow: hidden;
}

.wcals-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  border-radius: 11px;
  object-fit: contain;
}

.wcals-sale {
  position: absolute;
  top: 5px;
  right: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--wcals-accent);
  color: var(--wcals-accent-contrast);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.wcals-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  gap: 6px;
}

.wcals-title {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  color: var(--wcals-text);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.35;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.wcals-sku {
  max-width: 100%;
  overflow: hidden;
  color: var(--wcals-muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wcals-item-side {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 104px;
  padding-left: 8px;
  text-align: right;
}

.wcals-price {
  color: var(--wcals-text);
  font-size: 15px;
  font-weight: 750;
  line-height: 1.25;
  white-space: nowrap;
}

.wcals-price .amount {
  color: inherit;
}

.wcals-price del {
  display: block;
  margin-bottom: 3px;
  color: var(--wcals-muted);
  font-size: 12px;
  font-weight: 500;
  opacity: 0.72;
}

.wcals-price ins {
  color: inherit;
  text-decoration: none;
}

.wcals-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  padding: 28px 18px;
  color: var(--wcals-muted);
  text-align: center;
}

.wcals-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin-bottom: 12px;
  border-radius: 18px;
  background: var(--wcals-bg-soft);
  color: var(--wcals-text);
}

.wcals-empty-icon svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wcals-view-all {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
  margin-top: 8px;
  padding: 12px 18px;
  border-radius: 16px;
  background: var(--wcals-accent);
  color: var(--wcals-accent-contrast) !important;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none !important;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.wcals-view-all:hover,
.wcals-view-all:focus-visible {
  color: var(--wcals-accent-contrast) !important;
  opacity: 0.88;
  outline: 0;
  transform: translateY(-1px);
}

.wcals-view-all svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wcals-title mark {
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.wcals-live {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Existing Bootstrap search modal from header.php */
#searchModal {
  --bs-modal-zindex: 10050;
}

#searchModal .modal-dialog {
  max-width: 810px;
  margin-top: clamp(32px, 10vh, 110px);
}

#searchModal .modal-content {
  overflow: visible;
  border: 0;
  border-radius: 30px;
  background: var(--bs-body-bg, #ffffff);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.24);
}

#searchModal .modal-header {
  position: relative;
  display: flex !important;
  align-items: center;
  justify-content: space-between !important;
  width: 100%;
  min-height: 68px;
  padding: 26px 84px 10px 28px;
  border: 0;
}

#searchModal .modal-title {
  margin: 0;
  color: var(--bs-body-color, #171717);
  font-size: clamp(22px, 3vw, 32px) !important;
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

#searchModal .btn-close {
  position: absolute;
  top: 24px;
  right: 28px;
  left: auto;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  margin: 0 !important;
  padding: 0;
  border-radius: 50%;
  background-color: var(--bs-tertiary-bg, #f4f4f1);
  background-size: 13px;
  opacity: 1;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

#searchModal .btn-close:hover,
#searchModal .btn-close:focus-visible {
  opacity: 0.78;
  transform: rotate(5deg) scale(1.04);
  box-shadow: none;
}

#searchModal .modal-body {
  padding: 12px 28px 30px;
}

#searchModal .wcals-wrap {
  max-width: none;
}

@media (max-width: 767.98px) {
  .wcals-field {
    min-height: 58px;
    border-radius: 18px;
  }

  .wcals-input {
    height: 56px;
    padding-right: 72px;
    padding-left: 52px;
    font-size: 16px;
  }

  .wcals-field-icon {
    left: 18px;
    width: 20px;
    height: 20px;
  }

  .wcals-clear {
    right: 11px;
    width: 34px;
    height: 34px;
  }

  .wcals-loader {
    right: 20px;
  }

  .wcals-dropdown {
    top: calc(100% + 9px);
    padding: 6px;
    border-radius: 20px;
  }

  .wcals-list {
    max-height: min(56vh, 440px);
  }

  .wcals-item {
    grid-template-columns: 62px minmax(0, 1fr);
    gap: 11px;
    min-height: 76px;
    padding: 7px;
    border-radius: 16px;
  }

  .wcals-thumb {
    width: 62px;
    height: 62px;
    border-radius: 14px;
  }

  .wcals-thumb img {
    border-radius: 9px;
  }

  .wcals-title {
    font-size: 14px;
  }

  .wcals-item-side {
    grid-column: 2;
    min-width: 0;
    padding: 0;
    text-align: left;
    justify-content: flex-start;
  }

  .wcals-price {
    font-size: 14px;
    white-space: normal;
  }

  .wcals-price del {
    display: inline;
    margin-right: 5px;
  }

  #searchModal .modal-dialog {
    width: auto;
    max-width: none;
    margin: 10px;
  }

  #searchModal .modal-content {
    min-height: auto;
    border-radius: 24px;
  }

  #searchModal .modal-header {
    min-height: 58px;
    padding: 20px 68px 8px 18px;
  }

  #searchModal .modal-title {
    font-size: 24px !important;
  }

  #searchModal .btn-close {
    top: 18px;
    right: 18px;
    width: 38px;
    height: 38px;
  }

  #searchModal .modal-body {
    padding: 10px 18px 22px;
  }
}

@media (max-width: 420px) {
  .wcals-dropdown {
    left: -2px;
    right: -2px;
  }

  .wcals-view-all {
    min-height: 48px;
    border-radius: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wcals-field,
  .wcals-clear,
  .wcals-dropdown,
  .wcals-item,
  .wcals-view-all,
  #searchModal .btn-close {
    animation: none !important;
    transition: none !important;
  }
}
