/* AI Context 2.0 — Floating AI Assistant Widget Styles */

.ai-chat-widget {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none; /* Не перекрывает клики по странице в свернутом виде */
}

/* Floating Trigger Button */
.ai-chat-trigger {
  pointer-events: auto; /* Сама кнопка кликабельна */
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  outline: none;
}

.ai-chat-trigger:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 30px rgba(99, 102, 241, 0.6);
}

.ai-chat-trigger:active {
  transform: scale(0.96);
}

.ai-chat-trigger .icon-open,
.ai-chat-trigger .icon-close {
  position: absolute;
  transition: all 0.3s ease;
}

.ai-chat-trigger .icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.ai-chat-widget.is-open .ai-chat-trigger .icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.ai-chat-widget.is-open .ai-chat-trigger .icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Pulse badge */
.ai-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  background: #10b981;
  border: 2px solid #0b0f19;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Tooltip Hint Pill */
.ai-chat-hint {
  position: absolute;
  right: 70px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(18, 24, 38, 0.95);
  color: #e2e8f0;
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(-50%) translateX(10px);
  transition: all 0.3s ease;
}

.ai-chat-trigger:hover .ai-chat-hint {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.ai-chat-widget.is-open .ai-chat-hint {
  display: none !important;
}

/* Chat Modal Window */
.ai-chat-window {
  width: 450px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 110px);
  background: rgba(17, 22, 34, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(99, 102, 241, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 16px;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  visibility: hidden; /* Полностью исключает перехват кликов когда закрыто */
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
}

.ai-chat-widget.is-open .ai-chat-window {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Chat Header */
.ai-chat-header {
  padding: 16px 20px;
  background: rgba(26, 32, 48, 0.7);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.ai-chat-title-group h3 {
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
  margin: 0;
  line-height: 1.2;
}

.ai-chat-status {
  font-size: 11px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.ai-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.ai-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-chat-btn-icon {
  background: transparent;
  border: none;
  color: #94a3b8;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.ai-chat-btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
}

/* Chat Messages Stream */
.ai-chat-messages {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Message Bubble */
.ai-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: fadeInMsg 0.25s ease-out;
}

@keyframes fadeInMsg {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chat-msg.user {
  align-self: flex-end;
  max-width: 85%;
}

.ai-chat-msg.assistant {
  align-self: flex-start;
  max-width: 100%;
}

.ai-chat-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.ai-chat-msg.user .ai-chat-bubble {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.25);
}

.ai-chat-msg.assistant .ai-chat-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border-bottom-left-radius: 4px;
}

/* Markdown styling inside assistant bubble */
.ai-chat-bubble p {
  margin: 0 0 8px 0;
}
.ai-chat-bubble p:last-child {
  margin-bottom: 0;
}
.ai-chat-bubble strong {
  color: #ffffff;
  font-weight: 600;
}
.ai-chat-bubble code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  color: #a5b4fc;
}
.ai-chat-bubble pre {
  background: rgba(10, 14, 23, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.ai-chat-bubble pre code {
  background: transparent;
  padding: 0;
  color: #cbd5e1;
}
.ai-chat-bubble ul, .ai-chat-bubble ol {
  margin: 6px 0 8px 18px;
  padding: 0;
}
.ai-chat-bubble li {
  margin-bottom: 4px;
}
.ai-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.2);
  -webkit-overflow-scrolling: touch;
}

.ai-chat-bubble table {
  border-collapse: collapse;
  width: 100%;
  min-width: 380px;
  margin: 0;
  font-size: 12px;
}
.ai-chat-bubble th, .ai-chat-bubble td {
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 10px;
  text-align: left;
  word-break: normal;
  white-space: normal;
}
.ai-chat-bubble th:first-child,
.ai-chat-bubble td:first-child {
  white-space: nowrap;
  font-weight: 600;
  min-width: 100px;
}
.ai-chat-bubble th {
  background: rgba(255, 255, 255, 0.08);
  font-weight: 600;
}

/* Suggestion Pills */
.ai-chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 4px;
}

.ai-chat-suggestions::-webkit-scrollbar {
  width: 4px;
}

.ai-chat-suggestions::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.3);
  border-radius: 4px;
}

