/* =========================================
   RESET & VARIABEL
   ========================================= */
:root {
    color-scheme: light;
    --wa-green: #008069;
    --wa-bg: #efeae2;
    --wa-bubble-out: #d9fdd3;
    --wa-bubble-in: #ffffff;
    --wa-text: #111b21;
    --wa-text-muted: #667781;
    --wa-border: #e9edef;
    --wa-header-height: 60px;
    --wa-max-width: 900px;
    --bg: var(--wa-bg);
    --surface: var(--wa-bubble-in);
    --raised: #f0f2f5;
    --line: var(--wa-border);
    --text: var(--wa-text);
    --muted: var(--wa-text-muted);
    --accent: var(--wa-green);
    --success: #d9fdd3;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: #dadbd3;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
}

[hidden] { display: none !important; }
a { color: var(--wa-green); }
:focus-visible { outline: 2px solid var(--wa-green); outline-offset: 3px; }
.forum-shell { width: 100%; max-width: var(--wa-max-width); }

/* =========================================
   CONTAINER UTAMA (Desktop vs Mobile)
   ========================================= */
.chat-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background-color: var(--wa-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    border: 0;
    min-height: 0;
}

@media (min-width: 768px) {
    body { padding: 20px; }
    .chat-container {
        height: 90vh;
        height: 90dvh;
        max-height: calc(100dvh - 40px);
        max-width: var(--wa-max-width);
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0,0,0,0.15);
        overflow: hidden;
    }
}

/* =========================================
   HEADER CHAT
   ========================================= */
.chat-header {
    height: var(--wa-header-height);
    min-height: var(--wa-header-height);
    background: var(--wa-green);
    color: white;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
    border: 0;
}

