/*
 * General components
 */

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.truncate-4x30-chars {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30ch;
}

[role=button].primary-black {
  --background-color: black;
}

[role=button].primary-black:is([aria-current], :hover, :active, :focus) {
  --background-color: #0003;
}

.selectable:hover {
  background-color: var(--color-hover);
  cursor: pointer;
}

.selected {
  background-color: var(--border-color);
}

.icon-button.faicon {
  font-size: 0.75rem;
  line-height: 1.5rem;
  text-align: center;
}

.page-content {
  min-height: calc(100vh - 5.5rem);
  border-radius: 0.5rem;
}

.page-content:has(.chat-history.not-empty) {
  background: var(--background-11);
}

.page.embedded .page-background *,
.page:has(.chat-history.not-empty) .page-background * {
  display: none;
}

.page:has(.chat-history.not-empty) .page-header {
  background: var(--background-1);
}

/*
 * Home
 */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 0;
}

/*
 * Control pane
 */

.control-pane {
  display: flex;
  flex-direction: column;
  position: absolute;
  width: 100%;
  height: fit-content;
  top: 50%;
  left: 0;
  margin: 0;
  transform: translate(0, -50%);
  z-index: 10;
}

@media screen and (max-width:1100px) {
  .control-pane {
    margin-bottom: 0;
  }
}

.home:has(.chat-history.not-empty) .control-pane {
  position: sticky;
  top: unset;
  transform: unset;
  bottom: 1rem;
}

.page.embedded .home .control-pane {
  position: sticky;
  top: unset;
  transform: unset;
  width: calc(100% - 1rem);
  margin: 0 0.5rem;
  bottom: 0;
}

.page.embedded .home:has(.chat-history.not-empty) .control-pane {
  width: 100%;
  margin: 0;
}

.control-pane .banner {
  font-size: 2rem;
  font-weight: 500;
  padding: 2rem;
  text-align: center;
}

.page.embedded .control-pane .banner,
.home:has(.chat-history.not-empty) .control-pane .banner {
  display: none;
}

.control-pane .controls {
  position: relative;
  display: flex;
  flex-direction: column;
  background: rgb(from var(--background-6) r g b / 0.95);
  padding: 0;
  margin: 0;
  border-radius: 0.5rem;
}

.control-pane .controls-form {
  display: flex;
  flex-direction: column;
  font-size: 1rem;
  margin: 0.9rem 0.9rem 0 0.9rem;
  padding: 0;
}

.control-pane .question {
  color: var(--color-1);
  font-size: 0.8rem;
  /*height: 4rem;*/
  border: none;
  resize: none;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: break-word;
  word-break: break-word;
  padding: 0;
  margin: 0;
}

.control-pane .question:focus {
  --box-shadow: none;
  outline: none;
}

#home.hide-question .microphone,
#home.hide-question #select-power,
#home.hide-question #question-man {
  display: none;
}

.control-pane .controls-bar {
  display: flex;
  flex-wrap: wrap;
  padding: 0.2rem 0.5rem 0.5rem 0.5rem;
  margin: 0;
}

.control-pane #manage-agent,
.control-pane #select-power,
.control-pane #select-project {
  height: 1.5rem;
  margin: 0.25rem 0.125rem;
  padding: 0.25rem 0.5rem;
  color: var(--color-1);
  background: var(--background-2);
  cursor: pointer;
  border-radius: 0.25rem;
}

.control-pane #manage-agent:hover,
.control-pane #select-power:hover,
.control-pane #select-project:hover {
  background: var(--color-hover);
}

.control-pane:has(#manage-agent:not([data-requires-project=yes])) #select-project {
  display: none;
}

/* Power picker list status icon (dialog) */
#select-power-options {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

#select-power-options > li {
  position: relative;
  padding: 0.5rem 0.5rem 0.5rem 2rem; /* space for status icon */
  cursor: pointer;
  border-radius: 0.25rem;
  transition: background-color 120ms ease;
}

#select-power-options > li:hover {
  background-color: var(--color-hover);
}

#select-power-options > li .status {
  margin: 0;
  width: 1rem;
  height: 1rem;
  position: absolute;
  left: 0.5rem;
  top: 0.5rem;
  border-radius: 50%;
  background-color: var(--background-6);
  /* z-index: 1; */
}

#select-power-options > li .status.used {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' %3E%3Cpath d='M20 6 9 17l-5-5'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

.control-pane .icon-button {
  margin: 0.25rem;
  user-select: none;
  font-size: 0.8rem;
  padding: 0.2rem 0.35rem;
}

.control-pane .icon-button.attachments-button {
  position: relative;
}

