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

:root {
    --primary: #6c63ff;
    --primary-dark: #4b44cc;
    --secondary: #f0f2ff;
    --dark: #1a1a2e;
    --text: #333;
    --text-light: #777;
    --border: #e0e0f0;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --bg: #f5f6fa;
    --white: #fff;
    --shadow: 0 4px 20px rgba(108,99,255,0.1);
    --radius: 12px;
}

body {
    font-family: 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* NAV */
nav {
    background: var(--dark);
    padding: 15px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
nav .logo { color: var(--primary); font-size: 1.4rem; font-weight: 700; text-decoration: none; }
nav .nav-links a {
    color: #ccc;
    text-decoration: none;
    margin-left: 20px;
    font-size: 0.95rem;
    transition: color 0.2s;
}
nav .nav-links a:hover { color: var(--primary); }

/* CONTAINERS */
.container { max-width: 1100px; margin: 0 auto; padding: 30px 20px; }
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px;
    margin-bottom: 20px;
}

/* FORMS */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; color: var(--text); }
.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
    background: var(--white);
}
.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* BUTTONS */
.btn {
    padding: 11px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
}
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #b02a37; }
.btn-success { background: var(--success); color: var(--white); }
.btn-sm { padding: 7px 14px; font-size: 0.85rem; }
.btn-full { width: 100%; text-align: center; }

/* ALERTS */
.alert { padding: 12px 18px; border-radius: 8px; margin-bottom: 15px; font-size: 0.9rem; }
.alert-danger { background: #ffe0e3; color: var(--danger); border-left: 4px solid var(--danger); }
.alert-success { background: #d4edda; color: #155724; border-left: 4px solid var(--success); }
.alert-info { background: #d1ecf1; color: #0c5460; border-left: 4px solid #17a2b8; }

/* AUTH PAGES */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--dark) 0%, #16213e 100%);
}
.auth-card {
    background: var(--white);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-card h1 { text-align: center; color: var(--primary); margin-bottom: 8px; font-size: 1.8rem; }
.auth-card p { text-align: center; color: var(--text-light); margin-bottom: 25px; }
.auth-card .divider { text-align: center; margin: 15px 0; color: var(--text-light); }
.auth-card a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* CHAT LAYOUT */
.chat-layout { display: flex; height: calc(100vh - 70px); }
.sidebar {
    width: 300px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: var(--dark);
    color: var(--white);
}
.sidebar-header h3 { font-size: 1rem; margin-bottom: 10px; }
.search-box {
    display: flex;
    gap: 8px;
}
.search-box input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    background: rgba(255,255,255,0.1);
    color: var(--white);
    font-size: 0.85rem;
}
.search-box input::placeholder { color: rgba(255,255,255,0.5); }
.search-box button {
    padding: 8px 12px;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    color: var(--white);
    cursor: pointer;
    font-size: 0.85rem;
}

.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text);
}
.conv-item:hover, .conv-item.active { background: var(--secondary); }
.conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}
.conv-info .name { font-weight: 600; font-size: 0.95rem; }
.conv-info .preview { font-size: 0.82rem; color: var(--text-light); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 190px; }

/* CHAT BOX */
.chat-box { flex: 1; display: flex; flex-direction: column; }
.chat-header {
    padding: 14px 20px;
    background: #1f2c34;
    border-bottom: 1px solid #111b21;
    display: flex;
    align-items: center;
    gap: 12px;
}
.chat-header .name { font-weight: 700; font-size: 1rem; color: #e9edef; }
.chat-header .status { font-size: 0.78rem; color: #8696a0; margin-top: 1px; }

/* Fond sombre style WhatsApp */
.messages-area {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    background-color: #0b141a;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Bulles style WhatsApp — alignement correct */
.message-bubble {
    display: flex;
    margin-bottom: 2px;
    align-items: flex-end;
    gap: 0;
    padding: 1px 16px;
}
/* Espace entre groupes de messages différents */
.message-bubble.mine + .message-bubble.theirs,
.message-bubble.theirs + .message-bubble.mine {
    margin-top: 10px;
}

/* Bulle reçue : alignée à gauche */
.message-bubble.theirs {
    justify-content: flex-start;
}
/* Bulle envoyée : alignée à droite */
.message-bubble.mine {
    justify-content: flex-end;
}

.message-bubble .bubble {
    max-width: 65%;
    min-width: 60px;
    padding: 7px 12px 4px 12px;
    font-size: 0.92rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
}

/* Bulle reçue */
.message-bubble.theirs .bubble {
    background: #202c33;
    color: #e9edef;
    border-radius: 0px 10px 10px 10px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.3);
    margin-left: 10px;
}
.message-bubble.theirs .bubble::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 0;
    border-width: 0 8px 8px 0;
    border-style: solid;
    border-color: transparent #202c33 transparent transparent;
}

/* Bulle envoyée */
.message-bubble.mine .bubble {
    background: #005c4b;
    color: #e9edef;
    border-radius: 10px 0px 10px 10px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.3);
    margin-right: 10px;
}
.message-bubble.mine .bubble::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 0;
    border-width: 0 0 8px 8px;
    border-style: solid;
    border-color: transparent transparent transparent #005c4b;
}

