/* Vibe — тёмная градиентная тема с золотым акцентом.
   Правило по анимациям: двигаем только transform и opacity (композитинг на GPU).
   Никаких анимаций box-shadow/filter/фона в бесконечном цикле — телефон греется. */

:root {
  --bg: #0b0c11;
  --bg-2: #10121b;
  --surface: #161927;
  --surface-2: #1d2131;
  --line: #2a2f42;
  --line-soft: rgba(255, 255, 255, .07);
  --text: #e9ebf2;
  --muted: #99a0b6;

  /* Золото: один набор оттенков и для монеты, и для акцентов интерфейса. */
  --gold-1: #fff6cf;
  --gold-2: #ffe093;
  --gold-3: #f5c542;
  --gold-4: #e0a325;
  --gold-5: #b87616;
  --gold-6: #7a4a0d;

  --accent: var(--gold-3);
  --accent-soft: rgba(245, 197, 66, .12);
  --accent-line: rgba(245, 197, 66, .42);
  --on-accent: #23180a;

  --ok: #5db07a;
  --warn: #d9a441;
  --danger: #e0706e;

  --radius: 14px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  font-size: 16px;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  position: relative;
}

/* Фон в два слоя: статичная база + медленно плывущее сияние.
   Сияние двигается transform'ом, поэтому это композитинг, а не перерисовка. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -3;
  background: linear-gradient(168deg, #0e1018 0%, #0a0b11 52%, #0c0d14 100%);
}
body::before {
  content: '';
  position: fixed;
  inset: -25%;
  z-index: -2;
  background:
    radial-gradient(36% 28% at 22% 14%, rgba(245, 197, 66, .16), transparent 70%),
    radial-gradient(32% 26% at 84% 8%, rgba(255, 138, 56, .10), transparent 70%),
    radial-gradient(46% 36% at 52% 104%, rgba(122, 96, 255, .10), transparent 70%);
  animation: drift 26s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes drift {
  from { transform: translate3d(-2%, -1.5%, 0) scale(1.02); }
  to   { transform: translate3d(2.5%, 2%, 0) scale(1.09); }
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* ─── Монета ────────────────────────────────────────────────────────────────
   Слои: кант (вращающийся конический градиент) → лицо (радиальный градиент,
   объём) → фаска → знак ₿ с чеканкой → скользящий блик. */

.coin-stage {
  position: relative;
  flex: none;
  width: min(58vw, 220px);
  height: min(58vw, 220px);
  margin: 0 auto;
  /* Перспектива даёт наклону монеты настоящий объём, а не плоский сдвиг. */
  perspective: 760px;
}

/* Тёплое сияние вокруг: статичное, не анимируем — это дорогая заливка. */
.coin-halo {
  position: absolute;
  inset: -42%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 197, 66, .26) 0%, rgba(224, 163, 37, .10) 42%, transparent 68%);
  pointer-events: none;
}

.coin-float {
  position: absolute;
  inset: 0;
  animation: coin-float 6.5s ease-in-out infinite;
  will-change: transform;
}
@keyframes coin-float {
  0%, 100% { transform: translate3d(0, -5px, 0); }
  50%      { transform: translate3d(0, 6px, 0); }
}

.coin {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  /* Медленный разворот вокруг вертикали: монета «живая», но никогда не встаёт
     ребром — так не нужен фальшивый торец и не мигает пустой кадр. */
  animation: coin-turn 11s ease-in-out infinite;
  will-change: transform;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, .55),
    0 0 0 1px rgba(255, 226, 147, .22);
}
/* perspective() задаём прямо в transform: свойство perspective у .coin-stage
   действует только на прямых детей, а монета лежит на уровень глубже. */
@keyframes coin-turn {
  0%   { transform: perspective(760px) rotateY(-26deg) rotateX(7deg); }
  50%  { transform: perspective(760px) rotateY(26deg) rotateX(-5deg); }
  100% { transform: perspective(760px) rotateY(-26deg) rotateX(7deg); }
}

