* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary-color: #8a2be2;
  --primary-dark: #7a1bd2;
  --primary-gradient: linear-gradient(135deg, #b700ff, #8100b4);
  --bg-dark: #000000;
  --bg-darker: #111111;
  --bg-input: #1a1a1a;
  --text-light: #eeeeee;
  --text-muted: #cccccc;
  --border-radius: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow: 0 4px 20px rgba(138, 43, 226, 0.15);
}

body {
  margin: 0;
  background-color: var(--bg-dark);
  color: var(--text-light);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Navbar migliorata */
.navbar {
  height: 70px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: var(--bg-dark);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
}

.navbar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 2rem;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo img {
  width: 60px;
  height: 60px;
  transition: var(--transition);
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--text-light);
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-toggle:hover {
  background: rgba(138, 43, 226, 0.1);
  transform: scale(1.05);
}

/* Sidebar migliorata */
.sidebar {
  position: fixed;
  top: 0;
  right: -100%;
  width: 100%;
  max-width: 400px;
  height: 100%;
  background-color: var(--bg-dark);
  color: var(--text-light);
  padding: 2rem;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(138, 43, 226, 0.1);
}

.sidebar.show {
  right: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 1.5rem;
}

.sidebar-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

.close-button {
  background: transparent;
  border: none;
  color: var(--text-light);
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.close-button:hover {
  background: rgba(138, 43, 226, 0.1);
  transform: scale(1.05);
}

.session-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.select-wrapper {
  position: relative;
  width: 100%;
}

.session-select {
  width: 100%;
  padding: 1rem 1.5rem;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-light);
  font-size: 1rem;
  appearance: none;
  cursor: pointer;
  transition: var(--transition);
}

.session-select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(138, 43, 226, 0.2);
}

.select-arrow {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-light);
  pointer-events: none;
}

.session-actions {
  display: flex;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(138, 43, 226, 0.1);
  border-color: var(--primary-color);
}

.btn-outline {
  background: transparent;
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--primary-color);
}

.btn-full {
  width: 100%;
  justify-content: center;
}

.btn-icon {
  padding: 0.75rem;
}

.session-info {
  padding: 1rem;
  background: var(--bg-input);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.info-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0;
}

/* Main content e chat */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 70px;
  min-height: calc(100vh - 70px);
}

.chat-container {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.chat-box {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1rem 0;
  margin-bottom: 120px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar {
  width: 6px;
}

.chat-box::-webkit-scrollbar-track {
  background: transparent;
}

.chat-box::-webkit-scrollbar-thumb {
  background-color: var(--primary-color);
  border-radius: 3px;
}

/* Messaggi chat */
.message {
  max-width: 80%;
  padding: 1rem 1.20rem;
  border-radius: var(--border-radius);
  line-height: 1.2;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  animation: messageAppear 0.3s ease-out;
  font-size: 1rem;
}

@keyframes messageAppear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-user {
  background: var(--primary-gradient);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow);
}

.message-bot {
  background-color: #000000;
  color: var(--text-light);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

/* Welcome state */
.welcome-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.welcome-content {
  max-width: 600px;
  padding: 2rem;
}

.welcome-icon {
  margin-bottom: 1.5rem;
  color: var(--primary-color);
  opacity: 0.8;
}

.welcome-title {
  font-size: 2.5rem;
  font-weight: 700;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1rem;
}

.welcome-description {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-bottom: 2.5rem;
  line-height: 1.6;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.suggestion-chip {
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  color: var(--text-light);
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.suggestion-chip:hover {
  background: rgba(138, 43, 226, 0.1);
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

/* Input area migliorata */
.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--bg-primary);
  
  z-index: 1000;
  padding: 1rem;
}

.input-container {
  max-width: 800px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: center;
  background-color: var(--bg-input);
  border-radius: 30px;
  padding: 0.4rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: var(--transition);
  gap: 0.5rem;
}

.input-wrapper:focus-within {
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05);
  outline: none; /* Rimuove outline viola */
}

.btn-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-muted);
  flex-shrink: 0;
}

.btn-upload:hover {
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.05);
  transform: scale(1.05);
}

.input-field-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.input-field {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: none;
  background: transparent;
  color: var(--text-light);
  outline: none; /* Rimuove outline viola */
  resize: none;
  min-height: 24px;
  max-height: 120px;
  line-height: 1.5;
}

.input-field:focus {
  outline: none; /* Rimuove outline viola al focus */
  box-shadow: none; /* Rimuove eventuali box-shadow viola */
}

.input-field::placeholder {
  color: var(--text-muted);
}

.input-actions {
  display: flex;
  align-items: center;
}

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-gradient);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: var(--transition);
  color: white;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(138, 43, 226, 0.3);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.input-footer {
  margin-top: 0.75rem;
  text-align: center;
}

.disclaimer {
  font-size: 0.5rem;
  color: var(--text-muted);
  margin: 0;
}

