/* ── App shell ── */
.app {
  display: grid;
  --sidebar-live-w: var(--nv-sidebar-w);
  --panel-live-w: var(--nv-panel-w);
  --rail-w: 56px; /* collapsed left sidebar shows a slim icon rail, not nothing */
  grid-template-columns: var(--sidebar-live-w) minmax(0, 1fr) var(--panel-live-w);
  grid-template-areas: "sidebar chat panel";
  height: 100dvh;
  overflow: hidden;
  background: var(--nv-bg);
  position: relative;
  transition: grid-template-columns var(--nv-ease-slow);
}

.app[data-almanac="closed"] {
  grid-template-columns: var(--sidebar-live-w) minmax(0, 1fr) 0;
}

/* Collapsed sidebar keeps a rail-width column so the icon rail sits beside the
   chat instead of overlaying it. The chat centre stays stable as a result. */
.app[data-sidebar="closed"] {
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--panel-live-w);
}

.app[data-sidebar="closed"][data-almanac="closed"] {
  grid-template-columns: var(--rail-w) minmax(0, 1fr) 0;
}

/* ── Sidebar ── */
.sidebar {
  grid-area: sidebar;
  background: var(--nv-surface);
  border-right: 1px solid var(--rule-strong);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  transition: opacity var(--nv-ease), transform var(--nv-ease-slow), visibility var(--nv-ease);
}

.app[data-sidebar="closed"] .sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-18px);
  visibility: hidden;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--nv-sp-2);
  padding: var(--nv-sp-5) var(--nv-sp-4) var(--nv-sp-4);
  border-bottom: 3px double var(--rule-strong);
  flex-shrink: 0;
}

.brand__mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--moss);
  opacity: 0.9;
}

.brand__name {
  font-family: var(--nv-font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--nv-text);
}

.sidebar__collapse {
  width: 34px;
  height: 34px;
  margin-left: auto;
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-sm);
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}

.sidebar__collapse:hover,
.sidebar__collapse:focus-visible {
  border-color: var(--moss);
  color: var(--moss);
  outline: none;
}

.sidebar__new {
  display: flex;
  align-items: center;
  gap: var(--nv-sp-2);
  padding: 0.7rem var(--nv-sp-3);
  margin: var(--nv-sp-3) var(--nv-sp-3) var(--nv-sp-2);
  border-radius: var(--nv-r-sm);
  background: var(--moss);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 600;
  transition: background var(--nv-ease), transform 150ms ease;
  flex-shrink: 0;
}

.sidebar__new:hover {
  background: var(--moss-deep);
  color: var(--paper);
}

.sidebar__new:active { transform: translateY(1px); }

/* Opens the full conversation index (replaced the old in-place search). */
.sidebar__index {
  margin: 0 var(--nv-sp-3) var(--nv-sp-2);
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: var(--nv-sp-2);
  padding: 0 var(--nv-sp-3);
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-md);
  color: var(--nv-text-dim);
  background: var(--paper);
  flex-shrink: 0;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  text-align: left;
}

.sidebar__index:hover,
.sidebar__index:focus-visible {
  border-color: var(--moss);
  color: var(--moss);
  outline: none;
}

.sidebar__history {
  flex: 1;
  overflow-y: auto;
  padding: var(--nv-sp-2) var(--nv-sp-3);
}

.sidebar__history h3 {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ochre-ink);
  padding: var(--nv-sp-3) 0 var(--nv-sp-2);
}

.thread-list__loading {
  display: grid;
  place-items: center;
  padding: var(--nv-sp-3) 0;
}

.thread-list__error {
  padding: var(--nv-sp-2) 0;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--nv-text-dim);
}

.thread-item {
  padding: 0.72rem 0;
  border-top: 1px solid var(--nv-divider);
  border-radius: 0;
  font-family: var(--font-ui);
  font-size: 0.84rem;
  color: var(--nv-text-dim);
  cursor: pointer;
  transition: color var(--nv-ease), padding-left var(--nv-ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item:hover,
.thread-item.is-active {
  background: transparent;
  color: var(--moss);
  padding-left: var(--nv-sp-2);
}

.sidebar__account {
  border-top: 3px double var(--rule-strong);
  padding: var(--nv-sp-3) var(--nv-sp-4);
  display: flex;
  align-items: flex-start;
  gap: var(--nv-sp-2);
  flex-shrink: 0;
}

.account__avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--nv-r-sm);
  background: var(--moss);
  display: grid;
  place-items: center;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--nv-text-on-accent);
  flex-shrink: 0;
}

