/* ChatG — rendered Markdown, code blocks and message layout (chat app, tool widget, share view). Needs tokens.css. */
:root { --cg-fs: 16px; --cg-code-bg: #0F1118; --cg-code-head: #171A24; --cg-code-text: #E4E7F0; }
:root[data-cg-font="s"] { --cg-fs: 15px; }
:root[data-cg-font="l"] { --cg-fs: 17.5px; }
[data-theme="dark"] { --cg-code-bg: #0A0B10; --cg-code-head: #12141C; }

.cg-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- markdown ---------- */
.cg-md { font-size: var(--cg-fs); line-height: 1.72; color: var(--text); overflow-wrap: anywhere; min-width: 0; }
.cg-md > :first-child { margin-top: 0; }
.cg-md > :last-child { margin-bottom: 0; }
.cg-md p, .cg-md ul, .cg-md ol, .cg-md blockquote, .cg-md .cg-table, .cg-md .cg-code { margin: 0 0 .95em; }
.cg-md h1, .cg-md h2, .cg-md h3, .cg-md h4, .cg-md h5, .cg-md h6 { font-weight: 650; line-height: 1.3; letter-spacing: -.012em; margin: 1.5em 0 .55em; color: var(--text); }
.cg-md h1 { font-size: 1.5em; }
.cg-md h2 { font-size: 1.3em; }
.cg-md h3 { font-size: 1.14em; }
.cg-md h4, .cg-md h5, .cg-md h6 { font-size: 1em; }
.cg-md ul, .cg-md ol { padding-inline-start: 1.5em; }
.cg-md li { margin: .3em 0; }
.cg-md li > p { margin: .3em 0; }
.cg-md li > ul, .cg-md li > ol { margin: .25em 0; }
.cg-md li::marker { color: var(--muted); }
.cg-md ol > li::marker { font-variant-numeric: tabular-nums; }
.cg-md strong { font-weight: 650; }
.cg-md a { color: var(--accent-ink); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent-ink) 35%, transparent); text-underline-offset: 2px; }
.cg-md a:hover { text-decoration-color: currentColor; }
.cg-md hr { border: 0; height: 1px; background: var(--border); margin: 1.6em 0; }
.cg-md blockquote { padding: .1em 0; padding-inline-start: 1em; border-inline-start: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); color: var(--text-soft); }
.cg-md :not(pre) > code { font-family: var(--font-mono); font-size: .875em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .08em .38em; }
.cg-md input[type="checkbox"] { margin-inline-end: .45em; vertical-align: -1px; accent-color: var(--accent); }
.cg-md li:has(> input[type="checkbox"]) { list-style: none; margin-inline-start: -1.3em; }
.cg-md-raw { white-space: pre-wrap; }

/* tables */
.cg-table { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; -webkit-overflow-scrolling: touch; }
.cg-md table { border-collapse: collapse; width: 100%; font-size: .93em; line-height: 1.5; }
.cg-md th, .cg-md td { padding: 9px 14px; text-align: start; vertical-align: top; border-bottom: 1px solid var(--border); }
.cg-md th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; }
.cg-md tr:last-child td { border-bottom: 0; }
.cg-md td + td, .cg-md th + th { border-inline-start: 1px solid var(--border); }

/* code blocks */
.cg-code { background: var(--cg-code-bg); border-radius: 14px; overflow: hidden; border: 1px solid rgba(255, 255, 255, .06); direction: ltr; text-align: left; }
[data-theme="dark"] .cg-code { border-color: var(--border-strong); }
.cg-code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 6px 5px 14px; background: var(--cg-code-head); color: #9AA0B4; font: 500 12px/1.4 var(--font-mono); }
.cg-code-lang { text-transform: lowercase; }
.cg-code-copy { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: #B7BCCD; font: 500 12px var(--font); cursor: pointer; }
.cg-code-copy:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.cg-code-copy.is-done { color: #3DD68C; }
.cg-code-copy:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.cg-code pre { margin: 0; padding: 14px 16px 16px; overflow-x: auto; font: 13.5px/1.65 var(--font-mono); color: var(--cg-code-text); tab-size: 4; -webkit-overflow-scrolling: touch; }
.cg-code pre code { font: inherit; background: none; border: 0; padding: 0; white-space: pre; }

/* highlight.js tokens (dark code surface in both themes) */
.hljs-comment, .hljs-quote { color: #7C849A; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag, .hljs-section, .hljs-name { color: #A9A1FF; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: #7EE2B8; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-link { color: #FFB38A; }
.hljs-title, .hljs-title.function_, .hljs-selector-id { color: #6FD3F7; }
.hljs-title.class_, .hljs-type, .hljs-built_in, .hljs-class .hljs-title { color: #FFD580; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-selector-class, .hljs-property { color: #F59FC4; }
.hljs-params { color: #D6DAE6; }
.hljs-meta, .hljs-meta .hljs-keyword { color: #8FA3FF; }
.hljs-deletion { color: #FF8A8F; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------- messages (shared by chat + share view) ---------- */
.cg-thread { display: flex; flex-direction: column; gap: 30px; }
.cg-msg { position: relative; }
.cg-msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.cg-bubble { max-width: min(85%, 640px); padding: 10px 17px; border-radius: 22px; background: var(--surface-2); color: var(--text); font-size: var(--cg-fs); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
[data-theme="dark"] .cg-bubble { background: #20222D; }
.cg-msg-ai { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; align-items: start; }
.cg-msg-ai:not(:has(.cg-avatar)) { grid-template-columns: minmax(0, 1fr); }
.cg-avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-top: 1px; }
.cg-msg-body { min-width: 0; }
.cg-share-thread { max-width: 760px; margin: 0 auto; }
