:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --ink: #1c2826;
  --ink-soft: #5d6b68;
  --accent: #147a6b;
  --accent-soft: #2bb7a3;
  --user-bubble: #147a6b;
  --bot-bubble: #ffffff;
  --line: #e2e7e5;
  --shadow: 0 1px 3px rgba(20, 40, 36, 0.08), 0 8px 24px rgba(20, 40, 36, 0.06);
  --radius: 16px;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* --- Login --------------------------------------------------------------- */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #e8efed 0%, #d6e4e0 100%);
  z-index: 10;
}

.login-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 42px 38px;
  width: min(360px, 90vw);
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo { width: 64px; height: 64px; }

.login-card h1 {
  font-size: 1.35rem;
  margin-top: 14px;
  color: var(--accent);
}

.login-card > p {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin-top: 4px;
}

#login-form {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#password {
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

#password:focus { border-color: var(--accent-soft); }

#login-form button,
.composer button,
.btn-reset {
  cursor: pointer;
  border: none;
  font-family: inherit;
}

#login-form button {
  padding: 13px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.15s;
}

#login-form button:hover { background: #0f6457; }

.login-error {
  color: #c0392b;
  font-size: 0.85rem;
  min-height: 1.1em;
  margin-top: 10px;
}

/* --- App layout ---------------------------------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 820px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-logo { width: 36px; height: 36px; flex-shrink: 0; }

.topbar-text { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-text strong { font-size: 1rem; }
.topbar-text span { font-size: 0.78rem; color: var(--ink-soft); }

.btn-reset {
  margin-left: auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}

.btn-reset:hover { background: #e6ebe9; color: var(--accent); }
.btn-reset svg { width: 18px; height: 18px; }

/* --- Messages ------------------------------------------------------------ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg { display: flex; gap: 10px; max-width: 88%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.avatar.bot { background: #e3f1ee; }
.avatar.user { background: var(--accent); }
.avatar svg { width: 18px; height: 18px; }

.bubble {
  padding: 12px 15px;
  border-radius: var(--radius);
  font-size: 0.94rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.bot .bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--line);
  border-top-left-radius: 5px;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 5px;
}

/* --- Markdown renderizado ------------------------------------------------ */
.md { white-space: normal; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }

.md p { margin: 0 0 8px; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 14px 0 6px;
  line-height: 1.3;
  color: var(--accent);
}
.md h1 { font-size: 1.15rem; }
.md h2 { font-size: 1.06rem; }
.md h3 { font-size: 0.99rem; }
.md h4 { font-size: 0.94rem; }

.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md li { margin: 2px 0; }

.md strong { font-weight: 700; }
.md em { font-style: italic; }

.md a { color: var(--accent); text-decoration: underline; }

.md code {
  background: #eef3f1;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.86em;
}

.md pre {
  background: #f7faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0 10px;
  overflow-x: auto;
}
.md pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.84rem;
}

.md blockquote {
  margin: 6px 0 10px;
  padding: 4px 12px;
  border-left: 3px solid var(--accent-soft);
  color: var(--ink-soft);
}

.md hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}

.md table {
  border-collapse: collapse;
  margin: 6px 0 10px;
  font-size: 0.88rem;
  width: 100%;
}
.md th, .md td {
  border: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
}
.md th { background: #eef3f1; font-weight: 600; }

.tools-trace {
  margin-top: 8px;
  font-size: 0.76rem;
  color: var(--ink-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tool-chip {
  background: #eef3f1;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2px 9px;
}

.reasoning-toggle {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
}

.reasoning-body {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  background: #f7faf9;
  border-left: 3px solid var(--accent-soft);
  padding: 8px 11px;
  border-radius: 6px;
  white-space: pre-wrap;
}

/* --- Bienvenida ---------------------------------------------------------- */
.welcome {
  text-align: center;
  color: var(--ink-soft);
  margin: auto;
  padding: 20px;
}

.welcome svg { width: 56px; height: 56px; }
.welcome h2 { color: var(--ink); font-size: 1.1rem; margin: 12px 0 6px; }
.welcome p { font-size: 0.9rem; }

.suggestions {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestion {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--ink);
  transition: border-color 0.15s, color 0.15s;
}

.suggestion:hover { border-color: var(--accent-soft); color: var(--accent); }

/* --- Indicador de escritura --------------------------------------------- */
.typing { display: flex; gap: 4px; padding: 4px 2px; }

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-soft);
  animation: blink 1.3s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* --- Composer ------------------------------------------------------------ */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px 18px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

#input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 15px;
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.4;
  max-height: 140px;
  outline: none;
  transition: border-color 0.15s;
}

#input:focus { border-color: var(--accent-soft); }

.composer button {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background 0.15s, opacity 0.15s;
}

.composer button:hover { background: #0f6457; }
.composer button:disabled { opacity: 0.45; cursor: not-allowed; }
.composer button svg { width: 20px; height: 20px; }

@media (max-width: 600px) {
  .msg { max-width: 95%; }
}
