html {
  height: 100%;
  width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.bg-dark-bg {
  background-color: #1a1a1a;
}

.bg-sidebar-bg {
  background-color: #171717;
}

button {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
}

@media (hover: hover) and (pointer: fine) {
  button:hover {
    transform: translateY(-1px);
  }
}

button:active {
  transform: scale(0.95);
  transition: transform 0.1s ease;
}

input::placeholder {
  color: #9ca3af;
  opacity: 0.8;
}

textarea {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
  cursor: text;
}

#messageInput {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: text;
  user-select: text;
  pointer-events: auto;
  position: relative;
  z-index: 1;
  background: transparent;
}

#messageInput:focus {
  outline: none;
  pointer-events: auto;
}

input, textarea, button, a {
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
}

* {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.fixed.bottom-0 {
  z-index: 30;
  pointer-events: auto;
  transition: all 0.5s ease;
}

.fixed.bottom-0 > div {
  transition: all 0.5s ease;
}

.fixed.bottom-0 > div > div {
  pointer-events: auto;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
  background: #374151;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4b5563;
}

#sidebar {
  transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
              box-shadow 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: transform;
}

@media (min-width: 1024px) {
  #sidebar {
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
  }
  
  #sidebar.sidebar-closed {
    transform: translateX(-100%);
  }
  
  .content-shifted {
    margin-left: 320px;
  }
  
  .content-full {
    margin-left: 0;
  }
  
  /* Adaptar el contenedor del input cuando el sidebar está abierto */
  body.sidebar-open-desktop .fixed.bottom-0 {
    left: 320px;
    right: 0;
  }
  
  /* Cuando el sidebar está cerrado, el input ocupa todo el ancho */
  body.sidebar-closed-desktop .fixed.bottom-0 {
    left: 0;
    right: 0;
  }
}

#sidebar.sidebar-open {
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transform: translateX(0) scale(1.02);
}

@keyframes slideInLeft {
  0% {
    transform: translateX(-100%) scale(0.98);
    opacity: 0;
  }
  100% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

.sidebar-animation.translate-x-0 {
  animation: slideInLeft 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

#sidebarToggle span {
  transform-origin: center;
  transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55), 
              opacity 0.3s ease;
}

#sidebarOverlay {
  transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(4px);
  z-index: 40;
}

#sidebarOverlay.opacity-100 {
  opacity: 1;
}

#sidebarOverlay.opacity-0 {
  opacity: 0;
}

#sidebarOverlay.hidden {
  pointer-events: none;
}

#functionsMenu {
  z-index: 50;
  pointer-events: auto;
}

#functionsMenu.translate-y-full {
  pointer-events: none;
}

@media (max-width: 1023px) {
  #sidebar {
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  }
}

button:focus,
input:focus {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

@media (pointer: coarse) {
  button {
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
  }
  
  .touch-manipulation {
    touch-action: manipulation;
  }
}

* {
  -webkit-tap-highlight-color: transparent;
}

.text-red-500 {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

svg {
  transition: color 0.2s ease, filter 0.2s ease;
}

.w-6.h-6 svg {
  filter: drop-shadow(0 0 2px currentColor);
}

.bg-purple-btn {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bg-purple-btn:hover {
  background-color: #5b21b6;
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.sidebar-enter {
  animation: fadeInUp 0.3s ease forwards;
}

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

.text-gray-500 {
  opacity: 0.8;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  #sidebar,
  #sidebarToggle span,
  button,
  #sidebarOverlay {
    transition: none;
  }
  
  .sidebar-animation.translate-x-0 {
    animation: none;
  }
  
  .sidebar-enter {
    animation: none;
  }
}

.hover\:bg-gray-700:hover {
  background-color: #374151;
  transform: translateX(2px);
  transition: all 0.2s ease;
}

.message-user {
  text-align: right;
  padding: 8px 0;
  color: #ffffff;
  font-size: 15px;
  line-height: 1.6;
  margin-left: auto;
  margin-bottom: 12px;
}

.message-assistant {
  text-align: left;
  padding: 8px 0;
  color: #e5e7eb;
  font-size: 15px;
  line-height: 1.7;
  margin-right: auto;
  margin-bottom: 12px;
}

.message-assistant p {
  margin-bottom: 12px;
}

.message-assistant code {
  background-color: #2d2d2d;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 14px;
}

.message-assistant pre {
  background-color: #2d2d2d;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
}

.message-assistant pre code {
  background: none;
  padding: 0;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background-color: #2d2d2d;
  border-radius: 18px;
  margin-bottom: 12px;
  max-width: 80px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #6b7280;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-10px);
  }
}

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

.message-user,
.message-assistant {
  animation: slideIn 0.3s ease-out;
}

/* THINKING INDICATOR (LONG THINKING MODE) */
.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 12px;
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
  animation: fadeIn 0.3s ease-out;
}

.thinking-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(99, 102, 241, 0.3);
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.thinking-indicator span {
  color: #a5b4fc;
  font-size: 14px;
  font-weight: 500;
}

/* THINKING TIME LABEL */
.thinking-time {
  margin-top: 8px;
  font-size: 12px;
  color: #9ca3af;
  font-style: italic;
  opacity: 0.8;
}

/* IMAGE CONTAINER */
.image-container {
  margin: 12px 0;
  border-radius: 12px;
  overflow: hidden;
  max-width: 500px;
  animation: fadeIn 0.5s ease-out;
}

.generated-image {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border-radius: 8px;
}

.generated-image:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.image-caption {
  text-align: center;
  padding: 8px;
  background: rgba(45, 45, 45, 0.5);
  margin-top: 4px;
  border-radius: 0 0 8px 8px;
}

/* IMAGE MODAL */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-modal.active {
  opacity: 1;
}

.image-modal.closing {
  opacity: 0;
}

.image-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.image-modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 10000;
}

.image-modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 28px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.image-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(90deg);
}

.image-modal-img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s ease;
  cursor: zoom-in;
}

.image-modal-img:hover {
  cursor: zoom-in;
}

.image-modal-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.image-modal-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  background: rgba(99, 102, 241, 0.9);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.image-modal-btn:hover {
  background: rgba(99, 102, 241, 1);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.image-modal-btn svg {
  flex-shrink: 0;
}

/* IMAGE HINT */
.image-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 10px;
  margin-bottom: 12px;
  color: #a5b4fc;
  font-size: 13px;
  animation: slideIn 0.3s ease-out;
  transition: opacity 0.3s ease;
}

.image-hint svg {
  flex-shrink: 0;
  color: #818cf8;
}

/* RESPONSIVE ADJUSTMENTS */
@media (max-width: 768px) {
  .image-modal-content {
    max-width: 95vw;
  }
  
  .image-modal-img {
    max-height: 60vh;
  }
  
  .image-modal-close {
    top: -50px;
    width: 44px;
    height: 44px;
  }
  
  .image-modal-btn {
    padding: 10px 20px;
    font-size: 13px;
  }
  
  .image-container {
    max-width: 100%;
  }
}

/* FADE IN ANIMATION */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
