/* ZCode на телефоне: тот же тёплый монохром, что у панели агентов на ПК. */
:root {
  --bg: #FBFBFA; --surface: #FFFFFF; --border: #EAEAEA; --border-strong: #DAD9D5;
  --text: #2F3437; --muted: #787774; --faint: #A5A39D;
  --primary: #111111; --primary-text: #FFFFFF; --hover: rgba(0,0,0,.04); --bubble: #F1F0EC;
  --red-bg: #FDEBEC; --red: #9F2F2D; --green-bg: #EDF3EC; --green: #346538; --yellow-bg: #FBF3DB; --yellow: #956400;
  --blue: #1F6C9F;
  --serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace;
  --ease: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191919; --surface: #202020; --border: #2C2C2B; --border-strong: #3A3A38;
    --text: #E6E5E2; --muted: #9B9A97; --faint: #6F6E6A;
    --primary: #EDEDEB; --primary-text: #191919; --hover: rgba(255,255,255,.05); --bubble: #262625;
    --red-bg: #3A2524; --red: #F0A8A6; --green-bg: #213024; --green: #9BCB9F; --yellow-bg: #362F1E; --yellow: #E6C068;
    --blue: #8CC4EA;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
#app { height: 100dvh; display: flex; flex-direction: column; }

.top { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 2; min-height: 56px; }
.top h1 { font: 500 21px/1.2 var(--serif); margin: 0; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { font-size: 12px; color: var(--muted); }
.icon-btn { border: 0; background: none; padding: 8px; margin: -8px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.icon-btn:active { background: var(--hover); }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--green-bg); color: var(--green); white-space: nowrap; }
.pill.off { background: var(--yellow-bg); color: var(--yellow); }

.tabs { display: flex; gap: 4px; padding: 10px 16px 0; }
.tab { flex: 1; border: 1px solid var(--border); background: none; padding: 8px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.list { padding: 8px 8px calc(env(safe-area-inset-bottom) + 16px); }
.group { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); padding: 14px 10px 6px; display: flex; align-items: center; gap: 8px; }
.group span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group button { text-transform: none; letter-spacing: 0; border: 1px solid var(--border); background: none; border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; cursor: pointer; }
.row:active { background: var(--hover); }
.row .main { flex: 1; min-width: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.avatar { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: #fff; font: 500 17px var(--serif); flex: none; overflow: hidden; }
.avatar svg { width: 100%; height: 100%; stroke: none; }
.avatar.sm { width: 30px; height: 30px; border-radius: 8px; font-size: 13px; }

.empty { color: var(--muted); text-align: center; padding: 48px 24px; }
.empty h2 { font: 500 22px/1.3 var(--serif); color: var(--text); margin: 0 0 8px; }

.thread { padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 12px; }
.msg.user { align-self: flex-end; max-width: 85%; background: var(--bubble); padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { overflow-wrap: anywhere; }
.msg.assistant p { margin: 0 0 9px; } .msg.assistant p:last-child { margin: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 9px; padding-left: 22px; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font: 500 17px/1.3 var(--serif); margin: 12px 0 6px; }
.msg.assistant a { color: var(--blue); }
.msg code { font: 13px var(--mono); background: var(--bubble); padding: 1px 5px; border-radius: 4px; }
.msg pre { font: 12.5px/1.5 var(--mono); background: var(--bubble); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 0 0 9px; }
.msg pre code { background: none; padding: 0; }
.call { font: 12.5px var(--mono); color: var(--muted); display: flex; gap: 6px; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.call.err { color: var(--red); }
.shot { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.notice { font-size: 13px; color: var(--muted); text-align: center; }
.notice.error { color: var(--red); }
.thought { font-size: 13px; color: var(--muted); border-left: 2px solid var(--border-strong); padding-left: 10px; white-space: pre-wrap; max-height: 4.6em; overflow: hidden; }
.thought.open { max-height: none; }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
.card .head { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; color: var(--muted); }
.card.done .head { color: var(--green); } .card.question .head, .card.perm .head { color: var(--yellow); }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.composer { border-top: 1px solid var(--border); padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px); background: var(--bg); }
.composer .status { font-size: 12px; color: var(--muted); min-height: 0; padding: 0 4px 6px; }
.composer .status:empty { display: none; }
.composer .box { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 12px; padding: 9px 12px; max-height: 40vh; outline: none; line-height: 1.45; }
.composer textarea:focus { border-color: var(--text); }
.composer .tools { display: flex; gap: 8px; padding-top: 8px; }
.send { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .35; }
.chip { border: 1px solid var(--border); background: none; color: var(--muted); font-size: 13px; padding: 4px 10px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--green-bg); color: var(--green); border-color: transparent; }
.btn { border: 1px solid var(--border-strong); background: var(--surface); padding: 9px 14px; border-radius: 10px; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: transparent; }
.btn.block { width: 100%; }

.pair { padding: 40px 24px; max-width: 420px; margin: 0 auto; }
.pair h1 { font: 500 30px/1.2 var(--serif); margin: 0 0 10px; letter-spacing: -.01em; }
.pair p { color: var(--muted); margin: 0 0 24px; }
.pair input { width: 100%; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 10px; padding: 12px; font: 18px var(--mono); letter-spacing: .15em; text-transform: uppercase; text-align: center; margin-bottom: 12px; outline: none; }
.steps { color: var(--muted); padding-left: 20px; margin: 0 0 24px; }

.screen { flex: 1; background: #111; position: relative; overflow: hidden; }
.screen > div { width: 100%; height: 100%; }
.screen .msgbox { position: absolute; inset: 0; display: grid; place-items: center; color: #bbb; text-align: center; padding: 24px; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 84px); background: var(--primary); color: var(--primary-text); padding: 10px 14px; border-radius: 10px; font-size: 14px; z-index: 10; text-align: center; }
.toast.err { background: var(--red); color: #fff; }

/* Markdown */
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant strong { font-weight: 600; }
.msg.assistant h4, .msg.assistant h5, .msg.assistant h6 { font-size: 15px; font-weight: 600; margin: 12px 0 4px; }
.msg.assistant li.task { list-style: none; margin-left: -18px; }
.msg.assistant blockquote { margin: 0 0 9px; padding: 2px 0 2px 10px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.msg.assistant hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.md-table { overflow-x: auto; margin: 0 0 10px; border: 1px solid var(--border); border-radius: 8px; -webkit-overflow-scrolling: touch; }
.md-table table { border-collapse: collapse; min-width: 100%; font-size: 13.5px; line-height: 1.4; }
.md-table th, .md-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md-table th { font-weight: 600; background: var(--bubble); white-space: nowrap; }
.md-table tr:last-child td { border-bottom: 0; }
.md-table td + td, .md-table th + th { border-left: 1px solid var(--border); }

/* Вложения */
.attach { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); display: grid; place-items: center; flex: none; color: var(--muted); }
.attachments { display: flex; gap: 8px; overflow-x: auto; padding: 0 0 8px; }
.att { position: relative; flex: none; height: 56px; max-width: 180px; display: flex; align-items: center; padding: 0 26px 0 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bubble); font-size: 12.5px; }
.att:has(img) { width: 56px; padding: 0; overflow: hidden; }
.att img { width: 100%; height: 100%; object-fit: cover; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-x { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border: 0; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 14px; line-height: 20px; padding: 0; }
.user-group { align-self: flex-end; max-width: 85%; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.user-group .msg.user { max-width: 100%; }
.files { display: flex; flex-wrap: wrap; gap: 8px; }
.files.user { justify-content: flex-end; }
.card.file .head { color: var(--blue); }
.card.file .files { margin-top: 8px; }
.att-imgwrap { position: relative; }
.att-img { display: block; max-width: 220px; max-height: 220px; border-radius: 10px; border: 1px solid var(--border); background: var(--bubble); min-width: 48px; min-height: 48px; }
.att-img.big { max-width: 100%; max-height: none; }
.att-dl { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: rgba(0,0,0,.55); color: #fff; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); text-align: left; }
.fc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fc-size { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Мышление и контекст */
.composer .tools { align-items: center; }
.composer .tools .spacer { flex: 1; }
.chip.think { position: relative; padding-right: 6px; }
.chip.think svg { width: 15px; height: 15px; }
.chip.think select { appearance: none; -webkit-appearance: none; border: 0; background: none; color: inherit; font: inherit; padding: 0; outline: none; max-width: 52vw; }
.chip.ctx { font-family: var(--mono); font-size: 12px; }
.chip.ctx svg { width: 15px; height: 15px; transform: rotate(-90deg); }
.chip.ctx circle { fill: none; stroke-width: 2.6; }
.chip.ctx .bg { stroke: var(--border-strong); }
.chip.ctx .fg { stroke: currentColor; }
.chip.ctx.warn { color: var(--yellow); }
.chip.ctx.full { color: var(--red); }
.compacted { font-size: 12.5px; color: var(--muted); }
.compacted summary { list-style: none; display: flex; align-items: center; gap: 10px; }
.compacted summary::-webkit-details-marker { display: none; }
.compacted summary::before, .compacted summary::after { content: ''; flex: 1; border-top: 1px dashed var(--border-strong); }
.compacted[open] .msg { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 14px; }

/* Выбор модели */
.composer .tools { flex-wrap: wrap; }
.chip.model { max-width: 46vw; }
.chip.model span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.model svg { width: 15px; height: 15px; }
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; animation: fade 200ms; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-height: 80dvh; display: flex; flex-direction: column; background: var(--bg); border-radius: 16px 16px 0 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 12px); animation: up 280ms var(--ease); }
@keyframes up { from { transform: translateY(40%); } }
.sheet .grip { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 0 auto 10px; }
.sheet h2 { font: 500 20px/1.3 var(--serif); margin: 0 0 4px; }
.sheet .hint { font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }
.sheet-list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet .group { padding: 14px 4px 6px; }
.sheet .tag { font-style: normal; text-transform: none; letter-spacing: 0; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bubble); color: var(--muted); }
.unavail { font-size: 12.5px; color: var(--red); padding: 0 4px 6px; }
.model-row { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 11px 8px; border-radius: 10px; text-align: left; font: 14px var(--mono); }
.model-row span { flex: 1; overflow-wrap: anywhere; }
.model-row:active { background: var(--hover); }
.model-row[aria-pressed="true"] { background: var(--bubble); }
.model-row:disabled { opacity: .4; }

/* Шторка «Контекст» */
.ctx-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ctx-model { font: 12px var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-big { color: var(--muted); font-size: 14px; margin: 6px 0 12px; }
.ctx-big b { font: 500 26px var(--serif); color: var(--text); margin-right: 2px; }
.ctx-pct { float: right; font: 500 18px var(--mono); color: var(--text); padding-top: 6px; }
.ctx-bar { position: relative; display: flex; height: 12px; border-radius: 6px; background: var(--bubble); margin-bottom: 16px; }
.ctx-bar i { display: block; height: 100%; min-width: 2px; }
.ctx-bar i:first-child { border-radius: 6px 0 0 6px; }
.ctx-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: .45; }
.ctx-legend { display: grid; gap: 8px; margin-bottom: 14px; font-size: 14px; }
.ctx-legend > div { display: flex; align-items: center; gap: 10px; }
.ctx-legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.ctx-legend .lbl { flex: 1; }
.ctx-legend .val { font-family: var(--mono); color: var(--muted); }
.ctx-notes { color: var(--muted); font-size: 12.5px; display: grid; gap: 3px; padding-top: 12px; border-top: 1px solid var(--border); margin-bottom: 14px; }
.btn:disabled { opacity: .4; }

.bell { color: var(--muted); margin-right: 4px; }
.bell.on { color: var(--green); }
