/* ==========================================================================
   Base — reset, shell layout, navigation chrome, motion primitives.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }

/* --- invisible scrollbars, everywhere ----------------------------------- */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0; height: 0; display: none; }

::selection { background: var(--accent-soft); color: var(--text); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ==========================================================================
   Shell
   ========================================================================== */
/* Toolbar on top spanning everything, panes below — the Finder/Safari arrangement.

   The sidebar has no toggle. It rests as an icon rail and expands on hover or keyboard
   focus, overlaying the content rather than pushing it: reflowing the whole page every
   time the pointer grazes the edge would be far worse than the button ever was. The rail
   keeps its own column, so nothing shifts. */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.app__body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-rail) 1fr;
}
/* The sidebar is absolutely positioned so it can overlay when it expands, which takes it
   out of the grid flow. Pin the view to column 2 explicitly — otherwise it becomes the
   only in-flow child and lands in the 56px rail column. */
.app__body > .view { grid-column: 2; }

/* --- sidebar ------------------------------------------------------------- */
.sidebar {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  z-index: 30;
  width: var(--sidebar-rail);
  display: flex;
  flex-direction: column;
  /* Solid, not vibrant: nothing scrolls behind the sidebar, so a backdrop-filter here
     would buy no depth and only risks compositing artifacts. Blur is reserved for the
     topbar, thread header and composer, where content genuinely passes underneath. */
  background: var(--surface-2);
  border-right: var(--hairline) solid var(--separator);
  overflow: hidden;
  transition: width var(--t-slow) var(--ease), box-shadow var(--t-slow) var(--ease),
              background var(--t) var(--ease);
}
.sidebar:hover,
.sidebar:focus-within {
  width: var(--sidebar-w);
  box-shadow: var(--shadow-lg);
  background: var(--bg-elevated);
}

/* Brand lives in the toolbar now. */
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 4px 8px 4px 4px;
  margin-right: 2px;
  border-radius: var(--r-sm);
  color: var(--text);
  flex: 0 0 auto;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.brand:hover { background: var(--surface-hover); }
.brand:active { transform: scale(0.97); }
.brand__mark {
  width: 26px; height: 26px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--blue) 0%, var(--purple) 130%);
  color: #fff;
  font-size: 13px; font-weight: 700;
  letter-spacing: -0.04em;
  box-shadow: var(--shadow-accent);
  transition: transform var(--t) var(--ease-spring);
}
.brand:hover .brand__mark { transform: rotate(-8deg) scale(1.08); }
.brand__name { font-size: var(--fs-md); font-weight: 640; letter-spacing: -0.03em; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.42; }
}


.sidebar__scroll {
  flex: 1 1 auto; overflow-y: auto; overflow-x: hidden;
  padding: var(--sp-3) 10px var(--sp-4);
  width: var(--sidebar-w);            /* fixed inner width, so nothing reflows on expand */
}

/* Section labels fade rather than collapse — a changing height would make the icons
   jump every time the sidebar opened. In the rail the label is invisible, so a rule
   takes its place: without one the groups run together into an undifferentiated column
   of icons. The two cross-fade. */
.nav__section {
  padding: var(--sp-3) var(--sp-2) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-4);
  white-space: nowrap;
}
.nav__section span {
  opacity: 0;
  transition: opacity var(--t) var(--ease);
}
.sidebar:hover .nav__section span,
.sidebar:focus-within .nav__section span { opacity: 1; }

.nav__section::before {
  content: "";
  display: block;
  height: var(--hairline);
  margin: 0 6px var(--sp-2);
  background: var(--separator-firm);
  transition: opacity var(--t) var(--ease);
}
.sidebar:hover .nav__section::before,
.sidebar:focus-within .nav__section::before { opacity: 0; }
/* Nothing to separate above the first group. */
.nav__section:first-child { padding-top: var(--sp-2); }
.nav__section:first-child::before { display: none; }

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.nav__item + .nav__item { margin-top: 1px; }
.nav__item:hover { background: var(--surface-hover); color: var(--text); }
.nav__item:active { transform: scale(0.985); background: var(--surface-press); }
.nav__item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 590; }
.nav__item.is-active .icon { color: var(--accent); }
.nav__item .icon {
  width: 18px; height: 18px; flex: 0 0 auto;
  color: var(--text-3);
  transition: color var(--t-fast) var(--ease);
}
.nav__item__label {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  opacity: 0;
  transition: opacity var(--t) var(--ease);
}
.sidebar:hover .nav__item__label,
.sidebar:focus-within .nav__item__label { opacity: 1; }

