/* layout.css - shell, rail, navigator, stage, login layout, responsive (SPEC 8.4, 8.6). */

/* ---------- Shell: framed three-column grid ---------- */

.shell {
  position: relative;
  display: grid;
  grid-template-columns: 64px 288px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--s-3);
  height: 100vh;
  height: 100dvh;
  padding: var(--s-4);
  border-radius: var(--r-shell);
  background-color: var(--ground-2);
  background-image: var(--grad-ground);
  overflow: hidden;
}

/* ---------- Rail: graphite icon pill ---------- */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  min-height: 0;
  padding: var(--s-3) 0;
  border-radius: var(--r-card);
  background-color: var(--graphite-2);
  background-image: var(--grad-graphite);
  box-shadow: var(--shadow-pill), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  color: rgba(244, 245, 246, 0.6);
}

.rail__logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-top: var(--s-1);
  color: var(--on-graphite);
}

.rail__group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
}

.rail__spacer {
  flex: 1 1 auto;
  min-height: var(--s-4);
}

.rail__btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(244, 245, 246, 0.6);
  text-decoration: none;
  transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.rail__btn:focus-visible {
  outline: 2px solid var(--on-graphite);
  outline-offset: 2px;
}

.rail__btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--on-graphite);
}

.rail__btn.is-active {
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
}

/* Lime pip on the active tile, sitting on the rail's left edge */
.rail__btn.is-active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 4px;
  height: 16px;
  margin-top: -8px;
  border-radius: 4px;
  background: var(--lime);
  box-shadow: 0 0 8px rgba(212, 245, 74, 0.8);
}

/* ---------- Navigator: panel column ---------- */

.nav {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: var(--s-4) var(--s-3);
  border-radius: var(--r-card);
  background-color: var(--panel-2);
  background-image: var(--grad-panel);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.nav__head {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  column-gap: var(--s-3);
  row-gap: 2px;
  align-items: center;
  padding: var(--s-1) var(--s-1) var(--s-3);
}

.nav__ws-icon {
  grid-row: 1 / span 2;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-segment);
  background-color: var(--graphite-2);
  background-image: var(--grad-graphite);
  color: var(--on-graphite);
  font: 500 16px/1 var(--font-ui);
  box-shadow: var(--shadow-pill);
}

.nav__ws-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 500 16px/1.2 var(--font-ui);
  color: var(--ink);
}

.nav__ws-sub {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 400 13px/1.2 var(--font-ui);
  color: var(--ink-3);
}

.nav__search {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  height: var(--h-md);
  padding: 0 var(--s-2) 0 var(--s-3);
  border-radius: var(--r-control);
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 1px 2px rgba(19, 20, 22, 0.05);
  color: var(--ink-3);
  transition: box-shadow 0.2s;
}

.nav__search:focus-within {
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 0 0 2px var(--graphite-2);
}

.nav__search input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 400 14px/1 var(--font-ui);
  outline: none;
}

.nav__search input::placeholder {
  color: var(--ink-3);
  opacity: 1;
}

.nav__search .kbd {
  flex-shrink: 0;
}

.nav__scroll {
  flex: 1 1 auto;
  min-height: 0;
  margin: var(--s-3) calc(var(--s-1) * -1) 0;
  padding: 0 var(--s-1) var(--s-3);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.nav__foot {
  flex-shrink: 0;
  padding-top: var(--s-3);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-width: 0;
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-2);
  border-radius: var(--r-row);
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  box-shadow: var(--shadow-raised);
  color: var(--ink);
}

.user-chip__avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--graphite-2);
  background-image: var(--grad-graphite);
  color: var(--on-graphite);
  font: 500 13px/1 var(--font-ui);
}

.user-chip__name {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 500 14px/1.2 var(--font-ui);
}

.user-chip__role {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 400 11px/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.user-chip > .grow,
.user-chip > div {
  flex: 1 1 auto;
  min-width: 0;
}

.user-chip .btn--icon {
  flex-shrink: 0;
  width: 32px;
  min-width: 32px;
  height: 32px;
  margin-left: auto;
}

/* ---------- Stage: the content well ---------- */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: var(--s-6) var(--s-7);
  border-radius: var(--r-card);
  background-color: var(--stage-2);
  background-image: var(--grad-stage);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 1px 2px rgba(19, 20, 22, 0.04);
  overflow: hidden;
}

