/* ============================================
   SIDEBAR NAVIGATION - Universal Component
   ============================================ */

.sidebar-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100vh;
  background-color: var(--color-bg-surface);
  border-right: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: visible; /* allow collapse button to hang half outside the border */
  transition: width 300ms cubic-bezier(0.2, 0, 0.2, 1);
  will-change: width;
}

/* ============================================
   Logo Section
   ============================================ */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 32px 36px 24px 36px; /* left pad aligns logo with nav icons at 36px */
  position: relative;
  transition: padding 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

.sidebar-logo-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.sidebar-logo-img {
  width: 84px;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
  transition: width 300ms cubic-bezier(0.2, 0, 0.2, 1), opacity 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

.sidebar-logo-text {
  font-family: var(--font-family-bold);
  font-size: 18px;
  color: var(--color-text);
  white-space: nowrap;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

/* ============================================
   Main Navigation
   ============================================ */
.sidebar-main-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  flex: 1;
  overflow: hidden;
  overflow-y: auto;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--color-text);
  text-decoration: none;
  font-family: var(--font-family-medium);
  font-size: 15px;
  transition: background-color 200ms, color 200ms;
  cursor: pointer;
}

.sidebar-nav-item:hover {
  background-color: rgba(174, 170, 151, 0.1);
}

.sidebar-nav-item.active {
  background-color: var(--color-primary);
  color: var(--color-primary-text);
}

.sidebar-nav-icon {
  flex-shrink: 0;
}

.sidebar-nav-text {
  white-space: nowrap;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

/* ============================================
   Recent Files Button
   ============================================ */
.sidebar-recent-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 200ms;
  color: var(--color-text);
  font-family: var(--font-family-base);
  font-size: 14px;
  margin-bottom: 4px;
}

.sidebar-recent-btn:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.sidebar-recent-btn.active {
  background-color: rgba(0, 0, 0, 0.06);
  font-weight: 500;
}

.sidebar-recent-icon {
  flex-shrink: 0;
  color: var(--color-primary);
}

.sidebar-recent-text {
  white-space: nowrap;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

/* ============================================
   Projects Section
   ============================================ */
.sidebar-projects {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
}

.projects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: rgba(0, 0, 0, 0.75);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 200ms, color 200ms;
}

.projects-header:hover {
  background-color: rgba(0, 0, 0, 0.04);
  color: rgba(0, 0, 0, 1);
}

.projects-header-text {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1), max-width 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

.projects-chevron {
  flex-shrink: 0;
  color: rgba(0, 0, 0, 0.75);
  transition: transform 300ms cubic-bezier(0.2, 0, 0.2, 1), opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1), max-width 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

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

.projects-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: max-height 300ms, opacity 300ms;
}

.projects-list.collapsed {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: none;
  border: none;
  text-decoration: none;
  color: var(--color-text);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 200ms, color 200ms;
  width: 100%;
  text-align: left;
}

.project-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.project-item.active {
  background-color: rgba(0, 0, 0, 0.06);
  font-weight: 500;
}

.project-item.project-new {
  font-weight: 500;
}

.project-item.project-new:hover {
  background-color: rgba(102, 126, 234, 0.1);
}

.project-icon {
  flex-shrink: 0;
  color: var(--color-primary);
}

.project-item.project-new .project-icon {
  color: var(--color-primary);
}

.project-item.project-new .project-name {
  color: rgba(0, 0, 0, 0.9);
}

.project-item.active .project-icon {
  color: var(--color-primary);
}

.project-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1), max-width 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

/* Project Item Wrapper */
.project-item-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.project-item-wrapper .project-item {
  flex: 1;
  min-width: 0;
}

/* Project Menu Button (Three Dots) */
.project-menu-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background-color 150ms, color 150ms;
}

.project-item-wrapper:hover .project-menu-btn {
  display: flex;
}

.project-menu-btn:hover {
  background-color: rgba(0, 0, 0, 0.08);
  color: var(--color-text);
}

/* Project Context Menu */
.project-context-menu {
  position: fixed;
  background-color: #FFFFFF;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 180px;
  padding: 4px 0;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 150ms, visibility 150ms;
}

