/* ============================================================
   Рыбак всемогущий — «глубоководный премиум»
   Тёмная тема, биолюминесценция, лучи света, пузырьки.
   Все анимации — только transform/opacity (60fps).
   ============================================================ */

:root {
  /* Палитра «глубокая вода» */
  --bg-top: #0b1f38;
  --bg-mid: #081426;
  --bg-deep: #050b16;
  --bg: #081120;
  --surface: rgba(16, 30, 52, 0.72);
  --surface-strong: rgba(13, 25, 44, 0.94);
  --border: rgba(125, 170, 220, 0.14);
  --border-strong: rgba(125, 170, 220, 0.26);

  --text: #e8f0fa;
  --text-secondary: #93a8c4;
  --text-tertiary: #74879f; /* 5.1:1 на фоне — WCAG AA для мелкого текста */

  --primary: #38bdf8;
  --cyan: #22d3ee;
  --accent: #2dd4bf;
  --violet: #818cf8;
  --danger: #f87171;

  --bubble-user: linear-gradient(135deg, #2563eb 0%, #0ea5e9 60%, #0891b2 100%);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-soft: 0 8px 32px rgba(2, 8, 20, 0.55);
  --glow: 0 0 24px rgba(56, 189, 248, 0.25);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Unbounded', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  /* градиент глубины: светлее у «поверхности», темнее на «дне» */
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 45%, var(--bg-deep) 100%) fixed var(--bg-deep);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh; /* fallback для старых WebView */
  height: 100dvh;
  height: var(--tg-viewport-stable-height, 100dvh); /* поддерживается telegram-web-app.js */
  max-width: 720px;
  margin: 0 auto;
  overflow: hidden;
}

/* ============================================================
   Подводная атмосфера
   ============================================================ */
