.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100vh;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
}

.app-shell.chrome-hidden {
  display: block;
}

.app-shell.chrome-hidden .page-layer,
.app-shell.chrome-hidden .workbench {
  height: 100%;
  min-height: 0;
}

.app-shell.chrome-hidden .page-layer {
  padding-bottom: 0;
}

.app-shell.chrome-hidden .workbench {
  display: block;
}

.app-rail {
  position: sticky;
  z-index: 50;
  top: 0;
  display: flex;
  height: 100vh;
  height: 100svh;
  flex-direction: column;
  align-items: center;
  padding: 14px 10px;
  color: rgba(255, 255, 255, 0.58);
  background: var(--surface-dark);
}

.brand-mark {
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  margin-bottom: 22px;
  color: white;
  background: var(--accent);
  border-radius: var(--radius-12);
}

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 1.5px solid currentColor;
  content: "";
}

.brand-mark::before {
  top: 11px;
  left: 11px;
}

.brand-mark::after {
  right: 11px;
  bottom: 11px;
}

.brand-mark span {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 8px;
  height: 8px;
  background: currentColor;
}

.brand-mark i {
  position: absolute;
  bottom: 11px;
  left: 11px;
  width: 8px;
  height: 8px;
  background: currentColor;
  border-radius: 50%;
}

.rail-nav {
  display: flex;
  width: 100%;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 7px;
}

.rail-nav.bottom {
  min-height: auto;
  flex: 0;
  margin-top: auto;
}

.rail-btn {
  position: relative;
  display: grid;
  width: 100%;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  color: inherit;
  background: transparent;
  border-radius: var(--radius-12);
  text-decoration: none;
  transition: color 160ms ease, background 160ms ease, transform 160ms ease;
}

.rail-btn:hover {
  color: var(--on-dark);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.rail-btn.active {
  color: var(--on-dark);
  background: rgba(255, 255, 255, 0.12);
}

.rail-btn.active::before {
  position: absolute;
  left: -10px;
  width: 3px;
  height: 20px;
  background: var(--accent);
  border-radius: 0 var(--radius-4) var(--radius-4) 0;
  content: "";
}

.rail-btn::after {
  position: absolute;
  z-index: 100;
  left: 57px;
  padding: 7px 10px;
  color: var(--on-dark);
  background: rgba(25, 25, 25, 0.94);
  border-radius: var(--radius-8);
  content: attr(data-label);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
  white-space: nowrap;
}

.rail-btn:hover::after {
  opacity: 1;
  transform: translateX(0);
}

.rail-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--ink);
  background: var(--paper);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 750;
}

.rail-avatar.has-photo {
  background-position: center;
  background-size: cover;
}

.app-frame {
  position: relative;
  display: flex;
  min-width: 0;
  height: 100vh;
  height: 100svh;
  min-height: 100svh;
  flex-direction: column;
}

.shell-ai-task-pill {
  position: fixed;
  z-index: 48;
  top: 16px;
  /* The outer 40px lane belongs to route-level close controls. */
  right: calc(max(16px, env(safe-area-inset-right)) + 58px);
  display: flex;
  max-width: min(
    360px,
    calc(
      100vw - 168px
      - env(safe-area-inset-left)
      - env(safe-area-inset-right)
    )
  );
  min-height: 34px;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(14px);
  font-size: 11px;
  font-weight: 700;
}

.shell-ai-task-pill[hidden] {
  display: none;
}

.shell-ai-task-pill i {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 30%, transparent);
  animation: ai-task-pulse 1.4s ease-out infinite;
}

.shell-ai-task-pill span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell-ai-task-pill b {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 10px;
}