/* Counts read as a dot on the icon in the rail, and as a number once expanded. */
.nav__count {
  position: absolute; top: 5px; left: 26px;
  min-width: 9px; width: 9px; height: 9px; padding: 0;
  border-radius: 50%;
  background: var(--text-4);
  color: transparent;
  font-size: 0; font-weight: 620;
  display: grid; place-items: center;
  font-variant-numeric: tabular-nums;
  border: 2px solid var(--surface-2);
  transition: all var(--t) var(--ease);
}
.nav__count.is-accent { background: var(--accent); }
.sidebar:hover .nav__count,
.sidebar:focus-within .nav__count {
  position: static;
  min-width: 21px; width: auto; height: 19px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  border-color: transparent;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.sidebar:hover .nav__count.is-accent,
.sidebar:focus-within .nav__count.is-accent {
  background: var(--accent); color: #fff; box-shadow: var(--shadow-accent);
}
.sidebar:hover .nav__item.is-active .nav__count,
.sidebar:focus-within .nav__item.is-active .nav__count {
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent);
}

.sidebar__foot {
  flex: 0 0 auto;
  width: var(--sidebar-w);
  padding: var(--sp-2) 10px;
  border-top: var(--hairline) solid var(--separator);
}
.opcard {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: var(--r-md); width: 100%;
  transition: background var(--t-fast) var(--ease);
}
.opcard:hover { background: var(--surface-hover); }
.opcard__meta { min-width: 0; text-align: left; }
.opcard__name { font-size: var(--fs-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opcard__sub { font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- main ---------------------------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  position: relative; z-index: 40;
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 var(--sp-4) 0 var(--sp-3);
  background: var(--material);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: var(--hairline) solid var(--separator);
}
.topbar .crumbs { margin-left: var(--sp-2); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

/* --- breadcrumbs --------------------------------------------------------- */
.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; }
.crumb {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  border-radius: var(--r-xs);
  font-size: var(--fs-base);
  font-weight: 520;
  color: var(--text-3);
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden; text-overflow: ellipsis;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.crumb:hover { background: var(--surface-hover); color: var(--text); }
.crumb:active { transform: scale(0.96); }
.crumb.is-current { color: var(--text); font-weight: 600; cursor: default; }
.crumb.is-current:hover { background: none; }
.crumb__sep { color: var(--text-4); flex: 0 0 auto; opacity: 0.7; user-select: none; }

/* --- view host ----------------------------------------------------------- */
.view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.view__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  /* Extra bottom room so the assistant's floating button never sits on top of the last row. */
  padding: var(--sp-7) var(--sp-6) 104px;
}
.view--wide .view__inner { max-width: none; }
.view--flush { overflow: hidden; }

/* Route transition: content lifts in, never snaps. */
.view-enter { animation: viewIn var(--t-slow) var(--ease) both; }
.view-leave { animation: viewOut var(--t-fast) var(--ease-in-out) both; }

@keyframes viewIn {
  from { opacity: 0; transform: translate3d(0, 10px, 0) scale(0.994); filter: blur(2px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}
@keyframes viewOut {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translate3d(0, -6px, 0); }
}

/* Children stagger in behind the view — set --i on each row. */
.stagger > * {
  animation: riseIn var(--t-slow) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 34ms);
}
@keyframes riseIn {
  from { opacity: 0; transform: translate3d(0, 12px, 0); }
  to   { opacity: 1; transform: none; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: scale(0.94) translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes shimmer {
  from { background-position: -420px 0; }
  to   { background-position: 420px 0; }
}

/* --- page header --------------------------------------------------------- */
.page-head {
  display: flex; align-items: flex-end; gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.page-head__text { min-width: 0; }
.page-title {
  font-size: var(--fs-3xl);
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.page-sub { margin-top: 6px; color: var(--text-3); font-size: var(--fs-md); }
.page-head__actions { margin-left: auto; display: flex; gap: var(--sp-2); flex: 0 0 auto; }

.section-title {
  font-size: var(--fs-lg);
  font-weight: 640;
  letter-spacing: -0.02em;
  margin-bottom: var(--sp-3);
  display: flex; align-items: center; gap: var(--sp-2);
}
.section-title__count { color: var(--text-4); font-weight: 500; }

/* --- utilities ----------------------------------------------------------- */
.row { display: flex; align-items: center; gap: var(--sp-2); }
.row--between { justify-content: space-between; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-3); }
.dim { color: var(--text-4); }
.tnum { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- responsive ---------------------------------------------------------- */
/* The rail works on touch too — the icons are the navigation, so there is nothing to
   open and no button to miss. Only the wordmark goes on very narrow screens. */
@media (max-width: 560px) {
  .brand__name { display: none; }
}
@media (max-width: 720px) {
  .view__inner { padding: var(--sp-5) var(--sp-4) var(--sp-8); }
  .page-title { font-size: var(--fs-2xl); }
}
