/* ===== ОСНОВА ===== */
html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  color: #fff;
  font-family: "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  box-sizing: border-box;
  background-color: #101316; /* ⬅️ голубовато-серый тёмный */

  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.015) 2px, transparent 2px),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='%2300ccff' fill-opacity='0.03'%3E%3Cpath d='M20 20h20v20H20z'/%3E%3Cpath d='M120 20c0-10 20-10 20 0v20h-20V20z'/%3E%3Ccircle cx='60' cy='60' r='8'/%3E%3Cpath d='M160 160l8 8-8 8-8-8z'/%3E%3Cpath d='M80 200h30v5H80z'/%3E%3Ccircle cx='200' cy='60' r='4'/%3E%3Cpath d='M180 30h8v16h-8zM180 30a4 4 0 118 0v16'/%3E%3Cpath d='M60 180l4 4-4 4-4-4z'/%3E%3Cpath d='M30 120h4v12h-4z'/%3E%3Ccircle cx='120' cy='120' r='5'/%3E%3Cpath d='M200 200h10v3h-10z'/%3E%3C/g%3E%3C/svg%3E");

  background-size: 40px 40px, 240px 240px;
  background-repeat: repeat;
  background-position: center center;
  background-attachment: fixed;
}



/* ===== КОНТЕЙНЕР ===== */
.container {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ===== САЙДБАР ===== */
.sidebar {
  width: 355px;
  background: #1a1a1a;
  border-right: 1px solid #2a2a2a;
  padding: 20px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.chat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex-grow: 1;
  overflow-y: auto;
}

.chat-list-item-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #2e2e2e;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.chat-list-item-container:hover {
  background: #3a3a3a;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}

.status-indicator.online {
  background-color: #3aff3a;
}

.status-indicator.offline {
  background-color: #971212;
}

.chat-list-item-link {
  color: #fff;
  font-size: 14px;
  flex-grow: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.chat-partner {
  font-size: 14px;
}

.unread-badge {
  background: #4b4b4b;
  color: white;
  font-weight: bold;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 8px;
  min-width: 20px;
  text-align: center;
}

.chat-list-delete-btn {
  background: transparent;
  color: #f55;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 0 6px;
  flex-shrink: 0;
}

.chat-list-delete-btn:hover {
  color: #ff7777;
}

/* ===== ОБЛАСТЬ ЧАТА ===== */
.chat-area {
  display: flex;
  flex-direction: column;
  
  overflow: hidden;
  height: 100%;
}




/* ===== СООБЩЕНИЯ ===== */
.chat-messages {
  flex-grow: 1;
  padding: 20px;
  padding-bottom: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 75%;
  padding: 8px 12px 20px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
  min-width: 80px;
}

.msg.left {
  align-self: flex-start;
  background: #2c2c2c;
  color: #fff;
  border-top-left-radius: 0;
}

.msg.right {
  align-self: flex-end;
  background: #4fc3f7;
  color: #000;
  border-top-right-radius: 0;
  padding-right: 32px;
}

.msg-time {
  position: absolute;
  bottom: 4px;
  right: 8px;
  font-size: 11px;
  color: rgba(0, 0, 0, 0.4);
}

.msg.left .msg-time {
  color: rgba(255, 255, 255, 0.5);
}

/* ===== КНОПКА УДАЛЕНИЯ СООБЩЕНИЯ ===== */
.msg .delete-btn {
  position: absolute;
  top: 4px;
  right: 6px;
  border: none;
  background: transparent;
  color: #000000;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.4;
  transition: color 0.2s ease, opacity 0.2s ease;
  display: block;
  pointer-events: none;
}

.msg:hover .delete-btn {
  opacity: 1;
  pointer-events: auto;
  color: #f55;
}

/* ===== ПОЛЕ ВВОДА ===== */
.chat-input {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
  background: #1f1f1f;
  border-top: 1px solid #2a2a2a;
  flex-shrink: 0;
  position: relative;
}

.chat-input input {
  flex: 1;
  background: #2a2a2a;
  border: none;
  color: #fff;
  padding: 10px;
  border-radius: 8px;
  font-size: 14px;
}

.chat-input button {
  background: #4fc3f7;
  border: none;
  color: #000;
  font-weight: bold;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

/* ===== АУДИО СООБЩЕНИЯ ===== */
audio {
  width: 280px;
  height: 30px;
  margin-top: 6px;
}

/* ===== МОБИЛЬНЫЙ ВИД ===== */
@media (max-width: 767px) {
  html, body {
    overflow: hidden;
  }
  .container {
    flex-direction: column;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 85%;
    max-width: 300px;
    background: #1a1a1a;
    transform: translateX(-100%);
    z-index: 999;
    overflow-y: auto;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .chat-input {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
  }


  .chat-messages {
    padding-bottom: 120px !important;
  }
  .chat-messages::after {
    content: '';
    flex-shrink: 0;
    height: 30px;
  }
}

/* ===== ПЛАНШЕТЫ ===== */
@media (min-width: 768px) and (max-width: 1280px) {
  .chat-area {
    display: flex;
    flex-direction: column;
    height: 100dvh;
  }

  .chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding-bottom: 120px;
  }

  .chat-input {
    position: relative;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
  }
}

/* ===== ДЕСКТОПЫ ===== */
@media (min-width: 1281px) {
  .chat-area {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin: 0;
    max-width: none;
    width: 100%;
    border-left: none;
    border-right: none;
  }

  .chat-messages {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
  }

  .chat-input {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
  }
}


/* ===== ЛОГИН-ФОРМА ===== */
.login-box {
  width: 80%;
  max-width: 400px;
  margin: 60px auto;
  padding: 40px;
  background: #1a1a1a;
  border-radius: 12px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.login-box .logo {
  font-size: 32px;
  font-weight: bold;
  color: #4fc3f7;
  margin-bottom: 20px;
}

.login-box h2 {
  margin: 10px 0 20px;
  font-size: 22px;
}

.login-box input {
  width: 100%;
  padding: 12px;
  margin-bottom: 15px;
  background: #2a2a2a;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  box-sizing: border-box;
}

.login-box button {
  width: 100%;
  padding: 12px;
  background: #4fc3f7;
  color: #000;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}

.login-box .hint {
  font-size: 13px;
  color: #bbb;
  margin-top: 10px;
}

.msg audio {
  display: block;
  max-width: 100%;
  margin-top: 6px;
  border-radius: 8px;
  background: none;
  height: 36px;
  box-sizing: border-box;
}

.sound-toggle-wrapper {
  margin-top: 10px;
}

#soundToggleBtn {
  background: #2a2a2a;
  color: #4fc3f7;
  border: 1px solid #4fc3f7;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s ease, color 0.2s ease;
}

#soundToggleBtn:hover {
  background: #4fc3f7;
  color: #000;
}

.drop-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drop-overlay.active {
  pointer-events: all;
  opacity: 1;
}

#fileUploadLabel {
  cursor: pointer;
  font-size: 20px;
  margin-right: 10px;
}

.logo-darknet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: fadeGhost 1.2s ease-in-out;
}

.ghost-svg {
  width: 80px;
  height: 80px;
  filter: drop-shadow(0 0 20px #00ccff44);
  animation: pulse 2s infinite;
}

.ghost-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 0 0 15px #00ccff66;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ghost-text {
  color: #00ccff;
}

.me-text {
  color: #777;
  font-weight: 400;
  text-shadow: 0 0 6px #222;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px #00ccff66); }
  50% { transform: scale(1.05); filter: drop-shadow(0 0 25px #00ccff); }
}

@keyframes fadeGhost {
  from { opacity: 0; transform: translateY(-15px); }
  to { opacity: 1; transform: translateY(0); }
}

.sidebar-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 15px 0 10px;
  text-align: center;
}

.sidebar-logo .ghost-svg {
  width: 50px;
  height: 50px;
  filter: drop-shadow(0 0 12px #00ccff44);
  margin-bottom: 5px;
}

.sidebar-logo .ghost-title {
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 1px;
  text-shadow: 0 0 8px #00ccff55;
  display: flex;
  gap: 3px;
}

.sidebar-logo .ghost-text {
  color: #00ccff;
}

.sidebar-logo .me-text {
  color: #888;
}

#messageInput {
  max-height: 180px; /* Примерно 13-14 строк */
  overflow-y: auto;
  line-height: 1.4em;
  padding: 8px;
  font-size: 14px;
  color: #fff;
  background: #1a1a1a;
  border: none;
  border-radius: 8px;
  outline: none;
  flex: 1;
  min-height: 40px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #2a2a2a;
  padding: 10px 14px;
  color: #00ccff;
  font-weight: bold;
  border-bottom: 1px solid #222;
  position: relative;
}

.chat-search {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.chat-search input {
  padding: 2px 8px;
  border-radius: 6px;
  border: none;
  background: #1d1d1d;
  color: #fff;
  outline: none;
}

.chat-search button {
  background: none;
  border: none;
  color: #00ccff;
  cursor: pointer;
  font-size: 14px;
}

#openSearch {
  background: none;
  border: none;
  color: #00ccff;
  font-size: 16px;
  cursor: pointer;
  margin-left: 10px;
}

.highlighted {
  background-color: #00334488;
  border-left: 3px solid #00ccff;
  padding-left: 5px;
}

.highlight-word {
  background: rgba(0, 255, 219, 0.3); /* нежная подсветка, прозрачная */
  color: inherit;
  font-weight: bold;
  padding: 1px 3px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0, 255, 219, 0.6);
  transition: background 0.2s, box-shadow 0.2s;
}

.highlight-current {
  outline: 2px solid #00ffdb;
  outline-offset: 3px;
  box-shadow: 0 0 12px #00ffdb;
  border-radius: 6px;
  transition: outline 0.2s, box-shadow 0.2s;
}


.sidebar-close {
  display: none;
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: #00ccff;
  font-size: 22px;
  cursor: pointer;
  z-index: 1001;
}

@media (max-width: 767px) {
  .sidebar-close {
    display: block;
  }
}

.logout-btn {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #2a2a2a;
  color: #f66;
  font-size: 14px;
  text-decoration: none;
  border: 1px solid #333;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.logout-btn:hover {
  background: #2d2d2d;
  box-shadow: 0 0 8px #ff444455;
}

a.sidebar-logo {
  text-decoration: none;
}

/* Кнопка цитирования сообщений */
.quote-btn {
  position: absolute;
  bottom: 4px;
  right: 28px;
  background: none;
  border: none;
  color: #000;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.msg.left .quote-btn {
  color: #989898;
  opacity: 20%;
}

.msg:hover .quote-btn {
  opacity: 1;
}

/* ==== 1. Основные отступы сообщений ==== */
.msg {
  position: relative;
  padding-left: 26px;
}
.msg.right {
  padding-left: 26px;
  padding-right: 35px;
}

/* ==== 2. Кнопка "ответить" ==== */
.quote-btn {
  --s: 15px;
  width: var(--s);
  height: var(--s);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  bottom: 6px;
  left: 6px;
  border: none;
  background: none;
  font-size: 12px;
  color: #3b3b3b;
  opacity: 50%;
  cursor: pointer;
  transition: color 0.2s ease;
}
.quote-btn:hover {
  color: #00ccff;
}
.quote-btn i {
  transform: rotate(180deg);
  pointer-events: none;
}

/* ==== 3. Цитата внутри сообщения ==== */
.quoted-block {
  position: relative;
  font-size: 13px;
  line-height: 1.4;
  padding: 6px 10px;
  margin-bottom: 8px;
  border-left: 3px solid #2a779e;
  border-radius: 6px;
  max-height: 6em;
  overflow: hidden;
  word-break: break-word;
  background-color: rgba(255,255,255,0.1);
  backdrop-filter: blur(2px);
  color: inherit;
}

/* Подстройка под тёмную/светлую сторону */
.msg.right .quoted-block {
  background-color: rgb(255 255 255 / 55%);
  color: #111;
  box-shadow: inset 0 0 0 999px rgba(255,255,255,0.25);
}
.msg.left .quoted-block {
  background-color: rgba(255, 255, 255, 0.06);
  color: #eee;
}

/* ==== 4. Preview над полем ввода ==== */
.quote-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 18px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
  border-left: 3px solid #00ccff;
  border-radius: 8px;
  background-color: #222;
  color: #ccc;
  box-shadow: 0 2px 6px #0008;
}
.quote-preview button {
  margin-left: auto;
  background: none;
  border: none;
  color: #ff5c5c;
  font-size: 16px;
  cursor: pointer;
}
.quote-preview button:hover {
  color: #ff9191;
}

