/* ---------- шрифты (локальные, без сторонних запросов) ---------- */
@font-face {
  font-family: 'Onest';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('fonts/onest-cyrillic-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Onest';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('fonts/onest-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Unbounded';
  font-style: normal;
  font-display: swap;
  font-weight: 200 900;
  src: url('fonts/unbounded-cyrillic-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Unbounded';
  font-style: normal;
  font-display: swap;
  font-weight: 200 900;
  src: url('fonts/unbounded-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-display: swap;
  font-weight: 100 800;
  src: url('fonts/jetbrains-mono-cyrillic-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-display: swap;
  font-weight: 100 800;
  src: url('fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- токены ---------- */
:root {
  --snow: #f2f4f6;      /* фон */
  --paper: #ffffff;     /* поверхности: поле ввода, диалоги */
  --ink: #16212c;       /* основной текст */
  --slate: #5b6b7a;     /* второстепенный текст */
  --frost: #d6dee5;     /* линии */
  --rime: #e4eaef;      /* реплики пользователя, подложки */
  --signal: #f26b1d;    /* действие: отправить, активный режим */
  --on-signal: #1d0c02;
  --danger: #c62d1f;
  --focus: #f26b1d;

  --font: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Unbounded', 'Onest', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --side-w: 288px;
  --col: 46rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --snow: #0e1a26;
    --paper: #152433;
    --ink: #e8eef3;
    --slate: #93a3b2;
    --frost: #253a4d;
    --rime: #1c2e40;
    --signal: #ff7a2e;
    --on-signal: #1d0c02;
    --danger: #ff6b5c;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --snow: #0e1a26;
  --paper: #152433;
  --ink: #e8eef3;
  --slate: #93a3b2;
  --frost: #253a4d;
  --rime: #1c2e40;
  --signal: #ff7a2e;
  --on-signal: #1d0c02;
  --danger: #ff6b5c;
  color-scheme: dark;
}

/* ---------- база ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--snow);
  color: var(--ink);
  font: 400 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}
.sprite {
  display: none;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.i {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wordmark {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- каркас ---------- */
.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding: 16px 12px 12px;
  border-right: 1px solid var(--frost);
  background: var(--snow);
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 12px;
}
.btn-new {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 9px;
  border: 1px solid var(--frost);
  border-radius: 10px;
  background: var(--paper);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
}
.btn-new:hover {
  border-color: var(--slate);
}
.btn-new .i {
  width: 18px;
  height: 18px;
}
.search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--rime);
  font-size: 0.9rem;
}
.search input:focus {
  border-color: var(--frost);
  outline: none;
  background: var(--paper);
}
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 0.925rem;
}
.side-link:hover,
.side-link[aria-current='page'] {
  background: var(--rime);
}
.side-link .i {
  color: var(--slate);
}

.chat-list {
  flex: 1;
  min-height: 0;
  margin: 8px 0 0;
  padding: 8px 0 0;
  overflow-y: auto;
  list-style: none;
  border-top: 1px solid var(--frost);
}
.chat-list li {
  position: relative;
}
.chat-item {
  display: block;
  width: 100%;
  padding: 8px 64px 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item:hover {
  background: var(--rime);
}
.chat-item[aria-current='true'] {
  background: var(--rime);
  font-weight: 600;
}
.chat-item-actions {
  position: absolute;
  top: 50%;
  right: 4px;
  display: flex;
  translate: 0 -50%;
  opacity: 0;
}
.chat-list li:hover .chat-item-actions,
.chat-list li:focus-within .chat-item-actions,
.chat-item[aria-current='true'] + .chat-item-actions {
  opacity: 1;
}
.chat-item-actions .icon-btn {
  width: 28px;
  height: 28px;
}
.chat-item-actions .i {
  width: 16px;
  height: 16px;
}
.list-label {
  padding: 12px 10px 4px;
  color: var(--slate);
  font-size: 0.78rem;
}
.list-empty {
  padding: 12px 10px;
  color: var(--slate);
  font-size: 0.875rem;
}

.side-foot {
  padding-top: 10px;
  border-top: 1px solid var(--frost);
}
.storage {
  padding: 2px 10px 8px;
}
.storage-bar {
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--rime);
}
.storage-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--slate);
}
.storage p {
  margin: 6px 0 0;
  color: var(--slate);
  font-size: 0.78rem;
  line-height: 1.35;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 16px;
}
.model-pick select {
  max-width: min(60vw, 22rem);
  padding: 7px 30px 7px 12px;
  border: 1px solid var(--frost);
  border-radius: 10px;
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6b7a' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  font-size: 0.9rem;
  font-weight: 500;
  appearance: none;
  text-overflow: ellipsis;
}
.balance {
  margin-left: auto;
  color: var(--slate);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--slate);
}
.icon-btn:hover {
  background: var(--rime);
  color: var(--ink);
}
.only-narrow {
  display: none;
}

