/**
 * SocialBoost Kenya - Smart Floating Dropdown & Portal Component
 * Reusable Floating Popover Architecture for Service & Category Selectors
 * Designed for High-Performance SaaS & Mobile-Commerce
 */

/* ==========================================================================
   1. Floating Portal Root (Body Mounted - Immune to Parent Clipping)
   ========================================================================== */
#sb-floating-portal-root {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  overflow: visible;
  z-index: 9999999;
  pointer-events: none;
}

/* ==========================================================================
   2. Select Trigger (Rendered in Form Hierarchy)
   ========================================================================== */
.sb-fd-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  background: #ffffff;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  cursor: pointer;
  box-sizing: border-box;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.sb-fd-trigger:hover {
  border-color: #94a3b8;
  background-color: #f8fafc;
}

.sb-fd-trigger.open,
.sb-fd-trigger:focus-visible {
  border-color: #2563eb;
  background-color: #ffffff;
  box-shadow: 0 0 0 3.5px rgba(37, 99, 235, 0.14);
  outline: none;
}

.sb-fd-trigger.disabled {
  background-color: #f1f5f9;
  border-color: #e2e8f0;
  cursor: not-allowed;
  opacity: 0.7;
}

.sb-fd-trigger-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sb-fd-trigger-placeholder {
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
}

.sb-fd-trigger-val-badge {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  flex-shrink: 0;
}

.sb-fd-trigger-val-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.35;
  word-break: break-word;
}

.sb-fd-trigger-content-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-width: 0;
}

.sb-fd-trigger-top-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.sb-fd-trigger-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-width: 0;
  flex-wrap: wrap;
}

.sb-fd-trigger-specs-left {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1;
}

.sb-fd-trigger-spec-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  line-height: 1.25;
  white-space: nowrap;
}

.sb-fd-trigger-spec-pill.sb-pill-limits {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.sb-fd-trigger-spec-pill.sb-pill-refill {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.sb-fd-trigger-spec-pill.sb-pill-quality {
  background: #fdf4ff;
  color: #7e22ce;
  border: 1px solid #f0abfc;
}

.sb-fd-trigger-val-price {
  margin-left: auto;
  font-size: 0.84rem;
  font-weight: 800;
  color: #059669;
  background: #ecfdf5;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid #a7f3d0;
  flex-shrink: 0;
}

.sb-fd-trigger-arrow {
  flex-shrink: 0;
  color: #64748b;
  display: flex;
  align-items: center;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), color 0.2s ease;
}

.sb-fd-trigger.open .sb-fd-trigger-arrow {
  transform: rotate(180deg);
  color: #2563eb;
}

/* ==========================================================================
   3. Floating Popover Component (Direct Child of Portal Root)
   ========================================================================== */
.sb-floating-popover {
  position: fixed;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  box-shadow: 0 16px 38px -6px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transform-origin: top center;
  transform: translateY(6px) scale(0.985);
  transition: opacity 160ms cubic-bezier(0.16, 1, 0.3, 1), 
              transform 160ms cubic-bezier(0.16, 1, 0.3, 1), 
              visibility 160ms ease;
  z-index: 9999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #1e293b;
  box-sizing: border-box;
  max-width: calc(100vw - 20px);
}

.sb-floating-popover.sb-placement-top {
  transform-origin: bottom center;
  transform: translateY(-6px) scale(0.985);
}

.sb-floating-popover.sb-active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ==========================================================================
   4. Fixed Popover Header (Search & Category Chips)
   ========================================================================== */
.sb-fd-header {
  padding: 8px 10px 6px;
  background: #ffffff;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.sb-fd-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.sb-fd-search-icon {
  position: absolute;
  left: 10px;
  color: #94a3b8;
  font-size: 12px;
  pointer-events: none;
}

.sb-fd-search-input {
  width: 100%;
  height: 33px;
  padding: 0 28px 0 28px;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  font-size: 0.81rem;
  color: #0f172a;
  background: #f8fafc;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.sb-fd-search-input:focus {
  background: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.sb-fd-search-clear {
  position: absolute;
  right: 7px;
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 3px;
  display: none;
}

.sb-fd-search-clear.visible {
  display: block;
}

.sb-fd-filter-bar {
  display: flex;
  gap: 4px;
  margin-top: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 1px;
}

.sb-fd-filter-bar::-webkit-scrollbar {
  display: none;
}

.sb-fd-filter-chip {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.67rem;
  font-weight: 700;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  user-select: none;
}

.sb-fd-filter-chip:hover {
  border-color: #cbd5e1;
  background: #f1f5f9;
}

.sb-fd-filter-chip.active {
  background: #eff6ff;
  border-color: #2563eb;
  color: #1d4ed8;
}

/* ==========================================================================
   5. Scrollable Options Body
   ========================================================================== */
.sb-fd-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 6px 8px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f8fafc;
  min-height: 120px;
}

.sb-fd-body::-webkit-scrollbar {
  width: 6px;
}

.sb-fd-body::-webkit-scrollbar-track {
  background: #f8fafc;
}

.sb-fd-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.sb-fd-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ==========================================================================
   6. Group Sections & Dividers
   ========================================================================== */
.sb-fd-group {
  margin-bottom: 6px;
}

.sb-fd-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 5px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  position: sticky;
  top: -6px;
  background: #ffffff;
  z-index: 2;
}

