/* style.css - 8-Point Grid & Glassmorphism Edition */
:root {
    --primary: #DA251D; 
    --primary-light: #FADBD8;
    --bg-main: #F0F2F5;
    --bg-panel: #FFFFFF;
    --bg-white: #FFFFFF;
    --text-dark: #000000; 
    --text-muted: #667781;
    --border-color: #D1D7DB;
    --msg-received: #FFFFFF;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }

body { 
    background-color: #D1D7DB; 
    display: flex; justify-content: center; align-items: center; 
    height: 100dvh; overflow: hidden; position: relative; 
    color: var(--text-dark); 
}

.wa-bg-top { 
    position: absolute; top: 0; left: 0; 
    width: 100%; height: 128px;
    background-color: var(--primary); z-index: -1; 
}

.glass-panel {
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.1);
}

.login-body { background-color: var(--bg-main); }
.login-container { padding: 48px 32px; width: 90%; max-width: 400px; text-align: center; margin: auto; border-radius: 24px; }
.login-logo { max-width: 80%; height: auto; max-height: 64px; object-fit: contain; margin-bottom: 32px; }
.login-container input { width: 100%; padding: 16px; margin: 8px 0; border: 1px solid var(--border-color); border-radius: 8px; background: rgba(255, 255, 255, 0.9); outline: none; font-size: 15px; }
.login-container button { width: 100%; padding: 16px; margin-top: 16px; background: var(--primary); color: white; border: none; border-radius: 8px; cursor: pointer; font-size: 16px; font-weight: bold; transition: 0.2s;}
.login-container button:hover { background: #B91D16; }
.error { color: #e74c3c; font-size: 14px; margin-bottom: 16px; }
.auth-switch { margin-top: 24px; font-size: 14px; color: var(--text-muted); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: bold; }

.app-container { display: flex; width: 100%; max-width: 1600px; height: calc(100dvh - 48px); background: var(--bg-white); box-shadow: 0 8px 24px rgba(11,20,26,.05); border-radius: 16px; overflow: hidden;}
.header { padding: 8px 16px; height: 64px; display: flex; align-items: center; justify-content: space-between; background: var(--bg-panel); border-right: 1px solid var(--border-color); }
.header-logo { height: 24px; max-width: 130px; object-fit: contain; margin: 0 10px; }
.user-info { display: flex; align-items: center; gap: 16px; color: var(--text-dark); }
.avatar { width: 48px; height: 48px; background: #dfe5e7; color: var(--text-dark); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 18px; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.header-actions { display: flex; gap: 8px; }
.icon-btn { width: 48px; height: 48px; border-radius: 50%; border: none; background: transparent; color: #54656f; font-size: 20px; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.icon-btn:hover { background: rgba(11,20,26,.1); }

.sidebar { width: 35%; border-right: 1px solid var(--border-color); display: flex; flex-direction: column; background: var(--bg-white); }
.search-bar { padding: 16px; border-bottom: 1px solid var(--border-color); background: var(--bg-white); }
.search-bar input { width: 100%; padding: 8px 16px; border-radius: 16px; border: none; background: var(--bg-main); outline: none; font-size: 14px; }
.chat-list { flex: 1; overflow-y: auto; }
.chat-list::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 8px; }
.chat-item { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--bg-main); cursor: pointer; transition: 0.1s; background: var(--bg-white); }
.chat-item:hover { background: var(--bg-main); }
.chat-item.active { background: #f0f2f5; }
.chat-info h4 { font-size: 16px; color: var(--text-dark); margin-bottom: 4px; font-weight: normal;}
.chat-info p { font-size: 14px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px; }
.unread-badge { background: var(--primary); color: white; border-radius: 16px; padding: 4px 8px; font-size: 12px; font-weight: bold; }

.chat-area { width: 65%; display: flex; flex-direction: column; position: relative; background: var(--bg-main); }
.chat-header { border-right: none; border-bottom: 1px solid var(--border-color); }
.chat-header-info { display: flex; align-items: center; gap: 16px; }
.status-text { font-size: 14px; color: var(--text-muted); }

.wa-bg-image { background-image: url("https://i.pinimg.com/originals/8c/98/99/8c98994518b575bfd8c949e91d20548b.jpg"); background-size: cover; background-position: center; opacity: 0.95; }
.messages { flex: 1; padding: 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.empty-state-wa { margin: auto; text-align: center; color: var(--text-muted); }

.message { max-width: 65%; padding: 8px 16px; border-radius: 16px; position: relative; font-size: 15px; line-height: 1.5; display: inline-block; word-wrap: break-word; box-shadow: 0 1px 2px rgba(11,20,26,.15); }
.message-actions { display: none; position: absolute; top: 0; right: -8px; width: 80px; justify-content: flex-end; gap:8px; background: linear-gradient(to right, transparent, var(--msg-received) 20%); padding-left: 16px; border-top-right-radius:16px; }
.sent .message-actions { background: linear-gradient(to right, transparent, var(--primary-light) 20%); }
.message:hover .message-actions { display: flex; }
.action-btn { background: transparent; border: none; font-size: 14px; cursor: pointer; color: var(--text-muted); }

.msg-deleted { font-style: italic; color: var(--text-muted); }
.msg-edited-tag { font-size: 12px; color: var(--text-muted); font-style: italic; margin-left: 8px; }
.message .sender-name { font-size: 13px; font-weight: bold; color: var(--primary); margin-bottom: 4px; display: block; }
.message .meta { font-size: 12px; color: var(--text-muted); float: right; margin-top: 8px; margin-left: 16px; display:flex; align-items:center;}

.message.received { background: var(--msg-received); align-self: flex-start; border-top-left-radius: 0; }
.message.sent { background: var(--primary-light); align-self: flex-end; border-top-right-radius: 0; }

.msg-img { max-width: 100%; max-height: 256px; border-radius: 8px; margin-bottom: 8px; display: block; cursor: zoom-in; }
.msg-file { display: inline-block; padding: 8px 16px; background: rgba(0,0,0,0.05); border-radius: 8px; text-decoration: none; color: var(--text-dark); font-weight: 500; margin-bottom: 8px; }
.msg-audio { height: 48px; max-width: 256px; border-radius: 24px; outline: none; margin-bottom: 8px;}

.quote-block { background: rgba(0,0,0,0.05); border-left: 4px solid var(--primary); padding: 8px; margin-bottom: 8px; border-radius: 8px; font-size: 14px; color: var(--text-dark); }
.forwarded-tag { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.gps-tag { font-size: 12px; color: var(--primary); text-decoration: none; margin-left: 8px; font-weight: bold; }
.gps-tag:hover { text-decoration: underline; }
.reader-mini-container { display: inline-flex; margin-left: 8px; align-items: center; }
.reader-mini-ava { width: 16px; height: 16px; border-radius: 50%; overflow: hidden; margin-left: -4px; border: 1px solid white; display:flex; align-items:center; justify-content:center; background:#ccc; font-size:8px; color:white; }
.reader-mini-ava img { width: 100%; height: 100%; object-fit: cover; }

#replyPreview { display: none; padding: 8px 16px; background: #f0f2f5; border-left: 4px solid var(--primary); margin-bottom: 8px; border-radius: 8px; font-size: 14px; position: relative; }
#replyPreview .close-reply { position: absolute; right: 16px; top: 8px; cursor: pointer; color: var(--primary); font-weight: bold; }

.input-area { background: var(--bg-panel); padding: 16px; position: relative;}
#messageForm { display: flex; gap: 16px; align-items: center; }

.attach-menu { display: none; position: absolute; bottom: 72px; left: 16px; border-radius: 24px; flex-direction: column; padding: 16px 0; min-width: 240px; z-index: 50; transform: translateY(16px); opacity: 0; transition: all 0.2s ease; }
.attach-menu.active { display: flex; transform: translateY(0); opacity: 1; }
.attach-item { display: flex; align-items: center; gap: 16px; padding: 8px 24px; cursor: pointer; transition: 0.2s; font-weight: 500; font-size: 15px; color: var(--text-dark); border: none; background: transparent; width: 100%; text-align: left; }
.attach-item:hover { background: rgba(0,0,0,0.05); }
.icon-circle { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px; }

.emoji-color { background: #f1c40f; }
.photo-color { background: #007bff; }
.doc-color { background: #9b59b6; }
.mic-color { background: var(--primary); }

#messageInput { flex: 1; padding: 16px 24px; border: none; border-radius: 24px; outline: none; font-size: 15px; background: var(--bg-main); color: var(--text-dark); }
.send-btn { background: var(--primary); color: white; border: none; cursor: pointer; font-size: 20px; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.send-btn:hover { background: #B91D16; }
.file-preview { display: none; padding: 16px; background: var(--bg-main); border-radius: 8px; margin-bottom: 16px; font-size: 14px; border: 1px solid var(--border-color);}

.recording-pulse { animation: pulse-red 1.5s infinite; color: var(--primary) !important; }
@keyframes pulse-red { 0% { transform: scale(0.9); opacity: 1; } 50% { transform: scale(1.1); opacity: 0.6; } 100% { transform: scale(0.9); opacity: 1; } }

.emoji-picker { display: none; position: absolute; bottom: 72px; left: 16px; width: 256px; padding: 16px; border-radius: 24px; flex-wrap: wrap; gap: 8px; z-index: 50; }
.emoji-picker.active { display: flex; }
.emoji { font-size: 24px; cursor: pointer; padding: 8px; transition: 0.2s; }
.emoji:hover { background: rgba(0,0,0,0.05); border-radius: 8px; }

.status-tick { margin-left: 4px; font-size: 13px; font-weight: bold; }
.tick-read { color: #53bdeb; }
.tick-delivered { color: var(--text-muted); }

.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100dvh; background: rgba(0,0,0,0.4); justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(4px); }
.modal.active { display: flex; }
.modal-content { width: 400px; padding: 32px; border-radius: 24px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; color: var(--primary);}
.close-btn { background: transparent; border: none; font-size: 32px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { max-height: 480px; overflow-y: auto; }
.user-item { padding: 16px; border-bottom: 1px solid var(--border-color); cursor: pointer; display: flex; align-items: center; gap: 16px; }
.user-item:hover { background: rgba(0,0,0,0.05); }
.group-user-item { padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-color); }
.group-user-item:hover { background: rgba(0,0,0,0.05); }

.lightbox { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100dvh; z-index: 999; background: rgba(0,0,0,0.9); justify-content: center; align-items: center; }
.lightbox.active { display: flex; }
.lightbox img { max-width: 90%; max-height: 90%; border-radius: 8px; }
.close-lightbox { position: absolute; top: 24px; right: 32px; font-size: 48px; color: white; cursor: pointer; }

table th { background: rgba(0,0,0,0.05); padding: 16px; border-radius: 8px; }
table td { padding: 16px; border-bottom: 1px solid var(--border-color); }
.badge { font-size: 12px; padding: 4px 8px; border-radius: 8px; color: white; }
.badge.super { background: var(--text-dark); }
.badge.user { background: var(--text-muted); }

@media (max-width: 768px) {
    body { padding: 0; }
    .wa-bg-top { display: none; }
    .app-container { display: block; position: relative; height: 100dvh; width: 100vw; margin: 0; border-radius: 0; box-shadow: none; overflow: hidden; }
    .sidebar { width: 100%; height: 100dvh; position: absolute; top: 0; left: 0; z-index: 20; background: var(--bg-white); transition: transform 0.3s ease-in-out; }
    .sidebar.hidden { transform: translateX(-100%); }
    .chat-area { width: 100%; height: 100dvh; position: absolute; top: 0; left: 0; z-index: 10; }
    .header { padding: 8px 12px; }
    .header-logo { height: 20px; max-width: 100px; } 
    .icon-btn { width: 38px; height: 38px; font-size: 16px; } 
    .back-btn { display: flex !important; margin-right: 12px; }
    .messages { padding: 16px; }
    .input-area { padding: 16px; }
    .attach-menu { width: calc(100% - 32px); bottom: 80px; }
    .emoji-picker { width: calc(100% - 32px); bottom: 80px; }
}