.rich-content{min-width:0;line-height:1.8;overflow-wrap:anywhere;color:var(--ink)}
.rich-content>:first-child{margin-top:0}.rich-content>:last-child{margin-bottom:0}
.rich-content p{margin:.7em 0}.rich-content h1,.rich-content h2,.rich-content h3,.rich-content h4{margin:1.15em 0 .45em;line-height:1.4;color:var(--ink)}
.rich-content h1{font-size:1.5em}.rich-content h2{font-size:1.3em}.rich-content h3{font-size:1.14em}
.rich-content ul,.rich-content ol{padding-left:1.65em;margin:.65em 0}.rich-content li{padding-left:.2em;margin:.25em 0}.rich-content li>p{margin:.2em 0}
.rich-content blockquote{margin:.8em 0;padding:.3em 1em;border-left:3px solid var(--line-strong);color:var(--muted)}
.rich-content hr{border:0;border-top:1px solid var(--line);margin:1.5em 0}.rich-content a{text-decoration:underline;text-underline-offset:3px;color:inherit}
.rich-content img{max-width:100%;height:auto;border-radius:8px}.rich-content .rich-table-scroll{overflow-x:auto;max-width:100%;margin:1em 0}
.rich-content table{width:100%;border-collapse:collapse;font-size:14px;line-height:1.6}.rich-content th,.rich-content td{padding:10px 14px;border:1px solid var(--line);text-align:left;white-space:normal}.rich-content th{background:var(--hover);font-weight:600}
.rich-content :not(pre)>code{padding:.16em .38em;border:1px solid var(--line);background:var(--hover);border-radius:5px;font:14px/1.65 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace}
/* Code is an independent dark reading surface in both workspace themes. */
.rich-code-block,.rich-preview-dialog{
 --code-bg:#16181f;--code-top:#1d2029;--code-ink:#e4e8f0;--code-muted:#8f9bad;
 --code-keyword:#c5a2ff;--code-string:#9ee6a0;--code-number:#f291cd;
 --code-title:#ffd28c;--code-tag:#70b7ff;--code-attr:#f291cd;
 --code-type:#7edee4;--code-comment:#9aa7b8;--code-meta:#ff9b8c;
 --code-hover:#2b3140;--code-rule:#ffffff0d;color-scheme:dark;
}
.rich-code-block{margin:18px 0;border:0;border-radius:18px;overflow:hidden;background:var(--code-bg);color:var(--code-ink);font-weight:400;text-align:left;box-shadow:0 8px 24px #00000014}
.rich-code-toolbar{display:flex;align-items:center;justify-content:space-between;gap:10px;min-height:52px;padding:8px 16px;background:var(--code-top);color:var(--code-ink);border-bottom:1px solid var(--code-rule);font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}
.rich-code-language{text-transform:uppercase;letter-spacing:.025em;color:var(--code-tag);font-weight:600}.rich-code-actions{display:flex;gap:4px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
.rich-code-actions button{border:0;background:transparent;color:var(--code-ink);font:12px/1.4 system-ui,sans-serif;min-height:32px;padding:6px 9px;border-radius:8px;cursor:pointer}.rich-code-actions button:hover{background:var(--code-hover)}.rich-code-actions button[aria-expanded="true"]{background:var(--code-hover);color:var(--code-type)}.rich-code-actions button:focus-visible{outline:2px solid var(--code-tag);outline-offset:2px}
.rich-content .rich-code-source{display:flex;overflow:auto;max-height:520px;padding:20px 0;tab-size:2;scroll-behavior:auto;overflow-anchor:none;overscroll-behavior:contain;scrollbar-color:#505b70 var(--code-bg)}
.rich-content .rich-code-source:focus-visible{outline:2px solid var(--code-tag);outline-offset:-3px}
.rich-content .rich-line-numbers{flex:0 0 auto;white-space:pre;text-align:right;user-select:none;min-width:48px;padding:0 12px 0 16px;color:var(--code-muted);font:14px/1.75 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace}
.rich-content .rich-code-source pre{margin:0!important;padding:0 16px!important;border:0!important;border-radius:0!important;background:transparent!important;overflow:visible!important;flex:1 0 auto;color:inherit;white-space:pre!important}
.rich-content .rich-code-source code{display:block;padding:0!important;background:transparent!important;border:0!important;font:14px/1.75 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace!important;white-space:pre!important;word-break:normal!important;overflow-wrap:normal!important;color:var(--code-ink)}
.rich-source[hidden]{display:none!important}
.rich-code-block .hljs-keyword,.rich-code-block .hljs-literal{color:var(--code-keyword)}
.rich-code-block .hljs-string,.rich-code-block .hljs-regexp,.rich-code-block .hljs-addition{color:var(--code-string)}
.rich-code-block .hljs-number{color:var(--code-number)}
.rich-code-block .hljs-attr,.rich-code-block .hljs-selector-attr,.rich-code-block .hljs-selector-pseudo{color:var(--code-attr)}
.rich-code-block .hljs-name,.rich-code-block .hljs-selector-tag{color:var(--code-tag)}
.rich-code-block .hljs-title,.rich-code-block .hljs-section{color:var(--code-title)}
.rich-code-block .hljs-built_in,.rich-code-block .hljs-type,.rich-code-block .hljs-symbol,.rich-code-block .hljs-title.class_{color:var(--code-type)}
.rich-code-block .hljs-selector-class,.rich-code-block .hljs-selector-id{color:var(--code-keyword)}
.rich-code-block .hljs-variable,.rich-code-block .hljs-template-variable{color:var(--code-type)}
.rich-code-block .hljs-attribute,.rich-code-block .hljs-property,.rich-code-block .hljs-params,.rich-code-block .hljs-tag{color:var(--code-ink)}
.rich-code-block .hljs-comment,.rich-code-block .hljs-quote{color:var(--code-comment);font-style:normal}
.rich-code-block .hljs-meta,.rich-code-block .hljs-meta .hljs-keyword{color:var(--code-meta)}
.rich-code-block .hljs-subst{color:var(--code-ink)}
.rich-code-block .hljs-deletion{color:#ff9b8c}.rich-code-block .hljs-emphasis{font-style:italic}.rich-code-block .hljs-strong{font-weight:700}
.rich-code-block .rich-code-source ::selection{background:#3f557e;color:#fff}
.rich-code-source[hidden]{display:none!important}.rich-preview{height:320px;max-height:520px;overflow:hidden;background:#fff}.rich-preview-mount{height:100%}.rich-preview[hidden]{display:none!important}.rich-preview iframe{display:block;width:100%;height:100%!important;min-height:0;border:0;background:#fff;color-scheme:light}                                                                              .rich-content .katex-display{max-width:100%;overflow-x:auto;overflow-y:hidden;padding:.4em 0;margin:1em 0}.rich-content .katex{font-size:1.13em}.rich-content .math-fallback{font-family:ui-monospace,monospace;white-space:pre-wrap}.rich-fallback{white-space:pre-wrap}
@media(max-width:600px){.rich-code-toolbar{padding:6px 8px}.rich-code-actions button{padding:4px 5px}.rich-content .rich-line-numbers{min-width:34px;padding:0 8px}.rich-preview{height:260px}.rich-content th,.rich-content td{padding:8px 10px}}
@media print{.rich-code-actions,.rich-preview{display:none}.rich-content .rich-code-source{overflow:visible}.rich-content .rich-code-source pre,.rich-content .rich-code-source code{white-space:pre-wrap!important;overflow-wrap:anywhere!important;flex-shrink:1}}
/* Keep KaTeX accessibility spans inside their formula and chat scroller. */
.rich-content .katex{position:relative}

/* Only code, formulas and tables scroll sideways, never the conversation. */
.rich-code-block,.rich-code-source,.rich-table-scroll{min-width:0;max-width:100%;box-sizing:border-box}
@media(max-width:760px){
 .rich-code-block{margin:14px 0;border-radius:14px}
 .rich-code-toolbar{flex-wrap:wrap;gap:2px 8px;padding:6px 12px}
 .rich-code-actions{min-width:0;max-width:100%}
 .rich-code-actions button{min-height:44px;padding:6px 8px}
 .rich-content .rich-table-scroll table{width:max-content;min-width:100%}
 .rich-content .rich-code-source{padding:16px 0}
 .rich-content .rich-code-source pre{padding:0 12px!important}
 .rich-content .rich-code-source code,.rich-content .rich-line-numbers{font-size:12px!important;line-height:1.8!important}
}
@media(pointer:coarse){.rich-code-actions button{min-height:44px}}
@media print{.rich-code-block{--code-bg:#fff;--code-top:#f4f4f4;--code-ink:#222;--code-muted:#555;--code-keyword:#63339a;--code-string:#236536;--code-number:#8c285c;--code-title:#74470e;--code-tag:#17508c;--code-attr:#8c285c;--code-type:#19646b;--code-comment:#555;--code-meta:#943c24;color-scheme:light;box-shadow:none}.rich-content .rich-code-source{max-height:none}}

/* Native top-layer preview keeps focus and Escape handling inside the dialog. */
dialog.rich-preview-dialog{box-sizing:border-box;width:min(1440px,calc(100vw - 32px));max-width:calc(100vw - 32px);height:calc(100vh - 48px);height:calc(100dvh - 48px);max-height:calc(100vh - 48px);max-height:calc(100dvh - 48px);margin:auto;padding:0;border:1px solid var(--line-strong,#454b57);border-radius:12px;background:var(--code-bg);color:var(--code-ink);overflow:hidden;box-shadow:0 24px 100px var(--shadow-color,#0008)}
.rich-preview-dialog[open]{display:flex;flex-direction:column}
.rich-preview-dialog::backdrop{background:var(--overlay,#0008);backdrop-filter:blur(3px)}
.rich-preview-dialog>.rich-code-toolbar{flex:0 0 auto;min-height:46px;font:14px/1.5 system-ui,sans-serif}
.rich-preview-dialog>.rich-preview-mount{flex:1 1 auto;min-height:0;height:auto;background:#fff}
.rich-preview-dialog iframe{display:block;width:100%;height:100%;border:0;background:#fff;color-scheme:light}
@media(max-width:600px){dialog.rich-preview-dialog{width:calc(100vw - 16px);max-width:calc(100vw - 16px);height:calc(100vh - 24px);height:calc(100dvh - 24px);max-height:calc(100vh - 24px);max-height:calc(100dvh - 24px);border-radius:9px}}
@media print{.rich-preview-dialog{display:none!important}}
