/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.message.user {
  align-self: flex-end;
  background: #2b5278;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  opacity: 0.6;
  user-select: none;
  line-height: 1;
}
.message.user .msg-time {
  text-align: right;
}
.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  max-width: 100%;
}
.message strong { font-weight: 700; color: inherit; }
.message em { font-style: italic; }

/* Sent indicator on user messages */
.msg-wrap { display: inline; }
.msg-status {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 4px;
  vertical-align: middle;
  user-select: none;
}
.message code {
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9em;
}
.message pre {
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 6px 0;
}
.message pre code { background: none; padding: 0; font-size: 0.85em; }
.message h3 { font-size: 1.1em; margin: 6px 0; color: var(--accent); }
.message a { color: var(--accent); text-decoration: underline; }

/* Thinking dots (inside status bar) */
.thinking-dots {
  display: inline-flex;
  gap: 3px;
  vertical-align: middle;
  margin-left: 2px;
}
.thinking-dots span {
  width: 5px; height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}
.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Input — Telegram-style */
.input-area {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
  background: var(--bg-card);
  flex-shrink: 0;
  align-items: flex-end;
  position: relative;
}

/* Status bar — between messages and input */
.status-bar {
  padding: 3px 12px 5px;
  font-size: 16px;
  color: var(--text-muted);
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex !important;
  align-items: center;
  gap: 6px;
  animation: fadeIn 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  min-height: 22px;
}
.status-bar .status-icon { flex-shrink: 0; }
.status-bar .status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.status-bar.hidden { display: none !important; }

.input-area textarea {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 16px;
  color: var(--text);
  font-size: 16px;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 120px;
  min-height: 44px;
  transition: border-color 0.2s, background 0.2s;
}
.input-area textarea:focus {
  border-color: var(--accent);
  background: rgba(46, 166, 255, 0.03);
}
.input-area textarea::placeholder { color: var(--text-muted); }

/* Telegram-style action button (send or mic) */
.btn-action {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
  border: none;
  flex-shrink: 0;
  background: var(--accent);
  color: #ffffff;
  line-height: 1;
}
.btn-action:hover { background: var(--accent-hover); }
.btn-action:active { transform: scale(0.9); }
.btn-action.hidden { display: none; }

/* Voice recording bar — Telegram-style */
.voice-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  padding: 0 2px;
  height: 44px;
}
.btn-trash {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  border: none;
  flex-shrink: 0;
  background: transparent;
  color: var(--text-muted);
  order: -1;
}
.btn-trash:active { transform: scale(0.85); color: var(--danger); }

.voice-timer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.voice-timer .record-dot {
  width: 10px; height: 10px;
  background: #ef4444;
  border-radius: 50%;
  flex-shrink: 0;
  animation: tg-blink 1s steps(2) infinite;
}
@keyframes tg-blink { 0% { opacity: 1; } 50% { opacity: 0; } }
.voice-timer .time-text { 
  min-width: 52px; 
  text-align: center; 
  font-size: 16px;
  letter-spacing: 0.5px;
}

.btn-voice-send {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  border: none;
  background: var(--accent);
  color: #ffffff;
  flex-shrink: 0;
}
.btn-voice-send:active { transform: scale(0.9); opacity: 0.8; }

@media (max-width: 600px) {
  .message { max-width: 90%; }
  .chat-header { padding: 10px 12px; }
  .input-area { padding: 8px 12px; }
}

/* Clarify choice buttons */
.clarify-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 16px 12px;
  align-self: flex-start;
  max-width: 100%;
}
.clarify-btn {
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: inherit;
}
.clarify-btn:active {
  background: var(--accent);
  color: var(--bg);
  transform: scale(0.95);
}

/* Thinking stream */
.message.thinking-stream {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-bottom-left-radius: 4px;
  max-width: 100%;
  font-size: 12px;
  opacity: 0.8;
  padding: 8px 12px;
  width: 100%;
  animation: fadeIn 0.3s ease;
}
.thinking-label {
  font-weight: 600;
  color: var(--accent);
  margin-right: 8px;
}
.thinking-text {
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  font-style: italic;
}

/* Tool steps — внутри блока троеточия */
.tool-status-line {
  font-size: 12px;
  color: var(--text-muted);
  animation: fadeIn 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.tool-status-line .tool-step-icon {
  margin-right: 4px;
}
.tool-status-line .tool-step-label {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
}

/* Approval dialog */
.approval-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.approval-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 90%;
  width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.approval-header {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}
.approval-tool {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.approval-command {
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 16px;
  max-height: 150px;
  overflow-y: auto;
}
.approval-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.approval-actions button {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.approval-actions button:active {
  transform: scale(0.95);
}
.approval-actions .btn-approve {
  background: #22c55e;
  color: white;
  border-color: #22c55e;
}
.approval-actions .btn-deny {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
}
.approval-actions .btn-approve-all {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
