/* ===== Claude Manager — Apple-grade Dark UI ===== */

:root {
  --bg-primary: #141417;
  --bg-secondary: #1b1b1f;
  --bg-tertiary: #26262b;
  --bg-elevated: #313135;
  --bg-input: #202024;
  --bg-terminal: #121215;
  --bg-bubble-user: linear-gradient(135deg, #da7756, #c4613e);
  --bg-bubble-claude: #242428;
  --bg-header: rgba(20, 20, 23, 0.82);
  --bg-modal: rgba(0, 0, 0, 0.62);

  --text-primary: #ededf0;
  --text-secondary: #a8a8b0;
  --text-muted: #7a7a82;
  --text-faint: #55555c;
  --text-on-accent: #ffffff;

  --accent: #da7756;
  --accent-hover: #e88665;
  --accent-dim: rgba(218, 119, 86, 0.14);
  --accent-glow: rgba(218, 119, 86, 0.35);

  --green: #30d158;
  --yellow: #ffd60a;
  --red: #ff453a;
  --orange: #ff9f0a;

  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --border-focus: rgba(99, 102, 241, 0.5);

  --radius: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 6px 30px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.65);

  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --header-h: 52px;
  --subheader-h: 0px;
}

/* ===== Reset ===== */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.01em;
}

body {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
}

@supports (height: 100dvh) {
  body, #app { height: 100dvh; }
}

.screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ===== LOGIN SCREEN ===== */
#login-screen {
  align-items: center;
  justify-content: flex-start;
  padding: 20px;
  padding-top: max(60px, calc(20px + var(--safe-top)));
  padding-bottom: calc(20px + var(--safe-bottom));
  background:
    radial-gradient(ellipse at 20% 20%, rgba(218, 119, 86, 0.08) 0%, transparent 45%),
    radial-gradient(ellipse at 80% 80%, rgba(196, 97, 62, 0.06) 0%, transparent 45%),
    var(--bg-primary);
}

.login-container {
  width: 100%;
  max-width: 360px;
}

.login-logo {
  text-align: center;
  margin-bottom: 44px;
}

.logo-icon {
  margin-bottom: 20px;
  filter: drop-shadow(0 8px 24px rgba(218, 119, 86, 0.35));
}

.login-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.login-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 6px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.input-group input {
  width: 100%;
  padding: 15px 16px;
  font-size: 17px;
  font-family: var(--font-sans);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.input-group input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--accent-dim);
  background: var(--bg-tertiary);
}

.input-group input::placeholder {
  color: var(--text-faint);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  min-height: 46px;
  letter-spacing: -0.01em;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.12);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover, .btn-ghost:active {
  color: var(--text-primary);
  background: var(--accent-dim);
}

.btn-sm { padding: 9px 14px; font-size: 13px; min-height: 36px; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #ef3b30; }

.btn-loader {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  font-size: 13px;
  color: var(--red);
  text-align: center;
  padding: 10px 12px;
  background: rgba(255, 69, 58, 0.1);
  border-radius: var(--radius-sm);
}

/* ===== HEADER ===== */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  padding-top: var(--safe-top);
  padding-left: calc(8px + var(--safe-left));
  padding-right: calc(8px + var(--safe-right));
  background: var(--bg-header);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--border);
  height: calc(var(--header-h) + var(--safe-top));
  min-height: calc(var(--header-h) + var(--safe-top));
  z-index: 10;
  flex-shrink: 0;
  gap: 6px;
}

.header-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
}
#chat-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== SUBHEADER (hidden — moved to header / settings) ===== */
#subheader { display: none; }

/* ===== Header connection status ===== */
.header-connection {
  display: flex;
  align-items: center;
  gap: 5px;
}
.connection-text {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0;
}

/* Status dots */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { background: var(--green); box-shadow: 0 0 8px rgba(48, 209, 88, 0.6); }
.dot-yellow { background: var(--yellow); box-shadow: 0 0 8px rgba(255, 214, 10, 0.5); }
.dot-red { background: var(--red); box-shadow: 0 0 8px rgba(255, 69, 58, 0.6); }
.dot-orange { background: var(--orange); box-shadow: 0 0 8px rgba(255, 159, 10, 0.5); }
.dot-gray { background: var(--text-faint); }

/* Permission pill */
.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
  border: 1px solid transparent;
}
.pill-green  { background: rgba(48, 209, 88, 0.14); color: var(--green);  border-color: rgba(48, 209, 88, 0.25); }
.pill-yellow { background: rgba(255, 214, 10, 0.14); color: var(--yellow); border-color: rgba(255, 214, 10, 0.25); }
.pill-red    { background: rgba(255, 69, 58, 0.14); color: var(--red);    border-color: rgba(255, 69, 58, 0.3); }
.pill:hover { filter: brightness(1.25); }
.pill:active { transform: scale(0.95); }

/* Icon button */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--accent-dim); color: var(--text-primary); }
.icon-btn:active { transform: scale(0.92); }

/* ===== CHAT AREA ===== */
#chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

#messages-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
/* When only welcome is shown, center it */
#messages-container:has(.welcome-msg) {
  min-height: 100%;
  justify-content: center;
}

/* Welcome */
.welcome-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex: 1;
  padding: 60px 20px;
  text-align: center;
}
.welcome-icon {
  opacity: 0.85;
  filter: drop-shadow(0 6px 16px rgba(99, 102, 241, 0.25));
  margin-bottom: 8px;
}
.welcome-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.welcome-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

/* ===== MESSAGE BUBBLES ===== */
.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.25s ease;
}

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

.message-user {
  align-self: flex-end;
}

.message-user .bubble {
  background: var(--bg-bubble-user);
  color: var(--text-on-accent);
  border-radius: 20px 20px 6px 20px;
  padding: 11px 16px;
  font-size: 15.5px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 2px 10px rgba(218, 119, 86, 0.25);
  letter-spacing: -0.01em;
}

.copy-btn-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}
.copy-prompt-btn {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.15s, transform 0.1s;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.45);
}
.message-user:hover .copy-prompt-btn,
.copy-prompt-btn:focus { opacity: 1; }
.copy-prompt-btn:hover { color: rgba(255, 255, 255, 0.9); }
.copy-prompt-btn:active { opacity: 1; transform: scale(0.88); }
@media (hover: none) {
  .copy-prompt-btn { opacity: 0.5; }
}

.message-claude {
  align-self: flex-start;
}

.message-claude .bubble {
  background: var(--bg-bubble-claude);
  color: var(--text-primary);
  border-radius: 20px 20px 20px 6px;
  padding: 13px 17px;
  font-size: 15.5px;
  line-height: 1.55;
  border: 1px solid var(--border);
  letter-spacing: -0.005em;
}

.message-claude .bubble p { margin-bottom: 8px; }
.message-claude .bubble p:last-child { margin-bottom: 0; }
.message-claude .bubble strong { font-weight: 700; }
.message-claude .bubble em { font-style: italic; color: var(--text-secondary); }
.message-claude .bubble code {
  background: rgba(255,255,255,0.08);
  padding: 2px 7px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: #d4d4d8;
}
.message-claude .bubble pre {
  background: var(--bg-terminal);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
}
.message-claude .bubble pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  color: #cccccc;
}
.message-claude .bubble ul, .message-claude .bubble ol {
  padding-left: 24px;
  margin: 8px 0;
}
.message-claude .bubble li { margin: 2px 0; }

/* ===== Markdown: headings & lists (внутри bubble Claude) ===== */
.bubble .md-h {
  font-weight: 700;
  margin: 14px 0 6px;
  line-height: 1.3;
  color: var(--text-primary);
}
.bubble .md-h1 { font-size: 1.35em; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.bubble .md-h2 { font-size: 1.22em; }
.bubble .md-h3 { font-size: 1.10em; color: #da7756; }
.bubble .md-h4 { font-size: 1.02em; }
.bubble .md-h5, .bubble .md-h6 { font-size: 0.96em; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.bubble .md-h:first-child { margin-top: 0; }
.bubble .md-ul, .bubble .md-ol {
  margin: 6px 0 6px 0;
  padding-left: 22px;
}
.bubble .md-ul li, .bubble .md-ol li { margin: 3px 0; line-height: 1.45; }
.bubble .md-ul { list-style: disc; }
.bubble .md-ol { list-style: decimal; }
.bubble strong { font-weight: 700; color: var(--text-primary); }
.bubble em { font-style: italic; }

/* ===== Rate-limit pause card ===== */
/* Появляется в чате когда все аккаунты упёрлись в лимит. Заменяет собой
   мусорный финальный bubble. Содержит countdown + чекбокс авто-продолжения. */
.message-system { margin: 14px 0; display: flex; justify-content: center; }
.rate-limit-pause-card {
  width: 100%;
  max-width: 480px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.08), rgba(251, 146, 60, 0.05));
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text-primary);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}
.rl-pause-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  color: #fbbf24;
  margin-bottom: 10px;
}
.rl-pause-body { display: flex; flex-direction: column; gap: 10px; }
.rl-pause-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
}
.rl-pause-label { color: var(--text-muted); }
.rl-pause-countdown {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  color: #fbbf24;
  font-variant-numeric: tabular-nums;
}
.rl-pause-toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}
.rl-pause-toggle input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
  cursor: pointer;
}
.rl-pause-done {
  font-size: 11px;
  color: #4ade80;
  background: rgba(74, 222, 128, 0.08);
  padding: 5px 8px;
  border-radius: 6px;
}

/* ===== Markdown tables ===== */
/* Обёртка прокручивается по горизонтали — на телефоне таблицы из 5+ колонок
   не влезают, а wrap по ячейкам делает её нечитаемой. */
