/* Variables pour les couleurs modernes, profondes et nettes */
:root {
    /* Couleurs du thème Rouge/Jaune/Orange pour les accents et les bulles */
    --accent-red-pastel: #F08080; /* Un rouge plus pastel pour le dégradé du bouton Envoyer */
    --accent-red: #D94451;    /* Rouge moderne et profond (pour les bulles et autres) */
    --accent-orange: #F28C28; /* Orange vibrant mais élégant */
    --accent-yellow: #FFD700; /* Jaune doré */

    /* Couleurs d'arrière-plan et de texte pour un thème sombre et plat */
    --background-darker: #1E1F22; /* Fond principal très sombre, presque noir */
    --background-dark: #282A2E;   /* Arrière-plan des sections principales (header, chat_inner, list_part) */
    --background-light: #36393F;  /* Fond des éléments interactifs (inputs, user items) */
    --text-primary: #FFFFFF;      /* Texte blanc clair pour une lisibilité maximale */
    --text-secondary: #B9BBBE;    /* Texte gris clair pour les placeholders et les détails */
    --text-on-accent: #FFFFFF;    /* Texte sur les bulles rouges/oranges */
    --text-on-yellow: #282A2E;    /* Texte sombre sur la bulle jaune */

    /* Couleurs pour les accents de UI */
    --ui-accent-green: #2ecc71; /* Un vert pour les succès/confirmations */

    /* Ombres subtiles et bordures nettes */
    --shadow-subtle: rgba(0, 0, 0, 0.3); /* Ombre douce et diffuse pour la profondeur */
    --border-subtle: rgba(255, 255, 255, 0.08); /* Bordure très discrète */
    --border-subtle-save: rgba(22, 196, 36, 0.08);
    --border-subtle-unsave: rgba(196, 22, 22, 0.08);
    --focus-outline: rgba(255, 215, 0, 0.7); /* Lueur de focus jaune-doré et semi-transparente */
}

/* ---------------------------------------------- */
/* GLOBAL & RESET                */
/* ---------------------------------------------- */

/* Crucial: Apply box-sizing border-box universally to prevent layout issues */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0; /* Reset margins */
    padding: 0; /* Reset padding */
}

body {
    background-color: var(--background-darker);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden; /* Prevent horizontal scrolling on the body */
    min-height: 100vh; /* Ensure body takes at least full viewport height */
    display: flex;
    flex-direction: column; /* Allows footer to stick to bottom if content is short */
    width: 100%; /* Ensure body itself is 100% of viewport width */
}

textarea:focus, input:focus, button:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-outline);
}

a, a:visited {
    color: var(--accent-yellow);
    text-decoration: none;
    transition: color 0.2s ease-in-out;
}
a:hover {
    color: var(--accent-orange);
    text-decoration: underline;
}

/* ---------------------------------------------- */
/* HEADER SECTION                 */
/* ---------------------------------------------- */

header {
    background-color: var(--background-dark);
    padding: 1rem; /* Consistent padding for mobile */
    display: flex;
    flex-direction: column; /* Always column for mobile */
    align-items: center; /* Center items horizontally */
    justify-content: space-between;
    box-shadow: 0 4px 10px var(--shadow-subtle);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 10;
    position: relative;
    color: var(--text-primary);
    width: 100%; /* Ensure header takes full width */
}

@media (min-width: 768px) { /* Desktop layout for header */
    header {
        flex-direction: row; /* Switch to row for larger screens */
        padding: 1rem 2.5rem; /* Desktop padding */
        justify-content: flex-end; /* Align items to the end on desktop */
        min-height: 80px; /* Explicitly set a min-height for the header on desktop */
    }
}

#logo {
    height: 56px;
    width: auto;
    margin-bottom: 0.5rem; /* Space below logo on mobile */
    display: none; /* Hide logo by default */
}

@media (min-width: 768px) {
    #logo {
        margin-right: 1.5rem; /* Restore margin on larger screens */
        margin-bottom: 0;
        display: none; /* Keep logo hidden as requested by images */
    }
}

