/* ========================================= */
/* SIDEBAR SYSTEM - Clean Consolidated Styles */
/* ========================================= */

/* 1. CSS Variables & Configuration */
:root {
  --sidebar-width: 280px;
  --sidebar-z-index: 1000;
  --sidebar-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-bg: #ffffff;
  --sidebar-border: #e2e8f0;
  --sidebar-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
  --toggle-btn-size: 48px;
  --header-height: 64px;
}

/* Dark mode variables */
[data-theme="dark"],
.dark-mode {
  --sidebar-bg: #202123;  /* ChatGPT's exact sidebar color */
  --sidebar-border: rgba(255, 255, 255, 0.05);
  --sidebar-shadow: none;
}

/* ========================================= */
/* 2. Base Sidebar Layout                    */
/* ========================================= */

.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0 !important;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  z-index: var(--sidebar-z-index);
  transition: transform var(--sidebar-transition), 
              width var(--sidebar-transition),
              opacity var(--sidebar-transition),
              visibility var(--sidebar-transition);
  transform: translateX(0);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  margin-left: 0 !important;
}

/* ========================================= */
/* 3. Sidebar States                         */
/* ========================================= */

/* Collapsed state - completely hidden */
.sidebar.collapsed {
  width: 0;
  transform: translateX(-100%);
  visibility: hidden;
  opacity: 0;
  border-right: none;
}

/* Desktop: ensure sidebar is visible when not collapsed */
@media (min-width: 768px) {
  .sidebar:not(.collapsed) {
    visibility: visible;
    opacity: 1;
    display: flex;
    left: 0 !important;
    transform: translateX(0);
    width: var(--sidebar-width);
    margin-left: 0 !important;
  }
}

/* ========================================= */
/* 4. Sidebar Toggle Button                  */
/* ========================================= */

.sidebar-toggle {
  position: fixed !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  width: 24px;
  height: var(--toggle-btn-size);
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2001 !important;
  transition: all var(--sidebar-transition);
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.05);
  margin: 0 !important;
  padding: 0 !important;
  /* When sidebar is expanded, toggle is at the right edge of sidebar */
  left: var(--sidebar-width) !important;
}

.sidebar-toggle:hover {
  background: var(--color-surface-elevated, #f9fafb);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle i {
  font-size: 14px;
  color: var(--color-text-secondary, #666);
  transition: transform var(--sidebar-transition);
  /* Default state (expanded): point left to indicate "close" */
  transform: rotate(180deg);
}

/* When sidebar is collapsed, toggle moves to position 0 (attached to viewport edge) */
.sidebar.collapsed ~ .sidebar-toggle,
body.sidebar-collapsed .sidebar-toggle,
body.sidebar-collapsed #sidebar-toggle {
  left: 0 !important;
  border-right: 1px solid var(--sidebar-border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
}

/* Collapsed toggle hover state */
.sidebar.collapsed ~ .sidebar-toggle:hover,
body.sidebar-collapsed .sidebar-toggle:hover,
body.sidebar-collapsed #sidebar-toggle:hover {
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}

.sidebar.collapsed ~ .sidebar-toggle i {
  /* Collapsed state: point right to indicate "open" */
  transform: rotate(0deg);
}

/* Hide desktop toggle on mobile */
@media (max-width: 767px) {
  .sidebar-toggle.desktop-only {
    display: none;
  }
}

/* ========================================= */
/* 5. Mobile Sidebar Behavior                */
/* ========================================= */

@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    left: -100% !important;
    top: 0;
    width: 85%;
    max-width: 320px;
    height: 100%;
    z-index: 300;
    transition: left var(--sidebar-transition);
    transform: translateX(0) !important;
  }
  
  .sidebar.open {
    left: 0 !important;
    visibility: visible;
    opacity: 1;
    box-shadow: var(--sidebar-shadow);
  }
  
  /* Mobile backdrop */
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 250;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
  
  .sidebar.open + .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
  }
  
  /* Mobile toggle button */
  .sidebar-toggle-mobile {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 5;
    cursor: pointer;
    border: none;
    padding: 0;
  }
  
  /* Mobile close button */
  .sidebar .close-sidebar {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-secondary, #666);
    background: transparent;
    border: none;
    z-index: 10;
  }
  
  .sidebar .close-sidebar:hover {
    background-color: rgba(0, 0, 0, 0.05);
  }
}

