/* ─── Layout ─── */
.msg-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.msg-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ─── Chat back button (mobile only) ─── */
.chat-back-btn {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color .2s;
}
.chat-back-btn:hover { border-color: var(--accent); }
@media (max-width: 640px) {
  .chat-back-btn { display: flex; }
}

/* ─── Back button ─── */
.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 18px;
  transition: all .2s;
}
.back-btn:hover { color: var(--text); border-color: var(--accent); }

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

/* ─── Conversations panel ─── */
.conv-panel {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conv-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}

.new-chat-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.new-chat-btn:hover { background: var(--accent); border-color: var(--accent); }

.conv-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.conv-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 7px 14px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}
.conv-search input:focus { border-color: var(--accent); }
.conv-search input::placeholder { color: var(--text-muted); }

.conv-list {
  flex: 1;
  overflow-y: auto;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  position: relative;
}
.conv-item:hover { background: var(--surface2); }
.conv-item.active { background: var(--accent-glow); border-right: 2px solid var(--accent); }

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.conv-time {
  font-size: 11px;
  color: var(--text-muted);
}
.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 50px;
  min-width: 20px;
  text-align: center;
}

.conv-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ─── Chat area ─── */
.chat-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
  gap: 8px;
}
.chat-empty-icon { font-size: 56px; opacity: .4; }

/* shared chat view inner (user + admin) */
.chat-view-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background-size: cover;
  background-position: center;
}
.chat-header-info { flex: 1; }
.chat-header-name { font-size: 15px; font-weight: 600; }
.chat-header-sub  { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

/* ─── Messages list ─── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-date-sep {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin: 10px 0 4px;
  position: relative;
}
.msg-date-sep::before, .msg-date-sep::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}
.msg-date-sep::before { left: 0; }
.msg-date-sep::after  { right: 0; }

.msg-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.msg-bubble-wrap.mine { flex-direction: row-reverse; }

.msg-bubble-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.msg-content {
  max-width: 65%;
  display: flex;
  flex-direction: column;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.msg-bubble-wrap.mine .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-bubble-wrap.theirs .msg-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}
.msg-bubble-wrap.theirs .msg-time { text-align: left; }
.msg-bubble-wrap.mine .msg-content { align-items: flex-end; }

/* ─── Compose ─── */
.chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-compose textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color .2s;
}
.chat-compose textarea:focus { border-color: var(--accent); }
.chat-compose textarea::placeholder { color: var(--text-muted); }

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  transition: background .2s, transform .1s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.92); }

/* ─── User picker ─── */
.picker-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s;
}
.picker-user:hover { background: var(--surface2); }
.picker-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.picker-info { flex: 1; }
.picker-name { font-size: 14px; font-weight: 600; }
.picker-sub  { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Responsive ─── */
@media (max-width: 640px) {
  /* Панель і чат займають весь екран по черзі */
  .conv-panel {
    width: 100%;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .chat-area {
    width: 100%;
    flex-shrink: 0;
  }
  .msg-layout {
    flex-direction: column;
  }

  /* Коли чат відкрито — ховаємо панель */
  .msg-layout.chat-open .conv-panel { display: none; }
  .msg-layout.chat-open .chat-area  { flex: 1; min-height: 0; }

  /* Коли чат закрито — ховаємо chat-area */
  .msg-layout:not(.chat-open) .chat-area { display: none; }
  .msg-layout:not(.chat-open) .conv-panel { flex: 1; min-height: 0; }

  .msg-bubble { max-width: 85%; }
}

/* ─── Delete buttons ─── */
.conv-delete-btn {
  display: none;
  align-items: center;
  gap: 4px;
  background: rgba(224, 82, 82, 0.15);
  border: 1px solid rgba(224, 82, 82, 0.3);
  color: #e05252;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.conv-delete-btn:hover {
  background: rgba(224, 82, 82, 0.3);
  border-color: rgba(224, 82, 82, 0.6);
}
/* Desktop: show on hover */
@media (hover: hover) {
  .conv-item:hover .conv-delete-btn { display: inline-flex; }
}
/* Touch / mobile: always visible, icon only */
@media (hover: none) {
  .conv-delete-btn {
    display: inline-flex;
    padding: 5px 7px;
    font-size: 0;
  }
  .conv-delete-btn::before {
    content: '🗑';
    font-size: 15px;
  }
}

.conv-delete-all-btn {
  background: none;
  border: 1px solid rgba(224, 82, 82, 0.3);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #e05252;
  padding: 4px 10px;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
}
.conv-delete-all-btn:hover {
  background: rgba(224, 82, 82, 0.15);
  border-color: rgba(224, 82, 82, 0.5);
}

/* ─── Confirm modal ─── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.confirm-overlay.hidden { display: none; }

.confirm-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px 24px;
  max-width: 320px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.confirm-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.confirm-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.confirm-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
  min-height: 0;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-btn-cancel {
  flex: 1;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.confirm-btn-cancel:hover { background: var(--border); }

.confirm-btn-ok {
  flex: 1;
  padding: 11px;
  border-radius: 12px;
  border: none;
  background: #e05252;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.confirm-btn-ok:hover { background: #c93e3e; }
