/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg: #ffffff; --bg-secondary: #f8f9fa; --bg-tertiary: #f1f3f5;
  --text: #1a1a1a; --text-muted: #6b7280; --text-light: #9ca3af;
  --border: #e5e7eb; --border-strong: #d1d5db;
  --green: #1D9E75; --green-light: #e8f5ef;
  --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117; --bg-secondary: #1a1d27; --bg-tertiary: #232634;
    --text: #e8eaf0; --text-muted: #8b92a8; --text-light: #5c6380;
    --border: #2d3148; --border-strong: #3d4263;
    --green-light: #0d2e22;
  }
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: system-ui, -apple-system, sans-serif; font-size: 15px; background: var(--bg); color: var(--text); }

/* ── Screens ───────────────────────────────────────────────── */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── Start Screen ──────────────────────────────────────────── */
#start-screen { align-items: center; justify-content: center; padding: 2rem; }
.start-container { max-width: 420px; text-align: center; }
.start-logo { margin-bottom: 1.5rem; opacity: 0.85; }
.start-container h1 { font-size: 1.6rem; font-weight: 600; margin-bottom: 0.75rem; }
.start-desc { color: var(--text-muted); margin-bottom: 0.5rem; line-height: 1.6; }
.start-note { font-size: 0.82rem; color: var(--text-light); margin-bottom: 2rem; font-style: italic; }
.btn-primary { background: var(--green); color: white; border: none; padding: 12px 32px; border-radius: 8px; font-size: 1rem; font-weight: 500; cursor: pointer; transition: opacity 0.2s; }
.btn-primary:hover { opacity: 0.88; }

/* ── Chat Layout ───────────────────────────────────────────── */
#chat-screen { flex-direction: column; }
.chat-layout { display: flex; flex: 1; min-height: 0; }
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); }
.sidebar { width: 220px; flex-shrink: 0; display: flex; flex-direction: column; gap: 0; overflow-y: auto; background: var(--bg-secondary); }

/* ── Chat Header ───────────────────────────────────────────── */
#chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.header-title { font-size: 0.88rem; font-weight: 500; color: var(--text-muted); }
.header-right { display: flex; align-items: center; gap: 8px; }
.phase-badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 20px; background: var(--green-light); color: var(--green); font-weight: 500; }
.model-badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 20px; background: var(--bg-tertiary); color: var(--text-muted); }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1rem; padding: 4px 8px; border-radius: 6px; transition: background 0.15s; }
.btn-icon:hover { background: var(--bg-tertiary); }

/* ── Progress Bar ──────────────────────────────────────────── */
#progress-wrap { padding: 6px 16px 4px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-shrink: 0; }
#progress-track { height: 3px; background: var(--bg-tertiary); border-radius: 2px; overflow: hidden; margin-bottom: 3px; }
#progress-bar { height: 100%; background: var(--green); border-radius: 2px; transition: width 0.6s ease; width: 0%; }
#progress-label { font-size: 0.68rem; color: var(--text-light); display: block; }

/* ── Messages ──────────────────────────────────────────────── */
#messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--green); color: white; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 600; flex-shrink: 0; }
.msg.user .msg-avatar { background: var(--bg-tertiary); color: var(--text-muted); }
.msg-bubble { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; max-width: 85%; font-size: 0.9rem; line-height: 1.65; }
.msg.user .msg-bubble { background: var(--green-light); border-color: transparent; }
.msg-bubble p { margin: 0 0 0.5em; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h2 { font-size: 0.95rem; font-weight: 600; margin: 1rem 0 0.4rem; }
.msg-bubble h3 { font-size: 0.88rem; font-weight: 500; margin: 0.8rem 0 0.3rem; }
.msg-bubble ul { padding-left: 1.2rem; margin: 0.4rem 0; }
.msg-bubble li { margin-bottom: 0.25rem; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 0.8rem 0; }

/* ── Typing ────────────────────────────────────────────────── */
.typing-bubble { display: flex; align-items: center; gap: 5px; padding: 12px 16px; }
.typing-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-light); animation: bounce 1.2s infinite; }
.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* ── Report in chat ────────────────────────────────────────── */
.msg-report .msg-bubble { max-width: 95%; }
.report-bubble { padding: 1.2rem; }
.report-body { max-height: 55vh; overflow-y: auto; margin-bottom: 1rem; padding-right: 4px; }
.download-report-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; background: var(--green); color: white; border: none; border-radius: 8px; font-size: 0.85rem; cursor: pointer; font-weight: 500; transition: opacity 0.2s; }
.download-report-btn:hover { opacity: 0.85; }

