/* Three-pane messaging inbox: DIDs · threads · conversation.
 * Used by /office.html (renamed from /ecosystem.html 2026-05-15, which was
 * renamed from /messages.html 2026-05-14). The Office page hosts TWO shells
 * (TEXT + WhatsApp); each is wrapped in a .messaging-section for ID isolation. */

.messaging-page .admin-shell {
  padding: 12px 24px 24px;
}

.brand-inbox-panel {
  margin-top: 18px;
}

.brand-inbox-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
}

.brand-inbox-header h2 {
  margin: 0;
}

.brand-inbox-header p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
}

.messaging-shell {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(260px, 320px) minmax(360px, 1fr) minmax(260px, 320px);
  height: calc(100vh - 160px);
  min-height: 660px;
  overflow: hidden;
}

@media (max-width: 1280px) {
  .messaging-shell {
    grid-template-columns: minmax(220px, 280px) minmax(280px, 360px) 1fr;
  }
  .messaging-drawer {
    display: none;
  }
}

.messaging-shell > section,
.messaging-shell > aside {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  /* min-height: 0 lets the inner *-list elements actually scroll inside this
   * column instead of stretching it to fit content. Without it, the lists'
   * own overflow-y: auto is inert and the whole shell overflows. */
  min-height: 0;
  min-width: 0;
}

.messaging-shell > section:last-child {
  border-right: none;
}

/* Visible scrollbars on every scrollable pane in the shell. Subtle by default,
 * brand-green on hover. Drawn with the brand accent at low opacity so they
 * read as part of the UI, not as a system widget. */
.messaging-did-list,
.messaging-thread-list,
.messaging-message-list,
.messaging-drawer {
  scrollbar-width: thin;
  scrollbar-color: rgba(13, 122, 95, 0.45) transparent;
}

.messaging-did-list::-webkit-scrollbar,
.messaging-thread-list::-webkit-scrollbar,
.messaging-message-list::-webkit-scrollbar,
.messaging-drawer::-webkit-scrollbar {
  width: 8px;
}

.messaging-did-list::-webkit-scrollbar-track,
.messaging-thread-list::-webkit-scrollbar-track,
.messaging-message-list::-webkit-scrollbar-track,
.messaging-drawer::-webkit-scrollbar-track {
  background: transparent;
}

.messaging-did-list::-webkit-scrollbar-thumb,
.messaging-thread-list::-webkit-scrollbar-thumb,
.messaging-message-list::-webkit-scrollbar-thumb,
.messaging-drawer::-webkit-scrollbar-thumb {
  background: rgba(13, 122, 95, 0.35);
  border-radius: 4px;
}

.messaging-did-list::-webkit-scrollbar-thumb:hover,
.messaging-thread-list::-webkit-scrollbar-thumb:hover,
.messaging-message-list::-webkit-scrollbar-thumb:hover,
.messaging-drawer::-webkit-scrollbar-thumb:hover {
  background: rgba(13, 122, 95, 0.6);
}

.messaging-dids-head,
.messaging-threads-head,
.messaging-conversation-head {
  background: #f7fafc;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
}

.messaging-dids-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.messaging-dids-head button {
  font-size: 13px;
  padding: 6px 12px;
}

.messaging-dids-head h2,
.messaging-threads-head h2,
.messaging-conversation-head h2 {
  font-size: 15px;
  margin: 0;
}

.messaging-conversation-head {
  display: grid;
  gap: 2px;
}

.messaging-did-list,
.messaging-thread-list,
.messaging-message-list {
  flex: 1;
  list-style: none;
  margin: 0;
  overflow-y: auto;
  padding: 0;
}

.messaging-did,
.messaging-thread {
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 10px 14px;
}

.messaging-did:hover,
.messaging-thread:hover {
  background: #f3f6fa;
}

.messaging-did.selected,
.messaging-thread.selected {
  background: #e7f0f7;
}

.messaging-did-num {
  color: var(--muted);
  font-size: 13px;
}

