/* ===========================================
   Shell Layout
   =========================================== */

.shell {
  --shell-pad: 16px;
  --shell-gap: 16px;
  --shell-nav-width: 258px;
  --shell-nav-rail-width: 78px;
  --shell-topbar-height: 52px;
  --shell-focus-duration: 200ms;
  --shell-focus-ease: var(--ease-out);
  height: 100vh;
  display: grid;
  grid-template-columns: var(--shell-nav-width) minmax(0, 1fr);
  grid-template-rows: var(--shell-topbar-height) 1fr;
  grid-template-areas:
    "nav topbar"
    "nav content";
  gap: 0;
  animation: dashboard-enter 0.3s var(--ease-out);
  transition:
    grid-template-columns var(--shell-focus-duration) var(--shell-focus-ease),
    grid-template-rows var(--shell-focus-duration) var(--shell-focus-ease);
  overflow: hidden;
}

@supports (height: 100dvh) {
  .shell {
    height: 100dvh;
  }
}

.shell--chat {
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

@supports (height: 100dvh) {
  .shell--chat {
    height: 100dvh;
  }
}

.shell--nav-collapsed {
  grid-template-columns: var(--shell-nav-rail-width) minmax(0, 1fr);
}

.shell--chat-focus {
  grid-template-columns: 0px minmax(0, 1fr);
  grid-template-rows: 0 minmax(0, 1fr);
}

.shell--onboarding {
  grid-template-columns: 0 minmax(0, 1fr);
  grid-template-rows: 0 1fr;
}

.shell--onboarding .topbar {
  display: none;
}

.shell--onboarding .shell-nav {
  display: none;
}

.shell--onboarding .content {
  padding-top: 0;
}

.shell--chat-focus .content {
  padding-top: 0;
}

.shell--chat-focus .content > * + * {
  margin-top: 0;
}

.shell--chat-focus .topbar {
  min-height: 0;
  height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  border-bottom-width: 0;
}

/* ===========================================
   Topbar
   =========================================== */

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  padding: 0 24px;
  min-height: 58px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 74%, transparent);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px) saturate(1.6);
  -webkit-backdrop-filter: blur(12px) saturate(1.6);
}

.topnav-shell {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: var(--shell-topbar-height);
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.sidebar-menu-trigger {
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--border) 84%, transparent);
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--bg-elevated) 80%, transparent);
  color: var(--muted);
  cursor: pointer;
  transition:
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
  box-shadow: inset 0 1px 0 color-mix(in srgb, white 8%, transparent);
}

.sidebar-menu-trigger:hover {
  border-color: color-mix(in srgb, var(--border-strong) 88%, transparent);
  background: color-mix(in srgb, var(--bg-hover) 84%, transparent);
  color: var(--text);
  transform: translateY(-1px);
}

.sidebar-menu-trigger:active {
  transform: translateY(0);
}

.sidebar-menu-trigger:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.topbar-nav-toggle {
  display: none;
}

.topnav-shell__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topnav-shell__content {
  min-width: 0;
  flex: 1;
}

.topbar .nav-collapse-toggle {
  width: 36px;
  height: 36px;
  margin-bottom: 0;
}

.topbar .nav-collapse-toggle__icon {
  width: 20px;
  height: 20px;
}

.topbar .nav-collapse-toggle__icon svg {
  width: 20px;
  height: 20px;
}

.topnav-shell .dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.topnav-shell .dashboard-header__breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
}

.topnav-shell .dashboard-header__breadcrumb-link,
.topnav-shell .dashboard-header__breadcrumb-sep {
  color: var(--muted);
}

.topnav-shell .dashboard-header__breadcrumb-segment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topnav-shell .dashboard-header__breadcrumb-link {
  display: inline-flex;
  align-items: center;
  margin: -2px -4px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  white-space: nowrap;
}

