/* ── App Shell Layout ── */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background: var(--surface-1);
}

/* ── Sidebar ── */

.sidebar {
  width: var(--sidebar-width);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface-0);
  border-right: 1px solid var(--border-subtle);
  flex-shrink: 0;
  transition: width var(--duration-slow) var(--ease-out),
              transform var(--duration-slow) var(--ease-out);
  z-index: var(--z-sticky);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  min-height: 56px;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-primary);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  flex-shrink: 0;
}

.sidebar-brand-name {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}

.sidebar.collapsed .sidebar-brand-name {
  opacity: 0;
  width: 0;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.sidebar.collapsed .sidebar-toggle {
  transform: rotate(180deg);
}

/* ── Navigation ── */

.sidebar-nav {
  flex: 1;
  padding: var(--space-2) var(--space-2);
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  margin-bottom: var(--space-4);
}

.nav-section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-1) var(--space-3) var(--space-2);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .nav-section-title {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  user-select: none;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

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

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: var(--color-primary);
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

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

.nav-item-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.75;
}

.nav-item-label {
  transition: opacity var(--duration-normal) var(--ease-out);
}

.sidebar.collapsed .nav-item-label {
  opacity: 0;
  width: 0;
}

.nav-item-badge {
  margin-left: auto;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-on-primary);
  background: var(--color-primary);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}

.sidebar.collapsed .nav-item-badge {
  display: none;
}

/* ── Sidebar Footer ── */

.sidebar-footer {
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* ── Main Content ── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-8);
  scroll-behavior: smooth;
}

.page-container {
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
}

/* ── Page Header ── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
  gap: var(--space-4);
}

.page-header-left {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ── Mobile Overlay ── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: hsla(0, 0%, 0%, 0.4);
  z-index: calc(var(--z-sticky) - 1);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.sidebar-overlay.visible {
  display: block;
}

/* ── Mobile Menu Toggle ── */

.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: calc(var(--z-sticky) + 1);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--surface-0);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

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

  .sidebar.collapsed {
    width: var(--sidebar-width);
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .main-content {
    padding: var(--space-4);
    padding-top: calc(var(--space-4) + 52px);
  }

  .sidebar-header {
    padding-left: 60px;
  }

  .sidebar-toggle {
    display: none;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: var(--sidebar-collapsed);
  }

  .sidebar .nav-section-title,
  .sidebar .sidebar-brand-name,
  .sidebar .nav-item-label,
  .sidebar .nav-item-badge {
    opacity: 0;
    width: 0;
    height: 0;
    overflow: hidden;
  }
}
