.agent-body {
  min-height: 100vh;
}

.agent-brand-link {
  color: #ffffff;
  text-decoration: none;
}

.agent-main {
  min-width: 0;
  padding: 28px;
}

.agent-view.view.active {
  height: calc(100vh - 56px);
  overflow: auto;
}

.agent-view .topbar {
  margin-bottom: 18px;
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding-bottom: 28px;
}

.agent-panel {
  display: grid;
  align-content: start;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-cards, 8px);
  padding: 18px;
  background: var(--panel);
}

.agent-panel-wide {
  grid-column: 1 / -1;
}

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

.agent-panel h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.agent-panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.agent-status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.agent-status-card {
  display: grid;
  gap: 8px;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--field-bg);
}

.agent-status-card span,
.agent-form-grid label {
  color: var(--muted);
  font-size: 13px;
}

.agent-status-card strong {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.25;
}

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

.agent-form-grid label {
  display: grid;
  gap: 7px;
}

.agent-form-grid input,
.agent-form-grid select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--field-border);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--field-ink);
  background: var(--field-bg);
}

.agent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.agent-actions button,
#agent-refresh {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--field-bg);
  cursor: pointer;
}

.agent-actions .primary {
  border: 0;
  color: #ffffff;
  background: var(--accent);
}

.agent-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: var(--field-bg);
  font-size: 14px;
  line-height: 1.5;
}

.agent-result a {
  color: var(--accent);
}

.agent-inline-result {
  min-height: 20px;
}

.agent-users {
  display: grid;
  gap: 8px;
}

.agent-user-row {
  display: grid;
  grid-template-columns: minmax(130px, .8fr) minmax(180px, 1.2fr) 110px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--field-bg);
  font-size: 14px;
}

.agent-user-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-user-status {
  justify-self: start;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--ink);
  background: var(--panel);
  font-size: 12px;
}

.agent-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: var(--field-bg);
}

@media (max-width: 980px) {
  .agent-grid,
  .agent-status-grid,
  .agent-form-grid {
    grid-template-columns: 1fr;
  }

  .agent-user-row {
    grid-template-columns: 1fr;
  }
}

.agent-chat-toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: var(--shadow, 0 12px 28px rgba(15, 23, 42, .18));
  font-weight: 800;
  cursor: pointer;
}

.agent-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 84px;
  z-index: 61;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(420px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 116px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow, 0 18px 42px rgba(15, 23, 42, .22));
  overflow: hidden;
}

.agent-chat-toggle[hidden],
.agent-chat-panel[hidden] {
  display: none !important;
}

.agent-chat-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.agent-chat-head h2,
.agent-chat-head p,
.agent-chat-message p {
  margin: 0;
}

.agent-chat-head h2 {
  font-size: 17px;
}

.agent-chat-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.agent-chat-head-actions {
  display: flex;
  gap: 8px;
}

.agent-chat-head-actions button,
.agent-chat-form button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--field-bg);
  cursor: pointer;
}

.agent-chat-messages {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: var(--bg);
}

.agent-chat-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.agent-chat-message {
  display: grid;
  gap: 5px;
  max-width: 88%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
}

.agent-chat-message-user {
  justify-self: end;
  border-color: transparent;
  color: #ffffff;
  background: var(--accent);
}

.agent-chat-message span {
  font-size: 12px;
  font-weight: 700;
  opacity: .75;
}

.agent-chat-message p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.agent-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.agent-chat-form textarea {
  min-width: 0;
  resize: none;
  border: 1px solid var(--field-border);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--field-ink);
  background: var(--field-bg);
}

.agent-chat-form button {
  color: #ffffff;
  border-color: transparent;
  background: var(--accent);
}

.mailru-detail-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.mailru-add-route {
  flex: none;
  border: 0;
  border-radius: 6px;
  padding: 9px 12px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
}

@media (max-width: 640px) {
  .agent-chat-panel {
    right: 10px;
    bottom: 76px;
    width: calc(100vw - 20px);
    height: min(620px, calc(100vh - 96px));
  }

  .agent-chat-form {
    grid-template-columns: 1fr;
  }

  .mailru-detail-title-row {
    display: grid;
  }
}