.ai-chat-pill {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #c7d2fe;
  padding: 7px 12px;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  line-height: 1.3;
}

.ai-chat-pill:hover {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(99, 102, 241, 0.45);
  color: #ffffff;
  transform: translateX(3px);
}

/* Typing Indicator */
.ai-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.ai-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a5b4fc;
  animation: typingBounce 1.2s infinite ease-in-out;
}

.ai-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Chat Input Bar */
.ai-chat-input-area {
  padding: 12px 16px;
  background: rgba(22, 28, 42, 0.9);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.ai-chat-textarea {
  flex: 1;
  background: rgba(11, 15, 25, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 10px 14px;
  color: #f8fafc;
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  min-height: 42px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
}

.ai-chat-textarea:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.ai-chat-textarea::placeholder {
  color: #64748b;
}

.ai-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.ai-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-chat-footer-note {
  font-size: 10.5px;
  color: #64748b;
  text-align: center;
  line-height: 1.2;
}

/* Light Theme Overrides */
body.light .ai-chat-badge {
  border-color: #ffffff;
}

body.light .ai-chat-hint {
  background: #ffffff;
  color: #1e293b;
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

body.light .ai-chat-window {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15), 0 0 30px rgba(99, 102, 241, 0.1);
}

body.light .ai-chat-header {
  background: rgba(248, 250, 252, 0.85);
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

body.light .ai-chat-title-group h3 {
  color: #0f172a;
}

body.light .ai-chat-status {
  color: #64748b;
}

body.light .ai-chat-btn-icon {
  color: #64748b;
}

body.light .ai-chat-btn-icon:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #0f172a;
}

body.light .ai-chat-msg.assistant .ai-chat-bubble {
  background: #f1f5f9;
  border-color: rgba(0, 0, 0, 0.06);
  color: #1e293b;
}

body.light .ai-chat-bubble strong {
  color: #0f172a;
}

body.light .ai-chat-bubble code {
  background: #e2e8f0;
  color: #4338ca;
}

body.light .ai-chat-bubble pre {
  background: #1e293b;
  border-color: #334155;
}

body.light .ai-chat-bubble pre code {
  background: transparent;
  color: #f1f5f9;
}

body.light .ai-table-wrap {
  border-color: rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.02);
}

body.light .ai-chat-bubble th,
body.light .ai-chat-bubble td {
  border-color: rgba(0, 0, 0, 0.08);
}

body.light .ai-chat-bubble th {
  background: rgba(0, 0, 0, 0.04);
}

body.light .ai-chat-pill {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.2);
  color: #4338ca;
}

body.light .ai-chat-pill:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.35);
  color: #312e81;
}

body.light .ai-chat-typing {
  background: #f1f5f9;
  border-color: rgba(0, 0, 0, 0.06);
}

body.light .ai-chat-typing-dot {
  background: #6366f1;
}

body.light .ai-chat-input-area {
  background: #ffffff;
  border-top-color: rgba(0, 0, 0, 0.06);
}

body.light .ai-chat-textarea {
  background: #f8fafc;
  border-color: rgba(0, 0, 0, 0.12);
  color: #0f172a;
}

body.light .ai-chat-textarea::placeholder {
  color: #94a3b8;
}

/* Tablet / Intermediate Screens */
@media (max-width: 540px) {
  .ai-chat-window {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 80px;
    max-height: calc(100vh - 100px);
  }
}

/* Mobile Screens */
@media (max-width: 440px) {
  .ai-chat-widget {
    bottom: 16px;
    right: 16px;
  }
  .ai-chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    margin-bottom: 0;
  }
  .ai-chat-widget.is-open .ai-chat-trigger {
    display: none !important; /* На смартфонах скрываем кнопку вызова при открытом полноэкранном чате, закрытие через верхнюю панель */
  }
}
