/* ── Rusty Chat Widget — Glassmorphism Blue ─────────────────── */

:root {
  --rc-primary:      #71ADDD;
  --rc-primary-dark: #5599c9;
  --rc-primary-deep: #4272a0;
  --rc-gradient:     linear-gradient(135deg, #71ADDD 0%, #4f8fb8 100%);
  --rc-ink:          #0f172a;
  --rc-slate:        #334155;
  --rc-muted:        #64748b;
  --rc-bg:           #f4fafc;
  --rc-white:        #ffffff;
  --rc-dark-hdr:     #0c1220;
  --rc-shadow-panel: 0 24px 64px rgba(15,23,42,.18), 0 4px 16px rgba(15,23,42,.10), 0 0 0 1px rgba(255,255,255,.6);
  --rc-font:         "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --rc-font-heading: "Plus Jakarta Sans", "DM Sans", system-ui, sans-serif;
  --rc-radius:       22px;
}

/* ── Launcher ─────────────────────────────────────────────── */
#rusty-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 50010;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

#rusty-bubble-btn {
  pointer-events: auto;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--rc-gradient);
  border: none;
  cursor: pointer;
  box-shadow:
    0 6px 28px rgba(113,173,221,.55),
    0 2px 8px  rgba(15,23,42,.15),
    0 0 0 0    rgba(113,173,221,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform .24s cubic-bezier(.34,1.56,.64,1),
    box-shadow .22s ease;
  position: relative;
  animation: rc-launcher-pulse 3.2s ease-in-out infinite;
}
@keyframes rc-launcher-pulse {
  0%, 100% { box-shadow: 0 6px 28px rgba(113,173,221,.55), 0 2px 8px rgba(15,23,42,.15), 0 0 0 0   rgba(113,173,221,.35); }
  55%       { box-shadow: 0 6px 28px rgba(113,173,221,.55), 0 2px 8px rgba(15,23,42,.15), 0 0 0 12px rgba(113,173,221,0);  }
}
#rusty-bubble-btn:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 10px 36px rgba(113,173,221,.65), 0 4px 12px rgba(15,23,42,.18);
  animation: none;
}
#rusty-bubble-btn.open {
  animation: none;
  box-shadow: 0 4px 18px rgba(113,173,221,.4), 0 2px 6px rgba(15,23,42,.12);
}
#rusty-bubble-btn:hover:not(.open) { transform: scale(1.1) translateY(-2px); }

#rusty-bubble-btn svg           { width: 27px; height: 27px; fill: #fff; }
#rusty-bubble-btn .rusty-close-icon  { display: none; }
#rusty-bubble-btn.open .rusty-chat-icon  { display: none; }
#rusty-bubble-btn.open .rusty-close-icon { display: block; }

#rusty-notif-dot {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2.5px solid #fff;
  display: none;
}
#rusty-notif-dot.show { display: block; }

/* Greeting tooltip */
#rusty-greeting {
  background: var(--rc-white);
  color: var(--rc-ink);
  font-size: 13.5px;
  font-family: var(--rc-font);
  padding: 10px 15px;
  border-radius: 14px;
  box-shadow:
    0 8px 32px rgba(15,23,42,.12),
    0 0 0 1px rgba(15,23,42,.06);
  max-width: 230px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(8px) scale(.96);
  transition: opacity .32s ease, transform .36s cubic-bezier(.34,1.2,.64,1);
  pointer-events: none;
}
#rusty-greeting.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ── Panel ─────────────────────────────────────────────────── */
#rusty-panel {
  position: fixed;
  bottom: 104px;
  right: 28px;
  z-index: 50009;
  width: 375px;
  height: 548px;
  background: rgba(244,250,252,.97);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--rc-radius);
  box-shadow: var(--rc-shadow-panel);
  border: 1px solid rgba(255,255,255,.75);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(28px) scale(.94);
  pointer-events: none;
  transition:
    opacity .28s ease,
    transform .34s cubic-bezier(.34,1.18,.64,1);
}
#rusty-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}
#rusty-panel.rusty-expanded {
  height: calc(100dvh - 120px);
  height: calc(100vh  - 120px);
  max-height: 860px;
}

