/* ai-fullscreen.css — Full AI screen (#/ai) layout + polish (#908).
 *
 * Replaces the inline-style soup that used to live in ai-fullscreen.js.
 * Goals of this file:
 *   - Lock the chat-column reading width to ~760px so long answers wrap
 *     at a comfortable line length on wide displays (was bleeding to
 *     ~980px before).
 *   - Quiet the sidebar — trash icons hide-on-hover, "All chats" is a
 *     subtle nav row not a purple CTA, conversation list fades at the
 *     bottom so scrollability is obvious.
 *   - Anchor the empty state in the upper third of the pane rather than
 *     vertically centering an icon-headline-chip stack in 70vh of
 *     whitespace.
 *
 * Token discipline: every color comes from a token defined in
 * style.css. Hex fallbacks were stripped intentionally — when the token
 * system updates, callers should track it.
 */

/* -----------------------------------------------------------------
 * Layout shell
 * ----------------------------------------------------------------- */

/* The app shell renders every route inside `<main class="page-content">`
 * which has `max-width: 1280px`, horizontal padding, and `margin: 0
 * auto`. For the /#/ai route that container CENTERS the AI surface
 * inside a 1280px box and adds whitespace on either side at wider
 * viewports. We override those constraints when the AI surface is the
 * page-content's child so the shell truly fills the browser width
 * edge-to-edge. */
main.page-content:has(.ai-fullscreen) {
  max-width: none;
  padding: 0;
  margin-left: 0;
  margin-right: 0;
  width: 100%;
}

.ai-fullscreen {
  display: flex;
  height: calc(100dvh - var(--nav-height, 56px));
  min-height: 0;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

/* Hairline divider — the 4px filled bar shipped in round 1 reads as
 * a 1998-era column-split. Modern apps use a 1px hairline that EXPANDS
 * the hit-test area on hover via a transparent pseudo-element so the
 * drag-to-resize affordance stays without the visual clutter. */
.ai-fullscreen-divider {
  width: 1px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  position: relative;
  transition: background-color 120ms;
}
.ai-fullscreen-divider::before {
  /* invisible 9px hit area straddling the hairline */
  content: "";
  position: absolute;
  inset: 0 -4px;
}
.ai-fullscreen-divider:hover,
.ai-fullscreen-divider:focus-visible {
  background: var(--accent);
}

/* -----------------------------------------------------------------
 * Left rail — collections + sessions
 * ----------------------------------------------------------------- */

.ai-fullscreen-rail {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  /* Use `--bg-subtle` so the rail reads visibly distinct from the main
   * pane (which sits on the page-level canvas). In the light theme the
   * page is white-on-white otherwise and the sidebar appears to merge
   * with the chat area; in dark theme both are dark but the subtle tone
   * still separates them. */
  background: var(--bg-subtle);
  overflow: hidden;
  position: relative;
  /* Smooth width animation when toggling collapse so the columns "flow
   * together" instead of snapping. claude.ai uses ~150ms ease-out. */
  transition: width 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Topbar — collapse toggle. Sits at the very top-right of the rail so
 * the visual matches the claude.ai pattern where the sidebar control
 * is in its own header band. */
.ai-fullscreen-rail__topbar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 10px 0;
}
.ai-fullscreen-rail__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}
.ai-fullscreen-rail__toggle:hover {
  background: var(--bg-active);
  color: var(--text-primary, inherit);
}
.ai-fullscreen-rail.is-collapsed .ai-fullscreen-rail__topbar {
  justify-content: center;
  padding: 10px 0 0;
}

/* When collapsed, the rail shrinks to a slim icon column. Hide every
 * child block except the topbar (toggle) and the New chat button —
 * the latter renders as an icon-only square via the rules below.
 * Conversation list, search, collections tree, breadcrumbs all hide
 * because there's no room to render them legibly at 56px. */
.ai-fullscreen-rail.is-collapsed > :not(.ai-fullscreen-rail__topbar):not(.ai-fullscreen-rail__newchat) {
  display: none;
}
.ai-fullscreen-rail.is-collapsed .ai-fullscreen-rail__label {
  /* Labels inside the New chat button hide so it reads as an icon
   * square. The icon itself stays. */
  display: none;
}
.ai-fullscreen-rail.is-collapsed .ai-fullscreen-rail__newchat-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ai-fullscreen-rail.is-collapsed .ai-fullscreen-rail__newchat {
  padding: 8px 10px 12px;
}