.topnav-shell .dashboard-header__breadcrumb-link:hover,
.topnav-shell .dashboard-header__breadcrumb-link:focus-visible {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.topnav-shell .dashboard-header__breadcrumb-current {
  color: var(--accent);
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topnav-shell .dashboard-header__breadcrumb-context {
  max-width: 18ch;
  overflow: hidden;
  color: var(--muted);
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .topnav-shell .dashboard-header__breadcrumb-context {
    max-width: 10ch;
  }
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-status .pill {
  padding: 6px 10px;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  height: 32px;
  box-sizing: border-box;
}

.topbar-status .pill .mono {
  display: flex;
  align-items: center;
  line-height: 1;
  margin-top: 0px;
}

.topbar-status .statusDot {
  width: 6px;
  height: 6px;
}

.topbar-status .theme-orb__trigger {
  width: 26px;
  height: 26px;
  font-size: 13px;
}

.topbar-search {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--bg-elevated) 84%, transparent);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition:
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    color var(--duration-fast) ease;
  min-width: 200px;
}

.topbar-search:hover {
  border-color: color-mix(in srgb, var(--border-strong) 90%, transparent);
  background: color-mix(in srgb, var(--bg-hover) 84%, transparent);
  color: var(--text);
}

.topbar-search:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.topbar-search__label {
  flex: 1;
  text-align: left;
}

.topbar-search__kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
}

.topbar-theme-mode {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid color-mix(in srgb, var(--border) 84%, transparent);
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--bg-elevated) 78%, transparent);
}

.topbar-theme-mode__btn {
  position: relative;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

.topbar-theme-mode__btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.topbar-theme-mode__btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.topbar-theme-mode__btn--active {
  color: var(--accent);
  background: var(--accent-subtle);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}

.topbar-theme-mode__btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-theme-mode__btn[data-tooltip]::before,
.topbar-theme-mode__btn[data-tooltip]::after {
  position: absolute;
  left: 50%;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
  z-index: 60;
}

.topbar-theme-mode__btn[data-tooltip]::before {
  content: "";
  top: calc(100% + 4px);
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent color-mix(in srgb, var(--card) 94%, black 6%) transparent;
  transform: translate(-50%, -3px);
}

.topbar-theme-mode__btn[data-tooltip]::after {
  content: attr(data-tooltip);
  top: calc(100% + 10px);
  max-width: min(220px, 60vw);
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--border-strong) 84%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--card) 94%, black 6%);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.24),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  transform: translate(-50%, -4px);
}

.topbar-theme-mode__btn:last-child[data-tooltip]::before,
.topbar-theme-mode__btn:last-child[data-tooltip]::after {
  left: auto;
}

.topbar-theme-mode__btn:last-child[data-tooltip]::before {
  right: 9px;
  transform: translateY(-3px);
}

.topbar-theme-mode__btn:last-child[data-tooltip]::after {
  right: 0;
  transform: translateY(-4px);
}

@media (hover: hover) {
  .topbar-theme-mode__btn[data-tooltip]:hover::before,
  .topbar-theme-mode__btn[data-tooltip]:hover::after {
    opacity: 1;
  }

  .topbar-theme-mode__btn[data-tooltip]:hover::before,
  .topbar-theme-mode__btn[data-tooltip]:hover::after {
    transform: translate(-50%, 0);
  }

  .topbar-theme-mode__btn:last-child[data-tooltip]:hover::before,
  .topbar-theme-mode__btn:last-child[data-tooltip]:hover::after {
    transform: translateY(0);
  }
}

.topbar-theme-mode__btn[data-tooltip]:focus-visible::before,
.topbar-theme-mode__btn[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.topbar-theme-mode__btn:last-child[data-tooltip]:focus-visible::before,
.topbar-theme-mode__btn:last-child[data-tooltip]:focus-visible::after {
  transform: translateY(0);
}

/* ===========================================
   Navigation Sidebar
   =========================================== */

.shell-nav {
  grid-area: nav;
  display: flex;
  min-height: 100%;
  overflow: hidden;
  border-right: 1px solid color-mix(in srgb, var(--border) 74%, transparent);
  transition: width var(--shell-focus-duration) var(--shell-focus-ease);
}

.shell-nav-backdrop {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: color-mix(in srgb, var(--bg) 96%, var(--bg-elevated) 4%);
}

:root[data-theme-mode="light"] .sidebar {
  background: color-mix(in srgb, var(--panel) 98%, white 2%);
}

.sidebar-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  padding: 14px 10px 12px;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.sidebar--collapsed {
  width: var(--shell-nav-rail-width);
  min-width: var(--shell-nav-rail-width);
  flex: 0 0 var(--shell-nav-rail-width);
}

.sidebar-shell__header,
.sidebar-shell__footer {
  flex-shrink: 0;
}

.sidebar-shell__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 0;
  padding: 0 8px 18px;
}

