/* App Root Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--bg-main);
  position: relative;
}

/* ========================================================
   1. Left Sidebar
   ======================================================== */
.app-sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: var(--z-sidebar);
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--border-radius-md);
  background: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.4);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffffff;
  background: linear-gradient(135deg, #ffffff 30%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.sidebar-actions {
  padding: 14px 16px 8px;
}

.sidebar-actions .btn-new-project {
  width: 100%;
  justify-content: center;
  font-weight: 600;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(6, 182, 212, 0.15) 100%);
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: #d8b4fe;
}
.sidebar-actions .btn-new-project:hover {
  background: linear-gradient(135deg, var(--primary) 0%, #06b6d4 100%);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 12px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--border-radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(139, 92, 246, 0.14);
  color: #ffffff;
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 15%;
  bottom: 15%;
  width: 3.5px;
  border-radius: 0 4px 4px 0;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}
.nav-item:hover svg, .nav-item.active svg {
  opacity: 1;
}

.nav-item .nav-badge {
  margin-left: auto;
  padding: 2px 7px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: var(--border-radius-full);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.15);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: white;
  font-size: 0.85rem;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ========================================================
   2. Main Center Area & Header
   ======================================================== */
.app-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  background: var(--bg-main);
  position: relative;
}

.app-header {
  height: var(--header-height);
  background: rgba(14, 20, 36, 0.75);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-shrink: 0;
  z-index: var(--z-header);
}

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

.mobile-menu-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--border-radius-sm);
}

.header-title-box {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-breadcrumb {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-search {
  position: relative;
  width: 320px;
  cursor: pointer;
}

.header-search-btn {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  padding: 7px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-search-btn:hover {
  border-color: rgba(255, 255, 255, 0.25);
  background: var(--bg-input-focus);
  color: var(--text-secondary);
}

.search-shortcut {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
}

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

.ai-status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.25);
  padding: 5px 12px;
  border-radius: var(--border-radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent-cyan);
}

.header-icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: var(--border-radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-icon-btn:hover, .header-icon-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.notification-badge-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--primary);
}

/* Main Viewport Content */
.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

/* ========================================================
   3. Right Context Panel
   ======================================================== */
.app-context-panel {
  width: var(--context-panel-width);
  height: 100%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal), transform var(--transition-normal), opacity var(--transition-normal);
  overflow: hidden;
}

.app-context-panel.collapsed {
  width: 0;
  border-left: none;
  opacity: 0;
  pointer-events: none;
}

.context-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.context-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.context-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.context-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  padding: 14px;
}

.context-card-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: var(--z-sidebar);
}

/* ========================================================
   Responsive Media Queries
   ======================================================== */
@media (max-width: 1200px) {
  .app-context-panel {
    position: fixed;
    right: 0;
    top: var(--header-height);
    bottom: 0;
    z-index: var(--z-drawer);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.6);
  }
  .app-context-panel.collapsed {
    transform: translateX(100%);
  }
}

@media (max-width: 900px) {
  .header-search {
    display: none;
  }
  .ai-status-pill span.pill-label {
    display: none;
  }
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: block;
  }
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
  }
  .sidebar-overlay.active {
    display: block;
  }
  .app-main {
    padding: 16px;
  }
  .app-header {
    padding: 0 16px;
  }
}