/* Кант: конический градиент + мелкая насечка, крутится по кругу. */
.coin-rim {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg,
      rgba(0, 0, 0, .20) 0deg 1.7deg,
      rgba(255, 245, 205, .16) 1.7deg 3.4deg),
    conic-gradient(from 210deg,
      #7a4a0d 0deg,
      #f7dc8b 52deg,
      #c2871c 104deg,
      #fff3c4 168deg,
      #a4670f 226deg,
      #f2ce70 300deg,
      #7a4a0d 360deg);
  animation: coin-spin 17s linear infinite;
  will-change: transform;
}
@keyframes coin-spin { to { transform: rotate(360deg); } }

/* Лицо монеты: свет сверху-слева, тень справа-снизу. */
.coin-face {
  position: absolute;
  inset: 6.5%;
  border-radius: 50%;
  overflow: hidden;
  background:
    radial-gradient(circle at 31% 25%,
      #fffdf0 0%,
      #ffeeb4 13%,
      #f9cf5e 32%,
      #e2a92f 54%,
      #b97c19 76%,
      #8a5410 100%);
  box-shadow:
    inset 0 2px 3px rgba(255, 252, 226, .75),
    inset 0 -6px 14px rgba(88, 48, 4, .55);
}

/* Внутренняя фаска — тонкий рельефный ободок, добавляет «чеканности». */
.coin-bevel {
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  border: 2px solid rgba(122, 74, 13, .38);
  box-shadow:
    inset 0 1px 0 rgba(255, 250, 220, .55),
    0 1px 0 rgba(255, 250, 220, .28);
}

.coin-mark {
  position: absolute;
  left: 21%;
  top: 21%;
  width: 58%;
  height: 58%;
}

/* Скользящий блик: широкая полоса проходит по монете и надолго уходит. */
.coin-sheen {
  position: absolute;
  top: -60%;
  left: -40%;
  width: 34%;
  height: 220%;
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, .10) 30%,
    rgba(255, 255, 255, .62) 50%,
    rgba(255, 255, 255, .10) 70%,
    rgba(255, 255, 255, 0) 100%);
  /* Базовая прозрачность нулевая: при prefers-reduced-motion анимация
     выключается, и блик не должен застыть яркой полосой поперёк монеты. */
  opacity: 0;
  transform: rotate(18deg) translate3d(-60px, 0, 0);
  animation: coin-sheen 7s ease-in-out infinite;
  will-change: transform, opacity;
  pointer-events: none;
}
@keyframes coin-sheen {
  0%        { transform: rotate(18deg) translate3d(-60px, 0, 0); opacity: 0; }
  8%        { opacity: .95; }
  38%       { opacity: .95; }
  46%, 100% { transform: rotate(18deg) translate3d(340px, 0, 0); opacity: 0; }
}

/* Тень под монетой: «дышит» вместе с покачиванием. */
.coin-shadow {
  position: absolute;
  left: 14%;
  right: 14%;
  bottom: -13%;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 0, 0, .58) 0%, rgba(0, 0, 0, 0) 70%);
  opacity: .65;
  animation: coin-shadow 6.5s ease-in-out infinite;
  will-change: transform, opacity;
}
@keyframes coin-shadow {
  0%, 100% { transform: scale(.92); opacity: .55; }
  50%      { transform: scale(1.06); opacity: .8; }
}

/* Мини-монета в шапке — статичная, без анимации: она на рабочем экране. */
.brand-coin {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  background:
    radial-gradient(circle at 33% 28%, #fff5cd 0%, #ffdb85 28%, #e6ab2c 62%, #9a5f11 100%);
  box-shadow: inset 0 0 0 1.5px rgba(122, 74, 13, .55), 0 0 8px rgba(245, 197, 66, .35);
}

/* ─── Вход ──────────────────────────────────────────────────────────────── */

/* Flex, а не grid: у автоколонки grid ширина тянется по max-content,
   и карточка вылезала за правый край экрана. */
.login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  height: 100%;
  overflow-y: auto;
  padding: max(env(safe-area-inset-top), 24px) 24px calc(24px + env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 340px;
  background:
    linear-gradient(180deg, rgba(31, 34, 50, .92), rgba(20, 22, 33, .92));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 22px;
  display: grid;
  gap: 14px;
  position: relative;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  animation: rise .5s var(--ease) both;
}
/* Золотая нить по верхнему краю карточки. */
.login-card::before {
  content: '';
  position: absolute;
  left: 18%;
  right: 18%;
  top: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-3), transparent);
}
.login-card p { margin: 0; }

