/* Main CSS for Jarvis In Your Pocket */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Full height layout for independent scrolling */
html, body {
    height: 100%;
    overflow: hidden;
}

#jarvis-app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    display: flex;
    height: 100%;
    overflow: hidden;
}

#sidebar {
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#main-content {
    flex: 1;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#chat-interface {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    height: 0; /* Force flex item to respect container height */
    min-height: 300px; /* Ensure minimum height for visibility */
    padding: 1rem;
    /* Mobile-specific bottom padding to prevent chat input from blocking responses */
    padding-bottom: 120px; /* Extra space for mobile chat input bar */
}

/* Desktop adjustment - reduce bottom padding since sidebar provides more space */
@media (min-width: 768px) {
    #chat-messages {
        padding-bottom: 1rem; /* Normal padding for desktop */
    }
}

/* Mobile-specific adjustments for chat input positioning */
@media (max-width: 767px) {
    /* Ensure chat input bar has proper z-index and spacing on mobile */
    #fixed-chat-input {
        left: 0 !important; /* Full width on mobile */
        bottom: 0;
        padding: 16px;
        box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
    }
    
    /* Additional mobile padding for chat messages */
    #chat-messages {
        padding-bottom: 140px; /* More space needed on smaller screens */
    }
}

/* Streaming cursor animation for chat responses */
.streaming-cursor {
    display: inline-block;
    animation: blink 1s infinite;
    color: #3b82f6;
    font-weight: bold;
}

/* Searching the web wave animation */
.search-animation span {
    display: inline-block;
    animation: search-wave 1s infinite;
}
.search-animation span:nth-child(1) { animation-delay: 0s; }
.search-animation span:nth-child(2) { animation-delay: 0.05s; }
.search-animation span:nth-child(3) { animation-delay: 0.1s; }
.search-animation span:nth-child(4) { animation-delay: 0.15s; }
.search-animation span:nth-child(5) { animation-delay: 0.2s; }
.search-animation span:nth-child(6) { animation-delay: 0.25s; }
.search-animation span:nth-child(7) { animation-delay: 0.3s; }
.search-animation span:nth-child(8) { animation-delay: 0.35s; }
.search-animation span:nth-child(9) { animation-delay: 0.4s; }
.search-animation span:nth-child(10) { animation-delay: 0.45s; }
.search-animation span:nth-child(11) { animation-delay: 0.5s; }
.search-animation span:nth-child(12) { animation-delay: 0.55s; }
.search-animation span:nth-child(13) { animation-delay: 0.6s; }
.search-animation span:nth-child(14) { animation-delay: 0.65s; }
.search-animation span:nth-child(15) { animation-delay: 0.7s; }
.search-animation span:nth-child(16) { animation-delay: 0.75s; }
.search-animation span:nth-child(17) { animation-delay: 0.8s; }

@keyframes search-wave {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-0.35em); }
}

/* Nutrient calculation ripple animation */
.nutrient-animation span {
    display: inline-block;
    animation: nutrient-ripple 0.3s ease-in-out infinite;
}
.nutrient-animation span:nth-child(1) { animation-delay: 0s; }
.nutrient-animation span:nth-child(2) { animation-delay: 0.1s; }
.nutrient-animation span:nth-child(3) { animation-delay: 0.2s; }
.nutrient-animation span:nth-child(4) { animation-delay: 0.3s; }
.nutrient-animation span:nth-child(5) { animation-delay: 0.4s; }
.nutrient-animation span:nth-child(6) { animation-delay: 0.5s; }
.nutrient-animation span:nth-child(7) { animation-delay: 0.6s; }
.nutrient-animation span:nth-child(8) { animation-delay: 0.7s; }
.nutrient-animation span:nth-child(9) { animation-delay: 0.8s; }
.nutrient-animation span:nth-child(10) { animation-delay: 0.9s; }
.nutrient-animation span:nth-child(11) { animation-delay: 1.0s; }
.nutrient-animation span:nth-child(12) { animation-delay: 1.1s; }
.nutrient-animation span:nth-child(13) { animation-delay: 1.2s; }
.nutrient-animation span:nth-child(14) { animation-delay: 1.3s; }
.nutrient-animation span:nth-child(15) { animation-delay: 1.4s; }
.nutrient-animation span:nth-child(16) { animation-delay: 1.5s; }
.nutrient-animation span:nth-child(17) { animation-delay: 1.6s; }
.nutrient-animation span:nth-child(18) { animation-delay: 1.7s; }
.nutrient-animation span:nth-child(19) { animation-delay: 1.8s; }
.nutrient-animation span:nth-child(20) { animation-delay: 1.9s; }
.nutrient-animation span:nth-child(21) { animation-delay: 2.0s; }

@keyframes nutrient-ripple {
    0%, 100% { 
        transform: scale(1) translateY(0);
        opacity: 1;
        color: #3b82f6;
    }
    25% { 
        transform: scale(1.08) translateY(-0.08em);
        opacity: 0.85;
        color: #1d4ed8;
    }
    50% { 
        transform: scale(1.12) translateY(-0.12em);
        opacity: 0.8;
        color: #2563eb;
    }
    75% { 
        transform: scale(1.08) translateY(-0.08em);
        opacity: 0.85;
        color: #1d4ed8;
    }
}

