:root {
  --ink: #17202a;
  --muted: #667085;
  --line: #e3e8ef;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fbfc;
  --accent: #157f72;
  --accent-dark: #0f5f55;
  --accent-soft: #e7f5f2;
  --amber: #b26b00;
  --amber-soft: #fff5df;
  --danger: #b42318;
  --agent: #e8f5f2;
  --customer: #fff7e8;
  --shadow: 0 12px 28px rgba(24, 39, 75, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: white;
  padding: 0 14px;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: white;
  color: var(--accent);
}

button.secondary:hover {
  background: var(--accent-soft);
}

button:disabled {
  border-color: var(--line);
  background: #eef2f6;
  color: #98a2b3;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  min-width: 150px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21, 127, 114, 0.13);
}

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

.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: #17202a;
  color: white;
  padding: 18px 14px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 54px;
  margin-bottom: 18px;
  padding: 4px 4px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #e8f5f2;
  color: var(--accent-dark);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0;
}

.brand span {
  display: block;
  margin-top: 3px;
  color: #a7b0b8;
  font-size: 12px;
}

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

.nav-bottom {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border-color: transparent;
  border-radius: 8px;
  background: transparent;
  color: #d8dee4;
  text-align: left;
  font-weight: 600;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: transparent;
}

.nav-item.active {
  background: #e8f5f2;
  color: var(--accent-dark);
}

.nav-icon,
.coming-icon {
  width: 18px;
  height: 18px;
  flex: none;
  background: currentColor;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;
}

.chat-icon {
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 5h16v11H8l-4 4V5Zm2 2v8.2L7.2 14H18V7H6Z'/%3E%3C/svg%3E");
}

.report-icon {
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5 3h14v18H5V3Zm2 2v14h10V5H7Zm2 3h6v2H9V8Zm0 4h6v2H9v-2Zm0 4h4v2H9v-2Z'/%3E%3C/svg%3E");
}

.risk-icon {
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 2 22 20H2L12 2Zm0 4.1L5.4 18h13.2L12 6.1ZM11 9h2v5h-2V9Zm0 6h2v2h-2v-2Z'/%3E%3C/svg%3E");
}

.coach-icon {
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 3 3 8l9 5 7-3.9V15h2V8L12 3Zm0 2.3L16.9 8 12 10.7 7.1 8 12 5.3ZM6 12v4.5C6 18.4 8.8 20 12 20s6-1.6 6-3.5V12h-2v4.5c0 .5-1.5 1.5-4 1.5s-4-1-4-1.5V12H6Z'/%3E%3C/svg%3E");
}

.admin-icon {
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3Zm0 2.2L18 6.4V11c0 3.9-2.5 7.5-6 8.8-3.5-1.3-6-4.9-6-8.8V6.4l6-2.2Z'/%3E%3C/svg%3E");
}

.config-icon {
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M19.4 13.5c.1-.5.1-1 .1-1.5s0-1-.1-1.5l2-1.5-2-3.5-2.4 1a7 7 0 0 0-2.6-1.5L14 2h-4l-.4 2.5A7 7 0 0 0 7 6L4.6 5l-2 3.5 2 1.5c-.1.5-.1 1-.1 1.5s0 1 .1 1.5l-2 1.5 2 3.5 2.4-1a7 7 0 0 0 2.6 1.5L10 22h4l.4-2.5A7 7 0 0 0 17 18l2.4 1 2-3.5-2-1.5ZM12 15a3 3 0 1 1 0-6 3 3 0 0 1 0 6Z'/%3E%3C/svg%3E");
}

.admin-only {
  display: none;
}

.is-admin .admin-only {
  display: block;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  align-items: end;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

#diagnosticsView .toolbar {
  grid-template-columns: minmax(180px, 220px) minmax(260px, 340px) 112px 112px;
  justify-content: start;
}

.period-preview {
  display: flex;
  align-items: center;
  align-self: end;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  justify-content: start;
}

.period-preview span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 14px;
  padding-top: 3px;
}

.period-preview strong {
  font-size: 13px;
  line-height: 1;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.split {
  display: grid;
  grid-template-columns: minmax(310px, 0.68fr) minmax(560px, 1.32fr);
  gap: 12px;
  height: calc(100vh - 110px);
  min-height: 560px;
}

.diagnostics-layout {
  display: grid;
  grid-template-columns: minmax(310px, 0.4fr) minmax(680px, 1fr);
  gap: 12px;
  height: calc(100vh - 110px);
  min-height: 560px;
}

.config-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(420px, 1fr));
  gap: 12px;
}

.config-panel,
.table-panel,
.message-panel,
.insight,
.empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.config-panel,
.table-panel,
.message-panel {
  overflow: hidden;
}

.table-panel,
.message-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.config-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
  padding: 14px;
}

.config-form button {
  align-self: end;
}

.config-notes {
  padding: 14px;
  color: var(--muted);
  line-height: 1.7;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel-soft);
}

.panel-title strong {
  color: var(--ink);
  font-size: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: var(--panel-soft);
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: var(--accent-soft);
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 7px 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  background: var(--panel-soft);
}