/* Neutralize the legacy CollectionsTree "active row" styling on this
 * surface. The component renders its active row with `--accent-subtle`
 * (a purple tint at ~12% opacity) inline, which on a white rail bg
 * reads as a loud purple block — the wrong visual hierarchy when
 * "New chat" above it is already the page's primary CTA. Force a
 * neutral gray active tone. Scoped to .ai-fullscreen-rail descendants
 * so the floating-chat / split-view surfaces (which share the
 * component) are unaffected. `!important` is required because the
 * component sets `background:` inline. */
.ai-fullscreen-rail .collections-tree-row.active {
  background: var(--bg-active) !important;
  color: var(--text-primary, inherit) !important;
}

/* CollectionsTree's outer <nav> ships with inline `max-height: 260px;
 * overflow-y: auto` which is fine on a regular block layout, but
 * inside the rail's `flex-direction: column` parent the implicit
 * `flex-shrink: 1` lets the rail's later children (sessions list with
 * `flex: 1`) collapse the tree to ~0 height — so the "All chats" row
 * (the first child of the tree) is visible and everything after it
 * (user collections rendered via tree.map + the "+ New collection"
 * button) gets clipped out of view. Lock the tree to its content
 * height so it sits above the sessions list cleanly (#919). */
.ai-fullscreen-rail .collections-tree {
  flex-shrink: 0;
}

/* #921 — conversation-count chip rendered next to each collection name
 * (and next to "All chats"). Caller suppresses the chip when count=0
 * so an empty collection reads cleanly. */
.collection-count-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--bg-active);
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.collections-tree-row.active .collection-count-chip {
  background: var(--accent-subtle);
  color: var(--accent);
}

.ai-fullscreen-rail__newchat {
  padding: 16px 12px 12px;
}
.ai-fullscreen-rail__newchat > .btn {
  width: 100%;
  border-radius: 10px;
  font-weight: 500;
  padding: 10px 14px;
}

