/* =========================================
   1. Floating Chat Button & Badge
   ========================================= */
.chat-widget-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: #075e54;
    border-radius: 50%;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: transform 0.3s;
}

.chat-widget-btn:hover {
    transform: scale(1.1);
}

.chat-widget-btn .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 10px;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
    display: none; /* Diatur oleh JS */
    align-items: center;
    justify-content: center;
    font-weight: bold;
    padding: 0 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* =========================================
   2. Chat Widget Container & Main Header
   ========================================= */
.chat-widget-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    z-index: 9998;
    display: none !important; /* Default tersembunyi */
    flex-direction: column;
    overflow: hidden;
}

/* PERBAIKAN KRUSIAL DI SINI */
.chat-widget-container.active {
    display: flex !important; 
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-widget-header {
    background: #075e54;
    color: white;
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-widget-header h3 {
    margin: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-widget-header small {
    font-size: 11px;
    opacity: 0.8;
    display: block;
    margin-top: 2px;
}

.chat-widget-header .close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s;
}

.chat-widget-header .close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* =========================================
   3. User List (DIPERBARUI UNTUK FITUR UNREAD & LAST MESSAGE)
   ========================================= */
.chat-widget-users {
    flex: 1;
    overflow-y: auto;
    background: #fff;
}

.chat-widget-user {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
    position: relative;
}

.chat-widget-user:hover {
    background: #f5f5f5;
}

.chat-widget-user.active {
    background: #f0f9ff;
    border-left: 3px solid #075e54;
}

/* ✅ BARU: Highlight untuk user yang punya chat belum dibaca */
.chat-widget-user.has-unread {
    background-color: #f0fdf4;
}
.chat-widget-user.has-unread:hover {
    background-color: #dcfce7;
}

.chat-widget-user .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #075e54;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    position: relative;
    flex-shrink: 0;
    font-weight: bold;
}

/* ✅ DIPERBAIKI: Ubah dari 'none' agar titik hijau muncul saat online */
.chat-widget-user .avatar .status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid white;
    display: block; 
}

.chat-widget-user .user-info {
    flex: 1;
    overflow: hidden;
    min-width: 0; /* Penting agar text-overflow: ellipsis bekerja */
}

/* ✅ BARU: Wrapper untuk Nama dan Badge Unread */
.chat-widget-user .user-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-widget-user .user-name {
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 8px;
}

/* ✅ BARU: Badge merah di daftar user */
.chat-widget-user .unread-badge {
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

/* ✅ BARU: Wrapper untuk Status dan Last Message */
.chat-widget-user .user-status-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-widget-user .user-status {
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
}

.chat-widget-user .last-message {
    font-size: 12px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 400;
}

/* Jika ada unread, buat last message sedikit lebih gelap/tebal */
.chat-widget-user.has-unread .last-message {
    color: #1e293b;
    font-weight: 600;
}

/* =========================================
   4. Chat Area
   ========================================= */
.chat-widget-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e5ddd5;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%239C92AC' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E");
}

.chat-widget-chat-header {
    padding: 10px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
}

.chat-widget-chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-widget-back-icon {
    background: none;
    border: none;
    color: #075e54;
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    margin-right: 4px;
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget-back-icon:hover {
    background: rgba(7, 94, 84, 0.1);
}

.chat-widget-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #075e54;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-widget-chat-name {
    font-weight: 700;
    color: #1e293b;
    font-size: 14px;
}

.chat-widget-chat-status {
    font-size: 12px;
    color: #10b981;
    font-weight: 600;
}

.chat-widget-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-widget-message {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-widget-message.sent {
    align-self: flex-end;
    background: #dcf8c6;
    border-bottom-right-radius: 2px;
}

.chat-widget-message.received {
    align-self: flex-start;
    background: white;
    border-bottom-left-radius: 2px;
}

.chat-widget-message .message-time {
    font-size: 10px;
    color: #667781;
    text-align: right;
    margin-top: 4px;
}

.chat-widget-input {
    padding: 10px;
    background: #f0f2f5;
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-widget-input input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}

.chat-widget-input input:focus {
    border-color: #075e54;
}

.chat-widget-input button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #075e54;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background 0.2s;
}

.chat-widget-input button:hover {
    background: #064e46;
}

.chat-widget-input button:active {
    transform: scale(0.95);
}

/* =========================================
   5. Responsive Design
   ========================================= */
@media (max-width: 480px) {
    .chat-widget-container {
        width: calc(100% - 40px) !important;
        right: 20px !important;
        left: 20px !important;
        height: 70vh !important;
        bottom: 80px !important;
    }
}
