/*
  filename: agent-builder.css
  description: Styles for the Agent Builder chat panel (hero meta pills, suggested-prompt chips, message list, composer, tool-call cards).
  Author: Rodrigo Careaga
  Date: 03-05-2026
*/

/* ============================================================ Hero meta */
.ab-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.ab-pill {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--ink);
  letter-spacing: 0.01em;
}
.ab-pill-muted { color: var(--muted); }
.ab-pill-ok { background: var(--teal-soft); border-color: rgba(0, 191, 179, 0.45); color: var(--teal); }
[data-theme="dark"] .ab-pill-ok { color: #b9f5ed; }
.ab-pill-err { background: rgba(255, 102, 102, 0.18); border-color: rgba(255, 102, 102, 0.45); color: #c2185b; }
[data-theme="dark"] .ab-pill-err { color: #ffc1c1; }
.ab-pill-link { text-decoration: none; }
.ab-pill-link:hover { background: var(--panel-3); }

/* ============================================================ Workbench layout (sidebar + main) */
.ab-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 22px;
  margin-top: 22px;
  align-items: start;
}
.ab-sidebar {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  padding: 14px;
}
.ab-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.ab-sidebar-title {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.ab-sidebar-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ab-sidebar-kibana {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--primary);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(0, 119, 204, 0.35);
  background: transparent;
  white-space: nowrap;
  transition: background 0.15s;
}
.ab-sidebar-kibana:hover { background: var(--primary-soft); }
[data-theme="dark"] .ab-sidebar-kibana { color: #6cb5ff; border-color: rgba(108, 181, 255, 0.4); }
.ab-new-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(0, 119, 204, 0.4);
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
[data-theme="dark"] .ab-new-btn { color: var(--white); }
.ab-new-btn:hover { background: rgba(0, 119, 204, 0.22); }
.ab-sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ab-agent-card {
  position: relative;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.ab-agent-card:hover { background: var(--panel-3); }
.ab-agent-card.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.18);
  background: var(--panel-3);
}
.ab-agent-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ab-agent-name {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
}
.ab-agent-pill {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ab-agent-pill-master {
  background: var(--teal-soft);
  color: var(--teal);
  border: 1px solid rgba(0, 191, 179, 0.45);
}
[data-theme="dark"] .ab-agent-pill-master { color: #b9f5ed; }
.ab-agent-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}
.ab-agent-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
}
.ab-agent-desc {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ab-agent-trash {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ab-agent-trash:hover {
  color: var(--red, #c2185b);
  border-color: rgba(255, 102, 102, 0.45);
  background: rgba(255, 102, 102, 0.10);
}

.ab-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.ab-empty-sm {
  font-size: 12px;
  padding: 10px 12px;
  color: var(--muted);
  text-align: center;
}

/* ============================================================ Suggested chips */
.ab-suggested {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}
.ab-chip {
  appearance: none;
  cursor: pointer;
  font: 500 12.5px/1.2 inherit;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--primary-soft);
  border: 1px solid rgba(0, 119, 204, 0.4);
  color: var(--primary);
  transition: background .15s, transform .1s;
}
[data-theme="dark"] .ab-chip { color: var(--white); }
.ab-chip:hover { background: rgba(0, 119, 204, 0.22); }
.ab-chip:active { transform: scale(0.98); }

/* ============================================================ Chat surface */
.ab-chat {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 200px;
  margin: 12px 0 16px;
}
.ab-msg {
  border-radius: 14px;
  padding: 14px 18px;
  max-width: 100%;
  border: 1px solid var(--border-soft);
}
.ab-msg-user {
  background: rgba(0, 119, 204, 0.13);
  border-color: rgba(0, 119, 204, 0.35);
  align-self: flex-end;
  max-width: 80%;
}
.ab-msg-assistant {
  background: var(--panel-2);
}
.ab-msg-role {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.ab-msg-body {
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
}
.ab-msg-body code {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.ab-msg-body pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--code-border);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
}

/* ============================================================ Steps card */
.ab-steps {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}
.ab-step {
  display: flex;
  gap: 10px;
  font-size: 12.5px;
  color: var(--ink-2);
  padding: 6px 0;
}
.ab-step-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  background: var(--teal-soft);
  color: var(--teal);
}
[data-theme="dark"] .ab-step-icon { color: #b9f5ed; }
.ab-step-toolcall .ab-step-icon { background: var(--yellow-soft); color: #b6890a; }
[data-theme="dark"] .ab-step-toolcall .ab-step-icon { color: #ffe18a; }
.ab-step-reasoning .ab-step-icon { background: var(--blue-soft); color: var(--blue); }
[data-theme="dark"] .ab-step-reasoning .ab-step-icon { color: #b8e2ff; }
.ab-step-name { font-weight: 600; color: var(--ink); }
.ab-step-body { flex: 1; min-width: 0; }
.ab-step-detail {
  margin-top: 4px;
  background: var(--code-bg);
  padding: 8px 10px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--code-fg);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.ab-msg-stats {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

/* ============================================================ Composer */
.ab-composer {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  margin-bottom: 30px;
}
.ab-input-wrap textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font: 14.5px/1.4 Inter, system-ui, sans-serif;
}
.ab-input-wrap textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.18);
}
.ab-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.ab-hint {
  margin: 0;
  text-align: right;
  font-size: 11.5px;
  color: var(--muted);
}

/* ============================================================ Loader */
.ab-loader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.ab-loader::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--primary-hi);
  animation: ab-spin 0.7s linear infinite;
}
@keyframes ab-spin { to { transform: rotate(360deg); } }

/* ============================================================ Empty state */
.ab-empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--muted);
  font-size: 13.5px;
  border: 1px dashed var(--border);
  border-radius: 12px;
}

/* ============================================================ Mini (inline embeds) */
.abm-host {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  margin-top: 18px;
  border: 1px solid rgba(0, 119, 204, 0.35);
  background: linear-gradient(180deg, rgba(0, 119, 204, 0.08), rgba(0, 119, 204, 0.02));
  border-radius: 14px;
}
.abm-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.abm-title {
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
}
.abm-context-chip {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--teal-soft);
  border: 1px solid rgba(0, 191, 179, 0.35);
  color: var(--teal);
}
[data-theme="dark"] .abm-context-chip { color: #b9f5ed; }
.abm-reset {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
}
.abm-reset:hover { background: var(--panel-2); color: var(--ink); }

.abm-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.abm-chip {
  font: 500 11.5px/1.2 inherit;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--primary-soft);
  border: 1px solid rgba(0, 119, 204, 0.4);
  color: var(--primary);
  cursor: pointer;
}
[data-theme="dark"] .abm-chip { color: var(--white); }
.abm-chip:hover { background: rgba(0, 119, 204, 0.24); }

