@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap');

:root {
    /* MODE SOMBRE - VERT KHAKI ACCENTUÉ */
    --bg-main: #0f1612;
    --bg-sidebar: #0a0e0c;
    --border-color: #1c2821;
    --text-primary: #e3ebd6;
    --text-muted: #8fa093;
    --text-light: #58695f;
    --bg-chat: #121b16;
    --bg-input: #17231c;
    --bg-user-bar: #070a08;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --accent-green: #3d5a45;
    
    --discord-online: #23a55a;
    --discord-idle: #f0b232;
    --discord-dnd: #f23f43;
    --discord-invisible: #80848e;
}

.light-theme {
    /* CORRECTION VERT CLAIR - VRAIES NUANCES PASTEL ET SAGE (PAS BLANC ÉBLOUISSANT) */
    --bg-main: #dae3da;
    --bg-sidebar: #c2cdc1;
    --border-color: #a8b8a6;
    --text-primary: #1b2e1e;
    --text-muted: #415444;
    --text-light: #677d6a;
    --bg-chat: #e7ece6;
    --bg-input: #d1dad0;
    --bg-user-bar: #b3c0b1;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --accent-green: #486950;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Montserrat', sans-serif; }
body { background: var(--bg-main); display: flex; justify-content: center; align-items: center; height: 100vh; width: 100vw; overflow: hidden; }

/* FIX ARRIÈRE-PLAN LOGIN : FINI L'ANIMATION, REPOSANT ET FIXE */
body:not(.dark-theme-active):not(.light-theme) {
    background: #0f1612 !important;
}

.dynamic-scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border-color) transparent; }
.dynamic-scroll::-webkit-scrollbar { width: 6px; }
.dynamic-scroll::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 10px; }

