:root {
    --ig-bg: #000000;
    --ig-text: #F5F5F5;
    --ig-text-secondary: #A8A8A8;
    --ig-border: #262626;
    --ig-blue: #0095F6;
    --ig-highlight: #1A1A1A;
    --app-width: 414px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body { background-color: #111; font-family: var(--font-family); color: var(--ig-text); display: flex; justify-content: center; align-items: center; min-height: 100vh; overflow: hidden;}

.ig-container { width: 100%; max-width: var(--app-width); height: 100dvh; max-height: 896px; background-color: var(--ig-bg); display: flex; flex-direction: column; position: relative; overflow-y: auto; overflow-x: hidden; box-shadow: 0 0 50px rgba(0,0,0,0.8); scrollbar-width: none; }
.ig-container::-webkit-scrollbar { display: none; }

/* HEADER & PROFIL */
.ig-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--ig-border); position: sticky; top: 0; background-color: var(--ig-bg); z-index: 10; }
.header-center h1 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 4px; }
.header-right { display: flex; gap: 16px; }

.ig-profile-info { padding: 16px; }
.profile-stats { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.profile-pic-container { position: relative; width: 85px; height: 85px; cursor: pointer; }
.story-ring { width: 100%; height: 100%; border-radius: 50%; padding: 3px; background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%); }
.profile-pic { width: 100%; height: 100%; border-radius: 50%; border: 3px solid var(--ig-bg); object-fit: cover; background-color: #222;}

.stats-numbers { display: flex; flex: 1; justify-content: space-around; margin-left: 20px; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-count { font-weight: 700; font-size: 16px; }
.stat-label { font-size: 13px; color: var(--ig-text); }

.profile-bio h2 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.profile-bio p { font-size: 14px; line-height: 1.4; white-space: pre-line; }
.bio-link { color: #E0F1FF; text-decoration: none; font-size: 14px; font-weight: 500; display: block; margin-top: 4px; }

.profile-actions { display: flex; gap: 8px; margin-top: 16px; }
.profile-actions button { flex: 1; background-color: var(--ig-highlight); color: var(--ig-text); border: none; padding: 8px 0; border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; }
.profile-actions .btn-icon { flex: 0 0 40px; display: flex; justify-content: center; align-items: center; }

/* HIGHLIGHTS */
.ig-highlights { display: flex; gap: 16px; padding: 0 16px 16px 16px; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; min-height: 95px;}
.ig-highlights::-webkit-scrollbar { display: none; }
.highlight-item { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; width: 65px; flex-shrink: 0;}
.highlight-ring { width: 65px; height: 65px; border-radius: 50%; border: 1px solid var(--ig-border); padding: 3px; flex-shrink: 0;}
.highlight-ring img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background-color: #111; }
.highlight-item span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; text-align: center;}

/* TABS & GRID */
.ig-tabs { display: flex; border-top: 1px solid var(--ig-border); flex-shrink: 0;}
.tab { flex: 1; display: flex; justify-content: center; padding: 12px 0; color: var(--ig-text-secondary); cursor: pointer; }
.tab.active { color: var(--ig-text); border-bottom: 1px solid var(--ig-text); }

/* CORRECTION : L'espace de la grille est ajusté */
.ig-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding-bottom: 2px; /* On enlève le gros padding car la nav est sticky */
}
.grid-item { aspect-ratio: 1 / 1; cursor: pointer; overflow: hidden; position: relative; background-color: #111; }
.grid-item img { width: 100%; height: 100%; object-fit: cover; transition: filter 0.3s ease; }
.grid-item:hover img { filter: brightness(0.65); }
.carousel-icon { position: absolute; top: 8px; right: 8px; color: white; filter: drop-shadow(0 0 2px rgba(0,0,0,0.8)); }

/* CORRECTION : BOTTOM NAV STICKY */
.ig-bottom-nav {
    position: sticky; /* Reste accrochée au bas du scroll, empêche tout chevauchement */
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background-color: var(--ig-bg);
    border-top: 1px solid var(--ig-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 50;
    margin-top: auto; /* Pousse la nav tout en bas si l'écran est grand */
}
.nav-profile-pic { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--ig-text); object-fit: cover; background-color: #111;}

/* MODAL POST INTERACTIF (NOUVELLE STRUCTURE PAGE NATIVE) */
.modal { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 100; overflow: hidden; pointer-events: none; }
.modal.active { pointer-events: auto; }
.modal-content { width: 100%; height: 100%; background-color: var(--ig-bg); transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1); display: flex; flex-direction: column; }
.modal.active .modal-content { transform: translateX(0); }

.modal-header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--ig-border); background: var(--ig-bg); flex-shrink: 0;}
.close-modal { cursor: pointer; }

