/* Common Chat Styles - Shared across all chat interfaces */

:root {
  --sidebar-width: 260px;
  --hover-color: rgba(197, 5, 12, 0.45);
  --text-primary: #333333;
  --text-secondary: #ffffff;
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bucky-red: #c5050c;
  --border-color: #e5e5e5;
  --hover-bg: #f0f0f0;
  --message-user-bg: #f7f7f8;
  --message-assistant-bg: #ffffff;
  --input-bg: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --transition: all 0.2s ease;

    /* Brand */
    --uw-red: #C5050C;
    --uw-red-dark: #9B0000;
    --uw-red-light: #E86A6E;
  
    /* Text */
    --text-on-white: #2B2B2B;
    --text-muted: #6B6B6B;
    --text-on-red-strong: #FFFFFF;
    --text-on-red-soft: #FFFFFFB3;
  
    /* Background */
    --page-tint: #FFF5F5;
  
    /* Focus */
    --focus-ring: #8AB4FF;
  
    /* Shadows */
    --uw-shadow: 0 12px 32px rgba(197, 5, 12, 0.18);
    --uw-soft-shadow: 0 8px 20px rgba(197, 5, 12, 0.12);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #d0d0d0;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #b0b0b0;
}

/* Sidebar Styles */
.sidebar {
  width: var(--sidebar-width);
  /* frosted glass */
  background: linear-gradient(
    135deg,
    rgba(197, 5, 12, 0.90),
    rgba(197, 5, 12, 0.42)
  );
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);

  /* crisp border + glow */
  border-right: 1px solid rgba(197, 5, 12, 0.55);
  box-shadow: 0 10px 26px rgba(197, 5, 12, 0.20);
  background-clip: padding-box;

  /* keep existing layout props */
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  position: relative;
  height: 100vh;
  /* optional: ensure text stays readable on the glass */
  color: #fff;
}

/* Fallback for browsers without backdrop-filter */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .sidebar {
    background: color-mix(in srgb, var(--uw-red) 92%, white);
  }
}

.sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
  position: fixed;
  left: var(--sidebar-width);
  top: 10px;
  width: 40px;
  height: 40px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left var(--transition), border-radius var(--transition);
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle.sidebar-collapsed {
  left: 0;
  border-radius: 0 6px 6px 0;
  box-shadow: 2px 0 6px rgba(0,0,0,0.1);
}

.sidebar-toggle:hover {
  background: linear-gradient(
    135deg,
    rgba(197, 5, 12, 0.8),
    rgba(197, 5, 12, 0.5)
  );
  color: white;
  border-color: var(--hover-color);
  box-shadow: var(--shadow-md);
}

.sidebar-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.sidebar-toggle.sidebar-collapsed svg {
  transform: rotate(180deg);
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

/* Sidebar Footer Styles */
.sidebar-footer {
  margin-left: 40px;
  margin-bottom: 16px;
}

/* Feedback Chip Styles */
.feedback-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 18px;
  padding: 8px 16px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  min-width: 140px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.feedback-chip:hover {
  background: linear-gradient(135deg, rgba(197, 5, 12, 0.18), rgba(197,5,12,0.10));
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.feedback-chip:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.feedback-chip svg {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  flex-shrink: 0;
}


/* Conversations List Components */
.conversations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
}

.conversations-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text-secondary);
}

.new-chat-icon-btn {
  width: 33px;
  height: 33px;
  background-color: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
}

.new-chat-icon-btn:hover {
  background: linear-gradient(135deg, rgba(197,5,12,0.18), rgba(197,5,12,0.10));
  border-color: var(--text-secondary);
}

.plus-icon {
  font-size: 20px;
  font-weight: bold;
  line-height: 1;
  color: var(--text-secondary);
}

.new-chat-icon-btn:hover .plus-icon {
  color: var(--text-secondary);
}

.conversations-list {
  max-height: 60%;
  overflow-y: auto;
  padding: 8px;
  flex-shrink: 0;
}

/* When no remembered section exists, conversations should use all space */
.sidebar:not(.has-remembered) .conversations-list {
  max-height: calc(100% - 60px); /* Account for header */
  flex: 1;
}

