/* ==========================================================================
   Desktop shell (wave C1, lane C1-C)

   The rail (#sidebar-root, rendered by the DesktopSidebar island), the thin
   top bar (templates/includes/shell/_topbar.html) and the account menu that
   the island mounts into the top bar's account slot.

   Rules in this file read the shell's sizes as tokens (--sidebar-width,
   --sidebar-collapsed, --topbar-height) and write none of their own. The
   .app-sidebar and .top-bar rules in theme.css still place the outer boxes and
   the content offsets beside the rail; the old rail internals (.nav-item and
   the rest) are gone, and every element here carries a shell- class.

   Logical properties only; no raw colour; no dark-mode fork (the tokens
   already carry both themes); breakpoints from the ladder in
   design-tokens.md.
   ========================================================================== */

/* The rail is --sidebar-width on every screen; theme.css narrowed it to 92 %
   from 1200px, which made it 202px against a 220px design. */
body {
  --dock-w: var(--sidebar-width);
}

/* --------------------------------------------------------------------------
   Rail
   -------------------------------------------------------------------------- */

.shell-sidebar {
  overflow: hidden;
}

.shell-rail-brand {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--space-sm);
  min-height: var(--topbar-height);
  padding-inline: var(--space-md);
  border-bottom: 1px solid var(--border-dark);
  color: var(--text-primary);
  font-size: var(--font-size-lg);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.shell-rail-brand svg {
  flex: 0 0 auto;
  color: var(--craft-green-text);
}

.shell-sidebar.minimized .shell-rail-brand {
  justify-content: center;
  padding-inline: 0;
}

.shell-sidebar.minimized .shell-rail-brand span {
  display: none;
}

.shell-nav {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: var(--space-xs);
  min-height: 0;
  padding: var(--space-sm);
  overflow-x: hidden;
  overflow-y: auto;
}

.shell-nav__divider {
  flex: 0 0 auto;
  height: 1px;
  margin-block: var(--space-sm);
  margin-inline: var(--space-sm);
  background: var(--border-dark);
}

.shell-nav__item {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--space-md);
  /* One step above the pointer tier (36px for a fine pointer). */
  min-height: calc(var(--shell-target) + 6px);
  padding-block: var(--space-sm);
  padding-inline: var(--space-md);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
}

.shell-nav__item:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

.shell-nav__item:focus-visible,
.shell-collapse:focus-visible,
.shell-rail-brand:focus-visible {
  outline-offset: -2px;
}

.shell-nav__item[aria-current="page"] {
  background: var(--craft-indigo-tint);
  color: var(--text-primary);
}

/* The current page is marked on the inline-start edge, so it mirrors. */
.shell-nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset-block: 25%;
  inset-inline-start: 0;
  width: 3px;
  border-radius: var(--radius-xs);
  background: var(--craft-green-text);
}

.shell-nav__icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
}

.shell-nav__item:hover .shell-nav__icon,
.shell-nav__item[aria-current="page"] .shell-nav__icon {
  color: var(--craft-green-text);
}

.shell-nav__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell-nav__badge {
  flex: 0 0 auto;
  margin-inline-start: auto;
  min-width: 1.5rem;
  padding: 1px var(--space-sm);
  border-radius: var(--radius-full);
  background: var(--craft-indigo);
  color: var(--accent-contrast);
  font-size: var(--font-size-xs);
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}

/* Create: the one emphasised destination. Colour and gradient are painted by
   the .nav-item-create rules of the island (the contrast gate reads them
   there); here only its shape. */
.shell-nav__item--create {
  justify-content: center;
  margin-block: var(--space-sm);
  border-radius: var(--radius-full);
  font-weight: 700;
}

/* The pill is painted with --craft-gradient-hero, whose middle stop is the
   light theme's --focus-ring (#4B0082 on the default palette), so the inset
   ring every other rail item draws would vanish into it. Like the gradient
   [data-btn], its ring sits outside, on the rail. The nav scrolls, and focus
   scrolls the pill flush with its edge, so the scroll margin keeps the ring
   (offset + 2px stroke) inside the clip. */
.shell-nav__item--create:focus-visible {
  outline-offset: var(--focus-ring-offset, 2px);
  scroll-margin-block: calc(var(--focus-ring-offset, 2px) + 2px);
}

.shell-nav__item--create[aria-current="page"]::before {
  content: none;
}

/* Rail foot: install prompt, the one-time dock question, then Collapse, which
   is the last element of the rail. */
.shell-rail-foot {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-top: 1px solid var(--border-dark);
}

.shell-collapse {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  /* One step above the pointer tier (36px for a fine pointer). */
  min-height: calc(var(--shell-target) + 6px);
  padding-block: var(--space-sm);
  padding-inline: var(--space-md);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
}

.shell-collapse:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

/* The chevrons point at the edge the rail is docked to (it is placed by the
   dock, not by the text direction), so the island picks the glyph. */
.shell-collapse__icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
}

/* Collapsed: icons only. The labels stay in the page for assistive
   technology. */