/* ── Header ─────────────────────────────────────────────────── */
.rusty-header {
  background: var(--rc-dark-hdr);
  padding: 11px 12px 11px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.rusty-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(113,173,221,.18) 0%, transparent 60%);
  pointer-events: none;
}

.rusty-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--rc-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--rc-font-heading);
  color: #fff;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  box-shadow: 0 0 0 2px rgba(113,173,221,.45);
}
.rusty-avatar::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid rgba(113,173,221,.35);
  animation: rc-avatar-ring 2.6s ease-in-out infinite;
}
@keyframes rc-avatar-ring {
  0%, 100% { opacity: .5;  transform: scale(1);    }
  55%       { opacity: 0;  transform: scale(1.35); }
}

.rusty-header-info {
  flex: 1;
  position: relative;
  z-index: 1;
}
.rusty-header-info h4 {
  margin: 0 0 1px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--rc-font-heading);
  letter-spacing: -.01em;
}
.rusty-header-info span {
  font-size: 11px;
  color: rgba(255,255,255,.52);
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--rc-font);
}
.rusty-online-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 7px rgba(74,222,128,.65);
  animation: rc-online-blink 2.6s ease-in-out infinite;
}
@keyframes rc-online-blink {
  0%, 100% { opacity: 1;   }
  50%       { opacity: .45; }
}

.rusty-header-expand,
.rusty-header-close {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.08);
  color: rgba(255,255,255,.72);
  cursor: pointer;
  padding: 5px;
  border-radius: 8px;
  transition: background .16s, color .16s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  line-height: 1;
}
.rusty-header-close { font-size: 17px; }
.rusty-header-expand:hover,
.rusty-header-close:hover {
  background: rgba(255,255,255,.18);
  color: #fff;
}

/* ── Pre-chat form ─────────────────────────────────────────── */
.rusty-prechat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--rc-bg);
}
.rusty-prechat__intro {
  font-size: 14px;
  color: var(--rc-slate);
  margin: 0;
  line-height: 1.55;
  font-family: var(--rc-font);
}
.rusty-prechat__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rusty-prechat__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--rc-ink);
  font-family: var(--rc-font);
}
.rusty-prechat__req { color: #ef4444; margin-left: 2px; }
.rusty-prechat__opt {
  font-size: 11px;
  font-weight: 400;
  color: #94a3b8;
  margin-left: 4px;
}
.rusty-prechat__input {
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--rc-font);
  color: var(--rc-ink);
  outline: none;
  transition: border-color .18s, box-shadow .18s;
  background: var(--rc-white);
}
.rusty-prechat__input:focus {
  border-color: var(--rc-primary);
  box-shadow: 0 0 0 3px rgba(113,173,221,.16);
}
.rusty-prechat__input::placeholder { color: #94a3b8; }
.rusty-prechat__btn {
  margin-top: 4px;
  padding: 11px 0;
  border: none;
  border-radius: 999px;
  background: var(--rc-gradient);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--rc-font);
  cursor: pointer;
  transition: opacity .18s, transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .18s;
  box-shadow: 0 4px 18px rgba(113,173,221,.42);
}
.rusty-prechat__btn:hover {
  opacity: .92;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(113,173,221,.55);
}
.rusty-prechat__btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.rusty-prechat__err {
  font-size: 12.5px;
  color: #ef4444;
  margin: 0;
  min-height: 16px;
  font-family: var(--rc-font);
}

/* ── Messages area ─────────────────────────────────────────── */
#rusty-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #d2e5f5;
  scroll-behavior: smooth;
}
#rusty-messages::-webkit-scrollbar { width: 3px; }
#rusty-messages::-webkit-scrollbar-track { background: transparent; }
#rusty-messages::-webkit-scrollbar-thumb {
  background: rgba(113,173,221,.28);
  border-radius: 99px;
}

