.sa-container {
  max-width: 600px;
  margin: 0 auto 48px;
  background: #000000;
  border: 1px solid var(--sep);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 550px;
  max-height: 75vh;
  position: relative;
}

[data-theme="light"] .sa-container {
  background: #ffffff;
}

.sa-ambient-glow {
  position: absolute;
  inset: -50%;
  background: radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.06), transparent 50%);
  z-index: 0;
  pointer-events: none;
  animation: saAmbientFloat 15s infinite alternate ease-in-out;
  will-change: transform;
}

@keyframes saAmbientFloat {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-5%, 5%) scale(1.1); }
  100% { transform: translate(5%, -5%) scale(0.9); }
}

.sa-header {
  padding: 16px 20px;
  background: transparent;
  border-bottom: 1px solid var(--sep);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 2;
}

/* Aura Effect */
.sa-aura {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 150px;
  z-index: 1;
  pointer-events: none;
  transform-origin: bottom center;
  transform: scale(1);
  transition: height 0.8s var(--ease), transform 0.8s var(--ease);
}

.sa-aura::before, .sa-aura::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  will-change: transform, opacity;
  transition: opacity 0.8s var(--ease);
}

/* Idle State */
.sa-aura::before {
  background: radial-gradient(ellipse at bottom, rgba(59, 130, 246, 0.35) 0%, rgba(59, 130, 246, 0) 75%);
  filter: blur(40px);
  opacity: 0.9;
  animation: saAuraIdle 6s infinite alternate ease-in-out;
}

/* Active State */
.sa-aura::after {
  background: radial-gradient(ellipse at bottom, rgba(59, 130, 246, 0.4) 0%, rgba(139, 92, 246, 0.2) 50%, rgba(59, 130, 246, 0) 80%);
  filter: blur(40px);
  opacity: 0;
  animation: saAuraActive 3s infinite alternate ease-in-out;
}

.sa-aura.is-active {
  height: 200px;
}

.sa-aura.is-idle-paused::before,
.sa-aura.is-idle-paused::after {
  animation: none !important;
  opacity: 0.1 !important; /* Keep a minimal static glow instead of heavy animation */
}

.sa-aura.is-active::before {
  opacity: 0;
}

.sa-aura.is-active::after {
  opacity: 1;
}

.sa-aura.is-pulsing {
  transform: scaleY(1.1) scaleX(1.03);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Light Mode Aura */
[data-theme="light"] .sa-aura::before {
  background: radial-gradient(ellipse at bottom, rgba(56, 189, 248, 0.25) 0%, rgba(59, 130, 246, 0.15) 40%, rgba(59, 130, 246, 0) 75%);
  opacity: 1;
}

[data-theme="light"] .sa-aura::after {
  background: radial-gradient(ellipse at bottom, rgba(56, 189, 248, 0.35) 0%, rgba(139, 92, 246, 0.15) 50%, rgba(59, 130, 246, 0) 80%);
}

[data-theme="light"] .sa-ambient-glow {
  background: radial-gradient(circle at 50% 50%, rgba(56, 189, 248, 0.08), transparent 50%);
}

@keyframes saAuraIdle {
  0% { transform: translateY(10%) scaleY(0.8) scaleX(1); opacity: 0.4; }
  100% { transform: translateY(0%) scaleY(1) scaleX(1.05); opacity: 0.6; }
}

@keyframes saAuraActive {
  0% { transform: translateY(5%) scaleY(0.9) scaleX(1); opacity: 0.8; }
  100% { transform: translateY(-5%) scaleY(1.1) scaleX(1.1); opacity: 1; }
}

.sa-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.sa-header.is-thinking .sa-avatar {
  animation: saAvatarBounce 1s infinite;
}

@keyframes saAvatarBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.sa-header-info {
  display: flex;
  flex-direction: column;
}

.sa-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
}

.sa-subtitle {
  font-size: 12px;
  color: var(--green);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sa-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  animation: saPulse 2s infinite;
}

@keyframes saPulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.sa-chat-area {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: transparent;
  position: relative;
  z-index: 1;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--sep) transparent;
}

.sa-chat-area::-webkit-scrollbar {
  width: 6px;
}

.sa-chat-area::-webkit-scrollbar-track {
  background: transparent;
}

.sa-chat-area::-webkit-scrollbar-thumb {
  background-color: var(--sep);
  border-radius: 10px;
}

.sa-msg-row {
  display: flex;
  width: 100%;
  animation: saMsgIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  transform-origin: bottom center;
}

