/* GharFix Always-Visible Chatbot Widget */
:root {
  --gfc-primary: #1e88e5;
  --gfc-primary-dark: #1565c0;
  --gfc-bg: #ffffff;
  --gfc-text: #1f2937;
  --gfc-shadow: 0 10px 30px rgba(0,0,0,0.15);
  --gfc-border: #e5e7eb;
  --gfc-minimize-bg: #4CAF50;
}

/* Container */
#gfc-always-chat {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 350px;
  height: 500px;
  background: var(--gfc-bg);
  border-radius: 16px;
  box-shadow: var(--gfc-shadow);
  border: 1px solid var(--gfc-border);
  z-index: 999999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
}

/* Minimize button */
#gfc-minimize {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
#gfc-minimize:hover {
  background: rgba(255,255,255,0.3);
}

/* Minimized state */
#gfc-always-chat.minimized {
  width: 180px;
  height: 55px;
  border-radius: 28px;
  background: var(--gfc-minimize-bg);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(76,175,80,0.4);
}
#gfc-always-chat.minimized #gfc-header,
#gfc-always-chat.minimized #gfc-messages,
#gfc-always-chat.minimized .gfc-quick-actions,
#gfc-always-chat.minimized #gfc-inputbar {
  display: none;
}
#gfc-always-chat.minimized::after {
  content: "💬 AI Chat ";
  position: absolute;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Header */
#gfc-header {
  background: linear-gradient(135deg, #2196F3, #1976D2);
  color: #fff;
  padding: 16px 20px;
  position: relative;
}
#gfc-header h3 {
  margin: 0;
  font: 700 16px system-ui, sans-serif;
}
#gfc-header p {
  margin: 4px 0 0;
  font: 400 12px system-ui, sans-serif;
  opacity: 0.9;
}

/* Messages */
#gfc-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Welcome */
.gfc-welcome {
  background: linear-gradient(135deg,#f0f9ff,#e0f2fe);
  border: 1px solid #0ea5e9;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.gfc-welcome h4 {
  margin: 0 0 8px;
  color: #0369a1;
  font-size: 14px;
}
.gfc-welcome p {
  margin: 0;
  font-size: 12px;
  color: #0c4a6e;
}

/* Bubbles */
.gfc-msg {
  display: flex;
  gap: 8px;
}
.gfc-msg.gfc-user { justify-content: flex-end; }
.gfc-msg.gfc-bot  { justify-content: flex-start; }

.gfc-bubble {
  max-width: 250px;
  padding: 10px 14px;
  border-radius: 16px;
  font: 400 13px system-ui, sans-serif;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.gfc-user .gfc-bubble {
  background: #1e88e5;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.gfc-bot .gfc-bubble {
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

/* Quick actions */
.gfc-quick-actions {
  padding: 8px 12px;
  background: #f8fafc;
  border-top: 1px solid #e5e7eb;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.gfc-quick-btn {
  padding: 6px 12px;
  background: var(--gfc-primary);
  color: #fff;
  border: 1px solid var(--gfc-primary);
  border-radius: 16px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.gfc-quick-btn:hover {
  background: var(--gfc-primary-dark);
  transform: translateY(-1px);
}

/* Input bar */
#gfc-inputbar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}
#gfc-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  padding: 8px 12px;
  font: 400 13px system-ui, sans-serif;
  outline: none;
  transition: border-color 0.2s;
}
#gfc-input:focus { border-color: var(--gfc-primary); }

#gfc-send {
  padding: 8px 16px;
  border-radius: 20px;
  border: none;
  background: var(--gfc-primary);
  color: #fff;
  cursor: pointer;
  font: 500 13px system-ui, sans-serif;
  transition: background 0.2s;
}
#gfc-send:hover { background: var(--gfc-primary-dark); }
#gfc-send:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

/* Typing indicator */
.gfc-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #6b7280;
  font-size: 12px;
}
.gfc-typing .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9ca3af;
  animation: gfc-typing 1.4s infinite ease-in-out;
}
.gfc-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.gfc-typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes gfc-typing {
  0%,80%,100% { transform: scale(0.8); opacity:0.5; }
  40% { transform: scale(1); opacity:1; }
}

/* Scrollbar */
#gfc-messages::-webkit-scrollbar {
  width: 4px;
}
#gfc-messages::-webkit-scrollbar-track {
  background: transparent;
}
#gfc-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}
#gfc-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Enhanced mobile responsiveness - fixes iOS alignment issues */
@media (max-width: 480px) {
  #gfc-always-chat {
    position: fixed !important;
    top: auto !important;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    right: calc(20px + env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
    transform: none !important;
    width: calc(100vw - 40px);
    max-width: 360px;
    height: 60vh;
    max-height: calc(100vh - 120px);
    border-radius: 16px;
    /* iOS Safari specific fixes */
    will-change: transform;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }
  
  #gfc-always-chat.minimized {
    width: 160px !important;
    height: 50px !important;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    right: calc(20px + env(safe-area-inset-right, 0px)) !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  
  /* Ensure content doesn't overflow on small screens */
  .gfc-bubble {
    max-width: calc(100vw - 120px) !important;
  }
  
  /* Better touch targets for iOS */
  .gfc-quick-btn {
    min-height: 44px;
    padding: 8px 12px;
  }
  
  #gfc-send {
    min-height: 44px;
    min-width: 44px;
  }
}

/* iOS-specific fixes using feature detection */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 480px) {
    #gfc-always-chat {
      bottom: max(20px, env(safe-area-inset-bottom)) !important;
      right: max(20px, env(safe-area-inset-right)) !important;
    }
    
    #gfc-always-chat.minimized {
      bottom: max(20px, env(safe-area-inset-bottom)) !important;
      right: max(20px, env(safe-area-inset-right)) !important;
    }
  }
}