header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.03em;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
    text-align: center; /* Center header text on mobile */
    margin-bottom: 1rem; /* More space below title on mobile */
    white-space: nowrap; /* Prevent wrapping for title */
    overflow: hidden;
    text-overflow: ellipsis; /* Add ellipsis if it overflows */
    width: 100%; /* Ensure it respects header width */
    max-width: 400px; /* Limit max-width for very long titles on mobile */
    display: none; /* Hide H1 by default */
}

@media (min-width: 768px) {
    header h1 {
        display: none; /* Still hidden on desktop, focus on inputs */
    }
}

/* Menu Toggle Button for Mobile */
#menu-toggle {
    display: block; /* Show on mobile */
    margin-bottom: 1rem; /* Space below button */
    font-size: 1.1rem;
    padding: 0.8rem 1.5rem;
    width: 100%; /* Full width for the toggle button */
    max-width: 320px; /* Max width for the toggle button */
}

@media (min-width: 768px) {
    #menu-toggle {
        display: none; /* Hide on desktop as requested */
    }
}

#boxName {
    display: flex;
    flex-direction: column; /* Stack all forms/button vertically on mobile */
    align-items: center; /* Center items horizontally */
    gap: 0.75rem; /* Space between inputs/buttons */
    width: 100%; /* Take full width of header */
    padding: 0 0.5rem; /* Small horizontal padding inside boxName to prevent edge stickiness */
}

#header-menu-content {
    display: none; /* Hidden by default for mobile, controlled by JS */
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    margin-top: 1rem;
}

/* When active, show on mobile */
#header-menu-content.active {
    display: flex;
}

@media (min-width: 768px) { /* Desktop layout for header menu content (linear) */
    /* Adjust header to contain all inputs linearly on desktop */
    header {
        justify-content: flex-end; /* Push inputs to the right */
        flex-direction: row; /* Ensure row direction for header */
        flex-wrap: wrap; /* Allow wrapping if items don't fit in one line */
        gap: 1rem; /* Space between elements */
    }

    /* Make sure each form flows linearly */
    #boxName {
        flex-direction: row;
        flex-wrap: nowrap; /* Prevent wrapping for the linear layout */
        justify-content: flex-end;
        gap: 1rem;
        width: auto; /* Shrink to content */
        padding: 0;
        flex-grow: 1; /* Allow boxName to take available space on desktop */
    }

    /* Ensure #header-menu-content is always displayed as flex row on desktop */
    #header-menu-content {
        display: flex !important; /* Use !important to ensure it overrides any 'display: none' from JS or other rules */
        flex-direction: row; /* Ensure row direction for linear layout */
        align-items: center;
        gap: 1rem;
        width: auto;
        margin-top: 0;
        flex-wrap: nowrap; /* Ensure no wrapping for linear layout */
        flex-grow: 1; /* Allow it to grow and take space if needed within boxName */
    }

    /* All forms and validate button should sit side-by-side */
    #serverForm, #canalForm, #nameForm, #btn-validate {
        width: auto; /* Allow items to size based on content */
        max-width: none; /* Remove max-width constraints on desktop */
        margin: 0; /* Reset margins */
        flex-grow: 0; /* Do not force them to grow */
    }

    /* The input group within canalForm needs to be linear too */
    #canalForm .input-group {
        flex-direction: row; /* Ensure row direction for input and buttons */
        flex-wrap: nowrap;
        gap: 0.5rem;
        width: auto;
    }

    #canalForm .input-group .all-name {
        width: auto;
    }
}


/* Ensure individual forms take full width on mobile within #boxName */
#serverForm, #canalForm, #nameForm {
    width: 100%; /* Important for mobile: Forms should take full width of their parent (#boxName) */
    display: flex; /* Make forms flex containers */
    justify-content: center; /* Center their content (the input/input-group) */
}

