.communications-inbox-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(150px, 190px) minmax(160px, 210px) minmax(220px, 280px);
  gap: 10px;
  align-items: end;
  margin: 10px 0 12px;
}

.content #panel-communications-inbox .admin-mobile-section-tabs {
  display: none;
}

.communications-mailbox {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  min-height: 640px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.communications-mailbox-list,
.communications-mailbox-detail,
.communications-unmatched-panel {
  min-width: 0;
  background: #ffffff;
}

.communications-mailbox-list {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
}

.communications-mailbox-detail {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 640px;
}

.communications-mailbox-pane-head,
.communications-conversation-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.communications-conversation-head .btn-ghost {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  text-decoration: none;
}

.communications-thread-list {
  min-height: 0;
  overflow: auto;
  background: #ffffff;
}

.communications-thread-row {
  position: relative;
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 10px 14px 10px 16px;
  border: 0;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
  color: #0f172a;
  text-align: left;
  cursor: pointer;
}

.communications-thread-row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
}

.communications-thread-row:hover,
.communications-thread-row:focus-visible {
  background: #f8fafc;
  outline: none;
}

.communications-thread-row.is-active {
  background: #eef6ff;
}

.communications-thread-row.is-active::before {
  background: #2563eb;
}

.communications-thread-row.needs-reply .communications-thread-name {
  font-weight: 800;
  color: #0f172a;
}

.communications-thread-row-head,
.communications-thread-foot,
.communications-message-head,
.communications-message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.communications-thread-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  line-height: 1.25;
  font-weight: 600;
  color: #334155;
}

.communications-thread-time {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  color: #64748b;
  font-size: 12px;
  line-height: 1.2;
}

.communications-thread-preview {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  color: #475569;
  font-size: 13px;
  line-height: 1.35;
}

.communications-thread-meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #64748b;
  font-size: 12px;
  line-height: 1.3;
}

.communications-thread-badges {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  flex-wrap: wrap;
  min-width: 0;
}

.communications-thread-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.communications-reply-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #dc2626;
  box-shadow: 0 0 0 2px #fee2e2;
}

.communications-thread-unread {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.communications-inbound-label,
.communications-channel-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 3px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.communications-inbound-label {
  background: #fee2e2;
  color: #991b1b;
}

.communications-channel-pill--whatsapp {
  background: #dcfce7;
  color: #166534;
}

.communications-channel-pill--sms {
  background: #e0f2fe;
  color: #075985;
}

.communications-channel-pill--email {
  background: #fef3c7;
  color: #92400e;
}

.communications-channel-pill--voice {
  background: #f3f4f6;
  color: #374151;
}

.communications-thread-controls {
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.communications-message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: #f8fafc;
}

.communications-message {
  width: min(78%, 760px);
  display: grid;
  gap: 7px;
  padding: 10px 12px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.communications-message--inbound {
  align-self: flex-start;
  border-color: #cbd5e1;
}

.communications-message--outbound {
  align-self: flex-end;
  border-color: #bfdbfe;
  background: #eff6ff;
}

.communications-message-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 1.25;
}

.communications-message-head span,
.communications-message-meta {
  color: #64748b;
  font-size: 12px;
  line-height: 1.3;
}

.communications-message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #0f172a;
  font-size: 14px;
  line-height: 1.45;
}

.communications-message-subject {
  font-weight: 700;
  color: #0f172a;
  font-size: 13px;
  line-height: 1.35;
}

.communications-message-meta {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.communications-reply-box {
  display: grid;
  gap: 10px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.communications-reply-grid {
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(220px, 1fr);
  gap: 10px;
  align-items: end;
}

.communications-empty-state {
  padding: 18px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.communications-unmatched-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.communications-unmatched-list {
  padding: 12px;
  background: #ffffff;
}

.communications-unmatched-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #ffffff;
}

.b2b-crm-communication-inbox {
  overflow: hidden;
}

.b2b-crm-customer-message-list {
  min-height: 260px;
  max-height: 460px;
  border-top: 1px solid var(--line);
}

.b2b-crm-customer-reply-box {
  border-top: 1px solid var(--line);
}

.communications-template-workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin-top: 12px;
}

.communications-template-library,
.communications-template-editor {
  min-width: 0;
}

.communications-template-list {
  display: grid;
  gap: 8px;
}

.communications-template-card {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.communications-template-card:hover,
.communications-template-card:focus-visible {
  border-color: #9db6d8;
  background: #f8fafc;
  outline: none;
}

.communications-template-card.is-selected {
  border-color: #2563eb;
  box-shadow: inset 3px 0 0 #2563eb;
}

.communications-template-card-head {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.communications-template-card-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  line-height: 1.25;
}

.communications-template-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  min-width: 0;
}

.communications-template-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.communications-template-badge--ok {
  background: #dcfce7;
  color: #166534;
}

.communications-template-badge--warn {
  background: #fef3c7;
  color: #92400e;
}

.communications-template-badge--bad {
  background: #fee2e2;
  color: #991b1b;
}

.communications-template-badge--muted {
  background: #f1f5f9;
  color: #475569;
}

.communications-template-badge--checkout {
  background: #e0f2fe;
  color: #075985;
}

.communications-template-card-preview {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #475569;
  font-size: 13px;
  line-height: 1.35;
}

.communications-template-technical {
  margin-top: 8px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #ffffff;
}

.communications-template-technical summary {
  min-height: 36px;
  padding: 8px 10px;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.communications-template-technical[open] {
  padding: 0 10px 10px;
}

@media (max-width: 980px) {
  .communications-inbox-toolbar,
  .communications-mailbox,
  .communications-thread-controls,
  .communications-reply-grid,
  .communications-template-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .communications-mailbox {
    min-height: 0;
  }

  .communications-mailbox-list {
    border-right: 0;
    min-height: 420px;
  }

  .communications-mailbox-detail {
    min-height: 560px;
  }

  .communications-message {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .content #panel-communications-inbox .admin-mobile-section-tabs {
    display: flex;
  }
}
