/* Aviano Chat Widget — bottom-right floating chat. CSS variables let the WP
   settings override brand color from PHP. */
:root {
  --av-brand: #111111;
  --av-brand-text: #ffffff;
  --av-bg: #ffffff;
  --av-text: #1a1a1a;
  --av-muted: #6b7280;
  --av-border: #e5e7eb;
  --av-bubble-from-us: #f3f4f6;
  --av-bubble-from-them: #111111;
  --av-bubble-from-them-text: #ffffff;
  --av-radius: 16px;
  --av-shadow: 0 10px 40px rgba(0,0,0,.12);
}

#aviano-chat-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--av-text);
}

#aviano-chat-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--av-brand);
  color: var(--av-brand-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--av-shadow);
  transition: transform .15s ease;
  position: relative;
}
#aviano-chat-bubble:hover { transform: scale(1.05); }
#aviano-chat-bubble svg { width: 28px; height: 28px; }

/* Unread badge — red circle with white count on the bubble when panel is
   closed and at least one new message has arrived. */
#aviano-chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #ef4444;
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--av-bg);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
#aviano-chat-unread.show { display: inline-flex; animation: av-pop .35s ease; }
@keyframes av-pop {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

#aviano-chat-panel {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--av-bg);
  border-radius: var(--av-radius);
  box-shadow: var(--av-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--av-border);
}
#aviano-chat-panel.open { display: flex; }

#aviano-chat-header {
  background: var(--av-brand);
  color: var(--av-brand-text);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
#aviano-chat-header .header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
#aviano-chat-header .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: white;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}
#aviano-chat-header .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#aviano-chat-header .avatar::after {
  content: '';
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid var(--av-brand);
}
#aviano-chat-header .header-text { min-width: 0; }
#aviano-chat-header .title { font-weight: 600; font-size: 15px; line-height: 1.2; }
#aviano-chat-header .subtitle {
  font-size: 12px;
  opacity: .8;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#aviano-chat-header .subtitle .status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
}
#aviano-chat-header .close-btn {
  background: transparent;
  border: 0;
  color: var(--av-brand-text);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.85;
}
#aviano-chat-header .close-btn:hover { opacity: 1; }

#aviano-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #fafafa;
}

.av-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.av-form .av-greeting {
  font-size: 14px;
  color: var(--av-muted);
  margin-bottom: 4px;
}
.av-form label {
  font-size: 12px;
  font-weight: 600;
  color: var(--av-text);
  display: block;
  margin-bottom: 4px;
}
.av-form input[type="text"],
.av-form input[type="email"],
.av-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--av-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  box-sizing: border-box;
}
.av-form textarea { resize: vertical; min-height: 60px; }
.av-form input:focus, .av-form textarea:focus {
  outline: 2px solid var(--av-brand);
  outline-offset: -1px;
  border-color: transparent;
}
.av-form .av-error {
  color: #b91c1c;
  font-size: 12px;
  margin-top: -4px;
}
.av-form button[type="submit"] {
  background: var(--av-brand);
  color: var(--av-brand-text);
  border: 0;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.av-form button[type="submit"]:disabled { opacity: .6; cursor: wait; }

.av-msg {
  margin-bottom: 12px;
  display: flex;
}
.av-msg .bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.av-msg.from-them .bubble {
  background: var(--av-bubble-from-them);
  color: var(--av-bubble-from-them-text);
  border-bottom-left-radius: 4px;
}
.av-msg.from-us {
  justify-content: flex-end;
}
.av-msg.from-us .bubble {
  background: var(--av-bubble-from-us);
  color: var(--av-text);
  border-bottom-right-radius: 4px;
}
/* Links inside bubbles */
.av-msg .bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.av-msg.from-them .bubble a { color: #93c5fd; }
.av-msg.from-us .bubble a { color: #1d4ed8; }
.av-msg .bubble strong { font-weight: 700; }
.av-msg .bubble em { font-style: italic; }
.av-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}
.av-typing span {
  width: 7px; height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: av-bounce 1.2s infinite ease-in-out;
}
.av-typing span:nth-child(2) { animation-delay: .15s; }
.av-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes av-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: .5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Quick-reply chips bar — sits between the conversation body and the input row. */
#aviano-chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
  background: #fafafa;
}
#aviano-chat-quick-replies:empty { display: none; }
.av-quick {
  background: white;
  color: var(--av-text);
  border: 1px solid var(--av-border);
  border-radius: 18px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s ease;
  font-family: inherit;
}
.av-quick:hover { background: #f3f4f6; }

#aviano-chat-attach {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--av-muted);
  padding: 0 4px;
  display: flex;
  align-items: center;
}
#aviano-chat-attach:hover { color: var(--av-text); }
#aviano-chat-attach:disabled { opacity: .5; cursor: not-allowed; }
#aviano-chat-attach svg { width: 20px; height: 20px; }

#aviano-chat-input-row {
  display: none;
  border-top: 1px solid var(--av-border);
  background: white;
  padding: 10px;
  gap: 8px;
  align-items: flex-end;
}
#aviano-chat-input-row.show { display: flex; }
#aviano-chat-input {
  flex: 1;
  border: 1px solid var(--av-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
}
#aviano-chat-input:focus { outline: 2px solid var(--av-brand); outline-offset: -1px; border-color: transparent; }
/* Send button: 1:1 rounded square with a white paper-plane baked in as a CSS
   background-image (data URL). No inner <svg> element — bypasses any theme
   CSS that would suppress stroke/fill on dynamically-injected SVG. */
