/* App Shell */
.app-shell { display: flex; min-height: 100vh; position: relative; }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  background: var(--gradient-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column;
  z-index: var(--z-sticky);
  transition: transform var(--transition-base), width var(--transition-base);
  overflow: hidden;
  contain: strict;
}
.sidebar-logo {
  padding: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--topbar-height); flex-shrink: 0;
}
.sidebar-logo-icon {
  width: 36px; height: 36px;
  background: var(--gradient-brand); border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  flex-shrink: 0; box-shadow: var(--shadow-brand);
}
.sidebar-logo-name {
  font-size: var(--text-lg); font-weight: 800;
  background: var(--gradient-brand);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  white-space: nowrap;
}
.sidebar-logo-tagline { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }
.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--space-4) 0; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--border-default) transparent; }
.sidebar-section { margin-bottom: var(--space-2); }
.sidebar-section-label {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: var(--space-3) var(--space-5) var(--space-1);
}
.sidebar-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  cursor: pointer; transition: all var(--transition-fast);
  position: relative; color: var(--text-secondary);
  font-size: var(--text-sm); font-weight: 500;
  white-space: nowrap; user-select: none;
}
.sidebar-item:hover { background: var(--glass-bg); color: var(--text-primary); }
.sidebar-item.active { background: rgba(255,255,255,0.07); color: var(--text-brand); }
.sidebar-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--gradient-brand); border-radius: 0 2px 2px 0;
}
.sidebar-item-icon { width: 24px; height: 24px; flex-shrink: 0; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; }
.sidebar-item-badge {
  margin-left: auto; background: var(--brand-600); color: white;
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: var(--radius-full);
}
.sidebar-footer { border-top: 1px solid var(--border-subtle); padding: var(--space-4) var(--space-5); flex-shrink: 0; margin-top: auto; }
.sidebar-user {
  display: flex; align-items: center; gap: var(--space-3); cursor: pointer;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  transition: background var(--transition-fast);
  position: relative;
}
.sidebar-user:hover { background: var(--glass-bg); }
.sidebar-user-avatar {
  width: 36px; height: 36px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-sm); color: white; flex-shrink: 0;
  overflow: hidden;
  /* Background is set dynamically by renderAvatarContainer — no CSS override here */
}
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* MAIN CONTENT */
.main-content { margin-left: var(--sidebar-width); flex: 1; min-height: 100vh; display: flex; flex-direction: column; transition: margin-left var(--transition-base); }

/* TOPBAR */
.topbar {
  position: sticky; top: 0; height: var(--topbar-height);
  background: var(--bg-topbar); backdrop-filter: blur(4px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6); z-index: var(--z-sticky); flex-shrink: 0;
}
.topbar-menu-btn {
  display: none; background: none; border: none; color: var(--text-secondary);
  cursor: pointer; padding: var(--space-2); border-radius: var(--radius-sm);
  transition: all var(--transition-fast); font-size: 20px;
}
.topbar-menu-btn:hover { background: var(--glass-bg); color: var(--text-primary); }
.topbar-breadcrumb { display: flex; align-items: center; gap: var(--space-2); flex: 1; }
.breadcrumb-item { font-size: var(--text-sm); color: var(--text-muted); }
.breadcrumb-item.current { color: var(--text-primary); font-weight: 600; }
.breadcrumb-sep { color: var(--text-disabled); font-size: var(--text-xs); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }
/* Legacy .topbar-search — kept for responsive.css reference. New search uses .topbar-search-wrapper in components.css */
.topbar-search {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--bg-input); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); padding: var(--space-2) var(--space-3);
  transition: border-color var(--transition-fast);
}
.topbar-search:focus-within { border-color: var(--border-brand); }
.topbar-search input {
  background: none; border: none; outline: none;
  color: var(--text-primary); font-size: var(--text-sm); width: 180px; font-family: var(--font-sans);
}
.topbar-search input::placeholder { color: var(--text-muted); }
.icon-btn {
  width: 36px; height: 36px; background: var(--glass-bg);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-secondary); transition: all var(--transition-fast); position: relative;
}
.icon-btn:hover { background: var(--bg-card-hover); border-color: var(--border-strong); color: var(--text-primary); }
.icon-btn .badge {
  position: absolute; top: -4px; right: -4px; width: 16px; height: 16px;
  background: var(--accent-rose); border-radius: var(--radius-full);
  font-size: 9px; font-weight: 700; color: white;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg-base);
}

