.shell {
  --shell-pad: 16px;
  --shell-gap: 16px;
  --shell-nav-width: 220px;
  --shell-topbar-height: 56px;
  --shell-focus-duration: 220ms;
  --shell-focus-ease: cubic-bezier(0.2, 0.85, 0.25, 1);
  min-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:
    "topbar topbar"
    "nav content";
  gap: 0;
  animation: dashboard-enter 0.6s ease-out;
  transition: grid-template-columns var(--shell-focus-duration) var(--shell-focus-ease);
}

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

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

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

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: var(--shell-topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(18px);
}

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

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

.topbar .nav-collapse-toggle__icon {
  font-size: 22px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
  line-height: 1.1;
}

.brand-sub {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  line-height: 1;
}

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

/* Smaller pill and theme toggle in topbar */
.topbar-status .pill {
  padding: 4px 10px;
  gap: 6px;
  font-size: 11px;
}

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

.topbar-status .theme-toggle {
  --theme-item: 22px;
  --theme-gap: 4px;
  --theme-pad: 4px;
}

.topbar-status .theme-icon {
  width: 12px;
  height: 12px;
}

.nav {
  grid-area: nav;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(18px);
  transition: width var(--shell-focus-duration) var(--shell-focus-ease),
    padding var(--shell-focus-duration) var(--shell-focus-ease);
}

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

/* Collapsed nav sidebar - completely hidden */
.nav--collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: none;
  opacity: 0;
  pointer-events: none;
}

/* Nav collapse toggle button */
.nav-collapse-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
  margin-bottom: 16px;
}

.nav-collapse-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border);
}

:root[data-theme="light"] .nav-collapse-toggle:hover {
  background: rgba(0, 0, 0, 0.06);
}

.nav-collapse-toggle__icon {
  font-size: 16px;
  color: var(--muted);
}

.nav-group {
  margin-bottom: 18px;
  display: grid;
  gap: 6px;
  padding-bottom: 12px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}

.nav-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

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

.nav-group--collapsed .nav-group__items {
  display: none;
}

.nav-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 4px 0;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text);
  opacity: 0.7;
  margin-bottom: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
}

.nav-label:hover {
  opacity: 1;
}

.nav-label--static {
  cursor: default;
}

.nav-label--static:hover {
  opacity: 0.7;
}

.nav-label__text {
  flex: 1;
}

.nav-label__chevron {
  font-size: 12px;
  opacity: 0.6;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 12px 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.nav-item__icon {
  font-size: 16px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-item__text {
  font-size: 13px;
  white-space: nowrap;
}

.nav-item:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
}

.nav-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 4px;
  height: 60%;
  border-radius: 0 999px 999px 0;
  transform: translateY(-50%);
  background: transparent;
}

.nav-item.active {
  color: var(--text);
  border-color: rgba(245, 159, 74, 0.45);
  background: rgba(245, 159, 74, 0.12);
}

.nav-item.active::before {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(245, 159, 74, 0.4);
}

.content {
  grid-area: content;
  padding: 8px 6px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
  overflow-y: auto; /* Enable vertical scrolling for pages with long content */
  overflow-x: hidden;
}

.shell--chat .content {
  /* No-op: keep chat layout consistent with other tabs */
}

.content-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 6px;
  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: 90px;
}

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

.page-title {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.6px;
}

.page-sub {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.4px;
}

.page-meta {
  display: flex;
  gap: 10px;
}

/* Chat view: header and controls side by side */
.content--chat .content-header {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.content--chat .content-header > div:first-child {
  text-align: left;
}

.content--chat .page-meta {
  justify-content: flex-start;
}

.content--chat .chat-controls {
  flex-shrink: 0;
}

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

.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(140px, 1fr));
}

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

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

.stack {
  display: grid;
  gap: 14px;
}

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

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

  .nav {
    position: static;
    max-height: none;
    display: flex;
    gap: 16px;
    overflow-x: auto;
    border-right: none;
    padding: 12px;
  }

  .nav-group {
    grid-auto-flow: column;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    border-bottom: none;
    padding-bottom: 0;
  }

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

  .topbar {
    position: static;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .topbar-status {
    width: 100%;
    flex-wrap: wrap;
  }

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

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