/* BuySellCy Live Support Widget - Modern Design */
/* Full Mobile & Device Support */

/* Root container - positioned above back-to-top button */
#bscy-live-support-root {
  position: fixed;
  right: 24px;
  bottom: 130px; /* Above back-to-top button */
  z-index: 9998;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Floating Chat Button - Modern glassmorphism style */
.bscy-ls-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  color: #ffffff;
  box-shadow: 
    0 8px 32px rgba(245, 158, 11, 0.35),
    0 4px 16px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 24px;
  position: relative;
  overflow: hidden;
  /* Touch-friendly */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.bscy-ls-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
  border-radius: 50%;
}

.bscy-ls-button:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 
    0 12px 40px rgba(245, 158, 11, 0.45),
    0 6px 20px rgba(0, 0, 0, 0.2);
}

.bscy-ls-button:active {
  transform: scale(0.95);
  transition-duration: 0.1s;
}

/* Pulse animation for attention */
.bscy-ls-button.has-unread::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: inherit;
  animation: pulse-ring 2s infinite;
  z-index: -1;
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(1.3); opacity: 0; }
  100% { transform: scale(1); opacity: 0; }
}

/* Badge for unread messages */
.bscy-ls-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #fff;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 22px;
  text-align: center;
  display: none;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  border: 2px solid #fff;
  animation: badge-pop 0.3s ease-out;
}

@keyframes badge-pop {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* Chat Panel - Modern card design */
.bscy-ls-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 550px;
  max-height: calc(100vh - 180px);
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 
    0 25px 60px rgba(0, 0, 0, 0.15),
    0 10px 30px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  display: none;
  animation: panel-slide-up 0.3s ease-out;
  transform-origin: bottom right;
}