/* Show/hide mobile-only elements */
@media (min-width: 768px) {
  .mobile-only {
    display: none;
  }
}

@media (max-width: 767px) {
  .mobile-only {
    display: block;
  }
}

/* ========================================= */
/* 6. Sidebar Content Structure              */
/* ========================================= */

.session-sidebar-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--sidebar-bg);
  overflow: hidden;
}

.sidebar-header {
  padding: 0;
  border-bottom: none;
  background: transparent;
  flex-shrink: 0;
}

/* Hide text content when sidebar is collapsed */
.sidebar.collapsed .sidebar-text,
.sidebar.collapsed .session-title,
.sidebar.collapsed .session-subtitle,
.sidebar.collapsed .search-box,
.sidebar.collapsed .new-session-btn span,
.sidebar.collapsed .session-info,
.sidebar.collapsed .session-actions,
.sidebar.collapsed .mode-tab span,
.sidebar.collapsed .section-header h3,
.sidebar.collapsed .header-actions,
.sidebar.collapsed .search-container,
.sidebar.collapsed .meta-agent-text,
.sidebar.collapsed .group-header {
  display: none;
}

/* Center icons when collapsed */
.sidebar.collapsed .session-item {
  justify-content: center;
  padding: 8px;
}

.sidebar.collapsed .session-avatar {
  margin: 0 auto;
}

.sidebar.collapsed .meta-agent-btn {
  padding: 8px;
  justify-content: center;
}

.sidebar.collapsed .meta-agent-icon {
  margin: 0;
}

/* Mode toggle adjustments for collapsed state */
.sidebar.collapsed .mode-toggle {
  flex-direction: column;
  padding: 0.5rem 0;
}

.sidebar.collapsed .mode-tab {
  padding: 0.5rem;
  width: 100%;
}

.sidebar.collapsed .sidebar-header {
  padding: 0.5rem;
  text-align: center;
}

/* ========================================= */
/* 7. Dark Mode Support                      */
/* ========================================= */

.dark-mode .sidebar {
  background: var(--sidebar-bg);
  border-right-color: var(--sidebar-border);
}

.dark-mode .sidebar-toggle {
  background: var(--sidebar-bg);
  border-color: var(--sidebar-border);
}

.dark-mode .sidebar-toggle i {
  color: #e4e4e7;
}

.dark-mode .sidebar-backdrop {
  background-color: rgba(0, 0, 0, 0.7);
}

.dark-mode .sidebar-toggle-mobile {
  background-color: rgba(0, 0, 0, 0.3);
}

.dark-mode .sidebar .close-sidebar {
  color: #a0a0a0;
}

.dark-mode .sidebar .close-sidebar:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* ========================================= */
/* 8. Layout Integration                     */
/* ========================================= */

/* Main container base styles */
.main-container {
  position: relative;
  background: transparent;
  min-height: 100vh;
  width: 100%;
  padding: 0;
  margin: 0;
}

/* Chat container - removed positioning to avoid conflicts with chat-core.css */

/* Mobile adjustments - removed to avoid conflicts with chat-core.css */

/* ========================================= */
/* 9. Accessibility                          */
/* ========================================= */

