/**
 * THE SADIQ PROJECT - AI Chat Widget Styles
 * Polished, accessible, inline form UI
 */

/* =============================================
   CSS Variables
   ============================================= */
:root {
  --sp-chat-primary: #2d5a30;
  --sp-chat-primary-dark: #1e3d20;
  --sp-chat-primary-light: #4a7d4d;
  --sp-chat-gold: #c9a227;
  --sp-chat-white: #ffffff;
  --sp-chat-gray-50: #f9fafb;
  --sp-chat-gray-100: #f3f4f6;
  --sp-chat-gray-200: #e5e7eb;
  --sp-chat-gray-300: #d1d5db;
  --sp-chat-gray-400: #9ca3af;
  --sp-chat-gray-500: #6b7280;
  --sp-chat-gray-600: #4b5563;
  --sp-chat-gray-700: #374151;
  --sp-chat-gray-800: #1f2937;
  --sp-chat-danger: #dc2626;
  --sp-chat-success: #059669;
  --sp-chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  --sp-chat-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --sp-chat-radius: 16px;
  --sp-chat-radius-sm: 10px;
  --sp-chat-radius-xs: 6px;
  --sp-chat-transition: all 0.2s ease;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --sp-chat-transition: none;
  }
}

/* Screen Reader Only */
.sp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =============================================
   Widget Container
   ============================================= */
.sp-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .sp-chat-widget {
    bottom: 16px;
    right: 16px;
  }
}

/* =============================================
   Launcher Button
   ============================================= */
.sp-chat-launcher {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--sp-chat-primary);
  border: none;
  cursor: pointer;
  box-shadow: var(--sp-chat-shadow);
  transition: var(--sp-chat-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 22px;
}

.sp-chat-launcher:hover {
  transform: scale(1.05);
  background: var(--sp-chat-primary-dark);
}

.sp-chat-launcher:focus {
  outline: none;
  box-shadow: var(--sp-chat-shadow), 0 0 0 3px rgba(45, 90, 48, 0.3);
}

/* =============================================
   Chat Panel
   ============================================= */
.sp-chat-panel {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 100px);
  background: var(--sp-chat-white);
  border-radius: var(--sp-chat-radius);
  box-shadow: var(--sp-chat-shadow);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.98);
  transition: var(--sp-chat-transition);
  overflow: hidden;
}

.sp-chat-open .sp-chat-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

@media (max-width: 480px) {
  .sp-chat-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
    bottom: 76px;
  }
}

/* =============================================
   Header
   ============================================= */
.sp-chat-header {
  background: linear-gradient(135deg, #2d5a30, #1e3d20);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  color: #ffffff !important;
}

.sp-chat-header * {
  color: #ffffff !important;
}

.sp-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sp-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.sp-chat-avatar img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.sp-chat-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sp-chat-header-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: #ffffff !important;
}

.sp-chat-header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9) !important;
  display: flex;
  align-items: center;
  gap: 5px;
}

.sp-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80 !important;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.sp-chat-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: var(--sp-chat-transition);
}

.sp-chat-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* =============================================
   Disclaimer Banner
   ============================================= */
.sp-chat-disclaimer {
  background: var(--sp-chat-gray-100);
  padding: 8px 14px;
  font-size: 11px;
  color: var(--sp-chat-gray-500);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.sp-chat-disclaimer i {
  color: var(--sp-chat-gray-400);
  font-size: 10px;
}

/* =============================================
   Messages Container
   ============================================= */
.sp-chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0; /* Important for flex scroll */
  /* Removed justify-content: flex-end - it breaks scrolling */
}

/* =============================================
   Chat Messages
   ============================================= */
.sp-chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: sp-msg-in 0.2s ease;
}

@keyframes sp-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.sp-chat-message-user {
  align-self: flex-end;
}

.sp-chat-message-assistant {
  align-self: flex-start;
}

.sp-chat-message-content {
  padding: 10px 14px;
  border-radius: var(--sp-chat-radius-sm);
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
}

.sp-chat-message-user .sp-chat-message-content {
  background: var(--sp-chat-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.sp-chat-message-assistant .sp-chat-message-content {
  background: var(--sp-chat-gray-100);
  color: var(--sp-chat-gray-800);
  border-bottom-left-radius: 4px;
}

.sp-chat-message-content strong {
  font-weight: 600;
}

.sp-chat-message-assistant .sp-chat-message-content strong {
  color: var(--sp-chat-primary-dark);
}

.sp-chat-message-time {
  font-size: 10px;
  color: var(--sp-chat-gray-400);
  margin-top: 4px;
  padding: 0 2px;
}

.sp-chat-message-user .sp-chat-message-time {
  text-align: right;
}

/* Typing Indicator */
.sp-chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--sp-chat-gray-100);
  border-radius: var(--sp-chat-radius-sm);
  width: fit-content;
}

.sp-typing-dots {
  display: flex;
  gap: 4px;
}

.sp-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--sp-chat-gray-400);
  border-radius: 50%;
  animation: sp-bounce 1.4s infinite ease-in-out;
}

.sp-typing-dots span:nth-child(1) { animation-delay: 0s; }
.sp-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.sp-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sp-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* =============================================
   Quick Action Chips
   ============================================= */
.sp-chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-bottom: 4px;
}

