/* ============================================================
   FZX AI — стилі
   Нежна голубо-біла палітра, спокійні тіні, повна адаптація
   під Telegram WebApp + світла/темна тема.
   ============================================================ */

/* ---------- Токени теми ---------- */
:root {
  --bg: #f3f7fc;
  --bg-soft: #eaf1f9;
  --surface: #ffffff;
  --surface-2: #f7fafd;
  --surface-3: #eef4fb;
  --border: #e2ebf5;
  --border-strong: #cfdeef;

  --text: #182a45;
  --text-soft: #43536e;
  --muted: #7b8ba3;

  --accent: #5b9fdd;
  --accent-strong: #3f86c9;
  --accent-soft: #e9f2fc;
  --accent-ink: #2f6ea9;
  --on-accent: #ffffff;

  --danger: #cc5b56;
  --danger-soft: #fdeeee;

  --shadow-sm: 0 1px 2px rgba(30, 58, 95, 0.05);
  --shadow-md: 0 6px 18px rgba(30, 58, 95, 0.06);
  --shadow-lg: 0 10px 28px rgba(30, 58, 95, 0.09);

  --radius-lg: 22px;
  --radius-md: 15px;
  --radius-sm: 10px;

  --topbar-h: 58px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

[data-theme='dark'] {
  --bg: #000000;
  --bg-soft: #050505;
  --surface: #0c0c0c;
  --surface-2: #141414;
  --surface-3: #1e1e1e;
  --border: #222222;
  --border-strong: #363636;

  --text: #f7f7f7;
  --text-soft: #c6c6c6;
  --muted: #8f8f8f;

  --accent: #ededed;
  --accent-strong: #ffffff;
  --accent-soft: #171717;
  --accent-ink: #e2e2e2;
  --on-accent: #000000;

  --danger: #e08080;
  --danger-soft: #231414;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.65);
}

/* ---------- База ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body.theme-anim,
body.theme-anim * {
  transition: background-color 0.35s var(--ease), border-color 0.35s var(--ease),
    color 0.35s var(--ease), fill 0.35s var(--ease), stroke 0.35s var(--ease) !important;
}

button {
  font-family: inherit;
  cursor: pointer;
}

::selection {
  background: color-mix(in srgb, var(--accent) 32%, transparent);
}

/* ---------- Каркас ---------- */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  overflow: hidden;
}

/* ---------- Верхня панель ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(9px + var(--tg-safe-top, 0px)) 16px 9px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand__name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.75;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Кнопки ---------- */
.btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease),
    border-color 0.18s var(--ease), transform 0.12s var(--ease), box-shadow 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.96);
}

.btn--new {
  height: 38px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 22%, transparent);
}

.btn--new:hover {
  background: color-mix(in srgb, var(--accent) 16%, var(--accent-soft));
}

.btn--new:active {
  background: color-mix(in srgb, var(--accent) 24%, var(--accent-soft));
}

.btn--icon {
  width: 38px;
  height: 38px;
  color: var(--text-soft);
  background: var(--surface-2);
  border-color: var(--border);
  position: relative;
}

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

/* Іконки сонце/місяць — плавне перемикання */
.btn--icon .icon-sun,
.btn--icon .icon-moon {
  position: absolute;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}

[data-theme='light'] .icon-moon {
  opacity: 0;
  transform: rotate(-30deg) scale(0.6);
}

[data-theme='dark'] .icon-sun {
  opacity: 0;
  transform: rotate(30deg) scale(0.6);
}

