/* Timeline, messages, Markdown and the composer. */

.timeline-wrap { flex: 1; min-height: 0; position: relative; }
.timeline { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; }
.timeline-inner { max-width: 980px; margin: 0 auto; padding: 18px 0 10px; min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.timeline-loading { display: grid; place-items: center; padding: 12px; color: var(--ink-3); }
.timeline-loading.tall { flex: 1; }
.timeline-start { text-align: center; font: 600 11px var(--f-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); padding: 20px 0 8px; }
.day-sep, .unread-sep { display: flex; align-items: center; gap: 12px; margin: 18px 22px 10px; }
.day-sep::before, .day-sep::after, .unread-sep::before, .unread-sep::after { content: ''; flex: 1; height: 1px; background: var(--line-2); }
.day-sep span { font: 600 11px var(--f-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 4px 10px; border: 1px solid var(--line-2); border-radius: 99px; background: var(--paper); }
.unread-sep::before, .unread-sep::after { background: var(--accent); opacity: .5; }
.unread-sep span { font: 700 11px var(--f-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.to-bottom { position: absolute; right: 20px; bottom: 14px; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow-2); color: var(--ink); animation: pop .2s var(--ease); }

/* ---- message ---- */
.msg { position: relative; display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 0 10px; padding: 2px 22px; margin-top: 10px; animation: msg-in .32s var(--ease); }
.msg.grouped { margin-top: 3px; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg.mine { grid-template-columns: minmax(0, 1fr); }
.msg-gutter { display: flex; align-items: flex-start; padding-top: 22px; }
.msg.grouped .msg-gutter { padding-top: 0; }
.msg-col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.msg.mine .msg-col { align-items: flex-end; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin: 0 0 4px 4px; }
.msg-name { font-weight: 700; font-size: 13.5px; }
.msg-head time { font: 500 11px var(--f-mono); color: var(--ink-3); }
.from-bot .msg-name { font: 700 12.5px var(--f-mono); letter-spacing: .01em; color: var(--machine); }

.msg-body { position: relative; max-width: min(640px, 100%); padding: 9px 14px 8px; border-radius: 4px 18px 18px 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); overflow-wrap: anywhere; }
.msg.grouped .msg-body { border-radius: 18px; }
.msg.mine .msg-body { background: var(--mine); color: var(--mine-ink); border-color: transparent; border-radius: 18px 4px 18px 18px; max-width: min(600px, 86%); }
.msg.mine.grouped .msg-body { border-radius: 18px; }
/* Bots get a wider machined surface: a teal edge and room for blocks, like an AI answer. */
.msg.from-bot .msg-body { max-width: min(760px, 100%); width: fit-content; min-width: min(280px, 100%); border-color: var(--machine-line);
  background: linear-gradient(180deg, color-mix(in srgb, var(--machine) 5%, var(--surface)), var(--surface) 46px); box-shadow: inset 3px 0 0 var(--machine), var(--shadow-1); padding-left: 17px; }
.msg.pending .msg-body { opacity: .7; }
.msg.flash .msg-body { animation: flash 1.4s var(--ease); }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } }
.msg-stamp { float: right; display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 -2px 12px; font: 500 10.5px var(--f-mono); color: var(--ink-3); user-select: none; line-height: 1; position: relative; top: 3px; }
.msg-stamp em { font-style: normal; }
.msg.mine .msg-stamp { color: var(--mine-3); }
.ticks { display: inline-flex; }
.ticks .tick2 { margin-left: -8px; }
.ticks.read { color: var(--machine); }
.msg.mine .ticks.read { color: color-mix(in srgb, var(--machine) 80%, var(--mine-ink)); }
.msg-deleted { margin: 0; font-style: italic; color: var(--ink-3); }
.msg.big-emoji .msg-body { background: none; border: 0; box-shadow: none; padding: 0; }
.emoji-big { margin: 0; font-size: 46px; line-height: 1.1; }
.msg.big-emoji .msg-stamp { float: none; }

.msg-system { text-align: center; margin: 12px 22px; font-size: 13px; color: var(--ink-3); }
.msg-system b { color: var(--ink-2); font-weight: 600; }

.msg-quote { display: grid; gap: 1px; width: 100%; text-align: left; margin: 2px 0 8px; padding: 6px 10px; border-radius: 10px; border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 9%, transparent); font-size: 13px; }
.msg-quote strong { color: var(--c); font-size: 12.5px; }
.msg-quote span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.msg.mine .msg-quote { background: rgb(127 127 127 / .16); }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 8px; border-radius: 13px; background: var(--surface); border: 1px solid var(--line-2); font-size: 14px; transition: transform .1s; }
.reaction b { font: 600 11px var(--f-mono); color: var(--ink-2); }
.reaction.mine { border-color: var(--accent); background: var(--accent-soft); }
.reaction:active { transform: scale(.94); }