.control-pane .icon-button.attachments-button .attachment-count {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 0.5rem;
  color: white;
}

/* .control-pane .icon-button.attachments-button.has-attachments { */
/*   background: rgb(from var(--primary) r g b / 0.14); */
/*   box-shadow: inset 0 0 0 1px rgb(from var(--primary) r g b / 0.35); */
/* } */

.control-pane .icon-button.attachments-button:not(.has-attachments) .attachment-count {
  display: none;
}

.control-pane .icon-button.send {
  background: var(--primary);
  color: var(--color-1);
  font-size: 1rem;
  margin-left: auto;
}

.control-pane .icon-button[aria-busy=true] {
  font-size:0.8rem;
}

.control-pane .icon-button.send:hover {
  background: var(--primary) !important;
  color: var(--color) !important;
}

.page.embedded .control-pane .icon-button.scroll-top,
.page.embedded .control-pane .icon-button.scroll-bottom {
  display: none;
}

#home.auto-read-answer .control-pane .toggle-auto-read-answer svg[data-icon=speaker-muted],
#home:not(.auto-read-answer) .control-pane .toggle-auto-read-answer svg[data-icon=speaker] {
  display: none;
}

.control-pane .microphone {
  position: relative;
  width: fit-content;
  padding: 0;
}

.control-pane .microphone * {
  user-select: none;
}

.control-pane:has(.microphone .mic-button[aria-busy]) .microphone:not(:has(.mic-button[aria-busy])) {display:none;}