/* ---------- Область вкладок ---------- */
.content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- Область чату ---------- */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.chat::-webkit-scrollbar {
  width: 8px;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.chat__inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 16px 28px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Стартовий екран ---------- */
.welcome {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 30px 6px 10px;
  position: relative;
  animation: welcomeIn 0.6s var(--ease) both;
}

.welcome__glow {
  display: none;
}

.welcome__title {
  margin: 0;
  font-size: clamp(24px, 6vw, 30px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.welcome__subtitle {
  margin: 10px 0 0;
  max-width: 30em;
  color: var(--text-soft);
  font-size: 15px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin-top: 26px;
}

.suggestion {
  text-align: left;
  padding: 13px 15px;
  font-size: 14px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease),
    transform 0.16s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.suggestion:hover {
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.suggestion:active {
  transform: scale(0.975);
}

/* ---------- Повідомлення ---------- */
.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  display: flex;
  animation: msgIn 0.34s var(--ease) both;
}

.message--user {
  justify-content: flex-end;
}

.message--ai {
  justify-content: flex-start;
}

.bubble {
  max-width: 88%;
  border-radius: var(--radius-lg);
  font-size: 15.5px;
  overflow-wrap: anywhere;
}

.bubble--user {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 130%);
  color: var(--on-accent);
  padding: 11px 15px;
  border-bottom-right-radius: 8px;
  box-shadow: var(--shadow-sm);
  white-space: pre-wrap;
}

.bubble--ai {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-bottom-left-radius: 8px;
  box-shadow: var(--shadow-sm);
  width: 100%;
  max-width: 100%;
}

/* ---------- Markdown-вміст відповіді ---------- */
.md {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.md > * {
  margin: 0;
}

.md p {
  color: var(--text);
}

.md h3,
.md h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: 0;
  margin-top: 2px;
}

/* Розділи відповіді (1. Відповідь, 2. Як розв'язати…) — чітко поділені лінією */
.md h3 {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.md h3:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.md h4 {
  font-size: 14.5px;
}

.md strong {
  font-weight: 700;
  color: var(--text);
}

.md em {
  font-style: italic;
}

.md ul,
.md ol {
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.md li {
  color: var(--text);
}

.md li::marker {
  color: var(--accent);
}

.md code {
  font-family: 'SFMono-Regular', ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
}

.md pre {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.5;
}

.md pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13.5px;
}

.md a {
  color: var(--accent-ink);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

.md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* ---------- Картки-секції відповіді (Відповідь, Правило, Зошит…) ---------- */
.ans-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  overflow: hidden;
}

.ans-card__head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-bottom: 1px solid var(--border);
}

.ans-card__icon {
  display: inline-flex;
  flex: 0 0 auto;
}

.ans-card--answer .ans-card__head {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-color: transparent;
}

.ans-card__body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 11px 13px;
}

.ans-card__body > * {
  margin: 0;
}

/* Легка каскадна поява блоків відповіді */
.md .block-in:nth-child(2) {
  animation-delay: 0.05s;
}

.md .block-in:nth-child(3) {
  animation-delay: 0.1s;
}

.md .block-in:nth-child(4) {
  animation-delay: 0.15s;
}

.md .block-in:nth-child(5) {
  animation-delay: 0.2s;
}

.md .block-in:nth-child(n + 6) {
  animation-delay: 0.25s;
}

/* Математичні формули (KaTeX) */
.md .katex-display {
  margin: 10px 0;
  padding: 2px;
  overflow-x: auto;
  overflow-y: hidden;
}

.md .katex {
  font-size: 1.04em;
  color: inherit;
}

/* Поступова поява блоків відповіді */
.md .block-in {
  animation: blockIn 0.42s var(--ease) both;
}

/* Курсор під час потокової відповіді */
.md.is-streaming > *:last-child::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--accent);
  border-radius: 2px;
  animation: caret 1s steps(2, start) infinite;
}

/* ---------- Індикатор мислення: лоадер Uiverse (SchawnnahJ), відтінки голубого ---------- */
.thinking {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 2px 0;
}

.thinking__head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.think-loader {
  position: relative;
  width: 2.5em;
  height: 2.5em;
  font-size: 12px;
  flex: 0 0 auto;
  transform: rotate(165deg);
}

.think-loader::before,
.think-loader::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: 0.5em;
  height: 0.5em;
  border-radius: 0.25em;
  transform: translate(-50%, -50%);
}