.abm-chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 460px;
  overflow-y: auto;
  padding-right: 4px;
}
.abm-chat:empty { display: none; }

.abm-msg {
  border-radius: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border-soft);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
}
.abm-msg-user {
  background: rgba(0, 119, 204, 0.15);
  border-color: rgba(0, 119, 204, 0.4);
  align-self: flex-end;
  max-width: 86%;
}
.abm-msg-assistant { background: var(--panel-2); }
.abm-msg-body code {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}
.abm-msg-body pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--code-border);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12px;
}
.abm-msg-stats {
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--muted);
}
.abm-error { color: #c2185b; }
[data-theme="dark"] .abm-error { color: #ffc1c1; }

.abm-steps {
  margin-top: 6px;
  font-size: 12px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 8px;
  padding: 6px 8px;
}
.abm-steps summary { cursor: pointer; color: var(--muted); }
.abm-step { display: flex; gap: 8px; padding: 4px 0; }
.abm-step-num {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--teal-soft);
  font-size: 10px;
  font-weight: 700;
  color: var(--teal);
  flex: 0 0 18px;
}
[data-theme="dark"] .abm-step-num { color: #b9f5ed; }
.abm-step-toolcall .abm-step-num { background: var(--yellow-soft); color: #b6890a; }
[data-theme="dark"] .abm-step-toolcall .abm-step-num { color: #ffe18a; }
.abm-step-detail {
  margin-top: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 6px 8px;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}

.abm-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}
.abm-input {
  resize: vertical;
  min-height: 44px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font: 13px/1.4 Inter, system-ui, sans-serif;
}
.abm-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.18);
}
.abm-send { padding: 8px 16px; }

.abm-loader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}
.abm-loader::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--primary-hi);
  animation: ab-spin 0.7s linear infinite;
}

