/* ==========================================================================
   ScholarHubGo — Floating AI Academic Advisor & Chat Widget
   File: chat-widget.css
   Universal Responsive & Cross-Screen Compatibility
   ========================================================================== */

#scholarloop-ai-chat-container {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  inset-inline-start: max(16px, env(safe-area-inset-left, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  right: auto;
  z-index: 10000;
  font-family: var(--font-sans, 'Plus Jakarta Sans', 'Cairo', sans-serif);
  max-width: calc(100vw - 32px);
}

[dir="ltr"] #scholarloop-ai-chat-container {
  left: auto;
  right: max(16px, env(safe-area-inset-right, 0px));
  inset-inline-start: auto;
  inset-inline-end: max(16px, env(safe-area-inset-right, 0px));
}

[dir="rtl"] #scholarloop-ai-chat-container {
  right: auto;
  left: max(16px, env(safe-area-inset-left, 0px));
  inset-inline-end: auto;
  inset-inline-start: max(16px, env(safe-area-inset-left, 0px));
}

.ai-chat-fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 12px 14px;
  border-radius: 30px;
  background: linear-gradient(135deg, #0A1F44 0%, #152C59 50%, #C9A961 150%);
  border: 1.5px solid var(--color-gold-light, #E8D9A8);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(201, 169, 97, 0.35);
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ai-chat-fab:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6), 0 0 30px rgba(201, 169, 97, 0.5);
}

.ai-fab-icon-wrap {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C9A961 0%, #A68744 100%);
  color: #060F24;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-fab-icon-wrap i, .ai-fab-icon-wrap svg {
  width: 18px;
  height: 18px;
}

.ai-fab-sparkle {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 12px !important;
  height: 12px !important;
  color: #ffffff !important;
  animation: spin 4s linear infinite;
}

.ai-fab-label {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--color-gold-light, #E8D9A8);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.ai-fab-badge {
  background: #ef4444;
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 10px;
}

/* Chat Window Panel */
.ai-chat-window {
  position: absolute;
  bottom: calc(100% + 14px);
  left: 0;
  inset-inline-start: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(560px, calc(100dvh - 120px));
  max-height: calc(100dvh - 100px);
  background: rgba(6, 15, 36, 0.96);
  border: 1.5px solid rgba(201, 169, 97, 0.38);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75), 0 0 35px rgba(201, 169, 97, 0.2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom left;
}

[dir="ltr"] .ai-chat-window {
  left: auto;
  right: 0;
  inset-inline-start: auto;
  inset-inline-end: 0;
  transform-origin: bottom right;
}

[dir="rtl"] .ai-chat-window {
  right: auto;
  left: 0;
  inset-inline-end: auto;
  inset-inline-start: 0;
  transform-origin: bottom left;
}

.ai-chat-window.hidden {
  display: none !important;
}

.ai-chat-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(10, 31, 68, 0.95) 0%, rgba(13, 35, 76, 0.95) 100%);
  border-bottom: 1px solid rgba(201, 169, 97, 0.22);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ai-chat-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #C9A961 0%, #0A1F44 100%);
  border: 1px solid var(--color-gold-light, #E8D9A8);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-status-dot.online {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid #060F24;
}

.ai-chat-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--color-gold-light, #E8D9A8);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.ai-model-badge {
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(6, 182, 212, 0.2);
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: #38bdf8;
}

