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

/* PERBAIKAN 1: Mencegah efek mental/scroll bawaan browser HP dan menggunakan dinamic viewport */
html, body { height: 100%; height: 100dvh; overflow: hidden; margin: 0; touch-action: manipulation; }
body { background-color: #f1f3f4; display: flex; justify-content: center; align-items: center; }

.app-container { display: flex; width: 95vw; max-width: 1300px; height: 95vh; background-color: #ffffff; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); border: 1px solid #dadce0; overflow: hidden; position: relative; }

button { font-family: inherit; transition: all 0.15s ease; outline: none; }
.btn-primary { background: #1a73e8; color: white; border: none; padding: 10px 20px; border-radius: 20px; cursor: pointer; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #1557b0; }
.btn-primary:disabled { background: #a8c7fa; cursor: not-allowed; }
.btn-secondary { background: #f8f9fa; color: #202124; border: 1px solid #dadce0; padding: 10px 20px; border-radius: 20px; cursor: pointer; font-weight: 500; }
.btn-secondary:hover { background: #f1f3f4; border-color: #d5d7db; }
.btn-danger { background: #ea4335; color: white; border: none;}
.btn-danger:hover:not(:disabled) { background: #d33426; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn-icon { background: transparent; border: none; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; font-size: 1.1rem; }
.btn-icon:hover { background: #f1f3f4; }
.btn-info-circle { width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid #1a73e8; background: transparent; color: #1a73e8; font-weight: bold; font-size: 1.1rem; cursor: pointer; display: flex; justify-content: center; align-items: center; flex-shrink: 0;}
.btn-info-circle:hover { background: #1a73e8; color: white; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"] { width: 100%; padding: 12px 15px; border: 1px solid #dadce0; border-radius: 8px; outline: none; background: #f8f9fa; margin-bottom: 12px; font-size: 0.95rem; }
input:focus { border-color: #1a73e8; background: #fff; }
select:focus { border-color: #1a73e8; }

#auth-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #f8f9fa; z-index: 100; display: flex; justify-content: center; align-items: center; }
.auth-box { background: white; padding: 35px; border-radius: 12px; width: 340px; max-width: 90%; text-align: center; border: 1px solid #dadce0; }
.auth-box h2 { margin-bottom: 20px; color: #202124; font-size: 1.4rem; }
.auth-toggle { color: #1a73e8; cursor: pointer; font-size: 0.9rem; margin-top: 10px; }

#main-app { display: none; width: 100%; height: 100%; flex-direction: row; }
.sidebar { width: 320px; border-right: 1px solid #dadce0; display: flex; flex-direction: column; background-color: #ffffff; flex-shrink: 0; }
.sidebar-header { padding: 15px; border-bottom: 1px solid #dadce0; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.sidebar-header h2 { font-size: 1.1rem; color: #202124; margin-bottom: 2px; }
.profile-trigger { cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 5px; border-radius: 6px; overflow: hidden; }
.profile-trigger:hover { background-color: #f1f3f4; }
.header-text-area { flex: 1; overflow: hidden; }
.header-text-area h2, .header-text-area small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.profile-trigger small { color: #5f6368; font-size: 0.8rem; }
.menu-buttons { display: flex; gap: 2px; flex-shrink: 0; }

.chat-list { flex: 1; overflow-y: auto; }
.chat-list-item { display: flex; align-items: center; padding: 12px 15px; cursor: pointer; border-bottom: 1px solid #f8f9fa; }
.chat-list-item:hover { background-color: #f8f9fa; }
.chat-list-item.active { background-color: #e8f0fe; border-right: 3px solid #1a73e8; }

.avatar { width: 42px; height: 42px; border-radius: 50%; background-color: #1a73e8; color: white; display: flex; justify-content: center; align-items: center; font-weight: bold; flex-shrink: 0; overflow: hidden; font-size: 1.1rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 70px; height: 70px; font-size: 1.8rem; margin: 0 auto 10px auto; }

.chat-info { flex: 1; overflow: hidden; margin-left: 10px; }
.chat-info h4 { color: #202124; font-size: 0.95rem; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-info p { color: #5f6368; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* PERBAIKAN 2: Pastikan chat-window menjaga batasnya sendiri */
.chat-window { flex: 1; display: flex; flex-direction: column; background-color: #f0f2f5; min-width: 0; height: 100%; overflow: hidden; }
.chat-header { padding: 12px 20px; border-bottom: 1px solid #dadce0; display: flex; justify-content: space-between; align-items: center; background: white; z-index: 5; flex-shrink: 0; }
.chat-header-info { display: flex; align-items: center; gap: 12px; overflow: hidden; }
.chat-header-info h2 { font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-back { display: none; }

.kick-warning-banner { background: #ea4335; color: white; text-align: center; padding: 8px; font-size: 0.85rem; font-weight: bold; z-index: 4; box-shadow: 0 2px 5px rgba(0,0,0,0.1); flex-shrink: 0;}

/* PERBAIKAN 3: min-height 0 memastikan scroll berfungsi dengan baik */
.chat-messages { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.date-separator { align-self: center; background-color: #e4e6eb; color: #4b4f56; font-size: 0.75rem; padding: 5px 12px; border-radius: 12px; margin: 10px 0; }

.message { max-width: 70%; padding: 8px 12px; position: relative; font-size: 0.95rem; line-height: 1.4; word-wrap: break-word; }
.message.received { background-color: #ffffff; color: #202124; align-self: flex-start; border-radius: 0 12px 12px 12px; border: 1px solid #e8eaed; }
.message.sent { background-color: #d3e3fd; color: #041e49; align-self: flex-end; border-radius: 12px 0 12px 12px; }

.message .sender-name { font-size: 0.75rem; font-weight: bold; margin-bottom: 4px; cursor: pointer; display: inline-block; padding: 2px 4px; border-radius: 4px; transition: background 0.2s;}
.message .sender-name:hover { background: rgba(0,0,0,0.05); }

.media-album { display: grid; gap: 4px; border-radius: 8px; overflow: hidden; max-width: 260px; margin: 4px 0; }
.media-album[data-count="1"] { grid-template-columns: 1fr; max-width: 240px; }
.media-album[data-count="2"] { grid-template-columns: 1fr 1fr; }
.media-album[data-count="3"], .media-album[data-count="4"] { grid-template-columns: 1fr 1fr 1fr; }
.media-container { position: relative; cursor: pointer; background: #000; width: 100%; }
.media-album .media-container img, .media-album .media-container video { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 1/1; display: block; }
.media-album[data-count="1"] .media-container img, .media-album[data-count="1"] .media-container video { aspect-ratio: auto; max-height: 250px; }

.play-icon-overlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 36px; height: 36px; background: rgba(0,0,0,0.5); color: white; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 1rem; pointer-events: none; z-index: 2; }
.uploading-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; font-size: 0.85rem; gap: 8px; z-index: 3; }
.progress-bar-container { width: 80%; height: 6px; background: rgba(255,255,255,0.3); border-radius: 4px; overflow: hidden; margin-top: 5px; }
.progress-bar-fill { height: 100%; background: #34a853; width: 0%; transition: width 0.1s ease-out; }
.btn-cancel-upload { background: rgba(255,255,255,0.2); border: 1px solid white; color: white; padding: 4px 10px; border-radius: 12px; cursor: pointer; font-size: 0.75rem; margin-top: 5px;}
.btn-cancel-upload:hover { background: rgba(234,67,53,0.8); border-color: transparent; }

.message .time-row { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 2px; }
.time { font-size: 0.7rem; color: rgba(0,0,0,0.5); }
.btn-delete-msg { background: transparent; border: none; color: #5f6368; cursor: pointer; font-size: 0.85rem; opacity: 0.5; padding: 2px; }
.btn-delete-msg:hover { opacity: 1; color: #ea4335; }

/* PERBAIKAN 4: Cegah Input Area terdorong hilang dengan flex-shrink: 0 */
.chat-input-area { padding: 12px 20px; background-color: white; display: flex; gap: 8px; align-items: center; border-top: 1px solid #dadce0; flex-shrink: 0; z-index: 10;}
.chat-input-area input[type="text"] { flex: 1; margin: 0; background: #f0f2f5; border: none; border-radius: 20px; padding: 12px 18px; }
.attach-btn { font-size: 1.3rem; background: transparent; border: none; cursor: pointer; padding: 5px; color: #5f6368; flex-shrink: 0;}
.attach-btn:hover { color: #1a73e8; }
.send-btn { border-radius: 20px; padding: 0 20px; height: 40px; flex-shrink: 0;}

.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); justify-content: center; align-items: center; z-index: 200;}
.modal { background: white; padding: 25px; border-radius: 12px; width: 380px; max-width: 90%; max-height: 85vh; overflow-y: auto; }
.modal-sm { width: 320px; padding: 20px; }
.modal h3 { margin-bottom: 15px; color: #202124; }
.admin-panel { padding: 12px; background: #f8f9fa; border-radius: 8px; margin-bottom: 15px; border: 1px solid #e8eaed; }
.code-box { background: #ffffff; border: 1.5px dashed #1a73e8; padding: 12px; border-radius: 8px; text-align: center; margin-bottom: 15px; user-select: text; }
.members-list { margin-top: 10px; max-height: 180px; overflow-y: auto; background: #fff; border-radius: 8px; padding: 0 10px; border: 1px solid #e8eaed; }
.member-list-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #f1f3f4; font-size: 0.85rem; }
.badge-admin { background: #34a853; color: white; font-size: 0.6rem; padding: 2px 6px; border-radius: 8px; margin-left: 6px; }

.admin-actions { display: flex; gap: 4px; flex-shrink: 0;}
.btn-admin-action { background: #e8eaed; color: #4b4f56; border: none; border-radius: 4px; padding: 4px 6px; font-size: 0.7rem; cursor: pointer; }
.btn-admin-action:hover { background: #dadce0; }
.btn-admin-danger:hover { background: #fce8e6; color: #d93025; }

#toast-container { position: fixed; top: 15px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; width: 90%; align-items: center;}
.toast { background: #323232; color: white; padding: 10px 20px; border-radius: 20px; font-size: 0.85rem; animation: slideDown 0.2s forwards, fadeOut 0.2s forwards 2.8s; font-weight: 500; text-align: center;}
.toast.success { background: #188038; }
.toast.error { background: #d93025; }
@keyframes slideDown { from { transform: translateY(-15px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; visibility: hidden; } }

.lightbox-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: #000; z-index: 1000; justify-content: center; align-items: center; flex-direction: column; user-select: none; }
.lightbox-content { max-width: 100vw; max-height: 100vh; display: flex; justify-content: center; align-items: center; }
.lightbox-content img, .lightbox-content video { max-width: 100%; max-height: 100vh; object-fit: contain; }
.lightbox-close { position: absolute; top: 15px; right: 20px; background: rgba(255,255,255,0.15); border: none; color: white; font-size: 1.2rem; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; z-index: 10; }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.15); border: none; color: white; font-size: 1.5rem; width: 50px; height: 50px; border-radius: 50%; cursor: pointer; z-index: 10;}
.nav-left { left: 15px; } .nav-right { right: 15px; }
.lightbox-counter { position: absolute; bottom: 20px; color: white; font-size: 0.9rem; background: rgba(0,0,0,0.5); padding: 4px 12px; border-radius: 12px; }

/* KODE UNTUK RESPONSIF SMARTPHONE (HP) */
@media (max-width: 768px) {
    .app-container { width: 100vw; height: 100%; height: 100dvh; border-radius: 0; border: none; }
    .sidebar { width: 100%; }
    .chat-window { display: none; width: 100%; height: 100%; }
    
    #main-app.chat-active .sidebar { display: none; }
    #main-app.chat-active .chat-window { display: flex; }
    
    .btn-back { display: flex !important; margin-right: 8px;}
    .message { max-width: 85%; }
    .chat-header { padding: 10px 15px; }
    
    /* Mencegah input chat tertutup keyboard atau home bar di iPhone */
    .chat-input-area { padding: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    
    .desktop-only-msg { display: none; }
    .auth-box { width: 90%; padding: 25px; }
}
