/* ── Messages ──────────────────────────────────────────────────────────────── */

.msg-layout {
  padding-top: var(--sp-7);
  padding-bottom: var(--sp-10);
  max-width: 720px;
}

/* Inbox header */
.msg-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}
.msg-header .serif {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  margin: 0;
}

/* Empty state */
.msg-empty {
  padding: var(--sp-8) 0;
  color: var(--muted);
}
.msg-empty p { margin: 0 0 var(--sp-2); }
.msg-empty a { color: var(--accent); }

/* ── Thread list (inbox) ─────────────────────────────────────────────────── */

.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.thread-item {
  border-bottom: 1px solid var(--border);
}
.thread-item:last-child { border-bottom: none; }
.thread-item--unread { background: var(--surface-alt, oklch(98% .005 60)); }

[data-theme="dark"] .thread-item--unread {
  background: oklch(20% .01 60);
}

.thread-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  text-decoration: none;
  color: inherit;
  transition: background var(--transition);
}
.thread-link:hover { background: var(--hover-bg, oklch(97% .005 60)); }

[data-theme="dark"] .thread-link:hover { background: oklch(18% .01 60); }

.thread-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  font-weight: 600;
  flex-shrink: 0;
}

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

.thread-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-2);
  margin-bottom: 2px;
}

.thread-name {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item--unread .thread-name { color: var(--ink); }

.thread-time {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.thread-preview {
  font-size: .83rem;
  color: var(--muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item--unread .thread-preview { color: var(--text); }

.thread-you {
  color: var(--muted);
  font-weight: 500;
  margin-right: 4px;
}

.thread-badge {
  background: var(--accent);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  flex-shrink: 0;
}

.thread-role {
  font-size: .75rem;
  color: var(--muted);
  margin-left: 6px;
}

/* ── Thread view ──────────────────────────────────────────────────────────── */

.msg-thread-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  transition: color var(--transition);
}
.back-link:hover { color: var(--ink); }

.thread-with {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: 1;
}

.msg-thread {
  min-height: 240px;
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-4);
  scroll-behavior: smooth;
}

.msg-empty-thread {
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
  padding: var(--sp-6) 0;
}

.msg-bubble {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}
.msg-bubble--mine  { align-self: flex-end;  align-items: flex-end; }
.msg-bubble--theirs{ align-self: flex-start; align-items: flex-start; }

.msg-text {
  padding: var(--sp-3) var(--sp-4);
  border-radius: 18px;
  font-size: .88rem;
  line-height: 1.55;
  word-break: break-word;
}

.msg-bubble--mine   .msg-text {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-bubble--theirs .msg-text {
  background: var(--card, oklch(97% .005 60));
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
[data-theme="dark"] .msg-bubble--theirs .msg-text {
  background: oklch(22% .01 60);
}

.msg-ts {
  font-size: .7rem;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Reply form */
.msg-reply {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.msg-input {
  resize: vertical;
  min-height: 80px;
  font-size: .9rem;
}

.msg-reply-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.msg-char-count {
  font-size: .75rem;
  color: var(--muted);
}

/* ── Compose ──────────────────────────────────────────────────────────────── */

.msg-compose-card {
  background: var(--card, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--sp-6);
}

.msg-to {
  margin: 0 0 var(--sp-4);
  font-size: .9rem;
  color: var(--muted);
}
.msg-to strong { color: var(--ink); }

/* ── Favorites ────────────────────────────────────────────────────────────── */

.fav-item { position: relative; }

.fav-remove-btn {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  z-index: 2;
}
.fav-remove-btn:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

/* ── Nav unread badge ─────────────────────────────────────────────────────── */

.nav-msg-link {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.nav-unread-badge {
  position: absolute;
  top: -4px;
  right: -8px;
  background: var(--accent);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
}