/* ---------- сообщения ---------- */
.chat-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}
.messages {
  flex: 1;
  min-height: 0;
  padding: 8px 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-bottom: 24px;
}
.messages > * {
  max-width: var(--col);
  margin-inline: auto;
}

.empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100%;
  padding: 24px 0 8vh;
}
.empty h1 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(1.6rem, 1.1rem + 2.2vw, 2.4rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.empty p {
  max-width: 34rem;
  margin: 0;
  color: var(--slate);
}

.msg {
  margin-top: 22px;
}
.msg.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.msg.user .bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--rime);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-meta {
  margin-bottom: 6px;
  color: var(--slate);
  font-size: 0.8rem;
}
.msg-body {
  overflow-wrap: anywhere;
}
.msg-body > :first-child {
  margin-top: 0;
}
.msg-body > :last-child {
  margin-bottom: 0;
}
.msg-body p,
.msg-body ul,
.msg-body ol,
.msg-body blockquote,
.msg-body table {
  margin: 0 0 0.8em;
}
.msg-body h1,
.msg-body h2,
.msg-body h3,
.msg-body h4 {
  margin: 1.2em 0 0.5em;
  font-weight: 650;
  line-height: 1.25;
}
.msg-body h1 {
  font-size: 1.35rem;
}
.msg-body h2 {
  font-size: 1.2rem;
}
.msg-body h3,
.msg-body h4 {
  font-size: 1.05rem;
}
.msg-body ul,
.msg-body ol {
  padding-left: 1.4em;
}
.msg-body li + li {
  margin-top: 0.25em;
}
.msg-body a {
  color: inherit;
  text-decoration-color: var(--signal);
  text-underline-offset: 3px;
}
.msg-body blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--frost);
  color: var(--slate);
}
.msg-body code {
  padding: 0.1em 0.35em;
  border-radius: 5px;
  background: var(--rime);
  font-family: var(--mono);
  font-size: 0.86em;
}
.msg-body table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.msg-body th,
.msg-body td {
  padding: 6px 10px;
  border: 1px solid var(--frost);
  text-align: left;
}
.msg-body hr {
  border: 0;
  border-top: 1px solid var(--frost);
}
.code {
  margin: 0 0 0.8em;
  overflow: hidden;
  border: 1px solid var(--frost);
  border-radius: 10px;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 4px 12px;
  border-bottom: 1px solid var(--frost);
  background: var(--rime);
  color: var(--slate);
  font-size: 0.78rem;
}
.code-copy {
  padding: 3px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--slate);
  font-size: 0.78rem;
}
.code-copy:hover {
  background: var(--paper);
  color: var(--ink);
}
.code pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  background: var(--paper);
  font: 0.85rem/1.55 var(--mono);
}
.msg-body .code code {
  padding: 0;
  background: none;
  font-size: inherit;
}
.md-img {
  max-width: 100%;
  border-radius: 10px;
}
.ext-img {
  padding: 6px 10px;
  border: 1px dashed var(--frost);
  border-radius: 8px;
  background: transparent;
  color: var(--slate);
  font-size: 0.85rem;
}

.reasoning {
  margin: 0 0 10px;
  color: var(--slate);
  font-size: 0.9rem;
}
.reasoning summary {
  width: fit-content;
  cursor: pointer;
  user-select: none;
}
.reasoning div {
  margin-top: 6px;
  padding-left: 12px;
  border-left: 2px solid var(--frost);
  white-space: pre-wrap;
}

