:root {
  color-scheme: dark;
  font-family: "Inter", "Segoe UI", "Noto Sans", Arial, sans-serif;
  background: #131923;
  color: #eef2f8;
  font-size: 16px;
  --main: #131923;
  --sidebar: #10151e;
  --surface: #1a2330;
  --raised: #222c3a;
  --line: #2b3544;
  --foreground: #eef2f8;
  --muted: #a1adbd;
  --subtle: #8795a7;
  --mint: #a8edd1;
  --mint-dark: #132b26;
  --danger: #ffc3b1;
  --chat-width: 48rem;
  --content-pad: clamp(1.15rem, 3.4vw, 2.7rem);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, textarea, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}
button:disabled { opacity: .56; }
a { color: var(--mint); text-underline-offset: .22em; }
.visually-hidden {
  position: absolute;
  margin: -1px;
  padding: 0;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 50% 25%, #1e3034, var(--main) 38rem);
}
.auth-card {
  width: min(100%, 26rem);
  padding: clamp(1.4rem, 5vw, 2rem);
  background: #18222e;
  border: 1px solid #384953;
  border-radius: 1.15rem;
  box-shadow: 0 1rem 4rem #0a10194d;
}
.auth-brand { display: flex; align-items: center; gap: .7rem; font-size: 1.1rem; font-weight: 700; }
.auth-card h1 { margin: 1.6rem 0 .6rem; font-size: clamp(1.65rem, 7vw, 2rem); line-height: 1.15; letter-spacing: -.045em; }
.auth-description { margin: 0; color: var(--muted); line-height: 1.55; }
.auth-description:empty { display: none; }
.login-form { display: grid; gap: .55rem; margin-top: 1.3rem; }
.login-form > label { font-size: .94rem; }
.login-form > input { width: 100%; min-width: 0; min-height: 2.9rem; padding: .65rem .75rem; background: var(--main); color: var(--foreground); border: 1px solid #4b5b65; border-radius: .54rem; }
.telegram-link { justify-self: start; font-size: .92rem; padding: .2rem 0; margin-bottom: .5rem; }
.remember-device { display: flex; align-items: center; gap: .6rem; min-height: 2.8rem; line-height: 1.35; cursor: pointer; }
.remember-device input { width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--mint); }
.login-form .send-button { min-height: 2.85rem; font-size: 1rem; }
.auth-error { color: var(--danger); font-size: .94rem; line-height: 1.45; }

