html, body { height: 100%; }

.msg-page {
  display: flex;
  flex: 1;
  min-height: 0;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  border-left: 1px solid var(--beige-dark);
  border-right: 1px solid var(--beige-dark);
  background: white;
}

/* ── CONVERSATION LIST ── */
.conv-list {
  width: 340px;
  flex-shrink: 0;
  border-right: 1px solid var(--beige-dark);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.conv-list-header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--beige-dark);
}
.conv-list-header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: var(--brown);
}
.conv-items {
  flex: 1;
  overflow-y: auto;
}
.conv-item {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  border-bottom: 1px solid var(--beige-dark);
  transition: background 0.15s;
  position: relative;
}
.conv-item:hover { background: var(--beige); }
.conv-item.active { background: rgba(197,151,58,0.14); }
.conv-avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--white); font-weight: 800; font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
}
.conv-info { flex: 1; min-width: 0; }
.conv-top-row { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.conv-name { font-weight: 700; font-size: 0.9rem; color: var(--brown); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 0.7rem; color: var(--muted); flex-shrink: 0; }
.conv-article { font-size: 0.75rem; color: var(--gold); margin-bottom: 0.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item.unread .conv-preview { color: var(--text); font-weight: 600; }
.conv-unread-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--gold);
  flex-shrink: 0; margin-left: 0.4rem;
}
.conv-empty, .loading-msg {
  padding: 3rem 1.5rem; text-align: center; color: var(--muted); font-size: 0.9rem;
}
.conv-empty .back-link { display: inline-block; margin-top: 0.75rem; color: var(--gold); font-weight: 600; text-decoration: none; }

/* ── THREAD VIEW ── */
.thread-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--white);
}
.thread-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  padding: 2rem;
}
.thread-placeholder .placeholder-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.6; }

.thread-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.thread-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--beige-dark);
  background: white;
  flex-shrink: 0;
  min-width: 0;
}
.btn-thread-back {
  display: none;
  border: none;
  background: none;
  font-size: 1.2rem;
  color: var(--brown);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  flex-shrink: 0;
}
.thread-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  flex: 1;
}
.thread-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--white); font-weight: 800; font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.thread-user-info { min-width: 0; flex: 1; }
.thread-username {
  font-weight: 700; font-size: 0.92rem; color: var(--brown);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.thread-article {
  font-size: 0.75rem; color: var(--gold);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

.thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.msg-bubble {
  max-width: 68%;
  padding: 0.55rem 0.9rem;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.4;
  word-wrap: break-word;
}
.msg-bubble.received {
  align-self: flex-start;
  background: var(--beige);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg-bubble.sent {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--white);
  border-bottom-right-radius: 4px;
}
.msg-time {
  font-size: 0.68rem;
  color: var(--muted);
  margin: 0.15rem 0.3rem 0.5rem;
  align-self: flex-start;
}
.msg-time.sent { align-self: flex-end; }
.msg-day-sep {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0.75rem 0 0.25rem;
}

.thread-input-row {
  display: flex;
  gap: 0.6rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--beige-dark);
  background: white;
  flex-shrink: 0;
}
.thread-input-row input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--beige-dark);
  background: var(--beige);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.thread-input-row input:focus { border-color: var(--gold); }
.thread-input-row button {
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--white);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.thread-input-row button:disabled { opacity: 0.6; cursor: default; }

/* ── Nav badge ── */
.nav-msg-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #c0392b;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  margin-left: 0.35rem;
}

/* ── RESPONSIVE ── */
@media (max-width: 720px) {
  .msg-page { border: none; }
  .conv-list { width: 100%; border-right: none; }
  .thread-view { display: none; }
  .btn-thread-back { display: inline-block; }

  .msg-page.thread-open .conv-list { display: none; }
  .msg-page.thread-open .thread-view { display: flex; }
}
