/* AVIHPSAM Chat Panel Styles - chat.css */

/* ============================================
   CHAT PANEL
   ============================================ */

.chat-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 400px;
  max-width: 100vw;
  height: 70vh;
  max-height: 600px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transform: translateY(100%);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

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

/* Chat Overlay */
.chat-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.chat-overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* ============================================
   CHAT HEADER
   ============================================ */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background-color: var(--color-primary);
  color: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  flex-shrink: 0;
}

.chat-header h3 {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  margin: 0;
  color: white;
}

.chat-close {
  background: none;
  border: none;
  color: white;
  font-size: var(--text-xl);
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}

.chat-close:hover {
  opacity: 1;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.chat-expand {
  background: none;
  border: none;
  color: white;
  font-size: var(--text-lg);
  cursor: pointer;
  padding: var(--space-xs);
  line-height: 1;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
  text-decoration: none;
}

.chat-expand:hover {
  opacity: 1;
  color: white;
}

.chat-new {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-sm, 4px);
  color: white;
  font-size: var(--text-lg, 1.125rem);
  font-weight: 300;
  cursor: pointer;
  padding: 0 var(--space-xs, 0.5rem);
  line-height: 1.2;
  opacity: 0.8;
  transition: all var(--transition-fast, 0.15s);
}

.chat-new:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
  border-color: white;
}

/* Chat Header Layout */
.chat-header {
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
}

.chat-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

/* User Mode Badge */
.chat-mode-badge {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-xs);
  opacity: 0.9;
  background: rgba(255, 255, 255, 0.1);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  width: fit-content;
}

.chat-mode-label {
  opacity: 0.8;
}

.chat-mode-value {
  font-weight: var(--font-semibold);
  text-transform: capitalize;
}

/* Mode-specific colors */
.chat-mode-badge[data-mode="student"] {
  background: rgba(34, 197, 94, 0.2);
}

.chat-mode-badge[data-mode="teacher"] {
  background: rgba(59, 130, 246, 0.2);
}

.chat-mode-badge[data-mode="researcher"] {
  background: rgba(168, 85, 247, 0.2);
}

.chat-mode-badge[data-mode="curious"] {
  background: rgba(234, 179, 8, 0.2);
}

/* ============================================
   EVIDENCE TIER BADGES
   ============================================ */

.tier-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 600;
  margin-left: 4px;
  vertical-align: middle;
}

.tier-badge-1a,
.tier-badge-1b,
.tier-badge-1c,
.tier-1a,
.tier-1b,
.tier-1c {
  background: #22c55e;
  color: white;
}

.tier-badge-2,
.tier-2 {
  background: #eab308;
  color: black;
}

.tier-badge-3,
.tier-3 {
  background: #3b82f6;
  color: white;
}

.tier-badge-4,
.tier-4 {
  background: #ef4444;
  color: white;
  animation: tier-pulse 2s infinite;
}

@keyframes tier-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* ============================================
   CHAT MESSAGES
   ============================================ */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* Message Bubbles */
.message {
  max-width: 85%;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  line-height: var(--leading-relaxed);
  font-size: var(--text-base);
}

.message p {
  margin-bottom: var(--space-sm);
}

.message p:last-child {
  margin-bottom: 0;
}

/* User Message */
.message.user {
  align-self: flex-end;
  background-color: var(--color-accent);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

/* Assistant Message */
.message.assistant {
  align-self: flex-start;
  background-color: var(--color-background-alt);
  color: var(--color-text);
  border-bottom-left-radius: var(--radius-sm);
}

/* Message Content Formatting */
.message strong {
  font-weight: var(--font-semibold);
}

.message .tier-badge {
  display: inline-flex;
  margin: var(--space-xs) 0;
}

/* Typing Indicator */
.message.typing {
  display: flex;
  gap: 4px;
  padding: var(--space-md);
}

.message.typing span {
  width: 8px;
  height: 8px;
  background-color: var(--color-text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.message.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.message.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-8px);
  }
}

/* Error Message */
.message.error {
  background-color: var(--tier-4-bg);
  color: var(--tier-4);
  border: 1px solid var(--tier-4);
}

/* ============================================
   CHAT SUGGESTIONS
   ============================================ */

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding: 0 var(--space-md) var(--space-sm);
  flex-shrink: 0;
}

.chat-suggestions .suggestion {
  padding: var(--space-xs) var(--space-sm);
  background-color: var(--color-background-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-suggestions .suggestion:hover {
  background-color: var(--color-secondary);
  border-color: var(--color-secondary);
  color: var(--color-text);
}

/* Resource Buttons */
.chat-suggestions .suggestion.resource {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* ============================================
   CHAT INPUT
   ============================================ */

.chat-input-form {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-top: 1px solid var(--color-border);
  background-color: var(--color-surface);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-base);
  background-color: var(--color-background);
  transition: all var(--transition-fast);
}

#chat-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(46, 90, 76, 0.1);
}

#chat-input::placeholder {
  color: var(--color-text-muted);
}

