/* ------------------------------------------------------------------ */
/* 1. Variables Globales & Plus */
/* ------------------------------------------------------------------ */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #10b981;
    --accent: #f59e0b;
    --danger: #ef4444;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --border: #e5e7eb;
    --radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --transition: all 0.2s ease-in-out;
    --fs-title: 1.875rem;
    --fs-subtitle: 0.95rem;
    --fs-body: 1rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    color: var(--text-main);
    background-color: var(--bg-body);
    -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ */
/* 2. Layout & Conteneurs */
/* ------------------------------------------------------------------ */
.page-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

h1 {
    font-size: var(--fs-title);
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--text-main);
    margin-bottom: 1.5rem;
    font-family: inherit;
}

/* ------------------------------------------------------------------ */
/* 3. Header & Navigation (Style Moderne) */
/* ------------------------------------------------------------------ */
.main-header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.main-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    max-width: 1000px;
    margin: 0 auto;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
}

.user-status {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logged-in-user {
    font-size: var(--fs-subtitle);
    color: var(--text-muted);
    font-family: inherit;
}

.nav-link {
    font-size: var(--fs-subtitle);
    font-weight: 600;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: var(--transition);
    color: var(--primary);
    border: 1px solid var(--primary);
}

.nav-link:hover {
    background-color: var(--primary);
    color: white;
}

.nav-link.logout-btn {
    border-color: var(--border);
    color: var(--text-muted);
}

.nav-link.logout-btn:hover {
    background-color: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* ------------------------------------------------------------------ */
/* 4. Barre de Recherche & Filtres (Optimisée avec icônes) */
/* ------------------------------------------------------------------ */
.search-bar {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}

.search-bar form {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap; 
    align-items: stretch; 
}

.search-bar input, 
.search-bar select {
    flex-grow: 1; 
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: var(--fs-subtitle);
    background-color: #fcfcfc;
    min-width: 120px;
    font-family: inherit;
}

.icon-button {
    width: 40px; 
    height: 40px; 
    padding: 0;
    font-size: 1.25rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    border: none;
    text-decoration: none;
    flex-shrink: 0;
}

.search-btn {
    background: var(--primary);
    color: white;
    display: flex; 
}

.search-btn:hover {
    background: var(--primary-hover);
}

.clear-btn {
    background: var(--border);
    color: var(--text-muted);
}

.clear-btn:hover {
    background: #d1d5db;
}


/* ------------------------------------------------------------------ */
/* 5. Formulaire de Publication */
/* ------------------------------------------------------------------ */
.post-form {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

.post-form h3 {
    margin-bottom: 1rem;
    color: var(--text-main);
}

.post-form select {
    width: 100%;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: #fcfcfc;
}

.post-form textarea {
    width: 100%;
    min-height: 100px;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1rem;
    font-family: inherit;
    font-size: var(--fs-body);
}

.post-form button[type="submit"] {
    width: 100%;
    padding: 0.875rem;
    background: var(--primary);
    color: white;
    border: none;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.post-form button[type="submit"]:hover {
    background: var(--primary-hover);
}

/* ------------------------------------------------------------------ */
/* Upload zone (Homepage) */
/* ------------------------------------------------------------------ */
.upload-zone {
    margin-top: 10px;
    margin-bottom: 30px;
}
.upload-zone input[type="file"] {
    display: none;
}
.upload-label {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(99,102,241,0.02), transparent);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.upload-label .upload-hint {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}
.upload-label:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
    color: var(--primary);
    transform: translateY(-2px);
}
.upload-preview img {
    margin-top: 10px;
    max-height: 140px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border);
}

.upload-label.dragover {
    border-color: var(--primary-hover);
    background: linear-gradient(180deg, rgba(99,102,241,0.08), rgba(99,102,241,0.02));
}

/* ------------------------------------------------------------------ */
/* 6. Flux de Messages (Feed) */
/* ------------------------------------------------------------------ */
.message-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.25rem;
    transition: transform 0.2s ease;
    position: relative;
}

.message-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.message-card .meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1rem;
    font-size: var(--fs-subtitle);
    font-family: inherit;
}

.badge {
    background: #eef2ff;
    color: var(--primary);
    padding: 2px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: var(--fs-subtitle);
    text-transform: uppercase;
}

.message-card .content p {
    font-size: var(--fs-body);
    color: #374151;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: break-word; 
    word-wrap: break-word; 
    word-break: break-word;
}

