@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* --- Light Mode Palette --- */
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-muted: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --primary: #0d9488;
    --primary-light: #06b6d4;
    --bubble-sent: #0d9488;
    --bubble-sent-text: #ffffff;
    --bubble-recv: #f1f5f9;
    --bubble-recv-text: #0f172a;
    --online-indicator: #22c55e;
}

[data-theme="dark"] {
    /* --- Dark Mode Palette --- */
    --bg-main: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-muted: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border: #334155;
    --primary: #14b8a6;
    --primary-light: #22d3ee;
    --bubble-sent: #14b8a6;
    --bubble-sent-text: #0f172a;
    --bubble-recv: #334155;
    --bubble-recv-text: #f8fafc;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
}

/* --- Layout Split Screen (Halaman Utama) --- */
.split-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.split-left {
    flex: 1;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 4rem;
}

.split-left h1 { font-size: 3rem; font-weight: 800; margin-bottom: 1.5rem; line-height: 1.2; }
.split-left p { font-size: 1.2rem; opacity: 0.9; max-width: 500px; line-height: 1.6; }

.split-right {
    width: 480px;
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem;
    border-left: 1px solid var(--border);
    position: relative;
}

/* --- Theme Toggle Switch --- */
.theme-switch-wrapper {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
}

.btn-theme {
    background: var(--bg-surface-muted);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 30px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
}

/* --- UI Komponen Form --- */
.form-card { width: 100%; }
.form-card h2 { font-size: 1.75rem; margin-bottom: 0.5rem; }
.form-card p { color: var(--text-secondary); margin-bottom: 2rem; font-size: 0.95rem; }

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-secondary); }

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 0.85rem 1rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
}

input[type="text"]:focus, input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.btn-primary {
    width: 100%;
    padding: 0.85rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 1rem;
}
.btn-primary:hover { opacity: 0.95; }

/* --- Tata Letak Ruang Chat Modern --- */
.chat-container {
    max-width: 1200px;
    margin: 2rem auto;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex;
    height: calc(100vh - 4rem);
    overflow: hidden;
    box-shadow: 0 4px 20px -2px rgba(0,0,0,0.05);
}

.sidebar {
    width: 340px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    min-height: 0; /* Mencegah flex item meluap di firefox/chrome */
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.room-list { flex: 1; overflow-y: auto; min-height: 0; }
.room-item {
    display: flex;
    align-items: center;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.room-item:hover, .room-item.active { background: var(--bg-surface-muted); }

/* --- Indikator Bulatan Online --- */
.avatar-wrapper {
    position: relative;
    margin-right: 1rem;
}
.user-avatar {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}
.status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background-color: var(--online-indicator);
    border: 2px solid var(--bg-surface);
    border-radius: 50%;
    display: none;
}
.status-dot.active { display: block; }

.main-chat { flex: 1; display: flex; flex-direction: column; background: var(--bg-main); min-height: 0; }
.chat-header {
    padding: 1.25rem 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-body { flex: 1; padding: 2rem; overflow-y: auto; display: flex; flex-direction: column; gap: 1.25rem; min-height: 0; }

/* --- Balon Chat & Menu Opsi --- */
.message-row { display: flex; width: 100%; position: relative; }
.message-row.sent { justify-content: flex-end; }
.message-row.received { justify-content: flex-start; }

.message-bubble {
    max-width: 65%;
    padding: 0.85rem 1.25rem;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
}

.message-row.sent .message-bubble { background: var(--bubble-sent); color: var(--bubble-sent-text); border-bottom-right-radius: 2px; }
.message-row.received .message-bubble { background: var(--bubble-recv); color: var(--bubble-recv-text); border-bottom-left-radius: 2px; }

.meta-info { font-size: 0.7rem; opacity: 0.6; margin-top: 0.35rem; display: block; text-align: right; }

/* Menu aksi hover hapus/edit */
.msg-actions {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    gap: 0.35rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 0.25rem;
    border-radius: 6px;
    z-index: 5;
}
.message-row.sent:hover .msg-actions { display: flex; left: -75px; }

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 4px;
    color: var(--text-secondary);
}
.action-btn:hover { color: var(--primary); }

/* Status Sedang Mengetik */
.typing-indicator {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    padding: 0.25rem 1.5rem;
    flex-shrink: 0;
}

.chat-footer { padding: 1.25rem 1.5rem; background: var(--bg-surface); border-top: 1px solid var(--border); flex-shrink: 0; }

/* --- BARU: Perbaikan Penataan Flex Input Komponen --- */
.input-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    width: 100%;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.15rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover { color: var(--primary); }

/* Popover Pemilih Emoji */
.emoji-picker {
    position: absolute;
    bottom: 55px;
    left: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.35rem;
    z-index: 50;
}
.emoji-item {
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.25rem;
    text-align: center;
    border-radius: 4px;
}
.emoji-item:hover { background: var(--bg-surface-muted); }

/* Kotak File Terlampir */
.file-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface-muted);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
}

/* --- Menu Switcher Pengaturan Privasi --- */
.privacy-panel {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    flex-shrink: 0;
}
.privacy-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

@media (max-width: 900px) {
    .split-left { display: none; }
    .split-right { width: 100%; padding: 2rem; }
}

/* ==========================================================================
   SISTEM FULL RESPONSIVITAS MOBILE VIEW & FIX FOOTER TERPOTONG
   ========================================================================== */

@media (max-width: 768px) {
    body:not(.force-desktop) {
        padding: 0 !important;
        margin: 0 !important;
        height: 100vh;
        height: -webkit-fill-available; /* Trik iOS & Android modern agar pas layar */
        overflow: hidden;
    }

    body:not(.force-desktop) .chat-container {
        margin: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: -webkit-fill-available; /* Memaksa kontainer selalu 100% tinggi nyata */
        max-width: 100% !important;
        position: relative;
    }

    /* Mengubah sistem slide view menumpuk penuh */
    body:not(.force-desktop) .sidebar {
        width: 100% !important;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 10;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    body:not(.force-desktop) .main-chat {
        width: 100% !important;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 5;
        display: flex !important; /* Harus selalu flex agar struktur di dalamnya patuh */
    }

    /* Logika Alur Geser Halaman Mobile */
    body:not(.force-desktop).room-opened .sidebar {
        transform: translateX(-100%);
    }

    body:not(.force-desktop):not(.room-opened) .main-chat {
        transform: translateX(100%);
    }

    /* Memaksa chat body menyesuaikan sisa tempat tanpa mendorong footer keluar layar */
    body:not(.force-desktop) .chat-body {
        padding: 1rem;
    }

    body:not(.force-desktop) .message-bubble {
        max-width: 85%;
    }
}

/* Paksa tampilan desktop jika tombol Desktop Mode diaktifkan */
body.force-desktop {
    min-width: 1200px !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
}

body.force-desktop .chat-container {
    max-width: 1200px !important;
    margin: 2rem auto !important;
    border: 1px solid var(--border) !important;
    border-radius: 16px !important;
    display: flex !important;
    height: calc(100vh - 4rem) !important;
    position: static !important;
}

body.force-desktop .sidebar {
    width: 340px !important;
    position: static !important;
    transform: none !important;
    display: flex !important;
}

body.force-desktop .main-chat {
    flex: 1 !important;
    position: static !important;
    transform: none !important;
    display: flex !important;
}