:root {
  --bg: #f6f7f7;
  --surface: #ffffff;
  --line: #d8dddc;
  --line-strong: #aab3b1;
  --text: #1f2423;
  --muted: #65706d;
  --accent: #0f766e;
  --accent-dark: #0b5f58;
  --danger: #a32626;
  --warning: #8a5a00;
  --ok: #2d6a3f;
  --row: #fbfbfa;
  --sidebar: #eef1f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

a {
  color: var(--accent-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
}

.brand {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
}

.brand-subtitle {
  color: var(--muted);
  margin-top: 2px;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
}

.nav a.active,
.nav a:hover {
  background: #dfe6e4;
  text-decoration: none;
}

.main {
  min-width: 0;
  padding: 22px 26px 40px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 23px;
}

h2 {
  font-size: 18px;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading p,
.muted {
  color: var(--muted);
}

.section-heading p {
  margin: 4px 0 0;
}

.split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.upload-form,
.filter-form {
  display: grid;
  gap: 12px;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
button,
.button {
  font: inherit;
  border-radius: 6px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  padding: 8px 9px;
  background: #ffffff;
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid #a7d6cf;
  outline-offset: 1px;
}

button,
.button {
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: #ffffff;
  padding: 8px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  text-decoration: none;
}

button:hover,
.button:hover {
  background: var(--accent-dark);
  text-decoration: none;
}

button.secondary,
.button.secondary {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line-strong);
}

button.secondary:hover,
.button.secondary:hover {
  background: #eef1f0;
}

.form-actions,
.actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.metric-grid,
.meta-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 14px;
}

.metric,
.meta-grid > div {
  padding: 10px;
  border-right: 1px solid var(--line);
  background: var(--row);
  min-width: 0;
}

.metric:last-child,
.meta-grid > div:last-child {
  border-right: 0;
}

.metric span,
.meta-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong,
.meta-grid strong {
  font-size: 18px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f2f4f3;
}

.data-table tbody tr:hover {
  background: #f8faf9;
}

.table-section {
  overflow-x: auto;
}

.message-table th:nth-child(5),
.message-table td:nth-child(5) {
  width: 30%;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  margin: 0 0 10px;
}

.pagination + .data-table {
  margin-top: 8px;
}

.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.risk-badge,
.direction,
.flag-list span,
.audit-line span,
.signal-list span {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 12px;
  white-space: nowrap;
  background: #ffffff;
}

.risk-none {
  color: var(--muted);
}

.risk-low {
  color: var(--ok);
  border-color: #acd3b7;
  background: #f2faf4;
}

.risk-moderate {
  color: var(--warning);
  border-color: #e2c482;
  background: #fff8e6;
}

.risk-high {
  color: var(--danger);
  border-color: #e4a4a4;
  background: #fff1f1;
}

.direction.inbound {
  color: #245a8d;
  border-color: #b9cfe3;
  background: #f1f7fc;
}

.direction.outbound {
  color: #5f4b18;
  border-color: #d8c992;
  background: #fbf7e9;
}

.flag-list,
.audit-line,
.signal-list {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.participant-line {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
}

.transcript {
  padding: 0;
}

.message-row {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.message-row:last-child {
  border-bottom: 0;
}

.message-row.inbound {
  border-left: 4px solid #5f9dcb;
}

.message-row.outbound {
  border-left: 4px solid #c5aa4f;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.route-line {
  color: var(--muted);
  margin-bottom: 8px;
}

.message-body p {
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.attachments {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.attachment-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfbfa;
}

.attachment-item img {
  display: block;
  max-width: min(520px, 100%);
  max-height: 360px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
}

.attachment-actions {
  display: flex;
  gap: 10px;
}

.audit-details,
.reason-details {
  margin-top: 8px;
}

.audit-details summary,
.reason-details summary {
  cursor: pointer;
  color: var(--accent-dark);
}

.signal-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.signal-table th,
.signal-table td {
  border: 1px solid var(--line);
  padding: 6px;
  text-align: left;
}

.inline-form {
  display: inline;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background: #fbfbfa;
}

.error-box pre {
  white-space: pre-wrap;
  overflow-x: auto;
}

.job-status {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.job-status-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.job-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 3px 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.job-pill.running,
.job-pill.queued {
  color: var(--warning);
  border-color: #e2c482;
  background: #fff8e6;
}

.job-pill.completed {
  color: var(--ok);
  border-color: #acd3b7;
  background: #f2faf4;
}

.job-pill.failed {
  color: var(--danger);
  border-color: #e4a4a4;
  background: #fff1f1;
}

.progress-track {
  width: 100%;
  height: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #eef1f0;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 180ms ease-out;
}

.job-log {
  margin: 0;
  padding-left: 20px;
}

.job-log li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.job-log span {
  display: inline-block;
  min-width: 210px;
  color: var(--muted);
  font-size: 12px;
}

.error-text {
  color: var(--danger);
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    display: flex;
    flex-wrap: wrap;
  }

  .filter-row,
  .metric-grid,
  .meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split,
  .message-meta,
  .pagination {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 14px;
  }

  .filter-row,
  .metric-grid,
  .meta-grid {
    grid-template-columns: 1fr;
  }
}