.message-meta {
    font-size: 0.69rem;
    color: #8696a0;
    margin-top: 2px;
    text-align: right;
    float: right;
    margin-left: 8px;
    margin-bottom: -2px;
    clear: both;
}
.message-bubble.theirs .message-meta { float: left; text-align: left; margin-left: 0; margin-right: 8px; }
.message-bubble.mine .message-meta { color: rgba(134,150,160,0.9); }
.message-sender { font-size: 0.78rem; font-weight: 600; color: #53bdeb; margin-bottom: 4px; display: block; }

/* Bannière "pas ami" */
.not-friend-banner {
    background: #1f2c34;
    border: 1px solid #2a3942;
    border-radius: 10px;
    padding: 12px 18px;
    margin: 10px 0;
    text-align: center;
    color: #8696a0;
    font-size: 0.87rem;
}

/* Input zone */
.chat-input-area {
    padding: 12px 16px;
    background: #1f2c34;
    border-top: 1px solid #111b21;
    display: flex;
    gap: 10px;
    align-items: center;
}
.chat-input-area input {
    flex: 1;
    padding: 11px 16px;
    border: none;
    border-radius: 25px;
    font-size: 0.92rem;
    outline: none;
    background: #2a3942;
    color: #e9edef;
}
.chat-input-area input::placeholder { color: #8696a0; }
.chat-input-area input:focus { background: #2d4149; }
.chat-input-area input:disabled { cursor: not-allowed; opacity: 0.5; }
.chat-input-area button {
    padding: 11px 20px;
    background: #00a884;
    color: #fff;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.9rem;
}
.chat-input-area button:hover { background: #00cf9f; }
.chat-input-area button:disabled { background: #2a3942; color: #566d78; cursor: not-allowed; }

/* FRIENDS */
.user-list { display: flex; flex-direction: column; gap: 12px; }
.user-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow);
}
.user-card .info { flex: 1; }
.user-card .info .name { font-weight: 700; }
.user-card .info .sub { font-size: 0.82rem; color: var(--text-light); }
.user-card .actions { display: flex; gap: 8px; }
.badge { padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-pending { background: #fff3cd; color: #856404; }
.badge-accepted { background: #d4edda; color: #155724; }
.badge-blocked { background: #f8d7da; color: #721c24; }

/* ADMIN */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { background: var(--secondary); font-weight: 700; color: var(--text); }
.admin-table tr:hover td { background: var(--secondary); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); text-align: center; }
.stat-card .number { font-size: 2.5rem; font-weight: 700; color: var(--primary); }
.stat-card .label { color: var(--text-light); font-size: 0.9rem; margin-top: 5px; }

/* HERO */
.hero {
    background: linear-gradient(135deg, var(--dark), #16213e);
    color: var(--white);
    padding: 80px 20px;
    text-align: center;
}
.hero h1 { font-size: 2.8rem; margin-bottom: 16px; }
.hero h1 span { color: var(--primary); }
.hero p { font-size: 1.15rem; color: rgba(255,255,255,0.75); margin-bottom: 35px; max-width: 550px; margin-left: auto; margin-right: auto; }
.hero-btns { display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; }
.btn-outline { background: transparent; border: 2px solid var(--white); color: var(--white); }
.btn-outline:hover { background: var(--white); color: var(--dark); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; padding: 60px 20px; max-width: 1000px; margin: 0 auto; }
.feature-card { text-align: center; padding: 30px 20px; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); }
.feature-card .icon { font-size: 2.5rem; margin-bottom: 14px; }
.feature-card h3 { font-size: 1.1rem; margin-bottom: 8px; }
.feature-card p { color: var(--text-light); font-size: 0.9rem; }

/* SEARCH RESULTS */
#searchResults { margin-top: 10px; }
.search-result-item {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--white);
}

/* TABS */
.tabs { display: flex; gap: 10px; margin-bottom: 20px; }
.tab-btn {
    padding: 10px 20px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--white);
    cursor: pointer;
    font-weight: 600;
    color: var(--text-light);
    transition: all 0.2s;
}
.tab-btn.active { border-color: var(--primary); color: var(--primary); background: var(--secondary); }

/* NOTIFICATIONS */
.notif-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.notif {
    background: #1f2c34;
    color: #e9edef;
    border-radius: 12px;
    padding: 12px 16px;
    min-width: 280px;
    max-width: 340px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: all;
    cursor: pointer;
    border-left: 4px solid #6c63ff;
    animation: slideIn 0.3s ease;
    transition: opacity 0.4s, transform 0.4s;
}
.notif.msg { border-left-color: #00a884; }
.notif.friend { border-left-color: #6c63ff; }
.notif.hiding { opacity: 0; transform: translateX(40px); }
.notif .notif-icon { font-size: 1.5rem; flex-shrink: 0; }
.notif .notif-body {}
.notif .notif-title { font-weight: 700; font-size: 0.88rem; margin-bottom: 2px; }
.notif .notif-text { font-size: 0.82rem; color: #8696a0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
@keyframes slideIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Badge non-lu sur conv */
.unread-badge {
    background: #00a884;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    margin-left: auto;
}

/* =============================================
   RESPONSIVE MOBILE — Style app téléphone
   ============================================= */
@media (max-width: 700px) {
    /* Nav mobile */
    nav {
        padding: 10px 16px;
    }
    nav .nav-links a, nav .nav-links span {
        font-size: 0;  /* Cache le texte */
    }
    nav .nav-links a::before { font-size: 1.2rem; }

    /* Layout chat mobile : sidebar cachée, vue plein écran */
    .chat-layout {
        flex-direction: column;
        height: calc(100vh - 54px);
        position: relative;
    }
    .sidebar {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0; left: 0;
        z-index: 10;
        transition: transform 0.3s ease;
    }
    .sidebar.hidden-mobile {
        transform: translateX(-100%);
    }
    .chat-box {
        position: absolute;
        top: 0; left: 0;
        width: 100%;
        height: 100%;
        z-index: 5;
        display: none;
    }
    .chat-box.visible-mobile {
        display: flex;
    }

    /* Bouton retour mobile dans le header */
    .back-btn-mobile {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        background: none;
        border: none;
        color: #e9edef;
        font-size: 1.3rem;
        cursor: pointer;
        margin-right: 4px;
        flex-shrink: 0;
    }

    /* Messages area prend tout l'espace */
    .messages-area {
        padding: 10px 12px;
    }
    .message-bubble .bubble {
        max-width: 80%;
    }
    .message-bubble {
        padding: 1px 6px;
    }

    /* Input zone mobile */
    .chat-input-area {
        padding: 8px 10px;
    }
    .chat-input-area input {
        font-size: 0.9rem;
        padding: 10px 14px;
    }
    .chat-input-area button {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    /* Sidebar mobile style */
    .sidebar-header {
        padding: 14px 16px;
    }
    .conv-item {
        padding: 12px 14px;
    }

    /* Notifs mobile */
    .notif-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }
    .notif {
        min-width: unset;
        width: 100%;
        max-width: 100%;
    }

    /* Admin table mobile */
    .admin-table { font-size: 0.78rem; }
    .admin-table td, .admin-table th { padding: 8px 10px; }

    /* Auth page mobile */
    .landing-left { display: none; }
    .auth-card { padding: 28px 20px; }
}

/* Bouton retour caché sur desktop */
.back-btn-mobile { display: none; }

/* Séparateur de date dans le chat */
.date-divider {
    text-align: center;
    margin: 16px 0 10px;
}
.date-divider span {
    background: #182229;
    color: #8696a0;
    font-size: 0.73rem;
    padding: 4px 14px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Icône cadenas dans header */
.chat-header .lock-icon { font-size: 0.85rem; color: #8696a0; }

/* Amélioration sidebar conv-item */
.conv-item { position: relative; }
.conv-item .unread-badge { flex-shrink: 0; }

/* Scrollbar sombre pour zone messages */
.messages-area::-webkit-scrollbar { width: 5px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: #2a3942; border-radius: 3px; }

/* Conv list scrollbar */
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: #e0e0f0; border-radius: 2px; }

/* Bouton envoyer amélioré */
.chat-input-area #sendBtn {
    width: 44px; height: 44px;
    border-radius: 50% !important;
    padding: 0 !important;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
