/* ================= TOP BAR STYLES ================= */
/* Modern responsive top bar design for desktop and mobile */

/* CSS Variables for consistent theming */
:root {
  --topbar-height: 64px;
  --topbar-height-mobile: 56px;
  --topbar-bg: rgba(18, 18, 18, 0.95); /* Dark background by default */
  --topbar-bg-light: rgba(255, 255, 255, 0.95);
  --topbar-border: rgba(255, 255, 255, 0.08); /* Dark border by default */
  --topbar-border-light: rgba(0, 0, 0, 0.08);
  --topbar-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2); /* Dark shadow by default */
  --topbar-shadow-light: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --topbar-backdrop-blur: 16px;
  --topbar-padding: 0 24px;
  --topbar-padding-mobile: 0 16px;
  --topbar-gap: 20px;
  --topbar-gap-mobile: 12px;
  --topbar-z-index: 1200;
}

/* Light mode variables (if needed) - but force dark on mobile */
@media (prefers-color-scheme: light) {
  :root {
    --topbar-bg: var(--topbar-bg-light);
    --topbar-border: var(--topbar-border-light);
    --topbar-shadow: var(--topbar-shadow-light);
  }
  
  /* Force dark theme on mobile regardless of system preference */
  @media (max-width: 768px) {
    :root {
      --topbar-bg: rgba(18, 18, 18, 0.95) !important;
      --topbar-border: rgba(255, 255, 255, 0.08) !important;
      --topbar-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2) !important;
    }
  }
}

/* ================= MAIN HEADER OVERRIDE ================= */

.main-header {
  height: var(--topbar-height) !important;
  background: var(--topbar-bg) !important;
  border-bottom: 1px solid var(--topbar-border) !important;
  display: flex !important;
  align-items: center !important;
  padding: var(--topbar-padding) !important;
  gap: var(--topbar-gap) !important;
  position: sticky !important;
  top: 0 !important;
  z-index: var(--topbar-z-index) !important;
  pointer-events: auto !important;
  box-shadow: var(--topbar-shadow) !important;
  backdrop-filter: blur(var(--topbar-backdrop-blur)) !important;
  -webkit-backdrop-filter: blur(var(--topbar-backdrop-blur)) !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Removed blue line below formas.ai header */
/* .main-header::after {
  content: '' !important;
  position: absolute !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 1px !important;
  background: linear-gradient(90deg, transparent, var(--accent-color, #4a9eff), transparent) !important;
  opacity: 0.2 !important;
  transition: opacity 0.3s ease !important;
}

.main-header:hover::after {
  opacity: 0.4 !important;
} */

/* ================= MENU TOGGLE BUTTON ================= */
/* Menu toggle button removed */

/* On mobile, when the sidebar panel is open, fade user controls but keep title visible */
@media (max-width: 768px) {
  .sidebar.open ~ .main-content .main-header .header-user-section,
  .sidebar.open ~ .main-content .main-header #tutorialsDropdown,
  .sidebar.open ~ .main-content .main-header .dropdown,
  .sidebar.open ~ .main-content .main-header #dropBtn {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.2s ease !important;
  }
  /* Also fade the project title to let the sidebar header show through */
  .sidebar.open ~ .main-content .main-header .main-header-title {
    opacity: 0 !important;
    pointer-events: none !important;
  }
  /* Put the sidebar above the top bar on phones */
  .sidebar.open {
    z-index: 10050 !important; /* Above prompt bar and most UI */
  }
  /* And disable topbar interactions entirely while panel is open */
  .sidebar.open ~ .main-content .main-header {
    pointer-events: none !important;
  }
  /* Ensure the dim overlay also sits above the prompt bar on phones */
  .sidebar-overlay,
  .sidebar-overlay.active {
    z-index: 10040 !important;
  }
}

/* ================= HEADER TITLE SECTION ================= */

