:root {
  --bg: #f6f4ef; --panel: #fbfaf7; --ink: #1d2321; --muted: #5f6663; --line: #e3dfd6; --field-line: #898e8a;
  --accent: #1f5c4d; --accent-ink: #f6f4ef; --accent-soft: #dfece6;
  --bubble-bot: #ffffff; --bubble-me: #1f5c4d; --bubble-me-ink: #f6f4ef;
  --danger: #b3382c; --code-bg: #efece4; --shadow: 0 1px 2px rgb(30 35 33 / .06);
  --warn: #835c0e; --warn-soft: #f4e8cc;
  --font: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "D2Coding", monospace;
  --vh: 100dvh;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a; --panel: #1b1e20; --ink: #e8e6e0; --muted: #8f9692; --line: #2b2f31; --field-line: #6b726f;
    --accent: #5fb89e; --accent-ink: #0f1a16; --accent-soft: #1f302a;
    --bubble-bot: #23272a; --bubble-me: #2d6b59; --bubble-me-ink: #f1f5f2;
    --danger: #ea7a6d; --code-bg: #101213; --shadow: none;
    --warn: #e2b766; --warn-soft: #3a3020;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
#root { height: var(--vh); }
.noscript { padding: 2rem; }

/* shell */
/* minmax(0, …): a long chat name must not widen the column past the screen. */
.app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100%; }
.side { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border-right: 1px solid var(--line); }
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app[data-route="home"] .main { display: none; }
  .app:not([data-route="home"]) .side { display: none; }
}
.topbar { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; padding-top: max(.75rem, env(safe-area-inset-top)); min-height: 3.5rem; border-bottom: 1px solid var(--line); }
.topbar h1, .topbar h2 { margin: 0; font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: .55rem; flex: 1; }
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.brand span { font-weight: 700; letter-spacing: -.02em; font-size: 1.1rem; }
.icon-btn { width: 2.4rem; height: 2.4rem; border: 0; background: transparent; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.back { display: none; }
@media (max-width: 760px) { .back { display: grid; margin-left: -.5rem; } }

/* chat list */
.chat-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: .35rem; }
.chat-item { display: flex; gap: .75rem; width: 100%; padding: .7rem .75rem; border: 0; border-radius: 14px; background: transparent; text-align: left; align-items: center; }
.chat-item:hover { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.chat-item[aria-current="true"] { background: var(--accent-soft); }
.avatar { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; font-size: 1.1rem; color: var(--accent-ink); background: var(--hue, var(--accent)); }
.avatar.sm { width: 34px; height: 34px; font-size: .95rem; }
.chat-body { flex: 1; min-width: 0; }
.chat-row { display: flex; align-items: baseline; gap: .5rem; }
.chat-name { font-weight: 620; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { color: var(--muted); font-size: .76rem; flex: none; }
.chat-preview { color: var(--muted); font-size: .87rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; min-width: 1.35rem; height: 1.35rem; padding: 0 .4rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .74rem; font-weight: 700; display: grid; place-items: center; }

/* empty / notices */
.empty { margin: auto; text-align: center; color: var(--muted); padding: 2rem; max-width: 22rem; }
.empty h3 { color: var(--ink); margin: 0 0 .4rem; font-size: 1.05rem; }
.empty p { margin: .25rem 0; }
.conn { background: #f2dfb5; color: #4a3a0c; text-align: center; font-size: .8rem; padding: .25rem; }
@media (prefers-color-scheme: dark) { .conn { background: #4a3d17; color: #f2e3b5; } }

/* conversation */
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .3rem; scroll-behavior: auto; }
.messages > :first-child { margin-top: auto; }
.day { align-self: center; color: var(--muted); font-size: .76rem; margin: .8rem 0 .4rem; padding: .1rem .7rem; background: color-mix(in srgb, var(--line) 60%, transparent); border-radius: 999px; }
.msg { display: flex; gap: .5rem; max-width: min(46rem, 100%); align-items: flex-end; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot { align-self: flex-start; }
.msg.cont .avatar { visibility: hidden; }
.bubble { padding: .5rem .8rem; border-radius: 18px; background: var(--bubble-bot); box-shadow: var(--shadow); border: 1px solid var(--line); min-width: 0; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-ink); border-color: transparent; white-space: pre-wrap; border-bottom-right-radius: 6px; }
.msg.bot .bubble { border-bottom-left-radius: 6px; }
.meta { display: block; font-size: .7rem; color: var(--muted); margin: 0 .4rem; align-self: flex-end; flex: none; padding-bottom: .15rem; }
.msg.me.sending .bubble { opacity: .6; }
.msg.failed .bubble { background: transparent; color: var(--danger); border: 1px dashed var(--danger); }
.retry { border: 0; background: none; color: var(--danger); font-size: .75rem; text-decoration: underline; padding: 0 .3rem; align-self: flex-end; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .35rem 0; } .md ul, .md ol { margin: .35rem 0; padding-left: 1.3rem; } .md li { margin: .1rem 0; }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md code { font: .86em var(--mono); background: var(--code-bg); padding: .1em .35em; border-radius: 5px; }
.code { position: relative; margin: .5rem 0; background: var(--code-bg); border-radius: 10px; border: 1px solid var(--line); }
.code pre { margin: 0; padding: .7rem .85rem; padding-right: 3.6rem; overflow-x: auto; }
.code code { background: none; padding: 0; font: .83rem/1.5 var(--mono); white-space: pre; }
.copy { position: absolute; top: .35rem; right: .35rem; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 7px; font-size: .72rem; padding: .15rem .5rem; }
.copy:hover { color: var(--accent); }
.more { align-self: center; border: 0; background: none; color: var(--muted); font-size: .8rem; padding: .3rem .8rem; }

.composer { display: flex; gap: .5rem; align-items: flex-end; padding: .6rem .8rem; padding-bottom: max(.6rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; resize: none; max-height: 9rem; min-height: 2.6rem; padding: .6rem .9rem; border: 1px solid var(--line); border-radius: 20px; background: var(--bg); line-height: 1.45; outline: none; }
.composer textarea:focus { border-color: var(--accent); }
.send { flex: none; width: 2.6rem; height: 2.6rem; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.send:disabled { opacity: .35; cursor: default; }
.send svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) and (pointer: fine) { .send { display: none; } .composer textarea { border-radius: 14px; } }

/* pages (bots, settings) */
.page { flex: 1; overflow-y: auto; padding: 1.25rem 1rem 3rem; }
.page-inner { max-width: 40rem; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 1rem 1.1rem; }
.card h3 { margin: 0 0 .5rem; font-size: 1rem; }
.card p { margin: .3rem 0; color: var(--muted); }
.bot-row { display: flex; align-items: center; gap: .8rem; }
.bot-row .chat-body { flex: 1; }
.sub { color: var(--muted); font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: .45rem .9rem; font-weight: 550; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { color: var(--accent-ink); filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; }
.field label { font-size: .85rem; font-weight: 600; }
.field input { padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; }
.field input:focus { border-color: var(--accent); }
.field small { color: var(--muted); }
.error { color: var(--danger); font-size: .88rem; margin: .4rem 0 0; }
.token-box { display: flex; gap: .5rem; align-items: stretch; }
.token-box code { flex: 1; min-width: 0; padding: .6rem .8rem; background: var(--code-bg); border-radius: 10px; font: .85rem var(--mono); overflow-wrap: anywhere; }
.warn { background: var(--accent-soft); color: var(--ink); padding: .6rem .8rem; border-radius: 10px; font-size: .88rem; margin-bottom: .8rem; }
.example { margin-top: .9rem; } .example > span { font-size: .8rem; font-weight: 600; color: var(--muted); }

/* login */
.login { margin: auto; max-width: 24rem; padding: 2rem; text-align: center; }
.login img { width: 72px; height: 72px; border-radius: 20px; margin-bottom: 1rem; }
.login h1 { margin: 0 0 .5rem; font-size: 1.6rem; letter-spacing: -.03em; }
.login p { color: var(--muted); margin: .4rem 0; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .5rem 1rem; border-radius: 999px; font-size: .85rem; z-index: 10; }
.modal { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: grid; place-items: center; z-index: 9; padding: 1rem; }
.modal .card { max-width: 24rem; width: 100%; }
@media (prefers-reduced-motion: no-preference) { .chat-item, .btn, .icon-btn { transition: background .15s, border-color .15s, color .15s; } }
#root.center { display: flex; }

/* M2: status, open cards */
.head-avatar { display: contents; }
.head { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.head h2 { flex: none; }
.head-status { display: flex; align-items: center; gap: .4rem; min-width: 0; font-size: .76rem; color: var(--muted); line-height: 1.3; }
.head-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { --c: var(--muted); flex: none; display: inline-flex; align-items: center; gap: .3rem; color: var(--c); font-size: .72rem; font-weight: 600; white-space: nowrap; }
.status-pill.short { padding: .05rem .45rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 13%, transparent); }
.status-pill.long { font-size: .76rem; }
.status-pill .dot { width: .45rem; height: .45rem; border-radius: 50%; background: var(--c); }
.status-pill[data-state="working"] { --c: var(--accent); }
.status-pill[data-state="waiting"], .status-pill[data-state="limited"] { --c: var(--warn); }
.status-pill[data-state="failed"] { --c: var(--danger); }
.status-pill[data-state="offline"] .dot, .status-pill[data-state="idle"] .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
@media (prefers-reduced-motion: no-preference) {
  .status-pill[data-state="working"] .dot { animation: pulse 1.4s ease-in-out infinite; }
}
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
.card-jump { flex: none; display: inline-flex; align-items: center; gap: .35rem; border: 0; border-radius: 999px; padding: .3rem .7rem; background: var(--warn-soft); color: var(--warn); font-size: .8rem; font-weight: 650; }
.card-jump svg, .card-pill svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.chat-item.has-cards { box-shadow: inset 3px 0 0 var(--warn); }
.chat-item.has-cards .chat-preview { color: var(--ink); }
.card-pill { flex: none; display: inline-flex; align-items: center; gap: .2rem; height: 1.35rem; padding: 0 .45rem; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: .74rem; font-weight: 700; }

/* M2: streaming */
.cursor { display: inline-block; width: .5em; height: 1.05em; margin-left: .1em; vertical-align: -.15em; border-radius: 2px; background: var(--accent); }
@media (prefers-reduced-motion: no-preference) { .cursor { animation: blink 1s steps(1) infinite; } }
@keyframes blink { 50% { opacity: 0; } }
.msg.streaming .bubble { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.stack { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.stream-note { margin: 0 .4rem; font-size: .74rem; color: var(--danger); }
.msg.stream-failed .bubble { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }

/* M2: command output */
.msg.cmd { max-width: min(52rem, 100%); width: 100%; }
.cmdout { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--code-bg); overflow: hidden; }
.cmdout summary { display: flex; align-items: center; gap: .6rem; padding: .45rem .8rem; cursor: pointer; list-style: none; user-select: none; }
.cmdout summary::-webkit-details-marker { display: none; }
.cmdout summary::before { content: ""; width: .45rem; height: .45rem; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(-45deg); flex: none; }
.cmdout[open] summary::before { transform: rotate(45deg); }
.cmdout summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cmd-name { font: 600 .85rem var(--mono); color: var(--ink); }
.cmd-meta { color: var(--muted); font-size: .74rem; margin-left: auto; }
.cmdout .code { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; }
.cmdout pre { max-height: 28rem; overflow: auto; }

/* M2: cards */
.msg.card-msg { align-items: flex-start; }
/* flex-shrink + min-width 0: a long code line in the body must scroll, not widen the card. */
.qcard { width: 30rem; flex: 0 1 auto; min-width: 0; background: var(--bubble-bot); border: 1px solid var(--line); border-radius: 18px; border-top-left-radius: 6px; box-shadow: var(--shadow); padding: .8rem .95rem .9rem; display: flex; flex-direction: column; gap: .45rem; }
.qcard[data-status="open"] { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.qcard.approval[data-status="open"] { box-shadow: inset 3px 0 0 var(--warn), var(--shadow); }
.qcard-head { display: flex; align-items: center; gap: .5rem; font-size: .74rem; }
.qcard-kind { font-weight: 700; color: var(--warn); letter-spacing: .02em; }
.qcard:not([data-status="open"]) .qcard-kind { color: var(--muted); }
.qcard-state { padding: .05rem .5rem; border-radius: 999px; font-weight: 650; }
.qcard-state.answered { background: var(--accent-soft); color: var(--accent); }
.qcard-state.cancelled { background: color-mix(in srgb, var(--line) 70%, transparent); color: var(--muted); }
.qcard-time { margin-left: auto; color: var(--muted); }
.qcard-title { margin: 0; font-size: 1rem; font-weight: 650; letter-spacing: -.01em; }
.qcard-body { color: var(--ink); font-size: .92rem; }
.qcard-fields { border: 0; margin: .2rem 0 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: .75rem; }
.qcard-fields:disabled { opacity: .65; }
.qf { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: .35rem; }
.qf-label { padding: 0; font-size: .85rem; font-weight: 600; display: flex; flex-wrap: wrap; gap: .1rem .4rem; align-items: baseline; }
.opt-flag { font-size: .74rem; font-weight: 500; color: var(--muted); }
.qf textarea { resize: vertical; min-height: 2.6rem; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; line-height: 1.45; }
.qf textarea:focus { border-color: var(--accent); }
.opt { display: flex; gap: .6rem; align-items: flex-start; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); cursor: pointer; }
.opt:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.opt input { margin: .25rem 0 0; accent-color: var(--accent); flex: none; }
.opt-text { display: flex; flex-direction: column; min-width: 0; }
.opt-label { font-weight: 550; }
.opt-desc { font-size: .8rem; color: var(--muted); }
.seg-row { display: flex; gap: .5rem; }
.opt.seg { flex: 1; justify-content: center; align-items: center; }
.qcard-fields:disabled .opt { cursor: default; }
.qcard-actions { margin-top: .1rem; align-items: center; }
.qcard-busy { font-size: .8rem; color: var(--muted); }
.qcard .error { margin: 0; }
.qcard-answer { margin: .1rem 0 0; display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; font-size: .88rem; padding: .55rem .7rem; border-radius: 10px; background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.qcard-answer dt { color: var(--muted); }
.qcard-answer dd { margin: 0; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.qcard-cancel { margin: 0; font-size: .86rem; color: var(--muted); }

/* M2: command autocomplete */
.composer { position: relative; }
.ac { position: absolute; left: .6rem; right: .6rem; bottom: calc(100% + .35rem); margin: 0; padding: .3rem; list-style: none; max-height: min(18rem, 45vh); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 24px rgb(0 0 0 / .14); z-index: 5; }
.ac-item { display: flex; flex-direction: column; gap: .05rem; padding: .45rem .65rem; border-radius: 10px; cursor: pointer; min-height: 2.6rem; justify-content: center; }
.ac-item[aria-selected="true"] { background: var(--accent-soft); }
.ac-top { display: flex; gap: .5rem; align-items: baseline; min-width: 0; }
.ac-name { font: 600 .88rem var(--mono); color: var(--ink); white-space: nowrap; }
.ac-hint { font: .8rem var(--mono); color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-desc { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) { .ac-item:hover { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); } }

/* Polish: accessibility, touch, safe areas, overflow */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.composer textarea:focus-visible, .field input:focus-visible, .qf textarea:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.messages:focus-visible, .chat-list:focus-visible, .page:focus-visible { outline-offset: -2px; }
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }
.chat-item:focus-visible { outline-offset: -2px; }
.btn.primary:focus-visible { outline-color: var(--ink); }

/* Long names, words and URLs never push the layout sideways. */
.qcard, .card, .empty, .login, .opt-text, .qf-label, .stream-note { overflow-wrap: anywhere; }
.qcard-title, .qcard-body, .opt-label, .opt-desc { min-width: 0; }
.md li, .md p { overflow-wrap: anywhere; }
.bot-row .chat-name, .bot-row .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 520px) {
  .bot-row { flex-wrap: wrap; }
  .bot-row .chat-body { flex: 1 1 calc(100% - 4rem); }
  .bot-row .actions { width: 100%; margin-top: .2rem; }
}

/* Safe areas: notch and home indicator, including landscape. */
.topbar { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
.chat-list { padding-left: max(.35rem, env(safe-area-inset-left)); padding-right: max(.35rem, env(safe-area-inset-right)); padding-bottom: max(.35rem, env(safe-area-inset-bottom)); }
.messages { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
.composer { padding-left: max(.8rem, env(safe-area-inset-left)); padding-right: max(.8rem, env(safe-area-inset-right)); }
.page { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); padding-bottom: calc(3rem + env(safe-area-inset-bottom)); }
.login { padding: max(2rem, env(safe-area-inset-top)) max(2rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(2rem, env(safe-area-inset-left)); }
.modal { padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
/* Above the composer, not on top of the send button. */
.toast { bottom: calc(5rem + env(safe-area-inset-bottom)); max-width: calc(100vw - 2rem); text-align: center; }

/* Account switch prompt (review L3). */
.login.switch .actions { justify-content: center; }
.login.switch p { text-align: left; }

/* Touch: 44px targets on coarse pointers. */
@media (pointer: coarse) {
  .icon-btn, .send { width: 2.75rem; height: 2.75rem; }
  .btn { min-height: 2.75rem; }
  .composer textarea { min-height: 2.75rem; }
  .field input { min-height: 2.75rem; }
  .copy { top: 0; right: 0; min-width: 2.75rem; min-height: 2.75rem; border-radius: 0 10px 0 10px; font-size: .78rem; }
  .code pre { min-height: 2.75rem; }
  .more, .retry { min-height: 2.75rem; }
  .card-jump { min-height: 2.75rem; }
  .opt { min-height: 2.75rem; align-items: center; }
  .opt input { margin-top: 0; width: 1.15rem; height: 1.15rem; }
  .cmdout summary { min-height: 2.75rem; }
  .ac-item { min-height: 2.75rem; }
}

/* Text fields need a 3:1 boundary (WCAG 1.4.11); the hairline --line is decoration only. */
.composer textarea, .field input, .qf textarea { border-color: var(--field-line); }
.composer textarea:focus, .field input:focus, .qf textarea:focus { border-color: var(--accent); }
.bot-row + .bot-row { margin-top: .5rem; }
/* Korean wraps between words, not inside them; long unbroken strings still break. */
body { word-break: keep-all; overflow-wrap: break-word; }
.toast { overflow-wrap: anywhere; }

/* M4a: bot groups in the side list */
.avatar.xs { width: 28px; height: 28px; font-size: .8rem; }
.group { margin: .1rem 0; }
.group-head { display: flex; align-items: center; gap: .55rem; width: 100%; min-height: 2.75rem; padding: .35rem .6rem .35rem .45rem; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.group-head:hover { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.group-head > svg { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: none; }
.group[data-folded="true"] .group-head > svg { transform: rotate(-90deg); }
.group-name { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-body { list-style: none; margin: 0; padding: 0 0 .2rem .9rem; }
.chat-item.nested { padding: .5rem .6rem; gap: .55rem; min-height: 2.75rem; }
.nest-icon { flex: none; width: 22px; height: 22px; display: grid; place-items: center; color: var(--muted); }
.nest-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-item.nested .chat-name { font-weight: 580; }

/* M4a: thread state chip (icon + label; never colour alone) */
.tchip { --c: var(--muted); flex: none; display: inline-flex; align-items: center; gap: .25rem; padding: .05rem .5rem .05rem .35rem; border-radius: 999px; font-size: .72rem; font-weight: 650; line-height: 1.4; color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); white-space: nowrap; }
.tchip svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tchip[data-state="working"], .tchip[data-state="done"] { --c: var(--accent); }
.tchip[data-state="waiting"], .tchip[data-state="limited"] { --c: var(--warn); }
.tchip[data-state="failed"] { --c: var(--danger); }
.tchip[data-state="done"] { background: var(--accent-soft); }
.tchip[data-state="limited"] { box-shadow: inset 0 0 0 1px currentColor; }
.tchip[data-state="idle"] svg { opacity: .8; }
@media (prefers-reduced-motion: no-preference) { .tchip[data-state="working"] svg { animation: spin 1.1s linear infinite; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* M4a: channel = thread list | thread */
.split { flex: 1; min-height: 0; min-width: 0; display: flex; }
.tlist, .tpane { display: flex; flex-direction: column; min-width: 0; min-height: 0; flex: 1; }
.tpane { display: none; }
.split[data-thread="1"] .tlist { display: none; }
.split[data-thread="1"] .tpane { display: flex; }
.tback { display: none; }
@media (max-width: 1099px) { .tback { display: grid; margin-left: -.5rem; } }
@media (min-width: 1100px) {
  .tlist { flex: 0 0 380px; border-right: 1px solid var(--line); }
  .split[data-thread="1"] .tlist { display: flex; }
  .tpane { display: flex; }
}
.tbody { flex: 1; overflow-y: auto; padding: .5rem .6rem 1rem; display: flex; flex-direction: column; gap: .4rem; }
.tbody:focus-visible { outline-offset: -2px; }
.thread-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.tcard-wrap { position: relative; display: flex; align-items: stretch; gap: .15rem; }
.tcard { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .3rem; text-align: left; padding: .65rem .75rem .6rem; background: var(--bubble-bot); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.tcard:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.tcard[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.tcard.has-cards { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); box-shadow: inset 3px 0 0 var(--warn), var(--shadow); }
.tcard.archived { opacity: .8; }
.tc-top { display: flex; align-items: baseline; gap: .5rem; }
.tc-title { flex: 1; min-width: 0; font-weight: 640; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tcard.unread .tc-title { font-weight: 700; }
.tc-mid { display: flex; align-items: center; gap: .5rem; min-width: 0; min-height: 1.2rem; }
.tc-text { min-width: 0; flex: 1; font-size: .84rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-text.bad { color: var(--danger); }
.tc-meta { display: flex; align-items: center; gap: .45rem; font-size: .78rem; color: var(--muted); }
.tc-replies { margin-right: auto; }
.tmenu { flex: none; align-self: center; width: 2.4rem; height: 2.4rem; }
.tnote { color: var(--muted); font-size: .85rem; text-align: center; margin: .6rem 0; }
.empty.slim { padding: .8rem; }
.archive { margin-top: .6rem; display: flex; flex-direction: column; gap: .4rem; }
.arch-toggle { display: flex; align-items: center; gap: .45rem; min-height: 2.5rem; padding: .3rem .5rem; border: 0; background: none; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: .86rem; text-align: left; }
.arch-toggle:hover { color: var(--accent); }
.arch-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.arch-toggle[aria-expanded="false"] svg:first-child { transform: rotate(-90deg); }
.arch-count { font-weight: 500; }

/* M4a: thread head (the top-level post) */
.thread-root { align-self: stretch; margin: 0 0 .5rem; padding: .7rem .9rem; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 12px; background: var(--panel); }
.root-meta { display: flex; gap: .5rem; align-items: baseline; font-size: .76rem; color: var(--muted); margin-bottom: .25rem; }
.root-kicker { font-weight: 700; color: var(--accent); letter-spacing: .02em; }
.root-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14rem; overflow: auto; }
.root-text.md { white-space: normal; }
.thread-root.sending { opacity: .65; }
.thread-root.failed { border-left-color: var(--danger); }

/* M4a: action sheet */
.sheet { align-items: end; }
.sheet .card { max-width: 24rem; display: flex; flex-direction: column; gap: .5rem; }
.sheet .card h3 { overflow-wrap: anywhere; }
.sheet-list { display: flex; flex-direction: column; gap: .4rem; }
.sheet-act { display: flex; align-items: center; gap: .6rem; justify-content: flex-start; min-height: 2.75rem; }
.sheet-act svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 761px) { .sheet { align-items: center; } }

/* M4a: 44px targets on touch */
@media (pointer: coarse) {
  .tmenu, .tmenu-top { width: 2.75rem; height: 2.75rem; }
  .arch-toggle { min-height: 2.75rem; }
  .group-head { min-height: 2.75rem; }
  .tcard { min-height: 2.75rem; }
}
.tmenu-top { flex: none; }
/* The thread head sits at the top; replies stay anchored to the bottom like a chat. */
.messages > .thread-root:first-child { margin-top: 0; }
.messages > .thread-root + * { margin-top: auto; }
.tcard.has-cards { box-shadow: var(--shadow); border-left: 4px solid var(--warn); }
