.channel-page {
  background: var(--bg);
}

.channel-shell {
  margin: 0 auto;
  max-width: 1480px;
  min-height: 100vh;
  padding: 24px;
}

.channel-topbar,
.channel-nav,
.channel-command-band,
.channel-command-actions,
.channel-command-detail,
.channel-panel-header,
.channel-segmented,
.channel-record-header,
.channel-record-footer,
.channel-dialog-header {
  align-items: center;
  display: flex;
  gap: 10px;
}

.channel-topbar,
.channel-command-band,
.channel-panel-header,
.channel-record-header,
.channel-record-footer,
.channel-dialog-header {
  justify-content: space-between;
}

.channel-topbar {
  margin-bottom: 16px;
}

.channel-nav {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.channel-command-band {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  margin-bottom: 16px;
  min-height: 72px;
  padding: 12px 16px;
}

.channel-command-status {
  min-width: 0;
}

.channel-command-status > strong {
  display: block;
  font-size: 14px;
}

.channel-command-detail {
  color: var(--muted);
  flex-wrap: wrap;
  font-size: 12px;
  margin-top: 5px;
}

.channel-command-detail span + span::before {
  color: var(--line-strong);
  content: "|";
  margin-right: 10px;
}

#channelFeedback[data-tone="success"] {
  color: var(--green);
}

#channelFeedback[data-tone="warning"] {
  color: var(--amber);
}

#channelFeedback[data-tone="error"] {
  color: var(--red);
}

.channel-health-grid,
.channel-metrics-grid,
.channel-work-grid,
.channel-record-list,
.channel-record-meta {
  display: grid;
}

.channel-health-grid {
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.channel-health-card,
.channel-metrics-grid article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}

.channel-health-card {
  border-left: 3px solid var(--line-strong);
  min-height: 106px;
  padding: 14px 15px;
}

.channel-health-card[data-tone="success"] {
  border-left-color: var(--green);
}

.channel-health-card[data-tone="warning"] {
  border-left-color: var(--amber);
}

.channel-health-card[data-tone="danger"] {
  border-left-color: var(--red);
}

.channel-health-card span,
.channel-health-card strong,
.channel-health-card small,
.channel-metrics-grid span,
.channel-metrics-grid strong {
  display: block;
}

.channel-health-card span,
.channel-health-card small,
.channel-metrics-grid span {
  color: var(--muted);
  font-size: 12px;
}

.channel-health-card strong {
  font-size: 18px;
  margin-top: 9px;
}

.channel-health-card small {
  line-height: 1.5;
  margin-top: 7px;
  overflow-wrap: anywhere;
}