.control-pane .microphone .message {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  left: 50%;
  transform: translateX(-50%);
  width: min(90vw, 16rem);
  max-width: 16rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  border-radius: 0.9rem;
  background: rgba(22, 25, 30, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 0.6rem 1.5rem rgba(0, 0, 0, 0.45);
  font-size: 0.8rem;
  color: #e8e8e8;
  z-index: 30;
}

.control-pane .microphone .message:not(.shown) {
  display: none;
}

.control-pane .microphone .message.shown {
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.control-pane .microphone .message.dragging,
.control-pane .microphone .message.dragged {
  position: fixed;
  bottom: auto;
  right: auto;
  transform: none;
  z-index: 40;
}

.control-pane .microphone .message.dragging {
  cursor: grabbing;
}

.control-pane .microphone .message .live-transcript {
  width: 100%;
  margin: 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  min-height: 2.6rem;
  resize: none;
  overflow-y: auto;
}

.control-pane .microphone .message .live-transcript::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.control-pane .microphone .message .vol {
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  width: 100%;
  height: 2.4rem;
  margin: 0;
  padding: 0;
}

.control-pane .microphone .message .vol .bar {
  flex: 1 1 0;
  min-width: 0;
  height: 12%;
  min-height: 6px;
  border-radius: 0.2rem;
  background: linear-gradient(180deg, #58f0b0, #1fbf8f);
  box-shadow: 0 0 0.5rem rgba(88, 240, 176, 0.55);
  transition: height 0.08s ease-out;
}

.control-pane .microphone .message button {
  flex: 1;
  min-height: 2.4rem;
  border: none;
  border-radius: 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
}

.control-pane .microphone .message .cancel {
  background: rgba(255, 255, 255, 0.08);
  color: #cfcfcf;
}

.control-pane .microphone .message .end {
  background: rgba(214, 69, 69, 0.9);
  color: #fff;
}

.control-pane .microphone .message .send {
  background: #2f9bf0;
  color: #fff;
}

.control-pane .microphone .message button:hover {
  filter: brightness(1.1);
}

@media (max-width: 500px) {
  .control-pane .microphone .message {
    width: min(92vw, 15rem);
    padding: 0.6rem;
    gap: 0.45rem;
  }
  .control-pane .microphone .message button {
    min-height: 2.6rem;
    font-size: 0.85rem;
  }
}

/*
 * History pane
 */

.history-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin: 0 1rem;
}

/* Chat history */

.chat-history {
  flex: 1;
  border-radius: 0.25rem;
  margin: 0;
  padding: 0.5rem 0;
}

.chat-history .chat-message-controls .icon-button {
  font-size: 0.8rem;
  border-radius: 50%;
  background: var(--background-3);
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.chat-history .chat-message-controls .icon-button.copied {
  background: var(--color-3);
  color: var(--background-1);
  transform: scale(1.07);
}

.chat-history .chat-message {
  padding: 0 0 1rem 0;
  margin-bottom: 0.5rem;
  max-width:100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  font-size: var(--font-size);
}

.chat-history .chat-message.ignore {
  opacity: 0.6;
  background: #232c2d;
}

.chat-history .chat-message.ignore.right {
  border-radius: 0.5rem 0.5rem 0 0;
}
.chat-history .chat-message.ignore.left {
  border-radius: 0 0 0.5rem 0.5rem;
}

.chat-history:not(:has(.chat-message:not(.dummy))) .chat-message.dummy {
  display: none;
}

.chat-history .chat-message.collapsible {
  min-height: 2.5rem;
  overflow: hidden;
  position: relative;
}

.chat-history .chat-message.collapsible.collapsed {
  max-height: 40rem; /* preview height */
}

.chat-history .chat-message-toggle-collapse {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 1rem;
  border-radius: 0 0 0.5rem 0.5rem;
  background: linear-gradient(to bottom, transparent, var(--background-5));
  cursor: pointer;
}

.chat-history .chat-message-toggle-collapse:hover {
  background: linear-gradient(to bottom, transparent, #555, #666);
}

.chat-history .chat-message.collapsed .chat-message-toggle-collapse::before {
  content: "⌄";
  position: absolute;
  left: 50%;
  top: -0.4rem;
}

.chat-history .chat-message:not(.collapsed) .chat-message-toggle-collapse::before {
  content: "⌃";
  position: absolute;
  left: 50%;
}

.chat-history .chat-message-head {
  display: flex;
}

.chat-history .chat-message-icon {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0 0 auto 0;
  padding: 0;
  border-radius: 50%;
  background: var(--background-3);
}

.chat-history .chat-message.left .chat-message-icon {
  color: var(--primary);
}

.chat-history .chat-message.right .chat-message-icon {
  color: var(--color-2);
  font-size: 0.8rem;
}

.chat-history .chat-message.right .user-avatar {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  -webkit-mask-image: radial-gradient(circle, #000 60%, transparent 100%);
  mask-image: radial-gradient(circle, #000 60%, transparent 100%);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.chat-history .chat-message-controls {
  display: flex;
  flex-wrap: wrap;
}

.control-pane .chat-play {
  width: 2rem;
  height: 2rem;
  margin: 0.5rem auto;
  padding: 0;
  border-radius: 50%;
  background: var(--background-3);
  box-shadow: var(--background-3) 0 0 1rem 1rem;
}

.control-pane .chat-play:not(.active) {
  display: none;
}

.chat-history .chat-play {
  border-radius: 50%;
}

.control-pane .chat-play .loader-1 {
  width: 2rem;
  height: 2rem;
}

.control-pane .chat-play .loader-1::after,
.chat-history .chat-play .loader-1::after {
  background: var(--background-3);
}

.control-pane .chat-play:hover .loader-1::after,
.chat-history .chat-play:hover .loader-1::after {
  background: var(--color-3);
}

.control-pane .chat-play.playing svg[data-icon=play],
.control-pane .chat-play:not(.playing) svg[data-icon=pause],
.control-pane .chat-play:not(.playing) .loader-1,
.chat-history .chat-play.playing svg[data-icon=play],
.chat-history .chat-play:not(.playing) svg[data-icon=pause],
.chat-history .chat-play:not(.playing) .loader-1 {
  display: none;
}

.control-pane .chat-play[aria-busy=true] {
  padding: 0.15rem 0.375rem;
  font-size: 1.2rem;
}

.chat-history .chat-play[aria-busy=true] {
  padding: 0.2rem 0.35rem;
}

.control-pane .chat-play svg {
  width: 1.5rem;
  height: 1.5rem;
}

.control-pane .chat-play[aria-busy=true] svg,
.chat-history .chat-play[aria-busy=true] svg {
  display: none;
}

.chat-history .chat-message-agent,
.chat-history .chat-message-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  padding: 0 0 0 40px;
  min-width: 0;
  min-height: 0;
}

.chat-history .chat-message-head .chat-message-body {
  padding: 0 0.5rem;
}

.chat-history .chat-message:has(.chat-message-agent select.title.htmx-request) .chat-message-body>:not([aria-busy]) {
  display: none;
}

.chat-history .chat-message:not(:has(.chat-message-agent select.title.htmx-request)) .chat-message-body>[aria-busy] {
  display: none;
}

.chat-history .chat-message-body .context-source {
  font-size: 0.5rem;
  margin-bottom: 0.5rem;
  color: var(--color-2);
}

.chat-history .chat-message-agent {
  font-size: 0.7rem;
  padding: 0 0.5rem;
}

.chat-history .chat-message-agent .title {
  color: var(--color-3);
  font-size: 0.8em;
  font-style: italic;
}

.chat-history .chat-message-agent .description {
  color: var(--color-3);
  font-size: 0.6rem;
}

.chat-history .chat-message.dummy.agent .chat-message-controls,
.chat-history .chat-message.dummy.agent .chat-message-body,
.chat-history .chat-message.dummy.agent .chat-message-time {
  display: none;
}

.chat-history .chat-message-body .agent-response {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.chat-history .chat-message-body .agent-response .button{
  margin-left: -8px;
}

.chat-history .chat-message-body .agent-response > *:not(:last-child) {
  margin: 0 0 1rem 0;
}

.chat-history .chat-message-body .error {
  color: var(--color-red);
}

.chat-history .chat-message-body pre {
  /* font-family: Roboto, sans-serif; */
  margin: 0;
  color: var(--color);
  font-style: normal;
  font-weight: var(--font-weight);
  font-size: 0.8rem;
  line-height: unset;
  background: unset;
  white-space: pre-wrap;    /* Allows wrapping */
  overflow-wrap: break-word;  /* Break long words */
}

.chat-history .user-content {
  font-size: 0.7rem;
  color: var(--color-2);
}

/* .chat-history .markdown-content p { */
/*   color: var(--color-1); */
/* } */

.chat-history .markdown-content a {
  color: var(--link-color);
  text-decoration: underline;
  text-underline-offset: 0.12em;
  transition: color 120ms ease, background-color 120ms ease;
}

.chat-history .markdown-content a:hover {
  color: var(--color);
  background: var(--hover-color);
}

.markdown-content a.project-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.05em 0.4em;
  border-radius: 4px;
  border: 1px solid rgba(255, 127, 0, 0.4);
  background: var(--background-3);
  color: #ff7f00;
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
  transition: color 120ms ease,
              background-color 120ms ease,
              border-color 120ms ease;
}

.markdown-content a.project-link::after {
  content: "";
  flex: none;
  width: 0.9em;
  height: 0.9em;
  background-color: #ff7f00;
  -webkit-mask: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M18%2013v6a2%202%200%200%201-2%202H5a2%202%200%200%201-2-2V8a2%202%200%200%201%202-2h6'/%3E%3Cpolyline%20points='15%203%2021%203%2021%209'/%3E%3Cline%20x1='10'%20y1='14'%20x2='21'%20y2='3'/%3E%3C/svg%3E") no-repeat center / contain;
  mask: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M18%2013v6a2%202%200%200%201-2%202H5a2%202%200%200%201-2-2V8a2%202%200%200%201%202-2h6'/%3E%3Cpolyline%20points='15%203%2021%203%2021%209'/%3E%3Cline%20x1='10'%20y1='14'%20x2='21'%20y2='3'/%3E%3C/svg%3E") no-repeat center / contain;
  transition: background-color 120ms ease;
}

.markdown-content a.project-link:hover {
  color: #ff7f00;
  background: rgba(255, 127, 0, 0.15);
  border-color: #ff7f00;
}

.markdown-content a.project-link:hover::after {
  background-color: #ff7f00;
}

.chat-history .markdown-content .markdown-table-container {
  position: relative;
  padding-top: 0.5rem;
}

.chat-history .markdown-content .markdown-table-container .open-button {
  position: absolute;
  top: 0;
  right: 0;
  height: 1rem;
  font-size: 0.5rem;
  line-height: 1rem;
  background: var(--background-3);
  padding: 0 0.5rem;
  cursor: pointer;
}

.chat-history .markdown-content .markdown-table-container .open-button:hover {
  background: var(--hover-color);
}

.chat-history .chat-message-time {
  margin-top: 0.5rem;
  font-size: 0.5em;
  color: var(--color-2);
}

#home:not(.show-message-time) .chat-history .chat-message-time {
  display: none;
}

.chat-history .chat-message.left .chat-message-time {
  text-align: left;
}

.chat-history .chat-message.center .chat-message-body {
  background: #2a2f33;
}

.chat-history .chat-message.center .chat-message-time {
  text-align: center;
}

.chat-history .bullet-button {
  width: fit-content;
  padding: 0.1rem 0.5rem 0.1rem 0.1rem;
}

.chat-history .bullet-button .icon {
  height: 1.3rem;
  width: 1.3rem;
}

.chat-history .bullet-button .label {
  color: var(--color-2);
  font-size: 0.6rem;
  line-height: 1.3rem;
}

.chat-history .chat-project-separator {
  position: relative;
  margin: 1rem 0 0 0;
  border-top: 1px solid var(--border-color);
  height: 1rem;
}

.chat-history .chat-project-separator .label {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid var(--border-color);
  font-size: 0.5rem;
  color: var(--color-2);
  background: var(--background-3);
  border-radius: 0.5rem;
  line-height: 1rem;
  height: 1rem;
  padding: 0 1rem;
  width: fit-content;
}

.chat-history .chat-pending-requests {
  position: relative;
  margin: 1rem 0;
  display: flex;
  padding-left: 0.25rem;
}

.chat-history .chat-pending-requests [aria-busy] {
  font-size: 1rem;
}

.chat-history .chat-pending-requests .label {
  margin-left: 1rem;
  color: var(--color-2);
  font-style: italic;
  line-height: 1.5rem;
}

/* Attachments */

.chat-attachments,
.chat-history .agent-response .attachments {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  font-size: 0.7rem;
}

.chat-attachments .title,
.chat-history .attachments .title {
  position: absolute;
  font-size: 0.4rem;
  color: var(--color-2);
  left: 0.25rem;
  top: -0.5rem;
}

.chat-attachments .attachment-item,
.chat-history .attachment-item {
  display: inline-block;
  background: var(--background-3);
  border-radius: 0.24rem;
  padding: 0;
  margin: 0.1rem 0.25rem;
}

.chat-attachments .attachment-item .link,
.chat-history .attachment-item .link {
  padding: 0 0.5rem;
  color: var(--color-2);
}

.chat-attachments .attachment-item .icon-button,
.chat-history .attachment-item .icon-button {
  width: 1.25rem;
  height: 1.25rem;
  background: var(--background-3);
  font-size: 0.8rem;
  padding: 0;
  margin: 0;
}

.chat-attachments {
  padding: 0.25rem;
  background: var(--background-6);
  border-radius: 0.25rem;
}

#home:not(.show-artifacts-always) .chat-attachments:not(:has(.attachment-item)) {
  display: none;
}

.chat-attachments .file-input {
  margin-left: auto;
}

/* Images */

.chat-history figure.md.image .item .bar {
  background: var(--background-6);
}

/* Tables */

.chat-history .agent-response .tables {
  min-height: 0;
  min-width: 0;
  overflow: auto;
}

.chat-history .agent-response .tables .title {
  font-size: 0.5rem;
  color: var(--color-2);
}

.chat-history .agent-response .tables table {
  margin: 0;
  --table-border-color: none;
  --table-row-stripped-background-color: var(--background-1);
  --color: #E0E0E0;
  --line-height: 1.4;
}

/* .chat-history .agent-response .tables table tbody tr:nth-child(even) { */
/*   background-color: #2B2D2E; */
/* } */

.chat-history .agent-response .tables table tbody tr:nth-child(odd) {
  background-color: var(--table-row-stripped-background-color);
}

.chat-history .agent-response .tables table thead th,
.chat-history .agent-response .tables table thead td {
  color: var(--primary);
}

.chat-history .agent-response .tables table th {
  --font-size: 0.6rem;
  padding: 0.5rem;
}

.chat-history .agent-response .tables table td {
  --font-size: 0.6rem;
  padding: 0.5rem;
}

/* Checklist progress */

.chat-history .agent-checklist {
  font-size: 0.5rem;
}

.chat-history .agent-checklist:has(.progress-bar.complete) {
  display: none;
}

.chat-history .agent-checklist > * {
  margin-top: 0.25rem;
}

.chat-history .agent-checklist .overall {
  display: flex;
  flex-wrap: wrap;
}

.chat-history .agent-checklist .info {
  margin-left: 1rem;
}

.chat-history .agent-checklist .info:first-child {
  margin-left: auto;
}

.chat-history .agent-checklist .overall .info .label {
  padding: 0 0.2rem 0 0;
}

.chat-history .agent-checklist .overall .info .label::after {
  content: ":"
}

.chat-history .agent-checklist .overall .info .value {
  padding: 0;
  color: var(--color-green);
}

.chat-history .agent-checklist .progress-bar {
  position: relative;
  height: 1rem;
  margin: 0.5rem 0;
  background: var(--background-color-2);
  border-radius: var(--border-radius);
}

.chat-history .agent-checklist .progress-bar.complete {
  background: var(--color-green);
  opacity: 40%;
}

.chat-history .agent-checklist .progress-bar .bar {
  position: absolute;
  left: 0;
  background: var(--color-orange);
  height: 100%;
  min-width: 0.25rem;
  border-radius: inherit;
}

.chat-history .agent-checklist .task {
  position: relative;
  display: flex;
  padding: 0.5rem 0.25rem 0.5rem 2rem;
  color: var(--color-1);
}

.chat-history .agent-checklist .task .status {
  margin: 0;
  width: 1rem;
  height: 1rem;
  position: absolute;
  left: 0.5rem;
  top: 0.5rem;
  border-radius: 50%;
  background-color: var(--background-6);
  z-index: 1;
}

.chat-history .agent-checklist .task .status.complete {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-line-join='round' %3E%3Cpath d='M20 6 9 17l-5-5'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

.chat-history .agent-checklist .task .status[aria-busy=true] {
  padding-top: 0.14rem;
}

.chat-history .agent-checklist .task:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 1rem;
  top: 50%;
  height: 100%;
  border-left: 1px dashed var(--color-3);
}

.chat-history .agent-checklist .task .title {
  flex: 1;
  margin-left: 0.5rem;
  line-height: 1rem;
}

.chat-history .agent-checklist .task .title div {
  font-size: 0.8em;
  color: var(--color-2);
}

.chat-history .agent-checklist .task .time {
  color: var(--color);
  opacity: 40%;
}

/*
 * Dialogs
 */

dialog article footer {
  position: sticky;
  bottom: calc(-1 * var(--block-spacing-vertical));
}

dialog article select,
dialog article input:not([type=checkbox],[type=radio]),
dialog article textarea {
  margin-bottom: 0.25rem;
  margin-right: 0.25rem;
}

.file-list {
  padding: 0.5rem;
  margin-bottom: 0;
  max-height: 12rem;
  overflow-y: auto;
}

.file-list .file {
  display: flex;
  justify-content: space-between;
}

.file-list .remove {
  color: var(--asv-color-red);
  cursor: pointer;
  padding: 0 0.25rem;
  margin-left: 0.5rem;
  border-radius: 0.2rem;
  line-height: 1rem;
  font-weight: 700;
}

.file-list .remove:hover {
  background: var(--asv-color-red);
  color: white;
}

#attachments-dialog article {
  width: min(36rem, 90vw);
  box-sizing: border-box;
}

#attachments-dialog .attachments-drop-target {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  padding: 1.5rem;
  border: 2px dashed var(--border-color);
  border-radius: 0.6rem;
  color: var(--color-2);
  text-align: center;
  transition: border-color 0.15s, background-color 0.15s;
  cursor: pointer;
}

#attachments-dialog .attachments-drop-target strong {
  color: var(--color);
}