.md-table-wrap {
  margin: 10px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.02);
}
.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  line-height: 1.45;
}
.md-table th, .md-table td {
  padding: 7px 11px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  /* Переносить ТОЛЬКО на пробелах. Раньше унаследованный от .terminal-block
     `overflow-wrap: anywhere` ломал слова посимвольно — текст в ячейке
     выглядел как вертикальная колонна одиночных букв. Длинные слова без
     пробелов (URL/хэш) всё равно разорвутся через break-word. */
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
  line-height: 1.4;
  font-size: 12.5px;
}
.md-table {
  /* На узком экране даём таблице горизонтально скроллиться (через wrap'ер),
     но не сжимать колонки до буквенной колонны — каждой минимум ~80px. */
  min-width: 100%;
}
.md-table th, .md-table td {
  min-width: 90px;
}
.md-table th:last-child, .md-table td:last-child { border-right: none; }
.md-table tr:last-child td { border-bottom: none; }
.md-table thead th {
  background: rgba(255,255,255,0.05);
  font-weight: 600;
  color: var(--text-primary);
  position: sticky;
  top: 0;
  z-index: 1;
}
.md-table tbody tr:nth-child(even) td {
  background: rgba(255,255,255,0.015);
}
.md-table code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* ===== TERMINAL BLOCK (Live Phase) ===== */
.terminal-block {
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  color: #cccccc;
  max-height: 60vh;
  overflow-y: auto;
  /* НЕ даём горизонтальному скроллу появиться — длинные команды должны
     переноситься на новую строку, а не уезжать вправо за пределы экрана.
     overflow-wrap+anywhere ломает даже сплошные строки без пробелов
     (вроде длинных URL/UUID). */
  overflow-x: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

.terminal-block.live {
  border-color: rgba(218, 119, 86, 0.3);
  box-shadow: 0 0 0 3px var(--accent-dim);
  min-height: 40px;
}

/* Thinking stream (Claude's reasoning shown in real-time) */
.thinking-stream {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
/* Текстовые сообщения Claude между tool-вызовами — «промежуточные мысли»
   («Сейчас прочитаю X», «Нашёл проблему, чиню», «Готово»). Это не
   thinking-block (encrypted), а обычный text-блок ассистента. Стилизуем
   как читаемый абзац с лёгким акцентом — отличается от тулзов и thinking. */
.claude-narration {
  margin: 6px 0;
  padding: 6px 10px;
  color: #d8d8e0;
  font-size: 12.5px;
  line-height: 1.5;
  border-left: 2px solid rgba(218, 119, 86, 0.45);
  background: rgba(218, 119, 86, 0.05);
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Historical/persisted thinking blocks — server writes these into
   accumulatedTerminal so they survive reloads with the same look. */
.thinking-block {
  color: #8b8ba0;
  font-style: italic;
  font-size: 12px;
  line-height: 1.5;
  margin: 4px 0;
  padding: 4px 8px;
  border-left: 2px solid rgba(218, 119, 86, 0.3);
  white-space: pre-wrap;
}
.thinking-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #da7756;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.thinking-content {
  color: #8b8ba0;
  font-style: italic;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 40vh;
  overflow-y: auto;
}

/* Tool use badges in terminal. Изменилась структура: было одной строкой
   (badge + preview), стало блоком (head + опциональная команда). На головке
   все компактно как раньше; команда — отдельный <pre> ниже. */
.tool-use-line {
  margin: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tool-use-line.clickable .tool-head { cursor: pointer; }
.tool-use-line.clickable .tool-head:hover { background: rgba(255,255,255,0.03); border-radius: 4px; }
.tool-expand-arrow {
  display: inline-block;
  font-size: 9px;
  color: var(--text-muted);
  width: 10px;
  transition: transform 0.12s;
}
.tool-use-line.expanded .tool-expand-arrow { transform: rotate(90deg); }

/* Expanded tool panel — раскрывается по клику на .tool-use-line */
.tool-expanded-panel {
  margin: 6px 0 4px 18px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.025);
  border-left: 2px solid rgba(218,119,86,0.35);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.45;
}
.tool-expanded-panel .tp-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 6px 0 3px;
  font-weight: 600;
}
.tool-expanded-panel .tp-label:first-child { margin-top: 0; }
.tool-expanded-panel .tp-desc {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 11px;
  margin-bottom: 6px;
}
.tool-expanded-panel .tp-cmd,
.tool-expanded-panel .tp-out,
.tool-expanded-panel .tp-path {
  margin: 0;
  padding: 6px 8px;
  background: rgba(0,0,0,0.25);
  border-radius: 4px;
  color: #d8d8e0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 320px;
  overflow-y: auto;
  font-size: 11px;
}
.tool-expanded-panel .tp-cmd { border-left: 2px solid rgba(96,165,250,0.5); }
.tool-expanded-panel .tp-path { border-left: 2px solid rgba(167,139,250,0.4); color: #c7c2ff; }
.tool-expanded-panel .tp-out { border-left: 2px solid rgba(255,255,255,0.1); }
.tool-expanded-panel .tp-meta {
  font-size: 10.5px;
  color: var(--text-muted);
  margin: 2px 0;
}
.tool-expanded-panel .tp-pending {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  padding: 6px 0;
}
.tool-expanded-panel .tp-flag {
  display: inline-block;
  font-size: 9px;
  background: rgba(218,119,86,0.2);
  color: #e8a88a;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
}
.tool-expanded-panel .tp-todo {
  font-size: 11.5px;
  padding: 3px 0;
  color: var(--text-primary);
}
.tool-expanded-panel .tp-todo-completed { color: var(--text-muted); text-decoration: line-through; }
.tool-expanded-panel .tp-todo-in_progress { color: var(--accent); font-weight: 600; }

/* Diff block для Edit/MultiEdit */
.tool-expanded-panel .diff-block {
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  padding: 6px 0;
  overflow-x: auto;
}
.tool-expanded-panel .diff-line {
  padding: 1px 8px;
  white-space: pre;
  font-size: 11px;
  font-family: var(--font-mono);
  word-break: keep-all;
}
.tool-expanded-panel .diff-ctx { color: #6b6b80; }
.tool-expanded-panel .diff-rem {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}
.tool-expanded-panel .diff-add {
  background: rgba(34, 197, 94, 0.12);
  color: #4ade80;
}
.tool-head {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}
.tool-command {
  margin: 2px 0 4px 4px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.04);
  border-left: 2px solid rgba(218,119,86,0.5);
  border-radius: 4px;
  color: #d8d8e0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 220px;
  overflow-y: auto;
}
.tool-badge {
  display: inline-block;
  background: rgba(218, 119, 86, 0.18);
  color: #e8a88a;
  padding: 2px 8px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
}
.tool-count {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-weight: 600;
}
.tool-preview {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  /* Длинные пути/команды переносим, а не обрезаем ellipsis'ом — раньше
     половина инфо уходила за край и пользователю приходилось скроллить
     терминал горизонтально (которого больше нет). break-all нужен потому
     что в путях/командах нет пробелов, на которые word-break: break-word
     мог бы опереться. */
  white-space: normal;
  word-break: break-all;
  overflow-wrap: anywhere;
  min-width: 0;
  flex: 1 1 100%;
  line-height: 1.4;
}
.tool-use-line {
  min-width: 0;
}

/* Streamed assistant output — merged into one span per run to keep the DOM
   flat. Without this, token-granular streaming would create thousands of
   nested nodes and tank scroll performance. */
.output-chunk {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary, #e8e8f0);
  font-size: 12px;
  line-height: 1.5;
}

/* ============ Codex reviewer (ChatGPT-driven) ============
 * Violet/indigo accent to clearly distinguish from Claude's orange. Every
 * Codex bubble MUST carry the anti-fake footer (tokens + session-id) — the
 * .codex-footer is structural, not optional. */
.message-codex {
  align-self: flex-start;
  max-width: 88%;
}
.codex-bubble {
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.13), rgba(99, 102, 241, 0.10));
  color: var(--text-primary);
  border-radius: 18px 18px 18px 6px;
  padding: 12px 16px 8px;
  font-size: 15.5px;
  line-height: 1.55;
  border: 1px solid rgba(139, 92, 246, 0.45);
  letter-spacing: -0.005em;
  position: relative;
}
.codex-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -2px 0 8px;
  font-size: 12.5px;
  color: #c4b5fd;
  font-weight: 600;
}
.codex-avatar {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.codex-label-head { letter-spacing: 0.02em; }
.codex-reasons {
  font-size: 11px;
  font-weight: 500;
  color: #a78bfa;
  background: rgba(139, 92, 246, 0.18);
  padding: 1px 7px;
  border-radius: 8px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.codex-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(139, 92, 246, 0.35);
  border-top-color: #c4b5fd;
  border-radius: 50%;
  animation: codex-spin 0.9s linear infinite;
  margin-left: auto;
}
@keyframes codex-spin { to { transform: rotate(360deg); } }
.codex-message {
  margin-bottom: 8px;
}
.codex-message p { margin-bottom: 8px; }
.codex-message p:last-child { margin-bottom: 0; }
.codex-message code {
  background: rgba(255,255,255,0.07);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: #ede9fe;
}
.codex-message pre {
  background: #1a1530;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
}
.codex-pending .codex-message { color: var(--text-muted); font-style: italic; }
.codex-footer {
  border-top: 1px solid rgba(139, 92, 246, 0.25);
  margin-top: 8px;
  padding-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: #a78bfa;
}
.codex-footer-cell { white-space: nowrap; }
.codex-footer-key { color: #c4b5fd; margin-right: 2px; }
.codex-tokens-val, .codex-session-val { color: #ede9fe; }
.codex-verdict-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.05em;
}
.codex-verdict-approve { background: rgba(74, 222, 128, 0.18); color: #86efac; border: 1px solid rgba(74, 222, 128, 0.45); }
.codex-verdict-amend   { background: rgba(250, 204, 21, 0.18); color: #fde68a; border: 1px solid rgba(250, 204, 21, 0.45); }
.codex-verdict-reject  { background: rgba(248, 113, 113, 0.18); color: #fca5a5; border: 1px solid rgba(248, 113, 113, 0.45); }

/* ============ Codex reviewer header button + panel ============ */
.codex-btn { transition: color 0.15s; }
.codex-btn.codex-on { color: #a78bfa; }
.codex-btn.codex-on:hover { color: #c4b5fd; }

/* ChatGPT badge — рисуется рядом с названием чата в сайдбаре и в шапке
 * открытого диалога, когда GPT-ревьюер для этого диалога включён. Сам SVG —
 * шестилепестковая «розетка» (три повёрнутых эллипса), стилизованная под
 * OpenAI hex-knot. Зелёный — фирменный цвет ChatGPT-приложения. */
.chatgpt-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin-left: 6px;
  width: 16px;
  height: 16px;
  color: #10a37f;
  flex-shrink: 0;
}
.chatgpt-badge:hover { color: #1cb98f; }
.chatgpt-icon {
  width: 100%;
  height: 100%;
  display: block;
}
/* Слегка крупнее в шапке открытого диалога — там есть место. */
.header-title .chatgpt-badge {
  width: 17px;
  height: 17px;
  margin-left: 7px;
}
/* В сайдбаре чуть мельче — там плотная вёрстка. */
.convo-title .chatgpt-badge {
  width: 14px;
  height: 14px;
  margin-left: 5px;
}

#codex-panel .modal-panel { max-width: 460px; }
.codex-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.codex-section:last-child { border-bottom: none; }
.codex-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.codex-label { font-size: 14.5px; font-weight: 500; color: var(--text-primary); }
.codex-field-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.codex-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 8px 0 0;
  line-height: 1.4;
}
.codex-hint code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: rgba(139, 92, 246, 0.12);
  padding: 1px 5px;
  border-radius: 3px;
  color: #c4b5fd;
}
.codex-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--bg-input, rgba(255,255,255,0.04));
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 14px;
}
.codex-input:focus { outline: none; border-color: #8b5cf6; }
.codex-status-section {
  background: rgba(139, 92, 246, 0.05);
}
.codex-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 4px 0;
}
.codex-status-key { color: var(--text-muted); }
.codex-status-val { color: var(--text-primary); }
.codex-status-mono { font-family: var(--font-mono); font-size: 12.5px; }

/* Working indicator */
.working-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-muted);
  align-self: flex-start;
}

.pulse-dot, .pulse-dot-sm {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}
.pulse-dot-sm { width: 6px; height: 6px; }

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { opacity: 1; transform: scale(1.2); box-shadow: 0 0 0 6px transparent; }
}

/* Expand/collapse toggle */
.toggle-output {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  align-self: flex-start;
  font-family: var(--font-sans);
}
.toggle-output:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.07);
}

