/* =============================================
   Facebook-Style Comment System - CSS v4
   ============================================= */

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #e9ebee;
    color: #1c1e21;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ---- Topbar ---- */
.topbar {
    background-color: #1877f2;
    color: #fff;
    padding: 0 16px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.topbar-brand {
    font-size: 28px; font-weight: 900; color: #fff;
    text-decoration: none; font-style: italic; letter-spacing: -1px;
}
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar-user select {
    background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.35);
    color: #fff; padding: 5px 10px; border-radius: 6px;
    font-size: 13px; cursor: pointer; outline: none;
}
.topbar-user select option { background: #1877f2; color: #fff; }

/* ---- Layout ---- */
.container { max-width: 680px; margin: 20px auto; padding: 0 12px; }

/* ---- Avatar ---- */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-initials {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; color: #fff; flex-shrink: 0; user-select: none;
}
.avatar-initials.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.sm { width: 32px; height: 32px; }

/* =============================================
   POST COMPOSER
   ============================================= */
.composer-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
    padding: 12px 16px 10px;
    margin-bottom: 16px;
}
.composer-top {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.composer-textarea-wrap {
    flex: 1;
    border: 1px solid #dddfe2;
    border-radius: 22px;
    background: #f0f2f5;
    transition: border-color .2s, background .2s, border-radius .2s;
    overflow: hidden;
}
.composer-textarea-wrap:focus-within {
    border-color: #1877f2;
    background: #fff;
    border-radius: 12px;
}
#post-textarea {
    width: 100%;
    border: none;
    background: transparent;
    padding: 10px 16px 6px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    color: #1c1e21;
    min-height: 44px;
    max-height: 200px;
    overflow-y: auto;
    display: block;
}
#post-textarea::placeholder { color: #8a8d91; }

/* Preview gambar di composer */
.composer-image-preview {
    position: relative;
    margin: 4px 12px 6px;
    display: none;
}
.composer-image-preview.show { display: block; }
.composer-image-preview img {
    max-width: 100%; max-height: 200px;
    border-radius: 8px; object-fit: cover;
    display: block;
}
.composer-image-remove {
    position: absolute; top: 6px; right: 6px;
    background: rgba(0,0,0,.55); color: #fff;
    border: none; border-radius: 50%; width: 24px; height: 24px;
    font-size: 14px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    transition: background .15s;
}
.composer-image-remove:hover { background: rgba(0,0,0,.8); }

/* Toolbar composer bawah */
.composer-toolbar {
    display: flex;
    align-items: center;
    padding: 4px 8px 2px;
    gap: 2px;
    border-top: 1px solid #e4e6eb;
    margin-top: 2px;
}
.composer-tool-btn {
    background: none; border: none; cursor: pointer;
    padding: 6px 7px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
    color: #65676b;
    position: relative;
}
.composer-tool-btn:hover { background: #f0f2f5; }
.composer-tool-btn svg { display: block; }
.composer-tool-btn .tool-tooltip {
    position: absolute; bottom: calc(100% + 6px); left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.75); color: #fff;
    font-size: 11px; font-weight: 600; padding: 3px 8px;
    border-radius: 6px; white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity .12s;
}
.composer-tool-btn:hover .tool-tooltip { opacity: 1; }

