/*
 * chat.css — Muyi sales-bot chat widget (floating panel, corporate navy/amber).
 * Loaded after styles.css on index.html. Bilingual text comes from i18n keys.
 */

/* Floating launcher button */
.chat-launcher {
  position: fixed; right: 22px; bottom: 22px; z-index: 100;
  display: flex; align-items: center; gap: 0.55rem;
  background: linear-gradient(135deg, var(--amber), var(--amber-dark));
  color: var(--navy-900); border: none; cursor: pointer;
  font-weight: 800; font-size: 0.95rem;
  padding: 0.85rem 1.3rem; border-radius: 999px;
  box-shadow: 0 10px 28px rgba(242, 165, 65, 0.45);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(242, 165, 65, 0.55); }
.chat-launcher svg { width: 20px; height: 20px; }

/* Panel */
.chat-panel {
  position: fixed; right: 22px; bottom: 88px; z-index: 101;
  width: 392px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 120px);
  background: var(--white); border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(6, 13, 25, 0.35);
  display: none; flex-direction: column;
  border: 1px solid #e4e8ef;
}
.chat-panel.open { display: flex; }

/* Header */
.chat-header {
  background: linear-gradient(135deg, var(--navy-900), var(--navy-700));
  color: var(--white); padding: 0.9rem 1.1rem;
  display: flex; align-items: center; gap: 0.7rem;
}
.chat-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--amber); color: var(--navy-900);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
}
.chat-title { font-weight: 700; font-size: 0.98rem; line-height: 1.2; }
.chat-status { font-size: 0.74rem; color: #9fb0c8; display: flex; align-items: center; gap: 0.35rem; }
.chat-status::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: #43d675; display: inline-block;
}
.chat-close {
  margin-left: auto; background: none; border: none; color: #9fb0c8;
  font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 0.2rem;
}
.chat-close:hover { color: var(--white); }

/* Messages area */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: 0.7rem;
  background: var(--paper);
}
.chat-msg {
  max-width: 85%; padding: 0.65rem 0.95rem; border-radius: 14px;
  font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
}
.chat-msg.bot {
  background: var(--white); color: var(--ink);
  border: 1px solid #e4e8ef; border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.chat-msg.user {
  background: var(--navy-800); color: var(--white);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.chat-msg table { font-size: 0.8rem; }              /* model may emit small tables */
/* Persona header (team theater): who is speaking — receptionist/specialist */
.msg-author {
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.04em;
  color: var(--amber-dark); text-transform: uppercase; margin-bottom: 0.25rem;
}
.chat-typing {
  color: var(--muted); font-size: 0.85rem; align-self: flex-start;
  display: flex; align-items: center; gap: 0.4rem;
}
/* Animated "working" dots next to the staged status text — the visitor always
   sees movement while the model (re)loads or generates */
.chat-typing::after {
  content: "";
  width: 22px; height: 8px;
  background-image: radial-gradient(circle, var(--amber-dark) 2.5px, transparent 3px);
  background-size: 8px 8px;
  background-repeat: repeat-x;
  animation: typing-dots 0.9s linear infinite;
}
@keyframes typing-dots {
  from { background-position-x: 0; }
  to { background-position-x: 8px; }
}

/* Header tool buttons (maximize / detach) — same family as the close button */
.chat-tool {
  background: none; border: none; color: #9fb0c8; cursor: pointer;
  font-size: 1.05rem; line-height: 1; padding: 0.3rem;
  min-width: 32px; min-height: 32px; border-radius: 6px;
}
.chat-tool:hover { color: var(--white); background: rgba(255, 255, 255, 0.08); }

/* Maximized: the panel becomes a full reading view (no permissions needed) */
.chat-panel.maximized {
  right: 0; bottom: 0; left: 0; top: 0;
  width: 100%; max-width: none; height: 100%; max-height: none;
  border-radius: 0; border: none; z-index: 300;
}
.chat-panel.maximized .chat-messages { font-size: 1rem; }
.chat-panel.maximized .chat-msg { max-width: 720px; }

/* Standalone detached window (chat.html): the panel IS the page */
body.chat-standalone { background: var(--paper); }
body.chat-standalone .chat-panel {
  position: fixed; inset: 0; width: 100%; max-width: none; height: 100%;
  max-height: none; border-radius: 0; border: none; box-shadow: none;
  display: flex;
}
body.chat-standalone .chat-launcher { display: none; }

/* ---------- Soft contact-capture popup (card, NOT a chat message) ---------- */
.contact-popup {
  margin: 0 1rem 0.6rem; padding: 0.85rem 1rem;
  background: #fdf6ea; border: 1px solid #f0dfb8; border-radius: 12px;
  font-size: 0.85rem; color: var(--ink);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.contact-popup.visible { opacity: 1; transform: none; }
.contact-popup strong { display: block; margin-bottom: 0.15rem; color: var(--navy-800); }
.contact-popup p { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.55rem; }
.contact-popup-input {
  width: 100%; border: 1px solid #e2d3ac; border-radius: 8px;
  padding: 0.5rem 0.7rem; font-size: 0.85rem; font-family: inherit;
  margin-bottom: 0.55rem; outline: none; background: var(--white);
}
.contact-popup-input:focus { border-color: var(--amber); }
.contact-popup-row { display: flex; gap: 0.5rem; }
.contact-popup-save {
  flex: 1; background: var(--navy-800); color: var(--amber); border: none;
  border-radius: 8px; padding: 0.5rem; font-weight: 700; cursor: pointer; font-size: 0.84rem;
}
.contact-popup-dismiss {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.84rem; padding: 0.5rem 0.7rem;
}
.contact-popup-dismiss:hover { color: var(--ink); }

/* Machine context chip (shown when opened from a machine card) */
.chat-context {
  padding: 0.4rem 1rem; font-size: 0.78rem; color: var(--amber-dark);
  background: #fdf6ea; border-bottom: 1px solid #f3e3c2;
  display: none;
}
.chat-context.visible { display: block; }

/* Input row */
.chat-input-row {
  display: flex; gap: 0.5rem; padding: 0.75rem;
  border-top: 1px solid #e4e8ef; background: var(--white);
}
.chat-input {
  flex: 1; border: 1px solid #dbe1ea; border-radius: 10px;
  padding: 0.6rem 0.8rem; font-size: 0.92rem; font-family: inherit;
  resize: none; outline: none;
}
.chat-input:focus { border-color: var(--amber); }
.chat-send {
  background: var(--navy-800); color: var(--amber); border: none;
  border-radius: 10px; padding: 0 1.1rem; font-weight: 700; cursor: pointer;
  transition: background 0.15s ease;
}
.chat-send:hover { background: var(--navy-700); }
.chat-send:disabled { opacity: 0.45; cursor: default; }

@media (max-width: 560px) {
  /* Phone: panel becomes near-fullscreen sheet.
     dvh (dynamic viewport height) shrinks when the virtual keyboard opens,
     so the chat header never slides off-screen (keyboard-cutoff bug fix). */
  .chat-panel {
    right: 8px; bottom: 8px; width: calc(100vw - 16px);
    height: calc(100vh - 100px);                 /* fallback */
    height: calc(100dvh - 90px);                 /* keyboard-aware */
  }
  .chat-launcher { right: 14px; bottom: 14px; }
}
