/* ============================================================
   Layout — App Shell, Sidebar, Topbar, Job Bar
   ============================================================ */

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

/* App Shell Grid */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr var(--jobbar-height);
  grid-template-areas:
    "sidebar topbar"
    "sidebar content"
    "sidebar jobbar";
  height: 100vh;
  transition: grid-template-columns var(--transition-base);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

/* ─── Sidebar ─── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition-slow);
  z-index: 100;
}

.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-height);
}

.sidebar-brand svg {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--text-md);
  color: var(--text);
  white-space: nowrap;
}

.sidebar-brand-text span {
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

/* Nav Categories */
.nav-category {
  margin-bottom: var(--space-1);
}

.nav-category-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  cursor: pointer;
  user-select: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color var(--transition-fast);
}

.nav-category-header:hover {
  color: var(--text-secondary);
}

.nav-category-header .chevron {
  width: 14px;
  height: 14px;
  transition: transform var(--transition-fast);
  margin-left: auto;
  opacity: 0.5;
}

.nav-category.collapsed .nav-category-header .chevron {
  transform: rotate(-90deg);
}

.nav-category-items {
  overflow: hidden;
  transition: max-height var(--transition-slow), opacity var(--transition-base);
  max-height: 500px;
  opacity: 1;
}

.nav-category.collapsed .nav-category-items {
  max-height: 0;
  opacity: 0;
}

/* Nav Items */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  padding-left: var(--space-8);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  text-decoration: none;
}

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

.nav-item.active {
  color: var(--primary);
  background: var(--primary-dim);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active svg {
  opacity: 1;
}

/* Home items: no indent */
.nav-category:first-child .nav-item {
  padding-left: var(--space-5);
}

/* ─── Topbar ─── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 90;
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.topbar-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
}

.topbar-toggle svg {
  width: 20px;
  height: 20px;
}

.topbar-breadcrumb {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.topbar-breadcrumb strong {
  color: var(--text);
  font-weight: 600;
}

.topbar-spacer {
  flex: 1;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-dot.offline {
  background: var(--error);
  box-shadow: 0 0 6px var(--error);
}

/* ─── Main Content ─── */
.main-content {
  grid-area: content;
  overflow-y: auto;
  padding: var(--space-6);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.main-content::-webkit-scrollbar {
  width: 6px;
}

.main-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

/* ─── Job Bar ─── */
.job-bar {
  grid-area: jobbar;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  transition: max-height var(--transition-slow);
  max-height: var(--jobbar-height);
  z-index: 80;
}

.job-bar.expanded {
  max-height: 240px;
}

.job-bar-summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-6);
  min-height: var(--jobbar-height);
  font-size: var(--text-xs);
}

.job-bar-summary .label {
  font-weight: 600;
  color: var(--text);
}

.job-badge {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
}

.job-badge.processing {
  background: var(--info-dim);
  color: var(--info);
}

.job-badge.queued {
  background: var(--warning-dim);
  color: var(--warning);
}

.job-badge.completed {
  background: var(--success-dim);
  color: var(--success);
}

.job-bar-items {
  padding: 0 var(--space-6) var(--space-3);
  overflow-y: auto;
  max-height: 180px;
}

.job-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--text-xs);
  border-bottom: 1px solid var(--border);
}

.job-item:last-child {
  border-bottom: none;
}

.job-progress {
  flex: 1;
  height: 4px;
  background: var(--bg-card);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.job-progress-fill {
  height: 100%;
  background: var(--secondary);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}

.job-progress-fill.complete {
  background: var(--success);
}

/* ─── Sidebar Overlay (Mobile) ─── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 99;
}

/* ─── Loading ─── */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-12);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "content"
      "jobbar";
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }

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

  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }

  .topbar-toggle {
    display: flex;
  }

  .main-content {
    padding: var(--space-4);
  }
}

@media (max-width: 480px) {
  .main-content {
    padding: var(--space-3);
  }
}
