:root {
  --bg-dark: #08060d;
  --bg-card: rgba(18, 14, 28, 0.75);
  --accent-purple: #9d4edd;
  --accent-glow: #7b2cbf;
  --accent-pink: #e0aaff;
  --text-main: #f3f0f7;
  --text-muted: #a099b2;
  --border-color: rgba(157, 78, 221, 0.25);
  --font-heading: 'Cinzel', serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 80% 20%, rgba(123, 44, 191, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 10% 80%, rgba(157, 78, 221, 0.1) 0%, transparent 50%);
}

.bg-grid {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-size: 60px 60px;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  pointer-events: none;
  z-index: 0;
}

/* ШАПКА ТА НАВІГАЦІЯ */
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 80px;
  padding: 0 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(8, 6, 13, 0.8);
}

.logo {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: linear-gradient(135deg, #fff, var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-star {
  color: var(--accent-purple);
}

nav {
  display: flex;
  gap: 16px;
}

nav button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.85rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 8px 18px;
  border-radius: 20px;
}

nav button:hover, nav button.active {
  color: #fff;
  text-shadow: 0 0 10px var(--accent-purple);
  background: rgba(157, 78, 221, 0.15);
}

/* УПРАВЛІННЯ ВКЛАДКАМИ */
.tab-content {
  display: none !important;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.tab-content.active {
  display: flex !important;
}

/* СТОРІНКА 1: ВСТУП */
#tab-intro {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 120px 24px 60px;
}

.hero-title {
  font-family: var(--font-heading);
  font-size: clamp(2.5rem, 7vw, 6rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -1px;
  margin-bottom: 24px;
  background: linear-gradient(180deg, #ffffff 30%, var(--accent-pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-muted);
  max-width: 600px;
  line-height: 1.7;
  margin-bottom: 48px;
  font-weight: 300;
}

.btn-start {
  background: linear-gradient(135deg, rgba(157, 78, 221, 0.8), rgba(123, 44, 191, 0.9));
  color: #fff;
  border: 1px solid var(--accent-pink);
  padding: 16px 38px;
  font-size: 0.9rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  border-radius: 40px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 30px rgba(157, 78, 221, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.btn-start:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 0 50px rgba(157, 78, 221, 0.7);
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  color: #000;
  font-weight: 600;
}

.nebula-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(157, 78, 221, 0.25) 0%, transparent 70%);
  filter: blur(60px);
  pointer-events: none;
  z-index: -1;
}

/* СТОРІНКА 2: ЧАТ */
#tab-chat {
  padding-top: 100px;
  height: 100vh;
  width: 100vw;
  max-width: 1450px;
  margin: 0 auto;
}

.chat-container {
  display: flex;
  width: 100%;
  height: calc(100vh - 105px);
  gap: 20px;
  padding: 0 24px 24px;
}

.chat-sidebar {
  width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 20px;
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.sidebar-title {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  letter-spacing: 1px;
  color: var(--accent-pink);
  text-transform: uppercase;
}

.btn-new-chat {
  background: var(--accent-purple);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.3s;
}

.btn-new-chat:hover {
  background: var(--accent-pink);
  color: #000;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-item {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.2s;
}

.chat-item:hover, .chat-item.active {
  background: rgba(157, 78, 221, 0.2);
  color: #fff;
  border-color: var(--accent-purple);
}

.chat-main {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 0.95rem;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(157, 78, 221, 0.3), rgba(123, 44, 191, 0.4));
  border: 1px solid rgba(157, 78, 221, 0.4);
  color: #fff;
}

.msg.ai {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.msg-photo {
  display: block;
  width: auto;
  max-width: 180px;
  max-height: 150px;
  margin: 0 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  object-fit: cover;
}

/* Підказка перед першим повідомленням */
.chat-hint {
  align-self: flex-start;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 80%;
  padding: 12px 16px;
  border: 1px dashed rgba(157, 78, 221, 0.45);
  border-radius: 14px;
  background: rgba(157, 78, 221, 0.08);
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.55;
  animation: fadeIn 0.3s ease;
}

.chat-hint strong {
  color: var(--accent-pink);
  font-weight: 600;
}

.chat-hint-icon {
  font-size: 1rem;
  line-height: 1.4;
}

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  background: rgba(8, 6, 13, 0.6);
}