.channel-metrics-grid {
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.channel-metrics-grid article {
  min-height: 86px;
  padding: 13px 14px;
}

.channel-metrics-grid strong {
  font-size: 21px;
  margin-top: 8px;
}

.channel-danger-metric[data-active="true"] {
  border-color: #e5b5b5;
}

.channel-danger-metric[data-active="true"] strong {
  color: var(--red);
}

.channel-work-grid {
  align-items: start;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.channel-panel {
  min-width: 0;
  overflow: hidden;
}

.channel-panel-header {
  align-items: flex-start;
  flex-wrap: wrap;
}

.channel-panel-header > div:first-child {
  min-width: 180px;
}

.channel-segmented {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
}

.channel-segmented button {
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  min-height: 30px;
  padding: 5px 8px;
  white-space: nowrap;
}

.channel-segmented button:hover {
  color: var(--ink);
}

.channel-segmented button[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(20 35 50 / 12%);
  color: var(--blue-dark);
  font-weight: 700;
}

.channel-segmented button span {
  color: inherit;
  font-variant-numeric: tabular-nums;
  margin-left: 2px;
}

.channel-outbox-filters {
  max-width: 100%;
}

.channel-record-list {
  gap: 10px;
  max-height: 720px;
  overflow: auto;
  padding: 14px 18px 18px;
}

.channel-record {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-width: 0;
  padding: 13px 14px;
}

.channel-record-header {
  align-items: flex-start;
}

.channel-record-header > div {
  min-width: 0;
}

.channel-record-header strong,
.channel-record-header small {
  display: block;
  overflow-wrap: anywhere;
}

.channel-record-header strong {
  font-size: 14px;
  line-height: 1.45;
}

.channel-record-header small,
.channel-record-footer small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 4px;
}

.channel-status-badge {
  background: var(--surface-soft);
  border-radius: 999px;
  color: var(--muted);
  flex: none;
  font-size: 12px;
  padding: 4px 8px;
  white-space: nowrap;
}

.channel-status-badge.auto,
.channel-status-badge.sent {
  background: #e8f5ec;
  color: var(--green);
}

.channel-status-badge.human,
.channel-status-badge.retry {
  background: #fff7ed;
  color: var(--amber);
}

.channel-status-badge.pending,
.channel-status-badge.sending {
  background: #e9f2f8;
  color: var(--blue-dark);
}

.channel-status-badge.cancelled {
  background: #eef1f4;
  color: #596774;
}

.channel-status-badge.dead {
  background: #faeaea;
  color: var(--red);
}

.channel-record-meta {
  gap: 8px 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 12px 0 0;
}

.channel-record-meta div {
  background: var(--surface-soft);
  border-radius: 5px;
  min-width: 0;
  padding: 8px 9px;
}

.channel-record-meta dt,
.channel-record-meta dd {
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
}

.channel-record-meta dt {
  color: var(--muted);
}

.channel-record-meta dd {
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.channel-handoff-reason,
.channel-outbox-error {
  border-left: 3px solid var(--amber);
  color: #4a3a20;
  font-size: 12px;
  line-height: 1.55;
  margin-top: 11px;
  overflow-wrap: anywhere;
  padding: 8px 10px;
}

.channel-handoff-reason {
  background: #fffaf2;
}

.channel-outbox-error {
  background: #fff5f5;
  border-left-color: var(--red);
  color: #6f2929;
}

.channel-handoff-reason b,
.channel-outbox-error b {
  display: block;
  margin-bottom: 2px;
}

.channel-record-footer {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  min-height: 34px;
  padding-top: 10px;
}

.channel-record-footer small {
  margin: 0;
  min-width: 0;
}

.channel-conversation-action {
  flex: none;
  min-height: 34px;
  padding: 6px 10px;
}

.channel-outbox-content {
  color: #2d3d4c;
  font-size: 13px;
  line-height: 1.6;
  margin-top: 11px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.channel-outbox-record.dead {
  border-color: #e5b5b5;
}

.channel-outbox-record.cancelled {
  border-color: #cbd3da;
}

.channel-dialog {
  background: transparent;
  border: 0;
  max-width: 560px;
  padding: 0;
  width: calc(100% - 28px);
}

.channel-dialog::backdrop {
  background: rgb(15 23 42 / 46%);
}

.channel-dialog-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  padding: 18px;
}

.channel-dialog-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.channel-dialog-header h2 {
  font-size: 18px;
  margin: 0;
}

.channel-dialog-identity {
  color: #2d3d4c;
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
  overflow-wrap: anywhere;
}

.channel-dialog label {
  display: grid;
  gap: 6px;
}

.channel-dialog label > span {
  color: var(--muted);
  font-size: 12px;
}

.channel-dialog textarea {
  min-height: 108px;
}

.channel-dialog-feedback {
  color: var(--red);
  font-size: 12px;
  line-height: 1.5;
  margin: 0;
  min-height: 18px;
}

.channel-dialog .primary-button {
  justify-self: end;
}

@media (max-width: 1180px) {
  .channel-panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .channel-segmented {
    align-self: flex-start;
  }
}

@media (max-width: 980px) {
  .channel-metrics-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .channel-work-grid {
    grid-template-columns: 1fr;
  }

  .channel-record-list {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .channel-shell {
    padding: 14px;
  }

  .channel-topbar,
  .channel-command-band,
  .channel-dialog-header {
    align-items: stretch;
    flex-direction: column;
  }

  .channel-nav,
  .channel-command-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .channel-health-grid {
    grid-template-columns: 1fr;
  }

  .channel-metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .channel-command-detail {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .channel-command-detail span + span::before {
    content: none;
  }

  .channel-segmented {
    align-self: stretch;
    width: 100%;
  }

  .channel-segmented button {
    flex: 1 1 auto;
  }

  .channel-record-header,
  .channel-record-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .channel-status-badge {
    align-self: flex-start;
  }

  .channel-record-meta {
    grid-template-columns: 1fr;
  }

  .channel-record-footer small:empty {
    display: none;
  }

  .channel-conversation-action,
  .channel-dialog .primary-button,
  .channel-dialog-header .ghost-button {
    justify-self: stretch;
    width: 100%;
  }
}

@media (max-width: 420px) {
  .channel-shell {
    padding: 12px;
  }

  .channel-metrics-grid {
    gap: 8px;
  }

  .channel-metrics-grid article {
    min-height: 82px;
    padding: 12px;
  }

  .channel-panel .panel-header,
  .channel-record-list {
    padding-left: 12px;
    padding-right: 12px;
  }

  .channel-segmented button {
    flex-basis: calc(33.333% - 3px);
  }

  .channel-dialog-shell {
    padding: 14px;
  }
}
