/**
 * Agent Hub Styles
 * ================
 * Three-pane layout for the Agent Hub interface
 * Uses design tokens from variables.css
 */

/* ─────────────────────────────────────────────────────────────
 * CONTAINER
 * ───────────────────────────────────────────────────────────── */
.agent-hub {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

/* ─────────────────────────────────────────────────────────────
 * HEADER
 * ───────────────────────────────────────────────────────────── */
.agent-hub__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  transition: var(--transition-colors);
  user-select: none;
}

.agent-hub__header:hover {
  background-color: var(--gray-50);
}

.agent-hub__header-title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
}

.agent-hub__header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.agent-hub__toggle-icon {
  width: 20px;
  height: 20px;
  color: var(--color-text-muted);
  transition: var(--transition-transform);
}

.agent-hub--collapsed .agent-hub__toggle-icon {
  transform: rotate(-90deg);
}

/* ─────────────────────────────────────────────────────────────
 * BODY - Collapsible Content
 * ───────────────────────────────────────────────────────────── */
.agent-hub__body {
  display: grid;
  grid-template-columns: 280px 1fr auto;
  height: 500px;
  max-height: 500px;
  overflow: hidden;
}

.agent-hub--collapsed .agent-hub__body {
  display: none;
}

/* ─────────────────────────────────────────────────────────────
 * PANE BASE STYLES
 * ───────────────────────────────────────────────────────────── */
.agent-hub__pane {
  background-color: var(--color-surface);
  padding: var(--space-4);
  overflow-y: auto;
}

/* Borders between panes */
.agent-hub__pane--trace {
  border-right: 1px solid var(--color-border-light);
}

.agent-hub__pane--chat {
  border-right: 1px solid var(--color-border-light);
}

/* ─────────────────────────────────────────────────────────────
 * TRACE PANE (Left - 280px)
 * ───────────────────────────────────────────────────────────── */
.agent-hub__pane--trace {
  width: 280px;
  background-color: var(--gray-50);
}

.agent-hub__pane-header {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0 0 var(--space-3) 0;
}

/* Trace List */
.agent-hub__trace-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.agent-hub__trace-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: var(--transition-colors);
}

.agent-hub__trace-item:hover {
  background-color: var(--gray-100);
}

.agent-hub__trace-item--active {
  background-color: var(--color-secondary-light);
  color: var(--color-text-inverse);
}

/* Trace Status Indicator */
.agent-hub__trace-status {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.agent-hub__trace-status--running {
  background-color: var(--color-secondary);
  animation: pulse 1.5s ease-in-out infinite;
}

.agent-hub__trace-status--success {
  background-color: var(--color-success);
}

.agent-hub__trace-status--error {
  background-color: var(--color-error);
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.agent-hub__trace-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-hub__trace-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* ─────────────────────────────────────────────────────────────
 * CHAT PANE (Center - Flexible)
 * ───────────────────────────────────────────────────────────── */
.agent-hub__pane--chat {
  display: flex;
  flex-direction: column;
  max-width: 600px;
  min-width: 0;
  min-height: 0;  /* Required for flex children to scroll */
  overflow: hidden;
}

/* Header stays fixed, content fills remaining space */
.agent-hub__pane-header {
  flex-shrink: 0;
}

.agent-hub__chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;  /* Critical for nested flex scroll */
  overflow: hidden;
}

.agent-hub__chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
}

.agent-hub__chat-message {
  font-size: 16px;
  line-height: var(--leading-normal);
  color: var(--color-text);
}

.agent-hub__chat-message--user {
  background-color: var(--color-secondary-light);
  color: var(--color-text-inverse);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  align-self: flex-end;
  max-width: 85%;
}

.agent-hub__chat-message--agent {
  background-color: var(--gray-100);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  align-self: flex-start;
  max-width: 85%;
}

.agent-hub__chat-input-container {
  display: flex;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border-light);
}