.chat-send {
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.chat-send:hover {
  background-color: var(--color-accent-light);
}

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

/* ============================================
   CHAT HEADER ENHANCEMENTS
   ============================================ */

.chat-header-info {
  display: flex;
  flex-direction: column;
}

.chat-header-status {
  font-size: var(--text-xs);
  opacity: 0.8;
  font-weight: normal;
}

.chat-header-status.online::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: #4CAF50;
  border-radius: 50%;
  margin-right: 6px;
  animation: pulse-online 2s infinite;
}

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

.chat-header-actions {
  display: flex;
  gap: var(--space-xs);
}

.chat-header-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.chat-header-btn:hover {
  background: rgba(255,255,255,0.3);
}

/* ============================================
   TOPIC CONTEXT BAR
   ============================================ */

.chat-context {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-background-alt);
  border-bottom: 1px solid var(--color-border-light);
  font-size: var(--text-sm);
}

.chat-context-label {
  color: var(--color-text-muted);
}

.chat-context-topic {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background-color: var(--color-surface);
  border-radius: var(--radius-full);
  font-weight: var(--font-medium);
  color: var(--color-primary);
}

.chat-context-clear {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: var(--text-xs);
}

.chat-context-clear:hover {
  color: var(--color-text);
}

/* ============================================
   ENHANCED MESSAGE STYLES
   ============================================ */

.message-wrapper {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-wrapper.user {
  align-items: flex-end;
}

.message-wrapper.assistant {
  align-items: flex-start;
}

.message-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Message metadata row */
.message-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-xs);
}

/* Provider badge */
.provider-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.provider-gemini {
  background-color: #e8f0fe;
  color: #1a73e8;
}

.provider-groq {
  background-color: #fff3e0;
  color: #e65100;
}

.provider-claude {
  background-color: #fce4ec;
  color: #c2185b;
}

.provider-mock {
  background-color: #f3e5f5;
  color: #7b1fa2;
}

.provider-unknown {
  background-color: #eceff1;
  color: #546e7a;
}

.message-status {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.message-status.sent::after { content: '✓'; }
.message-status.delivered::after { content: '✓✓'; }
.message-status.read::after { content: '✓✓'; color: var(--color-accent); }

/* Message with avatar */
.message-with-avatar {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  flex-shrink: 0;
}

/* ============================================
   RICH MESSAGE CONTENT
   ============================================ */

/* Source Citation in Chat */
.chat-source {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  margin: var(--space-sm) 0;
  border-left: 3px solid var(--color-secondary);
}

.chat-source-icon {
  flex-shrink: 0;
  font-size: 1rem;
}

.chat-source-text {
  flex: 1;
}

.chat-source-title {
  font-weight: var(--font-medium);
  color: var(--color-primary);
}

.chat-source-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Inquiry Prompt in Chat */
.chat-inquiry {
  padding: var(--space-sm) var(--space-md);
  background-color: rgba(46, 90, 76, 0.1);
  border-left: 3px solid var(--color-accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  margin-top: var(--space-sm);
  color: var(--color-accent);
}

.chat-inquiry::before {
  content: '💭 ';
}

/* Evidence Tier Block in Chat */
.chat-tier-block {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  background-color: white;
  border-radius: var(--radius-sm);
  margin: var(--space-xs) 0;
  border: 1px solid var(--color-border-light);
}

/* Code blocks in chat */
.message pre {
  background-color: rgba(0, 0, 0, 0.05);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: var(--text-sm);
  margin: var(--space-sm) 0;
}

.message code {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}

/* Lists in messages */
.message ul, .message ol {
  margin: var(--space-sm) 0;
  padding-left: var(--space-lg);
}

.message li {
  margin-bottom: var(--space-xs);
  margin-left: 25px;
}

/* Headings in messages */
.message h4 {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-primary);
  margin: var(--space-sm) 0 var(--space-xs);
}

/* Links in messages */
.message a {
  color: var(--color-accent);
  text-decoration: underline;
}

.message.user a {
  color: white;
}

/* Blockquotes */
.message blockquote {
  border-left: 3px solid var(--color-secondary);
  padding-left: var(--space-sm);
  margin: var(--space-sm) 0;
  font-style: italic;
  color: var(--color-text-light);
}

/* ============================================
   QUICK ACTIONS
   ============================================ */

.chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.chat-quick-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-xs) var(--space-sm);
  background-color: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.chat-quick-action-icon {
  font-size: 0.875rem;
}