#attachments-dialog .attachments-drop-target span {
  font-size: 0.65rem;
}

#attachments-dialog .attachments-drop-target.dragging {
  border-color: var(--color-green);
  background-color: var(--color-hover);
}

#attachments-dialog .attachments-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
}

#attachments-dialog .attachments-option {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
}

#attachments-dialog .attachments-option input {
  margin: 0.5rem 0 0;
  font-size: 0.7rem;
}

#attachments-dialog .attachments-summary {
  margin-top: 0.75rem;
  color: var(--color-2);
  font-size: 0.7rem;
}

#attachments-dialog .attachments-summary.attachments-summary-error {
  color: var(--asv-color-red);
}

/* select agent dialog */

#select-project-dialog,
#select-agent-dialog {
  /* keep a sensible width that never exceeds the viewport */
  width: min(900px, 90vw);
  /* optional: center logic may live elsewhere */
  box-sizing: border-box;
}

#select-project-dialog article,
#select-agent-dialog article {
  display: flex;
  flex-direction: column;
  /* width constrained to the dialog box */
  max-width: 100%;
  /* height based on viewport HEIGHT, not width */
  max-height: min(80vh, 100dvh - 4rem);
  min-height: 1rem;
  box-sizing: border-box;
  /* padding: 0.5rem; */
}

