/* Live chat widget (see views/partials/chat-widget.php + assets/js/chat-widget.js).
   Plain CSS on purpose: keeps the widget out of the Tailwind purge-rebuild
   loop. Brand navy #224685, slate neutrals, square corners per house style.
   On phones everything sits above the fixed bottom CTA bar (z-40, ~48px):
   the widget uses z-index 60 and a raised bottom offset below 1024px. */

.swd-chat-launch {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: inline-flex; align-items: center; gap: 9px; padding: 12px 18px;
  border: 0; background: #224685; color: #fff;
  font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .25);
}
.swd-chat-launch:hover { background: #1b386a; }
.swd-chat-launch[hidden] { display: none; }
.swd-chat-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  background: #d97706; color: #fff; font-size: .78rem; font-weight: 700;
}
.swd-chat-badge[hidden] { display: none; }
.swd-chat-panel {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  width: min(370px, calc(100vw - 24px)); max-height: min(620px, calc(100vh - 40px));
  display: flex; flex-direction: column; background: #fff;
  border: 1px solid #e2e8f0; overflow: hidden;
  box-shadow: 0 18px 48px rgba(15, 23, 42, .26);
}
.swd-chat-panel[hidden] { display: none; }
.swd-chat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 13px 16px 11px; background: #224685; color: #fff; }
.swd-chat-head b { font-size: 1.02rem; }
.swd-chat-status { display: flex; align-items: center; gap: 7px; font-size: .8rem; opacity: .92; margin-top: 3px; }
.swd-chat-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex: 0 0 auto; }
.swd-chat-dot.is-on { background: #6ee7b7; }
.swd-chat-min { border: 0; background: transparent; color: #fff; font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 8px 3px; flex: 0 0 auto; }
.swd-chat-min:hover { background: rgba(255, 255, 255, .16); }
.swd-chat-msgs { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px 6px; display: flex; flex-direction: column; gap: 10px; min-height: 48px; }
.swd-chat-msg { display: flex; flex-direction: column; max-width: 86%; }
.swd-chat-msg.is-you { align-self: flex-end; align-items: flex-end; }
.swd-chat-msg.is-them { align-self: flex-start; align-items: flex-start; }
.swd-chat-bubble { padding: 8px 12px; font-size: .95rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word; }
.swd-chat-msg.is-you .swd-chat-bubble { background: #224685; color: #fff; }
.swd-chat-msg.is-them .swd-chat-bubble { background: #f8fafc; border: 1px solid #e2e8f0; color: #0f172a; }
.swd-chat-when { font-size: .72rem; color: #94a3b8; margin-top: 3px; }
.swd-chat-note { text-align: center; font-size: .8rem; color: #475569; margin: 4px 0; }
.swd-chat-form { padding: 10px 16px 0; border-top: 1px solid #e2e8f0; margin: 0; }
.swd-chat-prechat { display: grid; gap: 10px; margin-bottom: 10px; }
.swd-chat-prechat[hidden] { display: none; }
.swd-chat-field label { display: block; font-size: .82rem; font-weight: 600; color: #0f172a; margin-bottom: 4px; }
.swd-chat-field label span { font-weight: 400; color: #64748b; }
.swd-chat-field input {
  width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 0;
  font: inherit; font-size: .92rem; color: #0f172a; background: #fff;
}
.swd-chat-field input:focus { outline: 2px solid #224685; outline-offset: -1px; border-color: #224685; }
.swd-chat-error { color: #b91c1c; font-size: .85rem; margin: 0 0 8px; }
.swd-chat-error[hidden] { display: none; }
.swd-chat-composer { display: flex; align-items: flex-end; gap: 8px; }
.swd-chat-composer textarea {
  flex: 1 1 auto; resize: none; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 0;
  font: inherit; font-size: .95rem; color: #0f172a; background: #fff;
}
.swd-chat-composer textarea:focus { outline: 2px solid #224685; outline-offset: -1px; border-color: #224685; }
.swd-chat-send {
  border: 0; background: #224685; color: #fff; padding: 10px 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.swd-chat-send:hover { background: #1b386a; }
.swd-chat-send:disabled { opacity: .6; cursor: default; }
.swd-chat-alt { margin: 9px 16px 12px; font-size: .8rem; color: #475569; }
.swd-chat-alt a { color: #224685; font-weight: 600; }

/* proactive nudge */
.swd-chat-nudge {
  position: fixed; right: 18px; bottom: 78px; z-index: 59;
  width: min(300px, calc(100vw - 36px));
  background: #fff; border: 1px solid #e2e8f0;
  box-shadow: 0 14px 36px rgba(15, 23, 42, .2);
  animation: swd-nudge-in .35s ease-out;
}
.swd-chat-nudge[hidden] { display: none; }
@keyframes swd-nudge-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.swd-chat-nudge-body {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  font: inherit; cursor: pointer; padding: 14px 34px 14px 16px;
}
.swd-chat-nudge-body b { display: block; margin-bottom: 4px; color: #0f172a; }
.swd-chat-nudge-body span { color: #475569; font-size: .9rem; }
.swd-chat-nudge-x {
  position: absolute; top: 6px; right: 6px; border: 0; background: transparent;
  color: #94a3b8; font-size: 1.15rem; line-height: 1; padding: 4px 7px; cursor: pointer;
}
.swd-chat-nudge-x:hover { color: #0f172a; background: #f1f5f9; }

/* assistant typing dots + "connecting you" wait indicator */
.swd-chat-typing { display: inline-flex; gap: 4px; align-items: center; min-height: 1.4em; }
.swd-chat-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: #94a3b8;
  animation: swd-typing 1.1s infinite ease-in-out;
}
.swd-chat-typing span:nth-child(2) { animation-delay: .18s; }
.swd-chat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes swd-typing { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
.swd-chat-wait { display: flex; align-items: baseline; justify-content: center; gap: 1px; }
.swd-chat-wait-dots span { animation: swd-wait-blink 1.3s infinite; }
.swd-chat-wait-dots span:nth-child(2) { animation-delay: .22s; }
.swd-chat-wait-dots span:nth-child(3) { animation-delay: .44s; }
@keyframes swd-wait-blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* Phones/tablets: clear the fixed bottom CTA bar (call + contact, lg:hidden). */
@media (max-width: 1023px) {
  .swd-chat-launch { right: 12px; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  .swd-chat-panel { right: 8px; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); width: calc(100vw - 16px); max-height: min(560px, calc(100vh - 130px)); }
  .swd-chat-nudge { bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  .swd-chat-nudge { animation: none; }
  .swd-chat-typing span, .swd-chat-wait-dots span { animation: none; }
}