.chat-input-area textarea {
  flex: 1;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  resize: none;
  height: 48px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
}

.chat-input-area textarea:focus {
  border-color: var(--accent-purple);
}

.btn-send {
  background: var(--accent-purple);
  border: none;
  color: #fff;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.btn-send:hover {
  background: var(--accent-pink);
  color: #000;
}

/* МОБІЛЬНА АДАПТАЦІЯ (ДЛЯ ТЕЛЕФОНІВ) */
@media (max-width: 768px) {
  header {
    padding: 0 16px;
    height: 70px;
  }

  .logo {
    font-size: 1rem;
    letter-spacing: 1px;
  }

  nav button {
    padding: 6px 10px;
    font-size: 0.75rem;
    letter-spacing: 1px;
  }

  #tab-chat {
    padding-top: 75px;
    height: 100vh;
  }

  .chat-container {
    flex-direction: column;
    height: calc(100vh - 80px);
    padding: 0 8px 12px;
    gap: 10px;
  }

  .chat-sidebar {
    width: 100%;
    max-height: 120px;
    padding: 12px;
    gap: 8px;
    order: 2;
  }

  .chat-main {
    width: 100%;
    flex: 1;
    order: 1;
  }

  .chat-messages {
    padding: 16px;
  }

  .chat-input-area {
    padding: 12px;
  }

  .status-banner {
    top: 78px;
  }

  .chat-hint {
    max-width: 100%;
  }
}

/* Банер статусу AI */
.status-banner {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  width: max-content;
  max-width: calc(100% - 30px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  transition: all 0.3s ease;
}

/* Ховати банер за замовчуванням */
.status-banner.hidden {
  display: none;
}

/* Індикатор (крапка) */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  animation: pulse 1.8s infinite;
}

/* Стан: Технічні роботи / Проблема */
.status-banner.maintenance {
  background: rgba(255, 170, 0, 0.15);
  border: 1px solid rgba(255, 170, 0, 0.4);
  color: #ffca28;
}
.status-banner.maintenance .status-dot {
  background-color: #ffb300;
  box-shadow: 0 0 8px #ffb300;
}

/* Стан: сервер прокидається / файл завантажується */
.status-banner.loading {
  background: rgba(157, 78, 221, 0.18);
  border: 1px solid rgba(157, 78, 221, 0.45);
  color: var(--accent-pink);
}
.status-banner.loading .status-dot {
  background-color: var(--accent-purple);
  box-shadow: 0 0 8px var(--accent-purple);
}

/* Стан: Помилка сервера */
.status-banner.error {
  background: rgba(255, 77, 77, 0.15);
  border: 1px solid rgba(255, 77, 77, 0.4);
  color: #ff6b6b;
}
.status-banner.error .status-dot {
  background-color: #ff4d4d;
  box-shadow: 0 0 8px #ff4d4d;
}

/* Пульсація індикатора */
@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

/* Стан: Проблема з інтернетом користувача */
.status-banner.offline {
  background: rgba(0, 150, 255, 0.15);
  border: 1px solid rgba(0, 150, 255, 0.4);
  color: #64b5f6;
}
.status-banner.offline .status-dot {
  background-color: #2196f3;
  box-shadow: 0 0 8px #2196f3;
}

.btn-attach {
  flex-shrink: 0;
  border: 1px solid rgba(157, 78, 221, 0.4);
  border-radius: 12px;
  padding: 0 14px;
  color: #e0aaff;
  background: rgba(123, 44, 191, 0.15);
  cursor: pointer;
  font-size: 20px;
}

.btn-attach:hover {
  background: rgba(123, 44, 191, 0.3);
}

.file-preview {
  display: flex;
  align-items: center;
  align-self: flex-start;
  gap: 10px;
  max-width: calc(100% - 40px);
  margin: 12px 20px 8px;
  padding: 6px 8px 6px 6px;
  border: 1px solid rgba(157, 78, 221, 0.3);
  border-radius: 12px;
  background: rgba(157, 78, 221, 0.08);
  color: #e0aaff;
  overflow-wrap: anywhere;
}

.file-preview.hidden {
  display: none;
}

.file-preview img {
  display: block;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 8px;
  object-fit: cover;
}

.file-preview span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  color: #fff;
  background: rgba(8, 6, 13, 0.6);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

.file-preview button:hover {
  background: rgba(255, 77, 77, 0.75);
}

