:root {
  --background-body: #131313;
  --header-bg: #212121;
  --bg-color: white;
  --text-color: white;
  --chat-item-bg: rgba(255, 255, 255, 0.04);
  --chat-item-bg-hover: rgba(255, 255, 255, 0.1);
  --border-color: rgba(255, 255, 255, 0.075);
  --accent: #5aa0ff;
  --danger: #ff6464;
}
.light-theme {
  --background-body: #f9f9f9;
  --header-bg: #00aaff;
  --text-color: rgb(78, 78, 78);
  --chat-item-bg: rgba(0, 0, 0, 0.04);
  --chat-item-bg-hover: rgba(0, 0, 0, 0.1);
  --border-color: rgba(71, 71, 71, 0.075);
  --accent: #187ac5;
  --danger: #cf3c3c;
}
* {
  transition: all 0.25s ease !important;
  font-family: "Montserrat", sans-serif;
  font-optical-sizing: auto;
  font-style: normal;
  box-sizing: border-box;
}
html, body { overflow-x: hidden; }
body {
  background-color: var(--background-body);
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  color: var(--text-color);
}
.container {
  width: 100%;
  max-width: 1200px;
  border-radius: 10px;
  overflow: hidden;
  max-height: calc(100vh - 20px);
  display: flex;
  flex-direction: column;
  position: relative;
}
.header {
  background-color: var(--header-bg);
  color: var(--bg-color);
  padding: 12px 15px;
  text-align: center;
  font-size: 1.15em;
  position: relative;
  flex-shrink: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#header-title { font-weight: 600; cursor: pointer; }
.theme-toggle, .back-button {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-color);
  cursor: pointer; padding: 6px 10px; z-index: 20; border-radius: 10px;
}
.theme-toggle { right: 10px; font-size: 1.35em; }
.back-button {
    left: 10px;
    display: none;
  font-size: 1.1em;
  padding: 10px 16px;
  border-radius: 14px;
}
.back-button:hover {
  background-color: rgba(0,0,0,0.35);
}
.theme-toggle:hover, .back-button:hover { background-color: rgba(0,0,0,0.15); }

.chat-list, .chat-view {
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden; /* ключ к отсутствию горизонтального скролла */
  padding: 10px;
  display: none;
  flex-direction: column;
  position: relative;
}
.chat-list.active, .chat-view.active { display: flex; }

.section-toggle {
  display:flex; align-items:center; gap:8px; font-weight:700;
  padding:10px; margin-bottom:10px; cursor:pointer; border-radius:10px;
  background-color: var(--chat-item-bg);
  user-select: none;
}
.section-toggle .icon { text-decoration: line-through; }

.section-counter { margin-left:auto; font-weight:600; opacity:0.9; }

.section-toggle .icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.section-toggle .icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor; /* чтобы цвет наследовался */
  color: white; /* тёмная тема */
}

.light-theme .section-toggle .icon svg {
  color: #444; /* светлая тема */
}

