/* ═══════════════════════════════════════════
   TaskFlow Chat Widget — стили
   Плавающая кнопка + раскрывающаяся панель
   ═══════════════════════════════════════════ */

/* ── Кнопка (FAB) ── */
.chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6c8cff 0%, #4c6ef5 100%);
  color: #fff;
  border: none;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(76, 110, 245, 0.4);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.chat-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(76, 110, 245, 0.5);
}

.chat-fab:active {
  transform: scale(0.95);
}

.chat-fab.chat-fab--hidden {
  display: none;
}

/* ── Панель чата ── */
.chat-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: calc(100vw - 40px);
  max-width: 360px;
  height: min(70vh, 540px);
  background: var(--bg, #fff);
  color: var(--text, #1a1a1a);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  animation: chat-pop 0.18s ease-out;
}

.chat-panel.chat-panel--open {
  display: flex;
}

@keyframes chat-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Заголовок ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #6c8cff 0%, #4c6ef5 100%);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}

.chat-header__title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header__close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-header__close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chat-header__clear {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 12px;
  margin-right: 8px;
}

.chat-header__clear:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ── Область сообщений ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-msg--user {
  align-self: flex-end;
  background: var(--accent, #4c6ef5);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg--assistant {
  align-self: flex-start;
  background: var(--bubble, rgba(0, 0, 0, 0.06));
  color: inherit;
  border-bottom-left-radius: 4px;
}

.chat-msg--system {
  align-self: center;
  font-size: 12px;
  opacity: 0.6;
  background: none;
  padding: 4px 8px;
}

.chat-msg--error {
  align-self: flex-start;
  background: rgba(255, 80, 80, 0.12);
  color: #c0392b;
  border: 1px solid rgba(192, 57, 43, 0.2);
  font-size: 13px;
}

/* Markdown в сообщениях ассистента */
.chat-msg--assistant p { margin: 0 0 6px; }
.chat-msg--assistant p:last-child { margin-bottom: 0; }
.chat-msg--assistant code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}
.chat-msg--assistant pre {
  margin: 6px 0;
  background: rgba(0, 0, 0, 0.06);
  padding: 8px 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.chat-msg--assistant pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.chat-msg--assistant ul, .chat-msg--assistant ol {
  margin: 4px 0 4px 18px;
  padding: 0;
}
.chat-msg--assistant li { margin: 2px 0; }
.chat-msg--assistant strong { font-weight: 600; }
.chat-msg--assistant em { font-style: italic; }
.chat-msg--assistant a { color: var(--accent, #4c6ef5); }

/* ── Индикатор загрузки ── */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bubble, rgba(0, 0, 0, 0.06));
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.chat-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text, #1a1a1a);
  opacity: 0.3;
  animation: chat-bounce 1.2s infinite;
}
.chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 0.8; transform: translateY(-3px); }
}

/* ── Поле ввода ── */
.chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  flex-shrink: 0;
  background: var(--bg, #fff);
}

.chat-input__field {
  flex: 1;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.12));
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  background: var(--input-bg, rgba(0, 0, 0, 0.03));
  color: inherit;
  max-height: 100px;
}

.chat-input__field:focus {
  border-color: var(--accent, #4c6ef5);
}

.chat-input__send {
  background: var(--accent, #4c6ef5);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input__send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-input__send:hover:not(:disabled) {
  background: #3b5bdb;
}

/* ── Тёмная тема ── */
@media (prefers-color-scheme: dark) {
  .chat-panel {
    background: #1c1c1e;
    color: #f1f1f1;
    border-color: rgba(255, 255, 255, 0.08);
  }
  .chat-msg--assistant {
    background: rgba(255, 255, 255, 0.08);
  }
  .chat-msg--assistant code {
    background: rgba(255, 255, 255, 0.1);
  }
  .chat-msg--assistant pre {
    background: rgba(255, 255, 255, 0.06);
  }
  .chat-typing__dot {
    background: #f1f1f1;
  }
  .chat-input {
    background: #1c1c1e;
  }
  .chat-input__field {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f1f1f1;
  }
}

/* ── Telegram theme integration ── */
:root {
  --accent: #4c6ef5;
  --border: rgba(0, 0, 0, 0.08);
  --bubble: rgba(0, 0, 0, 0.06);
  --input-bg: rgba(0, 0, 0, 0.03);
  --text: #1a1a1a;
  --bg: #fff;
}
