/* Вид взят с мобильного приложения Claude: тёплый чёрный фон, антиква в
   заголовках, коралловая звёздочка, скруглённое поле ввода снизу. */

:root {
  --bg: #1f1e1c;
  --bg-raised: #2b2a27;
  --bg-chip: #333230;
  --line: #3a3835;
  --text: #e9e6dd;
  --text-dim: #8f8b81;
  --accent: #d97757;
  --user-bubble: #2f2e2b;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* в Telegram Mini App снизу свои панели — отступ держим переменной */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 16px;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* звёздочка Claude — рисуем лучами, чтобы не тащить картинку */
.logo {
  width: 40px; height: 40px; position: relative; margin: 0 auto;
}
.logo::before, .logo::after,
.logo > i { content: ""; position: absolute; inset: 0; }
.logo::before {
  background:
    conic-gradient(from 0deg,
      transparent 0 6deg, var(--accent) 6deg 10deg, transparent 10deg 30deg,
      transparent 30deg 36deg, var(--accent) 36deg 40deg, transparent 40deg 60deg,
      transparent 60deg 66deg, var(--accent) 66deg 70deg, transparent 70deg 90deg,
      transparent 90deg 96deg, var(--accent) 96deg 100deg, transparent 100deg 120deg,
      transparent 120deg 126deg, var(--accent) 126deg 130deg, transparent 130deg 150deg,
      transparent 150deg 156deg, var(--accent) 156deg 160deg, transparent 160deg 180deg,
      transparent 180deg 186deg, var(--accent) 186deg 190deg, transparent 190deg 210deg,
      transparent 210deg 216deg, var(--accent) 216deg 220deg, transparent 220deg 240deg,
      transparent 240deg 246deg, var(--accent) 246deg 250deg, transparent 250deg 270deg,
      transparent 270deg 276deg, var(--accent) 276deg 280deg, transparent 280deg 300deg,
      transparent 300deg 306deg, var(--accent) 306deg 310deg, transparent 310deg 330deg,
      transparent 330deg 336deg, var(--accent) 336deg 340deg, transparent 340deg 360deg);
  border-radius: 50%;
  -webkit-mask: radial-gradient(circle, #000 0 45%, transparent 46%);
          mask: radial-gradient(circle, #000 0 45%, transparent 46%);
}
.logo::after {
  width: 14px; height: 14px; margin: auto; border-radius: 50%;
  background: var(--accent);
}

/* ── вход ─────────────────────────────────────────────── */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 320px; display: grid; gap: 14px; }
.login-box input {
  width: 100%; padding: 14px 16px; border-radius: 14px;
  background: var(--bg-raised); border: 1px solid var(--line);
  color: var(--text); font-size: 16px; outline: none;
}
.login-box button {
  padding: 14px; border-radius: 14px; border: none;
  background: var(--text); color: #1b1a18; font-size: 16px; font-weight: 600;
}
.login-error { color: #e0806c; font-size: 14px; min-height: 18px; text-align: center; }

/* ── каркас ───────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100dvh; }

/* внутри Telegram высоту диктует сам webview: 100dvh там врёт и низ уезжает
   под клавиатуру, поэтому берём отметку, которую даёт Telegram */
body.tg .app { height: var(--tg-height, 100dvh); }
body.tg .topbar { padding-top: 10px; }   /* отступ сверху уже держит Telegram */

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  flex: 0 0 auto;
}
.chat-title {
  flex: 1; text-align: center; font-size: 14px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.round-btn {
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 50%; border: 1px solid var(--line);
  background: transparent; color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}

/* ── лента ────────────────────────────────────────────── */
.feed { flex: 1 1 auto; overflow-y: auto; padding: 8px 16px 4px; -webkit-overflow-scrolling: touch; }

.greeting { height: 100%; display: grid; place-content: center; gap: 18px; text-align: center; }
.greeting h1 {
  font-family: var(--serif); font-weight: 400; font-size: 28px;
  margin: 0; color: var(--text);
}

.messages { display: flex; flex-direction: column; gap: 18px; padding-bottom: 8px; }

.msg { max-width: 100%; line-height: 1.55; font-size: 15.5px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user {
  align-self: flex-end; max-width: 85%;
  background: var(--user-bubble); border-radius: 18px; padding: 11px 15px;
}
.msg.assistant { align-self: stretch; }

.tool-note {
  font-size: 13px; color: var(--text-dim);
  display: flex; align-items: center; gap: 7px;
}
.tool-note::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); flex: 0 0 auto;
}

.thinking { color: var(--text-dim); font-size: 14px; }

/* ── поле ввода ───────────────────────────────────────── */
.composer { flex: 0 0 auto; padding: 6px 12px calc(10px + var(--safe-bottom)); }
.composer-box {
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: 24px; padding: 10px 12px 8px;
}
.composer-box textarea {
  width: 100%; max-height: 140px; resize: none; border: none; outline: none;
  background: transparent; color: var(--text);
  font-family: var(--sans); font-size: 16px; line-height: 1.4;
}
.composer-box textarea::placeholder { color: var(--text-dim); }
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.chip {
  font-size: 13px; color: var(--text-dim);
  background: var(--bg-chip); border-radius: 999px; padding: 5px 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%;
}
.icon-btn {
  width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%;
  border: none; background: var(--bg-chip); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn.recording { background: var(--accent); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

#mic { margin-left: auto; }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px 6px; }
.attach {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-chip); border-radius: 999px; padding: 5px 8px 5px 11px;
  font-size: 13px; color: var(--text);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach button {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px;
}

.model-chip {
  border: none; cursor: pointer; font-size: 14px; color: var(--text);
  padding: 7px 14px;
}

/* шторка выбора модели — снизу, как в приложении */
.sheet { position: fixed; inset: 0; z-index: 8; }
.sheet.hidden { display: none; }
.sheet-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-raised); border-radius: 22px 22px 0 0;
  padding: 10px 8px calc(20px + var(--safe-bottom));
  max-height: 82vh; overflow-y: auto;
}
.sheet-head {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 14px; font-size: 17px;
}
.sheet-head span { flex: 1; text-align: center; margin-right: 40px; }

.model-list { list-style: none; margin: 0; padding: 0; }
.model-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px; border-radius: 14px; cursor: pointer;
}
.model-list li:active { background: var(--bg-chip); }
.model-list .m-name { font-size: 17px; }
.model-list .m-hint { font-size: 13px; color: var(--text-dim); margin-top: 3px; }
.model-list .tick { margin-left: auto; color: var(--accent); font-size: 18px; }
.model-list li > div:first-child { flex: 1; }

/* камера на компьютере */
.camera { position: fixed; inset: 0; z-index: 9; background: #000; display: flex;
  flex-direction: column; }
.camera.hidden { display: none; }
.camera video { flex: 1 1 auto; width: 100%; object-fit: contain; background: #000; }
.camera-bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px calc(24px + var(--safe-bottom));
}
.camera-cancel, .camera-spacer {
  width: 90px; border: none; background: transparent; color: var(--text);
  font-size: 16px; text-align: left; cursor: pointer;
}
.camera-shot {
  width: 68px; height: 68px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.35); background: #fff; cursor: pointer;
}

