/* ──────────────── Reset & Root ───────────────── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-popup: rgba(0, 0, 0, 0.01);
  --bg-header: rgba(255, 255, 255, 0.08);
  --bg-ctrl: rgba(37, 37, 37, 0.9);
  --text: #fff;
  --placeholder: rgba(255, 255, 255, 0.6);
  --brand: #007bff;
  --brand-dark: #005bb5;
}

/* ───────── Hover zoom su tutti i pulsanti ───────── */
button {
  transition: transform 0.2s ease-in-out;
}
button:hover {
  transform: scale(1.1);
}

/* ─────────────── Toggle Button ──────────────── */
#rddi-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--brand);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: background .2s;
  z-index: 10002;
}
#rddi-toggle.hidden { display: none; }
#rddi-toggle:hover { background: var(--brand-dark); }

/* ───────────────── Overlay ─────────────────── */
#rddi-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 999999;
  display: none;
}
@media (max-width: 600px) {
  #rddi-overlay.active { display: block; }
}

/* ───────────────── Popup ─────────────────────── */
#rddi-popup {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  right: 20px;
  width: 360px;
  max-height: 80vh;
  display: none;
  flex-direction: column;
  background: var(--bg-popup);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 30px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.6);
  overflow: hidden;
  z-index: 1000000;
  user-select: none;
  transform-origin: bottom right;
  animation-duration: .5s;
  animation-fill-mode: both;
  pointer-events: none;
}
@supports not (bottom: calc(env(safe-area-inset-bottom) + 20px)) {
  #rddi-popup { bottom: 20px; }
}
#rddi-popup.open {
  display: flex;
  animation-name: popupIn;
  pointer-events: auto;
}
@media (max-width:600px) {
  #rddi-popup {
    width: 95vw;
    bottom: 10px;
    right: 2.5vw;
    max-height: 80vh;
  }
}

/* ─────────────── Popup Animations ─────────── */
@keyframes popupIn {
  0%   { transform: scale(.3) translate(100%,100%); opacity:0; }
  60%  { transform: scale(1.05) translate(0); opacity:1; }
  100% { transform: scale(1) translate(0); opacity:1; }
}
@keyframes popupOut {
  0%   { transform: scale(1) translate(0); opacity:1; }
  100% { transform: scale(.3) translate(100%,100%); opacity:0; }
}

/* ────────────────── Header ──────────────────── */
#rddi-popup .header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 40px;
  font: 18px/1.2 "Montserrat", sans-serif;
  font-weight: bold;
  color: var(--text);
  background: var(--bg-header);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  text-shadow:
    -1px -1px 0 #000,
     1px -1px 0 #000,
    -1px  1px 0 #000,
     1px  1px 0 #000;
  position: relative;
}
#rddi-close {
  position: absolute;
  top: 12px;
  left: 12px;
  background: none;
  border: none;
  cursor: pointer;
}
#rddi-close img {
  width: 20px;
  height: 20px;
}
#rddi-close:hover { color: rgba(255,255,255,0.65); }

/* ─────────────── Status Dot ───────────────── */
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  background: red;
}
.status-dot.online { background: limegreen; }

/* ─────────────── Avatar 3D ────────────────── */
#rddi-avatar {
  width: 100%;
  height: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  position: relative;
}
#rddi-avatar model-viewer {
  border-radius: inherit;
  width: 100%;
  height: 100%;
  --poster-color: transparent;
}

/* ─────────────── Chat Box ─────────────────── */
#rddi-chatbox {
  position: relative;
  flex: 1;
  padding: 10px 16px;
  padding-bottom: 64px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font: 14px/1.35 "Montserrat", sans-serif;
  color: var(--text);
  -webkit-mask-image: linear-gradient(to top, transparent 0%, black 20px, black calc(100% - 20px), transparent 100%);
  mask-image: linear-gradient(to top, transparent 0%, black 20px, black calc(100% - 20px), transparent 100%);
}

/* ─────────────── Bubble Styles ─────────────── */
#rddi-chatbox .me,
#rddi-chatbox .ai {
  padding: 10px 14px;
  border-radius: 20px;
  max-width: 75%;
  word-break: break-word;
}
#rddi-chatbox .me { align-self: flex-end; background: rgba(50,50,50,0.85); }
#rddi-chatbox .ai { align-self: flex-start; background: rgba(37,37,37,0.85); }
#rddi-chatbox .ai.err { background: #b04444; }

/* ─────────────── Typing Indicator ─────────── */
#typing-indicator {
  display: none;
  font-style: italic;
  font-size: 13px;
  padding: 4px 16px;
  margin: 0 0 8px;
  color: var(--text);
  align-self: flex-start;
}
#typing-indicator.visible { display: block; }

/* ───────────────── Controls (barra unica) ────────────────── */
#rddi-popup .ctrl {
  position: sticky;
  bottom: 0;
  width: calc(100% - 24px);
  margin: 0 12px 12px;
  display: flex;
  align-items: center;
  background: var(--bg-ctrl);
  border-radius: 9999px;
  padding: 4px 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  gap: 8px;
  z-index: 1;
}