#select-agent-dialog .select-agent-head {
  display: flex;
  margin-bottom: 0.5rem;
  flex: 0 0 auto;
}

#select-agent-dialog .select-agent-history {
  display: flex;
  margin-bottom: 0.5rem;
  flex: 0 0 auto;
  overflow: auto;
}

#select-agent-dialog .select-agent-history button {
  margin: 0 0.5rem;
  border: 1px solid var(--secondary);
}

#select-agent-dialog .select-agent-history button:not(:hover) {
  background: none;
}

#select-agent-dialog .select-agent-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 1rem;
  overflow: auto;          /* <-- scrolling content */
  min-block-size: 0;       /* avoid flex overflow in some browsers */
}

@media screen and (max-width:600px) {
  #select-agent-dialog .tool-list-box .tool-table,
  #select-agent-dialog .tool-list-box .tool-tbody {
    display: flex;
    flex-direction: column;
  }

  #select-agent-dialog .tool-list-box .tool-list-item-header,
  #select-agent-dialog .tool-list-box .tool-list-item {
    display: flex;
    flex-direction: column;
  }

  #select-agent-dialog .tool-list-box .tool-list-item .tool-title {
    border-bottom: none;
  }

  #select-agent-dialog .tool-list-box .tool-list-item.collapsed,
  #select-agent-dialog .tool-list-box .tool-list-item.hidden,
  #select-agent-dialog .tool-list-box .tool-list-item-header.hidden { display: none; }

  #manage-agent-dialog table,
  #manage-agent-dialog tbody {
    display: flex;
    flex-direction: column;
  }

  #manage-agent-dialog thead {
    display: none;
  }

  #manage-agent-dialog .tr-agent {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
  }

  #manage-agent-dialog .tr-agent td {
    display: flex;
    flex-direction: column;
    padding: 0;
  }

  #manage-agent-dialog .tr-agent td:first-child {
    font-weight: 600;
    font-size: 0.65rem;
  }

  #manage-agent-dialog .tr-agent td .icon-button {
    align-self: flex-end;
  }

  #manage-agent-dialog .tr-agent td select {
    max-width: unset;
  }

}

