:root {
    --primary-color: #4a90e2;
    --secondary-color: #f0f4f8;
    --user-message-color: #e3f2fd;
    --ai-message-color: #e8f5e9;
    --text-color: #333;
    --border-radius: 20px;
}

body {
    font-family: 'Roboto', sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

.checkbox-container {
    display: flex;
    align-items: center;
    margin-top: 0.5rem;
}

.checkbox-container input[type="checkbox"] {
    margin-right: 0.5rem;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    padding-right: 1rem;
}

.custom-select {
    appearance: none;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
}

main {
    display: flex;
    flex-grow: 1;
    padding: 5rem 0 1rem;
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

#apiEndpointInput {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 1rem;
    border: 1px solid #ddd;
    border-radius: 5px;
}

.pinned-messages {
    width: 40%;
    padding: 1rem;
    background-color: #f0f0f0;
    border-radius: 10px;
    margin-right: 1rem;
    overflow-y: auto;
    max-height: calc(100vh - 100px);
    position: sticky;
    top: 9rem;
    align-self: flex-start;
    flex-shrink: 0;
}

.pinned-messages h2 {
    margin-top: 0;
    font-size: 1.2rem;
    color: #333;
}

.pinned-message {
    margin-bottom: 1rem;
    position: relative;
}

.pinned-message .message-container {
    transform: scale(0.9);
    transform-origin: top left;
}

#chatContainer {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 0 1rem;
    width: calc(100% - 300px);
}

#chatHistory {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--secondary-color);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    height: calc(100% - 60px); /* Adjust this value based on your user input height */
}

.message-container {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    margin-bottom: 1rem;
    position: relative;
}

.user-container {
    align-items: flex-end;
    margin-left: auto;
}

.ai-container {
    align-items: flex-start;
    margin-right: auto;
}

.message {
    padding: 0.8rem;
    border-radius: var(--border-radius);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.3s ease-out;
    max-width: 50rem;
}

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

.user-message {
    background-color: var(--user-message-color);
    border-bottom-right-radius: 0;
}

.ai-message {
    background-color: var(--ai-message-color);
    border-bottom-left-radius: 0;
}

.audio-container {
    margin-top: 0.5rem;
    align-self: flex-start;
}

.audio-control {
    max-width: 250px;
    height: 30px;
}

#userInput {
    display: flex;
    margin-top: 1rem;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    height: 50px; /* Set a fixed height for user input */
}

#textInput {
    flex-grow: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 1rem;
    resize: none;
    overflow-y: hidden;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    margin-left: 0.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #3a7bd5;
}

button:active {
    background-color: #2a5db0;
}

#recordButton {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.mic-icon, .stop-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.recording-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: rgba(255, 0, 0, 0.5);
    opacity: 0;
    animation: pulse 1s infinite;
    display: none;
}

#recordButton.recording .recording-pulse {
    display: block;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.7; }
    70% { transform: scale(1.1); opacity: 0; }
    100% { transform: scale(1); opacity: 0; }
}

#loadingSpinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border: 5px solid var(--secondary-color);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1000;
}

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

.hidden {
    display: none;
}

.markdown-body {
    box-sizing: border-box;
    min-width: 200px;
    max-width: 980px;
    margin: 0 auto;
    color: var(--text-color) !important;
    font-family: 'Roboto', sans-serif !important;
}

.ai-message .markdown-body {
    background-color: var(--ai-message-color);
    border-radius: var(--border-radius);
    border-bottom-left-radius: 0;
}

.pin-button {
    position: absolute;
    top: -10px;
    right: -10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    display: none;
    z-index: 10;
    transition: transform 0.2s ease;
    line-height: 1;  /* Added to improve vertical alignment */
}

.message-container:hover .pin-button {
    display: block;
}

.pin-button:hover {
    transform: scale(1.2);  /* Slight scale effect on hover */
    background-color: transparent !important;
    text-shadow: 1px 1px 2px black, 0 0 25px blue, 0 0 5px darkblue;
}

.pin-button.pinned {
    display: block;
}

.pinned-icon {
    transform: none;
}

@media (max-width: 1200px) {
    #chatHistory,
    #userInput {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    header {
        padding: 0.5rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .custom-select, #newChatButton {
        width: 100%;
        margin-top: 0.5rem;
    }

    main {
        flex-direction: column;
        padding-top: 5rem;
    }

    .pinned-messages {
        position: static;
        width: 100%;
        margin-right: 0;
        margin-bottom: 1rem;
        max-height: 200px;
    }

    #chatContainer {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        padding: 0 1rem;
        width: calc(60% - 1rem);
        height: calc(100vh - 150px); /* Adjust this value based on your layout */
        overflow: hidden; /* Hide overflow */
    }

    .message-container {
        max-width: 90%;
    }

    .message {
        min-width: 80%;
    }

    .audio-control {
        max-width: 200px;
    }

    #userInput {
        flex-wrap: wrap;
    }

    #textInput {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    #sendButton, #recordButton {
        flex: 1;
        margin-left: 0;
        margin-right: 0.5rem;
    }

    #recordButton {
        margin-right: 0;
    }
}