.sidebar-shell__body {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.sidebar-shell__footer {
  padding: 12px 0 0;
  border-top: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar-brand__logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 18px color-mix(in srgb, black 12%, transparent);
}

.sidebar-brand__copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sidebar-brand__eyebrow {
  font-size: 10px;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.sidebar-brand__title {
  font-size: 15px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  scrollbar-width: none;
}

.sidebar-sessions {
  display: grid;
  gap: 10px;
  flex-shrink: 0;
  padding: 0 8px;
  margin-bottom: 16px;
}

.sidebar-new-session {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  box-sizing: border-box;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border) 70%);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 11%, var(--bg-elevated) 89%);
  color: var(--text-strong);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  transition:
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}

.sidebar-new-session:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-hover) 82%);
  border-color: color-mix(in srgb, var(--accent) 44%, var(--border) 56%);
  transform: translateY(-1px);
}

.sidebar-new-session:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.sidebar-new-session__icon,
.sidebar-new-session__icon svg {
  width: 14px;
  height: 14px;
}

.sidebar-new-session__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
}

.sidebar-new-session__icon svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-recent-sessions {
  display: grid;
  gap: 6px;
}

.sidebar-recent-sessions__label {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--muted) 78%, var(--text) 22%);
}

.sidebar-recent-sessions__list {
  display: grid;
  gap: 4px;
}

.sidebar-recent-session {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--muted);
  text-decoration: none;
  transition:
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.sidebar-recent-session:hover {
  background: color-mix(in srgb, var(--bg-hover) 78%, transparent);
  border-color: color-mix(in srgb, var(--border) 70%, transparent);
  color: var(--text);
  text-decoration: none;
}

.sidebar-recent-session--active {
  background: color-mix(in srgb, var(--accent-subtle) 68%, transparent);
  border-color: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--text-strong);
}

.sidebar-recent-session__dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--muted) 46%, transparent);
}

.sidebar-recent-session--active .sidebar-recent-session__dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
}

.sidebar-recent-session__body {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sidebar-recent-session__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 650;
}

.sidebar-recent-session__meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--muted);
}

.sidebar-recent-session__live {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 12%, transparent);
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

.nav-collapse-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--border-strong) 68%, transparent);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
  margin-bottom: 0;
  color: var(--muted);
  box-shadow: inset 0 1px 0 color-mix(in srgb, white 8%, transparent);
}

.nav-collapse-toggle:hover {
  background: color-mix(in srgb, var(--bg-hover) 90%, transparent);
  border-color: color-mix(in srgb, var(--border-strong) 88%, transparent);
  color: var(--text);
  transform: translateY(-1px);
}

.nav-collapse-toggle__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: inherit;
}

.nav-collapse-toggle__icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-section {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.nav-section:last-child {
  margin-bottom: 0;
}

.nav-section__items {
  display: grid;
  gap: 4px;
}

.nav-section--collapsed .nav-section__items {
  display: none;
}

.nav-section__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 0 10px;
  min-height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: color-mix(in srgb, var(--muted) 72%, var(--text) 28%);
  cursor: pointer;
  text-align: left;
  transition:
    color var(--duration-fast) ease,
    background var(--duration-fast) ease;
}

.nav-section__label:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg-hover) 72%, transparent);
}

.nav-section__label-text {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-section__chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: transform var(--duration-fast) ease;
}

.nav-section__chevron svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-section--collapsed .nav-section__chevron {
  transform: rotate(-90deg);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 40px;
  padding: 0 9px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition:
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}

.nav-item__icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.72;
  transition:
    opacity var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.nav-item__icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item__text {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.nav-item:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg-hover) 84%, transparent);
  border-color: color-mix(in srgb, var(--border) 72%, transparent);
  text-decoration: none;
}

.nav-item:hover .nav-item__icon {
  opacity: 1;
}

.nav-item.active,
.nav-item--active {
  color: var(--text-strong);
  background: color-mix(in srgb, var(--accent-subtle) 88%, var(--bg-elevated) 12%);
  border-color: color-mix(in srgb, var(--accent) 18%, transparent);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, white 10%, transparent),
    0 12px 24px color-mix(in srgb, black 10%, transparent);
}

