/* ==================== */
/* Global Styles        */
/* ==================== */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Use min-height for flexibility */
    margin: 0;
    background: linear-gradient(135deg, #232526 0%, #414345 100%);
    color: #e0e0e0;
    transition: background 0.5s ease-in-out; /* Added ease-in-out for smoother transition */
}

/* ==================== */
/* Chat Container       */
/* ==================== */
.chat-container {
    width: 95%;
    max-width: 520px;
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(30, 30, 30, 0.7);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.3s ease-in-out, background 0.3s ease-in-out; /* Added ease-in-out */
    border-top: 1.5px solid rgba(255, 255, 255, 0.18);
    border-left: 1.5px solid rgba(255, 255, 255, 0.10);
}

/* ==================== */
/* Chat Header          */
/* ==================== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: linear-gradient(90deg, #007bff 60%, #0056b3 100%);
    border-bottom: 1.5px solid #333;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.10);
    min-height: 60px;
    position: relative;
    /* Added subtle text shadow for better contrast */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.chat-header h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 1px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); /* Slightly stronger shadow for heading */
}

.chat-header .chat-icon {
    font-size: 32px;
    margin-right: 10px;
    color: #fff;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15)); /* Slightly stronger drop shadow */
}

/* Style du bouton "Start New Chat" */
#new-chat-btn {
    padding: 8px 18px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff; /* Changed text color to white for better contrast */
    border: 1.5px solid rgba(255, 255, 255, 0.5); /* Softened border */
    border-radius: 10px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.3s ease-in-out, color 0.3s ease-in-out, border 0.3s ease-in-out;
    display: flex;
    align-items: center;
    gap: 7px;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(2px);
}

#new-chat-btn:hover {
    background: #fff;
    color: #007bff;
    border: 1.5px solid #007bff;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.2); /* Added stronger hover shadow */
}

/* ==================== */
/* Chat Messages        */
/* ==================== */
.chat-messages {
    height: 420px;
    overflow-y: auto;
    padding: 24px 18px 18px 18px;
    background: rgba(37, 37, 37, 0.85);
    border-bottom: 1.5px solid #333;
    display: flex;
    flex-direction: column;
    gap: 10px; /* Increased gap slightly for better spacing */
    scroll-behavior: smooth;
    /* Added custom scrollbar styles for better aesthetics */
    scrollbar-width: thin;
    scrollbar-color: #007bff #252525;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #252525;
}

.chat-messages::-webkit-scrollbar-thumb {
    background-color: #007bff;
    border-radius: 10px;
    border: 2px solid #252525;
}


.message {
    margin-bottom: 0;
    padding: 12px 18px;
    border-radius: 18px 18px 6px 18px; /* Default border radius, overridden by specific message types */
    max-width: 80%;
    word-wrap: break-word;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
    font-size: 16px;
    opacity: 0;
    animation: fadeInMsg 0.5s forwards;
    transition: background 0.2s ease-in-out, color 0.2s ease-in-out, box-shadow 0.2s ease-in-out, border 0.2s ease-in-out;
    border: 1.5px solid transparent;
}

.user-message {
    background: linear-gradient(90deg, #007bff 80%, #0056b3 100%);
    color: #fff;
    align-self: flex-end;
    border-radius: 18px 18px 6px 18px;
    border: 1.5px solid #007bff;
    box-shadow: 0 2px 8px 0 rgba(0, 123, 255, 0.15); /* Slightly stronger shadow */
    filter: drop-shadow(0 2px 4px rgba(0, 123, 255, 0.15));
}

.ai-message {
    background: rgba(51, 51, 51, 0.92);
    color: #e0e0e0;
    align-self: flex-start;
    border-radius: 18px 18px 18px 6px;
    border: 1.5px solid #444;
    box-shadow: 0 2px 8px 0 rgba(51, 51, 51, 0.15); /* Slightly stronger shadow */
    filter: drop-shadow(0 2px 4px rgba(51, 51, 51, 0.15));
}

.ai-text {
    display: inline-block;
    font-family: 'Fira Mono', 'Consolas', monospace;
    font-size: 15px;
    line-height: 1.4; /* Improved line height for readability */
}

/* Specific hover effects for messages */
.user-message:hover {
    background: linear-gradient(90deg, #0056b3 80%, #007bff 100%); /* Slight gradient shift on hover */
    box-shadow: 0 4px 16px 0 rgba(0, 123, 255, 0.2);
}

.ai-message:hover {
    background: rgba(65, 65, 65, 0.92); /* Slightly lighter background on hover */
    border: 1.5px solid #007bff; /* Highlight with primary color on hover */
    box-shadow: 0 4px 16px 0 rgba(51, 51, 51, 0.2);
}

/* ==================== */
/* Chat Input           */
/* ==================== */
.chat-input {
    display: flex;
    padding: 18px 15px 18px 15px;
    background: rgba(30, 30, 30, 0.92);
    border-top: 1.5px solid #333;
    gap: 12px;
    align-items: center;
}

#message-input {
    flex-grow: 1;
    padding: 12px 16px;
    border: 1.5px solid #444;
    border-radius: 12px;
    background: rgba(51, 51, 51, 0.92);
    color: #e0e0e0;
    font-size: 17px;
    outline: none;
    transition: border 0.2s ease-in-out, background 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.08);
}