.stage__header {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-3) var(--s-6);
  padding-bottom: var(--s-5);
  min-width: 0;
}

.stage__crumb {
  display: block;
  margin-bottom: var(--s-2);
  font: 400 11px/1.2 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.stage__title {
  min-width: 0;
  font: 400 44px/1 var(--font-ui);
  letter-spacing: -0.025em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.stage__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  max-width: 100%;
  min-width: 0;
}

.stage__body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
  min-height: 0;
  padding: 0 var(--s-1) var(--s-2) 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

/* Chat view: thread scrolls, composer pinned to the bottom */
.stage__body--chat {
  gap: 0;
  padding: 0;
  overflow: hidden;
}

/* ---------- Mobile bar, scrim (hidden on desktop) ---------- */

.mobile-bar {
  display: none;
}

.scrim {
  display: none;
}

.mobile-bar__title {
  font: 500 16px/1.2 var(--font-ui);
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* ---------- Login ---------- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--s-6) var(--s-4);
  background-color: var(--ground-2);
  background-image: var(--grad-ground);
  background-attachment: fixed;
}

.login {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  width: 100%;
  max-width: 400px;
  min-width: 0;
}

.login__card {
  gap: var(--s-5);
  padding: var(--s-7);
}

.login__brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font: 500 18px/1.1 var(--font-ui);
  letter-spacing: -0.01em;
  color: var(--ink);
}

.login__brand img,
.login__brand svg {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.login__error {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px 14px;
  border-radius: var(--r-control);
  background-color: var(--ember-soft);
  box-shadow: inset 0 0 0 1px rgba(229, 72, 42, 0.22);
  color: var(--ink);
  font: 400 14px/1.35 var(--font-ui);
}

.login__error::before {
  content: "";
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ember);
}

/* ---------- Responsive: below 860px the navigator becomes a drawer ---------- */

@media (max-width: 859px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: var(--s-2);
    padding: var(--s-2);
    border-radius: var(--r-card);
  }

  .rail {
    display: none;
  }

  .mobile-bar {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: var(--s-2);
    min-width: 0;
    min-height: 52px;
    padding: var(--s-1) var(--s-2) var(--s-1) var(--s-1);
    border-radius: var(--r-row);
    background-color: var(--panel-2);
    background-image: var(--grad-panel);
    box-shadow: var(--shadow-card);
  }

  .mobile-bar .btn--icon {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }

  .stage {
    grid-column: 1;
    grid-row: 2;
    padding: var(--s-4);
    border-radius: var(--r-row);
  }

  .stage__header {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: var(--s-3);
    padding-bottom: var(--s-4);
  }

  .stage__title {
    font-size: 30px;
    line-height: 1.05;
  }

  .stage__tools {
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .stage__tools::-webkit-scrollbar {
    display: none;
  }

  .stage__body {
    padding-right: 0;
  }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(19, 20, 22, 0.3);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s var(--ease-out);
  }

  .shell.is-nav-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }

  /* Navigator as a fixed left drawer */
  .nav {
    position: fixed;
    top: var(--s-2);
    bottom: var(--s-2);
    left: var(--s-2);
    z-index: 50;
    width: min(86vw, 320px);
    padding: var(--s-4) var(--s-3) var(--s-3);
    border-radius: var(--r-card);
    transform: translateX(calc(-100% - 16px));
    transition: transform 0.28s var(--ease-out), visibility 0.28s;
    visibility: hidden;
    box-shadow: var(--shadow-card), 0 30px 60px -20px rgba(19, 20, 22, 0.45);
  }

  .shell.is-nav-open .nav {
    transform: none;
    visibility: visible;
  }

  /* Bigger touch targets on phones */
  .btn--sm,
  .link-btn {
    min-height: var(--h-md);
    height: var(--h-md);
  }

  .seg__item {
    height: 36px;
  }

  .nav-item {
    min-height: var(--h-md);
  }
}

@media (max-width: 379px) {
  .stage {
    padding: var(--s-3);
  }

  .stage__title {
    font-size: 28px;
  }

  .card {
    padding: var(--s-4);
  }

  .login__card {
    padding: var(--s-5);
  }
}

/* ---------- Reduced motion: keep state changes, drop movement ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

  .toast,
  .dialog[open],
  .skeleton {
    animation: none !important;
  }

  .spinner {
    animation-duration: 2.4s !important;
  }

  .btn:active {
    transform: none;
  }
}
