/*
 * Chat internal — dua panel (kontak + percakapan).
 *
 * Warna dibaca dari custom property Filament (--primary-*, dst) supaya
 * ikut berganti otomatis di mode gelap, sama seperti berkas wr-*.css lain.
 */

.wr-chat {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1rem;
    height: calc(100vh - 12rem);
    min-height: 28rem;
}

@media (max-width: 768px) {
    .wr-chat {
        grid-template-columns: 1fr;
        height: auto;
    }
}

.wr-chat__kontak {
    border: 1px solid rgb(var(--gray-200));
    border-radius: 0.75rem;
    overflow-y: auto;
    background: rgb(var(--gray-50));
}

:root.dark .wr-chat__kontak {
    background: rgb(var(--gray-800));
    border-color: rgb(var(--gray-700));
}

.wr-chat__kontak-judul {
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgb(var(--gray-500));
}

.wr-chat__kontak-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    color: inherit;
}

.wr-chat__kontak-item:hover {
    background: rgb(var(--gray-100));
}

:root.dark .wr-chat__kontak-item:hover {
    background: rgb(var(--gray-700));
}

.wr-chat__kontak-item.is-aktif {
    background: rgb(var(--primary-50));
    border-right: 3px solid rgb(var(--primary-600));
}

:root.dark .wr-chat__kontak-item.is-aktif {
    background: rgba(var(--primary-500), 0.15);
}

.wr-chat__kontak-avatar {
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    background: rgb(var(--primary-600));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Grup diskusi task force: warna lain supaya tidak terbaca sebagai seorang kontak. */
.wr-chat__kontak-avatar--grup {
    background: rgb(var(--gray-700));
}

:root.dark .wr-chat__kontak-avatar--grup {
    background: rgb(var(--gray-500));
}

.wr-chat__kontak-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.wr-chat__kontak-nama {
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wr-chat__kontak-peran {
    font-size: 0.75rem;
    color: rgb(var(--gray-500));
}

.wr-chat__lencana {
    flex-shrink: 0;
    background: rgb(var(--danger-600));
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 1.25rem;
    height: 1.25rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.3rem;
}

.wr-chat__kosong {
    padding: 1rem;
    font-size: 0.875rem;
    color: rgb(var(--gray-500));
}

.wr-chat__percakapan {
    display: flex;
    flex-direction: column;
    border: 1px solid rgb(var(--gray-200));
    border-radius: 0.75rem;
    overflow: hidden;
}

:root.dark .wr-chat__percakapan {
    border-color: rgb(var(--gray-700));
}

.wr-chat__placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgb(var(--gray-500));
    font-size: 0.9rem;
}

.wr-chat__header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgb(var(--gray-200));
}

:root.dark .wr-chat__header {
    border-color: rgb(var(--gray-700));
}

.wr-chat__header-nama {
    font-weight: 600;
}

.wr-chat__header-peran {
    font-size: 0.75rem;
    color: rgb(var(--gray-500));
}

/* Kepala grup: daftar nama anggota dipotong satu baris, lengkapnya di title. */
.wr-chat__header-teks {
    min-width: 0;
    flex: 1;
}