.modal-body { flex: 1; overflow-y: auto; scrollbar-width: none; padding-bottom: 20px;}
.modal-body::-webkit-scrollbar { display: none; }

.post-user-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.post-user-header img { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--ig-border); object-fit: cover;}

/* CARROUSEL */
.modal-img-container { width: 100%; background-color: #000; position: relative; display: flex; align-items: center; justify-content: center; min-height: 300px; }
#modal-img { width: 100%; max-height: 500px; object-fit: contain; }
.carousel-btn { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.7); color: #000; border: none; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 5px rgba(0,0,0,0.3); z-index: 5; }
.prev-btn { left: 10px; }
.next-btn { right: 10px; }
.carousel-dots { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,0.4); transition: background 0.3s; }
.dot.active { background: #0095F6; }

/* ACTIONS & CAPTION */
.modal-actions { display: flex; justify-content: space-between; padding: 12px 16px 8px 16px; }
.action-icons { display: flex; gap: 16px; }
.like-btn { cursor: pointer; transition: transform 0.2s; }
.like-btn.liked { fill: #ed4956; stroke: #ed4956; animation: likePop 0.3s ease-in-out; }
@keyframes likePop { 0% { transform: scale(1); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }

#modal-likes { padding: 0 16px; font-weight: 600; font-size: 14px; margin-bottom: 8px;}
.modal-caption-container { display: flex; gap: 10px; padding: 0 16px; margin-bottom: 16px;}
.caption-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0;}
.caption-text { font-size: 14px; line-height: 1.4; white-space: pre-line; }

/* COMMENTAIRES */
.comments-divider { padding: 0 16px 16px 16px; font-size: 14px; color: var(--ig-text-secondary); border-bottom: 1px solid var(--ig-border); margin-bottom: 16px; font-weight: 500;}
.modal-comments-section { display: flex; flex-direction: column; }
.comment-block { display: flex; justify-content: space-between; align-items: flex-start; padding: 0 16px; margin-bottom: 20px; }
.comment-left { display: flex; gap: 10px; }
.comment-avatar { width: 32px; height: 32px; border-radius: 50%; background-color: #333; flex-shrink: 0; object-fit: cover; }
.comment-content { font-size: 14px; line-height: 1.4; }
.comment-content strong { font-weight: 600; margin-right: 6px; }
.comment-meta { font-size: 12px; color: var(--ig-text-secondary); margin-top: 6px; display: flex; gap: 16px; font-weight: 500; }
.comment-like { color: var(--ig-text-secondary); width: 14px; height: 14px; margin-top: 8px; flex-shrink: 0;}

/* FOOTER D'AJOUT COMMENTAIRE */
.modal-footer { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--ig-border); background: var(--ig-bg); flex-shrink: 0; padding-bottom: max(12px, env(safe-area-inset-bottom));}
.footer-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.modal-footer input { flex: 1; background: transparent; border: none; color: var(--ig-text); font-size: 14px; outline: none; }
.modal-footer input::placeholder { color: var(--ig-text-secondary); }

/* MODAL STORY PLEIN ECRAN */
.story-modal { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; z-index: 200; display: none; flex-direction: column; }
.story-modal.active { display: flex; }
.story-progress-container { width: 100%; height: 2px; background: rgba(255,255,255,0.3); position: absolute; top: 10px; left: 0; z-index: 202; }
.story-progress-bar { height: 100%; background: #fff; width: 0%; }
.story-progress-bar.animate { animation: storyFill 5s linear forwards; }
@keyframes storyFill { from { width: 0%; } to { width: 100%; } }

.story-header { position: absolute; top: 20px; left: 0; width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 0 16px; z-index: 202; }
.story-user { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; text-shadow: 0 1px 3px rgba(0,0,0,0.8);}
.story-user img { width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.5);}
.story-time { color: rgba(255,255,255,0.7); font-weight: 400; }
.close-story { font-size: 28px; cursor: pointer; text-shadow: 0 1px 3px rgba(0,0,0,0.8); color: white;}

.story-img-container { flex: 1; display: flex; justify-content: center; align-items: center; position: relative; z-index: 201; background-color: #000; padding: 60px 0;}
#story-img { width: 100%; height: 100%; object-fit: contain; }

.story-reply { position: absolute; bottom: 0; left: 0; width: 100%; padding: 16px; display: flex; gap: 16px; align-items: center; z-index: 202; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);}
.story-reply input { flex: 1; background: transparent; border: 1px solid rgba(255,255,255,0.4); border-radius: 30px; padding: 12px 20px; color: #fff; font-family: var(--font-family);}
.story-reply input::placeholder { color: #fff; }