/* Chat assistant (demo) — bubble bottom right, panel above it, full-screen sheet on phones.
   Uses the site tokens from site.css (--v-blue, --v-font, …). Stacking, from site.css:
   cookie bar 1040 · back-to-top 1045 · presenter fab 1046 · modal 1050 · presenter panel 1056 · alert 1060.
   The chat bubble sits at 1047 (above the back-to-top it is stacked on top of) and the panel at 1048, so a
   coverage modal or an alert still comes out in front of it. --v-chat-bottom is kept clear of the cookie bar
   by chat.js. */
:root {
  --v-chat-bottom: 20px;
  --v-chat-fab: 56px;
}

/* ------------------------------------------------------------------ bubble */
.v-chat-fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--v-chat-bottom) + var(--v-chat-fab) + 12px);
  z-index: 1047;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--v-chat-fab);
  height: var(--v-chat-fab);
  padding: 0;
  color: #FFFFFF;
  background: var(--v-blue, #0033A2);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
  cursor: pointer;
  transition: background-color .2s, box-shadow .2s, transform .2s, bottom .3s;
}
.v-chat-fab:hover {
  background: var(--v-blue2, #0061CF);
  transform: translateY(-2px);
  box-shadow: 0 0 0 5px rgba(0, 51, 162, .22), 0 8px 18px rgba(0, 0, 0, .28);
}
.v-chat-fab:focus-visible { outline: 2px solid var(--v-blue2, #0061CF); outline-offset: 3px; }
.v-chat-fab[aria-expanded="true"] { background: var(--v-blue2, #0061CF); }
.v-chat-fab__icon { width: 28px; height: 28px; }
.v-chat-fab__dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 11px;
  height: 11px;
  background: var(--v-yellow, #FCAF17);
  border: 2px solid #FFFFFF;
  border-radius: 50%;
}
.v-chat-fab[aria-expanded="true"] .v-chat-fab__dot, .v-chat-fab.is-seen .v-chat-fab__dot { display: none; }

/* ------------------------------------------------------------------ panel */
.v-chat {
  position: fixed;
  right: 20px;
  /* one bubble height above the bubble itself, which is one back-to-top height above the page corner */
  bottom: calc(var(--v-chat-bottom) + var(--v-chat-fab) * 2 + 24px);
  z-index: 1048;
  display: flex;
  flex-direction: column;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(600px, calc(100vh - 210px));
  font-family: var(--v-font, "Kanit", sans-serif);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 300;
  color: var(--v-text, #3F3F3F);
  background: #FFFFFF;
  border: 1px solid #E1E7F0;
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(10, 25, 60, .22);
  overflow: hidden;
  transform: translateY(12px) scale(.98);
  opacity: 0;
  transition: transform .18s ease-out, opacity .18s ease-out;
}
.v-chat.is-open { transform: none; opacity: 1; }
.v-chat[hidden] { display: none; }

.v-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 12px 14px;
  color: #FFFFFF;
  background: linear-gradient(135deg, var(--v-blue, #0033A2), var(--v-blue2, #0061CF));
}
.v-chat__id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.v-chat__avatar {
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 36px; height: 36px; background: rgba(255, 255, 255, .18); border-radius: 50%;
}
.v-chat__avatar svg { width: 21px; height: 21px; }
.v-chat__title { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 500; color: #FFFFFF; }
.v-chat__tag {
  display: inline-block; margin-left: 4px; padding: 0 7px; font-size: 11px; line-height: 18px; font-weight: 400;
  color: #3F2A00; background: var(--v-yellow, #FCAF17); border-radius: 9px; vertical-align: 2px;
}
.v-chat__sub { margin: 1px 0 0; font-size: 12px; line-height: 1.4; color: rgba(255, 255, 255, .86); }
.v-chat__close {
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 34px; height: 34px; padding: 0; color: #FFFFFF; background: rgba(255, 255, 255, .12);
  border: 0; border-radius: 50%; cursor: pointer; transition: background-color .15s, transform .15s;
}
.v-chat__close svg { width: 12px; height: 12px; }
.v-chat__close:hover { background: rgba(255, 255, 255, .3); transform: rotate(90deg); }
.v-chat__close:focus-visible { outline: 2px solid #FFFFFF; outline-offset: 2px; }

/* ------------------------------------------------------------------ messages */
.v-chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 6px;
  background: #F6F8FC;
}
.v-chat__log:focus-visible { outline: 2px solid var(--v-blue2, #0061CF); outline-offset: -2px; }
.v-msg { display: flex; margin-bottom: 10px; }
.v-msg__bubble {
  max-width: 85%;
  padding: 9px 13px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-line;
  word-break: break-word;
  border-radius: 14px;
}
.v-msg--bot .v-msg__bubble { color: var(--v-text, #3F3F3F); background: #FFFFFF; border: 1px solid #E4EAF3; border-bottom-left-radius: 4px; }
.v-msg--user { justify-content: flex-end; }
.v-msg--user .v-msg__bubble { color: #FFFFFF; background: var(--v-blue, #0033A2); border-bottom-right-radius: 4px; }
.v-msg--error .v-msg__bubble { color: #8C1B32; background: #FFF0F3; border: 1px solid #F6C4CF; }
.v-msg--note .v-msg__bubble { color: #1D5E2E; background: #E9F6ED; border: 1px solid #BFE3CA; }

.v-msg__sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.v-msg__source {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 2px 9px; font-family: inherit; font-size: 12.5px; line-height: 20px; font-weight: 300;
  color: var(--v-blue, #0033A2); background: #EEF4FF; border: 1px solid #CFE0FA; border-radius: 11px;
  cursor: pointer; text-align: left; text-decoration: none; transition: background-color .15s, border-color .15s, color .15s;
}
.v-msg__source:hover { color: #FFFFFF; background: var(--v-blue2, #0061CF); border-color: var(--v-blue2, #0061CF); }
.v-msg__source:focus-visible { outline: 2px solid var(--v-blue2, #0061CF); outline-offset: 1px; }
.v-msg__source svg { width: 12px; height: 12px; flex: 0 0 auto; }

.v-msg__meta { margin-top: 6px; font-size: 11.5px; line-height: 1.4; color: #8A93A1; }

/* typing indicator */
.v-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.v-typing span { width: 7px; height: 7px; background: #9FB0C8; border-radius: 50%; animation: v-chat-bounce 1.1s infinite ease-in-out; }
.v-typing span:nth-child(2) { animation-delay: .15s; }
.v-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes v-chat-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .55; } 30% { transform: translateY(-4px); opacity: 1; } }

/* highlight of the page section a source link points at */
.v-chat-target { animation: v-chat-flash 2.2s ease-out 1; }
@keyframes v-chat-flash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(252, 175, 23, 0); }
  15%, 60% { box-shadow: 0 0 0 4px rgba(252, 175, 23, .55); }
}

/* ------------------------------------------------------------------ suggestions */
.v-chat__suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 10px;
  background: #F6F8FC;
  border-top: 1px solid #E8EDF5;
}
.v-chat__suggest[hidden] { display: none; }
.v-chat__chip {
  max-width: 100%;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 300;
  text-align: left;
  color: var(--v-blue, #0033A2);
  background: #FFFFFF;
  border: 1px solid #CFE0FA;
  border-radius: 14px;
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s, box-shadow .15s;
}
.v-chat__chip:hover { color: #FFFFFF; background: var(--v-blue2, #0061CF); border-color: var(--v-blue2, #0061CF); box-shadow: 0 2px 8px rgba(0, 97, 207, .25); }
.v-chat__chip:focus-visible { outline: 2px solid var(--v-blue2, #0061CF); outline-offset: 2px; }

/* ------------------------------------------------------------------ composer */
.v-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: #FFFFFF;
  border-top: 1px solid #E8EDF5;
}
.v-chat__sronly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.v-chat__input {
  flex: 1 1 auto;
  min-height: 42px;
  max-height: 120px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  font-weight: 300;
  color: var(--v-text, #3F3F3F);
  background: #F7F9FC;
  border: 1px solid #DCE3EE;
  border-radius: 12px;
  resize: none;
}
.v-chat__input::placeholder { color: #9AA3B2; }
.v-chat__input:hover { border-color: #B9C8DF; }
.v-chat__input:focus { outline: none; background: #FFFFFF; border-color: var(--v-blue2, #0061CF); box-shadow: 0 0 0 3px rgba(0, 97, 207, .12); }
.v-chat__send {
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 42px; height: 42px; padding: 0; color: #FFFFFF; background: var(--v-blue, #0033A2);
  border: 0; border-radius: 50%; cursor: pointer; transition: background-color .15s, transform .15s, box-shadow .15s;
}
.v-chat__send svg { width: 19px; height: 19px; }
.v-chat__send:hover { background: var(--v-blue2, #0061CF); transform: scale(1.06); box-shadow: 0 3px 10px rgba(0, 51, 162, .3); }
.v-chat__send:focus-visible { outline: 2px solid var(--v-blue2, #0061CF); outline-offset: 2px; }
.v-chat__send[aria-busy="true"] { cursor: wait; opacity: .75; transform: none; }

.v-chat__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px 10px;
  background: #FFFFFF;
}
.v-chat__agent {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 14px; font-family: inherit; font-size: 13.5px; line-height: 1.5; font-weight: 400;
  color: var(--v-blue, #0033A2); background: #FFFFFF; border: 1px solid var(--v-blue, #0033A2);
  border-radius: 16px; cursor: pointer; transition: background-color .15s, color .15s, box-shadow .15s;
}
.v-chat__agent svg { width: 14px; height: 14px; }
.v-chat__agent:hover { color: #FFFFFF; background: var(--v-blue, #0033A2); box-shadow: 0 2px 8px rgba(0, 51, 162, .3); }
.v-chat__agent:focus-visible { outline: 2px solid var(--v-blue2, #0061CF); outline-offset: 2px; }
.v-chat__note { margin: 0; font-size: 11px; line-height: 1.3; text-align: right; color: #97A0AE; }

/* ------------------------------------------------------------------ handoff card */
.v-chat-form {
  margin: 2px 0 10px;
  padding: 12px 13px;
  background: #FFFFFF;
  border: 1px solid #CFE0FA;
  border-left: 4px solid var(--v-blue2, #0061CF);
  border-radius: 12px;
}
.v-chat-form__title { margin: 0 0 2px; font-size: 14.5px; font-weight: 500; color: var(--v-blue, #0033A2); }
.v-chat-form__hint { margin: 0 0 10px; font-size: 12.5px; line-height: 1.5; color: #6B7686; }
.v-chat-form .form-group { margin-bottom: 10px; }
.v-chat-form .form-label { margin-bottom: 3px; font-size: 13px; }
.v-chat-form .form-control { height: auto; padding: 7px 10px; font-size: 14px; }
.v-chat-form .field-error { font-size: 12.5px; }
.v-chat-form__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.v-chat-form__submit {
  flex: 1 1 150px; padding: 8px 14px; font-family: inherit; font-size: 14px; font-weight: 400;
  color: #FFFFFF; background: var(--v-blue, #0033A2); border: 1px solid var(--v-blue, #0033A2);
  border-radius: 8px; cursor: pointer; transition: background-color .15s, box-shadow .15s;
}
.v-chat-form__submit:hover { background: var(--v-blue2, #0061CF); box-shadow: 0 3px 10px rgba(0, 51, 162, .28); }
.v-chat-form__submit[aria-busy="true"] { cursor: wait; opacity: .8; }
.v-chat-form__cancel {
  padding: 8px 14px; font-family: inherit; font-size: 14px; font-weight: 300; color: #5A6577;
  background: #FFFFFF; border: 1px solid #CBD3DF; border-radius: 8px; cursor: pointer; transition: background-color .15s, color .15s;
}
.v-chat-form__cancel:hover { color: #FFFFFF; background: #5A6577; border-color: #5A6577; }
.v-chat-form__submit:focus-visible, .v-chat-form__cancel:focus-visible { outline: 2px solid var(--v-blue2, #0061CF); outline-offset: 2px; }

/* ------------------------------------------------------------------ phones: full-screen sheet */
@media (max-width: 575.98px) {
  .v-chat {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .v-chat__head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .v-chat__foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .v-chat-fab { right: 14px; }
  .v-msg__bubble { max-width: 90%; }
  .v-chat__note { display: none; }
}
@media (max-width: 575.98px) {
  body.v-chat-open { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .v-chat, .v-chat-fab, .v-typing span, .v-chat-target { transition: none; animation: none; }
}
