/* =================================================================
 * Asistente Rols — chatbot conversacional central.
 * Paleta y patrones consistentes con calc / consulta-stock.
 * ================================================================= */

/* Paleta y tokens de diseño: fuente única en shared/static/rols-tokens.css
   (servido en /shared/rols-tokens.css). No redefinir aquí. */
@import url("/shared/rols-tokens.css");

* { box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0;
  background: var(--bg-page);
  color: #2a2a2a;
}

/* ============= Login ============= */
.login-card {
  background: #fff; border: 1px solid var(--border); border-radius: 18px;
  padding: 2.25rem 2rem; width: 380px; max-width: calc(100vw - 2rem);
  box-shadow: 0 24px 48px -20px rgba(77,77,77,0.15);
}
.login-brand { text-align: center; margin-bottom: 1.25rem; }
.login-logo { width: 80px; height: auto; display: inline-block; }
.login-title {
  font-size: 1.55rem; font-weight: 300; text-align: center;
  color: #2a2a2a; margin: 0 0 0.25rem 0;
}
.login-title-em {
  font-weight: 500; position: relative;
  border-bottom: 2px solid #2a2a2a; padding-bottom: 2px;
}
.login-subtitle {
  text-align: center; font-size: 0.85rem; color: #7A7A7A; margin: 0 0 1.5rem 0;
}
.login-error {
  background: #f8e0e0; border: 1px solid #d8b8b8; color: #6f1f1f;
  border-radius: 10px; padding: 0.55rem 0.85rem; font-size: 0.82rem;
  margin-bottom: 1rem; text-align: center;
}
.login-form { display: flex; flex-direction: column; gap: 0.85rem; }
.login-field { display: flex; flex-direction: column; gap: 0.3rem; }
.login-field > span { font-size: 0.78rem; font-weight: 500; color: #4D4D4D; }
.login-field input {
  padding: 0.65rem 0.85rem; border: 1px solid var(--border); border-radius: 12px;
  font-size: 0.9rem; font-family: inherit; background: #FAF8F6; color: #2a2a2a;
  outline: none; transition: border-color 0.15s, background 0.15s;
}
.login-field input:focus { border-color: var(--accent); background: #fff; }
.login-btn {
  margin-top: 0.4rem;
  background: var(--accent); color: #fff; border: none;
  padding: 0.7rem 1rem; border-radius: 12px;
  font-family: inherit; font-size: 0.9rem; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
}
.login-btn:hover { background: var(--accent-hover); }
.login-foot {
  margin-top: 1.2rem; text-align: center; font-size: 0.72rem; color: #9a9a9a;
}

/* ============= Layout principal (chat) ============= */
.asistente-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.asistente-sidebar {
  background: var(--bg-sidebar); color: var(--text-sidebar);
  display: flex; flex-direction: column;
  padding: 1.25rem 0.85rem;
}
.asistente-brand {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0 0.4rem; margin-bottom: 1.5rem;
}
.asistente-brand img {
  width: 70px; height: auto;
  filter: brightness(0) invert(1);
}
.asistente-brand-tag {
  font-size: 0.65rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent);
  border: 1px solid var(--accent); padding: 0.1rem 0.5rem; border-radius: 999px;
  margin-left: auto;
}

.btn-nueva {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--accent); color: #fff; border: none;
  padding: 0.55rem 0.85rem; border-radius: 10px;
  font-family: inherit; font-size: 0.82rem; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
  margin-bottom: 1.25rem;
}
.btn-nueva:hover { background: var(--accent-hover); }