.msg-tools { position: absolute; top: -16px; right: 26px; display: none; gap: 2px; padding: 3px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow-2); z-index: 4; }
.msg.mine .msg-tools { right: auto; left: 26px; }
.msg:hover .msg-tools, .msg-tools:focus-within { display: flex; }
@media (hover: none) { .msg:hover .msg-tools { display: none; } }
.msg-tools-react { position: relative; }
.react-pop { position: absolute; bottom: 36px; right: -6px; display: flex; gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow-2); animation: pop .16s var(--ease); }
.react-pop button, .msg-menu-reacts button { width: 36px; height: 36px; border-radius: 10px; font-size: 20px; transition: transform .12s; }
.react-pop button:hover, .msg-menu-reacts button:hover { background: var(--surface-3); transform: scale(1.15); }

.msg-menu-backdrop { position: fixed; inset: 0; z-index: 700; background: rgb(18 16 12 / .25); display: grid; place-items: center; animation: fade .15s; }
.msg-menu { width: min(300px, calc(100vw - 32px)); background: var(--surface); border-radius: 18px; border: 1px solid var(--line-2); box-shadow: var(--shadow-2); padding: 8px; display: grid; gap: 2px; animation: pop .2s var(--ease); }
.msg-menu-reacts { display: flex; justify-content: space-between; padding: 2px 2px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.msg-menu > button { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 550; text-align: left; }
.msg-menu > button:hover { background: var(--surface-3); }
@media (max-width: 860px) {
  .msg-menu-backdrop { place-items: end stretch; }
  .msg-menu { width: 100%; border-radius: 22px 22px 0 0; padding: 10px 10px calc(14px + env(safe-area-inset-bottom)); animation: sheet .25s var(--ease); }
}

.typing { display: flex; align-items: center; gap: 10px; margin: 12px 22px 2px 70px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.pistons { display: inline-flex; align-items: flex-end; gap: 3px; height: 14px; }
.pistons i { width: 4px; height: 100%; border-radius: 2px; background: var(--machine); transform-origin: bottom; animation: piston .9s var(--ease) infinite; }
.pistons i:nth-child(2) { animation-delay: .15s; background: var(--accent); }
.pistons i:nth-child(3) { animation-delay: .3s; }

/* ---- Markdown ---- */
.md { font-size: 15px; line-height: 1.55; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .55em; }
.md .md-h { font-family: var(--f-display); letter-spacing: -.02em; line-height: 1.2; margin: .8em 0 .35em; }
.md h1.md-h { font-size: 1.45em; font-weight: 800; }
.md h2.md-h { font-size: 1.25em; font-weight: 750; }
.md h3.md-h { font-size: 1.08em; font-weight: 700; }
.md h4.md-h, .md h5.md-h, .md h6.md-h { font-size: 1em; font-weight: 700; }
.md strong { font-weight: 700; }
.md a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.msg.mine .md a { color: inherit; }
.md code { font: 500 .86em var(--f-mono); padding: .12em .38em; border-radius: 6px; background: var(--surface-3); border: 1px solid var(--line); }
.msg.mine .md code { background: rgb(127 127 127 / .2); border-color: transparent; }
.md ul, .md ol { margin: .3em 0 .6em; padding-left: 1.35em; }
.md li { margin: .15em 0; }
.md li::marker { color: var(--ink-3); }
.md ul.md-tasks { list-style: none; padding-left: .2em; }
.md-task { display: flex; gap: 8px; align-items: baseline; }
.md-check { flex: none; width: 15px; height: 15px; border-radius: 5px; border: 1.5px solid var(--ink-3); transform: translateY(2px); }
.md-task.done .md-check { background: var(--ok); border-color: var(--ok); box-shadow: inset 0 0 0 2.5px var(--surface); }
.md-task.done > span:last-child { color: var(--ink-3); text-decoration: line-through; }
.md blockquote { margin: .4em 0 .7em; padding: .2em 0 .2em 12px; border-left: 3px solid var(--accent); color: var(--ink-2); }
.md hr { border: 0; height: 1px; background: var(--line-2); margin: .9em 0; }
.md-img { display: block; max-height: 360px; border-radius: 10px; margin: .3em 0; border: 1px solid var(--line); }
.md-mention { font-weight: 650; color: var(--machine); background: var(--machine-soft); padding: 0 4px; border-radius: 5px; cursor: pointer; }
.md-mention.is-me { color: var(--accent); background: var(--accent-soft); }
.msg.mine .md-mention { color: inherit; background: rgb(127 127 127 / .22); }
.md-spoiler { background: var(--ink-2); color: transparent; border-radius: 4px; cursor: pointer; transition: all .25s; user-select: none; }
.md-spoiler.revealed { background: var(--surface-3); color: inherit; user-select: auto; }
.md-code { margin: .5em 0 .7em; border-radius: 12px; overflow: hidden; background: #171511; color: #ece5d6; border: 1px solid rgb(255 255 255 / .06); }
.md-code-head { display: flex; justify-content: space-between; align-items: center; padding: 5px 6px 5px 12px; font: 600 11px var(--f-mono); color: #9b9483; border-bottom: 1px solid rgb(255 255 255 / .07); }
.md-copy { font: 600 11px var(--f-mono); color: #d6cfbf; padding: 4px 8px; border-radius: 6px; }
.md-copy:hover { background: rgb(255 255 255 / .08); }
.md-code pre { margin: 0; padding: 12px 14px; overflow-x: auto; font: 500 13px/1.55 var(--f-mono); }
.md-code code { background: none; border: 0; padding: 0; font: inherit; color: inherit; }
.md-table { overflow-x: auto; margin: .4em 0 .7em; border: 1px solid var(--line-2); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.md th { font: 700 11.5px var(--f-mono); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); background: var(--surface-2); }
.md tr:last-child td { border-bottom: 0; }
.md td { font-variant-numeric: tabular-nums; }
/* Streaming answer: a block cursor rides the end of the text. */
.md.streaming > :last-child::after, .md.streaming:empty::after { content: ''; display: inline-block; width: .5em; height: 1.05em; margin-left: 3px; vertical-align: -.18em; background: var(--machine); border-radius: 2px; animation: caret 1s steps(2, start) infinite; }
@keyframes caret { to { visibility: hidden; } }

/* ---- composer ---- */
.composer-wrap { position: relative; max-width: 980px; width: 100%; margin: 0 auto; padding: 6px 18px calc(10px + env(safe-area-inset-bottom)); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; mask-image: linear-gradient(90deg, #000 92%, transparent); }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--machine-line); background: color-mix(in srgb, var(--machine) 6%, var(--surface)); color: var(--machine-2); font-weight: 600; font-size: 13.5px; transition: background .15s, transform .1s; animation: rise .3s var(--ease) both; }
.chip:nth-child(2) { animation-delay: .04s; } .chip:nth-child(3) { animation-delay: .08s; } .chip:nth-child(4) { animation-delay: .12s; } .chip:nth-child(5) { animation-delay: .16s; }
.chip:hover:not(:disabled) { background: var(--machine); color: var(--surface); border-color: var(--machine); }
.chip:active { transform: scale(.97); }
.chip.on, .chip:disabled { opacity: .7; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 6px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow-2); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--line-2)); }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent; padding: 9px 4px; line-height: 1.45; max-height: 40vh; font-size: 15.5px; }
.send { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-3); transition: background .2s, color .2s, transform .15s; }
.composer.has-text .send { background: var(--accent); color: var(--accent-ink); }
.composer.has-text .send:hover { transform: scale(1.06); }
.composer-plus { position: relative; }
.plus-menu { position: absolute; bottom: 48px; left: 0; min-width: 190px; padding: 6px; display: grid; gap: 2px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow-2); animation: pop .16s var(--ease); z-index: 10; }
.plus-menu button { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; font-weight: 600; text-align: left; }
.plus-menu button:hover { background: var(--surface-3); }
.composer-context { display: flex; align-items: center; gap: 10px; margin: 0 8px -12px; padding: 8px 10px 20px 14px; border-radius: 16px 16px 0 0; background: var(--surface-2); border: 1px solid var(--line-2); border-bottom: 0; font-size: 13px; color: var(--ink-2); animation: rise .2s var(--ease); }
.composer-context.editing { color: var(--accent); }
.composer-context > div { flex: 1; min-width: 0; display: grid; }
.composer-context strong { color: var(--ink); font-size: 13px; }
.composer-context span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-hint { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px 0; font-size: 11.5px; color: var(--ink-3); }
.composer-hint kbd { font-size: 10px; padding: 0 4px; }
@media (max-width: 860px), (pointer: coarse) { .composer-hint { display: none; } .composer-wrap { padding: 4px 10px calc(8px + env(safe-area-inset-bottom)); } .msg { padding: 2px 12px; } .msg-tools { right: 12px; } }

.palette { position: absolute; left: 18px; right: 18px; bottom: calc(100% - 4px); max-height: 300px; overflow-y: auto; padding: 6px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow-2); animation: pop .16s var(--ease); z-index: 20; }
.palette-head { font: 700 10.5px var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); padding: 6px 10px 6px; }
.palette-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; text-align: left; }
.palette-item.active { background: var(--surface-3); }
.palette-title { font: 650 14px var(--f-mono); color: var(--ink); }
.palette-hint { flex: 1; min-width: 0; color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-bot { font: 600 11px var(--f-mono); color: var(--machine); }
