/* Isola il widget da stili tema WP */
.sg-teo-chat-launcher,
.sg-teo-chat,
.sg-teo-chat * {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* FAB: avatar Teo (friendly) da StarGem */
.sg-teo-chat-launcher {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  z-index: 99990;
  width: 64px;
  height: 64px;
  min-width: 64px;
  min-height: 64px;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
  color: #0b1f2a;
  box-shadow: 0 10px 28px rgba(11, 31, 42, 0.28);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation;
}
.sg-teo-chat-launcher:hover,
.sg-teo-chat-launcher:focus-visible {
  transform: translateY(-2px);
  outline: none;
  box-shadow: 0 14px 32px rgba(11, 31, 42, 0.34);
}
html.sg-teo-chat-open .sg-teo-chat-launcher {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
.sg-teo-chat-launcher__pic,
.sg-teo-chat-launcher__img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  border: 0;
  border-radius: 0;
}
.sg-teo-chat-launcher__img {
  object-fit: cover;
  object-position: center 18%;
}
.sg-teo-chat-launcher .screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  word-wrap: normal !important;
}

/* Pannello laterale (stile Meta / messenger) */
.sg-teo-chat {
  --sg-teo-panel-h: 100dvh;
  position: fixed;
  top: 0;
  right: 0;
  bottom: auto;
  left: auto;
  z-index: 99991;
  display: flex;
  flex-direction: column;
  width: min(100%, 380px);
  max-width: 100%;
  height: var(--sg-teo-panel-h, 100dvh);
  max-height: var(--sg-teo-panel-h, 100dvh);
  margin: 0;
  padding: 0;
  background: #f0f2f5;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: contain;
  overflow: hidden;
}
.sg-teo-chat[hidden] {
  display: none !important;
}
.sg-teo-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex: 0 0 auto;
  padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 1rem 0.75rem;
  padding-right: calc(0.75rem + env(safe-area-inset-right, 0px));
  background: #0b1f2a;
  color: #fff;
  min-height: 56px;
}
.sg-teo-chat__brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1 1 auto;
}
.sg-teo-chat__brand > div {
  min-width: 0;
}
.sg-teo-chat__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
}
.sg-teo-chat__avatar picture,
.sg-teo-chat__avatar img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  border: 0;
  object-fit: cover;
  object-position: center 18%;
}
.sg-teo-chat__name {
  display: block;
  font-size: 1rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sg-teo-chat__status {
  display: block;
  font-size: 0.78rem;
  opacity: 0.9;
}
.sg-teo-chat__close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0 !important;
  border-radius: 50% !important;
  background: transparent !important;
  background-image: none !important;
  box-shadow: none !important;
  color: #fff !important;
  font-size: 1.6rem !important;
  font-weight: 400;
  line-height: 1;
  text-indent: 0 !important;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
}
.sg-teo-chat__close svg {
  display: block;
  margin: auto;
  pointer-events: none;
}
.sg-teo-chat__thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.sg-teo-chat__bubble {
  max-width: min(88%, 100%);
  padding: 0.65rem 0.8rem;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.sg-teo-chat__bubble--bot {
  align-self: flex-start;
  background: #fff;
  color: #111;
  border-bottom-left-radius: 4px;
}
.sg-teo-chat__bubble--bot a {
  color: #0a7c66;
  text-decoration: underline;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.sg-teo-chat__bubble--bot strong {
  font-weight: 700;
}
.sg-teo-chat__bubble--user {
  align-self: flex-end;
  background: #0b1f2a;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sg-teo-chat__composer {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  padding: 0.65rem 0.75rem;
  padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
  padding-left: calc(0.75rem + env(safe-area-inset-left, 0px));
  padding-right: calc(0.75rem + env(safe-area-inset-right, 0px));
  background: #fff;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}
.sg-teo-chat__input {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  max-width: 100%;
  height: 44px;
  margin: 0;
  border: 1px solid #d0d5dd !important;
  border-radius: 999px !important;
  padding: 0.55rem 0.9rem !important;
  /* 16px evita zoom automatico iOS */
  font-size: 16px !important;
  line-height: 1.3;
  background: #fff !important;
  color: #111 !important;
  box-shadow: none !important;
  appearance: none;
  -webkit-appearance: none;
}
.sg-teo-chat__input:focus {
  outline: 2px solid rgba(11, 31, 42, 0.35);
  outline-offset: 1px;
}
.sg-teo-chat__send {
  flex: 0 0 auto;
  border: 0 !important;
  border-radius: 50% !important;
  width: 44px;
  height: 44px;
  min-width: 44px;
  margin: 0;
  padding: 0;
  background: #0b1f2a !important;
  color: #fff !important;
  cursor: pointer;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: none !important;
  font-size: 1.05rem;
  line-height: 1;
}

/* Mobile / tablet stretto: pannello a tutto schermo */
@media (max-width: 767px) {
  .sg-teo-chat {
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: var(--sg-teo-panel-h, 100dvh);
    max-height: var(--sg-teo-panel-h, 100dvh);
    border-radius: 0;
    box-shadow: none;
  }
  .sg-teo-chat__bubble {
    max-width: 92%;
    font-size: 0.95rem;
  }
  .sg-teo-chat__thread {
    padding: 0.85rem 0.75rem;
  }
}

/* Solleva il FAB sopra il “torna su” tipico dei temi */
@media (max-width: 900px) {
  .sg-teo-chat-launcher {
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    right: max(0.85rem, env(safe-area-inset-right, 0px));
  }
}

/* Landscape telefono: header più compatto, thread utilizzabile */
@media (max-height: 480px) and (orientation: landscape) {
  .sg-teo-chat__head {
    padding-top: calc(0.4rem + env(safe-area-inset-top, 0px));
    padding-bottom: 0.4rem;
    min-height: 48px;
  }
  .sg-teo-chat__avatar {
    width: 32px;
    height: 32px;
  }
  .sg-teo-chat__status {
    display: none;
  }
  .sg-teo-chat__composer {
    padding-top: 0.4rem;
    padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px));
  }
  .sg-teo-chat__input,
  .sg-teo-chat__send {
    height: 40px;
    min-height: 40px;
  }
}

/* Blocca scroll pagina sotto la chat (classe su <html>) */
html.sg-teo-chat-open,
html.sg-teo-chat-open body {
  overflow: hidden !important;
  overscroll-behavior: none;
  touch-action: none;
}
html.sg-teo-chat-open .sg-teo-chat,
html.sg-teo-chat-open .sg-teo-chat__thread,
html.sg-teo-chat-open .sg-teo-chat__composer,
html.sg-teo-chat-open .sg-teo-chat__input {
  touch-action: manipulation;
}
html.sg-teo-chat-open .sg-teo-chat__thread {
  touch-action: pan-y;
}

@media (prefers-reduced-motion: reduce) {
  .sg-teo-chat-launcher {
    transition: none;
  }
}
