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

.shell {
  --shell-pad: 16px;
  --shell-gap: 16px;
  --shell-nav-width: 220px;
  --shell-topbar-height: 56px;
  --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:
    "topbar topbar"
    "nav content";
  gap: 0;
  animation: dashboard-enter 0.4s var(--ease-out);
  transition: grid-template-columns 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: 0px minmax(0, 1fr);
}

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

.shell--onboarding {
  grid-template-rows: 0 1fr;
}

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

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

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

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

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

.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(--bg);
}

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

.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;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

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

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text-strong);
}

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

/* Topbar status */
.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-toggle {
  --theme-item: 24px;
  --theme-gap: 2px;
  --theme-pad: 3px;
}

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

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

.nav {
  grid-area: nav;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px;
  background: var(--bg);
  scrollbar-width: none; /* Firefox */
  transition:
    width var(--shell-focus-duration) var(--shell-focus-ease),
    padding var(--shell-focus-duration) var(--shell-focus-ease),
    opacity var(--shell-focus-duration) var(--shell-focus-ease);
  min-height: 0;
}

.nav::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

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

.nav--collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: none;
  opacity: 0;
  pointer-events: none;
}

/* Nav collapse toggle */
.nav-collapse-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
  margin-bottom: 16px;
}

.nav-collapse-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.nav-collapse-toggle__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transition: color var(--duration-fast) ease;
}

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

.nav-collapse-toggle:hover .nav-collapse-toggle__icon {
  color: var(--text);
}

/* Nav groups */
.nav-group {
  margin-bottom: 20px;
  display: grid;
  gap: 2px;
}

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

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

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

/* Nav label */
.nav-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  border-radius: var(--radius-sm);
  transition:
    color var(--duration-fast) ease,
    background var(--duration-fast) ease;
}

.nav-label:hover {
  color: var(--text);
  background: var(--bg-hover);
}

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

.nav-label--static:hover {
  color: var(--muted);
  background: transparent;
}

.nav-label__text {
  flex: 1;
}

.nav-label__chevron {
  font-size: 10px;
  opacity: 0.5;
  transition: transform var(--duration-fast) ease;
}

.nav-group--collapsed .nav-label__chevron {
  transform: rotate(-90deg);
}

/* Nav items */
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 8px 10px;
  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;
}

.nav-item__icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 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: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.nav-item:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

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

.nav-item.active {
  color: var(--text-strong);
  background: var(--accent-subtle);
}

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

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

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

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

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

.content--chat {
  display: flex;
  flex-direction: column;
  gap: 24px;
  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;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.15;
  color: var(--text-strong);
}

.page-sub {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  margin-top: 6px;
  letter-spacing: -0.01em;
}

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

/* Chat view header adjustments */
.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 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";
  }

  .nav {
    position: static;
    max-height: none;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    background: var(--bg);
  }

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

  .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;
  }
}