.nav-item.active .nav-item__icon,
.nav-item--active .nav-item__icon {
  opacity: 1;
  color: var(--accent);
}

.sidebar--collapsed .sidebar-shell {
  padding: 12px 8px 10px;
}

.sidebar--collapsed .sidebar-shell__header {
  justify-content: center;
  align-items: center;
  gap: 0;
  padding: 0 2px 16px;
}

.sidebar--collapsed .sidebar-nav {
  padding: 0;
}

.sidebar--collapsed .sidebar-sessions {
  justify-items: center;
  padding: 0;
  margin-bottom: 14px;
}

.sidebar--collapsed .sidebar-new-session {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: var(--radius-lg);
}

.sidebar--collapsed .nav-section {
  gap: 6px;
  margin-bottom: 16px;
}

.sidebar--collapsed .nav-item {
  justify-content: center;
  width: 44px;
  min-height: 44px;
  padding: 0;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  border-color: transparent;
  box-shadow: none;
}

.sidebar--collapsed .nav-item__icon {
  width: 18px;
  height: 18px;
}

.sidebar--collapsed .nav-item__icon svg {
  width: 18px;
  height: 18px;
}

.sidebar--collapsed .nav-item__text,
.sidebar--collapsed .nav-item__external-icon {
  display: none;
}

.sidebar--collapsed .nav-item--active::before,
.sidebar--collapsed .nav-item.active::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--accent) 86%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 34%, transparent);
}

.sidebar--collapsed .nav-item.active,
.sidebar--collapsed .nav-item--active {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 14%, var(--bg-elevated) 86%) 0%,
    color-mix(in srgb, var(--accent) 8%, var(--bg) 92%) 100%
  );
  border-color: color-mix(in srgb, var(--accent) 18%, var(--border) 82%);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, white 8%, transparent),
    0 10px 20px color-mix(in srgb, black 18%, transparent);
}

.sidebar--collapsed .nav-collapse-toggle {
  width: 42px;
  height: 42px;
  border-color: color-mix(in srgb, var(--border) 82%, transparent);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, white 8%, transparent),
    0 8px 18px color-mix(in srgb, black 16%, transparent);
}

.sidebar--collapsed .sidebar-brand__logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  box-shadow:
    0 10px 20px color-mix(in srgb, black 20%, transparent),
    inset 0 1px 0 color-mix(in srgb, white 10%, transparent);
}

.sidebar-utility-group {
  display: grid;
  gap: 8px;
}

.sidebar-utility-link {
  min-height: 42px;
}

.sidebar-version {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--bg-elevated) 72%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
}

.sidebar-version__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-version__text {
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
}

.sidebar-version__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--accent) 78%, white 22%);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
  opacity: 1;
  margin: 0 auto;
}

.sidebar-version__status {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  margin-left: auto;
}

.sidebar-version__status.sidebar-connection-status--online {
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 14%, transparent);
}

.sidebar-version__status.sidebar-connection-status--offline {
  background: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 14%, transparent);
}

.sidebar--collapsed .sidebar-shell__footer {
  padding: 8px 0 2px;
}

.sidebar--collapsed .sidebar-utility-group {
  justify-items: center;
  gap: 6px;
}

.sidebar--collapsed .sidebar-version {
  width: 44px;
  min-height: 44px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-lg);
}

.sidebar--collapsed .sidebar-version__status {
  margin-left: 0;
}

/* Mode switch in sidebar — hidden on desktop, shown on mobile */
.sidebar-mode-switch {
  display: none;
}

.shell--nav-collapsed .shell-nav {
  width: var(--shell-nav-rail-width);
  min-width: var(--shell-nav-rail-width);
}

.shell--chat-focus .shell-nav {
  width: 0;
  min-width: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  border-right-width: 0;
}

.nav-item__external-icon {
  width: 12px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
  opacity: 0;
  transition: opacity var(--duration-fast) ease;
}

.nav-item__external-icon svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item:hover .nav-item__external-icon {
  opacity: 0.5;
}

/* ===========================================
   Content Area
   =========================================== */

.content {
  grid-area: content;
  padding: 16px 20px 32px;
  display: block;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.content > * + * {
  margin-top: 20px;
}

:root[data-theme-mode="light"] .content {
  background: var(--bg-content);
}

.content--chat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  padding-bottom: 0;
}

