/* Multi-Chat Sidebar Styles */

/* Sidebar container */
.chat-sidebar {
  position: fixed;
  top: 0;
  left: -380px; /* Hidden by default - increased width */
  width: 380px; /* Increased from 280px for MUSE content */
  height: 100vh;
  background: #121214;
  border-right: 1px solid #1f1f25;
  z-index: 2000; /* Higher z-index to ensure it's on top */
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: none; /* No shadow when closed */
  /* Force dark color scheme for Safari scrollbar theming */
  color-scheme: dark;
}

.chat-sidebar.open {
  left: 0;
  box-shadow: none;
}

/* Gradient fade at bottom of sidebar */
.chat-sidebar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: linear-gradient(180deg, rgba(18, 18, 20, 0) 0%, #121214 100%);
  pointer-events: none;
  z-index: 10;
}

/* Sidebar header */
.sidebar-header {
  padding: 18px 20px;
  border-bottom: 1px solid #1f1f25;
  background: #121214;
  display: flex;
  align-items: center;
  gap: 12px;
}

.new-chat-btn {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  background: #19191e;
  border: 1px solid #23232a;
  border-radius: 12px;
  color: #f3f3f5;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.new-chat-btn .new-chat-label {
  flex: 1;
  text-align: left;
  letter-spacing: inherit;
}

.new-chat-btn:hover {
  background: rgba(156, 136, 177, 0.14);
  border-color: rgba(156, 136, 177, 0.4);
  color: #ffffff;
}

.new-chat-btn:hover .sidebar-icon {
  color: var(--accent-warm);
}

.new-chat-btn:focus-visible {
  outline: 2px solid rgba(156, 136, 177, 0.6);
  outline-offset: 2px;
}

.sidebar-close-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid #23232a;
  background: transparent;
  color: #8a8a95;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.sidebar-close-btn:hover {
  background: rgba(156, 136, 177, 0.1);
  border-color: rgba(156, 136, 177, 0.35);
  color: #ffffff;
}

.sidebar-close-btn .sidebar-icon--close {
  color: #8a8a95;
}

.sidebar-close-btn:hover .sidebar-icon--close {
  color: #ffffff;
}

.sidebar-close-btn:focus-visible {
  outline: 2px solid rgba(156, 136, 177, 0.55);
  outline-offset: 2px;
}

/* Sidebar content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 30px 0; /* Add padding at bottom for fade */
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Force dark color scheme for native scrollbar theming in Safari */
  color-scheme: dark;
}

/*
 * Safari macOS uses overlay scrollbars by default which CANNOT be styled with CSS.
 * Safari completely ignores ::-webkit-scrollbar styles for overlay scrollbars.
 * The only CSS-based workaround is to use scrollbar-color which Safari 15.4+ supports.
 *
 * Chrome/Firefox: Use ::-webkit-scrollbar pseudo-elements
 * Safari: Falls back to scrollbar-color (limited styling) or native overlay scrollbar
 */

/* Firefox and Safari 15.4+ scrollbar styling */
@supports not selector(::-webkit-scrollbar) {
  .sidebar-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
  }
}

/* Chrome/Edge - webkit scrollbar styling (Safari ignores this for overlay scrollbars) */
.sidebar-content::-webkit-scrollbar {
  width: 5px;
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.35);
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar:horizontal {
  display: none;
}

/* Firefox scrollbar (outside @supports for broader compatibility) */
.sidebar-content {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}

/* Chat list */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 16px 0 16px;
}

/* Chat item */
.chat-item {
  position: relative;
  padding: 14px 18px;
  border-radius: 14px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  border: 1px solid transparent;
  background: transparent;
}

.chat-item:hover {
  background: rgba(156, 136, 177, 0.08);
}

.chat-item.active {
  background: rgba(156, 136, 177, 0.15);
  border-color: rgba(156, 136, 177, 0.35);
}

.chat-item.active::before {
  content: '';
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 0;
  width: 3px;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(156, 136, 177, 0.9) 0%, rgba(156, 136, 177, 0.4) 100%);
}

.chat-item-title {
  font-size: 14px;
  font-weight: 500;
  color: #f1f1f4;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta {
  font-size: 12px;
  color: #7d7d89;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-item-skeleton {
  padding: 20px 16px;
  color: #6f6f79;
  font-size: 14px;
  text-align: center;
}

/* Date separators */
.chat-date-separator {
  padding: 12px 16px 4px 16px;
  font-size: 11px;
  font-weight: 600;
  color: #585864;
  text-transform: uppercase;
  letter-spacing: 0.28em;
}

/* Prompt input wrapper */
.prompt-input-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 22px;
  border-radius: 24px;
  background: rgba(20, 20, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

/* Prompt controls */
.prompt-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.control-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
  padding: 0;
  position: relative;
  color: rgba(245, 245, 247, 0.78);
}

