/* Soup Web UI — Warm theme inspired by the Soup terracotta logo */
:root {
  --bg: #111014;
  --bg-card: #1a1720;
  --bg-input: #231f2a;
  --border: #3a3040;
  --text: #f0ece8;
  --text-dim: #a09088;
  --accent: #c0512d;
  --accent-hover: #a8442a;
  --accent-warm: #e8975a;
  --danger: #e84040;
  --warning: #f2b233;
  --info: #c0512d;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  padding: 0.75rem 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar-logo img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.sidebar-nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.9rem;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg-input); color: var(--text); }
.nav-item.active { color: var(--accent-warm); background: rgba(92, 224, 216, 0.08); border-right: 3px solid var(--accent-warm); }

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.main { flex: 1; padding: 2rem; overflow-y: auto; }

.page { display: none; }
.page.active { display: block; }

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-title { font-size: 1.5rem; font-weight: 600; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card { text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent-warm); }
.stat-label { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.25rem; }

/* Tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-dim);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(42, 48, 80, 0.5);
}

tr:hover td { background: rgba(139, 108, 199, 0.06); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  transition: all 0.15s;
}

.btn:hover { border-color: var(--text-dim); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: rgba(92, 224, 216, 0.15); color: var(--accent-warm); }
.badge-danger { background: rgba(232, 64, 64, 0.2); color: var(--danger); }
.badge-warning { background: rgba(242, 178, 51, 0.2); color: var(--warning); }
.badge-info { background: rgba(139, 108, 199, 0.15); color: var(--info); }

/* Forms */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}

/* Chart container */
.chart-container {
  position: relative;
  height: 300px;
  margin-top: 1rem;
}

/* Chat UI */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
}

.chat-msg {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
}

.chat-msg.user { background: rgba(92, 224, 216, 0.08); }
.chat-msg.assistant { background: rgba(139, 108, 199, 0.08); }

.chat-msg-role {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  min-width: 70px;
  color: var(--text-dim);
}

.chat-msg.user .chat-msg-role { color: var(--accent-warm); }
.chat-msg.assistant .chat-msg-role { color: var(--accent); }

.chat-msg-content {
  flex: 1;
  white-space: pre-wrap;
  line-height: 1.5;
}

.chat-input-area {
  display: flex;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.chat-input-area input {
  flex: 1;
}

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* Run detail modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  justify-content: center;
  align-items: flex-start;
  padding-top: 5vh;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-close:hover { color: var(--text); }

/* Data explorer */
.data-entry {
  background: var(--bg-input);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.data-entry-field {
  margin-bottom: 0.5rem;
}

.data-entry-key {
  font-weight: 600;
  color: var(--accent);
  margin-right: 0.5rem;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-dim);
}

.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state-text { font-size: 1.1rem; margin-bottom: 0.5rem; }
.empty-state-hint { font-size: 0.85rem; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-logo { font-size: 1rem; padding: 0 0.5rem 1rem; text-align: center; }
  .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 0.75rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* --- Training Live Monitor --- */
.log-panel {
  background: #0d0b10;
  color: #d0c8c0;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  max-height: 400px;
  overflow-y: auto;
  padding: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-all;
}

.progress-bar {
  width: 100%;
  height: 22px;
  background: var(--bg-input);
  border-radius: 11px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-warm));
  border-radius: 11px;
  transition: width 0.4s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #3ddc84;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  background: rgba(61,220,132,0.12);
}

.live-badge::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #3ddc84;
  border-radius: 50%;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* --- Enhanced Metrics --- */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

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

.eval-table {
  width: 100%;
  border-collapse: collapse;
}

.eval-table th, .eval-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.eval-table th {
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 600;
}

/* --- Chat Upgrade --- */
.chat-settings details summary {
  color: var(--text-dim);
}

.chat-settings details[open] summary {
  color: var(--text);
  margin-bottom: 0.5rem;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem 1rem;
  align-items: center;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

.code-block {
  background: #0d0b10;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 0.5rem 0;
}

.chat-markdown code {
  background: rgba(192, 81, 45, 0.15);
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-size: 0.88em;
}

.chat-markdown .code-block code {
  background: none;
  padding: 0;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* --- Config Builder --- */
.form-section {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.form-section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent-warm);
}

.form-section[open] summary {
  margin-bottom: 0.5rem;
}