.media {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 8px;
  margin-top: 4px;
}
.msg.user .media {
  justify-items: end;
  width: min(85%, 26rem);
}
.msg.assistant .media {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  max-width: 34rem;
}
.thumb {
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--frost);
  border-radius: 12px;
  background: var(--rime);
}
.thumb img {
  display: block;
  width: 100%;
  height: auto;
}
.msg.user .thumb {
  max-width: 160px;
}
.media video {
  display: block;
  width: 100%;
  max-height: 70vh;
  border-radius: 12px;
  background: #000;
}

.pending {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  color: var(--slate);
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--frost);
  border-top-color: var(--signal);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    rotate: 360deg;
  }
}
.caret {
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--signal);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}
.error-box {
  margin-top: 8px;
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  border-radius: 4px 10px 10px 4px;
  background: var(--rime);
  font-size: 0.92rem;
}
.notice {
  margin-top: 8px;
  color: var(--slate);
  font-size: 0.85rem;
}

.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0.55;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions {
  opacity: 1;
}
.msg-actions .icon-btn {
  width: 30px;
  height: 30px;
}
.msg-actions .i {
  width: 16px;
  height: 16px;
}
.usage {
  align-self: center;
  margin-left: 6px;
  color: var(--slate);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- поле ввода ---------- */
.composer-wrap {
  width: 100%;
  max-width: calc(var(--col) + 40px);
  margin: 0 auto;
  padding: 0 20px max(14px, env(safe-area-inset-bottom));
}
.modes {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}
.modes button {
  position: relative;
  padding: 6px 10px 8px;
  border: 0;
  background: transparent;
  color: var(--slate);
  font-size: 0.875rem;
  font-weight: 500;
}
.modes button:hover {
  color: var(--ink);
}
.modes button[aria-selected='true'] {
  color: var(--ink);
}
.modes button[aria-selected='true']::after {
  content: '';
  position: absolute;
  right: 10px;
  bottom: 2px;
  left: 10px;
  height: 2px;
  border-radius: 1px;
  background: var(--signal);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--frost);
  border-radius: 16px;
  background: var(--paper);
}
.composer:focus-within {
  border-color: var(--slate);
}
.composer .grow {
  flex: 1;
  display: flex;
}
.composer textarea {
  flex: 1;
  max-height: 40vh;
  min-height: 36px;
  padding: 7px 4px;
  border: 0;
  background: transparent;
  resize: none;
  line-height: 1.45;
}
.composer textarea:focus {
  outline: none;
}
.send {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: var(--signal);
  color: var(--on-signal);
}
.send .i {
  stroke-width: 2.2;
}
.send:disabled {
  background: var(--rime);
  color: var(--slate);
  cursor: default;
}
.send.stop {
  background: var(--ink);
  color: var(--snow);
}
.send.stop .i {
  fill: currentColor;
  stroke: none;
}
.mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  min-height: 0;
  padding: 8px 4px 0;
  color: var(--slate);
  font-size: 0.82rem;
}
.mode-options:empty {
  padding: 0;
}
.mode-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.mode-options select {
  padding: 3px 6px;
  border: 1px solid var(--frost);
  border-radius: 8px;
  background: var(--paper);
  font-size: 0.82rem;
}
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.attachments:not(:empty) {
  margin-bottom: 8px;
}
.att {
  position: relative;
  width: 64px;
  height: 64px;
}
.att img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid var(--frost);
  border-radius: 10px;
}
.att button {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--snow);
}
.att .i {
  width: 14px;
  height: 14px;
  stroke-width: 2.4;
}
.drop-hint {
  outline: 2px dashed var(--signal);
  outline-offset: -8px;
}

/* ---------- медиа ---------- */
.gallery-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}
.gallery-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 0 20px 12px;
}
.gallery-head h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
}
.seg {
  display: flex;
  margin-left: auto;
  padding: 3px;
  border-radius: 10px;
  background: var(--rime);
}
.seg button {
  padding: 5px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--slate);
  font-size: 0.85rem;
}
.seg button[aria-selected='true'] {
  background: var(--paper);
  color: var(--ink);
  font-weight: 500;
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  align-content: start;
  gap: 6px;
  flex: 1;
  min-height: 0;
  padding: 0 20px 24px;
  overflow-y: auto;
}
.tile {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: var(--rime);
}
.tile img,
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tile .badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  padding: 1px 7px;
  border-radius: 6px;
  background: rgb(14 26 38 / 0.72);
  color: #fff;
  font-size: 0.72rem;
}
.gallery .list-empty {
  grid-column: 1 / -1;
}