.ambient {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

/* Лучи света сквозь толщу воды */
.ray {
  position: absolute;
  top: -18%;
  height: 75vh;
  background: linear-gradient(180deg, rgba(148, 210, 255, 0.14), rgba(148, 210, 255, 0) 82%);
  filter: blur(22px);
  transform-origin: top center;
  mix-blend-mode: screen;
}
.ray-1 { left: 6%;  width: 170px; animation: ray-sway-1 14s ease-in-out infinite alternate; }
.ray-2 { left: 38%; width: 260px; opacity: 0.75; animation: ray-sway-2 19s ease-in-out infinite alternate; }
.ray-3 { right: 2%; width: 130px; opacity: 0.85; animation: ray-sway-3 16s ease-in-out infinite alternate; }
@keyframes ray-sway-1 {
  from { transform: rotate(12deg) translateX(-14px); }
  to   { transform: rotate(17deg) translateX(12px); }
}
@keyframes ray-sway-2 {
  from { transform: rotate(6deg) translateX(16px); }
  to   { transform: rotate(10deg) translateX(-18px); }
}
@keyframes ray-sway-3 {
  from { transform: rotate(-14deg) translateX(10px); }
  to   { transform: rotate(-9deg) translateX(-12px); }
}

/* Биолюминесцентные блики */
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
}
.blob-1 {
  width: 360px; height: 360px;
  top: -130px; left: -90px;
  background: radial-gradient(circle, #10456e 0%, transparent 70%);
  animation: drift-1 24s ease-in-out infinite alternate;
}
.blob-2 {
  width: 320px; height: 320px;
  bottom: 8%; right: -130px;
  background: radial-gradient(circle, #0f4a4a 0%, transparent 70%);
  animation: drift-2 30s ease-in-out infinite alternate;
}
.blob-3 {
  width: 240px; height: 240px;
  top: 38%; left: 28%;
  background: radial-gradient(circle, #1e2a6e 0%, transparent 70%);
  opacity: 0.35;
  animation: drift-1 36s ease-in-out infinite alternate-reverse;
}
@keyframes drift-1 {
  from { transform: translate(0, 0); }
  to   { transform: translate(48px, 36px); }
}
@keyframes drift-2 {
  from { transform: translate(0, 0); }
  to   { transform: translate(-40px, -30px); }
}

/* Всплывающие пузырьки */
.bubbles span {
  position: absolute;
  bottom: -40px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(200, 235, 255, 0.85), rgba(125, 211, 252, 0.08) 68%);
  opacity: 0;
  animation: rise linear infinite;
}
.bubbles span:nth-child(1)  { left: 8%;  width: 5px;  height: 5px;  animation-duration: 13s; animation-delay: 0s; }
.bubbles span:nth-child(2)  { left: 18%; width: 8px;  height: 8px;  animation-duration: 17s; animation-delay: 3s; }
.bubbles span:nth-child(3)  { left: 29%; width: 4px;  height: 4px;  animation-duration: 11s; animation-delay: 6s; }
.bubbles span:nth-child(4)  { left: 41%; width: 6px;  height: 6px;  animation-duration: 19s; animation-delay: 1.5s; }
.bubbles span:nth-child(5)  { left: 52%; width: 9px;  height: 9px;  animation-duration: 15s; animation-delay: 8s; }
.bubbles span:nth-child(6)  { left: 63%; width: 4px;  height: 4px;  animation-duration: 12s; animation-delay: 4.5s; }
.bubbles span:nth-child(7)  { left: 72%; width: 7px;  height: 7px;  animation-duration: 18s; animation-delay: 10s; }
.bubbles span:nth-child(8)  { left: 81%; width: 5px;  height: 5px;  animation-duration: 14s; animation-delay: 2s; }
.bubbles span:nth-child(9)  { left: 90%; width: 6px;  height: 6px;  animation-duration: 16s; animation-delay: 7s; }
.bubbles span:nth-child(10) { left: 96%; width: 4px;  height: 4px;  animation-duration: 12s; animation-delay: 11s; }
@keyframes rise {
  0%   { transform: translate(0, 0); opacity: 0; }
  6%   { opacity: 0.75; }
  85%  { opacity: 0.45; }
  100% { transform: translate(22px, -108vh); opacity: 0; }
}

/* Плёнка «зерна» для глубины картинки */
.grain {
  position: absolute;
  inset: 0;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================================================
   Стекло
   ============================================================ */
.glass {
  background: var(--surface);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
}
.glass-strong {
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-strong);
}

/* ============================================================
   Шапка
   ============================================================ */
.header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px;
  border-left: none;
  border-right: none;
  border-top: none;
}
/* бегущая световая кромка снизу */
.header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(56, 189, 248, 0.75) 30%, rgba(45, 212, 191, 0.6) 55%, transparent 100%);
  background-size: 220% 100%;
  animation: edge-flow 7s linear infinite;
}
@keyframes edge-flow {
  from { background-position: 220% 0; }
  to   { background-position: -220% 0; }
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.logo {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 12px;
  color: #67e8f9;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.4), rgba(45, 212, 191, 0.16));
  border: 1px solid rgba(103, 232, 249, 0.3);
  box-shadow: var(--glow);
}
.logo svg {
  width: 25px; height: 25px;
  animation: fish-swim 6s ease-in-out infinite;
}
/* рыба «плывёт» */
@keyframes fish-swim {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  25%      { transform: translate(1.5px, -1px) rotate(3deg); }
  60%      { transform: translate(-1.5px, 1px) rotate(-4deg); }
}
/* «заброс» при отправке сообщения */
.logo.cast svg {
  animation: fish-cast 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fish-cast {
  0%   { transform: translateX(0) rotate(0deg); }
  30%  { transform: translateX(10px) rotate(14deg) scale(1.12); }
  60%  { transform: translateX(-3px) rotate(-6deg); }
  100% { transform: translateX(0) rotate(0deg); }
}

.header-text { min-width: 0; }
.header-text h1 {
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(90deg, #e8f0fa 20%, #7dd3fc 85%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-sub {
  display: block;
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 500;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  color: var(--text-secondary);
  transition: background 180ms ease, color 180ms ease, transform 120ms ease;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(125, 170, 220, 0.1); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

.model-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 8px 6px 10px;
  flex-shrink: 0;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background:
    linear-gradient(rgba(11, 26, 46, 0.85), rgba(11, 26, 46, 0.85)) padding-box,
    linear-gradient(120deg, rgba(56, 189, 248, 0.6), rgba(45, 212, 191, 0.35)) border-box;
  border: 1px solid transparent;
  transition: filter 180ms ease, transform 120ms ease;
}
.model-chip:hover { filter: brightness(1.2); }
.model-chip:active { transform: scale(0.96); }
/* расширенная зона нажатия до ~44px без изменения вида */
.model-chip::before { content: ''; position: absolute; inset: -4px; border-radius: 999px; }
.model-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: dot-pulse 2.4s ease-in-out infinite;
}
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}
.model-chip .chevron { width: 14px; height: 14px; color: var(--text-secondary); }

.skill-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 42px;
  max-width: 112px;
  min-height: 36px;
  padding: 6px 9px;
  flex-shrink: 0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  background: rgba(15, 29, 50, 0.74);
  border: 1px solid var(--border-strong);
  transition: background 180ms ease, color 180ms ease, transform 120ms ease;
}
.skill-chip svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #7dd3fc;
}
.skill-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.skill-chip:hover,
.skill-chip.active {
  color: var(--text);
  background: rgba(56, 189, 248, 0.14);
}
.skill-chip:active { transform: scale(0.96); }