/* Conversation Items */
.conversation-item {
  padding: 8px 12px;
  margin-bottom: 2px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.conversation-item:hover {
  background: linear-gradient(135deg, rgba(197,5,12,0.18), rgba(197,5,12,0.10));
}

.conversation-item.active {
  background: linear-gradient(135deg, rgba(197,5,12,0.34), rgba(197,5,12,0.18));
  color: var(--text-secondary);
}

.conversation-title {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-delete {
  opacity: 0;
  width: 16px;
  height: 16px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: var(--transition);
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
  font-weight: 300;
}

.conversation-item:hover .conversation-delete {
  opacity: 0.7;
}

.conversation-delete:hover {
  background-color: rgba(255, 0, 0, 0.1);
  color: #ff4444;
  opacity: 1;
}

/* Site Group Headers */
.site-group-header {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 8px 16px 4px 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--transition);
  user-select: none;
}

.site-group-header:hover {
  color: rgba(254, 209, 209, 0.861);
}

.site-group-header .chevron {
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
}

.site-group-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.site-conversations {
  overflow: hidden;
  max-height: 1000px;
  transition: max-height 0.3s ease;
}

.site-conversations.collapsed {
  max-height: 0;
}

.site-conversations .conversation-item {
  padding-left: 32px;
}

/* Remembered Items Section */
#remembered-section {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border-color);
  padding: 16px;
  min-height: 0;
}

/* Main Chat Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  height: 60px;
  z-index: 2;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 24px 0 56px;
  background-color: var(--bg-primary);
  gap: 16px;
  transition: padding-left var(--transition);
}

.sidebar.collapsed ~ .main-content .chat-header {
  padding-left: 56px;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}

.chat-site-info {
  font-size: 14px;
  color: var(--text-secondary);
  background-color: var(--bg-primary);
  padding: 4px 12px;
  border-radius: 16px;
  font-weight: 600;
}

.logo-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-display);
  position: relative;
  right: 100px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity var(--transition);
}

.logo-title.hidden {
  opacity: 0;
  pointer-events: none;
}

.just-askbucky-heading.hidden,
.menu-heading.hidden {
  opacity: 0;
  pointer-events: none;
}

.logo-icon {
  width: 35px;
  height: 35px;
  flex-shrink: 0;
  object-fit: contain;
  transform: scaleX(-1);
}

    /* Chat Messages */
  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: 50% 0%;   /* center of the viewport area */
    background-size: min(100vw, 100vh);  
    position: relative;
    margin-top: -77px;
    padding-top: 40px;
    
}


/* Prevent background scrolling when no messages are present */
.chat-messages:not(:has(.message)) {
  overflow-y: hidden;
}


/* Welcome Message */
.welcome-message {
  position: relative;
  top: 25%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 1;
  pointer-events: none;
}


.welcome-message h2 { 
  font-size: 2rem;
  font-weight: bold bold;
  color: var(--text-primary);
  margin: 2px;
  font-family: var(--font-display);
  
}

.welcome-message.hidden {
  display: none;
}

.messages-container {
  width: 100%;
}

