/* Shared reader layout for two independently closable workspace files. */
.app-shell { --rail-width: 46px; --sidebar-width: 224px;
  grid-template-columns: var(--rail-width) var(--sidebar-width) var(--divider-width) minmax(0, 1fr); }
.app-shell.panel-hidden { grid-template-columns: var(--rail-width) minmax(0, 1fr); }
.workspace-rail { padding: 8px 3px; gap: 4px; }
.workspace-rail button { min-height: 42px; padding: 4px 1px; }
.workspace-rail button small { font-size: .65rem; letter-spacing: -.01em; }
.app-shell .chat-layout { display: flex; flex-direction: row; align-items: stretch; min-width: 0; }
.app-shell .chat-primary-pane { min-width: 0; width: 100%; min-height: 0; height: 100%; display: flex; flex-direction: column; position: relative; }
.app-shell.comparison-open .chat-primary-pane { width: 0; flex: 1 1 0; }
.app-shell .comparison-pane { min-width: 0; min-height: 0; height: 100%; background: var(--bg); }
.app-shell.comparison-open .comparison-pane { flex: 0 0 var(--comparison-width, 50%); display: flex; flex-direction: column; }
.comparison-divider { flex: 0 0 8px; cursor: col-resize; touch-action: none; background: var(--surface); border-inline: 1px solid var(--border); position: relative; z-index: 19; }
.comparison-divider::after { content: ''; width: 2px; height: 36px; border-radius: 2px; background: var(--muted); position: absolute; top: 50%; left: 2px; opacity: .48; }
.comparison-divider:hover, .comparison-divider:focus-visible { background: var(--surface-strong); outline: 0; }
.comparison-divider:hover::after, .comparison-divider:focus-visible::after { opacity: 1; }
.comparison-topbar { flex: 0 0 64px; display: flex; justify-content: space-between; align-items: center; padding: 8px 13px; border-bottom: 1px solid var(--border); gap: 8px; min-width: 0; }
.comparison-topbar strong { font-size: .94rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.comparison-close, .comparison-tools button { min-width: 32px; min-height: 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); cursor: pointer; }
.comparison-tools { display: flex; flex: 0 0 auto; align-items: center; gap: 5px; min-width: 0; border-bottom: 1px solid var(--border); padding: 8px; }
.comparison-tools input { min-width: 0; flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--text); font-size: .8rem; }
.comparison-tools small { font-size: .66rem; color: var(--muted); white-space: nowrap; }
.comparison-tools button:disabled { opacity: .35; cursor: default; }
.comparison-viewport { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; min-height: 0; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--muted) transparent; }
.comparison-viewport .messages { padding: 18px 12px 24px; }
.comparison-viewport .message__inner { padding: 15px 0; }
.comparison-viewport .message__content { overflow-wrap: anywhere; }
.comparison-viewport .message.is-comparison-match { background: color-mix(in srgb, var(--accent) 7%, transparent); outline: 1px solid var(--border); border-radius: 8px; }
.comparison-note { font-size: .68rem; line-height: 1.4; text-align: center; color: var(--muted); flex: 0 0 auto; margin: 0; padding: 10px; border-top: 1px solid var(--border); }
.comparison-empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.comparison-pane .message__actions { flex-shrink: 0; }
.comparison-pane .message__inline-editor { max-width: 100%; }
.app-shell .chat-primary-pane .composer-wrap { left: auto; right: auto; width: 100%; }
.app-shell .chat-primary-pane .chat-reader { min-height: 0; }
.comparison-divider:focus-visible, .comparison-tools :focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media(max-width: 1040px) {
 .app-shell .chat-primary-pane { flex: 1 1 auto; }
 .app-shell.comparison-open .chat-primary-pane { display: none; }
 .app-shell.comparison-open .comparison-pane { flex: 1 1 100%; }
 .comparison-divider { display: none !important; }
}
@media(max-width: 820px) {
 .app-shell, .app-shell.panel-hidden { --rail-width: 42px; grid-template-columns: var(--rail-width) minmax(0, 1fr); }
 .app-shell .sidebar { left: var(--rail-width); width: min(340px, calc(100vw - var(--rail-width))); }
 .app-shell .workspace-divider { display:none; }
 .sidebar-backdrop { left: var(--rail-width); right: 0; }
}
@media(max-width: 480px) {
 .comparison-topbar { flex-basis: 52px; }
 .comparison-tools { flex-wrap: wrap; }
 .comparison-tools input { flex-basis: 100%; }
 .comparison-note { font-size: .62rem; }
 .comparison-viewport .message__inner { grid-template-columns: 25px minmax(0,1fr); gap: 8px; }
}
@media(prefers-reduced-motion: reduce) { .comparison-divider, .comparison-pane { scroll-behavior: auto; } }