.workspace {
  display: grid;
  grid-template-columns: minmax(15.5rem, 17rem) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.5rem .9rem .95rem;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  z-index: 5;
}
.brand { display: flex; gap: .8rem; align-items: center; margin: 0 .32rem 1.55rem; }
.mark {
  display: inline-grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  flex: 0 0 auto;
  border-radius: .75rem;
  color: var(--mint);
  background: #1c342e;
  border: 1px solid #355b4f;
  font: 700 1.15rem/1 "DejaVu Sans Mono", Consolas, monospace;
  letter-spacing: -.13em;
  padding-right: .12em;
}
.brand b { display: block; font-size: 1.15rem; font-weight: 700; letter-spacing: -.035em; }
.brand div span { display: block; color: var(--muted); font-size: .81rem; margin-top: .1rem; }
.new-button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: .66rem;
  min-height: 2.8rem;
  padding: .6rem .85rem;
  margin: 0 .22rem .78rem;
  border: 1px solid #446356;
  border-radius: .64rem;
  color: var(--mint);
  background: #192c28;
  font-size: .92rem;
  font-weight: 700;
}
.new-button:hover:not(:disabled) { background: #233b33; border-color: #639683; }
.search-field {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 2.55rem;
  margin: 0 .22rem .96rem;
  padding: 0 .75rem;
  border-radius: .6rem;
  border: 1px solid #2a3442;
  background: #151d27;
  color: var(--muted);
}
.search-field input { border: 0; background: transparent; outline: none; color: var(--foreground); width: 100%; font-size: .87rem; }
.search-field:focus-within { border-color: #7aab9a; }
.search-field input::placeholder, textarea::placeholder { color: var(--subtle); opacity: 1; }
.session-scroll { min-height: 0; overflow-y: auto; padding: 0 .22rem .65rem; scrollbar-width: thin; scrollbar-color: #394657 transparent; }
.sidebar-heading { margin: .1rem .58rem .62rem; color: var(--subtle); font-size: .78rem; font-weight: 700; }
.session-note { margin: .75rem .58rem; color: var(--muted); font-size: .85rem; line-height: 1.45; }
.session-list { display: grid; gap: .2rem; }
.session-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .35rem;
  width: 100%;
  padding: .74rem .62rem .74rem .72rem;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: .54rem;
}
.session-button:hover { background: #1c2532; }
.session-button[aria-current="true"] {
  color: var(--foreground);
  background: #202d39;
  border-color: #394c55;
  box-shadow: inset 2px 0 var(--mint);
}
.session-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .875rem; }
.session-date { font-size: .74rem; color: var(--subtle); white-space: nowrap; }
.session-button[data-active="true"] .session-date { color: var(--mint); }
.more-button, .link-button {
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: var(--mint);
  padding: .42rem .5rem;
  font-size: .85rem;
}
.more-button { margin: .5rem .1rem 0; }
.more-button:hover:not(:disabled), .link-button:hover:not(:disabled) { background: #202e37; }
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: .52rem;
  min-height: 2.6rem;
  margin-top: auto;
  padding: .78rem .25rem 0;
  border-top: 1px solid #27313e;
  color: var(--muted);
  font-size: .78rem;
}
.sidebar-footer .link-button { margin-left: auto; font-size: .76rem; }
.connection-dot { width: .43rem; height: .43rem; flex: none; border-radius: 50%; background: #d8b779; }
.connection-dot[data-state="ready"] { background: var(--mint); }
.connection-dot[data-state="error"] { background: #eb9b88; }

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: radial-gradient(ellipse at 58% 16%, #18232f 0%, var(--main) 42rem);
}
.chat-header {
  min-height: 4.12rem;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .72rem var(--content-pad);
  border-bottom: 1px solid var(--line);
  background: #141b25;
}
.chat-header h1 {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 1.02rem;
  font-weight: 660;
  margin: 0;
  letter-spacing: -.012em;
}
.settings-area { position: relative; flex: 0 0 auto; }
.settings-button {
  display: flex;
  align-items: center;
  gap: .58rem;
  min-height: 2.35rem;
  max-width: 13.5rem;
  padding: .42rem .65rem;
  border: 1px solid #3a4656;
  border-radius: .55rem;
  background: #1b2532;
  font-size: .85rem;
  color: var(--foreground);
}
.settings-button:hover, .settings-button[aria-expanded="true"] { border-color: #6d887f; background: #213036; }
#modelLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { border: solid currentColor; border-width: 0 1px 1px 0; width: .38rem; height: .38rem; transform: rotate(45deg); color: var(--muted); margin: -.14rem .05rem 0 .22rem; flex: none; }
.settings-panel {
  position: absolute;
  z-index: 4;
  top: calc(100% + .65rem);
  right: 0;
  width: min(18.5rem, calc(100vw - 2rem));
  padding: 1rem;
  background: #1c2836;
  border: 1px solid #435061;
  border-radius: .72rem;
  box-shadow: 0 16px 34px #090e16a8;
}
.settings-panel h2 { font-size: 1rem; margin: 0 0 .8rem; }
.settings-panel label { display: grid; gap: .28rem; color: var(--muted); margin-top: .7rem; font-size: .85rem; }
.select-wrap { position: relative; }
.select-wrap::after { content: ""; position: absolute; right: .75rem; top: 43%; width: .38rem; height: .38rem; border: solid var(--muted); border-width: 0 1px 1px 0; transform: rotate(45deg); pointer-events: none; }
select { appearance: none; width: 100%; min-height: 2.4rem; background: #151e29; color: var(--foreground); border: 1px solid #445264; border-radius: .45rem; padding: .4rem 1.7rem .4rem .58rem; }

.notice-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  flex: 0 0 auto;
  padding: .42rem var(--content-pad);
  background: #35272a;
  border-bottom: 1px solid #63464a;
  color: var(--danger);
  font-size: .875rem;
}
.notice-bar span { min-width: 0; overflow-wrap: anywhere; }
.conversation { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #435265 transparent; }
.conversation:focus-visible { outline-offset: -3px; }
.thread-body { width: min(100%, calc(var(--chat-width) + 2 * var(--content-pad))); margin: 0 auto; padding: clamp(1.3rem, 3vh, 2.15rem) var(--content-pad) 1.1rem; }
.thread-body:has(.empty-state:not([hidden])) { display: grid; align-items: center; flex: 1; }
.empty-state { align-self: center; text-align: center; padding: 1.4rem 0 2rem; }
.empty-mark { width: 3.7rem; height: 3.7rem; border-radius: 1rem; font-size: 1.55rem; box-shadow: 0 0 0 .55rem #a3e9cb0b; }
.empty-state h2 { margin: 1.25rem 0 .45rem; font-size: clamp(1.85rem, 5vw, 2.4rem); letter-spacing: -.055em; line-height: 1.12; }
.empty-state p { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.56; }
.examples { display: flex; flex-wrap: wrap; justify-content: center; gap: .45rem; margin-top: 1.3rem; }
.examples button { background: #1b2531; border: 1px solid #364352; color: #d4dce6; border-radius: 2rem; padding: .48rem .7rem; min-height: 2.2rem; font-size: .85rem; }
.examples button:hover { border-color: #79a591; color: var(--mint); }
.history-button { display: block; margin: 0 auto 1.3rem; padding: .48rem .8rem; color: var(--muted); font-size: .83rem; border-radius: .5rem; border: 1px solid #394555; background: #1b2532; }
.history-button:hover:not(:disabled) { color: var(--mint); border-color: #6c9c89; }

.messages { display: grid; gap: 1.55rem; }
.message { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: .43rem; font-size: 1rem; }
.message.user { align-items: flex-end; padding-left: clamp(.2rem, 6vw, 4rem); }
.message-header { display: flex; gap: .5rem; align-items: center; min-height: 1.65rem; color: #c4cedc; font-size: .83rem; font-weight: 700; }
.message-header .mark { width: 1.55rem; height: 1.55rem; border-radius: .44rem; font-size: .71rem; }
.message.user .message-header { padding-right: .24rem; color: var(--muted); }
.message-body { color: #e6edf6; line-height: 1.64; overflow-wrap: anywhere; max-width: 100%; }
.message.user .message-body { padding: .64rem .9rem; white-space: pre-wrap; background: #253548; border: 1px solid #3a4c60; border-radius: .88rem .3rem .88rem .88rem; }
.message.assistant .message-body { width: 100%; }
.message-body p, .message-body ul, .message-body ol, .message-body blockquote { margin: .05rem 0 .83rem; }
.message-body p { white-space: pre-wrap; }
.message-body li { padding-left: .18rem; }
.message-body h2, .message-body h3, .message-body h4 { margin: .9rem 0 .35rem; line-height: 1.35; font-size: 1.11em; }
.message-body blockquote { padding-left: .8rem; border-left: 2px solid #749989; color: #b6c5d7; }
.message-body pre { max-width: 100%; margin: .65rem 0 .95rem; border: 1px solid #3b4657; background: #101722; border-radius: .55rem; overflow: auto; padding: .68rem .8rem; line-height: 1.52; }
.message-body code { font-family: "Noto Mono", "DejaVu Sans Mono", Consolas, monospace; font-size: .89em; color: #d4f0e4; }
.message-body :not(pre) > code { border-radius: .26rem; background: #25313d; padding: .1em .24em; }
.message-body > :last-child { margin-bottom: 0; }
.message-copy { margin-left: .2rem; border: 0; background: transparent; border-radius: .3rem; color: var(--subtle); padding: .25rem .3rem; font: inherit; font-size: .75rem; font-weight: 400; }
.message-copy:hover { color: var(--mint); background: #25333e; }
.live-output { margin-top: 1.6rem; }
.run-status { color: var(--muted); display: flex; gap: .65rem; align-items: center; font-size: .9rem; margin: 0; }
.run-status::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: #a8edd1; flex: none; animation: breathe 1.4s ease-in-out infinite alternate; }
@keyframes breathe { from { opacity: .45; } to { opacity: 1; } }
.run-progress { color: var(--muted); margin: .65rem 0 0 1.1rem; font-size: .86rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.draft-message { margin-bottom: .8rem; }
.running-empty .empty-state { display: none; }

.compose-area { flex: 0 0 auto; padding: .65rem var(--content-pad) max(.76rem, env(safe-area-inset-bottom)); background: var(--main); }
.composer {
  width: min(100%, var(--chat-width));
  margin: 0 auto;
  display: grid;
  gap: .4rem;
  background: #1d2836;
  border: 1px solid #465466;
  border-radius: .92rem;
  padding: .55rem;
  box-shadow: 0 7px 22px #080d1650;
}
.composer-row { display: flex; align-items: flex-end; gap: .35rem; min-width: 0; }
.composer:focus-within { border-color: #78a997; }
.composer textarea { flex: 1; width: 100%; min-width: 0; min-height: 2.35rem; max-height: 10rem; padding: .55rem .45rem; overflow-y: auto; resize: none; border: 0; outline: none; background: transparent; color: var(--foreground); font-size: 1rem; line-height: 1.4; }
.send-button { display: flex; gap: .45rem; align-items: center; justify-content: center; flex: 0 0 auto; padding: .56rem .78rem; min-height: 2.4rem; border: 1px solid #b4efd6; border-radius: .56rem; background: var(--mint); color: #142921; font-size: .85rem; font-weight: 700; }
.send-button:hover:not(:disabled) { background: #c9f6e3; }
.send-button:disabled { opacity: .62; background: #86b6a5; border-color: #8cb8a9; }
.compose-hint { display: flex; justify-content: space-between; gap: .6rem; width: min(100%, var(--chat-width)); margin: .44rem auto 0; padding: 0 .15rem; color: var(--subtle); font-size: .76rem; line-height: 1.35; }
.attachment-tray, .message-files { display: flex; flex-wrap: wrap; gap: .36rem; min-width: 0; max-width: 100%; }
.attachment-tray { max-height: 6rem; overflow-y: auto; }
.message-files { justify-content: flex-end; }
.file-chip { display: inline-flex; align-items: center; max-width: 100%; min-width: 0; gap: .48rem; padding: .28rem .55rem; background: #203832; border: 1px solid #3c5c53; border-radius: .55rem; color: #dcf3e9; font-size: .875rem; line-height: 1.4; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: #afc8be; font-size: .8rem; white-space: nowrap; }
.remove-file { display: grid; place-items: center; flex: none; color: inherit; background: transparent; border: 0; border-radius: .25rem; width: 1.7rem; height: 1.7rem; padding: 0; }
.remove-file:hover { background: #335348; }

.icon-button { display: inline-grid; place-items: center; flex: 0 0 auto; width: 2.1rem; height: 2.1rem; padding: 0; border: 1px solid transparent; border-radius: .44rem; color: inherit; background: transparent; }
.icon-button:hover { background: #253243; }
.css-icon { display: inline-block; position: relative; width: .95rem; height: .95rem; flex: none; color: currentColor; }
.icon-plus::before, .icon-plus::after, .icon-close::before, .icon-close::after {
  content: ""; position: absolute; left: 10%; right: 10%; top: calc(50% - .75px); height: 1.5px; background: currentColor; border-radius: 2px;
}
.icon-plus::after { transform: rotate(90deg); }
.icon-close::before { transform: rotate(45deg); }
.icon-close::after { transform: rotate(-45deg); }
.icon-search::before { content: ""; position: absolute; width: 65%; height: 65%; top: 1px; left: 1px; border: 1.4px solid currentColor; border-radius: 50%; }
.icon-search::after { content: ""; position: absolute; left: 54%; top: 63%; width: 41%; height: 1.4px; background: currentColor; transform: rotate(45deg); transform-origin: left; }
.icon-panel { border: 1.45px solid currentColor; border-radius: 2px; width: 1.03rem; height: .85rem; }
.icon-panel::after { content: ""; position: absolute; top: 0; bottom: 0; left: 34%; width: 1px; background: currentColor; }
.icon-sliders::before { content: ""; position: absolute; inset: 3px 0; border: solid currentColor; border-width: 1.25px 0; }
.icon-sliders::after { content: ""; position: absolute; top: 1px; left: 3px; width: 3px; height: 5px; background: currentColor; border-radius: 1px; box-shadow: 6px 5px currentColor; }
.icon-send { background: currentColor; clip-path: polygon(0 5%, 100% 50%, 0 95%, 13% 57%, 58% 50%, 13% 43%); width: .92rem; height: .92rem; }
.icon-clip { width: .64rem; height: 1.06rem; border: solid currentColor; border-width: 0 1.6px 1.6px; border-radius: 0 0 .35rem .35rem; transform: rotate(36deg); }
.icon-clip::after { content: ""; position: absolute; top: -.08rem; left: -.1rem; width: .43rem; height: .78rem; border: 1.5px solid currentColor; border-radius: .25rem .25rem .2rem .2rem; }
.attach-button { color: var(--muted); min-height: 2.4rem; }
.attach-button:hover { color: var(--mint); }
.close-drawer, .open-drawer, .drawer-shade { display: none; }

@media (min-width: 1550px) { .workspace { grid-template-columns: 18.5rem minmax(0, 1fr); } }
@media (max-width: 760px) {
  .workspace { display: block; height: var(--visible-height, 100dvh); }
  .auth-screen { min-height: var(--visible-height, 100dvh); }
  .chat { height: 100%; }
  .sidebar { position: fixed; inset: 0 auto auto 0; height: var(--visible-height, 100dvh); width: min(18rem, calc(100vw - 2.6rem)); padding-top: max(1rem, env(safe-area-inset-top)); transform: translateX(-103%); visibility: hidden; transition: transform .18s ease, visibility .18s; }
  .workspace.drawer-open .sidebar { transform: translateX(0); visibility: visible; }
  .drawer-shade { display: block; position: fixed; inset: 0; z-index: 4; border: 0; background: #0b111ac0; }
  .open-drawer, .close-drawer { display: inline-grid; }
  .close-drawer { margin-left: auto; }
  .chat-header { min-height: 3.5rem; padding: max(.38rem, env(safe-area-inset-top)) .68rem .38rem; gap: .45rem; }
  .chat-header h1 { font-size: .91rem; }
  .settings-button { max-width: min(8.4rem, 34vw); }
  .settings-button .icon-sliders { display: none; }
  .notice-bar { padding-inline: .75rem; }
  .sidebar-footer { padding-bottom: env(safe-area-inset-bottom); }
  .compose-area { padding-inline: .8rem; }
  .thread-body { padding-inline: 1rem; }
  .empty-state p { max-width: 21rem; margin-inline: auto; }
  .open-drawer, .close-drawer, .attach-button, .send-button { min-width: 44px; min-height: 44px; }
  .settings-button, .sidebar-footer .link-button { min-height: 44px; }
  .settings-panel { max-height: calc(var(--visible-height, 100dvh) - 4.3rem); overflow-y: auto; }
  .search-field input, .settings-panel select { font-size: 1rem; }
  .composer textarea { max-height: min(7rem, 24dvh); }
  .send-button > span:not(.css-icon) { display: none; }
  .send-button { padding-inline: .5rem; }
  .compose-hint .key-hint { display: none; }
  .remove-file { width: 2.2rem; height: 2.2rem; }
}
@media (max-width: 390px) {
  .composer .send-button { aspect-ratio: 1; }
  .compose-hint { font-size: .71rem; }
}
@media (max-width: 760px) and (max-height: 640px) {
  .empty-state { padding: .6rem 0; }
  .empty-mark { width: 2.75rem; height: 2.75rem; font-size: 1.2rem; }
  .empty-state h2 { margin-top: .8rem; }
  .examples { margin-top: .8rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
