/* path: public/css/ai-widget.css */

#ai-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  font-family: "Segoe UI", Arial, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

#ai-widget.left {
  right: auto;
  left: 20px;
}

#ai-widget * {
  box-sizing: border-box;
}

/* =======================
   States
   ======================= */

#ai-widget.ai-open #ai-window {
  display: flex;
}
#ai-widget.ai-open #ai-btn {
  display: none;
}
#ai-widget:not(.ai-open) #ai-window {
  display: none;
}

/* Expanded */
#ai-widget.ai-expanded {
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
}

#ai-widget.ai-expanded #ai-window {
  width: min(980px, 96vw);
  height: min(820px, 92vh);
}

/* Mobile fullscreen */
@media (max-width: 640px) {
  #ai-widget.ai-expanded {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
  }

  #ai-widget.ai-expanded #ai-window {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }
}

/* =======================
   Floating button
   ======================= */

#ai-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #4f46e5;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.35);
  transition: background 0.25s, transform 0.15s, box-shadow 0.25s;
}

#ai-btn:hover {
  background: #4338ca;
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.45);
}

/* =======================
   Window
   ======================= */

#ai-window {
  width: 360px;
  height: 480px;
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.45);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: ai-slide-in 0.18s ease-out;
}

@keyframes ai-slide-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* =======================
   Header
   ======================= */

#ai-header {
  padding: 10px 12px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: white;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#ai-header-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#ai-header-avatar {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

#ai-header-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#ai-header-sub {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.9;
}

#ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-header-btn {
  border: none;
  background: rgba(15, 23, 42, 0.18);
  color: #e5e7eb;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-header-btn:hover {
  background: rgba(15, 23, 42, 0.3);
  color: #ffffff;
}

/* =======================
   Chat
   ======================= */

#ai-chat {
  flex: 1;
  padding: 12px 10px 8px;
  background: #f9fafb;
  overflow-y: auto;
  font-size: 14px;
}

#ai-chat-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Expanded: растягиваем колонку сообщений */
#ai-widget.ai-expanded #ai-chat-inner {
  align-items: stretch;
}

.ai-msg {
  max-width: 270px;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.45;
  word-break: break-word;
}

/* Expanded: шире баблы */
#ai-widget.ai-expanded .ai-msg {
  max-width: calc(100% - 8px);
}

.ai-msg-user {
  margin-left: auto;
  background: #e5e7eb;
  color: #111827;
  border-radius: 14px 14px 4px 14px;
}

#ai-widget.ai-expanded .ai-msg-user {
  max-width: min(720px, 80%);
}

.ai-msg-assistant {
  margin-right: auto;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #111827;
  border-radius: 14px 14px 14px 4px;
}

/* Expanded: ответ ассистента на всю ширину */
#ai-widget.ai-expanded .ai-msg-assistant {
  width: 100%;
}

.ai-msg-assistant a {
  color: #4f46e5;
  text-decoration: underline;
}

/* =======================
   Typing indicator
   ======================= */

#ai-typing {
  display: none;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
  color: #6b7280;
}

#ai-typing-dots {
  display: inline-flex;
  gap: 2px;
}

.ai-dot {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: #9ca3af;
  animation: ai-dot-bounce 0.9s infinite;
}

.ai-dot:nth-child(2) {
  animation-delay: 0.15s;
}
.ai-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-dot-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* =======================
   Input
   ======================= */

#ai-input-box {
  padding: 8px 10px 10px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: white;
}

#ai-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

#ai-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 7px 8px;
  font-size: 14px;
  resize: none;
  min-height: 34px;
  max-height: 84px;
}

#ai-input::placeholder {
  color: #9ca3af;
}

#ai-send {
  background: #4f46e5;
  border-radius: 10px;
  padding: 7px 12px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  border: none;
  min-width: 40px;
}

#ai-send[disabled] {
  opacity: 0.55;
  cursor: default;
}

#ai-send:hover:not([disabled]) {
  background: #4338ca;
}

#ai-helper {
  font-size: 10px;
  color: #9ca3af;
  padding: 0 2px;
}

/* =========================================================
   AI Markdown (ЕДИНЫЙ источник стилей)
   ========================================================= */

.ai-msg-assistant .ai-md {
  font-size: 13px;
  line-height: 1.4;
  color: #111827;
}

/* сброс браузерных отступов */
.ai-msg-assistant .ai-md p,
.ai-msg-assistant .ai-md ul,
.ai-msg-assistant .ai-md ol,
.ai-msg-assistant .ai-md table,
.ai-msg-assistant .ai-md pre,
.ai-msg-assistant .ai-md blockquote,
.ai-msg-assistant .ai-md h1,
.ai-msg-assistant .ai-md h2,
.ai-msg-assistant .ai-md h3 {
  margin: 0;
}