.all-name {
    padding: 0.75rem 1.2rem;
    border-radius: 0.5rem;
    background-color: var(--background-light);
    border: 3px solid var(--border-subtle);
    color: var(--text-primary);
    font-weight: 400;
    width: 100%; /* Crucial: Make inputs take full width of their parent */
    text-align: center; /* Center placeholder text */
    max-width: 320px; /* Prevent inputs from becoming too wide on larger mobile screens */
    height: auto; /* Ensure height adjusts based on content */
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.all-name::placeholder {
    color: var(--text-secondary);
    opacity: 0.8;
}

.all-name:focus {
    border-color: var(--focus-outline);
    box-shadow: 0 0 0 3px var(--focus-outline);
}

.input-group {
    display: flex;
    flex-direction: column; /* Stack input and buttons vertically by default */
    align-items: center; /* Center items horizontally */
    gap: 0.5rem; /* Space between input and buttons */
    width: 100%; /* Take full width */
    max-width: 320px; /* Consistently limit width */
}

.input-group .all-name {
    flex-grow: 1; /* Allow the input to grow and take space */
    max-width: none; /* Remove max-width for input within this specific group when stacking */
}

/* Breakpoint for input-group to switch to row layout */
@media (min-width: 500px) { /* Adjust this breakpoint as needed for better appearance on wider phones/small tablets */
    .input-group {
        flex-direction: row; /* Arrange input and buttons horizontally */
        flex-wrap: nowrap; /* Prevent wrapping */
        justify-content: center; /* Center contents */
        max-width: none; /* Remove max-width when in a row layout */
    }
    .input-group .all-name {
        width: auto; /* Reset width to auto or specific value if needed */
        flex-grow: 1; /* Input takes remaining space */
    }
    .input-group .icon-button {
        width: auto; /* Buttons adjust to content */
        max-width: none;
    }
}

.icon-button {
    background-color: var(--background-light);
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%; /* Full width for icon buttons on mobile */
    max-width: 320px; /* Limit button width on wider mobile screens */
}

/* Ensure the validate button also behaves responsively */
#btn-validate {
    width: 100%; /* Full width on mobile */
    max-width: 320px; /* Consistent with other inputs/buttons */
    margin-top: 0.5rem; /* Small margin after other elements if needed */
}

@media (min-width: 768px) {
    #btn-validate {
        width: auto; /* Auto width on desktop */
        max-width: none;
        margin-top: 0;
    }
}

/* Hover effect for icon buttons - NOW ORANGE */
.icon-button:hover {
    background-color: var(--accent-orange);
    color: var(--text-primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.icon-button:active {
    transform: translateY(1px);
}

.hidden {
    display: none !important;
}

/* ---------------------------------------------- */
/* MAIN CONTENT                  */
/* ---------------------------------------------- */

#main {
    display: flex;
    flex-direction: column; /* Always column on mobile */
    justify-content: flex-start; /* Align items to the start of the cross-axis */
    align-items: center; /* Center items horizontally in column layout */
    padding: 1rem; /* Consistent padding for mobile */
    gap: 1.5rem; /* Adjusted gap for mobile */
    flex-grow: 1; /* Allow main content to take up available vertical space */
    width: 100%; /* Ensure main takes full width */
}

@media (min-width: 1024px) { /* Desktop layout for main content */
    #main {
        flex-direction: row;
        align-items: flex-start;
        padding: 2.5rem; /* Original padding for larger screens */
        gap: 2.5rem; /* Original gap for larger screens */
        justify-content: center; /* Center the chatbox and user list */
    }
}

/* ---------------------------------------------- */
/* CHAT BOX                    */
/* ---------------------------------------------- */

#chat_inner {
    width: 100%; /* Full width on smaller screens */
    max-width: 600px; /* Max width for chat box on tablets/mid-size phones */
    background-color: var(--background-dark);
    border-radius: 0.5rem;
    box-shadow: 0 8px 20px var(--shadow-subtle);
    overflow: hidden; /* Hide overflow to prevent internal scrolling issues */
    position: relative;
    z-index: 1;
    margin: 0 auto; /* Center the chat box horizontally on mobile */
}

@media (min-width: 768px) {
    #chat_inner {
        max-width: 700px; /* Slightly larger max width for mid-size screens */
    }
}

@media (min-width: 1024px) { /* Desktop width for chat box (3/4) */
    #chat_inner {
        width: 74%; /* Approx 3/4 of the main content area, leaving canal for gap */
        max-width: none; /* Remove max-width on desktop */
        margin: 0; /* Reset auto margin for desktop layout */
    }
}