#select-agent-dialog .tool-list-box .tool-list-item {
  user-select: none;
}

#select-agent-dialog .tool-list-box .tool-list-item.selected {
  background: var(--background-6);
}

#select-agent-dialog .tool-list-box .tool-list-item .tool-title {
  position: relative;
  padding-right: 5rem;
}

#select-agent-dialog .warning {
  color: gold;
}

#select-agent-dialog .warning:not([data-warning]) {
  display: none;
}

#select-agent-dialog .tool-list-box .tool-list-item .use-count {
  position: absolute;
  top: 0.25rem;
  right: 0;
  display: flex;
}

#select-agent-dialog .tool-list-box .tool-list-item .use-count input {
  width: 1.5rem;
  padding: 0;
  margin: 0;
  text-align: center;
  user-select:none;
  background: var(--color-2);
  color: var(--background-3);
}

#select-agent-dialog .tool-list-box .tool-list-item .use-count input[value='0'] {
  background: unset;
}

#select-agent-dialog .tool-list-box .tool-list-item .tool-description {
  padding-left: 0.25rem;
}

/* agent warning dialog */

#agent-warning-dialog article {
  min-width: 30%;
}

/* manage agent dialog */

#manage-agent-dialog {
  width: min(1000px, 92vw);
  box-sizing: border-box;
}

