/* ─────────────────────────────────────────────────────────────────────
   App shell — sidebar, topbar, content frame
   ───────────────────────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar"
    "content";
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* Sidebar removed but kept in DOM for transitions; just hide it. */
.sidebar { display: none !important; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--surface-overlay);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-right: 1px solid var(--line-1);
  min-width: 0;
  z-index: 2;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: var(--topbar-h);
  border-bottom: 1px solid var(--line-1);
  flex-shrink: 0;
}
.sidebar-brand img { height: 22px; }
.sidebar-brand-text {
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--ink-1);
}
.sidebar-brand-sub {
  font-size: var(--fs-11);
  font-weight: var(--fw-medium);
  color: var(--ink-4);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin-left: 2px;
}

.sidebar-section {
  padding: var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-uppercase);
  color: var(--ink-4);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  height: 30px;
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  color: var(--ink-2);
  border-radius: var(--radius-6);
  position: relative;
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease-glide),
    color var(--dur-fast) var(--ease-glide),
    transform var(--dur-fast) var(--ease-spring);
}
.nav-item:hover { background: var(--canvas-tint); color: var(--ink-1); }
.nav-item.is-active {
  background: var(--surface);
  color: var(--ink-1);
  box-shadow: var(--shadow-xs);
}
.nav-item.is-active::before {
  content: '';
  position: absolute;
  left: -3px; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--brand-red);
  border-radius: var(--radius-full);
  animation: rise var(--dur-base) var(--ease-spring);
}
.nav-item-icon {
  width: 16px; height: 16px;
  color: var(--ink-3);
  flex-shrink: 0;
}
.nav-item.is-active .nav-item-icon { color: var(--brand-red); }
.nav-item-count {
  margin-left: auto;
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  color: var(--ink-4);
}

.sidebar-projects {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-3) var(--space-3);
}

.project-pill {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-8);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-glide), transform var(--dur-fast) var(--ease-spring);
  position: relative;
}
.project-pill:hover { background: var(--canvas-tint); transform: translateX(2px); }
.project-pill.is-active { background: var(--surface); box-shadow: var(--shadow-xs); }

.project-swatch {
  width: 24px; height: 24px;
  border-radius: var(--radius-6);
  background: var(--accent, var(--brand-red));
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: var(--fs-11);
  font-weight: var(--fw-bold);
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 6px rgba(15, 18, 25, 0.10);
}
.project-pill[data-live="true"] .project-swatch::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: var(--radius-8);
  border: 2px solid var(--brand-red);
  animation: pulse-bloom 1.8s var(--ease-out) infinite;
  pointer-events: none;
}

.project-info { min-width: 0; flex: 1; }
.project-name {
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  color: var(--ink-1);
  letter-spacing: var(--tracking-tight);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.project-meta {
  font-size: var(--fs-11);
  color: var(--ink-4);
  margin-top: 1px;
}

.sidebar-foot {
  padding: var(--space-3);
  border-top: 1px solid var(--line-1);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--surface-overlay);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--line-1);
  z-index: 2;
}

/* Top progress bar — fires on landing → project click, drains when ready. */
.topbar-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--brand-red-deep), var(--brand-red), #BD5555);
  box-shadow: 0 0 12px rgba(231, 27, 36, 0.6), 0 0 4px rgba(231, 27, 36, 0.8);
  z-index: 9999;
  border-radius: 0 2px 2px 0;
  transition: width 80ms linear, opacity 200ms var(--ease-glide);
  pointer-events: none;
}
.topbar-progress::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--brand-red), transparent);
  filter: blur(4px);
  opacity: 0.7;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 8px;
  border-radius: var(--radius-6);
  text-decoration: none;
  color: inherit;
  transition: background var(--dur-fast);
}
.topbar-brand:hover { background: var(--canvas-tint); }
.topbar-brand-mark {
  width: 22px; height: 22px;
  border-radius: var(--radius-6);
  background: var(--brand-red);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-12);
  box-shadow: 0 2px 6px rgba(231, 27, 36, 0.32);
}
.topbar-brand-text {
  font-size: var(--fs-13);
  font-weight: var(--fw-bold);
  color: var(--ink-1);
  letter-spacing: var(--tracking-tight);
}

/* Project switcher button */
.proj-switcher {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2) 0 var(--space-1);
  height: 30px;
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  color: var(--ink-1);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-6);
  cursor: pointer;
  max-width: 220px;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.proj-switcher:hover { background: var(--canvas-tint); border-color: var(--line-1); }
.proj-switcher .swatch {
  width: 18px; height: 18px;
  border-radius: var(--radius-4);
  background: var(--accent, var(--brand-red));
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  font-weight: var(--fw-bold);
  flex-shrink: 0;
}
.proj-switcher .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-switcher .chev { color: var(--ink-4); flex-shrink: 0; }