/* ============================================================
   Лента сообщений
   ============================================================ */
.messages {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 12px;
  /* без scroll-behavior: smooth — иначе автоскролл при стриминге не успевает */
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: msg-in 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-ai   { align-self: flex-start; align-items: flex-start; }

.bubble {
  position: relative;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  overflow-wrap: break-word;
  word-break: break-word;
}
.msg-user .bubble {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 6px 24px rgba(14, 165, 233, 0.35);
}
/* пузырь Клода: градиентная светящаяся обводка */
.msg-ai .bubble {
  background:
    linear-gradient(rgba(17, 33, 58, 0.92), rgba(13, 26, 46, 0.92)) padding-box,
    linear-gradient(140deg, rgba(56, 189, 248, 0.5), rgba(45, 212, 191, 0.22) 45%, rgba(129, 140, 248, 0.2) 90%) border-box;
  border: 1px solid transparent;
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-soft), 0 0 18px rgba(56, 189, 248, 0.06);
  overflow: hidden;
}
/* шиммер во время стриминга */
.streaming .bubble::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 32%, rgba(125, 211, 252, 0.1) 50%, transparent 68%);
  background-size: 220% 100%;
  animation: bubble-shimmer 2.2s linear infinite;
  pointer-events: none;
}
@keyframes bubble-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.msg-meta {
  margin-top: 4px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--text-tertiary);
}

/* Markdown внутри пузыря */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.bubble a { color: #7dd3fc; text-decoration: underline; text-underline-offset: 2px; }
.bubble strong { font-weight: 600; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15.5px; font-weight: 700; margin: 10px 0 6px; }
.bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(5, 12, 24, 0.75);
  border: 1px solid var(--border);
}
.bubble pre {
  margin: 8px 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(4, 10, 20, 0.88);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.bubble pre code {
  padding: 0;
  border: none;
  background: none;
  font-size: 12.5px;
  line-height: 1.5;
}
.bubble blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--primary);
  color: var(--text-secondary);
}