.brand {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: .06em;
  background: linear-gradient(100deg, var(--gold-1), var(--gold-3) 45%, var(--gold-5));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ─── Каркас приложения ─────────────────────────────────────────────────── */

/* Экран проекта: шапка, вкладки, полоска «нет входа», лента, «работает», ввод.
   Высоту задаёт .view (100dvh или точная высота visualViewport при клавиатуре). */
.app {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto auto;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(env(safe-area-inset-top), 8px) 10px 8px;
  background: linear-gradient(180deg, rgba(23, 26, 39, .95), rgba(17, 19, 29, .88));
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}
.topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-line), transparent);
}
.title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
#project-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
  transition: background-color .25s;
}
.dot.live { background: var(--ok); }
.dot.busy { background: var(--warn); }
.dot.down { background: var(--danger); }

/* Цель нажатия — не меньше 44×44: в шапке промахиваться нечем. */
.icon-btn {
  background: none;
  border: 0;
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1;
  min-width: 46px;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border-radius: 12px;
  cursor: pointer;
  flex: none;
  transition: transform .12s var(--ease), background-color .18s;
}
.icon-btn:active { background: var(--surface-2); transform: scale(.9); }
/* Ставим на место отсутствующей кнопки, чтобы заголовок остался по центру. */
.topbar-pad { width: 46px; flex: none; }

/* Вкладки проектов — горизонтальный скролл обязателен. */
.tabs {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  background: linear-gradient(180deg, rgba(19, 21, 32, .9), rgba(14, 16, 24, .8));
  border-bottom: 1px solid var(--line-soft);
  scrollbar-width: none;
  scroll-behavior: smooth;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(38, 42, 60, .8), rgba(26, 29, 43, .8));
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color .2s, border-color .2s, transform .12s var(--ease);
}
.tab:active { transform: scale(.94); }
.tab.active {
  background: linear-gradient(180deg, rgba(245, 197, 66, .22), rgba(224, 163, 37, .10));
  border-color: var(--accent-line);
  color: #ffeec2;
  animation: tab-pop .26s var(--ease);
}
@keyframes tab-pop {
  from { transform: scale(.9); }
  to   { transform: scale(1); }
}

/* ─── Лента сообщений ───────────────────────────────────────────────────── */

