#agent-dialog {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 32px);
  padding: 18px;
  border-radius: 16px;
  background: #f7f8f2;
  scrollbar-width: thin;
  scrollbar-color: #b7bdb2 transparent;
}

#agent-dialog::backdrop {
  background: #1d292360;
  backdrop-filter: blur(5px);
}

#agent-dialog[open] {
  animation: agent-arrive 180ms ease-out both;
}

@keyframes agent-arrive {
  from { opacity: .5; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.agent-card {
  padding: 15px 23px 18px;
  border: 1px solid #cfc8ae;
  border-radius: 4px;
  background:
    linear-gradient(140deg, #fffdf0be 5%, #faf5e69e 55%, #e5decb91),
    #f4f0df url('/assets/papers/ivory.webp') center / cover;
  box-shadow: inset 0 1px #fffdf3, 0 1px 1px #766d5930, 0 3px 0 -1px #d6cdba, 0 9px 18px #453f2d18;
  color: #333a2d;
}

.agent-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.agent-seal {
  width: 31px;
  height: 31px;
  border: 1px solid #5a635074;
  border-radius: 50%;
  color: #405940;
  box-shadow: inset 0 -1px #fff9e6, 0 1px #fff9e6;
}

.agent-seal svg { width: 20px; height: 20px; }

#agent-close { width: 36px; height: 36px; margin: -3px -7px -3px 0; }
#agent-close:hover { background: #463f2810; }

#agent-name {
  font: 490 clamp(1.9rem, 6vw, 2.6rem) / .98 var(--serif);
  letter-spacing: -.055em;
  text-shadow: 0 1px #fff9e9;
  overflow-wrap: anywhere;
}

.agent-role {
  color: #41563d;
  font: italic 510 1.02rem / 1.2 var(--serif);
  margin-top: 5px;
}

.agent-description {
  font-size: .82rem;
  line-height: 1.45;
  margin-top: 12px;
}

.agent-identity {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 12px;
  border-top: 1px solid #77755440;
  margin: 13px 0 0;
  padding-top: 9px;
  font-size: .75rem;
  line-height: 1.35;
}

.agent-identity div:last-child { grid-column: 1 / -1; }
.agent-identity dt { color: #535647; }
.agent-identity dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }

#agent-form { display: grid; gap: 12px; margin-top: 17px; }
.agent-field { display: grid; gap: 5px; font-size: .83rem; font-weight: 575; }

.agent-field :is(input, textarea) {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid #a7b39f;
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.35;
  background: #fffefa;
}

.agent-field textarea { resize: vertical; }

.agent-permissions {
  margin: 0;
  min-width: 0;
  padding: 4px 10px 8px;
  border: 1px solid #ced6c7;
  border-radius: 7px;
}

.agent-permissions legend { padding-inline: 4px; font-size: .8rem; font-weight: 600; }

.agent-permission {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 8px;
  min-height: 37px;
  padding-block: 4px;
  font-size: .8rem;
  cursor: pointer;
}

.agent-permission input { width: 16px; height: 16px; margin: 0; accent-color: #304f3f; }
.agent-permission small { display: block; margin-top: 2px; color: #515d50; font-size: .74rem; line-height: 1.3; }
.agent-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 9px; }
.agent-actions .text-action { margin-right: auto; padding: 8px 0; }
#agent-task-actions { margin-top: 15px; }
#agent-retry { margin-top: 12px; }

.agent-status, .agent-error, .agent-result, .agent-usage {
  margin: 13px 0 0;
  font-size: .84rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.agent-status { color: #405347; }
.agent-error { color: #823a2e; }
.agent-status:empty, .agent-error:empty { margin: 0; }
.agent-result h3 { font: 510 1.55rem / 1.08 var(--serif); }
.agent-result ul { margin: 7px 0 0; padding-inline-start: 20px; }
.agent-result a { color: #304f3f; text-underline-offset: 2px; }
.agent-usage { padding-inline-start: 20px; color: #515d50; font-size: .75rem; }

@media (max-width: 430px) {
  #agent-dialog { padding: 12px; }
  .agent-card { padding: 12px 15px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #agent-dialog[open] { animation: none; }
}