@keyframes rc-msg-in-bot {
  from { opacity: 0; transform: translateX(-16px) translateY(6px); }
  to   { opacity: 1; transform: translateX(0) translateY(0); }
}
@keyframes rc-msg-in-user {
  from { opacity: 0; transform: translateX(16px) translateY(6px); }
  to   { opacity: 1; transform: translateX(0) translateY(0); }
}

.rusty-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  gap: 4px;
}
.rusty-msg.bot {
  align-self: flex-start;
  animation: rc-msg-in-bot .32s cubic-bezier(.22,1,.36,1) both;
}
.rusty-msg.user {
  align-self: flex-end;
  animation: rc-msg-in-user .32s cubic-bezier(.22,1,.36,1) both;
}

.rusty-name {
  font-size: 10px;
  color: rgba(15,23,42,.45);
  padding: 0 5px;
  font-family: var(--rc-font);
  font-weight: 500;
  letter-spacing: .01em;
}
.rusty-msg.user .rusty-name { text-align: right; }

.rusty-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.56;
  word-break: break-word;
  font-family: var(--rc-font);
}
.rusty-msg.bot .rusty-bubble {
  background: #ffffff;
  color: var(--rc-ink);
  border-top-left-radius: 4px;
  border-bottom-left-radius: 5px;
  box-shadow:
    0 2px 8px rgba(15,23,42,.1),
    0 0 0 1px rgba(15,23,42,.05);
}
.rusty-msg.user .rusty-bubble {
  background: var(--rc-gradient);
  color: #fff;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(113,173,221,.42);
}

/* ── Typing indicator ──────────────────────────────────────── */
.rusty-typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 18px;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 5px;
  box-shadow:
    0 2px 8px rgba(15,23,42,.1),
    0 0 0 1px rgba(15,23,42,.05);
  width: fit-content;
  animation: rc-msg-in-bot .32s cubic-bezier(.22,1,.36,1) both;
}
.rusty-typing-label {
  font-size: 12px;
  color: var(--rc-muted);
  margin-right: 4px;
  font-family: var(--rc-font);
  letter-spacing: .01em;
}
.rusty-typing-dots span:not(.rusty-typing-label) {
  width: 7px;
  height: 7px;
  background: var(--rc-primary);
  border-radius: 50%;
  opacity: .65;
  animation: rc-dot-bounce 1.1s ease-in-out infinite;
}
.rusty-typing-dots span:nth-child(2) { animation-delay: .18s; }
.rusty-typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes rc-dot-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: .65; }
  30%            { transform: translateY(-7px); opacity: 1;   }
}

/* ── Footer / Input ────────────────────────────────────────── */
.rusty-footer {
  padding: 10px 12px;
  border-top: 1px solid rgba(15,23,42,.06);
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--rc-white);
  flex-shrink: 0;
}
#rusty-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 24px;
  padding: 9px 16px;
  font-size: 14px;
  outline: none;
  font-family: var(--rc-font);
  color: var(--rc-ink);
  transition: border-color .18s, box-shadow .18s, background .18s;
  resize: none;
  overflow: hidden;
  max-height: 80px;
  background: var(--rc-bg);
  line-height: 1.45;
}
#rusty-input:focus {
  border-color: var(--rc-primary);
  box-shadow: 0 0 0 3px rgba(113,173,221,.15);
  background: var(--rc-white);
}
#rusty-input::placeholder { color: #94a3b8; }

#rusty-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--rc-gradient);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    opacity .18s,
    transform .24s cubic-bezier(.34,1.56,.64,1),
    box-shadow .18s;
  box-shadow: 0 3px 14px rgba(113,173,221,.45);
}
#rusty-send:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(113,173,221,.6);
}
#rusty-send:active { transform: scale(.95); }
#rusty-send:disabled {
  opacity: .35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