.account__name {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--nv-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account__body {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: var(--nv-sp-2);
}

.account__logout {
  min-height: 30px;
  padding: 0 var(--nv-sp-3);
  border-radius: var(--nv-r-sm);
  background: transparent;
  border: 1px solid var(--rule-strong);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--nv-text-dim);
  transition: opacity var(--nv-ease);
}

.account__logout:hover { opacity: 0.85; }

.account__logout[hidden] { display: none; }

.auth-screen-open .sidebar__hamburger {
  visibility: hidden;
}

.sidebar__hamburger {
  display: none;
  position: fixed;
  top: var(--nv-sp-3);
  left: var(--nv-sp-3);
  z-index: 200;
  padding: var(--nv-sp-2);
  border-radius: var(--nv-r-sm);
  background: var(--nv-surface);
  border: 1px solid var(--rule-strong);
}

/* ── Chat ── */
.chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--paper);
}

.chat__header {
  background: var(--paper);
  border-bottom: 3px double var(--rule-strong);
  padding: var(--nv-sp-3) var(--edge);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-height: 52px;
}

.chat__title {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--moss);
}

.chat__stream-status {
  display: inline-flex;
  align-items: center;
  gap: var(--nv-sp-2);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  color: var(--nv-text-muted);
}

.chat__stream-status[hidden] {
  display: none;
}

.chat__stream-spinner {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* The log itself spans the full chat column so its scrollbar sits at the
   column's true edge whatever panels are open; the reading measure is capped
   by the inline padding instead of max-width (a capped, centred scroll
   container leaves the scrollbar floating mid-screen when panels close). */
.chat__log {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: none;
  padding-block: clamp(1.5rem, 4vw, 3rem);
  padding-inline: max(var(--edge), calc((100% - var(--container-w)) / 2));
  display: flex;
  flex-direction: column;
  gap: var(--nv-sp-5);
  width: 100%;
}

.msg { max-width: min(720px, 100%); }

.msg--user { align-self: flex-end; }

.msg--user .msg__bubble {
  background: var(--moss);
  color: var(--nv-text-on-accent);
  border-radius: var(--nv-r-lg);
  padding: 0.85rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.55;
}

.msg--novalis {
  align-self: flex-start;
  display: flex;
  gap: var(--nv-sp-3);
  align-items: flex-start;
}

.msg__avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--nv-r-sm);
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--moss);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.msg__avatar svg { width: 18px; height: 18px; }

.msg--novalis .msg__bubble {
  background: transparent;
  border: none;
  border-radius: var(--nv-r-md);
  padding: 0;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink);
}

.msg__text {
  display: block;
}

.msg__text > * + * {
  margin-top: 0.85rem;
}

.msg__text h1,
.msg__text h2,
.msg__text h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

.msg__text h1 { font-size: 1.7rem; }
.msg__text h2 { font-size: 1.35rem; }
.msg__text h3 { font-size: 1.12rem; }

.msg__text ul,
.msg__text ol {
  padding-left: 1.25rem;
}

.msg__text ul { list-style: disc; }
.msg__text ol { list-style: decimal; }

.msg__text li + li {
  margin-top: 0.35rem;
}

.msg__text code {
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.86em;
  background: var(--paper-alt);
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-sm);
  padding: 0.08rem 0.28rem;
}

.msg__text pre {
  overflow-x: auto;
  background: var(--paper-alt);
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-md);
  padding: var(--nv-sp-4);
}

.msg__text pre code {
  border: none;
  background: transparent;
  padding: 0;
}

/* Fenced code with a labelled header and per-block copy */
.msg__text .code-block {
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-md);
  overflow: hidden;
}

.code-block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--nv-sp-2);
  padding: var(--nv-sp-1) var(--nv-sp-3);
  background: var(--paper-alt);
  border-bottom: 1px solid var(--rule);
}

.code-block__lang {
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--nv-text-muted);
}