.think-loader::before {
  animation: thinkBefore 2s infinite;
}

.think-loader::after {
  animation: thinkAfter 2s infinite;
}

.thinking__phase {
  font-size: 14px;
  color: var(--text-soft);
  font-weight: 500;
}

.thinking__phase span {
  display: inline-block;
  animation: phaseIn 0.4s var(--ease) both;
}

/* ---------- Вкладення ---------- */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 4px 10px;
}

.attachments[hidden] {
  display: none;
}

.attach-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 220px;
  padding: 6px 8px 6px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: blockIn 0.34s var(--ease) both;
}

.attach-chip__thumb {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 auto;
  background: var(--surface-3);
}

.attach-chip__fileicon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
}

.attach-chip__meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.attach-chip__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-chip__size {
  font-size: 11.5px;
  color: var(--muted);
}

.attach-chip__remove {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease);
}

.attach-chip__remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Вкладення всередині повідомлення користувача */
.msg-attach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 8px;
}

.msg-attach {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px 4px 4px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 9px;
  font-size: 12.5px;
}

.msg-attach img {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  object-fit: cover;
}

.msg-attach__name {
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* У темній темі пузир користувача білий — вкладення мають бути темними */
[data-theme='dark'] .msg-attach {
  background: rgba(0, 0, 0, 0.07);
  border-color: rgba(0, 0, 0, 0.2);
}

/* ---------- Профіль ---------- */
.profile {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.profile__inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: welcomeIn 0.5s var(--ease) both;
}

.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.profile-card__title {
  margin: 0 0 6px;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 24px;
  font-weight: 700;
  overflow: hidden;
}

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

.avatar img[hidden] {
  display: none;
}

.user-card__name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.user-card__nick {
  margin-top: 2px;
  font-size: 13.5px;
  color: var(--muted);
}

.quota-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 15px;
  color: var(--text-soft);
}

.quota-row + .quota-row {
  border-top: 1px solid var(--border);
}

.quota-row b {
  font-weight: 700;
  color: var(--text);
  text-align: right;
}

.quota-row .mono {
  font-family: 'SFMono-Regular', ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
}

.quota-hint {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------- Нижні вкладки: плавучий острівець ---------- */
.tabbar {
  flex: 0 0 auto;
  align-self: center;
  display: flex;
  gap: 2px;
  margin: 0 12px calc(10px + var(--tg-safe-bottom, 0px) + env(safe-area-inset-bottom, 0px));
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 15;
}

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease),
    transform 0.12s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.tab:active {
  transform: scale(0.96);
}

.tab.is-active {
  background: var(--text);
  color: var(--bg);
}

/* ---------- Панель вводу ---------- */
.composer-wrap {
  flex: 0 0 auto;
  padding: 0 12px 8px;
  background: linear-gradient(180deg, transparent, var(--bg) 34%);
  z-index: 15;
}

.composer-wrap[hidden] {
  display: none;
}

.composer {
  max-width: 780px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 8px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.composer.is-focused {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow-lg);
}

.composer__row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.composer__attach {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  color: var(--text-soft);
}

.composer__input {
  flex: 1 1 auto;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15.5px;
  line-height: 1.5;
  resize: none;
  padding: 9px 4px;
  max-height: 148px;
  min-height: 22px;
  overflow-y: auto;
  scrollbar-width: none;
}

.composer__input::-webkit-scrollbar {
  display: none;
}

.composer__input::placeholder {
  color: var(--muted);
}

.btn--send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent);
}

.btn--send:hover {
  background: var(--accent-strong);
}

.btn--send:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
  transform: none;
}

.btn--send.is-stop {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: none;
}

.composer__tools {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 7px 4px 1px;
}

/* Перемикач глибокого мислення */
.think-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease),
    border-color 0.2s var(--ease);
}

.think-toggle__track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background-color 0.24s var(--ease);
}

.think-toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.24s var(--ease);
}

.think-toggle[aria-checked='true'] {
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
}

