:root{
  /* Palette DARK */
  --cb-bg: #0b0f14;          /* sfondo generale (se serve) */
  --cb-panel: #0f1620;       /* pannello chat */
  --cb-border: rgba(255,255,255,.12);
  --cb-text: #e8eef6;        /* testo principale */
  --cb-muted: rgba(232,238,246,.70);
  --cb-accent: #6ee7ff;      /* accento (bottone/hover) */

  --cb-user: rgba(110,231,255,.18);
  --cb-bot: rgba(255,255,255,.08);

  --cb-shadow: 0 18px 50px rgba(0,0,0,.38);
  --cb-radius: 18px;
  --cb-font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
}

#cb-root{
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 999999;
  font-family: var(--cb-font);
}

/* =========================
   BOTTONE (NUVOLETTA/LOGO)
   ========================= */
#cb-toggle{
  width: 56px;
  height: 56px;
  border: 1px solid var(--cb-border);
  border-radius: 999px;
  background: var(--cb-panel);
  box-shadow: var(--cb-shadow);
  cursor: pointer;

  display: grid;
  place-items: center;

  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
#cb-toggle:hover{
  transform: translateY(-1px);
  background: rgba(15,22,32,.95);
}
#cb-toggle:active{
  transform: translateY(0px);
}
#cb-toggle img{
  width: 26px;
  height: 26px;
  object-fit: contain;
  display: block;
}

/* =========================
   PANNELLO (FIX LAYOUT: contiene chat + input + bottoni)
   ========================= */
#cb-panel{
  position: absolute;
  right: 0;
  bottom: 68px;

  width: 360px;
  max-width: calc(100vw - 36px);

  height: 560px;                       /* un po' più alto per Invio+Salva+Mic */
  max-height: calc(100vh - 120px);

  border: 1px solid var(--cb-border);
  border-radius: var(--cb-radius);

  background: var(--cb-panel);
  color: var(--cb-text);

  box-shadow: var(--cb-shadow);

  display: flex;                        /* ✅ chiave */
  flex-direction: column;               /* ✅ chiave */
  overflow: hidden;                     /* ok: lo scroll lo fa #cb-messages */
}
.cb-hidden{ display:none !important; }

/* =========================
   HEADER
   ========================= */
#cb-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;

  padding: 14px 14px;
  border-bottom: 1px solid var(--cb-border);

  background: linear-gradient(180deg, rgba(110,231,255,.10), transparent);
}

.cb-title{
  color: var(--cb-text);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .2px;
}

.cb-subtitle{
  color: var(--cb-muted);
  font-size: 12px;
  margin-top: 2px;
}

.cb-titlewrap{
  display:flex;
  flex-direction: column;
  line-height: 1.15;
}

#cb-close{
  border: 1px solid var(--cb-border);
  background: transparent;
  color: var(--cb-text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
}
#cb-close:hover{
  background: rgba(255,255,255,.06);
}

/* =========================
   MESSAGGI (scroll SOLO qui)
   ========================= */
#cb-messages{
  padding: 14px;
  flex: 1 1 auto;                      /* ✅ prende lo spazio disponibile */
  min-height: 0;                       /* ✅ fondamentale per scroll in flex */
  overflow-y: auto;

  background: var(--cb-panel);
  color: var(--cb-text);
}

/* scrollbar (facoltativo) */
#cb-messages::-webkit-scrollbar{ width: 10px; }
#cb-messages::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.12);
  border-radius: 10px;
}
#cb-messages::-webkit-scrollbar-track{
  background: rgba(255,255,255,.04);
}

.cb-msg{
  display:flex;
  margin: 10px 0;
}
.cb-user{ justify-content: flex-end; }
.cb-bot{ justify-content: flex-start; }

.cb-bubble{
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--cb-border);

  background: var(--cb-bot);
  color: var(--cb-text);

  white-space: pre-wrap;
  word-wrap: break-word;

  font-size: 14px;
  line-height: 1.35;
}
.cb-user .cb-bubble{
  background: var(--cb-user);
}

/* =========================
   FORM INPUT (nel flusso, non absolute)
   ========================= */
#cb-form{
  position: relative;                  /* ✅ prima era absolute */
  display:flex;
  flex-wrap: wrap;                     /* ✅ spazio per mic + layout stabile */
  gap: 10px;
  padding: 12px;

  border-top: 1px solid var(--cb-border);
  background: rgba(15,22,32,.96);
}

#cb-input{
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--cb-border);
  background: rgba(0,0,0,.18);
  color: var(--cb-text);

  padding: 10px 12px;
  border-radius: 12px;
  outline: none;
}
#cb-input::placeholder{
  color: rgba(232,238,246,.55);
}
#cb-input:focus{
  border-color: rgba(110,231,255,.45);
}

#cb-send{
  flex: 0 0 auto;
  border: 1px solid var(--cb-border);
  background: rgba(110,231,255,.18);
  color: var(--cb-text);

  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}
#cb-send:hover{
  background: rgba(110,231,255,.26);
}

/* =========================
   BOTTONE SALVA (creato dal JS con id=cb-save)
   ========================= */
#cb-save{
  display: block !important;
  width: calc(100% - 24px) !important; /* piena larghezza dentro pannello */
  margin: 0 12px 12px !important;
  background: #1e1e1e !important;
  color: #fff !important;
  border: none !important;
  border-radius: 12px !important;
  padding: 10px 12px !important;
  font-size: 14px !important;
  cursor: pointer !important;
}
#cb-save:hover{
  background: rgba(255,255,255,.10) !important;
}

/* =========================
   FUTURO: BOTTONE MICROFONO (se lo crei con id=cb-mic)
   ========================= */
#cb-mic{
  flex: 0 0 auto;
  border: 1px solid var(--cb-border);
  background: rgba(255,255,255,.06);
  color: var(--cb-text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
}
#cb-mic:hover{
  background: rgba(255,255,255,.10);
}

/* =========================
   MOBILE
   ========================= */
@media (max-width: 420px){
 #cb-panel {
  overflow-y: auto !important;
  overflow-x: hidden;
  padding-bottom: 60px; /* spazio extra per il bottone Salva */
}
/* === Fix visibilità bottone Salva === */
#cb-form {
  position: relative !important; /* era absolute, blocca il flusso */
  flex-direction: column;        /* impila input, invio e salva */
}

#cb-save {
  margin-top: 8px;
  width: 100%;
  background: #1e1e1e;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px;
  font-size: 14px;
  cursor: pointer;
  display: block;
}