#message-input::placeholder { /* Style for placeholder text */
    color: rgba(224, 224, 224, 0.6);
}

#message-input:focus {
    border: 1.5px solid #007bff;
    background: #232b3b;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2); /* Added a subtle focus ring */
}


/* ==================== */
/* Buttons              */
/* ==================== */
button {
    padding: 10px 22px;
    background: linear-gradient(90deg, #007bff 80%, #0056b3 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.3s ease-in-out, color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.08);
    outline: none;
    display: flex; /* Ensure consistent alignment for content */
    align-items: center;
    justify-content: center;
}

button:hover {
    background: linear-gradient(90deg, #0056b3 80%, #007bff 100%);
    color: #fff;
    box-shadow: 0 4px 16px 0 rgba(0, 123, 255, 0.2); /* Increased shadow on hover */
}

button#stop-btn {
    background: linear-gradient(90deg, #ff4d4d 80%, #b30000 100%);
    gap: 7px;
    color: #fff;
    font-weight: 600;
    border-radius: 10px;
    box-shadow: 0 2px 8px 0 rgba(255, 77, 77, 0.10);
}

button#stop-btn:hover {
    background: linear-gradient(90deg, #b30000 80%, #ff4d4d 100%);
    color: #fff;
    box-shadow: 0 4px 16px 0 rgba(255, 77, 77, 0.2); /* Increased shadow on hover */
}

.hidden {
    display: none !important; /* Use !important to ensure hiding */
}

/* ==================== */
/* Loading Animation    */
/* ==================== */
.loading .ai-text {
    color: #888;
    font-style: italic;
    opacity: 0.7;
}

.fa-spinner {
    margin-right: 5px;
    animation: spin 1s linear infinite;
}

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

@keyframes fadeInMsg {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==================== */
/* Responsive Design    */
/* ==================== */
@media (max-width: 600px) {
    .chat-container {
        width: 100%;
        height: 100vh; /* Full viewport height on small screens */
        border-radius: 0;
        max-width: 100vw;
        min-width: unset; /* Remove min-width */
    }

    .chat-messages {
        height: calc(100vh - 170px);
        padding: 12px 10px 8px 10px; /* Adjusted padding */
        font-size: 15px;
    }

    .chat-header {
        padding: 12px 15px; /* Adjusted header padding */
        min-height: 50px; /* Slightly smaller header height */
    }

    .chat-header h1 {
        font-size: 20px; /* Adjusted font size for smaller screens */
    }

    .chat-header .chat-icon {
        font-size: 24px; /* Adjusted icon size */
    }

    .chat-input {
        flex-direction: row;
        gap: 8px; /* Adjusted gap */
        padding: 12px 10px; /* Adjusted padding */
    }

    #message-input {
        flex-grow: 1;
        font-size: 15px;
        padding: 10px 12px; /* Adjusted padding */
        border-radius: 8px;
    }

    button {
        width: auto;
        height: 40px; /* Slightly taller buttons */
        font-size: 14px; /* Slightly larger font size */
        padding: 8px 12px;
        border-radius: 8px;
    }

    button#send-btn {
        flex-grow: 1; /* Allow send button to grow */
    }

    button#stop-btn {
        flex-grow: 0.5; /* Allow stop button to grow less than send */
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px 10px; /* Adjusted padding for stop button */
    }

    #new-chat-btn {
        padding: 6px 12px; /* Adjusted padding */
        font-size: 12px; /* Adjusted font size */
        border-radius: 8px;
    }
}