/* ═══════════════════════════════════════════════════
   BUILDAWORLD — SHARED SIDEBAR + LAYOUT
   Include this on every page for consistency.
   ═══════════════════════════════════════════════════ */
:root {
  --sb-w: 220px;
  --sb-w-collapsed: 56px;
  --sb-bg: #0f1117;
  --sb-border: rgba(255,255,255,0.07);
  --sb-text: rgba(255,255,255,0.55);
  --sb-hover: rgba(255,255,255,0.06);
  --sb-active-bg: rgba(92,184,0,0.14);
  --sb-active-color: #7dd63a;
}

/* ── BODY LAYOUT ── */
body {
  display: flex;
  flex-direction: row;
  background: #f1f3f7;
  min-height: 100vh;
  font-family: 'Source Sans 3', sans-serif;
  color: #1a1a1a;
  font-size: 14px;
}

/* ── SIDEBAR ── */
#appSidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sb-w);
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  z-index: 300;
  overflow: hidden;
  transition: width 0.25s cubic-bezier(0.22,1,0.36,1);
  flex-shrink: 0;
}

/* ── APP MAIN ── */
.app-main {
  margin-left: var(--sb-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.25s cubic-bezier(0.22,1,0.36,1);
  min-width: 0;
}

/* ── TOP BAR ── */
.top-bar {
  background: white;
  border-bottom: 1px solid #e8e8e8;
  padding: 0 24px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  flex-shrink: 0;
}
.top-bar-title {
  font-size: 18px;
  font-weight: 800;
  color: #1a1a1a;
  letter-spacing: -0.4px;
}
/* Right-side action button group — shared across every page */
.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
/* Optional left group when a page needs a title + badge cluster */
.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── BRAND ── */
.sb-brand {
  padding: 18px 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
  overflow: hidden;
  min-height: 68px;
}
.sb-brand-mark {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #5cb800, #4a9400);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(92,184,0,0.4);
}
.sb-brand-text { overflow: hidden; flex-shrink: 1; min-width: 0; }
.sb-brand-name {
  font-size: 15px; font-weight: 800; color: white;
  letter-spacing: -0.3px; white-space: nowrap;
  transition: opacity 0.2s;
}
.sb-brand-org {
  font-size: 10px; color: rgba(255,255,255,0.35);
  margin-top: 1px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 140px;
  transition: opacity 0.2s;
}

/* ── NAV ── */
.sb-nav {
  padding: 10px 8px 6px;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  min-height: 0;
}
.sb-nav::-webkit-scrollbar { display: none; }
/* Neutralize the inline flex spacer between nav and org section —
   the scrollable nav already fills the space, so the spacer must not grow */
#appSidebar > div[style*="flex:1"] { flex: 0 0 0 !important; min-height: 0 !important; }
.sb-nav-label {
  font-size: 9px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.8px; color: rgba(255,255,255,0.2);
  padding: 0 8px; margin-bottom: 4px; margin-top: 6px;
  white-space: nowrap; overflow: hidden;
  transition: opacity 0.2s;
}
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px;
  font-size: 13px; font-weight: 600;
  color: var(--sb-text);
  transition: background 0.15s, color 0.15s, transform 0.1s;
  margin-bottom: 1px;
  background: transparent; border: none;
  width: 100%; font-family: inherit;
  text-align: left; text-decoration: none;
  cursor: pointer; white-space: nowrap;
  overflow: hidden; min-height: 36px;
  position: relative;
}
.sb-item:hover { background: var(--sb-hover); color: rgba(255,255,255,0.9); }
.sb-item:active { transform: scale(0.98); }
.sb-item.active {
  background: var(--sb-active-bg);
  color: var(--sb-active-color);
  font-weight: 700;
}
/* Active-page accent bar on the left */
.sb-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--sb-active-color);
  border-radius: 0 3px 3px 0;
}
#appSidebar.collapsed .sb-item.active::before { left: -4px; }
.sb-item-ico {
  flex-shrink: 0; width: 15px; height: 15px;
  opacity: 0.6; transition: opacity 0.13s;
  display: flex; align-items: center; justify-content: center;
}
.sb-item:hover .sb-item-ico, .sb-item.active .sb-item-ico { opacity: 1; }
.sb-item-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* Cleaner collapse control — separated from nav items */
.sb-collapse-btn {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--sb-border) !important;
  border-radius: 0 !important;
  color: rgba(255,255,255,0.35);
  font-size: 12px;
}
.sb-collapse-btn:hover {
  background: transparent !important;
  color: rgba(255,255,255,0.7);
}
.sb-collapse-btn .sb-item-ico { opacity: 0.5; }
.sb-collapse-btn:hover .sb-item-ico { opacity: 0.9; }