.content--chat > * + * {
  margin-top: 0;
}

/* Content header */
.content-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 8px;
  overflow: hidden;
  transform-origin: top center;
  transition:
    opacity var(--shell-focus-duration) var(--shell-focus-ease),
    transform var(--shell-focus-duration) var(--shell-focus-ease),
    max-height var(--shell-focus-duration) var(--shell-focus-ease),
    padding var(--shell-focus-duration) var(--shell-focus-ease);
  max-height: 80px;
}

.shell--chat-focus .content-header {
  opacity: 0;
  transform: translateY(-8px);
  max-height: 0px;
  padding: 0;
  pointer-events: none;
}

.content--chat .content-header.content-header--chat-hidden {
  opacity: 0;
  transform: translateY(-10px);
  min-height: 0;
  max-height: 0px;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  pointer-events: none;
}

.page-title {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--accent);
}

.page-sub {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  margin-top: 4px;
  letter-spacing: -0.005em;
}

.page-meta {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dreaming-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dreaming-header-controls__modes {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
}

.dreaming-header-controls__mode {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: 4px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0;
  max-width: 90px;
  overflow: hidden;
  transition:
    max-width var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.dreaming-header-controls__mode:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  color: var(--text);
  max-width: 290px;
}

.dreaming-header-controls__mode:focus:not(:disabled) {
  max-width: 290px;
}

.dreaming-header-controls__mode:disabled {
  opacity: 0.55;
  cursor: default;
}

.dreaming-header-controls__mode--active {
  border-color: color-mix(in srgb, var(--accent) 62%, var(--border));
  background: color-mix(in srgb, var(--accent-subtle) 70%, var(--bg-elevated));
  color: var(--text-strong);
}

.dreaming-header-controls__mode-label {
  flex-shrink: 0;
}

.dreaming-header-controls__mode-detail {
  max-width: 0;
  opacity: 0;
  margin-left: 0;
  overflow: hidden;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: normal;
  font-size: 10px;
  font-weight: 500;
  color: color-mix(in srgb, var(--muted) 86%, var(--text) 14%);
  transition:
    max-width var(--duration-fast) ease,
    margin-left var(--duration-fast) ease,
    opacity var(--duration-fast) ease;
}

.dreaming-header-controls__mode:hover:not(:disabled) .dreaming-header-controls__mode-detail,
.dreaming-header-controls__mode:focus:not(:disabled) .dreaming-header-controls__mode-detail {
  max-width: 220px;
  margin-left: 6px;
  opacity: 0.95;
}

/* Chat view header adjustments */
.content--chat .content-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px;
  overflow: visible;
  max-height: 44px;
}

.content--chat .content-header > div:first-child {
  display: grid;
  align-items: center;
  position: relative;
  text-align: left;
  min-width: 0;
}

.shell--chat-focus .content--chat .content-header {
  min-height: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
}

.content--chat .page-meta {
  align-self: center;
  justify-content: flex-end;
  height: 36px;
  align-items: center;
  min-width: max-content;
  overflow: visible;
}

.content--chat .chat-controls {
  flex-shrink: 0;
  flex-wrap: nowrap;
  gap: 6px;
}

.content--chat .content-header .chat-controls__session-notice {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  width: min(100%, 680px);
  min-height: 0;
  overflow: hidden;
  pointer-events: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===========================================
   Grid Utilities
   =========================================== */

.grid {
  display: grid;
  gap: 20px;
}

.grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.note-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.stack {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ===========================================
   Responsive - Tablet
   =========================================== */

@media (max-width: 1100px) {
  .shell {
    --shell-pad: 12px;
    --shell-gap: 12px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "topbar"
      "nav"
      "content";
  }

  .grid-cols-2,
  .grid-cols-3 {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: static;
    padding: 12px 14px;
    gap: 10px;
  }

  .topbar-status {
    flex-wrap: wrap;
  }

  .table-head,
  .table-row {
    grid-template-columns: 1fr;
  }

  .list-item {
    grid-template-columns: 1fr;
  }
}

/* Mobile chat controls — hidden on desktop, shown in layout.mobile.css */
.chat-mobile-controls-wrapper {
  display: none;
}

.chat-controls-mobile-toggle {
  display: none;
  border-radius: var(--radius-full);
}

.chat-controls-dropdown {
  display: none;
}