.stream {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* flex: none обязателен. Лента — колоночный flex, а у карточки инструмента
   стоит overflow:hidden, что отключает автоминимум высоты: без запрета сжатия
   такие карточки схлопываются в полоску, когда лента переполнена. */
.stream > * {
  flex: none;
  animation: rise .26s var(--ease) both;
}
@keyframes rise {
  from { opacity: 0; transform: translate3d(0, 10px, 0); }
  to   { opacity: 1; transform: none; }
}

.bubble {
  max-width: 92%;
  padding: 10px 13px;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.user {
  align-self: flex-end;
  background: linear-gradient(158deg, rgba(245, 197, 66, .20), rgba(184, 118, 22, .13));
  border: 1px solid var(--accent-line);
  border-bottom-right-radius: 5px;
}
.bubble.assistant {
  align-self: flex-start;
  /* Фон спокойный: длинные ответы и код должны читаться без напряжения. */
  background: linear-gradient(180deg, rgba(28, 31, 46, .92), rgba(22, 25, 37, .92));
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.bubble.system {
  align-self: center;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
  padding: 2px;
}
.bubble.error {
  align-self: stretch;
  background: linear-gradient(180deg, rgba(62, 28, 32, .95), rgba(42, 22, 26, .95));
  border: 1px solid var(--danger);
  color: #ffd9d9;
  font-size: .9rem;
}

/* Карточка инструмента */
.tool {
  align-self: stretch;
  background: linear-gradient(180deg, rgba(26, 29, 43, .9), rgba(20, 23, 34, .9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
/* Заголовок карточки — кнопка во всю ширину и высотой в палец. */
.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: .9rem;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  transition: background-color .18s;
}
.tool-head:active { background: rgba(255, 255, 255, .05); }
.tool-chev {
  flex: none;
  width: 26px;
  text-align: center;
  color: var(--muted);
  transition: transform .18s var(--ease);
}
.tool.open .tool-chev { transform: rotate(180deg); }
.tool-name {
  font-weight: 600;
  color: var(--gold-2);
}
.tool-summary {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem;
}
.tool-status {
  flex: none;
  font-size: 1.05rem;
  width: 22px;
  text-align: center;
  color: var(--muted);
}
.tool-status.ok { color: var(--ok); }
.tool-status.bad { color: var(--danger); }
.tool-body {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-x: auto;
  color: var(--muted);
  /* dvh, а не vh: с открытой клавиатурой лог не должен занимать весь экран. */
  max-height: 42dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(8, 9, 14, .5);
}

/* Запрос разрешения */
.perm {
  align-self: stretch;
  background: linear-gradient(180deg, rgba(44, 38, 22, .92), rgba(28, 26, 20, .92));
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 6px 22px rgba(217, 164, 65, .12);
}
.perm-title { font-weight: 600; margin-bottom: 6px; }
.perm-detail {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 26dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin-bottom: 12px;
}

/* Принять / Отклонить — самое частое и самое опасное действие.
   Две крупные кнопки в ряд, разного цвета, с разными значками и заметным
   зазором: промахнуться и «разрешить не то» так гораздо труднее. */
.perm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.perm-actions button {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 14px;
  border: 1px solid;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s var(--ease);
}
.perm-actions button:active { transform: scale(.96); }
.perm-ico { font-size: 1.15rem; line-height: 1; }
.perm-allow {
  background: linear-gradient(150deg, var(--gold-2), var(--gold-3) 45%, var(--gold-4));
  border-color: var(--gold-4);
  color: var(--on-accent);
  box-shadow: 0 4px 16px rgba(224, 163, 37, .22);
}
.perm-deny {
  background: linear-gradient(180deg, rgba(64, 28, 32, .95), rgba(44, 20, 24, .95));
  border-color: var(--danger);
  color: #ffc9c9;
}
/* «Всегда» — отдельной строкой и тише остальных: случайно не нажать. */
.perm-always {
  margin-top: 10px;
  width: 100%;
  min-height: 44px;
  border-radius: 11px;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  font-size: .88rem;
  cursor: pointer;
}
.perm-always:active { transform: scale(.98); }
.perm.resolved { border-color: var(--line); opacity: .6; }
.perm.resolved .perm-actions,
.perm.resolved .perm-always { display: none; }
.perm-verdict:not(:empty) { margin-top: 8px; font-size: .85rem; color: var(--muted); }

/* ─── Полоса «работает» и композер ──────────────────────────────────────── */

.running-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  background: linear-gradient(180deg, rgba(28, 26, 20, .95), rgba(19, 20, 30, .95));
  border-top: 1px solid var(--line-soft);
  font-size: .87rem;
  color: #d9d4c2;
  position: relative;
  overflow: hidden;
  animation: rise .22s var(--ease) both;
}
/* Бегущая золотая нить — признак того, что Claude сейчас работает. */
.running-bar::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-3), transparent);
  animation: sweep 1.7s linear infinite;
  will-change: transform;
}
@keyframes sweep {
  from { transform: translate3d(-100%, 0, 0); }
  to   { transform: translate3d(100%, 0, 0); }
}
.running-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.running-lines { display: grid; min-width: 0; }
.running-lines > * {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#running-sub { color: var(--muted); font-size: .76rem; }

/* Главная кнопка остановки: крупная, у нижнего края, под большим пальцем.
   Прерывание не мгновенное, поэтому у неё есть честное состояние ожидания. */
.stop-btn {
  flex: none;
  min-height: 52px;
  min-width: 116px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 20px;
  border-radius: 14px;
  border: 1px solid var(--danger);
  background: linear-gradient(180deg, rgba(74, 30, 34, .96), rgba(50, 22, 26, .96));
  color: #ffd0d0;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s var(--ease);
}
.stop-btn:active { transform: scale(.95); }
.stop-glyph {
  width: 15px;
  height: 15px;
  border-radius: 3px;
  background: currentColor;
  flex: none;
}
/* Пока идёт остановка — квадратик пульсирует (только transform). */
.stop-btn.waiting .stop-glyph {
  animation: stop-pulse 1s ease-in-out infinite;
  will-change: transform;
}
@keyframes stop-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(.72); }
}
.running-bar.stopping { color: #ffd7c9; }
.running-bar.stopping .spinner { opacity: .5; }

/* Спиннер — маленькая крутящаяся монета вместо безликого кольца. */
.spinner {
  width: 14px; height: 14px;
  flex: none;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #7a4a0d, #ffe89b 25%, #b87616 50%, #fff3c4 75%, #7a4a0d);
  box-shadow: inset 0 0 0 2px rgba(20, 14, 4, .55);
  animation: spin 1.4s linear infinite;
  will-change: transform;
}
@keyframes spin { to { transform: rotate(360deg); } }

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(21, 24, 36, .94), rgba(15, 17, 26, .98));
  border-top: 1px solid var(--line-soft);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 40dvh;
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(9, 10, 16, .85);
  color: var(--text);
  /* 16px обязательны: при меньшем размере Safari зумит страницу на фокусе. */
  font-size: 16px;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color .2s;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent-line);
}
.send {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(150deg, var(--gold-2), var(--gold-3) 45%, var(--gold-5));
  color: var(--on-accent);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(224, 163, 37, .3);
  transition: transform .12s var(--ease);
}
.send:active { transform: scale(.9); }
.send:disabled { opacity: .4; }

