/* ─── Темы ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #faf9f5;
  --bg-sidebar: #f5f4ed;
  --surface: #ffffff;
  --surface-2: #f0eee6;
  --surface-3: #e8e6dc;
  --user-bubble: #f0eee6;
  --border: rgba(31, 30, 29, 0.13);
  --border-strong: rgba(31, 30, 29, 0.22);
  --text: #1f1e1d;
  --text-2: #5e5d59;
  --text-3: #8a8780;
  --accent: #c96442;
  --accent-hover: #b4573a;
  --accent-soft: rgba(201, 100, 66, 0.12);
  --accent-text: #ffffff;
  --danger: #b53333;
  --code-bg: #f6f5f0;
  --code-border: rgba(31, 30, 29, 0.1);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.14);
  --backdrop: rgba(20, 20, 19, 0.35);
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Source Serif 4", ui-serif, "New York", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --font-answer: var(--font-serif);
  --radius: 16px;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --app-height: var(--tg-viewport-height, 100dvh);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #262624;
  --bg-sidebar: #1f1e1d;
  --surface: #30302e;
  --surface-2: #383835;
  --surface-3: #42413e;
  --user-bubble: #141413;
  --border: rgba(222, 220, 209, 0.13);
  --border-strong: rgba(222, 220, 209, 0.24);
  --text: #f5f4ef;
  --text-2: #c2c0b6;
  --text-3: #8f8d86;
  --accent: #c96442;
  --accent-hover: #d9775a;
  --accent-soft: rgba(217, 119, 87, 0.18);
  --danger: #e06c6c;
  --code-bg: #1f1e1d;
  --code-border: rgba(222, 220, 209, 0.1);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.45);
  --backdrop: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

:root[data-font="sans"] {
  --font-answer: var(--font-ui);
}

/* ─── Основа ───────────────────────────────────────────────────────────── */
[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

input,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

svg {
  display: block;
  flex: none;
}

.app {
  position: fixed;
  inset: 0;
  height: var(--app-height);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:active,
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.mark {
  width: 28px;
  height: 28px;
  background: url("img/mark.svg") center / contain no-repeat;
  flex: none;
}

/* ─── Заставка ─────────────────────────────────────────────────────────── */
.splash {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: var(--bg);
  z-index: 50;
  transition: opacity 0.25s;
}

/* Значок в кольце: дорожка и бегущая дуга. */
.splash-ring {
  position: relative;
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
}

.splash-ring svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  animation: spin 1.1s linear infinite;
}

.splash-ring .track {
  stroke: var(--surface-3);
}

.splash-ring .arc {
  stroke: var(--accent);
}

.splash-mark {
  width: 44px;
  height: 44px;
  background: url("img/mark.svg") center / contain no-repeat;
  animation: pulse 1.8s ease-in-out infinite;
}

.splash-text {
  font-size: 15px;
  color: var(--text-2);
  letter-spacing: 0.01em;
}

/* Три точки появляются по очереди. */
.splash-text .dots span {
  opacity: 0;
  animation: dot 1.4s infinite;
}

.splash-text .dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.splash-text .dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot {
  0%, 20% { opacity: 0; }
  40%, 100% { opacity: 1; }
}

.splash.hidden {
  opacity: 0;
  pointer-events: none;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.88); opacity: 0.7; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Шапка ────────────────────────────────────────────────────────────── */
.header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  min-height: 52px;
  background: var(--bg);
  position: relative;
  z-index: 5;
}

.header.scrolled {
  box-shadow: 0 1px 0 var(--border);
}