#quotePreview {
  background: #2a2a2a;
  bottom: 10px;
  border-left: 3px solid #00ccff;
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 2px 6px #000a;
  font-size: 13px;
  line-height: 1.4;
  display: flex;
  gap: 6px;
  color: #ccc;
  flex-wrap: wrap;
  z-index: 100;
  max-width: 720px;
  width: 100%;
  margin: 6px auto 0;
  position: relative; /* главное изменение */
}

/* === Кнопка закрытия === */
#quotePreview button {
  margin-left: auto;
  background: none;
  border: none;
  color: #ff5c5c;
  font-size: 16px;
  cursor: pointer;
}
#quotePreview button:hover {
  color: #ff9191;
}

/* === МОБИЛКА: фиксированное позиционирование === */
@media (max-width: 767px) {
  #quotePreview {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 99px;
    max-width: unset;
    width: auto;
    border-left: 3px solid #00ccff;
    border-radius: 8px;
    box-shadow: 0 2px 6px #000a;
    padding: 8px 10px;
    background: #2a2a2a;
    z-index: 101;
  }
}

.quoted-block {
  cursor: pointer;
  transition: background 0.2s;
}

.quoted-block:hover {
  background: #d6efff;
}

.lang-switcher {
  margin: 16px auto 0;
  text-align: center;
}
.lang-switcher select {
  background: #222;
  color: #fff;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  width: 90%;
  max-width: 200px;
}
.lang-switcher select:focus {
  outline: none;
  border-color: #00ccff;
}
.chat-list {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 10px;
}
@media (max-height: 700px) {
  .chat-list {
    max-height: 220px;
  }
}