.agent-hub__chat-input {
  flex: 1;
  padding: var(--space-3);
  font-size: var(--text-base);
  font-family: var(--font-family);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  color: var(--color-text);
  resize: none;
  transition: var(--transition-colors);
}

.agent-hub__chat-input:focus {
  outline: none;
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.agent-hub__chat-input::placeholder {
  color: var(--color-text-muted);
}

.agent-hub__chat-send {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-inverse);
  background-color: var(--color-secondary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-colors);
}

.agent-hub__chat-send:hover {
  background-color: var(--color-secondary-dark);
}

.agent-hub__chat-send:disabled {
  background-color: var(--gray-300);
  cursor: not-allowed;
}

/* ─────────────────────────────────────────────────────────────
 * SKETCH PANE (Right - Auto width, hidden by default)
 * ───────────────────────────────────────────────────────────── */
.agent-hub__pane--sketch {
  display: none;
  width: 400px;  /* Wider to accommodate diagrams */
  min-width: 320px;
  background-color: var(--gray-50);
  overflow: auto;  /* Allow scrolling for large diagrams */
}

.agent-hub--sketch-visible .agent-hub__pane--sketch {
  display: flex;
  flex-direction: column;
}

.agent-hub__sketch-canvas {
  width: 100%;
  height: 300px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
}

.agent-hub__sketch-tools {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.agent-hub__sketch-tool {
  padding: var(--space-2);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-colors);
}

.agent-hub__sketch-tool:hover {
  background-color: var(--gray-100);
}

.agent-hub__sketch-tool--active {
  background-color: var(--color-secondary-light);
  border-color: var(--color-secondary);
  color: var(--color-text-inverse);
}

/* Diagram container - shrink to fit with maximize option */
.agent-sketch-pad__diagram {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-3);
  min-height: 200px;
  overflow: hidden;  /* No scrolling - shrink to fit */
}

.agent-sketch-pad__diagram svg {
  /* Scale down to fit container while preserving aspect ratio */
  max-width: 100%;
  max-height: 100%;
  height: auto;
  width: auto;
}

/* Maximize button */
.agent-sketch-pad__maximize-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.agent-sketch-pad__maximize-btn:hover {
  opacity: 1;
  background: var(--gray-100);
}

/* Popup overlay */
.agent-sketch-pad__popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

/* Popup container */
.agent-sketch-pad__popup {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.agent-sketch-pad__popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
  font-weight: var(--font-weight-medium);
}

.agent-sketch-pad__popup-close {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
}

.agent-sketch-pad__popup-close:hover {
  background: var(--gray-100);
  color: var(--color-text);
}

.agent-sketch-pad__popup-content {
  padding: var(--space-4);
  overflow: auto;
}

.agent-sketch-pad__popup-content svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Error state styling */
.agent-sketch-pad__error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
  min-height: 200px;
}

.agent-sketch-pad__error-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-warning);
  background-color: var(--color-warning-light, #fff3cd);
  border-radius: 50%;
  margin-bottom: var(--space-3);
}

.agent-sketch-pad__error-title {
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.agent-sketch-pad__error-message {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  max-width: 280px;
}

/* ─────────────────────────────────────────────────────────────
 * EMPTY STATES
 * ───────────────────────────────────────────────────────────── */
.agent-hub__empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
}

.agent-hub__empty-state-icon {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-3);
  opacity: 0.5;
}

.agent-hub__empty-state-text {
  font-size: var(--text-sm);
  margin: 0;
}

/* ─────────────────────────────────────────────────────────────
 * MOBILE RESPONSIVE (768px breakpoint)
 * ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .agent-hub__body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .agent-hub__pane--trace {
    width: 100%;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--color-border-light);
  }

  .agent-hub__pane--chat {
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--color-border-light);
  }

  .agent-hub__pane--sketch {
    width: 100%;
  }

  .agent-hub--sketch-visible .agent-hub__body {
    grid-template-rows: auto 1fr auto;
  }

  /* Trace list horizontal scroll on mobile */
  .agent-hub__trace-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: var(--space-2);
    gap: var(--space-3);
  }

  .agent-hub__trace-item {
    flex-shrink: 0;
    min-width: 150px;
  }
}