/* Курсор стриминга */
.table-wrap {
  max-width: 100%;
  margin: 8px 0;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.bubble table {
  width: 100%;
  min-width: 360px;
  border-collapse: collapse;
  font-size: 13px;
  background: rgba(4, 10, 20, 0.64);
}
.bubble th,
.bubble td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(125, 170, 220, 0.14);
  text-align: left;
  vertical-align: top;
}
.bubble th {
  color: #dbeafe;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.1);
}
.bubble tr:last-child td { border-bottom: none; }
.message-attachments {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.message-image {
  display: block;
  max-width: min(280px, 100%);
  max-height: 320px;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.message-file {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(5, 12, 24, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.14);
}
.msg-user .message-file { background: rgba(255, 255, 255, 0.12); }
.message-file-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.12);
}
.message-file-icon svg { width: 16px; height: 16px; }
.message-file-body { min-width: 0; }
.message-file-name {
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-file-meta {
  font-size: 11.5px;
  opacity: 0.75;
}
.streaming .bubble::after {
  content: '';
  display: inline-block;
  width: 8px; height: 15px;
  margin-left: 3px;
  vertical-align: text-bottom;
  border-radius: 2px;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Индикатор «клюёт» — поплавок с кругами на воде */
.bobber-wrap {
  display: inline-flex;
  align-items: flex-end;
  gap: 8px;
  padding: 2px 4px;
}
.bobber-wrap svg { width: 30px; height: 36px; overflow: visible; }
.bobber-body {
  transform-box: fill-box;
  transform-origin: center 80%;
  animation: bobber-bob 1.7s ease-in-out infinite;
}
@keyframes bobber-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30%      { transform: translateY(2.5px) rotate(-3deg); }
  65%      { transform: translateY(-1.5px) rotate(2deg); }
}
.ripple {
  transform-box: fill-box;
  transform-origin: center;
  animation: ripple-out 1.7s ease-out infinite;
}
.ripple.r2 { animation-delay: 0.55s; }
@keyframes ripple-out {
  0%   { transform: scale(0.35); opacity: 0.8; }
  100% { transform: scale(1.5);  opacity: 0; }
}
.bobber-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  animation: dot-pulse 1.7s ease-in-out infinite;
}

.msg-error .bubble {
  background:
    linear-gradient(rgba(60, 18, 22, 0.5), rgba(45, 14, 20, 0.55)) padding-box,
    linear-gradient(140deg, rgba(248, 113, 113, 0.55), rgba(248, 113, 113, 0.15)) border-box;
  border: 1px solid transparent;
  color: #fecaca;
}

/* ============================================================
   Пустое состояние
   ============================================================ */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 8px;
}
.empty-scene {
  width: min(230px, 58vw);
  margin-bottom: 4px;
  filter: drop-shadow(0 0 28px rgba(56, 189, 248, 0.3));
}
.empty-scene svg { width: 100%; height: auto; overflow: visible; }
.scene-fish {
  transform-box: fill-box;
  transform-origin: center;
  animation: float 5.5s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-9px) rotate(-2deg); }
}
.fish-tail {
  transform-box: fill-box;
  transform-origin: right center;
  animation: tail-wag 1.9s ease-in-out infinite;
}
@keyframes tail-wag {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-6deg); }
}
.fish-eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink-eye 5s ease-in-out infinite;
}
@keyframes blink-eye {
  0%, 90%, 100% { transform: scaleY(1); }
  94%           { transform: scaleY(0.12); }
}
.scene-hook {
  transform-box: fill-box;
  transform-origin: top center;
  animation: hook-dangle 4.5s ease-in-out infinite;
}
@keyframes hook-dangle {
  0%, 100% { transform: rotate(0.6deg) translateY(0); }
  50%      { transform: rotate(-1.2deg) translateY(3px); }
}
.scene-bubble {
  transform-box: fill-box;
  transform-origin: center;
  animation: scene-bubble-rise 3.6s ease-in-out infinite;
}
.scene-bubble.b2 { animation-delay: 1.2s; }
.scene-bubble.b3 { animation-delay: 2.3s; }
@keyframes scene-bubble-rise {
  0%   { transform: translateY(6px) scale(0.6); opacity: 0; }
  35%  { opacity: 0.9; }
  100% { transform: translateY(-14px) scale(1.05); opacity: 0; }
}

.empty-state h2 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
  background: linear-gradient(120deg, #eef5fd 30%, #7dd3fc 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.empty-state p {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 260px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}
.suggestion {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  background:
    linear-gradient(rgba(13, 26, 46, 0.8), rgba(13, 26, 46, 0.8)) padding-box,
    linear-gradient(120deg, rgba(125, 170, 220, 0.35), rgba(45, 212, 191, 0.2)) border-box;
  border: 1px solid transparent;
  transition: filter 180ms ease, transform 120ms ease, box-shadow 180ms ease;
}
.suggestion svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  color: #67e8f9;
}
.suggestion:hover {
  filter: brightness(1.25);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.15);
}
.suggestion:active { transform: scale(0.96); }

