/* Te Kete Ako Sidebar v3 - Untitled UI Style (Push Interaction) */

/* =========================================================================
   CRITICAL: Hide embedded/legacy components immediately to prevent flash
   These old components conflict with the shared component system
   ========================================================================= */

/* Hide embedded sidebars */
.left-sidebar.no-print,
.main-container > .left-sidebar,
aside.left-sidebar {
  display: none !important;
}

/* Hide embedded headers when shared header system is active */
/* Only hide if the page has data-auto-init (meaning shared components will load) */
body[data-auto-init="true"] > header.site-header,
body[data-auto-init="true"] header.site-header.no-print {
  display: none !important;
}

/* Hide embedded footers when shared footer system is active */
body[data-auto-init="true"] > footer.site-footer,
body[data-auto-init="true"] footer.site-footer.no-print {
  display: none !important;
}

:root {
  --sidebar-width-slim: 56px;
  --sidebar-width-expanded: 280px;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e5e7eb;
  --sidebar-text: #344054;
  --sidebar-text-active: #0f172a;
  --sidebar-hover-bg: #f3f4f6;
  /* gray-50 */
  --sidebar-active-bg: #f0fdf4;
  /* green-50 */
  --sidebar-active-text: #166534;
  /* green-800 */
  --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --header-height: 90px;
  /* Matches site header min-height */
}

/* =========================================================================
   SIDEBAR CONTAINER - FIXED POSITION
   ========================================================================= */
.tka-sidebar {
  position: fixed;
  left: 0;
  top: var(--header-height);
  bottom: 0;
  width: var(--sidebar-width-slim);
  /* Start Slim */
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  /* Unified chrome layer */
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  /* Hide overflowing text in slim mode */
  box-shadow: 1px 0 0 rgba(0, 0, 0, 0.05);
}

/* HOVER STATE: EXPAND */
/* Only on desktop (min-width > 1024px) */
@media (min-width: 1025px) {
  .tka-sidebar:hover {
    width: var(--sidebar-width-expanded);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
    /* Add shadow on expand */
  }

  /* CRITICAL: Ensure mobile toggles are NEVER visible on desktop */
  .mobile-menu-toggle,
  .mobile-sidebar-toggle,
  .sidebar-toggle-btn {
    display: none !important;
  }
}

/* =========================================
   Conflict Resolution
   ========================================= */
/* When the shared sidebar is loaded (.tka-sidebar-loaded on body), 
   hide the default header mobile toggle to prevent "Double Menu" confusion. */
body.tka-sidebar-loaded .mobile-menu-toggle {
  display: none !important;
}

@media (min-width: 1025px) {
  body.tka-sidebar-loaded {
    padding-left: var(--sidebar-width-slim);
    transition: padding-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* HOMEPAGE OVERRIDE: Sidebar overlays on full-bleed hero pages */
  body.tka-sidebar-loaded[data-current-page="home"],
  body.tka-sidebar-loaded[data-current-page="landing"] {
    padding-left: 0 !important;
  }

  /* 
     OVERLAY INTERACTION (Fixes Jitter):
     We no longer push the body content when hovering. 
     The sidebar will expand "over" the content (z-index 100).
     This prevents the footer and other layout elements from dancing/flickering.
  */
  body.tka-sidebar-loaded:has(.tka-sidebar:hover),
  body.tka-sidebar-loaded.sidebar-hovered {
    padding-left: var(--sidebar-width-expanded);
  }

  /* Keep homepage overlay mode even on hover */
  body.tka-sidebar-loaded[data-current-page="home"]:has(.tka-sidebar:hover),
  body.tka-sidebar-loaded[data-current-page="home"].sidebar-hovered,
  body.tka-sidebar-loaded[data-current-page="landing"]:has(.tka-sidebar:hover),
  body.tka-sidebar-loaded[data-current-page="landing"].sidebar-hovered {
    padding-left: 0 !important;
  }
}

body.tka-sidebar-loaded .site-header .nav-container {
  /* Optional: Center logo if toggle is gone? Or keep left? */
  /* justify-content: flex-start; */
}

/* =========================================================================
   HEADER SECTION
   ========================================================================= */
.sidebar-header {
  height: 64px;
  /* Slightly shorter than main header to distinct it */
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  width: 100%;
  gap: 12px;
  overflow: hidden;
  /* Ensure text doesn't bleed in slim mode */
}

.brand-logo-container {
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  opacity: 0;
  /* Hidden in slim */
  transition: opacity 0.2s ease;
  transform: translateX(-10px);
}

/* Show text on hover */
.tka-sidebar:hover .brand-text {
  opacity: 1;
  transform: translateX(0);
  transition-delay: 0.1s;
  /* Slight delay so it doesn't flicker on quick swipes */
}

.brand-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--sidebar-text-active);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: #667085;
}

/* =========================================================================
   NAVIGATION CONTENT
   ========================================================================= */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 8px;
  /* Vertical padding, slim sides */
  display: flex;
  flex-direction: column;
  gap: 24px;
  scrollbar-width: thin;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  position: relative;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px;
  /* 8px padding + 24px icon = roughly centered in 56px */
  border-radius: 8px;
  text-decoration: none;
  color: var(--sidebar-text);
  transition: background 0.2s, color 0.2s;
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.95rem;
  height: 40px;
}