.main-header-title {
  flex: 0 0 auto !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  letter-spacing: 0 !important;
  color: var(--text-primary) !important;
  cursor: pointer !important;
  padding: 5px 16px !important;
  border-radius: 50px !important;
  transition: all 0.3s ease !important;
  margin: 0 !important;
  min-height: auto !important;
  position: relative !important;
  overflow: hidden !important;
  margin-left: 0 !important;
  max-width: fit-content !important;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.08) 100%) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}

.main-header-title::before {
  content: '' !important;
  position: absolute !important;
  top: 0 !important;
  left: -100% !important;
  width: 100% !important;
  height: 100% !important;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(255, 255, 255, 0.2) 50%, 
    transparent 100%) !important;
  transition: left 0.5s ease !important;
  border-radius: 50px !important;
  z-index: 0 !important;
}

.main-header-title:hover {
  background: linear-gradient(135deg, 
    rgba(255, 255, 255, 0.18) 0%, 
    rgba(255, 255, 255, 0.14) 50%,
    rgba(255, 255, 255, 0.10) 100%) !important;
  border-color: rgba(255, 255, 255, 0.25) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 
              inset 0 1px 0 rgba(255, 255, 255, 0.3) !important;
  transform: translateY(-1px) !important;
}

.main-header-title:hover::before {
  left: 100% !important;
}

.main-header-title h1 {
  font-size: 14px !important;
  font-weight: 600 !important;
  margin: 0 !important;
  padding: 0 !important;
  color: var(--text-primary) !important;
  letter-spacing: -0.02em !important;
  line-height: 1.3 !important;
  max-width: 15ch !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  cursor: default !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  position: relative !important;
  z-index: 1 !important;
  text-align: left !important;
}

.main-header-title h1:hover {
  opacity: 0.9 !important;
}

/* Removed "Go to Project Chat" text - header title is no longer clickable */

/* Remove any underline from header title */
.main-header-title {
  text-decoration: none !important;
}

.main-header-title:hover {
  text-decoration: none !important;
}

.main-header-title h1 {
  text-decoration: none !important;
}

.main-header-title h1:hover {
  text-decoration: none !important;
}

/* ================= PROJECT THUMBNAIL ================= */

.main-header-title .project-thumb {
  width: 23px !important;
  height: 23px !important;
  border-radius: 50% !important;
  background-size: cover !important;
  background-position: center !important;
  flex-shrink: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-weight: 600 !important;
  font-size: 10px !important;
  position: relative !important;
  overflow: hidden !important;
  box-shadow: none !important;
  z-index: 1 !important;
  margin-left: -9px !important;
  margin-right: 2px !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease !important;
}

/* Remove animation for now - debugging */

.main-header-title .project-thumb::before {
  content: '' !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05)) !important;
  opacity: 0 !important;
  transition: opacity 0.3s ease !important;
}

.main-header-title .project-thumb:hover {
  transform: scale(1.05) !important;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3) !important;
}

.main-header-title .project-thumb:hover::before {
  opacity: 0 !important;
}

/* ================= FORMAS LOGO ================= */

.main-header-title .formas-logo-link {
  display: flex !important;
  align-items: center !important;
  text-decoration: none !important;
  text-decoration-line: none !important;
  text-decoration-style: none !important;
  text-decoration-color: transparent !important;
  text-underline-offset: 0 !important;
  text-decoration-thickness: 0 !important;
  margin-right: 8px !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  border-radius: 50% !important;
  overflow: hidden !important;
  color: inherit !important;
  border: none !important;
  outline: none !important;
}

.main-header-title .formas-logo-link:hover,
.main-header-title .formas-logo-link:visited,
.main-header-title .formas-logo-link:active,
.main-header-title .formas-logo-link:focus {
  text-decoration: none !important;
  text-decoration-line: none !important;
  text-decoration-style: none !important;
  text-decoration-color: transparent !important;
  text-underline-offset: 0 !important;
  text-decoration-thickness: 0 !important;
  color: inherit !important;
  border: none !important;
  outline: none !important;
}

.main-header-title .formas-logo-link:hover {
  transform: scale(1.05) !important;
}

