/*
 * Component: Navigation
 *
 * Left sidebar navigation for authenticated users.
 * Mobile: collapses to hamburger overlay.
 */

/* ============================================================================
   SIDEBAR - Desktop fixed left panel
   ============================================================================ */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--bg);
  border-right: 0.5px solid var(--border);
  background: var(--accent-bg);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  contain: layout style;
}

/* Sidebar header - logo area (fallback when no org) */
.sidebar-header {
  padding: var(--space-lg) var(--space-md);
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.02em;
  display: block;
}

.sidebar-logo:hover {
  color: var(--accent);
  text-decoration: none;
}

/* Sidebar org identity */
.sidebar-org {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  flex-shrink: 0;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
  margin: var(--space-xs) var(--space-sm) 0;
}

@media (any-hover: hover) {
  a.sidebar-org:hover {
    background: var(--accent-bg);
  }
}

.sidebar-org--active .sidebar-org-name {
  color: var(--accent);
}

.sidebar-org .organization-logo-display {
  width: 36px;
  height: 36px;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-org .organization-logo-placeholder {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

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

.sidebar-org-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* Sidebar navigation */
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-sm) 0;
  overflow-y: auto;
}

.sidebar-nav .nav-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--space-sm);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-light);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  min-height: var(--touch-target-recommended);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: currentColor;
}

turbo-frame#nav_user_avatar,
#nav_user_avatar {
  display: contents;
}

/* Onboarding badge */
.nav-icon-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

/* Nav badge — small count pill shown on nav items (e.g. attention count on Roster) */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-full);
  background: var(--invalid);
  color: oklch(100% 0 0);
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  margin-left: auto;
}

/* Dot variant — used in the bottom nav icon wrap where space is tight */
.nav-badge--dot {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 8px;
  width: 8px;
  height: 8px;
  padding: 0;
  margin-left: 0;
  font-size: 0;
}

.nav-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.nav-avatar--org {
  border-radius: var(--radius-logo);
}

.nav-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: currentColor;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* Active state */
.nav-item.active {
  color: var(--accent);
}

.nav-item.active .nav-icon {
  color: var(--accent);
}

/* Hover state */
@media (any-hover: hover) {
  .nav-item:hover:not(.active) {
    color: var(--text);
  }
}


/* Sidebar log session button */
.sidebar-log-session {
  padding: var(--space-sm) var(--space-md);
}

.sidebar-log-session-btn {
  width: 100%;
  justify-content: center;
}

/* Sidebar Pro today stats */
.sidebar-pro-today {
  flex-shrink: 0;
  padding: var(--space-md) var(--space-md) var(--space-sm);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.sidebar-pro-today-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.sidebar-pro-today-label {
  font-size: 0.65rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}


.sidebar-pro-today-count {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-2);
}

/* Lite usage meters */
.sidebar-lite-meters {
  flex-shrink: 0;
  padding: var(--space-xs) var(--space-sm) var(--space-xs);
  border-top: 1px solid var(--line);
}

.lite-meter {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lite-meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lite-meter-count {
  color: var(--text-2);
  font-weight: 600;
}

.lite-meter-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.lite-meter-fill {
  height: 100%;
  width: var(--meter-fill, 0%);
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.lite-meter-fill--warn {
  background: var(--warn);
}

.lite-meter-fill--full {
  background: var(--invalid);
}

/* Sidebar footer */
.sidebar-footer {
  flex-shrink: 0;
  padding: var(--space-sm) 0;
}

.sidebar-footer .nav-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--space-sm);
}

/* Mobile visibility helpers */
.desktop-only {
  display: none;
}

/* ============================================================================
   MOBILE TOPBAR - Visible only on mobile
   ============================================================================ */

.mobile-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(52px + var(--safe-inset-top));
  background: var(--bg);
  display: flex;
  align-items: center;
  padding: var(--safe-inset-top) var(--space-sm) 0;
  gap: var(--space-sm);
  z-index: 150;
  view-transition-name: mobile-topbar;
  contain: layout style;
}

/* Handled in animations.css */
::view-transition-old(mobile-topbar),
::view-transition-new(mobile-topbar) {
  animation: none;
}

.mobile-topbar-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-left: auto;
}

.topbar-actions .btn-text {
  display: none;
}

.topbar-actions .btn {
  width: 36px;
  height: 36px;
  min-block-size: unset;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0;
  min-height: unset;
  min-width: unset;
  flex-shrink: 0;
}

.mobile-menu-btn .icon {
  width: 22px;
  height: 22px;
  color: currentColor;
}

