/* Telegram AI agent screens.

   Only the conversation view needs geometry the rest of the backoffice does not have
   (a list beside a transcript). Everything else reuses .panel, .data-table,
   .status-pill and friends, and every colour here comes from the existing tokens in
   app.css so the pages stay in the same design as the rest of the panel. */

.agent-split {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.agent-list {
  max-height: min(70vh, 720px);
  overflow-y: auto;
}

.agent-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}

.agent-row:hover {
  background: var(--bg-muted);
}

.agent-row.is-active {
  background: var(--brand-soft);
  box-shadow: inset 3px 0 0 var(--brand);
}

.agent-row__avatar {
  grid-row: 1 / span 2;
  align-self: center;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 700;
}

.agent-row__name {
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-row__time {
  color: var(--muted);
  font-size: 0.6875rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.agent-row__preview {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-row__state {
  grid-column: 3;
  align-self: center;
}

/* Transcript */
.agent-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: min(58vh, 620px);
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.agent-day {
  align-self: center;
  padding: 2px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 650;
}

.agent-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(70ch, 78%);
}

.agent-msg__bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.agent-msg__meta {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

/* Customer on the left in a plain surface; the AI in brand green; the operator in the
   sidebar navy, so a glance is enough to tell a human reply from a generated one. */
.agent-msg--customer {
  align-self: flex-start;
}

.agent-msg--customer .agent-msg__bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--ink);
}

.agent-msg--assistant {
  align-self: flex-end;
  align-items: flex-end;
}

.agent-msg--assistant .agent-msg__bubble {
  background: var(--brand);
  border-bottom-right-radius: 4px;
  color: #ffffff;
}

.agent-msg--operator {
  align-self: flex-end;
  align-items: flex-end;
}

.agent-msg--operator .agent-msg__bubble {
  background: var(--sidebar-bg);
  border-bottom-right-radius: 4px;
  color: #ffffff;
}

/* Composer */
.agent-composer {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-top: 12px;
}

.agent-composer textarea {
  flex: 1;
  min-height: 46px;
  max-height: 160px;
  resize: vertical;
}

.agent-locked {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-muted);
  color: var(--muted);
  font-size: 0.8125rem;
}

/* Long free text (a lead note, a document body) is allowed to wrap. Without this the
   panel's `white-space: nowrap` on table cells lets a long note squeeze the name column
   until "Nodira Yusupova" renders as "Nodira ...". */
.agent-cell-wrap {
  white-space: normal;
  max-width: 42ch;
}

.agent-cell-name .table-primary {
  min-width: 150px;
}

/* Userbot o'chirib-yoqish tugmasi. Holat matn bilan ham aytiladi: o'chiq userbot
   jim turgani uchun ekranda boshqa hech qanday belgi bo'lmaydi. */
.agent-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.agent-switch small {
  color: var(--muted);
  font-size: 0.75rem;
}

/* Notice strip. The panel has no generic callout class, so this one is namespaced
   rather than claiming a global name other pages might later define differently. */
.agent-callout {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--warning-line);
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.agent-callout--info {
  border-color: var(--line-strong);
  background: var(--info-soft);
  color: var(--info);
}

.agent-callout--danger {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

/* Cost and quality tiles on the report page */
.agent-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.agent-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.agent-stat small {
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.agent-stat strong {
  font-size: 1.75rem;
  font-weight: 680;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.agent-stat span {
  color: var(--muted);
  font-size: 0.75rem;
}

.agent-stat span.is-warning {
  color: var(--warning);
  font-weight: 600;
}

.agent-stat span.is-danger {
  color: var(--danger);
  font-weight: 600;
}

/* Bar chart, no library: a column per day, value on hover */
.agent-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 160px;
  padding-top: 16px;
  border-bottom: 1px solid var(--line-strong);
  background: repeating-linear-gradient(to top, var(--line) 0 1px, transparent 1px 33.34%);
}

.agent-chart__col {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.agent-chart__bar {
  width: 100%;
  max-width: 34px;
  min-height: 2px;
  border-radius: 3px 3px 2px 2px;
  background: var(--brand);
}

.agent-chart__axis {
  display: flex;
  gap: 3px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.6875rem;
}

.agent-chart__axis span {
  flex: 1;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

@media (max-width: 900px) {
  .agent-split {
    grid-template-columns: minmax(0, 1fr);
  }

  .agent-list {
    max-height: 320px;
  }

  .agent-msg {
    max-width: 90%;
  }

  .agent-chart__axis span:nth-child(even) {
    visibility: hidden;
  }
}
