/* ===== CSS VARIABLES ===== */
:root {
  --bg: #f0f2ee;
  --surface: #ffffff;
  --green-dark: #1a3a1a;
  --green-primary: #2d6a2d;
  --green-bright: #3a8a3a;
  --green-light: #4caf50;
  --green-accent: #5cb85c;
  --green-pale: #e8f5e9;
  --text-dark: #111;
  --text-mid: #444;
  --text-muted: #888;
  --border: #d8ddd4;
  --warning: #f5a623;
  --font-main: 'DM Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
}

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

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text-dark);
  font-size: 13px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ═══════════════════════════════════════
   CHATBOT POPUP
═══════════════════════════════════════ */
.chatbot-popup {
  position: fixed;
  bottom: 24px;
  left: 196px;
  width: 320px;
  height: 400px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18), 0 2px 12px rgba(0,0,0,0.10);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  overflow: hidden;
  border: 1px solid #d0d8cc;
  transform: translateY(0) scale(1);
  opacity: 1;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.2s ease;
}
.chatbot-popup.hidden {
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
}
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--green-dark);
  padding: 12px 14px;
  flex-shrink: 0;
}
.chatbot-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  font-family: var(--font-mono);
}
.chatbot-star-icon {
  color: #8bc34a;
  font-size: 14px;
  animation: pulse-star 2s infinite;
}
@keyframes pulse-star {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.2); }
}
.chatbot-x-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  color: rgba(255,255,255,0.8);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
  font-family: var(--font-main);
}
.chatbot-x-btn:hover { background: rgba(255,255,255,0.25); color: #fff; }
.chatbot-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f7f9f6;
}
.chatbot-body::-webkit-scrollbar { width: 4px; }
.chatbot-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }
.chat-msg-row { display: flex; align-items: flex-end; gap: 8px; }
.bot-row { justify-content: flex-start; }
.user-row { justify-content: flex-end; }
.chat-avatar { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; }
.bot-av { background: var(--green-primary); }
.user-av { background: #bbb; }
.chat-bubble {
  max-width: 210px;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
}
.bot-bubble { background: #fff; color: var(--text-dark); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.user-bubble { background: var(--green-dark); color: #fff; border-bottom-right-radius: 4px; }
.typing-bubble {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green-primary); opacity: 0.6;
  animation: typing-bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.6; }
  40% { transform: translateY(-5px); opacity: 1; }
}
.chatbot-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-text-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 22px;
  font-size: 12px;
  font-family: var(--font-main);
  background: #f4f6f3;
  outline: none;
  color: var(--text-dark);
  transition: border-color 0.2s;
}
.chat-text-input:focus { border-color: var(--green-primary); background: #fff; }
.chat-text-input::placeholder { color: #bbb; }
.chat-send-btn {
  width: 32px; height: 32px;
  background: var(--green-primary);
  border: none; border-radius: 50%;
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.chat-send-btn:hover { background: var(--green-bright); transform: scale(1.07); }
.chat-send-btn:active { transform: scale(0.95); }

/* ═══════════════════════════════════════
   TOP NAV
═══════════════════════════════════════ */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 48px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topnav-left { display: flex; align-items: center; gap: 28px; }
.brand { font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--text-dark); letter-spacing: -0.3px; }
.top-tabs { display: flex; gap: 2px; }
.tab {
  padding: 4px 14px; font-size: 13px; font-weight: 500; color: var(--text-muted);
  text-decoration: none; border-bottom: 2px solid transparent; transition: all 0.2s;
}
.tab.active, .tab:hover { color: var(--green-primary); border-bottom-color: var(--green-primary); }
.topnav-right { display: flex; align-items: center; gap: 10px; }
.btn-outline {
  padding: 5px 12px; border: 1.5px solid var(--border); background: transparent;
  border-radius: 6px; font-size: 12px; font-family: var(--font-main); cursor: pointer; color: var(--text-dark); transition: 0.2s;
}
.btn-outline:hover { border-color: var(--green-primary); color: var(--green-primary); }
.btn-filled {
  padding: 5px 12px; background: var(--green-primary); color: #fff;
  border: none; border-radius: 6px; font-size: 12px; font-family: var(--font-main); cursor: pointer; font-weight: 600;
}
.icon-btn { cursor: pointer; font-size: 16px; opacity: 0.7; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #ccc; display: flex; align-items: center; justify-content: center; font-size: 14px; }

/* ═══════════════════════════════════════
   LAYOUT
═══════════════════════════════════════ */
.layout { display: flex; flex: 1; min-height: calc(100vh - 48px); }

/* ═══════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════ */
.sidebar {
  width: 180px; min-width: 180px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 0;
  position: sticky; top: 48px;
  height: calc(100vh - 48px);
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 0 14px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.brand-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--green-primary); flex-shrink: 0; }
.brand-name { font-size: 10px; font-weight: 700; color: var(--text-dark); line-height: 1.2; text-transform: uppercase; letter-spacing: 0.3px; }
.brand-sub { font-size: 9px; color: var(--text-muted); margin-top: 2px; line-height: 1.3; }
.active-tag { color: var(--green-primary); font-weight: 700; }
.chatbot-open-btn {
  margin: 0 10px 12px;
  padding: 8px 10px;
  background: var(--green-dark);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 11px;
  font-family: var(--font-main);
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  letter-spacing: 0.2px;
  transition: background 0.2s, transform 0.1s;
}
.chatbot-open-btn:hover { background: var(--green-primary); }
.chatbot-open-btn:active { transform: scale(0.97); }
.sidebar-nav { flex: 1; padding: 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--text-mid); text-decoration: none;
  font-size: 12px; font-weight: 500; transition: 0.15s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--green-pale); color: var(--green-primary); }