@keyframes saMsgIn {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sa-msg-row.sa-bot {
  justify-content: flex-start;
  animation: saBotMsgIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transform-origin: left center;
}

@keyframes saBotMsgIn {
  0% { opacity: 0; transform: perspective(500px) rotateY(-10deg) translateY(16px) scale(0.95); }
  100% { opacity: 1; transform: perspective(500px) rotateY(0) translateY(0) scale(1); }
}

.sa-msg-row.sa-user {
  justify-content: flex-end;
}

.sa-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.sa-widget-bubble {
  width: 100%;
  padding: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.sa-bot .sa-bubble:not(.sa-widget-bubble) {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-bottom-left-radius: 4px;
}

.sa-user .sa-bubble {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--blue);
  border-bottom-right-radius: 4px;
}

.sa-options-area {
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--sep);
  position: relative;
  z-index: 2;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: 150px;
  overflow: hidden;
}

.sa-options-area.is-hidden-typing {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  border-top-color: transparent;
  pointer-events: none;
}

.sa-options-area.is-hidden-typing .sa-chips-wrapper {
  transform: translateY(20px);
  opacity: 0;
}

[data-theme="light"] .sa-options-area {
  background: rgba(255, 255, 255, 0.5);
}

.sa-chips-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  animation: saChipsIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: 0.1s;
  opacity: 0;
  transform: translateY(16px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes saChipsIn {
  to { opacity: 1; transform: translateY(0); }
}

.sa-chip {
  padding: 8px 14px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--sep);
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  font-family: inherit;
  text-align: left;
  animation: saChipStagger 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

[data-theme="light"] .sa-chip {
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

@keyframes saChipStagger {
  0% { opacity: 0; transform: translateY(16px); }
  100% { opacity: 1; transform: translateY(0); }
}

.sa-chip:hover {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.4);
  color: var(--text);
  transform: translateY(-1px);
}

.sa-chip:active {
  transform: translateY(0);
}

.sa-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 20px;
}

.sa-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text3);
  border-radius: 50%;
  animation: saTypingDot 1.4s infinite ease-in-out both;
}

.sa-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.sa-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes saTypingDot {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.sa-link {
  color: var(--blue);
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
  transition: text-shadow 0.2s ease;
}

.sa-link:hover {
  text-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

/* Autocomplete Area */
.sa-autocomplete-container {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 100%;
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;  /* IE and Edge */
}

.sa-autocomplete-container::-webkit-scrollbar {
  display: none;
}

.sa-autocomplete-container.is-active {
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0);
}

.sa-autocomplete-pill {
  flex: 0 0 auto;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--sep);
  border-radius: 16px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: scale(0.95);
  opacity: 0;
  animation: saPillIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

[data-theme="light"] .sa-autocomplete-pill {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

@keyframes saPillIn {
  to { transform: scale(1); opacity: 1; }
}

.sa-autocomplete-pill:hover {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.4);
  color: var(--text);
  transform: translateY(-2px);
}

.sa-autocomplete-pill:active {
  transform: translateY(0);
}

/* Input Area */
.sa-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--sep);
  position: relative;
  z-index: 2;
}

[data-theme="light"] .sa-input-area {
  background: rgba(255, 255, 255, 0.5);
}

.sa-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--sep);
  border-radius: 100px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s var(--ease);
}

.sa-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.sa-input::placeholder {
  color: var(--text3);
}

[data-theme="light"] .sa-input {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .sa-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.25);
}

.sa-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  color: var(--text3);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sa-send-btn:not(:disabled) {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.4);
}

.sa-send-btn:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.5);
}

.sa-send-btn:not(:disabled):active {
  transform: scale(0.95);
}

.sa-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Tally wrapper */
.tally-wrapper {
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.tally-wrapper.is-hidden {
  display: none;
}

/* Header Actions */
.sa-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sa-action-btn {
  background: transparent;
  border: none;
  color: var(--text2);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 8px;
}

.sa-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

[data-theme="light"] .sa-action-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sa-action-btn svg {
  width: 100%;
  height: 100%;
}

.sa-focus-btn {
  display: flex;
}

/* Timestamp */
.sa-timestamp {
  font-size: 11px;
  color: var(--text2);
  margin-top: 4px;
  opacity: 0.8;
}

.sa-user-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 85%;
}

.sa-bot-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 85%;
}

.sa-bot-wrap.is-widget {
  max-width: 100%;
}

/* Focus Mode Active State (Global) */
body.sa-focus-active {
  overflow: hidden !important;
}

.sa-desktop-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 99998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.sa-desktop-backdrop.is-active {
  opacity: 1;
  pointer-events: auto;
}