.project-context-menu.active {
  opacity: 1;
  visibility: visible;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  text-align: left;
  color: var(--color-text);
  font-family: var(--font-family-base);
  font-size: 14px;
  cursor: pointer;
  transition: background-color 150ms;
}

.context-menu-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.context-menu-item svg {
  flex-shrink: 0;
  color: var(--color-text-secondary);
}

.context-menu-item-danger {
  color: var(--color-error);
}

.context-menu-item-danger svg {
  color: var(--color-error);
}

.context-menu-item-danger:hover {
  background-color: rgba(255, 68, 68, 0.08);
}

/* Collapsed sidebar - text/labels fade out (handled in the collapsed block below) */

/* no gap change — keep identical to expanded state */

/* project items keep their original layout — text fades via opacity */

.sidebar-nav.collapsed .project-menu-btn {
  display: none;
}

/* ============================================
   Tour Button
   ============================================ */
.sidebar-tour-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 4px 12px;
  padding: 10px 12px 10px 24px; /* 12 margin + 24 pad = 36px icon alignment */
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 200ms;
  color: var(--color-text);
  font-family: var(--font-family-base);
  font-size: 14px;
}

.sidebar-tour-btn:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.sidebar-tour-icon {
  flex-shrink: 0;
  color: var(--color-primary);
}

.sidebar-tour-text {
  white-space: nowrap;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

/* ============================================
   Credits Widget
   ============================================ */
.sidebar-credits {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 24px; /* 12 margin + 24 pad = 36px icon alignment */
  margin: 0 12px 8px 12px;
  background: none;
  border: none;
  border-radius: 8px;
}

.sidebar-credits-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1), max-width 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

.sidebar-credits-icon {
  flex-shrink: 0;
  color: var(--color-primary);
}

.sidebar-credits-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1), max-width 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

.sidebar-credits-label {
  font-size: 11px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--font-family-medium);
  white-space: nowrap;
}

.sidebar-credits-balance {
  font-size: 16px;
  font-family: var(--font-family-bold);
  color: var(--color-text);
  white-space: nowrap;
}

.sidebar-credits-buy {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-primary);
  color: var(--color-primary-text);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 200ms, transform 200ms;
}

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

.sidebar-credits-buy:active {
  background-color: var(--color-primary-active);
  transform: scale(0.98);
}

/* ============================================
   Bottom Section (User + Dropdown)
   ============================================ */
.sidebar-bottom {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 12px;
}

/* User Dropdown Menu */
.sidebar-user-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 8px;
  background-color: #FFFFFF;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 200ms, visibility 200ms, transform 200ms;
  z-index: 1001;
  overflow: hidden;
}

.sidebar-user-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Dropdown User Header */
.dropdown-user-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background-color: rgba(0, 0, 0, 0.02);
}

.dropdown-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.dropdown-user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-user-email {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-divider {
  height: 1px;
  background-color: rgba(0, 0, 0, 0.1);
  margin: 4px 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  color: var(--color-text);
  font-family: var(--font-family-base);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 200ms;
}

.dropdown-item:hover {
  background-color: rgba(174, 170, 151, 0.1);
}

.dropdown-item svg {
  flex-shrink: 0;
  color: var(--color-text-secondary);
}

.dropdown-item strong {
  font-family: var(--font-family-bold);
  color: var(--color-primary);
}

.dropdown-item-danger:hover {
  background-color: rgba(255, 68, 68, 0.1);
  color: var(--color-error);
}

.dropdown-item-danger:hover svg {
  color: var(--color-error);
}

/* User Trigger Button */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 24px; /* 12 bottom-pad + 24 user-pad = 36px avatar alignment */
  border-radius: 8px;
  transition: background-color 200ms, padding 300ms cubic-bezier(0.2, 0, 0.2, 1);
  cursor: pointer;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
}

.sidebar-user:hover {
  background-color: rgba(174, 170, 151, 0.06);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: var(--color-primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-bold);
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-user-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  transition: opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1), max-width 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