/* Spacer dan tombol kirim di toolbar */
.composer-toolbar-spacer { flex: 1; }
.composer-send-btn {
    background: none; border: none; cursor: pointer;
    padding: 6px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #1877f2; transition: background .15s;
}
.composer-send-btn:hover { background: #e7f0fd; }
.composer-send-btn:disabled { color: #bcc0c4; cursor: not-allowed; }
.composer-send-btn:disabled:hover { background: none; }

/* Footer composer (tombol Bagikan besar) */
.composer-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e4e6eb;
}

/* =============================================
   EMOJI PICKER POPUP
   ============================================= */
.emoji-picker-popup {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    z-index: 500;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,.18), 0 1px 6px rgba(0,0,0,.1);
    padding: 10px;
    width: 320px;
    max-height: 280px;
    display: none;
    flex-direction: column;
    animation: pickerFadeIn .15s ease;
}
.emoji-picker-popup.show { display: flex; }
@keyframes pickerFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.emoji-picker-search {
    width: 100%; border: 1px solid #dddfe2; border-radius: 20px;
    padding: 6px 12px; font-size: 13px; outline: none;
    margin-bottom: 8px; font-family: inherit; background: #f0f2f5;
}
.emoji-picker-search:focus { border-color: #1877f2; background: #fff; }
.emoji-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    overflow-y: auto;
    max-height: 200px;
}
.emoji-picker-grid button {
    background: none; border: none; cursor: pointer;
    font-size: 22px; padding: 4px; border-radius: 6px;
    transition: background .1s, transform .1s;
    line-height: 1;
}
.emoji-picker-grid button:hover {
    background: #f0f2f5;
    transform: scale(1.3);
}

/* =============================================
   BUTTONS (umum)
   ============================================= */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 16px; border: none; border-radius: 6px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background .2s, opacity .2s; outline: none; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: #1877f2; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #166fe5; }

/* =============================================
   POST CARD
   ============================================= */