.ai-fullscreen-rail__collections {
  padding: 8px 12px;
  color: var(--text-tertiary);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-fullscreen-rail__search {
  padding: 8px 12px 12px;
}
.ai-fullscreen-rail__search > input {
  width: 100%;
  padding: 8px 12px;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
.ai-fullscreen-rail__search > input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* Sessions list — scrollable inside the rail. On macOS the system
 * scrollbar is overlay-style and only appears on hover, which made
 * users assume the list wasn't scrollable at all. Force a thin always-
 * visible track via `scrollbar-width: thin` (Firefox) and `::-webkit-
 * scrollbar` rules (Chromium / Safari) so the affordance is permanent.
 * `min-height: 0` is the magic flex-child reset that prevents this
 * `flex: 1` child from inheriting its content's intrinsic height and
 * blowing past the parent — without it, in some browsers the rail's
 * `flex-direction: column` lets the list grow unbounded. */
.ai-fullscreen-rail__sessions {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.ai-fullscreen-rail__sessions::-webkit-scrollbar {
  width: 8px;
}
.ai-fullscreen-rail__sessions::-webkit-scrollbar-track {
  background: transparent;
}
.ai-fullscreen-rail__sessions::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.ai-fullscreen-rail__sessions::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

.ai-fullscreen-rail__empty {
  padding: 12px;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* Conversation row — title is the primary click target; the trash icon
 * is reveal-on-hover so the list isn't visually noisy at rest. Rows get
 * a generous touch height + soft rounded hover state, scoped inside an
 * 8px horizontal gutter so the active highlight doesn't bleed
 * edge-to-edge of the rail (which read as "the entire rail row is
 * selected" — visually too loud). */
.ai-fullscreen-rail__sessions > li {
  padding: 0 8px;
}
.ai-fullscreen-session {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
  color: var(--text-secondary, inherit);
  font: inherit;
  border-radius: 8px;
  position: relative;
  transition: background-color 100ms;
}
.ai-fullscreen-session:hover {
  background: var(--bg-active);
}
.ai-fullscreen-session.active {
  background: var(--bg-active);
  color: var(--text-primary, inherit);
  font-weight: 500;
}
.ai-fullscreen-session__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.ai-fullscreen-session__delete {
  background: transparent;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--text-tertiary);
  opacity: 0;
  transition: opacity 80ms;
}
.ai-fullscreen-session:hover .ai-fullscreen-session__delete,
.ai-fullscreen-session:focus-within .ai-fullscreen-session__delete,
.ai-fullscreen-session__delete:focus-visible {
  opacity: 1;
}
.ai-fullscreen-session__delete:hover {
  color: var(--danger);
}
/* Touch — keep the trash visible on coarse pointers so users without
 * hover affordance can still delete. */
@media (hover: none) {
  .ai-fullscreen-session__delete {
    opacity: 0.6;
  }
}

/* Collection nav rows — used for "All chats", "+ New collection", and
 * each user-created collection. Subtle, not a CTA. The active state is
 * a soft bg, not a filled purple block (which was overpowering the
 * actual primary action — "New chat" — directly above it). */
.ai-fullscreen-rail__nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  font: inherit;
  color: var(--text-secondary, inherit);
  text-align: left;
  width: 100%;
}
.ai-fullscreen-rail__nav-row:hover {
  background: var(--bg-subtle);
}
.ai-fullscreen-rail__nav-row.active {
  background: var(--bg-active);
  color: var(--text-primary, inherit);
  font-weight: 500;
}

/* -----------------------------------------------------------------
 * Main chat pane
 * ----------------------------------------------------------------- */

.ai-fullscreen-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-surface);
  /* Ensure the main pane never overflows its flex parent — combined
   * with the .ai-fullscreen { overflow: hidden } shell rule above this
   * is what prevents the page horizontal-scrolling when a wide
   * markdown table lands inside an assistant bubble. */
  overflow: hidden;
}

/* The messages container scrolls; the inner wrapper centers the column
 * so long bubbles wrap at ~65ch instead of stretching across the entire
 * viewport on wide displays (the biggest readability complaint). */
.ai-fullscreen-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.ai-fullscreen-messages__column {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
  box-sizing: border-box;
}

/* Smaller viewports — shrink padding so the column still has breathing
 * room without hugging the rail. */
@media (max-width: 720px) {
  .ai-fullscreen-messages { padding: 16px; }
  .ai-fullscreen-messages__column { gap: 12px; }
}

/* Empty state — anchored a bit above center, NOT top-glued. Round 2
 * (#908) top-anchored the block at `margin-top: clamp(40px, 12vh, 120px)`
 * which left a tall slab of pure whitespace between the chip grid and
 * the composer at the bottom of the pane. Use `margin: auto` instead so
 * the block centers vertically in whatever space the messages column
 * has, with `min-height: 0` on the column parent making the centering
 * resolve correctly inside a flex parent. The block stays a max of
 * 560px wide and a max of ~520px tall (icon + headline + sub + 2x2
 * grid) so on tall viewports it sits roughly 40% from the top — close
 * to where the eye lands on first look. */
/* claude.ai-inspired hero (round 5). Time-aware greeting in
 * Source Serif 4 next to a coral sparkles icon, then a single row of
 * quick-action pill chips below. No "Try one of these" sub-copy —
 * the chips ARE the prompt. */
.ai-fullscreen-empty {
  /* True vertical center via `margin: auto`. Round 5 (#914) shipped
   * `margin: auto auto 0` which set bottom=0 and pushed the block to
   * the BOTTOM of the messages column — the composer then fell below
   * the viewport fold and required scrolling to reach. */
  margin: auto;
  padding: 32px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  max-width: 720px;
  text-align: center;
}
.ai-fullscreen-empty__hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.ai-fullscreen-empty__hero > svg,
.ai-fullscreen-empty__hero > img {
  color: var(--accent);
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}
.ai-fullscreen-empty__title {
  /* Source Serif 4 — pulled in by index.html with the Inter +
   * JetBrains Mono request. Matches the editorial tone of the visual
   * reference (claude.ai) while staying within the existing brand
   * type stack everywhere else on the platform. */
  font-family: "Source Serif 4", "Charter", "Georgia", serif;
  font-size: clamp(32px, 4.4vw, 44px);
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--text-primary, inherit);
  line-height: 1.1;
  margin: 0;
}
.ai-fullscreen-empty__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}

/* Quick-action pill — small, monochrome, icon-led. Inspired by the
 * "Code / Write / From Drive / From Calendar" row on claude.ai. Sits
 * directly below the greeting in the empty state. */
