.messages { display: grid; grid-template-columns: minmax(280px, 38%) 1fr; gap: 16px; align-items: start;
    height: calc(100vh - 160px); }
.messages-list-pane { display: flex; flex-direction: column; gap: 10px; min-height: 0; height: 100%; }
.messages-toolbar { display: flex; gap: 8px; align-items: center; }
.messages-search { flex: 1; padding: 10px 12px; border: 1px solid var(--sb-border); border-radius: 10px;
    background: var(--sb-surface); font-size: 14px; color: var(--sb-ink); font-family: inherit; }
/* Primary action buttons reuse the app-standard .btn-gold (see site.css); override its
   default full width for these inline actions (New / Send / Reply). */
.messages .btn-gold { width: auto; padding: 0 18px; }
.messages-results { overflow-y: auto; min-height: 0; flex: 1; }
.messages-thread-pane { background: var(--sb-surface); border: 1px solid var(--sb-border); border-radius: var(--sb-radius);
    box-shadow: 0 8px 24px rgba(52,37,27,.06); height: 100%; display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.messages-thread-empty { margin: auto; color: var(--sb-taupe); font-family: var(--sb-serif); font-size: 18px; }

/* Compose */
.messages-compose { display: flex; flex-direction: column; gap: 10px; align-items: flex-start;
    background: var(--sb-surface); border: 1px solid var(--sb-border); border-radius: var(--sb-radius);
    padding: 16px 18px; box-shadow: 0 8px 24px rgba(52,37,27,.06); }
.messages-input { width: 100%; padding: 12px 14px; border: 1px solid var(--sb-border); border-radius: 12px;
    background: var(--sb-surface-2); font-size: 15px; color: var(--sb-ink); font-family: inherit; resize: vertical; }
.messages-context-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px;
    background: var(--sb-surface-2); border: 1px solid var(--sb-border); font-size: 12.5px; color: var(--sb-taupe); }
.messages-context-thumb { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #fff; flex-shrink: 0; }
.thread-context-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #fff; flex-shrink: 0; }

/* List */
.messages-empty { color: var(--sb-taupe); font-family: var(--sb-serif); font-size: 20px; padding: 24px 0; }
.messages-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.msg-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; cursor: pointer;
    padding: 14px 16px; background: var(--sb-surface); border: 1px solid var(--sb-border); border-radius: var(--sb-radius);
    box-shadow: 0 8px 24px rgba(52,37,27,.06); }
.msg-card.unread { border-left: 3px solid var(--sb-gold); }
.msg-card-status { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; color: var(--sb-taupe);
    background: var(--sb-surface-2); border-radius: 999px; padding: 3px 10px; }
.msg-card-ctx { font-size: 12.5px; color: var(--sb-taupe); }
.msg-card-preview { font-family: var(--sb-serif); font-size: 16px; color: var(--sb-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-card.unread .msg-card-preview { font-weight: 600; }
.msg-card-time { font-size: 12px; color: var(--sb-taupe); white-space: nowrap; }
.msg-sentinel { text-align: center; color: var(--sb-taupe); padding: 16px; font-size: 13px; list-style: none; }

/* Thread pane */
.thread-dialog { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 12px; padding: 18px 20px; }
.thread-head { display: flex; align-items: center; gap: 12px; }
.thread-title { font-family: var(--sb-serif); font-size: 22px; color: var(--sb-ink); flex: 1; }
.thread-status { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; color: var(--sb-taupe);
    background: var(--sb-surface-2); border-radius: 999px; padding: 3px 10px; }
/* Back-to-list button: hidden in the two-pane view (the list is always visible there),
   shown only in the single-column layout where the conversation replaces the list. */
.thread-back { display: none; align-items: center; gap: 6px; border: 1px solid var(--sb-border);
    background: var(--sb-surface-2); color: var(--sb-gold-deep); font-weight: 600; font-size: 14px;
    padding: 8px 15px; border-radius: 999px; cursor: pointer; min-height: 40px; font-family: inherit; }
.thread-bubbles { flex: 1; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.thread-bubble { max-width: 78%; padding: 10px 14px; border-radius: 16px; }
.thread-bubble.left { align-self: flex-start; background: var(--sb-surface); border: 1px solid var(--sb-border); color: var(--sb-ink); }
.thread-bubble.right { align-self: flex-end; background: #f6ecd4; border: 1px solid #e6d3a6; color: var(--sb-ink); }
.thread-bubble-who { display: block; font-size: 10px; font-weight: 600; letter-spacing: .02em; margin-bottom: 3px; }
.thread-bubble.left .thread-bubble-who { color: var(--sb-gold-deep); }
.thread-bubble.right .thread-bubble-who { color: #8a6d34; }
.thread-bubble-body { font-size: 15px; }
.thread-bubble-body p { margin: 0 0 6px; }
.thread-bubble-body p:last-child { margin-bottom: 0; }
.thread-bubble-body ul, .thread-bubble-body ol { margin: 4px 0; padding-left: 20px; }
.thread-bubble-body a { color: var(--sb-gold-deep); text-decoration: underline; }
.thread-bubble-time { display: block; margin-top: 4px; font-size: 11px; opacity: .7; }
.thread-reply { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }

@media (max-width: 900px) {
    .messages { grid-template-columns: 1fr; height: auto; }
    .messages-thread-pane { min-height: 60vh; }
    .messages .messages-thread-pane { display: none; }
    .messages.show-thread .messages-list-pane { display: none; }
    .messages.show-thread .messages-thread-pane { display: flex; }
    .thread-back { display: inline-flex; }
}

.msg-format { display: flex; gap: 6px; margin-bottom: 8px; }
.msg-format-btn { width: 34px; height: 34px; border: 1px solid var(--sb-border); border-radius: 8px;
    background: var(--sb-surface); color: var(--sb-ink); cursor: pointer; font-size: 14px; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center; }
.msg-format-btn:hover { border-color: var(--sb-gold); }

.msg-editor-root { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.msg-editor { min-height: 72px; width: 100%; padding: 12px 14px; border: 1px solid var(--sb-border); border-radius: 12px;
    background: var(--sb-surface-2); font-size: 15px; color: var(--sb-ink); font-family: inherit; overflow-y: auto; }
.msg-editor:focus { outline: 2px solid var(--sb-gold); outline-offset: -1px; }
.msg-editor:empty:before { content: attr(data-placeholder); color: var(--sb-taupe); }
.msg-editor p { margin: 0 0 6px; }
.msg-editor ul, .msg-editor ol { margin: 4px 0; padding-left: 20px; }
.msg-editor a { color: var(--sb-gold-deep); text-decoration: underline; }