/* ============================================================
   Поле ввода
   ============================================================ */
.composer {
  position: relative;
  z-index: 10;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-left: none;
  border-right: none;
  border-bottom: none;
}
.attachment-tray {
  display: flex;
  gap: 8px;
  margin: 0 4px 8px;
  padding-bottom: 2px;
  overflow-x: auto;
}
.attachment-tray[hidden] { display: none; }
.attachment-draft {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
  max-width: 240px;
  padding: 7px 38px 7px 8px;
  border-radius: var(--radius-md);
  background: rgba(8, 17, 32, 0.92);
  border: 1px solid var(--border-strong);
}
.attachment-thumb {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 9px;
  object-fit: cover;
  background: rgba(125, 170, 220, 0.12);
}
.attachment-file-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 9px;
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(125, 211, 252, 0.18);
}
.attachment-file-icon svg { width: 17px; height: 17px; }
.attachment-info { min-width: 0; }
.attachment-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-size {
  font-size: 11.5px;
  color: var(--text-tertiary);
}
.attachment-remove {
  position: absolute;
  right: 6px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--text-secondary);
  transform: translateY(-50%);
}
.attachment-remove:hover { background: rgba(248, 113, 113, 0.14); color: var(--danger); }
.attachment-remove svg { width: 15px; height: 15px; }
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 5px 5px 5px 16px;
  border-radius: 27px;
  background:
    linear-gradient(rgba(8, 17, 32, 0.88), rgba(8, 17, 32, 0.88)) padding-box,
    linear-gradient(120deg, rgba(125, 170, 220, 0.3), rgba(125, 170, 220, 0.14)) border-box;
  border: 1px solid transparent;
  transition: box-shadow 180ms ease, background 180ms ease;
}
.composer-inner:focus-within {
  background:
    linear-gradient(rgba(8, 17, 32, 0.88), rgba(8, 17, 32, 0.88)) padding-box,
    linear-gradient(120deg, rgba(56, 189, 248, 0.65), rgba(45, 212, 191, 0.4)) border-box;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12), 0 0 24px rgba(56, 189, 248, 0.1);
}
.attach-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background 180ms ease, color 180ms ease, transform 120ms ease;
}
.attach-btn svg { width: 20px; height: 20px; }
.attach-btn:hover { background: rgba(125, 170, 220, 0.1); color: var(--text); }
.attach-btn:active { transform: scale(0.92); }
.attach-btn.has-files {
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.12);
}
#input {
  flex: 1;
  max-height: 132px;
  padding: 9px 0;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: none;
  border: none;
  outline: none;
  resize: none;
}
#input::placeholder { color: var(--text-tertiary); }

.send-btn {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0ea5e9 55%, #22d3ee);
  background-size: 180% 180%;
  box-shadow: 0 4px 18px rgba(14, 165, 233, 0.45);
  animation: send-glow 4s ease-in-out infinite alternate;
  transition: transform 140ms ease, opacity 180ms ease, box-shadow 180ms ease;
}
@keyframes send-glow {
  from { background-position: 0% 0%; }
  to   { background-position: 100% 100%; }
}
.send-btn svg { width: 20px; height: 20px; margin-left: -1px; }
.send-btn:active:not(:disabled) { transform: scale(0.88); }
.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
  animation: none;
}
.send-btn.stop-mode {
  background: rgba(248, 113, 113, 0.18);
  border: 1px solid rgba(248, 113, 113, 0.5);
  color: #fca5a5;
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.15);
  animation: none;
}

/* ============================================================
   Оверлеи
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 6, 14, 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 220ms ease;
}
.overlay[hidden] { display: none; }
.overlay.visible { opacity: 1; }

/* ============================================================
   Шторка истории
   ============================================================ */
.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  width: min(320px, 86vw);
  display: flex;
  flex-direction: column;
  padding: 14px 12px calc(14px + var(--safe-bottom));
  border-top: none; border-bottom: none; border-left: none;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  transform: translateX(-105%);
  transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}