/* A replicated navigation/selection workspace, independent of the original source reader. */
.comparison-pane .comparison-reader { min-height: 0; flex: 1 1 auto; }
.comparison-pane .comparison-viewport { flex: 1 1 auto; scrollbar-width: none; }
.comparison-pane .comparison-viewport::-webkit-scrollbar { display: none; }
.comparison-pane .highlight-tools { padding: 6px 8px; }
.chat-primary-pane .chat-scrollbar, .comparison-pane .chat-scrollbar { flex: 0 0 var(--chat-scrollbar-width, 46px); }
@media(max-width:820px) { .app-shell { --chat-scrollbar-width: 42px; } }
.comparison-pane .chat-scroll-preview { z-index: 40; }
.comparison-pane .highlight-tools .chat-navigation-toolbar { margin-left: auto; }
@media(max-width: 520px) { .comparison-pane .highlight-tools { padding: 4px 6px; } }

.comparison-pane .comparison-tools[hidden] { display: none !important; }
.comparison-preview-host { position: relative; }

/* The global status bar owns the complete first grid row, above the rail, explorer,
   divider and chat panes. All workspaces share the remaining viewport height. */
.app-shell { --global-status-height: 36px; grid-template-rows: var(--global-status-height) minmax(0, 1fr); }
.app-shell .workspace-global-status {
  grid-column: 1 / -1; grid-row: 1; position: relative; z-index: 50;
  inset: auto; width: 100%; height: var(--global-status-height); min-width: 0;
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 2px 12px; border-bottom: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: .72rem;
}
.app-shell .workspace-rail { grid-column: 1; grid-row: 2; top: auto; height: 100%; min-height: 0; }
.app-shell .sidebar { grid-column: 2; grid-row: 2; top: auto; height: 100%; min-height: 0; }
.app-shell .workspace-divider { grid-column: 3; grid-row: 2; top: auto; height: 100%; min-height: 0; }
.app-shell .chat-layout { grid-column: 4; grid-row: 2; height: 100%; min-height: 0; margin-top: 0; }
.app-shell.panel-hidden .chat-layout { grid-column: 2; }
.workspace-global-status .model-badge { font-size: .68rem; padding: 3px 8px; max-width: 45%; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.workspace-global-status #chat-cost { font-size: .70rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 820px) {
  .app-shell .sidebar { top: var(--global-status-height); height: calc(100dvh - var(--global-status-height)); }
  .app-shell .sidebar-backdrop { top: var(--global-status-height); }
  .app-shell .chat-layout { grid-column: 2; }
}
@media (max-width: 520px) {
  .app-shell .workspace-global-status { gap: 5px; padding: 2px 7px; }
  .workspace-global-status .model-badge { max-width: 85px; }
  .workspace-global-status #chat-cost { font-size: .62rem; }
}

/* Workspace windows can be closed separately without deleting the conversation. */
.app-shell.source-closed .chat-primary-pane { display: none !important; }
.app-shell.source-closed .comparison-pane:not([hidden]) { flex: 1 1 100%; }
.app-shell.workspace-empty .chat-layout { background: var(--bg); }
.app-shell .chat-primary-pane .topbar, .app-shell .comparison-topbar { min-height: 64px; height: 64px; flex: 0 0 64px; }
.app-shell .chat-primary-pane .topbar { gap: 9px; }
.app-shell .chat-primary-pane .topbar__conversation { min-width: 0; }
.app-shell .chat-primary-pane #active-chat-title { min-width: 0; }
.app-shell .chat-primary-pane .comparison-close { flex-shrink: 0; }
/* Same source component, same footprint and marker coordinate system on both readers. */
.app-shell { --chat-scrollbar-width: 46px; }
.app-shell .chat-primary-pane .chat-scrollbar, .app-shell .comparison-pane .chat-scrollbar { width: var(--chat-scrollbar-width); flex: 0 0 var(--chat-scrollbar-width); }
@media(max-width:820px) { .app-shell { --chat-scrollbar-width: 42px; } }

