/* =====================================================================
   Manava CRM - aplikasi chat untuk HP (crm.manava.id)

   Dirancang dari layar HP ke atas: satu kolom dengan tab di bawah, chat
   meluncur dari kanan. Di layar >= 960px menjadi dua kolom (daftar + chat).
   Semua warna lewat token di :root; tema gelap cukup mengganti token.
   ===================================================================== */

:root {
    --brand-1: #1896e2;
    --brand-2: #3ac962;
    --brand-grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));
    --accent: #11a37f;
    --accent-ink: #ffffff;
    --accent-soft: #e3f6ef;
    --link: #1677d2;

    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f2f4f7;
    --surface-3: #e9edf2;
    --line: #e5e9ef;
    --text: #0e1a2b;
    --text-2: #344257;
    --muted: #6b778a;
    --faint: #98a3b3;

    --bubble-in: #ffffff;
    --bubble-in-ink: #0e1a2b;
    --bubble-out: #dff5ea;
    --bubble-out-ink: #0b2a1f;
    --chat-bg: #eef2f5;
    --chat-pattern: radial-gradient(circle at 1px 1px, rgba(14, 26, 43, .045) 1px, transparent 0);

    --danger: #e5484d;
    --danger-soft: #fdecec;
    --warn: #c27c0e;
    --warn-soft: #fff6e5;
    --ok: #12a150;
    --ok-soft: #e6f7ee;
    --read: #2f8fe8;

    --shadow-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-2: 0 8px 24px rgba(16, 24, 40, .10), 0 2px 6px rgba(16, 24, 40, .06);
    --shadow-3: 0 18px 50px rgba(16, 24, 40, .22);

    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 20px;
    --r-xl: 26px;

    --ease: cubic-bezier(.2, .8, .2, 1);
    --ease-out: cubic-bezier(.16, 1, .3, 1);
    --dur: 280ms;

    --tabbar-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    --app-h: 100dvh;

    color-scheme: light;
}

html[data-tema="gelap"] {
    --accent: #2cc493;
    --accent-ink: #04140e;
    --accent-soft: #123a2f;
    --link: #6cb6ff;

    --bg: #0a111d;
    --surface: #101a2a;
    --surface-2: #162236;
    --surface-3: #1d2b42;
    --line: #1f2d44;
    --text: #e9eef6;
    --text-2: #c3cddc;
    --muted: #8e9cb2;
    --faint: #66758c;

    --bubble-in: #172437;
    --bubble-in-ink: #e9eef6;
    --bubble-out: #11463a;
    --bubble-out-ink: #e3fbf2;
    --chat-bg: #0c1522;
    --chat-pattern: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .035) 1px, transparent 0);

    --danger: #ff6b6f;
    --danger-soft: #3a1a1d;
    --warn: #f0b44c;
    --warn-soft: #382a10;
    --ok: #3dd68c;
    --ok-soft: #12321f;
    --read: #5aaeff;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 10px 28px rgba(0, 0, 0, .45);
    --shadow-3: 0 18px 50px rgba(0, 0, 0, .6);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--link); text-decoration: none; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2.5px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Tombol: respons sentuhan terasa (sedikit mengecil), bukan sekadar berubah warna. */
.tekan { transition: transform 120ms var(--ease), background-color 160ms var(--ease), opacity 160ms; }
.tekan:active { transform: scale(.96); }

/* =====================================================================
   Kerangka
   ===================================================================== */
