/* Google Sans — Fontsource CDN (латиница + кириллица) */
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/latin-400-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/cyrillic-400-normal.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/latin-500-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/cyrillic-500-normal.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/latin-600-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/cyrillic-600-normal.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/latin-700-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Google Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(https://cdn.jsdelivr.net/fontsource/fonts/google-sans@latest/cyrillic-700-normal.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

:root {
  --bg: #141414;
  --bg-elevated: #181818;
  --bg-input: #181818;
  --border: #2a2a2e;
  --text: #e4e4e7;
  --text-muted: #8b8b92;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --user-msg-bg: #2a2a2e;
  --assistant-msg-bg: transparent;
  --error: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

/* Тонкий скроллбар: Firefox */
html {
  scrollbar-width: thin;
}

/* Тонкий скроллбар: Chrome, Edge, Safari (WebKit) */
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.screen.hidden {
  display: none;
}

/* ——— Token screen ——— */
#token-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.token-card {
  width: 100%;
  max-width: 400px;
  padding: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.token-header {
  margin-bottom: 24px;
}

.token-header .logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.token-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.token-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.token-form input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s;
}

.token-form input::placeholder {
  color: var(--text-muted);
}

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

.token-form button {
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.token-form button:hover {
  background: var(--accent-hover);
}

.token-form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.token-note {
  margin: 16px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ——— Chat screen ——— */
.chat-header {
  flex-shrink: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.chat-header-inner {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.logout-btn {
  padding: 8px 14px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.logout-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 16px;
}

.welcome {
  text-align: center;
  padding: 48px 24px;
}

.welcome p {
  margin: 0 0 8px;
  font-size: 1.25rem;
  color: var(--text);
}

.welcome-sub {
  font-size: 0.95rem !important;
  color: var(--text-muted) !important;
}

.msg {
  margin-bottom: 24px;
  padding: 16px 0;
}

.msg-user {
  padding: 14px 18px;
  background: var(--user-msg-bg);
  border-radius: var(--radius);
  margin-left: 0;
  margin-right: 0;
}

.msg-assistant {
  padding-left: 0;
  padding-right: 0;
}

.msg-role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.msg-content {
  font-size: 1rem;
  line-height: 1.6;
  word-break: break-word;
}

/* Сообщения пользователя — текст как есть, с сохранением переносов */
.msg-user .msg-content {
  white-space: pre-wrap;
}

/* Ответы ассистента (HTML/markdown) — без pre-wrap, чтобы вёрстка не разъезжалась */
.msg-assistant .msg-content {
  white-space: normal;
}

.msg-content p {
  margin: 0 0 0.75em;
}

.msg-content p:last-child {
  margin-bottom: 0;
}

/* Markdown и HTML в ответах ассистента */
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 1em 0 0.5em; font-weight: 600; }
.msg-content h1 { font-size: 1.25rem; }
.msg-content h2 { font-size: 1.1rem; }
.msg-content h3 { font-size: 1rem; }
.msg-content ul, .msg-content ol { margin: 0.5em 0; padding-left: 1.5em; }
.msg-content li { margin: 0.25em 0; }
.msg-content code { font-family: 'JetBrains Mono', ui-monospace, monospace; background: var(--bg-input); padding: 0.15em 0.4em; border-radius: 4px; font-size: 0.9em; }
.msg-content pre { font-family: 'JetBrains Mono', ui-monospace, monospace; position: relative; background: var(--bg-input); padding: 12px 12px 12px 12px; padding-top: 40px; border-radius: var(--radius-sm); overflow-x: auto; margin: 0.75em 0; }
.msg-content pre code { font-family: inherit; background: none; padding: 0; font-size: 0.875rem; }
/* Подсветка синтаксиса (highlight.js) — переопределяем фон под нашу тему */
.msg-content pre.hljs { background: var(--bg-input); padding: 12px; padding-top: 40px; }
/* Кнопка копирования в блоке кода */
.msg-content .code-block-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.msg-content .code-block-copy:hover {
  color: var(--text);
  border-color: var(--text-muted);
}
.msg-content .code-block-copy.code-block-copy-done {
  color: var(--accent);
  border-color: var(--accent);
}
.msg-content blockquote { border-left: 3px solid var(--border); margin: 0.75em 0; padding-left: 1em; color: var(--text-muted); }
.msg-content a { color: var(--accent); text-decoration: none; }
.msg-content svg { max-width: 100%; height: auto; vertical-align: middle; }

.msg-error .msg-content {
  color: var(--error);
}

.msg-loading .msg-content {
  color: var(--text-muted);
  min-height: 1.5em;
}

/* Фиксированная ширина для точек, анимация только по прозрачности — без подпрыгивания */
.msg-loading .typing-dots {
  display: inline-block;
  min-width: 2ch;
}
.msg-loading .typing-dots::after {
  content: '...';
  animation: dots-opacity 1s ease-in-out infinite;
}

@keyframes dots-opacity {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.input-area {
  flex-shrink: 0;
  padding: 16px 20px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chat-form {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.chat-form:focus-within {
  border-color: var(--accent);
}

.chat-form textarea {
  flex: 1;
  min-height: 40px;
  max-height: 200px;
  padding: 0;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  line-height: 1.5;
}

.chat-form textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

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

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .token-card {
    padding: 24px;
  }
  .messages {
    padding: 16px 12px;
  }
  .input-area {
    padding: 12px;
  }
}
