/* Apple-Inspired Dark Theme Minimalist Design */

/* Global Styles */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -0.01em;
  background: #000000;
  color: #ffffff;
  /* Prevent pull-to-refresh on mobile */
  overscroll-behavior-y: contain;
  /* Improve touch scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

/* Touch manipulation for better mobile interaction */
.touch-manipulation {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Prevent text selection on buttons for better UX */
button, .example-query, .suggestion-item {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Custom Scrollbar - Dark */
#messages-container::-webkit-scrollbar {
  width: 6px;
}

#messages-container::-webkit-scrollbar-track {
  background: transparent;
}

#messages-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

#messages-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Smooth Scroll */
#messages-container {
  scroll-behavior: smooth;
}

/* Message Animations - Subtle */
@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Only animate new messages, not when loading history */
.message-user:last-child {
  animation: slideInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.message-ai:last-of-type {
  animation: slideInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Prevent animation on page load */
.messages-container-loading .message-user,
.messages-container-loading .message-ai {
  animation: none !important;
}

/* Car Card Link Wrapper */
.car-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

/* Car Card Styles - Dark Theme */
.car-card {
  background: #1c1c1e;
  border: 1px solid #2c2c2e;
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 640px) {
  .car-card {
    border-radius: 12px;
  }
  
  /* Reduce card inner padding on mobile */
  .car-card > div:last-child {
    padding: 1rem !important;
  }
}

/* Only animate car cards when added dynamically */
.car-cards-grid:not(.no-animation) .car-card {
  animation: slideInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.car-card-link:hover .car-card {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(255, 255, 255, 0.1);
  border-color: #3c3c3e;
  background: #2c2c2e;
}

.car-card-link:active .car-card {
  transform: translateY(-2px);
}

.car-card-image {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: #0a0a0a;
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 640px) {
  .car-card-image {
    height: 200px;
  }
}

.car-card:hover .car-card-image {
  transform: scale(1.05);
}

.car-card-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #ffffff;
  color: #000000;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Price Display - Dark */
.price-display {
  color: #ffffff;
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

/* Pagination Button */
.show-more-btn {
  margin-top: 1.5rem;
  padding: 0.875rem 2rem;
  background: #1c1c1e;
  border: 1px solid #2c2c2e;
  border-radius: 12px;
  color: #ffffff;
  font-weight: 500;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
  width: 100%;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.show-more-btn:hover {
  background: #2c2c2e;
  border-color: #3c3c3e;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255, 255, 255, 0.1);
}

.show-more-btn:active {
  transform: translateY(0);
}

/* Hidden car cards */
.car-card-link.hidden {
  display: none;
}

/* Typing Indicator Animation */
@keyframes bounce {
  0%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-6px);
  }
}

/* Message Bubble Styles */
.message-bubble {
  max-width: 70%;
  word-wrap: break-word;
}

@media (max-width: 768px) {
  .message-bubble {
    max-width: 85%;
  }
  
  /* Reduce horizontal padding on mobile */
  #messages-container {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
  }
  
  /* Match padding for header and input area */
  header {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    padding-top: 0.875rem !important;
    padding-bottom: 0.875rem !important;
  }
  
  /* Input area compact on mobile */
  .bg-black.border-t {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
  }
  
  /* Hide suggestions dropdown on small screens to prevent overlap */
  #suggestions-dropdown {
    max-height: 40vh;
  }
  
  /* Compact header title on mobile */
  header h1 {
    font-size: 1.125rem !important;
  }
  
  /* Larger touch targets for buttons - minimum 44x44px */
  .example-query {
    min-height: 52px;
    padding: 0.875rem 1rem !important;
  }
  
  /* Better readability for welcome text */
  .text-2xl {
    font-size: 1.75rem !important;
    line-height: 2rem !important;
  }
  
  /* Input and button touch-friendly sizes */
  #user-input {
    font-size: 16px !important; /* Prevents zoom on iOS */
    min-height: 48px;
  }
  
  #send-btn {
    min-width: 48px;
    min-height: 48px;
    padding: 0.75rem 1.25rem !important;
  }
  
  #clear-history-btn {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Price display more readable */
  .price-display {
    font-size: 1.375rem !important;
  }
  
  /* Card titles more readable */
  .car-card h3 {
    font-size: 1.125rem !important;
    line-height: 1.5rem !important;
  }
}