.code-block__copy {
  padding: 3px var(--nv-sp-2);
  border-radius: var(--nv-r-sm);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--nv-text-dim);
  transition: color var(--nv-ease), background var(--nv-ease);
}

.code-block__copy:hover,
.code-block__copy:focus-visible {
  color: var(--moss);
  background: var(--nv-tint-accent-low);
  outline: none;
}

.code-block__copy.is-done {
  color: var(--moss);
}

.msg__text .code-block pre {
  border: none;
  border-radius: 0;
  margin: 0;
}

/* Markdown extras: tables, checklists, horizontal rules */
.msg__table {
  overflow-x: auto;
}

.msg__text table {
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.86rem;
  line-height: 1.5;
  min-width: 320px;
}

.msg__text th,
.msg__text td {
  border: 1px solid var(--rule);
  padding: var(--nv-sp-2) var(--nv-sp-3);
  text-align: left;
  vertical-align: top;
}

.msg__text th {
  background: var(--paper-alt);
  font-weight: 600;
}

.msg__text li.msg__task {
  list-style: none;
  margin-left: -1.25rem;
  display: flex;
  align-items: baseline;
  gap: var(--nv-sp-2);
}

.msg__task input[type="checkbox"] {
  accent-color: var(--moss);
  transform: translateY(1px);
}

.msg__text hr {
  border: none;
  border-top: 1px solid var(--rule-strong);
  margin: var(--nv-sp-2) 0;
}

.msg__text blockquote {
  border-left: 2px solid var(--ochre);
  margin: 0;
  padding-left: var(--nv-sp-4);
  color: var(--ink-soft);
}

.msg__text a {
  color: var(--moss);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* Bounded document card in the chat — opens the sliding preview panel */
.msg__preview-action {
  margin-top: var(--nv-sp-4);
  border: 1px solid var(--rule-strong);
  border-radius: var(--nv-r-md);
  padding: var(--nv-sp-3) var(--nv-sp-4);
  display: flex;
  align-items: center;
  gap: var(--nv-sp-3);
  width: min(380px, 100%);
  text-align: left;
  font-family: var(--font-ui);
  color: var(--ink-soft);
  background: var(--paper-alt);
  transition: border-color var(--nv-ease);
}

.msg__preview-action:hover,
.msg__preview-action:focus-visible {
  border-color: var(--moss);
  outline: none;
}

.msg__doc-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-sm);
  color: var(--ochre-ink);
  background: var(--paper);
}

.msg__doc-meta {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 1px;
}

.msg__doc-meta strong {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--nv-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg__doc-meta span {
  font-size: 0.72rem;
  color: var(--nv-text-muted);
}

.msg__doc-open {
  flex-shrink: 0;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--moss);
}

.msg__actions {
  display: flex;
  justify-content: flex-end;
  padding-top: var(--nv-sp-2);
  margin-top: var(--nv-sp-2);
  border-top: 1px solid var(--nv-divider);
}

.why-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--nv-sp-1);
  padding: 3px var(--nv-sp-2);
  border-radius: var(--nv-r-sm);
  color: var(--nv-text-muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  transition: color var(--nv-ease), background var(--nv-ease);
}

.why-btn:hover,
.why-btn:focus-visible {
  color: var(--moss);
  background: var(--nv-tint-accent-low);
  outline: none;
}

/* Copy / Regenerate share the Why button's quiet treatment */
.msg-action {
  display: inline-flex;
  align-items: center;
  gap: var(--nv-sp-1);
  padding: 3px var(--nv-sp-2);
  border-radius: var(--nv-r-sm);
  color: var(--nv-text-muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  transition: color var(--nv-ease), background var(--nv-ease);
}

.msg-action:hover,
.msg-action:focus-visible {
  color: var(--moss);
  background: var(--nv-tint-accent-low);
  outline: none;
}

.msg-action.is-done {
  color: var(--moss);
}

.chat.is-streaming .msg-action--regenerate,
.chat.is-streaming .msg__retry,
.chat.is-streaming .msg__edit {
  display: none;
}

/* Edit-and-resend on the user's own messages — revealed on hover/focus */
.msg--user {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--nv-sp-2);
}

.msg__edit {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--nv-divider);
  border-radius: var(--nv-r-sm);
  color: var(--nv-text-muted);
  opacity: 0;
  transition: opacity var(--nv-ease), color var(--nv-ease), border-color var(--nv-ease);
}