/* R3Dark — animated waiting indicator */

.waiting-message {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 190px;
  padding: 18px 22px !important;
}

.waiting-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.waiting-waves {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 25px;
}

.waiting-waves span {
  display: block;
  width: 4px;
  height: 8px;
  border-radius: 8px;
  background: #c77dff;
  box-shadow: 0 0 8px #9d4edd;
  animation: r3-wave 1s ease-in-out infinite;
}

.waiting-waves span:nth-child(2) {
  animation-delay: 0.1s;
}

.waiting-waves span:nth-child(3) {
  animation-delay: 0.2s;
}

.waiting-waves span:nth-child(4) {
  animation-delay: 0.3s;
}

.waiting-waves span:nth-child(5) {
  animation-delay: 0.4s;
}

@keyframes r3-wave {
  0%, 100% {
    height: 7px;
    opacity: 0.5;
  }

  50% {
    height: 23px;
    opacity: 1;
  }
}

/* Анімація пошуку в інтернеті: «радар» із орбітами */

.waiting-message.searching {
  border-color: rgba(199, 125, 255, 0.28);
  box-shadow: 0 0 22px rgba(157, 78, 221, 0.12);
}

.search-orb {
  position: relative;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
}

.search-orb::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(199, 125, 255, 0.55);
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(199, 125, 255, 0.35), transparent 55%),
    radial-gradient(circle at 50% 50%, rgba(24, 12, 38, 0.95), rgba(10, 6, 18, 0.95));
  box-shadow:
    0 0 14px rgba(157, 78, 221, 0.45),
    inset 0 0 10px rgba(199, 125, 255, 0.2);
}

.search-sweep {
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg 250deg,
    rgba(224, 170, 255, 0.8) 330deg,
    transparent 360deg
  );
  -webkit-mask: radial-gradient(circle, transparent 57%, #000 58%);
  mask: radial-gradient(circle, transparent 57%, #000 58%);
  animation: search-sweep 1.8s linear infinite;
}

.search-core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: #e0aaff;
  box-shadow: 0 0 8px #c77dff;
  animation: search-core-pulse 1.4s ease-in-out infinite;
}

.search-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #e0aaff;
  box-shadow: 0 0 6px #c77dff;
  animation: search-orbit 2.4s linear infinite;
}

.search-dot.dot-b {
  animation-delay: -0.8s;
}

.search-dot.dot-c {
  animation-delay: -1.6s;
  opacity: 0.7;
}

@keyframes search-sweep {
  to {
    transform: rotate(360deg);
  }
}

@keyframes search-core-pulse {
  0%, 100% {
    transform: scale(0.8);
    opacity: 0.7;
  }

  50% {
    transform: scale(1.25);
    opacity: 1;
  }
}

@keyframes search-orbit {
  from {
    transform: rotate(0deg) translateX(13px) rotate(0deg);
  }

  to {
    transform: rotate(360deg) translateX(13px) rotate(-360deg);
  }
}

.waiting-label {
  color: #e0aaff;
  font-size: 14px;
  letter-spacing: 0.3px;
}

.waiting-time {
  color: #9d8ba9;
  font-size: 11px;
  margin-left: 29px;
  opacity: 0.8;
}

@media (prefers-reduced-motion: reduce) {
  .waiting-waves span {
    animation: none;
    height: 10px;
  }

  .search-sweep,
  .search-core,
  .search-dot {
    animation: none;
  }

  .search-sweep {
    opacity: 0.35;
  }
}

/* R3Dark — typing cursor */

.msg.ai.typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 3px;
  color: #c77dff;
  animation: typing-cursor 0.8s steps(2, start) infinite;
}

@keyframes typing-cursor {
  to {
    visibility: hidden;
  }
}

/* R3Dark — markdown у відповідях */

.msg.ai p {
  margin: 0 0 10px;
}

.msg.ai p:last-child {
  margin-bottom: 0;
}

.msg.ai ul,
.msg.ai ol {
  margin: 8px 0 10px 22px;
}

.msg.ai li {
  margin-bottom: 4px;
}

.msg.ai strong {
  color: #f6e9ff;
  font-weight: 700;
}

.msg.ai em {
  color: #e6d6ff;
  font-style: italic;
}

.msg.ai del {
  opacity: 0.65;
}