.sp-quick-action {
  padding: 8px 14px;
  background: white;
  border: 1.5px solid var(--sp-chat-gray-300);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--sp-chat-gray-700);
  cursor: pointer;
  transition: var(--sp-chat-transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sp-quick-action:hover {
  background: var(--sp-chat-primary);
  border-color: var(--sp-chat-primary);
  color: white;
}

.sp-quick-action i {
  font-size: 11px;
}

/* =============================================
   Inline Form Card (Fills 85-90% of chat)
   ============================================= */
.sp-inline-card {
  background: white;
  border: 1.5px solid var(--sp-chat-gray-200);
  border-radius: var(--sp-chat-radius);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  width: 100%;
  min-height: 380px;
  max-height: calc(100% - 20px);
  animation: sp-msg-in 0.2s ease;
  display: flex;
  flex-direction: column;
}

.sp-inline-card-header {
  background: linear-gradient(135deg, #2d5a30, #1e3d20);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sp-inline-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.sp-inline-card-title i {
  font-size: 16px;
}

.sp-inline-card-step {
  font-size: 11px;
  opacity: 0.8;
}

.sp-inline-card-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  cursor: pointer;
  padding: 6px 10px;
  font-size: 18px;
  line-height: 1;
  border-radius: 6px;
}

.sp-inline-card-close:hover {
  background: rgba(255,255,255,0.3);
}

.sp-inline-card-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
  transition: max-height 0.25s ease, opacity 0.2s ease;
}

.sp-inline-card.collapsed .sp-inline-card-body {
  max-height: 0;
  padding: 0 18px;
  opacity: 0;
}

/* Form Fields */
.sp-form-group {
  margin-bottom: 14px;
}

.sp-form-group:last-child {
  margin-bottom: 0;
}

.sp-form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--sp-chat-gray-600);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

.sp-form-label .required {
  color: var(--sp-chat-danger);
}

.sp-form-input,
.sp-form-select,
.sp-form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--sp-chat-gray-200);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  transition: var(--sp-chat-transition);
  background: var(--sp-chat-gray-50);
}

.sp-form-input:focus,
.sp-form-select:focus,
.sp-form-textarea:focus {
  outline: none;
  border-color: var(--sp-chat-primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(45, 90, 48, 0.1);
}

.sp-form-input::placeholder {
  color: var(--sp-chat-gray-400);
}

.sp-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sp-phone-row {
  display: flex;
  gap: 8px;
}

.sp-phone-row select {
  width: 80px;
  flex-shrink: 0;
}

.sp-phone-row input {
  flex: 1;
}

/* Form Actions */
.sp-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.sp-btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: var(--sp-chat-radius-xs);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--sp-chat-transition);
  border: none;
}

.sp-btn-primary {
  background: var(--sp-chat-primary);
  color: white;
}

.sp-btn-primary:hover {
  background: var(--sp-chat-primary-dark);
}

.sp-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.sp-btn-secondary {
  background: var(--sp-chat-gray-100);
  color: var(--sp-chat-gray-600);
}

.sp-btn-secondary:hover {
  background: var(--sp-chat-gray-200);
}

/* =============================================
   Review State
   ============================================= */
.sp-review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sp-review-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--sp-chat-gray-50);
  border-radius: var(--sp-chat-radius-xs);
  font-size: 13px;
}

.sp-review-item-label {
  color: var(--sp-chat-gray-500);
  font-size: 11px;
}

.sp-review-item-value {
  color: var(--sp-chat-gray-800);
  font-weight: 500;
}

.sp-review-item-edit {
  background: none;
  border: none;
  color: var(--sp-chat-primary);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 11px;
}

.sp-review-item-edit:hover {
  text-decoration: underline;
}

/* =============================================
   Success State
   ============================================= */
.sp-success-card {
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  border: 1px solid #a7f3d0;
  border-radius: var(--sp-chat-radius-sm);
  padding: 14px;
  text-align: center;
}

.sp-success-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.sp-success-title {
  font-size: 15px;
  font-weight: 600;
  color: #065f46;
  margin: 0 0 4px;
}

.sp-success-detail {
  font-size: 13px;
  color: #047857;
  margin: 0;
}

.sp-success-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--sp-chat-primary);
  text-decoration: none;
}

.sp-success-link:hover {
  text-decoration: underline;
}

/* =============================================
   Input Container
   ============================================= */
.sp-chat-input-container {
  padding: 12px 14px;
  border-top: 1px solid var(--sp-chat-gray-200);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: white;
}

.sp-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--sp-chat-gray-200);
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  transition: var(--sp-chat-transition);
}

.sp-chat-input:focus {
  outline: none;
  border-color: var(--sp-chat-primary);
}

.sp-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--sp-chat-primary);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--sp-chat-transition);
  flex-shrink: 0;
}

.sp-chat-send:hover {
  background: var(--sp-chat-primary-dark);
}

.sp-chat-send:disabled {
  background: var(--sp-chat-gray-300);
  cursor: not-allowed;
}

/* =============================================
   Contact Form (Same inline style)
   ============================================= */
.sp-contact-card {
  background: white;
  border: 1px solid var(--sp-chat-gray-200);
  border-radius: var(--sp-chat-radius-sm);
  box-shadow: var(--sp-chat-shadow-sm);
  overflow: hidden;
  max-width: 100%;
  animation: sp-msg-in 0.2s ease;
}

/* =============================================
   Mobile Adjustments
   ============================================= */
@media (max-width: 480px) {
  .sp-form-row {
    grid-template-columns: 1fr;
  }
  
  .sp-chat-messages {
    padding: 12px;
  }
}

/* =============================================
   Print - Hide widget
   ============================================= */
@media print {
  .sp-chat-widget {
    display: none !important;
  }
}