#manage-agent-dialog > article {
  /* max-width: 100%; */
  /* max-height: min(86vh, 100dvh - 3rem); */
  width: 80vw;
  display: flex;
  flex-direction: column;
  height: 80%;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.35);
}

@media screen and (max-width:900px) {
  #manage-agent-dialog > article {
    width: 800px;
  }
}

@media screen and (max-width:600px) {
  #manage-agent-dialog > article {
    width: 550px;
    height: 95%;
  }
}

#manage-agent-dialog .manage-agent-dialog-header {
  margin: calc(-1 * var(--block-spacing-vertical)) calc(-1 * var(--block-spacing-horizontal)) 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--background-2);
}

#manage-agent-dialog .manage-agent-dialog-header h2 {
  margin: 0;
  color: var(--color-1);
  letter-spacing: 0.02em;
}

#manage-agent-dialog .manage-agent-dialog-body {
  overflow: auto;
}

#manage-agent-dialog .conversation-fields {
  display: flex;
  flex-direction: column;
}

#manage-agent-dialog .conversation-fields input,
#manage-agent-dialog .conversation-fields select {
  width: unset;
  max-width: unset;
  background-color: var(--background-12);
}

#manage-agent-dialog .manage-agent-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}

#manage-agent-dialog thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-3);
  border-bottom: 1px solid var(--border-color);
}

#manage-agent-dialog .tr-no-agents td {
  font-style: italic;
  color: silver;
  font-size: 0.7rem;
  padding: 1rem;
}

#manage-agent-dialog:has(.tr-agent) .tr-no-agents {
  display: none;
}

#manage-agent-dialog .tr-agent {
  background: var(--background-1);
}

#manage-agent-dialog .tr-agent:nth-child(even) {
  background: var(--background-2);
}

#manage-agent-dialog .tr-agent td {
  vertical-align: top;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

#manage-agent-dialog .tr-agent td.id {
  padding: 0.5rem;
  color: var(--color-2);
  font-size: 0.6rem;
}

#manage-agent-dialog .tr-agent .warning {
  color: gold;
}

#manage-agent-dialog .tr-agent .warning:not([data-warning]) {
  display: none;
}

#manage-agent-dialog .tr-agent td .agent-picker {
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--color-1);
  min-width: 8rem;
  max-width: 10rem;
  word-break: break-word;
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  background: var(--background-12);
  padding: 0.25rem 0.5rem;
}