/* аккуратный вертикальный ритм */
.ai-msg-assistant .ai-md > * + * {
  margin-top: 8px;
}

/* ============================
   Paragraph spacing
   ============================ */

.ai-msg-assistant .ai-md p {
  margin-bottom: 8px;
}

.ai-msg-assistant .ai-md p + ul,
.ai-msg-assistant .ai-md p + ol {
  margin-top: 2px;
}

/* заголовки */
.ai-msg-assistant .ai-md h1,
.ai-msg-assistant .ai-md h2,
.ai-msg-assistant .ai-md h3 {
  font-weight: 700;
  line-height: 1.25;
}

.ai-msg-assistant .ai-md h1 {
  font-size: 15px;
}
.ai-msg-assistant .ai-md h2 {
  font-size: 14px;
}
.ai-msg-assistant .ai-md h3 {
  font-size: 13px;
}

/* списки */
.ai-msg-assistant .ai-md ul,
.ai-msg-assistant .ai-md ol {
  padding-left: 20px;
}

.ai-msg-assistant .ai-md li {
  margin: 2px 0;
}

.ai-msg-assistant .ai-md li + li {
  margin-top: 6px;
}

.ai-msg-assistant .ai-md li > p {
  margin: 0;
}

/* таблицы — аккуратные */
.ai-msg-assistant .ai-md table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ai-msg-assistant .ai-md th,
.ai-msg-assistant .ai-md td {
  border: 1px solid #e5e7eb;
  padding: 6px 8px;
  vertical-align: top;
}

.ai-msg-assistant .ai-md thead th {
  background: #f8fafc;
  font-weight: 600;
}

/* code */
.ai-msg-assistant .ai-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

.ai-msg-assistant .ai-md pre {
  padding: 10px;
  border-radius: 10px;
  background: #f3f4f6;
  overflow: auto;
}

/* цитаты */
.ai-msg-assistant .ai-md blockquote {
  padding-left: 10px;
  border-left: 3px solid #e5e7eb;
  color: #374151;
}

/* ============================
   Нивелирование лишних <br>
   ============================ */

/* убираем <br> внутри markdown, где они ломают ритм */
.ai-msg-assistant .ai-md br {
  display: none;
}

/* НО: разрешаем <br> в <pre> (код) */
.ai-msg-assistant .ai-md pre br {
  display: inline;
}

/* ============================
   Markdown lists (ul)
   ============================ */

.ai-msg-assistant .ai-md ul {
  list-style: none;              /* убираем стандартные */
  padding-left: 16px;
}

.ai-msg-assistant .ai-md ul li {
  position: relative;
  padding-left: 14px;
}

/* серый кружочек */
.ai-msg-assistant .ai-md ul li::before {
  content: "•";
  position: absolute;
  left: 0;
  top: 0;
  color: #9ca3af;                /* аккуратный серый */
  font-size: 14px;
  line-height: 1.4;
}


/* ============================
   Markdown ordered lists (ol)
   ============================ */

.ai-msg-assistant .ai-md ol {
  padding-left: 20px;
  list-style-position: outside;
}

.ai-msg-assistant .ai-md ol li {
  padding-left: 2px;
  color: #111827;
}

/* расстояние между пунктами */
.ai-msg-assistant .ai-md ol li + li {
  margin-top: 6px;
}

/* ============================
   Soft bold (strong)
   ============================ */

.ai-msg-assistant .ai-md strong {
  font-weight: 500;
  color: #111827;
}


/* =========================================================
   Info blocks — адрес / контакты (АККУРАТНО)
   ========================================================= */

/* общий инфоблок */
.ai-msg-assistant .ai-md p:has(a[href^="tel"]),
.ai-msg-assistant .ai-md p:has(a[href^="mailto"]),
.ai-msg-assistant .ai-md p:has(strong) {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 12.5px;
  line-height: 1.55;
}

/* ссылки внутри инфоблока */
.ai-msg-assistant .ai-md p:has(a[href^="tel"]) a,
.ai-msg-assistant .ai-md p:has(a[href^="mailto"]) a {
  color: #1f2937;
  text-decoration: none;
  font-weight: 500;
}

/* hover аккуратный */
.ai-msg-assistant .ai-md p:has(a[href^="tel"]) a:hover,
.ai-msg-assistant .ai-md p:has(a[href^="mailto"]) a:hover {
  text-decoration: underline;
}

/* strong внутри инфоблока — спокойнее */
.ai-msg-assistant .ai-md p:has(strong) strong {
  font-weight: 600;
}

/* если несколько инфоблоков подряд — склеиваем визуально */
.ai-msg-assistant .ai-md p:has(a[href^="tel"]) + p:has(a[href^="mailto"]),
.ai-msg-assistant .ai-md p:has(strong) + p:has(strong) {
  margin-top: -6px;
}