/* PAGE CONTENT */
.page-content { flex: 1; padding: var(--space-6) var(--space-8); position: relative; z-index: var(--z-base); }
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--space-8); gap: var(--space-4); flex-wrap: wrap;
}
.page-header-left { flex: 1; }
.page-title { font-size: var(--text-2xl); font-weight: 800; color: var(--text-primary); margin-bottom: var(--space-1); }
.page-subtitle { font-size: var(--text-sm); color: var(--text-muted); }
.page-header-actions { display: flex; gap: var(--space-3); align-items: center; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(9,9,11,0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: calc(var(--z-modal) - 1);
  transition: opacity 0.2s ease;
}
.sidebar-overlay.visible { display: block; }

/* Collapsible Sidebar Styles */
.app-shell.collapsed .sidebar {
  width: 68px;
}

.app-shell.collapsed .main-content {
  margin-left: 68px;
}

.app-shell.collapsed .sidebar-logo {
  padding: var(--space-5) 0;
  justify-content: center;
}

.app-shell.collapsed .sidebar-logo-icon {
  margin: 0;
}

/* Smooth logo transition */
.sidebar-logo-text-wrapper {
  display: flex;
  flex-direction: column;
  opacity: 1;
  width: auto;
  overflow: hidden;
  transition: opacity var(--transition-base), width var(--transition-base);
}

.app-shell.collapsed .sidebar-logo-text-wrapper {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

/* Smooth section label hide */
.sidebar-section-label {
  transition: opacity var(--transition-base), height var(--transition-base), padding var(--transition-base);
  overflow: hidden;
}

.app-shell.collapsed .sidebar-section-label {
  opacity: 0;
  height: 0;
  padding: 0;
  pointer-events: none;
}

/* Smooth sidebar item label hide */
.sidebar-item-label {
  opacity: 1;
  transition: opacity var(--transition-base), width var(--transition-base), margin var(--transition-base);
  overflow: hidden;
  white-space: nowrap;
}

.app-shell.collapsed .sidebar-item-label {
  opacity: 0;
  width: 0;
  margin-left: 0;
  pointer-events: none;
}

/* Hide health widget smoothly when collapsed */
.sidebar-widget {
  transition: opacity var(--transition-base), height var(--transition-base), padding var(--transition-base), margin var(--transition-base);
  overflow: hidden;
}

.app-shell.collapsed .sidebar-widget {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  border: none;
  pointer-events: none;
}

/* Smooth footer user details hide */
.sidebar-user-info {
  transition: opacity var(--transition-base), width var(--transition-base);
  overflow: hidden;
  white-space: nowrap;
}

.app-shell.collapsed .sidebar-user-info {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

.app-shell.collapsed .sidebar-footer {
  padding: var(--space-4) var(--space-2);
}

.app-shell.collapsed .sidebar-user {
  padding: var(--space-2) 0;
  justify-content: center;
  gap: 0;
}

.app-shell.collapsed .sidebar-item {
  padding: var(--space-3) 0;
  justify-content: center;
  gap: 0;
}

/* Sidebar collapse toggle button in topbar */
.topbar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.topbar-collapse-btn:hover {
  background: var(--glass-bg);
  color: var(--text-primary);
}

@media (max-width: 1023px) {
  .topbar-collapse-btn {
    display: none !important;
  }
}

/* ============ THEME-SPECIFIC LAYOUT OVERRIDES ============ */

/* Light theme: main content and topbar are properly light */
:root.theme-light .main-content { background: var(--bg-base); }
:root.theme-light .page-content { background: var(--bg-base); }
:root.theme-light .topbar { background: var(--bg-topbar); border-bottom-color: var(--border-default); }

/* Light theme: sidebar stays dark (professional contrast sidebar pattern) */
:root.theme-light .sidebar { background: var(--bg-sidebar); }
:root.theme-light .sidebar-item { color: rgba(255,255,255,0.6); }
:root.theme-light .sidebar-item:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.9); }
:root.theme-light .sidebar-item.active { background: rgba(255,255,255,0.15); color: white; }
:root.theme-light .sidebar-section-label { color: rgba(255,255,255,0.3); }
:root.theme-light .sidebar-user-name { color: rgba(255,255,255,0.9); }
:root.theme-light .sidebar-user-role { color: rgba(255,255,255,0.5); }
:root.theme-light .sidebar-logo-tagline { color: rgba(255,255,255,0.4); }

/* Classic theme: neon active sidebar items */
:root.theme-classic .sidebar-item:hover { background: rgba(99,102,241,0.1); }
:root.theme-classic .sidebar-item.active { background: rgba(99,102,241,0.18); }