.post-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
    margin-bottom: 16px;
    overflow: visible;
    animation: slideIn .3s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.post-header {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px 8px;
}
.post-header-info { flex: 1; }
.post-username { font-weight: 700; color: #1877f2; font-size: 14px; text-decoration: none; }
.post-username:hover { text-decoration: underline; }
.post-time { font-size: 12px; color: #8a8d91; margin-top: 1px; }
.post-content {
    padding: 4px 16px 10px;
    font-size: 15px; color: #1c1e21;
    line-height: 1.6; word-break: break-word; white-space: pre-wrap;
}
/* Gambar pada post */
.post-image {
    width: 100%; max-height: 400px; object-fit: cover;
    display: block; border-radius: 0;
    margin-bottom: 2px;
}
.post-delete-btn {
    background: none; border: none; color: #8a8d91;
    font-size: 20px; cursor: pointer; padding: 4px 6px;
    border-radius: 50%; line-height: 1;
    transition: background .15s, color .15s;
}
.post-delete-btn:hover { background: #f0f2f5; color: #fa3e3e; }

/* ---- Reaction Summary Bar ---- */
.reaction-summary {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 16px; border-bottom: 1px solid #e4e6eb; min-height: 32px;
}
.reaction-summary-left {
    display: flex; align-items: center; gap: 4px;
    font-size: 13px; color: #65676b; cursor: pointer;
}
.reaction-summary-left:hover { text-decoration: underline; }
.reaction-emoji-stack { display: flex; align-items: center; }
.reaction-emoji-stack .r-icon {
    width: 20px; height: 20px; border-radius: 50%;
    border: 2px solid #fff; margin-left: -4px;
    font-size: 14px; display: flex; align-items: center; justify-content: center;
    line-height: 1; background: #e4e6eb;
}
.reaction-emoji-stack .r-icon:first-child { margin-left: 0; }
.reaction-count { font-size: 13px; color: #65676b; margin-left: 4px; }
.reaction-summary-right { font-size: 13px; color: #65676b; cursor: pointer; }
.reaction-summary-right:hover { text-decoration: underline; }

/* =============================================
   POST ACTIONS BAR (SVG icons)
   ============================================= */
.post-actions {
    display: flex; align-items: stretch;
    padding: 2px 8px; border-bottom: 1px solid #e4e6eb;
}
.action-btn {
    flex: 1; background: none; border: none;
    padding: 8px 4px; border-radius: 6px;
    font-size: 14px; font-weight: 600; color: #65676b;
    cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 7px;
    transition: background .15s, color .15s;
    position: relative; user-select: none; white-space: nowrap;
}
.action-btn:hover { background: #f0f2f5; }

/* SVG icon dalam action button */
.action-btn .btn-svg { display: flex; align-items: center; flex-shrink: 0; }
.action-btn .btn-svg svg { width: 20px; height: 20px; }

/* Like button states */
.like-btn.reacted-like  { color: #1877f2; }
.like-btn.reacted-like  .btn-svg svg { fill: #1877f2; }
.like-btn.reacted-love  { color: #f33e58; }
.like-btn.reacted-love  .btn-svg svg { fill: #f33e58; }
.like-btn.reacted-haha  { color: #f7b928; }
.like-btn.reacted-haha  .btn-svg svg { fill: #f7b928; }
.like-btn.reacted-wow   { color: #f7b928; }
.like-btn.reacted-wow   .btn-svg svg { fill: #f7b928; }
.like-btn.reacted-sad   { color: #f7b928; }
.like-btn.reacted-sad   .btn-svg svg { fill: #f7b928; }
.like-btn.reacted-angry { color: #e9710f; }
.like-btn.reacted-angry .btn-svg svg { fill: #e9710f; }

.comment-action-btn { flex: 1; background: none; border: none; padding: 8px 4px; border-radius: 6px; font-size: 14px; font-weight: 600; color: #65676b; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 7px; transition: background .15s, color .15s; white-space: nowrap; }
.comment-action-btn:hover { background: #f0f2f5; color: #1877f2; }
.comment-action-btn .btn-svg svg { width: 20px; height: 20px; }

.share-action-btn { flex: 1; background: none; border: none; padding: 8px 4px; border-radius: 6px; font-size: 14px; font-weight: 600; color: #65676b; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 7px; transition: background .15s, color .15s; white-space: nowrap; }
.share-action-btn:hover { background: #f0f2f5; color: #42b72a; }
.share-action-btn .btn-svg svg { width: 20px; height: 20px; }

/* =============================================
   REACTION PICKER WRAPPER & POPUP
   ============================================= */
.reaction-picker-wrap {
    position: relative; flex: 1; display: flex; align-items: stretch;
}
.reaction-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) scale(.6);
    transform-origin: bottom center;
    background: #fff;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0,0,0,.22), 0 1px 6px rgba(0,0,0,.12);
    padding: 8px 12px;
    display: flex; gap: 4px; align-items: center;
    z-index: 300; opacity: 0; pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
    white-space: nowrap;
}
.reaction-picker-wrap:hover .reaction-picker,
.reaction-picker.visible {
    opacity: 1; pointer-events: all;
    transform: translateX(-50%) scale(1);
}

/* Reaction picker untuk komentar */
.comment-reaction-picker-wrap {
    position: relative; display: inline-flex; align-items: center;
}
.comment-reaction-picker-wrap .reaction-picker {
    bottom: calc(100% + 6px); left: 0;
    transform: translateX(0) scale(.6);
    transform-origin: bottom left;
}
.comment-reaction-picker-wrap:hover .reaction-picker,
.comment-reaction-picker-wrap .reaction-picker.visible {
    opacity: 1; pointer-events: all;
    transform: translateX(0) scale(1);
}

/* =============================================
   ANIMASI EMOJI
   ============================================= */
@keyframes emojiBounce {
    0%   { transform: scale(1) translateY(0); }
    20%  { transform: scale(1.4) translateY(-8px); }
    40%  { transform: scale(1.2) translateY(-4px); }
    60%  { transform: scale(1.35) translateY(-7px); }
    80%  { transform: scale(1.15) translateY(-2px); }
    100% { transform: scale(1.3) translateY(-6px); }
}
@keyframes emojiWiggle {
    0%,100% { transform: scale(1.3) translateY(-6px) rotate(0deg); }
    25%      { transform: scale(1.3) translateY(-6px) rotate(-10deg); }
    75%      { transform: scale(1.3) translateY(-6px) rotate(10deg); }
}
@keyframes emojiPop {
    0%   { transform: scale(0.5); opacity: 0; }
    60%  { transform: scale(1.25); opacity: 1; }
    80%  { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.reaction-option {
    width: 44px; height: 44px; border-radius: 50%; border: none;
    background: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; line-height: 1;
    transition: transform .15s ease;
    position: relative; padding: 0; flex-shrink: 0;
    animation: emojiPop .3s ease both;
}
.reaction-option:nth-child(1) { animation-delay: 0s; }
.reaction-option:nth-child(2) { animation-delay: .04s; }
.reaction-option:nth-child(3) { animation-delay: .08s; }
.reaction-option:nth-child(4) { animation-delay: .12s; }
.reaction-option:nth-child(5) { animation-delay: .16s; }
.reaction-option:nth-child(6) { animation-delay: .20s; }
.reaction-option:hover {
    animation: emojiBounce .3s ease forwards, emojiWiggle .5s ease .3s infinite;
    z-index: 1;
}
.reaction-option .r-label {
    position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.75); color: #fff; font-size: 11px; font-weight: 600;
    padding: 2px 7px; border-radius: 10px; white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity .12s;
}
.reaction-option:hover .r-label { opacity: 1; }

/* =============================================
   COMMENTS SECTION
   ============================================= */
.comments-section {
    background: #f0f2f5; border-top: 1px solid #e4e6eb;
    padding: 8px 16px 12px; border-radius: 0 0 10px 10px;
}

/* Comment item */
.comment-item {
    display: flex; align-items: flex-start; gap: 8px;
    margin-bottom: 6px; animation: fadeIn .25s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}
.comment-body { flex: 1; min-width: 0; }
.comment-bubble {
    background: #fff; border-radius: 18px; padding: 8px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
    display: inline-block; max-width: 100%; word-break: break-word;
}
.comment-author { font-weight: 700; color: #1877f2; font-size: 13px; text-decoration: none; display: block; }
.comment-author:hover { text-decoration: underline; }
.comment-text { font-size: 13.5px; color: #1c1e21; margin-top: 2px; white-space: pre-wrap; }

/* Badge reaksi komentar */
.comment-reaction-badge {
    display: inline-flex; align-items: center; gap: 2px;
    background: #fff; border: 1px solid #e4e6eb; border-radius: 20px;
    padding: 1px 6px 1px 4px; font-size: 12px; color: #65676b;
    margin-top: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.1);
    cursor: pointer; transition: background .15s; vertical-align: middle;
}
.comment-reaction-badge:hover { background: #f0f2f5; }
.comment-reaction-badge .badge-emojis { font-size: 13px; line-height: 1; }
.comment-reaction-badge .badge-count  { font-size: 12px; color: #65676b; }

/* Meta row komentar */
.comment-meta {
    display: flex; align-items: center; gap: 8px;
    margin-top: 3px; padding-left: 4px; flex-wrap: wrap;
}
.comment-time { font-size: 11px; color: #8a8d91; }

.comment-like-btn,
.comment-reply-btn {
    background: none; border: none; font-size: 12px; font-weight: 700;
    color: #65676b; cursor: pointer; padding: 2px 4px; border-radius: 4px;
    transition: color .15s, background .15s; line-height: 1.4;
}
.comment-like-btn:hover  { color: #1877f2; background: rgba(24,119,242,.08); }
.comment-reply-btn:hover { color: #1877f2; background: rgba(24,119,242,.08); }
.comment-like-btn.reacted-like   { color: #1877f2; }
.comment-like-btn.reacted-love   { color: #f33e58; }
.comment-like-btn.reacted-haha   { color: #f7b928; }
.comment-like-btn.reacted-wow    { color: #f7b928; }
.comment-like-btn.reacted-sad    { color: #f7b928; }
.comment-like-btn.reacted-angry  { color: #e9710f; }

.comment-delete {
    background: none; border: none; color: #fa3e3e;
    font-size: 11px; cursor: pointer; padding: 2px 4px;
    border-radius: 4px; opacity: 0; transition: opacity .2s; font-weight: 700;
}
.comment-item:hover .comment-delete,
.reply-item:hover .comment-delete { opacity: 1; }

/* =============================================
   NESTED REPLIES
   FIX: Sejajar dengan comment bubble pertama (margin-left = lebar avatar + gap)
   ============================================= */
.replies-container {
    /* 32px (avatar sm) + 8px (gap) = 40px — sejajar dengan bubble komentar induk */
    margin-left: 40px;
    margin-top: 4px;
    padding-left: 10px;
    border-left: 2px solid #d8dadf;
}
.reply-item {
    display: flex; align-items: flex-start; gap: 8px;
    margin-bottom: 6px; animation: fadeIn .25s ease;
}
.reply-item .comment-bubble { background: #e9ebee; }

/* Tombol lihat balasan */
.view-replies-btn {
    background: none; border: none; color: #1877f2;
    font-size: 12px; font-weight: 700; cursor: pointer;
    /* Sejajar dengan bubble: 40px (avatar sm + gap) */
    padding: 4px 0 4px 40px;
    display: flex; align-items: center; gap: 4px; transition: color .15s;
}
.view-replies-btn:hover { color: #166fe5; text-decoration: underline; }
.view-replies-btn .vr-icon { font-size: 14px; }

/* Input balasan */
.reply-input-wrap {
    display: flex; align-items: center; gap: 8px;
    margin-top: 6px;
    /* Sejajar dengan bubble: 40px */
    margin-left: 40px;
    animation: fadeIn .2s ease;
}
.reply-input-wrap input[type="text"] {
    flex: 1; border: 1px solid #dddfe2; border-radius: 22px;
    padding: 6px 12px; font-size: 13px; font-family: inherit;
    background: #fff; outline: none; color: #1c1e21; transition: border-color .2s;
}
.reply-input-wrap input[type="text"]:focus { border-color: #1877f2; }
.reply-input-wrap input[type="text"]::placeholder { color: #8a8d91; }
.reply-submit-btn {
    background: #1877f2; color: #fff; border: none; border-radius: 6px;
    padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
    transition: background .2s; white-space: nowrap; flex-shrink: 0;
}
.reply-submit-btn:hover { background: #166fe5; }
.reply-submit-btn:disabled { opacity: .55; cursor: not-allowed; }

/* Comment input */
.comment-input-wrap { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.comment-input-wrap input[type="text"] {
    flex: 1; border: 1px solid #dddfe2; border-radius: 22px;
    padding: 8px 14px; font-size: 13.5px; font-family: inherit;
    background: #fff; outline: none; color: #1c1e21; transition: border-color .2s;
}
.comment-input-wrap input[type="text"]:focus { border-color: #1877f2; }
.comment-input-wrap input[type="text"]::placeholder { color: #8a8d91; }
.comment-submit-btn {
    background: #1877f2; color: #fff; border: none; border-radius: 6px;
    padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: background .2s; white-space: nowrap; flex-shrink: 0;
}
.comment-submit-btn:hover { background: #166fe5; }
.comment-submit-btn:disabled { opacity: .55; cursor: not-allowed; }

/* =============================================
   REALTIME INDICATOR
   ============================================= */
.realtime-indicator {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: #65676b; padding: 6px 0 2px; margin-bottom: 8px;
}
.realtime-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #42b72a; animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .5; transform: scale(.85); }
}

/* =============================================
   TOAST
   ============================================= */
.toast-container {
    position: fixed; bottom: 24px; right: 24px;
    z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
    background: #333; color: #fff; padding: 10px 18px;
    border-radius: 8px; font-size: 13.5px;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    animation: toastIn .3s ease; max-width: 320px;
}
.toast.success { background: #42b72a; }
.toast.error   { background: #fa3e3e; }
.toast.info    { background: #1877f2; }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Spinner */
.spinner {
    display: inline-block; width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff; border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: #8a8d91; }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 600px) {
    .container { padding: 0 4px; }
    .post-content { font-size: 14px; }
    .action-btn span { display: none; }
    .action-btn { padding: 10px 4px; }
    .composer-toolbar { gap: 0; }
}
