.onechat-root {
  --onechat-color: #004080;
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: #1f2937;
}
.onechat-root *, .onechat-root *::before, .onechat-root *::after { box-sizing: border-box; }
.onechat-root.onechat-pos-right { right: 20px; }
.onechat-root.onechat-pos-left { left: 20px; }

.onechat-root .onechat-svg { display: inline-flex; align-items: center; justify-content: center; }
.onechat-root .onechat-svg svg { display: block; }

.onechat-root .onechat-fab {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: #fff;
  background: var(--onechat-color);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease;
}
.onechat-root .onechat-fab:hover { transform: scale(1.05); }
.onechat-root .onechat-fab:focus-visible { outline: 3px solid rgba(0, 0, 0, .35); outline-offset: 3px; }
.onechat-root .onechat-fab .onechat-svg svg { width: 28px; height: 28px; }
.onechat-root .onechat-fab .onechat-svg { position: absolute; transition: opacity .2s ease, transform .2s ease; }
.onechat-root .onechat-fab .onechat-fab-close { opacity: 0; transform: rotate(-90deg); }
.onechat-root.onechat-menu-open .onechat-fab > .onechat-svg:first-child,
.onechat-root.onechat-panel-open .onechat-fab > .onechat-svg:first-child { opacity: 0; transform: rotate(90deg); }
.onechat-root.onechat-menu-open .onechat-fab .onechat-fab-close,
.onechat-root.onechat-panel-open .onechat-fab .onechat-fab-close { opacity: 1; transform: none; }

.onechat-root .onechat-menu {
  position: absolute;
  bottom: 70px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.onechat-root.onechat-pos-right .onechat-menu { right: 4px; align-items: flex-end; }
.onechat-root.onechat-pos-left .onechat-menu { left: 4px; align-items: flex-start; }
.onechat-root.onechat-menu-open .onechat-menu { opacity: 1; visibility: visible; transform: none; }

.onechat-root .onechat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  font: inherit;
}
.onechat-root.onechat-pos-right .onechat-item { flex-direction: row-reverse; }
.onechat-root .onechat-item-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .18);
}
.onechat-root .onechat-item-icon svg { width: 24px; height: 24px; }
.onechat-root .onechat-item-label {
  background: #fff;
  color: #1f2937;
  padding: 6px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  white-space: nowrap;
  font-size: 13px;
}
.onechat-root .onechat-item:hover .onechat-item-icon { transform: scale(1.06); }
.onechat-root .onechat-item:focus-visible { outline: 2px solid var(--onechat-color); outline-offset: 3px; border-radius: 24px; }

