/* #region Variables */
:root {
  --primary-color: #007bff;
  --primary-light: #cfe2ff;
  --primary-dark: #0056b3;
  --primary-hover-color: #0056b3;
  --secondary-color: #6c757d;
  --light-bg-color: #f8f9fa;
  --border-color: #dee2e6;
  --input-bg-color: #f0f0f0;
  --sent-message-bg: #d1ecf1;
  --received-message-bg: #e9ecef;
  --active-chat-bg: #e6f2ff;
  --font-size-small: 0.875rem;
  --font-size-normal: 1rem;
  --border-radius: 8px;
  --box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --gradient-start: #667eea;
  --gradient-end: #6b1fba;
  --warning-bg-color: #ffc107; /* Giallo più vivace */
  --warning-text-color: #000000; /* Testo nero per massimo contrasto */
  --warning-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
/* #endregion */

/* #region Global Styles */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
/* #endregion */

/* #region Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.navbar {
  box-shadow: var(--box-shadow);
}
/* #endregion */

/* #region Chat List */
#chat-list {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
}

.chat-list-content {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  cursor: pointer;
  transition: background-color 0.3s ease;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.chat-item:hover {
  background-color: var(--light-bg-color);
}

.chat-item.active {
  background-color: var(--active-chat-bg);
}

.chat-item .btn {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.chat-item:hover .btn {
  opacity: 1;
}

/* #endregion */

/* #region WaveSurfer */
.audio-wrapper {
  display: flex;
  align-items: center;
  width: 100%;
}

.audio-duration {
  font-size: 0.8em;
  color: #6c757d;
  min-width: 40px;
  text-align: right;
  margin-right: 10px;
}

.waveform {
  flex-grow: 1;
  min-width: 0;
}

.play-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border-radius: 0.2rem;
  margin-left: 10px;
}
/* #endregion */

/* #region Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  padding-bottom: 80px !important;
}

.message {
  max-width: 70%;
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
  position: relative;
}

.message-sent {
  background-color: var(--sent-message-bg);
  margin-left: auto;
}

.message-received {
  background-color: var(--received-message-bg);
}

.message::after {
  content: "";
  position: absolute;
  bottom: -10px;
  width: 0;
  height: 0;
  border: 10px solid transparent;
}

.message-sent::after {
  right: 10px;
  border-top-color: var(--sent-message-bg);
}

.message-received::after {
  left: 10px;
  border-top-color: var(--received-message-bg);
}
/* #endregion */

/* #region Input Area */

.input-group {
  align-items: flex-end;
}

.input-area {
  padding: 1rem;
}

.textarea-container {
  flex-grow: 1;
  position: relative;
}

#message-input {
  resize: none;
  overflow-y: hidden;
  padding-right: 45px;
  min-height: 38px;
}

#send-message-btn {
  position: absolute;
  bottom: 5px;
  right: 5px;
  padding: 0.25rem 0.5rem;
}

#pulsing-dots-loader {
  position: relative;
  top: -15px;
  left: 0;
  right: 0;
  height: 10px;
  display: block;
}

.input-note {
  font-size: 0.8rem;
  color: var(--secondary-color);
  text-align: right;
  margin-top: 0.5rem;
  padding-right: 4rem; /* Allinea con il margine destro dell'input */
}

.input-note span {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Versione mobile */
@media (max-width: 768px) {
  .input-note {
    text-align: center;
    padding-right: 0 !important;
  }
}
/* #endregion */

/* #region Area registrazione audio */

#record-audio-btn {
  height: 38px;
  width: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #6c5ce7;
  border-color: #6c5ce7;
}
#record-audio-btn:hover {
  background-color: #5b4cdb;
  border-color: #5b4cdb;
}

#record-audio-btn.recording {
  background-color: #e74c3c; /* Un rosso per indicare la registrazione attiva */
  border-color: #e74c3c;
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
  transform: translateY(1px); /* Effetto "premuto" */
}

/* Disabilita la selezione del testo durante la registrazione */
#record-audio-btn.recording,
#record-audio-btn.recording * {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.recording-warning {
  position: fixed;
  background-color: var(--warning-bg-color);
  color: var(--warning-text-color);
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  font-size: 0.75rem;
  font-weight: bold;
  box-shadow: var(--warning-shadow);
  z-index: 1010;
  text-align: center;
  animation: fadeIn 0.3s ease-out;
  border: 1px solid #d39e00;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 768px) {
  .recording-warning {
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
  }
}

