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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    body {
        height: -webkit-fill-available;
    }
    
    .chat-container {
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
    }
}

/* Chat Container */
.chat-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 800px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.status-indicator {
    display: flex;
    align-items: center;
    font-size: 0.9rem;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background: linear-gradient(180deg, 
        rgba(255, 255, 255, 0.9) 0%, 
        rgba(240, 242, 255, 0.9) 100%);
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 10px;
}

/* Message Styles */
.message {
    display: flex;
    margin-bottom: 1.5rem;
    animation: fadeInUp 0.3s ease-out;
}

.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    margin: 0 1rem;
    flex-shrink: 0;
}

.ai-message .message-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.user-message .message-avatar {
    background: linear-gradient(135deg, #36d1dc, #5b86e5);
}

.message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
}

.user-message .message-content {
    align-items: flex-end;
}

.message-bubble {
    padding: 1rem 1.5rem;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.5;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
}

.ai-message .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 5px;
}

.user-message .message-bubble {
    background: linear-gradient(135deg, #36d1dc, #5b86e5);
    color: white;
    border-bottom-right-radius: 5px;
}

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

/* Typing Indicator */
.typing-indicator {
    padding: 0 2rem;
}

.typing-bubble {
    background: white !important;
    padding: 1rem 1.5rem !important;
}

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

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

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

/* Message Input */
.message-input-container {
    padding: 1.5rem 2rem;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.message-input .form-control {
    border: 2px solid #e9ecef;
    border-radius: 25px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.message-input .form-control:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

.message-input .btn {
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    transition: all 0.3s ease;
    margin-left: 0.5rem;
}

.message-input .btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.message-input .btn:disabled {
    opacity: 0.6;
    transform: none;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
        border-radius: 0;
    }
    
    .chat-header {
        padding: 1rem 1.5rem;
    }
    
    .chat-messages {
        padding: 1rem;
        padding-bottom: 0.5rem;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .message-input-container {
        padding: 1rem 1.5rem;
        position: relative;
        flex-shrink: 0;
        z-index: 1000;
    }
    
    .chat-header h4 {
        font-size: 1.1rem;
    }
    
    .chat-header small {
        font-size: 0.8rem;
    }
}

/* iOS Safari specific mobile fixes */
@media (max-width: 768px) and (-webkit-touch-callout: none) {
    .chat-container {
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
    }
    
    .message-input-container {
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        z-index: 1001;
        padding: 1rem 1.5rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
    
    .message-input .form-control {
        -webkit-appearance: none;
        border-radius: 25px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Ensure input stays visible when keyboard appears */
    .message-input .form-control:focus {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}

/* Loading states */
.btn-loading {
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 1s ease infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast customization */
.toast {
    border: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Accessibility improvements */
.message-bubble:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chat-container {
        background: white;
        border: 2px solid black;
    }
    
    .message-bubble {
        border: 1px solid #333;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .message {
        animation: none;
    }
    
    .typing-dots span {
        animation: none;
    }
    
    .chat-messages {
        scroll-behavior: auto;
    }
}
