/* ============================================
   CHAT PAGE - Full-Page Chat Interface
   Follows AVIHPSAM Design System (main.css)
   ============================================ */

/* Reset body for full-page chat */
.chat-page-body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100vh;
  background-color: var(--color-background);
  font-family: var(--font-body);
}

/* Main container */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

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

.chat-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  flex-shrink: 0;
  height: var(--header-height);
  z-index: 100;
}

.chat-page-header-left,
.chat-page-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-page-header-center {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-page-header-center h1 {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-primary);
  margin: 0;
  letter-spacing: 0.02em;
}

.chat-topic-badge {
  background-color: var(--color-background-alt);
  color: var(--color-primary);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  text-transform: capitalize;
}

.chat-back-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-text);
  text-decoration: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  font-size: var(--text-base);
}

.chat-back-btn:hover {
  background-color: var(--color-background-alt);
  color: var(--color-primary);
  text-decoration: none;
}

.mode-select {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-select:hover {
  border-color: var(--color-primary);
}

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

.mode-select option {
  color: var(--color-text);
  background-color: var(--color-surface);
}

.export-pdf-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  transition: all var(--transition-fast);
}

.export-pdf-btn:hover {
  background-color: var(--color-background-alt);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.export-pdf-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.export-pdf-btn .spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-accent);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  transition: background-color var(--transition-fast);
}

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

/* ============================================
   CONTENT AREA
   ============================================ */

.chat-page-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ============================================
   SIDEBAR - ChatGPT Style
   ============================================ */

.chat-sidebar {
  width: 260px;
  background-color: var(--color-background-alt);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-section {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Topics section - 60% height */
.sidebar-section.topics-section {
  flex: 0 0 60%;
  border-bottom: 1px solid var(--color-border);
}

/* Join Us section - 40% height */
.sidebar-section.join-section {
  flex: 0 0 40%;
  background: linear-gradient(180deg, var(--color-background-alt) 0%, var(--color-border-light) 100%);
}

.sidebar-section:last-child {
  border-bottom: none;
}

.sidebar-title {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  margin: 0 0 var(--space-md) var(--space-xs);
}

/* Sidebar search */
.sidebar-search {
  margin-bottom: var(--space-md);
}

.sidebar-search input {
  width: 100%;
  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-sm);
  background-color: var(--color-surface);
  transition: all var(--transition-fast);
  color: var(--color-text);
}

.sidebar-search input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(46, 90, 76, 0.1);
  background-color: var(--color-surface);
}

.sidebar-search input::placeholder {
  color: var(--color-text-muted);
}

/* Topic list */
.topic-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
  padding-right: var(--space-xs);
  margin-right: calc(-1 * var(--space-xs));
}

/* Custom scrollbar */
.topic-nav::-webkit-scrollbar {
  width: 6px;
}

.topic-nav::-webkit-scrollbar-track {
  background: transparent;
}

.topic-nav::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: var(--radius-full);
}

.topic-nav::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted);
}

/* Topic link */
.chat-sidebar .topic-link {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text) !important;
  text-decoration: none !important;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  transition: all var(--transition-fast);
  cursor: pointer;
  background-color: transparent;
  border: 1px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-text-fill-color: var(--color-text);
}

.chat-sidebar .topic-link:hover {
  background-color: var(--color-surface);
  color: var(--color-primary) !important;
  -webkit-text-fill-color: var(--color-primary);
  text-decoration: none !important;
}

.chat-sidebar .topic-link:active {
  background-color: var(--color-border-light);
}

.chat-sidebar .topic-link.active {
  background-color: var(--color-surface);
  font-weight: var(--font-medium);
  color: var(--color-primary) !important;
  -webkit-text-fill-color: var(--color-primary);
  border-color: var(--color-border);
}

.chat-sidebar .topic-link:visited,
.chat-sidebar .topic-link:focus {
  color: var(--color-text) !important;
  -webkit-text-fill-color: var(--color-text);
  text-decoration: none !important;
  outline: none;
}