/* ─── Кнопки, поля, шторки ──────────────────────────────────────────────── */

button, select, input, textarea { font-family: inherit; }

.primary, .ghost, .danger {
  padding: 11px 16px;
  border-radius: 11px;
  font-size: .95rem;
  cursor: pointer;
  border: 1px solid var(--line);
  transition: transform .12s var(--ease), border-color .2s, color .2s;
}
.primary:active, .ghost:active, .danger:active { transform: scale(.97); }
.primary {
  background: linear-gradient(150deg, var(--gold-2), var(--gold-3) 45%, var(--gold-4));
  color: var(--on-accent);
  border-color: var(--gold-4);
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(224, 163, 37, .22);
}
.ghost {
  background: linear-gradient(180deg, rgba(38, 42, 60, .75), rgba(26, 29, 43, .75));
  color: var(--text);
}
.danger {
  background: linear-gradient(180deg, rgba(58, 26, 30, .9), rgba(40, 20, 24, .9));
  color: #ffb3b3;
  border-color: var(--danger);
}
.wide { width: 100%; }

.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--gold-2);
  font-size: .75rem;
  line-height: 1.5;
}

.zone-label {
  margin: 0;
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--danger);
  opacity: .8;
}

input[type="text"], input[type="password"], select {
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(9, 10, 16, .85);
  color: var(--text);
  /* 16px: иначе Safari зумит страницу при фокусе. */
  font-size: 16px;
  width: 100%;
  transition: border-color .2s;
}
input[type="text"]:focus, input[type="password"]:focus, select:focus {
  outline: none;
  border-color: var(--accent-line);
}

.inline-row { display: flex; gap: 8px; align-items: center; }
.inline-row input { flex: 1; min-width: 0; }
.inline-row button { flex: none; }

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  animation: fade .2s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-body {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(28, 31, 46, .98), rgba(17, 19, 29, .99));
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  max-height: 85dvh;
  overflow-y: auto;
  animation: sheet-up .26s var(--ease) both;
  will-change: transform;
}
@keyframes sheet-up {
  from { transform: translate3d(0, 100%, 0); }
  to   { transform: none; }
}
/* Хват сверху — намёк, что это шторка. */
.sheet-body::before {
  content: '';
  width: 38px; height: 4px;
  border-radius: 999px;
  background: var(--line);
  justify-self: center;
  margin-bottom: 2px;
}
.sheet-body h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--gold-2);
}
.sheet-body hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
.row { display: grid; gap: 6px; }
.row label { font-size: .85rem; color: var(--muted); }

.adopt-list { display: grid; gap: 8px; }
.adopt-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(180deg, rgba(34, 38, 55, .8), rgba(24, 27, 40, .8));
  font-size: .9rem;
}
.adopt-item > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adopt-item button { padding: 7px 12px; font-size: .85rem; }
.adopt-actions { display: flex; gap: 6px; flex: none; }

/* ─── Три экрана: вход → список проектов → проект ────────────────────────
   Экраны лежат стопкой и переезжают горизонтально. Двигаем только transform
   и opacity; неактивные выключены из отрисовки через visibility. */