/* ─────────────────────────────────────────────────────────────
 * LOADING STATES
 * ───────────────────────────────────────────────────────────── */
.agent-hub__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.agent-hub__loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-border-light);
  border-top-color: var(--color-secondary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

/* ─────────────────────────────────────────────────────────────
 * UTILITY CLASSES
 * ───────────────────────────────────────────────────────────── */
.agent-hub__divider {
  height: 1px;
  background-color: var(--color-border-light);
  margin: var(--space-3) 0;
}

.agent-hub__badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-full);
  background-color: var(--gray-200);
  color: var(--color-text-secondary);
}

.agent-hub__badge--running {
  background-color: rgba(33, 150, 243, 0.15);
  color: var(--color-secondary-dark);
}

.agent-hub__badge--success {
  background-color: rgba(76, 175, 80, 0.15);
  color: var(--color-primary-dark);
}

.agent-hub__badge--error {
  background-color: rgba(244, 67, 54, 0.15);
  color: var(--color-error-dark);
}

/* ─────────────────────────────────────────────────────────────
 * TRACE VIEW COMPONENT
 * ───────────────────────────────────────────────────────────── */
.trace-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  font-family: var(--font-family-mono, 'SF Mono', 'Consolas', monospace);
  font-size: var(--text-sm);
}

.trace-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}

/* Placeholder when no trace */
.trace-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: var(--color-text-muted);
  gap: var(--space-2);
}

.trace-placeholder__icon {
  font-size: var(--text-2xl);
  opacity: 0.5;
}

.trace-placeholder__text {
  font-size: var(--text-sm);
}

/* Trace root (main trace label) */
.trace-root {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.trace-root__symbol {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.trace-root__label {
  flex: 1;
}

/* Trace steps container */
.trace-steps {
  padding-left: var(--space-1);
}

/* Individual trace step */
.trace-step {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  line-height: 1.4;
  white-space: nowrap;
}

.trace-step__indent {
  color: var(--color-text-muted);
  opacity: 0.5;
  white-space: pre;
  font-family: var(--font-family-mono, 'SF Mono', 'Consolas', monospace);
}

.trace-step__symbol {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  font-size: var(--text-xs);
}

.trace-step__label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-text);
}

.trace-step__duration {
  flex-shrink: 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-left: var(--space-2);
}

/* Status colors for trace steps */
.trace-step--running .trace-step__symbol,
.trace-root.trace-step--running .trace-root__symbol {
  color: var(--color-secondary);
  animation: trace-pulse 1.5s ease-in-out infinite;
}

.trace-step--success .trace-step__symbol,
.trace-root.trace-step--success .trace-root__symbol {
  color: var(--color-success);
}

.trace-step--error .trace-step__symbol,
.trace-root.trace-step--error .trace-root__symbol {
  color: var(--color-error);
}

.trace-step--pending .trace-step__symbol,
.trace-root.trace-step--pending .trace-root__symbol {
  color: var(--color-text-muted);
}

@keyframes trace-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ─────────────────────────────────────────────────────────────
 * TRACE EVENT LOG
 * ───────────────────────────────────────────────────────────── */
.trace-event-log {
  border-top: 1px solid var(--color-border-light);
  margin-top: auto;
  padding-top: var(--space-2);
}

.trace-event-log__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: none;
  border: none;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: var(--transition-colors);
  text-align: left;
}

.trace-event-log__toggle:hover {
  color: var(--color-text);
  background-color: var(--gray-100);
}

.trace-event-log__toggle-icon {
  font-size: 10px;
  transition: transform 0.2s ease;
}

.trace-event-log__toggle[aria-expanded="true"] .trace-event-log__toggle-icon {
  transform: rotate(90deg);
}