.attach-menu {
  position: absolute; bottom: 100%; left: 12px; margin-bottom: 8px;
  background: var(--bg-chip); border: 1px solid var(--line); border-radius: 14px;
  padding: 6px; display: flex; flex-direction: column; min-width: 160px; z-index: 4;
}
.attach-menu button {
  border: none; background: transparent; color: var(--text);
  padding: 11px 14px; text-align: left; font-size: 15px; border-radius: 10px; cursor: pointer;
}
.attach-menu button:active { background: var(--bg-raised); }
.composer { position: relative; }

.send-btn {
  width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%; border: none;
  background: var(--text); color: #1b1a18; display: grid; place-items: center; cursor: pointer;
}
.send-btn:disabled { opacity: .4; }
.send-btn.stopping { background: var(--accent); color: #fff; }

/* Telegram в iOS запрещает выделение текста на всей странице ради нативного
   ощущения. Возвращаем его там, где текст нужен целиком: ответы, размышления,
   пути к файлам. Остальной интерфейс остаётся невыделяемым. */
/* Правило с !important и на всех потомков: запрет приходит не из нашего кода,
   а из самого webview, и мягкое объявление он перебивает. */
.msg, .msg-text, .msg-text *, .think, .tool-note {
  -webkit-user-select: text !important; user-select: text !important;
  -webkit-touch-callout: default !important;
}
.copy-btn, .copy-code {
  -webkit-user-select: none !important; user-select: none !important;
}

.msg { position: relative; }
.copy-btn {
  display: block; margin: 6px 0 0 auto; padding: 4px 10px; border: none;
  border-radius: 8px; background: var(--bg-raised); color: var(--text-dim);
  font-size: 12px; cursor: pointer; -webkit-user-select: none; user-select: none;
}
.copy-btn:active { background: var(--accent); color: #fff; }

/* ── разметка в ответе ────────────────────────────────── */
/* у ответа переносы расставляет разметка, а не сами пробелы в тексте */
.msg.assistant .msg-text { display: block; white-space: normal; }
.msg-text > :first-child { margin-top: 0; }
.msg-text > :last-child { margin-bottom: 0; }
.msg-text p { margin: 0 0 10px; }
.msg-text h3, .msg-text h4, .msg-text h5, .msg-text h6 {
  margin: 16px 0 8px; font-size: 16px; font-weight: 600; line-height: 1.35;
}
.msg-text ul, .msg-text ol { margin: 0 0 10px; padding-left: 22px; }
.msg-text li { margin: 3px 0; }
.msg-text strong { font-weight: 600; }
.msg-text a { color: var(--accent); }
.msg-text hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.msg-text blockquote {
  margin: 0 0 10px; padding: 2px 0 2px 12px;
  border-left: 2px solid var(--line); color: var(--text-dim);
}
.msg-text code {
  background: var(--bg-raised); border-radius: 5px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px;
}
.msg-text pre {
  position: relative; margin: 0 0 10px; padding: 10px 12px 12px;
  background: var(--bg-raised); border-radius: 10px; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  line-height: 1.45;
}
.msg-text pre code { background: none; padding: 0; font-size: inherit; }
.copy-code { position: absolute; top: 6px; right: 6px; margin: 0; }

/* таблица шире экрана прокручивается вбок, а не ломает вёрстку */
.msg-text table {
  display: block; width: max-content; max-width: 100%; overflow-x: auto;
  border-collapse: collapse; margin: 0 0 10px; font-size: 14px;
}
.msg-text th, .msg-text td {
  border: 1px solid var(--line); padding: 6px 10px; text-align: left;
  vertical-align: top;
}
.msg-text th { background: var(--bg-raised); font-weight: 600; }

/* очередь: отправленное, пока Клод ещё говорит */
.queued {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
  padding: 7px 10px; border-radius: 10px; background: var(--bg-raised);
  font-size: 13px; color: var(--text-dim);
}
.queued-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queued-drop {
  flex: 0 0 auto; border: none; background: none; color: var(--text-dim);
  font-size: 14px; cursor: pointer; padding: 0 2px;
}

/* ── шторка ───────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .22s ease; z-index: 5;
}
.overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(86vw, 360px);
  background: var(--bg); z-index: 6;
  display: flex; flex-direction: column;
  transform: translateX(-102%); transition: transform .24s ease;
  border-right: 1px solid var(--line);
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 20px 12px;
}
.wordmark { font-family: var(--serif); font-size: 26px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg-chip); display: grid; place-items: center; font-size: 14px;
  object-fit: cover;
}

/* ── вкладки шторки: разговоры и файлы ────────────────── */
.tabs { display: flex; gap: 4px; }
.tab {
  width: 40px; height: 36px; border: none; border-radius: 11px;
  background: transparent; color: var(--text-dim);
  display: grid; place-items: center; cursor: pointer;
}
.tab.active { background: var(--bg-raised); color: var(--text); }
.logo.small { width: 22px; height: 22px; margin: 0; }
.logo.small::after { width: 8px; height: 8px; }

/* ── файловое хранилище ───────────────────────────────── */
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  padding: 10px 8px 8px; font-size: 13px; color: var(--text-dim);
}
.crumbs button {
  border: none; background: none; color: var(--text-dim);
  font-size: 13px; padding: 2px 4px; cursor: pointer; border-radius: 6px;
}
.crumbs button:last-child { color: var(--text); }
.crumbs .sep { opacity: .45; }

.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 10px; border-radius: 12px; cursor: pointer; font-size: 15px;
}
.file-list li:active { background: var(--bg-raised); }
.file-list .f-icon { flex: 0 0 auto; color: var(--text-dim); display: grid; }
.file-list .f-name {
  flex: 1 1 auto; overflow-wrap: anywhere; line-height: 1.3;
}
.file-list .f-meta { flex: 0 0 auto; font-size: 12px; color: var(--text-dim); }
/* строка становится «карточкой», когда под ней раскрыты действия */
.file-list li { flex-wrap: wrap; position: relative; }
.file-list .more {
  flex: 0 0 auto; border: none; background: none; color: var(--text-dim);
  font-size: 18px; line-height: 1; padding: 4px 6px; cursor: pointer;
  border-radius: 8px;
}
.acts {
  flex: 1 0 100%; display: flex; gap: 8px; align-items: center;
  padding: 8px 2px 2px; flex-wrap: wrap;
}
.acts span { font-size: 14px; color: var(--text-dim); }
.acts button {
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-raised); color: var(--text); font-size: 14px; cursor: pointer;
}
.acts button.danger { color: #e0806c; }
.name-box.inline { flex: 1 0 100%; padding: 8px 2px 2px; }

.file-list .empty, .file-list .oops {
  padding: 14px 10px; color: var(--text-dim); font-size: 14px; cursor: default;
}

.file-actions { display: flex; gap: 8px; }
.file-actions button {
  flex: 1 1 0; padding: 13px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg-raised); color: var(--text); font-size: 15px; cursor: pointer;
}
/* поле ввода имени папки живёт прямо в списке — браузерный prompt
   внутри Telegram Mini App не показывается вовсе */
