.afm-chat, .afm-chat * { box-sizing: border-box; }
.afm-chat {
  --afm-brand: #0B3D5C;
  --afm-bg: #ffffff;
  --afm-soft: #f3f5f8;
  --afm-text: #1d2530;
  --afm-muted: #6b7684;
  --afm-border: #e1e5eb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--afm-text);
  text-align: left;
}

/* ---------- Floating mode ---------- */
.afm-chat--floating {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
}
.afm-chat--floating.afm-chat--left { right: auto; left: 20px; }

.afm-chat__launcher {
  width: 60px; height: 60px;
  border: 0; border-radius: 50%;
  background: var(--afm-brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  transition: transform .15s ease;
  margin-left: auto;
}
.afm-chat--left .afm-chat__launcher { margin-left: 0; }
.afm-chat__launcher:hover { transform: scale(1.06); }
.afm-chat__launcher:focus-visible { outline: 3px solid rgba(0,0,0,.35); outline-offset: 3px; }
.afm-chat__launcher .afm-i-close { display: none; }
.afm-chat--open .afm-chat__launcher .afm-i-open { display: none; }
.afm-chat--open .afm-chat__launcher .afm-i-close { display: block; }

.afm-chat--floating .afm-chat__panel {
  position: absolute;
  bottom: 76px; right: 0;
  width: 370px;
  height: min(580px, calc(100vh - 110px));
  opacity: 0; visibility: hidden;
  transform: translateY(12px);
  transition: opacity .18s ease, transform .18s ease, visibility .18s;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.afm-chat--floating.afm-chat--left .afm-chat__panel { right: auto; left: 0; }
.afm-chat--open .afm-chat__panel { opacity: 1; visibility: visible; transform: none; }

/* ---------- Inline (shortcode) mode ---------- */
.afm-chat-inline { max-width: 720px; margin: 0 auto; }
.afm-chat--inline { height: 100%; }
.afm-chat--inline .afm-chat__panel { height: 100%; border: 1px solid var(--afm-border); }

/* ---------- Panel ---------- */
.afm-chat__panel {
  display: flex; flex-direction: column;
  background: var(--afm-bg);
  border-radius: 16px;
  overflow: hidden;
}
.afm-chat__header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 12px 14px 16px;
  background: var(--afm-brand); color: #fff;
}
.afm-chat__avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
}
.afm-chat__titles { flex: 1; min-width: 0; }
.afm-chat__name { font-weight: 600; font-size: 15px; }
.afm-chat__sub { font-size: 12.5px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.afm-chat__icon {
  background: transparent; border: 0; color: #fff; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; padding: 0;
  display: flex; align-items: center; justify-content: center; opacity: .85;
}
.afm-chat__icon:hover { background: rgba(255,255,255,.15); opacity: 1; }

.afm-chat__log {
  flex: 1; overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--afm-soft);
  overscroll-behavior: contain;
}
.afm-chat__msg {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 14px;
  word-wrap: break-word; overflow-wrap: anywhere;
  white-space: normal;
}
.afm-chat__msg--bot {
  align-self: flex-start;
  background: #fff; color: var(--afm-text);
  border: 1px solid var(--afm-border);
  border-bottom-left-radius: 4px;
}
.afm-chat__msg--user {
  align-self: flex-end;
  background: var(--afm-brand); color: #fff;
  border-bottom-right-radius: 4px;
}
.afm-chat__msg a { color: inherit; text-decoration: underline; }
.afm-chat__msg--bot a { color: var(--afm-brand); }

.afm-chat__typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.afm-chat__typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--afm-muted); opacity: .4;
  animation: afm-blink 1.2s infinite ease-in-out;
}
.afm-chat__typing span:nth-child(2) { animation-delay: .15s; }
.afm-chat__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes afm-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: .9; transform: translateY(-3px); } }

.afm-chat__chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 14px 10px;
  background: var(--afm-soft);
}
.afm-chat__chip {
  font: inherit; font-size: 13px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--afm-brand);
  background: #fff; color: var(--afm-brand);
  cursor: pointer;
}
.afm-chat__chip:hover { background: var(--afm-brand); color: #fff; }

.afm-chat__form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 10px 6px 14px;
  border-top: 1px solid var(--afm-border);
  background: #fff;
  margin: 0;
}
.afm-chat__input {
  flex: 1; resize: none;
  font: inherit; font-size: 15px; color: var(--afm-text);
  border: 0; outline: 0; background: transparent;
  padding: 8px 0; margin: 0;
  max-height: 120px; min-height: 0;
  box-shadow: none;
}
.afm-chat__send {
  flex: none; width: 38px; height: 38px;
  border: 0; border-radius: 50%; padding: 0;
  background: var(--afm-brand); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.afm-chat__send:disabled { opacity: .5; cursor: default; }
.afm-chat__foot {
  font-size: 11px; color: var(--afm-muted);
  text-align: center; padding: 0 10px 8px; background: #fff;
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  .afm-chat--floating { right: 16px; bottom: 16px; }
  .afm-chat--floating.afm-chat--left { left: 16px; }
  .afm-chat--floating .afm-chat__panel {
    position: fixed; inset: 0;
    width: 100%; height: 100%;
    border-radius: 0;
  }
  .afm-chat--open .afm-chat__launcher { display: none; }
  .afm-chat__input { font-size: 16px; } /* prevents iOS zoom */
}

@media (prefers-reduced-motion: reduce) {
  .afm-chat__panel, .afm-chat__launcher { transition: none; }
  .afm-chat__typing span { animation: none; }
}
