/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --border:    #2a2d3e;
  --accent:    #6c63ff;
  --accent2:   #a78bfa;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --user-bg:   #6c63ff;
  --maven-bg:  #1e2235;
  --tool-bg:   #151825;
  --radius:    16px;
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
}

.hidden { display: none !important; }

/* ── Login ───────────────────────────────────────────────────── */
#login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a1d3a 0%, var(--bg) 70%);
}

.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  width: min(380px, 92vw);
}

.logo {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; color: #fff;
}

.login-box h2 { font-size: 22px; font-weight: 700; }
.login-box .subtitle { color: var(--muted); font-size: 13px; }

.login-box input {
  width: 100%; padding: 12px 16px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 15px;
  outline: none; letter-spacing: 2px;
}
.login-box input:focus { border-color: var(--accent); }

.login-box button {
  width: 100%; padding: 13px;
  background: var(--accent); border: none;
  border-radius: 12px; color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
}
.login-box button:hover { opacity: .9; }

.error { color: #f87171; font-size: 13px; }

/* ── App shell ───────────────────────────────────────────────── */
#app {
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}

/* ── Dashboard ───────────────────────────────────────────────── */
#dashboard {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  overflow-y: auto;
  max-height: 42vh;
  flex-shrink: 0;
}

@media (max-width: 480px) {
  #dashboard { padding: 8px 10px; max-height: 48vh; }
}

.dash-header {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; margin-bottom: 6px;
}
.dash-update-time {
  font-size: 10px; color: var(--muted);
}
#dash-refresh-btn {
  background: none; border: none;
  color: var(--muted); font-size: 15px;
  cursor: pointer; padding: 0 2px;
  line-height: 1; transition: color .15s;
}
#dash-refresh-btn:hover { color: var(--accent2); }
#dash-refresh-btn.spinning {
  animation: spin .7s linear infinite;
  pointer-events: none;
}

.dash-loading {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px;
  padding: 4px 0;
}

/* Stat cards — 4 col desktop, 2x2 mobile */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

@media (max-width: 600px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
}
.stat-card.accent { border-color: #10b981; }

.stat-icon { font-size: 18px; flex-shrink: 0; }
.stat-body { min-width: 0; }
.stat-num  { font-size: 20px; font-weight: 800; line-height: 1; }
.stat-label {
  font-size: 10px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@media (max-width: 380px) {
  .stat-icon { font-size: 15px; }
  .stat-num  { font-size: 18px; }
  .stat-label { font-size: 9px; }
}

/* Pipeline */
.pipeline-section, .followup-section { margin-bottom: 8px; }

.section-title {
  font-size: 10px; font-weight: 700;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: .6px; margin-bottom: 5px;
}

.pipe-row {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
}
.pipe-label {
  font-size: 11px; color: var(--text);
  width: 90px; flex-shrink: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pipe-track {
  flex: 1; height: 7px;
  background: var(--bg);
  border-radius: 99px; overflow: hidden;
  border: 1px solid var(--border);
  min-width: 0;
}
.pipe-fill {
  height: 100%; border-radius: 99px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
  min-width: 5px;
}
.pipe-count {
  font-size: 11px; color: var(--muted);
  width: 14px; text-align: right; flex-shrink: 0;
}

@media (max-width: 380px) {
  .pipe-label { width: 75px; font-size: 10px; }
}

/* Follow-up list */
.fu-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 4px;
  gap: 6px;
  min-width: 0;
}
.fu-name {
  font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.fu-right { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.fu-date  { font-size: 11px; color: var(--muted); }
.fu-empty { color: var(--muted); font-size: 12px; padding: 3px 0; }

/* Badges */
.badge {
  font-size: 9px; font-weight: 700;
  padding: 2px 6px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .3px;
  white-space: nowrap;
}
.badge-purple { background: rgba(108,99,255,.2); color: #a78bfa; }
.badge-green  { background: rgba(16,185,129,.2); color: #34d399; }
.badge-yellow { background: rgba(245,158,11,.2); color: #fbbf24; }
.badge-orange { background: rgba(249,115,22,.2); color: #fb923c; }
.badge-blue   { background: rgba(59,130,246,.2); color: #60a5fa; }

/* ── Header ──────────────────────────────────────────────────── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }

.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff;
}

.name { font-weight: 700; font-size: 16px; }
.status { font-size: 12px; color: var(--muted); }
.status.thinking { color: var(--accent2); }

.header-actions { display: flex; gap: 6px; }

#clear-btn, #dash-toggle {
  background: none; border: 1px solid var(--border);
  color: var(--muted); border-radius: 10px;
  padding: 6px 10px; cursor: pointer; font-size: 16px;
  transition: color .15s, border-color .15s;
}
#clear-btn:hover, #dash-toggle:hover { color: var(--text); border-color: var(--accent); }

/* ── Messages ────────────────────────────────────────────────── */
#messages {
  flex: 1; overflow-y: auto;
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 8px;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.msg {
  display: flex;
  max-width: 82%;
  animation: fadeUp .2s ease;
}
.msg.user  { align-self: flex-end; flex-direction: row-reverse; }
.msg.maven { align-self: flex-start; }

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

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user  .bubble { background: var(--user-bg); color: #fff; border-bottom-right-radius: 4px; }
.msg.maven .bubble { background: var(--maven-bg); color: var(--text); border-bottom-left-radius: 4px; border: 1px solid var(--border); }

/* Markdown básico en respuestas de Maven */
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; color: var(--accent2); }
.bubble code {
  background: rgba(108,99,255,.18);
  padding: 1px 5px; border-radius: 5px;
  font-family: monospace; font-size: 13px;
}
.bubble pre {
  background: var(--tool-bg); border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 10px; overflow-x: auto;
  margin: 6px 0; font-size: 12.5px;
}

/* Burbuja de "escribiendo..." */
.typing .bubble {
  display: flex; gap: 5px; align-items: center;
  padding: 12px 16px;
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%; background: var(--accent2);
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%,80%,100% { transform: scale(1); opacity: .5; }
  40%         { transform: scale(1.25); opacity: 1; }
}

/* ── Tool indicator ──────────────────────────────────────────── */
.tool-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px;
  background: var(--tool-bg);
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--accent2);
  flex-shrink: 0;
}
.tool-spinner {
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Footer / input ──────────────────────────────────────────── */
footer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.voice-btn {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg); cursor: pointer; font-size: 18px;
  transition: background .15s, border-color .15s;
  display: flex; align-items: center; justify-content: center;
}
.voice-btn.recording {
  background: #dc2626;
  border-color: #dc2626;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.4); }
  50%      { box-shadow: 0 0 0 8px rgba(220,38,38,0); }
}

.input-wrap {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  transition: border-color .15s;
}
.input-wrap:focus-within { border-color: var(--accent); }

textarea {
  flex: 1; background: none; border: none;
  color: var(--text); font-size: 14.5px; font-family: var(--font);
  resize: none; outline: none;
  max-height: 120px; overflow-y: auto;
  line-height: 1.45;
}

#send-btn {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 50%; border: none;
  background: var(--accent); color: #fff;
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .1s;
}
#send-btn:hover  { opacity: .9; }
#send-btn:active { transform: scale(.93); }
#send-btn:disabled { opacity: .4; cursor: default; }