.nav-item.active { background: var(--green-primary); color: #fff; }
.nav-icon { font-size: 13px; }
.sidebar-bottom { padding: 8px 8px 0; border-top: 1px solid var(--border); margin-top: 8px; }

/* ═══════════════════════════════════════
   MAIN
═══════════════════════════════════════ */
.main { flex: 1; padding: 24px 24px 32px; overflow-y: auto; }

/* PAGE HEADER */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.page-eyebrow { font-size: 10px; font-weight: 600; letter-spacing: 1.2px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 4px; }
.page-title { font-size: 26px; font-weight: 700; color: var(--text-dark); letter-spacing: -0.5px; margin-bottom: 6px; }
.page-desc { font-size: 12px; color: var(--text-muted); max-width: 420px; line-height: 1.5; }
.system-health-badge {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow);
}
.sh-label { font-size: 9px; font-weight: 600; letter-spacing: 1px; color: var(--text-muted); text-transform: uppercase; }
.sh-value { font-size: 15px; font-weight: 700; color: var(--text-dark); margin-top: 2px; }
.sh-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--green-pale); display: flex; align-items: center; justify-content: center; font-size: 18px; }

/* CARDS */
.card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 16px; box-shadow: var(--shadow);
}
.card-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text-dark); display: flex; align-items: center; gap: 7px; }
.card-icon { font-size: 14px; }
.badge-active {
  font-size: 9px; font-weight: 700; letter-spacing: 0.8px;
  color: var(--green-primary); border: 1.5px solid var(--green-primary);
  padding: 3px 8px; border-radius: 20px; text-transform: uppercase;
}

/* AGENT ROWS */
.agents-row { display: flex; gap: 16px; margin-bottom: 16px; align-items: stretch; }
.agent-wide { flex: 2; }
.agent-narrow { flex: 1; }
.agents-row2 { align-items: stretch; }
.agent-decision { flex: 2; }
.agent-monitor { flex: 1.2; }
.agent-memory { flex: 1; }

/* AGENT 1 */
.agent1-grid { display: flex; gap: 20px; }
.sliders-col { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.selects-col { flex: 0 0 160px; display: flex; flex-direction: column; gap: 12px; }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-label { font-size: 11px; color: var(--text-muted); width: 80px; flex-shrink: 0; }
.slider-val { font-size: 11px; font-family: var(--font-mono); color: var(--text-dark); width: 36px; text-align: right; flex-shrink: 0; }
.slider {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 4px; border-radius: 2px;
  background: #ddd; /* JS overrides this with gradient on load+input */
  outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--green-primary); cursor: pointer;
  box-shadow: 0 0 0 3px rgba(45,106,45,0.15);
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; border: none;
  background: var(--green-primary); cursor: pointer;
  box-shadow: 0 0 0 3px rgba(45,106,45,0.15);
}
.green-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 2px;
  background: #ddd; /* JS overrides this with gradient on load+input */
  outline: none; cursor: pointer; margin: 6px 0;
}
.green-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; border: none;
  background: var(--green-primary); cursor: pointer;
}
.green-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; border: none;
  background: var(--green-primary); cursor: pointer;
}
.btn-pipeline.success-btn {
  background: #1b5e20;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(27,94,32,0.3);
}
.select-group { display: flex; flex-direction: column; gap: 5px; }
.select-label { font-size: 9px; font-weight: 700; letter-spacing: 1px; color: var(--text-muted); text-transform: uppercase; }
.custom-select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 12px; font-family: var(--font-main); color: var(--text-dark);
  background: #fff; cursor: pointer; outline: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}

