.communications-inbox-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(150px, 190px) minmax(160px, 210px);
  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 auto;
  align-content: start;
  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-delivery-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.communications-delivery-status strong {
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.18rem 0.48rem;
}

.communications-delivery-status--ok { color: #147a45; }
.communications-delivery-status--warn { color: #9a5b00; }
.communications-delivery-status--bad { color: #b42318; }

.communications-delivery-timeline {
  display: grid;
  gap: 0.35rem;
  margin: 0.65rem 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.communications-delivery-timeline li {
  display: grid;
  grid-template-columns: minmax(8rem, auto) minmax(8rem, auto) 1fr;
  gap: 0.5rem;
}

.communications-thread-head-meta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.communications-thread-select {
  appearance: none;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  color: #1d4ed8;
  cursor: pointer;
}

.communications-thread-select:hover,
.communications-thread-select:focus-visible {
  border-color: #2563eb;
  outline: 3px solid #93c5fd;
  outline-offset: 1px;
}

.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-name--customer {
  color: #0f172a;
}

.communications-thread-name--customer::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 999px;
  background: #2563eb;
  vertical-align: middle;
}

button.communications-thread-name {
  appearance: none;
  display: inline-block;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

button.communications-thread-name:hover,
button.communications-thread-name:focus-visible {
  color: #1d4ed8;
  text-decoration: underline;
  outline: none;
}

.communications-thread-title-link {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.communications-thread-title-link:hover,
.communications-thread-title-link:focus-visible {
  color: #1d4ed8;
  text-decoration: underline;
  outline: none;
}

.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-replied-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-replied-label {
  background: #dcfce7;
  color: #166534;
}

.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-settings {
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.communications-thread-settings summary {
  min-height: 38px;
  padding: 10px 14px;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

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

.communications-message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  max-height: min(52vh, 520px);
  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: #475569;
  font-size: 12px;
  line-height: 1.3;
}

.communications-message-head-actions {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.communications-message-copy {
  appearance: none;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  padding: 0;
}

.communications-message-copy svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.communications-message-copy:hover,
.communications-message-copy:focus-visible {
  border-color: #2563eb;
  color: #1d4ed8;
  outline: 3px solid #93c5fd;
  outline-offset: 1px;
}

.communications-message-details > summary:focus-visible,
button.communications-thread-name:focus-visible,
.communications-thread-title-link:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.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-message-details {
  min-width: 0;
}

.communications-message-details > summary {
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

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

.communications-reply-box[hidden] {
  display: none;
}

.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-thread-actions {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.communications-unmatched-thread-actions[hidden] {
  display: none;
}

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

.communications-unmatched-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.communications-unmatched-card-head strong,
.communications-unmatched-card-body,
.communications-unmatched-card a {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.communications-unmatched-card-actions {
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: end;
}

.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;
}

.communications-template-actions {
  margin: 10px 0 0;
  padding: 12px;
  border: 1px solid var(--border, #d8deea);
  border-radius: 12px;
}

.communications-template-actions legend {
  padding: 0 6px;
  font-weight: 700;
}

.communications-template-action-row {
  display: grid;
  grid-template-columns: minmax(140px, .8fr) minmax(180px, 1fr) minmax(220px, 1.4fr) auto;
  gap: 8px;
  align-items: end;
  margin: 8px 0;
}

.communications-template-phone-preview {
  width: min(100%, 390px);
  margin: 14px auto 0;
  padding: 14px;
  border: 8px solid #172033;
  border-radius: 26px;
  background: #eef8ef;
  box-shadow: 0 10px 28px rgba(16, 24, 40, .12);
}

.communications-template-phone-preview-head {
  margin: -14px -14px 12px;
  padding: 10px 14px;
  border-radius: 16px 16px 0 0;
  background: #075e54;
  color: #fff;
  font-weight: 700;
}

.communications-template-phone-preview p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.communications-template-preview-media {
  margin-bottom: 8px;
  padding: 16px 10px;
  border-radius: 10px;
  background: #d9e7dc;
  color: #41534a;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.communications-template-preview-actions {
  display: grid;
  gap: 6px;
}

.communications-template-preview-actions span {
  padding: 8px;
  border-top: 1px solid #cbd9ce;
  color: #0878a4;
  text-align: center;
  font-weight: 700;
}

@media (min-width: 721px) {
  .communications-message-details > summary {
    display: none;
  }

  .communications-message-details:not([open]) > .communications-message-meta {
    display: flex;
  }

  .communications-mailbox {
    height: clamp(520px, calc(100vh - 220px), 820px);
    height: clamp(520px, calc(100dvh - 220px), 820px);
    min-height: 520px;
  }

  .communications-mailbox-list,
  .communications-mailbox-detail {
    min-height: 0;
  }

  .communications-mailbox-detail {
    overflow: hidden;
  }

  .communications-message-list {
    max-height: none;
  }

  .communications-reply-box {
    position: sticky;
    bottom: 0;
    z-index: 2;
    box-shadow: 0 -8px 18px rgba(15, 23, 42, 0.06);
  }
}

@media (min-width: 721px) and (max-width: 980px) {
  .communications-mailbox {
    height: max(360px, calc(100vh - 360px));
    height: max(360px, calc(100dvh - 360px));
    min-height: 360px;
  }
}

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

  .communications-message {
    width: 100%;
  }

  .communications-template-action-row {
    grid-template-columns: 1fr;
  }
}

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

  .communications-mailbox {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
  }

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

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

}