@keyframes ai-task-pulse {
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.rail-btn.has-alerts {
  position: relative;
  color: var(--accent);
}

.shell-notification-count {
  position: absolute;
  top: -3px;
  right: -4px;
  display: grid;
  min-width: 15px;
  height: 15px;
  place-items: center;
  padding: 0 4px;
  color: white;
  background: var(--accent);
  border: 2px solid var(--paper);
  border-radius: var(--radius-pill);
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
}

.shell-alert-stack {
  position: relative;
  z-index: 35;
  display: grid;
  flex: 0 0 auto;
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.shell-alert {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 7px 24px;
  color: var(--ink-2);
  background: var(--warning-soft);
  font-size: 12px;
}

.shell-alert.critical {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.shell-alert > .icon {
  width: 15px;
  height: 15px;
}

.shell-alert-copy {
  min-width: 0;
  flex: 1;
}

.shell-alert .btn {
  flex: 0 0 auto;
}

.shell-alert-dismiss {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.mobile-menu-btn,
.mobile-workspace-tools,
.mobile-dock {
  display: none;
}

.page-layer {
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

/* Класс появления НЕ снимается после проигрывания, поэтому заливка обязана
   быть backwards, а не both: анимация с заливкой forwards остаётся «активной»
   навсегда, и браузер держит слой контекстом наложения — как если бы на нём
   стоял transform. Мобильная шторка с чатами лежит внутри .page-layer, а её
   затемняющая подложка снаружи: из-за запертого контекста подложка
   оказывалась ВЫШЕ шторки, та просвечивала сквозь затемнение и не принимала
   клики. backwards даёт тот же плавный вход и ничего после себя не оставляет. */
.page-layer.is-entering {
  animation: page-enter 280ms cubic-bezier(.2, .8, .2, 1) backwards;
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.workbench {
  position: relative;
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-columns: var(--context-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  transition: grid-template-columns 180ms cubic-bezier(.2, .8, .2, 1);
}

.workbench.no-context {
  grid-template-columns: minmax(0, 1fr);
}

.workbench.context-resizing {
  transition: none;
  user-select: none;
}

/* Идёт переход на другой маршрут.
   Фабрика экрана сначала грузит свои данные и только потом отдаёт DOM, а до
   этого на месте стоит прежний экран. Полоса — единственное, что сообщает
   «клик услышан»; она НИЧЕГО не перерисовывает, поэтому не мешает работать в
   том, что сейчас на экране, и не мигает на быстрых переходах. */
.workbench.route-busy::before {
  content: "";
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--accent) 42%,
    var(--accent) 58%,
    transparent 100%);
  background-size: 42% 100%;
  background-repeat: no-repeat;
  /* Появление и бег — РАЗНЫЕ анимации.
     Задержка на появлении — чтобы быстрый переход не успел мигнуть полосой
     вовсе. Держит полосу видимой именно появление (forwards), а не бег: если
     бег притормозит (свёрнутая вкладка, слабая машина), полоса всё равно
     останется на месте, а не исчезнет вместе с ним. */
  opacity: 0;
  animation:
    route-busy-in 120ms linear 140ms forwards,
    route-busy-sweep 900ms linear 140ms infinite;
  pointer-events: none;
}

@keyframes route-busy-in {
  to { opacity: 1; }
}

@keyframes route-busy-sweep {
  from { background-position: -45% 0; }
  to { background-position: 145% 0; }
}

.route-view {
  transition: opacity 160ms ease, filter 160ms ease;
}

.workbench.workspace-blocked > .route-view {
  opacity: .42;
  filter: grayscale(.78) saturate(.45);
  pointer-events: none;
  user-select: none;
}

.workspace-access-notice {
  position: fixed;
  z-index: 84;
  top: 18px;
  left: calc(var(--rail-w) + var(--context-w) + 24px);
  display: flex;
  max-width: min(620px, calc(100vw - var(--rail-w) - var(--context-w) - 48px));
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 92%, var(--warning, #d89223));
  border: 1px solid color-mix(in srgb, var(--warning, #d89223) 42%, var(--line));
  border-radius: var(--radius-12);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
}

.workspace-access-notice[hidden] {
  display: none;
}

.workspace-access-notice .icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--warning, #b36b00);
}

.context-panel {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-width: 0;
  height: 100%;
  flex-direction: column;
  padding: 19px 16px 16px;
  background: color-mix(in srgb, var(--surface) 54%, transparent);
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: opacity 150ms ease, padding 180ms ease;
}

.workbench.context-collapsed .context-panel {
  padding-inline: 0;
  border-right-color: transparent;
  opacity: 0;
  pointer-events: none;
}

.context-resizer {
  position: absolute;
  z-index: 29;
  top: 0;
  bottom: 0;
  left: calc(var(--context-w) - 4px);
  width: 8px;
  cursor: col-resize;
  touch-action: none;
}

.context-resizer::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  background: var(--accent);
  content: "";
  opacity: 0;
  transition: opacity 140ms ease;
}

.context-resizer:hover::after,
.context-resizer:focus-visible::after,
.context-resizer.dragging::after {
  opacity: .72;
}

.context-resizer.collapsed {
  cursor: default;
  pointer-events: none;
}

.context-collapse {
  position: absolute;
  z-index: 31;
  /* Align with the first control row inside the 22px-padded context panel. */
  top: 22px;
  left: calc(var(--context-w) - 15px);
  transition: left 180ms cubic-bezier(.2, .8, .2, 1);
}

.context-collapse[data-collapsed="true"] {
  left: 8px;
}

/* Первая строка панели — общая для всех разделов полоса высотой с кнопку
   сворачивания и на её же отметке. Раньше каждый экран задавал шапке свою
   высоту, и «Задачи», «Диалоги» и «Галерея» вставали на трёх разных уровнях
   относительно одной и той же кнопки. Числа держатся здесь одним местом. */
.context-panel {
  --panel-head-h: 30px;
  --panel-head-top: 3px;
}

.context-head {
  display: flex;
  min-height: var(--panel-head-h);
  align-items: center;
  gap: 8px;
  margin: var(--panel-head-top) 4px 16px;
}

.context-head strong {
  font-size: 12px;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.context-head .count {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.context-scroll {
  width: 100%;
  min-height: 0;
  min-width: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.context-scroll > * {
  max-width: 100%;
}

.context-panel .assistant-chat-row[draggable="true"] {
  cursor: grab;
}

.context-panel .assistant-chat-row.dragging {
  opacity: .42;
}

.context-panel .assistant-chat-row.drop-target {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, var(--line));
}

.context-search {
  margin-bottom: 16px;
}

.context-section-label {
  margin: 20px 7px 8px;
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.context-row {
  position: relative;
  display: grid;
  width: 100%;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 9px;
  color: var(--ink-2);
  background: transparent;
  border-radius: var(--radius-12);
  text-align: left;
  text-decoration: none;
  transition: background 150ms ease, transform 150ms ease;
}

.context-row:hover {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  transform: translateX(2px);
}

.context-row.active {
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.context-row.active::before {
  position: absolute;
  left: 0;
  width: 3px;
  height: 22px;
  background: var(--accent);
  border-radius: 0 var(--radius-4) var(--radius-4) 0;
  content: "";
}

.context-row .row-copy {
  min-width: 0;
}

.context-row .row-title {
  display: block;
  overflow: hidden;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-row .row-meta {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-row .row-date {
  align-self: start;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.context-month-heading {
  padding: 9px 12px 4px 30px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: var(--muted-2);
  border-radius: 50%;
}

.status-dot.accent {
  background: var(--accent);
}

.status-dot.success {
  background: var(--success);
}

.status-dot.warning {
  background: var(--warning);
}

.route-view {
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  outline: none;
}

.mobile-context-backdrop {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  /* Бег снимаем, появление оставляем: полоса нужна и здесь, а порог
     заметности — не украшение, а защита от мигания на быстрых переходах. */
  .workbench.route-busy::before {
    background: var(--accent);
    opacity: 0;
    animation: route-busy-in 1ms linear 140ms forwards;
  }
}

@media (max-width: 720px) {
  .workspace-access-notice {
    top: calc(60px + env(safe-area-inset-top));
    right: 12px;
    left: 12px;
    max-width: none;
  }
}
