/* Source reading uses the same surfaces, type and controls as the conversation. */
.source-viewer-modal {
  width: min(1280px, calc(100vw - 40px)); height: min(92dvh, 1000px); max-width: none; max-height: calc(100dvh - 32px);
  margin: auto; padding: 0; color: var(--app-text); background: var(--app-bg);
  border: 1px solid var(--app-line); border-radius: 12px; overflow: hidden; font-family: var(--app-sans);
}
.source-viewer-modal[open] { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; }
.source-viewer-modal::backdrop { background: #0009; }
.source-viewer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 18px 22px; }
.source-viewer-header-copy { min-width: 0; flex: 1; }
#source-viewer-citation-select { margin-top: 10px; max-width: 100%; width: 100%; text-overflow: ellipsis; }
#source-viewer-close { flex: none; }
.source-viewer-eyebrow { color: var(--app-muted); font-size: .7rem; margin-bottom: 5px; }
.source-viewer-header h2 { margin: 0; color: var(--app-text); font-size: 1.05rem; font-weight: 550; line-height: 1.4; overflow-wrap: anywhere; }
.source-viewer-subtitle { margin: 4px 0 0; color: var(--app-muted); font-size: .8rem; }
.source-viewer-subtitle:empty { display: none; }
.source-viewer-modal button, .source-viewer-modal select, .source-viewer-modal input, .source-viewer-actions a {
  width: auto; min-width: 0; min-height: 34px; padding: 7px 10px; border: 1px solid var(--app-line); border-radius: var(--app-control-radius);
  background: transparent; box-shadow: none; transform: none; color: var(--app-text); font: 400 .8rem/1.4 var(--app-sans); text-decoration: none;
}
.source-viewer-modal button:hover, .source-viewer-actions a:hover { background: var(--app-hover); box-shadow: none; transform: none; }
.source-viewer-modal button:disabled { opacity: .4; cursor: default; }
.source-viewer-modal :where(button,input,select,a,[tabindex]):focus-visible { outline: 2px solid var(--app-focus); outline-offset: 2px; }
.source-viewer-modal select { background: var(--app-field); }
.source-viewer-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 18px; padding: 10px 22px; border-block: 1px solid var(--app-line); background: var(--app-sidebar); }
.source-viewer-page-form, .source-viewer-zoom-controls, .source-viewer-actions { display: flex; align-items: center; gap: 6px; }
.source-viewer-page-form { color: var(--app-muted); font-size: .78rem; }
#source-viewer-page-input { width: 58px; text-align: center; appearance: textfield; padding: 6px; }
#source-viewer-page-input::-webkit-inner-spin-button { appearance: none; }
.source-viewer-actions { margin-left: auto; }
.source-viewer-body { min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.source-viewer-frame { position: relative; min-height: 0; min-width: 0; overflow: auto; padding: 16px; background: var(--app-sidebar); overscroll-behavior: contain; }
.source-viewer-image { display: block; margin: 0 auto; max-width: none; max-height: none; object-fit: contain; }
.source-viewer-embed { display: block; width: 100%; height: 100%; border: 0; background: white; }
.source-viewer-loading, .source-viewer-empty { padding: 24px; color: var(--app-muted); font-size: .9rem; }
.source-viewer-loading { position: sticky; top: 0; z-index: 1; background: var(--app-panel); border-radius: 8px; }
.source-viewer-stage-copy { width: 100%; max-width: 68ch; box-sizing: border-box; margin: 0 auto; padding: 16px 6px; font-size: 1rem; line-height: 1.8; overflow-wrap: anywhere; }
.source-content-text, .dialogue-line { white-space: pre-wrap; }
.source-content-heading, .dialogue-speaker { margin: 0 0 8px; font-size: .85rem; line-height: 1.5; font-weight: 550; }
.source-content-note { color: var(--app-muted); font-size: .8rem; line-height: 1.6; margin: 0 0 12px; }
.source-content-metadata { display: flex; flex-wrap: wrap; gap: 12px 28px; margin: 0 0 24px; font-size: .8rem; }
.source-content-metadata dt { color: var(--app-muted); }
.source-content-metadata dd { margin: 0; }
.source-content-details { margin-top: 24px; font-size: .8rem; color: var(--app-muted); }
.source-content-details summary { cursor: pointer; padding-block: 8px; }
.dialogue-transcript { margin-block: 16px; }
.dialogue-turn { padding: 18px 16px; border-left: 2px solid var(--app-line); }
.dialogue-turn + .dialogue-turn { margin-top: 8px; }
.dialogue-turn[data-cited="true"] { border-color: var(--app-accent); background: color-mix(in srgb, var(--app-accent) 7%, transparent); }
.dialogue-turn p:last-child { margin-bottom: 0; }
.dialogue-line { margin: 0; }
.dialogue-cited-label { margin-left: 12px; color: var(--app-accent); font-size: .72rem; font-weight: 400; }
.dialogue-navigation h3 { font-size: .85rem; font-weight: 550; }
.dialogue-choices { list-style: none; margin: 0; padding: 0; }
.dialogue-choices li + li { border-top: 1px solid var(--app-line); }
.dialogue-choices button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 12px 16px; text-align: left; border: 0; font-size: .9rem; }
.dialogue-choices .source-content-note { margin: 6px 0 0; }
.source-viewer-modal[data-content-type="conversation"] { height: min(86dvh, 900px); }
.source-viewer-modal[data-reader-mode="text"][data-content-type="conversation"] .source-viewer-frame { max-height: none; }
.source-viewer-modal[data-document-kind="blog"] { width: min(940px, calc(100vw - 40px)); }
.source-viewer-modal[data-document-kind="blog"] .source-viewer-frame { padding: 0; overflow: hidden; }
.source-viewer-modal[data-document-kind="blog"] .source-viewer-embed { background: var(--app-bg); }
.source-viewer-status { margin: 0; padding: 9px 22px; color: var(--app-muted); font-size: .76rem; border-top: 1px solid var(--app-line); }
.source-viewer-status:empty { display: none; }
.source-viewer-modal[data-reader-mode="text"] { width: min(800px, calc(100vw - 40px)); height: fit-content; grid-template-rows: auto minmax(0, 1fr) auto; }
.source-viewer-modal[data-reader-mode="text"] .source-viewer-toolbar { display: none; }
.source-viewer-modal[data-reader-mode="text"][data-has-original="true"] { grid-template-rows: auto auto minmax(0, 1fr) auto; }
.source-viewer-modal[data-reader-mode="text"][data-has-original="true"] .source-viewer-toolbar { display: flex; }
body.source-viewer-open { overflow: hidden; }
.source-viewer-modal[data-reader-mode="text"][data-content-type="conversation"] { grid-template-rows: auto auto minmax(0, 1fr) auto; height: min(86dvh, 900px); }
.source-viewer-modal[data-content-type="conversation"] .source-viewer-toolbar { display: flex; }
.conversation-view-switch { display: flex; flex-wrap: wrap; gap: 6px; }
.conversation-view-switch button[aria-pressed="true"] { border-color: var(--app-accent); background: var(--app-hover); }
.source-viewer-modal[data-conversation-tree="true"] { width: min(1100px, calc(100vw - 40px)); }
.source-viewer-modal[data-conversation-tree="true"] .source-viewer-stage-copy { max-width: none; }
.conversation-tree-tools { position: sticky; top: -16px; z-index: 1; display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; padding: 10px 0; background: var(--app-bg); box-shadow: 0 1px var(--app-line); }
.conversation-tree-tools .conversation-tree-search { flex: 1 1 260px; min-width: 0; font-size: 16px; }
.conversation-tree-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.conversation-tree-rows { list-style: none; padding: 0; margin: 0; }
.conversation-tree-row { display: grid; grid-template-columns: 36px minmax(0, 1fr); margin-left: calc(var(--tree-depth) * 18px); border-left: 2px solid var(--app-line); border-bottom: 1px solid var(--app-line); }
.conversation-tree-row[data-route="true"] { border-left-color: var(--app-accent); background: color-mix(in srgb, var(--app-accent) 5%, transparent); }
.conversation-tree-row[data-tree-focus="true"] { outline: 1px solid var(--app-accent); outline-offset: -1px; }
.source-viewer-modal .conversation-tree-toggle { align-self: start; border: 0; padding: 8px 4px; font-size: 15px; }
.source-viewer-modal .conversation-tree-line { width: 100%; border: 0; border-radius: 0; padding: 12px; text-align: left; }
.conversation-tree-line > span { display: block; }
.conversation-tree-heading { color: var(--app-muted); font-size: .78rem; margin-bottom: 5px; }
.conversation-tree-text { font-size: .95rem; line-height: 1.65; display: -webkit-box !important; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.conversation-tree-line .source-content-note { margin: 6px 0 0; }
.source-viewer-modal [hidden] { display: none !important; }
.source-viewer-modal[data-reader-mode="text"] .source-viewer-frame { max-height: calc(var(--app-viewport-height, 100dvh) * .66); background: var(--app-bg); }
@media (max-width: 720px) {
  .source-viewer-modal { width: calc(100vw - 16px); height: calc(var(--app-viewport-height, 100dvh) - 16px); max-height: calc(var(--app-viewport-height, 100dvh) - 16px); inset-block: 8px auto; margin-block: 0; border-radius: 10px; }
  .source-viewer-header { padding: 14px; gap: 12px; }
  .source-viewer-header h2 { font-size: .95rem; }
  #source-viewer-page-input, #source-viewer-citation-select { font-size: 16px; }
  .source-viewer-toolbar { padding: 8px 12px; gap: 8px 10px; }
  .source-viewer-modal button, .source-viewer-modal select, .source-viewer-modal input, .source-viewer-actions a { padding: 6px 8px; min-height: 44px; min-width: 44px; font-size: .75rem; }
  .source-viewer-page-form { flex-basis: 100%; }
  .source-viewer-actions { margin-left: auto; }
  .source-viewer-modal[data-reader-mode="text"] { width: calc(100vw - 16px); }
  .source-viewer-modal[data-content-type="conversation"], .source-viewer-modal[data-document-kind="blog"] { width: calc(100vw - 16px); height: calc(var(--app-viewport-height, 100dvh) - 16px); }
  .source-viewer-modal[data-content-type="conversation"] .source-viewer-frame { padding: 10px; }
}
/* Ebooks share one scroll area and use named chapters instead of file-page controls. */
.source-viewer-modal[data-document-kind="ebook"] { width: min(940px, calc(100vw - 40px)); }
.source-viewer-modal[data-document-kind="ebook"] .source-viewer-frame { padding: 0; overflow: hidden; background: var(--app-bg); }
.source-viewer-modal[data-document-kind="ebook"] .source-viewer-embed { background: var(--app-bg); }
.source-viewer-modal[data-document-kind="ebook"] .source-viewer-page-form { flex: 1; min-width: 0; max-width: 620px; }
.source-viewer-modal[data-document-kind="ebook"] .source-viewer-page-form > :is(label, input, #source-viewer-page-count) { display: none; }
#source-viewer-chapter { flex: 1; min-width: 0; text-overflow: ellipsis; }
@media (max-width: 720px) {
  .source-viewer-modal[data-document-kind="ebook"] { width: calc(100vw - 16px); }
  .source-viewer-modal[data-document-kind="ebook"] .source-viewer-toolbar { gap: 8px; }
  .source-viewer-modal[data-document-kind="ebook"] .source-viewer-page-form { flex-basis: 0; }
  .source-viewer-modal[data-document-kind="ebook"] .source-viewer-toolbar a { font-size: 0; text-align: center; }
  .source-viewer-modal[data-document-kind="ebook"] .source-viewer-toolbar a::after { content: '↗'; font-size: 18px; }
  #source-viewer-chapter { font-size: 16px; }
}
/* Keep document reading on the same surface regardless of its original container. */
.source-viewer-modal:is([data-document-kind="docx"],[data-document-kind="html"],[data-document-kind="mhtml"],[data-document-kind="doc"],[data-document-kind="text"],[data-document-kind="native"]) { width: min(940px, calc(100vw - 40px)); }
.source-viewer-modal:is([data-document-kind="docx"],[data-document-kind="html"],[data-document-kind="mhtml"],[data-document-kind="doc"],[data-document-kind="text"],[data-document-kind="native"]) .source-viewer-frame { padding: 0; overflow: hidden; }
.source-viewer-title-details > summary { display: block; list-style: none; }
.source-viewer-title-details > summary::-webkit-details-marker { display: none; }
.source-viewer-title-details.long-title > summary { cursor: pointer; }
.source-viewer-title-details.long-title:not([open]) h2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.source-viewer-title-details.long-title > summary::after { content: 'Full title ▾'; font-size: .72rem; color: var(--app-muted); }
.source-viewer-title-details.long-title[open] > summary::after { content: 'Collapse title ▴'; }
.source-viewer-image { cursor: grab; touch-action: none; user-select: none; }
.source-viewer-image:active { cursor: grabbing; }
.source-viewer-image-hint { margin: 0 0 12px; color: var(--app-muted); font-size: .75rem; text-align: center; }
@media (max-width: 720px) {
  .source-viewer-modal .source-viewer-frame { padding: 8px; }
  .source-viewer-modal:is([data-document-kind="docx"],[data-document-kind="html"],[data-document-kind="mhtml"],[data-document-kind="doc"],[data-document-kind="text"],[data-document-kind="native"]) { width: calc(100vw - 16px); }
  #source-viewer-return { order: 3; flex-basis: 100%; }
  .source-viewer-modal[data-conversation-tree="true"] { width: calc(100vw - 16px); }
  .source-viewer-modal[data-reader-mode="text"][data-content-type="conversation"] { height: calc(var(--app-viewport-height, 100dvh) - 16px); }
  .conversation-tree-row { grid-template-columns: 44px minmax(0, 1fr); margin-left: calc(min(var(--tree-depth), 4) * 8px); }
  .conversation-tree-tools { top: -10px; }
  .source-viewer-modal .conversation-tree-line { padding: 10px 8px; }
}