#manage-agent-dialog .tr-agent input,
#manage-agent-dialog .tr-agent textarea,
#manage-agent-dialog .tr-agent select {
  margin: 0;
  background-color: var(--background-12);
  width: 100%;
}

#manage-agent-dialog .tr-agent textarea[name=system-prompt] {
  min-width: 8rem;
  max-width: 16rem;
  min-height: 3.5rem;
}

#manage-agent-dialog .tr-agent input[name=group] {
  max-width: 7rem;
}

#manage-agent-dialog .tr-agent input[name=title] {
  min-width: 8rem;
  /* width: min(8rem, 100%); */
}

#manage-agent-dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.75rem;
}

#manage-agent-dialog .profile-picker {
  display: flex;
  width: 100%;
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  background: var(--background-12);
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
}

#manage-agent-dialog .profile-picker-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-1);
}

#manage-agent-dialog .profile-none {
  color: var(--color-3);
}

/**** Loading response ***/

.reveal-animation {
  animation-duration: 1s;
  animation-name: reveal-animation-fade;
  animation-delay: 0.1s;
  animation-fill-mode: backwards;
}

@keyframes reveal-animation-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/*.sidebar-leaf .label {
  overflow: hidden;
  display: inline-block;
  white-space: nowrap;
  text-overflow: ellipsis;
}
*/

.chat-history .chat-message-body .collapse {
  max-width: 52rem;
  width: 100%;
}

.chat-history .chat-message-body .collapse-body {
  padding: 0.75rem 0.75rem 0.75rem 0;
  font-size: 0.8em;
}

.chat-history .chat-message-body .collapse:not(.is-open) .collapse-body {
  display: none;
}

.chat-history .chat-message-body .collapse-body .reasoning-block {
  position: relative;
  padding: 0.25rem 0 0.25rem 1.25rem;
  color: rgba(255,255,255,0.85);
  line-height: 1.45;
}

.chat-history .chat-message-body .collapse-body .reasoning-block::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.2rem;
  bottom: 0.2rem;
  width: 3px;
  border-radius: 999px;
  background: rgba(255,255,255,0.22);
}

.chat-history .chat-message-body .reasoning-wrap {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.75rem 0.75rem 0;
  align-items: flex-start;
}

.chat-history .chat-message-body .reasoning-bar {
  width: 3px;
  border-radius: 999px;
  background: rgba(255,255,255,0.22);
  align-self: stretch;
  min-height: 1.2rem;
}

.chat-history .chat-message-body .reasoning-text {
  color: rgba(255,255,255,0.85);
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-history .chat-message-body .hidden { display: none; }

.chat-history .chat-message-body .collapse-head {
  display: flex;
  justify-content: normal;
  align-items: left;
  cursor: pointer;
  user-select: none;
  font-size: 0.7rem;
  color: var(--color-2);
  padding: 0.5rem 0.1rem 0.9rem;
  border-radius: 0.5rem;
  gap: 0.3rem;
  background: transparent;
  transition: background-color 120ms ease, transform 120ms ease;
}

.chat-history .chat-message-body .collapse-head:hover {
  background-color: var(--background-3);
}

.chat-history .chat-message-body .collapse-head:hover .collapse-title {
  color: var(--primary);
}

.chat-history .chat-message-body .collapse-head:hover .collapse-icon {
  transform: translateY(-1px);
}

.chat-history .chat-message-body .collapse.is-open .collapse-icon {
  transform: rotate(180deg);
}

.chat-history .chat-message-body .collapse-icon {
  transition: transform 150ms ease;
}

#agent-profile-dialog article {
  min-width: 15rem;
}

#agent-profile-dialog .profile-group-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-3);
  margin: 0.5rem 0.125rem 0.125rem;
}

#agent-profile-dialog .profile-group:first-child .profile-group-label,
#agent-profile-dialog .profile-group-label:first-child {
  margin-top: 0;
}

#agent-profile-dialog .profile-option {
  display: block;
  padding: 0.2rem 0.25rem;
  cursor: pointer;
}

#agent-profile-dialog .profile-option:hover {
  background: rgba(115, 130, 140, 0.12);
}

#agent-profile-dialog .profile-option input[type=checkbox] {
  width: 0.875em;
  height: 0.875em;
  margin: 0 0.5rem 0 0;
}

#agent-profile-dialog .profile-option .profile-title {
  font-weight: 600;
  color: var(--color-1);
}

#agent-profile-dialog .profile-option .profile-desc {
  display: block;
  font-size: 0.75rem;
  color: var(--color-3);
}

/* Chat attachment input buttons (add file / camera) */
.chat-attachment-inputs {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}
.chat-attachments .file-input {
  margin-left: 0;
}