.app {
    position: fixed;
    inset: 0;
    height: var(--app-h);
    display: grid;
    grid-template-columns: 1fr;
    background: var(--bg);
}
.kolom-kiri {
    position: relative;
    min-width: 0;
    height: var(--app-h);
    display: flex;
    flex-direction: column;
    background: var(--surface);
}
.tab-view {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    animation: tabMasuk 260ms var(--ease-out);
}
@keyframes tabMasuk { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.gulir {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* Kepala setiap tab */
.kepala {
    position: relative;
    z-index: 3;
    padding: calc(var(--safe-t) + 14px) 18px 10px;
    background: var(--surface);
}
.kepala-baris { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.kepala-judul { flex: 1 1 auto; min-width: 0; }
.kepala-judul h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.kepala-judul small { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.kepala-judul small .titik { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.kepala-judul small .titik.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.ikon-btn {
    position: relative;
    width: 42px; height: 42px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-2);
    background: var(--surface-2);
    flex: none;
    font-size: 17px;
}
.ikon-btn:hover { background: var(--surface-3); }
.ikon-btn .lencana {
    position: absolute; top: -2px; right: -2px;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 99px; background: var(--danger); color: #fff;
    font-size: 10.5px; font-weight: 800; line-height: 18px; text-align: center;
    border: 2px solid var(--surface);
}
.org-pill {
    display: inline-flex; align-items: center; gap: 8px;
    max-width: 100%;
    padding: 5px 12px 5px 5px;
    border-radius: 99px;
    background: var(--surface-2);
    font-size: 12.5px; font-weight: 700; color: var(--text-2);
}
.org-pill .org-logo { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.org-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-pill i { font-size: 10px; color: var(--muted); }

/* Kotak cari */
.cari {
    position: relative;
    margin-top: 12px;
}
.cari i {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--faint); font-size: 14px; pointer-events: none;
}
.cari input {
    width: 100%;
    height: 44px;
    padding: 0 40px 0 40px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: var(--surface-2);
    font-size: 16px;   /* 16px: iOS tidak memperbesar halaman saat fokus */
    outline: none;
    transition: background-color 160ms, border-color 160ms, box-shadow 160ms;
}
.cari input::placeholder { color: var(--faint); }
.cari input:focus { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent); }
.cari .hapus-cari {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    width: 30px; height: 30px; border-radius: 50%; color: var(--muted);
}

/* Chip filter: digulir mendatar, tanpa batang gulir */
.chips {
    display: flex; gap: 8px;
    margin: 12px -18px 0;
    padding: 0 18px 4px;
    overflow-x: auto;
    scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex: none;
    display: inline-flex; align-items: center; gap: 7px;
    height: 34px; padding: 0 14px;
    border-radius: 99px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 13px; font-weight: 700;
    border: 1px solid transparent;
    transition: background-color 180ms var(--ease), color 180ms var(--ease), transform 120ms;
    white-space: nowrap;
}
.chip i { font-size: 13px; }
.chip .jml { font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); }
.chip.aktif { background: var(--text); color: var(--surface); }
.chip.aktif .jml { background: color-mix(in srgb, var(--surface) 22%, transparent); color: var(--surface); }
.chip:active { transform: scale(.95); }

.segmen {
    display: inline-flex; padding: 3px; gap: 2px;
    border-radius: 12px; background: var(--surface-2);
}
.segmen button {
    height: 30px; padding: 0 12px; border-radius: 9px;
    font-size: 12.5px; font-weight: 700; color: var(--muted);
    transition: background-color 180ms, color 180ms, box-shadow 180ms;
}
.segmen button.aktif { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* Spanduk (device terputus, offline, dsb.) */
.spanduk {
    display: flex; align-items: flex-start; gap: 10px;
    margin: 8px 16px 0;
    padding: 11px 14px;
    border-radius: var(--r-md);
    font-size: 13px; line-height: 1.45;
    background: var(--warn-soft); color: var(--warn);
    animation: tabMasuk 240ms var(--ease-out);
}
.spanduk i { margin-top: 2px; }
.spanduk b { color: inherit; }
.spanduk.bahaya { background: var(--danger-soft); color: var(--danger); }
.spanduk.info { background: var(--accent-soft); color: var(--accent); }
.spanduk .spanduk-aksi { margin-left: auto; font-weight: 800; white-space: nowrap; color: inherit; text-decoration: underline; }

/* =====================================================================
   Daftar percakapan
   ===================================================================== */
.daftar { list-style: none; margin: 0; padding: 6px 0 calc(var(--tabbar-h) + var(--safe-b) + 18px); }
.baris {
    position: relative;
    display: flex; align-items: center; gap: 13px;
    padding: 11px 18px;
    min-height: 76px;
    cursor: pointer;
    transition: background-color 160ms var(--ease);
    animation: barisMasuk 320ms var(--ease-out) both;
}
@keyframes barisMasuk { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.baris:hover { background: var(--surface-2); }
.baris:active { background: var(--surface-3); }
.baris.terpilih { background: var(--accent-soft); }
.baris + .baris::before {
    content: ''; position: absolute; top: 0; right: 0; left: 82px;
    border-top: 1px solid var(--line);
}
.baris-isi { flex: 1 1 auto; min-width: 0; }
.baris-atas, .baris-bawah { display: flex; align-items: center; gap: 8px; }
.baris-nama {
    flex: 1 1 auto; min-width: 0;
    font-weight: 700; font-size: 15.5px; letter-spacing: -.005em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.baris-waktu { flex: none; font-size: 12px; color: var(--muted); font-weight: 600; }
.baris.belum-dibaca .baris-waktu { color: var(--accent); font-weight: 800; }
.baris-bawah { margin-top: 3px; }
.baris-cuplikan {
    flex: 1 1 auto; min-width: 0;
    color: var(--muted); font-size: 13.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: flex; align-items: center; gap: 5px;
}
.baris-cuplikan i { font-size: 12px; flex: none; }
.baris.belum-dibaca .baris-cuplikan { color: var(--text-2); font-weight: 600; }
.jml-baca {
    flex: none;
    min-width: 22px; height: 22px; padding: 0 7px;
    border-radius: 99px;
    background: var(--accent); color: var(--accent-ink);
    font-size: 11.5px; font-weight: 800; line-height: 22px; text-align: center;
    animation: letup 360ms var(--ease-out);
}
@keyframes letup { 0% { transform: scale(.4); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.baris-tag { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tag {
    display: inline-flex; align-items: center; gap: 5px;
    height: 21px; padding: 0 8px; border-radius: 99px;
    font-size: 11px; font-weight: 700;
    background: var(--surface-2); color: var(--text-2);
    max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.tag i { font-size: 10px; }
.tag .bulat { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.tag.ai { background: color-mix(in srgb, #7c5cff 14%, transparent); color: #7c5cff; }
html[data-tema="gelap"] .tag.ai { color: #b4a3ff; }
.tag.saya { background: var(--accent-soft); color: var(--accent); }

/* Avatar */
.avatar {
    position: relative;
    flex: none;
    width: 50px; height: 50px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 17px; color: #fff;
    background: var(--av, #7a8aa3);
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar.kecil { width: 38px; height: 38px; font-size: 14px; }
.avatar.besar { width: 92px; height: 92px; font-size: 32px; }
.avatar .kanal {
    position: absolute; right: -3px; bottom: -3px;
    width: 21px; height: 21px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11.5px; color: #fff;
    border: 2.5px solid var(--surface);
}
.avatar.kecil .kanal { width: 17px; height: 17px; font-size: 9.5px; border-width: 2px; }
.k-wa { background: #25d366; }
.k-ig { background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 90%); }
.k-fb { background: #0866ff; }
.k-tt { background: #111; }
.k-mail { background: #64748b; }

/* Kerangka muat (skeleton) */
.kerangka { padding: 8px 0; }
.kerangka-baris { display: flex; gap: 13px; padding: 12px 18px; align-items: center; }
.kerangka-baris .k-av { width: 50px; height: 50px; border-radius: 50%; }
.kerangka-baris .k-teks { flex: 1; display: grid; gap: 8px; }
.kerangka-baris .k-teks span { height: 12px; border-radius: 6px; }
.kerangka-baris .k-teks span:first-child { width: 55%; }
.kerangka-baris .k-teks span:last-child { width: 85%; }
.kilau {
    background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
    background-size: 200% 100%;
    animation: kilau 1.3s ease-in-out infinite;
}
@keyframes kilau { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Keadaan kosong */
.kosong {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center;
    padding: 56px 32px;
    color: var(--muted);
    animation: tabMasuk 300ms var(--ease-out);
}
.kosong .kosong-ikon {
    width: 76px; height: 76px; border-radius: 26px;
    display: flex; align-items: center; justify-content: center;
    font-size: 30px; margin-bottom: 18px;
    background: var(--accent-soft); color: var(--accent);
}
.kosong h3 { margin: 0 0 6px; color: var(--text); font-size: 17px; }
.kosong p { margin: 0; font-size: 13.5px; max-width: 300px; }
.kosong .tombol { margin-top: 18px; }

.muat-lagi { display: flex; justify-content: center; padding: 14px; color: var(--muted); font-size: 12.5px; gap: 8px; align-items: center; }

/* Tarik untuk muat ulang */
.tarik {
    height: 0; overflow: hidden;
    display: flex; align-items: flex-end; justify-content: center;
    color: var(--muted); font-size: 12.5px; font-weight: 700;
    transition: height 220ms var(--ease);
}
.tarik i { margin-right: 8px; transition: transform 200ms; }
.tarik.siap i { transform: rotate(180deg); }

/* =====================================================================
   Bilah tab bawah
   ===================================================================== */
.tabbar {
    position: absolute; left: 0; right: 0; bottom: 0;
    z-index: 5;
    display: grid; grid-template-columns: repeat(var(--jml-tab, 3), 1fr);
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(16px);
    -webkit-backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--line);
}
.tab {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    color: var(--faint);
    font-size: 11px; font-weight: 700;
    transition: color 180ms var(--ease);
}
.tab i { font-size: 20px; transition: transform 220ms var(--ease-out); }
.tab.aktif { color: var(--accent); }
.tab.aktif i { transform: translateY(-1px) scale(1.08); }
.tab::before {
    content: ''; position: absolute; top: 7px; width: 54px; height: 32px; border-radius: 16px;
    background: var(--accent-soft); opacity: 0; transform: scaleX(.5);
    transition: opacity 220ms var(--ease), transform 260ms var(--ease-out);
    z-index: -1;
}
.tab.aktif::before { opacity: 1; transform: none; }
.tab .lencana {
    position: absolute; top: 6px; left: calc(50% + 6px);
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 99px; background: var(--danger); color: #fff;
    font-size: 10.5px; font-weight: 800; line-height: 18px; text-align: center;
    border: 2px solid var(--surface);
}

/* =====================================================================
   Layar chat
   ===================================================================== */
.chat {
    position: fixed; inset: 0;
    height: var(--app-h);
    z-index: 20;
    display: flex; flex-direction: column;
    background: var(--chat-bg);
    transform: translateX(100%);
    visibility: hidden;
    /* Tersembunyi sesudah meluncur keluar: bayangannya tidak membayang di tepi
       kanan, dan isinya tidak bisa terfokus lewat keyboard. */
    transition: transform var(--dur) var(--ease-out), visibility 0s linear var(--dur);
    will-change: transform;
}
.chat.buka { transform: none; visibility: visible; box-shadow: var(--shadow-3); transition: transform var(--dur) var(--ease-out), visibility 0s; }
.chat-kepala {
    display: flex; align-items: center; gap: 8px;
    padding: calc(var(--safe-t) + 8px) 10px 8px 6px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 2;
}
.chat-kepala .kembali { width: 40px; height: 40px; border-radius: 50%; font-size: 18px; color: var(--text-2); flex: none; display: inline-flex; align-items: center; justify-content: center; }
.chat-kepala .kembali:hover { background: var(--surface-2); }
.chat-identitas { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 11px; padding: 4px 6px; border-radius: 12px; text-align: left; }
.chat-identitas:hover { background: var(--surface-2); }
.chat-identitas .teks { min-width: 0; }
.chat-identitas strong { display: block; font-size: 15.5px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-identitas small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

.pesan-area {
    position: relative;
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 18px;
    background-image: var(--chat-pattern);
    background-size: 18px 18px;
}
.tanggal {
    position: sticky; top: 4px; z-index: 1;
    display: flex; justify-content: center;
    margin: 14px 0 10px;
    pointer-events: none;
}
.tanggal span {
    padding: 5px 12px; border-radius: 99px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: var(--shadow-1);
    font-size: 11.5px; font-weight: 700; color: var(--muted);
    backdrop-filter: blur(8px);
}
.psn {
    display: flex;
    margin: 2px 0;
}
/* Hanya pesan yang baru tiba (dan gelembung yang baru dikirim) yang beranimasi.
   Menggambar ulang daftar - memuat pesan lama, status centang berubah - tidak
   boleh membuat seluruh percakapan berkedip. */
.psn.baru { animation: psnMasuk 260ms var(--ease-out); }
@keyframes psnMasuk { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.psn.keluar { justify-content: flex-end; }
.baris-cuplikan .baca { color: var(--read); }
.baris-cuplikan .gagal-ikon { color: var(--danger); }
.psn.lanjut { margin-top: 1px; }
.psn:not(.lanjut) { margin-top: 8px; }
.gelembung {
    position: relative;
    max-width: min(80%, 560px);
    padding: 8px 11px 6px;
    border-radius: 18px;
    background: var(--bubble-in);
    color: var(--bubble-in-ink);
    box-shadow: var(--shadow-1);
    word-wrap: break-word; overflow-wrap: anywhere;
    touch-action: pan-y;
    transition: transform 160ms var(--ease);
    user-select: text;
}
.psn.masuk:not(.lanjut) .gelembung { border-top-left-radius: 6px; }
.psn.keluar .gelembung { background: var(--bubble-out); color: var(--bubble-out-ink); }
.psn.keluar:not(.lanjut) .gelembung { border-top-right-radius: 6px; }
.psn.tertunda .gelembung { opacity: .72; }
.psn.gagal .gelembung { box-shadow: inset 0 0 0 1.5px var(--danger); }
.psn.disorot .gelembung { animation: sorot 1.4s var(--ease); }
@keyframes sorot { 0%, 30% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); } 100% { box-shadow: var(--shadow-1); } }
.pengirim { display: block; font-size: 12px; font-weight: 800; color: var(--accent); margin-bottom: 2px; }
.psn-teks { white-space: pre-wrap; font-size: 15px; line-height: 1.42; }
.psn-teks a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.psn-teks code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: color-mix(in srgb, currentColor 9%, transparent); padding: 1px 4px; border-radius: 4px; }
.psn-meta {
    float: right;
    display: inline-flex; align-items: center; gap: 4px;
    margin: 6px 0 -2px 10px;
    font-size: 11px; color: color-mix(in srgb, currentColor 52%, transparent);
    font-weight: 600;
    white-space: nowrap;
}
.psn-meta .baca { color: var(--read); }
.psn-meta .gagal-ikon { color: var(--danger); }
.psn-catatan { font-size: 11px; font-style: italic; opacity: .65; margin-left: 6px; }
.psn-terhapus { font-style: italic; opacity: .7; display: inline-flex; gap: 6px; align-items: center; }
.kutip {
    display: block;
    margin: 0 0 6px;
    padding: 6px 10px;
    border-radius: 10px;
    border-left: 3.5px solid var(--accent);
    background: color-mix(in srgb, currentColor 7%, transparent);
    font-size: 12.5px;
    max-height: 64px; overflow: hidden;
}
.kutip strong { display: block; color: var(--accent); font-size: 11.5px; }
.media-gambar {
    display: block;
    margin: -4px -7px 6px;
    border-radius: 14px;
    overflow: hidden;
    background: var(--surface-3);
    min-width: 200px;
}
.media-gambar img { width: 100%; max-height: 340px; object-fit: cover; }
.media-gambar.stiker { background: none; min-width: 0; }
.media-gambar.stiker img { width: 140px; height: 140px; object-fit: contain; }
.media-gambar video, .media-gambar audio { display: block; width: 100%; max-height: 340px; }
.media-gambar audio { min-width: 240px; }
.media-tombol {
    display: flex; align-items: center; gap: 11px;
    width: 100%; min-width: 210px;
    margin: 0 0 6px;
    padding: 10px 12px;
    border-radius: 12px;
    background: color-mix(in srgb, currentColor 7%, transparent);
    text-align: left;
}
.media-tombol .m-ikon {
    width: 40px; height: 40px; border-radius: 11px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface); color: var(--accent); font-size: 17px;
}
.media-tombol strong { display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.media-tombol small { display: block; font-size: 11.5px; opacity: .7; }
.media-tombol.memuat .m-ikon i { animation: putar 900ms linear infinite; }
@keyframes putar { to { transform: rotate(360deg); } }

/* Isyarat geser untuk membalas */
.isyarat-balas {
    position: absolute; left: -38px; top: 50%;
    width: 30px; height: 30px; margin-top: -15px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface); color: var(--accent);
    box-shadow: var(--shadow-1);
    opacity: 0; transform: scale(.5);
    transition: opacity 120ms, transform 160ms var(--ease-out);
    pointer-events: none;
}
.psn.keluar .isyarat-balas { left: -38px; }

.muat-atas { display: flex; justify-content: center; padding: 8px 0 4px; color: var(--muted); font-size: 12px; gap: 8px; align-items: center; }

/* Tombol turun ke pesan terbaru */
.ke-bawah {
    position: absolute; right: 14px; bottom: 14px;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface); color: var(--text-2);
    box-shadow: var(--shadow-2);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    opacity: 0; transform: translateY(12px) scale(.9); pointer-events: none;
    transition: opacity 200ms, transform 240ms var(--ease-out);
    z-index: 3;
}
.ke-bawah.tampil { opacity: 1; transform: none; pointer-events: auto; }
.ke-bawah .lencana {
    position: absolute; top: -6px; right: -4px;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
    background: var(--accent); color: var(--accent-ink);
    font-size: 11px; font-weight: 800; line-height: 20px; text-align: center;
}
.pesan-bungkus { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* Pemberitahuan di atas kotak tulis */
.chat-catatan {
    margin: 0 10px 8px;
    padding: 11px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    box-shadow: var(--shadow-1);
    font-size: 13px; line-height: 1.45; color: var(--text-2);
    display: flex; gap: 10px; align-items: flex-start;
    animation: tabMasuk 240ms var(--ease-out);
}
.chat-catatan i { color: var(--warn); margin-top: 2px; }
.chat-catatan .aksi { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Kotak tulis */
.tulis {
    padding: 8px 10px calc(8px + var(--safe-b));
    background: var(--surface);
    border-top: 1px solid var(--line);
}
.balas-pratinjau {
    display: flex; align-items: center; gap: 10px;
    margin: 0 2px 8px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--surface-2);
    border-left: 3.5px solid var(--accent);
    animation: tabMasuk 200ms var(--ease-out);
}
.balas-pratinjau .teks { flex: 1; min-width: 0; font-size: 12.5px; }
.balas-pratinjau strong { color: var(--accent); display: block; font-size: 11.5px; }
.balas-pratinjau span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.balas-pratinjau button { width: 30px; height: 30px; border-radius: 50%; color: var(--muted); flex: none; }
.tulis-baris { display: flex; align-items: flex-end; gap: 8px; }
.tulis-kotak {
    flex: 1 1 auto; min-width: 0;
    display: flex; align-items: flex-end;
    border-radius: 24px;
    background: var(--surface-2);
    border: 1px solid transparent;
    transition: border-color 160ms, background-color 160ms;
}
.tulis-kotak:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--surface); }
.tulis-kotak textarea {
    flex: 1 1 auto; min-width: 0;
    min-height: 44px; max-height: 140px;
    padding: 11px 6px 11px 4px;
    border: 0; outline: none; resize: none;
    background: transparent;
    font-size: 16px; line-height: 1.38;
}
.tulis-kotak textarea::placeholder { color: var(--faint); }
.tulis .lampir { width: 44px; height: 44px; border-radius: 50%; color: var(--muted); font-size: 18px; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.tulis .lampir:hover { color: var(--accent); }
.kirim {
    width: 46px; height: 46px; border-radius: 50%; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent); color: var(--accent-ink);
    font-size: 17px;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 35%, transparent);
    transition: transform 160ms var(--ease-out), opacity 160ms, box-shadow 160ms;
}
.kirim:disabled { opacity: .45; box-shadow: none; transform: scale(.92); }
.kirim:not(:disabled):active { transform: scale(.9); }
.tulis.terkunci textarea, .tulis.terkunci .lampir { opacity: .5; }

/* Kosong (layar lebar, belum ada chat terpilih) */
.chat-kosong {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--muted); text-align: center; padding: 40px;
}
.chat-kosong .logo-besar { width: 96px; height: 96px; border-radius: 28px; margin-bottom: 20px; box-shadow: var(--shadow-2); }
.chat-kosong h2 { margin: 0 0 6px; color: var(--text); font-size: 20px; }

/* =====================================================================
   Lembar bawah (bottom sheet), dialog, toast, lightbox
   ===================================================================== */
.lapisan {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(5, 12, 22, .42);
    opacity: 0;
    transition: opacity 240ms var(--ease);
}
.lapisan.tampil { opacity: 1; }
.lembar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
    max-height: calc(var(--app-h) - var(--safe-t) - 28px);
    display: flex; flex-direction: column;
    background: var(--surface);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-3);
    transform: translateY(105%);
    transition: transform 320ms var(--ease-out);
    padding-bottom: var(--safe-b);
}
.lembar.tampil { transform: none; }
.lembar-pegangan { display: flex; justify-content: center; padding: 10px 0 2px; cursor: grab; touch-action: none; }
.lembar-pegangan span { width: 42px; height: 5px; border-radius: 99px; background: var(--surface-3); }
.lembar-kepala { display: flex; align-items: center; gap: 10px; padding: 6px 20px 12px; touch-action: none; }
.lembar-kepala h3 { flex: 1; margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.lembar-kepala .ikon-btn { width: 36px; height: 36px; font-size: 15px; }
.lembar-isi { overflow-y: auto; overscroll-behavior: contain; padding: 0 20px 20px; }

.daftar-aksi { list-style: none; margin: 0; padding: 4px 8px 12px; }
.daftar-aksi button, .daftar-aksi a {
    width: 100%;
    display: flex; align-items: center; gap: 14px;
    padding: 13px 14px;
    border-radius: 14px;
    font-size: 15.5px; font-weight: 600; color: var(--text);
    text-align: left;
}
.daftar-aksi button:hover, .daftar-aksi a:hover { background: var(--surface-2); }
.daftar-aksi i { width: 22px; text-align: center; color: var(--muted); font-size: 17px; }
.daftar-aksi .bahaya, .daftar-aksi .bahaya i { color: var(--danger); }
.daftar-aksi small { display: block; font-size: 12.5px; color: var(--muted); font-weight: 500; }

.kartu {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 16px;
    box-shadow: var(--shadow-1);
}
.kartu + .kartu { margin-top: 12px; }
.kartu-judul { font-size: 11.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.info-baris { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.info-baris + .info-baris { border-top: 1px solid var(--line); }
.info-baris .ikon { width: 36px; height: 36px; border-radius: 11px; background: var(--surface-2); color: var(--muted); display: flex; align-items: center; justify-content: center; flex: none; }
.info-baris .teks { flex: 1; min-width: 0; }
.info-baris .teks small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.info-baris .teks span { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.info-baris .salin { color: var(--muted); width: 34px; height: 34px; border-radius: 50%; }
.info-baris .salin:hover { background: var(--surface-2); color: var(--accent); }

.profil-atas { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 6px 0 18px; gap: 4px; }
.profil-atas h2 { margin: 12px 0 0; font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.profil-atas p { margin: 0; color: var(--muted); font-size: 13.5px; }

.tombol {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 46px; padding: 0 20px;
    border-radius: 14px;
    font-weight: 800; font-size: 14.5px;
    background: var(--accent); color: var(--accent-ink);
    transition: transform 120ms var(--ease), filter 160ms, opacity 160ms;
}
.tombol:hover { filter: brightness(1.05); }
.tombol:active { transform: scale(.97); }
.tombol:disabled { opacity: .55; }
.tombol.blok { width: 100%; }
.tombol.kedua { background: var(--surface-2); color: var(--text); }
.tombol.garis { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1.5px var(--line); }
.tombol.bahaya { background: var(--danger-soft); color: var(--danger); }
.tombol.kecil { height: 36px; padding: 0 14px; font-size: 13px; border-radius: 11px; }

.isian { width: 100%; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); padding: 12px 14px; font-size: 16px; outline: none; transition: border-color 160ms, box-shadow 160ms; }
.isian:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent); }
textarea.isian { resize: vertical; min-height: 96px; line-height: 1.45; }

/* Sakelar */
.sakelar { position: relative; width: 52px; height: 32px; flex: none; }
.sakelar input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.sakelar span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); transition: background-color 220ms var(--ease); }
.sakelar span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform 260ms var(--ease-out); }
.sakelar input:checked + span { background: var(--ok); }
.sakelar input:checked + span::after { transform: translateX(20px); }

/* Daftar pengaturan (tab Akun) */
.setelan { padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); }
.setelan .kartu { padding: 6px 16px; }
.setelan-baris { display: flex; align-items: center; gap: 14px; padding: 14px 0; width: 100%; text-align: left; }
.setelan-baris + .setelan-baris { border-top: 1px solid var(--line); }
.setelan-baris .ikon { width: 38px; height: 38px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; }
.setelan-baris .teks { flex: 1; min-width: 0; }
.setelan-baris .teks strong { display: block; font-size: 15px; }
.setelan-baris .teks small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.setelan-baris > .fa-chevron-right { color: var(--faint); font-size: 12px; }
.setelan-kelompok { margin: 22px 4px 8px; font-size: 11.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ik-hijau { background: linear-gradient(135deg, #18b47b, #3ac962); }
.ik-biru { background: linear-gradient(135deg, #1677d2, #3aa0f0); }
.ik-ungu { background: linear-gradient(135deg, #6d4cff, #9b7bff); }
.ik-oranye { background: linear-gradient(135deg, #f08a24, #f5b041); }
.ik-abu { background: linear-gradient(135deg, #64748b, #94a3b8); }
.ik-merah { background: linear-gradient(135deg, #e5484d, #ff7b7f); }

.kartu-profil {
    display: flex; align-items: center; gap: 14px;
    padding: 18px;
    border-radius: var(--r-lg);
    color: #fff;
    background: var(--brand-grad);
    box-shadow: 0 14px 34px color-mix(in srgb, var(--brand-1) 30%, transparent);
    margin-top: 6px;
}
.kartu-profil .avatar { background: rgba(255,255,255,.22); border: 2px solid rgba(255,255,255,.55); }
.kartu-profil strong { display: block; font-size: 17px; font-weight: 800; }
.kartu-profil small { display: block; opacity: .9; font-size: 13px; }

/* Toast */
.toast-wadah {
    position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
    transform: translateX(-50%);
    z-index: 90;
    display: flex; flex-direction: column; gap: 8px; align-items: center;
    width: min(92vw, 420px);
    pointer-events: none;
}
/* Di layar chat bagian bawah milik kotak tulis dan catatannya: toast pindah ke atas. */
body.di-chat .toast-wadah { bottom: auto; top: calc(var(--safe-t) + 70px); }
.toast {
    display: flex; align-items: center; gap: 10px;
    max-width: 100%;
    padding: 12px 16px;
    border-radius: 16px;
    background: #0e1a2b; color: #fff;
    font-size: 13.5px; font-weight: 600;
    box-shadow: var(--shadow-2);
    animation: toastMasuk 300ms var(--ease-out);
    pointer-events: auto;
}
html[data-tema="gelap"] .toast { background: #e9eef6; color: #0e1a2b; }
.toast i { font-size: 15px; }
.toast.ok i { color: #3dd68c; }
.toast.galat i { color: #ff6b6f; }
.toast.keluar { animation: toastKeluar 220ms var(--ease) forwards; }
@keyframes toastMasuk { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastKeluar { to { opacity: 0; transform: translateY(8px) scale(.96); } }

/* Lightbox gambar */
.lightbox {
    position: fixed; inset: 0; z-index: 95;
    background: rgba(0, 0, 0, .94);
    display: flex; flex-direction: column;
    opacity: 0; transition: opacity 220ms;
}
.lightbox.tampil { opacity: 1; }
.lightbox-atas { display: flex; justify-content: flex-end; gap: 10px; padding: calc(var(--safe-t) + 10px) 12px 10px; }
.lightbox-atas a, .lightbox-atas button { width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; }
.lightbox-isi { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 10px; touch-action: pinch-zoom; }
.lightbox-isi img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; animation: lbMasuk 280ms var(--ease-out); }
@keyframes lbMasuk { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }

/* Pratinjau lampiran sebelum dikirim */
.lampiran-pratinjau { border-radius: 16px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; min-height: 140px; margin-bottom: 14px; }
.lampiran-pratinjau img, .lampiran-pratinjau video { max-height: 46vh; width: 100%; object-fit: contain; }
.lampiran-berkas { display: flex; gap: 12px; align-items: center; padding: 18px; width: 100%; }
.lampiran-berkas .m-ikon { width: 52px; height: 52px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 22px; flex: none; }

/* Pemasangan aplikasi */
.pasang-langkah { counter-reset: pl; list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 12px; }
.pasang-langkah li { counter-increment: pl; position: relative; padding-left: 40px; font-size: 14px; line-height: 1.5; color: var(--text-2); }
.pasang-langkah li::before { content: counter(pl); position: absolute; left: 0; top: -2px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.pasang-langkah i { color: var(--link); }

/* Halaman tanpa akses */
.tanpa-akses { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.tanpa-akses .kartu { max-width: 400px; width: 100%; text-align: center; padding: 30px 24px; }

/* =====================================================================
   Layar lebar: dua kolom (daftar + chat)
   ===================================================================== */
@media (min-width: 960px) {
    .app { grid-template-columns: minmax(340px, 400px) 1fr; }
    .kolom-kiri { border-right: 1px solid var(--line); }
    .chat, .chat.buka {
        position: relative; inset: auto;
        transform: none;
        visibility: visible;
        box-shadow: none;
        transition: none;
        z-index: 1;
    }
    .chat .kembali { display: none !important; }
    .lembar { left: 50%; right: auto; width: 480px; bottom: auto; top: 50%; border-radius: var(--r-xl); transform: translate(-50%, -46%) scale(.96); opacity: 0; transition: transform 260ms var(--ease-out), opacity 200ms; max-height: 86vh; padding-bottom: 0; }
    .lembar.tampil { transform: translate(-50%, -50%); opacity: 1; }
    .lembar-pegangan { display: none; }
    .lembar-kepala { padding-top: 20px; }
    .toast-wadah { bottom: 28px; }
    body.di-chat .toast-wadah { bottom: 28px; top: auto; }
    .gelembung { max-width: min(68%, 620px); }
}
@media (max-width: 959.98px) {
    .chat-kosong { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* =====================================================================
   Halaman masuk (crm_masuk.php)
   ===================================================================== */
.halaman-masuk {
    position: fixed; inset: 0;
    overflow-y: auto;
    display: flex; flex-direction: column;
    background: var(--bg);
}
.masuk-hiasan {
    position: relative;
    padding: calc(var(--safe-t) + 46px) 28px 72px;
    color: #fff;
    background: var(--brand-grad);
    overflow: hidden;
}
.masuk-hiasan::before, .masuk-hiasan::after {
    content: ''; position: absolute; border-radius: 50%;
    background: rgba(255,255,255,.12);
}
.masuk-hiasan::before { width: 260px; height: 260px; right: -80px; top: -90px; }
.masuk-hiasan::after { width: 160px; height: 160px; left: -50px; bottom: -70px; }
.masuk-hiasan img { width: 64px; height: 64px; border-radius: 20px; box-shadow: 0 10px 26px rgba(0,0,0,.18); position: relative; z-index: 1; }
.masuk-hiasan h1 { position: relative; z-index: 1; margin: 22px 0 6px; font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.masuk-hiasan p { position: relative; z-index: 1; margin: 0; font-size: 15px; opacity: .92; max-width: 330px; }
.masuk-kartu {
    position: relative; z-index: 2;
    margin: -40px 16px 24px;
    padding: 24px 20px;
    border-radius: var(--r-xl);
    background: var(--surface);
    box-shadow: var(--shadow-2);
    animation: tabMasuk 420ms var(--ease-out);
}
.masuk-kartu h2 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.masuk-kartu > p { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }
.label { display: block; font-size: 13px; font-weight: 700; color: var(--text-2); margin: 14px 0 6px; }
.isian-ikon { position: relative; }
.isian-ikon > i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.isian-ikon .isian { padding-left: 42px; height: 52px; }
.isian-ikon .mata { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; color: var(--muted); }
.masuk-galat { margin: 0 0 6px; padding: 11px 14px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: 13px; display: flex; gap: 9px; align-items: flex-start; }
.pemisah { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--faint); font-size: 12px; font-weight: 700; }
.pemisah::before, .pemisah::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.masuk-bawah { margin-top: auto; padding: 0 24px calc(var(--safe-b) + 24px); text-align: center; font-size: 12.5px; color: var(--muted); }
.masuk-bawah a { font-weight: 700; }
@media (min-width: 720px) {
    .halaman-masuk { align-items: center; justify-content: center; background: var(--brand-grad); }
    .masuk-hiasan { display: none; }
    .masuk-kartu { margin: 24px; width: 420px; padding: 32px 28px; }
    .masuk-kartu .logo-kartu { display: flex !important; }
    .masuk-bawah { margin-top: 0; color: rgba(255,255,255,.88); }
    .masuk-bawah a { color: #fff; }
}