/* ── Input ─────────────────────────────────────────────────── */
#input-area { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg); flex-shrink: 0; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
#user-input { flex: 1; padding: 10px 14px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--bg); color: var(--text); font-size: 0.9rem; resize: none; line-height: 1.5; max-height: 120px; font-family: inherit; }
#user-input:focus { outline: none; border-color: var(--green); }
#user-input:disabled { opacity: 0.5; }
.btn-send { width: 38px; height: 38px; border-radius: 8px; background: var(--green); color: white; border: none; cursor: pointer; font-size: 1.1rem; flex-shrink: 0; transition: opacity 0.2s; }
.btn-send:hover { opacity: 0.85; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.input-meta { font-size: 0.72rem; color: var(--text-light); margin-top: 4px; display: flex; gap: 8px; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar-section { padding: 14px 12px; border-bottom: 1px solid var(--border); }
.sidebar-title { font-size: 0.68rem; font-weight: 600; color: var(--text-light); letter-spacing: 0.08em; margin-bottom: 10px; }
.empty-hint { font-size: 0.78rem; color: var(--text-light); font-style: italic; }

/* ── Hypotheses ────────────────────────────────────────────── */
.h-item { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.h-code { font-size: 0.72rem; font-weight: 600; color: var(--green); width: 52px; flex-shrink: 0; }
.h-bar-wrap { flex: 1; height: 5px; background: var(--bg-tertiary); border-radius: 3px; overflow: hidden; }
.h-bar { height: 100%; background: var(--green); border-radius: 3px; transition: width 0.5s ease; }
.h-pct { font-size: 0.7rem; color: var(--text-muted); width: 30px; text-align: right; }
.descartados { font-size: 0.65rem; color: var(--text-light); margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--border); line-height: 1.4; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 600px) {
  .sidebar { display: none; }
  .chat-panel { border-right: none; }
}

/* ── Email capture ─────────────────────────────────────────── */
.report-actions { margin-bottom: 12px; }
.email-capture { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; }
.email-caption { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 8px; }
.email-row { display: flex; gap: 8px; }
#email-input { flex: 1; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 0.85rem; background: var(--bg); color: var(--text); }
#email-input:focus { outline: none; border-color: var(--green); }
#email-send-btn { padding: 8px 16px; background: var(--green); color: white; border: none; border-radius: 8px; font-size: 0.85rem; cursor: pointer; font-weight: 500; white-space: nowrap; }
#email-send-btn:hover { opacity: 0.85; }
#email-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#email-status { font-size: 0.78rem; color: var(--text-muted); display: block; margin-top: 6px; }

/* ── Mic button ─────────────────────────────────────────────── */
#mic-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
#mic-btn:hover { border-color: var(--green); }
#mic-btn.recording {
  background: #fee2e2;
  border-color: #e53e3e;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* ── Redirect block ─────────────────────────────────────────── */
.redirect-block {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface, #f0faf5);
  border-radius: 10px;
  border: 1px solid var(--border, #d0e8de);
}
.redirect-caption {
  font-size: 0.85rem;
  color: var(--text-muted, #666);
  margin: 0 0 10px 0;
}
.redirect-btn {
  display: inline-block;
  background: var(--green, #1D9E75);
  color: white !important;
  padding: 10px 18px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity 0.2s;
}
.redirect-btn:hover { opacity: 0.88; }
