/* ============================================
   Spring AI Agent Platform - Demo UI Styles
   Design inspired by Scopevisio.com
   ============================================ */

:root {
  /* Scopevisio-inspired palette */
  --gold: #C9A227;
  --gold-light: #e8d48a;
  --gold-dark: #9a7b1a;
  --navy: #1E293B;
  --navy-light: #2d3a4f;
  --navy-dark: #111827;
  --blue: #0088c2;
  --blue-light: #e0f2fe;

  /* Neutrals */
  --bg: #f4f6f9;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  /* Status */
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --error: #ef4444;
  --error-bg: #fef2f2;
  --info: #3b82f6;
  --info-bg: #eff6ff;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);

  /* Layout */
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-sm: 4px;

  /* Fonts */
  --font: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ============ Reset & Base ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 700; line-height: 1.3; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

pre {
  background: var(--navy-dark);
  color: #e2e8f0;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.5;
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--navy);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  color: white;
  flex-shrink: 0;
}

.logo-text { display: flex; flex-direction: column; }
.logo-title { font-weight: 700; font-size: 1rem; color: #f8fafc; }
.logo-subtitle { font-size: 0.75rem; color: var(--gold); font-weight: 600; }

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

.nav-section { margin-bottom: 0.5rem; }

.nav-section-label {
  padding: 0.5rem 1.25rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
  cursor: pointer;
}

.nav-link:hover {
  color: #e2e8f0;
  background: rgba(255,255,255,0.05);
  text-decoration: none;
}

.nav-link.active {
  color: var(--gold);
  background: rgba(201, 162, 39, 0.08);
  border-left-color: var(--gold);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--gold);
  color: var(--navy);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.8rem;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.status-dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.disconnected { background: var(--error); }

.api-url-display {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: #475569;
  word-break: break-all;
}

/* ============ Main Content ============ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
}

.menu-toggle svg { width: 24px; height: 24px; color: var(--text); }

.breadcrumb {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.top-bar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.api-url-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.api-url-input-wrap label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.api-url-input-wrap input {
  width: 200px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text);
}

.content-area {
  flex: 1;
  padding: 1.5rem;
  max-width: 1400px;
  width: 100%;
}

/* ============ Page Header ============ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header h1 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
}

.page-description {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ============ Cards ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 { font-size: 1rem; }

.card-body {
  padding: 1.25rem;
}

.card-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border-light);
  background: #fafbfc;
}

/* Stat Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.stat-icon.gold { background: rgba(201,162,39,0.12); color: var(--gold-dark); }
.stat-icon.blue { background: rgba(0,136,194,0.12); color: var(--blue); }
.stat-icon.green { background: rgba(16,185,129,0.12); color: var(--success); }
.stat-icon.purple { background: rgba(139,92,246,0.12); color: #8b5cf6; }

.stat-info { flex: 1; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.25rem; font-weight: 500; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
}
.btn-primary:hover:not(:disabled) { background: var(--navy-light); }

.btn-gold {
  background: var(--gold);
  color: white;
  border-color: var(--gold);
}
.btn-gold:hover:not(:disabled) { background: var(--gold-dark); }

.btn-secondary {
  background: white;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); border-color: #cbd5e1; }

.btn-danger {
  background: white;
  color: var(--error);
  border-color: var(--error);
}
.btn-danger:hover:not(:disabled) { background: var(--error); color: white; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-lg { padding: 0.7rem 1.5rem; font-size: 0.95rem; }
.btn-icon { padding: 0.4rem; }
.btn-icon svg { width: 16px; height: 16px; }

.btn-group { display: flex; gap: 0.5rem; }

/* ============ Tables ============ */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

tbody tr {
  transition: background 0.1s;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child td {
  border-bottom: none;
}

td .cell-primary { font-weight: 600; color: var(--text); }
td .cell-secondary { font-size: 0.78rem; color: var(--text-secondary); }

.table-actions {
  display: flex;
  gap: 0.25rem;
}

/* ============ Forms ============ */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.form-group .form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

input[type="text"],
input[type="url"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,162,39,0.15);
}

textarea {
  min-height: 120px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
}

textarea.tall { min-height: 250px; }

select {
  cursor: pointer;
  appearance: auto;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-inline {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.form-inline .form-group { flex: 1; margin-bottom: 0; }

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
  width: auto;
  accent-color: var(--gold);
}

/* ============ Badges ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-success { background: var(--success-bg); color: #065f46; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-error { background: var(--error-bg); color: #991b1b; }
.badge-info { background: var(--info-bg); color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }
.badge-gold { background: rgba(201,162,39,0.15); color: var(--gold-dark); }

/* ============ Tags ============ */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  background: #f1f5f9;
  color: #475569;
  font-size: 0.72rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-weight: 500;
}

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
}