.header-title {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.header-title button {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.header-title button:active {
  background: var(--surface-2);
}

.header-title .title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-title .chev {
  color: var(--text-3);
}

.plan-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

.plan-pill b {
  color: var(--accent);
  font-weight: 600;
}

/* ─── Лента сообщений ─────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

#view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.scroller {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.thread {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin-left: 12%;
}

.bubble {
  background: var(--user-bubble);
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.msg-actions {
  display: flex;
  gap: 2px;
  color: var(--text-3);
  min-height: 32px;
  align-items: center;
}

.msg-actions .icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-3);
}

.msg-user .msg-actions {
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  min-height: 0;
  height: 0;
  overflow: hidden;
}

.msg-user.show-actions .msg-actions {
  opacity: 1;
  pointer-events: auto;
  height: 32px;
}

.msg-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-left: auto;
  padding-right: 4px;
}

.edit-box {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.edit-box textarea {
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.45;
  max-height: 40vh;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text);
}

.btn:active {
  filter: brightness(0.96);
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
}

.btn-accent {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
}

.btn-block {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  font-size: 15px;
}

.btn-danger {
  color: var(--danger);
}

/* Вложения в сообщении */
.msg-files {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 100%;
}

.msg-files img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 240px;
  padding: 8px 12px 8px 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left;
}

.file-card .file-ico {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: none;
}

.file-card .file-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card .file-sub {
  font-size: 12px;
  color: var(--text-3);
}

.file-card > div:last-child {
  min-width: 0;
}

/* Ответ Claude */
.msg-assistant {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.answer {
  font-family: var(--font-answer);
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--text);
  overflow-wrap: anywhere;
}

:root[data-font="sans"] .answer {
  font-size: 16px;
  line-height: 1.6;
}

.answer > :first-child {
  margin-top: 0;
}

.answer > :last-child {
  margin-bottom: 0;
}

.answer p {
  margin: 0 0 0.85em;
}

.answer h1,
.answer h2,
.answer h3,
.answer h4 {
  font-family: var(--font-answer);
  font-weight: 600;
  line-height: 1.3;
  margin: 1.2em 0 0.5em;
}

.answer h1 { font-size: 1.4em; }
.answer h2 { font-size: 1.22em; }
.answer h3 { font-size: 1.08em; }
.answer h4 { font-size: 1em; }

.answer ul,
.answer ol {
  margin: 0 0 0.85em;
  padding-left: 1.5em;
}

.answer li {
  margin: 0.25em 0;
}

.answer li > p {
  margin: 0;
}

.answer li > ul,
.answer li > ol {
  margin: 0.2em 0;
}

.answer li.task {
  list-style: none;
  margin-left: -1.3em;
}

.answer li.task input {
  margin: 0 0.4em 0 0;
  vertical-align: -1px;
}

.answer blockquote {
  margin: 0 0 0.85em;
  padding: 0.1em 0 0.1em 1em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-2);
}

.answer hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.4em 0;
}

.answer a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.answer strong {
  font-weight: 600;
}

.answer code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  padding: 0.08em 0.35em;
  color: var(--danger);
}

:root[data-theme="dark"] .answer code:not(pre code) {
  color: #f0a58c;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 0 0.85em;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.answer table {
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 14px;
  min-width: 100%;
}

.answer th,
.answer td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.answer th {
  font-weight: 600;
  background: var(--surface-2);
}

.answer tr:last-child td {
  border-bottom: 0;
}

/* Блок кода */
.code-block {
  margin: 0 0 0.85em;
  border-radius: 12px;
  border: 1px solid var(--code-border);
  background: var(--code-bg);
  overflow: hidden;
  font-family: var(--font-ui);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 4px 14px;
  font-size: 12px;
  color: var(--text-3);
  border-bottom: 1px solid var(--code-border);
}

.code-head .code-tools {
  display: flex;
  gap: 2px;
}

.code-head button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--text-2);
}