#scrollToBottomBtn {
  position: fixed;
  bottom: 90px;
  right: 60px; /* чуть левее от края */
  z-index: 1000;
  width: 48px;
  height: 48px;
  padding: 0;
  font-size: 22px;
  line-height: 48px;
  text-align: center;
  background: #00ccff;
  color: #000;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 16px #00ccff55;
  transition: all 0.25s ease;
  opacity: 0.9;
}

#scrollToBottomBtn:hover {
  transform: scale(1.12);
  box-shadow: 0 0 22px #00ccffcc;
  opacity: 1;
}




/* ===== Телеграм-подобный scrollbar ===== */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background-color: #444;
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.chat-messages:hover::-webkit-scrollbar-thumb {
  background-color: #666;
}

/* Бургер скрыт по умолчанию */
.mobile-toggle {
  display: none;
}

/* Показываем только на мобилках */
@media (max-width: 767px) {
  .mobile-toggle {
    display: block;
    position: relative;
    font-size: 22px;
    background: none;
    border: none;
    color: #00ccff;
    cursor: pointer;
    margin-right: 10px;
  }
}

.chat-list::-webkit-scrollbar {
  width: 8px;
}

.chat-list::-webkit-scrollbar-track {
  background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
  background-color: #444;
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.chat-list:hover::-webkit-scrollbar-thumb {
  background-color: #666;
}

#scrollToBottomBtn {
  background: #444; /* вместо голубого */
  color: #eee;
}