/* Explorer represents a chat as a group of two independent workspace files. */
.conversation-file-group { min-width: 0; border-radius: 9px; padding: 1px 2px 5px; }
.conversation-file-group__header { width: 100%; min-height: 34px; grid-template-columns: minmax(0,1fr) auto; padding: 3px 4px; }
.conversation-file-group__header .conversation-item__title { font-weight: 650; font-size: .77rem; }
.conversation-file-group__children { display: grid; gap: 2px; border-inline-start: 1px solid var(--border); margin-inline-start: 12px; padding-inline-start: 9px; }
.conversation-file-group__file { min-height: 31px; width: 100%; display: block; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: .77rem; padding: 6px 7px; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.conversation-file-group__file::before { content: '▤'; margin-inline-end: 6px; opacity: .7; }
.conversation-file-group__file:hover, .conversation-file-group__file:focus-visible, .conversation-file-group__file.is-open { background: var(--surface-strong); color: var(--text); }
.conversation-file-group__file.is-open { font-weight: 650; }
.conversation-file-group__file:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Small screens display the workspace file selected in Explorer (not always the editable one). */
@media(max-width:1040px) {
 .app-shell.comparison-open.workspace-focus-source .chat-primary-pane:not([hidden]) { display: flex; flex: 1 1 100%; width:100%; }
 .app-shell.comparison-open.workspace-focus-source .comparison-pane { display: none; }
 .app-shell.comparison-open.workspace-focus-working .chat-primary-pane { display: none; }
 .app-shell.comparison-open.workspace-focus-working .comparison-pane:not([hidden]) { display:flex; flex:1 1 100%; }
}

/* Version 20: reversible removals are scoped to the editable workspace only. */
.comparison-hidden-toggle { flex: 0 0 auto; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 9px; background: var(--surface); color: var(--text); font: inherit;
  font-size: .75rem; cursor: pointer; white-space: nowrap; }
.comparison-hidden-toggle[hidden] { display: none !important; }
.comparison-hidden-toggle[aria-pressed="true"] { background: var(--surface-strong); }
.comparison-hidden-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.comparison-pane .message[data-workspace-hidden="true"] > .message__inner { display: none; }
.comparison-pane .message[data-workspace-hidden="true"] { padding: 4px 0; }
.comparison-pane .message__workspace-removed { display: flex; align-items: center;
  justify-content: space-between; gap: 12px; border: 1px dashed var(--border);
  border-radius: 8px; padding: 9px 12px; color: var(--muted); font-size: .78rem; }
.comparison-pane .message__workspace-removed[hidden] { display: none !important; }
.comparison-pane .message__workspace-removed button { border: 1px solid var(--border);
  background: var(--surface); border-radius: 7px; padding: 7px 10px;
  color: var(--text); font: inherit; cursor: pointer; }
@media (max-width: 520px) {
 .comparison-topbar { flex-wrap: wrap; gap: 6px; padding: 7px; }
 .comparison-hidden-toggle { font-size: .7rem; padding: 5px 6px; }
 .comparison-pane .message__workspace-removed { flex-wrap: wrap; }
}

.comparison-topbar #comparison-title { min-width: 64px; flex: 1 1 auto; }

/* v22: hierarchical, immutable excerpt documents under their source workspace file. */
.conversation-variant-node { min-width: 0; }
.conversation-variant-children { margin-inline-start: 9px; padding-inline-start: 9px;
  border-inline-start: 1px solid var(--border); display: grid; gap: 2px; }
.conversation-file-group__variant { font-size: .72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-file-group__variant::before { content: '↳'; margin-inline-end: 5px; color: var(--muted); }

/* v24: one disclosure system for chats, workspace files and nested variants. */
.conversation-file-group__header { grid-template-columns: 22px minmax(0, 1fr) auto; gap: 2px; align-items: center; }
.conversation-file-group__row { display: flex; align-items: center; gap: 2px; min-width: 0; }
.conversation-file-group__row > .conversation-file-group__file { flex: 1 1 auto; width: 0; min-width: 0; }
.conversation-file-group__disclosure, .conversation-file-group__disclosure-spacer {
  flex: 0 0 22px; width: 22px; height: 28px; border: 0; padding: 0;
  border-radius: 5px; display: grid; place-items: center; font: inherit;
}
.conversation-file-group__disclosure { cursor: pointer; background: transparent; color: var(--muted);
  font-size: 12px; line-height: 1; transition: transform 120ms ease; }
.conversation-file-group__disclosure[aria-expanded="true"] { transform: rotate(90deg); }
.conversation-file-group__disclosure:hover { background: var(--surface-strong); color: var(--text); }
.conversation-file-group__disclosure:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.conversation-file-group__children[hidden], .conversation-variant-children[hidden] { display: none !important; }
.conversation-file-group__file.is-open {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--text); box-shadow: inset 3px 0 0 var(--accent); font-weight: 650;
}
.conversation-file-group__variant.is-open { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
@media (prefers-reduced-motion: reduce) {
  .conversation-file-group__disclosure { transition: none; }
}

/* Editor groups: the existing source/editor instances remain canonical; their
   DOM nodes are moved, not cloned, when a tab is placed in another group. */
.app-shell .chat-layout:has(.editor-group) { display: flex; flex-direction: row; min-width: 0; min-height: 0; overflow: hidden; }
.editor-group { min-width: 0; min-height: 0; flex: 1 1 0; display: flex; flex-direction: column; background: var(--bg); border-inline-end: 1px solid var(--border); }
.editor-group__tabs { display: flex; flex: 0 0 40px; min-width: 0; overflow-x: auto; scrollbar-width: thin; background: var(--surface); border-bottom: 1px solid var(--border); }
.editor-tab { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 10px; max-width: min(290px, 75vw); min-height: 39px; padding: 0 9px 0 13px; border: 0; border-inline-end: 1px solid var(--border); background: transparent; color: var(--muted); cursor: grab; font-size: .77rem; }
.editor-tab__menu-button { flex: 0 0 27px; height: 39px; margin-inline-end: 3px; border: 0; background: var(--surface); color: var(--muted); cursor: pointer; border-radius: 5px; }
.editor-tab__menu-button:hover, .editor-tab__menu-button:focus-visible { color: var(--text); background: var(--surface-strong); outline: 2px solid var(--accent); outline-offset: -2px; }
.editor-tab[aria-selected="true"] { background: var(--bg); color: var(--text); box-shadow: inset 0 2px var(--accent); }
.editor-tab > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-tab__close { width: 22px; height: 24px; display: grid; place-items: center; border-radius: 5px; font-size: 18px; cursor: pointer; }
.editor-tab__close:hover { background: var(--surface-strong); }
.editor-tab:focus-visible, .editor-group__divider:focus-visible, .editor-tab-menu button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.editor-group__breadcrumb { flex: 0 0 30px; min-width: 0; padding: 7px 12px; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--border); direction: ltr; text-align: start; }
.editor-group__body { flex: 1 1 auto; min-width: 0; min-height: 0; position: relative; display: flex; flex-direction: column; }
.editor-group__empty { margin: auto; color: var(--muted); font-size: .82rem; padding: 16px; text-align: center; }
.app-shell .editor-group__body > .chat-primary-pane, .app-shell.comparison-open .editor-group__body > .chat-primary-pane,
.app-shell .editor-group__body > .comparison-pane, .app-shell.comparison-open .editor-group__body > .comparison-pane,
.app-shell.source-closed .editor-group__body > .comparison-pane { display: flex; width: 100%; flex: 1 1 auto; height: 100%; min-height: 0; }
.app-shell .editor-group__body > .editor-prompt-pane { display: flex; min-height: 0; height: 100%; flex-direction: column; width: 100%; }
.app-shell .editor-prompt-pane > .saved-requests-wrap, .app-shell .editor-prompt-pane > .saved-requests-wrap.is-collapsed { flex: 1 1 auto; height: auto; max-height: none; display: flex; }
.app-shell .editor-group__body .saved-requests-divider { display: none !important; }
.editor-group__divider { flex: 0 0 7px; border-inline: 1px solid var(--border); background: var(--surface); cursor: col-resize; touch-action: none; }
.editor-group--drop { outline: 3px solid var(--accent); outline-offset: -3px; }
.editor-tab-menu { position: fixed; z-index: 100; min-width: 190px; max-width: calc(100vw - 8px); padding: 5px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); box-shadow: 0 8px 24px #0003; }
.editor-tab-menu button { display: block; width: 100%; min-height: 38px; border: 0; border-radius: 5px; padding: 6px 10px; text-align: start; color: var(--text); background: transparent; cursor: pointer; }
.editor-tab-menu button:hover { background: var(--surface-strong); }
.editor-readonly { flex: 1; min-height: 0; overflow: auto; padding: 12px; }
.editor-readonly article { padding: 12px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; white-space: pre-wrap; }
.editor-readonly small { display: block; margin-bottom: 8px; color: var(--muted); }
@media (max-width: 1040px) {
 .app-shell .chat-layout:has(.editor-group) { overflow-x: auto; scroll-snap-type: x proximity; }
 .editor-group { flex: 0 0 100% !important; width: 100%; scroll-snap-align: start; }
 .editor-group__divider { display: none; }
 .app-shell.comparison-open.workspace-focus-source .editor-group__body > .comparison-pane,
 .app-shell.comparison-open.workspace-focus-working .editor-group__body > .chat-primary-pane { display: flex; }
}
@media (max-width: 520px) { .editor-group__tabs { flex-basis: 44px; } .editor-tab { min-height: 43px; } }
@media (prefers-reduced-motion: reduce) { .app-shell .chat-layout:has(.editor-group) { scroll-behavior: auto; } }
