/* ==========================================================================
   NAVIGATION COMPONENTS
   ========================================================================== */

/* Sidebar Navigation */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg);
  color: var(--gray-600);
  /* Self-contained chrome — its own column, own grid. Vertical rhythm
     shared with the topbar via --chrome-pad-y. */
  padding: var(--chrome-pad-y) var(--chrome-pad-x-self);
  overflow-y: auto;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.sidebar-nav {
  flex: 1 1 auto;
}

.sidebar-brand {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: var(--space-4);
  text-align: center;
}

.sidebar-brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 210px;
  height: 150px;
  padding: 20px;
  box-sizing: border-box;
  margin: 0 auto;
}

.sidebar-brand-logo img,
.sidebar-brand-logo svg {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto !important;  /* override inline width="100%" on fallback SVGs */
  height: auto !important;
  object-fit: contain;
}

/* App Launcher (cross-app navigation) — styled to sit flush with the nav list */
.app-launcher {
  position: relative;
}

.app-launcher-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.app-launcher-trigger:hover,
.app-launcher.is-open .app-launcher-trigger {
  background: var(--color-surface-2, #f5f5f5);
  color: var(--primary);
}

.app-launcher-popover {
  position: absolute;
  bottom: 100%;
  left: var(--space-3);
  right: var(--space-3);
  z-index: 1100;
  margin-bottom: var(--space-1);
  padding: var(--space-3);
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  background: var(--bg, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.12);
}

.app-launcher-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
}

.app-launcher-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  padding: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--color-surface-2, #f8f8f8);
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.app-launcher-tile:hover {
  background: var(--bg, #fff);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.app-launcher-tile.is-current {
  border-color: var(--primary);
  background: var(--bg, #fff);
  cursor: default;
  pointer-events: none;
}

.app-launcher-tile img,
.app-launcher-tile svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.app-launcher-tile-fallback {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.app-launcher-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-3) 0;
}

.app-launcher-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-launcher-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.8125rem;
  transition: background var(--transition), color var(--transition);
}

.app-launcher-link:hover {
  background: var(--color-surface-2, #f5f5f5);
  color: var(--primary);
}

.app-launcher-link-favicon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  min-width: 20px;
  object-fit: contain;
  border-radius: 3px;
}

.app-launcher-link-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
}

.sidebar-nav a:hover,
.sidebar-nav .active > a {
  background: var(--color-surface-2, #f5f5f5);
  color: var(--primary);
}

.menu-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* Submenu System */
.has-submenu > a {
  cursor: pointer;
}

.submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition);
  margin-top: 4px;
}

.has-submenu.open .submenu {
  max-height: none;
}

.submenu li {
  padding-left: 20px;
}

.submenu li a {
  padding: var(--space-3) var(--space-4);
}

/* Tab Navigation */
.nav-tabs-container {
  margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--border);
}

.nav-tabs {
  display: flex;
  gap: var(--space-2);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 3px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
}

/* Lock the icon size INSIDE every tab to a single value, regardless of
 * what the page passes to icon($name, $size). The codebase historically
 * mixed 14, 15, 16 across hand-rolled vs helper-emitted tabs; this rule
 * guarantees identical visual output platform-wide.
 *
 * !important is intentional: it beats the inline width/height attributes
 * that icon() emits on the SVG. */
.nav-tab svg {
  width: 14px !important;
  height: 14px !important;
  flex-shrink: 0;
}

.nav-tab:hover {
  color: var(--primary);
  background: var(--gray-50);
}

.nav-tab.active,
.nav-tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--gray-50);
}

/* Count badge inside a tab — single source of truth for tab counts.
 * `.count-badge` and `.nav-tab-count` are deliberate aliases so every
 * tab across the platform renders an identical count pill regardless of
 * whether the page uses the tabs() helper (which emits .nav-tab-count)
 * or hand-rolled HTML (which historically used .count-badge). */
.nav-tab-count,
.nav-tab .count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 0.375rem;
  border-radius: 100px;
  font-size: 0.6875rem;
  font-weight: 700;
  background: var(--gray-200, #e5e7eb);
  color: var(--text-muted);
  transition: all var(--transition);
  /* Reset the legacy .count-badge margin (badges.css gave it a left margin
   * that the helper version doesn't have — kill it for tab contexts). */
  margin-left: 0;
}

.nav-tab.active .nav-tab-count,
.nav-tab.is-active .nav-tab-count,
.nav-tab.active .count-badge,
.nav-tab.is-active .count-badge {
  background: var(--primary);
  color: #fff;
}