.terminal-expandable {
  overflow: hidden;
  transition: max-height 0.22s ease, opacity 0.2s ease, margin-top 0.2s ease;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}
.terminal-expandable.expanded {
  max-height: 60vh;
  opacity: 1;
  margin-top: 10px;
}

/* ===== INPUT AREA ===== */
#input-area {
  /* Внутренние отступы фиксированы; safe-bottom уже учитывается через
     padding снаружи (см. body / #app). Стабильная высота — input не «прыгает»
     при возврате из file picker / открытии клавиатуры. */
  padding: 8px 12px 8px;
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 22px;
  /* Чуть толще paddings + единая структура — pill теперь идеальная форма. */
  padding: 4px 4px 4px 4px;
  transition: border-color 0.18s, box-shadow 0.18s;
  box-sizing: border-box;
}
.input-row {
  display: flex;
  align-items: flex-end;
  /* Все элементы row (кнопки 36x36 + textarea min-height 36) выровнены по
     нижнему краю — кнопки лежат строго на одной горизонтали. */
  gap: 2px;
  min-height: 44px;
}
.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#message-input {
  flex: 1 1 0%;
  font-size: 16px;
  font-family: var(--font-sans);
  background: transparent;
  border: none;
  color: var(--text-primary);
  outline: none;
  resize: none;
  /* min-height = высота кнопок, чтобы пустой textarea был ровно одной
     высоты с send/attach. max-height предохраняет от заполнения экрана. */
  min-height: 36px;
  max-height: 160px;
  line-height: 1.45;
  padding: 8px 6px;
  letter-spacing: -0.01em;
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  box-sizing: border-box;
}
#message-input::placeholder { color: var(--text-faint); }
#message-input:disabled { opacity: 0.5; }

/* ===== Round 36px кнопки рядом с textarea (attach / schedule / send) ===== */
.attach-button,
.schedule-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  margin: 0;
  padding: 0;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.attach-button:hover,
.schedule-button:hover { color: var(--text-primary); background: var(--accent-dim); }
.attach-button:active,
.schedule-button:active { transform: scale(0.92); }

.send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  margin: 0;
  padding: 0;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 1px 3px rgba(218, 119, 86, 0.4), inset 0 1px 0 rgba(255,255,255,0.15);
}
.send-button:hover { background: var(--accent-hover); }
.send-button:disabled { opacity: 0.25; cursor: not-allowed; box-shadow: none; }
.send-button:active:not(:disabled) { transform: scale(0.92); }

/* ===== Boot overlay ===== */
/* Виден сразу при заходе на страницу и скрывается когда либо main screen готов,
   либо checkAuth решил, что нужно показывать login. Прогресс реальный — каждый
   чекпоинт (WS, accounts, conversations, perms, config) даёт +20%. */
.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: var(--bg-primary, #0a0a0f);
  display: flex;
  align-items: center;
  justify-content: center;
  /* iPhone safe area + home indicator. */
  padding: env(safe-area-inset-top, 0px) 20px env(safe-area-inset-bottom, 0px);
  opacity: 1;
  transition: opacity 0.32s ease;
}
.boot-overlay.fading { opacity: 0; pointer-events: none; }
.boot-overlay.hidden { display: none !important; }
.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 280px;
  width: 100%;
}
.boot-logo { margin-bottom: 14px; }
.boot-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 18px;
  color: var(--text-primary, #e6e6e6);
}
.boot-label {
  font-size: 13px;
  color: var(--text-secondary, #9ca3af);
  margin-bottom: 10px;
}
.boot-bar {
  width: 100%;
  max-width: 240px;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}
.boot-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #da7756, #fbbf24);
  border-radius: inherit;
  transition: width 0.28s ease;
  box-shadow: 0 0 8px rgba(218,119,86,0.4);
}
.boot-hint {
  font-size: 11.5px;
  color: var(--text-muted, #6b7280);
  min-height: 16px;
}

/* Reload overlay — затемнённое окно поверх UI пока идёт догрузка состояния
 * (после потери WS / возврата во вкладку). z-index выше modal-overlay
 * (1000) и боковой панели (≈100), но ниже boot-overlay (99999) — boot
 * первичный, reload вторичный.
 *
 * `pointer-events: auto` (через :not(.hidden)) — overlay перехватывает
 * клики, чтобы пользователь не тыкал по застывшему UI и не запускал
 * action'ы пока состояние не догрузилось. backdrop-filter blur даёт
 * лёгкую расфокусировку фона — пользователь видит, что приложение
 * рядом, но взаимодействовать пока нельзя. */
.reload-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 15, 0.58);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: env(safe-area-inset-top, 0px) 20px env(safe-area-inset-bottom, 0px);
  opacity: 1;
  transition: opacity 0.2s ease;
  pointer-events: auto;
}
.reload-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.reload-card {
  background: var(--bg-elevated, #313135);
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 14px;
  padding: 22px 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 280px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}
.reload-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(218,119,86,0.18);
  border-top-color: #da7756;
  border-radius: 50%;
  animation: reload-spin 0.9s linear infinite;
}
@keyframes reload-spin { to { transform: rotate(360deg); } }
.reload-label {
  font-size: 13.5px;
  color: var(--text-secondary, #9ca3af);
  text-align: center;
  line-height: 1.4;
}
.reload-force-reload {
  margin-top: 4px;
  font-size: 12px;
  padding: 6px 12px;
  opacity: 0.85;
}
.reload-force-reload.hidden { display: none !important; }

/* CLAUDE.md editor modal */
.claudemd-modal-panel { max-width: 720px; }
.claudemd-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.45;
}
.claudemd-hint code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: rgba(255,255,255,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  word-break: break-all;
}
.claudemd-textarea {
  width: 100%;
  min-height: 240px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg-terminal);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  resize: vertical;
  -webkit-overflow-scrolling: touch;
}
.claudemd-textarea:focus { outline: none; border-color: var(--accent); }
.claudemd-status.error { color: #f87171; }
.claudemd-status.ok { color: #22c55e; }

/* Rollback button on user bubble — серая, маленькая, в copy-btn-row.
   Случайный клик безопасен: показывает модалку-подтверждение. */
.rollback-msg-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 14px;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.rollback-msg-btn:hover { color: #ef4444; background: rgba(239,68,68,0.12); }
.rollback-msg-btn:active { transform: scale(0.92); }

/* Rollback confirm dialog */
.rollback-dialog { max-width: 460px; }
.rollback-warn {
  background: rgba(239,68,68,0.10);
  border-left: 3px solid #ef4444;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  color: #fca5a5;
  margin-bottom: 12px;
}
.rollback-preview-wrap {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.rollback-preview-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.rollback-preview {
  font-size: 13px;
  color: var(--text-primary);
  word-break: break-word;
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.45;
}
.rollback-note { font-size: 11.5px; line-height: 1.45; }

/* Маркер «↳ вдогонку» — каждая приписка внутри user-bubble. */
.followup-tag {
  display: inline-block;
  padding: 1px 7px;
  margin-right: 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  background: rgba(96,165,250,0.18);
  color: #93c5fd;
  vertical-align: middle;
}

/* Приписка-«вдогонку» внутри prompt-bubble. Визуально отделяется лёгкой
   пунктирной линией сверху и небольшим отступом — пользователь видит, что
   это продолжение исходного промпта, а не его часть. Можно класть несколько
   подряд. У каждого сегмента — своя строка действий (время + откат + копи),
   как у самостоятельного сообщения. */
/* Followup-сегмент — приписка ВНУТРИ исходного prompt-bubble (одна общая
 * рамка, dashed разделитель). Раньше margin-top:10 + padding-top:10 давали
 * визуальный воздушный gap ~20px и followup казался отдельным сообщением;
 * сжали до 6+6 = ~12px реального промежутка через разделитель. */
.user-followup {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255,255,255,0.22);
  font-size: 14.5px;
  line-height: 1.4;
}
.user-followup-text {
  display: block;
  margin-top: 2px;
  color: inherit;
  word-break: break-word;
  white-space: pre-wrap;
}
/* Hover/touch на bubble подсвечивает действия и followup-сегмента тоже —
   правило .message-user:hover .copy-prompt-btn уже сделает это; здесь
   явно прописываем msg-time чтобы он сидел слева, а кнопки прижались
   справа в той же копи-строке. */
.user-followup .copy-btn-row {
  margin-top: 4px;
}

/* Send ↔ Stop toggle.
   ВАЖНО: ни на одну из иконок не вешать класс `.hidden` — у него
   `display:none !important;`, и состояние .send-button.working не сможет
   переключить видимость через обычный селектор. */
.send-button .icon-send { display: flex; }
.send-button .icon-stop { display: none; }
.send-button.working {
  background: #ef4444;
  color: white;
  border: none;
  /* Тонкое внутреннее свечение + лёгкая внешняя обводка вместо «уродского»
     большого красного круга без иконки. Иконка стоп — чёткий белый
     закруглённый квадрат внутри. */
  box-shadow:
    inset 0 0 0 1.5px rgba(255,255,255,0.22),
    0 0 0 3px rgba(239, 68, 68, 0.18),
    0 2px 10px rgba(239, 68, 68, 0.45);
  width: 34px;
  height: 34px;
  animation: stop-ring-pulse 2.2s ease-in-out infinite;
}
.send-button.working .icon-send { display: none; }
.send-button.working .icon-stop { display: flex; color: white; }
.send-button.working:hover {
  background: #f56363;
  animation: none;
  box-shadow:
    inset 0 0 0 1.5px rgba(255,255,255,0.3),
    0 0 0 5px rgba(239, 68, 68, 0.22),
    0 2px 12px rgba(239, 68, 68, 0.55);
}
.send-button.working:active { transform: scale(0.92); animation: none; }
@keyframes stop-ring-pulse {
  0%, 100% {
    box-shadow:
      inset 0 0 0 1.5px rgba(255,255,255,0.22),
      0 0 0 3px rgba(239, 68, 68, 0.18),
      0 2px 10px rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow:
      inset 0 0 0 1.5px rgba(255,255,255,0.32),
      0 0 0 6px rgba(239, 68, 68, 0.08),
      0 2px 14px rgba(239, 68, 68, 0.55);
  }
}
/* Follow-up mode: пользователь печатает во время работы Claude.
   Кнопка возвращается к виду «отправить» (синий акцент), но мы помним
   что Claude всё ещё работает — это сообщение полетит вдогонку. */
.send-button.followup {
  background: var(--accent);
  animation: none;
  box-shadow: 0 1px 3px rgba(218, 119, 86, 0.4), inset 0 1px 0 rgba(255,255,255,0.18);
}
.send-button.followup .icon-send { display: flex; }
.send-button.followup .icon-stop { display: none; }
.send-button.followup:hover { background: var(--accent-hover); }

/* CLI Status Bar */
.cli-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  margin-top: 6px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  gap: 12px;
}
.cli-status-bar .status-activity {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cli-status-bar .status-timer {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  flex-shrink: 0;
}
/* Live elapsed timer — раньше жил в .cli-status-bar и его выдавливало
 * длинным activity-текстом + tokens. Перенесли в floating badge в правом
 * верхнем углу message-claude wrapper'а: position absolute, маленькая
 * pill-форма, не мешает потоку, всегда видна. После task_complete wrapper
 * перестраивается (state.liveWrapper.innerHTML заменяется на финальный
 * bubble) — badge удаляется вместе с ним. tabular-nums чтобы ширина не
 * прыгала на каждом тике. */
.message-claude { position: relative; }
.live-elapsed-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  z-index: 2;
  padding: 2px 9px 3px;
  background: rgba(20, 22, 28, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.live-elapsed-badge:empty { display: none; }
/* Замороженная финальная длительность — дописывается и в server'овский
 * accumulatedTerminal (websocket.js task_complete), и в client'овский
 * state.liveTerminal перед finishLiveBlock'ом. Стиль одинаков в обоих
 * вариантах (live и persistent), потому что DOM-структура одна. */
.terminal-duration {
  margin: 10px 4px 2px;
  padding: 6px 10px;
  border-top: 1px dashed rgba(148, 163, 184, 0.28);
  color: #86efac;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  letter-spacing: 0.02em;
}

/* ============ ASK_USER card (викторина-уточнение) ============
 * Карточка рисуется ПОД claude-bubble когда Claude эмитил блок >>>ASK_USER.
 * После клика "Отправить ответы" карточка получает .askuser-answered —
 * кнопки disabled, выбранные подсвечены, submit заменён на статус.
 * Цвет акцента — голубой (#60a5fa), чтобы визуально отличать от Codex (фиолетовый),
 * rate-limit (жёлтый) и compact (зелёный) карточек. */
.askuser-card {
  margin: 12px 0 4px;
  padding: 14px 16px 12px;
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.08), rgba(96, 165, 250, 0.03));
  border: 1px solid rgba(96, 165, 250, 0.28);
  border-radius: 12px;
}
.askuser-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.askuser-icon {
  font-size: 16px;
  line-height: 1;
}
.askuser-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.askuser-status {
  font-size: 11.5px;
  color: #86efac;
  font-weight: 500;
  flex-shrink: 0;
}
.askuser-questions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.askuser-q {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.askuser-q-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.45;
}
.askuser-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.askuser-yesno .askuser-option {
  min-width: 64px;
  text-align: center;
}
.askuser-multi {
  flex-direction: column;
  gap: 4px;
}
.askuser-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.askuser-option:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: rgba(96, 165, 250, 0.55);
}
.askuser-option:active:not(:disabled) {
  transform: scale(0.98);
}
.askuser-option.selected {
  background: rgba(96, 165, 250, 0.18);
  border-color: rgba(96, 165, 250, 0.75);
  color: #c7dcff;
}
.askuser-option:disabled {
  cursor: default;
  opacity: 0.55;
}
.askuser-option.selected:disabled {
  opacity: 1;
  background: rgba(96, 165, 250, 0.22);
  border-color: rgba(96, 165, 250, 0.85);
}
.askuser-option-label {
  display: block;
  line-height: 1.3;
}
.askuser-option-desc {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 400;
  line-height: 1.35;
}
/* Multi: чекбокс-варианты в столбик */
.askuser-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}
.askuser-checkbox:hover:has(input:not(:disabled)) {
  background: var(--bg-elevated);
  border-color: rgba(96, 165, 250, 0.55);
}
.askuser-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: #60a5fa;
  cursor: pointer;
  flex-shrink: 0;
}
.askuser-checkbox input:disabled { cursor: default; }
.askuser-checkbox .askuser-option-desc {
  flex-basis: 100%;
  margin-left: 24px;
}
/* Text input */
.askuser-text-wrap { display: flex; }
.askuser-text {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}
.askuser-text:focus {
  outline: none;
  border-color: rgba(96, 165, 250, 0.7);
}
.askuser-text:disabled {
  opacity: 0.7;
  cursor: default;
}
.askuser-footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.askuser-submit {
  font-size: 13px;
  padding: 8px 16px;
}
.askuser-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.askuser-foot-status {
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
}
.askuser-card.askuser-pending {
  opacity: 0.85;
  pointer-events: none;
}
.askuser-card.askuser-answered {
  background: rgba(96, 165, 250, 0.04);
  border-color: rgba(96, 165, 250, 0.18);
}
.status-dot-live {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

/* Attach button stylesheet is defined в основном блоке input area сверху
   (единый 36x36 round) — здесь оставлен только заголовок секции для
   читаемости. */

/* Attachment preview chips.
   Inline above the input wrapper (not absolutely positioned) so the iOS
   keyboard-avoidance logic resizes both input and preview as a unit. */
.attach-preview {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 5px;
  padding: 4px 4px 4px;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
  /* Стабильная высота тяжа — точно в высоту chip'а, чтобы input-row не
     прыгал когда у пользователя добавляются/убираются файлы. */
  min-height: 30px;
}
.attach-preview.hidden { display: none; }
.attach-preview::-webkit-scrollbar { display: none; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  border-radius: 14px;
  padding: 3px 8px;
  font-size: 11.5px;
  color: var(--text-secondary);
  max-width: 200px;
  flex-shrink: 0;
  height: 26px;
}
.attach-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-chip-remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
.attach-chip-remove:hover { color: var(--red); }

/* Attachment tags in message bubble */
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.attach-tag {
  display: inline-block;
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 12px;
}

#input-status { display: none; } /* removed */

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-modal);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease;
}
/* «Верхний» модал — открывается ПОВЕРХ уже открытого модала (например,
   список saved-sessions поверх настроек, или превью сессии поверх списка).
   Без этого слайды наезжают с одинаковым z-index и второй модал визуально
   накрывается фоном первого. */
