.agent-top-bar {
  position: absolute;
  top: 16px;
  right: 24px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-history-hint {
  font-size: 0.8rem;
  color: var(--text-muted, #94a3b8);
  margin: 0 0 12px;
  padding: 0 4px;
  line-height: 1.4;
}

.history-list-inner {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.history-list-inner li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted, #94a3b8);
  margin-bottom: 2px;
}

.history-list-inner li:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text, #e0e7ff);
}

.history-list-inner li.active {
  background: rgba(161, 161, 170, 0.15);
  color: var(--text, #e0e7ff);
  font-weight: 600;
}

.history-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-delete {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 4px;
  opacity: 0.5;
}

.history-item-delete:hover {
  opacity: 1;
  color: #ff4757;
}

.agent-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted, #94a3b8);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  user-select: none;
}

.agent-mode-toggle input {
  accent-color: #a1a1aa;
  cursor: pointer;
}

.agent-mode-toggle.is-on {
  color: var(--text, #e0e7ff);
  border-color: rgba(161, 161, 170, 0.45);
}

.agent-steps {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: var(--text-muted, #94a3b8);
}

.agent-steps summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.agent-steps summary::-webkit-details-marker {
  display: none;
}

.agent-steps ol {
  margin: 8px 0 0;
  padding-left: 1.2rem;
}

.agent-steps li {
  margin-bottom: 4px;
  line-height: 1.35;
}

.agent-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding-top: 88px;
  padding-bottom: 48px;
}

.agent-header {
  margin-bottom: 28px;
}

.agent-header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.agent-header p {
  color: var(--text-muted);
  max-width: 640px;
}

.agent-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 960px) {
  .agent-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.panel-body { padding: 20px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.status-pill.online { color: var(--green); border-color: rgba(16, 185, 129, 0.4); }
.status-pill.offline { color: var(--red); border-color: rgba(239, 68, 68, 0.4); }

.agent-window {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  min-height: 480px;
}

.agent-window .panel-header {
  flex: 0 0 auto !important;
  padding: 10px 16px;
}

.agent-messages {
  flex: 1 1 0% !important;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.agent-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.2), rgba(59, 130, 246, 0.2));
  border: 1px solid rgba(0, 212, 255, 0.35);
}

.agent-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

.agent-bubble.system {
  align-self: center;
  max-width: 100%;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: transparent;
  border: none;
  padding: 4px;
}

.agent-input-row {
  flex: 0 0 auto !important;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.6);
}

.agent-input-row textarea,
.agent-input-controls textarea {
  flex: 1;
  resize: none;
  min-height: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
}

.agent-input-row textarea:focus,
.agent-input-controls textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.12);
}

.agent-input-row #agent-send {
  align-self: flex-end;
}

.agent-input-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.agent-input-controls {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.btn-icon {
  flex: 0 0 auto;
  align-self: flex-end;
  min-width: 44px;
  padding: 10px 12px;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.image-attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-attach-preview[hidden] {
  display: none !important;
}

.image-attach-thumb,
.agent-bubble-image {
  max-width: 120px;
  max-height: 120px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--bg-primary);
}

.agent-bubble-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.agent-bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-bubble-markdown {
  white-space: normal;
}

.agent-markdown > :first-child {
  margin-top: 0;
}

.agent-markdown > :last-child {
  margin-bottom: 0;
}

.agent-markdown p,
.agent-markdown ul,
.agent-markdown ol,
.agent-markdown blockquote,
.agent-markdown pre {
  margin: 0 0 0.75rem;
}

.agent-markdown h1,
.agent-markdown h2,
.agent-markdown h3 {
  margin: 0 0 0.5rem;
  line-height: 1.3;
  font-weight: 700;
}

.agent-markdown h1 { font-size: 1.15rem; }
.agent-markdown h2 { font-size: 1.05rem; }
.agent-markdown h3 { font-size: 0.98rem; }

.agent-markdown ul,
.agent-markdown ol {
  padding-left: 1.25rem;
}

.agent-markdown li + li {
  margin-top: 0.25rem;
}

.agent-markdown blockquote {
  padding-left: 0.85rem;
  border-left: 3px solid rgba(0, 212, 255, 0.35);
  color: var(--text-muted);
}

.agent-markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
}