.main-header-title .formas-logo {
  width: 28px !important;
  height: 28px !important;
  object-fit: contain !important;
  border: none !important;
  border-radius: 50% !important;
  background: rgba(74, 158, 255, 0.1) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  padding: 6px !important;
  box-shadow: 0 2px 8px rgba(74, 158, 255, 0.2) !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.main-header-title .formas-logo:hover {
  background: rgba(74, 158, 255, 0.2) !important;
  transform: scale(1.1) !important;
  box-shadow: 0 4px 16px rgba(74, 158, 255, 0.3) !important;
}

/* ================= HEADER USER SECTION ================= */

.header-user-section {
  display: flex !important;
  align-items: center !important;
  gap: 20px !important;
  flex-shrink: 0 !important;
  margin-left: auto !important;
}

/* ================= MOBILE RESPONSIVE STYLES ================= */

@media (max-width: 768px) {
  :root {
    --topbar-height-mobile: 64px;
    --topbar-padding-mobile: 0 20px;
    --topbar-gap-mobile: 16px;
    /* Force dark theme on mobile */
    --topbar-bg: rgba(18, 18, 18, 0.95) !important;
    --topbar-border: rgba(255, 255, 255, 0.08) !important;
    --topbar-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2) !important;
  }
  
  .main-header {
    height: var(--topbar-height-mobile) !important;
    padding: var(--topbar-padding-mobile) !important;
    gap: var(--topbar-gap-mobile) !important;
    /* Explicitly force dark background on mobile */
    background: rgba(18, 18, 18, 0.95) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2) !important;
  }
  
  /* Menu toggle removed */
  
  .main-header-title {
    font-size: 15px !important;
    gap: 16px !important;
    padding: 10px 16px !important;
    margin: -10px -16px !important;
    min-height: 44px !important;
  }
  
  /* Reduce project title size and hide the icon on phones */
  .main-header-title h1 {
    font-size: 12px !important; /* Smaller for mobile */
    max-width: 14ch !important;
    font-weight: 600 !important;
    text-align: left !important;
  }

  .main-header-title .project-thumb {
    display: none !important; /* Hide project icon on phones */
  }
  
  .main-header-title .project-thumb {
    width: 36px !important;
    height: 36px !important;
  }
  
  .main-header-title .formas-logo {
    width: 28px !important;
    height: 28px !important;
    padding: 6px !important;
  }
  
  .header-user-section {
    gap: 16px !important;
  }
  
  /* Hide tutorials text on mobile, show only icon */
  .tutorials-btn .tutorials-text {
    display: none !important;
  }
  
  .tutorials-btn {
    padding: 12px !important;
    min-width: 44px !important;
    justify-content: center !important;
  }
  
  .tutorials-icon {
    width: 20px !important;
    height: 20px !important;
  }
}

/* ================= TABLET RESPONSIVE STYLES ================= */

@media (min-width: 769px) and (max-width: 1024px) {
  .main-header-title h1 {
    max-width: 20ch !important;
  }
}

/* ================= SIDEBAR HEADER (MOBILE) ================= */
@media (max-width: 768px) {
  /* Ensure the sidebar header shows logo + text clearly on phones */
  .sidebar-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    height: var(--topbar-height-mobile, 56px) !important;
    min-height: var(--topbar-height-mobile, 56px) !important;
    padding: 0 16px !important;
    border-bottom: 1px solid var(--topbar-border, rgba(255,255,255,0.08)) !important;
    backdrop-filter: blur(var(--topbar-backdrop-blur, 12px)) !important;
    -webkit-backdrop-filter: blur(var(--topbar-backdrop-blur, 12px)) !important;
  }

  .sidebar-logo {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    height: 100% !important;
    text-decoration: none !important;
  }

  .sidebar-logo img {
    width: 24px !important;
    height: 24px !important;
    border-radius: 50% !important;
    background: rgba(128, 128, 128, 0.15) !important;
    padding: 4px !important;
  }

  .sidebar-logo span {
    display: inline !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    letter-spacing: -0.01em !important;
    color: var(--text-primary, #fff) !important;
    opacity: 0.95 !important;
  }

  /* Make the X close button circular and always visible on phones */
  .sidebar-close {
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.14) !important;
    color: var(--text-secondary) !important;
    border-radius: 50% !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 16px !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
    pointer-events: auto !important;
    z-index: 2 !important;
  }

  .sidebar-close:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(255, 255, 255, 0.24) !important;
    color: var(--text-primary) !important;
  }
}