.modal.wide { max-width: 900px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 1.1rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  background: #fafbfc;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============ Toast ============ */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  min-width: 280px;
  max-width: 420px;
  animation: toastIn 0.3s ease;
}

.toast.removing { animation: toastOut 0.3s ease forwards; }

.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-success { border-left: 3px solid var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-error { border-left: 3px solid var(--error); }
.toast-error .toast-icon { color: var(--error); }
.toast-info { border-left: 3px solid var(--info); }
.toast-info .toast-icon { color: var(--info); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ============ Chat UI ============ */
.chat-container {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1rem;
  height: calc(100vh - var(--topbar-height) - 5rem);
  min-height: 500px;
}

.chat-main {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  background: #fafbfc;
}

.chat-input-area input {
  flex: 1;
}

.message {
  max-width: 85%;
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-user {
  align-self: flex-end;
}

.message-user .message-bubble {
  background: var(--navy);
  color: white;
  border-radius: var(--radius) var(--radius) 3px var(--radius);
}

.message-assistant {
  align-self: flex-start;
}

.message-assistant .message-bubble {
  background: #f1f5f9;
  color: var(--text);
  border-radius: var(--radius) var(--radius) var(--radius) 3px;
}

.message-bubble {
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  line-height: 1.6;
  word-break: break-word;
}

/* Markdown inside message bubbles & response blocks */
.md-content { white-space: normal; }
.md-content p { margin: 0.35em 0; }
.md-content p:first-child { margin-top: 0; }
.md-content p:last-child { margin-bottom: 0; }
.md-content h1, .md-content h2, .md-content h3,
.md-content h4, .md-content h5, .md-content h6 {
  margin: 0.75em 0 0.35em;
  line-height: 1.3;
}
.md-content h1 { font-size: 1.3em; }
.md-content h2 { font-size: 1.15em; }
.md-content h3 { font-size: 1.05em; }
.md-content h4, .md-content h5, .md-content h6 { font-size: 0.95em; }
.md-content ul, .md-content ol { margin: 0.35em 0; padding-left: 1.5em; }
.md-content li { margin: 0.15em 0; }
.md-content code {
  background: rgba(0,0,0,0.06);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.88em;
  font-family: var(--font-mono);
}
.md-content pre {
  margin: 0.5em 0;
  padding: 0.75em;
  border-radius: var(--radius-sm);
  font-size: 0.82em;
  overflow-x: auto;
}
.md-content pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.md-content blockquote {
  margin: 0.5em 0;
  padding: 0.35em 0.75em;
  border-left: 3px solid var(--gold);
  background: rgba(201,162,39,0.05);
  color: var(--text-secondary);
}
.md-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75em 0;
}
.md-content table {
  margin: 0.5em 0;
  font-size: 0.85em;
}
.md-content a { color: var(--blue); }
.md-content strong { font-weight: 700; }
.md-content .mermaid-container {
  margin: 0.75em 0;
  border-radius: var(--radius);
}
/* Override dark pre background for code blocks inside assistant messages */
.message-assistant .md-content pre:not(.mermaid) {
  background: rgba(0,0,0,0.06);
  color: var(--text);
}
/* User messages: lighter code blocks */
.message-user .md-content code {
  background: rgba(255,255,255,0.15);
}
.message-user .md-content pre:not(.mermaid) {
  background: rgba(0,0,0,0.15);
  color: white;
}
/* Response blocks (invoke, jobs, llm) markdown */
.response-block { white-space: normal; }
.response-block.md-content pre:not(.mermaid) {
  background: var(--navy-dark);
  color: #e2e8f0;
}

.message-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  padding: 0 0.25rem;
}

.message-user .message-meta { text-align: right; }

.tool-call-card {
  background: white;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
  font-size: 0.82rem;
  animation: msgIn 0.2s ease;
}

.tool-call-header {
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.tool-call-header:hover { background: #fafbfc; }

.tool-call-name {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--gold-dark);
}

.tool-call-details {
  display: none;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border-light);
}

.tool-call-details.open { display: block; }

.tool-call-details pre {
  font-size: 0.78rem;
  margin-top: 0.25rem;
  padding: 0.5rem;
  max-height: 200px;
  overflow: auto;
}

.tool-result-card {
  border-left-color: var(--success);
}

.tool-result-card .tool-call-name { color: #065f46; }

/* Chat sidebar */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-config {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.chat-config h4 {
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-threads {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-threads h4 {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-light);
}

.thread-list {
  flex: 1;
  overflow-y: auto;
}

.thread-item {
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.82rem;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.thread-item:hover { background: #f8fafc; }
.thread-item.active { background: rgba(201,162,39,0.08); border-left: 2px solid var(--gold); }

.thread-id {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Streaming indicator */
.streaming-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: 600;
}

.streaming-dot {
  width: 6px;
  height: 6px;
  background: var(--gold);
  border-radius: 50%;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ============ Mermaid ============ */
.mermaid-container {
  background: var(--navy-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.mermaid-container .mermaid {
  display: flex;
  justify-content: center;
}

/* Let xychart-beta SVGs use their intrinsic height so x-axis labels aren't
   clipped by a CSS-forced aspect ratio. The ChartPalette init sets height: 600
   for breathing room on the bottom labels and y-axis title. */
.mermaid-container .mermaid svg[id^="mermaid-"] {
  max-width: 100%;
  height: auto;
}

.diagram-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.diagram-grid .mermaid-container { min-height: 200px; }

/* ============ Empty State ============ */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.empty-state-text {
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ============ Loading ============ */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Job Timeline ============ */
.job-timeline {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 1rem 0;
}

.timeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  position: relative;
}

.timeline-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: white;
  font-weight: 700;
  z-index: 1;
}

.timeline-dot.active { background: var(--gold); }
.timeline-dot.done { background: var(--success); }
.timeline-dot.failed { background: var(--error); }

.timeline-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  font-weight: 600;
}

.timeline-step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 14px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.timeline-step.done:not(:last-child)::after { background: var(--success); }
.timeline-step.active:not(:last-child)::after {
  background: linear-gradient(to right, var(--gold), var(--border));
}

/* ============ JSON display ============ */
.json-display {
  background: var(--navy-dark);
  color: #e2e8f0;
  padding: 1rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
}

.json-key { color: #93c5fd; }
.json-string { color: #86efac; }
.json-number { color: #fde68a; }
.json-boolean { color: #c4b5fd; }
.json-null { color: #94a3b8; }

/* ============ Detail View ============ */
.detail-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.88rem;
}

.detail-label {
  font-weight: 600;
  color: var(--text-secondary);
}

.detail-value {
  color: var(--text);
  word-break: break-word;
}

/* ============ Tabs ============ */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
  gap: 0;
}

.tab {
  padding: 0.6rem 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all 0.15s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--gold-dark); border-bottom-color: var(--gold); }

/* ============ Collapsible ============ */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  padding: 0.75rem 1rem;
}

.collapsible-header:hover { background: #f8fafc; }

.collapsible-arrow {
  transition: transform 0.2s;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.collapsible-header.open .collapsible-arrow { transform: rotate(90deg); }

.collapsible-body {
  display: none;
  padding: 0 1rem 0.75rem;
}

.collapsible-body.open { display: block; }

/* ============ Metrics Grid ============ */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.metric-item {
  text-align: center;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
}

.metric-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
  font-weight: 600;
  text-transform: uppercase;
}

/* ============ Responsive ============ */
@media (max-width: 1024px) {
  .chat-container { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
  .diagram-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .form-row { grid-template-columns: 1fr; }
  .content-area { padding: 1rem; }
  .api-url-input-wrap { display: none; }
}

/* ============ Utility ============ */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-gold { color: var(--gold-dark); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.72rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ============ Conversations page ============ */
.conversations-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .conversations-layout { grid-template-columns: 1fr; }
}

.conversations-list-pane,
.conversations-detail-pane {
  display: flex;
  flex-direction: column;
  min-height: 480px;
  max-height: calc(100vh - 220px);
}

.conversations-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.conversations-list-pane .thread-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.conversations-detail-pane {
  overflow: hidden;
}

.conversations-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.conversations-detail-section-header {
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: #fafbfc;
}

.conversations-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 1rem;
}

/* Human-in-the-loop approval card (PAUSED graph run) */
.hitl-card {
  background: var(--warning-bg);
  border: 1px solid var(--warning);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
  font-size: 0.85rem;
  animation: msgIn 0.2s ease;
}

.hitl-card.hitl-resolved {
  opacity: 0.6;
  border-left-color: var(--text-muted);
}

.hitl-header {
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(245, 158, 11, 0.25);
}

.hitl-badge {
  font-weight: 600;
  color: var(--warning);
}

.hitl-body { padding: 0.5rem 0.75rem; }

.hitl-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  margin: 0.25rem 0 0.5rem;
}

.hitl-actions { display: flex; gap: 0.5rem; }

.hitl-dot { color: var(--warning); }

/* Graph node lifecycle markers in the stream view */
.node-event {
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0.15rem 0.25rem;
  margin: 0.1rem 0;
  border-left: 2px solid var(--border);
  padding-left: 0.5rem;
}

.node-event-label { color: var(--blue); font-weight: 600; }
