/* === General Styles & Resets === */
html {
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    background-color: #f0f2f5;
    color: #333;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main, #marketplace-container, #profile-container, #chat-container, #messages-inbox-container {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* === Header === */
header {
    background-color: #ffffff;
    color: #333;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-wrap: wrap;
}

header h1 {
    font-size: 2rem;
    color: #4CAF50;
    margin-bottom: 0.5rem;
}

header p {
    font-size: 1rem;
    color: #666;
}

header img {
    position: absolute;
    left: 2rem;
    top: 50%;
    transform: translateY(-50%);
    height: 60px;
}

#vreuse-logo {
    display: block;
}

#vit-logo {
    display: none;
}

/* === Navigation Bar === */
nav {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    background-color: #fff;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

nav .nav-button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    margin: 0.5rem 0.5rem 0.5rem 1rem;
    transition: background-color 0.3s;
    white-space: nowrap;
}

nav .nav-button:hover {
    background-color: #45a049;
}

#welcome-message {
    color: #333;
    font-weight: bold;
    margin-right: auto;
    margin-left: 1rem;
}

/* === Forms === */
.form-container {
    display: flex;
    justify-content: center;
    padding: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.auth-form, #add-item-form {
    background-color: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    max-width: 400px;
    width: 100%;
}

.auth-form h2, #add-item-form h2 {
    text-align: center;
    color: #4CAF50;
    margin-bottom: 1.5rem;
}

.auth-form label, #add-item-form label {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.3rem;
    font-weight: bold;
    color: #555;
}

.auth-form input, .auth-form select, .auth-form textarea,
#add-item-form input, #add-item-form select, #add-item-form textarea {
    width: 100%;
    padding: 10px;
    margin-top: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.auth-form button, #add-item-form button {
    width: 100%;
    padding: 12px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 2rem;
    font-size: 1rem;
    transition: background-color 0.3s;
}

.auth-form button:hover, #add-item-form button:hover {
    background-color: #45a049;
}

.error-message {
    color: red;
    font-size: 0.9rem;
    margin-top: 1rem;
    text-align: center;
}

/* === Marketplace Feed === */
#marketplace-container {
    padding: 2rem;
}

#marketplace-container h2 {
    font-size: 2rem;
    color: #4CAF50;
    text-align: center;
    margin-bottom: 2rem;
}

#item-list {
    display: grid;
    /* FIX: Use auto-fill to ensure columns maintain min-width and fill available space */
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    /* FIX: Center items when there are fewer than a full row */
    justify-content: center;
    /* FIX: Align content to start to prevent stretching of single items across full width */
    align-items: start;
}

.item-listing {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    width: 100%; /* Ensure it takes full width of its grid cell */
    display: flex;
    flex-direction: column;
    /* FIX: Ensure a minimum height for consistency */
    min-height: 400px; /* Adjust as needed based on content */
    /* FIX: Set a maximum width to prevent excessive stretching on very wide screens when there's only one item */
    max-width: 400px; /* This helps keep the card size consistent */
    margin: 0 auto; /* Center the card within its grid cell if max-width is applied */
}

.item-listing h3 {
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.item-listing p {
    color: #666;
    margin-bottom: 0.5rem;
}

.item-listing img {
    width: 100%;
    height: auto;
    max-height: 200px;
    object-fit: cover;
    border-radius: 5px;
    margin-bottom: 1rem;
}

.item-actions {
    display: flex;
    gap: 10px;
    margin-top: auto;
}

.contact-button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
    text-align: center;
    text-decoration: none;
    flex: 1;
}

.contact-button:hover {
    background-color: #45a049;
}

.remove-button {
    background-color: #c0392b;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
    text-align: center;
    text-decoration: none;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.remove-button:hover {
    background-color: #a53125;
}

.remove-button.deleting {
    background-color: #27ae60;
}

.remove-button.deleting .fa-remove {
    display: none;
}

.remove-button.deleting .fa-check {
    display: inline-block;
}

/* === User Profile Page === */
#profile-container {
    background-color: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    max-width: 600px;
    width: 100%;
    margin: 2rem auto;
}