.messaging-did-regd {
  background: #fef3c7;
  border-radius: 3px;
  color: #92400e;
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  text-transform: uppercase;
}

.messaging-thread-head {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.messaging-thread-peer {
  font-weight: 700;
}

.messaging-thread-brand {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.messaging-thread-ch {
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  text-transform: uppercase;
}

.messaging-thread-ch.wa {
  background: #d1fae5;
  color: #065f46;
}

.messaging-thread-ch.sms {
  background: #dbeafe;
  color: #1e40af;
}

.messaging-reply-channel {
  align-items: center;
  display: flex;
  gap: 14px;
  font-size: 13px;
  margin-bottom: 6px;
}

.messaging-reply-channel label {
  align-items: center;
  cursor: pointer;
  display: inline-flex;
  font-weight: 600;
  gap: 4px;
}

.messaging-thread-preview {
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messaging-thread-meta {
  color: var(--muted);
  display: flex;
  font-size: 11px;
  gap: 8px;
}

.messaging-message-list {
  background: #f9fafb;
  padding: 16px;
}

.messaging-message {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.messaging-message.messaging-outbound {
  justify-items: end;
}

.messaging-bubble {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 70%;
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.messaging-outbound .messaging-bubble {
  background: #d1fae5;
  border-color: #a7f3d0;
}

.messaging-media {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  max-width: 70%;
}

.messaging-outbound .messaging-media {
  align-self: end;
  align-items: flex-end;
}

.messaging-media-image img {
  border: 1px solid var(--line);
  border-radius: 10px;
  display: block;
  max-height: 240px;
  max-width: 100%;
  object-fit: cover;
}

.messaging-media-video,
.messaging-media-audio {
  border-radius: 8px;
  max-width: 100%;
}

.messaging-media-video {
  background: #000;
}

.messaging-media-link {
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #1e3a8a;
  display: inline-block;
  font-weight: 600;
  padding: 8px 12px;
  text-decoration: none;
}

.messaging-media-link:hover {
  background: #dbe5f1;
}

.messaging-meta {
  color: var(--muted);
  font-size: 11px;
}

.messaging-reply-form {
  background: #ffffff;
  border-top: 1px solid var(--line);
  padding: 12px 14px;
}

.messaging-reply-form textarea {
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  width: 100%;
}

.messaging-reply-row {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 14px;
}

/* Compose modal */
.messaging-modal {
  align-items: center;
  background: rgba(15, 23, 42, 0.5);
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 24px;
  position: fixed;
  z-index: 70;
}

.messaging-modal[hidden] {
  display: none;
}

.messaging-modal-card {
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
  display: grid;
  gap: 12px;
  max-width: 480px;
  padding: 22px;
  width: 100%;
}

.messaging-modal-card form {
  display: grid;
  gap: 10px;
}

.messaging-modal-card label {
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 4px;
}

.messaging-modal-card input,
.messaging-modal-card select,
.messaging-modal-card textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
}

.messaging-error {
  background: #fee2e2;
  border-radius: 6px;
  color: #991b1b;
  font-size: 13px;
  padding: 8px 10px;
}

.messaging-modal-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Customer drawer (right pane on wide screens) */
.messaging-drawer {
  background: #fdfdfd;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
}

.messaging-drawer-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px;
}

.drawer-section {
  margin-bottom: 18px;
}

.drawer-section h3 {
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  letter-spacing: 0.04em;
  margin: 0 0 8px;
  padding-bottom: 4px;
  text-transform: uppercase;
}

.drawer-identity .drawer-name {
  font-size: 15px;
  font-weight: 700;
}

.drawer-identity .drawer-phone {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.drawer-identity .drawer-seen {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.drawer-aliases {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.drawer-memory-list,
.drawer-actions-list,
.drawer-events-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.drawer-memory {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 4px;
  padding: 8px 10px;
}

.drawer-memory-head {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.drawer-memory-kind {
  background: #eef2f7;
  border-radius: 3px;
  color: #1f2937;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  text-transform: uppercase;
}

.drawer-memory-importance {
  color: var(--muted);
  font-size: 11px;
}

.drawer-memory-content {
  font-size: 13px;
  line-height: 1.35;
}

.drawer-memory-delete {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  text-align: left;
}

.drawer-memory-delete:hover {
  color: #a83232;
  text-decoration: underline;
}

.drawer-memory-form {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.drawer-memory-form select,
.drawer-memory-form textarea {
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
}

.drawer-memory-form textarea {
  min-height: 60px;
  resize: vertical;
}

.drawer-memory-form button {
  align-self: flex-end;
  font-size: 12px;
  padding: 6px 12px;
}

.drawer-action {
  background: #fef9c3;
  border: 1px solid #fde68a;
  border-radius: 6px;
  display: grid;
  gap: 6px;
  padding: 8px 10px;
}

.drawer-action-text {
  font-size: 13px;
  font-weight: 600;
}

.drawer-action-quote {
  background: rgba(255, 255, 255, 0.6);
  border-left: 3px solid #d97706;
  color: #78350f;
  font-size: 12px;
  font-style: italic;
  padding: 4px 8px;
}

.drawer-action-row {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.drawer-action-due {
  color: #78350f;
  font-size: 11px;
}

.drawer-action-buttons {
  display: flex;
  gap: 4px;
}

.drawer-action-buttons button {
  background: #ffffff;
  border: 1px solid #d97706;
  border-radius: 4px;
  color: #92400e;
  cursor: pointer;
  font-size: 11px;
  padding: 3px 8px;
}

.drawer-action-buttons button:hover {
  background: #fef3c7;
}

.drawer-event {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  padding: 6px 8px;
}

.drawer-event-hot {
  border-color: #ef4444;
  background: #fef2f2;
}

.drawer-event-kind {
  font-weight: 700;
  text-transform: capitalize;
}

.drawer-event-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

/* Hot-lead toast (fixed top-right) */
.lead-hot-toast-host {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: fixed;
  right: 16px;
  top: 16px;
  z-index: 80;
}

.lead-hot-toast {
  background: #fef2f2;
  border: 1px solid #ef4444;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
  display: grid;
  gap: 4px;
  max-width: 360px;
  padding: 10px 14px;
}

.lead-hot-toast-head {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.lead-hot-toast-title {
  color: #991b1b;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.lead-hot-toast-close {
  background: transparent;
  border: 0;
  color: #991b1b;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
}

.lead-hot-toast-body {
  color: #1f2937;
  font-size: 13px;
}

.lead-hot-toast-meta {
  color: #7f1d1d;
  font-size: 11px;
}

/* Drawer -> SOP link */
.drawer-sop {
  margin-top: 8px;
}

.drawer-sop-link {
  color: #1e40af;
  font-size: 12px;
  font-weight: 600;
  text-decoration: underline;
}

/* SOP modal (full-page overlay, scrolls internally) */
.sop-modal-host {
  align-items: flex-start;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  inset: 0;
  justify-items: center;
  overflow-y: auto;
  padding: 32px 24px;
  position: fixed;
  z-index: 90;
}

.sop-modal-host[hidden] {
  display: none;
}

.sop-modal-card {
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
  display: grid;
  gap: 12px;
  max-width: 820px;
  padding: 22px 26px;
  width: 100%;
}

.sop-modal-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding-bottom: 8px;
}

.sop-modal-head strong {
  font-size: 16px;
}

.sop-modal-close {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 22px;
  padding: 0;
}

.sop-modal-meta {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 4px;
}

.sop-modal-flag {
  background: #fef3c7;
  border-radius: 4px;
  color: #92400e;
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  text-transform: uppercase;
}

.sop-modal-prompt {
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  max-height: 50vh;
  overflow-y: auto;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.sop-modal-card details {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
}

.sop-modal-card details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.sop-modal-card details pre {
  background: #f9fafb;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  max-height: 30vh;
  overflow-y: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.sop-modal-loading,
.sop-modal-error {
  color: var(--muted);
  padding: 12px;
}