.pager button {
  min-width: 76px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.message {
  max-width: 78%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid #f0dfbf;
  border-radius: 8px;
  background: var(--customer);
}

.message.agent {
  margin-left: auto;
  border-color: #cde7e2;
  background: var(--agent);
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.message-card {
  display: grid;
  gap: 8px;
}

.card-title {
  font-weight: 700;
}

.card-subtitle,
.product-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.product-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.product-item,
.metric,
.agent-card,
.evidence-item,
.run-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.product-title {
  line-height: 1.45;
  word-break: break-word;
}

.media-block {
  display: grid;
  gap: 8px;
}

.chat-image,
.chat-video {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  object-fit: contain;
}

.media-link {
  color: var(--accent);
  word-break: break-all;
}

.stack,
.report-list,
.agent-card,
.evidence-list,
.evidence-item,
.run-list,
.run-item {
  display: grid;
  gap: 8px;
}

.report-list {
  align-content: start;
  overflow: auto;
  padding: 10px;
}

.report-row {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
  padding: 8px;
}

.report-row:hover,
.report-row.selected {
  background: var(--accent-soft);
  border-color: #b7dad3;
}

.report-open {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 4px;
  text-align: left;
  box-shadow: none;
}

.report-open:hover {
  background: transparent;
  color: var(--accent-dark);
}

.report-open strong {
  font-size: 14px;
}

.icon-button {
  display: grid;
  place-items: center;
  min-width: 32px;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 7px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover {
  background: #fff0ee;
  border-color: #f0c6c1;
  color: var(--danger);
}

.report-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.report-row span,
.report-row small,
.muted {
  color: var(--muted);
}

.report-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.report-detail {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.report-section {
  display: grid;
  gap: 11px;
  padding: 4px 0 20px;
  border-bottom: 1px solid var(--line);
}

.report-section + .report-section {
  padding-top: 18px;
}

.report-section h2 {
  margin: 0;
  font-size: 16px;
}

.overview-summary {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  padding: 10px 12px;
  border-radius: 7px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  gap: 8px;
}

.metric {
  display: grid;
  gap: 4px;
  background: white;
}

.metric strong {
  font-size: 24px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.report-list-text {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.agent-cards {
  display: grid;
  gap: 10px;
}

.traffic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(300px, 1fr));
  gap: 12px;
}

.traffic-title {
  margin-bottom: 8px;
  font-weight: 800;
  font-size: 14px;
}

.traffic-title.red {
  color: var(--danger);
}

.traffic-title.green {
  color: var(--accent-dark);
}

.issue-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 10px;
}

.issue-card {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
}

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

.issue-head span {
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.typical-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.typical-link {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.agent-card p,
.evidence-item p,
.report-section p {
  margin: 0;
  line-height: 1.6;
}

.agent-card-head,
.run-item div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.agent-card.red {
  border-color: #f0c6c1;
  background: #fff8f7;
}

.agent-card.green {
  border-color: #cde7e2;
  background: #f4fbf9;
}

.agent-card button {
  justify-self: start;
}

.agent-card-head span,
.run-item span,
.run-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-row span {
  border: 1px solid #cde7e2;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 2px 7px;
  font-size: 12px;
}

.evidence-item button {
  justify-self: start;
}

.distribution-list {
  display: grid;
  gap: 10px;
}

.distribution-row {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr 42px;
  gap: 10px;
  align-items: center;
}

.distribution-row span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.distribution-row div {
  height: 10px;
  border-radius: 999px;
  background: #eef2f6;
  overflow: hidden;
}

.distribution-row i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.distribution-row strong {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.run-list {
  max-height: 360px;
  overflow: auto;
  padding: 0 14px 14px;
}

.empty {
  padding: 16px;
  line-height: 1.6;
  color: var(--muted);
}

.coming-soon {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  min-height: calc(100vh - 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--muted);
}

.coming-soon .coming-icon {
  width: 42px;
  height: 42px;
  color: var(--accent);
}

.coming-soon h1 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
}

.coming-soon p {
  margin: 0;
  font-size: 14px;
}

.status {
  color: var(--amber);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 420px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #1f2428;
  color: white;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.drawer-shell {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.drawer-shell.open {
  pointer-events: auto;
  opacity: 1;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.28);
}

.conversation-drawer {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  width: min(980px, calc(100vw - 48px));
  height: 100%;
  background: var(--panel);
  box-shadow: -22px 0 50px rgba(15, 23, 42, 0.18);
  transform: translateX(24px);
  transition: transform 0.18s ease;
}

.drawer-shell.open .conversation-drawer {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.drawer-header strong {
  display: block;
  font-size: 16px;
}

.drawer-header span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.drawer-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 0;
  flex: 1;
}

.drawer-conversation-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

.drawer-conversation-item {
  display: grid;
  gap: 5px;
  min-height: 64px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  text-align: left;
}

.drawer-conversation-item:hover,
.drawer-conversation-item.active {
  border-color: #b7dad3;
  background: var(--accent-soft);
  color: var(--ink);
}

.drawer-conversation-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.drawer-messages {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.drawer-issue-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.drawer-issue-summary p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .toolbar,
  #diagnosticsView .toolbar,
  .split,
  .config-layout,
  .diagnostics-layout,
  .config-form {
    grid-template-columns: 1fr;
  }

  .split,
  .diagnostics-layout {
    height: auto;
  }

  .table-panel,
  .message-panel {
    min-height: 520px;
  }

  .metric-grid,
  .agent-cards,
  .traffic-grid,
  .issue-cards {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }

  .conversation-drawer {
    width: 100vw;
  }

  .drawer-body {
    grid-template-columns: 1fr;
  }

  .drawer-conversation-list {
    max-height: 180px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