.code-head button:active {
  background: var(--surface-2);
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.code-block code {
  font-family: inherit;
  white-space: pre;
}

.tok-k { color: #a626a4; }
.tok-s { color: #50a14f; }
.tok-c { color: #a0a1a7; font-style: italic; }
.tok-n { color: #986801; }
.tok-f { color: #4078f2; }
.tok-t { color: #c18401; }
:root[data-theme="dark"] .tok-k { color: #c678dd; }
:root[data-theme="dark"] .tok-s { color: #98c379; }
:root[data-theme="dark"] .tok-c { color: #7f848e; }
:root[data-theme="dark"] .tok-n { color: #d19a66; }
:root[data-theme="dark"] .tok-f { color: #61afef; }
:root[data-theme="dark"] .tok-t { color: #e5c07b; }

/* Формулы */
.math-block {
  overflow-x: auto;
  margin: 0 0 0.85em;
  text-align: center;
}

.math-raw {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--text-2);
}

/* Рассуждение */
.thinking {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  font-family: var(--font-ui);
  margin-bottom: 4px;
}

.thinking-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-2);
  text-align: left;
}

.thinking-head .chev {
  margin-left: auto;
  transition: transform 0.2s;
  color: var(--text-3);
}

.thinking.open .thinking-head .chev {
  transform: rotate(180deg);
}

.thinking-body {
  display: none;
  padding: 0 14px 12px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-2);
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

.thinking.open .thinking-body {
  display: block;
}

.thinking.live .thinking-label {
  background: linear-gradient(90deg, var(--text-3) 0%, var(--text) 50%, var(--text-3) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 1.6s linear infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.typing-mark {
  width: 26px;
  height: 26px;
  margin-top: 4px;
  background: url("img/mark.svg") center / contain no-repeat;
  animation: pulse 1.2s ease-in-out infinite;
}

.assistant-foot {
  display: flex;
  align-items: center;
  gap: 2px;
  color: var(--text-3);
  margin-left: -6px;
}

.assistant-foot .icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-3);
}

.stopped-note {
  font-size: 13px;
  color: var(--text-3);
  font-style: italic;
  font-family: var(--font-ui);
}

.error-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(181, 51, 51, 0.08);
  border: 1px solid rgba(181, 51, 51, 0.2);
  color: var(--text);
  font-size: 14px;
}

.error-card .btn {
  margin-left: auto;
  flex: none;
}

/* Приветствие */
.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 20px 40px;
  text-align: center;
}

.greeting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(26px, 7.5vw, 38px);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
  color: var(--text);
}

.greeting .mark {
  width: 34px;
  height: 34px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 520px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  color: var(--text-2);
}

.chip.active {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-2);
}

.chip svg {
  color: var(--text-3);
}

.prompt-list {
  width: 100%;
  max-width: 520px;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
}

.prompt-list button {
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-2);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.prompt-list button:last-child {
  border-bottom: 0;
}

.prompt-list button:active {
  background: var(--surface-2);
}

.to-bottom {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.to-bottom.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Поле ввода ──────────────────────────────────────────────────────── */
.composer-wrap {
  flex: none;
  padding: 0 12px calc(var(--safe-bottom) + 6px);
  background: var(--bg);
}

.composer {
  max-width: 760px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 10px 10px 8px 14px;
  transition: border-color 0.15s;
}

.composer:focus-within {
  border-color: var(--border-strong);
}

.composer textarea {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.45;
  padding: 2px 0 6px;
  max-height: 38vh;
  min-height: 26px;
}

.composer textarea::placeholder {
  color: var(--text-3);
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: -4px;
}

.composer-row .spacer {
  flex: 1;
}

.tool-btn {
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
}

.tool-btn:active {
  background: var(--surface-2);
}

.tool-btn.on {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-soft);
}

.model-btn {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px 0 10px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--text-2);
  max-width: 48vw;
}

.model-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-btn:active {
  background: var(--surface-2);
}

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  transition: opacity 0.15s, transform 0.1s;
}

.send-btn:active {
  transform: scale(0.94);
}

.send-btn:disabled {
  opacity: 0.35;
}

.send-btn.stop {
  background: var(--text);
  color: var(--bg);
}

.disclaimer {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
  padding: 6px 8px 0;
}

.pending-files {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  margin-right: -4px;
}

.pending {
  position: relative;
  flex: none;
}

.pending img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}

.pending .file-card {
  height: 64px;
  max-width: 200px;
}

.pending .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.pending .uploading {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
}

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.spinner.dark {
  border-color: var(--border-strong);
  border-top-color: var(--text);
}

/* ─── Боковая панель ──────────────────────────────────────────────────── */
.backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 20;
}

.backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(86vw, 330px);
  height: var(--app-height);
  background: var(--bg-sidebar);
  z-index: 21;
  transform: translateX(-102%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.28s;
}

.sidebar.open {
  transform: none;
  visibility: visible;
  box-shadow: var(--shadow-lg);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 6px 18px;
}

.wordmark {
  font-family: var(--font-serif);
  font-size: 23px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.new-chat {
  margin: 6px 10px 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
}

.new-chat .plus {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

.new-chat:active {
  background: var(--surface-2);
}

.side-search {
  margin: 4px 12px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-3);
}

.side-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 15px;
}

.side-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  overscroll-behavior: contain;
}

.side-section {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-3);
  padding: 14px 10px 6px;
}

.side-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14.5px;
  color: var(--text);
  text-align: left;
}

.side-item span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-item.active {
  background: var(--surface-3);
}

.side-item:active {
  background: var(--surface-2);
}

.side-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 14px;
  color: var(--text-3);
}

.side-foot {
  border-top: 1px solid var(--border);
  padding: 10px 10px calc(var(--safe-bottom) + 10px);
}

.profile {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  text-align: left;
}

