* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: #f6f7fb;
    color: #222;
}
img { max-width: 100%; height: auto; display: block; }
.container { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* ---- Navbar ---- */
.navbar { background: #1e1e2f; color: #fff; padding: 14px 0; position: relative; }
.navbar-inner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.logo { color: #fff; font-weight: 700; font-size: 20px; text-decoration: none; }
.nav-toggle {
    display: none; background: none; border: none; color: #fff; font-size: 22px;
    cursor: pointer; padding: 4px 8px;
}
.navbar nav { display: flex; align-items: center; }
.navbar nav a { color: #ddd; text-decoration: none; margin-left: 18px; font-size: 14px; padding: 6px 0; }
.navbar nav a:hover { color: #fff; }

.alert { background: #e7f7ec; border: 1px solid #b6e3c6; color: #1e6b3a; padding: 10px 14px; border-radius: 6px; margin: 16px 0; }
.alert-error { background: #fdecea; border: 1px solid #f5c2bd; color: #c0392b; padding: 10px 14px; border-radius: 6px; margin: 0 0 16px; }
.alert-error p { margin: 2px 0; }
.error { color: #c0392b; font-size: 14px; }
.field-error { color: #c0392b; font-size: 13px; margin: -8px 0 12px; }

main.container { padding: 30px 20px; }

/* ---- Layout / grid ---- */
.layout { display: flex; gap: 24px; align-items: flex-start; }
.sidebar { width: 200px; flex-shrink: 0; }
.sidebar ul { list-style: none; padding: 0; margin: 0; }
.sidebar li { margin-bottom: 6px; }
.sidebar a { text-decoration: none; color: #444; font-size: 14px; }
.sidebar a.active, .sidebar a:hover { color: #4b4bff; font-weight: 600; }

.post-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; min-width: 0; }
.post-card { background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.post-card a { text-decoration: none; color: inherit; }
.post-thumb { width: 100%; height: 140px; object-fit: cover; }
.post-thumb-wrap { position: relative; }
.post-thumb-wrap.video-thumb { height: 140px; background: #1e1e2f; display: flex; align-items: center; justify-content: center; }
.play-badge {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,0.6); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 16px; pointer-events: none;
}
.post-card h4 { margin: 10px 14px 4px; font-size: 16px; word-break: break-word; }
.post-card .meta { margin: 0 14px 14px; font-size: 12px; color: #888; }

.tag { background: #eef0ff; color: #4b4bff; padding: 2px 8px; border-radius: 10px; font-size: 11px; }

.pagination { margin-top: 24px; display: flex; gap: 12px; align-items: center; font-size: 14px; flex-wrap: wrap; }
.pagination a { color: #4b4bff; text-decoration: none; }

/* ---- Forms ---- */
.form-card { background: #fff; max-width: 480px; margin: 0 auto; padding: 30px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.form-card h2 { margin-top: 0; }
.form-card label { display: block; font-size: 13px; font-weight: 600; color: #555; margin-bottom: 4px; }
.form-input, form input[type=text], form input[type=email], form input[type=password], form input[type=file], form input[type=url], form select, form textarea {
    display: block; width: 100%; padding: 10px 12px; margin-bottom: 12px;
    border: 1px solid #ddd; border-radius: 6px; font-size: 16px; font-family: inherit;
}
.btn {
    background: #4b4bff; color: #fff; border: none; padding: 12px 18px;
    border-radius: 6px; font-size: 15px; cursor: pointer; width: 100%;
}
form .btn { width: auto; }
.btn:hover { background: #3939d6; }
.btn.small { padding: 6px 12px; font-size: 12px; display: inline-block; margin-top: 8px; text-decoration: none; width: auto; }
.btn.btn-outline { background: #fff; color: #4b4bff; border: 1px solid #4b4bff; }
.btn.btn-outline:hover { background: #eef0ff; }
.inline-form { display: inline-block; margin: 8px 0 0; }

.search-form { display: flex; gap: 8px; margin-bottom: 18px; max-width: 420px; }
.search-form .form-input { margin-bottom: 0; }
.search-form .btn.small { margin-top: 0; flex-shrink: 0; }

/* ---- Rich text editor (CKEditor 5) ---- */
/* CKEditor renders its own toolbar/editing UI; just give it breathing room. */
.ck.ck-editor { margin-bottom: 12px; }
.ck.ck-editor__editable_inline { min-height: 220px; border-radius: 0 0 6px 6px !important; }
.rich-content img, .rich-content figure { border-radius: 8px; margin: 10px 0; }
.rich-content figure.image { max-width: 100%; }
.rich-content blockquote { border-left: 3px solid #4b4bff; margin: 10px 0; padding-left: 14px; color: #555; }
.rich-content pre { background: #f0f1f5; padding: 12px; border-radius: 6px; overflow-x: auto; }

/* ---- Post detail ---- */
.post-detail { background: #fff; padding: 30px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); overflow-wrap: break-word; }
.post-detail-img { width: 100%; max-height: 360px; object-fit: cover; border-radius: 8px; margin-bottom: 16px; }
.post-detail-video {
    display: block; width: 100%; aspect-ratio: 16 / 9; max-height: 480px;
    border-radius: 8px; margin-bottom: 16px; background: #000; object-fit: contain;
}
.youtube-embed { position: relative; width: 100%; padding-bottom: 56.25%; height: 0; margin-bottom: 16px; border-radius: 8px; overflow: hidden; }
.youtube-embed iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
.post-content { line-height: 1.6; margin: 20px 0; }
.meta { color: #888; font-size: 13px; }

#like-post-btn, .like-comment-btn {
    background: #fff; border: 1px solid #ddd; padding: 10px 18px; border-radius: 20px;
    cursor: pointer; font-size: 14px; touch-action: manipulation;
}
#like-post-btn:hover, .like-comment-btn:hover { border-color: #4b4bff; color: #4b4bff; }

.comment { border-bottom: 1px solid #eee; padding: 12px 0; }
.comment .muted { color: #aaa; font-size: 12px; }
.comment p { overflow-wrap: break-word; }

/* ---- Profile ---- */
.profile-header { display: flex; gap: 20px; align-items: center; background: #fff; padding: 24px; border-radius: 10px; margin-bottom: 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); flex-wrap: wrap; }
.avatar-lg { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; }
.avatar-lg.placeholder { display: flex; align-items: center; justify-content: center; background: #4b4bff; color: #fff; font-size: 32px; font-weight: 700; }

/* ---- Messaging / member list ---- */
.badge { background: #4b4bff; color: #fff; border-radius: 12px; font-size: 12px; padding: 2px 8px; margin-left: 2px; }

.conversation-list { display: flex; flex-direction: column; gap: 8px; }
.conversation-item {
    display: flex; align-items: center; gap: 12px; background: #fff; padding: 12px 16px;
    border-radius: 10px; text-decoration: none; color: inherit; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    flex-wrap: wrap;
}
.conversation-item.unread { border-left: 3px solid #4b4bff; }
.conv-avatar {
    width: 44px; height: 44px; border-radius: 50%; overflow: hidden; background: #4b4bff; color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.conv-info { flex: 1; min-width: 0; }
.conv-info p { margin: 2px 0 0; font-size: 13px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: center; flex-wrap: wrap; }
.user-card-actions .btn.small { margin-top: 0; }
.user-card-actions .inline-form { margin: 0; }

.chat-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.chat-header .back-link { text-decoration: none; color: #4b4bff; font-size: 20px; }
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: #ccc; margin-left: auto; flex-shrink: 0; }
.connection-dot.online { background: #2ecc71; }
.connection-dot.connecting { background: #f1c40f; }
.connection-dot.offline { background: #c0392b; }

.message-list {
    background: #fff; border-radius: 10px; padding: 16px; height: 420px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.msg-row { display: flex; gap: 8px; align-items: flex-end; max-width: 78%; }
.msg-row.mine { flex-direction: row-reverse; align-self: flex-end; }
.msg-row.theirs { align-self: flex-start; }
.msg-avatar {
    width: 26px; height: 26px; border-radius: 50%; overflow: hidden; background: #4b4bff; color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-bubble-wrap { display: flex; flex-direction: column; min-width: 0; }
.msg-row.mine .msg-bubble-wrap { align-items: flex-end; }
.msg-row.theirs .msg-bubble-wrap { align-items: flex-start; }
.msg-username { font-size: 11px; color: #999; margin-bottom: 2px; padding: 0 4px; }
.msg-bubble { position: relative; padding: 8px 12px; border-radius: 14px; font-size: 14px; }
.msg-bubble p { margin: 0; overflow-wrap: break-word; }
.msg-bubble .msg-time { font-size: 10px; opacity: 0.6; display: block; margin-top: 3px; }
.msg-bubble.mine { background: #4b4bff; color: #fff; }
.msg-bubble.theirs { background: #f0f1f5; color: #222; }
.msg-delete-btn {
    position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; border-radius: 50%;
    background: #fff; border: 1px solid #ddd; color: #888; font-size: 13px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center; padding: 0; opacity: 0; transition: opacity 0.15s;
}
.msg-bubble:hover .msg-delete-btn { opacity: 1; }
.msg-delete-btn:hover { background: #fdecea; border-color: #c0392b; color: #c0392b; }
.msg-delete-btn:disabled { opacity: 0.5; cursor: default; }
.msg-attachment-img { max-width: 220px; max-height: 220px; border-radius: 8px; object-fit: cover; margin-bottom: 4px; }
.msg-attachment-video { max-width: 260px; max-height: 220px; border-radius: 8px; display: block; margin-bottom: 4px; background: #000; }
.msg-attachment-audio { max-width: 240px; margin-bottom: 4px; }
.msg-attachment-doc {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px;
    background: rgba(0,0,0,0.06); color: inherit; text-decoration: none; font-size: 13px; margin-bottom: 4px;
    max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-bubble.mine .msg-attachment-doc { background: rgba(255,255,255,0.2); color: #fff; }

.chat-toolbar { display: flex; gap: 4px; margin-bottom: 8px; width: 100%; }
.icon-btn {
    background: #fff; border: 1px solid #ddd; border-radius: 8px; width: 38px; height: 38px;
    font-size: 17px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: #4b4bff; }
.icon-btn.recording { background: #fdecea; border-color: #c0392b; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.emoji-picker {
    display: flex; flex-wrap: wrap; gap: 4px; background: #fff; border: 1px solid #ddd; border-radius: 8px;
    padding: 8px; margin-bottom: 8px; width: 100%; box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.emoji-option { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px; border-radius: 6px; }
.emoji-option:hover { background: #f0f1f5; }

#message-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
#message-form textarea { margin-bottom: 0; flex: 1; }
#message-form .btn { width: auto; }

/* =========================================================
   Responsive breakpoints
   ========================================================= */

/* Tablets and small laptops */
@media (max-width: 768px) {
    .container { padding: 0 16px; }
    main.container { padding: 20px 16px; }

    .layout { flex-direction: column; }
    .sidebar { width: 100%; }
    .sidebar ul { display: flex; flex-wrap: wrap; gap: 4px 14px; }

    .post-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }

    .post-detail, .form-card { padding: 20px; }

    .message-list { height: 380px; }
}

/* Phones */
@media (max-width: 480px) {
    .navbar-inner { flex-wrap: nowrap; }
    .nav-toggle { display: inline-block; }
    .navbar nav {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        position: absolute;
        top: 100%;
        left: 0;
        background: #1e1e2f;
        padding: 10px 20px 16px;
    }
    .navbar nav.open { display: flex; }
    .navbar nav a { margin-left: 0; padding: 8px 0; font-size: 15px; }
    .nav-push-btn { margin-left: 0; margin-top: 4px; }

    .post-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .post-thumb, .post-thumb-wrap.video-thumb { height: 100px; }
    .post-card h4 { font-size: 14px; margin: 8px 10px 4px; }
    .post-card .meta { font-size: 11px; margin: 0 10px 10px; }

    .form-card { padding: 16px; }
    .post-detail { padding: 16px; }
    .post-detail-img { max-height: 220px; }
    /* Keep the 16:9 box (not a fixed max-height) on phones so the video
       element always has enough height for the native control bar to
       render and stay tappable, whatever the source clip's aspect ratio
       is (object-fit: contain letterboxes instead of squeezing/clipping
       the controls). */
    .post-detail-video { max-height: none; }

    .profile-header { flex-direction: column; align-items: flex-start; text-align: left; }

    .pagination { justify-content: space-between; }

    #like-post-btn, .like-comment-btn { width: 100%; text-align: center; }

    .search-form { flex-wrap: wrap; }

    .message-list { height: 320px; }
    .msg-row { max-width: 92%; }
    .msg-attachment-img, .msg-attachment-video { max-width: 100%; }
    .conv-info p { max-width: 160px; }
    .user-card-actions { width: 100%; }
    .user-card-actions .btn.small, .user-card-actions .inline-form .btn.small { flex: 1; text-align: center; }
}

/* ---- Typing indicator ---- */
.typing-indicator { font-size: 12px; color: #888; margin: -6px 0 8px 4px; font-style: italic; }

/* ---- Nav push-notification bell ---- */
.nav-push-btn { width: 30px; height: 30px; font-size: 14px; margin-left: 18px; background: transparent; border-color: #444; color: #ddd; }
.nav-push-btn:hover { border-color: #fff; color: #fff; }
.nav-push-btn.active { background: #4b4bff; border-color: #4b4bff; color: #fff; }

/* ---- YouTube fallback link ---- */
.youtube-fallback { font-size: 12px; color: #888; margin: -10px 0 16px; }