@media (max-width: 767px) {
  #scrollToBottomBtn {
    width: 40px;
    height: 40px;
    font-size: 18px;
    right: 18px;
    bottom: 85px;
    box-shadow: 0 0 10px #0006;
  }
}

@supports (-webkit-touch-callout: none) {

  /* === 1. Фикс для перекрытия кнопки удаления сообщений === */
  .msg {
    position: relative;
    z-index: 1;
    transform: translateZ(0); /* устраняет странные баги Safari с слоями */
  }

  .msg .delete-btn {
    z-index: 10;
  }

  /* === 2. Фикс для quotePreview на мобильных — позиционируется как надо === */
  #quotePreview {
    position: fixed !important;
    z-index: 9999 !important;
    bottom: 95px !important;
    left: 12px;
    right: 12px;
    background: #2a2a2a;
    box-shadow: 0 2px 6px #000a;
  }

  /* === 3. Фикс для селектора языка, чтобы не уезжал за экран === */
  .lang-switcher {
    margin-bottom: 120px !important;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* === 4. Доп. защита для кнопки "цитировать", чтобы не конфликтовала === */
  .quote-btn {
    z-index: 9;
  }
}

@supports (-webkit-touch-callout: none) {
  .msg.right {
    padding-right: 44px !important;
  }
}

.msg .delete-btn {
  right: 10px !important;
}