.msg--user:hover .msg__edit,
.msg__edit:focus-visible {
  opacity: 1;
}

.msg__edit:hover,
.msg__edit:focus-visible {
  color: var(--moss);
  border-color: var(--moss);
  outline: none;
}

@media (pointer: coarse) {
  .msg__edit { opacity: 1; }
}

.msg--user.is-editing { width: min(720px, 100%); }
.msg--user.is-editing .msg__edit { display: none; }
.msg--user.is-editing .msg__bubble { flex: 1; }

.msg__edit-area {
  width: 100%;
  min-height: 60px;
  padding: 0;
  color: inherit;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.55;
}

.msg__edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--nv-sp-2);
  margin-top: var(--nv-sp-2);
}

.msg__edit-actions button {
  min-height: 28px;
  padding: 0 var(--nv-sp-3);
  border-radius: var(--nv-r-sm);
  border: 1px solid var(--nv-tint-paper);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--nv-text-on-accent);
}

.msg__edit-actions .msg__edit-send {
  background: var(--paper);
  color: var(--moss-deep);
  border-color: transparent;
}

/* Plain-language failure banner inside the affected bubble */
.msg__error {
  margin-top: var(--nv-sp-3);
  padding: var(--nv-sp-2) var(--nv-sp-3);
  border: 1px solid var(--rule-strong);
  border-radius: var(--nv-r-sm);
  background: var(--nv-tint-ochre);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--nv-sp-3);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--ink);
}

/* The user bubble is moss-dark; keep the banner readable inside it */
.msg--user .msg__error {
  background: var(--paper-alt);
}

.msg__retry {
  flex-shrink: 0;
  min-height: 26px;
  padding: 0 var(--nv-sp-3);
  border: 1px solid var(--ochre-ink);
  border-radius: var(--nv-r-sm);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ochre-ink);
  transition: background var(--nv-ease), color var(--nv-ease);
}

.msg__retry:hover,
.msg__retry:focus-visible {
  background: var(--ochre-ink);
  color: var(--paper);
  outline: none;
}

/* Floating jump-to-latest control, shown when scrolled up */
.chat__jump {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translate(-50%, 6px);
  z-index: 5;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: var(--paper);
  color: var(--moss);
  box-shadow: 0 4px 16px var(--nv-shadow-ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--nv-ease), transform var(--nv-ease);
}

.chat__jump.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.chat__jump:hover,
.chat__jump:focus-visible {
  border-color: var(--moss);
  outline: none;
}

/* Skeleton placeholder while a reply starts streaming — calm opacity pulse,
   no blank gap, no layout shift when text arrives. */
.msg__thinking {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 5px 0;
  width: min(420px, 100%);
}

.msg__thinking span {
  display: block;
  height: 11px;
  border-radius: var(--nv-r-sm);
  background: var(--rule);
  animation: nv-skeleton 1.8s ease-in-out infinite;
}

.msg__thinking span:nth-child(2) { width: 86%; animation-delay: 0.2s; }
.msg__thinking span:nth-child(3) { width: 58%; animation-delay: 0.4s; }

.msg-date {
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--nv-text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: var(--nv-sp-2) 0;
}

/* ── Chat empty / welcome state ── */
.chat__empty {
  /* margin:auto centres the welcome within the flex-column log */
  margin: auto;
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 34rem;
  padding: var(--nv-sp-6) 0;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--nv-sp-4);
  width: 100%;
  animation: nv-empty-rise var(--nv-ease-slow) ease both;
}

.empty-state__title {
  font-family: var(--nv-font-display);
  font-size: clamp(2rem, 1.4rem + 2vw, 3rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: 0;
  color: var(--nv-text);
  text-wrap: balance;
}

.empty-state__lede {
  font-size: 1.08rem;
  line-height: 1.65;
  color: var(--nv-text-dim);
  max-width: 42ch;
  text-wrap: pretty;
}

.empty-state__prompts {
  display: flex;
  flex-direction: column;
  gap: var(--nv-sp-2);
  width: 100%;
  margin-top: var(--nv-sp-2);
}

.empty-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--nv-sp-3);
  width: 100%;
  text-align: left;
  padding: var(--nv-sp-3) var(--nv-sp-4);
  background: transparent;
  border: 1px solid var(--nv-divider);
  border-radius: var(--nv-r-md);
  color: var(--nv-text-dim);
  font-family: var(--font-ui);
  font-size: 0.86rem;
  line-height: 1.4;
  transition: border-color var(--nv-ease), background var(--nv-ease), color var(--nv-ease);
}

