/* Animaciones */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fade-in {
  animation: fade-in 0.3s ease-out;
}

/* Scrollbar personalizado */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

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

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Mensajes del chat */
.message {
  transition: all 0.2s ease;
}

.message:hover {
  transform: translateX(2px);
}

/* Panel lateral */
#panel-container {
  transition: width 0.1s ease, transform 0.3s ease;
}

#panel-container.hidden {
  transform: translateX(100%);
}

/* Resize handle - visible en desktop (>768px) */
@media (min-width: 769px) {
  #panel-resize-handle {
    display: flex !important;
  }
}

#panel-resize-handle {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#panel-resize-handle:hover,
#panel-resize-handle.active {
  background-color: rgba(59, 130, 246, 0.3) !important;
}

#panel-resize-handle.active {
  background-color: rgba(59, 130, 246, 0.5) !important;
}

/* Mientras se redimensiona, desactivar transiciones */
#panel-container.resizing {
  transition: none !important;
}

/* Responsive - Mobile */
@media (max-width: 768px) {
  /* Fixed input container on mobile */
  #input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  /* Messages container with proper height */
  #messages-container {
    height: calc(100vh - 60px - 80px); /* viewport - header - input */
    max-height: calc(100vh - 60px - 80px);
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1rem;
  }

  /* Chat container constraints */
  #chat-container {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }

  /* Hide chat when panel is open */
  #chat-container.panel-open {
    display: none;
  }

  /* Panel full screen on mobile */
  #panel-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    max-width: 100% !important;
    z-index: 50;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  #panel-container.hidden {
    transform: translateX(100%);
  }

  #panel-container:not(.hidden) {
    transform: translateX(0);
  }

  /* Safe area insets */
  header {
    padding-top: calc(1rem + env(safe-area-inset-top));
  }

  #panel-container {
    padding-top: env(safe-area-inset-top);
  }

  /* Touch optimizations */
  * {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  button {
    min-height: 44px; /* Apple's minimum touch target */
    min-width: 44px;
  }

  #messages-container {
    overscroll-behavior: contain;
  }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  #messages-container {
    height: calc(100vh - 50px - 70px); /* Reduced heights for landscape */
  }

  header {
    padding: 0.5rem 1rem;
    padding-top: calc(0.5rem + env(safe-area-inset-top));
  }

  #input-container {
    padding: 0.5rem 1rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  }

  header h1 {
    font-size: 1.25rem;
  }

  header p {
    font-size: 0.75rem;
  }
}

/* Botones */
button {
  -webkit-tap-highlight-color: transparent;
}

/* Loading spinner */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Utilidades */
.transition {
  transition-property: all;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 150ms;
}

/* Pantalla de login */
#login-screen {
  animation: fade-in 0.5s ease-out;
}

#login-form input[type="password"]:focus {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#login-error {
  animation: fade-in 0.3s ease-out;
}

/* Transiciones de pantalla */
#app-container {
  animation: fade-in 0.4s ease-out;
}

.hidden {
  display: none !important;
}
