/* ===== Chat follow-up section ===== */

.chat-section {
  margin: 16px 0 8px;
  border: 1px solid var(--line-soft, #e2e8e4);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface, #fff);
  animation: fadeSlideIn 0.2s ease;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--green-light, #f0f7f3);
  border-bottom: 1px solid var(--line-soft, #e2e8e4);
  font-size: 13px;
  font-weight: 600;
  color: var(--green-dark, #1B4332);
}

.chat-header span { flex: 1; }

.chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted, #6b7c74);
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s;
}
.chat-close:hover { background: var(--line-soft, #e2e8e4); }

.chat-messages {
  min-height: 48px;
  max-height: 300px;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.ai   { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-msg.user .chat-bubble {
  background: var(--green-dark, #1B4332);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-msg.ai .chat-bubble {
  background: var(--green-light, #f0f7f3);
  color: var(--text, #1a2e22);
  border-bottom-left-radius: 3px;
}

.chat-msg.ai.loading .chat-bubble {
  color: var(--text-muted, #6b7c74);
  font-style: italic;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line-soft, #e2e8e4);
  background: var(--bg, #f8faf9);
}

#chatInput {
  flex: 1;
  resize: none;
  border: 1px solid var(--line-soft, #e2e8e4);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface, #fff);
  color: var(--text, #1a2e22);
  outline: none;
  line-height: 1.45;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
#chatInput:focus { border-color: var(--green-mid, #2d6a4f); }
#chatInput::placeholder { color: var(--text-muted, #6b7c74); }

.chat-send-btn {
  background: var(--green-dark, #1B4332);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.chat-send-btn:hover   { opacity: 0.87; }
.chat-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ===== Per-step inline chat ===== */
.step-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 4px 10px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted, #64748b);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.step-chat-btn:hover {
  background: var(--accent-light, #eff6ff);
  color: var(--accent, #3b82f6);
}
.step-chat-wrap {
  margin-top: 10px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-card, #fff);
}
.step-chat-wrap.hidden { display: none; }
.sc-msgs {
  max-height: 260px;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sc-msg { display: flex; }
.sc-msg.user  { justify-content: flex-end; }
.sc-msg.ai, .sc-msg.system { justify-content: flex-start; }
.sc-bubble {
  max-width: 85%;
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 0.84rem;
  line-height: 1.45;
  word-break: break-word;
}
.sc-msg.user   .sc-bubble { background: var(--accent, #3b82f6); color: #fff; border-bottom-right-radius: 3px; }
.sc-msg.ai     .sc-bubble { background: var(--bg-input, #f1f5f9); color: var(--text, #1e293b); border-bottom-left-radius: 3px; }
.sc-msg.system .sc-bubble { background: transparent; color: var(--text-muted, #94a3b8); font-size: 0.75rem; }
.sc-msg.loading .sc-bubble { opacity: 0.6; font-style: italic; }
.sc-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border, #e2e8f0);
  background: var(--bg-input-wrap, #f8fafc);
}
.sc-input {
  flex: 1;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.84rem;
  resize: none;
  outline: none;
  background: var(--bg-input, #fff);
  color: var(--text, #1e293b);
  min-height: 34px;
  max-height: 100px;
  overflow-y: auto;
}
.sc-input:focus { border-color: var(--accent, #3b82f6); }
.sc-send {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent, #3b82f6);
  color: #fff;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}
.sc-send:hover { opacity: 0.85; }
.sc-send:disabled { opacity: 0.35; cursor: not-allowed; }

/* Hide step chat on locked steps; auto-reveals when .step-locked is removed by revealBtn */
.step-locked .step-chat-btn,
.step-locked .step-chat-wrap { display: none; }

/* ===== Credit cost badge in history cards ===== */
.hc-credit-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted, #8B93A1);
  background: var(--bg-subtle, rgba(0,0,0,0.04));
  border: 1px solid var(--line-soft, rgba(0,0,0,0.07));
  border-radius: 10px;
  padding: 1px 6px;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}
.hc-credit-badge[data-hc-credits="1"] { /* base cost — subtle */ }
.hc-credit-badge:not([data-hc-credits="1"]) {
  color: var(--accent, #6366F1);
  background: rgba(99,102,241,0.08);
  border-color: rgba(99,102,241,0.18);
}

/* MYBAD1 refund button — appears inline in AI chat bubble */
.mybad-redeem-btn {
  display: block;
  margin-top: 8px;
  padding: 4px 12px;
  border: 1px solid #7c3aed;
  background: transparent;
  color: #7c3aed;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.mybad-redeem-btn:hover:not(:disabled) { background: rgba(124,58,237,0.08); }
.mybad-redeem-btn:disabled { opacity: 0.7; cursor: default; }
.mybad-redeem-btn.mybad-ok { border-color: #16a34a; color: #16a34a; }
.mybad-redeem-btn.mybad-err { border-color: #dc2626; color: #dc2626; }

/* ===== Interactive graph (s2s-plot + pin annotations) ===== */
.s2s-plot {
  margin: 14px 0;
  border-radius: 10px;
  overflow: visible;
  background: #f8faff;
  border: 1px solid #e0e7ff;
  cursor: crosshair;
  position: relative;
}
.s2s-plot-hint {
  text-align: center;
  font-size: 11px;
  color: #6366f1;
  padding: 4px 0 8px;
  opacity: 0.7;
  pointer-events: none;
}
.s2s-pin {
  position: absolute;
  pointer-events: auto;
  z-index: 20;
}
.pin-dot {
  width: 10px;
  height: 10px;
  background: #4338CA;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  position: absolute;
  left: -5px;
  top: -5px;
}
.pin-bubble {
  position: absolute;
  left: 10px;
  top: -8px;
  background: #fff;
  border: 1px solid #e0e7ff;
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  width: 220px;
  font-size: 13px;
  z-index: 21;
}
.pin-coord {
  font-weight: 600;
  color: #4338CA;
  margin-bottom: 6px;
  font-size: 12px;
}
.pin-input {
  width: 100%;
  border: 1px solid #e0e7ff;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  resize: none;
  outline: none;
  box-sizing: border-box;
}
.pin-input:focus { border-color: #4338CA; }
.pin-btns {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.pin-send {
  flex: 1;
  background: #4338CA;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.pin-send:hover { opacity: 0.85; }
.pin-send:disabled { opacity: .5; cursor: not-allowed; }
.pin-close {
  background: none;
  border: 1px solid #e0e7ff;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  color: #64748b;
}
.pin-close:hover { background: #f1f5f9; }
.pin-answer {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: #1e293b;
  max-height: 120px;
  overflow-y: auto;
}
.pin-answer.hidden { display: none; }
