/* ============================================================
   LIVE CHAT WIDGET  —  public/assets/chat.css
   Loaded by app/Views/partials/chat_widget.php, and ONLY when
   setting('chat_enabled') is on, so a site with chat off never
   downloads it.

   THIS IS A NEW FILE ON PURPOSE. palace.css, pages.css and
   myvan.js are byte-identical copies of the original static
   site and must stay that way, so nothing here belongs in them.

   COLOUR: every value below is either one of the design's own
   custom properties (--pl-brand, --pl-ink, --pl-line, …, all
   declared in palace.css :root) or plain white/black alpha.
   No new brand colour is invented, so re-theming the site
   re-themes the widget. The one exception is the unread dot,
   which is a fixed alert red because "you have a reply" must
   not be brand-coloured — it would disappear into the launcher.

   Z-INDEX: 1040, deliberately the same layer as palace.css's
   .scroll-top and BELOW Bootstrap's modal (1055) and offcanvas
   (1045). A chat bubble floating over an open modal is a bug.
   The launcher also sits ABOVE .scroll-top's slot (bottom:24px)
   rather than on top of it, so the two never overlap.
   ============================================================ */

.mv-chat {
  font-family: var(--bs-body-font-family, system-ui, sans-serif);
}

/* --- Launcher ------------------------------------------------ */

.mv-chat__launch {
  position: fixed;
  right: 24px;
  bottom: 80px;          /* clears .scroll-top, which owns bottom:24px */
  z-index: 1040;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--pl-brand);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(23, 27, 42, .22);
  transition: transform .2s ease, background .2s ease;
}

.mv-chat__launch:hover {
  background: var(--pl-brand-dark);
  transform: translateY(-2px);
}

/* Keyboard focus must be obvious — the launcher is the only way in. */
.mv-chat__launch:focus-visible,
.mv-chat__x:focus-visible,
.mv-chat__send:focus-visible,
.mv-chat__submit:focus-visible {
  outline: 3px solid var(--pl-brand-soft);
  outline-offset: 2px;
}

.mv-chat__badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #dc3545;   /* see the header note: alert red, not brand */
  border: 2px solid #fff;
}

/* --- Panel --------------------------------------------------- */

.mv-chat__panel {
  position: fixed;
  right: 24px;
  bottom: 148px;         /* above the launcher, never over it */
  z-index: 1040;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 480px;
  max-height: calc(100vh - 180px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--pl-line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(23, 27, 42, .22);
}

/* [hidden] must win over the flex display above. */
.mv-chat__panel[hidden],
.mv-chat [hidden] {
  display: none !important;
}

.mv-chat__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .85rem 1rem;
  background: var(--pl-brand);
  color: #fff;
}

.mv-chat__ident {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}

.mv-chat__title {
  font-weight: 700;
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .01em;
}

.mv-chat__sub {
  font-size: .75rem;
  opacity: .85;
}

.mv-chat__x {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  padding: .25rem;
  cursor: pointer;
  opacity: .85;
}

.mv-chat__x:hover { opacity: 1; }

/* --- Pre-chat form ------------------------------------------- */

.mv-chat__intro {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  background: #fff;
}

.mv-chat__greeting {
  font-size: .875rem;
  color: var(--pl-body);
  line-height: 1.6;
  margin: 0 0 .85rem;
}

.mv-chat__label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  color: var(--pl-ink);
  margin: .6rem 0 .25rem;
}

.mv-chat__opt {
  font-weight: 400;
  color: var(--pl-body);
}

.mv-chat__input {
  width: 100%;
  padding: .5rem .7rem;
  font-size: .875rem;
  color: var(--pl-ink);
  background: #fff;
  border: 1px solid var(--pl-line);
  border-radius: 8px;
}

.mv-chat__input:focus {
  outline: none;
  border-color: var(--pl-brand);
  box-shadow: 0 0 0 .2rem var(--pl-brand-soft);
}

.mv-chat__area {
  resize: vertical;
  min-height: 72px;
  font-family: inherit;
}

.mv-chat__err {
  margin: .6rem 0 0;
  font-size: .8rem;
  color: #dc3545;
}

.mv-chat__submit {
  width: 100%;
  margin-top: .9rem;
  padding: .55rem 1rem;
  border: 0;
  border-radius: 8px;
  background: var(--pl-brand);
  color: #fff;
  font-weight: 600;
  font-size: .875rem;
  cursor: pointer;
}

.mv-chat__submit:hover { background: var(--pl-brand-dark); }
.mv-chat__submit[disabled] { opacity: .6; cursor: default; }

/* --- Transcript ---------------------------------------------- */

.mv-chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  background: var(--pl-panel);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.mv-chat__empty {
  margin: auto;
  font-size: .825rem;
  color: var(--pl-body);
  text-align: center;
}

.mv-chat__msg {
  max-width: 84%;
  padding: .5rem .7rem;
  border-radius: 12px;
  font-size: .875rem;
  line-height: 1.5;
  /* pre-wrap is what preserves the newlines chat.js sets via textContent —
     the client path adds no <br>, by design (see the widget header). */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mv-chat__msg--me {
  align-self: flex-end;
  background: var(--pl-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.mv-chat__msg--them {
  align-self: flex-start;
  background: #fff;
  color: var(--pl-ink);
  border: 1px solid var(--pl-line);
  border-bottom-left-radius: 4px;
}

.mv-chat__time {
  display: block;
  margin-top: .2rem;
  font-size: .675rem;
  opacity: .7;
}

/* --- Compose ------------------------------------------------- */

.mv-chat__compose {
  flex: 0 0 auto;
  display: flex;
  gap: .5rem;
  padding: .6rem;
  background: #fff;
  border-top: 1px solid var(--pl-line);
}

.mv-chat__textarea {
  flex: 1 1 auto;
  max-height: 96px;
  resize: none;
  padding: .5rem .7rem;
  font-family: inherit;
  font-size: .875rem;
  color: var(--pl-ink);
  background: #fff;
  border: 1px solid var(--pl-line);
  border-radius: 10px;
}

.mv-chat__textarea:focus {
  outline: none;
  border-color: var(--pl-brand);
}

.mv-chat__send {
  flex: 0 0 auto;
  width: 42px;
  border: 0;
  border-radius: 10px;
  background: var(--pl-brand);
  color: #fff;
  font-size: .95rem;
  cursor: pointer;
}

.mv-chat__send:hover { background: var(--pl-brand-dark); }
.mv-chat__send[disabled] { opacity: .6; cursor: default; }

.mv-chat__note {
  flex: 0 0 auto;
  margin: 0;
  padding: .5rem .8rem;
  font-size: .75rem;
  color: var(--pl-body);
  background: var(--pl-brand-soft);
  border-top: 1px solid var(--pl-line);
}

/* --- Mobile: a full-width sheet ------------------------------ */

@media (max-width: 575.98px) {
  .mv-chat__launch {
    right: 16px;
    bottom: 76px;
    width: 52px;
    height: 52px;
  }

  .mv-chat__panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    height: 88vh;
    max-height: none;
    border-radius: 14px 14px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
}

/* A floating bubble has no meaning on paper. */
@media print {
  #myvanChat { display: none !important; }
}

/* Respect a reduced-motion preference: the hover lift is decoration. */
@media (prefers-reduced-motion: reduce) {
  .mv-chat__launch { transition: none; }
  .mv-chat__launch:hover { transform: none; }
}