.think-toggle[aria-checked='true'] .think-toggle__track {
  background: var(--accent);
}

.think-toggle[aria-checked='true'] .think-toggle__thumb {
  transform: translateX(14px);
}

/* ---------- Підпис-попередження ---------- */
.disclaimer {
  max-width: 780px;
  margin: 8px auto 2px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

/* ---------- Помилка та повтор ---------- */
.error-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.error-box__text {
  color: var(--danger);
  font-size: 14.5px;
}

.btn--retry {
  height: 34px;
  padding: 0 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
}

.btn--retry:hover {
  background: color-mix(in srgb, var(--accent) 16%, var(--accent-soft));
}

.btn--retry:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ---------- Меню вкладень ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 28, 44, 0.42);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.22s var(--ease);
  z-index: 40;
}

.sheet-backdrop.is-open {
  opacity: 1;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: calc(12px + var(--tg-safe-bottom, 0px) + env(safe-area-inset-bottom, 0px));
  width: min(420px, calc(100vw - 24px));
  transform: translate(-50%, 20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 41;
  opacity: 0;
  transition: opacity 0.22s var(--ease), transform 0.26s var(--ease);
}

.sheet.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sheet__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  transition: background-color 0.16s var(--ease);
}

.sheet__item:hover {
  background: var(--surface-2);
}

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

.sheet__item svg {
  color: var(--accent-ink);
  flex: 0 0 auto;
}

.sheet__hint {
  padding: 6px 12px 10px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Тост ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(200px + var(--tg-safe-bottom, 0px) + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px);
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  z-index: 60;
  text-align: center;
}

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

/* ---------- Анімації ---------- */
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blockIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes welcomeIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes phaseIn {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes thinkBefore {
  0% {
    width: 0.5em;
    box-shadow: 1em -0.5em rgba(63, 134, 201, 0.85), -1em 0.5em rgba(147, 197, 253, 0.85);
  }

  35% {
    width: 2.5em;
    box-shadow: 0 -0.5em rgba(63, 134, 201, 0.85), 0 0.5em rgba(147, 197, 253, 0.85);
  }

  70% {
    width: 0.5em;
    box-shadow: -1em -0.5em rgba(63, 134, 201, 0.85), 1em 0.5em rgba(147, 197, 253, 0.85);
  }

  100% {
    box-shadow: 1em -0.5em rgba(63, 134, 201, 0.85), -1em 0.5em rgba(147, 197, 253, 0.85);
  }
}

@keyframes thinkAfter {
  0% {
    height: 0.5em;
    box-shadow: 0.5em 1em rgba(91, 159, 221, 0.85), -0.5em -1em rgba(191, 219, 254, 0.85);
  }

  35% {
    height: 2.5em;
    box-shadow: 0.5em 0 rgba(91, 159, 221, 0.85), -0.5em 0 rgba(191, 219, 254, 0.85);
  }

  70% {
    height: 0.5em;
    box-shadow: 0.5em -1em rgba(91, 159, 221, 0.85), -0.5em 1em rgba(191, 219, 254, 0.85);
  }

  100% {
    box-shadow: 0.5em 1em rgba(91, 159, 221, 0.85), -0.5em -1em rgba(191, 219, 254, 0.85);
  }
}

@keyframes caret {
  0%,
  50% {
    opacity: 1;
  }
  51%,
  100% {
    opacity: 0;
  }
}

/* ---------- Малі екрани ---------- */
@media (max-width: 460px) {
  body {
    font-size: 15px;
  }

  .suggestions {
    grid-template-columns: 1fr;
    max-width: 100%;
  }

  .chat__inner {
    padding: 16px 12px 22px;
  }

  .bubble--user {
    max-width: 90%;
  }
}

@media (min-width: 900px) {
  .chat__inner {
    padding-top: 28px;
  }
}

/* ---------- Повага до системного зменшення анімацій ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .md.is-streaming > *:last-child::after {
    animation: none;
  }
}