/* Fenced blocks reuse SDK .code-block highlighting (keyword/string/comment/function) */
.agent-markdown pre,
.agent-markdown pre.code-block {
  position: relative;
  overflow-x: auto;
  margin: 0 0 0.75rem;
  padding: 2rem 0.9rem 0.75rem;
  border-radius: 10px;
  background: #111827;
  border: 1px solid rgba(0, 212, 255, 0.35);
  color: #e2e8f0;
  font-family: 'Fira Code', 'Consolas', ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  white-space: pre;
  word-wrap: normal;
}

.agent-markdown pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  white-space: pre;
}

.agent-markdown pre .comment { color: #94a3b8; }
.agent-markdown pre .keyword { color: #c4b5fd; font-weight: 600; }
.agent-markdown pre .string { color: #6ee7b7; }
.agent-markdown pre .function { color: #7dd3fc; font-weight: 600; }

.agent-markdown a {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.agent-markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0;
}

.agent-md-table-wrap {
  overflow-x: auto;
  margin: 0 0 0.75rem;
}

.agent-md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
}

.agent-md-table th,
.agent-md-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.65rem;
}

.agent-md-table th {
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
}

.training-samples {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.training-sample-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.training-sample-item {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

.training-sample-item img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.training-sample-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.training-sample-meta strong {
  color: var(--text-primary);
  font-size: 0.8rem;
}

.training-sample-actions {
  display: flex;
  align-items: flex-start;
}

.stat-card {
  padding: 16px;
  border-radius: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--cyan);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.form-row .form-group { margin-bottom: 0; }

.job-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
}

.job-item {
  padding: 14px;
  border-radius: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

.job-item .job-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.job-item .job-id {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}

.job-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
}

.job-badge.completed { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.job-badge.running, .job-badge.queued { background: rgba(0, 212, 255, 0.12); color: var(--cyan); }
.job-badge.failed { background: rgba(239, 68, 68, 0.15); color: var(--red); }

.progress-bar {
  height: 6px;
  background: var(--bg-primary);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--blue));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.marketplace-layout .form-group textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 88px;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  resize: vertical;
}

.marketplace-layout .form-group textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.marketplace-layout .form-group--full {
  grid-column: 1 / -1;
  width: 100%;
}

.marketplace-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
}

@media (max-width: 1024px) {
  .marketplace-layout { grid-template-columns: 1fr; }
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  font-size: 0.9rem;
}

/* Agent Layout Full Height Optimization */
.agent-layout-page {
  height: calc(100vh - 72px);
  min-height: 0;
  padding-top: 16px;
  padding-bottom: 16px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.agent-layout-page > .container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.agent-layout-page .agent-header {
  flex: 0 0 auto;
  margin-bottom: 16px;
}

.agent-layout-page .agent-grid {
  flex: 1;
  min-height: 0;
  height: 100%;
  align-items: stretch;
}

.agent-layout-page .agent-window {
  height: 100%;
  min-height: 0;
}

.agent-layout-page aside {
  height: 100%;
}

.agent-layout-page aside .panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .agent-layout-page {
    height: auto;
  }
  .agent-layout-page .agent-grid {
    display: flex;
    flex-direction: column;
    height: auto;
  }
  .agent-layout-page .agent-window {
    height: calc(100vh - 200px);
    min-height: 420px;
  }
  .agent-layout-page aside {
    margin-top: 20px;
    height: auto;
  }
  .agent-layout-page aside .panel {
    height: auto;
  }
  .agent-bubble {
    max-width: 95%;
    padding: 10px 14px;
    font-size: 0.9rem;
  }
  .agent-input-row {
    padding: 10px 12px;
    gap: 8px;
  }
  .agent-input-controls {
    gap: 8px;
  }
}