.wr-chat__header-anggota {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wr-chat__bubbles {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.wr-chat__bubble {
    max-width: 70%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    background: rgb(var(--gray-100));
    align-self: flex-start;
}

:root.dark .wr-chat__bubble {
    background: rgb(var(--gray-700));
}

.wr-chat__bubble.is-saya {
    align-self: flex-end;
    background: rgb(var(--primary-600));
    color: white;
}

/* Nama pengirim di atas gelembung orang lain — hanya dipakai di grup. */
.wr-chat__bubble-pengirim {
    font-size: 0.75rem;
    font-weight: 600;
    color: rgb(var(--primary-700));
    margin-bottom: 0.15rem;
}

:root.dark .wr-chat__bubble-pengirim {
    color: rgb(var(--primary-300));
}

.wr-chat__bubble-isi {
    font-size: 0.875rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.wr-chat__bubble-waktu {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 0.2rem;
    text-align: right;
}

.wr-chat__form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid rgb(var(--gray-200));
}

:root.dark .wr-chat__form {
    border-color: rgb(var(--gray-700));
}

.wr-chat__form textarea {
    flex: 1;
    resize: none;
    border-radius: 0.5rem;
    border: 1px solid rgb(var(--gray-300));
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    background: transparent;
    color: inherit;
}

:root.dark .wr-chat__form textarea {
    border-color: rgb(var(--gray-600));
}

.wr-chat__kirim {
    align-self: flex-end;
    background: rgb(var(--primary-600));
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}

.wr-chat__kirim:hover {
    background: rgb(var(--primary-700));
}

.wr-chat__kirim:disabled,
.wr-chat__ikon-tombol:disabled,
.wr-chat__tombol-sekunder:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Lampiran di gelembung ─────────────────────────────────────── */

.wr-chat__bubble.has-lampiran {
    max-width: min(70%, 22rem);
}

.wr-chat__gambar {
    display: block;
    margin: -0.15rem -0.35rem 0.25rem;
}

.wr-chat__gambar img {
    display: block;
    max-width: 100%;
    max-height: 16rem;
    border-radius: 0.5rem;
    object-fit: cover;
    background: rgba(0, 0, 0, 0.05);
}

.wr-chat__berkas,
.wr-chat__tertunda {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    padding: 0.5rem 0.6rem;
    border-radius: 0.5rem;
    background: rgba(0, 0, 0, 0.06);
    color: inherit;
    text-decoration: none;
}

.wr-chat__bubble.is-saya .wr-chat__berkas {
    background: rgba(255, 255, 255, 0.16);
}

.wr-chat__berkas:hover {
    background: rgba(0, 0, 0, 0.1);
}

.wr-chat__bubble.is-saya .wr-chat__berkas:hover {
    background: rgba(255, 255, 255, 0.24);
}

.wr-chat__berkas-ikon {
    flex-shrink: 0;
    min-width: 2.5rem;
    height: 2.5rem;
    padding: 0 0.3rem;
    border-radius: 0.4rem;
    background: rgb(var(--primary-100));
    color: rgb(var(--primary-700));
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wr-chat__berkas-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.wr-chat__berkas-nama {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wr-chat__berkas-ukuran {
    font-size: 0.72rem;
    opacity: 0.75;
}

.wr-chat__berkas-aksi {
    flex-shrink: 0;
    width: 1.1rem;
    height: 1.1rem;
    opacity: 0.8;
}

.wr-chat__bubble.has-lampiran .wr-chat__bubble-isi {
    margin-top: 0.35rem;
}

/* ── Pemutar suara ─────────────────────────────────────────────── */

.wr-pemutar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 13rem;
}

.wr-pemutar__tombol {
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgb(var(--primary-600));
    color: white;
}

.wr-chat__bubble.is-saya .wr-pemutar__tombol {
    background: white;
    color: rgb(var(--primary-700));
}

.wr-pemutar__ikon {
    width: 1.1rem;
    height: 1.1rem;
}

.wr-pemutar__jalur {
    flex: 1;
    height: 0.4rem;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.15);
    cursor: pointer;
    overflow: hidden;
}

.wr-chat__bubble.is-saya .wr-pemutar__jalur {
    background: rgba(255, 255, 255, 0.35);
}

.wr-pemutar__isi {
    height: 100%;
    background: rgb(var(--primary-600));
    transition: width 0.15s linear;
}

.wr-chat__bubble.is-saya .wr-pemutar__isi {
    background: white;
}

.wr-pemutar__waktu {
    flex-shrink: 0;
    min-width: 2.5rem;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.wr-pemutar__cadangan {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.72rem;
    text-decoration: underline;
    color: inherit;
}

/* ── Penyusun: lampiran tertunda, perekam, pratinjau ───────────── */

.wr-chat__penyusun {
    border-top: 1px solid rgb(var(--gray-200));
}

:root.dark .wr-chat__penyusun {
    border-color: rgb(var(--gray-700));
}

.wr-chat__penyusun .wr-chat__form {
    border-top: none;
}

.wr-chat__tertunda {
    margin: 0.75rem 0.75rem 0;
}

:root.dark .wr-chat__tertunda,
:root.dark .wr-chat__berkas {
    background: rgba(255, 255, 255, 0.08);
}

.wr-chat__tertunda-gambar {
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.4rem;
    object-fit: cover;
}

.wr-chat__galat {
    margin: 0.5rem 0.75rem 0;
    font-size: 0.8rem;
    color: rgb(var(--danger-600));
}

:root.dark .wr-chat__galat {
    color: rgb(var(--danger-400));
}

.wr-chat__unggah {
    margin: 0.5rem 0.75rem 0;
    font-size: 0.8rem;
    color: rgb(var(--gray-500));
}

.wr-chat__ikon-tombol {
    align-self: flex-end;
    flex-shrink: 0;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 0.5rem;
    border: 1px solid rgb(var(--gray-300));
    background: transparent;
    color: rgb(var(--gray-600));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wr-chat__ikon-tombol:hover {
    background: rgb(var(--gray-100));
    color: rgb(var(--primary-600));
}

:root.dark .wr-chat__ikon-tombol {
    border-color: rgb(var(--gray-600));
    color: rgb(var(--gray-300));
}

:root.dark .wr-chat__ikon-tombol:hover {
    background: rgb(var(--gray-700));
}

.wr-chat__tertunda .wr-chat__ikon-tombol {
    align-self: center;
    border: none;
}

.wr-chat__perekam,
.wr-chat__pratinjau {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem;
    flex-wrap: wrap;
}

.wr-chat__spasi {
    flex: 1;
}

.wr-chat__rec-titik {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 9999px;
    background: rgb(var(--danger-600));
    animation: wr-chat-rekam 1s ease-in-out infinite;
}

@keyframes wr-chat-rekam {
    50% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
    .wr-chat__rec-titik { animation: none; }
}

.wr-chat__perekam-label {
    font-weight: 600;
    font-size: 0.875rem;
}

.wr-chat__perekam-waktu {
    font-variant-numeric: tabular-nums;
    font-size: 0.875rem;
}

.wr-chat__perekam-batas,
.wr-chat__pratinjau-catatan {
    font-size: 0.75rem;
    color: rgb(var(--gray-500));
}

.wr-chat__pratinjau .wr-pemutar {
    flex: 1 1 14rem;
}

.wr-chat__perekam .wr-chat__kirim,
.wr-chat__pratinjau .wr-chat__kirim {
    align-self: center;
}

.wr-chat__tombol-sekunder {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem 0.9rem;
    border-radius: 0.5rem;
    border: 1px solid rgb(var(--gray-300));
    background: transparent;
    color: inherit;
    font-size: 0.875rem;
    cursor: pointer;
}

.wr-chat__tombol-sekunder:hover {
    background: rgb(var(--gray-100));
}

:root.dark .wr-chat__tombol-sekunder {
    border-color: rgb(var(--gray-600));
}

:root.dark .wr-chat__tombol-sekunder:hover {
    background: rgb(var(--gray-700));
}

/* ── Layar HP ──────────────────────────────────────────────────────
 *
 * Daftar kontak dan percakapan tampil BERGANTIAN, seperti aplikasi pesan
 * pada umumnya. Percakapan mengisi layar dari bawah bilah atas sampai tepi
 * bawah: kepala (dengan tombol kembali), pesan yang bisa digulir, dan kotak
 * ketik yang selalu menempel di bawah.
 *
 * --wr-tinggi-layar diisi wr-chat.js dari visualViewport — tinggi yang
 * benar-benar tampak, yang ikut menyusut saat papan ketik muncul. Tanpa itu
 * kotak ketik tertutup papan ketik di iPhone. 4rem = tinggi bilah atas
 * Filament (h-16).
 */

.wr-chat__kembali {
    display: none;
}

@media (max-width: 768px) {
    .wr-chat {
        display: block;
        height: auto;
        min-height: 0;
    }

    .wr-chat.is-terbuka .wr-chat__kontak,
    .wr-chat:not(.is-terbuka) .wr-chat__percakapan {
        display: none;
    }

    /* Daftar kontak: mengalir bersama halaman, butirnya enak diketuk. */
    .wr-chat__kontak {
        overflow: visible;
    }

    .wr-chat__kontak-item {
        padding: 0.8rem 1rem;
    }

    .wr-chat.is-terbuka .wr-chat__percakapan {
        position: fixed;
        top: 4rem;
        left: 0;
        right: 0;
        z-index: 10; /* di bawah bilah atas (20) dan menu samping (30) */
        height: calc(var(--wr-tinggi-layar, 100vh) - 4rem);
        border: none;
        border-radius: 0;
        background: #fff;
    }

    @supports (height: 100dvh) {
        .wr-chat.is-terbuka .wr-chat__percakapan {
            height: calc(var(--wr-tinggi-layar, 100dvh) - 4rem);
        }
    }

    :root.dark .wr-chat.is-terbuka .wr-chat__percakapan {
        background: rgb(var(--gray-900));
    }

    /* Halaman di belakangnya tidak ikut tergulir saat percakapan terbuka. */
    html:has(.wr-chat.is-terbuka) {
        overflow: hidden;
    }

    .wr-chat__header {
        flex-shrink: 0;
        padding: 0.6rem 0.75rem;
    }

    .wr-chat__kembali {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 2.5rem;
        height: 2.5rem;
        margin-left: -0.25rem;
        border: none;
        border-radius: 9999px;
        background: none;
        color: inherit;
        cursor: pointer;
    }

    .wr-chat__kembali:active {
        background: rgb(var(--gray-100));
    }

    :root.dark .wr-chat__kembali:active {
        background: rgb(var(--gray-700));
    }

    .wr-chat__header-nama {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .wr-chat__header > div {
        min-width: 0;
    }

    .wr-chat__bubbles {
        min-height: 0; /* tanpa ini flex item tidak mau menyusut dan tidak bisa digulir */
        padding: 0.75rem;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .wr-chat__bubble,
    .wr-chat__bubble.has-lampiran {
        max-width: 85%;
    }

    .wr-chat__penyusun {
        flex-shrink: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .wr-chat__form {
        gap: 0.35rem;
        padding: 0.5rem;
        align-items: flex-end;
    }

    /*
     * 16px, bukan 14px: iPhone memperbesar seluruh halaman setiap kali kolom
     * isian berhuruf lebih kecil dari 16px mendapat fokus, dan tidak
     * mengembalikannya.
     */
    .wr-chat__form textarea {
        min-width: 0;
        font-size: 16px;
        padding: 0.45rem 0.6rem;
    }

    .wr-chat__kirim {
        padding: 0.55rem 0.8rem;
    }

    .wr-chat__perekam,
    .wr-chat__pratinjau {
        flex-wrap: wrap;
    }
}

/* ── Penampil gambar ───────────────────────────────────────────────
 *
 * Satu lapisan penuh layar yang dibuat wr-chat.js dan ditempel ke <body>,
 * di luar bagian yang dirender ulang Livewire setiap 5 detik — kalau ia
 * berada di dalam halaman Chat, polling akan menutupnya sendiri.
 *
 * z-index di atas segalanya milik Filament (bilah atas 20, menu samping 30,
 * modal 40-50).
 */

.wr-chat__gambar {
    cursor: zoom-in;
}

.wr-lihat-gambar {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(3, 7, 18, 0.97);
    /* Tinggi yang benar-benar tampak di HP; lihat --wr-tinggi-layar di atas. */
    height: var(--wr-tinggi-layar, 100vh);
    touch-action: pinch-zoom;
}

.wr-lihat-gambar[hidden] {
    display: none;
}

.wr-lihat-gambar__gambar {
    max-width: 100vw;
    max-height: calc(var(--wr-tinggi-layar, 100vh) - 5rem);
    object-fit: contain;
    cursor: default;
    user-select: none;
    -webkit-user-drag: none;
}

.wr-lihat-gambar__bilah {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: calc(0.5rem + env(safe-area-inset-top, 0px)) 0.5rem 0.5rem 1rem;
    color: #fff;
    background: linear-gradient(rgba(3, 7, 18, 0.75), rgba(3, 7, 18, 0));
}

.wr-lihat-gambar__nama {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
}

.wr-lihat-gambar__tombol {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    height: 2.75rem; /* 44px: ukuran sentuh terkecil yang nyaman */
    padding: 0 0.75rem;
    border: none;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.wr-lihat-gambar__tombol:hover,
.wr-lihat-gambar__tombol:focus-visible {
    background: rgba(255, 255, 255, 0.28);
    outline: none;
}

.wr-lihat-gambar__tutup {
    padding: 0;
    font-size: 1.6rem;
    line-height: 1;
}

/* Halaman di belakangnya tidak ikut tergulir selama gambar terbuka. */
html.wr-gambar-terbuka {
    overflow: hidden;
}
