/* Base styles */
#learnfoAIButton {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #4f46e5;
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 25px;
  cursor: pointer;
  z-index: 9999;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
}

#learnfoAIButton:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

#learnfoAIPanel {
  position: fixed;
  top: 0;
  right: -100%;
  width: 100%;
  height: 100%;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease-out;
  z-index: 10000;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

#learnfoAIPanel.open {
  right: 0;
}

.ai-header {
  padding: 16px 20px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 18px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

#closeLearnfoAI {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
}

#closeLearnfoAI:active {
  background-color: #f3f4f6;
}

.ai-chat {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 20px;
}

.ai-msg {
  background: #e5e7eb;
  padding: 12px 16px;
  border-radius: 18px;
  margin-bottom: 12px;
  font-size: 15px;
  line-height: 1.4;
  max-width: 85%;
  word-wrap: break-word;
  hyphens: auto;
}

.ai-msg.user {
  background: #4f46e5;
  color: #fff;
  text-align: right;
  margin-left: auto;
  border-bottom-right-radius: 6px;
}

.ai-msg:not(.user) {
  border-bottom-left-radius: 6px;
}

.ai-suggestions {
  padding: 16px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.ai-suggestions button {
  flex: 1;
  min-width: 120px;
  max-width: 180px;
  padding: 10px 16px;
  border-radius: 20px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-suggestions button:active {
  background: #4f46e5;
  color: white;
  border-color: #4f46e5;
  transform: scale(0.98);
}

.ai-input {
  display: flex;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  padding: 12px 16px;
  align-items: center;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

.ai-input input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #d1d5db;
  border-radius: 24px;
  font-size: 16px;
  margin-right: 8px;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  min-height: 48px;
}

.ai-input input:focus {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.ai-input button {
  padding: 12px 20px;
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background-color 0.2s, transform 0.2s;
  flex-shrink: 0;
}

.ai-input button:active {
  background: #4338ca;
  transform: scale(0.95);
}

/* Prevent zoom on iOS when focusing input */
@media (max-width: 768px) {
  input, textarea, select {
    font-size: 16px !important;
  }
  
  .ai-input input {
    font-size: 16px !important;
  }
}

/* Tablet and Desktop (over 768px) */
@media (min-width: 769px) {
  #learnfoAIPanel {
    width: 400px;
    right: -400px;
  }
  
  .ai-msg {
    max-width: 75%;
  }
  
  .ai-suggestions button {
    min-width: 140px;
    padding: 12px 20px;
  }
  
  .ai-input {
    padding: 16px 20px;
  }
}

/* Very small phones (under 360px) */
@media (max-width: 360px) {
  .ai-header {
    padding: 14px 16px;
    font-size: 16px;
  }
  
  .ai-chat {
    padding: 12px;
  }
  
  .ai-msg {
    padding: 10px 14px;
    font-size: 14px;
    max-width: 90%;
  }
  
  .ai-suggestions {
    padding: 12px;
  }
  
  .ai-suggestions button {
    min-width: 100px;
    font-size: 13px;
    padding: 8px 12px;
  }
  
  .ai-input {
    padding: 10px 12px;
  }
  
  .ai-input input {
    padding: 10px 14px;
    min-height: 44px;
  }
  
  .ai-input button {
    width: 44px;
    height: 44px;
  }
}

/* Landscape orientation adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  #learnfoAIPanel {
    height: 100vh;
    overflow: hidden;
  }
  
  .ai-header {
    flex-shrink: 0;
  }
  
  .ai-suggestions {
    flex-shrink: 0;
    padding: 12px;
  }
  
  .ai-input {
    flex-shrink: 0;
  }
  
  .ai-chat {
    flex: 1;
    overflow-y: auto;
  }
}

/* Safe area insets for notched phones */
@supports (padding: max(0px)) {
  .ai-header,
  .ai-input {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  
  .ai-header {
    padding-top: max(16px, env(safe-area-inset-top));
  }
  
  .ai-input {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  
  #learnfoAIButton {
    right: max(20px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .ai-msg.user {
    background: #000;
    color: #fff;
  }
  
  .ai-input input {
    border-width: 2px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #learnfoAIPanel {
    transition: none;
  }
  
  .ai-msg {
    animation: none;
  }
  
  #learnfoAIButton {
    transition: none;
  }
}