#rusty-send svg { width: 17px; height: 17px; fill: #fff; }

/* ── Ticket tag ─────────────────────────────────────────────── */
.rusty-ticket-tag {
  margin-top: 8px;
  padding: 9px 13px;
  background: rgba(113,173,221,.08);
  border: 1px solid rgba(113,173,221,.24);
  border-radius: 13px;
  font-size: 13px;
  color: var(--rc-primary-dark);
  line-height: 1.48;
  font-family: var(--rc-font);
}
.rusty-ticket-tag strong { font-weight: 700; letter-spacing: .03em; }
.rusty-ticket-tag a { color: var(--rc-primary-dark); font-weight: 600; }

/* ── Powered by ─────────────────────────────────────────────── */
.rusty-powered {
  text-align: center;
  font-size: 10px;
  color: #94a3b8;
  padding: 4px 0 6px;
  background: var(--rc-white);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  font-family: var(--rc-font);
}
.rusty-powered a,
.rusty-powered a:link,
.rusty-powered a:visited {
  color: #94a3b8;
  text-decoration: underline;
  text-underline-offset: 2px;
  pointer-events: auto !important;
  cursor: pointer !important;
  position: relative;
  z-index: 10;
}
.rusty-powered a:hover { color: var(--rc-muted); }

/* ── Demo bar ───────────────────────────────────────────────── */
.rusty-demo-bar {
  padding: 0 12px 10px;
  flex-shrink: 0;
  background: var(--rc-white);
}
.rusty-demo-bar__btn {
  width: 100%;
  border: none;
  border-radius: 13px;
  padding: .62rem .75rem;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: var(--rc-gradient);
  box-shadow: 0 3px 14px rgba(113,173,221,.38);
  font-family: var(--rc-font);
  transition: filter .18s, transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .18s;
}
.rusty-demo-bar__btn:hover {
  filter: brightness(1.06);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(113,173,221,.5);
}

/* ── Quick replies ──────────────────────────────────────────── */
.rusty-quick-replies {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
  max-height: 110px;
  overflow-y: auto;
  flex-shrink: 0;
  background: var(--rc-white);
}
.rusty-quick-replies.has-items { display: flex; }
.rusty-quick-reply {
  border: 1.5px solid rgba(113,173,221,.38);
  background: rgba(113,173,221,.07);
  color: var(--rc-primary-deep);
  border-radius: 999px;
  padding: .35rem .9rem;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.3;
  font-family: var(--rc-font);
  transition: background .16s, border-color .16s, transform .18s cubic-bezier(.34,1.56,.64,1);
}
.rusty-quick-reply:hover {
  background: rgba(113,173,221,.16);
  border-color: var(--rc-primary);
  transform: translateY(-1px);
}

/* ── Mobile ─────────────────────────────────────────────────── */
body.rusty-open { overflow: hidden; }

@media (max-width: 640px) {
  #rusty-panel {
    /* Fill the visual viewport exactly — JS keeps --rusty-vp-h in sync with
       the visual viewport so iOS keyboard shrinks the panel correctly.      */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;    /* fallback */
    height: 100dvh;   /* dynamic viewport height on iOS 15.4+ / Chrome 108+ */
    border-radius: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: #d2e5f5;
    border: none;
  }
  #rusty-launcher  { right: 16px; bottom: 20px; }
  #rusty-messages  { flex: 1; min-height: 0; }
  #rusty-panel.open ~ #rusty-launcher,
  body.rusty-open #rusty-launcher { display: none; }
  /* Safe area padding for notched phones */
  .rusty-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* ── Reduced motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #rusty-bubble-btn,
  .rusty-avatar::after,
  .rusty-online-dot,
  .rusty-msg.bot,
  .rusty-msg.user,
  .rusty-typing-dots { animation: none !important; }
  #rusty-panel,
  #rusty-greeting { transition: opacity .15s ease !important; transform: none !important; }
}