.message {
  margin-bottom: 20px;
  font-weight: 600;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

/* User bubble — iMessage-style (white, right-aligned) */
.user-message {
  position: relative;
  display: block;
  width: fit-content;
  margin: 30px 0 10px auto;           /* push to the right */
  max-width: min(72ch, 85%);           /* readable width */
  padding: 12px 14px;
  font-weight: 600;

  background: #ffffff;
  color: var(--text-primary, #1a1a1a);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px 18px 18px 18px;   /* iMessage-ish corner profile */
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);

  word-wrap: break-word;
  overflow-wrap: anywhere;
}



/* Keep links and code readable on white */
.user-message a { color: #7a0910; text-decoration: underline; }
.user-message code {
  background: rgba(0,0,0,0.06);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.user-message .message-avatar {
  background-color: var(--hover-color);
  color: white;
}

.assistant-message .message-avatar {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.message-content {
  flex: 1;
}

.message-text {
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Debug Info */
.message-debug-icon {
  margin-left: 12px;
  padding: 4px 8px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: monospace;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: var(--transition);
  display: none;
}

.message-debug-icon:hover {
  background-color: var(--hover-color);
  color: white;
  border-color: var(--hover-color);
}

.debug-info {
  background-color: #f0f0f0;
  padding: 16px;
  margin: 12px 0;
  border-radius: 8px;
  font-family: monospace;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* Loading Animation */
.loading-dots {
  display: inline-flex;
  gap: 4px;
}

.loading-dot {
  width: 8px;
  height: 8px;
  background-color: var(--text-primary);
  border-radius: 50%;
  animation: loading 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes loading {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 8px;
  left: 16px;
  z-index: 1000;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

.mobile-menu-toggle:hover {
  background: linear-gradient(
    135deg,
    rgba(197, 5, 12, 1),
    rgba(197, 5, 12, 0.7)
  );
  color: white;
  border-color: var(--hover-color);
}

/* Item Container Styles (for search results) */
.item-container {
  background-color: #ffffff;
  border: 1px solid #f0f0f0;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  gap: 16px;
  width: 100%;
}

.item-content {
  flex: 1;
}

.item-title-row {
  margin-bottom: 8px;
}

.item-title-link {
  color: #0066cc;
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
}

.item-title-link:hover {
  text-decoration: underline;
}

.item-site-link {
  display: inline-block;
  margin-top: 4px;
  color: #5a6c7d;
  text-decoration: none;
  font-size: 13px;
}

.item-site-link:hover {
  text-decoration: underline;
}

.item-description {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  margin: 8px 0;
}

.item-details-text {
  display: inline-block;
  margin: 4px 0;
  padding: 4px 8px;
  background-color: #e9ecef;
  border-radius: 4px;
  font-size: 13px;
  color: #495057;
}

.item-explanation {
  font-style: italic;
  color: #666;
  margin-top: 8px;
  font-size: 14px;
}

.item-image {
  max-width: 120px;
  height: auto;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -var(--sidebar-width);
    z-index: 999;
    height: 100vh;
    box-shadow: var(--shadow-md);
    /* Ensure sidebar is closed by default on mobile */
    transform: translateX(-100%);
    transition: transform var(--transition);
    /* Ensure proper flex layout on mobile */
    display: flex;
    flex-direction: column;
  }

  .sidebar.open {
    left: 0;
    transform: translateX(0);
  }
  
  .sidebar.collapsed {
    left: -var(--sidebar-width);
    transform: translateX(-100%);
  }
  
  .sidebar-toggle {
    display: none; /* Hide desktop toggle on mobile */
  }

  .mobile-menu-toggle {
    display: flex; /* Show mobile menu toggle */
    transition: opacity var(--transition), visibility var(--transition);
  }
  
  /* Hide mobile menu toggle when sidebar is open - simple approach */
  .mobile-menu-toggle.hidden {
    display: none !important;
  }

  .chat-header {
    padding-left: 16px; /* Reduce padding since sidebar is hidden */
  }
  
  /* Ensure main content takes full width on mobile */
  .main-content {
    width: 100%;
    margin-left: 0;
  }
  
  /* Ensure feedback chip is visible in sidebar on mobile */
  .sidebar .feedback-chip {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 1000 !important;
  }
  
  /* Position feedback chip at bottom but ensure it's visible on mobile */
  .sidebar-footer {
    margin-left: 8px; /* Reduced from 16px to center it better */
    margin-bottom: 16px;
    margin-top: auto; /* Push to bottom of sidebar */
    padding: 8px 16px; /* Reduce padding */
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: sticky; /* Keep it visible */
    bottom: 0; /* Stick to bottom */
  }
  
  /* Ensure feedback chip is properly sized on mobile */
  .sidebar .feedback-chip {
    min-width: 100px;
    font-size: 12px;
    padding: 4px 8px;
    width: 100%; /* Take full width of footer */
    justify-content: center;
    height: 32px; /* Fixed height for consistency */
  }
  
  /* Ensure conversations list doesn't take all space */
  .conversations-list {
    flex: 1;
    overflow-y: auto;
  }
}