#chat_box {
    flex-grow: 1;
    height: 600px; /* Increased height for chat box on desktop */
    padding: 1rem; /* Adjusted padding for mobile */
    background-color: var(--background-dark);
    overflow-y: auto; /* Allow vertical scrolling for chat messages */
    overflow-x: hidden; /* Ensure no horizontal scroll in chat box */
    display: flex;
    flex-direction: column;
    border-radius: inherit;
}

/* ---------------------------------------------- */
/* CUSTOM SCROLLBAR                 */
/* ---------------------------------------------- */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-dark);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--background-light);
    border-radius: 10px;
    border: 2px solid var(--background-dark);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ---------------------------------------------- */
/* CHAT INPUT AREA                 */
/* ---------------------------------------------- */

.chat_text-container {
    padding: 0.8rem; /* Adjusted padding for mobile */
    background-color: var(--background-dark);
    border-top: 1px solid var(--border-subtle);
    box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.1);
    display: flex; /* Make it a flex container */
    flex-direction: column; /* Stack elements vertically by default */
    gap: 0.8rem; /* Gap between form and preview container */
}

.chat_text-container form {
    display: flex; /* Use flexbox for desktop for full width input */
    flex-direction: row; /* Changed to row for mobile to put button and input on same line */
    gap: 0.8rem; /* Adjusted gap for mobile */
    align-items: center; /* Center items vertically within the form */
    width: 100%; /* Ensure form takes full width */
}

@media (min-width: 550px) { /* Tablet/Larger mobile to row layout */
    .chat_text-container form {
        flex-direction: row; /* Row direction for larger mobile and tablet */
        gap: 1rem;
        align-items: stretch; /* Stretch items to fill height in row layout */
    }
}

#t-entre {
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem 1.2rem;
    font-size: 1rem;
    background-color: var(--background-light);
    color: var(--text-primary);
    flex-grow: 1; /* Allow input to grow and take available space */
    width: 100%; /* Ensure input takes full width in column layout */
    max-width: none; /* Allow input to take full width of its container on desktop */
}

#t-entre::placeholder {
    color: var(--text-secondary);
    opacity: 0.8;
}

#t-entre:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-outline);
    background-color: var(--background-light);
}

/* Bouton "Envoyer" - NOW WITH GRADIENT */
.chat_text-btn {
    padding: 0.7rem 1.4rem;
    border-radius: 0.5rem;
    background: linear-gradient(to right, var(--accent-red), var(--accent-orange));
    color: var(--text-on-accent);
    font-weight: 600;
    box-shadow: 0 2px 5px var(--shadow-subtle);
    transition: background 0.2s ease-in-out, box-shadow 0.2s ease-in-out, transform 0.2s ease-in-out;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    width: auto; /* Changed to auto to prevent full width on mobile */
    max-width: 200px; /* Limit button width on wider mobile screens */
}

@media (min-width: 550px) {
    .chat_text-btn {
        width: auto; /* Reset width for larger screens */
        max-width: none; /* Remove max-width when in a row layout */
    }
}

.chat_text-btn:hover {
    background: linear-gradient(to left, var(--accent-red-pastel), var(--accent-orange));
    box-shadow: 0 4px 10px var(--shadow-subtle);
    transform: translateY(-2px);
}

.chat_text-btn:active {
    transform: translateY(0);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}


#btn-attach {
    width: 40px; /* Réduction de la largeur */
    height: 40px; /* Réduction de la hauteur */
    flex-shrink: 0;
    padding: 0;
    border-radius: 50%;
    font-size: 1.2rem; /* Réduction de la taille de l'icône */
    background-color: var(--accent-red);
    color: var(--text-primary);
}

#btn-attach:hover {
    background-color: var(--accent-red-pastel);
}

/* ... le reste de votre CSS ... */

/* Image Preview Container */
#image-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--border-subtle);
    margin-top: 10px;
    justify-content: flex-start;
}

.image-preview-wrapper {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 2px 5px var(--shadow-subtle);
}

.image-preview-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image-button {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
}