/* Project switcher popover */
.popover-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-popover);
  background: transparent;
}
.popover {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-12);
  box-shadow: var(--shadow-pop);
  min-width: 220px;
  max-width: 360px;
  overflow: hidden;
  z-index: calc(var(--z-popover) + 1);
  animation: rise var(--dur-base) var(--ease-spring);
  transform-origin: top left;
}
.popover-search {
  padding: var(--space-3);
  border-bottom: 1px solid var(--line-1);
}
.popover-list {
  max-height: 400px;
  overflow-y: auto;
  padding: var(--space-2);
}
.popover-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-6);
  cursor: pointer;
  transition: background var(--dur-fast);
}
.popover-item:hover, .popover-item.is-active { background: var(--canvas-tint); }
.popover-item.is-current { background: var(--brand-red-wash); color: var(--brand-red); }
.popover-item .swatch {
  width: 24px; height: 24px;
  border-radius: var(--radius-6);
  background: var(--accent, var(--brand-red));
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: var(--fw-bold);
  flex-shrink: 0;
}
.popover-item .info { flex: 1; min-width: 0; }
.popover-item .name { font-size: var(--fs-13); font-weight: var(--fw-semibold); color: var(--ink-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-item .meta { font-size: var(--fs-11); color: var(--ink-4); margin-top: 1px; }
.popover-item.is-current .name { color: var(--brand-red); }
.popover-foot {
  padding: var(--space-2);
  border-top: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-13);
  color: var(--ink-3);
  min-width: 0;
}
.crumbs a { color: var(--ink-3); transition: color var(--dur-fast); }
.crumbs a:hover { color: var(--ink-1); }
.crumbs .sep { color: var(--ink-5); font-size: var(--fs-12); }
.crumbs .last { color: var(--ink-1); font-weight: var(--fw-semibold); }

.topbar-search {
  flex: 1;
  display: flex;
  justify-content: center;
}
.topbar-search-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  height: 30px;
  width: 100%;
  max-width: 460px;
  font-size: var(--fs-13);
  color: var(--ink-4);
  background: var(--canvas-tint);
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.topbar-search-btn:hover { background: var(--surface); border-color: var(--line-2); color: var(--ink-2); }
.topbar-search-btn .search-spacer { flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  height: 26px;
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  color: var(--ink-3);
  background: var(--canvas-tint);
  border-radius: var(--radius-full);
  transition: all var(--dur-base) var(--ease-glide);
}
.live-indicator[data-state="live"] {
  color: var(--brand-red);
  background: var(--brand-red-wash);
  box-shadow: var(--bloom-soft);
}
.live-indicator[data-state="live"] .dot { background: var(--brand-red); animation: pulse-bloom 1.6s var(--ease-out) infinite; }

/* ── Content ─────────────────────────────────────────────────────── */
.content {
  grid-area: content;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.view-pad {
  padding: var(--space-8) var(--space-8);
  max-width: var(--content-max);
  margin: 0 auto;
}

/* Page entrance — applies on every view mount, view-transitions amplify it */
.view-enter > * { animation: rise var(--dur-slow) var(--ease-snap) backwards; }
.view-enter > *:nth-child(1) { animation-delay: 0ms; }
.view-enter > *:nth-child(2) { animation-delay: 60ms; }
.view-enter > *:nth-child(3) { animation-delay: 120ms; }
.view-enter > *:nth-child(4) { animation-delay: 180ms; }
.view-enter > *:nth-child(5) { animation-delay: 240ms; }
.view-enter > *:nth-child(6) { animation-delay: 300ms; }

/* ── Command palette ─────────────────────────────────────────────── */
.cmd-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--z-command);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  animation: fade-in var(--dur-base) var(--ease-out);
}
.cmd-backdrop[data-closing="true"] { animation: fade-in var(--dur-base) var(--ease-out) reverse; }

.cmd {
  width: min(640px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-16);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  animation: rise var(--dur-base) var(--ease-spring);
}
.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line-1);
}
.cmd-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--fs-16);
  font-weight: var(--fw-medium);
  color: var(--ink-1);
}
.cmd-input::placeholder { color: var(--ink-4); }
.cmd-list {
  max-height: 420px;
  overflow-y: auto;
  padding: var(--space-2);
}
.cmd-group-label {
  padding: var(--space-3) var(--space-3) var(--space-1);
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-uppercase);
  color: var(--ink-4);
}
.cmd-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-8);
  cursor: pointer;
  transition: background var(--dur-instant);
}
.cmd-item:hover, .cmd-item.is-active { background: var(--canvas-tint); }
.cmd-item.is-active {
  background: var(--brand-red-wash);
  box-shadow: inset 2px 0 0 var(--brand-red);
}
.cmd-item-icon { width: 18px; height: 18px; color: var(--ink-3); flex-shrink: 0; }
.cmd-item.is-active .cmd-item-icon { color: var(--brand-red); }
.cmd-item-title { flex: 1; font-size: var(--fs-14); color: var(--ink-1); font-weight: var(--fw-medium); }
.cmd-item-meta { font-size: var(--fs-12); color: var(--ink-4); }
.cmd-foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--line-1);
  font-size: var(--fs-12);
  color: var(--ink-4);
  background: var(--surface-sunken);
}
.cmd-foot-hint { display: inline-flex; align-items: center; gap: var(--space-1); }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--ink-1);
  color: white;
  border-radius: var(--radius-10);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  min-width: 240px;
  max-width: 420px;
  animation: rise var(--dur-base) var(--ease-spring);
}
.toast--success { background: var(--success); }
.toast--danger { background: var(--brand-red); }
