:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #171916;
  --rail: #10120f;
  --panel: #20231e;
  --line: #353a31;
  --muted: #abb3a7;
  --ink: #f1f4ec;
  --accent: #dbfa98;
  --accent-ink: #1b2511;
  --error: #ffc0ad;
  --chat-font-increase: 0rem;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
body[data-chat-font-size="1"] { --chat-font-increase: .125rem; }
body[data-chat-font-size="2"] { --chat-font-increase: .25rem; }
body[data-chat-font-size="3"] { --chat-font-increase: .375rem; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.layout { display: grid; grid-template-columns: 224px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.rail {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3.5rem;
  min-height: 0; padding: 1.9rem 1.25rem 1.5rem; background: var(--rail); border-right: 1px solid var(--line);
}
.brand { display: inline-flex; gap: .75rem; align-items: center; font-size: 1.28rem; font-weight: 760; text-decoration: none; letter-spacing: -.045em; }
.brand-mark { display: grid; grid-template: 6px 6px / 6px 6px; gap: 2px; padding: 8px; background: var(--accent); border-radius: 8px; }
.brand-mark i { background: var(--accent-ink); border-radius: 1px; }
.brand-mark i:nth-child(2) { grid-column: 2; grid-row: 2; }
.brand-mark i:nth-child(3) { grid-column: 1; grid-row: 2; }
.rail-body { width: 100%; }
.rail-label { display: block; padding: 0 .55rem .75rem; color: var(--muted); font-size: .875rem; }
.rail-current { display: flex; align-items: center; gap: .62rem; border-radius: .6rem; background: #252a22; padding: .65rem .72rem; font-size: .94rem; }
.rail-current i { width: .4rem; height: .4rem; border-radius: 50%; background: var(--accent); }
.rail-footer { display: grid; gap: .85rem; margin-top: auto; }
.rail-footer a, .rail-footer button, .mobile-logout { background: none; border: 0; padding: 0; color: var(--muted); text-align: left; text-decoration: none; font-size: .9rem; }
.rail-footer a:hover, .rail-footer button:hover, .mobile-logout:hover { color: var(--ink); }
.mobile-logout { display: none; }

.main { min-height: 0; min-width: 0; }
.loading { margin: 2rem; color: var(--muted); }
.login { height: 100%; display: grid; place-items: center; padding: 1.5rem; overflow: auto; }
.login-card { width: min(100%, 480px); border: 1px solid var(--line); padding: clamp(1.35rem, 5vw, 2.55rem); border-radius: 1.1rem; background: var(--panel); box-shadow: 0 22px 70px #05070338; }
.login h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 2.45rem); line-height: 1.12; letter-spacing: -.05em; }
.login-desc { color: var(--muted); margin: 1rem 0 1.75rem; line-height: 1.55; }
.login-options { display: flex; flex-wrap: wrap; gap: .55rem; }
.telegram-link { display: inline-block; padding: .65rem .9rem; border: 1px solid #68765b; border-radius: .55rem; text-decoration: none; font-weight: 650; }
.telegram-link:hover { border-color: var(--accent); }
.login-tip { color: var(--muted); font-size: .9rem; margin: .85rem 0 1.75rem; line-height: 1.45; }
.login-tip code { color: var(--accent); }
.login-fields { display: flex; gap: .55rem; margin-top: .55rem; }
.login-fields input { min-width: 0; width: 100%; padding: .68rem .8rem; border: 1px solid var(--line); border-radius: .55rem; background: var(--rail); color: var(--ink); }
.notice { color: var(--error); font-size: .875rem; line-height: 1.4; margin: .6rem 0 0; overflow-wrap: anywhere; }
.notice:empty { display: none; }

.chat { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-width { width: min(100% - 3rem, 880px); margin-inline: auto; }
.chat-header { border-bottom: 1px solid var(--line); }
.header-inner { display: flex; justify-content: space-between; align-items: center; gap: .5rem; min-height: 5rem; }
.chat-header-controls, .chat-font-controls { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.chat-font-controls { gap: .2rem; }
.chat-font-controls button {
  min-width: 2rem;
  min-height: 36px;
  padding: 0 .35rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--panel);
  color: var(--ink);
  font-size: .875rem;
}
.chat-font-controls button:hover:not(:disabled) { border-color: var(--accent); }
.chat-font-controls button:disabled { cursor: default; }
.header-inner h1 { font-size: 1.26rem; letter-spacing: -.035em; margin: 0; }
.header-inner p { font-size: .875rem; color: var(--muted); margin: .35rem 0 0; }
.scroll { overflow-y: auto; overscroll-behavior-y: contain; scrollbar-color: #51594c transparent; }
.timeline { padding: 1.65rem 0 1.2rem; }
.older { display: block; margin: 0 auto 1.4rem; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 2rem; background: var(--panel); color: var(--muted); font-size: .875rem; }
.older:hover { color: var(--ink); }
.empty { margin: 7vh 0 0; color: var(--muted); line-height: 1.55; }
.date { display: flex; gap: .8rem; align-items: center; margin: 0 0 1.3rem; font-size: .875rem; color: var(--muted); text-align: center; }
.date::before, .date::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.turn { display: grid; row-gap: 1.05rem; margin: 0 0 1.65rem; }
.bubble { max-width: min(92%, 690px); min-width: 0; }
.question { justify-self: end; background: #2c3426; border: 1px solid #3b4833; padding: .75rem .95rem; border-radius: 1rem 1rem .3rem 1rem; }
.response { padding: .25rem 0 .1rem; }
.message-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: .45rem; color: var(--muted); font-size: .8rem; margin-bottom: .4rem; }
.response .message-meta strong { color: var(--accent); font-size: .9rem; }
.message-text { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.55; }
.message-text, .composer textarea { font-size: calc(1rem + var(--chat-font-increase)); }
.message-text a { color: var(--accent); text-underline-offset: .15em; }
.response .message-text code { background: #2b3028; border-radius: .24rem; padding: .04em .27em; }
.attachment-name { color: var(--muted); font-size: .9rem; margin: .5rem 0 0; overflow-wrap: anywhere; }
.download { display: inline-block; background: var(--panel); border: 1px solid var(--line); color: var(--ink); padding: .45rem .75rem; margin: .55rem .45rem 0 0; border-radius: .45rem; text-decoration: none; overflow-wrap: anywhere; max-width: 100%; }
.download:hover { border-color: var(--accent); }
.pending { color: var(--muted); font-size: .9rem; margin: 0; }

.compose-area { padding: .75rem 0 calc(.65rem + env(safe-area-inset-bottom)); background: var(--bg); }
.compose-notice { margin: 0 0 .6rem; }
.composer { border: 1px solid #4a5146; border-radius: .9rem; background: var(--panel); padding: .6rem .7rem .55rem; }
.composer:focus-within { border-color: #7d8b71; }
.composer textarea { width: 100%; display: block; resize: vertical; min-height: 3.6rem; max-height: min(36vh, 15rem); background: transparent; color: var(--ink); border: 0; padding: .45rem .45rem .25rem; line-height: 1.45; outline: 0; }
.composer textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.composer-submit { display: flex; align-items: center; gap: .6rem; }
.composer-model { color: var(--muted); font-size: .8rem; text-align: right; }
.primary { border: 1px solid var(--accent); border-radius: .55rem; background: var(--accent); color: var(--accent-ink); padding: .56rem .86rem; font-weight: 730; }
.primary:hover { background: #e6ffb5; border-color: #e6ffb5; }
.attach { color: var(--muted); border: 0; background: transparent; font-size: .9rem; padding: .4rem; border-radius: .45rem; }
.attach:hover { color: var(--ink); background: #2c3329; }
.attach span { font-size: 1.12rem; margin-right: .3rem; }
.compose-hint { color: var(--muted); margin: .55rem 0 0; font-size: .8rem; text-align: center; }
.file-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .45rem .2rem .6rem; margin: .15rem .35rem; border: 1px solid #4a5146; border-radius: .5rem; max-width: 95%; font-size: .9rem; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { background: transparent; color: var(--muted); border: 0; font-size: 1.15rem; line-height: 1; }

@media (max-width: 720px) {
  .layout { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .rail { flex-direction: row; align-items: center; justify-content: space-between; gap: 1rem; padding: .65rem 1rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-body, .rail-footer button { display: none; }
  .rail-footer { margin: 0; }
  .brand { font-size: 1.1rem; gap: .5rem; }
  .brand-mark { padding: 6px; }
  .mobile-logout { display: block; }
  .chat-width { width: calc(100% - 1.5rem); }
  .header-inner { min-height: 3.8rem; }
  .header-inner h1 { font-size: 1.09rem; }
  .mobile-logout { white-space: nowrap; }
  .header-inner p { margin-top: .2rem; }
  .timeline { padding-top: 1.1rem; }
  .form { padding: .7rem; }
  .bubble { max-width: 96%; }
  .login { place-items: start center; padding-top: 12vh; }
}
