:root {
  --bg: #f6f1e7; --paper: #fffdf8; --ink: #2b2620; --mute: #8a8073; --line: #e6dccb;
  --accent: #e8590c; --user: #2b2620; --r: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { overscroll-behavior: none; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
textarea, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* вход */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--paper); border: 1px solid var(--line); border-radius: 22px; padding: 32px 26px; width: 100%; max-width: 340px; text-align: center; box-shadow: 0 10px 40px #0000000d; }
.login-card .logo { font-size: 52px; }
.login-card h1 { margin: 6px 0 4px; font-size: 28px; }
.login-card p { margin: 0 0 20px; color: var(--mute); }
.login-card input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 16px; }
.login-card button { width: 100%; margin-top: 10px; padding: 13px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 600; }
.err { color: #c92a2a; margin-top: 10px; min-height: 1.2em; font-size: 14px; }

/* каркас */
.app { height: 100dvh; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--paper); border-bottom: 1px solid var(--line); }
.icon { width: 40px; height: 40px; border-radius: 12px; font-size: 19px; display: grid; place-items: center; flex: none; }
.icon:active { background: var(--line); }
.title-wrap { flex: 1; min-width: 0; }
.ptitle { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.psub { font-size: 12px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { flex: 1; display: flex; min-height: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 12px 8px; -webkit-overflow-scrolling: touch; }

/* сообщения */
.msg { display: flex; gap: 9px; margin: 0 auto 14px; max-width: 760px; }
.msg .ava { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 17px; flex: none; margin-top: 2px; }
.msg .body { min-width: 0; flex: 1; }
.msg .who { font-size: 13px; font-weight: 700; margin: 0 0 3px 2px; }
.msg .who span { font-weight: 400; color: var(--mute); }
.bubble { background: var(--paper); border: 1px solid var(--line); border-radius: 4px var(--r) var(--r) var(--r); padding: 10px 13px; line-height: 1.5; font-size: 15.5px; overflow-wrap: anywhere; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.bubble h3, .bubble h4 { margin: 10px 0 4px; font-size: 15.5px; }
.bubble code { background: #f1ebdf; padding: 1px 5px; border-radius: 5px; font-size: 13.5px; }
.bubble pre { background: #f1ebdf; padding: 9px; border-radius: 8px; overflow-x: auto; font-size: 13px; white-space: pre; }
.bubble pre code { background: none; padding: 0; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user); color: #fff; border-color: var(--user); border-radius: var(--r) 4px var(--r) var(--r); max-width: 85%; white-space: pre-wrap; }
.msg.user .body { flex: none; max-width: 85%; display: flex; justify-content: flex-end; }
.msg .tools { opacity: 0; font-size: 12px; color: var(--mute); margin: 3px 4px 0; transition: opacity .15s; }
.msg:hover .tools, .msg.show-tools .tools { opacity: 1; }
.msg .tools button { color: var(--mute); padding: 2px 6px; }
.typing::after { content: '▍'; animation: blink 1s infinite; color: var(--mute); }
@keyframes blink { 50% { opacity: 0; } }
.sysline { text-align: center; color: var(--mute); font-size: 13px; margin: 6px 0 14px; }
.errline { color: #c92a2a; font-size: 13px; margin-top: 4px; }

.welcome { max-width: 560px; margin: 20px auto; text-align: center; color: var(--mute); }
.welcome .big { font-size: 46px; }
.welcome h2 { color: var(--ink); margin: 8px 0; }
.welcome .starts { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.welcome .starts button { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; text-align: left; color: var(--ink); }

/* ввод */
.composer { border-top: 1px solid var(--line); background: var(--paper); padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 7px; scrollbar-width: none; max-width: 760px; margin: 0 auto; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px 5px 7px; font-size: 13px; background: #fff; white-space: nowrap; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.row { display: flex; gap: 8px; align-items: flex-end; max-width: 760px; margin: 0 auto; }
#input { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 10px 14px; font-size: 16px; line-height: 1.35; max-height: 160px; background: #fff; outline: none; }
#input:focus { border-color: #cbbda5; }
.send { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 18px; flex: none; }
.send:disabled { opacity: .4; }
.row2 { display: flex; align-items: center; gap: 8px; margin: 7px auto 0; max-width: 760px; min-height: 30px; }
.ghost { border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13.5px; background: #fff; }
.ghost:disabled { opacity: .45; }
.ghost.small { padding: 3px 10px; font-size: 12.5px; }
.stop { color: #c92a2a; border-color: #f0c4c4; }
.status { font-size: 13px; color: var(--mute); flex: 1; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* паспорт */
.passport { width: 360px; border-left: 1px solid var(--line); background: var(--paper); display: flex; flex-direction: column; }
.pass-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.pass-head h2 { font-size: 16px; margin: 0; flex: 1; }
.pass-body { overflow-y: auto; padding: 14px; flex: 1; font-size: 14.5px; line-height: 1.45; }
.pass-body .pname { font-size: 20px; font-weight: 800; }
.pass-body .ppitch { margin: 6px 0 14px; color: #5c5246; }
.pass-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); margin: 16px 0 6px; }
.pass-body ul { margin: 0; padding-left: 18px; }
.pass-body li { margin: 4px 0; }
.pass-body .empty { color: var(--mute); font-style: italic; }
.pass-body .dec li::marker { content: '✔ '; color: #2f9e44; }
.pass-body .con li::marker { content: '◇ '; color: #e67700; }
.pass-body .que li::marker { content: '? '; color: #1971c2; font-weight: 700; }
.pass-body textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: 14px; }
.pass-body input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: 15px; }
.pass-body label { display: block; font-size: 12px; color: var(--mute); margin: 12px 0 4px; }
.pass-body .btns { display: flex; gap: 8px; margin-top: 14px; }
.primary { background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.pass-wait { font-size: 12px; color: var(--mute); }
.pass-toggle, .only-mobile { display: none; }

/* выдвижные панели */
.drawer { position: fixed; inset: 0; z-index: 20; display: flex; }
.drawer.right { flex-direction: row-reverse; }
.drawer-panel { width: 320px; max-width: 86vw; background: var(--paper); height: 100%; overflow-y: auto; padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); position: relative; z-index: 1; }
.scrim { flex: 1; background: #0000004d; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 17px; }
.drawer .primary { width: 100%; }
.proj-list { margin-top: 12px; }
.proj { display: flex; align-items: center; gap: 4px; border-radius: 12px; }
.proj.on { background: #efe6d6; }
.proj .open { flex: 1; text-align: left; padding: 10px 10px; min-width: 0; }
.proj .open b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj .open small { color: var(--mute); }
.proj .del { color: var(--mute); padding: 8px; }
.hint { color: #5c5246; font-size: 14px; line-height: 1.45; margin-top: 0; }
.agent { display: flex; gap: 10px; align-items: flex-start; padding: 10px 6px; border-radius: 12px; width: 100%; text-align: left; }
.agent:active { background: var(--line); }
.agent .ava { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; flex: none; }
.agent b { display: block; }
.agent small { color: var(--mute); display: block; line-height: 1.35; margin-top: 2px; }

@media (max-width: 860px) {
  .pass-toggle, .only-mobile { display: grid; }
  .passport { position: fixed; inset: 0; width: auto; z-index: 15; border: 0; display: none; padding-top: env(safe-area-inset-top); }
  .passport.open { display: flex; }
}