.ai-chat-status {
  font-size: 11px;
  color: var(--text-muted, #94A3B8);
  margin: 0;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chat-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.ai-header-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted, #94A3B8);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.ai-header-btn:hover {
  background: rgba(201, 169, 97, 0.2);
  color: var(--color-gold-light, #E8D9A8);
  border-color: var(--color-gold-light, #E8D9A8);
}

.ai-header-btn i, .ai-header-btn svg {
  width: 15px;
  height: 15px;
}

/* Quick Chips */
.ai-quick-chips-wrapper {
  padding: 10px 14px 6px;
  background: rgba(10, 31, 68, 0.5);
  border-bottom: 1px solid rgba(201, 169, 97, 0.12);
  flex-shrink: 0;
}

.ai-quick-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.ai-quick-chips::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  flex-shrink: 0;
  background: rgba(13, 35, 76, 0.85);
  border: 1px solid rgba(201, 169, 97, 0.25);
  color: var(--color-gold-light, #E8D9A8);
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ai-chip:hover {
  background: rgba(201, 169, 97, 0.22);
  border-color: var(--color-accent, #C9A961);
  transform: translateY(-1px);
}

/* Messages */
.ai-chat-messages {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(6, 15, 36, 0.4);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: fadeIn 0.25s ease;
}

.ai-msg.user {
  align-self: flex-start;
}

[dir="rtl"] .ai-msg.user {
  align-self: flex-start;
}

[dir="ltr"] .ai-msg.user {
  align-self: flex-end;
}

.ai-msg.bot {
  align-self: flex-end;
}

[dir="rtl"] .ai-msg.bot {
  align-self: flex-end;
}

[dir="ltr"] .ai-msg.bot {
  align-self: flex-start;
}

.ai-msg-bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  position: relative;
  word-break: break-word;
  overflow-wrap: break-word;
}

.ai-msg.user .ai-msg-bubble {
  background: linear-gradient(135deg, #152C59 0%, #0A1F44 100%);
  color: #ffffff;
  border: 1px solid rgba(201, 169, 97, 0.3);
  border-bottom-left-radius: 4px;
}

.ai-msg.bot .ai-msg-bubble {
  background: rgba(13, 35, 76, 0.88);
  color: var(--text-primary, #F8FAFC);
  border: 1px solid rgba(201, 169, 97, 0.2);
  border-bottom-right-radius: 4px;
}

.ai-msg-time {
  font-size: 10px;
  color: var(--text-muted, #94A3B8);
  margin-top: 4px;
  padding: 0 4px;
}

/* Embedded Scholarship Card in Bot */
.ai-sch-card {
  margin-top: 8px;
  background: rgba(10, 31, 68, 0.9);
  border: 1px solid rgba(201, 169, 97, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-sch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-gold-light, #E8D9A8);
}

.ai-sch-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.ai-sch-btn {
  flex: 1;
  min-width: 110px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border-color, rgba(201, 169, 97, 0.22));
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-gold-light, #E8D9A8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ai-sch-btn:hover {
  background: var(--color-accent, #C9A961);
  color: #060F24;
  border-color: var(--color-accent, #C9A961);
}

.ai-sch-btn.primary {
  background: rgba(201, 169, 97, 0.2);
  border-color: var(--color-accent, #C9A961);
}

/* Typing indicator */
.ai-typing-indicator {
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--color-gold-light, #E8D9A8);
  flex-shrink: 0;
}

.ai-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent, #C9A961);
  animation: bounce 1.2s infinite ease-in-out;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Chat Input Bar */
.ai-chat-input-bar {
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  background: rgba(10, 31, 68, 0.95);
  border-top: 1px solid rgba(201, 169, 97, 0.2);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.ai-chat-input-bar input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color, rgba(201, 169, 97, 0.22));
  border-radius: 12px;
  color: var(--text-primary, #F8FAFC);
  padding: 10px 12px;
  font-size: 16px !important; /* Prevents Safari auto-zoom on iPhone */
  outline: none;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.ai-chat-input-bar input:focus {
  border-color: var(--color-accent, #C9A961);
}

.ai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #C9A961 0%, #A68744 100%);
  border: none;
  color: #060F24;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ai-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(201, 169, 97, 0.4);
}

.ai-send-btn i, .ai-send-btn svg {
  width: 18px;
  height: 18px;
}

/* Mobile & Small Screen Media Queries */
@media (max-width: 640px) {
  .ai-chat-window {
    position: fixed;
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: calc(75px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: calc(100vw - 20px);
    height: min(520px, calc(100dvh - 95px));
    max-height: calc(100dvh - 90px);
    border-radius: 18px;
    transform-origin: bottom center;
    z-index: 100001;
  }

  [dir="ltr"] .ai-chat-window,
  [dir="rtl"] .ai-chat-window {
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 480px) {
  #scholarloop-ai-chat-container {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    right: auto;
    max-width: calc(100vw - 24px);
  }

  [dir="ltr"] #scholarloop-ai-chat-container {
    left: auto;
    right: max(12px, env(safe-area-inset-right, 0px));
  }

  .ai-chat-fab {
    padding: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    justify-content: center;
    gap: 0;
  }

  .ai-fab-label {
    display: none;
  }

  .ai-fab-icon-wrap {
    width: 34px;
    height: 34px;
  }

  .ai-fab-sparkle {
    top: -2px;
    right: -2px;
  }
}