.sb-fd-group-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: #fef3c7;
  color: #92400e;
  font-weight: 700;
  letter-spacing: normal;
  text-transform: none;
}

/* ==========================================================================
   7. Option Card (Compact SaaS + Mobile Commerce)
   ========================================================================== */
.sb-fd-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  user-select: none;
  box-sizing: border-box;
  margin-bottom: 2px;
}

.sb-fd-option:hover,
.sb-fd-option.focused {
  background: #f8fafc;
  border-color: #e2e8f0;
}

.sb-fd-option.selected {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.sb-fd-opt-main {
  flex: 1 1 auto;
  min-width: 0;
}

.sb-fd-opt-header-line {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
  flex-wrap: wrap;
}

.sb-fd-id-badge {
  font-size: 0.62rem;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 3px;
  background: #f1f5f9;
  color: #475569;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.sb-fd-tag {
  font-size: 0.58rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
}

.sb-fd-tag-recommended {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.sb-fd-tag-instant {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.sb-fd-tag-refill {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.sb-fd-tag-new {
  background: #fdf2f8;
  color: #9d174d;
  border: 1px solid #fbcfe8;
}

.sb-fd-opt-title {
  font-size: 0.77rem;
  line-height: 1.26;
  color: #1e293b;
  word-break: break-word;
  font-weight: 600;
}

.sb-fd-option.selected .sb-fd-opt-title {
  color: #1d4ed8;
  font-weight: 700;
}

.sb-fd-opt-specs {
  display: flex;
  gap: 3px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.sb-fd-spec-pill {
  font-size: 0.58rem;
  padding: 0 4px;
  line-height: 1.3;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 3px;
  color: #64748b;
}

.sb-fd-opt-price-col {
  flex-shrink: 0;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.15;
}

.sb-fd-opt-price {
  font-size: 0.82rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.sb-fd-opt-unit {
  font-size: 0.58rem;
  color: #94a3b8;
  font-weight: 600;
}

.sb-fd-opt-check {
  width: 14px;
  height: 14px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #2563eb;
  color: #ffffff;
  font-size: 9px;
  margin-top: 2px;
}

.sb-fd-option.selected .sb-fd-opt-check {
  display: inline-flex;
}

/* ==========================================================================
   8. Empty Search Results
   ========================================================================== */
.sb-fd-empty {
  padding: 28px 16px;
  text-align: center;
}

.sb-fd-empty-icon {
  font-size: 26px;
  margin-bottom: 6px;
}

.sb-fd-empty-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 4px;
}

.sb-fd-empty-desc {
  font-size: 0.75rem;
  color: #64748b;
  max-width: 260px;
  margin: 0 auto;
  line-height: 1.4;
}

/* ==========================================================================
   9. Fixed Popover Footer
   ========================================================================== */
.sb-fd-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: #f8fafc;
  border-top: 1px solid #f1f5f9;
  font-size: 0.72rem;
  color: #64748b;
  flex-shrink: 0;
}

.sb-fd-footer kbd {
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 0.65rem;
  font-family: inherit;
}

/* ==========================================================================
   10. Mobile Responsive Touch Enhancements
   ========================================================================== */
@media (max-width: 640px) {
  .sb-floating-popover {
    border-radius: 14px;
  }
  .sb-fd-option {
    min-height: 40px;
    padding: 6px 8px;
  }
  .sb-fd-opt-title {
    font-size: 0.78rem;
  }
  .sb-fd-footer-hint {
    display: none;
  }
}

/* ==========================================================================
   11. Global Fix for Duplicate Modal Close Buttons (Removes pseudo-icon)
   ========================================================================== */
.modal .close:before,
.close:before,
button.close:before {
  content: none !important;
  display: none !important;
}

/* ==========================================================================
   12. Category Specific Presentation Styling
   ========================================================================== */
.sb-fd-cat-icon {
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.sb-fd-cat-arrow {
  font-size: 0.78rem;
  color: #94a3b8;
  flex-shrink: 0;
  transition: transform 0.15s ease, color 0.15s ease;
}
.sb-fd-option:hover .sb-fd-cat-arrow {
  color: #2563eb;
  transform: translateX(3px);
}

/* ==========================================================================
   13. Form Step Badges & Label Continuity Across AJAX Replacements
   ========================================================================== */
.qo-step-badge,
.sb-label-badge {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 22px !important;
  height: 22px !important;
  min-width: 22px !important;
  border-radius: 50% !important;
  background: var(--sb-blue-700, #2563eb) !important;
  color: #ffffff !important;
  font-size: 0.75rem !important;
  font-weight: 800 !important;
  line-height: 1 !important;
  margin-right: 6px !important;
  vertical-align: middle !important;
}

.sb-label,
label.sb-label {
  font-size: 0.88rem !important;
  font-weight: 700 !important;
  color: #1e293b !important;
  display: flex !important;
  align-items: center !important;
  margin-bottom: 0.5rem !important;
}

