/* ============================================
   ZeroLabs Security - Layout System
   Sidebar Navigation & App Shell
   ============================================ */

/* ============================================
   1. APP LAYOUT STRUCTURE
   ============================================ */

.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg-base, #fafafa);
  overflow-x: hidden;
  width: 100%;
}

/* When logged out, center content */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: var(--bg-base, #fafafa);
}

/* ============================================
   2. SIDEBAR
   ============================================ */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width, 260px);
  height: 100vh;
  background: var(--bg-surface, #ffffff);
  border-right: 1px solid var(--border-default, #e4e4e7);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar, 400);
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Collapsed State */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width, 72px);
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .user-info,
.sidebar.collapsed .stats-mini {
  display: none;
}

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

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
}

.sidebar.collapsed .sidebar-collapse-btn {
  position: static;
  margin-left: 0;
}

.sidebar.collapsed .sidebar-collapse-btn i {
  transform: rotate(180deg);
}

.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 12px;
}

.sidebar.collapsed .nav-icon {
  margin-right: 0;
}

.sidebar.collapsed .user-menu {
  justify-content: center;
  padding: 12px;
}

.sidebar.collapsed .user-avatar {
  margin-right: 0;
}

.sidebar.collapsed .user-actions {
  display: none;
}

/* ----------------------------------------
   2.1 Sidebar Header
   ---------------------------------------- */

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border-muted, #f4f4f5);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary, #18181b);
}

.brand-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary-600, #4f46e5) 0%, var(--color-primary-500, #6366f1) 100%);
  border-radius: 10px;
  color: white;
  font-size: 16px;
  flex-shrink: 0;
}

