/* Mendflow — чаты / мессенджер. Токены (:root, кнопки) остаются в /style.css */

/* ============================================================
   MESSENGER / CHATS — new design
   ============================================================ */

.msg-view {
  display: none !important;
  height: calc(100vh - 80px);
  height: calc(100dvh - 80px);
  max-height: 860px;
  border-radius: 24px;
  overflow: hidden;
  border: 1.5px solid #ece7f4;
  background: #fff;
}

.msg-view.app-view-active {
  display: grid !important;
  grid-template-columns: 300px 1fr;
}

/* ── SIDEBAR ── */
.msg-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1.5px solid #ece7f4;
  background: #fff;
  overflow: hidden;
}

.msg-sidebar-head {
  padding: 24px 20px 12px;
  flex-shrink: 0;
}

.msg-sidebar-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: #16131d;
}

.msg-search-wrap {
  position: relative;
  padding: 0 14px 14px;
  flex-shrink: 0;
}

.msg-search-icon {
  position: absolute;
  left: 26px;
  top: 50%;
  transform: translateY(-60%);
  font-size: 0.85rem;
  pointer-events: none;
}

.msg-search-input {
  width: 100%;
  height: 42px;
  border-radius: 999px;
  border: 1.5px solid #ece7f4;
  background: #f8f6ff;
  padding: 0 16px 0 36px;
  font-size: 0.85rem;
  color: #16131d;
  outline: none;
  transition: border-color 0.15s;
}

.msg-search-input:focus {
  border-color: #7c3aed;
}

.msg-contact-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px 12px;
}

/* Contact row */
.msg-contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  width: 100%;
}

.msg-contact-item:hover {
  background: #f8f6ff;
}

.msg-contact-item.is-active {
  background: #f0ebff;
}

.msg-contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #a78bfa;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  position: relative;
}

.msg-avatar-system { background: #ede9fe; color: #7c3aed; }
.msg-avatar-group  { background: #ede9fe; color: #7c3aed; font-size: 1.1rem; }

.msg-contact-info {
  flex: 1;
  min-width: 0;
}

.msg-contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.msg-contact-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: #16131d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-contact-time {
  font-size: 0.68rem;
  color: #857d93;
  flex-shrink: 0;
  font-weight: 500;
}

.msg-contact-preview {
  margin: 0;
  font-size: 0.78rem;
  color: #857d93;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
}

/* ── THREAD SHELL ── */
.msg-thread-shell {
  display: flex;
  flex-direction: column;
  background: #f8f6ff;
  overflow: hidden;
}

/* Thread header */
.msg-thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1.5px solid #ece7f4;
  flex-shrink: 0;
}

.msg-thread-peer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.msg-peer-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 0.78rem;
  background-size: cover;
  background-position: center;
}

.msg-peer-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-peer-info strong {
  font-size: 0.95rem;
  font-weight: 800;
  color: #16131d;
}

.msg-peer-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: #16a34a;
  white-space: nowrap;
}

.msg-info-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
  color: #857d93;
  border-color: #ece7f4;
}

.msg-info-btn:hover {
  color: #7c3aed;
  border-color: #7c3aed;
  background: #f0ebff;
}

/* Messages area */
.msg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-day-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0 16px;
}

.msg-day-divider span {
  font-size: 0.72rem;
  font-weight: 700;
  color: #857d93;
  background: #f8f6ff;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid #ece7f4;
}

/* Bubble rows */
.msg-bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 6px;
  width: 100%;
}

.msg-row-in {
  justify-content: flex-start;
  flex-direction: row;
}

.msg-row-out {
  justify-content: flex-end;
  flex-direction: row;
}

.msg-bubble-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #a78bfa;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 60%;
}

.msg-wrap-out {
  align-items: flex-end;
}

.msg-row-out .msg-bubble-wrap {
  align-items: flex-end;
}

.msg-bubble {
  padding: 14px 18px;
  border-radius: 20px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
}

.msg-bubble-in {
  background: #fff;
  color: #16131d;
  border-radius: 4px 20px 20px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.msg-bubble-out {
  background: #7c3aed;
  color: #fff;
  border-radius: 20px 20px 4px 20px;
}

.msg-bubble-time {
  font-size: 0.65rem;
  color: #857d93;
  font-weight: 500;
}

.msg-row-out .msg-bubble-time {
  color: #857d93;
}

.msg-loading {
  text-align: center;
  color: #857d93;
  font-size: 0.85rem;
  padding: 24px;
}

/* Input bar */
.msg-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: #fff;
  border-top: 1.5px solid #ece7f4;
  flex-shrink: 0;
}

