/* Базовые стили */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #f5f5f5;
  position: fixed;
  overflow: hidden;
}

/* Основной контейнер */

.chat-app {
  height: 100dvh;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  background-color: #f5f5f5;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Шапка */

.chat-header {
  background: white;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  min-height: 60px;
  cursor: pointer;
}

.bot-avatar-container {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.bot-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background: #e0f7fa;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
}

.bot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.default-avatar-icon {
  color: #4285f4;
  font-size: 20px;
}

.bot-info-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.bot-name {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-chat-type {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.5);
}

.bot-status {
  font-size: 14px;
  font-weight: 400;
}

.bot-status.active {
  color: #4CAF50;
}

.bot-status.inactive {
  color: #f44336;
}

/* Область сообщений */

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background-color: #DCF8C6;
  border-bottom-right-radius: 4px;
}

.message.bot {
  align-self: flex-start;
  background-color: white;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.message .content {
  font-size: 16px;
  margin-bottom: 4px;
}

.message .timestamp {
  font-size: 12px;
  color: #999;
  text-align: right;
}

/* Индикатор набора текста */

.typing-indicator {
  display: flex;
  align-items: center;
  padding: 12px 0;
  margin-bottom: 12px;
  
  /* Позиционирование */
  align-self: flex-start;
  margin-left: 10px;
  max-width: 80%;
  
  /* Убираем фон и окантовку */
  background-color: transparent;
  border-radius: 0;
  box-shadow: none;
  border: none;
}

.typing-indicator.hidden {
  display: none;
}

.typing-dot {
  color: rgba(0, 0, 0, 0.6);
  font-size: 24px;
  line-height: 1;
  margin-right: 4px;
  animation: typingAnimation 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingAnimation {
  0%, 60%, 100% {
    opacity: 0.4;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* Область ввода */

.chat-input-area {
  background: white;
  border-top: 1px solid #e0e0e0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
  margin-bottom: 8px;
}

#messageInput {
  flex: 1;
  padding: 12px 50px 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 24px;
  font-size: 16px;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  font-family: inherit;
  line-height: 1.4;
  -webkit-appearance: none;
  -webkit-border-radius: 24px;
  background-color: white;
  transform: translateZ(0);
}

#messageInput:focus {
  outline: none;
  border-color: #e0e0e0;
  font-size: 16px !important;
}

.send-button {
  position: absolute;
  right: 8px;
  bottom: 6px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background-color: #ccc;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-appearance: none;
}

.send-button:not(:disabled) {
  background-color: #4285f4;
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.char-counter {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
  text-align: right;
  padding-right: 4px;
}

.char-counter.warning {
  color: #ff6b6b;
}

.platform-credit {
  text-align: center;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.4);
  margin-top: 4px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.platform-credit a {
  color: rgba(0, 0, 0, 0.3); /* Изменено с #4285f4 на чёрный с прозрачностью 0.5 */
  text-decoration: none;
  font-weight: 500;
}

.platform-credit a:hover {
  text-decoration: underline;
}

/* Мобильные стили */

@media (max-width: 480px) {
  .chat-header {
    padding: 10px 12px;
    min-height: 56px;
  }
  
  .bot-avatar-container {
    width: 32px;
    height: 32px;
  }
  
  .bot-avatar {
    font-size: 16px;
  }
  
  .default-avatar-icon {
    font-size: 18px;
  }
  
  .bot-name {
    font-size: 15px;
  }
  
  .bot-chat-type,
  .bot-status {
    font-size: 13px;
  }
  
  .chat-messages {
    padding: 12px;
    gap: 10px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  
  .message {
    max-width: 90%;
    padding: 10px 14px;
  }
  
  .message .content {
    font-size: 15px;
  }
  
  /* Индикатор набора текста для мобильных */
  .typing-indicator {
    margin-left: 7px;
    padding: 10px 0;
  }
  
  .typing-dot {
    font-size: 20px;
  }

  .chat-input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  
  .input-container {
    margin-bottom: 6px;
  }
  
  #messageInput {
    padding: 10px 45px 10px 14px;
    font-size: 15px;
    min-height: 44px;
  }
  
  .send-button {
    width: 32px;
    height: 32px;
    right: 6px;
    bottom: 6px;
  }
  
  .char-counter {
    font-size: 11px;
  }
  
  .platform-credit {
    font-size: 11px;
  }
}

@media (max-width: 768px) {
  .chat-app {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100% !important;
  }
  
  .chat-messages {
    overflow-anchor: none;
  }
}

/* Скроллбар */

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

/* Специфичные фиксы для iOS Safari */

@supports (-webkit-touch-callout: none) {
  .chat-app {
    height: -webkit-fill-available;
  }
}

/* ===================== */
/* Стили модального окна */
/* ===================== */

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.7);
  -webkit-tap-highlight-color: transparent;
}

.modal-content {
  position: relative;
  background-color: #fff;
  margin: 0 auto;
  margin-top: 20px;
  width: 95%;
  max-width: 500px;
  border-radius: 10px;
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
  animation-name: animatetop;
  animation-duration: 0.3s;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

@keyframes animatetop {
  from {top: -300px; opacity: 0}
  to {top: 0; opacity: 1}
}

.close-button {
  color: #aaa;
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 28px;
  font-weight: bold;
  z-index: 1001;
  cursor: pointer;
}

.close-button:hover,
.close-button:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}

.modal-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 20px;
}