/* Extra small devices (phones in portrait, less than 375px) */
@media (max-width: 374px) {
  /* Even more compact on very small screens */
  header h1 {
    font-size: 1rem !important;
  }
  
  .example-query {
    padding: 0.75rem 0.875rem !important;
    font-size: 0.8125rem !important;
  }
  
  #messages-container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  
  .car-card-image {
    height: 180px !important;
  }
  
  .price-display {
    font-size: 1.25rem !important;
  }
}

/* Example Query Hover Effect - Dark */
.example-query {
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.example-query:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255, 255, 255, 0.1);
  border-color: #3c3c3e;
  background: #1c1c1e;
}

.example-query:active {
  transform: translateY(0);
}

/* Car Cards Grid */
.car-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1.5rem;
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 641px) and (max-width: 1024px) {
  .car-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .car-cards-grid {
    grid-template-columns: 1fr;
    gap: 0.875rem;
  }
  
  /* Allow car cards to take more width on mobile without overflow */
  .message-ai .car-cards-grid {
    margin-left: 0;
    margin-right: 0;
    width: 100%;
  }
}

/* Error Message - Dark */
.error-message {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  padding: 1rem;
  color: #fca5a5;
  animation: slideInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Success Animation */
@keyframes successPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
}

.success-indicator {
  animation: successPulse 1.5s ease-out;
}

/* Custom Input Focus - Dark */
#user-input:focus {
  background: #1c1c1e;
}

/* Button Disabled State */
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Fade Out Animation */
@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.fade-out {
  animation: fadeOut 0.3s ease-out forwards;
}

/* No Results Message */
.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: #6b7280;
  animation: fadeIn 0.5s ease-out;
}

/* Info Badge - Dark */
.info-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #1c1c1e;
  border: 1px solid #2c2c2e;
  color: #9ca3af;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  font-weight: 500;
}

/* Welcome Animation - Gentle */
@keyframes welcomeFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.welcome-icon {
  animation: welcomeFloat 4s ease-in-out infinite;
}

/* Connection Status Dot Animation */
@keyframes pulse-dot {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

#connection-status + .w-2 {
  animation: pulse-dot 2s ease-in-out infinite;
}

/* User Message Styles - Dark */
.user-message-bubble {
  background: #ffffff;
  color: #000000;
  border-radius: 20px;
  border-bottom-right-radius: 4px;
  padding: 12px 18px;
  font-size: 0.9375rem;
  line-height: 1.5;
  max-width: 70%;
}

/* AI Message Styles - Dark */
.ai-message-bubble {
  background: #1c1c1e;
  color: #ffffff;
  border: 1px solid #2c2c2e;
  border-radius: 20px;
  border-top-left-radius: 4px;
  padding: 12px 18px;
  font-size: 0.9375rem;
  line-height: 1.5;
}

/* Smooth transitions for all interactive elements */
a, button, input, .example-query, .car-card {
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* Loading Skeleton - Dark */
.skeleton {
  background: linear-gradient(90deg, #1c1c1e 25%, #2c2c2e 50%, #1c1c1e 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Card text colors - Dark theme specific */
.car-card h3 {
  color: #ffffff;
}

.car-card .text-gray-600 {
  color: #9ca3af;
}

.car-card .text-gray-500 {
  color: #6b7280;
}

.car-card .bg-gray-100 {
  background: #2c2c2e;
  color: #d1d5db;
}

.car-card .border-gray-200 {
  border-color: #2c2c2e;
}

/* Suggestions Dropdown - Dark */
#suggestions-dropdown {
  animation: slideUpFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 640px) {
  #suggestions-dropdown {
    border-radius: 0.75rem;
  }
  
  #suggestions-dropdown .suggestion-item {
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
  }
  
  #suggestions-dropdown .suggestion-item span {
    font-size: 0.875rem;
  }
}

@keyframes slideUpFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.suggestion-item {
  cursor: pointer;
  user-select: none;
}

.suggestion-item:active {
  transform: scale(0.98);
}

/* Suggestions Scrollbar */
#suggestions-dropdown > div::-webkit-scrollbar {
  width: 6px;
}

#suggestions-dropdown > div::-webkit-scrollbar-track {
  background: transparent;
}

#suggestions-dropdown > div::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

#suggestions-dropdown > div::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  #messages-container {
    padding-top: 1rem;
    padding-bottom: 1rem;
  }
  
  .welcome-message {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }
  
  .example-query {
    padding-top: 0.625rem !important;
    padding-bottom: 0.625rem !important;
  }
}

/* Prevent zoom on double-tap for iOS Safari */
@media (max-width: 768px) {
  button, a, input {
    touch-action: manipulation;
  }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  
  .bg-black.border-t {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* Print styles */
@media print {
  .no-print {
    display: none;
  }
}