/* ------------------------------------------------------------------ */
/* 7. Actions & Votes */
/* ------------------------------------------------------------------ */
.actions {
    display: flex;
    gap: 1.5rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.actions a, .actions span {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-subtitle);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.actions a:hover {
    color: var(--primary);
}

/* ------------------------------------------------------------------ */
/* 8. Commentaires (Inclusif des réponses nichées) */
/* ------------------------------------------------------------------ */
.comments-section {
    margin-top: 1rem;
    background: #f9fafb;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #f1f5f9;
}

.comment {
    padding: 0.75rem 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: var(--fs-subtitle);
    color: var(--text-main);
    font-family: inherit;
}
.comment:last-child {
    border-bottom: none;
}

.comment strong {
    color: var(--primary);
    font-weight: 700;
}

.comment-replies {
    padding-left: 15px;
    border-left: 2px solid #e5e7eb;
    margin-top: 5px;
    margin-bottom: 5px;
}
.comment-replies .comment {
    border-bottom: 1px dotted #e5e7eb;
}

.comment-reply-form {
    margin: 5px 0 10px 0;
    padding-left: 5px;
}

.comment-reply-form form {
    display: flex;
    gap: 5px;
}

.comment-reply-form input {
    flex: 1;
    padding: 3px 8px;
    font-size: 0.8rem;
    height: 30px;
    border-radius: 20px;
}

.comment-reply-form button {
    height: 30px;
    padding: 0 10px;
    font-size: 0.8rem;
    border-radius: 20px;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}
.comment-reply-form button:hover {
    background: var(--primary-hover);
}

.first-level-comment-form {
    margin-top: 15px; 
    display: flex;
    gap: 8px;
}
.first-level-comment-form input {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: var(--fs-body);
    font-family: inherit;
}
.first-level-comment-form button[type="submit"] {
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}
.first-level-comment-form button[type="submit"]:hover {
    background: var(--primary-hover);
}


/* ------------------------------------------------------------------ */
/* 9. Footer */
/* ------------------------------------------------------------------ */
.main-footer-style {
    margin-top: auto;
    background: var(--text-main);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
}

.footer-content p {
    opacity: 0.7;
    font-size: 0.875rem;
}

/* ------------------------------------------------------------------ */
/* 10. Formulaires d'Auth (Login/Register) */
/* ------------------------------------------------------------------ */
.auth-page {
    max-width: 450px;
    padding-top: 3rem;
}

.auth-form {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.auth-page h2 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"] {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.auth-form button[type="submit"] {
    width: 100%;
    padding: 12px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}
.auth-form button[type="submit"]:hover {
    background-color: var(--primary-hover);
}

.error-message {
    color: var(--danger);
    border: 1px solid var(--danger); 
    background: #fee2e2;
    padding: 10px; 
    border-radius: 8px; 
    margin-bottom: 20px;
    font-weight: 500;
}

.alert-message.success {
    color: #0b6b2f;
    border: 1px solid #8fd19a;
    background: #e6f7ec;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 600;
}

.alert-message.error {
    color: var(--danger);
    border: 1px solid var(--danger);
    background: #fee2e2;
    padding: 10px; 
    border-radius: 8px; 
    margin-bottom: 20px;
    font-weight: 600;
}

/* ------------------------------------------------------------------ */
/* 11. Responsive */
/* ------------------------------------------------------------------ */
@media (min-width: 768px) {
    .container {
        padding-top: 3rem;
    }
    
    .search-bar input[name="q"] {
        flex-grow: 2; 
    }
}

.message-card .delete-button {
    position: absolute;
    top: 10px;
    right: 10px;
    color: white !important;
    background-color: red !important;
    padding: 5px 10px;
    border-radius: 5px;
    text-decoration: none;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: visible !important;
}

.message-card .delete-button:hover {
    background-color: darkred !important;
}

/* ------------------------------------------------------------------ */
/* Action menus ("...") for messages and comments */
/* ------------------------------------------------------------------ */
.action-menu summary, .comment-action-menu summary { 
    cursor: pointer; 
    background: none; 
    border: none; 
    font-size: 1.1em; 
    padding: 4px 6px; 
    border-radius: 6px; 
}
.action-menu { position: relative; }
.comment { position: relative; }
.action-menu .action-list, .comment-action-menu .action-list { 
    list-style: none; 
    margin: 0; 
    padding: 6px; 
    background: #fff; 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    position: absolute; 
    right: 0; 
    top: 28px; 
    min-width: 160px; 
    box-shadow: 0 2px 6px rgba(0,0,0,0.12); 
    display: none; 
    z-index: 10; 
}
.action-menu[open] .action-list, .comment-action-menu[open] .action-list { display: block; }
.action-list li { padding: 6px 8px; }
.action-list li a { text-decoration: none; color: var(--text-main); display:block; }
.action-list li a:hover { background: #f5f5f5; }