/* ============================================================
   Prime Dentistry — Chat Assistant
   ============================================================ */

.chat {
  position: fixed; right: 22px; bottom: 22px; z-index: 200;
  font-family: var(--ff-body);
}

/* ---------- Launcher ---------- */
.chat__launcher {
  position: relative; width: 64px; height: 64px; border: 0; border-radius: 50%;
  background: var(--grad-brand); cursor: pointer; box-shadow: 0 14px 30px rgba(24,163,154,.5);
  display: grid; place-items: center; transition: transform .3s ease, box-shadow .3s ease;
}
.chat__launcher:hover { transform: scale(1.06); box-shadow: 0 18px 38px rgba(24,163,154,.6); }
.chat__launcher svg { width: 30px; height: 30px; fill: #073a37; }
.chat__launcher-icon { position: absolute; inset: 0; display: grid; place-items: center; transition: opacity .25s ease, transform .25s ease; }
.chat__launcher-icon--close { opacity: 0; transform: rotate(-45deg) scale(.6); }
.chat.is-open .chat__launcher-icon--chat { opacity: 0; transform: rotate(45deg) scale(.6); }
.chat.is-open .chat__launcher-icon--close { opacity: 1; transform: none; }
.chat__launcher::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 0 rgba(127,209,174,.55);
  animation: chatPulse 2.4s infinite;
}
.chat.is-open .chat__launcher::after { animation: none; }
@keyframes chatPulse { 0% { box-shadow: 0 0 0 0 rgba(127,209,174,.5);} 70% { box-shadow: 0 0 0 18px rgba(127,209,174,0);} 100% { box-shadow:0 0 0 0 rgba(127,209,174,0);} }

.chat__badge {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px;
  background: #ff5a5f; color: #fff; border-radius: 999px; font-size: .76rem; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 3px 8px rgba(0,0,0,.2); border: 2px solid #fff;
}
.chat.is-open .chat__badge, .chat.is-seen .chat__badge { display: none; }

/* ---------- Panel ---------- */
.chat__panel {
  position: absolute; right: 0; bottom: 80px; width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100dvh - 120px);
  background: #fff; border-radius: 22px; box-shadow: 0 30px 70px rgba(14,42,71,.34);
  display: flex; flex-direction: column; overflow: hidden;
  transform-origin: bottom right; opacity: 0; transform: translateY(16px) scale(.96);
  transition: opacity .28s ease, transform .28s ease; pointer-events: none;
}
.chat.is-open .chat__panel { opacity: 1; transform: none; pointer-events: auto; }
.chat__panel[hidden] { display: flex; }