.nav-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.nav-icon {
  min-width: 24px;
  text-align: center;
  font-size: 1.2rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-text {
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease;
  font-weight: 500;
}

.tka-sidebar:hover .nav-text {
  opacity: 1;
}

/* Chevron for submenus */
.chevron {
  margin-left: auto;
  opacity: 0;
  font-size: 1.2rem;
  transition: transform 0.2s ease;
}

.tka-sidebar:hover .chevron {
  opacity: 0.5;
}

.submenu-toggle[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

/* Submenu */
.submenu {
  list-style: none;
  padding: 4px 0 4px 30px;
  /* Indent subitems */
  margin: 0;
  display: none;
  /* Hidden by default */
  flex-direction: column;
  gap: 2px;
}

.submenu-toggle[aria-expanded="true"]+.submenu {
  display: flex;
  /* Only show submenu content if sidebar is expanded, 
     otherwise it looks weird floating in the slim bar. 
     Actually, standard pattern is sidebar MUST be expanded to see submenus.
  */
}

/* Logic: If sidebar is slim, submenus shouldn't be interactable or visible really.
   But if user clicks toggle, it stays expanded. 
   When hovering, we see it.
*/

.submenu-link {
  display: block;
  padding: 6px 12px;
  text-decoration: none;
  color: #475467;
  font-size: 0.9rem;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.submenu-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.tka-sidebar:hover .submenu-link {
  opacity: 1;
}

/* =========================================================================
   FORUM CATEGORIES SECTION
   ========================================================================= */
.forum-categories-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--sidebar-border);
}

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tka-sidebar:hover .nav-section-header {
  opacity: 1;
}

.nav-tree {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* =========================================================================
   FOOTER (WHAKATAUKI / USER PROFILE)
   ========================================================================= */
.sidebar-footer {
  padding: 16px 8px;
  border-top: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center; /* Centered in slim mode */
}

.tka-sidebar:hover .sidebar-footer {
  justify-content: space-between;
  /* Spread in expanded */
  padding: 16px 12px;
}

.user-profile-container {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 12px;
}

/* Auth Mode: Text Left, Avatar Right */
.user-profile-container.auth-mode {
  justify-content: space-between;
}

/* Text Group: Hidden in slim mode */
.profile-text-group {
  display: flex;
  flex-direction: column;
  opacity: 0;
  width: 0;
  visibility: hidden;
  transition: opacity 0.2s;
  overflow: hidden;
}

.tka-sidebar:hover .profile-text-group {
  opacity: 1;
  width: auto;
  visibility: visible;
  flex: 1;
}

.profile-greeting {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--sidebar-text-active);
  white-space: nowrap;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-link {
  font-size: 0.75rem;
  color: #667085;
  text-decoration: none;
  white-space: nowrap;
}

.profile-link:hover {
  color: var(--sidebar-accent-color, #166534);
  text-decoration: underline;
}

/* Avatar Wrapper: Always Visible */
.profile-avatar-wrapper {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* In Slim Mode, Avatar is the only thing shown. 
   It is naturally usually on the "Right" in DOM order? 
   Yes. But in slim 'justify-content: center', it centers.
*/
.profile-avatar-img,
.profile-avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--sidebar-border);
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #667085;
  transition: border-color 0.2s;
}

.tka-sidebar:hover .profile-avatar-img,
.tka-sidebar:hover .profile-avatar-placeholder {
  border-color: var(--sidebar-accent-color, #166534);
}

/* SLIM MODE TEXT HIDING (Aggressive) */
.tka-sidebar:not(:hover) .whakatauki-content,
.tka-sidebar:not(:hover) .whakatauki-label,
.tka-sidebar:not(:hover) .brand-text,
.tka-sidebar:not(:hover) .nav-text,
.tka-sidebar:not(:hover) .nav-section-header,
.tka-sidebar:not(:hover) .sidebar-title-text,
.tka-sidebar:not(:hover) .profile-text-group {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  width: 0 !important;
}

/* =========================================================================
   MOBILE TOGGLE BUTTON
   ========================================================================= */
.mobile-sidebar-toggle {
  display: none;
  /* Hidden by default - shown on mobile via media query */
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  width: 56px;
  height: 56px;
  background: var(--sidebar-bg);
  border: 2px solid var(--sidebar-border);
  border-radius: 50%;
  box-shadow: var(--shadow-medium);
  z-index: 101;
  /* Just above chrome layer */
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.mobile-sidebar-toggle:hover {
  background: var(--sidebar-hover-bg);
  box-shadow: var(--shadow-strong);
  transform: scale(1.05);
}

.mobile-sidebar-toggle:active {
  transform: scale(0.95);
}

/* =========================================================================
   MOBILE OVERLAY & DRAWER (Mobile Only)
   ========================================================================= */
@media (max-width: 1024px) {

  /* Body scroll lock when sidebar is open */
  body.sidebar-open {
    overflow: hidden;
  }

  /* Overlay backdrop */
  .tka-sidebar::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: -1;
    /* Behind sidebar content, above page */
    pointer-events: none;
  }

  .tka-sidebar.expanded::before {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /* Sidebar drawer behavior on mobile */
  .tka-sidebar {
    width: var(--sidebar-width-expanded, 280px);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    z-index: 100;
    /* Unified chrome layer (no need to be higher on mobile) */
    top: 0;
    /* Full height on mobile */
  }

  /* Expanded state - slide in */
  .tka-sidebar.expanded {
    transform: translateX(0);
  }

  /* Show toggle button on mobile */
  .mobile-sidebar-toggle {
    display: flex !important;
  }

  /* On mobile, always show text/icons (no hover state) */
  .tka-sidebar .brand-text,
  .tka-sidebar .nav-text,
  .tka-sidebar .chevron,
  .tka-sidebar .submenu-link,
  .tka-sidebar .whakatauki-label,
  .tka-sidebar .whakatauki-content,
  .tka-sidebar .nav-section-header {
    opacity: 1 !important;
    transform: none !important;
    width: auto !important;
  }

  /* Submenus always visible when parent is expanded */
  .tka-sidebar .submenu-toggle[aria-expanded="true"]+.submenu {
    display: flex;
  }
}