/* ── Дневальный — фиолетовая тема (под портал Mycelia) ── */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f3f0ff;
  --bg-hover: #ede9fe;
  --bg-input: #ffffff;
  --border: #d8d0f0;
  --border-light: #e8e0fa;
  --text-primary: #2d3436;
  --text-secondary: #888888;
  --text-muted: #aaaaaa;
  --accent: #d45a5a;
  --accent-hover: #c04a4a;
  --accent-glow: rgba(212, 90, 90, 0.12);
  --user-bubble: #d45a5a;
  --assistant-bubble: #fef2f2;
  --success: #33bd66;
  --danger: #e66767;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(120, 111, 166, 0.12);
  #d45a5a: #786fa6;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ── Фиолетовая рамка вокруг чата ── */
.app {
  display: flex;
  height: 100vh;
  border: 3px solid var(#d45a5a);
  border-radius: 10px;
  overflow: hidden;
  margin: 2px;
}

/* ── Сайдбар ── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header .logo {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  font-weight: 700;
}

.sidebar-header h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.new-chat-btn {
  width: calc(100% - 24px);
  margin: 10px 12px;
  padding: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}

.new-chat-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.session-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.session-item:hover {
  background: var(--bg-hover);
}

.session-item.active {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
}

.session-item .icon {
  font-size: 14px;
  opacity: 0.7;
}

.session-item .info { flex: 1; min-width: 0; }
.session-item .title { font-size: 12px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .date { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Шапка чата ── */
.chat-header {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-tertiary);
}

.chat-header .avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.chat-header .chat-info h2 { font-size: 14px; font-weight: 600; }
.chat-header .chat-info p { font-size: 11px; color: var(--text-muted); }

/* ── Сообщения ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.messages:empty::after {
  content: 'Напишите что-нибудь, чтобы начать чат';
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 30px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 88%;
  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; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.message .msg-avatar {
  width: 28px; height: 28px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 12px;
}

.message.user .msg-avatar { background: var(--accent); color: #fff; }
.message.assistant .msg-avatar { background: var(--bg-hover); color: var(--accent); }

.message .bubble {
  padding: 8px 14px; border-radius: var(--radius); font-size: 13px;
  line-height: 1.5; word-wrap: break-word; white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--accent); color: #fff; border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--assistant-bubble); border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px; color: var(--text-primary);
}

.message .time { font-size: 10px; color: var(--text-muted); margin-top: 3px; text-align: right; }

/* ── Печатание ── */
.typing-indicator {
  align-self: flex-start; display: flex; gap: 10px; padding: 2px 0; display: none;
}

.typing-indicator.active { display: flex; }

.typing-indicator .typing-avatar {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--bg-hover); display: flex; align-items: center;
  justify-content: center; font-size: 12px; flex-shrink: 0;
}

.typing-dots {
  background: var(--assistant-bubble); border: 1px solid var(--border-light);
  border-radius: var(--radius); border-bottom-left-radius: 4px;
  padding: 10px 18px; display: flex; gap: 4px; align-items: center;
}

.typing-dots span {
  width: 7px; height: 7px; background: var(--accent); border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

/* ── Поле ввода ── */
.input-area {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.input-wrapper {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 3px 3px 3px 14px;
  transition: border-color 0.15s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 0;
  resize: none;
  font-family: inherit;
  max-height: 100px;
}

.input-wrapper textarea::placeholder { color: var(--text-muted); }

.attach-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  margin-bottom: 2px;
}

.attach-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

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

.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Скроллбар ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Мобилка (DeepSeek-style) ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .chat-header { padding: 8px 12px; }
  .chat-header .avatar { width: 28px; height: 28px; font-size: 12px; }
  .chat-header .chat-info h2 { font-size: 13px; }
  .chat-header .chat-info p { font-size: 10px; }
  .messages { padding: 12px; gap: 10px; }
  .message { max-width: 95%; }
  .message .bubble { font-size: 13px; padding: 8px 12px; }
  .input-area { padding: 8px 12px; }
  .input-wrapper { padding: 2px 2px 2px 10px; }
  .input-wrapper textarea { font-size: 14px; max-height: 80px; }
  .send-btn { width: 34px; height: 34px; }
  .attach-btn { width: 32px; height: 32px; }
  .app { border-width: 1px; border-radius: 6px; }
}

/* ── Очень маленькие экраны ── */
@media (max-width: 400px) {
  .sidebar { display: none; }
  .input-area { padding: 6px 8px; }
  .input-wrapper { padding: 2px 2px 2px 8px; }
  .message .bubble { font-size: 12px; padding: 6px 10px; }
}