.name-box { display: flex; gap: 8px; padding: 8px 6px; }
.name-box input {
  flex: 1 1 auto; padding: 10px 12px; border-radius: 11px;
  background: var(--bg-raised); border: 1px solid var(--line);
  color: var(--text); font-size: 15px; outline: none;
}
.name-box button {
  padding: 10px 14px; border-radius: 11px; border: none;
  background: var(--text); color: #1b1a18; font-size: 15px; cursor: pointer;
}

/* ── просмотр файла ───────────────────────────────────── */
.viewer {
  position: fixed; inset: 0; z-index: 60; background: var(--bg);
  display: flex; flex-direction: column;
}
.viewer-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
}
.viewer-name {
  flex: 1 1 auto; font-size: 15px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.viewer-body { flex: 1 1 auto; overflow: auto; padding: 14px; }
.viewer-body pre {
  margin: 0; font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.viewer-body img, .viewer-body video { max-width: 100%; border-radius: 12px; }
.viewer-body audio { width: 100%; }
.viewer-body .note { color: var(--text-dim); font-size: 14px; }
/* ── переключатель размышлений ────────────────────────── */
.sheet-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 6px; border-top: 1px solid var(--line); margin-top: 6px;
}
.toggle {
  flex: 0 0 auto; width: 48px; height: 28px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-raised);
  position: relative; cursor: pointer; padding: 0;
}
.toggle span {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--text-dim); transition: .15s;
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle.on span { left: 23px; background: #fff; }

/* ход мысли: тише основного ответа, чтобы не спорил с ним за внимание */
.think {
  border-left: 2px solid var(--line); padding: 2px 0 2px 12px;
  margin: 2px 0 8px; color: var(--text-dim); font-size: 13px;
  line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}

.editor {
  width: 100%; min-height: 60vh; resize: none; outline: none;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); padding: 12px; font-size: 14px; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.viewer-foot { padding: 12px 14px calc(12px + var(--safe-bottom)); }
.viewer-ask {
  width: 100%; padding: 14px; border-radius: 14px; border: none;
  background: var(--text); color: #1b1a18; font-size: 15px; font-weight: 600;
  cursor: pointer;
}

.drawer-scroll { flex: 1 1 auto; overflow-y: auto; padding: 6px 12px; }
.section-label {
  font-size: 13px; color: var(--text-dim); padding: 10px 8px 6px;
}
.session-list { list-style: none; margin: 0; padding: 0; }
.session-list li {
  padding: 12px 10px; border-radius: 12px; cursor: pointer; font-size: 15px;
  display: flex; align-items: center; gap: 8px;
}
.session-list li:active, .session-list li.active { background: var(--bg-raised); }
/* длинное название переносится по словам — до двух строк, иначе по обрезку
   не понять, что за сессия; время и вес всегда видно целиком */
.session-list li .row {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: baseline; gap: 6px;
}
.session-list li .name {
  flex: 1 1 auto; min-width: 0;
  white-space: normal; overflow-wrap: anywhere; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.session-list li .when {
  flex: 0 0 auto; color: var(--text-dim); font-size: 12px; white-space: nowrap;
}
.session-list li .del {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px;
  border: none; background: transparent; color: var(--text-dim);
  display: grid; place-items: center; cursor: pointer;
}
.session-list li .del:active { background: var(--bg-chip); color: var(--text); }

.confirm {
  position: absolute; right: 12px;
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-chip); border-radius: 10px; padding: 5px 8px; font-size: 13px;
}
.confirm button {
  border: none; border-radius: 7px; padding: 4px 10px; font-size: 13px; cursor: pointer;
  background: var(--bg-raised); color: var(--text);
}
.confirm button:first-of-type { background: var(--accent); color: #fff; }
.session-list li { position: relative; }
/* точка у сессии, в которой прямо сейчас идёт ответ */
.session-list li.working .name::before {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
  animation: working-pulse 1.4s ease-in-out infinite;
}
@keyframes working-pulse { 50% { opacity: 0.35; } }

.drawer-foot { padding: 12px 16px calc(16px + var(--safe-bottom)); }
.new-chat {
  width: 100%; padding: 13px; border: none; border-radius: 999px;
  background: var(--text); color: #1b1a18; font-size: 15px; font-weight: 600; cursor: pointer;
}

@media (min-width: 900px) {
  .greeting h1 { font-size: 34px; }
  .feed { padding: 8px 22px 4px; }
  .messages { max-width: 760px; margin: 0 auto; width: 100%; }
  .composer-box { max-width: 760px; margin: 0 auto; }
}