@keyframes recordingBackground {
  0% {
    background-color: rgba(207, 226, 255, 0.6); /* Versione più chiara e trasparente di --primary-light */
  }
  50% {
    background-color: rgba(0, 123, 255, 0.2); /* Versione molto trasparente di --primary-color */
  }
  100% {
    background-color: rgba(207, 226, 255, 0.6);
  }
}

#message-input.recording-animation {
  animation: recordingBackground 2s ease-in-out infinite;
}

#message-input::placeholder {
  transition: color 0.3s ease;
}

#message-input.recording-animation::placeholder {
  color: #0056b3; /* Un blu scuro per il placeholder durante la registrazione */
}

/* Assicurati che il testo dell'input rimanga nero */
#message-input.recording-animation {
  color: black;
}

.recording-animation #message-input::placeholder {
  color: var(--primary-dark);
}

/* Assicurati che il testo dell'input rimanga leggibile durante l'animazione */
.recording-animation #message-input {
  color: var(--primary-dark);
  background-color: transparent;
}

/* #endregion */

/* #region Animations and Transitions */
.chat-item,
.message {
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.btn,
.form-control {
  transition: all 0.3s ease;
}

.btn:hover,
.form-control:focus {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
/* #endregion */

/* #region Header Styles */
.navbar-brand {
  display: flex;
  align-items: center;
}

.bg-light {
  background-color: var(--primary-light);
  border-radius: 0.25rem;
  padding: 0.5rem 1rem;
}

.bi-person-circle {
  font-size: 1.2rem;
  color: var(--primary-color);
}

.bi-lightning-charge {
  font-size: 1.2rem;
  color: var(--primary-color);
}

.token-count {
  font-size: 1rem;
  color: var(--primary-color);
}

/* Gestione del wrapping del testo nei dettagli aziendali */
.bg-light span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px; /* Regola secondo necessità */
  display: inline-block;
}

/* Regolazioni responsive */
@media (max-width: 1200px) {
  .bg-light {
    flex-direction: column;
    align-items: center;
  }

  .bg-light span {
    margin-bottom: 0.5rem;
  }

  .bg-light span:last-child {
    margin-bottom: 0;
  }
}
/* #endregion */

/* #region Login Styles */
.login-background {
  background: linear-gradient(135deg, var(--gradient-start) 0%, var(--gradient-end) 100%);
  background-size: 400% 400%;
  animation: gradient 15s ease infinite;
}

@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.login-card {
  backdrop-filter: blur(10px);
  background-color: rgba(255, 255, 255, 0.8);
  border: none;
  -webkit-backdrop-filter: blur(10px);
}

.login-btn {
  background-color: var(--gradient-start);
  border-color: var(--gradient-start);
  transition: all 0.3s ease;
}

.login-btn:hover {
  background-color: var(--gradient-end);
  border-color: var(--gradient-end);
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.login-input:focus {
  border-color: var(--gradient-start);
  box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}
/* #endregion */

/* #region Responsive Styles */
@media (max-width: 768px) {
  /* Layout */
  .main-content {
    flex-direction: column;
  }

  .mobile-header {
    background-color: var(--light-bg-color);
    border-radius: 0.25rem;
    padding: 0.5rem 1rem;
  }

  .logout-mobile {
    margin-right: 0.5rem;
  }

  #chat-list {
    position: fixed;
    left: -300px;
    top: 0;
    bottom: 0;
    width: 300px;
    z-index: 1000;
    transition: left 0.3s ease;
    background-color: rgba(255, 255, 255, 0.95); /* Semi-transparent background */
    backdrop-filter: blur(5px); /* Blur effect for browsers that support it */
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    -webkit-backdrop-filter: blur(5px);
  }

  #chat-list.open {
    left: 0;
  }

  .chat-area {
    width: 100%;
  }

  /* Header */
  .navbar .container-fluid {
    flex-wrap: nowrap;
  }

  .navbar-brand {
    font-size: 1rem;
  }

  .bg-light {
    display: none; /* Hide company info on mobile */
  }

  /* NUOVO: Stili per le icone con etichette */
  .col.d-md-none .text-center {
    font-size: 0.8rem;
  }

  .col.d-md-none .bi {
    font-size: 1.2rem;
    margin-bottom: 0.2rem;
  }

  /* MODIFICATO: Layout della chat area */
  .chat-area {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px); /* Altezza totale meno l'altezza dell'header */
  }

  /* MODIFICATO: Gestione dello scrolling dei messaggi */
  #chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Per uno scrolling fluido su iOS */
    padding: 1rem !important;
    padding-bottom: 100px !important;
  }

  /* Chat messages */
  .message {
    max-width: 85%;
  }

  /* MODIFICATO: Input area */
  .input-area {
    flex-shrink: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 0.5rem;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
    z-index: 10;
  }

  #message-input {
    font-size: 16px; /* Prevent zoom on input focus on iOS */
  }

  /* Buttons */
  .btn {
    padding: 0.5rem 1rem;
    font-size: 1rem;
  }

  /* MODIFICATO: Rimozione del padding-bottom dalla main-content */
  .main-content {
    padding-bottom: 0;
  }

  /* Aggiungiamo una regola per creare spazio sotto l'ultimo messaggio */
  #chat-messages::after {
    content: "";
    display: block;
    height: 80px; /* Regola questo valore se necessario */
  }

  .container-fluid > .row {
    flex-wrap: wrap;
  }
  .mobile-title {
    font-size: 0.8rem;
  }
}

