/* ── Messaging ────────────────────────────────────────────────────────────── */
.msg-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  height: calc(100vh - 120px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.msg-threads {
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.msg-threads-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-size: 17px; font-weight: 700;
}
#threadItems { flex: 1; overflow-y: auto; }
.thread-item {
  display: flex; flex-direction: column; gap: 3px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background .15s;
}
.thread-item:hover { background: var(--bg-alt); }
.thread-item.active { background: #e3f0fb; }
.thread-item.active .thread-label { color: #1565c0; }
.thread-item-top { display: flex; align-items: center; gap: 6px; }
.thread-label { font-size: 14px; font-weight: 600; flex: 1; }
.thread-customer { font-size: 12px; color: var(--text-muted); }
.thread-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-unread { color: var(--orange); }
.thread-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--orange); color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 700; padding: 1px 7px; flex-shrink: 0;
}

.msg-chat { display: flex; flex-direction: column; overflow: hidden; }
.msg-chat-header { padding: 14px 20px; border-bottom: 1px solid var(--border); font-weight: 600; }
.msg-messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 4px;
  background: #fff;
}
/* ── Message bubbles ─────────────────────────────────────────────────────── */
.msg-row { display: flex; flex-direction: column; max-width: 72%; margin-bottom: 6px; }
.msg-row--mine   { align-self: flex-end;  align-items: flex-end; }
.msg-row--theirs { align-self: flex-start; align-items: flex-start; }
.msg-bubble {
  padding: 9px 13px; border-radius: 18px; font-size: 14px; line-height: 1.5;
  word-break: break-word;
}
.msg-bubble--mine   { background: var(--orange); color: #fff; border-bottom-right-radius: 4px; }
.msg-bubble--theirs { background: #fff; border: 1px solid #e0e0e0; color: var(--text); border-bottom-left-radius: 4px; }
.msg-bubble-meta {
  font-size: 11px; color: var(--text-light); margin-top: 3px; padding: 0 4px;
}
.msg-input-bar { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg); }
.msg-input-bar textarea { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: inherit; resize: none; outline: none; }
.msg-input-bar textarea:focus { border-color: var(--orange); }

/* ── Ask seller button (product page) ────────────────────────────────────── */
.ask-seller-btn {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  font-size: 14px; color: var(--text-muted); cursor: pointer;
  background: none; border: 1px solid var(--border); border-radius: 24px;
  padding: 7px 16px; transition: all .15s;
}
.ask-seller-btn:hover { color: var(--orange); border-color: var(--orange); }

/* ── Message modal ────────────────────────────────────────────────────────── */
.msg-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 600;
}
.msg-modal {
  background: var(--bg); border-radius: var(--radius-lg); padding: 0;
  width: 100%; max-width: 520px; max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(0,0,0,.2);
  overflow: hidden;
}
.msg-modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 700; display: flex; justify-content: space-between; }
.msg-modal-close { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }
.msg-modal-messages { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; background: #fff; min-height: 200px; }
.msg-modal-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.msg-modal-input textarea { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: inherit; resize: none; outline: none; }
.msg-modal-input textarea:focus { border-color: var(--orange); }

@media (max-width: 768px) {
  .msg-layout { grid-template-columns: 1fr; height: auto; }
  .msg-threads { height: 240px; }
  .msg-chat { height: calc(100vh - 400px); }
}