.msg.ai hr {
  height: 1px;
  margin: 16px 0;
  border: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(199, 125, 255, 0.55),
    transparent
  );
}

.msg.ai a {
  color: #c77dff;
  text-decoration: none;
  border-bottom: 1px solid rgba(199, 125, 255, 0.4);
}

.msg.ai a:hover {
  color: #fff;
  border-bottom-color: #fff;
}

.msg.ai code {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.88em;
  background: rgba(157, 78, 221, 0.16);
  border: 1px solid rgba(157, 78, 221, 0.28);
  border-radius: 6px;
  padding: 1px 5px;
}

.msg.ai pre {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(157, 78, 221, 0.25);
  background: rgba(0, 0, 0, 0.45);
  overflow-x: auto;
}

.msg.ai pre code {
  background: none;
  border: 0;
  padding: 0;
}

.msg.ai blockquote {
  margin: 10px 0;
  padding: 6px 14px;
  border-left: 3px solid rgba(199, 125, 255, 0.5);
  color: #cfc4dd;
  background: rgba(157, 78, 221, 0.08);
  border-radius: 0 10px 10px 0;
}

.msg.ai h1,
.msg.ai h2,
.msg.ai h3,
.msg.ai h4 {
  font-family: var(--font-heading);
  color: #f3e9ff;
  letter-spacing: 0.5px;
  margin: 12px 0 8px;
  line-height: 1.3;
}

.msg.ai h1 { font-size: 1.25rem; }
.msg.ai h2 { font-size: 1.15rem; }
.msg.ai h3 { font-size: 1.05rem; }

/* R3Dark — формули KaTeX */

.katex {
  font-size: 1.05em;
}

.katex-display {
  margin: 12px 0;
  padding: 4px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.math-fallback {
  font-family: "Consolas", "Courier New", monospace;
  color: #e0aaff;
  white-space: pre-wrap;
}

/* R3Dark — картка Даші */

.dasha-card {
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(199, 125, 255, 0.45);
  background:
    radial-gradient(circle at 100% 0%, rgba(199, 125, 255, 0.18), transparent 55%),
    linear-gradient(145deg, rgba(157, 78, 221, 0.16), rgba(18, 14, 28, 0.9));
  box-shadow:
    0 0 26px rgba(157, 78, 221, 0.22),
    inset 0 0 24px rgba(157, 78, 221, 0.06);
  max-width: 380px;
}

.dasha-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(199, 125, 255, 0.22);
}

.dasha-card-star {
  font-size: 1.4rem;
  color: #e0aaff;
  text-shadow: 0 0 12px #9d4edd;
}

.dasha-card-name {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  letter-spacing: 1px;
  color: #fff;
}

.dasha-card-role {
  font-size: 0.72rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #a099b2;
}

.dasha-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 4px 0;
  font-size: 0.85rem;
}

.dasha-card-label {
  flex-shrink: 0;
  font-size: 0.7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #a099b2;
}

.dasha-card-link {
  color: #e0aaff;
  text-decoration: none;
  border-bottom: 1px solid rgba(199, 125, 255, 0.4);
}

.dasha-card-link:hover {
  color: #fff;
  border-bottom-color: #fff;
}

.dasha-card-note {
  color: #cfc4dd;
  text-align: right;
}

@media (max-width: 768px) {
  .dasha-card {
    max-width: 100%;
  }

  .dasha-card-row {
    flex-direction: column;
    gap: 2px;
  }

  .dasha-card-note {
    text-align: left;
  }
}

/* R3Dark — керування чатами. Зірка й затемнення шторки — тільки для телефона. */

.btn-mobile-chats,
.chat-backdrop {
  display: none;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Кнопка «⋯» біля назви чату (ноутбук) */

.chat-item-more {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease,
    border-color 0.2s ease;
}

.chat-item:hover .chat-item-more,
.chat-item.active .chat-item-more,
.chat-item-more:focus-visible {
  opacity: 1;
}

.chat-item-more:hover {
  background: rgba(157, 78, 221, 0.25);
  border-color: rgba(157, 78, 221, 0.35);
  color: #fff;
}

/* Закріплене фото над полем введення (ноутбук) */

.chat-pin-bar {
  display: flex;
  position: relative;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 20px 0;
  padding: 8px 12px;
  border: 1px solid rgba(157, 78, 221, 0.28);
  border-radius: 12px;
  background: rgba(157, 78, 221, 0.08);
  color: #cfc4dd;
  font-size: 0.8rem;
  overflow: hidden;
}

.chat-pin-bar.hidden {
  display: none;
}

.chat-pin-bar.has-photo {
  width: fit-content;
  max-width: 100%;
  padding: 6px;
  border-color: rgba(199, 125, 255, 0.4);
  box-shadow: 0 0 18px rgba(157, 78, 221, 0.22);
}

.chat-pin-bar img {
  display: block;
  width: auto;
  height: 72px;
  max-width: 168px;
  border-radius: 8px;
  object-fit: cover;
}

.chat-pin-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.5px;
}

