body {
    font-family: 'Inter', sans-serif;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.chat-container {
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e0e0e0;
    height: 100vh;
}

.chat-header {
    background-color: #007bff;
    color: #ffffff;
    padding: 7px 20px;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    text-align: center;
    font-weight: 600;
    font-size: 1.1em;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between; /* Space out items */
    position: relative;
    flex-shrink: 0;
}

/* NEW: Style for header admin profile (avatar + status) */
.header-admin-profile {
    display: flex;
    flex-direction: column; /* Stack avatar and status */
    align-items: center;
    position: absolute; /* Position explicitly */
    left: 90%;
    transform: translateX(-50%); /* Center horizontally */
    top: 50%; /* Adjust vertical positioning */
    transform: translate(-50%, -50%); /* Fine-tune centering */
    /* Adjust width/margin for proper layout */
    margin-right: auto; /* Push to left side of title effectively */
    margin-left: auto; /* Push to right side of title effectively */
    padding-left: 0px; /* Adjust padding around it */
    padding-right: 0px;
    box-sizing: content-box;
    z-index: 5; /* Ensure it's above other text elements if needed */
}

.header-admin-avatar {
    width: 40px; /* Size of avatar in header */
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff; /* White border for avatar */
    margin-bottom: 5px; /* Space between avatar and status indicator */
}


.chat-header h3 {
    margin: 0; /* Remove default margin */
    flex-grow: 1; /* Allow title to take available space */
    text-align: center; /* Center the title */
    /* Adjust margin to make space for back button and new admin profile */
    padding-left: 60px; /* Space for back button */
    padding-right: 60px; /* Space for admin profile on right */
    box-sizing: border-box; /* Include padding in width calculation */
    white-space: nowrap; /* Prevent title from wrapping too early */
    overflow: hidden; /* Hide overflow if title is too long */
    text-overflow: ellipsis; /* Add ellipsis if hidden */
}


.back-button {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 1.2em;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background-color 0.2s ease;
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.back-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Status indicator now inside .header-admin-profile */
.status-indicator {
    width: 10px; /* Slightly smaller dot for compactness */
    height: 10px;
    border-radius: 50%;
    background-color: transparent; /* Default transparent */
    position: absolute; /* Position relative to .header-admin-profile */
    bottom: 5px; /* Position at the bottom right of avatar */
    right: -2px;
    border: 2px solid #fff; /* White border to make it stand out */
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
    transition: background-color 0.3s ease;
}

.status-indicator.online {
    background-color: #28a745;
}

.status-indicator.offline {
    background-color: #dc3545;
}

.welcome-message-box { /* This style is now largely unused as content moves to messages-display */
    padding: 10px;
    background: #ffe744;
    border-radius: 5px;
    white-space: pre-line;
    text-align: center;
    color: #333;
    font-size: 0.95em;
    line-height: 1.6;
}

/* NEW: Loading Overlay Styles */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    font-size: 1.1em;
    color: #555;
}

.spinner {
    border: 4px solid rgba(0, 123, 255, 0.1);
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* END NEW: Loading Overlay Styles */

.chat-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.messages-display {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f9fafa;
    border-bottom: 1px solid #eee;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.no-history-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #888;
    font-size: 1em;
    padding: 20px;
    background-color: #f0f0f0;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    max-width: 80%;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.no-history-message i {
    font-size: 2.5em;
    margin-bottom: 15px;
    color: #b0b0b0;
    display: block;
}

.no-history-message.offline-message {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.no-history-message.offline-message i {
    color: #dc3545;
}

/* Styling pesan dengan avatar */
.message-wrapper {
    display: flex;
    align-items: flex-start;
    margin-bottom: 15px;
    gap: 10px;
}

.avatar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    width: 50px;
    text-align: center;
}

.avatar { /* Avatar inside chat bubbles */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #ddd;
}

.avatar-label {
    font-size: 0.7em;
    color: #888;
    font-weight: 300;
    white-space: nowrap;
}

/* POSISI PESAN DAN AVATAR DI SISI USER FRONTEND: Admin Kiri, User Kanan */
.message-wrapper.admin-wrapper {
    justify-content: flex-start; /* Admin messages to the left */
}
.message-wrapper.user-wrapper {
    justify-content: flex-end; /* User messages to the right */
}
/* System messages will align left with admin messages, for consistency */
.message-wrapper.system-wrapper {
    justify-content: flex-start;
}

.message {
    padding: 10px 15px;
    border-radius: 15px;
    max-width: calc(80% - 50px);
    word-wrap: break-word;
    font-size: 0.95em;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.message.user-message {
    background-color: #e6f7ff; /* User pesan - Biru Muda */
    color: #333;
    border-bottom-right-radius: 5px; /* Sudut kanan bawah kotak pesan user */
}

.message.admin-message {
    background-color: #f1f0f0; /* Admin balasan - Abu-abu Muda */
    color: #333;
    border-bottom-left-radius: 5px; /* Sudut kiri bawah kotak pesan admin */
}

/* Updated System Message Style */
/* Ensure system message has no avatar if `addMessageToDisplay` skips it, and centers well */
.message.system-message {
    background-color: #e9e9e9; /* Soft grey background */
    color: #555;
    text-align: center;
    border-radius: 8px;
    margin: 10px auto; /* Centered */
    max-width: 90%;
    font-style: italic;
    box-shadow: none;
    font-size: 0.85em; /* Smaller font for system messages */
    padding: 8px 12px; /* Adjusted padding */
}


.message p {
    margin: 0;
    line-height: 1.5;
    white-space: pre-wrap;
}

.message .timestamp {
    display: block;
    font-size: 0.75em;
    color: #888;
    margin-top: 5px;
}
/* POSISI TIMESTAMP UNTUK USER FRONTEND: Admin Kiri, User Kanan */
.message.admin-message .timestamp {
    text-align: left; /* Timestamp untuk pesan admin di kiri */
}
.message.user-message .timestamp {
    text-align: right; /* Timestamp untuk pesan user di kanan */
}
/* System message timestamp (if any) should align left or center */
.message.system-message .timestamp {
    text-align: center; /* System message timestamp centered */
}


.message img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 5px;
    display: block;
}

.message-input-area {
    display: flex;
    padding: 10px 15px;
    background-color: #f0f2f5;
    border-top: 1px solid #e0e0e0;
    gap: 10px;
    flex-shrink: 0;
    align-items: center;
}

.message-input-area input[type="text"] {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid #cccccc;
    border-radius: 25px;
    font-size: 1em;
    box-sizing: border-box;
    min-width: 0;
}

.message-input-area button,
.message-input-area .upload-btn {
    background-color: #007bff;
    color: #ffffff;
    padding: 10px 15px;
    border: none;
    border-radius: 25px;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-input-area button i,
.message-input-area .upload-btn i {
    margin: 0;
}


.message-input-area button:hover,
.message-input-area .upload-btn:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.message-input-area button:active {
    transform: translateY(0);
}

.message-input-area .upload-btn {
    background-color: #6c757d;
}
.message-input-area .upload-btn:hover {
    background-color: #5a6268;
}

/* --- FAQ Buttons Styles (Adjusted) --- */
.faq-buttons-container {
    padding: 10px 15px;
    margin-top: 15px;
    text-align: center;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

.faq-buttons-container .faq-title {
    width: 100%;
    font-size: 0.9em;
    color: #555;
    margin-bottom: 10px;
    font-weight: 500;
}

.faq-buttons-wrapper { /* Container for flex-wrap of FAQ buttons */
    display: flex;
    flex-wrap: wrap;
    gap: 0px; /* Removed gap, separator will handle spacing */
    justify-content: center;
}

.faq-button {
    background: none;
    color: #333;
    border: none;
    padding: 5px 0px;
    border-radius: 0;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
    transition: color 0.2s ease;
    white-space: nowrap;
    line-height: 1.2;
    margin: 0; /* Remove any margin */
}

.faq-button::before { /* Add '#' before each button */
    content: "#";
    color: #333; /* Color of the hash */
    font-weight: bold;
    margin-right: 0; /* No space before the text */
}

/* No specific :not(:last-child)::after for separator now */
/* Instead, we use margin-right for spacing between button+hash groups */
.faq-buttons-wrapper .faq-button:not(:last-child) {
    margin-right: 8px; /* Space after each button (and its ::before) */
}

/* Remove default # separator if it's not the last button in the row or line */
/* This is more complex with flex-wrap and might need JS to decide */
/* For simplicity, we'll let margin-right handle separation */


.faq-button:hover {
    color: #007bff;
    text-decoration: underline;
    transform: none;
    box-shadow: none;
}
.faq-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    text-decoration: none;
    color: #888;
}

/* Responsive Design */
@media (max-width: 600px) {
    body {
        padding: 0;
        align-items: flex-start;
        min-height: -webkit-fill-available;
        min-height: 100dvh;
    }
    .chat-container {
        border-radius: 0;
        height: 100vh;
        max-width: 100%;
        height: -webkit-fill-available;
        height: 100dvh;
    }
    .chat-header {
        border-radius: 0;
        padding-left: 50px;
        padding-right: 20px;
    }
    .chat-header h3 {
        /* Adjust margin for better centering with back button and admin profile */
        padding-left: 0px; /* Reset padding-left */
        padding-right: 0px; /* Reset padding-right */
        margin-left: auto; /* Push title to center */
        margin-right: auto;
        text-align: center;
        flex-grow: 1; /* Allow it to grow */
    }
    /* Re-adjust header-admin-profile for mobile as header h3 will center */
    .header-admin-profile {
        position: static; /* Remove absolute positioning on small screens */
        transform: none; /* Remove transform */
        order: 3; /* Push to the right end (after title) */
        margin-left: 10px; /* Space from title */
    }
    .back-button {
        left: 10px;
        order: 1; /* Keep on the left */
    }

    .message {
        max-width: calc(90% - 50px);
    }
    .back-button {
        left: 10px;
    }
    .status-indicator {
        right: 20px; /* Adjust based on new header-admin-profile positioning */
        top: 40px;
        bottom: 0px; /* Position status dot relative to its container */
        border: 1px solid #fff; /* Smaller border for mobile dot */
        width: 12px; /* Smaller dot */
        height: 12px;
    }
    .no-history-message {
        font-size: 0.9em;
        padding: 15px;
    }
    .no-history-message i {
        font-size: 2em;
        margin-bottom: 10px;
    }
    .faq-buttons-container {
        padding: 10px;
    }
    .faq-button {
        padding: 3px 0px;
        font-size: 0.8em;
    }
    .faq-buttons-wrapper .faq-button:not(:last-child) {
        margin-right: 5px; /* Adjust spacing in mobile */
    }
}