/* AGENT 2 */
.field-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.field-label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; }
.field-val { font-size: 11px; font-weight: 600; color: var(--text-dark); }
.field-val.high { color: var(--green-primary); }
.mt8 { margin-top: 8px; }
.mb4 { margin-bottom: 4px; }
.risk-box { background: var(--bg); border-radius: 8px; padding: 12px; margin-top: 12px; }
.risk-label { font-size: 9px; font-weight: 700; letter-spacing: 1px; color: var(--text-muted); text-transform: uppercase; }
.risk-value { font-size: 22px; font-weight: 700; color: var(--text-dark); font-family: var(--font-mono); text-align: right; margin-top: -16px; }
.risk-bar-wrap { height: 5px; background: #ddd; border-radius: 3px; margin: 8px 0 6px; }
.risk-bar { height: 100%; background: var(--warning); border-radius: 3px; }
.risk-warn { font-size: 10px; color: var(--warning); font-weight: 600; }

/* AGENT 3 */
.strategy-row { display: flex; gap: 20px; }
.strategy-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.strategy-btn {
  padding: 7px 14px; border-radius: 6px; border: none;
  font-size: 12px; font-family: var(--font-main); cursor: pointer;
  text-align: left; background: #f0f2ee; color: var(--text-muted);
  transition: 0.15s; font-weight: 500;
}
.strategy-btn.active { background: var(--green-primary); color: #fff; font-weight: 600; }
.strategy-btn:hover:not(.active) { background: var(--green-pale); color: var(--green-primary); }
.budget-col { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.budget-row { display: flex; justify-content: space-between; align-items: center; }
.budget-val { font-size: 12px; font-weight: 600; color: var(--green-primary); font-family: var(--font-mono); }

/* AGENT 4 */
.toggle-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.toggle-sub { font-size: 9px; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.toggle { position: relative; width: 38px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: #ccc; border-radius: 10px; cursor: pointer; transition: 0.3s;
}
.toggle input:checked + .toggle-slider { background: var(--green-primary); }
.toggle-slider::before {
  content: ''; position: absolute; width: 14px; height: 14px;
  background: #fff; border-radius: 50%; top: 3px; left: 3px; transition: 0.3s;
}
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.sparkline-box {
  background: #0d1117; border-radius: 8px; padding: 8px; margin-top: 12px;
  display: flex; align-items: center; justify-content: center;
}

/* AGENT 5 */
.memory-quote {
  font-size: 10px; color: var(--text-muted); font-style: italic;
  border-left: 3px solid var(--green-primary); padding-left: 8px; margin-top: 12px; line-height: 1.5;
}

/* BOTTOM ROW */
.bottom-row { display: flex; gap: 16px; align-items: stretch; }
.hist-card { flex: 2; }
.yield-card {
  flex: 1; background: var(--green-dark); color: #fff;
  display: flex; flex-direction: column; justify-content: center;
}
.yield-label { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: rgba(255,255,255,0.6); margin-bottom: 6px; }
.yield-value { font-size: 42px; font-weight: 700; font-family: var(--font-mono); color: #fff; line-height: 1; margin-bottom: 16px; }
.yield-metrics { border-top: 1px solid rgba(255,255,255,0.15); padding-top: 12px; }
.yield-metric-row { display: flex; justify-content: space-between; font-size: 11px; color: rgba(255,255,255,0.8); margin-bottom: 5px; }
.yield-metric-row .high { color: var(--green-accent); font-weight: 700; }
.yield-metric-bar { height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px; margin-bottom: 6px; }
.ymb-fill { height: 100%; background: var(--green-accent); border-radius: 2px; }
.legend { display: flex; align-items: center; gap: 14px; font-size: 11px; color: var(--text-muted); }
.leg-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.leg-dot.predicted { background: #90caf9; }
.leg-dot.actual { background: #26a69a; }

/* ═══════════════════════════════════════
   RUN AI PIPELINE — below bottom row
═══════════════════════════════════════ */
.pipeline-section {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}
.pipeline-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.pipeline-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pipeline-section-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.pipeline-btn-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}
.btn-pipeline {
  padding: 10px 28px;
  background: var(--green-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.02em;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(45,106,45,0.25);
}
.btn-pipeline:hover {
  background: var(--green-bright);
  box-shadow: 0 4px 16px rgba(45,106,45,0.35);
}
.btn-pipeline:active { transform: scale(0.97); }
.btn-pipeline.running {
  background: #aac9aa;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-pipeline.success-btn {
  background: #1b5e20;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(27,94,32,0.3);
}
.pipeline-status-text {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  min-height: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pipeline-status-text.success { color: var(--green-primary); font-weight: 600; }
.pipeline-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid #ccc;
  border-top-color: var(--green-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pipeline steps progress */
.pipeline-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 16px;
}
.pipeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  position: relative;
}
.pipeline-step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 14px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: #ddd;
  z-index: 0;
  transition: background 0.4s;
}
.pipeline-step.done:not(:last-child)::after { background: var(--green-primary); }
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #ddd;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  z-index: 1;
  position: relative;
  transition: all 0.3s;
  color: #ccc;
  font-weight: 700;
  font-family: var(--font-mono);
}
.pipeline-step.active .step-dot {
  border-color: var(--green-primary);
  color: var(--green-primary);
  box-shadow: 0 0 0 4px rgba(45,106,45,0.1);
}
.pipeline-step.done .step-dot {
  border-color: var(--green-primary);
  background: var(--green-primary);
  color: #fff;
}
.step-label {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.pipeline-step.active .step-label { color: var(--green-primary); }
.pipeline-step.done .step-label { color: var(--green-primary); }

/* Result panel */
.pipeline-result {
  display: none;
  background: var(--green-pale);
  border: 1px solid #b2dfb2;
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 14px;
}
.pipeline-result.visible { display: block; }
.result-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--green-primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.result-item {
  background: #fff;
  border-radius: 7px;
  padding: 10px 12px;
  border: 1px solid #c8e6c9;
}
.ri-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.ri-val {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dark);
  font-family: var(--font-mono);
}
.ri-val.positive { color: var(--green-primary); }
/* RESPONSIVE — TABLET */
@media (max-width: 900px) {
  .layout { flex-direction: column; min-height: 0; }
  .sidebar {
    width: 100%; min-width: 0;
    /* Base rule pins a full-height sticky column (height: calc(100vh - 48px)) — undo it. */
    height: auto; position: static; overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row; align-items: center; flex-wrap: wrap;
    gap: 12px; padding: 10px 12px;
  }
  .sidebar-nav { flex: 1 1 100%; padding: 0; }
  .sidebar-bottom { margin-top: 0; border-top: none; padding: 0; }
  .main { padding: 16px 12px 24px; overflow-y: visible; }
  .agents-row, .agent1-grid, .bottom-row { flex-direction: column; }
  .page-header { flex-direction: column; gap: 12px; }
  .page-desc { max-width: 100%; }
  .result-grid { grid-template-columns: 1fr 1fr; }
  /* Popup is anchored to the desktop sidebar (left:196px) — untether it. */
  .chatbot-popup { left: 12px; right: 12px; width: auto; }
}

/* RESPONSIVE — PHONE */
@media (max-width: 600px) {
  .topnav { flex-wrap: wrap; height: auto; gap: 8px; padding: 8px 12px; }
  .top-tabs { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; }
  .result-grid { grid-template-columns: 1fr; }
  .chatbot-popup { bottom: 12px; height: min(400px, 65vh); }
}

/* RESPONSIVE — CHARTS */
@media (max-width: 900px) {
  /* Canvases carry hardcoded width/height attributes (histChart is 480px wide),
     so they cannot shrink on their own — scale them to the card instead. */
  canvas { max-width: 100%; height: auto; }
}

/* RESPONSIVE — AGENT 3 */
@media (max-width: 600px) {
  /* Agent 3 sets the strategy list and budget column side by side (.strategy-row).
     At 375px that leaves ~145px each, colliding the labels — stack them instead. */
  .strategy-row { flex-direction: column; gap: 14px; }
}

/* RESPONSIVE — PIPELINE STATUS */
@media (max-width: 600px) {
  /* #pipelineStatus lives inside .pipeline-btn-wrap and is EMPTY until a run
     finishes; once it fills with "Pipeline complete — all 5 agents synced" the
     nowrap row forces the whole page sideways. Let it wrap onto its own line. */
  .pipeline-section-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .pipeline-btn-wrap { flex-wrap: wrap; }
  .pipeline-status-text { flex: 1 0 100%; }
}
