/* stamps.cl — deterministic philatelic chat assistant widget.
   Inherits the active theme via CSS custom properties (--accent, --card, --text…) so it looks
   right in every skin (Patrimonio, Oscuro, Claro, Infantil) and follows the light/dark choice.
   Sizes use rem/em so the "Senior Mode" font scaling and high-contrast toggle apply automatically. */

/* ---- Floating launcher bubble ---- */
.asst-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1030;                 /* above page content but BELOW Bootstrap modals (1040+), so a ficha
                                    opened from a result card appears on top of the chat panel */
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--accent, #5b8cff);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.asst-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.34); }
.asst-fab:focus-visible { outline: 3px solid var(--accent-2, #b3892f); outline-offset: 2px; }
.asst-fab .asst-fab-badge {
  position: absolute; top: -0.15rem; right: -0.15rem;
  background: #e5484d; color: #fff; border-radius: 999px;
  font-size: 0.6rem; padding: 0.05rem 0.3rem; font-weight: 700;
}

/* ---- Panel ---- */
.asst-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1035;
  width: min(420px, calc(100vw - 2rem));
  height: min(660px, calc(100vh - 2.5rem));
  display: flex;
  flex-direction: column;
  background: var(--bg, #0b0f1a);
  color: var(--text, #e8edf7);
  border: 1px solid var(--panel-border, rgba(255, 255, 255, 0.12));
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  animation: asstIn 0.18s ease;
}
@keyframes asstIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.asst-panel[hidden] { display: none; }

.asst-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  background: var(--accent, #5b8cff);
  color: #fff;
}
.asst-head .asst-avatar {
  flex: 0 0 auto; font-size: 1.25rem; width: 2.2rem; height: 2.2rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.18);
}
.asst-head-txt { flex: 1 1 auto; min-width: 0; }
.asst-head .asst-title { font-weight: 800; line-height: 1.15; }
.asst-head .asst-sub { font-size: 0.72rem; opacity: 0.92; display: flex; align-items: center; }
/* Pulsing "online" dot — the assistant answers instantly, so it is always live. */
.asst-dot {
  display: inline-block; width: 0.5rem; height: 0.5rem; border-radius: 50%;
  background: #38d39f; margin-right: 0.35rem; flex: 0 0 auto;
  animation: asstPulse 2s infinite;
}
@keyframes asstPulse {
  0% { box-shadow: 0 0 0 0 rgba(56, 211, 159, 0.5); }
  70% { box-shadow: 0 0 0 5px rgba(56, 211, 159, 0); }
  100% { box-shadow: 0 0 0 0 rgba(56, 211, 159, 0); }
}
.asst-head .asst-act, .asst-head .asst-close {
  flex: 0 0 auto; background: transparent; border: none; color: #fff; cursor: pointer;
  line-height: 1; border-radius: 8px; opacity: 0.92;
}
.asst-head .asst-act { font-size: 1.05rem; padding: 0.25rem 0.35rem; }
.asst-head .asst-close { font-size: 1.5rem; padding: 0.1rem 0.35rem; }
.asst-head .asst-act:hover, .asst-head .asst-close:hover { background: rgba(255, 255, 255, 0.2); opacity: 1; }

/* ---- Trending strip ("lo más consultado") ---- */
.asst-trend { padding: 0.6rem 0.9rem 0.15rem; border-bottom: 1px solid var(--panel-border, rgba(255, 255, 255, 0.1)); }
.asst-trend[hidden] { display: none; }
.asst-trend-t { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted, #8a96b3); font-weight: 800; margin-bottom: 0.4rem; }
.asst-trend-chips { display: flex; gap: 0.4rem; overflow-x: auto; padding-bottom: 0.4rem; scrollbar-width: thin; }
.asst-trend-chip {
  flex: 0 0 auto; font-size: 0.74rem; padding: 0.32rem 0.72rem; border-radius: 999px; cursor: pointer;
  white-space: nowrap; color: var(--accent, #5b8cff); font-weight: 600;
  background: color-mix(in srgb, var(--accent, #5b8cff) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent, #5b8cff) 35%, transparent);
}
.asst-trend-chip:hover { background: var(--accent, #5b8cff); color: #fff; }

/* ---- Messages ---- */
.asst-msgs {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  background: var(--bg, #0b0f1a);
}
.asst-row { display: flex; }
.asst-row.user { justify-content: flex-end; }
.asst-row.bot { justify-content: flex-start; }

/* Message cards: titled (sender header) + body + footer, mirroring the reference chat layout. */
.asst-bubble {
  min-width: 0;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.45;
  padding: 0.6rem 0.75rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
.asst-row.bot .asst-bubble {
  max-width: 90%;
  background: var(--card, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--panel-border, rgba(255, 255, 255, 0.12));
  border-top-left-radius: 4px;
}
.asst-row.user .asst-bubble {
  max-width: 82%;
  background: var(--accent, #5b8cff);
  color: #fff;
  border-top-right-radius: 4px;
}

/* Sender header inside the bot card (avatar + name), like "Juan Pablo" in the reference. */
.asst-sender { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.35rem; }
.asst-sender-av {
  flex: 0 0 auto; width: 1.3rem; height: 1.3rem; border-radius: 50%; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent, #5b8cff) 20%, transparent);
}
.asst-sender-n { font-size: 0.74rem; font-weight: 800; color: var(--accent, #5b8cff); letter-spacing: 0.2px; }

/* Message body text (wraps preserving line breaks). */
.asst-body { white-space: pre-wrap; word-wrap: break-word; }

/* Card footer: controls left, timestamp right. */
.asst-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.5rem; }
.asst-foot-ctrls { display: flex; gap: 0.35rem; }
.asst-foot-time { font-size: 0.62rem; opacity: 0.75; white-space: nowrap; margin-left: auto; }
.asst-row.user .asst-foot { margin-top: 0.25rem; justify-content: flex-end; }
.asst-row.user .asst-foot-time { color: #fff; }

/* Animated "typing" dots inside the pending bot bubble. */
.asst-typing-dots { display: inline-flex; gap: 4px; padding: 0.15rem 0; }
.asst-typing-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted, #8a96b3); animation: asstBlink 1.2s infinite; }
.asst-typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.asst-typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes asstBlink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ---- Result cards ---- */
.asst-cards { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 0.5rem; }
.asst-card {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.4rem; border-radius: 10px; cursor: pointer; text-align: left; width: 100%;
  background: var(--tile, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--panel-border, rgba(255, 255, 255, 0.1));
  color: inherit;
}
.asst-card:hover { border-color: var(--accent, #5b8cff); }
.asst-card img { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; background: #fff; flex: 0 0 auto; }
.asst-card .asst-card-body { min-width: 0; }
.asst-card .asst-card-name { font-size: 0.82rem; font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.asst-card .asst-card-meta { font-size: 0.7rem; color: var(--muted, #8a96b3); }

/* ---- Sources + actions ---- */
.asst-sources { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.asst-src {
  font-size: 0.72rem; padding: 0.2rem 0.5rem; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px dashed var(--panel-border, rgba(255, 255, 255, 0.25));
  color: var(--muted, #8a96b3);
}
.asst-src:hover { color: var(--accent, #5b8cff); border-color: var(--accent, #5b8cff); }

.asst-catalog-btn {
  margin-top: 0.5rem; font-size: 0.78rem; padding: 0.35rem 0.7rem; border-radius: 8px; cursor: pointer;
  background: var(--accent, #5b8cff); color: #fff; border: none; font-weight: 600;
}

/* ---- Suggestion chips ---- */
.asst-suggestions { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0 0.9rem 0.6rem; }
.asst-chip {
  font-size: 0.78rem; padding: 0.35rem 0.7rem; border-radius: 999px; cursor: pointer;
  background: var(--panel, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--panel-border, rgba(255, 255, 255, 0.18));
  color: var(--text, #e8edf7);
}
.asst-chip:hover { border-color: var(--accent, #5b8cff); color: var(--accent, #5b8cff); }

/* ---- Feedback / footer control buttons (subtle icon buttons) ---- */
.asst-feedback { display: flex; gap: 0.35rem; margin-top: 0.45rem; }
.asst-fb {
  background: transparent; border: none; border-radius: 7px; cursor: pointer;
  font-size: 0.9rem; line-height: 1; padding: 0.15rem 0.3rem; opacity: 0.7;
}
.asst-fb:hover { opacity: 1; background: color-mix(in srgb, var(--accent, #5b8cff) 15%, transparent); }
.asst-fb.done { opacity: 1; }
/* On the accent-coloured user bubble the icons must stay legible (not used today, defensive). */
.asst-row.user .asst-fb { color: #fff; }

/* ---- Input ---- */
.asst-input {
  display: flex; gap: 0.5rem; align-items: flex-end;
  padding: 0.75rem 0.9rem;
  border-top: 1px solid var(--panel-border, rgba(255, 255, 255, 0.12));
  background: var(--bg, #0b0f1a);
}
.asst-input textarea {
  flex: 1 1 auto; resize: none; max-height: 6rem; min-height: 2.7rem;
  padding: 0.65rem 0.85rem; border-radius: 22px; font: inherit; font-size: 0.92rem; line-height: 1.35;
  background: var(--tile, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--panel-border, rgba(255, 255, 255, 0.18));
  color: var(--text, #e8edf7);
}
.asst-input textarea::placeholder { color: var(--muted, #8a96b3); }
.asst-input textarea:focus { outline: none; border-color: var(--accent, #5b8cff); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #5b8cff) 18%, transparent); }
.asst-send {
  flex: 0 0 auto; width: 2.7rem; height: 2.7rem; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent, #5b8cff); color: #fff; font-size: 1.15rem;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.asst-send:hover:not(:disabled) { transform: scale(1.06); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28); }
.asst-send:disabled { opacity: 0.5; cursor: default; }

/* Voice input button: neutral tile when idle, so it reads as secondary to Send. */
.asst-mic {
  flex: 0 0 auto; width: 2.7rem; height: 2.7rem; border-radius: 50%; cursor: pointer;
  background: var(--tile, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--panel-border, rgba(255, 255, 255, 0.18));
  color: var(--text, #e8edf7); font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.asst-mic:hover { transform: scale(1.06); }
/* Recording: red, pulsing halo — the assistant is listening and will auto-stop on silence. */
.asst-mic.rec {
  background: #e5484d; border-color: #e5484d; color: #fff;
  animation: asstMicPulse 1.4s infinite;
}
.asst-mic.asst-busy { opacity: 0.75; cursor: default; }
@keyframes asstMicPulse {
  0% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0); }
}

/* Small screens: full-width sheet. */
@media (max-width: 480px) {
  .asst-panel { right: 0; bottom: 0; width: 100vw; height: 88vh; border-radius: 18px 18px 0 0; }
  .asst-fab { right: 1rem; bottom: 1rem; }
}