#profile-container h2 {
    text-align: center;
    color: #4CAF50;
    margin-bottom: 1.5rem;
    font-size: 2rem;
}

.profile-info {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.profile-info p {
    font-size: 1.2rem;
}

.profile-info strong {
    color: #333;
}

.profile-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 1rem;
}

.profile-form-actions {
    display: flex;
    gap: 10px;
    margin-top: 1rem;
}

.profile-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* Added styles for profile buttons */
#edit-profile-button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

#edit-profile-button:hover {
    background-color: #45a049;
}

#delete-account-button {
    background-color: #c0392b;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

#delete-account-button:hover {
    background-color: #a53125;
}

.profile-form .nav-button {
    width: auto;
    padding: 12px 20px;
    margin: 0;
    font-size: 1rem;
    border-radius: 4px;
}

#cancel-edit-button {
    background-color: #6c757d;
}

#cancel-edit-button:hover {
    background-color: #5a6268;
}

/* General form element styling for profile edit form */
.profile-form input,
.profile-form select {
    width: 100%;
    padding: 10px;
    margin-top: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

#profile-update-message {
    text-align: center;
    font-weight: bold;
}


/* === Search and Filters === */
.search-and-filters-container {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.search-and-filters-container input,
.search-and-filters-container select {
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #ccc;
    font-size: 1rem;
}

#search-input {
    width: 300px;
}

/* === Chat UI === */
#chat-container {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    max-width: 600px;
    width: 100%;
    margin: 2rem auto;
    display: flex;
    flex-direction: column;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #ccc;
}

.chat-header h2 {
    font-size: 1.5rem;
    color: #4CAF50;
    text-align: left;
    margin: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 1rem;
    border: 1px solid #eee;
    border-radius: 5px;
    margin-bottom: 1rem;
}

.chat-message {
    padding: 10px;
    border-radius: 15px;
    max-width: 70%;
    word-break: break-word;
}

.chat-message.sent {
    background-color: #4CAF50;
    color: white;
    align-self: flex-end;
}

.chat-message.received {
    background-color: #e5e5ea;
    color: #333;
    align-self: flex-start;
}

.chat-input {
    display: flex;
    gap: 10px;
}

.chat-input input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

.chat-input button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
}

/* === Message Inbox === */
#messages-inbox-container {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    max-width: 600px;
    width: 100%;
    margin: 2rem auto;
    display: flex;
    flex-direction: column;
}

.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 1rem;
    border-bottom: 1px solid #eee;
    max-height: 400px;
    overflow-y: auto;
}

.conversation-item {
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
    background-color: #f9f9f9;
    border: 1px solid #eee;
    transition: background-color 0.2s;
}

.conversation-item:hover {
    background-color: #e9e9e9;
}

.conversation-item h3 {
    font-size: 1.2rem;
    color: #4CAF50;
}

.conversation-item p {
    font-size: 0.9rem;
    color: #666;
    margin-top: 5px;
}

/* === Footer === */
footer {
    background-color: #333;
    color: #fff;
    text-align: center;
    padding: 1rem;
    margin-top: auto;
}

/* === Responsive Media Queries === */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        padding: 1rem 0;
    }

    header img {
        position: static;
        transform: none;
        margin-bottom: 0.5rem;
    }

    nav {
        justify-content: center;
        margin-bottom: 1rem;
        padding: 0.5rem;
        gap: 0;
    }

    nav .nav-button {
        margin: 0.25rem;
    }

    #welcome-message {
        margin-right: 0;
        margin-bottom: 0.5rem;
    }

    .search-and-filters-container {
        flex-direction: column;
        align-items: center;
    }

    #search-input {
        width: 100%;
    }

    .chat-messages {
        max-height: 300px;
    }
}