[data-theme="light"] .sa-desktop-backdrop {
  background: rgba(255, 255, 255, 0.6);
}

body.sa-focus-active .sa-hide-on-focus,
body.sa-focus-active .nav,
body.sa-focus-active .footer,
body.sa-focus-active .scroll-top,
body.sa-focus-active .theme-toggle,
body.sa-focus-active .nav-overlay {
  display: none !important;
}

.sa-container.is-focused {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90vw;
  height: 85vh;
  max-width: 1100px;
  max-height: 900px;
  margin: 0;
  z-index: 99999;
  box-sizing: border-box;
  will-change: transform, opacity;
  animation: saFocusInDesktop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}

[data-theme="light"] .sa-container.is-focused {
  box-shadow: 0 24px 48px rgba(0,0,0,0.1);
}

.sa-container.is-focused * {
  box-sizing: border-box;
}

.sa-container.is-focused .sa-chat-area {
  overscroll-behavior: contain;
}

@keyframes saFocusInDesktop {
  0% { opacity: 0; transform: translate(-50%, -45%) scale(0.95); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

  /* Mobile Optimizations */
@media (max-width: 899px) {
  .sa-container {
    min-height: 480px; /* Più spazio verticale per touch */
  }
  .sa-header {
    padding: 14px 16px;
  }
  .sa-chat-area {
    padding: 16px;
    gap: 12px;
  }
  .sa-bubble {
    padding: 10px 14px;
    font-size: 13.5px;
  }
  .sa-user-wrap, .sa-bot-wrap {
    max-width: 90%;
  }
  .sa-options-area {
    padding: 14px 16px;
  }
  .sa-input-area {
    padding: 10px 16px;
  }
  .sa-chip {
    padding: 8px 12px;
    font-size: 12px;
  }

  /* Focus Mode Active State for Body (Mobile override) */
  body.sa-focus-active {
    position: fixed;
    width: 100%;
    height: 100%;
  }

  body.sa-focus-active .bg-glow,
  body.sa-focus-active .bg-noise,
  body.sa-focus-active .bg-grid,
  body.sa-focus-active .bg-vignette {
    display: none !important;
  }

  .sa-desktop-backdrop {
    display: none !important;
  }

  /* Focus Mode Active State (Mobile override) */
  .sa-container.is-focused {
    top: 0;
    left: 0;
    transform: none;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: none;
    animation: saFocusInMobile 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }

  /* Safe area insets per evitare notch e navigation bar */
  .sa-container.is-focused .sa-header {
    padding: max(14px, env(safe-area-inset-top, 0px)) 16px 14px 16px;
  }
  
  .sa-container.is-focused .sa-input-area {
    padding: 10px 16px max(10px, env(safe-area-inset-bottom, 0px)) 16px;
  }

  @keyframes saFocusInMobile {
    0% { opacity: 0; transform: translateY(20px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
  }
}

/* Optimized Landscape Mode (e.g., iPad or short desktops) */
@media (min-width: 900px) and (max-height: 850px) {
  .sa-container.is-focused {
    top: 10px;
    bottom: 10px;
    height: auto;
    max-height: none;
    transform: translateX(-50%);
    animation: saFocusInLandscape 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }
  @keyframes saFocusInLandscape {
    0% { opacity: 0; transform: translate(-50%, 20px) scale(0.95); }
    100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  }
}

/* Accessibilità / Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .sa-msg-row, .sa-msg-row.sa-bot, .sa-chips-wrapper, .sa-chip {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .sa-status-dot, .sa-typing-dot, .sa-header.is-thinking .sa-avatar, .sa-ambient-glow {
    animation: none !important;
  }
  .sa-chat-area {
    scroll-behavior: auto;
  }
  .sa-aura {
    animation: none !important;
    transition: opacity 0.3s ease !important;
    transform: none !important;
    height: 30%;
    opacity: 0.2;
  }
  .sa-aura.is-active {
    opacity: 0.5;
  }
}

/* PWA Standalone Mode Optimizations */
@media (display-mode: standalone) {
  /* Leverage safe areas when running as a native app without browser chrome */
  .sa-container {
    margin-bottom: max(24px, env(safe-area-inset-bottom));
  }
  
  @media (max-width: 600px) {
    .sa-container {
      margin-bottom: 0;
      border-radius: 0;
      border: none;
      height: 100vh;
      max-height: none;
    }
    
    .sa-header {
      padding-top: max(14px, env(safe-area-inset-top));
    }
    
    .sa-input-area {
      padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
  }
}