.view {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  /* --app-h ставит JS по visualViewport: 100dvh на айфоне не ужимается,
     когда вылезает клавиатура. */
  height: var(--app-h, 100dvh);
  overflow: hidden;
  z-index: 1;
  transform: translate3d(100%, 0, 0);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  will-change: transform;
  transition:
    transform .3s var(--ease),
    opacity .22s linear,
    visibility 0s linear .3s;
}
.view.active {
  transform: none;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 2;
  transition:
    transform .3s var(--ease),
    opacity .22s linear,
    visibility 0s;
}
/* Экран, оставшийся позади, слегка уезжает влево — видно, куда возвращаться. */
.view.behind {
  transform: translate3d(-22%, 0, 0);
  opacity: 0;
}
/* Карточка входа на низком экране должна прокручиваться. */
.view.login { overflow-y: auto; }

/* ─── Домашний экран: список проектов ───────────────────────────────────── */

.home {
  display: grid;
  grid-template-rows: auto 1fr;
}
/* На домашнем экране заголовок один — ставим его по центру шапки. */
.home .title { justify-content: center; }
.brand-word { letter-spacing: .04em; }
.home-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px calc(20px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  align-content: start;
}
.home-head {
  margin: 6px 2px 0;
  font-size: .78rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.home-list { display: grid; gap: 10px; }

/* Строка проекта: крупная цель, всё нужное видно сразу. */
.project-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 76px;
  padding: 12px 14px;
  text-align: left;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(32, 36, 52, .88), rgba(22, 25, 38, .88));
  color: var(--text);
  cursor: pointer;
  animation: rise .26s var(--ease) both;
  transition: transform .12s var(--ease), border-color .2s;
}
.project-card:active { transform: scale(.985); border-color: var(--accent-line); }
.pc-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.pc-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pc-name {
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pc-dir {
  font-size: .74rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pc-chip {
  flex: none;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .7rem;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, .04);
}
.pc-chip.new { opacity: .75; }
.pc-chip.working {
  border-color: var(--accent-line);
  color: #ffe7ac;
  background: var(--accent-soft);
  animation: chip-pulse 1.6s ease-in-out infinite;
  will-change: opacity;
}
@keyframes chip-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .5; }
}
.pc-go { flex: none; font-size: 1.5rem; color: var(--muted); }

/* «Продолжить» — быстрый возврат в последний проект. */
.resume {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 60px;
  padding: 10px 16px;
  border-radius: 16px;
  border: 1px solid var(--accent-line);
  background: linear-gradient(150deg, rgba(245, 197, 66, .20), rgba(184, 118, 22, .10));
  color: #ffeec2;
  cursor: pointer;
  text-align: left;
  transition: transform .12s var(--ease);
}
.resume:active { transform: scale(.985); }
.resume-label { font-size: .78rem; color: var(--gold-2); opacity: .85; flex: none; }
.resume-name {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.resume-go { font-size: 1.4rem; flex: none; }

.home-links { display: grid; gap: 10px; margin-top: 8px; }

/* ─── Баннер «нет входа» ────────────────────────────────────────────────── */

.auth-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  padding: 12px 14px;
  text-align: left;
  border-radius: 16px;
  border: 1px solid var(--danger);
  background: linear-gradient(180deg, rgba(66, 28, 32, .95), rgba(44, 22, 26, .95));
  color: #ffd9d9;
  cursor: pointer;
  transition: transform .12s var(--ease);
}
.auth-banner:active { transform: scale(.985); }
.auth-banner-mark {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  background: rgba(224, 112, 110, .22);
  border: 1px solid var(--danger);
}
.auth-banner-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.auth-banner-text small { color: #f0b9b9; font-size: .78rem; }
.auth-banner-go {
  flex: none;
  font-size: .82rem;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--danger);
  background: rgba(0, 0, 0, .2);
}

/* Тонкая полоска на экране проекта — то же предупреждение, но не в ущерб ленте. */
.auth-strip {
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid rgba(224, 112, 110, .5);
  background: linear-gradient(180deg, rgba(66, 28, 32, .95), rgba(48, 22, 26, .9));
  color: #ffd9d9;
  font-size: .84rem;
  text-align: left;
  cursor: pointer;
}
.auth-strip:active { background: rgba(88, 34, 38, .95); }

/* ─── Лента: обёртка, плавающие кнопки ──────────────────────────────────── */

.stream-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.stream { height: 100%; }

