.shell {
  --sidebar-current: var(--sidebar-width);

  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.shell[data-collapsed] {
  --sidebar-current: var(--sidebar-rail);
}

.shell__sidebar {
  position: sticky;
  top: 0;
  display: var(--layout-sidebar);
  flex: none;
  flex-direction: column;
  gap: var(--space-8);
  width: var(--sidebar-current);
  height: 100vh;
  height: 100dvh;
  padding: calc(var(--space-6) + var(--safe-top)) var(--space-4) calc(var(--space-6) + var(--safe-bottom)) max(var(--space-4), var(--safe-left));
  overflow: hidden auto;
  border-right: var(--border-width) solid var(--color-border);
  background: var(--color-surface);
  transition: width var(--duration-fast);
}

.shell__sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.shell[data-collapsed] .shell__sidebar-head {
  flex-direction: column;
}

.shell[data-collapsed] .shell__sidebar .brand-logo__wordmark,
.shell[data-collapsed] .shell__sidebar .nav-link__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.shell[data-collapsed] .shell__sidebar .nav-link {
  justify-content: center;
}

.shell__main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.shell__header {
  position: var(--layout-header-position);
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: var(--layout-header-justify);
  gap: var(--space-4);
  padding: calc(var(--space-2) + var(--safe-top)) var(--gutter-right) var(--space-2) var(--gutter-left);
  border-bottom: var(--border-width) solid var(--layout-header-border);
  background: var(--layout-header-bg);
}

.shell__header .shell__brand {
  display: var(--layout-header-brand);
}

.shell__brand {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  text-decoration: none;
}

.shell__content {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: clamp(var(--space-4), 3vw, var(--space-8)) var(--gutter-right) calc(var(--space-16) + var(--safe-bottom)) var(--gutter-left);
}

.icon-button {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: var(--touch-target);
  height: var(--touch-target);
  padding: 0;
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-ink-muted);
  cursor: pointer;
}

.icon-button:hover {
  background: var(--color-field-fill);
  color: var(--color-ink);
}

.shell[data-collapsed] .icon-button svg {
  transform: scaleX(-1);
}

.nav {
  display: grid;
  gap: var(--space-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-ink);
  font-weight: var(--weight-medium);
  text-decoration: none;
}

.nav-link svg {
  flex: none;
}

.nav-link:hover {
  background: var(--color-field-fill);
}

.nav-link[aria-current="page"] {
  background: var(--color-sage-light);
  color: var(--color-sage-600);
  font-weight: var(--weight-semibold);
}

.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-ink-muted);
  cursor: pointer;
  list-style: none;
}

.user-menu__trigger::-webkit-details-marker {
  display: none;
}

.user-menu__trigger:hover {
  background: var(--color-field-fill);
}

.user-menu[open] .user-menu__chevron {
  transform: rotate(180deg);
}

.user-menu__name {
  max-width: var(--layout-menu-name);
  overflow: hidden;
  color: var(--color-ink);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: inline-grid;
  flex: none;
  place-items: center;
  overflow: hidden;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: var(--radius-full);
  background: var(--color-sage-light);
  color: var(--color-sage-600);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.avatar__photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-menu__panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 20;
  display: grid;
  gap: var(--space-4);
  width: min(18rem, calc(100vw - var(--gutter-left) - var(--gutter-right)));
  max-height: calc(100dvh - var(--touch-target) - 2 * var(--space-4) - var(--safe-top));
  padding: var(--space-3);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.user-menu__nav {
  display: var(--layout-menu-nav);
  padding-bottom: var(--space-3);
  border-bottom: var(--border-width) solid var(--color-border);
}

.user-menu__identity {
  display: grid;
  gap: var(--space-1);
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.card {
  padding: clamp(var(--space-6), 5vw, var(--space-10));
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.page-title {
  margin-top: var(--space-3);
  font-size: clamp(var(--text-xl), 5vw, var(--text-2xl));
  overflow-wrap: anywhere;
}

.page-lead {
  margin-top: var(--space-3);
  color: var(--color-ink-muted);
  line-height: var(--leading-relaxed);
  overflow-wrap: anywhere;
}