.empty-prompt:hover {
  border-color: var(--moss);
  background: var(--nv-tint-accent-low);
  color: var(--moss);
}

.empty-prompt:focus-visible {
  outline: none;
  border-color: var(--moss);
  box-shadow: none;
}

.empty-prompt__arrow {
  flex-shrink: 0;
  color: var(--nv-text-muted);
  transition: transform var(--nv-ease), color var(--nv-ease);
}

.empty-prompt:hover .empty-prompt__arrow,
.empty-prompt:focus-visible .empty-prompt__arrow {
  color: var(--moss);
  transform: translateX(3px);
}

@keyframes nv-empty-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .empty-state { animation: none; }
  .empty-prompt,
  .empty-prompt__arrow { transition: none; }
  .empty-prompt:hover .empty-prompt__arrow,
  .empty-prompt:focus-visible .empty-prompt__arrow { transform: none; }
}

/* Composer */
.chat__composer {
  background: var(--paper-alt);
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-md);
  padding: 0.45rem 0.55rem;
  display: flex;
  align-items: center;
  gap: var(--nv-sp-2);
  flex-shrink: 0;
  max-width: min(760px, calc(100% - (var(--edge) * 2)));
  width: 100%;
  margin: 0 auto var(--nv-sp-4);
}

.composer__attach {
  width: 30px;
  height: 30px;
  border-radius: var(--nv-r-sm);
  border: 1px solid var(--rule-strong);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--nv-text-muted);
  transition: background var(--nv-ease), color var(--nv-ease);
}

.composer__attach:not([disabled]):hover {
  background: var(--nv-tint-accent-low);
  color: var(--moss);
}

.composer__attach[disabled] { opacity: 0.4; cursor: not-allowed; }

.composer__input-wrap {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  border-radius: var(--nv-r-md);
  padding: 0 var(--nv-sp-2);
  transition: border-color var(--nv-ease);
}

.composer__input-wrap:focus-within { border-color: var(--moss); }

.composer__textarea {
  display: block;
  width: 100%;
  min-height: 26px;
  max-height: 88px;
  overflow-y: auto;
  line-height: 1.45;
  font-family: var(--font-ui);
  font-size: 0.92rem;
}

/* Stop-generating: appears beside send only while a reply is streaming */
.composer__stop {
  display: none;
  width: 30px;
  height: 30px;
  border-radius: var(--nv-r-sm);
  border: 1px solid var(--ochre-ink);
  color: var(--ochre-ink);
  place-items: center;
  flex-shrink: 0;
  transition: background var(--nv-ease), color var(--nv-ease);
}

.chat__composer.is-queue-mode .composer__stop {
  display: grid;
}

.composer__stop:hover,
.composer__stop:focus-visible {
  background: var(--ochre-ink);
  color: var(--paper);
  outline: none;
}

.composer__send {
  width: 30px;
  height: 30px;
  border-radius: var(--nv-r-sm);
  background: var(--moss);
  color: var(--nv-text-on-accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background var(--nv-ease), transform 150ms ease;
}

.composer__send:hover { background: var(--moss-deep); }
.composer__send:active { transform: translateY(1px); }
.composer__send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Subtle tint on send button signals queue-mode without changing the icon */
.chat__composer.is-queue-mode .composer__send {
  background: var(--ochre);
}

/* ── Queue indicator ── */
.queue-indicator {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--nv-sp-1) var(--nv-sp-4);
  background: var(--paper-alt);
  border-top: 1px solid var(--nv-divider);
  gap: var(--nv-sp-2);
}

.queue-indicator.is-visible { display: flex; }

.queue-indicator__text {
  display: flex;
  align-items: center;
  gap: var(--nv-sp-2);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--nv-text-dim);
}

.queue-indicator__text::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ochre);
  flex-shrink: 0;
}