.abm-export-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.abm-export-btn {
  font: 500 11px/1.2 inherit;
  padding: 4px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.15s;
}
.abm-export-btn:hover { background: var(--panel-3); color: var(--ink); }

/* ============================================================ Demo Data cards */
.dd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  margin-top: 20px;
  margin-bottom: 30px;
}
.dd-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0, 119, 204, 0.08), rgba(0, 119, 204, 0.02)), var(--panel);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dd-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.dd-icon { font-size: 28px; }
.dd-title { margin: 0; font-size: 17px; color: var(--ink); }
.dd-desc {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 0;
}
.dd-indices {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}
.dd-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}
.dd-status {
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
}
.dd-status.running { color: var(--yellow); }
.dd-status.ok { color: var(--teal); }
.dd-status.err { color: var(--red); }

/* ============================================================ Modal: create agent */
.ab-modal[hidden] { display: none; }
.ab-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.ab-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 16, 32, 0.55);
  backdrop-filter: blur(2px);
}
.ab-modal-card {
  position: relative;
  width: min(1080px, 95vw);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 28px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.ab-modal-card * { box-sizing: border-box; }
.ab-modal-card textarea, .ab-modal-card input { max-width: 100%; }
.ab-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.ab-modal-head h3 {
  margin: 0;
  font-size: 18px;
  color: var(--ink);
}
.ab-modal-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.ab-modal-close:hover { background: var(--panel-3); color: var(--ink); }
.ab-modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ab-modal-form .ab-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 700px) {
  .ab-modal-form .ab-field-row { grid-template-columns: 1fr; }
}
.ab-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.ab-field-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.ab-counter {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.ab-field input[type="text"],
.ab-field textarea {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font: 13.5px/1.45 Inter, system-ui, sans-serif;
  width: 100%;
}
.ab-field input[type="text"]:focus,
.ab-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.18);
}
.ab-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important;
  font-size: 12.5px !important;
  line-height: 1.5 !important;
}
.ab-slug-row {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}
.ab-slug-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.18);
}
.ab-slug-prefix {
  padding: 9px 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  background: var(--panel-2);
  color: var(--muted);
  border-right: 1px solid var(--border);
}
.ab-slug-row input {
  border: 0 !important;
  border-radius: 0 !important;
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important;
  font-size: 12.5px !important;
}
.ab-slug-row input:focus { box-shadow: none !important; }
.ab-tools-field { border: 0; padding: 0; margin: 0; }

/* Recommended bundles: chip row above the search input. */
.ab-tool-bundles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.ab-tool-bundle {
  appearance: none;
  cursor: pointer;
  font: 600 11.5px/1 inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--teal-soft);
  border: 1px solid rgba(0, 191, 179, 0.4);
  color: var(--teal);
  transition: background .12s, transform .1s;
}
[data-theme="dark"] .ab-tool-bundle { color: #b9f5ed; }
.ab-tool-bundle:hover { background: rgba(0, 191, 179, 0.22); }
.ab-tool-bundle:active { transform: scale(0.97); }

/* Search input above the tool list. */
.ab-tool-search {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}
.ab-tool-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.ab-tool-search input[type="search"] {
  width: 100%;
  padding: 8px 32px 8px 30px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: 13px/1.4 Inter, system-ui, sans-serif;
}
.ab-tool-search input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.18);
}
/* Hide the native clear button so our own X is the single affordance. */
.ab-tool-search input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.ab-tool-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.ab-tool-search-clear:hover { background: var(--panel-3); color: var(--ink); }

/* Tool list container: scrollable, grouped by category. */
.ab-tools-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 460px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}
.ab-tool-section-rows {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 8px;
}
@media (max-width: 720px) {
  .ab-tool-section-rows { grid-template-columns: 1fr; }
}

/* Section: header with title, count, and a Select all link. */
.ab-tool-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ab-tool-section.is-hidden { display: none; }
.ab-tool-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px 2px;
}
.ab-tool-section-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.ab-tool-section-count {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--ink-2);
  letter-spacing: 0;
}
.ab-tool-section-select {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--primary);
  font: 500 11px/1 inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
[data-theme="dark"] .ab-tool-section-select { color: var(--white); }
.ab-tool-section-select:hover { background: var(--primary-soft); }