/* ── ORGS SECTION ── */
.sb-teams {
  flex: 1; overflow-y: auto; padding: 0 8px 6px;
  scrollbar-width: none;
}
.sb-teams::-webkit-scrollbar { display: none; }
/* Org list: capped height, scrolls internally so it never pushes the profile off */
#sbOrgList {
  max-height: 132px;
  overflow-y: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
#sbOrgList::-webkit-scrollbar { display: none; }
.sb-section-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 3px;
  flex-shrink: 0;
}
/* Collapsible org section header */
.sb-section-toggle {
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.13s;
  user-select: none;
}
.sb-section-toggle:hover { background: var(--sb-hover); }
.sb-section-chev {
  display: flex; align-items: center;
  color: rgba(255,255,255,0.3);
  transition: transform 0.2s;
}
.sb-section-collapsed .sb-section-chev { transform: rotate(-90deg); }
/* Collapse the org list smoothly */
#sbOrgList {
  transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.2s ease;
}
#sbOrgList.sb-org-collapsed {
  max-height: 0 !important;
  opacity: 0;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  overflow: hidden;
  pointer-events: none;
}
.sb-section-lbl {
  font-size: 9px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.8px; color: rgba(255,255,255,0.2);
  white-space: nowrap;
}
.sb-team-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 7px;
  font-size: 12px; font-weight: 600;
  color: rgba(255,255,255,0.45);
  transition: all 0.13s; margin-bottom: 1px;
  background: transparent; border: none;
  width: 100%; font-family: inherit; text-align: left;
  cursor: pointer; white-space: nowrap; overflow: hidden;
  min-height: 32px;
}
.sb-team-item:hover { background: var(--sb-hover); color: rgba(255,255,255,0.8); }
.sb-team-item.active { background: rgba(255,255,255,0.08); color: white; }
.sb-team-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sb-team-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sb-team-count {
  font-size: 10px; font-weight: 700;
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.3);
  padding: 1px 6px; border-radius: 10px; flex-shrink: 0;
}
.sb-team-item.active .sb-team-count { background: rgba(92,184,0,0.2); color: #7dd63a; }

/* ── USER FOOTER ── */
.sb-user {
  padding: 12px 14px;
  border-top: 1px solid var(--sb-border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; cursor: pointer;
  transition: background 0.13s;
  min-height: 60px;
  position: relative;
}
.sb-user::after {
  content: '';
  position: absolute; right: 14px; top: 50%;
  width: 6px; height: 6px;
  border-right: 1.5px solid rgba(255,255,255,0.3);
  border-top: 1.5px solid rgba(255,255,255,0.3);
  transform: translateY(-50%) rotate(-45deg);
  transition: opacity 0.15s;
}
#appSidebar.collapsed .sb-user::after { display: none; }
.sb-user:hover { background: var(--sb-hover); }
.sb-user-av {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #5cb800, #3b7a00);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: white;
  flex-shrink: 0;
  border: 2px solid rgba(92,184,0,0.4);
}
.sb-user-info { flex: 1; min-width: 0; overflow: hidden; transition: opacity 0.2s; }
.sb-user-name {
  font-size: 12px; font-weight: 700; color: white;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-user-email {
  font-size: 10px; color: rgba(255,255,255,0.35);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-user-chevron { color: rgba(255,255,255,0.25); flex-shrink: 0; transition: opacity 0.2s; }

/* User popup menu */
.sb-user-menu {
  display: none; position: absolute;
  bottom: calc(100% + 6px); left: 10px; right: 10px;
  background: #1a1a22; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.4); z-index: 500;
}
.sb-user-menu.open { display: block; animation: sbMenuIn 0.14s ease; }
@keyframes sbMenuIn { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:translateY(0)} }
.sb-user-menu-item {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px; font-size: 12px; font-weight: 600;
  color: rgba(255,255,255,0.7); cursor: pointer;
  transition: background 0.1s; text-decoration: none;
}
.sb-user-menu-item:hover { background: rgba(255,255,255,0.07); color: white; }
.sb-user-menu-item.danger { color: #f87171; }
.sb-user-menu-item.danger:hover { background: rgba(248,113,113,0.1); }

/* ── COLLAPSED STATE ── */
#appSidebar.collapsed { width: var(--sb-w-collapsed); }

/* Hide text when collapsed */
#appSidebar.collapsed .sb-brand-text,
#appSidebar.collapsed .sb-nav-label,
#appSidebar.collapsed .sb-item-label,
#appSidebar.collapsed .sb-section-hdr,
#appSidebar.collapsed .sb-teams,
#appSidebar.collapsed .sb-user-info,
#appSidebar.collapsed .sb-user-chevron {
  opacity: 0;
  width: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Center items when collapsed */
#appSidebar.collapsed .sb-brand { justify-content: center; padding: 18px 0; }
#appSidebar.collapsed .sb-nav { padding: 10px 4px 6px; }
#appSidebar.collapsed .sb-item {
  padding: 9px 0;
  justify-content: center;
  gap: 0;
}
#appSidebar.collapsed .sb-item-ico { width: 18px; height: 18px; opacity: 0.8; }
#appSidebar.collapsed .sb-user {
  padding: 14px 0;
  justify-content: center;
}

/* Adjusted main margin */
#appSidebar.collapsed ~ .app-main,
body.sb-collapsed .app-main { margin-left: var(--sb-w-collapsed); }

/* Tooltip for collapsed items */
#appSidebar.collapsed .sb-item { position: relative; }
#appSidebar.collapsed .sb-item:hover::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 10px); top: 50%;
  transform: translateY(-50%);
  background: #1a1a1a; color: white;
  font-size: 11px; font-weight: 600;
  padding: 5px 10px; border-radius: 6px;
  white-space: nowrap; pointer-events: none; z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

/* ── DARK MODE ── */
body.dark { background: #111113 !important; color: #f0f0f0 !important; }
body.dark .app-main { background: #111113; }
body.dark #appSidebar { background: #09090d; border-right-color: rgba(255,255,255,0.05); }
body.dark .top-bar { background: #111116 !important; border-color: #2a2a2e !important; box-shadow: 0 1px 4px rgba(0,0,0,0.4) !important; }
body.dark .top-bar-title { color: #f0f0f0 !important; }

/* ═══════════════════════════════════════
   CRITICAL OVERRIDES — prevent wrapping
   ═══════════════════════════════════════ */
#appSidebar {
  display: flex !important;
  flex-direction: column !important;
}
.sb-nav {
  display: flex !important;
  flex-direction: column !important;
  gap: 1px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 8px 6px;
}
.sb-item {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  width: 100% !important;
  overflow: hidden;
  white-space: nowrap;
  min-height: 36px;
  box-sizing: border-box;
}
.sb-item-ico {
  flex-shrink: 0 !important;
  width: 16px !important;
  height: 16px !important;
}
.sb-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#appSidebar.collapsed .sb-item {
  padding: 9px 0 !important;
  justify-content: center !important;
  gap: 0 !important;
  width: 56px !important;
}
#appSidebar.collapsed .sb-brand-text,
#appSidebar.collapsed .sb-nav-label,
#appSidebar.collapsed .sb-item-label,
#appSidebar.collapsed .sb-section-hdr,
#appSidebar.collapsed .sb-teams,
#appSidebar.collapsed #sbOrgList,
#appSidebar.collapsed .sb-user-info,
#appSidebar.collapsed .sb-user-chevron { display: none !important; }
#appSidebar.collapsed .sb-brand { justify-content: center !important; padding: 16px 0 !important; }
#appSidebar.collapsed .sb-user { justify-content: center !important; padding: 14px 0 !important; }
.sb-user { margin-top: auto; flex-shrink: 0; }
#appSidebar.collapsed .sb-item:hover::after {
  content: attr(data-tip);
  position: fixed; left: 66px;
  background: #1a1a1a; color: white;
  font-size: 11px; font-weight: 600;
  padding: 5px 10px; border-radius: 6px;
  white-space: nowrap; pointer-events: none;
  z-index: 9999; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ── ORG SWITCHER ITEMS ── */
.sb-team-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  transition: all 0.13s;
  background: transparent;
  border: none;
  width: 100%;
  font-family: inherit;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.sb-team-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.8); }
.sb-team-item.active { background: rgba(255,255,255,0.08); color: white; }
.sb-team-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sb-team-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