.drawer[hidden] { display: none; }
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 12px;
}
.drawer-head h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.new-chat-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  margin-bottom: 12px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0891b2 70%, #0ea5e9);
  background-size: 180% 180%;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.3);
  overflow: hidden;
  transition: transform 140ms ease, filter 180ms ease;
  animation: send-glow 5s ease-in-out infinite alternate;
}
.new-chat-btn svg { width: 18px; height: 18px; }
.new-chat-btn:hover { filter: brightness(1.12); }
.new-chat-btn:active { transform: scale(0.97); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: background 180ms ease, border-color 180ms ease;
}
.chat-item:hover { background: rgba(125, 170, 220, 0.08); }
.chat-item.active {
  background:
    linear-gradient(rgba(19, 38, 64, 0.7), rgba(19, 38, 64, 0.7)) padding-box,
    linear-gradient(120deg, rgba(56, 189, 248, 0.55), rgba(45, 212, 191, 0.3)) border-box;
  border: 1px solid transparent;
}
.chat-item-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px 10px 10px;
  text-align: left;
  border-radius: var(--radius-md);
}
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.chat-item-time {
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}
.chat-item-delete {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 10px;
  color: var(--text-tertiary);
  transition: background 180ms ease, color 180ms ease;
}
.chat-item-delete svg { width: 16px; height: 16px; }
.chat-item-delete:hover { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

.chat-list-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13.5px;
}

/* ============================================================
   Bottom sheet: выбор модели
   ============================================================ */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-bottom: none;
  transform: translateY(105%);
  transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}
.sheet[hidden] { display: none; }
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 42px; height: 4px;
  margin: 6px auto 14px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.5), rgba(45, 212, 191, 0.4));
}
.sheet h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.sheet-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: 3px 0 14px;
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.model-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  text-align: left;
  background: rgba(15, 29, 50, 0.6);
  border: 1px solid var(--border);
  transition: background 180ms ease, border-color 180ms ease, transform 120ms ease, box-shadow 180ms ease;
}
.model-option:active { transform: scale(0.98); }
.model-option.selected {
  background:
    linear-gradient(rgba(17, 34, 58, 0.85), rgba(17, 34, 58, 0.85)) padding-box,
    linear-gradient(120deg, rgba(56, 189, 248, 0.65), rgba(45, 212, 191, 0.35)) border-box;
  border: 1px solid transparent;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.12);
}
.model-icon {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 11px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
}
.model-icon.tier-opus   { background: rgba(129, 140, 248, 0.16); color: #a5b4fc; border: 1px solid rgba(129, 140, 248, 0.35); }
.model-icon.tier-fable  { background: rgba(232, 121, 249, 0.13); color: #f0abfc; border: 1px solid rgba(232, 121, 249, 0.3); }
.model-icon.tier-sonnet { background: rgba(45, 212, 191, 0.13); color: #5eead4; border: 1px solid rgba(45, 212, 191, 0.3); }
.model-icon.tier-haiku  { background: rgba(251, 191, 36, 0.12); color: #fcd34d; border: 1px solid rgba(251, 191, 36, 0.28); }
.model-option-body { flex: 1; min-width: 0; }
.model-option-name {
  font-size: 14.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.model-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(45, 212, 191, 0.15);
  color: var(--accent);
}
.model-option-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.model-check {
  width: 22px; height: 22px;
  flex-shrink: 0;
  color: var(--primary);
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.6));
  opacity: 0;
  transition: opacity 180ms ease;
}
.model-option.selected .model-check { opacity: 1; }

.quick-skill-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.quick-skill-form input,
.quick-skill-form textarea,
.quick-skill-form select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(8, 17, 32, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  outline: none;
}
.quick-skill-form textarea {
  min-height: 72px;
  resize: vertical;
}
.quick-skill-form input:focus,
.quick-skill-form textarea:focus,
.quick-skill-form select:focus {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}
.quick-skill-form input::placeholder,
.quick-skill-form textarea::placeholder { color: var(--text-tertiary); }
.quick-skill-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
}
.quick-skill-form button {
  min-height: 42px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
}
.quick-skill-form button:disabled { opacity: 0.55; }

/* ============================================================
   Админка
   ============================================================ */
.admin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  margin-top: 10px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px dashed var(--border-strong);
  transition: background 180ms ease, color 180ms ease;
}
.admin-btn[hidden] { display: none; }
.admin-btn svg { width: 17px; height: 17px; }
.admin-btn:hover { background: rgba(125, 170, 220, 0.08); color: var(--text); }