.modal-overlay.modal-top { z-index: 130; }
.modal-overlay.modal-top.modal-top-2 { z-index: 140; }

.modal-dialog {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: scaleIn 0.2s cubic-bezier(.17,.67,.3,1.01);
}
@keyframes scaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 340px;
  max-width: 88vw;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  padding-top: var(--safe-top);
  /* padding-bottom переехал ВНУТРЬ — на .modal-body и .modal-footer.
     На panel он давал «полку» цвета bg-secondary под скроллом: контент
     обрезался выше home-indicator'а, видна была пустая полоса того же
     цвета что и панель. Внутренний padding-bottom скроллит вместе с
     содержимым, поэтому последний элемент остаётся выше home-indicator,
     а полосы нет. */
}
.slide-right {
  right: 0;
  border-left: 1px solid var(--border-strong);
  animation: slideInRight 0.25s cubic-bezier(.2,.8,.2,1);
}
.slide-left {
  left: 0;
  border-right: 1px solid var(--border-strong);
  animation: slideInLeft 0.25s cubic-bezier(.2,.8,.2,1);
}
/* .slide-up — bottom sheet. До этого фикса класс был, а CSS-правила не
   было: панель растягивалась на весь экран по умолчанию от .modal-panel,
   мешала видеть остальное и оставляла «полку» внизу. */
.slide-up {
  top: auto;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 100%;
  max-height: 92vh;
  border-top: 1px solid var(--border-strong);
  border-radius: 16px 16px 0 0;
  animation: slideInUp 0.25s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slideInLeft  { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes slideInUp    { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2, .modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  /* Внутренний safe-area, чтобы последний элемент не упирался в
     home-indicator на iPhone. max() гарантирует минимум 14px на
     устройствах без safe-area-inset-bottom. */
  padding-bottom: max(14px, var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.modal-footer {
  padding: 12px 16px;
  padding-bottom: max(12px, var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.modal-actions { justify-content: flex-end; }

/* ===== COMPACT MODAL ===== */
.compact-modal-panel { max-width: 520px; }
.compact-modal-warning {
  background: rgba(255, 184, 0, 0.08);
  border-left: 3px solid #fbbf24;
  color: #f5d089;
  padding: 8px 12px;
  border-radius: 6px;
  margin: 0 0 14px 0;
  font-size: 13px;
  line-height: 1.45;
}
.compact-modal-label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.compact-modal-textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary, rgba(255,255,255,0.04));
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  box-sizing: border-box;
}
.compact-modal-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.compact-modal-hint {
  margin: 8px 0 0 0;
  font-size: 11.5px;
  line-height: 1.4;
}

/* ===== CONVERSATION LIST ===== */
#new-chat-btn {
  margin-bottom: 12px;
}
.convo-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.convo-item {
  display: flex;
  align-items: center;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  min-height: 54px;
}
.convo-item:hover { background: var(--accent-dim); }
.convo-item.active { background: var(--accent-dim); }
/* Working dot — мигающая зелёная точка слева от title пока в диалоге идёт
   стрим Claude (даже если этот диалог не активен — пользователь видит что
   там что-то происходит и может переключиться). */
.convo-working-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 6px;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.7);
  animation: convo-working-pulse 1.4s ease-in-out infinite;
  vertical-align: middle;
}
.convo-working-dot.hidden { display: none; }
@keyframes convo-working-pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.1); }
}
.convo-item.working .convo-title { color: #4ade80; font-weight: 600; }

.convo-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.convo-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}
.convo-delete {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-faint);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s;
  flex-shrink: 0;
}
.convo-item:hover .convo-delete,
.convo-item.active .convo-delete { opacity: 1; }
.convo-delete:hover { color: var(--red); background: rgba(255,69,58,0.12); }

/* ===== ACCOUNT ITEMS ===== */
.account-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: background 0.15s, border-color 0.15s;
}
.account-item:hover { background: var(--accent-dim); }
.account-item.active { border-color: var(--accent); background: var(--accent-dim); }

.account-info { flex: 1; min-width: 0; }
.account-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.account-actions {
  display: flex;
  gap: 4px;
}

.add-account-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}
.add-account-form input {
  width: 100%;
  padding: 11px 13px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.add-account-form input:focus { border-color: var(--border-focus); }
.add-account-form input::placeholder { color: var(--text-faint); }

.empty-hint {
  color: var(--text-muted);
  text-align: center;
  padding: 24px 12px;
  font-size: 13px;
  line-height: 1.55;
}

/* ===== PERMISSION MODAL ===== */
.command-display {
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: #4ade80;
  margin: 8px 0;
  white-space: pre-wrap;
  word-break: break-all;
}
.command-display::before { content: '$ '; color: var(--text-muted); }

/* ===== LIMIT MODAL ===== */
#limit-modal-content {
  padding: 24px;
  text-align: center;
}
#limit-modal-content h3 {
  margin-bottom: 16px;
  font-size: 18px;
}
#limit-modal-content p {
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.6;
}
.countdown {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  margin: 18px 0;
}
.limit-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  z-index: 200;
  animation: toastIn 0.25s cubic-bezier(.2,.8,.2,1), toastOut 0.2s ease 2.6s forwards;
  pointer-events: none;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .modal-panel { width: 100%; max-width: 100%; }
  .message { max-width: 92%; }
  #chat-area { padding: 12px; }
  .welcome-msg { padding: 40px 16px; }
  .welcome-title { font-size: 20px; }
}

/* Larger tap targets on touch devices */
@media (hover: none) and (pointer: coarse) {
  .convo-delete { opacity: 0.6; } /* always visible on touch */
}

