/* ============================================================
   MAIN.CSS — App layout, sidebar, main content, responsive
   ============================================================ */

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

/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width var(--transition-slow);
  overflow: hidden;
}

/* Logo / Brand */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  text-decoration: none;
  flex-shrink: 0;
  cursor: pointer;
}
.sidebar-logo:hover { text-decoration: none; }

.sidebar-logo-icon {
  width: 24px; height: 24px;
  flex-shrink: 0;
  filter: brightness(0) invert(1) drop-shadow(0 0 6px rgba(255,255,255,0.3));
}

.sidebar-logo-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 0;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  position: relative;
  cursor: pointer;
}
.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #e2e8f0;
  text-decoration: none;
}
.nav-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  border-left-color: var(--brand-primary);
}
.nav-item-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}
.nav-item.active .nav-item-icon,
.nav-item:hover .nav-item-icon { opacity: 1; }

/* Notification badge in nav */
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  line-height: 1.6;
}

/* ---- Sidebar User Section ---- */
.sidebar-user {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  position: relative;
  flex-shrink: 0;
}
.sidebar-user-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 8px 8px;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
  width: 100%;
  background: none;
  border: none;
}
.sidebar-user-btn:hover { background: rgba(255,255,255,0.07); }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  background: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  text-transform: uppercase;
}
.user-info { flex: 1; overflow: hidden; text-align: left; }
.user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* User popover */
.user-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 12px; right: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  display: none;
}
.user-popover.open { display: block; }

.user-popover-info {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.user-popover-name  { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-popover-email { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }

.user-popover-actions { padding: 6px; }
.popover-logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.popover-logout-btn:hover { background: var(--danger-bg); }

/* ================================================================
   MAIN CONTENT
   ================================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: var(--content-padding);
  background: var(--bg-secondary);
  transition: margin-left var(--transition-slow);
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header-left {}
.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.page-actions { display: flex; gap: 10px; align-items: center; }

/* ================================================================
   RESPONSIVE BREAKPOINTS
   ================================================================ */

/* ---- Tablet (icon-only sidebar) ---- */
@media (max-width: 1024px) {
  :root { --sidebar-width: var(--sidebar-width-collapsed); }

  .sidebar-logo-text,
  .nav-item span,
  .user-info { display: none; }

  .sidebar-logo { justify-content: center; padding: 16px 12px; }

  .nav-item {
    justify-content: center;
    padding: 12px;
    border-left: none;
    border-bottom: 2px solid transparent;
  }
  .nav-item.active {
    border-left: none;
    border-bottom-color: var(--brand-primary);
  }
  .nav-badge {
    position: absolute; top: 6px; right: 4px;
    min-width: 14px; font-size: 9px; padding: 1px 3px;
  }
  .sidebar-user-btn { justify-content: center; padding: 8px; }
}

/* ---- Mobile (drawer sidebar) ---- */
@media (max-width: 768px) {
  :root { --sidebar-width: 220px; }

  .sidebar {
    transform: translateX(-100%);
    z-index: 300;
    transition: transform var(--transition-slow);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
    padding: 16px;
  }
  .sidebar-logo-text,
  .nav-item span,
  .user-info { display: block; }
  .nav-item {
    justify-content: flex-start;
    padding: 9px 16px;
    border-left: 3px solid transparent;
    border-bottom: none;
  }
  .nav-item.active {
    border-left-color: var(--brand-primary);
    border-bottom: none;
  }
  .nav-badge {
    position: static;
    min-width: 18px; font-size: 10px; padding: 1px 6px;
  }
  .sidebar-user-btn { justify-content: flex-start; }

  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 299;
  }
  .sidebar-overlay.active { display: block; }

  .mobile-menu-btn {
    display: flex !important;
    position: fixed; top: 14px; left: 14px;
    z-index: 200;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    align-items: center;
    justify-content: center;
  }
}

@media (min-width: 769px) {
  .mobile-menu-btn { display: none !important; }
  .sidebar-overlay { display: none !important; }
}

/* ---- Auth pages (no sidebar) ---- */
.auth-page {
  min-height: 100vh;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
