/**
 * Codway Commerce Search - Command Palette & Live Search Styles
 * Universal CSS compatible with any WordPress theme (Flatsome, Divi, Elementor, Astra, Codway)
 */

/* ==========================================================================
   THEME TOKENS: LIGHT THEME (Default)
   ========================================================================== */
:root,
[data-theme="light"],
html:not(.dark) {
  --cw-search-acc: #2563eb;
  --cw-search-radius: 16px;
  --cw-search-bg: #ffffff;
  --cw-search-card: #f8fafc;
  --cw-search-fg: #0f172a;
  --cw-search-mut: #64748b;
  --cw-search-line: #e2e8f0;
  --cw-search-hover: #f1f5f9;
  --cw-search-kbd-bg: #e2e8f0;
  --cw-search-kbd-fg: #334155;
  --cw-search-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.16);
}

/* ==========================================================================
   THEME TOKENS: DARK THEME
   ========================================================================== */
html.dark,
body.dark,
[data-theme="dark"],
html.dark [data-theme="dark"] {
  --cw-search-acc: #3b82f6;
  --cw-search-radius: 16px;
  --cw-search-bg: #09090b;
  --cw-search-card: #141416;
  --cw-search-fg: #f8fafc;
  --cw-search-mut: #94a3b8;
  --cw-search-line: #27272a;
  --cw-search-hover: #1f1f23;
  --cw-search-kbd-bg: #27272a;
  --cw-search-kbd-fg: #cbd5e1;
  --cw-search-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not(.light) {
    --cw-search-acc: #3b82f6;
    --cw-search-radius: 16px;
    --cw-search-bg: #09090b;
    --cw-search-card: #141416;
    --cw-search-fg: #f8fafc;
    --cw-search-mut: #94a3b8;
    --cw-search-line: #27272a;
    --cw-search-hover: #1f1f23;
    --cw-search-kbd-bg: #27272a;
    --cw-search-kbd-fg: #cbd5e1;
    --cw-search-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  }
}

/* Overlay & Backdrop */
.cw-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  padding-top: max(40px, 8vh);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s ease;
  box-sizing: border-box;
}

.cw-search-overlay.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.cw-search-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(var(--cw-search-blur, 8px));
  -webkit-backdrop-filter: blur(var(--cw-search-blur, 8px));
}

/* Modal Card - Responsive fluid width across mobile, tablet, laptop and ultra-wide screens */
.cw-search-card {
  position: relative;
  width: 100%;
  max-width: var(--cw-search-max-w, 840px);
  max-height: 85vh;
  background-color: var(--cw-search-bg);
  color: var(--cw-search-fg);
  border-radius: var(--cw-search-radius);
  border: 1px solid var(--cw-search-line);
  box-shadow: var(--cw-search-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.96) translateY(-8px);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), max-width 0.2s ease;
  box-sizing: border-box;
}

@media (min-width: 1024px) {
  .cw-search-card {
    max-width: var(--cw-search-max-w, 840px);
  }
}

@media (min-width: 1440px) {
  .cw-search-card {
    max-width: var(--cw-search-max-w, 940px);
  }
}

@media (max-width: 639px) {
  .cw-search-overlay {
    padding: 0 !important;
    padding-top: 0 !important;
    align-items: stretch !important;
  }
  .cw-search-card {
    max-width: 100% !important;
    max-height: 100vh !important;
    height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
  }
}

.cw-search-overlay.is-active .cw-search-card {
  transform: scale(1) translateY(0);
}

/* Header & Input Bar */
.cw-search-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--cw-search-line);
  gap: 12px;
}

.cw-search-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--cw-search-mut);
  flex-shrink: 0;
}

.cw-search-input {
  flex: 1;
  min-width: 0;
  border: none !important;
  outline: none !important;
  background: transparent !important;
  color: var(--cw-search-fg) !important;
  font-size: 16px !important;
  font-family: inherit !important;
  line-height: 1.4 !important;
  padding: 0 !important;
  box-shadow: none !important;
}

.cw-search-input::placeholder {
  color: var(--cw-search-mut);
  opacity: 0.8;
}

.cw-search-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.cw-search-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--cw-search-line);
  border-top-color: var(--cw-search-acc);
  border-radius: 50%;
  animation: cw-spin 0.6s linear infinite;
}

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

.cw-search-esc-btn {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--cw-search-mut);
  display: inline-flex;
  align-items: center;
}

.cw-search-esc-btn kbd,
.cw-shortcut-item kbd,
.cw-search-kbd-hint kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  line-height: 1.2;
  color: var(--cw-search-kbd-fg);
  background-color: var(--cw-search-kbd-bg);
  border: 1px solid var(--cw-search-line);
  border-bottom-width: 2px;
  border-radius: 5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cw-search-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background-color: var(--cw-search-hover);
  border: 1px solid var(--cw-search-line);
  color: var(--cw-search-mut);
  cursor: pointer;
  padding: 0;
  transition: all 0.15s ease;
  margin-right: 2px;
}

.cw-search-clear-btn:hover {
  color: var(--cw-search-fg);
  border-color: var(--cw-search-acc);
  background-color: var(--cw-search-card);
}

/* Body & Scrolling Area */
.cw-search-body {
  flex: 1;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain;
  padding: 16px 20px;
  max-height: calc(85vh - 120px);
  width: 100%;
  box-sizing: border-box;
}

.cw-search-body::-webkit-scrollbar {
  width: 6px;
  height: 0px;
}
.cw-search-body::-webkit-scrollbar-track {
  background: transparent;
}
.cw-search-body::-webkit-scrollbar-thumb {
  background: var(--cw-search-line);
  border-radius: 9999px;
}
.cw-search-body::-webkit-scrollbar-thumb:hover {
  background: var(--cw-search-mut);
}