/* Ensure the sidebar close button is always visible and styled like the hamburger */
.sidebar .sidebar-header .sidebar-close {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 32px !important;
  height: 32px !important;
  border-radius: 50% !important;
  background: rgba(255, 255, 255, 0.08) !important;
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  color: var(--text-secondary) !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2) !important;
  backdrop-filter: blur(6px) !important;
  -webkit-backdrop-filter: blur(6px) !important;
  pointer-events: auto !important;
}

.sidebar .sidebar-header .sidebar-close:hover {
  background: rgba(255, 255, 255, 0.12) !important;
  border-color: rgba(255, 255, 255, 0.24) !important;
  color: var(--text-primary) !important;
}

/* ================= DESKTOP LARGE SCREEN STYLES ================= */

@media (min-width: 1025px) {
  .main-header {
    padding: 0 12px !important;
    gap: 12px !important;
  }
  
  .main-header-title {
    gap: 20px !important;
  }
  
  .main-header-title h1 {
    max-width: 25ch !important;
    font-size: 16px !important;
    text-align: left !important;
  }
  
  .header-user-section {
    gap: 24px !important;
  }
}

/* ================= FOCUS STATES FOR ACCESSIBILITY ================= */

/* Menu toggle focus states removed */

.main-header-title:focus-visible {
  outline: 2px solid var(--accent-color, #4a9eff) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.2) !important;
}

/* ================= ANIMATIONS ================= */

@keyframes topbarSlideIn {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.main-header {
  animation: topbarSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* ================= HIGH CONTRAST MODE SUPPORT ================= */
/* Ensure desktop prompt bar keeps the glass blur */
@media (min-width: 769px) {
  .input-section {
    background: rgba(0, 0, 0, 0.3) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
  }
}

@media (prefers-contrast: high) {
  .main-header {
    border-bottom: 2px solid var(--topbar-border) !important;
  }
  
  .menu-toggle {
    border: 2px solid var(--text-secondary) !important;
  }
  
  .main-header-title .project-thumb {
    border: 2px solid var(--text-primary) !important;
  }
}

/* ================= REDUCED MOTION SUPPORT ================= */

@media (prefers-reduced-motion: reduce) {
  .main-header,
  .main-header-title,
  .main-header-title h1,
  .main-header-title .project-thumb,
  .main-header-title .formas-logo {
    transition: none !important;
    animation: none !important;
  }
  
  .main-header-title:hover,
  .main-header-title h1:hover,
  .main-header-title .project-thumb:hover,
  .main-header-title .formas-logo:hover {
    transform: none !important;
  }
}

/* ================= SMOOTH PROMPT BAR SLIDE (MOBILE) ================= */
@media (max-width: 768px) {
  /* Use transform-based animation so the bar glides to the bottom */
  .input-section {
    top: auto !important;
    bottom: 0 !important;
    transform: translateY(0) !important;
    transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1),
                opacity 0.3s ease,
                padding-bottom 0.4s ease !important;
    will-change: transform;
    /* Restore blur background while docked */
    background: rgba(0, 0, 0, 0.3) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
  }

  /* Centered state: position relative to bottom so we can interpolate transform */
  .input-section.no-project {
    top: auto !important;
    bottom: 0 !important;
    transform: translateY(-20vh) !important; /* start lower on phones */
    transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1),
                opacity 0.3s ease !important;
    /* Keep the nice blur even before docking */
    background: rgba(0, 0, 0, 0.3) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
  }
}
