/* =========================================================================
   RESET GENERALE
   ========================================================================= */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

/* =========================================================================
   SIDEBAR BASE
   ========================================================================= */
#chatSidebar {
  position: fixed;
  top: 0;
  left: auto;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 660px;
  height: 100dvh; /* usa 100dvh al posto di vh */
  transform: translateX(100%);
  transition: transform 0.3s ease-in-out;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at center, #0c0c0c 0%, #060606 100%);
  color: #0ff;
  font-family: 'Poppins', 'Segoe UI', sans-serif;
  box-shadow: -10px 0 40px rgba(0, 255, 255, 0.5),
              inset 0 0 30px rgba(0, 255, 255, 0.1);
  border-left: 2px solid #0ff;
  backdrop-filter: blur(8px);
  z-index: 9999;
  box-sizing: border-box;
  overflow-x: hidden;
}

#chatSidebar.open {
  transform: translateX(0);
}

/* =========================================================================
   ANIMAZIONI DI SFONDO
   ========================================================================= */
#chatSidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    rgba(0, 255, 255, 0.03) 0,
    rgba(0, 255, 255, 0.03) 1px,
    transparent 1px,
    transparent 5px
  );
  pointer-events: none;
  animation: bgMove 15s linear infinite;
  z-index: 0;
}

@keyframes bgMove {
  to {
    background-position: 100px 100px;
  }
}

@keyframes neonPulse {
  50% {
    box-shadow: -10px 0 40px rgba(0, 255, 255, 0.5),
                inset 0 0 30px rgba(0, 255, 255, 0.1);
  }
}

/* =========================================================================
   HEADER
   ========================================================================= */
#chatSidebar header {
  position: relative;
  flex-shrink: 0;
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to right, #00ffff, #0077ff);
  color: #000;
  box-shadow: 0 0 25px rgba(0, 255, 255, 0.5);
  z-index: 1;
}

#chatSidebar header h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  word-break: break-word;
}

#chatSidebar header button {
  background: none;
  border: none;
  color: #000;
  font-size: 26px;
  cursor: pointer;
  transition: transform 0.2s;
}

#chatSidebar header button:hover {
  transform: scale(1.2);
}

/* =========================================================================
   AREA MESSAGGI
   ========================================================================= */
#chatMessages {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px;
  background: radial-gradient(ellipse at center, #0c0c0c 0%, #060606 100%);
  scroll-behavior: smooth;
  flex: 1;
}

#chatMessages::-webkit-scrollbar {
  width: 6px;
}

#chatMessages::-webkit-scrollbar-thumb {
  background: #0ff;
  border-radius: 10px;
}

/* =========================================================================
   BUBBLE MESSAGGI
   ========================================================================= */
.chat-message {
  display: block;
  max-width: 100%;
  padding: 12px 16px;
  margin-bottom: 14px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 0 12px rgba(0, 255, 255, 0.2);
  animation: fadeInUp 0.4s ease forwards;
}

.chat-message.user {
  background: linear-gradient(145deg, #00ffff, #0099bb);
  color: #000;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  box-shadow: 0 0 16px #0ff, inset 0 0 5px rgba(0, 0, 0, 0.3);
}

.chat-message.ai {
  background: #101010;
  color: #0ff;
  align-self: flex-start;
  border: 1px solid #0ff;
  border-bottom-left-radius: 6px;
  box-shadow: 0 0 18px #0ff, inset 0 0 8px rgba(0, 255, 255, 0.15);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* =========================================================================
   LOADER
   ========================================================================= */
.loader {
  display: flex;
  gap: 6px;
  margin: 14px 0;
  padding-left: 4px;
}

.loader span {
  width: 10px;
  height: 10px;
  background: #0ff;
  border-radius: 50%;
  animation: blink 1.2s infinite ease-in-out, pulseLoader 1.5s infinite;
}

@keyframes pulseLoader {
  50% {
    box-shadow: 0 0 10px #0ff;
  }
}

/* =========================================================================
   FORM DI INVIO
   ========================================================================= */
#chatForm {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: #000;
  border-top: 1px solid #0ff;
  box-shadow: 0 -2px 10px rgba(0, 255, 255, 0.2);
}

#chatInput {
  flex: 1;
  padding: 12px 16px;
  background: #111;
  border: 1px solid #0ff;
  border-radius: 25px;
  color: #0ff;
  font-size: 15px;
  outline: none;
  transition: border 0.3s, box-shadow 0.3s;
  animation: pulseGlow 2.5s infinite ease-in-out;
}

#chatInput:focus {
  border-color: #44ffff;
  box-shadow: 0 0 12px #44ffff, inset 0 0 4px #000;
}

#chatInput::placeholder {
  color: #44ffff;
  opacity: 0.6;
}

#chatForm button {
  margin-left: 12px;
  padding: 12px 22px;
  background: #0ff;
  border: none;
  border-radius: 25px;
  color: #000;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.25s ease-in-out;
  box-shadow: 0 0 16px #0ff, inset 0 0 6px #000;
}

#chatForm button:hover {
  background: #44ffff;
  box-shadow: 0 0 20px #44ffff, inset 0 0 12px #000;
  transform: scale(1.08);
}

/* Default: mostra solo testo */
#chatForm button .btn-icon {
  display: none;
}

#chatForm button .btn-text {
  display: inline;
}

/* =========================================================================
   MEDIA QUERY: MOBILE (≤768px)
   ========================================================================= */
@media (max-width: 768px) {

  #chatSidebar {
    height: 100dvh;
    width: 100%;
    left: 0;
    right: 0;
    overflow: hidden;
  }

  #chatSidebar header {
    padding: 12px 16px;
  }

  #chatSidebar header h2 {
    font-size: 18px;
  }

  #chatSidebar header button {
    font-size: 24px;
  }

  #chatMessages {
    padding: 12px 16px;
  }

  .chat-message {
    padding: 10px 14px;
    margin-bottom: 12px;
  }
 #chatForm {
    position: sticky;
    bottom: 0;
    z-index: 999;
  }

  #chatForm button {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0a0a;
    border: 1px solid #00ffff;
    box-shadow: 0 0 8px #00ffffaa;
  }

  #chatForm button .btn-text {
    display: none;
  }

  #chatForm button .btn-icon {
    display: inline;
    font-size: 22px;
    line-height: 1;
  }

  .btn-send {
    background: radial-gradient(circle, #00ffff40, #001e2f);
    border-radius: 50%;
    padding: 8px;
    border: 1px solid #00ffff70;
    box-shadow: 0 0 8px #00ffff80;
  }

  .icon-send {
    width: 30px;
    height: 30px;
    filter: drop-shadow(0 0 3px #00ffff) brightness(2);
  }

}