.no-topics {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-lg) var(--space-md);
  line-height: var(--leading-relaxed);
}

/* ============================================
   NO SEARCH RESULTS STATE
   ============================================ */

.no-search-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-lg) var(--space-md);
  gap: var(--space-sm);
}

.no-search-results p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: var(--leading-relaxed);
}

.no-search-results .no-search-hint {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  margin-top: var(--space-xs);
}

.start-chat-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  background-color: var(--color-accent);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  transition: all var(--transition-fast);
  margin-top: var(--space-md);
}

.start-chat-btn:hover {
  background-color: var(--color-accent-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.start-chat-btn:active {
  transform: translateY(0);
}

.start-chat-btn svg {
  flex-shrink: 0;
}

.no-search-results .no-search-note {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-sm);
  font-style: italic;
}

/* ============================================
   JOIN US SECTION
   ============================================ */

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

.join-intro {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--color-text-light);
}

.join-intro strong {
  color: var(--color-primary);
}

.join-roles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin: var(--space-xs) 0;
}

.join-role {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background-color: var(--tier-1-bg);
  border-radius: var(--radius-lg);
  font-size: var(--text-xs);
  color: var(--color-accent);
}

.join-role svg {
  width: 12px;
  height: 12px;
  opacity: 0.7;
}

.join-cta {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: auto;
}

.join-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.join-btn:hover {
  background-color: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  color: white;
  text-decoration: none;
}

.join-btn:active {
  transform: translateY(0);
}

.join-btn svg {
  width: 16px;
  height: 16px;
}

.join-note {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-align: center;
  line-height: var(--leading-normal);
}

/* Sidebar Videos */
.sidebar-videos {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-video {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
  transition: background-color 0.2s;
}

.sidebar-video:hover {
  background-color: var(--color-background-alt, #f5f5f0);
}

.sidebar-video-thumb {
  width: 60px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  background-color: #ddd;
}

.sidebar-video-info {
  flex: 1;
  min-width: 0;
}

.sidebar-video-title {
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-video-channel {
  font-size: 0.7rem;
  color: var(--color-text-muted, #666);
}

/* ============================================
   RIGHT PANEL - Question History
   ============================================ */

.chat-history-panel {
  width: 240px;
  background-color: var(--color-background-alt);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.history-section {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.history-title {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  margin: 0 0 var(--space-md) var(--space-xs);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex: 1;
  overflow-y: auto;
  padding-right: var(--space-xs);
  margin-right: calc(-1 * var(--space-xs));
}

/* Custom scrollbar for history list */
.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: var(--radius-full);
}

.history-list::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted);
}

/* Question item in history */
.history-question {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  transition: all var(--transition-fast);
  cursor: pointer;
  background-color: transparent;
  border: 1px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  gap: var(--space-sm);
}

.history-question:hover {
  background-color: var(--color-surface);
  color: var(--color-primary);
}

.history-question:active {
  background-color: var(--color-border-light);
}

.history-question .q-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-primary);
  color: white;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
}

.history-question .q-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-question .q-time {
  flex-shrink: 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.no-questions {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-lg) var(--space-md);
  line-height: var(--leading-relaxed);
}

/* ============================================
   MAIN CHAT AREA
   ============================================ */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  padding: 0 1rem;
}

/* Messages area - override chat.css styles for full page */
.chat-page .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Message styling adjustments for full page */
.chat-page .message {
  max-width: 85%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg, 12px);
  line-height: 1.6;
}

.chat-page .message.user {
  align-self: flex-end;
  background-color: var(--color-primary, #8B4513);
  color: white;
}

.chat-page .message.assistant {
  align-self: flex-start;
  background-color: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e0ddd5);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Suggestions */
.chat-page .chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  justify-content: center;
}

