/* General Styles */
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-size: 16px;
    overscroll-behavior: contain;
    overflow-y: auto;
    height: 100%;
    position: fixed;
    width: 100%;
}

#chat-container {
    position: relative;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#chat-messages {
    flex: 1;
    overflow-y: auto !important;
    padding: 20px 10px 160px 10px;
    background-color: #ffffff;
    height: calc(100vh - 60px);
    transition: padding-bottom 0.3s ease;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: auto;
    overscroll-behavior-y: contain;
    position: relative;
    z-index: 1;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.message {
    margin: 15px 0;
    display: flex;
    flex-direction: row;
    clear: both;
    width: 100%;
}

/* Avatar styles */
.avatar {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    background-color: #ff7f27;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 8px;
}

.avatar svg {
    width: 24px;
    height: 24px;
}

/* Message Styles */
.message.bot {
    align-items: flex-start;
}

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

/* Bot Message Styles */
.bot .content {
    background-color: #dddddd;
    padding: 15px;
    border-radius: 15px;
    max-width: 85%;
    box-shadow: 0 2px 5px rgb(173, 173, 173);
    margin-bottom: 10px;
}

.bot .content p {
    margin: 0 0 15px 0;
}

.bot .content p:last-child {
    margin-bottom: 0;
}

.bot .content ul {
    margin: 0;
    padding-left: 20px;
    margin-bottom: 15px;
}

.bot .content ul:last-child {
    margin-bottom: 20px;
}

.bot .content h2,
.bot .content h3 {
    margin: 10px 0;
}

/* --- PASTE THIS NEW CODE HERE --- */
.mermaid {
    background: white;
    padding: 10px;
    border-radius: 8px;
    margin-top: 10px;
    overflow-x: auto; /* Allows scrolling if diagram is wide */
    text-align: center;
    border: 1px solid #eee; /* Optional: adds a subtle border */
}
/* -------------------------------- */

.user .content {
    background-color: #007bff;
    color: white;
    padding: 15px;
    border-radius: 15px;
    max-width: 70%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Typing Indicator */
#typing-indicator {
    position: fixed;
    bottom: 80px;
    left: 10px;
    z-index: 1001;
    background: none;
    box-shadow: none;
    margin: 0;
    pointer-events: none;
}

#typing-indicator .content {
    background-color: #dddddd;
    padding: 8px 12px;
    border-radius: 15px;
    max-width: fit-content;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    opacity: 1 !important;
}

.typing-indicator {
    display: flex;
    align-items: center;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin: 0 2px;
    border-radius: 50%;
    background-color: #606060;
    animation: bounce 1.3s ease infinite;
}

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

.typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Chat Form */
#chat-form {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #ffffff;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    padding: 15px;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
    z-index: 1000;
}

#user-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 18px;
    transition: all 0.3s ease;
}

#send-button {
    padding: 10px 20px;
    margin-left: 10px;
    border: none;
    background-color: #28a745;
    color: white;
    border-radius: 5px;
    cursor: pointer;
}

#send-button:hover {
    background-color: #218838;
}

/* Mobile Styles (both iOS and Android) */
@media (max-width: 767px) {
    #chat-messages {
        padding: 20px 10px 80px 10px;
    }

    .message {
        margin: 8px 0;
    }

    .message:last-child {
        margin-bottom: 70px;
    }

    #chat-form {
        padding: 10px;
    }

    #user-input {
        padding: 8px;
        font-size: 16px;
    }

    #send-button {
        padding: 8px 16px;
    }

    #typing-indicator {
        bottom: 60px;
    }
}

/* iOS Specific */
@supports (-webkit-touch-callout: none) and (max-width: 767px) {
    #chat-messages {
        padding-bottom: 90px;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    .keyboard-open #chat-messages {
        padding-bottom: 270px;
    }

    #chat-form {
        padding: 12px 10px;
        background-color: rgba(255, 255, 255, 0.95);
    }
}

/* Android Specific */
.android-device #chat-messages {
    padding-bottom: 60px;
    height: calc(100vh - 120px); /* Account for header and input */
    overscroll-behavior-y: contain;
}

.android-device.keyboard-open #chat-messages {
    height: calc(100vh - 350px); /* Account for keyboard height + suggestion bar */
    padding-bottom: 20px;
}

.android-device #chat-form {
    position: fixed;
    bottom: 0;
    padding: 8px;
    background-color: #ffffff;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
}

.android-device.keyboard-open #chat-form {
    position: fixed;
    bottom: 0;
}

/* Message spacing for Android */
.android-device .message {
    margin: 8px 0;
}

.android-device .message:last-child {
    margin-bottom: 16px;
}

/* Typing indicator position for Android */
.android-device #typing-indicator {
    bottom: 70px;
}

.android-device.keyboard-open #typing-indicator {
    bottom: 280px;
}

/* Responsive Design */
@media (max-width: 600px) {
    #chat-container {
        width: 100%;
    }
}

@media screen and (max-height: 500px) {
    #chat-form {
        height: 60vh;
    }
}

/* Desktop and iPad Styles */
@media (min-width: 768px) {
    body {
        overflow: auto;
        position: static;
    }
    
    #chat-container {
        max-width: 800px;
        margin: 0 auto;
        height: auto;
        min-height: 100vh;
    }
    
    #chat-messages {
        max-height: none;
        height: auto;
        overflow-y: auto !important;
        padding-bottom: 200px;
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
    }
    
    #chat-messages::-webkit-scrollbar {
        width: 8px;
    }
    
    #chat-messages::-webkit-scrollbar-track {
        background: transparent;
    }
    
    #chat-messages::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
    }
    
    #chat-form {
        width: 100%;
        max-width: 800px;
        margin: 0 auto;
    }

    #typing-indicator {
        left: 50%;
        transform: translateX(-50%);
        margin-left: -380px;
    }

    .message {
        margin: 15px 0;
    }
}

/* Keyboard Handling for Mobile */
@media (max-width: 767px) {
    body.keyboard-open #chat-form {
        position: fixed;
        bottom: 0;
    }

    .android-device.keyboard-open #chat-form {
        position: fixed;
        bottom: 0;
    }
}