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

body {
    font-family: sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f0f0f0;
    min-height: 100vh; 
}

/* Main container for responsive layout */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 30px;
    align-items: center;
}

/* Chat container styles */
#chat-container {
    width: 100%;
    max-width: 400px;
    height: 600px;
    border: 1px solid #ccc;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#chat-box {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    border-bottom: 1px solid #ccc;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#input-container {
    display: flex;
    padding: 10px;
}

#status-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-top: 1px solid #ccc;
    background-color: #f8f8f8;
}

#user-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 8px;
    font-size: 16px;
    transition: opacity 0.2s ease;
}

#user-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#send-button, #connect-button {
    border: none;
    background-color: #007bff;
    color: #fff;
    border-radius: 4px;
    padding: 8px 12px;
    margin-left: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    min-width: 60px;
}

#send-button:hover:not(:disabled), #connect-button:hover:not(:disabled) {
    background-color: #0056b3;
}

#send-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

/* Loading button styles */
#send-button.loading {
    background-color: #6c757d;
    cursor: not-allowed;
}

#send-button.loading::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

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

#status-message {
    margin: 0;
    font-size: 14px;
}

#status-message.connected {
    color: #28a745;
    font-weight: bold;
}

#status-message.disconnected {
    color: #dc3545;
    font-weight: bold;
}

.message {
    margin-bottom: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 70%;
}

.user-message {
    background-color: #007bff;
    color: #fff;
    align-self: flex-end;
    margin-left: auto;
}

.bot-message {
    background-color: #e9e9eb;
    color: #000;
    align-self: flex-start;
    white-space: pre-wrap; /* Preserve whitespace and line breaks */
    word-wrap: break-word; /* Break long words if necessary */
    line-height: 1.4; /* Improve readability */
}

.system-message {
    background-color: #ffc107;
    color: #000;
    align-self: center;
    text-align: center;
    font-style: italic;
    font-size: 0.9em;
    margin: 5px auto;
}

.error-message {
    background-color: #dc3545;
    color: #fff;
    align-self: center;
    text-align: center;
    font-size: 0.9em;
    margin: 5px auto;
}

.loading-message {
    background-color: #6c757d;
    color: #fff;
    align-self: center;
    text-align: center;
    font-style: italic;
    font-size: 0.9em;
    margin: 5px auto;
    animation: pulse 1.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

/* Instructions section styles */
.instructions-section {
    width: 100%;
    max-width: 800px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.instructions-content {
    padding: 30px;
}

.instructions-content p {
    margin-bottom: 15px;
    line-height: 1.6;
    color: #333;
}

.instructions-content a {
    color: #007bff;
    text-decoration: none;
}

.instructions-content a:hover {
    text-decoration: underline;
}

/* Medication Information Board Styles */
section.medication-list {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.medication-list article.condition {
    background-color: white;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.medication-list h3 {
    color: #2c3e50;
    margin-top: 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.medication-list ul.medications {
    list-style-type: none;
    padding-left: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.medication-list li {
    padding: 6px 10px;
    background-color: #f1f8fe;
    border-radius: 4px;
    color: #1a5276;
    font-size: 0.9em;
}

.medication-list .condition:nth-child(1) li {
    background-color: #e8f8f5;
    color: #117864;
}

.medication-list .condition:nth-child(2) li {
    background-color: #fef9e7;
    color: #9a7d0a;
}

.medication-list .condition:nth-child(3) li {
    background-color: #fdedec;
    color: #922b21;
}

/* Tablet styles */
@media (min-width: 768px) {
    body {
        padding: 40px;
    }
    
    .main-container {
        flex-direction: row;
        align-items: flex-start;
        gap: 40px;
    }
    
    #chat-container {
        flex-shrink: 0;
    }
    
    .instructions-section {
        flex: 1;
        min-width: 0;
    }
}

/* Desktop styles */
@media (min-width: 1024px) {
    .main-container {
        gap: 50px;
    }
    
    .instructions-content {
        padding: 40px;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 767px) {
    body {
        padding: 10px;
    }
    
    .main-container {
        gap: 20px;
    }
    
    #chat-container {
        height: 500px;
        max-width: none;
    }
    
    .instructions-content {
        padding: 20px;
    }
    
    .medication-list ul.medications {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}