/* Consulting sources ripple animation */
.consulting-sources-animation span {
    display: inline-block;
    animation: consulting-ripple 0.35s ease-in-out infinite;
}
.consulting-sources-animation span:nth-child(1) { animation-delay: 0s; }
.consulting-sources-animation span:nth-child(2) { animation-delay: 0.12s; }
.consulting-sources-animation span:nth-child(3) { animation-delay: 0.24s; }
.consulting-sources-animation span:nth-child(4) { animation-delay: 0.36s; }
.consulting-sources-animation span:nth-child(5) { animation-delay: 0.48s; }
.consulting-sources-animation span:nth-child(6) { animation-delay: 0.6s; }
.consulting-sources-animation span:nth-child(7) { animation-delay: 0.72s; }
.consulting-sources-animation span:nth-child(8) { animation-delay: 0.84s; }
.consulting-sources-animation span:nth-child(9) { animation-delay: 0.96s; }
.consulting-sources-animation span:nth-child(10) { animation-delay: 1.08s; }
.consulting-sources-animation span:nth-child(11) { animation-delay: 1.2s; }
.consulting-sources-animation span:nth-child(12) { animation-delay: 1.32s; }
.consulting-sources-animation span:nth-child(13) { animation-delay: 1.44s; }
.consulting-sources-animation span:nth-child(14) { animation-delay: 1.56s; }
.consulting-sources-animation span:nth-child(15) { animation-delay: 1.68s; }
.consulting-sources-animation span:nth-child(16) { animation-delay: 1.8s; }
.consulting-sources-animation span:nth-child(17) { animation-delay: 1.92s; }
.consulting-sources-animation span:nth-child(18) { animation-delay: 2.04s; }
.consulting-sources-animation span:nth-child(19) { animation-delay: 2.16s; }

@keyframes consulting-ripple {
    0%, 100% { 
        transform: scale(1) translateY(0);
        opacity: 1;
        color: #8b5cf6;
    }
    30% { 
        transform: scale(1.1) translateY(-0.1em);
        opacity: 0.8;
        color: #7c3aed;
    }
    60% { 
        transform: scale(1.15) translateY(-0.15em);
        opacity: 0.75;
        color: #6d28d9;
    }
    90% { 
        transform: scale(1.08) translateY(-0.08em);
        opacity: 0.85;
        color: #7c3aed;
    }
}

@keyframes profile-ripple {
    0%, 100% { 
        transform: scale(1) translateY(0);
        opacity: 1;
        color: #10b981;
    }
    25% { 
        transform: scale(1.09) translateY(-0.09em);
        opacity: 0.85;
        color: #059669;
    }
    50% { 
        transform: scale(1.13) translateY(-0.13em);
        opacity: 0.8;
        color: #047857;
    }
    75% { 
        transform: scale(1.09) translateY(-0.09em);
        opacity: 0.85;
        color: #059669;
    }
}

.updating-profile-animation {
    font-weight: 500;
    color: #10b981;
}

.updating-profile-animation span {
    display: inline-block;
    animation: profile-ripple 1.3s ease-in-out infinite;
}

.updating-profile-animation span:nth-child(1) { animation-delay: 0.0s; }
.updating-profile-animation span:nth-child(2) { animation-delay: 0.1s; }
.updating-profile-animation span:nth-child(3) { animation-delay: 0.2s; }
.updating-profile-animation span:nth-child(4) { animation-delay: 0.3s; }
.updating-profile-animation span:nth-child(5) { animation-delay: 0.4s; }
.updating-profile-animation span:nth-child(6) { animation-delay: 0.5s; }
.updating-profile-animation span:nth-child(7) { animation-delay: 0.6s; }
.updating-profile-animation span:nth-child(8) { animation-delay: 0.7s; }
.updating-profile-animation span:nth-child(9) { animation-delay: 0.8s; }
.updating-profile-animation span:nth-child(10) { animation-delay: 0.9s; }
.updating-profile-animation span:nth-child(11) { animation-delay: 1.0s; }
.updating-profile-animation span:nth-child(12) { animation-delay: 1.1s; }
.updating-profile-animation span:nth-child(13) { animation-delay: 1.2s; }
.updating-profile-animation span:nth-child(14) { animation-delay: 1.3s; }
.updating-profile-animation span:nth-child(15) { animation-delay: 1.4s; }
.updating-profile-animation span:nth-child(16) { animation-delay: 1.5s; }
.updating-profile-animation span:nth-child(17) { animation-delay: 1.6s; }
.updating-profile-animation span:nth-child(18) { animation-delay: 1.7s; }
.updating-profile-animation span:nth-child(19) { animation-delay: 1.8s; }
.updating-profile-animation span:nth-child(20) { animation-delay: 1.9s; }

@keyframes blink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

