:root {
  --bg: #0d0f14;
  --bg-alt: #141824;
  --surface: #1a1f2e;
  --surface-2: #222840;
  --border: #2b3350;
  --text: #e8eaf2;
  --text-dim: #9aa3bd;
  --accent: #7c5cff;
  --accent-hover: #9378ff;
  --danger: #ff6b81;
  --radius: 14px;
  font-size: 15px;
}

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

/* Scrollbars con los colores del tema */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--accent); }
*::-webkit-scrollbar-corner { background: transparent; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
}

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1d1640 0%, var(--bg) 60%);
}

.login-card {
  width: min(380px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 34px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 1.5rem; margin-top: 14px; }
.login-logo p { color: var(--text-dim); font-size: 0.85rem; margin-top: 4px; }

.logo-mark {
  width: 52px; height: 52px;
  margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), #4f8cff);
  border-radius: 14px;
  font-size: 1.6rem; font-weight: 800; color: white;
}
.logo-mark.small { width: 30px; height: 30px; font-size: 0.95rem; border-radius: 8px; margin: 0; }
.logo-mark.big { width: 64px; height: 64px; font-size: 2rem; margin-bottom: 18px; }

.login-card label { display: block; font-size: 0.8rem; color: var(--text-dim); margin: 14px 0 6px; }
.login-card input {
  width: 100%;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 0.95rem;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%;
  margin-top: 22px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px;
  cursor: pointer;
}
.login-card button:hover:not(:disabled) { background: var(--accent-hover); }
.login-card button:disabled { opacity: 0.6; cursor: default; }
.login-error { color: var(--danger); font-size: 0.85rem; margin-top: 12px; min-height: 1.2em; text-align: center; }

/* ---------- App layout ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 15, 20, 0.9);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; }
.topbar-actions button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 0.82rem;
  cursor: pointer;
}
.topbar-actions button:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Chat ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 26px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.welcome {
  margin: auto;
  text-align: center;
  max-width: 720px;
  padding: 30px 10px;
}
.welcome h2 { font-size: 1.35rem; font-weight: 600; margin-bottom: 26px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px; }
.suggestion {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.suggestion:hover { border-color: var(--accent); color: var(--text); }

.msg { max-width: 860px; width: 100%; margin: 0 auto; display: flex; gap: 12px; }
.msg .avatar {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
}
.msg.user .avatar { background: var(--surface-2); color: var(--text-dim); }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), #4f8cff); color: white; }

.msg .bubble { flex: 1; min-width: 0; padding-top: 4px; line-height: 1.65; overflow-wrap: break-word; }
.msg.user .bubble { color: var(--text); white-space: pre-wrap; }

/* Actividad de herramientas */
.tool-log {
  font-size: 0.78rem;
  color: var(--text-dim);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 6px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.tool-log .tool-line { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.tool-log .tool-line .dot { color: var(--accent); }
.tool-log details { margin-top: 2px; }
.tool-log summary { cursor: pointer; }
.tool-log pre {
  white-space: pre-wrap;
  margin-top: 6px;
  color: #b8c0d8;
  max-height: 180px;
  overflow-y: auto;
}

.thinking { padding: 6px 0; }
.thinking-text {
  font-size: 0.88rem;
  background: linear-gradient(90deg, var(--text-dim) 30%, var(--text) 50%, var(--text-dim) 70%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 1.8s linear infinite;
}
.thinking-text::after {
  content: '';
  color: var(--text-dim);
  animation: ellipsis 1.5s steps(4, end) infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes ellipsis {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* Markdown */
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 8px; font-size: 1.05rem; }
.bubble p { margin: 8px 0; }
.bubble ul, .bubble ol { margin: 8px 0 8px 22px; }
.bubble code {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.85em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.bubble pre {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.bubble pre code { background: none; border: none; padding: 0; }

.bubble table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
  display: block;
  overflow-x: auto;
  font-size: 0.86rem;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
  white-space: nowrap;
}
.bubble th { background: var(--surface-2); position: sticky; top: 0; }
.bubble tr:nth-child(even) td { background: var(--bg-alt); }

.msg .error-text { color: var(--danger); font-size: 0.88rem; }

/* ---------- Composer ---------- */
.composer-wrap { padding: 10px 16px 16px; }
.composer {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 10px 10px 18px;
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
  max-height: 180px;
  /* centra la línea de texto respecto al botón de enviar (38px de alto) */
  padding: 8px 0;
}
.composer button {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.composer button:hover:not(:disabled) { background: var(--accent-hover); }
.composer button:disabled { opacity: 0.45; cursor: default; }
.composer-hint {
  max-width: 860px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-dim);
}