.chat-brand { display: flex; flex-shrink: 0; }
.chat-header .avatar {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
}
.chat-header .info { flex: 1; min-width: 0; }
.chat-header h1 { font-size: 16px; font-weight: 500; margin-bottom: 2px; letter-spacing: normal; }
.chat-header p { font-size: 12px; color: #d1d7db; }
.chat-header .actions { display: flex; gap: 16px; align-items: center; }
.chat-header .actions button { background: none; border: none; color: white; font-size: 18px; cursor: pointer; }

/* Menu native: tautan forum tetap bisa diakses dengan mouse/keyboard. */
.chat-menu { position: relative; }
.chat-menu summary {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 28px;
    line-height: 1;
    list-style: none;
}
.chat-menu summary::-webkit-details-marker { display: none; }
.chat-menu summary:hover,.chat-menu[open] summary { background: #ffffff20; }
.chat-menu summary:focus-visible { outline-color: white; }
.chat-header nav {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 240px;
    max-width: calc(100vw - 32px);
    padding: 8px;
    margin: 0;
    background: white;
    color: var(--wa-text);
    border: 1px solid var(--wa-border);
    border-radius: 8px;
    box-shadow: 0 4px 20px #0003;
    font-size: 14px;
}
.chat-header nav a { padding: 10px 12px; border-radius: 6px; color: var(--wa-text); }
.chat-header nav a:hover { background: #f0f2f5; }
.chat-header .watch-videos { margin: 0; background: transparent; border: 0; font-size: 13px; }
.chat-header .profile-link { max-width: 100%; }
.chat-header .header-avatar { width: 32px; height: 32px; flex-basis: 32px; margin: 0; }
.chat-header nav .button.primary { color: white; background: var(--wa-green); }

/* =========================================
   AREA PESAN (SCROLL)
   ========================================= */
.timeline-wrap { position: relative; flex: 1; min-height: 0; }
.chat-messages {
    flex: 1;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: var(--wa-bg);
    background-image: url('chat-pattern.png');
    background-size: cover;
    background-blend-mode: soft-light;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 10px; }
#messages { flex-shrink: 0; }
#olderMessages { flex-shrink: 0; align-self: center; margin: 0 auto 8px; background: white; }
.empty-chat { flex-shrink: 0; }
.chat-message { gap: 8px; margin: 8px 0; }
.avatar { background: #dfe9e5; color: var(--wa-green); }
.day-divider { margin: 20px 0; color: var(--wa-text-muted); }
.forum-announcement { background: #fff8; color: #54656f; border-color: #d6ded8; margin-block: 8px 0; padding: 6px 12px; }
.membership-status { padding: 6px 12px; }

/* =========================================
   BUBBLE PESAN
   ========================================= */
.message {
    max-width: 75%;
    padding: 8px 12px;
    border: 0;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.message.incoming { align-self: flex-start; background-color: var(--wa-bubble-in); border-top-left-radius: 0; color: var(--wa-text); }
.message.outgoing { align-self: flex-end; background-color: var(--wa-bubble-out); border-radius: 8px 0 8px 8px; color: var(--wa-text); }
.sender,.chat-message.admin-message .sender { color: var(--wa-green); margin-bottom: 4px; }
.message-text { line-height: 1.4; }
.message-text a { color: #027eb5; }
.message .meta {
    font-size: 11px;
    color: var(--wa-text-muted);
    text-align: right;
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 4px 8px;
}
.message .meta .read-icon { color: #53bdeb; }
.eye-icon,.reply-button { color: var(--wa-text-muted); }
.delete-message-button { color: #b42335; }
.message .reply-context,.reply-draft {
    background-color: rgba(0,0,0,0.05);
    border-left: 3px solid var(--wa-green);
    padding: 6px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--wa-text-muted);
}
.reply-quote strong,.reply-draft strong { color: var(--wa-green); }
.chat-message.is-target .bubble { outline-color: var(--wa-green); }
.message-media { max-width: 100%; border-radius: 6px; margin-top: 4px; cursor: pointer; }
.chat-photo { border-radius: 6px; }
.link-preview { background: #f0f2f5; }
.link-preview-icon { background: #dfe9e5; color: var(--wa-green); }
.link-preview-image { background: #e9edef; }

/* =========================================
   INPUT CHAT (FOOTER)
   ========================================= */
.chat-input-area {
    padding: 10px 16px max(10px,env(safe-area-inset-bottom));
    background-color: #f0f2f5;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    flex-shrink: 0;
    border: 0;
}
.composer-row { align-items: center; gap: 10px; padding: 0; background: transparent; border: 0; }
.chat-input-area .input-wrapper {
    flex: 1;
    min-width: 0;
    background-color: white;
    border-radius: 24px;
    padding: 0 16px;
    display: flex;
    align-items: center;
}
.chat-input-area textarea {
    width: 100%;
    border: none;
    font-size: 16px;
    color: var(--wa-text);
    padding: 11px 0;
    background: transparent;
}
.chat-input-area .btn-send {
    background-color: var(--wa-green);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 18px;
    transition: background-color 0.2s;
}
.chat-input-area .btn-send:hover { background-color: #006e5a; }
.chat-input-area .btn-attach,.chat-input-area .icon-button { background: none; border: none; font-size: 20px; color: var(--wa-text-muted); cursor: pointer; }
.chat-input-area .icon-button { width: 32px; height: 44px; flex-basis: 32px; }
.guest-name { margin-bottom: 8px; }
.guest-name input { background: white; font-size: 16px; }
.composer-footer { margin-top: 6px; }
.media-preview { margin: 0 0 8px; padding: 6px; overflow-wrap: anywhere; min-width: 0; }
.media-preview button,dialog button { color: var(--wa-text); }
dialog { margin: auto; }
.emoji-picker { background: white; bottom: 100%; z-index: 25; box-shadow: 0 4px 20px #0002; }
.notice { color: var(--wa-green) !important; background: #d9fdd3; border-color: #00806955; }

/* =========================================
   PENYESUAIAN MOBILE (HP)
   ========================================= */
@media (max-width: 767px) {
    body { padding: 0; background: var(--wa-bg); align-items: flex-start; }
    .chat-container { height: 100vh; height: 100dvh; max-width: 100%; border-radius: 0; box-shadow: none; }
    .message { max-width: 85%; }
    .chat-header h1 { font-size: 15px; }
    .chat-header p { font-size: 11px; max-width: none; }
    .chat-messages { padding: 12px; }
    .chat-input-area { padding: 8px 8px max(8px,env(safe-area-inset-bottom)); }
    .composer-row { gap: 4px; }
    .chat-input-area .input-wrapper { padding-inline: 12px; }
    .chat-input-area .icon-button { width: 28px; flex-basis: 28px; }
    .forum-announcement { width: calc(100% - 24px); }
}

/* =========================================
   TOMBOL PESAN BARU
   ========================================= */
.scroll-to-bottom {
    position: absolute;
    bottom: 16px;
    right: 20px;
    background: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    cursor: pointer;
    display: none;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    color: var(--wa-green);
    z-index: 5;
}
.scroll-to-bottom.show { display: flex; }
.scroll-to-bottom .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: red;
    color: white;
    border-radius: 50%;
    font-size: 10px;
    width: 22px;
    height: 22px;
    display: flex;
    justify-content: center;
    align-items: center;
}
