:root { --bg:#212121; --side:#171717; --raised:#2f2f2f; --hover:#262626; --line:#3a3a3a; --text:#ececec; --muted:#9b9b9b; --link:#8ab4ff; --danger:#ff8a7a; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 400 16px/1.6 "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; line-height: 1.2; } a { color: var(--link); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
::-webkit-scrollbar { width: 8px; } ::-webkit-scrollbar-thumb { background: #444; border-radius: 8px; }

.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand::before { content: ""; width: 28px; height: 28px; background: url(icons/logo.svg) center/contain no-repeat; }
.icon-btn::before, .send::before, .attach::before, .new-chat::before, .chat-del::before, .att-x::before { content: ""; display: block; background: currentColor; -webkit-mask: center/contain no-repeat; mask: center/contain no-repeat; }
#open-side::before { width: 22px; height: 22px; -webkit-mask-image: url(icons/menu.svg); mask-image: url(icons/menu.svg); }
#close-side::before, .att-x::before { width: 16px; height: 16px; -webkit-mask-image: url(icons/close.svg); mask-image: url(icons/close.svg); }
#close-side::before { width: 22px; height: 22px; }
.send::before { width: 20px; height: 20px; -webkit-mask-image: url(icons/send.svg); mask-image: url(icons/send.svg); }
.attach::before { width: 22px; height: 22px; -webkit-mask-image: url(icons/clip.svg); mask-image: url(icons/clip.svg); }
.new-chat::before { width: 18px; height: 18px; -webkit-mask-image: url(icons/plus.svg); mask-image: url(icons/plus.svg); }
.chat-del::before { width: 17px; height: 17px; -webkit-mask-image: url(icons/trash.svg); mask-image: url(icons/trash.svg); }

.btn { background: var(--text); color: #171717; border: 0; border-radius: 12px; padding: .95rem 1.4rem; min-height: 48px; font: 600 1rem/1 inherit; font-family: inherit; cursor: pointer; transition: opacity .15s; }
.btn:hover { opacity: .88; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: .4rem 0; } .link-btn:hover { color: var(--text); }
.icon-btn { display: none; align-items: center; justify-content: center; width: 44px; height: 44px; font-size: 0; background: none; border: 0; color: var(--text); border-radius: 12px; cursor: pointer; } .icon-btn:hover { background: var(--hover); }
input, textarea { width: 100%; background: var(--raised); color: var(--text); border: 1px solid transparent; border-radius: 12px; padding: .85rem 1rem; font: inherit; font-size: 16px; }
input:focus, textarea:focus { border-color: #666; outline: none; }

.auth { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; min-height: 100dvh; }
.auth-side { position: relative; overflow: hidden; padding: 3rem clamp(1.5rem, 5vw, 4.5rem); display: flex; flex-direction: column; justify-content: space-between; gap: 3rem; background: var(--side); border-right: 1px solid #262626; }
.auth-side::after { content: ""; position: absolute; width: 640px; height: 640px; right: -230px; bottom: -230px; background: url(icons/orbits.svg) center/contain no-repeat; pointer-events: none; }
.auth-side > * { position: relative; z-index: 1; }
.auth-side h1 { font-size: clamp(2rem, 3.6vw, 3.1rem); font-weight: 700; letter-spacing: -.03em; max-width: 15ch; }
.lead { color: var(--muted); max-width: 44ch; margin: 1.2rem 0 2rem; }
.sample { display: flex; flex-direction: column; gap: .7rem; max-width: 440px; }
.sample .bubble { margin: 0; padding: .85rem 1.1rem; font-size: .95rem; border-radius: 18px; }
.sample .user { align-self: flex-end; background: var(--raised); } .sample .ai { border: 1px solid var(--line); color: #c9c9c9; }
.auth-main { display: grid; place-items: center; padding: 2rem; }
.form { width: min(400px, 100%); display: flex; flex-direction: column; gap: 1.1rem; }
.form h2 { font-size: 1.8rem; font-weight: 700; margin-bottom: .3rem; }
.form label { display: flex; flex-direction: column; gap: .45rem; font-weight: 500; font-size: .92rem; }
.form small { color: var(--muted); font-weight: 400; } .alt { color: var(--muted); font-size: .95rem; margin: .2rem 0 0; text-align: center; }
.alert { margin: 0; padding: .75rem 1rem; border-radius: 12px; border: 1px solid rgba(255,138,122,.35); background: rgba(255,138,122,.08); color: var(--danger); font-size: .95rem; }

.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--side); display: flex; flex-direction: column; min-height: 0; padding: .9rem .6rem; }
.side-top { display: flex; justify-content: space-between; align-items: center; padding: 0 .6rem .8rem; }
.new-chat { display: flex; align-items: center; gap: .6rem; background: none; color: var(--text); border: 0; border-radius: 10px; padding: .7rem .8rem; min-height: 44px; font: 500 .95rem/1 inherit; font-family: inherit; cursor: pointer; } .new-chat:hover { background: var(--hover); }
.chat-list { flex: 1; overflow-y: auto; margin: .6rem 0; display: flex; flex-direction: column; gap: 2px; }
.list-empty { color: var(--muted); font-size: .9rem; padding: 0 .8rem; }
.chat-item { display: flex; align-items: center; border-radius: 10px; } .chat-item:hover { background: var(--hover); } .chat-item.active { background: var(--raised); }
.chat-open { flex: 1; min-width: 0; min-height: 42px; background: none; border: 0; color: var(--text); font: inherit; font-size: .94rem; text-align: left; padding: .6rem .8rem; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-del { display: grid; place-items: center; width: 38px; height: 38px; font-size: 0; background: none; border: 0; color: var(--muted); cursor: pointer; opacity: 0; border-radius: 8px; }
.chat-item:hover .chat-del, .chat-del:focus-visible { opacity: 1; } .chat-del:hover { color: var(--danger); }
.side-bottom { border-top: 1px solid #2a2a2a; padding: .9rem .6rem 0; display: flex; justify-content: space-between; align-items: center; gap: .8rem; font-size: .9rem; }
.email { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: .4rem; padding: .6rem 1.4rem; min-height: 56px; }
.chat-head h1 { font-size: 1rem; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow-y: auto; padding: 1rem 1.4rem; scroll-behavior: smooth; overscroll-behavior: contain; }
.messages > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; padding-top: 16vh; }
.empty::before { content: ""; display: block; width: 52px; height: 52px; margin: 0 auto 1.2rem; background: url(icons/logo.svg) center/contain no-repeat; }
.empty h2 { font-size: clamp(1.7rem, 5vw, 2.2rem); font-weight: 700; letter-spacing: -.02em; } .empty p { color: var(--muted); margin: .5rem 0 0; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; margin-top: 1.6rem; }
.chip { background: none; color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: .6rem 1rem; font: inherit; font-size: .9rem; cursor: pointer; } .chip:hover { background: var(--hover); }

.msg { display: flex; gap: .8rem; margin-bottom: 1.5rem; }
.msg.user { flex-direction: column; align-items: flex-end; gap: .4rem; }
.msg.assistant::before { content: ""; flex: none; width: 28px; height: 28px; margin-top: 2px; background: url(icons/logo.svg) center/contain no-repeat; }
.msg .bubble { line-height: 1.7; overflow-wrap: anywhere; min-width: 0; }
.msg.user .bubble { background: var(--raised); padding: .7rem 1.1rem; border-radius: 20px; max-width: 85%; white-space: pre-wrap; }
.msg.assistant .bubble { flex: 1; }
.msg.assistant .bubble p { margin: 0 0 .9rem; } .msg.assistant .bubble p:last-child { margin: 0; }
.msg code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; background: var(--raised); padding: .12em .4em; border-radius: 6px; }
.msg pre { margin: .9rem 0; padding: 1rem 1.1rem; background: #141414; border: 1px solid #2f2f2f; border-radius: 12px; overflow-x: auto; } .msg pre code { background: none; padding: 0; font-size: .86rem; }
.bubble.error, .error-note { color: var(--danger); } .error-note { margin: .6rem 0 0; }
.bubble.typing::after { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--text); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }

.files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; max-width: 85%; }
.att { display: flex; align-items: center; gap: .55rem; max-width: 230px; background: #262626; border: 1px solid var(--line); border-radius: 12px; padding: .35rem .6rem .35rem .4rem; font-size: .85rem; }
.att img, .att .ico { flex: none; width: 36px; height: 36px; border-radius: 8px; object-fit: cover; background: #333; }
.att .ico { -webkit-mask: none; position: relative; } .att .ico::before { content: ""; position: absolute; inset: 8px; background: var(--text); -webkit-mask: url(icons/file.svg) center/contain no-repeat; mask: url(icons/file.svg) center/contain no-repeat; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-x { display: grid; place-items: center; flex: none; width: 24px; height: 24px; font-size: 0; background: #444; color: var(--text); border: 0; border-radius: 50%; cursor: pointer; }
.attachments { flex: 1 0 100%; display: flex; flex-wrap: wrap; gap: .5rem; padding: .3rem .3rem 0; } .attachments:empty { display: none; }

.composer { padding: .5rem 1.4rem max(1rem, env(safe-area-inset-bottom)); }
.composer-box, .composer .hint { max-width: 760px; margin-left: auto; margin-right: auto; }
.composer-box { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .3rem; background: var(--raised); border-radius: 26px; padding: .5rem; }
.composer-box textarea { flex: 1; min-width: 0; border: 0; background: none; padding: .6rem .4rem; resize: none; max-height: 200px; line-height: 1.5; }
.attach, .send { flex: none; display: grid; place-items: center; width: 40px; height: 40px; font-size: 0; border: 0; border-radius: 50%; cursor: pointer; }
.attach { background: none; color: var(--text); } .attach:hover { background: #3a3a3a; }
.send { background: var(--text); color: #171717; } .send:disabled { opacity: .35; cursor: wait; }
.hint { color: var(--muted); font-size: .78rem; text-align: center; margin: .55rem 0 0; }
.chat.drag::after { content: "Отпустите, чтобы прикрепить файлы"; position: absolute; inset: 10px; display: grid; place-items: center; background: rgba(23,23,23,.92); border: 2px dashed #777; border-radius: 20px; z-index: 5; }
.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: #3a2623; color: #ffb4a9; padding: .7rem 1.1rem; border-radius: 12px; z-index: 30; max-width: 90vw; }
.scrim { display: none; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { border-right: 0; border-bottom: 1px solid #262626; gap: 1rem; padding: 1.4rem 1.4rem 1.6rem; }
  .auth-side::after { width: 380px; height: 380px; right: -150px; bottom: -170px; }
  .auth-side h1 { font-size: 1.7rem; } .lead, .sample { display: none; }
  .auth-main { padding: 1.6rem 1.4rem 2.5rem; align-items: start; }
  .icon-btn { display: inline-flex; } .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(310px, 86vw); z-index: 20; transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 0 60px #000; }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 10; }
  .chat-head { padding: .3rem .6rem; } .messages { padding: .8rem 1rem; } .chat-del { opacity: .8; } .hint { display: none; }
  .composer { padding: .4rem .7rem max(.8rem, env(safe-area-inset-bottom)); } .msg { gap: .6rem; } .msg.user .bubble, .files { max-width: 92%; } .empty { padding-top: 8vh; } .toast { bottom: 90px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* Markdown в ответах */
.msg.assistant .bubble > :first-child { margin-top: 0; }
.msg.assistant .bubble h1, .msg.assistant .bubble h2, .msg.assistant .bubble h3, .msg.assistant .bubble h4 { margin: 1.5rem 0 .6rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.3; }
.msg.assistant .bubble h1 { font-size: 1.45rem; } .msg.assistant .bubble h2 { font-size: 1.28rem; }
.msg.assistant .bubble h3 { font-size: 1.12rem; } .msg.assistant .bubble h4 { font-size: 1rem; }
.msg.assistant .bubble ul, .msg.assistant .bubble ol { margin: .5rem 0 1rem; padding-left: 1.5rem; }
.msg.assistant .bubble li { margin: .35rem 0; padding-left: .2rem; }
.msg.assistant .bubble li::marker { color: var(--muted); }
.msg.assistant .bubble li > ul, .msg.assistant .bubble li > ol { margin: .3rem 0 .4rem; }
.msg.assistant .bubble li > p { margin: 0 0 .4rem; }
.msg.assistant .bubble blockquote { margin: .9rem 0; padding: .2rem 0 .2rem 1rem; border-left: 3px solid #555; color: #c4c4c4; }
.msg.assistant .bubble hr { border: 0; border-top: 1px solid var(--line); margin: 1.4rem 0; }
.msg.assistant .bubble a { text-underline-offset: 2px; }
.tbl { overflow-x: auto; margin: 1rem 0; border: 1px solid var(--line); border-radius: 12px; }
.tbl table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { padding: .65rem .9rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.tbl th { background: #262626; font-weight: 600; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td { min-width: 120px; }