.control-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(156, 136, 177, 0.6);
  background: rgba(156, 136, 177, 0.16);
  color: rgba(202, 184, 222, 0.95);
}

.control-btn:active {
  transform: scale(0.96);
}

/* Control icons */
.control-icon {
  width: 18px;
  height: 18px;
  opacity: 0.85;
  transition: opacity 0.2s ease;
  color: rgba(245, 245, 247, 0.75);
  background-color: currentColor;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  -webkit-mask-size: contain;
}

.control-btn:hover .control-icon {
  opacity: 1;
}


.control-icon--new {
  mask-image: url('/static/icons/control-new-chat.svg');
  -webkit-mask-image: url('/static/icons/control-new-chat.svg');
}

.control-icon--sidebar {
  mask-image: url('/static/icons/control-sidebar.svg');
  -webkit-mask-image: url('/static/icons/control-sidebar.svg');
}

/* Control button tooltips */
.control-btn::before {
  content: attr(data-tooltip);
  position: absolute;
  right: 44px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(12, 12, 16, 0.9);
  color: rgba(245, 245, 247, 0.88);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-family: 'MontrealSerial', sans-serif;
  font-weight: 300;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
  z-index: 1000;
}

.control-btn:hover::before {
  opacity: 0.6;
  visibility: visible;
}

/* Prompt editor takes remaining space */
#prompt-editor {
  flex: 1;
  background: transparent;
  border: none;
  color: rgba(245, 245, 247, 0.88);
  font-size: 22px;
  font-weight: 300;
  line-height: 1.3;
  resize: none;
  min-height: 48px;
  max-height: 240px;
  padding: 0;
  margin: 0;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999; /* Just below sidebar z-index 2000 */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* Main content shifts to accommodate sidebar (desktop only) */
body.sidebar-open {
  --sidebar-width: 380px;
}

body.sidebar-open #chat-container {
  left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  transition: left 0.3s ease, width 0.3s ease;
}

body.sidebar-open #site-logo {
  left: calc(25px + var(--sidebar-width));
  transition: left 0.3s ease;
}

body.sidebar-open #nav-links {
  left: calc(150px + var(--sidebar-width));
  transition: left 0.3s ease;
}

body.sidebar-open #prompt-editor-container {
  left: calc(var(--sidebar-width) + (100% - var(--sidebar-width)) / 2);
  transition: left 0.3s ease;
}

/* Remove transition for prompt editor container */
#prompt-editor-container {
  transition: none;
}

/* Responsive design */
@media (max-width: 768px) {
  .chat-sidebar {
    width: 380px;
    left: -380px;
  }
  
  .chat-sidebar.open {
    left: 0;
  }
  
  /* Content stays in place on mobile (sidebar overlays) */
  body.sidebar-open #chat-container {
    left: 0;
    width: 100%;
  }

  body.sidebar-open #site-logo {
    left: 25px;
  }

  body.sidebar-open #nav-links {
    left: 150px;
  }

  body.sidebar-open #prompt-editor-container {
    left: 50%; /* Stay centered on mobile */
  }
  
  .prompt-controls {
    order: -1; /* Show controls first on mobile */
  }
}

/* Animation classes */
.chat-item-enter {
  opacity: 0;
  transform: translateX(-20px);
  animation: slideInLeft 0.3s ease forwards;
}

@keyframes slideInLeft {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Loading states */
.chat-item.loading {
  opacity: 0.6;
  pointer-events: none;
}

.chat-item.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Delete chat button */
.delete-chat-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 24px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(156, 136, 177, 0.08);
  color: #9c88b1;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.delete-chat-btn:hover {
  background: rgba(156, 136, 177, 0.18);
  border-color: rgba(156, 136, 177, 0.35);
  color: #cab8de;
}

.delete-chat-btn:focus-visible {
  outline: 2px solid rgba(156, 136, 177, 0.55);
  outline-offset: 2px;
}

.delete-chat-btn .delete-chat-icon {
  width: 14px;
  height: 14px;
  background-color: currentColor;
  mask: url('/static/icons/trash.svg') center/contain no-repeat;
  -webkit-mask: url('/static/icons/trash.svg') center/contain no-repeat;
}

/* Sidebar icon system */
.sidebar-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  color: #9c88b1;
  background-color: currentColor;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  -webkit-mask-size: contain;
}

.sidebar-icon--add {
  mask-image: url('/static/icons/add.svg');
  -webkit-mask-image: url('/static/icons/add.svg');
  color: var(--accent-warm);
}

.sidebar-icon--close {
  width: 16px;
  height: 16px;
  mask-image: url('/static/icons/close.svg');
  -webkit-mask-image: url('/static/icons/close.svg');
}