.cw-search-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  box-sizing: border-box;
}

.cw-search-subgroup {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.cw-search-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cw-search-mut);
}

.cw-search-count-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 9999px;
  background-color: var(--cw-search-hover);
  color: var(--cw-search-mut);
}

/* Bestsellers Grid in Zero-Query */
.cw-search-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.cw-search-card-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background-color: var(--cw-search-card);
  border: 1px solid var(--cw-search-line);
  text-decoration: none;
  color: inherit;
  transition: all 0.15s ease;
  position: relative;
  min-width: 0;
  box-sizing: border-box;
}

.cw-search-card-item:hover,
.cw-search-card-item.is-selected {
  background-color: var(--cw-search-hover);
  border-color: var(--cw-search-acc);
  transform: translateY(-1px);
}

.cw-search-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background-color: var(--cw-search-hover);
  flex-shrink: 0;
  border: 1px solid var(--cw-search-line);
}

.cw-search-card-info {
  flex: 1 1 0%;
  min-width: 0;
  overflow: hidden;
}

.cw-search-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cw-search-fg);
  line-height: 1.35;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

.cw-search-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.cw-search-price {
  font-size: 12px;
  font-weight: 700;
  color: var(--cw-search-acc);
}

.cw-search-regular-price {
  font-size: 11px;
  text-decoration: line-through;
  color: var(--cw-search-mut);
}

/* Chips & Categories */
.cw-search-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.cw-search-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px;
  background-color: var(--cw-search-hover);
  border: 1px solid var(--cw-search-line);
  color: var(--cw-search-fg);
  text-decoration: none;
  transition: all 0.15s ease;
  max-width: 100%;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
}

.cw-search-chip:hover {
  border-color: var(--cw-search-acc);
  color: var(--cw-search-acc);
  background-color: var(--cw-search-hover);
}

/* Results List */
.cw-search-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cw-search-row-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background-color 0.12s ease;
  min-width: 0;
  box-sizing: border-box;
  width: 100%;
}

.cw-search-row-item:hover,
.cw-search-row-item.is-selected {
  background-color: var(--cw-search-hover);
}

.cw-search-row-content {
  flex: 1 1 0%;
  min-width: 0;
  overflow: hidden;
}

.cw-search-row-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  min-width: 0;
}

.cw-search-row-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--cw-search-fg);
  margin: 0;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  white-space: normal;
}

.cw-search-sku-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  background-color: var(--cw-search-card);
  border: 1px solid var(--cw-search-line);
  color: var(--cw-search-mut);
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

.cw-search-row-desc {
  font-size: 12px;
  color: var(--cw-search-mut);
  margin: 3px 0 0 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.35;
}

/* Badges */
.cw-badge-sale {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #ef4444;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
}

html.dark .cw-badge-sale,
[data-theme="dark"] .cw-badge-sale {
  background-color: rgba(248, 113, 113, 0.15);
  border-color: rgba(248, 113, 113, 0.3);
  color: #fca5a5;
}

.cw-badge-stock {
  font-size: 11px;
  font-weight: 500;
  color: #10b981;
}

.cw-badge-stock.is-out {
  color: #ef4444;
}

/* Quick Add Button - Tactile Swiss Air & E-Commerce CRO Optimized */
.cw-quick-add-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  background-color: var(--cw-search-card);
  border: 1px solid var(--cw-search-line);
  color: var(--cw-search-fg);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.cw-quick-add-btn:hover {
  background-color: var(--cw-search-acc);
  border-color: var(--cw-search-acc);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -2px rgba(37, 99, 235, 0.25);
}

.cw-quick-add-btn.is-added {
  background-color: #10b981 !important;
  border-color: #10b981 !important;
  color: #ffffff !important;
  pointer-events: none;
}

.cw-quick-add-btn:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

.cw-quick-add-btn.is-added {
  background-color: #10b981;
}

/* Empty State */
.cw-search-empty {
  text-align: center;
  padding: 36px 16px;
}

.cw-search-empty-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.cw-search-empty-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 6px 0;
  color: var(--cw-search-fg);
}

.cw-search-empty-desc {
  font-size: 13px;
  color: var(--cw-search-mut);
  margin: 0;
}

/* Skeleton Loading */
.cw-search-skeleton {
  height: 60px;
  border-radius: 12px;
  background-color: var(--cw-search-hover);
  animation: cw-pulse 1.4s ease-in-out infinite;
}

@keyframes cw-pulse {
  50% { opacity: 0.4; }
}

/* Footer Shortcuts */
.cw-search-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-top: 1px solid var(--cw-search-line);
  background-color: var(--cw-search-card);
  font-size: 11px;
  color: var(--cw-search-mut);
}

.cw-search-shortcuts {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cw-shortcut-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cw-search-brand {
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Responsive Mobile Full-Screen Layout (<640px) */
@media (max-width: 639px) {
  .cw-search-overlay {
    padding: 0;
    align-items: stretch;
  }
  .cw-search-card {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: none;
  }
  .cw-search-body {
    max-height: calc(100vh - 120px);
  }
  .cw-search-grid {
    grid-template-columns: 1fr;
  }
  .cw-search-shortcuts {
    display: none;
  }
}

/* Toast feedback notification */
.cw-search-toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--cw-search-card);
  color: var(--cw-search-fg);
  border: 1px solid var(--cw-search-line);
  box-shadow: var(--cw-search-shadow);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 99999;
  white-space: nowrap;
  max-width: 90%;
}
.cw-search-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.cw-search-toast.is-success {
  border-color: rgba(34, 197, 94, 0.4);
  color: #16a34a;
}
.cw-search-toast.is-error {
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
}