/* FIX iOS: Miglioramenti per Safari */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 8px;
  padding: 8px 12px;
  background-color: white;
  background-image: url("data:image/svg+xml;charset=US-ASCII,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'><path fill='%23666' d='M2 0L0 2h4zm0 5L0 3h4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 8px 10px;
  outline: none; /* Rimuove outline viola */
}

select:focus {
  outline: none; /* Rimuove outline viola al focus */
  box-shadow: none; /* Rimuove eventuali box-shadow viola */
}

/* FIX iOS: Previene zoom su focus */
input, select, textarea {
  font-size: 16px; /* Previene zoom automatico iOS */
}

/* FIX iOS: Migliora touch targets */
.suggestion-chip, button, select {
  min-height: 44px; /* Dimensione minima touch Apple */
  cursor: pointer;
}

/* FIX iOS: Scroll migliorato */
#chat-box {
  -webkit-overflow-scrolling: touch;
  overflow-scrolling: touch;
}

/* FIX iOS: Previene highlight blu */
* {
  -webkit-tap-highlight-color: transparent;
}

/* FIX iOS: Migliora performance animazioni */
.message {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Rimuove tutti i contorni viola indesiderati */
input:focus, 
textarea:focus, 
select:focus, 
button:focus {
  outline: none !important;
  box-shadow: none !important;
}

/* Specifico per input field per sicurezza */
#user-input:focus,
#prompt-input:focus,
#session-modal-input:focus {
  outline: none !important;
  box-shadow: none !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
}

/* Modal migliorato */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal.show {
  opacity: 1;
  visibility: visible;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.modal-container {
  position: relative;
  width: 90%;
  max-width: 400px;
}

.modal-content {
  background: var(--bg-darker);
  padding: 2rem;
  border-radius: var(--border-radius);
  color: var(--text-light);
  transform: translateY(20px);
  transition: var(--transition);
  border: 1px solid rgba(138, 43, 226, 0.2);
  box-shadow: var(--shadow);
}

.modal.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  margin-bottom: 1.5rem;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  margin: 0;
}

.modal-body {
  margin-bottom: 1.5rem;
}

.modal-input {
  width: 100%;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--text-light);
  font-size: 1rem;
  transition: var(--transition);
}

.modal-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(138, 43, 226, 0.2);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Prompt container */
.prompt-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 500px;
  z-index: 10001;
  display: none;
}

.prompt-container.show {
  display: block;
  animation: messageAppear 0.3s ease-out;
}

.prompt-content {
  background: var(--bg-darker);
  border-radius: var(--border-radius);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.prompt-header {
  padding: 1.5rem 1.5rem 0;
}

.prompt-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 1rem 0;
}

.prompt-body {
  padding: 0 1.5rem;
}

.prompt-label {
  display: block;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.prompt-input {
  width: 100%;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--text-light);
  font-size: 1rem;
  transition: var(--transition);
}

.prompt-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(138, 43, 226, 0.2);
}

.prompt-footer {
  padding: 1.5rem;
}

/* Typing animation */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.typing-dots span {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-color);
  animation: bounceWave 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes bounceWave {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10002;
}

.loading-spinner {
  text-align: center;
  color: var(--text-light);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(138, 43, 226, 0.3);
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  font-size: 1rem;
  color: var(--text-muted);
}

/* Media queries */
@media (max-width: 768px) {
  .navbar-container {
    padding: 0 1rem;
  }
  
  .brand-name {
    display: none;
  }
  
  .sidebar {
    max-width: 100%;
    padding: 1.5rem;
  }
  
  .chat-box {
    margin-bottom: 140px;
    padding: 0.5rem 0;
  }
  
  .message {
    max-width: 90%;
    padding: 1rem 1.25rem;
  }
  
  .welcome-title {
    font-size: 2rem;
  }
  
  .welcome-description {
    font-size: 1.1rem;
  }
  
  .suggestions-grid {
    grid-template-columns: 1fr;
  }
  
  .input-wrapper {
    border-radius: 20px;
    padding: 0.375rem;
  }
  
  .input-field {
    padding: 0.625rem 0.875rem;
    font-size: 0.95rem;
  }
  
  .btn-send,
  .btn-upload {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 480px) {
  .main-content {
    margin-top: 60px;
  }
  
  .chat-container {
    padding: 0.5rem;
  }
  
  .chat-box {
    margin-bottom: 160px;
  }
  
  .message {
    max-width: 95%;
    padding: 0.875rem 1rem;
    font-size: 0.95rem;
  }
  
  .input-area {
    padding: 0.75rem;
  }
  
  .session-actions {
    flex-direction: column;
  }
  
  .modal-content {
    padding: 1.5rem;
  }
  
  .modal-footer {
    flex-direction: column;
  }
}

/* Focus visible per accessibilità */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Transizioni smooth */
button, input, textarea, select {
  transition: var(--transition);
}