/* Per-tool card layout: checkbox, id + pill, one-line description. */
.ab-tool-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  transition: border-color .12s, background .12s;
}
.ab-tool-row:hover { border-color: var(--primary); background: var(--panel-3); }
.ab-tool-row.is-hidden { display: none; }
.ab-tool-row input[type="checkbox"] {
  margin: 2px 0 0;
  flex: 0 0 auto;
}
.ab-tool-row-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}
.ab-tool-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ab-tool-row-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
}
.ab-tool-row-pill {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(0, 119, 204, 0.4);
}
[data-theme="dark"] .ab-tool-row-pill { color: var(--white); }
.ab-tool-row-desc {
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

/* Sticky bottom counter: how many tools the user has selected. */
.ab-tool-counter {
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: right;
}
.ab-field-error {
  font-size: 11.5px;
  color: var(--red, #c2185b);
  min-height: 0;
}
[data-theme="dark"] .ab-field-error { color: #ffc1c1; }
.ab-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}
.ab-modal-status {
  margin: 0;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
}
.ab-modal-status.is-err { color: var(--red, #c2185b); }
[data-theme="dark"] .ab-modal-status.is-err { color: #ffc1c1; }

/* ============================================================ Responsive: tablet (769-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .dd-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================ Responsive: workbench breakpoint (<= 900px) */
@media (max-width: 900px) {
  .ab-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .ab-sidebar {
    position: static;
    max-height: none;
    padding: 12px;
  }
  .ab-sidebar-list {
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
  }
  .ab-agent-card {
    flex: 0 0 240px;
    scroll-snap-align: start;
  }
  .ab-agent-desc { -webkit-line-clamp: 1; }
  .ab-tools-grid { max-height: 260px; }
}

/* ============================================================ Responsive: mobile (<= 768px) */
@media (max-width: 768px) {
  /* Suggested chips: full-width tappable rows so prompts are not 12px wide. */
  .ab-suggested { flex-direction: column; align-items: stretch; gap: 8px; }
  .ab-chip { width: 100%; padding: 12px 14px; font-size: 13.5px; text-align: left; min-height: 44px; }

  /* Chat surface: messages take full width; user bubble loses 80% cap. */
  .ab-msg-user, .ab-msg-assistant { max-width: 100%; align-self: stretch; }
  .ab-msg { padding: 12px 14px; }
  .ab-msg-body { font-size: 14px; }

  /* Composer stays full width, send button wraps below. */
  .ab-composer { padding: 12px; gap: 8px; }
  .ab-actions { flex-wrap: wrap; justify-content: stretch; }
  .ab-actions .btn { flex: 1 1 auto; }

  /* Mini embed: composer becomes single column. */
  .abm-host { padding: 12px; }
  .abm-composer { grid-template-columns: 1fr; }
  .abm-send { width: 100%; min-height: 44px; }
  .abm-suggestions { flex-direction: column; align-items: stretch; }
  .abm-chip { width: 100%; text-align: left; padding: 10px 12px; font-size: 12.5px; min-height: 40px; }
  .abm-chat { max-height: none; }

  /* Demo data cards: single column, comfortable padding. */
  .dd-grid { grid-template-columns: 1fr; gap: 14px; }
  .dd-card { padding: 16px; }
  .dd-actions { flex-wrap: wrap; }
  .dd-actions .btn { flex: 1 1 auto; }

  /* Modal close (create / edit agent dialog): inflate to 36 px square plus
     a transparent hit pad so total touch area clears 44 px. */
  .ab-modal-card { padding: 22px 18px 18px; }
  .ab-modal-close {
    position: relative;
    width: 36px;
    height: 36px;
  }
  .ab-modal-close::before { content: ""; position: absolute; inset: -4px; }
  .ab-modal-actions { flex-wrap: wrap; }
  .ab-modal-actions .btn { flex: 1 1 auto; min-height: 44px; }

  /* Agent list trash icon. Visual stays 32x32; ::before pseudo doubles the
     tappable area without growing the rendered button. */
  .ab-agent-trash {
    position: absolute;
    width: 32px;
    height: 32px;
  }
  .ab-agent-trash::before { content: ""; position: absolute; inset: -6px; }

  /* Tool bundle and tool-section-select buttons sit on a chip row; ensure
     they clear 36 px on mobile. */
  .ab-tool-bundle { padding: 8px 12px; min-height: 36px; }
  .ab-tool-section-select { padding: 8px 6px; min-height: 36px; }
  .ab-tool-search-clear {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }
  .ab-tool-search-clear::before { content: ""; position: absolute; inset: -8px; }
  .ab-tool-search input[type="search"] { font-size: 14px; min-height: 44px; }
}

/* ============================================================ Selected tools summary */
.ab-selected-summary {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ab-selected-empty {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 8px 4px;
}
.ab-selected-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ab-selected-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.ab-selected-count {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(0, 119, 204, 0.32);
}
[data-theme="dark"] .ab-selected-count { color: #9fd1ff; }
.ab-selected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ab-selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font: 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink);
}
.ab-selected-chip-cat {
  font-family: Inter, system-ui, sans-serif;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--primary-soft);
  color: var(--primary);
}
.ab-selected-chip[data-cat="research"] .ab-selected-chip-cat { background: rgba(0, 191, 179, 0.18); color: var(--teal); }
.ab-selected-chip[data-cat="compete"]  .ab-selected-chip-cat { background: rgba(240, 78, 152, 0.18); color: var(--pink); }
.ab-selected-chip[data-cat="sizing"]   .ab-selected-chip-cat { background: rgba(254, 197, 20, 0.22); color: #b58504; }
.ab-selected-chip[data-cat="build"]    .ab-selected-chip-cat { background: rgba(27, 169, 245, 0.20); color: var(--blue); }
[data-theme="dark"] .ab-selected-chip[data-cat="sizing"] .ab-selected-chip-cat { color: var(--yellow); }
.ab-selected-chip-id { color: var(--ink); }
.ab-selected-chip-remove {
  appearance: none;
  background: transparent;
  border: 0;
  cursor: pointer;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  font: 700 11px/1 Inter, sans-serif;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.ab-selected-chip-remove:hover {
  background: rgba(220, 38, 38, 0.16);
  color: #ff5b6f;
}

/* ============================================================ Markdown rendering inside chat
   The standalone agent-builder chat (.ab-msg-body) and the embedded mini
   chat (.abm-msg-body) both run rendered HTML through renderMarkdown.
   These rules style headings, lists, blockquotes, hr, and paragraphs so
   the rendered output reads cleanly inside the chat bubble. */
.ab-msg-body h1, .abm-msg-body h1 { font-size: 18px; font-weight: 700; margin: 12px 0 6px; line-height: 1.25; }
.ab-msg-body h2, .abm-msg-body h2 { font-size: 16px; font-weight: 700; margin: 12px 0 6px; line-height: 1.3; color: var(--primary); }
.ab-msg-body h3, .abm-msg-body h3 { font-size: 14px; font-weight: 700; margin: 10px 0 4px; line-height: 1.3; }
.ab-msg-body h4, .abm-msg-body h4,
.ab-msg-body h5, .abm-msg-body h5,
.ab-msg-body h6, .abm-msg-body h6 { font-size: 13px; font-weight: 700; margin: 8px 0 4px; }
.ab-msg-body p, .abm-msg-body p { margin: 0 0 10px; line-height: 1.55; }
.ab-msg-body p:last-child, .abm-msg-body p:last-child { margin-bottom: 0; }
.ab-msg-body ul, .abm-msg-body ul,
.ab-msg-body ol, .abm-msg-body ol { margin: 6px 0 12px; padding-left: 22px; }
.ab-msg-body li, .abm-msg-body li { margin: 3px 0; line-height: 1.5; }
.ab-msg-body strong, .abm-msg-body strong { color: var(--ink); font-weight: 700; }
.ab-msg-body em, .abm-msg-body em { font-style: italic; }
.ab-msg-body a, .abm-msg-body a { color: var(--primary); text-decoration: underline; }
.ab-msg-body a:hover, .abm-msg-body a:hover { text-decoration: none; }
.ab-msg-body blockquote, .abm-msg-body blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--primary);
  background: var(--panel-2);
  color: var(--ink-2);
  border-radius: 0 6px 6px 0;
  font-style: italic;
}
.ab-msg-body hr, .abm-msg-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