.jump {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(40, 44, 63, .96), rgba(26, 29, 43, .96));
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
  animation: rise .2s var(--ease) both;
}
.jump:active { transform: scale(.92); }
.jump-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--gold-3);
  color: var(--on-accent);
  font-size: .7rem;
  font-weight: 700;
}

/* Ставим над кнопкой «вниз», чтобы две плавающие цели не наезжали друг
   на друга: промах здесь стоит дорого. */
.perm-pill {
  position: absolute;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--warn);
  background: linear-gradient(180deg, rgba(64, 52, 24, .97), rgba(42, 36, 20, .97));
  color: #ffe9b8;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
  animation: rise .2s var(--ease) both;
}
.perm-pill-count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--warn);
  color: #2a1e05;
  font-size: .78rem;
}

/* Очень длинный ответ сворачиваем: одной рукой такой не пролистать. */
.bubble { position: relative; }
.bubble.clamped { max-height: 46dvh; overflow: hidden; }
.expand {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 26px 0 10px;
  border: 0;
  color: var(--gold-2);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(180deg, rgba(24, 27, 40, 0), rgba(24, 27, 40, .96) 55%);
}
/* У пузыря пользователя фон тёплый — растушёвка должна совпадать с ним. */
.bubble.user .expand {
  background: linear-gradient(180deg, rgba(46, 38, 18, 0), rgba(44, 36, 16, .97) 55%);
}

/* ─── Сервисная панель ──────────────────────────────────────────────────── */

.service {
  display: grid;
  grid-template-rows: auto 1fr;
}
.screen-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px calc(24px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  align-content: start;
}
.card {
  background: linear-gradient(180deg, rgba(28, 31, 46, .9), rgba(20, 23, 35, .9));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.card h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--gold-2);
}
.card hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 2px 0; }
.card > div[hidden] { display: none !important; }
#auth-browser, #auth-flow, #auth-token-box, .confirm-row { display: grid; gap: 10px; }

.auth-state { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.auth-chip {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--muted);
}
.auth-chip.ok { color: #bff0cf; border-color: var(--ok); background: rgba(93, 176, 122, .14); }
.auth-chip.bad { color: #ffc9c9; border-color: var(--danger); background: rgba(224, 112, 110, .14); }
.auth-chip.unknown { color: #ffe0ab; border-color: var(--warn); background: rgba(217, 164, 65, .12); }

/* Крупная кнопка — для решений, которые делаешь одной рукой. */
.big { min-height: 54px; font-size: 1rem; }
.linkbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: 11px;
  padding: 11px 16px;
  font-weight: 600;
}

.notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 11px;
  font-size: .86rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  overflow-wrap: anywhere;
}
.notice.ok { border-color: var(--ok); color: #cdeed9; background: rgba(93, 176, 122, .1); }
.notice.bad { border-color: var(--danger); color: #ffd0d0; background: rgba(224, 112, 110, .1); }
.notice.warn { border-color: var(--warn); color: #ffe6b8; background: rgba(217, 164, 65, .1); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.stat {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(9, 10, 16, .5);
  min-width: 0;
}
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: .95rem; font-weight: 600; overflow-wrap: anywhere; }
.bar {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .09);
  overflow: hidden;
  margin-top: 4px;
}
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--gold-4), var(--gold-2)); }
.bar-fill.hot { background: linear-gradient(90deg, #a8433f, var(--danger)); }

.logs {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(6, 7, 11, .75);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .72rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 40dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.danger-badge {
  background: rgba(224, 112, 110, .16);
  border-color: var(--danger);
  color: #ffc9c9;
}

/* ─── Всплывающее уведомление ───────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  /* Выше композера: подсказка не должна закрывать поле ввода и «Стоп». */
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  max-width: 88vw;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(20, 23, 35, .97);
  color: var(--text);
  font-size: .88rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  animation: toast-in .2s var(--ease) both;
}
.toast.bad { border-color: var(--danger); color: #ffd0d0; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Шторки лежат выше экранов. */
.sheet { z-index: 80; }

/* ─── Уважение к настройкам доступности ─────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    /* Задержку тоже снимаем: у переключения экранов на visibility стоит
       отложенный переход, иначе экран появлялся бы с паузой. */
    transition-delay: 0s !important;
    animation-delay: 0s !important;
  }
}