.queue-indicator__cancel {
  font-size: 15px;
  color: var(--nv-text-muted);
  line-height: 1;
  padding: 2px var(--nv-sp-1);
  transition: color var(--nv-ease);
}

.queue-indicator__cancel:hover { color: var(--nv-text); }

/* ── Transient status popups (stall / queued-decision / selection) ──
   Built by components/chat/index.js as classes so the theme reaches them;
   the selection popup adds its own inline position:fixed/left/top/transform. */
.nv-popup {
  background: var(--nv-surface);
  border: 1px solid var(--nv-divider);
  border-radius: var(--nv-r-sm);
  padding: 10px 14px;
  margin: 0 var(--nv-sp-4) var(--nv-sp-1);
  display: flex;
  align-items: center;
  gap: var(--nv-sp-3);
  font-family: var(--nv-font-body);
  font-size: 12px;
  color: var(--nv-text-dim);
}

.nv-popup__btn {
  font-family: var(--nv-font-body);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--nv-r-sm);
  cursor: pointer;
  border: 1px solid var(--nv-divider);
  background: var(--nv-surface);
  color: var(--nv-text-dim);
  white-space: nowrap;
  transition: opacity 0.15s;
}

.nv-popup__btn--accent {
  border-color: transparent;
  background: var(--moss);
  color: var(--paper);
}

/* Floating "Why?" popup anchored to a text selection */
.nv-popup--selection {
  position: fixed;
  z-index: 30;
  margin: 0;
  padding: 6px;
  box-shadow: 0 10px 30px var(--nv-shadow-ink);
}

/* ── Right Panel ── */
.panel {
  grid-area: panel;
  background: var(--nv-surface);
  border-left: 1px solid var(--rule-strong);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
  transition: opacity var(--nv-ease), transform var(--nv-ease-slow), visibility var(--nv-ease);
}

.app[data-almanac="closed"] .panel {
  opacity: 0;
  pointer-events: none;
  transform: translateX(18px);
  visibility: hidden;
}

.panel__head {
  position: relative; /* anchors the add-instrument menu */
  padding: var(--nv-sp-3) var(--nv-sp-4);
  border-bottom: 3px double var(--rule-strong);
  display: flex;
  align-items: center;
  gap: var(--nv-sp-2);
  flex-shrink: 0;
  min-height: 52px;
}

.panel__label {
  display: inline-flex;
  align-items: center;
  gap: var(--nv-sp-2);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ochre-ink);
  margin-right: auto;
}

.panel__collapse {
  width: 34px;
  height: 34px;
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-sm);
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}

.panel__collapse:hover,
.panel__collapse:focus-visible {
  border-color: var(--moss);
  color: var(--moss);
  outline: none;
}

.almanac-rail {
  position: fixed;
  top: 50%;
  right: var(--nv-sp-3);
  z-index: 35;
  writing-mode: vertical-rl;
  transform: translateY(-50%);
  display: none;
  padding: var(--nv-sp-3) var(--nv-sp-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--nv-r-md);
  background: var(--paper-alt);
  color: var(--moss);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.app[data-almanac="closed"] .almanac-rail {
  display: inline-flex;
}

/* Collapsed left sidebar — a slim icon rail sharing grid-area: sidebar with the
   full sidebar; only one is visible at a time. Lives in the grid (beside the
   chat), never an overlay. The mark expands back to the full sidebar. */
.sidebar-rail {
  grid-area: sidebar;
  z-index: 5;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--nv-sp-1);
  padding: var(--nv-sp-4) 0;
  background: var(--nv-surface);
  border-right: 1px solid var(--rule-strong);
  overflow: hidden;
}

.app[data-sidebar="closed"] .sidebar-rail {
  display: flex;
}

.sidebar-rail__mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  margin-bottom: var(--nv-sp-2);
  border-radius: var(--nv-r-sm);
  color: var(--moss);
  transition: background var(--nv-ease);
}

.sidebar-rail__mark:hover,
.sidebar-rail__mark:focus-visible {
  background: var(--nv-tint-accent-low);
  outline: none;
}

.sidebar-rail__btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--nv-r-sm);
  color: var(--ink-soft);
  transition: background var(--nv-ease), color var(--nv-ease);
}

.sidebar-rail__btn:hover,
.sidebar-rail__btn:focus-visible {
  background: var(--nv-tint-accent-low);
  color: var(--moss);
  outline: none;
}