.remove-image-button:hover {
    background-color: rgba(0, 0, 0, 0.8);
}


/* ---------------------------------------------- */
/* CHAT BUBBLES                  */
/* ---------------------------------------------- */

.chat_bubble {
    padding: 0.8rem 1.2rem;
    max-width: 90%; /* Increased max-width for bubbles on mobile for better text flow */
    width: fit-content;
    border-radius: 0.8rem;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    word-wrap: break-word; /* Ensure long words break */
    margin-bottom: 0.75rem; /* Add spacing between bubbles */
    font-size: 1.1rem; /* Ensure readable font size, slightly larger */
    display: flex;
    flex-direction: column; /* Stack images and text within bubble */
    gap: 0.5rem; /* Space between images and text */
}

.chat_bubble-left {
    background: linear-gradient(to right, var(--accent-red), var(--accent-orange));
    color: var(--text-on-accent);
    margin-right: auto;
    border-bottom-left-radius: 0.2rem;
}

.chat_bubble-right {
    background: linear-gradient(to right, var(--accent-yellow), var(--accent-red-pastel));
    color: var(--text-on-yellow);
    margin-left: auto;
    border-bottom-right-radius: 0.2rem;
}

.chat_bubble_name {
    font-weight: 500;
    font-size: 0.8em;
    margin-bottom: 0.2rem;
    color: rgba(255, 255, 255, 0.7);
}

.chat_bubble-right .chat_bubble_name {
    color: rgba(40, 42, 46, 0.7);
}

/* Styles for images within chat bubbles */
.chat_image_received img, .chat_image_sent img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin-top: 0.2rem; /* Small gap between multiple images or image and text */
}

/* ---------------------------------------------- */
/* LIST USERS                    */
/* ---------------------------------------------- */
#list_users_box {
    width: 100%; /* Full width on mobile */
    max-width: 600px; /* Consistent max-width with chat box on mobile */
    background-color: var(--background-dark);
    border-radius: 0.5rem;
    box-shadow: 0 8px 20px var(--shadow-subtle);
    padding: 1.5rem;
    margin-top: 1.5rem; /* Add some space above user list on mobile */
    margin-left: auto; /* Center list users box */
    margin-right: auto; /* Center list users box */
}

@media (min-width: 1024px) { /* Desktop width for user list (1/4) */
    #list_users_box {
        width: 24%; /* Approx 1/4 of the main content area, leaving canal for gap */
        max-width: none; /* Remove max-width on desktop */
        margin-top: 0; /* Reset margin for larger screens */
        margin-left: 0;
        margin-right: 0;
    }
}

#list_users_box h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-right: 1rem;
    text-align: center;
}

#list_users {
    list-style: none;
    padding: 0;
    margin: 0;
}

#list_users li {
    background-color: var(--background-light);
    padding: 0.75rem 1rem;
    border-radius: 0.4rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    transition: background-color 0.2s ease-in-out;
}

#list_users li:last-child {
    margin-bottom: 0;
}

#list_users li:hover {
    background-color: #40444B;
}

#list_users_header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

#btn-refresh-list-users {
    width: auto;
}

/* ---------------------------------------------- */
/* FOOTER                      */
/* ---------------------------------------------- */

footer {
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.9rem;
    margin-top: auto; /* Pushes footer to the bottom */
    width: 100%;
}

/* ---------------------------------------------- */
/* RESPONSIVE - Consolidated and refined         */
/* ---------------------------------------------- */

/* Smaller global adjustments to padding/margins for very small screens */
@media screen and (max-width: 400px) { /* Adjusted breakpoint for very small screens */
    header {
        padding: 0.5rem;
    }
    #boxName {
        gap: 0.5rem;
    }
    .all-name, .icon-button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    #main {
        padding: 0.5rem;
        gap: 1rem;
    }
    .chat_text-container {
        padding: 0.5rem;
    }
    .chat_text-container form {
        gap: 0.5rem;
    }
    #t-entre, .chat_text-btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    .chat_bubble {
        padding: 0.7rem 1rem;
        font-size: 1rem; /* Maintain good font size for chat messages */
    }
    #list_users_box {
        padding: 1rem;
    }
}