/* ---------- Header ---------- */
.chat__header {
  display: flex; align-items: center; gap: 12px; padding: 16px 16px;
  background: var(--grad-navy); color: #fff; position: relative;
}
.chat__avatar {
  width: 42px; height: 42px; border-radius: 50%; background: #fff; overflow: hidden;
  display: grid; place-items: center; flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.chat__avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat__heading { display: flex; flex-direction: column; line-height: 1.25; flex: 1; }
.chat__heading strong { font-size: 1rem; }
.chat__heading span { font-size: .8rem; color: #cfe0ee; display: inline-flex; align-items: center; gap: 6px; }
.chat__status-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.chat__close { background: rgba(255,255,255,.12); border: 0; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.chat__close svg { width: 16px; height: 16px; fill: #fff; }
.chat__close:hover { background: rgba(255,255,255,.24); }

/* ---------- Views ---------- */
.chat__view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat__view[hidden] { display: none; }

/* ---------- Messages ---------- */
.chat__messages {
  flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 12px;
  background: linear-gradient(180deg, #f7fbfa, #ffffff);
  scrollbar-width: thin; scrollbar-color: #cfe0d9 transparent;
}
.chat__messages::-webkit-scrollbar { width: 6px; }
.chat__messages::-webkit-scrollbar-thumb { background: #cfe0d9; border-radius: 6px; }

.msg { display: flex; gap: 8px; max-width: 88%; animation: msgIn .35s ease both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg__avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--grad-brand); color: #073a37; font-size: .62rem; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.msg__avatar--logo { background: #fff; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.msg__avatar--logo img { width: 100%; height: 100%; object-fit: cover; }
.msg__bubble { padding: 10px 14px; border-radius: 16px; font-size: .92rem; line-height: 1.5; }
.msg__bubble a { color: var(--teal-deep); font-weight: 600; text-decoration: underline; }

.msg--bot { align-self: flex-start; }
.msg--bot .msg__bubble { background: #fff; color: var(--ink); border: 1px solid var(--gray-line); border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm); }
.msg--user { align-self: flex-end; flex-direction: row-reverse; }
.msg--user .msg__bubble { background: var(--grad-brand); color: #073a37; border-bottom-right-radius: 4px; font-weight: 500; }
.msg--user .msg__avatar { background: var(--navy); color: #fff; }

/* typing indicator */
.msg--typing .msg__bubble { display: inline-flex; gap: 4px; align-items: center; }
.msg--typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); animation: typing 1.2s infinite; }
.msg--typing span:nth-child(2) { animation-delay: .2s; }
.msg--typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- Quick replies ---------- */
.chat__quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 16px 10px; }
.chat__chip {
  border: 1.5px solid var(--mint); background: var(--mint-soft); color: var(--teal-deep);
  border-radius: 999px; padding: 7px 13px; font-size: .82rem; font-weight: 600; cursor: pointer;
  font-family: var(--ff-body); transition: background .2s, transform .2s; white-space: nowrap;
}
.chat__chip:hover { background: var(--mint); color: #073a37; transform: translateY(-1px); }
.chat__chip--accent { border-color: var(--navy); background: var(--navy); color: #fff; }
.chat__chip--accent:hover { background: var(--navy-700); color: #fff; }

/* ---------- Input bar ---------- */
.chat__inputbar { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--gray-line); background: #fff; }
.chat__inputbar input {
  flex: 1; border: 1.5px solid var(--gray-line); border-radius: 999px; padding: 11px 16px;
  font-family: var(--ff-body); font-size: .92rem; background: var(--gray-soft); transition: border-color .2s, background .2s;
}
.chat__inputbar input:focus { outline: none; border-color: var(--teal); background: #fff; }
.chat__send { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--grad-brand); cursor: pointer; display: grid; place-items: center; flex-shrink: 0; transition: transform .2s; }
.chat__send:hover { transform: scale(1.07); }
.chat__send svg { width: 20px; height: 20px; fill: #073a37; }

/* ---------- Text Us view ---------- */
.chat__view--text { overflow-y: auto; }
.chat__text-head { padding: 18px 20px 6px; }
.chat__step { font-size: .8rem; color: var(--gray); }
.chat__text-head h3 { font-size: 1.4rem; margin-top: 2px; }
.chat__text-body { padding: 8px 20px 22px; }
.chat__text-intro { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0 18px; }
.chat__text-icon { flex-shrink: 0; width: 42px; height: 42px; border-radius: 12px; background: var(--mint-soft); display: grid; place-items: center; }
.chat__text-icon svg { width: 22px; height: 22px; fill: var(--teal-deep); }
.chat__text-intro p { font-size: .92rem; color: var(--ink); }
.chat__textform { display: grid; gap: 12px; }
.chat__row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chat__textform input, .chat__textform textarea {
  width: 100%; border: 1.5px solid var(--gray-line); border-radius: 12px; padding: 12px 14px;
  font-family: var(--ff-body); font-size: .92rem; background: var(--gray-soft); transition: border-color .2s, background .2s, box-shadow .2s;
}
.chat__textform input:focus, .chat__textform textarea:focus { outline: none; border-color: var(--teal); background: #fff; box-shadow: 0 0 0 4px rgba(24,163,154,.1); }
.chat__textform textarea { resize: vertical; }
.chat__consent { display: flex; gap: 10px; align-items: flex-start; font-size: .78rem; color: var(--gray); line-height: 1.4; cursor: pointer; }
.chat__consent input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--teal); flex-shrink: 0; }
.chat__formnote { font-size: .85rem; font-weight: 600; min-height: 1em; margin: -2px 0; }
.chat__formnote.is-error { color: #c0392b; }
.chat__formnote.is-success { color: var(--teal-deep); }

.chat__success { text-align: center; padding: 30px 10px; animation: msgIn .4s ease both; }
.chat__success-check { width: 64px; height: 64px; border-radius: 50%; background: var(--grad-brand); display: grid; place-items: center; margin: 0 auto 16px; }
.chat__success-check svg { width: 32px; height: 32px; fill: #073a37; }
.chat__success h3 { font-size: 1.3rem; margin-bottom: 8px; }
.chat__success p { color: var(--gray); font-size: .94rem; margin-bottom: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .chat { right: 16px; bottom: 16px; }
  .chat__panel { width: calc(100vw - 24px); height: calc(100dvh - 96px); bottom: 76px; right: -4px; }
  .chat__launcher { width: 58px; height: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat__launcher::after, .msg, .msg--typing span, .chat__success { animation: none !important; }
  .chat__panel { transition: opacity .2s ease; }
}