/* Prevent text selection on UI chrome */
#header, #subheader, #input-area, .modal-header, .modal-footer,
.btn, .pill, .icon-btn, .convo-meta, .account-meta {
  -webkit-user-select: none;
  user-select: none;
}
/* Allow selection in message content + terminal */
.bubble, .terminal-block, .command-display, #message-input {
  -webkit-user-select: text;
  user-select: text;
}

/* Restart spinner (settings → перезагрузить сервер) */
.restart-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 3px solid rgba(218, 119, 86, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: restart-spin 0.8s linear infinite;
}
@keyframes restart-spin {
  to { transform: rotate(360deg); }
}

/* Small utility styles wired from app.js */
.bubble-error {
  border-color: var(--red) !important;
  color: var(--red);
}
.empty-msg {
  color: var(--text-muted);
  text-align: center;
  padding: 24px 16px;
  font-size: 13px;
  line-height: 1.5;
}

/* ===== CONTEXT popover ===== */
.context-popover {
  position: fixed;
  top: 52px;
  right: 8px;
  width: 320px;
  max-width: calc(100vw - 16px);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  padding: 12px 14px;
  z-index: 9000;
  font-size: 12px;
  color: var(--text-primary);
  animation: ctxpop-in 0.16s ease;
}
.context-popover.hidden { display: none; }
@keyframes ctxpop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.context-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: #a78bfa;
  margin-bottom: 10px;
}
.context-popover-header .icon-btn { width: 24px; height: 24px; }
.context-total {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
}
.context-total strong { color: #facc15; }
.context-total .context-pct { color: var(--text-muted); font-size: 12px; margin-left: 6px; }
.context-bar {
  display: flex;
  height: 14px;
  background: rgba(255,255,255,0.05);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
.context-bar-fill { display: flex; width: 100%; }
.context-bar-seg {
  height: 100%;
  transition: width 0.35s ease;
}
.context-bar-loading {
  background: linear-gradient(90deg, #444 25%, #666 50%, #444 75%);
  background-size: 200% 100%;
  animation: ctx-loading-shimmer 1.2s infinite;
}
@keyframes ctx-loading-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.context-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  font-size: 11.5px;
}
.context-legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.context-legend-dot {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.context-legend-label { flex: 1; color: var(--text-secondary); }
.context-legend-val {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 600;
}
.context-hint {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid rgba(255,255,255,0.05);
  padding-top: 8px;
  line-height: 1.5;
}
.context-hint code {
  background: rgba(255,255,255,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.context-actions {
  margin-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.05);
  padding-top: 10px;
}
.context-actions .btn { font-size: 12px; }

/* Круговой индикатор на иконке Контекст в шапке */
.context-indicator svg { display: block; }
#context-indicator-arc { transition: stroke-dashoffset 0.4s ease, stroke 0.25s; }
#context-indicator-text {
  font-family: var(--font-mono);
  pointer-events: none;
}

/* ===== ATTACHMENT preview ===== */
.attach-tag.clickable {
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.attach-tag.clickable:hover {
  background: var(--accent-dim);
  color: var(--accent);
}
.attach-viewer-panel { max-width: 760px; }
.attach-img-preview {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: 6px;
  background: rgba(0,0,0,0.2);
}
.attach-pdf-preview {
  width: 100%;
  height: 70vh;
  border: 0;
  background: white;
  border-radius: 6px;
}
.attach-text-preview {
  margin: 0;
  padding: 12px;
  background: rgba(0,0,0,0.25);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 70vh;
  overflow-y: auto;
}

/* ===== PC SESSIONS panel ===== */
.pc-sessions-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.pc-sessions-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}
.pc-sessions-status {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-family: var(--font-mono);
}
.pc-sessions-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pc-session-item {
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s;
}
.pc-session-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent-dim);
}
.pc-session-item:active { transform: scale(0.99); }
.pc-session-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}
.pc-session-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pc-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
}
.pc-tag-renamed {
  background: rgba(167, 139, 250, 0.15);
  color: #a78bfa;
}
.pc-session-cwd {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pc-session-meta {
  font-size: 11px;
  color: var(--text-faint);
}

/* PC preview modal */
.pc-preview-panel { max-width: 720px; }
.pc-preview-meta {
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.04);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  line-height: 1.7;
}
.pc-preview-meta strong { color: var(--text-primary); font-weight: 500; }
.pc-preview-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}
.pc-prev-msg {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.4;
}
.pc-prev-user {
  background: rgba(96,165,250,0.08);
  border-left: 2px solid rgba(96,165,250,0.4);
}
.pc-prev-claude {
  background: rgba(218,119,86,0.06);
  border-left: 2px solid rgba(218,119,86,0.4);
}
.pc-prev-role {
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  font-weight: 600;
}
.pc-prev-text {
  color: var(--text-primary);
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}
.muted { color: var(--text-muted); font-size: 13px; }
.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 8px;
}
.form-input:focus { outline: none; border-color: var(--border-focus); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }

.convo-actions { display: flex; gap: 2px; flex-shrink: 0; }
.convo-rename {
  width: 28px; height: 28px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}
.convo-item:hover .convo-rename,
.convo-item.active .convo-rename { opacity: 1; }
.convo-rename:hover { color: var(--accent); background: var(--accent-dim); }
@media (hover: none) and (pointer: coarse) {
  .convo-rename { opacity: 0.6; }
}

/* Pin (звёздочка) — закреплённые видны всегда, у обычных проявляется при
   hover/active, чтобы не загромождать. Закрашенная жёлтая = pinned. */