#aviano-chat-send {
  background-color: var(--av-brand);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'><path d='M2.01 21L23 12 2.01 3 2 10l15 2-15 2z'/></svg>");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: 20px 20px;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color .12s ease;
}
#aviano-chat-send:hover { background-color: #000; }
#aviano-chat-send:disabled { opacity: .5; cursor: not-allowed; background-color: var(--av-brand); }

@media (max-width: 600px) {
  /* Full-screen on phones — feels native instead of a tiny card. */
  #aviano-chat-root { right: 12px; bottom: 12px; }
  #aviano-chat-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: 0;
  }
  #aviano-chat-panel.open { animation: av-slide-in .22s ease-out; }
  @keyframes av-slide-in {
    from { transform: translateY(20px); opacity: .6; }
    to   { transform: translateY(0); opacity: 1; }
  }
  #aviano-chat-header { padding-top: max(14px, env(safe-area-inset-top)); }
}

/* ── Channel chooser (bubble click → Website chat / Telegram) ── */
#aviano-chat-chooser {
  position: absolute;
  bottom: 80px;
  right: 4px;            /* centers the 52px circles under the 60px bubble */
  display: none;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}
#aviano-chat-chooser.open { display: flex; }
/* Just two clean circles popping up — no label/background.
   Hard-reset the <button> so the WP theme's default button styling
   (background fill / border / box-shadow) can't show behind the circle. */
.av-choice {
  display: inline-flex;
  background: none !important;
  background-color: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  outline: none !important;
  padding: 0 !important;
  margin: 0 !important;
  -webkit-appearance: none;
  appearance: none;
  line-height: 0;
  cursor: pointer;
  animation: av-pop 0.18s ease-out;
}
.av-choice:hover, .av-choice:focus { background: none !important; box-shadow: none !important; }
.av-choice-ic {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.22);
  transition: transform 0.12s ease;
  flex: 0 0 auto;
}
.av-choice:hover .av-choice-ic { transform: scale(1.08); }
.av-choice-ic svg { width: 26px; height: 26px; }
.av-choice-web .av-choice-ic { background: var(--av-brand, #111); color: #fff; }
.av-choice-tg .av-choice-ic { background: #229ED9; color: #fff; }
@keyframes av-pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Teaser cloud (shown while the bubble is closed) ── */
#aviano-chat-teaser {
  position: absolute;
  bottom: 26px;
  right: 78px;
  display: none;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: #111;
  border-radius: 16px;
  padding: 10px 12px 10px 14px;
  font-size: 14px;
  font-weight: 600;
  max-width: 230px;
  line-height: 1.3;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18);
  cursor: pointer;
}
#aviano-chat-teaser.show { display: flex; animation: av-pop 0.25s ease-out; }
#aviano-chat-teaser::after {
  content: '';
  position: absolute;
  right: -6px;
  bottom: 16px;
  width: 12px; height: 12px;
  background: #fff;
  transform: rotate(45deg);
}
.av-teaser-text { flex: 1 1 auto; }
.av-teaser-x {
  background: transparent;
  border: none;
  color: #999;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 0 4px;
  flex: 0 0 auto;
}
.av-teaser-x:hover { color: #111; }

@media (max-width: 480px) {
  #aviano-chat-teaser { max-width: 180px; right: 72px; }
}
