html {
    height: 100%;
}

body {
    font-family: sans-serif;
    background-color: #f4f4f9;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.chat-container {
    width: 80%;
    max-width: 800px;
    height: 90vh;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;

    position: relative;
}

#new-search-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 18px;
    z-index: 10;
}

#new-search-button:hover {
    background-color: #5a6268;
}

.chat-area {
    flex-grow: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 1px solid #ddd;
}

.chat-box {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
}

.chat-message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 20px;
    max-width: 70%;
    line-height: 1.4;
}

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

.agent-message {
    background-color: #e9e9eb;
    color: #333;
    align-self: flex-start;
    max-width: 100%;
    position: relative; /* For positioning the copy button */
    padding-bottom: 30px; /* Make space for the copy button */
}

.sources-container {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #ddd;
}

.sources-container h4 {
    margin-top: 0;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: #555;
}

.sources-list {
    list-style-type: none;
    padding-left: 0;
    margin: 5px 0 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sources-list li {
    /* No margin needed here, the 'gap' property on the parent handles it */
}

.sources-list a {
    display: inline-block;
    padding: 4px 12px;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 16px;
    font-.85em;
    color: #333;
    text-decoration: none;
    transition: background-color 0.2s, border-color 0.2s;
}
.sources-list a:hover {
    background-color: #e0e0e0;
    border-color: #ccc;
    text-decoration: none;
}

.copy-button {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background-color: #d1d1d6;
    color: #333;
    border: 1px solid #c8c8cd;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s;
}

.agent-message:hover .copy-button {
    opacity: 1; /* Show on hover */
}

.copy-button:hover {
    background-color: #c8c8cd;
}

.chat-input {
    display: flex;
    padding: 20px;
}

#user-input {
    flex-grow: 1;
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 20px;
    margin-right: 10px;
    resize: none;
    white-space: pre-wrap;
    overflow-y: hidden;
    font-family: sans-serif;
    box-sizing: border-box;
}

#agent-selector {
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 20px;
    margin-right: 10px;
    background-color: white;
}

#send-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
}

#send-button:hover {
    background-color: #0056b3;
}



.loading-indicator {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
    /* Using rgba for semi-transparency so text behind is visible */
    border: 4px solid rgba(243, 243, 243, 0.7); /* Light grey */
    border-top: 4px solid rgba(0, 123, 255, 0.7); /* Blue */
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 10;
}

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

/* Media Queries for Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        height: 100%;
        overflow: hidden;
        -webkit-tap-highlight-color: transparent;
        display: block; /* Override desktop flex centering */
    }

    .chat-container {
        width: 100%;
        height: 100%;
        max-width: none;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-box {
        padding: 15px;
    }

    .chat-message {
        max-width: 85%;
        font-size: 16px;
    }

    .chat-input {
        padding: 15px;
        flex-direction: row;
        align-items: center;
    }

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

    #send-button, #new-search-button {
        padding: 12px 15px;
        font-size: 14px;
        white-space: nowrap;
    }

    #new-search-button {
        margin-left: 8px;
    }
}

@media (max-width: 480px) {
    .chat-input {
        padding: 10px;
        flex-wrap: wrap; /* Allow items to wrap to the next line */
    }

    #user-input, #agent-selector {
        padding: 10px;
        font-size: 14px;
    }

    #agent-selector {
        flex-basis: 100%; /* Make selector take full width */
        margin-right: 0;   /* Remove side margin */
        margin-bottom: 8px; /* Add space below */
    }

    #user-input {
        margin-right: 5px;
        min-width: 0; /* Allow input to shrink more */
    }

    #send-button, #new-search-button {
        padding: 10px 8px; /* Reduce horizontal padding */
        font-size: 12px;
        flex-shrink: 0; /* Prevent buttons from shrinking */
    }

    #new-search-button {
        margin-left: 5px;
    }
}