.convo-pin-btn {
  width: 28px; height: 28px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.convo-item:hover .convo-pin-btn,
.convo-item.active .convo-pin-btn,
.convo-item.pinned .convo-pin-btn { opacity: 1; }
.convo-pin-btn:hover { background: rgba(250, 204, 21, 0.12); color: #facc15; }
@media (hover: none) and (pointer: coarse) {
  .convo-pin-btn { opacity: 0.6; }
  .convo-item.pinned .convo-pin-btn { opacity: 1; }
}

.convo-group-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  color: var(--text-muted, #888); letter-spacing: 0.06em;
  margin: 14px 4px 6px; padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.convo-group-label:first-child { margin-top: 4px; }
.convo-item.system {
  background: linear-gradient(90deg, rgba(99,102,241,0.08), transparent);
  border: 1px solid rgba(99,102,241,0.25);
}
.convo-item.system.active {
  background: linear-gradient(90deg, rgba(99,102,241,0.22), rgba(139,92,246,0.08));
  border-color: #6366f1;
}
.convo-pin { margin-right: 4px; font-size: 12px; opacity: 0.9; }

/* ===== Permission modal ===== */
.perm-dialog {
  max-width: 420px;
  padding: 24px 22px 20px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.perm-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: rgba(234, 179, 8, 0.12);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.perm-title { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.perm-body { width: 100%; text-align: left; }
.perm-desc { color: var(--text-muted, #aaa); margin: 8px 0; line-height: 1.5; }
.perm-badge {
  display: inline-block;
  background: rgba(218, 119, 86, 0.18);
  color: #e8a88a;
  padding: 3px 10px;
  border-radius: 6px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  margin-bottom: 10px;
}
.perm-badge-bash { background: rgba(234, 88, 12, 0.18); color: #fdba74; }
.command-display {
  background: #000;
  color: #d4d4d8;
  padding: 12px 14px;
  border-radius: 8px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.perm-actions {
  width: 100%;
  display: flex; gap: 10px; margin-top: 18px;
}
.perm-actions .btn { flex: 1; }
.btn-lg { padding: 12px 16px; font-size: 15px; }

.usage-real-section {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 12px;
}
.usage-real-section .usage-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; margin-bottom: 4px;
}
.usage-real-section .usage-label { color: var(--text-muted, #aaa); }
.usage-real-section .usage-value { color: var(--text, #eee); font-variant-numeric: tabular-nums; }

.account-item.disconnected {
  opacity: 0.7;
  border: 1px dashed rgba(239, 68, 68, 0.3);
}

/* ===== /btw ephemeral side-conversation ===== */
.btw-banner {
  margin: 10px 12px;
  padding: 10px 14px;
  background: rgba(234, 179, 8, 0.08);
  border: 1px dashed rgba(234, 179, 8, 0.4);
  border-radius: 10px;
  color: #fbbf24;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.btw-banner code {
  background: rgba(234, 179, 8, 0.2);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, Menlo, monospace;
}
.message-user.btw .bubble {
  border: 1px dashed rgba(234, 179, 8, 0.5);
  background: rgba(234, 179, 8, 0.06);
}
.btw-tag {
  display: inline-block;
  background: rgba(234, 179, 8, 0.25);
  color: #fbbf24;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  margin-right: 6px;
}

/* ===== Usage chip (legacy, hidden) ===== */
.usage-chip { display: none; }

/* ===== Usage panel internals ===== */
#usage-body .usage-section {
  margin-bottom: 18px;
}
#usage-body .usage-section:last-child { margin-bottom: 0; }
#usage-body .usage-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 13px;
}
#usage-body .usage-label {
  color: var(--text-muted, #aaa);
  font-weight: 500;
}
#usage-body .usage-value {
  color: var(--text, #eee);
  font-variant-numeric: tabular-nums;
}
#usage-body .usage-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}
#usage-body .usage-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.3s;
}
#usage-body .usage-bar-fill.warn { background: linear-gradient(90deg, #eab308, #f97316); }
#usage-body .usage-bar-fill.danger { background: linear-gradient(90deg, #ef4444, #dc2626); }
#usage-body .usage-reset {
  font-size: 11px;
  color: var(--text-muted, #888);
}
#usage-body .usage-account-row {
  font-size: 11px;
  color: var(--text-muted, #888);
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}
#usage-body .usage-account {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
#usage-body .usage-account-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
#usage-body .usage-account-name {
  font-weight: 600; font-size: 13px; color: var(--text, #eee);
}
#usage-body .usage-account-status {
  font-size: 10px; padding: 2px 8px; border-radius: 999px;
  background: rgba(34,197,94,0.15); color: #4ade80; text-transform: uppercase;
}
#usage-body .usage-account-status.limit_reached { background: rgba(239,68,68,0.15); color: #f87171; }
#usage-body .usage-account-status.extra_usage { background: rgba(234,179,8,0.15); color: #fbbf24; }

/* ===== Slash command popup ===== */
.slash-popup {
  position: absolute;
  bottom: 100%;
  left: 12px;
  right: 12px;
  margin-bottom: 8px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel, #14141c);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 50;
  padding: 4px;
}
.slash-popup.hidden { display: none; }
.slash-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.slash-item:hover, .slash-item.selected {
  background: var(--accent-dim, rgba(99, 102, 241, 0.18));
}
.slash-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #eee);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.slash-item-desc {
  font-size: 11px;
  color: var(--text-muted, #888);
}
#input-area { position: relative; }
/* На iOS виртуальная клавиатура накрывает нижнюю часть экрана. JS пишет
   --keyboard-h в :root при resize visualViewport. Подвигаем нижнюю
   границу #app вверх на эту величину — input остаётся над клавиатурой. */
#app { bottom: var(--keyboard-h, 0px); }

/* ===== SETTINGS PANEL ===== */
.settings-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--bg-primary);
}
.settings-section {
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
}
/* Hero-карточка для лимитов: чуть крупнее, с акцентной обводкой. */
.settings-section-hero {
  padding: 16px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, rgba(218,119,86,0.045), var(--bg-secondary));
}
.settings-section-hero .settings-section-label {
  font-size: 12px;
  color: var(--text-secondary);
}
.settings-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.settings-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-option {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02);
  transition: all 0.15s;
}
.settings-option:hover { background: var(--accent-dim); border-color: rgba(99,102,241,0.35); }
.settings-option.active { background: rgba(99,102,241,0.18); border-color: #6366f1; }
.settings-option-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.settings-option-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.settings-option-check { color: #6366f1; font-size: 14px; font-weight: 700; }
.settings-option-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.settings-option.perm-auto.active { background: rgba(48,209,88,0.12); border-color: var(--green); }
.settings-option.perm-bash.active { background: rgba(255,214,10,0.10); border-color: var(--yellow); }
.settings-option.perm-all.active  { background: rgba(255,69,58,0.10);  border-color: var(--red); }
.settings-option.perm-auto.active .settings-option-check { color: var(--green); }
.settings-option.perm-bash.active .settings-option-check { color: var(--yellow); }
.settings-option.perm-all.active  .settings-option-check { color: var(--red); }

/* Model cards */
.model-cards {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.model-card {
  flex: 1;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.model-card:hover {
  border-color: var(--card-color, var(--accent));
  background: color-mix(in srgb, var(--card-color, var(--accent)) 10%, transparent);
}
.model-card.active {
  border-color: var(--card-color, var(--accent));
  background: color-mix(in srgb, var(--card-color, var(--accent)) 16%, transparent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--card-color) 25%, transparent);
}
.model-card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}
.model-card.active .model-card-name { color: var(--card-color); }
.model-card-sub {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 2px;
}

/* Model slider */
.model-slider-wrap {
  padding: 4px 0 10px;
}
.model-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-tertiary);
  outline: none;
  --slider-color: var(--accent);
}
.model-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--slider-color, var(--accent));
  border: 2px solid var(--bg-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.model-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--slider-color) 25%, transparent);
}
.model-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--slider-color, var(--accent));
  border: 2px solid var(--bg-primary);
  cursor: pointer;
}
.model-slider-labels {
  display: flex;
  justify-content: space-between;
  padding: 4px 2px 0;
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.model-slider-labels-multi span {
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.model-slider-info {
  margin-top: 10px;
  text-align: center;
}
.model-slider-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
}
.model-slider-desc {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  font-style: italic;
}

.settings-account-summary { min-height: 30px; }

.settings-usage .usage-account {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.settings-usage .usage-account-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.settings-usage .usage-account-name { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.settings-usage .usage-account-status {
  font-size: 10px; padding: 2px 8px; border-radius: 999px;
  background: rgba(34,197,94,0.15); color: #4ade80; text-transform: uppercase;
}
.settings-usage .usage-account-status.limit_reached { background: rgba(239,68,68,0.15); color: #f87171; }
.settings-usage .usage-account-status.extra_usage { background: rgba(234,179,8,0.15); color: #fbbf24; }
.settings-usage .usage-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px; font-size: 13px;
}
.settings-usage .usage-label { color: var(--text-muted); font-weight: 500; }
.settings-usage .usage-value { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.settings-usage .usage-bar {
  height: 5px; background: rgba(255,255,255,0.06); border-radius: 3px;
  overflow: hidden; margin-bottom: 5px;
}
.settings-usage .usage-bar-fill {
  height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width 0.3s;
}
.settings-usage .usage-bar-fill.warn { background: linear-gradient(90deg, #eab308, #f97316); }
.settings-usage .usage-bar-fill.danger { background: linear-gradient(90deg, #ef4444, #dc2626); }
.settings-usage .usage-reset { font-size: 11px; color: var(--text-muted); }

/* Keep backward-compat usage selectors for renderUsagePanel (settings panel reuse) */
.usage-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 13px; }
.usage-label { color: var(--text-muted); font-weight: 500; }
.usage-value { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.usage-bar { height: 5px; background: rgba(255,255,255,0.06); border-radius: 3px; overflow: hidden; margin-bottom: 5px; }
.usage-bar-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width 0.3s; }
.usage-bar-fill.warn { background: linear-gradient(90deg, #eab308, #f97316); }
.usage-bar-fill.danger { background: linear-gradient(90deg, #ef4444, #dc2626); }
.usage-reset { font-size: 11px; color: var(--text-muted); }
.usage-account { background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.usage-account-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.usage-account-name { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.usage-account-status { font-size: 10px; padding: 2px 8px; border-radius: 999px; background: rgba(34,197,94,0.15); color: #4ade80; text-transform: uppercase; }
.usage-account-status.limit_reached { background: rgba(239,68,68,0.15); color: #f87171; }
.usage-account-status.extra_usage { background: rgba(234,179,8,0.15); color: #fbbf24; }

/* ===== USAGE QUOTA (реальные лимиты подписки, отдельный от старого .usage-* блок) ===== */
.usage-quota-block {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  /* Высота зарезервирована под typical-кейс (header + 2 окна лимитов).
     Если позже появится опц. строка Sonnet weekly — блок чуть подрастёт,
     но в типичном кейсе (0 sonnet) высота не «прыгает» между skel/data. */
  min-height: 110px;
}
.usage-quota-acc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 6px;
}
.usage-quota-acc-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.usage-quota-raw-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  color: var(--text-muted);
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
.usage-quota-raw-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }
.usage-quota-row { margin-bottom: 9px; }
.usage-quota-row:last-child { margin-bottom: 0; }
.usage-quota-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 4px;
}
.usage-quota-label { color: var(--text-muted); }
.usage-quota-val { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.usage-quota-bar {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}
.usage-quota-bar-fill {
  height: 100%;
  border-radius: 3px;
  /* Плавное заполнение: после rAF мы меняем width: 0% → final value, и
     transition тянет 1.4с — глаз приятно следит, бары не «выскакивают».
     Background тоже плавный, на случай перекраски (зелёный → красный при
     переходе порога). */
  transition: width 1.4s cubic-bezier(.22, .68, .22, 1), background 0.35s ease;
  width: 0%;
}
/* Skeleton-полосе анимация заполнения не нужна — ей рисуется shimmer
   фоном. Отменяем transition, иначе при перерендере skel→data будет
   двойной эффект. */
.usage-quota-bar-skel { transition: none !important; }
/* Пустой row для отсутствующих окон лимитов — слегка приглушаем подписи,
   чтобы было видно «здесь данных просто нет», но место занято. */
.usage-quota-row-empty .usage-quota-label { color: var(--text-faint, #6b7280); }
.usage-quota-row-empty .usage-quota-val { color: var(--text-faint, #6b7280); }

/* Skeleton-состояние блока лимитов: пустые полосы + тусклые подписи
   «Загрузка…». Структура та же что и реальная, чтобы переключение не
   двигало layout. Мягкий shimmer показывает что данные грузятся. */
.usage-quota-val-skel {
  color: var(--text-faint, #6b7280);
  font-style: italic;
  opacity: 0.7;
}
.usage-quota-bar-skel {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.12) 50%,
    rgba(255,255,255,0.04) 100%
  );
  background-size: 200% 100%;
  animation: usage-skel-shimmer 1.6s ease-in-out infinite;
}
@keyframes usage-skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.usage-session-footer {
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 4px 4px;
  border-top: 1px dashed rgba(255,255,255,0.07);
  margin-top: 6px;
  text-align: center;
}

/* Usage CLI output */
.usage-cli-output {
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: #ccc;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* iOS PWA: body background matches input area to fill bottom gap */
body { background: var(--bg-secondary); }

/* ===== Rate limit bars (official Anthropic data) ===== */
.rl-row {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
}
.rl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.rl-label {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 12px;
}
.rl-pct {
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  font-weight: 600;
}
.rl-bar {
  height: 6px;
  background: rgba(255,255,255,0.07);
  border-radius: 3px;
  overflow: hidden;
}
.rl-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.rl-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--text-faint, var(--text-muted));
}

/* ===== Live token counter in status bar ===== */
.cli-status-bar .status-tokens {
  display: inline-flex;
  gap: 8px;
  margin-left: auto;
  margin-right: 10px;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  opacity: 0.85;
}
.cli-status-bar .status-tokens .tok-in { color: #60a5fa; }
.cli-status-bar .status-tokens .tok-out { color: #34d399; }
.cli-status-bar .status-tokens .tok-cache { color: #fbbf24; }
/* Новая модель: ⇅ — потрачено на запрос, 🧠 — объём контекста из кеша. */
.cli-status-bar .status-tokens .tok-spend { color: #fbbf24; font-weight: 600; }
.cli-status-bar .status-tokens .tok-ctx { color: #a78bfa; }

/* ===== Interrupted message banner ===== */
.interrupted-banner {
  background: rgba(234,179,8,0.10);
  border: 1px solid rgba(234,179,8,0.35);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: #fbbf24;
  margin-bottom: 8px;
  line-height: 1.4;
}

/* Scroll-to-bottom button */
.scroll-to-bottom-btn {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  transition: opacity 0.2s, transform 0.15s;
}
.scroll-to-bottom-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  transform: scale(1.08);
}
.scroll-to-bottom-btn.hidden { display: none; }

/* Compact progress bar */
.compact-progress-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 8px;
}
.compact-progress-bar-fill {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, #60a5fa, #a78bfa, #60a5fa);
  background-size: 200% 100%;
  border-radius: 2px;
  animation: compact-shimmer 1.4s ease-in-out infinite;
}
@keyframes compact-shimmer {
  0%   { background-position: 200% center; width: 20%; }
  50%  { background-position: 0% center;   width: 70%; }
  100% { background-position: 200% center; width: 20%; }
}

/* Кнопка «Загрузить предыдущий сегмент» — рисуется над самым ранним
   видимым compact-маркером, если есть скрытая история. Один тап
   расширяет видимую область на один сегмент назад. */
.load-prev-segment-row {
  display: flex;
  justify-content: center;
  padding: 8px 16px;
  margin: 6px 0 12px;
}
.load-prev-segment-btn {
  background: rgba(96,165,250,0.08);
  border: 1px dashed rgba(96,165,250,0.35);
  color: #93c5fd;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.load-prev-segment-btn:hover {
  background: rgba(96,165,250,0.14);
  border-color: rgba(96,165,250,0.55);
  border-style: solid;
}
.load-prev-segment-btn:active { transform: scale(0.98); }

/* Compact result card */
.compact-result-card {
  background: rgba(96,165,250,0.07);
  border: 1px solid rgba(96,165,250,0.25);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.compact-result-card .compact-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #60a5fa;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.compact-result-card .compact-summary {
  color: var(--text-primary);
  font-size: 13px;
}
.compact-result-card .compact-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-family: var(--font-mono);
}
.compact-result-card .compact-ratio {
  color: #34d399;
  font-weight: 700;
  margin-left: 4px;
}
.compact-result-card .compact-confirm {
  font-size: 12px;
  margin-bottom: 6px;
}
.compact-result-card .compact-details {
  margin-top: 8px;
  border-top: 1px dashed rgba(96,165,250,0.2);
  padding-top: 8px;
}
.compact-result-card .compact-details > summary {
  cursor: pointer;
  font-size: 11px;
  color: #60a5fa;
  user-select: none;
  list-style: none;
  padding: 2px 0;
}
.compact-result-card .compact-details > summary::-webkit-details-marker { display: none; }
.compact-result-card .compact-details > summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s;
}
.compact-result-card .compact-details[open] > summary::before {
  content: "▾ ";
}
.compact-result-card .compact-details .compact-summary {
  margin-top: 8px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 12px;
  background: rgba(0,0,0,0.18);
  border-radius: 6px;
  padding: 8px 10px;
}

/* ============================================================
   v2 design refresh — overrides layered on top of the base.
   Goal: tighter mobile layout, clearer status, bigger tap targets.
   ============================================================ */

/* Header chip (account name + plan badge) sits in the header below the title. */
.header-title {
  flex-direction: column;
  gap: 2px;
  align-items: center;
}
.header-title #chat-title {
  font-size: 14.5px;
  line-height: 1.15;
}
.header-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 9px 3px;
  background: linear-gradient(135deg, rgba(218,119,86,0.16), rgba(196,97,62,0.12));
  border: 1px solid rgba(218,119,86,0.32);
  border-radius: 999px;
  color: #f0c9b5;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}
.header-chip:hover { background: rgba(218,119,86,0.22); }
.header-chip:active { transform: scale(0.96); }
.header-chip .chip-name {
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Subscription plan badge — colored by tier. */
.sub-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.4;
  vertical-align: middle;
  margin-left: 4px;
}
.sub-badge.sub-max_5x,
.sub-badge.sub-max_20x,
.sub-badge.sub-max {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: white;
  box-shadow: 0 1px 6px rgba(124, 58, 237, 0.35);
}
.sub-badge.sub-pro {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: white;
}
.sub-badge.sub-team {
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: white;
}

/* Connection indicator — tappable to force reconnect. */
.header-connection {
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 999px;
  transition: background 0.15s;
}
.header-connection:hover { background: rgba(255,255,255,0.04); }
.header-connection:active { transform: scale(0.96); }

/* Retry button in error bubble */
.error-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}
.retry-btn {
  font-size: 12px;
  padding: 6px 12px;
}

/* Inline conversation rename input */
.convo-rename-input {
  width: 100%;
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  background: var(--bg-tertiary);
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  color: var(--text-primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.convo-item.renaming { background: rgba(218,119,86,0.05) !important; }
.convo-item.renaming .convo-actions { display: none; }

/* Account summary rows in settings panel */
.acc-summary-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.acc-summary-row.last { border-bottom: none; }
.acc-summary-body { flex: 1; min-width: 0; }
.acc-summary-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.acc-summary-status { font-size: 11px; margin-top: 2px; }
.text-success { color: #4ade80; font-weight: 500; }
.text-danger { color: #f87171; font-weight: 500; }
.text-muted-inline { color: var(--text-muted); }

/* Larger, clearer connection label on desktop */
@media (min-width: 640px) {
  .connection-text { font-size: 12px; }
}

/* Better mobile-safe scroll-to-bottom button placement (above input area). */
.scroll-to-bottom-btn {
  bottom: calc(76px + var(--safe-bottom));
  right: calc(14px + var(--safe-right));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: rgba(35, 35, 38, 0.85);
  border-color: rgba(255, 255, 255, 0.1);
}

/* Message bubble polish: subtle gradient for Claude bubbles for depth. */
.message-claude .bubble {
  background: linear-gradient(180deg, rgba(38,38,40,0.95), rgba(30,30,32,0.95));
  backdrop-filter: blur(1px);
}

/* Slightly softer user bubble shadow */
.message-user .bubble {
  box-shadow: 0 3px 14px rgba(218, 119, 86, 0.28), inset 0 1px 0 rgba(255,255,255,0.15);
}

/* Active conversation indicator: left accent bar */
.convo-item.active {
  background: linear-gradient(90deg, rgba(218,119,86,0.16), rgba(218,119,86,0.04));
  position: relative;
}
.convo-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

/* Settings option: larger tap targets on touch */
@media (hover: none) and (pointer: coarse) {
  .settings-option { padding: 14px 14px; }
  .settings-option-label { font-size: 15px; }
  .settings-option-desc { font-size: 13px; }
  .btn-sm { min-height: 40px; }
  .icon-btn { width: 44px; height: 44px; }
}

/* Prevent iOS zoom on focus by keeping inputs at 16px+ */
input[type="text"], input[type="password"], textarea, select {
  font-size: 16px !important;
}
.convo-rename-input { font-size: 14.5px !important; }

/* Smoother transitions for primary interactive elements */
.icon-btn, .btn, .convo-item, .account-item, .settings-option, .send-button {
  will-change: transform;
}

/* Better tool badge inside live terminal — bit more breathing room. */
.tool-use-line {
  padding: 2px 0;
  gap: 8px;
}

/* Output-chunk readability on mobile */
@media (max-width: 480px) {
  .output-chunk, .terminal-block { font-size: 13px; line-height: 1.5; }
  .thinking-content { font-size: 12.5px; }
  #chat-area { padding: 10px 10px 8px; }
  .message { max-width: 94%; }
  .message-user .bubble, .message-claude .bubble {
    padding: 10px 14px;
    font-size: 15px;
  }
}

/* "Нет интернета" and other offline messaging stands out */
.status-dot.dot-red { animation: dot-pulse-red 1.6s ease-in-out infinite; }
@keyframes dot-pulse-red {
  0%, 100% { box-shadow: 0 0 8px rgba(255,69,58,0.6); }
  50% { box-shadow: 0 0 14px rgba(255,69,58,0.9), 0 0 0 3px rgba(255,69,58,0.12); }
}

/* Account chip in the accounts list — cleaner actions row */
.account-item .account-actions .btn { padding: 6px 10px; }
.account-item .account-actions .btn-danger {
  background: transparent;
  color: rgba(255,69,58,0.75);
  border: 1px solid rgba(255,69,58,0.25);
}
.account-item .account-actions .btn-danger:hover {
  background: rgba(255,69,58,0.12);
  color: var(--red);
}

/* Settings usage block — compact cards */
#settings-usage-body > div {
  border-radius: var(--radius-sm);
}
#refresh-usage-btn { width: 100%; }

/* Focused textarea should not jitter when message is sent */
#message-input { transform: translateZ(0); }

/* Improved settings open animation */
#settings-panel, #sidebar, #accounts-panel { touch-action: manipulation; }

/* Thinking block: bit more visual distinction */
.thinking-stream {
  background: rgba(218,119,86,0.03);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 4px 0 8px;
  border-bottom: none;
}
.thinking-header { font-size: 10.5px; }

/* ===== USER MESSAGE ACK INDICATOR ===== */
/* Часики ⏳ внутри bubble, рядом со значком «копировать». Пока Claude не
   получил сообщение — горят. На первом event'е от Claude — пропадают
   совсем (без галочки), чтобы не оставлять визуальный шум. */
.copy-btn-row { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.msg-ack {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  line-height: 1;
  user-select: none;
}
.msg-ack.ack-pending { color: #fbbf24; animation: ack-pulse 1.4s ease-in-out infinite; }
@keyframes ack-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ===== TODO LIST STICKY (TodoWrite plan) ===== */
/* Прикреплён под live-terminal'ом — последний снапшот плана. Показывает
   сколько задач выполнено и текущую in_progress. */
.todo-list-sticky {
  margin-top: 8px;
  padding: 10px 12px;
  background: rgba(218,119,86,0.06);
  border: 1px solid rgba(218,119,86,0.22);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.todo-list-sticky .todo-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #e8a88a;
  font-weight: 700;
  margin-bottom: 6px;
}
.todo-list-sticky .todo-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 2px 0;
}
.todo-list-sticky .todo-mark {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  font-weight: 700;
}
.todo-list-sticky .todo-text {
  flex: 1 1 auto;
  word-break: break-word;
}
.todo-list-sticky .todo-item.completed .todo-mark { color: #4ade80; }
.todo-list-sticky .todo-item.completed .todo-text { color: var(--text-muted); text-decoration: line-through; }
.todo-list-sticky .todo-item.in_progress .todo-mark { color: #fbbf24; animation: ack-pulse 1.4s ease-in-out infinite; }
.todo-list-sticky .todo-item.in_progress .todo-text { color: #fde68a; font-weight: 500; }
.todo-list-sticky .todo-item.pending .todo-mark { color: var(--text-muted); }
.todo-list-sticky .todo-item.pending .todo-text { color: var(--text-secondary, #a8a8b8); }

/* ===== SUB-AGENT BADGE & MODAL ===== */
/* Бейдж в основном терминале при запуске Task tool. Кликабельный — открывает
   модал с подробностями этого суб-агента. Цветовое состояние меняется
   когда агент завершается. */
.agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 6px 0;
  padding: 6px 12px;
  background: rgba(96,165,250,0.10);
  border: 1px solid rgba(96,165,250,0.30);
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #cfe2ff;
  transition: background .12s, border-color .12s, transform .08s;
  user-select: none;
}
.agent-badge:hover {
  background: rgba(96,165,250,0.18);
  border-color: rgba(96,165,250,0.50);
}
.agent-badge:active { transform: scale(0.98); }
.agent-badge .agent-icon { font-size: 14px; line-height: 1; }
.agent-badge .agent-label { font-weight: 600; color: #93c5fd; white-space: nowrap; }
.agent-badge .agent-desc {
  color: #cdd6e3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
  flex: 1 1 auto;
  min-width: 0;
}
.agent-badge .agent-status {
  font-size: 13px;
  color: #93c5fd;
  font-weight: 700;
  margin-left: 4px;
}
.agent-badge.running .agent-status { color: #fbbf24; animation: agent-pulse 1.4s ease-in-out infinite; }
.agent-badge.done {
  background: rgba(34,197,94,0.10);
  border-color: rgba(34,197,94,0.32);
}
.agent-badge.done .agent-status { color: #4ade80; }
.agent-badge.error {
  background: rgba(239,68,68,0.10);
  border-color: rgba(239,68,68,0.36);
}
.agent-badge.error .agent-status { color: #f87171; }
@keyframes agent-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* Модал суб-агента — переиспользует .modal-overlay/.modal-panel/.modal-header. */
.agent-modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 24px;
}
.agent-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.agent-meta-status {
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 5px;
}
.agent-meta-running { background: rgba(251,191,36,0.15); color: #fbbf24; }
.agent-meta-done    { background: rgba(34,197,94,0.15);  color: #4ade80; }
.agent-meta-error   { background: rgba(239,68,68,0.15);  color: #f87171; }
.agent-meta-pill {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(255,255,255,0.06);
  color: var(--text-muted);
}
.agent-task {
  background: rgba(96,165,250,0.05);
  border: 1px solid rgba(96,165,250,0.20);
  border-radius: 8px;
  padding: 10px 12px;
}
.agent-task-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #93c5fd;
  font-weight: 600;
  margin-bottom: 6px;
}
.agent-task-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
}
.agent-terminal {
  /* min-height: окно агента раньше схлопывалось до пары строк, потому что
     родительский flex-контейнер не растягивал его. Теперь — flex:1 + минимум
     45vh, чтобы вывод агента всегда был читаем, даже когда контента мало.
     Скролл внутри терминала, как и было. */
  flex: 1 1 auto;
  min-height: 45vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(0,0,0,0.18);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
}
.agent-terminal:empty::before {
  content: "Ждём первое событие…";
  color: var(--text-muted);
  font-style: italic;
  font-size: 11.5px;
}
.agent-terminal-content { display: block; }
.agent-summary {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid;
}
.agent-summary.done {
  background: rgba(34,197,94,0.06);
  border-color: rgba(34,197,94,0.25);
}
.agent-summary.error {
  background: rgba(239,68,68,0.06);
  border-color: rgba(239,68,68,0.30);
}
.agent-summary-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 600;
  margin-bottom: 6px;
}
.agent-summary.done .agent-summary-label { color: #4ade80; }
.agent-summary.error .agent-summary-label { color: #f87171; }
.agent-summary-body {
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

/* ============ FILE EXPLORER ============ */
.files-panel-wide { width: 520px; max-width: 96vw; }

.files-pathbar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.files-navbtn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.files-navbtn:active { opacity: .6; }
.files-path {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow-x: auto;
  padding: 4px 6px;
  background: var(--bg-input);
  border-radius: 7px;
}
.files-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.files-list { padding: 2px 0; }
.files-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.files-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.files-row-main:active { opacity: .55; }
.files-icon { font-size: 18px; flex-shrink: 0; width: 22px; text-align: center; }
.files-col { display: flex; flex-direction: column; min-width: 0; }
.files-name {
  font-size: 13.5px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.files-meta { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; }
.files-acts { display: flex; gap: 1px; flex-shrink: 0; }
.files-act {
  width: 31px;
  height: 31px;
  border-radius: 7px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
}
.files-act:active { background: var(--bg-elevated); }
/* Звёздочка-pin для сохранённых сессий. Прижата слева от тайтла, активная
   подсвечена жёлтым; ховер расширяется на «полная звезда» если ещё пустая.
   Размер чуть меньше, чем у action-кнопок справа — глаз не путает её. */
.files-act-star {
  width: 28px;
  height: 28px;
  color: var(--text-faint, #6b7280);
  font-size: 16px;
  transition: color 0.15s ease, transform 0.15s ease;
}
.files-act-star.is-pinned {
  color: #fbbf24;
  text-shadow: 0 0 6px rgba(251, 191, 36, 0.45);
}
.files-act-star:hover { color: #fbbf24; transform: scale(1.12); }
.files-row.is-pinned {
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.06), transparent 35%);
  border-left: 2px solid #fbbf24;
}
/* Шип «сегмент / полный» рядом с тайтлом сохранённой сессии. */
.saved-mode-chip {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 7px;
  margin-left: 4px;
  vertical-align: middle;
  background: rgba(74, 222, 128, 0.12);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.22);
}
.saved-mode-chip-full {
  background: rgba(120, 120, 200, 0.12);
  color: #a8b0e8;
  border-color: rgba(120, 120, 200, 0.22);
}

/* Диалог выбора режима сохранения (segment vs full). */
.save-mode-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.save-mode-opt:hover { border-color: var(--border-strong); background: rgba(255,255,255,0.02); }
.save-mode-opt input[type="radio"] { margin-top: 3px; flex-shrink: 0; }
.save-mode-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.save-mode-title { font-weight: 500; color: var(--text-primary); font-size: 14px; }
.save-mode-sub { color: var(--text-muted); font-size: 12px; }
.files-loading, .files-empty, .files-error, .files-note {
  padding: 18px 16px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}
.files-error { color: var(--red); }
.files-note { padding: 10px 16px; font-size: 11px; }

/* File viewer / editor */
.file-viewer-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 75%;
}
.file-viewer-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.file-frame {
  flex: 1;
  width: 100%;
  min-height: 70vh;
  border: none;
  background: #fff;
}
.file-img-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: auto;
}
.file-img { max-width: 100%; height: auto; border-radius: 6px; }
.file-edit {
  flex: 1;
  width: 100%;
  min-height: 62vh;
  border: none;
  background: var(--bg-terminal);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  padding: 12px;
  resize: none;
  outline: none;
}
.file-note {
  padding: 8px 14px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}
.file-binary {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 30px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}
.file-binary-icon { font-size: 48px; }
.file-viewer-footer.hidden { display: none; }

/* Conversation working directory line in the sidebar */
.convo-dir {
  font-size: 10.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Improved attachment tray: chip-icon size + .attach-chip-size hidden
   (compact mode — имя файла достаточно, размер был визуальным шумом). */
.attach-chip-icon { font-size: 12px; }
.attach-chip-size { display: none; }

/* Drag-and-drop overlay */
#main-screen.drag-over::after {
  content: "📎  Отпустите файлы — они прикрепятся к сообщению";
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-on-accent);
  background: rgba(99,102,241,0.30);
  border: 3px dashed rgba(139,92,246,0.9);
  backdrop-filter: blur(3px);
  pointer-events: none;
}

/* "Remember me" checkbox on the login forms */
.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.remember-check {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== GPT reviewer: Settings entry button ===== */
.settings-feature-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
}
.settings-feature-btn:active { background: var(--bg-tertiary); }
.settings-feature-ic { font-size: 22px; flex-shrink: 0; }
.settings-feature-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.settings-feature-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.settings-feature-sub { font-size: 11.5px; color: var(--text-muted); }
.settings-feature-arrow { font-size: 22px; color: var(--text-muted); flex-shrink: 0; line-height: 1; }

/* ===== GPT reviewer panel ===== */
.codex-body { display: flex; flex-direction: column; gap: 12px; }
.codex-hero {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(139,92,246,0.14), rgba(99,102,241,0.10));
  border: 1px solid rgba(139,92,246,0.40);
}
.codex-hero-icon {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
}
.codex-hero-text { font-size: 12.5px; line-height: 1.5; color: var(--text-secondary); }
.codex-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.codex-toggle-card { display: flex; align-items: center; gap: 12px; }
.codex-card-main { flex: 1; min-width: 0; }
.codex-card-title { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.codex-card-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.codex-status-card .codex-card-title { margin-bottom: 6px; }

/* iOS-style toggle switch */
.codex-switch { position: relative; width: 46px; height: 28px; flex-shrink: 0; }
.codex-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.codex-switch-track {
  position: absolute; inset: 0;
  border-radius: 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-strong);
  transition: background .2s;
  pointer-events: none;
}
.codex-switch-track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}
.codex-switch input:checked + .codex-switch-track {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-color: transparent;
}
.codex-switch input:checked + .codex-switch-track::after { transform: translateX(18px); }

.codex-card .codex-field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 12px 0 5px;
}
.codex-card .codex-field-label:first-child { margin-top: 0; }
.codex-card .codex-input {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
}
.codex-card .codex-hint { margin: 8px 0 0; font-size: 11.5px; line-height: 1.45; color: var(--text-muted); }
.codex-status-card .codex-status-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; font-size: 12.5px;
}
.codex-status-card .codex-status-key { color: var(--text-muted); }
.codex-status-card .codex-status-val { color: var(--text-primary); }
.codex-status-card .codex-status-mono { font-family: var(--font-mono); font-size: 11px; }

/* ===== Detected accounts (one-tap re-add) ===== */
.detected-accounts { display: flex; flex-direction: column; gap: 6px; }
.detected-loading { font-size: 11.5px; color: var(--text-muted); }
.detected-label { font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.detected-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.detected-item:active { background: var(--bg-tertiary); }
.detected-item.ok { border-color: rgba(48,209,88,0.40); }
.detected-name { font-family: var(--font-mono); font-size: 12px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detected-tag {
  flex-shrink: 0;
  font-size: 10px; font-weight: 600;
  padding: 2px 7px; border-radius: 6px;
  background: var(--bg-tertiary); color: var(--text-secondary);
}
.detected-item.ok .detected-tag { background: rgba(48,209,88,0.18); color: #4ade80; }

/* ===== Message timestamps + date dividers (messenger-style) ===== */
.msg-time {
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  margin-right: 4px;
  white-space: nowrap;
}
.date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0 10px;
}
.date-divider span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 3px 12px;
  border-radius: 11px;
}

/* Saved-sessions buttons row in Settings */
.session-btn-row { display: flex; gap: 8px; }
.session-btn-row .btn { flex: 1; }

/* ===== File explorer toolbar — even 2-column grid instead of ragged wrap ===== */
.files-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.files-toolbar .btn { width: 100%; }
#files-open-agent-btn { grid-column: 1 / -1; }

/* ===== Schedule (delayed message) button — рядом с send-button ===== */
/* .schedule-button styles consolidated в основном input-area блоке (36x36 round). */

/* Schedule modal — отдельный max-width чтобы list of pending messages не растягивал. */
.schedule-modal-panel { max-width: 540px; }
.schedule-modal-hint { font-size: 13px; color: var(--text-muted); margin: 0 0 12px; }
.schedule-modal-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.schedule-modal-textarea {
  width: 100%;
  min-height: 96px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
}
.schedule-modal-when {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
}
.schedule-quick-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.schedule-quick-row .btn { flex: 1; min-width: 70px; padding: 6px 8px; font-size: 12px; }

.schedule-modal-list { margin-top: 16px; max-height: 240px; overflow-y: auto; }
.scheduled-row {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.scheduled-row.done { opacity: 0.6; }
.scheduled-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.scheduled-row-when { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.scheduled-row-text {
  font-size: 13px;
  color: var(--text-secondary, var(--text-muted));
  word-break: break-word;
  white-space: pre-wrap;
}
.scheduled-row-error { font-size: 11px; color: #ef4444; margin-top: 4px; }
.scheduled-status {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--bg-secondary, rgba(255,255,255,0.05));
  color: var(--text-muted);
}
.scheduled-status.ok { color: #22c55e; }
.scheduled-status.err { color: #ef4444; }
.scheduled-cancel {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 16px;
  line-height: 18px;
  padding: 0;
}
.scheduled-cancel:hover { color: #ef4444; background: rgba(239,68,68,0.12); }

/* Чип активного фильтра по папке в панели PC-сессий. */
.pc-sessions-folder-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 0;
  padding: 6px 8px 6px 10px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}
.pc-sessions-folder-chip.hidden { display: none; }
.pc-folder-chip-ic { font-size: 12px; }
.pc-folder-chip-text {
  flex: 1;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pc-folder-chip-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 16px;
  padding: 0;
}
.pc-folder-chip-clear:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }

/* Folder picker modal — тот же стиль что у file explorer, но скромнее. */
.folder-picker-panel { max-width: 520px; }
.folder-picker-pathbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}
.folder-picker-pathbar .files-path {
  flex: 1;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-picker-row { cursor: pointer; }
.folder-picker-row:hover { background: var(--accent-dim); }

/* Баннер «⏰ 2 отложенных» над input-area — кликабельный. */
.scheduled-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(99, 102, 241, 0.10);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}
.scheduled-banner:hover { background: rgba(99, 102, 241, 0.16); }
.scheduled-banner-ic { font-size: 14px; }
.scheduled-banner-text { flex: 1; }
.scheduled-banner-arrow { color: var(--text-muted); font-size: 16px; }