.msg-attach-btn,
.msg-emoji-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #857d93;
  cursor: pointer;
  background: transparent;
  border: none;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.msg-attach-btn:hover,
.msg-emoji-btn:hover {
  color: #7c3aed;
  background: #f0ebff;
}

.msg-text-input {
  flex: 1;
  height: 48px;
  border-radius: 999px;
  border: 1.5px solid #ece7f4;
  background: #f8f6ff;
  padding: 0 20px;
  font-size: 0.88rem;
  font-family: inherit, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  color: #16131d;
  outline: none;
  transition: border-color 0.15s;
}

.msg-text-input:focus {
  border-color: #7c3aed;
}

.msg-send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #7c3aed;
  color: #fff;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

.msg-send-btn:hover {
  background: #6d28d9;
  transform: scale(1.06);
}

/* Attachment image in bubble */
.msg-bubble .message-attachment-image {
  max-width: 260px;
  border-radius: 12px;
  margin-top: 8px;
  display: block;
}

@media (max-width: 780px) {
  .msg-view.app-view-active {
    grid-template-columns: 1fr;
  }
  .msg-sidebar {
    display: none;
  }
  .msg-bubble-wrap {
    max-width: 80%;
  }
}

/* ── Messenger — complete ── */
[data-theme="dark"] .msg-view {
  background: #1a1625;
  border-color: var(--border);
}

[data-theme="dark"] .msg-sidebar {
  background: #120e1d;
  border-right-color: var(--border);
}

[data-theme="dark"] .msg-sidebar-title {
  color: var(--ink);
}

[data-theme="dark"] .msg-search-input {
  background: #1a1625;
  border-color: var(--border);
  color: var(--ink);
}

[data-theme="dark"] .msg-search-input::placeholder {
  color: var(--ink-muted);
}

[data-theme="dark"] .msg-contact-item:hover {
  background: #231c3a;
}

[data-theme="dark"] .msg-contact-item.is-active {
  background: #2d1f5e;
}

[data-theme="dark"] .msg-contact-name {
  color: var(--ink);
}

[data-theme="dark"] .msg-contact-time,
[data-theme="dark"] .msg-contact-preview {
  color: var(--ink-muted);
}

[data-theme="dark"] .msg-thread-shell {
  background: #0d0a18;
}

[data-theme="dark"] .msg-thread-head {
  background: #1a1625;
  border-bottom-color: var(--border);
}

[data-theme="dark"] .msg-peer-info strong {
  color: var(--ink);
}

[data-theme="dark"] .msg-bubble-in {
  background: #231c3a;
  color: var(--ink);
  box-shadow: none;
}

[data-theme="dark"] .msg-bubble-out {
  background: var(--accent);
  color: #0d0a18;
}

[data-theme="dark"] .msg-day-divider span {
  background: #1a1625;
  border-color: var(--border);
  color: var(--ink-muted);
}

[data-theme="dark"] .msg-input-bar {
  background: #1a1625;
  border-top-color: var(--border);
}

[data-theme="dark"] .msg-text-input {
  background: #120e1d;
  border-color: var(--border);
  color: var(--ink);
}

[data-theme="dark"] .msg-attach-btn,
[data-theme="dark"] .msg-emoji-btn {
  color: var(--ink-muted);
}

[data-theme="dark"] .msg-attach-btn:hover,
[data-theme="dark"] .msg-emoji-btn:hover {
  color: var(--accent);
  background: #2d1f5e;
}

[data-theme="dark"] .chat-no-select {
  background: #0d0a18;
}

/* Позже style.css (≤768px) перекрывал блок мессенджера — оставляем тот же порядок внутри этого файла */
@media (max-width: 768px) {
  .msg-view.app-view-active {
    display: flex !important;
    flex-direction: column;
    min-height: calc(100dvh - 140px);
    grid-template-columns: 1fr !important;
  }

  .msg-sidebar {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border-right: none;
  }

  .msg-thread-shell {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
  }

  .msg-view.has-active-chat .msg-sidebar {
    display: none !important;
  }

  .msg-view.has-active-chat .msg-thread-shell {
    display: flex !important;
  }

  .msg-view.has-active-chat .chat-no-select {
    display: none !important;
  }

  .msg-mobile-back {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0;
    margin-right: 4px;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
  }

  .msg-thread-head {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .msg-thread-peer {
    flex: 1;
    min-width: 0;
  }
}