.onechat-root .onechat-panel {
  position: absolute;
  bottom: 72px;
  width: 340px;
  height: 460px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.onechat-root.onechat-pos-right .onechat-panel { right: 0; }
.onechat-root.onechat-pos-left .onechat-panel { left: 0; }
.onechat-root.onechat-panel-open .onechat-panel { opacity: 1; visibility: visible; transform: none; }
.onechat-root.onechat-panel-open .onechat-menu { display: none; }

.onechat-root .onechat-panel-header {
  background: var(--onechat-color);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 15px;
}
.onechat-root .onechat-panel-close {
  background: none;
  border: 0;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  margin: 0;
  display: flex;
}
.onechat-root .onechat-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f5f6f8;
}
.onechat-root .onechat-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.onechat-root .onechat-out { align-self: flex-end; background: var(--onechat-color); color: #fff; border-bottom-right-radius: 4px; }
.onechat-root .onechat-in { align-self: flex-start; background: #fff; border: 1px solid #e5e7eb; border-bottom-left-radius: 4px; }
.onechat-root .onechat-error { align-self: center; color: #b91c1c; font-size: 12px; }

.onechat-root .onechat-panel-input {
  display: flex;
  gap: 8px;
  padding: 10px;
  margin: 0;
  border-top: 1px solid #eee;
  background: #fff;
}
.onechat-root .onechat-panel-input input {
  flex: 1;
  min-width: 0;
  height: 40px;
  margin: 0;
  padding: 0 14px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  font: inherit;
  font-size: 16px;
  color: #1f2937;
  background: #fff;
  box-shadow: none;
}
.onechat-root .onechat-panel-input input:focus { outline: none; border-color: var(--onechat-color); }
.onechat-root .onechat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  margin: 0;
  background: var(--onechat-color);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* MSN-style presence header + off-hours contact form */
.onechat-root .onechat-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.onechat-root .onechat-avatar {
  position: relative; width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: #fff; color: var(--onechat-color); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}
.onechat-root .onechat-avatar > .onechat-svg svg { width: 22px; height: 22px; }
.onechat-root .onechat-badge {
  position: absolute; right: -2px; bottom: -2px; width: 13px; height: 13px; border-radius: 50%;
  background: #94a3b8; border: 2px solid #fff;
}
.onechat-root .onechat-online .onechat-badge { background: #22c55e; animation: onechat-pulse 2s ease-out infinite; }
.onechat-root .onechat-offline .onechat-badge { background: #f59e0b; }
@keyframes onechat-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .7); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.onechat-root .onechat-panel-head { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.onechat-root .onechat-panel-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.onechat-root .onechat-status { font-size: 12px; font-weight: 400; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.onechat-root .onechat-online .onechat-status::before { content: '● '; color: #4ade80; }
.onechat-root .onechat-offline .onechat-status::before { content: '● '; color: #fbbf24; }

.onechat-root .onechat-lead { display: none; flex: 1; overflow-y: auto; padding: 14px; background: #f5f6f8; }
.onechat-root .onechat-offline .onechat-lead { display: block; }
.onechat-root .onechat-offline .onechat-panel-body,
.onechat-root .onechat-offline .onechat-panel-input { display: none; }
.onechat-root .onechat-lead-intro { background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.onechat-root .onechat-lead-form { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.onechat-root .onechat-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #4b5563; margin: 0; }
.onechat-root .onechat-field input,
.onechat-root .onechat-field textarea {
  width: 100%; margin: 0; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px;
  font: inherit; font-size: 16px; color: #1f2937; background: #fff; box-shadow: none; resize: vertical;
}
.onechat-root .onechat-field input:focus,
.onechat-root .onechat-field textarea:focus { outline: none; border-color: var(--onechat-color); }
.onechat-root .onechat-lead-submit {
  margin: 4px 0 0; padding: 10px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--onechat-color); color: #fff; font: inherit; font-weight: 600;
}
.onechat-root .onechat-lead-submit:disabled { opacity: .6; cursor: default; }
.onechat-root .onechat-lead .onechat-error:empty { display: none; }
.onechat-root .onechat-lead-done { display: none; text-align: center; padding: 40px 10px; font-size: 15px; font-weight: 600; }
.onechat-root .onechat-lead-check { width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 50%; background: #22c55e; color: #fff; font-size: 26px; line-height: 48px; }
.onechat-root .onechat-lead-sub { font-size: 13px; font-weight: 400; color: #6b7280; margin-top: 4px; }
.onechat-root .onechat-lead-sent .onechat-lead-intro,
.onechat-root .onechat-lead-sent .onechat-lead-form { display: none; }
.onechat-root .onechat-lead-sent .onechat-lead-done { display: block; }

@media (max-width: 480px) {
  .onechat-root.onechat-pos-right { right: 14px; }
  .onechat-root.onechat-pos-left { left: 14px; }
  .onechat-root .onechat-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    width: auto;
    height: auto;
    top: calc(70px + env(safe-area-inset-top, 0px));
    max-height: none;
  }
}

/* ── engagement: label pill, presence, badge, greeting bubble, one-off motion ── */
.onechat-root .onechat-fabrow { display: flex; align-items: center; gap: 10px; }
.onechat-root.onechat-pos-left .onechat-fabrow { flex-direction: row-reverse; }
.onechat-root .onechat-pill {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  background: #fff; color: #1f2937; border: 0; margin: 0; cursor: pointer;
  padding: 8px 14px; border-radius: 999px; box-shadow: 0 4px 16px rgba(0, 0, 0, .14);
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1.25; text-align: left;
  transition: opacity .2s ease, transform .2s ease;
}
.onechat-root.onechat-pos-left .onechat-pill { align-items: flex-end; text-align: right; }
.onechat-root .onechat-pill-sub { font-size: 11px; font-weight: 400; color: #15803d; }
.onechat-root .onechat-pill-sub::before { content: '● '; }
.onechat-root .onechat-pill-sub.onechat-pill-off { color: #b45309; }
.onechat-root.onechat-menu-open .onechat-pill,
.onechat-root.onechat-panel-open .onechat-pill { opacity: 0; transform: translateX(8px); pointer-events: none; }

.onechat-root .onechat-presence {
  position: absolute; right: 1px; bottom: 1px; width: 14px; height: 14px; border-radius: 50%;
  background: #22c55e; border: 2px solid #fff; box-sizing: border-box;
}
.onechat-root .onechat-presence.onechat-presence-off { background: #f59e0b; }
.onechat-root.onechat-menu-open .onechat-fab .onechat-presence,
.onechat-root.onechat-panel-open .onechat-fab .onechat-presence { display: none; }
.onechat-root .onechat-fab-badge {
  position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: #e0245e; color: #fff; font-size: 12px; font-weight: 700; line-height: 16px;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-sizing: border-box;
}
.onechat-root .onechat-fab-badge[hidden], .onechat-root .onechat-presence[hidden] { display: none; }

.onechat-root .onechat-teaser {
  position: absolute; bottom: 72px; width: 300px; max-width: calc(100vw - 40px);
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  background: #fff; color: #1f2937; padding: 14px 34px 14px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18); animation: onechat-pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
.onechat-root.onechat-pos-right .onechat-teaser { right: 0; border-radius: 14px 14px 4px 14px; }
.onechat-root.onechat-pos-left .onechat-teaser { left: 0; border-radius: 14px 14px 14px 4px; }
.onechat-root .onechat-teaser[hidden] { display: none; }
.onechat-root.onechat-menu-open .onechat-teaser,
.onechat-root.onechat-panel-open .onechat-teaser { display: none; }
@keyframes onechat-pop { from { opacity: 0; transform: translateY(10px) scale(.95); } }
.onechat-root .onechat-teaser-av {
  position: relative; width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--onechat-color); color: #fff; display: flex; align-items: center; justify-content: center;
}
.onechat-root .onechat-teaser-av img,
.onechat-root .onechat-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.onechat-root .onechat-teaser-av .onechat-presence { width: 12px; height: 12px; right: -1px; bottom: -1px; }
.onechat-root .onechat-teaser-body { min-width: 0; }
.onechat-root .onechat-teaser-who { font-size: 12px; color: #6b7280; margin-bottom: 2px; }
.onechat-root .onechat-teaser-msg { font-size: 14px; line-height: 1.45; }
.onechat-root .onechat-teaser-x {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; padding: 0; margin: 0;
  border: 0; background: none; color: #9ca3af; cursor: pointer; display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.onechat-root .onechat-teaser-x:hover { background: #f3f4f6; color: #4b5563; }
.onechat-root .onechat-teaser-x svg { width: 14px; height: 14px; }

.onechat-root .onechat-fab.onechat-attn { animation: onechat-wiggle .7s ease-in-out 2; }
.onechat-root .onechat-fab.onechat-attn::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  animation: onechat-ring 2.4s ease-out 3;
}
@keyframes onechat-wiggle { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-12deg); } 40% { transform: rotate(10deg); } 60% { transform: rotate(-6deg); } 80% { transform: rotate(4deg); } }
@keyframes onechat-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--onechat-color) 45%, transparent); } 100% { box-shadow: 0 0 0 18px transparent; } }

@media (max-width: 480px) {
  .onechat-root .onechat-pill { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .onechat-root * { transition: none !important; animation: none !important; }
}