.chat-page .suggestion {
  background-color: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e0ddd5);
  border-radius: 9999px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-page .suggestion:hover {
  background-color: var(--color-primary, #8B4513);
  color: white;
  border-color: var(--color-primary, #8B4513);
}

/* Input form */
.chat-page .chat-input-form {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  background-color: var(--color-surface, #fff);
  border-top: 1px solid var(--color-border, #e0ddd5);
}

.chat-page #chat-input {
  flex: 1;
  padding: 0.875rem 1.25rem;
  border: 1px solid var(--color-border, #e0ddd5);
  border-radius: 9999px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-page #chat-input:focus {
  border-color: var(--color-primary, #8B4513);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
}

.chat-page .chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background-color: var(--color-primary, #8B4513);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.chat-page .chat-send:hover {
  background-color: var(--color-primary-dark, #6d3610);
}

.chat-page .chat-send:active {
  transform: scale(0.95);
}

/* Follow-up questions */
.chat-page .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, #e0ddd5);
}

.chat-page .followup-question {
  background-color: var(--color-background-alt, #f5f5f0);
  border: 1px solid var(--color-border, #e0ddd5);
  border-radius: 9999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-page .followup-question:hover {
  background-color: var(--color-primary, #8B4513);
  color: white;
  border-color: var(--color-primary, #8B4513);
}

/* ============================================
   MOBILE SIDEBAR TOGGLE
   ============================================ */

.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 80px;
  left: var(--space-md);
  width: 48px;
  height: 48px;
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
  background-color: var(--color-primary-dark);
  transform: scale(1.05);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Large screens */
@media (min-width: 1400px) {
  .chat-sidebar {
    width: 280px;
  }

  .chat-history-panel {
    width: 280px;
  }
}

/* Tablet */
@media (max-width: 1024px) {
  .chat-sidebar {
    width: 200px;
  }

  .chat-history-panel {
    width: 200px;
  }

  .chat-page-header-center h1 {
    font-size: 1rem;
  }

  .new-chat-btn span {
    display: none;
  }

  .chat-back-btn span {
    display: none;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .chat-page-header {
    padding: 0 var(--space-md);
  }

  .chat-page-header-center h1 {
    font-size: var(--text-base);
  }

  .chat-topic-badge {
    display: none;
  }

  /* Hide sidebar by default on mobile */
  .chat-sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    z-index: 90;
    box-shadow: var(--shadow-lg);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  /* Adjust section heights for mobile */
  .sidebar-section.topics-section {
    flex: 0 0 55%;
  }

  .sidebar-section.join-section {
    flex: 0 0 45%;
  }

  .join-intro {
    font-size: var(--text-xs);
  }

  .join-roles {
    gap: var(--space-xs);
  }

  .join-role {
    font-size: 10px;
    padding: 3px var(--space-sm);
  }

  /* Hide right panel on mobile */
  .chat-history-panel {
    display: none;
  }

  .sidebar-toggle {
    display: flex;
  }

  .chat-page .chat-container {
    padding: 0 0.5rem;
  }

  .chat-page .message {
    max-width: 90%;
    padding: 0.875rem 1rem;
  }

  .chat-page .chat-input-form {
    padding: 0.75rem;
  }

  .chat-page #chat-input {
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
  }

  .chat-page .chat-send {
    width: 44px;
    height: 44px;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .chat-page-header-right {
    gap: 0.5rem;
  }

  .mode-select {
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
  }

  .new-chat-btn {
    padding: 0.4rem 0.5rem;
  }

  .chat-page .suggestion {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
  }
}

/* ============================================
   WELCOME MESSAGE STYLING
   ============================================ */

.chat-page #chat-welcome {
  background-color: transparent;
  border: none;
  box-shadow: none;
  text-align: center;
  max-width: 600px;
  margin: 2rem auto;
  padding: 2rem;
}

.chat-page #chat-welcome p {
  margin: 0.5rem 0;
  color: var(--color-text, #333);
}

.chat-page #chat-welcome p:first-child {
  font-size: 1.25rem;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.chat-page .message.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1rem;
}

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

.chat-page .message.typing span:nth-child(1) {
  animation-delay: -0.32s;
}

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

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================================
   MESSAGE HIGHLIGHT (for scroll-to feature)
   ============================================ */

.chat-page .message-wrapper.highlight {
  animation: message-highlight 1.5s ease-out;
}

.chat-page .message-wrapper.highlight .message {
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.4);
}

@keyframes message-highlight {
  0% {
    background-color: rgba(139, 69, 19, 0.15);
  }
  100% {
    background-color: transparent;
  }
}

/* ============================================
   MICROPHONE BUTTON (Voice Input)
   ============================================ */

.chat-mic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background-color: #e8e4df;
  color: #666;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-mic:hover {
  background-color: #d9d4cd;
  color: #333;
}

.chat-mic:active {
  transform: scale(0.95);
}

/* Recording state - red with pulse animation */
.chat-mic.recording {
  background-color: #dc2626;
  color: white;
  animation: pulse-recording 1.5s ease-in-out infinite;
}

.chat-mic.recording:hover {
  background-color: #b91c1c;
}

@keyframes pulse-recording {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(220, 38, 38, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
  }
}

/* Hide mic button if speech recognition not supported */
.chat-mic.hidden {
  display: none;
}

/* Listening indicator text */
.chat-mic-status {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  margin-bottom: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.chat-mic.recording .chat-mic-status {
  opacity: 1;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .chat-mic {
    width: 40px;
    height: 40px;
  }
}

/* ============================================
   PODCAST / LISTEN CONTROLS
   ============================================ */

.podcast-controls {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.podcast-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-background-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.podcast-btn:hover {
  background-color: var(--color-surface);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.podcast-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Stop button - smaller, red tint */
.podcast-btn.podcast-stop {
  padding: var(--space-sm);
  background-color: var(--tier-4-bg);
  border-color: var(--tier-4);
  color: var(--tier-4);
}

.podcast-btn.podcast-stop:hover {
  background-color: var(--tier-4);
  color: white;
}

/* Playing/active state - green tint */
#podcast-pause-btn,
#podcast-resume-btn {
  background-color: var(--tier-1-bg);
  border-color: var(--tier-1);
  color: var(--tier-1);
}

#podcast-pause-btn:hover,
#podcast-resume-btn:hover {
  background-color: var(--tier-1);
  color: white;
}

/* Message reading highlight */
.chat-page .message-wrapper.reading {
  position: relative;
}

.chat-page .message-wrapper.reading::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 0;
  bottom: 0;
  width: 4px;
  background-color: var(--color-primary, #8B4513);
  border-radius: 2px;
  animation: reading-pulse 1s ease-in-out infinite;
}

.chat-page .message-wrapper.reading .message {
  box-shadow: 0 0 0 2px rgba(139, 69, 19, 0.3);
}

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

/* Mobile - hide label */
@media (max-width: 768px) {
  .podcast-btn .podcast-label {
    display: none;
  }

  .podcast-btn {
    padding: 0.5rem;
  }
}

/* ============================================
   FEEDBACK BUTTON
   ============================================ */

.chat-feedback-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background-color: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-feedback-btn:hover {
  background-color: var(--color-background-alt);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.chat-feedback-btn svg {
  flex-shrink: 0;
}

/* ============================================
   FEEDBACK MODAL
   ============================================ */

.feedback-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
  padding: var(--space-md);
}

.feedback-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.feedback-modal {
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  padding: var(--space-xl);
  transform: scale(0.95) translateY(20px);
  transition: transform var(--transition-normal);
}

.feedback-modal-overlay.active .feedback-modal {
  transform: scale(1) translateY(0);
}

.feedback-modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-xs);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.feedback-modal-close:hover {
  background-color: var(--color-background-alt);
  color: var(--color-text);
}

.feedback-modal-title {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--color-primary);
  margin: 0 0 var(--space-xs) 0;
}

.feedback-modal-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  margin: 0 0 var(--space-lg) 0;
}

/* Feedback Form */
.feedback-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.feedback-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.feedback-form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.feedback-form-group label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text);
}

.feedback-form-group label .required {
  color: var(--tier-4);
}

.feedback-form-group input,
.feedback-form-group select,
.feedback-form-group textarea {
  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-sm);
  background-color: var(--color-surface);
  color: var(--color-text);
  transition: all var(--transition-fast);
}

.feedback-form-group input:focus,
.feedback-form-group select:focus,
.feedback-form-group textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(46, 90, 76, 0.1);
}

.feedback-form-group input::placeholder,
.feedback-form-group textarea::placeholder {
  color: var(--color-text-muted);
}

.feedback-form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.feedback-form-group select {
  cursor: pointer;
}

/* Captcha */
.feedback-captcha {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.feedback-captcha label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text);
}