/* Ensure complete section isolation - prevent check-ins bleeding */
#checkins-section {
    position: absolute !important;
    top: -10000px !important;
    left: -10000px !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: -999 !important;
}

#checkins-section.active {
    position: static !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 1 !important;
}

:root {
  --primary-blue: #2563eb;
  --primary-blue-hover: #1d4ed8;
  --success-green: #16a34a;
  --warning-orange: #ea580c;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --border-color: #e5e7eb;
}

.dark {
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --border-color: #374151;
}

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

/* Custom animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

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

/* Chat message styles */
.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  word-wrap: break-word;
}

.message.user {
  background-color: var(--primary-blue);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  background: none !important;
  color: var(--text-primary);
  border: none !important;
  border-radius: 0 !important;
  padding: 16px 0 !important;
  max-width: 100% !important;
  margin-bottom: 16px;
  line-height: 1.6;
  box-shadow: none !important;
}

.message.loading {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Loading dots animation */
.loading-dots {
  display: flex;
  gap: 4px;
}

/* Fixed chat input styles */
#fixed-chat-input {
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1), 0 -2px 4px -1px rgba(0, 0, 0, 0.06);
  transition: left 0.3s ease;
}

/* Adjust chat input when sidebar is collapsed */
.sidebar-collapsed ~ * #fixed-chat-input {
  left: 64px !important;
}

/* Main content bottom padding to prevent overlap with fixed input */
.main-content {
  padding-bottom: 100px !important;
}

/* Ensure all content sections have proper bottom padding */
#chat-interface,
#overall-plan-section,
#food-history-section,
#analytics-section,
#recipes-section,
#checkins-section {
  padding-bottom: 100px !important;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  animation: loadingDots 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

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

/* Sidebar enhancements */
.nav-item.active {
  background-color: var(--primary-blue);
  color: white;
}

.nav-item.active:hover {
  background-color: var(--primary-blue-hover);
}

/* Chat history items */
.chat-history-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
  border: 1px solid transparent;
}

.chat-history-item:hover {
  background-color: var(--bg-secondary);
  border-color: var(--border-color);
}

.chat-history-item.active {
  background-color: var(--primary-blue);
  color: white;
}

/* Responsive design */
@media (max-width: 768px) {
  #sidebar {
    position: fixed !important;
    left: -100% !important;
    top: 0 !important;
    z-index: 9999 !important;
    height: 100vh !important;
    width: 280px !important;
    background-color: white !important;
    border-right: 1px solid #e5e7eb !important;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
    transition: left 0.3s ease !important;
    transform: none !important;
  }
  
  #sidebar.open {
    left: 0 !important;
    transform: none !important;
  }
  
  /* Dark mode support for mobile sidebar */
  .dark #sidebar {
    background-color: #1f2937 !important;
    border-right-color: #374151 !important;
  }
  
  /* Ensure main content takes full width on mobile when sidebar is closed */
  #main-content {
    width: 100% !important;
    margin-left: 0 !important;
  }
  
  .message {
    max-width: 95%;
  }
  
  /* Mobile chat input fixes */
  #fixed-chat-input {
    left: 0 !important;
    right: 0 !important;
    padding: 12px !important;
  }
  
  #fixed-chat-input .flex {
    max-width: 100% !important;
    gap: 8px !important;
  }
  
  #chat-input {
    font-size: 16px !important; /* Prevents zoom on iOS */
  }
}

/* Desktop chat centering - applies to screens larger than mobile */
@media (min-width: 769px) {
  #fixed-chat-input {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    max-width: 800px !important;
    width: 90% !important;
    padding: 16px !important;
  }
  
  #fixed-chat-input .flex {
    gap: 12px !important;
  }
  
  #chat-input {
    font-size: 14px !important;
  }
  
  /* Center chat messages area on desktop too */
  #chat-section .space-y-4 {
    max-width: 800px !important;
    margin: 0 auto !important;
    padding: 0 16px !important;
    width: 90% !important;
  }
  
  /* Ensure chat container has same constraints as input */
  #chat-section {
    max-width: 800px !important;
    margin: 0 auto !important;
    width: 90% !important;
  }
  
  /* Make chat messages align with input box */
  #chat-messages {
    max-width: 800px !important;
    margin: 0 auto !important;
    width: 90% !important;
    padding: 0 16px !important;
  }
  
  #chat-interface {
    max-width: 800px !important;
    margin: 0 auto !important;
    width: 90% !important;
  }
  
  /* Mobile overlay to close sidebar when clicking outside */
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    display: none;
  }
  
  .sidebar-overlay.active {
    display: block;
  }
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-primary);
}

/* Focus states */
input:focus, button:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Health metrics cards */
.metric-card {
  transition: transform 0.2s, box-shadow 0.2s;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Button enhancements */
.btn-primary {
  background-color: var(--primary-blue);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn-primary:hover {
  background-color: var(--primary-blue-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

/* Utility classes */
.glass-effect {
  backdrop-filter: blur(10px);
  background-color: rgba(255, 255, 255, 0.8);
}

.dark .glass-effect {
  background-color: rgba(17, 24, 39, 0.8);
}