.chat-pin-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(8, 6, 13, 0.72);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease;
}

.chat-pin-remove:hover {
  background: rgba(255, 77, 77, 0.75);
}

/* Меню дій із чатом (ноутбук — картка по центру) */

.chat-actions {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.chat-actions-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.chat-actions-sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 380px;
  padding: 16px;
  border: 1px solid rgba(157, 78, 221, 0.3);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(28, 20, 42, 0.99), rgba(12, 9, 19, 0.99));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.chat-actions-title {
  padding: 0 4px 6px;
  color: #e0aaff;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  letter-spacing: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-action {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-action:hover {
  background: rgba(157, 78, 221, 0.2);
  border-color: rgba(157, 78, 221, 0.35);
}

.chat-action.danger {
  color: #ff8f9f;
  border-color: rgba(255, 77, 77, 0.28);
  background: rgba(255, 77, 77, 0.08);
}

.chat-action.danger:hover {
  background: rgba(255, 77, 77, 0.16);
}

.chat-action.cancel {
  margin-top: 2px;
  color: var(--text-muted);
  text-align: center;
  background: none;
}

@media (max-width: 768px) {
  body.mobile-chats-open {
    overflow: hidden;
  }

  header {
    padding: 0 10px;
    gap: 8px;
  }

  .btn-mobile-chats {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(199, 125, 255, 0.45);
    background: rgba(157, 78, 221, 0.16);
    color: #e0aaff;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 0 16px rgba(157, 78, 221, 0.3);
    transition: transform 0.3s ease, background 0.3s ease;
  }

  .btn-mobile-chats:active {
    transform: scale(0.92);
    background: rgba(157, 78, 221, 0.35);
  }

  .logo {
    font-size: 0.92rem;
    letter-spacing: 0.5px;
    white-space: nowrap;
  }

  nav button {
    padding: 6px 8px;
    font-size: 0.68rem;
    letter-spacing: 0.5px;
  }

  #tab-chat {
    padding-top: 70px;
  }

  .chat-container {
    position: relative;
    height: calc(100vh - 70px);
    padding: 0 8px 10px;
    gap: 0;
  }

  .chat-backdrop {
    display: block;
    position: fixed;
    inset: 70px 0 0 0;
    z-index: 140;
    background: rgba(3, 2, 7, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
  }

  body.mobile-chats-open .chat-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-sidebar {
    position: fixed;
    top: 70px;
    bottom: 0;
    left: 0;
    width: 70vw;
    height: auto;
    max-height: none;
    padding: 16px 12px calc(18px + env(safe-area-inset-bottom));
    gap: 12px;
    order: initial;
    z-index: 150;
    border-radius: 0 20px 20px 0;
    border-left: 0;
    background: rgba(14, 10, 22, 0.98);
    box-shadow: 24px 0 60px rgba(0, 0, 0, 0.6);
    transform: translateX(-105%);
    transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
  }

  body.mobile-chats-open .chat-sidebar {
    transform: translateX(0);
  }

  .chat-main {
    width: 100%;
    flex: 1;
    order: initial;
    transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
  }

  body.mobile-chats-open .chat-main {
    transform: translateX(70vw);
  }

  .chat-item {
    padding: 10px 10px 10px 14px;
  }

  .chat-item-more {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 9px;
    border: 1px solid rgba(157, 78, 221, 0.25);
    background: rgba(157, 78, 221, 0.12);
    color: #e0aaff;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    opacity: 1;
  }

  .chat-item-more:active {
    background: rgba(157, 78, 221, 0.35);
  }

  /* Закріплене фото над полем введення */

  .chat-pin-bar {
    display: flex;
    position: relative;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 10px 8px;
    padding: 8px 12px;
    border: 1px solid rgba(157, 78, 221, 0.28);
    border-radius: 12px;
    background: rgba(157, 78, 221, 0.08);
    color: #cfc4dd;
    font-size: 0.8rem;
    overflow: hidden;
  }

  .chat-pin-bar.hidden {
    display: none;
  }

  .chat-pin-bar.has-photo {
    width: fit-content;
    max-width: 100%;
    padding: 6px;
    border-color: rgba(199, 125, 255, 0.4);
    box-shadow: 0 0 18px rgba(157, 78, 221, 0.22);
  }

  .chat-pin-bar img {
    display: block;
    width: auto;
    height: 60px;
    max-width: 140px;
    border-radius: 8px;
    object-fit: cover;
  }

  .chat-pin-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.5px;
  }

  .chat-pin-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(8, 6, 13, 0.72);
    color: #fff;
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
  }

  .file-preview {
    margin: 8px 10px 8px;
    max-width: calc(100% - 20px);
  }

  .file-preview img {
    width: 46px;
    height: 46px;
  }

  .msg-photo {
    max-width: 150px;
    max-height: 130px;
  }

  /* Нижнє меню дій із чатом */

  .chat-actions {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    align-items: flex-end;
    padding: 0;
  }

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

  .chat-actions-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
  }

  .chat-actions-sheet {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    border: 1px solid rgba(157, 78, 221, 0.3);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
    background: linear-gradient(180deg, rgba(28, 20, 42, 0.99), rgba(12, 9, 19, 0.99));
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
    animation: sheetUp 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .chat-actions-title {
    padding: 0 4px 6px;
    color: #e0aaff;
    font-family: var(--font-heading);
    font-size: 0.95rem;
    letter-spacing: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-action {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.95rem;
    text-align: left;
    cursor: pointer;
  }

  .chat-action:active {
    background: rgba(157, 78, 221, 0.25);
  }

  .chat-action.danger {
    color: #ff8f9f;
    border-color: rgba(255, 77, 77, 0.28);
    background: rgba(255, 77, 77, 0.08);
  }

  .chat-action.cancel {
    margin-top: 2px;
    color: var(--text-muted);
    text-align: center;
    background: none;
  }

  @keyframes sheetUp {
    from {
      opacity: 0.3;
      transform: translateY(36px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .status-banner {
    top: 78px;
  }

  @media (max-width: 360px) {
    .logo {
      font-size: 0.78rem;
      letter-spacing: 0;
    }

    nav button {
      padding: 5px 6px;
      font-size: 0.62rem;
    }
  }
}

/* R3Dark — джерела під відповіддю, згорнуті під стрілочку */

.sources-block {
  margin-top: 12px;
  padding-top: 9px;
  border-top: 1px solid rgba(199, 125, 255, 0.18);
}

.sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 9px;
  border: 1px solid rgba(199, 125, 255, 0.22);
  border-radius: 999px;
  color: #e0aaff;
  background: rgba(157, 78, 221, 0.08);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  line-height: 1;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.sources-toggle::-webkit-details-marker {
  display: none;
}

.sources-toggle::marker {
  content: "";
}

.sources-toggle:hover {
  background: rgba(157, 78, 221, 0.16);
  border-color: rgba(199, 125, 255, 0.4);
}

.sources-title {
  white-space: nowrap;
}

.sources-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  color: #f3e8ff;
  background: rgba(199, 125, 255, 0.2);
  font-size: 0.68rem;
  font-weight: 700;
}

.sources-arrow {
  width: 7px;
  height: 7px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 0.25s ease;
}

.sources-block[open] .sources-arrow {
  transform: rotate(225deg) translate(-1px, -1px);
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  animation: sources-reveal 0.22s ease;
}

.sources-list li {
  position: relative;
  padding-left: 17px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.sources-list li::before {
  content: "↗";
  position: absolute;
  left: 0;
  top: 0;
  color: #9d4edd;
  font-size: 0.78rem;
}

.sources-list a {
  color: #c77dff;
  text-decoration: none;
  border-bottom: 1px solid rgba(199, 125, 255, 0.28);
  word-break: break-word;
}

.sources-list a:hover {
  color: #e0aaff;
  border-bottom-color: #e0aaff;
}

@keyframes sources-reveal {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sources-list {
    animation: none;
  }

  .sources-arrow {
    transition: none;
  }
}