.admin-sheet {
  display: flex;
  flex-direction: column;
  max-height: 84dvh;
}
.admin-sheet[hidden] { display: none; }
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.admin-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 4px 2px 8px;
}
.admin-section h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.admin-hint {
  font-size: 12.5px;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}
.admin-create-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0891b2 70%, #0ea5e9);
  background-size: 180% 180%;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.3);
  transition: transform 140ms ease, filter 180ms ease;
}
.admin-create-btn svg { width: 17px; height: 17px; }
.admin-create-btn:hover { filter: brightness(1.12); }
.admin-create-btn:active { transform: scale(0.97); }
.admin-create-btn:disabled { opacity: 0.5; }

.admin-form {
  display: flex;
  gap: 8px;
}
.admin-form input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: rgba(8, 17, 32, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.admin-form input:focus {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}
.admin-form input::placeholder { color: var(--text-tertiary); }
.admin-form button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  transition: transform 140ms ease, filter 180ms ease;
}
.admin-form button:active { transform: scale(0.96); }

.skill-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.skill-form input,
.skill-form textarea,
.skill-form select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(8, 17, 32, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  outline: none;
}
.skill-form textarea {
  min-height: 82px;
  resize: vertical;
}
.skill-form input:focus,
.skill-form textarea:focus,
.skill-form select:focus {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}
.skill-form input::placeholder,
.skill-form textarea::placeholder { color: var(--text-tertiary); }
.skill-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 108px;
  gap: 8px;
}
.skill-form button {
  min-height: 44px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
}
.skill-form button:disabled { opacity: 0.55; }

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.admin-list:empty { margin-top: 0; }
.admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 6px 9px 12px;
  border-radius: var(--radius-md);
  background: rgba(15, 29, 50, 0.6);
  border: 1px solid var(--border);
}
.admin-row-body { flex: 1; min-width: 0; }
.admin-row-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-row-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.admin-row-actions { display: flex; flex-shrink: 0; }
.admin-icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  color: var(--text-secondary);
  transition: background 180ms ease, color 180ms ease;
}
.admin-icon-btn svg { width: 17px; height: 17px; }
.admin-icon-btn:hover { background: rgba(125, 170, 220, 0.1); color: var(--text); }
.admin-icon-btn.danger:hover { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.admin-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  margin-left: 6px;
  border-radius: 5px;
  background: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  vertical-align: 1px;
}
.admin-empty {
  padding: 10px 4px;
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
}

/* ============================================================
   Экран «нет доступа»
   ============================================================ */
.locked {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border: none;
}
.locked[hidden] { display: none; }
.locked-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  max-width: 320px;
  animation: msg-in 400ms cubic-bezier(0.16, 1, 0.3, 1);
}
.locked-icon {
  display: grid;
  place-items: center;
  width: 74px; height: 74px;
  margin-bottom: 6px;
  border-radius: 24px;
  color: #7dd3fc;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.3), rgba(45, 212, 191, 0.12));
  border: 1px solid rgba(103, 232, 249, 0.28);
  box-shadow: var(--glow);
}
.locked-icon svg { width: 36px; height: 36px; }
.locked h2 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  background: linear-gradient(120deg, #eef5fd 30%, #7dd3fc 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.locked p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ============================================================
   Тост
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bottom));
  z-index: 80;
  max-width: min(86vw, 420px);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 500;
  text-align: center;
  color: var(--text);
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============================================================
   Скроллбары, фокус, доступность
   ============================================================ */
.messages::-webkit-scrollbar,
.chat-list::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb,
.chat-list::-webkit-scrollbar-thumb {
  background: rgba(125, 170, 220, 0.2);
  border-radius: 2px;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* ---------- Десктоп ---------- */
@media (min-width: 721px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
  .drawer { left: max(0px, calc(50vw - 360px)); }
}