.sidebar-rail__spacer {
  flex: 1;
}

.sidebar-rail__avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--nv-r-sm);
  background: var(--moss);
  color: var(--nv-text-on-accent);
  display: grid;
  place-items: center;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  transition: background var(--nv-ease);
}

.sidebar-rail__avatar:hover,
.sidebar-rail__avatar:focus-visible {
  background: var(--moss-deep);
  outline: none;
}

/* Slides in over the Almanac (like Claude's artifact panel), never squeezes
   the chat grid. Same open/close pattern as the Why Layer. */
.document-preview {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100%);
  z-index: 38;
  background: var(--paper-alt);
  border-left: 1px solid var(--rule-strong);
  box-shadow: -8px 0 30px var(--nv-shadow-ink);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--nv-ease);
}

.document-preview.is-open {
  transform: none;
}

.document-preview[hidden] {
  display: none;
}

.document-preview__file {
  margin: var(--nv-sp-4) var(--nv-sp-5) 0;
  padding: var(--nv-sp-3) var(--nv-sp-4);
  border: 1px solid var(--rule-strong);
  border-radius: var(--nv-r-md);
  background: var(--paper);
  display: flex;
  align-items: center;
  gap: var(--nv-sp-3);
  flex-shrink: 0;
}

.document-preview__file-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-sm);
  color: var(--ochre-ink);
  background: var(--paper-alt);
}

.document-preview__file-meta {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 1px;
}

.document-preview__file-meta strong {
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--nv-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-preview__file-meta span {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--nv-text-muted);
}

.document-preview__download {
  flex-shrink: 0;
  min-height: 32px;
  padding: 0 var(--nv-sp-4);
  border-radius: var(--nv-r-sm);
  background: var(--moss);
  color: var(--nv-text-on-accent);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  transition: background var(--nv-ease);
}

.document-preview__download:hover,
.document-preview__download:focus-visible {
  background: var(--moss-deep);
  outline: none;
}

.document-preview__head {
  min-height: 52px;
  padding: var(--nv-sp-3) var(--nv-sp-5);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--nv-sp-3);
}

.document-preview__eyebrow {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ochre-ink);
}

.document-preview__title {
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.2;
}

.document-preview__close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--rule);
  border-radius: var(--nv-r-sm);
  color: var(--ink-soft);
}

.document-preview__close:hover,
.document-preview__close:focus-visible {
  border-color: var(--moss);
  color: var(--moss);
  outline: none;
}

.document-preview__body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(1.5rem, 3vw, 2.5rem);
  font-size: 1rem;
  line-height: 1.75;
}

.document-preview__body .msg__text {
  max-width: 62ch;
  margin-inline: auto;
}

.nv-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--nv-bg);
}

.nv-spinner {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--nv-sp-3);
  width: max-content;
}

.nv-spinner__svg {
  display: block;
  width: var(--nv-spinner-size);
  height: var(--nv-spinner-size);
  overflow: visible;
  color: var(--moss);
}

.nv-spinner__status {
  margin: 0;
  font-family: var(--nv-font-body);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--nv-text-muted);
  text-align: center;
}

.nv-spinner__status[hidden] {
  display: none;
}

.panel__widgets {
  flex: 1;
  overflow-y: auto;
  padding: var(--nv-sp-3);
}

.shell-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 34;
  width: 12px;
  cursor: col-resize;
  touch-action: none;
}

.shell-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 1px;
  background: transparent;
  transition: background var(--nv-ease);
}

.shell-resizer:hover::before,
.shell-resizer:focus-visible::before,
.app.is-resizing .shell-resizer::before {
  background: var(--moss);
}

.shell-resizer--sidebar {
  left: calc(var(--sidebar-live-w) - 6px);
}

.shell-resizer--almanac {
  right: calc(var(--panel-live-w) - 6px);
}

.app[data-sidebar="closed"] .shell-resizer--sidebar,
.app[data-almanac="closed"] .shell-resizer--almanac {
  display: none;
}

/* Fixed to the viewport, not nested in .panel: the panel is display:none below
   1080px and a child overlay would vanish with it — the Why Layer must stay
   reachable on tablet and phone. Desktop geometry is identical (right edge,
   panel width, full height). */