.sidebar-user-name {
  font-family: var(--font-family-medium);
  font-size: 14px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-plan {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-chevron {
  flex-shrink: 0;
  color: var(--color-text-secondary);
  transition: transform 300ms cubic-bezier(0.2, 0, 0.2, 1), color 300ms, opacity 300ms cubic-bezier(0.2, 0, 0.2, 1), visibility 300ms cubic-bezier(0.2, 0, 0.2, 1), max-width 300ms cubic-bezier(0.2, 0, 0.2, 1);
  margin-left: auto;
}

.sidebar-user:hover .sidebar-user-chevron {
  color: var(--color-primary);
}

.sidebar-user-dropdown.active ~ .sidebar-user .sidebar-user-chevron {
  transform: rotate(180deg);
  color: var(--color-primary);
}

/* Logout Button (OLD - will be removed) */
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--color-text);
  font-family: var(--font-family-medium);
  font-size: 14px;
  cursor: pointer;
  transition: background-color 200ms, color 200ms;
  width: 100%;
  text-align: left;
}

.sidebar-logout:hover {
  background-color: rgba(174, 170, 151, 0.1);
  color: var(--color-error);
}

.sidebar-logout svg {
  flex-shrink: 0;
}

/* Collapse Toggle Button — sits half on/half off the sidebar right border */
.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: white;
  border: 1px solid rgba(174, 170, 151, 0.3);
  border-radius: 6px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background-color 200ms, border-color 200ms, top 300ms cubic-bezier(0.2, 0, 0.2, 1);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: -16px;
  z-index: 10;
}

.sidebar-collapse-btn:hover {
  background-color: rgba(174, 170, 151, 0.1);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.sidebar-collapse-btn svg {
  transition: transform 300ms cubic-bezier(0.2, 0, 0.2, 1);
}

.sidebar-nav.collapsed .sidebar-collapse-btn {
  transform: translateY(-50%);
}

/* ============================================
   Collapsed State
   ============================================ */
.sidebar-nav.collapsed {
  width: 90px;
}

.sidebar-nav.collapsed .sidebar-logo-text,
.sidebar-nav.collapsed .sidebar-nav-text,
.sidebar-nav.collapsed .sidebar-recent-text,
.sidebar-nav.collapsed .sidebar-tour-text,
.sidebar-nav.collapsed .sidebar-credits-info,
.sidebar-nav.collapsed .sidebar-user-details,
.sidebar-nav.collapsed .projects-header-text,
.sidebar-nav.collapsed .project-name,
.sidebar-nav.collapsed .projects-chevron,
.sidebar-nav.collapsed .sidebar-user-chevron {
  opacity: 0;
  visibility: hidden;
  max-width: 0;
  overflow: hidden;
  pointer-events: none;
}

/* logo keeps its original layout — no instant centering snap */

.sidebar-nav.collapsed .sidebar-logo-img {
  width: 38px;
}

.sidebar-nav.collapsed .sidebar-logo {
  padding-left: 26px;
  padding-right: 26px;
}

.sidebar-nav.collapsed .sidebar-logo-content {
  cursor: pointer;
}

.sidebar-nav.collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

.sidebar-nav.collapsed .sidebar-logo-content:hover {
  opacity: 0.8;
}

/* projects header not clickable when collapsed — text and chevron are already invisible */
.sidebar-nav.collapsed .projects-header {
  pointer-events: none;
  cursor: default;
}

/* active highlight uses normal item background — centered because
   sidebar width (90px) puts icons at center: 12+12+12+9 = 45 = 90/2 */

/* user row and bottom keep original padding — no instant snap */

/* tour btn keeps original layout in collapsed state */

/* credits: info hidden, buy button stays visible and centered */
.sidebar-nav.collapsed .sidebar-credits {
  justify-content: center;
  padding: 10px 0;
  gap: 0;
}

/* user avatar is 36px wide (vs 18px icons), center at 45px needs left at 27px: 12 + 15 */
.sidebar-nav.collapsed .sidebar-user {
  padding-left: 15px;
}

.sidebar-nav.collapsed .sidebar-user-dropdown {
  left: 0;
  right: auto;
  min-width: 240px;
}

/* ============================================
   Responsive: Mobile
   ============================================ */
@media (max-width: 1024px) {
  .sidebar-nav {
    transform: translateX(-100%);
    transition: transform 300ms cubic-bezier(0.2, 0, 0.2, 1);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }

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

  /* Mobile overlay backdrop */
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
  }

  .sidebar-backdrop.active {
    display: block;
  }
}