@media (any-hover: hover) {
  .mobile-menu-btn:hover {
    background: var(--accent-bg);
  }
}

.mobile-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--text);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  text-decoration: none;
}

.mobile-back-btn .icon {
  width: 22px;
  height: 22px;
  color: currentColor;
}

@media (any-hover: hover) {
  .mobile-back-btn:hover {
    background: var(--accent-bg);
  }
}

.desktop-back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  text-decoration: none;
  border: none;
  background: transparent;
}

.desktop-back-btn .icon {
  width: 24px;
  height: 24px;
  color: currentColor;
}

@media (any-hover: hover) {
  .desktop-back-btn:hover {
    background: var(--accent-bg);
    color: var(--text);
  }
}

@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
  .desktop-back-btn {
    display: flex;
  }
}

/* ============================================================================
   SIDEBAR BACKDROP - Mobile overlay
   ============================================================================ */

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0% 0 0 / 0.4);
  z-index: 190;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}

.sidebar-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================================
   RESPONSIVE - Mobile sidebar as overlay
   ============================================================================ */

@media (max-width: 767px), (hover: none) and (pointer: coarse) {

  /* Hide sidebar by default on mobile */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 250ms var(--ease-spring);
    padding-top: var(--safe-inset-top);
    padding-bottom: var(--safe-inset-bottom);
  }

  /* Show sidebar when open */
  .sidebar.is-open {
    transform: translateX(0);
  }

  .desktop-only {
    display: none;
  }
}

@media (min-width: 768px) and (hover: hover) and (pointer: fine) {

  /* Desktop: sidebar always visible */
  .sidebar {
    transform: none;
  }

  /* Desktop: hide mobile topbar */
  .mobile-topbar {
    display: none;
  }

  .desktop-only {
    display: flex;
  }

}



/* ============================================================================
   BOTTOM NAV - Mobile navigation bar (restored original style)
   ============================================================================ */

.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 100;
  background: var(--accent-bg);
  box-shadow: 0 -1px 0 var(--border), 0 -4px 24px oklch(0% 0 0 / 0.06);
  contain: layout style;
}

.nav .nav-container {
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  height: calc(var(--nav-height-mobile) + var(--safe-inset-bottom));
  max-width: 48rem;
  margin: 0 auto;
}

.nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-xs);
  text-decoration: none;
  color: var(--text-lighter);
  transition: color var(--transition-standard), opacity var(--transition-standard);
  position: relative;
  min-height: var(--touch-target-recommended);
  padding: var(--space-sm) var(--space-xs) calc(var(--space-sm) + var(--safe-inset-bottom)) var(--space-xs);
  background: none;
  border: none;
  border-radius: 0;
}

.nav .nav-item.active {
  color: var(--accent);
  background: none;
}

.nav .nav-item .nav-icon {
  width: 24px;
  height: 24px;
}

.nav .nav-item .nav-label {
  font-size: 0.625rem;
  font-weight: 500;
  line-height: 1;
  color: currentColor;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: initial;
  min-width: unset;
}

/* Circle - Add Session button */
.nav-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 50%;
  color: white;
  transition: background-color var(--transition-fast), transform 0.1s ease;
}

.nav-circle .nav-icon {
  width: 20px;
  height: 20px;
}

@media (any-hover: hover) {
  .nav .nav-item:not(.nav-item-add):hover {
    background: var(--accent-bg);
    color: var(--text-lighter);
  }

  .nav .nav-item-add:hover .nav-circle {
    background: color-mix(in oklch, var(--accent) 85%, white);
  }
}

.nav .nav-item-add:active .nav-circle {
  transform: scale(0.92);
}

/* Tap feedback for bottom nav items */
.nav .nav-item:not(.nav-item-add):active {
  opacity: 0.6;
  transform: scale(0.94);
  transition-duration: 0.05s;
}

@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
  .nav {
    display: none;
  }
}

/* ============================================================================
   MOBILE LANDSCAPE - Adjustments for phones rotated to landscape
   ============================================================================ */

@media (orientation: landscape) and (hover: none) and (pointer: coarse) {
  /* Topbar: shorter height (no top notch in landscape), respect side safe areas */
  .mobile-topbar {
    height: 44px;
    padding-top: 0;
    padding-left: max(var(--space-sm), env(safe-area-inset-left, 0px));
    padding-right: max(var(--space-sm), env(safe-area-inset-right, 0px));
  }

  /* Bottom nav: respect side safe areas (notch/home indicator shifts to sides) */
  .nav .nav-container {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
}