/* Utility overrides for nav-tabs-container */
.nav-tabs-container.border-0 { border-bottom: 0; }
.nav-tabs-container.mb-0 { margin-bottom: 0; }

/* =========================================================
   nav-tabs — variant: pill
   Tabs sit in a gray pill tray; the active tab is a white
   rounded chip. Compact, good for toolbar switches.
   ========================================================= */
.nav-tabs--pill {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--gray-100, #f3f4f6);
  border-radius: 0.625rem;
}
.nav-tabs--pill .nav-tab {
  padding: 0.4rem 0.9rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted, #6b7280);
  border: 1px solid transparent;
  border-bottom: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  transition: color var(--transition), background var(--transition), box-shadow var(--transition);
}
.nav-tabs--pill .nav-tab:hover {
  color: var(--text, #1f2937);
  background: rgba(255, 255, 255, 0.6);
}
.nav-tabs--pill .nav-tab.active,
.nav-tabs--pill .nav-tab.is-active {
  color: var(--text, #1f2937);
  background: #fff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
}
.nav-tabs--pill .nav-tab-count {
  background: var(--gray-200, #e5e7eb);
  color: var(--text-muted, #6b7280);
}
.nav-tabs--pill .nav-tab.active .nav-tab-count,
.nav-tabs--pill .nav-tab.is-active .nav-tab-count {
  background: var(--primary);
  color: #fff;
}
/* Pill trays typically don't want a wrapper bottom border */
.nav-tabs-container:has(.nav-tabs--pill) { border-bottom: 0; }

/* =========================================================
   nav-tabs — variant: in-header
   Tabs live inside a panel/drawer header row. The tabs define
   their own vertical height via padding; the active tab's
   bottom border sits flush with the header's bottom border.

   If the host header has padding (e.g. .xori-fab-header with
   padding: 0.75rem 1rem), cancel the vertical padding on the
   tabs wrapper so the active underline lands on the header's
   bottom border — see .xori-fab-header override in xori-fab.css.
   ========================================================= */
.nav-tabs--in-header {
  display: flex;
  flex: 1;
  min-width: 0;
  align-self: stretch;
  gap: 0;
}
.nav-tabs--in-header .nav-tab {
  padding: 0.75rem 1rem;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.8125rem;
  border-radius: 0;
}
.nav-tabs--in-header .nav-tab:hover {
  background: transparent;
  color: var(--primary);
}
.nav-tabs--in-header .nav-tab.active,
.nav-tabs--in-header .nav-tab.is-active {
  background: transparent;
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Mobile Header */
.mobile-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg);
  color: var(--gray-700);
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  z-index: 999;
}

.hamburger-btn {
  background: none;
  border: none;
  color: var(--gray-700);
  cursor: pointer;
  padding: var(--space-2);
}

/* View Toggle */
.view-toggle {
  display: flex;
  gap: 0.25rem;
  background: var(--gray-100);
  padding: 0.25rem;
  border-radius: var(--radius);
}

.view-btn {
  padding: 0.5rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.view-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow);
}

/* Submenu Toggle Icons */
.submenu-toggle {
  cursor: pointer;
}

.submenu-toggle .icon-cont:last-child svg,
.submenu-toggle .icon-cont:last-child > * {
  transition: transform var(--transition);
  transform-origin: center;
}

.has-submenu.open .submenu-toggle .icon-cont:last-child svg,
.has-submenu.open .submenu-toggle .icon-cont:last-child > * {
  transform: rotate(180deg);
}

.submenu-toggle > .icon-cont:nth-child(2) svg,
.submenu-toggle > .icon-cont:nth-child(2) > * {
  transition: transform var(--transition);
  transform-origin: center;
}

.has-submenu.open .submenu-toggle > .icon-cont:nth-child(2) svg,
.has-submenu.open .submenu-toggle > .icon-cont:nth-child(2) > * {
  transform: rotate(180deg);
}

.submenu-toggle .menu-label .icon-cont,
.submenu-toggle .menu-label .icon-cont svg,
.submenu-toggle .menu-label .icon-cont > * {
  transform: none !important;
}

/* Sidebar Notification Badges */
.sidebar-badge {
  font-size: 0.6rem;
  padding: 0;
  min-width: 1.1rem;
  height: 1.1rem;
  line-height: 1.1rem;
  text-align: center;
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .mobile-header { 
    display: flex; 
  }
  
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition);
  }
  
  .sidebar.open { 
    transform: translateX(0); 
  }
}