* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    height: 100vh;
    /* Support for mobile viewport when keyboard appears */
    height: 100svh; /* Safari iOS support */
    height: 100dvh; /* Dynamic viewport height */
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh; /* Safari iOS support */
    height: 100dvh; /* Dynamic viewport height */
    width: 100vw;
    margin: 0;
    background: white;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.app-container.loaded {
    opacity: 1;
}

.main-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh; /* Safari iOS support */
    height: 100dvh; /* Dynamic viewport height */
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.user-phone {
    font-size: 0.9rem;
    opacity: 0.8;
    font-family: 'Courier New', monospace;
}

.logout-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Authentication Styles */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-form {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 100%;
    margin: 1rem;
    text-align: center;
}

.auth-form h1 {
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 1.8rem;
}

.auth-form p {
    color: #666;
    margin-bottom: 2rem;
    font-size: 1rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.phone-input-container {
    display: flex;
    align-items: center;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.phone-input-container:focus-within {
    border-color: #667eea;
}

.phone-prefix {
    background-color: #f8f9fa;
    color: #6c757d;
    padding: 1rem 0.75rem;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1rem;
    border-right: 1px solid #ddd;
    user-select: none;
}

#phoneInput {
    flex: 1;
    padding: 1rem;
    border: none;
    outline: none;
    font-size: 1rem;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    letter-spacing: 0.05rem;
}

#otpInput {
    width: 100%;
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    text-align: center;
}

#phoneInput:focus, #otpInput:focus {
    border-color: #667eea;
}

#sendOTPButton, #verifyOTPButton {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-bottom: 0.5rem;
}

#sendOTPButton:hover, #verifyOTPButton:hover {
    opacity: 0.9;
}

.back-button {
    width: 100%;
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.back-button:hover {
    background: #5a6268;
}

.message {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 6px;
    text-align: center;
    font-size: 0.9rem;
}

.message.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message.info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Authentication Success Styles */
.auth-success {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.success-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 100%;
    margin: 1rem;
    text-align: center;
}

.success-content h1 {
    color: #28a745;
    margin-bottom: 1rem;
    font-size: 1.8rem;
}

.success-content p {
    color: #666;
    margin-bottom: 2rem;
    font-size: 1rem;
}

#proceedButton {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

#proceedButton:hover {
    opacity: 0.9;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: calc(100vh - 120px);
    height: calc(100svh - 120px); /* Safari iOS support */
    height: calc(100dvh - 120px); /* Dynamic viewport height */
    overflow: hidden;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 1rem;
    padding-bottom: 5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
    max-height: calc(100vh - 200px);
    scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
    margin: 4px;
}

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

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

/* For Firefox */
.chat-messages {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
}

.message {
    display: flex;
    margin-bottom: 0.5rem;
}

.bot-message {
    justify-content: flex-start;
}

.user-message {
    justify-content: flex-end;
}

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

.message-content a {
    color: #667eea;
    text-decoration: underline;
    word-break: break-all;
}

.user-message .message-content a {
    color: #ffffff;
    text-decoration: underline;
}

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

.user-message .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.chat-input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    border-top: 2px solid #e0e0e0;
    background-color: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 0.5rem;
    z-index: 9999;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
    /* Ensure it stays at the bottom of the viewport */
    bottom: 0;
    bottom: env(safe-area-inset-bottom, 0);
    /* iOS keyboard navigation fix - use visibility instead of display */
    visibility: hidden;
    height: 0;
    opacity: 0;
    transition: opacity 0.3s ease, height 0.3s ease;
}

.chat-input-container.visible {
    visibility: visible;
    height: auto;
    opacity: 1;
}

#messageInput {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
    font-size: 1rem;
}

#messageInput:focus {
    border-color: #667eea;
}

#sendButton {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: opacity 0.2s;
}

#sendButton:hover {
    opacity: 0.9;
}

#sendButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: #f1f1f1;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    max-width: 70%;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

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

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

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

@media (max-width: 768px) {
    header {
        padding: 1rem;
        flex-shrink: 0;
    }

    .header-left h1 {
        font-size: 1.2rem;
    }

    .user-phone {
        font-size: 0.8rem;
    }

    .auth-form {
        margin: 0.5rem;
        padding: 1.5rem;
    }

    .chat-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0; /* Important for flexbox */
    }

    .chat-messages {
        flex: 1;
        padding: 0.75rem;
        padding-bottom: 6rem; /* Space for fixed input at bottom */
        gap: 0.75rem;
        overflow-y: auto;
        min-height: 0; /* Important for flexbox */
    }

    .message-content {
        max-width: 85%;
        font-size: 0.9rem;
    }

    .chat-input-container {
        padding: 0.75rem;
        border-top: 1px solid #e0e0e0;
        box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        flex-shrink: 0;
        z-index: 9999;
        /* Add safe area for iOS devices */
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0.75rem));
    }

    /* Ensure proper viewport handling on mobile */
    .main-app {
        height: 100vh;
        height: 100svh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100svh;
        max-height: 100dvh;
    }
}

@media (max-width: 480px) {
    .header-left h1 {
        font-size: 1rem;
    }
    
    .user-phone {
        font-size: 0.75rem;
    }
    
    .message-content {
        max-width: 90%;
        font-size: 0.85rem;
    }
}