.shell-sidebar.minimized .shell-nav__label,
.shell-sidebar.minimized .shell-collapse__label,
.shell-sidebar.minimized .shell-dock-ask {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.shell-sidebar.minimized .shell-nav__item,
.shell-sidebar.minimized .shell-collapse {
  justify-content: center;
  padding-inline: 0;
}

.shell-sidebar.minimized .shell-nav__badge {
  position: absolute;
  inset-block-start: var(--space-xs);
  inset-inline-end: var(--space-xs);
  min-width: 0;
  padding: 0 var(--space-xs);
}

/* One-time dock question (left or right only). */
.shell-dock-ask {
  margin: 0;
  padding-inline: var(--space-md);
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.shell-dock-toggle {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--surface-dark);
}

.shell-dock-toggle__btn {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  min-height: var(--shell-target);
  padding: var(--space-sm);
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.shell-dock-toggle__btn:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

.shell-dock-toggle__btn[aria-pressed="true"] {
  background: var(--craft-indigo);
  color: var(--accent-contrast);
}

.shell-sidebar.minimized .shell-dock-toggle {
  flex-direction: column;
}

/* Install prompt. */
.shell-install {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
}

.shell-install__action {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-start;
}

.shell-install__dismiss {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-width: var(--shell-target);
  min-height: var(--shell-target);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.shell-install__dismiss:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

.shell-sidebar.minimized .shell-install {
  display: none;
}

/* --------------------------------------------------------------------------
   Top bar: search, bell, account. Brand and navigation are in the rail.
   -------------------------------------------------------------------------- */

.shell-topbar {
  min-height: var(--topbar-height);
  padding-block: var(--space-sm);
  padding-inline: var(--space-lg);
  gap: var(--space-md);
}

.shell-topbar .search-container {
  flex: 1 1 auto;
  max-inline-size: 40rem;
}

/* theme.css forces every input[type=search] to one padding with !important,
   which erased the island's own gutter for the icon. These win on specificity
   and keep the gutter on the inline-end side, in both directions. */
.shell-topbar .shell-search__input {
  inline-size: 100%;
  padding-block: var(--space-sm) !important;
  padding-inline-start: var(--space-md) !important;
  padding-inline-end: var(--space-2xl) !important;
  border-radius: var(--radius-full) !important;
  font-size: var(--font-size-sm);
}

.shell-search__icon {
  position: absolute;
  inset-block: 0;
  inset-inline-end: var(--space-md);
  display: flex;
  align-items: center;
  pointer-events: none;
  color: var(--text-muted);
}

.shell-topbar .top-nav-controls--desktop {
  margin-inline-start: auto;
  gap: var(--space-sm);
}

.shell-account-slot {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  /* Held open until the island puts the account control here. */
  min-height: var(--shell-target);
  min-width: var(--shell-target);
}

/* A guest's block (language, theme, help, Log in, Sign up) is 298px in
   Persian, 314px in English and 366px in German. The slot reserves the widest,
   so the search field does not shrink when the island mounts, and the block
   sits at the inline end. */
.shell-account-slot[data-guest="true"] {
  justify-content: flex-end;
  min-inline-size: 23rem;
}

.shell-mode-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--craft-pink-text);
  border-radius: var(--radius-full);
  color: var(--craft-pink-text);
  font-size: var(--font-size-xs);
  font-weight: 700;
  white-space: nowrap;
}

.shell-account-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--shell-target);
  min-height: var(--shell-target);
  padding: 2px;
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  background: transparent;
  cursor: pointer;
}

.shell-account-trigger:hover {
  background: var(--surface-light);
}

/* The ring marks an account page. It is a state of the button, not a page, so
   it is not aria-current: the matching row inside the open menu carries that. */
.shell-account-trigger[data-active="true"] {
  border-color: var(--craft-green-text);
}

/* Guest controls: language, theme, help, then Log in and Sign up. */
.shell-guest {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.shell-guest__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--shell-target);
  min-height: var(--shell-target);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
}

.shell-guest__icon-btn:hover {
  background: var(--surface-highlight);
  color: var(--craft-green-text);
}

.shell-lang {
  min-height: var(--shell-target);
  padding-inline: var(--space-sm);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Account menu
   -------------------------------------------------------------------------- */

.shell-menu {
  min-width: 14rem;
  max-height: calc(100vh - var(--topbar-height));
  padding: var(--space-sm);
  overflow-y: auto;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
}

.shell-menu__who {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  font-size: var(--font-size-sm);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.shell-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  min-height: var(--shell-target);
  padding-block: var(--space-sm);
  padding-inline: var(--space-sm);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--font-size-sm);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
  outline: none;
}

.shell-menu__item:hover,
.shell-menu__item[data-highlighted] {
  background: var(--surface-light);
  color: var(--text-primary);
}

.shell-menu__item[data-highlighted] {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

.shell-menu__item--danger {
  color: var(--status-danger-text);
}

.shell-menu__item--current {
  color: var(--text-primary);
  font-weight: 700;
}

.shell-menu__icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}

.shell-menu__check {
  margin-inline-start: auto;
}

.shell-menu__label {
  padding: var(--space-sm) var(--space-sm) var(--space-xs);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.shell-menu__separator {
  height: 1px;
  margin: var(--space-sm) var(--space-xs);
  background: var(--border-dark);
}