/* Badge de notification rouge */
.sidebar-large-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 8px; background: transparent; border: none; color: var(--text-muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.friends-btn-content { display: flex; align-items: center; gap: 12px; }
.sidebar-large-btn:hover, .sidebar-large-btn.active { background: var(--bg-input); color: var(--text-primary); }

.badge-notif { background-color: var(--discord-dnd); color: white; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 12px; min-width: 18px; text-align: center; display: inline-block; }

/* Auth Forms */
.container { background: #131c17; border-radius: 16px; box-shadow: 0 10px 30px var(--shadow-color); position: relative; width: 768px; min-height: 480px; overflow: hidden; border: 1px solid var(--border-color); }
.container form { background: #131c17; display: flex; align-items: center; flex-direction: column; justify-content: center; padding: 0 50px; height: 100%; }
.container h1 { color: #e3ebd6; margin-bottom: 20px; font-size: 24px; }
.brand-badge { background: #1b2820; border: 1px solid var(--border-color); color: #e3ebd6; padding: 6px 12px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.input-group { display: flex; align-items: center; background: #1b2820; border: 1px solid var(--border-color); border-radius: 10px; width: 100%; margin: 8px 0; padding: 0 12px; }
.input-group input { background: transparent; border: none; padding: 12px 0; width: 100%; font-size: 14px; color: #e3ebd6; outline: none; }
.input-group i { color: #58695f; margin-right: 10px; }
.btn-primary { background: #3d5a45; color: white; border: none; padding: 12px 24px; border-radius: 10px; cursor: pointer; font-weight: 600; width: 100%; transition: opacity 0.2s; }
.btn-primary:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 2px solid white; color: white; padding: 10px 24px; border-radius: 10px; cursor: pointer; font-weight: 600; }

.form-container { position: absolute; top: 0; height: 100%; transition: all 0.5s ease-in-out; }
.sign-in { left: 0; width: 50%; z-index: 2; }
.container.active .sign-in { transform: translateX(100%); }
.sign-up { left: 0; width: 50%; opacity: 0; z-index: 1; }
.container.active .sign-up { transform: translateX(100%); opacity: 1; z-index: 5; }
.toggle-container { position: absolute; top: 0; left: 50%; width: 50%; height: 100%; overflow: hidden; transition: all 0.5s ease-in-out; z-index: 1000; }
.container.active .toggle-container { transform: translateX(-100%); }
.toggle { height: 100%; background: #3d5a45; color: white; position: relative; left: -100%; width: 200%; transform: translateX(0); transition: all 0.5s ease-in-out; }
.container.active .toggle { transform: translateX(50%); }
.toggle-panel { position: absolute; width: 50%; height: 100%; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 0 30px; text-align: center; }
.toggle-left { transform: translateX(-200%); }
.container.active .toggle-left { transform: translateX(0); }
.toggle-right { right: 0; transform: translateX(0); }
.container.active .toggle-right { transform: translateX(200%); }

/* Window Structure & Layouts */
.app-window { display: flex; width: 100vw; height: 100vh; background: var(--bg-main); color: var(--text-primary); position: fixed; top: 0; left: 0; }
.app-sidebar { width: 280px; background: var(--bg-sidebar); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; height: 100%; }
.sidebar-top { padding: 20px; display: flex; align-items: center; }
.friends-nav-box { padding: 0 12px 12px; border-bottom: 1px solid var(--border-color); }

.sidebar-menu { flex: 1; padding: 16px 8px; display: flex; flex-direction: column; overflow: hidden; }
.menu-header { font-size: 10px; font-weight: 700; color: var(--text-light); letter-spacing: 0.5px; margin-bottom: 8px; padding-left: 12px; }
.menu-list { list-style: none; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.menu-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--text-muted); font-size: 14px; font-weight: 500; cursor: pointer; transition: background 0.15s; }
.menu-list li:hover { background: var(--bg-input); color: var(--text-primary); }
.menu-list li.active-item { background: var(--accent-green); color: white; }

/* User Bar Section */
.sidebar-user { padding: 12px; background: var(--bg-user-bar); border-top: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; }
.user-details { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px; border-radius: 6px; width: calc(100% - 40px); overflow: hidden; }
.user-details:hover { background: var(--bg-input); }
.avatar-wrapper { position: relative; display: inline-flex; shrink: 0; align-items: center; }
.user-avatar-circle { width: 36px; height: 36px; background: var(--accent-green); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: white; font-size: 14px; text-transform: uppercase; background-size: cover; background-position: center; }
.user-avatar-circle.small { width: 32px; height: 32px; font-size: 12px; }
.user-avatar-circle.giant { width: 72px; height: 72px; font-size: 24px; border: 4px solid var(--bg-sidebar); }

.status-dot { position: absolute; bottom: -2px; right: -2px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--bg-user-bar); z-index: 2; box-shadow: 0 0 0 2px rgba(0,0,0,0.25); }
.status-dot.online { background: var(--discord-online); }
.status-dot.idle { background: var(--discord-idle); }
.status-dot.dnd { background: var(--discord-dnd); }
.status-dot.invisible { background: var(--discord-invisible); }
.status-dot.offline { background: var(--discord-invisible); }

.user-meta-block { display: flex; flex-direction: column; overflow: hidden; }
.user-meta-block span { font-size: 13px; font-weight: 600; color: var(--text-primary); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.user-meta-block small { font-size: 11px; color: var(--text-light); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.btn-action-circle { background: transparent; border: none; color: var(--text-light); font-size: 15px; cursor: pointer; padding: 6px; border-radius: 50%; }
.btn-action-circle:hover { color: var(--text-primary); background: var(--bg-input); }

/* Main Chat Panels Layout */
.app-chat-main { flex: 1; background: var(--bg-chat); display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.sub-view-container { display: flex; flex-direction: column; height: 100%; width: 100%; overflow: hidden; }

.tab-header, .chat-main-header { height: 60px; min-height: 60px; padding: 0 24px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; background: var(--bg-main); width: 100%; }
.active-chat-info { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.header-left-group { display: flex; align-items: center; gap: 16px; width: 100%; }
.header-left-group h2, .active-chat-info h2 { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.v-separator { width: 1px; height: 20px; background: var(--border-color); }
.icon-muted { color: var(--text-light); font-size: 16px; }
.friends-sub-nav { display: flex; gap: 8px; align-items: center; }
.sub-nav-btn { background: transparent; border: none; padding: 6px 12px; border-radius: 6px; font-size: 14px; font-weight: 500; color: var(--text-muted); cursor: pointer; transition: background 0.15s; }
.sub-nav-btn:hover { background: var(--bg-input); color: var(--text-primary); }
.sub-nav-btn.active { background: var(--border-color); color: var(--text-primary); font-weight: 600; }
.sub-nav-btn.btn-success-tab { color: var(--discord-online); }
.sub-nav-btn.btn-success-tab.active { background: var(--discord-online); color: white; }

/* Grid Cadrage Amis */
.tab-content-body { flex: 1; padding: 24px; overflow-y: auto; width: 100%; }
.friends-list-wrapper { display: flex; flex-direction: column; gap: 8px; max-width: 1000px; margin: 0 auto; width: 100%; }

/* Petite barre/séparateur de catégorie dans l'onglet En attente */
.pending-separator { font-size: 11px; font-weight: 700; color: var(--text-light); letter-spacing: 0.5px; margin: 14px 0 6px 4px; text-transform: uppercase; border-bottom: 1px solid var(--border-color); padding-bottom: 6px; }

.friend-row-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 12px; transition: border-color 0.15s, transform 0.1s; }
.friend-row-item:hover { border-color: var(--text-light); }
.friend-row-left { display: flex; align-items: center; gap: 14px; cursor: pointer; flex: 1; overflow: hidden; }
.friend-name-details { display: flex; flex-direction: column; overflow: hidden; }
.friend-name-details strong { font-size: 14px; color: var(--text-primary); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.friend-name-details small { font-size: 12px; color: var(--text-light); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; margin-top: 2px; }
.friend-row-actions { display: flex; gap: 8px; align-items: center; shrink: 0; }
.btn-action-square { height: 36px; width: 36px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-input); color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; transition: all 0.15s; }
.btn-action-square:hover { color: var(--text-primary); border-color: var(--text-light); background: var(--border-color); }
.btn-action-square.danger-btn:hover { color: var(--discord-dnd); border-color: var(--discord-dnd); background: rgba(242, 63, 67, 0.1); }

/* Form Add Layout */
.add-friend-panel { max-width: 550px; display: flex; flex-direction: column; gap: 12px; margin: 0 auto; width: 100%; }
.add-friend-panel h3 { font-size: 13px; font-weight: 700; color: var(--text-primary); letter-spacing: 0.5px; }
.add-friend-panel p { font-size: 13px; color: var(--text-muted); }
.add-friend-input-row { display: flex; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 10px; padding: 6px; align-items: center; }
.add-friend-input-row input { flex: 1; background: transparent; border: none; outline: none; padding: 0 12px; font-size: 14px; color: var(--text-primary); }
.add-friend-input-row .btn-primary { width: auto; border-radius: 8px; padding: 10px 24px; font-size: 13.5px; }

/* Chat Box Structure */
.chat-messages-box { flex: 1; padding: 24px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; width: 100%; box-sizing: border-box; }
.msg-wrapper { display: flex; flex-direction: column; max-width: 65%; padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.msg-wrapper strong { font-size: 12px; margin-bottom: 4px; opacity: 0.85; font-weight: 600; }
.msg-wrapper.sent { background: var(--accent-green); color: white; align-self: flex-end; border-bottom-right-radius: 2px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.msg-wrapper.received { background: var(--bg-input); color: var(--text-primary); align-self: flex-start; border-bottom-left-radius: 2px; border: 1px solid var(--border-color); }

.chat-main-footer { padding: 18px 24px; background: var(--bg-main); border-top: 1px solid var(--border-color); width: 100%; }
#chat-form { display: flex; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 12px; padding: 4px 6px 4px 16px; align-items: center; max-width: 1100px; margin: 0 auto; width: 100%; }
#chat-form input { flex: 1; background: transparent; border: none; outline: none; padding: 12px 0; font-size: 14px; color: var(--text-primary); }
.btn-primary-send { height: 40px; width: 40px; border-radius: 10px; border: none; background: var(--accent-green); color: white; cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; transition: background 0.15s; }
.btn-primary-send:hover { opacity: 0.9; }

/* ── En-tête du chat : actions à droite (personnalisation) ────────── */
.chat-header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ── Fond de conversation personnalisé (par ami, partagé via le serveur, chiffré) ─── */
.chat-messages-box.has-conv-bg { background-size: cover; background-position: center; position: relative; }
.chat-messages-box.has-conv-bg::before { content: ""; position: absolute; inset: 0; background: var(--bg-chat); opacity: .82; z-index: 0; pointer-events: none; }
.chat-messages-box.has-conv-bg > * { position: relative; z-index: 1; }
.msg-wrapper.sent { background: var(--my-conv-accent, var(--accent-green)); }
.msg-wrapper.received { background: var(--peer-conv-accent, var(--bg-input)); }

/* ── Édition / suppression / réactions sur un message ──────────────── */
.msg-wrapper { position: relative; user-select: none; -webkit-user-select: none; transition: outline-color .12s, box-shadow .12s; outline: 2px solid transparent; outline-offset: 2px; }
.msg-header-row { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.msg-pin-indicator { font-size: 11px; opacity: 0.75; }
.msg-edited-tag {
    font-size: 10px; font-style: italic; opacity: 0.65; white-space: nowrap;
}

/* Message sélectionné (menu d'actions ouvert dessus) : mise en évidence
   visible, comme sur Discord, pour qu'on voie clairement sur quel message
   on s'apprête à agir. */
.msg-wrapper.msg-selected {
    outline-color: rgba(255,255,255,0.55);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.15), 0 4px 14px rgba(0,0,0,0.25);
}
.msg-wrapper.received.msg-selected { outline-color: var(--accent-green); }

/* Séparateur de jour dans le fil de discussion */
.day-divider { display: flex; align-items: center; gap: 12px; margin: 6px 0 2px; align-self: stretch; user-select: none; }
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--border-color); }
.day-divider span {
    font-size: 11px; font-weight: 700; color: var(--text-light); letter-spacing: .3px;
    padding: 3px 10px; border-radius: 20px; background: var(--bg-input); border: 1px solid var(--border-color);
    white-space: nowrap;
}

.msg-reactions-bar { display: none; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.msg-reaction-pill {
    background: rgba(0,0,0,0.18); border-radius: 12px; padding: 1px 8px; font-size: 12px;
    cursor: pointer; line-height: 1.6;
}
.msg-reaction-pill.mine { background: rgba(255,255,255,0.35); }
.msg-reaction-pill:hover { filter: brightness(1.15); }

/* ── Menu d'actions flottant (carré, façon Discord) ─────────────────── */
.msg-action-menu {
    position: fixed; z-index: 900; background: var(--bg-sidebar); border: 1px solid var(--border-color);
    border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); overflow: hidden; min-width: 200px;
    display: flex; flex-direction: column; padding: 6px;
}
.msg-action-menu .msg-reaction-picker { display: flex; gap: 2px; padding: 4px 2px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border-color); justify-content: space-between; }
.msg-action-menu .msg-reaction-picker button {
    font-size: 19px; background: none; border: none; cursor: pointer; padding: 5px 7px; border-radius: 8px; line-height: 1;
}
.msg-action-menu .msg-reaction-picker button:hover { background: var(--bg-input); transform: scale(1.15); }
.msg-action-menu button.msg-action-item {
    display: flex; align-items: center; gap: 10px; background: none; border: none; text-align: left;
    padding: 9px 10px; font-size: 13.5px; color: var(--text-primary); border-radius: 8px; cursor: pointer;
}
.msg-action-item i { width: 16px; text-align: center; opacity: 0.85; font-size: 13px; }
.msg-action-menu button.msg-action-item:hover { background: var(--bg-input); }
.msg-action-menu button.msg-action-item.danger { color: #f23f43; }
.msg-action-menu button.msg-action-item.danger i { opacity: 1; }

/* ── Panneau des messages épinglés ───────────────────────────────────── */
.pinned-msg-item { display: flex; gap: 10px; padding: 10px 8px; border-radius: 10px; cursor: pointer; align-items: flex-start; }
.pinned-msg-item:hover { background: var(--bg-input); }
.pinned-msg-item .pinned-msg-body { flex: 1; min-width: 0; }
.pinned-msg-item .pinned-msg-meta { font-size: 11.5px; color: var(--text-light); margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
.pinned-msg-item .pinned-msg-text { font-size: 13.5px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pinned-msg-item .btn-unpin { background: none; border: none; color: var(--text-light); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 13px; }
.pinned-msg-item .btn-unpin:hover { color: #f23f43; background: var(--bg-input); }
.pinned-empty-state { font-size: 13px; color: var(--text-light); text-align: center; padding: 24px 10px; }

/* Bref flash de repérage quand on clique un message épinglé pour y aller */
@keyframes msgFlashHighlight {
    0% { outline-color: var(--accent-green); box-shadow: 0 0 0 4px rgba(46,204,113,0.25); }
    100% { outline-color: transparent; box-shadow: none; }
}
.msg-wrapper.msg-flash { animation: msgFlashHighlight 1.6s ease-out; }

.edit-message-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 20px; background: var(--bg-input); border-top: 1px solid var(--border-color);
    font-size: 12.5px; color: var(--text-muted);
}
.edit-message-banner button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.edit-message-banner button:hover { color: var(--text-primary); }

/* ── Menu "+" (joindre un fichier) ──────────────────────────────────── */
.attach-menu-wrap { position: relative; }
.attach-dropdown-menu {
    position: absolute; bottom: calc(100% + 8px); left: 0; min-width: 190px;
    background: var(--bg-sidebar); border: 1px solid var(--border-color); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35); overflow: hidden; z-index: 500;
}
.attach-dropdown-menu button {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px;
    background: transparent; border: none; color: var(--text-primary); font-size: 13px;
    font-weight: 600; cursor: pointer; text-align: left;
}
.attach-dropdown-menu button:hover { background: var(--bg-input); }
.attach-dropdown-menu button i { width: 16px; color: var(--text-muted); }

/* ── Bandeau de prévisualisation des fichiers en attente d'envoi ──── */
.attach-preview-strip {
    display: flex; gap: 10px; padding: 10px 24px; overflow-x: auto;
    border-top: 1px solid var(--border-color); background: var(--bg-main); flex-shrink: 0;
}
.attach-preview-item {
    position: relative; flex-shrink: 0; width: 64px; height: 64px; border-radius: 10px;
    overflow: hidden; background: var(--bg-input); border: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: center;
}
.attach-preview-item img, .attach-preview-item video { width: 100%; height: 100%; object-fit: cover; }
.attach-preview-item .file-generic-icon { font-size: 20px; color: var(--text-muted); }
.attach-preview-item .attach-remove-btn {
    position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
    background: rgba(0,0,0,0.65); color: #fff; border: none; font-size: 10px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; line-height: 1;
}
.attach-preview-item .attach-size-tag {
    position: absolute; bottom: 0; left: 0; right: 0; font-size: 9px; text-align: center;
    background: rgba(0,0,0,0.6); color: #fff; padding: 1px 0;
}

/* ── Personnalisation de conversation : swatches de couleur ───────── */
.conv-accent-swatches { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.conv-accent-swatch {
    width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid transparent;
    transition: transform .1s;
}
.conv-accent-swatch:hover { transform: scale(1.1); }
.conv-accent-swatch.active { border-color: var(--text-primary); }
.conv-bg-preview {
    margin-top: 8px; height: 90px; border-radius: 10px; background: var(--bg-input);
    border: 1px dashed var(--border-color); background-size: cover; background-position: center;
    display: flex; align-items: center; justify-content: center; color: var(--text-light); font-size: 12px;
}

/* ── Pièces jointes affichées dans les messages ─────────────────────── */
.msg-attachment-image { max-width: 260px; max-height: 260px; border-radius: 10px; cursor: pointer; display: block; margin-top: 4px; }
.msg-attachment-video { max-width: 280px; max-height: 280px; border-radius: 10px; display: block; margin-top: 4px; }
.msg-attachment-file {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
    background: rgba(0,0,0,0.15); margin-top: 4px; min-width: 200px; cursor: pointer;
}
.msg-attachment-file i { font-size: 20px; opacity: .85; }
.msg-attachment-file .file-meta { display: flex; flex-direction: column; overflow: hidden; }
.msg-attachment-file .file-meta strong { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.msg-attachment-file .file-meta small { font-size: 11px; opacity: .75; }
.msg-attachment-loading { font-size: 12px; opacity: .7; font-style: italic; margin-top: 4px; }

/* Lightbox simple pour l'aperçu image en plein écran */
#attachment-lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 200000; display: none; align-items: center; justify-content: center; cursor: zoom-out; }
#attachment-lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 6px; }

/* Settings Layout */
.settings-fullscreen-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: var(--bg-main); z-index: 9999; }
.settings-layout { display: flex; width: 100%; height: 100%; }
.settings-sidebar { width: 30%; background: var(--bg-sidebar); display: flex; justify-content: flex-end; padding: 40px 30px 40px 20px; border-right: 1px solid var(--border-color); }
.settings-menu-group { width: 190px; display: flex; flex-direction: column; gap: 2px; }
.settings-menu-label { font-size: 10px; font-weight: 700; color: var(--text-light); padding: 6px; }
.settings-menu-separator { height: 1px; background: var(--border-color); margin: 6px; }
.settings-nav-item {
    background: transparent; border: none; border-radius: 6px; padding: 10px 10px;
    text-align: left; font-size: 13.5px; font-weight: 500; color: var(--text-muted); cursor: pointer;
    display: flex; align-items: center; gap: 12px;
}
.settings-nav-icon { width: 18px; text-align: center; color: var(--text-light); font-size: 14px; flex-shrink: 0; }
.settings-nav-item span { flex: 1; text-align: left; }
.settings-nav-chevron { color: var(--text-light); font-size: 12px; flex-shrink: 0; }
.settings-nav-item:hover, .settings-nav-item.active { background: var(--bg-input); color: var(--text-primary); }
.settings-nav-item.active .settings-nav-icon,
.settings-nav-item:hover .settings-nav-icon { color: var(--text-primary); }
.settings-nav-item.danger-item { color: var(--discord-dnd); }
.settings-nav-item.danger-item .settings-nav-icon { color: var(--discord-dnd); }

.settings-content-area { flex: 1; background: var(--bg-main); padding: 40px; }
.settings-view-wrapper { max-width: 600px; }
.settings-section-content h2 { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 20px; }
.account-card-preview { background: var(--bg-sidebar); border-radius: 12px; border: 1px solid var(--border-color); overflow: hidden; }
.account-banner { height: 80px; background: var(--accent-green); }
.account-info-row { display: flex; align-items: flex-end; gap: 16px; padding: 0 20px; margin-top: -36px; margin-bottom: 16px; }
.account-name-meta h3 { font-size: 16px; color: var(--text-primary); }
.account-name-meta p { font-size: 12px; color: var(--text-light); }
.account-details-box { padding: 20px; background: var(--bg-user-bar); border-top: 1px solid var(--border-color); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-item { display: flex; flex-direction: column; gap: 6px; }
.form-item.full-width { grid-column: span 2; }
.form-item label { font-size: 10px; font-weight: 700; color: var(--text-light); }
.form-item input, .form-item textarea, .form-item select { background: var(--bg-input); border: 1px solid var(--border-color); padding: 10px; border-radius: 8px; outline: none; font-size: 13px; color: var(--text-primary); width: 100%; }
.form-item input[type="color"] { width: 50px; height: 35px; padding: 2px; cursor: pointer; }

.theme-cards-container { display: flex; gap: 12px; }
.theme-card-select { flex: 1; padding: 14px; border-radius: 8px; border: 2px solid var(--border-color); cursor: pointer; font-weight: 600; font-size: 13px; text-align: center; }
.theme-card-select.light { background: #c2cdc1; color: #1b2e1e; }
.theme-card-select.dark { background: #0a0e0c; color: #e3ebd6; }
.theme-card-select.active { border-color: var(--accent-green); }

/* FIX FENÊTRE PARAMÈTRES : JUSTE LA CROIX, ULTRA PROPRE ET MODERNE */
.just-cross-btn-absolute { position: absolute; top: 20px; right: 24px; background: transparent; border: none; color: var(--text-light); cursor: pointer; font-size: 20px; padding: 8px; border-radius: 50%; transition: background 0.15s, color 0.15s; display: flex; align-items: center; justify-content: center; z-index: 10000; }
.just-cross-btn-absolute:hover { color: var(--text-primary); background: var(--bg-input); }

/* Floating Profile Cards Popovers */
.popover-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 100000; display: flex; align-items: center; justify-content: center; }
.popover-card { width: 320px; background: var(--bg-sidebar); border-radius: 16px; border: 1px solid var(--border-color); overflow: hidden; box-shadow: 0 12px 36px rgba(0,0,0,0.6); position: relative; }
.popover-banner { height: 64px; background: var(--accent-green); }
.popover-avatar-wrap { padding-left: 18px; margin-top: -36px; margin-bottom: 12px; }
.popover-body { padding: 18px; background: var(--bg-main); }
.popover-username { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.popover-act { font-size: 12.5px; color: var(--text-light); margin-top: 4px; }
.popover-divider { height: 1px; background: var(--border-color); margin: 14px 0; }
.popover-body h4 { font-size: 10px; color: var(--text-light); margin-bottom: 6px; font-weight: 700; }
.popover-bio-text { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* Ajouts intégration backend (auth réelle / profils / admin) */
.error-msg { background: rgba(242, 63, 67, 0.12); border: 1px solid var(--discord-dnd); color: var(--discord-dnd); font-size: 12.5px; font-weight: 600; padding: 8px 12px; border-radius: 8px; width: 100%; margin: 6px 0; }
.toggle-password { margin-left: auto; color: var(--text-light); }
.btn-outline-small { background: transparent; border: 1px solid var(--border-color); color: var(--text-primary); padding: 8px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-outline-small:hover { background: var(--bg-input); }
.role-badge-admin { background: var(--discord-dnd); color: white; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; margin-left: 6px; text-transform: uppercase; vertical-align: middle; }
.banned-row { opacity: .55; }

/* Spinner de chargement (boutons login/register) */
.btn-spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff; border-radius: 50%; animation: btn-spin 0.7s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
.btn-primary:disabled { opacity: 0.75; cursor: default; }

/* Bloc identité (nom d'affichage + identifiant) en lecture seule, empilés */
.identity-display-block { display: flex; flex-direction: column; gap: 14px; }
.identity-row { display: flex; flex-direction: column; }
.identity-info label { font-size: 10px; font-weight: 700; color: var(--text-light); margin-bottom: 4px; display: block; }
.identity-value { font-size: 15px; font-weight: 600; color: var(--text-primary); background: var(--bg-input); border: 1px solid var(--border-color); padding: 10px 12px; border-radius: 8px; margin: 0; }
.badge-notif-small {
    background: var(--discord-dnd, #f23f43);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    line-height: 1;
}

.friend-list-section-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-light);
    font-weight: 700;
    margin: 16px 4px 8px 4px;
    letter-spacing: 0.5px;
    width: 100%;
}

.avatar, .user-avatar, .friend-item img, .chat-message img, .contact-avatar, .msg-header img {
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    flex-shrink: 0 !important;
}
.unread-message-badge {
    position: absolute;
    top: 6px;
    right: 12px;
    background-color: var(--accent-green, #3d5a45);
    color: var(--text-primary, #e3ebd6);
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 5;
}

/* Container et bouton 3 points */
.profile-actions-dropdown-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.more-profile-btn {
    background: rgba(0, 0, 0, 0.5) !important;
    color: var(--text-primary) !important;
    width: 32px;
    height: 32px;
    font-size: 14px;
}
.more-profile-btn:hover {
    background: rgba(0, 0, 0, 0.8) !important;
}

/* Menu déroulant */
.profile-dropdown-menu {
    position: absolute;
    right: 0;
    top: 38px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 1000;
    width: 180px;
    padding: 6px;
}
.dropdown-item {
    width: 100%;
    background: transparent;
    border: none;
    padding: 8px 12px;
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}
.dropdown-item:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}
.dropdown-item.danger-item {
    color: var(--discord-dnd);
}
.dropdown-item.danger-item:hover {
    background: rgba(242, 63, 67, 0.1);
}

/* Onglets du Profil */
.profile-tabs-nav {
    display: flex;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
}
.profile-tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 0;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    text-transform: uppercase;
}
.profile-tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-green);
}

/* Listes d'amis/groupes communs */
.mutual-title {
    font-size: 10px;
    color: var(--text-light);
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.mutuals-list-mini {
    max-height: 100px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mutual-item-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border-radius: 6px;
    background: var(--bg-input);
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
}
.mutual-item-row:hover {
    background: var(--border-color);
}

.profile-top-actions {
    position: absolute !important;
    top: 15px !important;
    right: 15px !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
    z-index: 99999 !important;
}

.profile-actions-dropdown-container {
    position: relative;
    display: flex;
    align-items: center;
}

.btn-action-circle.more-profile-btn,
.btn-action-circle.close-profile-btn {
    background: rgba(0, 0, 0, 0.5) !important;
    color: var(--text-primary) !important;
    border: none !important;
    width: 34px;
    height: 34px;
    font-size: 14px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-action-circle.more-profile-btn:hover {
    background: rgba(0, 0, 0, 0.8) !important;
}

.btn-action-circle.close-profile-btn:hover {
    background: #f23f43 !important; /* Devient rouge Discord au survol */
}

/* Menu déroulant bien calé sous les 3 points */
.profile-dropdown-menu {
    position: absolute;
    right: 0;
    top: 40px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 1000;
    width: 180px;
    padding: 6px;
}

.more-profile-btn, .close-profile-btn {
    width: 36px !important;
    height: 36px !important;
    cursor: pointer !important;
    pointer-events: auto !important; /* Indique au navigateur d'intercepter le clic ici */
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE MOBILE
   Tout ce qui suit est additif et scopé à des @media : rien ici ne
   modifie le rendu desktop existant (>860px).
   ═══════════════════════════════════════════════════════════════ */

/* Hauteur d'écran fiable sur mobile : la barre d'adresse qui
   apparaît/disparaît fausse `100vh` sur la plupart des navigateurs
   mobiles (le contenu saute / est coupé). `100dvh` s'ajuste à la
   zone réellement visible. On garde 100vh en repli pour les
   navigateurs qui ne supportent pas dvh — aucun impact desktop. */
body,
.app-window,
.settings-fullscreen-overlay,
.popover-overlay {
    height: 100vh;
    height: 100dvh;
}

/* Boutons "retour" / actions mobiles : invisibles sur desktop, la
   barre latérale et les deux colonnes y sont toujours affichées. */
.mobile-back-btn,
.mobile-fab-add,
.settings-mobile-back,
.mobile-switch-line { display: none; }

@media (max-width: 860px) {

    /* ── Empêche le zoom automatique iOS Safari sur les champs
       de saisie (se déclenche dès que font-size < 16px). ── */
    input, textarea, select { font-size: 16px !important; }

    /* ── Cibles tactiles plus grandes (44px recommandé) ── */
    .btn-action-circle, .btn-action-square { min-width: 40px; min-height: 40px; }
    .btn-action-circle:active, .btn-action-square:active,
    .sub-nav-btn:active, .friend-row-item:active,
    .settings-nav-item:active, .btn-primary:active { opacity: 0.7; }

    /* ─────────────────────────────────────────────
       ÉCRAN DE CONNEXION / INSCRIPTION
       Refonte complète pour mobile : plus de panneau coulissant
       768px (illisible sur téléphone). Écran plein, épuré, centré,
       avec un simple lien texte pour basculer connexion/inscription.
       ───────────────────────────────────────────── */
    body { background: var(--bg-main, #0f1612); }

    .container {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        min-height: unset;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: transparent;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }

    .container form {
        background: transparent;
        padding: 0 28px;
        height: auto;
        min-height: unset;
        flex-shrink: 0;
        justify-content: center;
        gap: 2px;
        width: 100%;
        margin: auto 0;
    }

    .container .brand-badge {
        align-self: center;
        margin-bottom: 22px;
    }
    .container h1 {
        font-size: 22px;
        text-align: center;
        margin-bottom: 26px;
    }

    /* Un seul des deux formulaires affiché à la fois, en flux
       normal (fini l'overlay absolu + transform pensé pour desktop).
       flex:1 + justify-content:center permet au formulaire actif de
       remplir toute la hauteur restante de l'écran et de centrer
       verticalement son contenu (au lieu de rester collé en haut). */
    .form-container {
        position: relative;
        width: 100%;
        flex: 1 1 auto;
        min-height: 0;
        top: auto;
        left: auto !important;
        transform: none !important;
        transition: none;
        opacity: 1 !important;
        z-index: auto !important;
        display: none;
        flex-direction: column;
        justify-content: center;
    }
    .sign-in { display: flex; }
    .container.active .sign-in { display: none; }
    .container.active .sign-up { display: flex; }

    /* Le panneau vert "Espace sécurisé" coulissant n'a plus de sens
       en pile verticale : remplacé par un lien discret sous le
       bouton (voir .mobile-switch-line), le panneau lui-même est retiré. */
    .toggle-container { display: none; }

    .mobile-switch-line {
        display: block;
        text-align: center;
        font-size: 13.5px;
        color: var(--text-muted);
        margin: 18px 0 32px;
    }
    .mobile-switch-line a {
        color: var(--text-primary);
        font-weight: 700;
        text-decoration: none;
    }
    .mobile-switch-line a:active { opacity: 0.7; }

    /* ─────────────────────────────────────────────
       INTERFACE PRINCIPALE — navigation une-vue-à-la-fois
       Sur desktop, sidebar (amis/discussions) et contenu (chat,
       profil, admin) sont côte à côte. Sur mobile il n'y a pas la
       place : on affiche l'un OU l'autre, avec un bouton "retour".
       Piloté par la classe .mobile-content-active sur #app-screen
       (ajoutée par switchMainView() dans app.js), sans quoi cette
       règle n'a aucun effet.
       ───────────────────────────────────────────── */
    .app-sidebar { width: 100%; }
    #app-screen.mobile-content-active .app-sidebar { display: none; }
    #app-screen:not(.mobile-content-active) .app-chat-main { display: none; }

    .mobile-back-btn { display: flex; }

    /* ── En-têtes ── */
    .tab-header, .chat-main-header {
        padding: 0 14px;
        height: auto;
        min-height: 58px;
        flex-wrap: wrap;
        row-gap: 10px;
        padding-top: 12px;
        padding-bottom: 12px;
    }
    .header-left-group { flex-wrap: wrap; gap: 10px; align-items: center; }
    .header-left-group h2, .active-chat-info h2 { font-size: 15px; }
    .v-separator { display: none; }

    /* ── Barre d'onglets Amis : défilement horizontal propre,
       le bouton "Ajouter" en est retiré (remplacé par le bouton +
       toujours visible dans l'en-tête, voir .mobile-fab-add). ── */
    .friends-sub-nav {
        flex: 1 1 auto;
        min-width: 0;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .friends-sub-nav::-webkit-scrollbar { display: none; }
    .sub-nav-btn { flex-shrink: 0; padding: 7px 12px; font-size: 13px; }
    .sub-nav-btn[data-tab="add"] { display: none; }

    /* Bouton "+" toujours accessible pour ajouter un ami, jamais
       caché dans une liste d'onglets qui défile. */
    .mobile-fab-add {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        flex-shrink: 0;
        border-radius: 10px;
        border: none;
        background: var(--accent-green);
        color: #fff;
        font-size: 15px;
        cursor: pointer;
        margin-left: auto;
    }
    .mobile-fab-add:active { opacity: 0.8; }

    /* ── Contenu : marges réduites pour laisser de la place ── */
    .tab-content-body { padding: 16px; }
    .chat-messages-box { padding: 16px; }
    .chat-main-footer { padding: 12px 14px; }
    .msg-wrapper { max-width: 82%; }
    .friend-row-item { padding: 10px 12px; }
    .friend-row-actions { gap: 6px; }

    /* Panneau "Ajouter un ami" : occupe tout l'espace disponible,
       champ + bouton empilés pour rester confortables au pouce. */
    .add-friend-panel { padding-top: 4px; }
    .add-friend-input-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        background: transparent;
        border: none;
        padding: 0;
    }
    .add-friend-input-row input {
        background: var(--bg-input);
        border: 1px solid var(--border-color);
        border-radius: 10px;
        padding: 12px 14px;
    }
    .add-friend-input-row .btn-primary {
        width: 100%;
        border-radius: 10px;
        padding: 13px 24px;
    }

    /* ─────────────────────────────────────────────
       PARAMÈTRES — vraie navigation liste → détail
       La liste des sections occupe tout l'écran ; taper une section
       l'ouvre plein écran avec un bouton retour (classe
       .mobile-section-open ajoutée par app.js sur #settings-layout).
       ───────────────────────────────────────────── */
    .settings-layout { flex-direction: column; position: relative; height: 100%; }

    .settings-sidebar {
        width: 100%;
        height: 100%;
        justify-content: flex-start;
        padding: 24px 16px;
        border-right: none;
        overflow-y: auto;
    }
    .settings-menu-group { width: 100%; gap: 2px; }
    .settings-menu-label { padding: 14px 10px 8px; }

    .settings-nav-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 13px 10px;
        font-size: 14.5px;
        border-radius: 10px;
    }
    .settings-nav-icon {
        width: 20px;
        text-align: center;
        color: var(--text-light);
        font-size: 15px;
    }
    .settings-nav-item.active .settings-nav-icon,
    .settings-nav-item:hover .settings-nav-icon { color: var(--text-primary); }
    .settings-nav-item span { flex: 1; text-align: left; }
    .settings-nav-chevron { color: var(--text-light); font-size: 12px; }
    .settings-nav-item.danger-item .settings-nav-icon { color: var(--discord-dnd); }

    .settings-content-area {
        display: none;
        position: absolute;
        top: 0; left: 0;
        width: 100%;
        height: 100%;
        padding: 20px;
        overflow-y: auto;
        background: var(--bg-main);
    }
    .settings-layout.mobile-section-open .settings-sidebar { display: none; }
    .settings-layout.mobile-section-open .settings-content-area { display: block; }

    .settings-mobile-back {
        display: flex;
        align-items: center;
        gap: 8px;
        background: transparent;
        border: none;
        color: var(--text-muted);
        font-size: 14px;
        font-weight: 600;
        padding: 8px 4px;
        margin-bottom: 14px;
        cursor: pointer;
    }
    .settings-mobile-back:active { opacity: 0.7; }

    .settings-view-wrapper { max-width: 100%; }
    .just-cross-btn-absolute { top: 10px; right: 10px; }

    .form-grid { grid-template-columns: 1fr; }
    .form-item.full-width { grid-column: span 1; }

    /* ─────────────────────────────────────────────
       POPUPS / MODALES — jamais plus larges que l'écran
       ───────────────────────────────────────────── */
    .popover-overlay { padding: 16px; }
    .popover-card { width: 100% !important; max-width: 420px; }
}

/* Très petits écrans (ex. iPhone SE ~375px et moins) */
@media (max-width: 400px) {
    .theme-cards-container { flex-direction: column; }
    .account-info-row { flex-direction: column; align-items: flex-start; gap: 8px; }
    .popover-avatar-wrap { padding-left: 14px; }
    .container form { padding: 0 20px; }
}