.asistente-history { flex-grow: 1; overflow-y: auto; min-height: 0; }
.asistente-history-label,
.asistente-apps-label {
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #9a9a8e;
  padding: 0 0.4rem; margin-bottom: 0.45rem;
}
.asistente-history-list { list-style: none; padding: 0; margin: 0 0 1rem 0; display: flex; flex-direction: column; gap: 1px; }
.asistente-history-list li {
  position: relative;
  font-size: 0.82rem; line-height: 1.3; color: var(--text-sidebar);
}
.asistente-history-list a {
  display: block; padding: 0.5rem 0.65rem; border-radius: 8px;
  text-decoration: none; color: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.12s;
  padding-right: 1.8rem;
}
.asistente-history-list a:hover { background: var(--bg-sidebar-hover); }
.asistente-history-list a.active {
  background: var(--bg-sidebar-active); color: var(--text-sidebar-active);
}
.asistente-history-loading {
  font-size: 0.78rem; color: #9a9a8e; padding: 0.4rem 0.65rem;
}
.history-delete {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: #c5b8ad;
  width: 24px; height: 24px; border-radius: 6px;
  cursor: pointer; opacity: 0; transition: opacity 0.12s, background 0.12s;
  display: inline-flex; align-items: center; justify-content: center;
}
.asistente-history-list li:hover .history-delete { opacity: 1; }
.history-delete:hover { background: rgba(255,255,255,0.1); color: #fff; }

.asistente-apps {
  margin: 0.5rem 0 0.75rem 0;
  padding-top: 0.75rem; border-top: 1px solid rgba(255,255,255,0.08);
}
.asistente-app-link {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.45rem 0.65rem; border-radius: 8px;
  text-decoration: none; color: var(--text-sidebar);
  font-size: 0.82rem; transition: background 0.12s;
}
.asistente-app-link:hover { background: var(--bg-sidebar-hover); color: #fff; }
.dot-violet, .dot-blue {
  width: 8px; height: 8px; border-radius: 999px; display: inline-block;
}
.dot-violet { background: #b89eea; }
.dot-blue   { background: #8fb7e6; }

.asistente-user {
  padding-top: 0.75rem; border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 0.55rem;
  font-size: 0.82rem;
}
.asistente-user-info { display: flex; align-items: center; gap: 0.55rem; flex-grow: 1; min-width: 0; }
.asistente-user-avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 600;
  flex-shrink: 0;
}
.asistente-user-name { font-weight: 500; color: #fff; line-height: 1.1; }
.asistente-user-rol { font-size: 0.7rem; color: #b8aa9e; line-height: 1.1; margin-top: 1px; }
.asistente-logout {
  width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #b8aa9e; text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.asistente-logout:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* ===== Main: thread + composer ===== */
.asistente-main {
  display: flex; flex-direction: column;
  background: var(--bg-page);
  max-height: 100vh; min-height: 100vh;
}
.asistente-thread {
  flex-grow: 1; overflow-y: auto;
  padding: 1.5rem 1.5rem 1rem 1.5rem;
  scroll-behavior: smooth;
}
.asistente-thread-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: #9a9a9a; text-align: center;
}
.asistente-thread-empty .emoji { font-size: 2.5rem; margin-bottom: 0.6rem; }
.asistente-thread-empty h2 { font-size: 1.2rem; font-weight: 400; margin: 0 0 0.35rem 0; color: #4D4D4D; }
.asistente-thread-empty p { font-size: 0.88rem; margin: 0; max-width: 380px; }

.msg-row { display: flex; gap: 0.7rem; margin-bottom: 1rem; max-width: 800px; }
.msg-row.user { justify-content: flex-end; margin-left: auto; }
.msg-row.assistant { justify-content: flex-start; margin-right: auto; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 999px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700;
}
.msg-row.assistant .msg-avatar { background: var(--accent-soft); color: var(--accent-hover); }
.msg-row.user .msg-avatar { display: none; }

.msg-bubble {
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem; line-height: 1.5; color: #2a2a2a;
  max-width: 100%;
}
.msg-row.user .msg-bubble {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.msg-row.user .msg-bubble strong { color: #fff; }
.msg-bubble strong { color: #4D4D4D; }
.msg-bubble a { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 2px; }

.msg-meta {
  margin-top: 0.4rem;
  font-size: 0.7rem; color: #9a9a9a;
  display: flex; align-items: center; gap: 0.5rem;
}
.msg-skill { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Deep-link button dentro del mensaje del asistente */
.msg-deep-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin-top: 0.7rem;
  background: var(--accent-soft); color: var(--accent-hover);
  font-size: 0.78rem; font-weight: 500;
  padding: 0.4rem 0.85rem; border-radius: 999px;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.msg-deep-link:hover {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
  text-decoration: none;
}

/* Composer (input) */
.asistente-composer {
  display: flex; gap: 0.5rem; align-items: flex-end;
  padding: 0.85rem 1.5rem 0.4rem 1.5rem;
  background: var(--bg-page);
}
.asistente-composer textarea {
  flex-grow: 1; resize: none;
  font-family: inherit; font-size: 0.92rem; line-height: 1.4;
  padding: 0.7rem 0.95rem;
  border: 1px solid var(--border); border-radius: 14px;
  background: #fff;
  outline: none;
  min-height: 44px; max-height: 200px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.asistente-composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(213,179,140,0.15);
}
.composer-send {
  background: var(--accent); color: #fff; border: none;
  width: 44px; height: 44px; border-radius: 12px;
  cursor: pointer; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s, transform 0.08s;
}
.composer-send:hover { background: var(--accent-hover); }
.composer-send:active { transform: scale(0.96); }
.composer-send:disabled { opacity: 0.6; cursor: wait; }
.spinner {
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%; width: 14px; height: 14px;
  animation: spin 0.6s linear infinite;
}
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Sugerencias rapidas (chips) */
.asistente-suggestions {
  display: flex; gap: 0.4rem; flex-wrap: wrap;
  padding: 0 1.5rem 1rem 1.5rem;
}
.chip-sugg {
  background: #fff; border: 1px solid var(--border); color: #7A7A7A;
  font-family: inherit; font-size: 0.78rem;
  padding: 0.4rem 0.85rem; border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip-sugg:hover {
  background: var(--accent-soft); color: var(--accent-hover);
  border-color: var(--accent);
}

/* Responsive: sidebar colapsable en moviles */
@media (max-width: 768px) {
  .asistente-layout { grid-template-columns: 1fr; }
  .asistente-sidebar { display: none; }
}

/* ============= Modo EMBED (iframe desde calc / stock) =============
 * Cuando otra app de Rols Suite embebe el asistente vía iframe con
 * ?embed=1, ocultamos la sidebar (history + apps) y compactamos el
 * layout. La conversacion (history persistente) sigue activa: el LLM
 * recupera el contexto al reabrir el iframe. */
body.embed { background: var(--bg-page); }
body.embed .asistente-layout { grid-template-columns: 1fr; }
body.embed .asistente-sidebar { display: none; }
body.embed .asistente-main { max-height: 100vh; min-height: 100vh; }
body.embed .asistente-thread { padding: 1rem; }
body.embed .asistente-composer { padding: 0.6rem 1rem 0.4rem 1rem; }
body.embed .asistente-suggestions { padding: 0 1rem 0.75rem 1rem; }
/* En login embebido, centramos pero algo mas pequeño */
body.embed .login-card { width: 320px; padding: 1.5rem 1.25rem; }