.why-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--nv-panel-w);
  z-index: 40;
  overflow-y: auto;
  transform: translateX(100%);
}

.why-overlay.is-open {
  transform: translateX(0);
}

.why-overlay[hidden] {
  display: none;
}

/* ── Responsive ── */
/* Each breakpoint restates every data-attribute combination the base sheet
   defines: the base combo selectors (e.g. .app[data-sidebar="closed"]
   [data-almanac="closed"]) are more specific than a bare .app override, so
   leaving one out lets a 3-track desktop template win inside a 1-column
   template-areas — which squeezed the whole chat into a 56px rail track. */
@media (max-width: 1080px) {
  .app,
  .app[data-almanac="closed"] {
    grid-template-columns: var(--nv-sidebar-w) minmax(0, 1fr);
    grid-template-areas: "sidebar chat";
  }
  .app[data-sidebar="closed"],
  .app[data-sidebar="closed"][data-almanac="closed"] {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }
  /* The Almanac leaves the grid and becomes a slide-over (same pattern as
     the Why Layer / document preview), opened from the almanac rail. */
  .panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(360px, 100%);
    z-index: 36;
    box-shadow: -8px 0 30px var(--nv-shadow-ink);
  }
  .app[data-almanac="closed"] .panel {
    transform: translateX(100%);
  }
  .shell-resizer--almanac { display: none; }
  .chat__stream-status:not([hidden]) { display: inline-flex; }
  .why-overlay {
    width: min(360px, 100%);
    box-shadow: -8px 0 30px var(--nv-shadow-ink);
  }
}

@media (max-width: 768px) {
  .app,
  .app[data-almanac="closed"],
  .app[data-sidebar="closed"],
  .app[data-sidebar="closed"][data-almanac="closed"] {
    grid-template-columns: 1fr;
    grid-template-areas: "chat";
  }
  .sidebar {
    position: fixed;
    left: calc(-1 * var(--nv-sidebar-w));
    top: 0;
    bottom: 0;
    z-index: 100;
    width: var(--nv-sidebar-w);
    transition: left var(--nv-ease);
  }
  .app[data-sidebar="closed"] .sidebar {
    opacity: 1;
    transform: none;
    visibility: visible;
    /* The base closed-state rule disables pointer events; the mobile drawer
       is the same element slid off-canvas, so it must stay interactive. */
    pointer-events: auto;
  }
  .app.sidebar-open .sidebar {
    left: 0;
    box-shadow: 4px 0 20px var(--nv-shadow-ink);
  }
  .sidebar__hamburger { display: flex; }
  .sidebar__collapse,
  .sidebar-rail { display: none !important; }
  /* Clear the fixed hamburger (occupies ~12-46px from the left edge) so
     titles aren't hidden underneath it. */
  .chat__header,
  .changelog-overlay__head,
  .why-overlay__head,
  .document-preview__head {
    padding-left: 56px;
  }
  .document-preview { width: 100%; }
  .why-overlay { width: 100%; }
  .panel { width: 100%; }
}

/* Touch devices: 44px minimum hit areas (WCAG 2.5.5 / mobile parity). */
@media (pointer: coarse) {
  .composer__send,
  .composer__attach,
  .sidebar-rail__mark,
  .sidebar-rail__btn {
    width: 44px;
    height: 44px;
  }
  .queue-indicator__cancel {
    padding: 10px 12px;
  }
  .why-btn {
    padding: 8px 12px;
  }
  .why-overlay__dismiss,
  .changelog-overlay__dismiss {
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar__new,
  .thread-item,
  .chat__composer,
  .sidebar__collapse,
  .composer__send,
  .composer__stop,
  .nv-popup__btn,
  .panel,
  .document-preview,
  .almanac-rail,
  .sidebar-rail,
  .sidebar-rail__mark,
  .sidebar-rail__btn,
  .sidebar-rail__avatar,
  .msg-action,
  .msg__edit,
  .msg__retry,
  .msg__preview-action,
  .code-block__copy,
  .chat__jump,
  .document-preview__download {
    transition: none;
  }
  .sidebar__new:active,
  .composer__send:active {
    transform: none;
  }
  .chat__jump,
  .chat__jump.is-visible {
    transform: translate(-50%, 0);
  }
}
