/* === Floating Chat Button + Window === */

.chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a3a5c, #003399);
  border: none;
  box-shadow: 0 6px 20px rgba(0, 51, 153, 0.35);
  color: white;
  font-size: 28px;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.chat-fab:hover,
.chat-fab:active {
  transform: scale(1.05);
  box-shadow: 0 8px 24px rgba(0, 51, 153, 0.45);
}

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

@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(0, 51, 153, 0.35); }
  50%      { box-shadow: 0 6px 20px rgba(0, 51, 153, 0.35), 0 0 0 12px rgba(0, 51, 153, 0); }
}
.chat-fab.pulse {
  animation: chat-pulse 2s ease-in-out 3;
}

/* === Chat Window === */
.chat-window {
  position: fixed;
  top: 31px;
  height: 80vh;
  max-height: 80vh;
  min-height: 400px;
  bottom: auto;
  right: 20px;
  width: calc(100vw - 40px);
  max-width: 380px;
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Aldrich', 'Montserrat', system-ui, -apple-system, sans-serif;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  transition: height 0.25s ease;
}

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

/* Компактный режим — когда открыта клавиатура */
.chat-window.open.compact {
  height: 57vh;
  max-height: 57vh;
}

.chat-header {
  background: linear-gradient(135deg, #1a3a5c, #003399);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-header-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.chat-clear {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: white;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
  line-height: 1;
}
.chat-clear:hover,
.chat-clear:active {
  background: rgba(255, 255, 255, 0.32);
}

/* Кнопка закрытия (Перенесена вниз) */
.chat-close {
  position: absolute;
  bottom: 8px;
  right: 10px;
  background: rgba(0, 0, 0, 0.08);
  border: none;
  color: #333;
  font-size: 20px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.chat-close:hover,
.chat-close:active {
  background: rgba(0, 0, 0, 0.15);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #007aff, #0056b3);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.7);
  color: #1a1a1a;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-bottom-left-radius: 4px;
}

.chat-msg.error {
  align-self: center;
  background: rgba(220, 53, 69, 0.12);
  color: #b02030;
  font-size: 0.82rem;
  text-align: center;
  border-radius: 10px;
}

.chat-typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #003399;
  opacity: 0.5;
  animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* === Persistent Quick Suggestions === */
.chat-suggestions-viewport {
  background: rgba(255, 255, 255, 0.55);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 51, 153, 0.25) transparent;
}

.chat-suggestions-viewport::-webkit-scrollbar {
  height: 4px;
}
.chat-suggestions-viewport::-webkit-scrollbar-thumb {
  background: rgba(0, 51, 153, 0.25);
  border-radius: 2px;
}
.chat-suggestions-viewport::-webkit-scrollbar-track {
  background: transparent;
}

.chat-suggestions-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  width: max-content;
  min-width: 100%;
}

.chat-suggestion-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.chat-suggestion {
  background: rgba(0, 51, 153, 0.08);
  border: 1px solid rgba(0, 51, 153, 0.2);
  color: #003399;
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  white-space: nowrap;
}

.chat-suggestion:hover,
.chat-suggestion:active {
  background: rgba(0, 51, 153, 0.18);
}

.chat-suggestion:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Input area === */
.chat-input-area {
  padding: 7px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  gap: 7px;
  background: rgba(255, 255, 255, 0.5);
  flex-shrink: 0;
  margin-bottom: 45px
}

/* Уменьшенное поле ввода */
.chat-input {
  flex: 1;
  padding: 6px 14px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 20px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  background: white;
  resize: none;
  max-height: 70px;
  min-height: 32px;
  line-height: 1.3;
}

.chat-input:focus {
  border-color: #003399;
  box-shadow: 0 0 0 2px rgba(0, 51, 153, 0.15);
}

.chat-send {
  background: linear-gradient(135deg, #1a3a5c, #003399);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s ease;
}

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

/* Измененный отступ, чтобы текст не пересекался с кнопкой закрытия */
.chat-disclaimer {
  font-size: 0.7rem;
  color: #666;
  text-align: center;
  padding: 6px 45px 10px 10px; 
  background: rgba(255, 255, 255, 0.5);
  min-height: 24px;
}

/* === Tab links inside assistant messages === */
.chat-tab-link {
  display: inline-block;
  margin: 4px 2px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #28a745, #1e7e34);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(40, 167, 69, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-tab-link:hover,
.chat-tab-link:active {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(40, 167, 69, 0.35);
}

/* === Page links inside assistant messages === */
.chat-page-link {
  display: inline-block;
  margin: 4px 2px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #003399, #1a3a5c);
  color: white !important;
  border: none;
  border-radius: 14px;
  font-size: 0.85rem;
  font-family: inherit;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 51, 153, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-page-link:hover,
.chat-page-link:active {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 51, 153, 0.4);
  color: white !important;
}

/* === External URL links === */
.chat-url-link {
  display: inline-block;
  margin: 4px 2px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #ff9800, #f57c00);
  color: white !important;
  border: none;
  border-radius: 14px;
  font-size: 0.85rem;
  font-family: inherit;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(245, 124, 0, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-url-link:hover,
.chat-url-link:active {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(245, 124, 0, 0.45);
  color: white !important;
}

/* === Mobile adjustments === */
@media (max-width: 480px) {
  .chat-window {
    top: 31px;
    bottom: auto;
    right: 10px;
    left: 10px;
    width: auto;
    max-width: none;
    height: 80vh;
    max-height: 80vh;
    min-height: 400px;
    border-radius: 20px;
  }
  
  .chat-window.open.compact {
    height: 57vh;
    max-height: 57vh;
  }
  
  .chat-fab {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
    font-size: 26px;
  }
}

/* ============================================ */
/* === PC (мышь) + Smart TV (пульт-указка) === */
/* === Применяется если: большой экран ИЛИ точный указатель === */
/* ============================================ */
@media (min-width: 1024px), (pointer: fine) {
  .chat-window {
    width: 440px;
    max-width: 440px;
    height: 73vh;
    max-height: 720px;
    min-height: 500px;
    top: 30px;
    right: 30px;
  }

  /* На PC/TV нет программной клавиатуры — компактный режим не нужен */
  .chat-window.open.compact {
    height: 73vh;
    max-height: 720px;
  }

  .chat-fab {
    width: 64px;
    height: 64px;
    font-size: 30px;
    bottom: 30px;
    right: 30px;
  }

  .chat-input {
    font-size: 14px;
    padding: 8px 16px;
    min-height: 38px;
    max-height: 100px;
  }

  .chat-msg {
    font-size: 0.95rem;
  }

  .chat-suggestion {
    font-size: 0.85rem;
    padding: 7px 14px;
  }
}