.sidebar:focus-within {
  outline: 2px solid var(--color-primary, #E3175E);
  outline-offset: -2px;
}

.sidebar-toggle:focus {
  outline: 2px solid var(--color-primary, #E3175E);
  outline-offset: 2px;
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ========================================= */
/* 10. Performance Optimizations             */
/* ========================================= */

/* Add will-change for elements that animate */
.sidebar,
.sidebar-toggle {
  will-change: transform, width, opacity, visibility;
}

/* Remove will-change after animation */
.sidebar:not(.transitioning),
.sidebar-toggle:not(.transitioning) {
  will-change: auto;
}

/* ========================================= */
/* 11. Force Sidebar to Viewport Edge        */
/* ========================================= */

/* Ensure sidebar is always at viewport edge */
.sidebar {
  left: 0 !important;
  margin-left: 0 !important;
  padding-left: 0 !important;
}

/* Override any parent container constraints */
body .sidebar,
html body .sidebar {
  position: fixed !important;
  left: 0 !important;
  margin-left: 0 !important;
}

/* ========================================= */
/* 12. Ensure Visual Separation              */
/* ========================================= */

/* Make sure sidebar is completely independent from chat */
.sidebar {
  /* Higher z-index to ensure it's above everything */
  z-index: 2000 !important;
  /* Remove any potential transforms from parent */
  transform-origin: left center !important;
}

/* Chat container styles removed - handled by chat-core.css */

/* Main container should not constrain sidebar */
.main-container {
  /* Remove any transforms that might affect fixed children */
  transform: none !important;
  /* Ensure no overflow hidden that might clip sidebar */
  overflow: visible !important;
  /* No positioning that might create a new stacking context */
  position: static !important;
}

/* ========================================= */
/* 13. CLEANED UP POSITIONING RULES         */
/* ========================================= */

/* Remove redundant toggle positioning - handled by core rules above */

/* Hide desktop toggle on mobile */
@media (max-width: 767px) {
  .sidebar-toggle.desktop-only {
    display: none;
  }
}

/* ========================================= */
/* 14. ABSOLUTE VIEWPORT POSITIONING FIX    */
/* ========================================= */

/* Force sidebar to be positioned relative to viewport, not any parent container */
.sidebar {
  /* Reset all potential positioning issues */
  position: fixed !important;
  top: 64px !important; /* Header height */
  left: 0 !important;
  bottom: 0 !important;
  height: calc(100vh - 64px) !important;
  width: var(--sidebar-width) !important;
  z-index: 2000 !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
  /* Remove from document flow */
  transform: translateX(0) !important;
  transform-origin: left center !important;
  /* Prevent any parent container from affecting position */
  inset: auto !important;
  clip: auto !important;
  contain: layout style paint !important;
}

/* Collapsed state - hide completely */
.sidebar.collapsed {
  width: 0 !important;
  transform: translateX(-100%) !important;
  visibility: hidden !important;
  opacity: 0 !important;
  border-right: none !important;
}

/* Ensure main content doesn't overlap with expanded sidebar */
body:not(.sidebar-collapsed) .main-container {
  margin-left: 0 !important; /* Sidebar overlays, doesn't push content */
}

/* ========================================= */
/* 15. NEW LAYOUT STRUCTURE SUPPORT          */
/* ========================================= */

/* Main chat layout container */
.main-chat-layout {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: visible;
}

/* Chat content area that contains both sidebar and main content */
.chat-content-area {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  overflow: visible;
  /* Ensure this doesn't interfere with fixed positioning */
  transform: none !important;
  contain: none !important;
}

/* Ensure the centered container doesn't interfere with sidebar */
.chat-content-area .container.mx-auto.px-4 {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  /* Don't let the container affect the sidebar */
  position: relative;
  z-index: 1;
}

/* Force sidebar to always be at viewport edge regardless of parent containers */
.chat-content-area .sidebar {
  position: fixed !important;
  left: 0 !important;
  top: 64px !important;
  bottom: 0 !important;
  height: calc(100vh - 64px) !important;
  width: var(--sidebar-width) !important;
  z-index: 2000 !important;
  /* Remove from flex layout */
  flex: none !important;
  order: -1 !important;
}

/* ========================================= */
/* 16. FORCE VIEWPORT EDGE CLASS             */
/* ========================================= */

/* Critical class added by JavaScript to force viewport edge positioning */
.sidebar.force-viewport-edge,
.force-viewport-edge.sidebar {
  position: fixed !important;
  left: 0 !important;
  top: 64px !important;
  bottom: 0 !important;
  height: calc(100vh - 64px) !important;
  width: var(--sidebar-width) !important;
  z-index: 2000 !important;
  margin: 0 !important;
  padding: 0 !important;
  transform: none !important;
  /* Override any container constraints */
  max-width: none !important;
  min-width: var(--sidebar-width) !important;
  /* Remove from any layout flow */
  float: none !important;
  clear: none !important;
  flex: none !important;
  grid-area: auto !important;
  order: initial !important;
  /* Ensure it's not affected by parent transforms */
  transform-origin: left center !important;
  /* Remove any potential clips or overflows */
  clip: auto !important;
  clip-path: none !important;
  overflow: visible !important;
  contain: none !important;
}

/* Force collapsed state positioning */
.sidebar.force-viewport-edge.collapsed {
  width: 0 !important;
  transform: translateX(-100%) !important;
  visibility: hidden !important;
  opacity: 0 !important;
} 
