/* ===================================================
   HEADER VISIBILITY - Single Source of Truth
   All header visibility controlled by body classes
   =================================================== */
/* ===== HARD DESKTOP KILL SWITCH ===== */
@media (min-width: 769px) {
  .mobile-header-toggle {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
}

/* ===== DEFAULT STATE (MOST IMPORTANT!) ===== */
/* Default: Show navbar, hide AI header */
/* This applies when NO special body classes are present */
.navbar {
    display: flex !important;
}

.ai-custom-header {
    display: none !important;
}

/* ===== HOME NAVIGATION LINKS ===== */
/* Hide home nav links by default */
.home-nav-links {
    display: none !important;
}

/* Show ONLY on home page */
body.home-page .home-nav-links {
    display: flex !important;
    align-items: center;
    gap: 1rem;
}

/* ===== USER AUTH ACTIONS ===== */
/* Show on all pages by default */
.user-auth-actions {
    display: flex !important;
}

/* Hide on specific pages if needed */
body.ai-assistant-logged-in .user-auth-actions,
body[data-hide-auth-actions="true"] .user-auth-actions {
    display: none !important;
}

/* ===== AI CHAT PAGES (LOGGED IN) ===== */
/* ONLY show AI header on ai-assistant-logged-in pages */
/* Hide navbar on ai-assistant-logged-in pages */
body.ai-assistant-logged-in .navbar {
    display: none !important;
}

body.ai-assistant-logged-in .ai-custom-header {
    display: flex !important;
}

/* ===== ENSURE DEFAULTS FOR NON-AI PAGES ===== */
/* Explicitly reset headers for pages without ai-assistant-logged-in class */
body:not(.ai-assistant-logged-in) .navbar {
    display: flex !important;
}

body:not(.ai-assistant-logged-in) .ai-custom-header {
    display: none !important;
}

/* ===== GUEST AI CHAT PAGES ===== */
/* Show navbar (guest header), hide AI custom header */
body.ai-assistant-guest .navbar {
    display: flex !important;
}

body.ai-assistant-guest .ai-custom-header {
    display: none !important;
}

/* Guest header stays visible */
body.ai-assistant-guest .billing-header.guest-header {
    display: flex !important;
}

/* ===== NO-SIDEBAR PAGES ===== */
/* Hide mobile toggle on pages without sidebar */
body.no-sidebar .mobile-header-toggle {
    display: none !important;
}

/* Show mobile toggle on pages with sidebar */
body:not(.no-sidebar) .mobile-header-toggle {
    display: flex !important;
}

/* ===== MODEL DROPDOWN VISIBILITY ===== */
/* Hide model dropdown in navbar for specific pages */
body[data-hide-model-dropdown="true"] .navbar .model-selector-container {
    display: none !important;
}

/* Always show model dropdown in AI header when logged in */
body.ai-assistant-logged-in .ai-custom-header .model-selector-container {
    display: flex !important;
}

/* Show model dropdown for guest users on AI pages */
body.ai-assistant-guest .navbar .model-selector-container {
    display: flex !important;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
    /* Mobile header toggle only on non-no-sidebar pages */
    body:not(.no-sidebar) .mobile-header-toggle {
        display: flex !important;
    }

    /* Ensure proper padding when mobile toggle is visible */
    body:not(.no-sidebar) .navbar.with-sidebar {
        padding-left: 56px !important;
    }

    /* AI header adjustments for mobile */
    body.ai-assistant-logged-in .ai-custom-header {
        top: 0;
        left: 0;
        right: 0;
        height: 50px !important;
    }

    /* Stack home nav links vertically on mobile if needed */
    body.home-page .home-nav-links {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ===== SIDEBAR STATE ADJUSTMENTS ===== */
/* When sidebar is open, adjust AI header position */
body.sidebar-open .ai-custom-header {
    left: 235px !important;
}

/* On mobile, keep AI header at left: 0 even when sidebar is open */
@media (max-width: 768px) {
    body.sidebar-open .ai-custom-header {
        left: 0 !important;
    }
}

/* KEEP TOGGLE ACTIVE ON AI CHAT MOBILE */
@media (max-width: 768px) {
  body.ai-assistant-logged-in.sidebar-open .mobile-header-toggle {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: none !important;
  }
}


/* ========================================
   MOBILE SETTINGS CLOSE BUTTON
   ======================================== */

.mobile-settings-close-btn {
  position: fixed;
  top: 6px;
  left: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  padding: 0;
  z-index: 10001; /* Above everything */
}

.mobile-settings-close-btn:active {
  background: #F3F4F6;
}

.mobile-settings-close-btn i {
  font-size: 28px;
  color: #374151;
  font-weight: 300;
}

/* ===== SHOW/HIDE LOGIC ===== */

@media (max-width: 768px) {
  /* When settings modal is open, hide sidebar toggle and show X */
  body.modal-open:has(#settingsModal.show) .mobile-header-toggle {
    display: none !important;
  }

  body.modal-open:has(#settingsModal.show) .mobile-settings-close-btn {
    display: flex !important;
  }
}

/* Force hide on no-sidebar pages */
body.no-sidebar .navbar.with-sidebar {
    margin-left: 0 !important;
}

body.no-sidebar .ai-custom-header {
    display: none !important;
}