.captcha-challenge {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.captcha-question {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-primary);
  background-color: var(--color-background-alt);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  min-width: 150px;
  text-align: center;
}

.captcha-challenge input {
  width: 100px;
  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);
  text-align: center;
}

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

/* Form Actions */
.feedback-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
}

.feedback-cancel-btn {
  padding: var(--space-sm) var(--space-lg);
  background-color: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-light);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.feedback-cancel-btn:hover {
  background-color: var(--color-background-alt);
  color: var(--color-text);
}

.feedback-submit-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  background-color: var(--color-accent);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.feedback-submit-btn:hover {
  background-color: var(--color-accent-light);
}

.feedback-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Success State */
.feedback-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-xl);
  gap: var(--space-md);
}

.feedback-success svg {
  color: var(--tier-1);
}

.feedback-success h4 {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--color-primary);
  margin: 0;
}

.feedback-success p {
  font-size: var(--text-sm);
  color: var(--color-text-light);
  margin: 0;
  max-width: 300px;
}

.feedback-done-btn {
  padding: var(--space-sm) var(--space-xl);
  background-color: var(--color-accent);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-top: var(--space-md);
}

.feedback-done-btn:hover {
  background-color: var(--color-accent-light);
}

/* Mobile responsiveness */
@media (max-width: 480px) {
  .feedback-modal {
    padding: var(--space-lg);
    max-height: 85vh;
  }

  .feedback-form-row {
    grid-template-columns: 1fr;
  }

  .captcha-challenge {
    flex-direction: column;
    align-items: stretch;
  }

  .captcha-question {
    min-width: auto;
  }

  .captcha-challenge input {
    width: 100%;
  }

  .feedback-form-actions {
    flex-direction: column-reverse;
  }

  .feedback-cancel-btn,
  .feedback-submit-btn {
    width: 100%;
    justify-content: center;
  }
}

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

/* Visually hidden - for screen readers only */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Keyboard Focus Indicators */
*:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Specific focus styles for different elements */
.chat-back-btn:focus,
.podcast-btn:focus,
.export-pdf-btn:focus,
.new-chat-btn:focus,
.sidebar-toggle:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.mode-select:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(139, 69, 19, 0.2);
}

#chat-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.15);
}

#topic-search:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.15);
}

.topic-link:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
  background-color: var(--color-background);
}

.chat-send:focus,
.chat-mic:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.chat-suggestion-btn:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  background-color: var(--color-background);
}

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

/* Feedback modal focus styles */
.feedback-modal input:focus,
.feedback-modal select:focus,
.feedback-modal textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.15);
}

.feedback-modal-close:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.feedback-cancel-btn:focus,
.feedback-submit-btn:focus,
.feedback-done-btn:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--color-accent);
  color: white;
  padding: var(--space-sm) var(--space-md);
  z-index: 1000;
  text-decoration: none;
  border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
  top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  *:focus {
    outline: 3px solid currentColor;
    outline-offset: 3px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