.ai-fullscreen-quickchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-secondary, inherit);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms, background-color 120ms,
              color 120ms, transform 100ms;
}
.ai-fullscreen-quickchip > svg {
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.ai-fullscreen-quickchip:hover {
  border-color: var(--accent);
  color: var(--text-primary, inherit);
  background: var(--accent-subtle);
}
.ai-fullscreen-quickchip:hover > svg {
  color: var(--accent);
}
.ai-fullscreen-quickchip:active {
  transform: translateY(1px);
}
.ai-fullscreen-quickchip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Message bubbles — the inner wrapper centers + caps width, so the
 * bubbles just hug their content up to the column width. */
.ai-fullscreen-execution {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-fullscreen-message {
  display: flex;
}
.ai-fullscreen-message.user {
  justify-content: flex-end;
}
.ai-fullscreen-message.assistant {
  justify-content: flex-start;
  /* #927 — stack the read-aloud action row beneath the answer bubble. */
  flex-direction: column;
  align-items: flex-start;
}
.ai-fullscreen-message-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  word-break: break-word;
}
.ai-fullscreen-message-bubble.user {
  background: var(--accent);
  color: var(--accent-fg, #fff);
}
.ai-fullscreen-message-bubble.assistant {
  background: var(--bg-subtle);
  color: inherit;
}
.ai-fullscreen-message-bubble.assistant.error,
.ai-fullscreen-message.assistant.error .ai-fullscreen-message-bubble {
  color: var(--danger);
}
.ai-fullscreen-message-bubble__thinking {
  color: var(--text-tertiary);
}

/* Markdown tables / fenced code blocks inside an assistant bubble can
 * have intrinsic widths far larger than the column cap (especially when
 * an agent emits a CSV preview or a wide-column domain list). Without
 * letting the OVERFLOW happen on the bubble itself, the table pushes
 * the flex layout and the whole page horizontal-scrolls. Cap the
 * intrinsic width to the bubble's box and let the bubble scroll
 * internally for the rare wide-table case. */
.ai-fullscreen-message-bubble.assistant {
  max-width: 100%;
  overflow-x: auto;
}
.ai-fullscreen-message-bubble.assistant table,
.ai-fullscreen-message-bubble.assistant pre {
  max-width: 100%;
  overflow-x: auto;
}

/* -----------------------------------------------------------------
 * Composer (text input + voice + Send)
 * -----------------------------------------------------------------
 *
 * The composer used to be inline-styled in `ai-fullscreen.js` with a
 * bare `<input>` and a `padding: "8px 12px"` rule and nothing else —
 * which is why the input rendered as a default browser-styled box with
 * no rounding, no token-aware background, and no focus ring. Rebuild
 * it here as a pill-shaped composer with the input + buttons living
 * INSIDE a single rounded container so the surface reads as one
 * primary action area, not three loose form controls.
 */

.ai-fullscreen-composer {
  /* No border-top — let the pill itself be the visual element so the
   * composer feels like it floats over the messages column rather than
   * sitting in a fixed footer band. The empty state has plenty of
   * breathing room above, and during a conversation the column scrolls
   * cleanly past the pill. */
  background: transparent;
  padding: 8px 24px 20px;
  flex-shrink: 0;
}

.ai-fullscreen-composer__inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 18px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--bg-surface);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  transition: border-color 120ms, box-shadow 120ms;
}
.ai-fullscreen-composer__inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle),
              0 2px 12px rgba(0, 0, 0, 0.06);
}

.ai-fullscreen-composer__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  padding: 10px 4px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-primary, inherit);
}
.ai-fullscreen-composer__input::placeholder {
  color: var(--text-tertiary);
}
.ai-fullscreen-composer__input:disabled {
  opacity: 0.6;
  cursor: progress;
}

.ai-fullscreen-composer__btn {
  border-radius: 18px;
  padding: 8px 18px;
  min-height: 36px;
}

@media (max-width: 720px) {
  .ai-fullscreen-composer { padding: 10px 12px 14px; }
  .ai-fullscreen-composer__inner { padding-left: 12px; }
}

/* Network status badge — sits above the composer when offline or the
 * server is unreachable. Kept as a thin info bar, not a banner, so the
 * composer stays the visual anchor. */
.ai-fullscreen-netbadge {
  padding: 6px 24px;
  font-size: 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border-top: 1px solid var(--border);
  text-align: center;
}

/* #927 — two-way voice in Full AI mode */
.ai-fullscreen-message-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
/* Voice settings popover sits just above the composer, right-aligned to
   the gear + mic controls. agent-chat.css supplies .voice-settings-panel
   visuals; this only positions the wrapper within the Full AI column. */
.ai-fullscreen-voice-settings {
  display: flex;
  justify-content: flex-end;
  padding: 0 16px;
}
.ai-fullscreen-voice-settings .voice-settings-panel {
  margin-bottom: 8px;
  max-width: 320px;
}