.profile:active {
  background: var(--surface-2);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  flex: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile .p-name {
  font-size: 14.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile .p-plan {
  font-size: 12.5px;
  color: var(--text-3);
}

.profile > div:not(.avatar) {
  min-width: 0;
  flex: 1;
}

/* ─── Нижние листы ────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(var(--app-height) - var(--safe-top) - 40px);
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  z-index: 31;
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  margin: 0 auto;
}

.sheet.open {
  transform: none;
}

.sheet-backdrop {
  z-index: 30;
}

.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--border-strong);
  margin: 8px auto 4px;
  flex: none;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 8px 20px;
  flex: none;
}

.sheet-title {
  font-size: 17px;
  font-weight: 600;
}

.sheet-body {
  overflow-y: auto;
  padding: 0 16px calc(var(--safe-bottom) + 16px);
  overscroll-behavior: contain;
}

.menu {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 12px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  font-size: 15px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.menu-item:last-child {
  border-bottom: 0;
}

.menu-item:active {
  background: var(--surface-2);
}

.menu-item svg {
  color: var(--text-2);
}

.menu-item .mi-text {
  flex: 1;
  min-width: 0;
}

.menu-item .mi-sub {
  display: block;
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 1px;
}

.menu-item .mi-right {
  color: var(--text-3);
  font-size: 14px;
}

.menu-item.danger,
.menu-item.danger svg {
  color: var(--danger);
}

.check {
  color: var(--accent);
}

.lock {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 7px;
  font-weight: 500;
}

.switch {
  width: 46px;
  height: 28px;
  border-radius: 14px;
  background: var(--surface-3);
  position: relative;
  transition: background 0.2s;
  flex: none;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.switch.on {
  background: var(--accent);
}

.switch.on::after {
  transform: translateX(18px);
}

.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-2);
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.field-label {
  font-size: 13px;
  color: var(--text-3);
  margin: 4px 4px 6px;
}

.text-input {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 0 14px;
  font-size: 16px;
  outline: 0;
  margin-bottom: 12px;
}

.text-input:focus {
  border-color: var(--accent);
}

/* Тарифы */
.usage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.usage-card .u-title {
  font-size: 14px;
  color: var(--text-2);
}

.usage-card .u-value {
  font-size: 20px;
  font-weight: 600;
  margin: 2px 0 8px;
}

.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
}

.bar > div {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

.usage-card .u-sub {
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 8px;
}

.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

.plan-card.featured {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}

.plan-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.plan-name {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
}

.plan-price {
  font-size: 15px;
  color: var(--text-2);
  white-space: nowrap;
}

.plan-price b {
  font-size: 20px;
  color: var(--text);
}

.plan-badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: 3px;
  font-family: var(--font-ui);
}

.perks {
  list-style: none;
  padding: 0;
  margin: 10px 0 14px;
  font-size: 14px;
  color: var(--text-2);
}

.perks li {
  display: flex;
  gap: 8px;
  padding: 3px 0;
}

.perks li svg {
  color: var(--accent);
  margin-top: 3px;
}

.pay-row {
  display: flex;
  gap: 8px;
}

.pay-row .btn {
  flex: 1;
  height: 44px;
  border-radius: 12px;
}

.fine {
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  margin: 6px 8px 4px;
  line-height: 1.45;
}

.fine a {
  color: var(--text-2);
}

/* Просмотр картинки и предпросмотр кода */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.viewer.open {
  opacity: 1;
  pointer-events: auto;
}

.viewer img {
  flex: 1;
  min-height: 0;
  object-fit: contain;
  width: 100%;
}

.viewer .viewer-close {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  right: 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 50%;
}

.artifact {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding-top: var(--safe-top);
}

.artifact.open {
  transform: none;
}

.artifact-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.artifact-head .a-title {
  flex: 1;
  font-weight: 500;
  font-size: 15px;
}

.artifact iframe {
  flex: 1;
  border: 0;
  width: 100%;
  background: #fff;
}

.artifact .segmented {
  width: 180px;
}

.artifact pre {
  flex: 1;
  margin: 0;
  overflow: auto;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--code-bg);
}

/* Тост */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 12px);
  transform: translate(-50%, -20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Экран «откройте в Telegram» */
.gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  gap: 14px;
}

.gate h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 28px;
  margin: 8px 0 0;
}

.gate p {
  color: var(--text-2);
  margin: 0;
  max-width: 340px;
}

@media (min-width: 900px) {
  .thread {
    padding-left: 24px;
    padding-right: 24px;
  }
}

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