.main-photo-container {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 10px 10px 0 0;
  display: flex;
  justify-content: center;
  background-color: #000;
}

.main-photo {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 10px 10px 0 0;
  display: block;
  margin: 0 auto;
}

.overlay-text {
  position: absolute;
  bottom: 20px;
  left: 20px;
  color: white;
  font-size: 24px;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
}

.bot-flag {
  font-size: 24px;
}

/* Блок статуса чата */

.chat-status-block {
  margin: 12px;
  border-radius: 12px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
  min-height: 60px;
  max-height: 80px;
  display: flex;
  width: 90%; /* Увеличить ширину блока */
  align-items: center;
  background-clip: padding-box;
}

.chat-status-block.public {
  background-color: #FCE4EC;
  border-color: #F8BBD0;
}

.chat-status-block.private {
  background-color: #E3F2FD;
  border-color: #BBDEFB;
}

.status-content {
  display: flex;
  align-items: center;
  height: 100%;
  width: 100%;
  justify-content: flex-start;
}

.status-icon {
  font-size: 16px;
  margin-right: 6px;
  flex-shrink: 0;
  flex-grow: 0;
  align-self: flex-start;
  margin-top: 1px;
}

.status-text {
  font-size: 10px;
  line-height: 1.2;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  margin-right: 4px;
}

.chat-status-block.public .status-text {
  color: #AD1457;
}

.chat-status-block.private .status-text {
  color: #1976D2;
}

/* Убираем треугольник и улучшаем внешний вид */

.chat-status-block::before {
  display: none;
}

/* Адаптивные стили */

@media (max-width: 480px) {
  .chat-status-block {
    min-height: 50px;
    max-height: 70px;
    padding: 10px;
  }
  
  .status-text {
    font-size: 9px;
    line-height: 1.1;
  }
  
  .status-icon {
    font-size: 14px;
    margin-right: 4px;
  }
}

@media (max-width: 320px) {
  .chat-status-block {
    min-height: 45px;
    max-height: 60px;
    padding: 8px;
  }
  
  .status-text {
    font-size: 8px;
    line-height: 1.1;
  }
  
  .status-icon {
    font-size: 12px;
    margin-right: 3px;
  }
}

.bot-info {
  padding: 16px;
}

.info-section {
  margin-bottom: 20px;
}

.info-header {
  display: flex;
  align-items: center;
  font-size: 22px;
  font-weight: bold;
  opacity: 0.7;
  margin-bottom: 4px;
}

.icon {
  margin-right: 8px;
  font-size: 20px;
}

.info-value {
  font-size: 16px;
  opacity: 0.5;
  margin-left: 28px;
  word-wrap: break-word;
}

.share-container {
  display: flex;
  align-items: center;
  margin-top: 8px;
  background-color: rgba(211, 211, 211, 0.2);
  border-radius: 8px;
  padding: 2px;
  overflow: hidden;
}

.chat-url {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 12px;
  font-size: 14px;
  opacity: 0.7;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-button {
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 0, 0, 0.3);
  transition: color 0.2s;
}

.copy-button:hover {
  color: #4CAF50;
}

.copy-button.copied {
  color: #4CAF50;
}

.photo-album {
  padding: 16px;
  padding-top: 0;
}

.album-header {
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  opacity: 0.7;
  margin-bottom: 8px;
}

.album-photos {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.album-photo-container {
  width: 100%;
  max-width: 300px;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  background-color: #000;
}

.album-photo {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 10px;
  display: block;
  margin: 0 auto;
}

@media (min-width: 768px) {
  .album-photos {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  .album-photo-container {
    max-width: calc(50% - 8px);
  }
}

@media (min-width: 1024px) {
  .modal-content {
    margin-top: 50px;
    max-width: 600px;
  }
  .album-photo-container {
    max-width: calc(33.333% - 11px);
  }
}

@media (min-width: 769px) {
  
  body:not(.iframe-mode) .chat-app {
    width: 700px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
    height: 95vh;
  }
  
  body:not(.iframe-mode) .chat-header {
    border-radius: 8px 8px 0 0;
  }
  body:not(.iframe-mode) .chat-input-area {
    border-radius: 0 0 8px 8px;
  }
}

body.iframe-mode .chat-app {
  width: 100%;
  margin: 0;
  box-shadow: none;
  border-radius: 0;
}