/* ─────────────── Input & Buttons ───────────── */
#rddi-msg {
  flex: 1;
  min-width: 0;           /* permette lo shrink corretto */
  background: transparent;
  border: none;
  padding: 2px 8px;
  color: #fff;
  font-size: 16px;
  outline: none;
}
#rddi-msg::placeholder {
  color: var(--placeholder);
  opacity: 1;             /* placeholder sempre visibile */
}

/* ───────── Pulsanti nella barra Ctrl ───────── */
#rddi-popup .ctrl button {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
}
/* spazio orizzontale tra pulsanti */
#rddi-popup .ctrl .play-button,
#rddi-popup .ctrl .mic-button {
  margin: 0 6px;
  align-self: center;
}

/* ─── Forzo tutte le icone PNG a 20×20 ───────── */
#rddi-popup .ctrl img,
#rddi-toggle img {
  width: 20px !important;
  height: 20px !important;
  object-fit: contain;
}

/* ─────────────── Animazioni ────────────────── */
@keyframes spin {
  0% { transform: rotate(0); }
  100% { transform: rotate(360deg); }
}
@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ─── Microphone Active State ───────────────── */
#rddi-mic.active {
  animation: pulse 0.9s ease-in-out infinite;
  transform-origin: center;
}
#rddi-mic.active img {
  transform: scale(1.1);
}

/* ─────────────── Custom Scrollbar ────────────── */
/* Nasconde il track bianco, mostra solo thumb (ovale) e freccette */
#rddi-chatbox::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
#rddi-chatbox::-webkit-scrollbar-track {
  background: transparent;
}
#rddi-chatbox::-webkit-scrollbar-thumb {
  background-color: rgba(255,255,255,0.4);
  border-radius: 6px;
  border: none;
}
#rddi-chatbox::-webkit-scrollbar-button {
  display: block;
  background: transparent;
}
/* Freccette su/giù (metti il path corretto alle tue icone SVG) */
#rddi-chatbox::-webkit-scrollbar-button:vertical:decrement {
  height: 12px;
  background-image: url('path/to/up-arrow.svg');
  background-repeat: no-repeat;
  background-position: center;
}
#rddi-chatbox::-webkit-scrollbar-button:vertical:increment {
  height: 12px;
  background-image: url('path/to/down-arrow.svg');
  background-repeat: no-repeat;
  background-position: center;
}

/* Supporto Firefox */
#rddi-chatbox {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.4) transparent;
}

/* ───────────── Mini-popup di approfondimento ───────────── */
#rddi-deeplink {
  display: flex;
  position: fixed;
  top: calc(env(safe-area-inset-top, 20px) + 60px);
  left: 50%;
  transform: translateX(-50%) scale(0);
  opacity: 0;
  pointer-events: none;

  flex-direction: column;
  padding: 10px 20px;
  width: 320px;
  max-width: 90vw;
  border-radius: 50px;
  background-color: rgba(50,50,50,0.85);
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);

  transition: opacity 0.3s ease, transform 0.3s ease;
  transform-origin: top center;
  z-index: 1000001;
}

/* Riga di testo */
#rddi-deeplink > span {
  font-size: 15px;
  text-align: center;
}

#rddi-deeplink p {
  margin: 0 0 12px;
  line-height: 1.4;
}

#rddi-deeplink .btns {
  display: flex;
  gap: 8px;                 /* spazio orizzontale tra Sì e No */
}

/* Stili base per i bottoni Sì/No */
#rddi-deeplink button {
  margin: 3 3px;
  flex: 1;                   /* li rende della stessa larghezza */
  padding: 6px 12px;
  font-size: 14px;
  border: none;
  border-radius: 12px;      /* arrotonda anche i bottoni */
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

/* Colore “Sì” (successo) */
#rddi-deeplink-yes {
  background: #8f8f8f;      
  color: #fff;
}
#rddi-deeplink-yes:hover {
  background: #7d7d7d;
  transform: scale(1.03);
}

/* Colore “No” (attenzione) */
#rddi-deeplink-no {
  background: #8f8f8f;      
  color: #fff;
}
#rddi-deeplink-no:hover {
  background: #7d7d7d;
  transform: scale(1.03);
}

#rddi-avatar {
  transition: transform 0.4s ease;
  transform-origin: bottom center;
}

/* quando il popup di approfondimento è aperto, rimpicciolisci l’avatar */
#rddi-avatar.zoom-out {
  transform: scale(0.70);        
  transition: transform 0.4s ease;
  transform-origin: bottom center;
}

#rddi-deeplink.open {
  transform: translateX(-50%) scale(1);
  opacity: 1;
  pointer-events: auto;
  animation: deeplinkIn 0.4s ease-out both;
}

  /* ───────────── Mobile Deeplink ───────────── */
@media (max-width: 600px) {
  #rddi-deeplink {
    top: calc(env(safe-area-inset-top, 20px) + 100px); /* più spazio su mobile */
  }
  #rddi-deeplink .btns button {
    flex: 1 !important;
    width: 40px !important;
  }
}