@keyframes panel-slide-up {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.bscy-ls-panel.open {
  display: flex;
  flex-direction: column;
}

/* Header - Gradient with modern styling */
.bscy-ls-header {
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.bscy-ls-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Header right actions */
.bscy-ls-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bscy-ls-feedback {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.bscy-ls-feedback:hover,
.bscy-ls-feedback:active {
  background: rgba(255, 255, 255, 0.2);
}

.bscy-ls-title > div:first-child {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
  flex-shrink: 0;
}

.bscy-ls-title > div:first-child svg {
  color: #fff;
}

.bscy-ls-title strong {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
  display: block;
  margin-bottom: 2px;
}

.bscy-ls-subtitle {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bscy-ls-subtitle::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  animation: status-pulse 2s infinite;
  flex-shrink: 0;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Close button */
.bscy-ls-close {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 22px;
  font-weight: 300;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.bscy-ls-close:hover,
.bscy-ls-close:active {
  background: rgba(255, 255, 255, 0.2);
}

/* Message Body */
.bscy-ls-body {
  flex: 1;
  background: linear-gradient(to bottom, #f8fafc 0%, #f1f5f9 100%);
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* Smooth iOS scrolling */
  overscroll-behavior: contain;
}

/* Custom scrollbar */
.bscy-ls-body::-webkit-scrollbar {
  width: 6px;
}

.bscy-ls-body::-webkit-scrollbar-track {
  background: transparent;
}

.bscy-ls-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.bscy-ls-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* Message Rows */
.bscy-ls-row {
  display: flex;
  margin-bottom: 12px;
  animation: message-fade-in 0.3s ease-out;
}

@keyframes message-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bscy-ls-row.user {
  justify-content: flex-end;
}

/* Message Bubbles */
.bscy-ls-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

/* Support/AI message */
.bscy-ls-row:not(.user):not(.system) .bscy-ls-bubble {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

/* User message */
.bscy-ls-row.user .bscy-ls-bubble {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

/* System message */
.bscy-ls-row.system .bscy-ls-bubble {
  background: #f1f5f9;
  color: #64748b;
  font-size: 13px;
  text-align: center;
  max-width: 100%;
  border-radius: 12px;
  padding: 10px 16px;
  border: 1px dashed rgba(0, 0, 0, 0.1);
}

/* Links in messages */
.bscy-ls-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bscy-ls-row.user .bscy-ls-bubble a {
  color: #bfdbfe;
}

/* Meta text (time) */
.bscy-ls-meta {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.6;
}

/* Footer Input Area */
.bscy-ls-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: #ffffff;
  flex-shrink: 0;
}

/* Guest Identity Inputs */
.bscy-ls-identity {
  display: none;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.bscy-ls-identity input {
  flex: 1;
  min-width: 120px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  font-size: 16px; /* Prevents iOS zoom */
  background: #f8fafc;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.bscy-ls-identity input:focus {
  outline: none;
  border-color: #f59e0b;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

/* Input Row */
.bscy-ls-input-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.bscy-ls-input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid #e2e8f0;
  font-size: 16px; /* Prevents iOS zoom on focus */
  background: #f8fafc;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
  min-width: 0; /* Allows flex shrink */
}

.bscy-ls-input:focus {
  outline: none;
  border-color: #f59e0b;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.1);
}

.bscy-ls-input:disabled {
  background: #f1f5f9;
  color: #94a3b8;
}

.bscy-ls-input::placeholder {
  color: #9ca3af;
}

/* Send Button */
.bscy-ls-send {
  width: 48px;
  min-width: 48px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.bscy-ls-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

.bscy-ls-send:active:not(:disabled) {
  transform: scale(0.95);
}

.bscy-ls-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bscy-ls-send svg {
  width: 20px;
  height: 20px;
}

/* Hint Text */
.bscy-ls-hint {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 8px;
  text-align: center;
}

/* New Chat Button */
.bscy-ls-new-chat {
  width: 100%;
  margin-top: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px dashed #e2e8f0;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
}

.bscy-ls-new-chat::before {
  content: '💬';
}

.bscy-ls-new-chat:hover,
.bscy-ls-new-chat:active {
  background: #f1f5f9;
  border-color: #f59e0b;
  color: #1e293b;
}

/* Typing Indicator */
#bscy-ls-typing .bscy-ls-bubble {
  background: #ffffff;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
}

/* ===========================================
   RESPONSIVE - TABLETS (768px - 1024px)
   =========================================== */
@media (max-width: 1024px) and (min-width: 769px) {
  #bscy-live-support-root {
    right: 20px;
    bottom: 120px;
  }
  
  .bscy-ls-panel {
    width: 360px;
    height: 520px;
  }
}

/* ===========================================
   RESPONSIVE - MOBILE (up to 768px)
   =========================================== */
@media (max-width: 768px) {
  #bscy-live-support-root {
    right: 12px;
    /* Keep above the mobile bottom nav */
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  
  .bscy-ls-button {
    width: 48px;
    height: 48px;
  }
  
  .bscy-ls-button svg {
    width: 22px;
    height: 22px;
  }
  
  .bscy-ls-panel {
    position: fixed;
    right: 8px;
    left: 8px;
    bottom: 8px;
    top: auto;
    width: auto;
    max-width: none;
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
    border-radius: 20px;
  }
  
  .bscy-ls-header {
    padding: 14px 16px;
  }
  
  .bscy-ls-title > div:first-child {
    width: 38px;
    height: 38px;
  }
  
  .bscy-ls-title > div:first-child svg {
    width: 18px;
    height: 18px;
  }
  
  .bscy-ls-title strong {
    font-size: 14px;
  }
  
  .bscy-ls-body {
    padding: 12px;
  }
  
  .bscy-ls-bubble {
    max-width: 88%;
    font-size: 15px;
  }
  
  .bscy-ls-footer {
    padding: 12px 14px;
    /* Safe area for iOS home indicator */
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  
  .bscy-ls-input {
    padding: 12px 14px;
  }
  
  .bscy-ls-send {
    width: 46px;
    min-width: 46px;
    height: 46px;
  }
}

/* ===========================================
   RESPONSIVE - SMALL MOBILE (up to 576px)
   =========================================== */
@media (max-width: 576px) {
  #bscy-live-support-root {
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  
  .bscy-ls-button {
    width: 46px;
    height: 46px;
  }
  
  .bscy-ls-badge {
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    font-size: 11px;
    top: -2px;
    right: -2px;
  }
  
  .bscy-ls-panel {
    right: 0;
    left: 0;
    bottom: 0;
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    border-radius: 20px 20px 0 0;
  }
  
  .bscy-ls-identity {
    flex-direction: column;
  }
  
  .bscy-ls-identity input {
    min-width: 100%;
  }
}

/* ===========================================
   RESPONSIVE - VERY SMALL MOBILE (up to 380px)
   =========================================== */
@media (max-width: 380px) {
  #bscy-live-support-root {
    right: 10px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  
  .bscy-ls-button {
    width: 44px;
    height: 44px;
  }
  
  .bscy-ls-button svg {
    width: 22px;
    height: 22px;
  }
  
  .bscy-ls-header {
    padding: 12px 14px;
  }
  
  .bscy-ls-title > div:first-child {
    width: 34px;
    height: 34px;
  }
  
  .bscy-ls-body {
    padding: 10px;
  }
  
  .bscy-ls-bubble {
    padding: 10px 14px;
    font-size: 14px;
  }
  
  .bscy-ls-footer {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  
  .bscy-ls-input {
    padding: 10px 12px;
    font-size: 16px;
  }
  
  .bscy-ls-send {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }
  
  .bscy-ls-hint {
    font-size: 10px;
  }
}

/* ===========================================
   LANDSCAPE ORIENTATION (Mobile)
   =========================================== */
@media (max-height: 500px) and (orientation: landscape) {
  #bscy-live-support-root {
    bottom: 70px;
    right: 16px;
  }
  
  .bscy-ls-button {
    width: 48px;
    height: 48px;
  }
  
  .bscy-ls-panel {
    height: calc(100vh - 20px);
    max-height: calc(100vh - 20px);
    bottom: 10px;
    right: 10px;
    left: auto;
    width: 340px;
    max-width: calc(100vw - 80px);
    border-radius: 16px;
  }
  
  .bscy-ls-header {
    padding: 10px 14px;
  }
  
  .bscy-ls-title > div:first-child {
    width: 32px;
    height: 32px;
  }
  
  .bscy-ls-body {
    padding: 8px;
  }
  
  .bscy-ls-bubble {
    padding: 8px 12px;
    font-size: 13px;
  }
  
  .bscy-ls-footer {
    padding: 8px 10px;
  }
  
  .bscy-ls-input {
    padding: 8px 12px;
  }
  
  .bscy-ls-send {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }
  
  .bscy-ls-hint {
    display: none; /* Save space in landscape */
  }
}

/* ===========================================
   iOS SAFE AREAS (Notch & Home Indicator)
   =========================================== */
@supports (padding: env(safe-area-inset-bottom)) {
  .bscy-ls-panel {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  
  @media (max-width: 576px) {
    #bscy-live-support-root {
      right: calc(14px + env(safe-area-inset-right, 0px));
    }
    
    .bscy-ls-panel {
      right: env(safe-area-inset-right, 0px);
      left: env(safe-area-inset-left, 0px);
    }
  }
}

/* ===========================================
   HIGH DPI / RETINA DISPLAYS
   =========================================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .bscy-ls-bubble {
    -webkit-font-smoothing: subpixel-antialiased;
  }
}

/* ===========================================
   TOUCH DEVICES - Enhanced Tap Targets
   =========================================== */
@media (hover: none) and (pointer: coarse) {
  .bscy-ls-button:hover {
    transform: none;
    box-shadow: 
      0 8px 32px rgba(245, 158, 11, 0.35),
      0 4px 16px rgba(0, 0, 0, 0.15);
  }
  
  .bscy-ls-close:hover {
    background: rgba(255, 255, 255, 0.1);
  }
  
  .bscy-ls-send:hover:not(:disabled) {
    transform: none;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
  }
  
  .bscy-ls-new-chat:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
  }
}

/* ===========================================
   REDUCED MOTION (Accessibility)
   =========================================== */
@media (prefers-reduced-motion: reduce) {
  .bscy-ls-button,
  .bscy-ls-panel,
  .bscy-ls-row,
  .bscy-ls-close,
  .bscy-ls-send,
  .bscy-ls-input,
  .bscy-ls-new-chat {
    transition: none;
    animation: none;
  }
  
  .bscy-ls-button.has-unread::after {
    animation: none;
  }
  
  .bscy-ls-subtitle::before {
    animation: none;
  }
  
  .bscy-ls-badge {
    animation: none;
  }
}

/* ===========================================
   DARK MODE (Optional - Uncomment to enable)
   =========================================== */
/*
@media (prefers-color-scheme: dark) {
  .bscy-ls-panel {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .bscy-ls-body {
    background: linear-gradient(to bottom, #0f172a 0%, #1e293b 100%);
  }
  
  .bscy-ls-row:not(.user):not(.system) .bscy-ls-bubble {
    background: #334155;
    color: #f1f5f9;
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  .bscy-ls-row.system .bscy-ls-bubble {
    background: #1e293b;
    color: #94a3b8;
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  .bscy-ls-footer {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  .bscy-ls-input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
  }
  
  .bscy-ls-input:focus {
    background: #1e293b;
    border-color: #f59e0b;
  }
  
  .bscy-ls-identity input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
  }
  
  .bscy-ls-new-chat {
    background: #0f172a;
    border-color: #334155;
    color: #94a3b8;
  }
  
  .bscy-ls-hint {
    color: #64748b;
  }
}
*/

/* ===========================================
   PRINT - Hide Widget
   =========================================== */
@media print {
  #bscy-live-support-root {
    display: none !important;
  }
}