/* ============================================
   FEEDBACK BUTTONS
   ============================================ */

.message-feedback {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.message-wrapper:hover .message-feedback {
  opacity: 1;
}

.feedback-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
  font-size: var(--text-sm);
}

.feedback-btn:hover {
  opacity: 1;
}

.feedback-btn.active {
  opacity: 1;
}

/* ============================================
   LOADING & EMPTY STATES
   ============================================ */

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-muted);
}

.chat-empty-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

.chat-empty-title {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.chat-empty-text {
  font-size: var(--text-sm);
  max-width: 250px;
}

/* Thinking indicator */
.message.thinking {
  background-color: transparent;
  padding: var(--space-sm);
}

.thinking-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.thinking-indicator .loading-spinner {
  width: 16px;
  height: 16px;
}

/* ============================================
   ENHANCED SUGGESTIONS
   ============================================ */

.chat-suggestions-header {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-xs) var(--space-md) 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.suggestion-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.suggestion.primary {
  background-color: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.suggestion.primary:hover {
  background-color: var(--color-accent-light);
  border-color: var(--color-accent-light);
}

/* ============================================
   EXPANDED VIEW
   ============================================ */

.chat-panel.expanded {
  width: 600px;
  max-width: 90vw;
  height: 80vh;
  max-height: 700px;
}

.chat-expand-btn {
  display: none;
}

@media (min-width: 769px) {
  .chat-expand-btn {
    display: flex;
  }
}

/* ============================================
   MOBILE STYLES
   ============================================ */

@media (max-width: 768px) {
  .chat-panel {
    width: 100%;
    height: 80vh;
    max-height: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    right: 0;
    left: 0;
  }

  .chat-header {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .message {
    max-width: 90%;
  }

  .chat-suggestions {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: var(--space-sm);
  }

  .chat-suggestions::-webkit-scrollbar {
    display: none;
  }

  .chat-suggestions .suggestion {
    flex-shrink: 0;
  }
}

/* ============================================
   FULLSCREEN MODE (Optional)
   ============================================ */

.chat-panel.fullscreen {
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.chat-panel.fullscreen .chat-header {
  border-radius: 0;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.chat-panel:focus-within {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

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

/* Focus Visible for Chat Elements */
.chat-suggestions .suggestion:focus-visible,
.chat-send:focus-visible,
.chat-close:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

#chat-input:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ============================================
   CLICKABLE FOLLOW-UP QUESTIONS
   ============================================ */

.chat-followup-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}

.followup-question {
  background-color: var(--color-surface-alt, #f5f5f0);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full, 9999px);
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast, 0.15s);
  text-align: left;
  line-height: 1.3;
}

.followup-question:hover {
  background-color: var(--color-accent, #8B4513);
  color: white;
  border-color: var(--color-accent, #8B4513);
  transform: translateY(-1px);
}

.followup-question:active {
  transform: translateY(0);
}

/* ============================================
   DETAILS BUTTON (in meta row, right-aligned)
   ============================================ */

.chat-details-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background-color: transparent;
  color: var(--color-primary, #2c5530);
  border: 1px solid var(--color-primary, #2c5530);
  border-radius: var(--radius-sm, 4px);
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-left: auto;
}

.chat-details-btn:hover {
  background-color: var(--color-primary, #2c5530);
  color: white;
}

/* ============================================
   SOURCES SECTION
   ============================================ */

.chat-sources-section {
  background-color: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
}

.sources-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: #6c757d;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.source-item {
  font-size: 0.8125rem;
  color: #495057;
  padding: 0.25rem 0;
  border-bottom: 1px solid #e9ecef;
}

.source-item:last-child {
  border-bottom: none;
}

/* ============================================
   FOLLOW-UP SECTION
   ============================================ */

.chat-followup-section {
  background-color: #f0f8ff;
  border: 1px solid #cce5ff;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
}

.followup-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: #0056b3;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ============================================
   PANEL-SPECIFIC FOLLOW-UP BUTTONS
   ============================================ */

.chat-panel .chat-followup-questions {
  pointer-events: auto;
  position: relative;
  z-index: 10;
}

.chat-panel .followup-question {
  pointer-events: auto;
  cursor: pointer;
  background-color: #f5f5f0;
  border: 1px solid #e0ddd5;
  color: #333;
  white-space: normal;
  text-align: left;
  max-width: 100%;
}

.chat-panel .followup-question:hover {
  background-color: #8B4513;
  color: white;
  border-color: #8B4513;
  transform: translateY(-1px);
}

.chat-panel .followup-question:active {
  transform: translateY(0);
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .chat-panel,
  .chat-overlay {
    display: none !important;
  }
}