/* ---------- диалоги ---------- */
dialog {
  color: var(--ink);
}
dialog::backdrop {
  background: rgb(14 26 38 / 0.45);
}
.sheet {
  width: min(32rem, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--frost);
  border-radius: 16px;
  background: var(--paper);
}
.sheet > form {
  padding: 22px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.sheet h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.25rem;
}
.sheet h3 {
  margin: 22px 0 10px;
  font-size: 0.95rem;
  font-weight: 600;
}
.wordmark.big {
  margin: 0 0 14px;
  font-size: clamp(1.6rem, 6vw, 2.1rem);
  white-space: normal;
}
.lead {
  margin: 0 0 18px;
  color: var(--slate);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
  font-size: 0.875rem;
}
.field > span {
  color: var(--slate);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--frost);
  border-radius: 10px;
  background: var(--snow);
  font-size: 0.95rem;
}
.field textarea {
  resize: vertical;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--slate);
  outline: none;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -2px 0 12px;
  font-size: 0.9rem;
}
.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--signal);
}
.more {
  margin-bottom: 12px;
  font-size: 0.875rem;
}
.more summary {
  width: fit-content;
  margin-bottom: 10px;
  color: var(--slate);
  cursor: pointer;
}
.btn,
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--frost);
  border-radius: 10px;
  background: var(--paper);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}
.btn:hover {
  border-color: var(--slate);
}
.btn-primary {
  width: 100%;
  border-color: var(--signal);
  background: var(--signal);
  color: var(--on-signal);
  font-weight: 600;
}
.row-btns .btn-primary {
  width: auto;
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}
.btn-danger {
  border-color: transparent;
  color: var(--danger);
}
.btn-danger:hover {
  border-color: var(--danger);
}
.row-btns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.row-btns.end {
  justify-content: flex-end;
  margin-top: 16px;
}
.hint {
  margin: 8px 0 0;
  color: var(--slate);
  font-size: 0.85rem;
}
.row-btns .hint {
  margin: 0;
}
.hint + .row-btns {
  margin-top: 12px;
}
.mode-options .warn {
  color: var(--danger);
}
.form-error {
  min-height: 1.4em;
  margin: 0 0 10px;
  color: var(--danger);
  font-size: 0.875rem;
}
.danger {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--frost);
}
.confirm {
  width: min(24rem, calc(100vw - 24px));
}
.confirm p {
  margin: 0;
}

.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgb(8 14 20 / 0.94);
  color: #fff;
}
.lightbox[open] {
  display: flex;
  flex-direction: column;
}
.lb-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px;
}
.lb-bar .btn {
  border-color: rgb(255 255 255 / 0.25);
  background: transparent;
  color: #fff;
}
.lb-bar .icon-btn {
  color: #fff;
}
.lb-bar .icon-btn:hover {
  background: rgb(255 255 255 / 0.12);
}
.lb-body {
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 0;
  padding: 0 12px;
}
.lb-body img,
.lb-body video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.lb-caption {
  max-width: 60rem;
  margin: 0 auto;
  padding: 10px 16px max(16px, env(safe-area-inset-bottom));
  color: rgb(255 255 255 / 0.75);
  font-size: 0.875rem;
  text-align: center;
}

.toast {
  position: fixed;
  top: max(64px, calc(env(safe-area-inset-top) + 56px));
  left: 50%;
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  translate: -50% 0;
  border-radius: 12px;
  background: var(--ink);
  color: var(--snow);
  font-size: 0.9rem;
}

/* ---------- узкие экраны ---------- */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 320px);
    padding-top: max(16px, env(safe-area-inset-top));
    translate: -100% 0;
    transition: translate 0.2s ease;
  }
  .sidebar.open {
    translate: 0 0;
    box-shadow: 0 0 0 100vmax rgb(14 26 38 / 0.4);
  }
  .scrim {
    position: fixed;
    inset: 0;
    z-index: 29;
  }
  .only-narrow {
    display: inline-grid;
  }
  .topbar {
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  }
  .messages {
    padding: 4px 14px 20px;
  }
  .composer-wrap {
    padding-inline: 10px;
  }
  .gallery,
  .gallery-head {
    padding-inline: 12px;
  }
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
  .chat-item-actions {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}