.trace-event-log__list {
  overflow-y: auto;
  padding: 0 var(--space-2);
  transition: max-height 0.3s ease;
}

.trace-event-log__empty {
  padding: var(--space-3);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.trace-event-log__item {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  line-height: 1.4;
  border-bottom: 1px solid var(--color-border-light);
}

.trace-event-log__item:last-child {
  border-bottom: none;
}

.trace-event-log__time {
  flex-shrink: 0;
  color: var(--color-text-muted);
  font-family: var(--font-family-mono, 'SF Mono', 'Consolas', monospace);
}

.trace-event-log__desc {
  flex: 1;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─────────────────────────────────────────────────────────────
 * STATUS INDICATOR VARIANTS
 * ───────────────────────────────────────────────────────────── */
.agent-hub__status-indicator--active {
  background-color: rgba(76, 175, 80, 0.15);
  color: var(--color-success);
  animation: status-pulse 2s ease-in-out infinite;
}

.agent-hub__status-indicator--idle {
  background-color: var(--gray-200);
  color: var(--color-text-muted);
}

@keyframes status-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* ─────────────────────────────────────────────────────────────
 * EMBEDDED CHAT COMPONENT (for Agent Hub integration)
 * Uses larger fonts (16px base) and no fixed positioning
 * ───────────────────────────────────────────────────────────── */
.embedded-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  font-size: 16px;
}

.embedded-chat__messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  min-height: 0;
}

.embedded-chat__message {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  max-width: 90%;
  line-height: var(--leading-normal);
  word-wrap: break-word;
}

.embedded-chat__message--user {
  background-color: var(--color-secondary-light);
  color: var(--color-text-inverse);
  align-self: flex-end;
  margin-left: auto;
}

.embedded-chat__message--assistant {
  background-color: var(--gray-100);
  color: var(--color-text);
  align-self: flex-start;
}

.embedded-chat__welcome {
  color: var(--color-text-secondary);
}

.embedded-chat__loading {
  opacity: 0.7;
}

.embedded-chat__loading .embedded-chat__text {
  animation: embedded-chat-pulse 1.5s ease-in-out infinite;
}

@keyframes embedded-chat-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.embedded-chat__text {
  display: block;
  font-size: 16px;
}

.embedded-chat__time {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
  opacity: 0.8;
}

.embedded-chat__message--user .embedded-chat__time {
  color: rgba(255, 255, 255, 0.8);
}

.embedded-chat__input-container {
  display: flex;
  align-items: flex-end;  /* Align button to bottom when textarea expands */
  gap: var(--space-2);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border-light);
  flex-shrink: 0;  /* Never shrink - always visible at bottom */
  background: var(--color-surface);  /* Cover any content behind */
}

.embedded-chat__input {
  flex: 1;
  padding: var(--space-3);
  font-size: 16px;
  font-family: var(--font-family);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  color: var(--color-text);
  transition: var(--transition-colors);
  /* Textarea-specific styles */
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: var(--leading-normal);
  overflow-y: hidden;
}

.embedded-chat__input:focus {
  outline: none;
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.embedded-chat__input::placeholder {
  color: var(--color-text-muted);
}

.embedded-chat__input--disabled {
  background-color: var(--gray-100);
  cursor: not-allowed;
  opacity: 0.6;
}

.embedded-chat__send-btn {
  padding: var(--space-3) var(--space-4);
  font-size: 16px;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-inverse);
  background-color: var(--color-secondary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-colors);
}

.embedded-chat__send-btn:hover {
  background-color: var(--color-secondary-dark);
}

.embedded-chat__send-btn:disabled,
.embedded-chat__send-btn--disabled {
  background-color: var(--gray-300);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Responsive adjustments for embedded chat */
@media (max-width: 768px) {
  .embedded-chat__message {
    max-width: 95%;
    padding: var(--space-2) var(--space-3);
  }

  .embedded-chat__input,
  .embedded-chat__send-btn,
  .embedded-chat__text {
    font-size: 14px;
  }
}