.brand-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.sidebar-collapse-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-default, #e4e4e7);
  border-radius: 6px;
  color: var(--text-muted, #a1a1aa);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background: var(--interactive-hover, #fafafa);
  color: var(--text-primary, #18181b);
  border-color: var(--border-strong, #d4d4d8);
}

.sidebar-collapse-btn i {
  font-size: 12px;
  transition: transform 0.25s ease;
}

/* ----------------------------------------
   2.2 Sidebar Navigation
   ---------------------------------------- */

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
}

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

.nav-section-title {
  display: block;
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #a1a1aa);
  margin-top: 8px;
}

.nav-section-title:first-child {
  margin-top: 0;
}

.nav-item {
  margin-bottom: 2px;
}

.nav-divider {
  height: 1px;
  background: var(--border-muted, #f4f4f5);
  margin: 12px 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary, #52525b);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  position: relative;
}

.nav-link:hover {
  background: var(--interactive-hover, #fafafa);
  color: var(--text-primary, #18181b);
}

.nav-link.active {
  background: var(--interactive-selected, rgba(99, 102, 241, 0.1));
  color: var(--color-primary-600, #4f46e5);
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--color-primary-600, #4f46e5);
  border-radius: 0 3px 3px 0;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.nav-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  background: var(--color-primary-100, #e0e7ff);
  color: var(--color-primary-700, #4338ca);
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

[data-theme="dark"] .nav-badge {
  background: rgba(99, 102, 241, 0.2);
  color: var(--color-primary-300, #a5b4fc);
}

/* ----------------------------------------
   2.3 Sidebar Footer
   ---------------------------------------- */

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-muted, #f4f4f5);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-subtle, #fafafa);
  border-radius: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-100, #e0e7ff);
  color: var(--color-primary-600, #4f46e5);
  border-radius: 8px;
  font-size: 14px;
  flex-shrink: 0;
}

[data-theme="dark"] .user-avatar {
  background: rgba(99, 102, 241, 0.2);
  color: var(--color-primary-400, #818cf8);
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #18181b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  display: block;
  font-size: 12px;
  color: var(--text-muted, #a1a1aa);
}

.user-actions {
  display: flex;
  gap: 4px;
}

.logout-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted, #a1a1aa);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.logout-btn:hover {
  background: var(--color-danger-100, #fee2e2);
  color: var(--color-danger-600, #dc2626);
}

[data-theme="dark"] .logout-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-danger-400, #f87171);
}

/* ============================================
   3. MAIN CONTENT WRAPPER
   ============================================ */

.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width, 260px);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed ~ .main-wrapper,
[data-sidebar="collapsed"] .main-wrapper {
  margin-left: var(--sidebar-collapsed-width, 72px);
}

.main-wrapper.no-sidebar {
  margin-left: 0;
}

/* ----------------------------------------
   3.1 Top Header
   ---------------------------------------- */

.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height, 64px);
  padding: 0 24px;
  background: var(--bg-surface, #ffffff);
  border-bottom: 1px solid var(--border-default, #e4e4e7);
  position: sticky;
  top: 0;
  z-index: var(--z-header, 500);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-center {
  flex: 1;
  max-width: 480px;
  margin: 0 24px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
}

.breadcrumb ol {
  display: flex;
  align-items: center;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 4px;
}

.breadcrumb li {
  display: flex;
  align-items: center;
}

.breadcrumb li:not(:last-child)::after {
  content: '/';
  margin-left: 8px;
  color: var(--text-muted, #a1a1aa);
  font-size: 14px;
}

.breadcrumb a {
  color: var(--text-muted, #a1a1aa);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.15s ease;
}

.breadcrumb a:hover {
  color: var(--color-primary-600, #4f46e5);
}

.breadcrumb li:last-child span {
  color: var(--text-primary, #18181b);
  font-size: 14px;
  font-weight: 500;
}

/* Search Box */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box i {
  position: absolute;
  left: 12px;
  color: var(--text-muted, #a1a1aa);
  font-size: 14px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 38px;
  background: var(--bg-subtle, #fafafa);
  border: 1px solid var(--border-default, #e4e4e7);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-primary, #18181b);
  transition: all 0.15s ease;
}

.search-input:focus {
  outline: none;
  background: var(--bg-surface, #ffffff);
  border-color: var(--color-primary-500, #6366f1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.search-input::placeholder {
  color: var(--text-muted, #a1a1aa);
}

.search-shortcut {
  position: absolute;
  right: 8px;
  padding: 4px 6px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-default, #e4e4e7);
  border-radius: 4px;
  color: var(--text-muted, #a1a1aa);
  pointer-events: none;
}

/* Icon Buttons */
.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-secondary, #52525b);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.icon-btn:hover {
  background: var(--interactive-hover, #fafafa);
  color: var(--text-primary, #18181b);
}

.icon-btn i {
  font-size: 18px;
}

/* Notification Button */
.notification-btn {
  position: relative;
}

.notification-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
  background: var(--color-danger-500, #ef4444);
  color: white;
  border-radius: 8px;
}

/* Theme Toggle Button */
.theme-toggle-btn {
  position: relative;
}

.theme-toggle-btn .theme-icon-light,
.theme-toggle-btn .theme-icon-dark {
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.theme-toggle-btn .theme-icon-dark {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg);
}

[data-theme="dark"] .theme-toggle-btn .theme-icon-light {
  opacity: 0;
  transform: rotate(90deg);
}

[data-theme="dark"] .theme-toggle-btn .theme-icon-dark {
  opacity: 1;
  transform: rotate(0);
}

/* User Menu in Header */
.header-user-menu {
  position: relative;
}

.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  background: var(--bg-subtle, #fafafa);
  border: 1px solid var(--border-default, #e4e4e7);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.user-menu-btn:hover {
  background: var(--interactive-hover, #fafafa);
  border-color: var(--border-strong, #d4d4d8);
}

.user-avatar-sm {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-100, #e0e7ff);
  color: var(--color-primary-600, #4f46e5);
  border-radius: 6px;
  font-size: 12px;
}

.user-name-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary, #18181b);
}

.user-menu-btn i:last-child {
  font-size: 10px;
  color: var(--text-muted, #a1a1aa);
}

/* User Dropdown */
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-default, #e4e4e7);
  border-radius: 10px;
  box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.15s ease;
}

.user-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--text-secondary, #52525b);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s ease;
}

.dropdown-item:hover {
  background: var(--interactive-hover, #fafafa);
  color: var(--text-primary, #18181b);
}

.dropdown-item.text-danger {
  color: var(--color-danger-600, #dc2626);
}

.dropdown-item.text-danger:hover {
  background: var(--color-danger-50, #fef2f2);
}

.dropdown-item i {
  width: 16px;
  text-align: center;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-muted, #f4f4f5);
  margin: 6px 0;
}

/* ----------------------------------------
   3.2 Main Content
   ---------------------------------------- */

.main-content {
  flex: 1;
  padding: 24px;
  overflow-x: hidden;
}

/* Page Header */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary, #18181b);
  margin-bottom: 4px;
}

.page-header p {
  font-size: 15px;
  color: var(--text-secondary, #52525b);
}

/* Content Container */
.content-container {
  max-width: var(--container-max-width, 1280px);
  margin: 0 auto;
}

/* ============================================
   4. MOBILE LAYOUT
   ============================================ */

/* Mobile Header (hidden by default) */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-surface, #ffffff);
  border-bottom: 1px solid var(--border-default, #e4e4e7);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: var(--z-header, 500);
}

.mobile-menu-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-primary, #18181b);
  cursor: pointer;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary, #18181b);
}

.mobile-brand i {
  color: var(--color-primary-600, #4f46e5);
}

.mobile-actions {
  display: flex;
  gap: 4px;
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-sidebar, 400) - 1);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.active {
  opacity: 1;
}

/* ============================================
   5. RESPONSIVE STYLES
   ============================================ */

@media (max-width: 1024px) {
  /* Show mobile header */
  .mobile-header {
    display: flex;
  }

  /* Hide desktop sidebar by default */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(0, 0, 0, 0.1));
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Show overlay when sidebar is open */
  .sidebar.mobile-open ~ .sidebar-overlay,
  .sidebar-overlay.active {
    display: block;
  }

  /* Adjust main wrapper */
  .main-wrapper {
    margin-left: 0;
    padding-top: 56px;
  }

  /* Hide desktop header elements */
  .header-center {
    display: none;
  }

  .header-user-menu {
    display: none;
  }

  .top-header {
    padding: 0 16px;
    display: none;
  }

  /* Main content adjustments */
  .main-content {
    padding: 16px;
  }

  /* Prevent body scroll when sidebar is open */
  body.sidebar-open {
    overflow: hidden;
  }
}

@media (max-width: 640px) {
  .search-shortcut {
    display: none;
  }

  .main-content {
    padding: 12px;
  }

  .page-header h1 {
    font-size: 24px;
  }
}

/* ============================================
   6. DARK MODE ADJUSTMENTS
   ============================================ */

[data-theme="dark"] .sidebar {
  background: var(--bg-surface, #0f172a);
  border-color: var(--border-default, #1e293b);
}

[data-theme="dark"] .sidebar-header {
  border-color: var(--border-muted, #1e293b);
}

[data-theme="dark"] .top-header {
  background: var(--bg-surface, #0f172a);
  border-color: var(--border-default, #1e293b);
}

[data-theme="dark"] .mobile-header {
  background: var(--bg-surface, #0f172a);
  border-color: var(--border-default, #1e293b);
}

[data-theme="dark"] .user-menu {
  background: var(--bg-muted, #1e293b);
}

[data-theme="dark"] .user-dropdown {
  background: var(--bg-surface, #0f172a);
  border-color: var(--border-default, #1e293b);
}

[data-theme="dark"] .search-input {
  background: var(--bg-muted, #1e293b);
  border-color: var(--border-default, #334155);
}

[data-theme="dark"] .search-shortcut {
  background: var(--bg-elevated, #1e293b);
  border-color: var(--border-default, #334155);
}

[data-theme="dark"] .user-menu-btn {
  background: var(--bg-muted, #1e293b);
  border-color: var(--border-default, #334155);
}

/* ============================================
   7. ACCESSIBILITY
   ============================================ */

/* Focus visible styles */
.nav-link:focus-visible,
.icon-btn:focus-visible,
.user-menu-btn:focus-visible,
.sidebar-collapse-btn:focus-visible {
  outline: 2px solid var(--color-primary-500, #6366f1);
  outline-offset: 2px;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary-600, #4f46e5);
  color: white;
  padding: 8px 16px;
  z-index: 1001;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .main-wrapper,
  .sidebar-collapse-btn i,
  .user-dropdown,
  .sidebar-overlay {
    transition: none;
  }
}

/* ============================================
   8. PRINT STYLES
   ============================================ */

@media print {
  .sidebar,
  .mobile-header,
  .top-header,
  .sidebar-overlay {
    display: none !important;
  }

  .main-wrapper {
    margin-left: 0 !important;
    padding-top: 0 !important;
  }

  .main-content {
    padding: 0 !important;
  }
}