/* Additional responsive adjustments */
@media (max-width: 576px) {
  .message {
    max-width: 90%;
  }

  .navbar-brand img {
    height: 25px;
  }
}

@media (max-width: 768px) {
  .app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 80px; /* Spazio per l'area di input */
  }

  .input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  }

  /* Previene lo zoom su input su iOS */
  input[type="text"],
  textarea {
    font-size: 16px;
  }

  /* Assicura che il contenuto non sia nascosto sotto la tastiera virtuale */
  body.keyboard-open .input-area {
    position: absolute;
  }
}
/* #endregion */

@media (max-width: 768px) {
  #header_desktop_only .dropdown {
    display: none;
  }
}

@media (min-width: 769px) {
  #header_mobile_only .logout-mobile {
    display: none;
  }
}

.dropdown-toggle[style="cursor: pointer;"] {
  color: inherit;
  text-decoration: none;
}

.dropdown-menu .dropdown-item {
  transition: background-color 0.3s ease, color 0.3s ease;
}

.dropdown-menu .dropdown-item:hover {
  background-color: rgba(0, 123, 255, 0.1); /* Colore di sfondo moderno */
  color: #0056b3; /* Colore del testo per il focus */
}

/* #region CONSOLE AMMINISTRATIVA */

/* Sidebar */
#admin-sidebar .nav-link.active {
  background-color: #e9ecef;
  color: #0d6efd !important;
  font-weight: 500;
  border-radius: 0.25rem;
}

.bg-light {
  background-color: #f8f9fa !important;
  height: 100%;
}

.nav-link {
  padding: 0.75rem;
  border-radius: 8px;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.nav-link:hover {
  background-color: rgba(0, 123, 255, 0.1);
  color: #0056b3;
}

.nav-link i {
  font-size: 1.2rem;
}

/* Contenuto principale */
.container h4 {
  color: #333;
}

.container p {
  color: #666;
  line-height: 1.6;
}
.chart-container {
  max-height: 300px !important;
  height: 300px !important;
}

.card .card-body {
  padding: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
  .bg-light {
    height: auto;
  }
}

/* Admin styles */
.content-area {
  flex: 1;
  overflow-y: auto;
}

#admin-sidebar {
  width: 250px;
  min-height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
}

/* #endregion */

/* #region admin/analytics */
/* Analytics specific styles */
.border-left-primary {
  border-left: 4px solid #4e73df;
}

.border-left-success {
  border-left: 4px solid #1cc88a;
}

.border-left-info {
  border-left: 4px solid #36b9cc;
}

.border-left-warning {
  border-left: 4px solid #f6c23e;
}

.text-xs {
  font-size: 0.7rem;
}

.chart-area,
.chart-pie {
  position: relative;
  margin: auto;
  height: 300px;
}
/* #endregion */

/* #region admin/knowledge_base */

/* #endregion */
