/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height when supported */
    overflow: hidden;
}

/* Chat container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height when supported */
    max-width: 800px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* Header */
.chat-header {
    background: #2c3e50;
    color: white;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.chat-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #fafafa;
    scroll-behavior: smooth;
}

/* Message styles */
.message {
    margin-bottom: 1rem;
    animation: messageSlide 0.3s ease-out;
}

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

.message-content {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.message-time {
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.25rem;
    padding: 0 1rem;
}

/* User messages */
.user-message {
    text-align: right;
}

.user-message .message-content {
    background: #007AFF;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.user-message .message-time {
    text-align: right;
}

/* Bot messages */
.bot-message {
    text-align: left;
}

.bot-message .message-content {
    background: #e9ecef;
    color: #333;
    border-bottom-left-radius: 4px;
}

.bot-message .message-time {
    text-align: left;
}

/* Input container */
.chat-input-container {
    padding: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    background: white;
    border-top: 1px solid #e0e0e0;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border-radius: 25px;
    padding: 0.5rem;
    border: 1px solid #e0e0e0;
    transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: #007AFF;
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    outline: none;
    color: #333;
}

#messageInput::placeholder {
    color: #999;
}

.send-button {
    background: #007AFF;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 0.5rem;
}

.send-button:hover {
    background: #0056CC;
    transform: scale(1.05);
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height when supported */
        border-radius: 0;
        box-shadow: none;
    }
    
    .chat-header {
        padding: 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
    }
    
    .chat-header h1 {
        font-size: 1.25rem;
    }
    
    .message-content {
        max-width: 90%;
        font-size: 0.95rem;
    }
    
    .chat-input-container {
        padding: 0.75rem;
        padding-bottom: max(0.75rem, calc(env(safe-area-inset-bottom) + 0.25rem));
    }
    
    #messageInput {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .chat-messages {
        padding: 0.75rem;
    }
    
    .message-content {
        max-width: 95%;
        padding: 0.65rem 0.9rem;
    }
    
    .chat-input-container {
        padding: 0.5rem;
        padding-bottom: max(0.5rem, calc(env(safe-area-inset-bottom) + 0.25rem));
    }
}

/* Loading indicator for bot responses */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 1rem;
    margin-bottom: 1rem;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typingAnimation 1.4s infinite ease-in-out;
}

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

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

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

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
    }
    
    .chat-container {
        background: #2d2d2d;
        color: #ffffff;
    }
    
    .chat-messages {
        background: #1e1e1e;
    }
    
    .bot-message .message-content {
        background: #3a3a3a;
        color: #ffffff;
    }
    
    .chat-input-container {
        background: #2d2d2d;
        border-top-color: #404040;
    }
    
    .input-wrapper {
        background: #3a3a3a;
        border-color: #404040;
    }
    
    #messageInput {
        color: #ffffff;
    }
    
    #messageInput::placeholder {
        color: #999;
    }
}
