/* Live chat box on the public website (chat.js builds it). Loaded on every page by site_head() in inc/site.php.
   Everything is under .rtc so the site's own form and button styles (style.css) don't leak in. */

.rtc {
  --rtc-navy: var(--navy, #0b1a3a);
  --rtc-navy-2: var(--navy-2, #12285a);
  --rtc-blue: var(--blue, #2f5fb8);
  --rtc-line: var(--silver, #d9dee7);
  --rtc-soft: var(--silver-2, #f3f5f9);
  --rtc-text: var(--text, #1c2333);
  --rtc-muted: var(--muted, #5d6679);
  --rtc-head: var(--font-head, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif);
  --rtc-gap: 20px;
  --rtc-lift: 0px;   /* how far up the button sits (the phone bar is under it on phones) */
  position: fixed; right: var(--rtc-gap); bottom: calc(var(--rtc-gap) + var(--rtc-lift)); z-index: 70;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-size: 15px; line-height: 1.45;
  color: var(--rtc-text);
  pointer-events: none;
}
.rtc > * { pointer-events: auto; }
.rtc *, .rtc *::before, .rtc *::after { box-sizing: border-box; }
.rtc svg { display: block; flex: none; }

/* ---------- The round button in the corner */
.rtc-launch {
  position: relative; display: inline-flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 22px 0 18px; border: 0; border-radius: 999px; cursor: pointer;
  background: linear-gradient(180deg, #3a6fd0, #23479a); color: #fff;
  font: 600 1rem/1 var(--rtc-head);
  box-shadow: 0 6px 22px rgba(11, 26, 58, .32), 0 1px 3px rgba(11, 26, 58, .2);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.rtc-launch:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 8px 26px rgba(11, 26, 58, .36), 0 1px 3px rgba(11, 26, 58, .2); }
.rtc-launch:focus-visible { outline: 3px solid rgba(47, 95, 184, .55); outline-offset: 3px; }
.rtc.is-open .rtc-launch { padding: 0; width: 56px; justify-content: center; }
.rtc.is-open .rtc-launch-l { display: none; }
.rtc-badge {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 999px; border: 2px solid #fff;
  background: #d93025; color: #fff; font: 700 .75rem/1 system-ui, sans-serif;
}
@keyframes rtc-nudge { 0%, 100% { transform: none; } 20% { transform: translateY(-5px); } 40% { transform: none; } 60% { transform: translateY(-3px); } }
.rtc-launch.rtc-nudge { animation: rtc-nudge .9s ease 1; }

/* A reply arrived while the box was shut */
.rtc-peek {
  max-width: min(300px, calc(100vw - 2 * var(--rtc-gap))); padding: 12px 14px; cursor: pointer; text-align: left;
  background: #fff; color: var(--rtc-text); border: 1px solid var(--rtc-line); border-radius: 14px 14px 4px 14px;
  font: inherit; font-size: .95rem; box-shadow: 0 8px 26px rgba(11, 26, 58, .18);
  animation: rtc-in .25s ease;
}
.rtc-peek strong { color: var(--rtc-navy-2); }
.rtc-peek:hover { border-color: var(--rtc-blue); }

/* ---------- The chat window */
@keyframes rtc-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.rtc-panel {
  width: 370px; height: min(660px, calc(100vh - 56px - 3 * var(--rtc-gap) - var(--rtc-lift)));
  height: min(660px, calc(100dvh - 56px - 3 * var(--rtc-gap) - var(--rtc-lift)));
  display: flex; flex-direction: column; overflow: hidden;
  background: #fff; border: 1px solid var(--rtc-line); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(11, 26, 58, .28), 0 2px 6px rgba(11, 26, 58, .12);
  transform-origin: bottom right; animation: rtc-in .2s ease;
}

.rtc-head {
  flex: none; display: flex; align-items: center; gap: 12px; padding: 14px 12px 14px 16px;
  background: radial-gradient(400px 160px at 10% -40%, #1b3a80 0%, var(--rtc-navy) 70%); color: #fff;
}
.rtc-av {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(180deg, #3a6fd0, #23479a); border: 2px solid rgba(255, 255, 255, .7);
  font: 700 1rem/1 var(--rtc-head);
}
.rtc-ht { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rtc-ht strong { font: 600 1.02rem/1.25 var(--rtc-head); }
.rtc-status { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: #c3cde4; }
.rtc-status i { width: 8px; height: 8px; border-radius: 50%; background: #8a94a8; }
.rtc-status i.on { background: #34c26b; box-shadow: 0 0 0 3px rgba(52, 194, 107, .25); }
.rtc-x {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 10px; background: transparent; color: #fff; cursor: pointer;
}
.rtc-x:hover { background: rgba(255, 255, 255, .12); }
.rtc-x:focus-visible { outline: 2px solid #9fbaf0; }

/* messages */
.rtc-body {
  flex: 1 1 auto; min-height: 60px; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 14px 8px; background: var(--rtc-soft);
  display: flex; flex-direction: column; gap: 3px;
}
.rtc-msg { display: flex; flex-direction: column; max-width: 84%; margin-top: 2px; }
.rtc-msg.them { align-self: flex-start; align-items: flex-start; }
.rtc-msg.me { align-self: flex-end; align-items: flex-end; }
.rtc-who { margin: 6px 0 2px 4px; font-size: .75rem; font-weight: 700; color: var(--rtc-muted); }
.rtc-b {
  padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.rtc-msg.them .rtc-b { background: #fff; border: 1px solid var(--rtc-line); border-bottom-left-radius: 5px; color: var(--rtc-text); }
.rtc-msg.me .rtc-b { background: var(--rtc-blue); color: #fff; border-bottom-right-radius: 5px; }
.rtc-t { margin: 2px 6px 6px; font-size: .72rem; color: var(--rtc-muted); }
.rtc-msg.pending .rtc-b { opacity: .65; }
.rtc-msg.failed { cursor: pointer; }
.rtc-msg.failed .rtc-b { background: #fff; color: #a3261c; border: 1px solid #e5a29b; }
.rtc-msg.failed .rtc-t { color: #a3261c; font-weight: 600; }
.rtc-sys {
  align-self: center; max-width: 92%; margin: 8px 0; padding: 5px 12px; border-radius: 999px;
  background: #e6eaf2; color: var(--rtc-muted); font-size: .8rem; text-align: center;
}

/* ---------- First screen: name, contact details and the question */
.rtc form.rtc-start {
  display: flex; flex-direction: column; gap: 10px; margin: 0;
  flex: none; max-height: 66%; overflow-y: auto; padding: 14px 16px 12px;
  border-top: 1px solid var(--rtc-line); background: #fff;
}
.rtc form.rtc-start > * { flex-shrink: 0; }
.rtc-panel:has(.rtc-start:not([hidden])) .rtc-start { flex: 1 1 auto; max-height: none; border-top: 0; }
/* the greeting above the form: the same grey band as the conversation, running to the edges */
.rtc-intro { margin: -14px -16px 4px; padding: 16px 14px 14px; background: var(--rtc-soft); border-bottom: 1px solid var(--rtc-line); display: flex; flex-direction: column; }
/* just after a chat ends */
.rtc-ended { margin: auto 0; padding: 24px 12px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
.rtc-ended-t { margin: 0; color: var(--rtc-text); font-size: 1rem; font-weight: 600; }
.rtc-again { max-width: 240px; }
.rtc .rtc-field { display: flex; flex-direction: column; gap: 4px; margin: 0; font-weight: 600; font-size: .85rem; color: var(--rtc-navy-2); }
.rtc .rtc-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rtc input, .rtc textarea {
  width: 100%; margin: 0; padding: 9px 11px; font: inherit; font-size: 16px; font-weight: 400; color: var(--rtc-text);
  background: #fff; border: 1px solid #b9c1d3; border-radius: 9px; box-shadow: none;
}
.rtc textarea { resize: none; line-height: 1.4; }
.rtc input:focus, .rtc textarea:focus { outline: 3px solid rgba(47, 95, 184, .3); outline-offset: 0; border-color: var(--rtc-blue); }
.rtc input.rtc-bad, .rtc textarea.rtc-bad { border-color: #c0392b; }
.rtc-hint, .rtc-small { margin: -2px 0 0; font-size: .8rem; color: var(--rtc-muted); }
.rtc-small a { color: var(--rtc-blue); }
.rtc-err { margin: 0; padding: 8px 11px; border-radius: 8px; background: #fdecea; border: 1px solid #f2b8b2; color: #a3261c; font-size: .88rem; font-weight: 600; }
.rtc-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.rtc-go {
  width: 100%; height: 46px; margin-top: 2px; border: 0; border-radius: 10px; cursor: pointer;
  background: linear-gradient(180deg, #3a6fd0, #23479a); color: #fff; font: 600 1rem/1 var(--rtc-head);
}
.rtc-go:hover { filter: brightness(1.08); }
.rtc-go:disabled { opacity: .65; cursor: wait; }
.rtc-go:focus-visible { outline: 3px solid rgba(47, 95, 184, .55); outline-offset: 2px; }

/* ---------- Typing a message */
.rtc form.rtc-compose {
  flex: none; display: flex; align-items: flex-end; gap: 8px; margin: 0;
  padding: 10px 10px 10px 12px; border-top: 1px solid var(--rtc-line); background: #fff;
}
.rtc-compose textarea { flex: 1; min-height: 42px; max-height: 120px; padding: 10px 12px; border-radius: 21px; }
.rtc-send {
  flex: none; width: 42px; height: 42px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: 50%; cursor: pointer; background: var(--rtc-blue); color: #fff;
}
.rtc-send:hover { filter: brightness(1.1); }
.rtc-send:focus-visible { outline: 3px solid rgba(47, 95, 184, .45); outline-offset: 2px; }
.rtc-foot { flex: none; padding: 0 12px 8px; background: #fff; text-align: center; }
.rtc-end { padding: 4px 8px; border: 0; background: none; color: var(--rtc-muted); font: inherit; font-size: .8rem; text-decoration: underline; cursor: pointer; }
.rtc-end[data-sure] { color: #a3261c; font-weight: 600; }

/* ---------- Phones: above the Call / WhatsApp / Book bar, and the chat fills the screen when open */
@media (max-width: 720px) {
  .rtc { --rtc-gap: 12px; --rtc-lift: calc(64px + env(safe-area-inset-bottom, 0px)); transition: bottom .2s ease; }
  body.typing .rtc:not(.is-open) { --rtc-lift: 0px; }
  .rtc-launch { height: 52px; padding: 0 18px 0 15px; font-size: .95rem; }
  html.rtc-lock, html.rtc-lock body { overflow: hidden; }
  .rtc.is-open { inset: 0; gap: 0; }
  .rtc.is-open .rtc-launch, .rtc.is-open .rtc-peek { display: none; }
  .rtc-panel { width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none; animation-duration: .15s; }
  .rtc-head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .rtc form.rtc-compose, .rtc-foot { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .rtc form.rtc-compose + .rtc-foot { padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .rtc form.rtc-compose:has(+ .rtc-foot:not([hidden])) { padding-bottom: 6px; }
  .rtc-msg { max-width: 88%; }
}
@media (max-width: 360px) { .rtc .rtc-two { grid-template-columns: 1fr; } }
/* a phone held sideways, or a very short window: just the icon */
@media (max-height: 460px) { .rtc:not(.is-open) .rtc-launch-l { display: none; } .rtc:not(.is-open) .rtc-launch { width: 52px; padding: 0; justify-content: center; } }

@media (prefers-reduced-motion: reduce) {
  .rtc-panel, .rtc-peek, .rtc-launch.rtc-nudge { animation: none; }
  .rtc-launch, .rtc { transition: none; }
}
@media print { .rtc { display: none; } }