.chat-item {
  display: flex; align-items: center; font-weight: 500; padding: 10px; margin-bottom: 10px; cursor: pointer; border-radius: 10px; background-color: var(--chat-item-bg); position: relative;
}
.chat-item:hover { background-color: var(--chat-item-bg-hover); box-shadow: inset 0 0 0 2px var(--border-color); }
.avatar { width: 50px; height: 50px; border-radius: 50%; margin-right: 10px; background-color: #000; overflow: hidden; flex: 0 0 50px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.chat-title { font-size: 1em; color: var(--text-color); }

.action-bar { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: flex; gap: 6px; opacity: 0; pointer-events: none; }
.chat-item.show-actions .action-bar { opacity: 1; pointer-events: auto; }
.action-btn { padding: 6px 10px; border-radius: 8px; border: none; cursor: pointer; font-weight: 700; }
.hide-btn { background: var(--accent); color: #fff; }
.unhide-btn { background: var(--danger); color: #fff; }

.chat-item {
  -webkit-user-select: none;
  user-select: none;
}

/* Сообщения */
.message {
  margin: 10px 0; padding: 10px; border-radius: 10px; font-weight: 500; max-width: 70%; display: flex; flex-direction: column;
  min-width: 0; /* важно для flex-внутренностей, чтобы они могли сжиматься и переноситься */
  word-break: normal;
}
.message.my { color: white; background-color: #2a2a2a; margin-left: auto; }
.message.another { color: white; background-color: #343434; margin-right: auto; }
.light-theme .message.my { background-color: #187ac5; }
.light-theme .message.another { background-color: #0090ff; }

.reply { border-left: 3px solid var(--accent); padding: 6px 8px; margin-bottom: 6px; border-radius: 6px; background: rgba(255,255,255,0.06); font-size: 0.86em; line-height: 1.25; }
.light-theme .reply { background: rgba(0,0,0,0.06); }
.reply .title { font-weight: 700; opacity: 0.95; margin-bottom: 2px; }
.reply .text {
  white-space: pre-wrap; /* разрешаем переносы */
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  opacity: 0.9;
}

.message img, .message video, .message audio { max-width: 100%; height: auto; border-radius: 10px; display: block; }

.timestamp {
  font-weight: 600 !important; margin-top: 5px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  font-size: 0.8em !important; word-break: break-word; overflow-wrap: anywhere;
  min-width: 0; /* позволяет контенту внутри переноситься, а не расширять контейнер */
}
.message.my .timestamp { flex-direction: row; }
.message.another .timestamp { flex-direction: row-reverse; }

.content {
  font-size: 0.95em; font-weight: 500;
  white-space: pre-wrap;           /* сохраняем \n и переносим длинные токены */
  overflow-wrap: anywhere;         /* переносит длинные ссылки/слова */
  word-break: break-word;          /* страховка для старых браузеров */
  line-break: anywhere;
  min-width: 0;                    /* критично в флекс-контейнере */
}
.content a {
  color: #cde0ff; text-decoration: underline; text-underline-offset: 2px;
  overflow-wrap: anywhere; word-break: break-word; hyphens: auto;
}

.action-bar,
.action-btn,
.hide-btn,
.unhide-btn {
  -webkit-user-select: none; /* iOS Safari */
  -webkit-touch-callout: none; /* убираем системное меню */
  user-select: none;
}

.timestamp .content { flex: 1 1 auto; text-align: left; min-width: 0; }
.message.another .timestamp .content { text-align: right; }
.timestamp .time { flex: 0 0 auto; font-size: 0.8em; color: #aaa; text-align: right; }
.message.another .timestamp .time { text-align: left; }
.light-theme .timestamp .time, .light-theme .timestamp .content { color: #ffffffbd; }

.date-divider { text-align: center; font-size: 0.9em; font-weight: 800; color: #888; margin: 10px 0; width: 100%; }
.light-theme .date-divider { color: #bbb; }

.error { color: rgb(255, 84, 84); padding: 10px; text-align: center; }
.loading { padding: 10px; text-align: center; color: var(--text-color); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal.open { display: flex; }
.modal-card { background: var(--background-body); color: var(--text-color); width: min(420px, 92vw); border-radius: 16px; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,0.35); }
.profile-top { display: flex; align-items: center; gap: 12px; }
.profile-photo { width: 74px; height: 74px; border-radius: 50%; background: #000; overflow: hidden; }
.profile-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-name { font-size: 1.15em; font-weight: 800; }
.profile-username { opacity: 0.85; margin-top: 2px; }
.profile-actions { margin-top: 14px; display: flex; gap: 8px; }
.btn { border: 1px solid var(--border-color); background: var(--chat-item-bg); color: var(--text-color); padding: 10px 12px; border-radius: 10px; cursor: pointer; font-weight: 700; }
.btn:hover { background: var(--chat-item-bg-hover); }

/* Выделение режима просмотра скрытых */
#hiddenList.active-scope { background: linear-gradient(180deg, rgba(255,99,132,0.08), rgba(255,99,132,0.02)); border-radius: 12px; padding: 6px; }
#hiddenList.active-scope .chat-item { background-color: rgba(255,99,132,0.14); box-shadow: inset 0 0 0 1px rgba(255,99,132,0.3); }
.light-theme #hiddenList.active-scope { background: linear-gradient(180deg, rgba(255,99,132,0.12), rgba(255,99,132,0.05)); }
.light-theme #hiddenList.active-scope .chat-item { background-color: rgba(255,99,132,0.18); }
button, .btn, .action-btn, .back-button {
  -webkit-user-select: none; /* Safari */
  -moz-user-select: none;    /* Firefox */
  -ms-user-select: none;     /* IE10+/Edge */
  user-select: none;         /* Стандарт */
  -webkit-touch-callout: none; /* убирает меню при долгом тапе */
}