/* =================================== */
/* ==== VISITOR CHAT WIDGET CSS (Fixed) ==== */
/* =================================== */

.chat-widget-container {
    display: none;
}

:root {
    --chat-primary-color: #1b52d3;
    --chat-primary-hover: #0b5ed7;
    --chat-visitor-bubble: var(--chat-primary-color);
    --chat-agent-bubble: #e9ecef;
    --chat-text-light: #dedede;
    --chat-text-dark: #212529;
    --chat-text-muted: #6c757d;
    --chat-border-color: #dee2e6;
    --chat-background-light: #f8f9fa;
    --chat-background-widget: white;
    --chat-status-online: #16d47c;
    --chat-status-offline: #ffc107;
}

.chat-widget-container {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 1050;
}

.chat-toggle-button {
    background-color: var(--chat-primary-color);
    color: var(--chat-text-light);
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s ease;
}

.chat-toggle-button:hover {
    background-color: var(--chat-primary-hover);
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 0.7rem;
    padding: 3px 6px;
    border-radius: 50%;
    pointer-events: none;
}

.chat-popup {
    position: absolute;
    bottom: calc(100% + 15px);
    right: 0;
    width: 350px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background-color: var(--chat-background-widget);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    /* This is crucial */
    overflow: hidden;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}

.chat-popup[style*="display: flex"] {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}


.chat-header {
    background-color: var(--chat-primary-color);
    color: var(--chat-text-light);
    padding: 12px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    flex-shrink: 0;
    /* Make sure header never shrinks */
}

.chat-status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--chat-status-offline);
    margin-right: 8px;
    flex-shrink: 0;
}

.chat-status-indicator.online {
    background-color: var(--chat-status-online);
}

.chat-status-indicator.offline {
    background-color: var(--chat-status-offline);
}

#chat-header-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: auto;
    padding-left: 5px;
    color: var(--chat-text-light) !important;
    font-weight: 600;
}


.chat-header .btn-close {
    padding: 0.5rem;
    margin-left: 10px;
    filter: invert(1) grayscale(100%) brightness(200%);
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.chat-header .btn-close:hover {
    opacity: 1;
}

/* ================================== */
/* START: CSS FIX */
/* This new wrapper holds the scrolling content */
.chat-body-content {
    flex-grow: 1;
    /* This is the single element that grows */
    overflow-y: auto;
    /* This is the single element that scrolls */
    background-color: var(--chat-background-light);
}

/* Updated .chat-messages */
.chat-messages {
    /* REMOVED: flex-grow, overflow-y */
    padding: 15px;
    /* Add padding here instead of parent */
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* END: CSS FIX */
/* ================================== */


/* Improve scrollbar appearance (Webkit browsers) */
.chat-body-content::-webkit-scrollbar {
    width: 6px;
}

.chat-body-content::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}

.chat-body-content::-webkit-scrollbar-track {
    background: transparent;
}


.chat-message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.chat-message.visitor {
    align-self: flex-end;
    background-color: var(--chat-visitor-bubble);
    color: var(--chat-text-light);
    border-bottom-right-radius: 6px;
    font-weight: 500;
}

.chat-message.staff {
    align-self: flex-start;
    background-color: var(--chat-agent-bubble);
    color: var(--chat-text-dark);
    border-bottom-left-radius: 6px;
}

.chat-message .timestamp {
    display: block;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.75) !important;
    margin-top: 4px;
    text-align: right;
}

.chat-message.staff .timestamp {
    color: var(--chat-text-muted);
    text-align: left;
}


.chat-system-message {
    text-align: center;
    color: var(--chat-text-muted);
    font-size: 0.8rem;
    margin: 10px 0;
}

.chat-system-message.error {
    color: #dc3545;
    font-weight: 500;
}

.chat-typing-indicator {
    padding: 5px 15px;
    font-size: 0.8rem;
    color: var(--chat-text-muted);
    font-style: italic;
    height: 25px;
    flex-shrink: 0;
    /* Fixed element */
    opacity: 0.8;
    background-color: var(--chat-background-widget);
    /* Match footer background */
}

.chat-input-area {
    display: flex;
    padding: 10px 15px;
    border-top: 1px solid var(--chat-border-color);
    background-color: var(--chat-background-widget);
    flex-shrink: 0;
    /* Fixed element */
}

.chat-input-area input {
    flex-grow: 1;
    border: 1px solid #ced4da;
    border-radius: 20px;
    padding: 8px 15px;
    margin-right: 10px;
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

.chat-input-area input:focus {
    outline: none;
    border-color: var(--chat-primary-color);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.chat-input-area button {
    background-color: var(--chat-primary-color);
    color: var(--chat-text-light);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.chat-input-area button:hover {
    background-color: var(--chat-primary-hover);
}

.chat-input-area button:disabled {
    background-color: #adb5bd;
    cursor: not-allowed;
}

/* Updated .chat-offline-form */
.chat-offline-form {
    /* REMOVED: flex-shrink, border-top, background-color */
    /* ADDED: padding to match .chat-messages */
    padding: 20px 15px;
}

.chat-offline-form p {
    font-size: 0.9rem;
    color: var(--chat-text-muted);
    margin-bottom: 15px;
    text-align: center;
}

.chat-offline-form input,
.chat-offline-form textarea {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

.chat-offline-form input:focus,
.chat-offline-form textarea:focus {
    outline: none;
    border-color: var(--chat-primary-color);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.chat-offline-form textarea {
    resize: vertical;
    min-height: 60px;
}

/* --- NEW: Styles for Phone Input Wrapper and Validation --- */
.iti-container {
    position: relative;
    width: 100%;
    margin-bottom: 25px;
    /* Increased margin to make space for error message */
}

/* Make intl-tel-input library full width */
.iti {
    width: 100%;
}

.phone-validation-message {
    font-size: 0.75rem;
    padding-top: 3px;
    position: absolute;
    width: 100%;
    left: 0;
    bottom: -18px;
    /* Position it right below the input */
    color: #dc3545;
    /* Bootstrap danger color */
}

.chat-offline-form input.is-valid {
    border-color: #198754;
    /* Bootstrap success */
}

.chat-offline-form input.is-invalid {
    border-color: #dc3545;
    /* Bootstrap danger */
}

/* --- END: New Phone Styles --- */


.chat-offline-form button {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: var(--chat-primary-color);
    color: var(--chat-text-light);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.chat-offline-form button:hover {
    background-color: var(--chat-primary-hover);
}

.chat-offline-form button:disabled {
    background-color: #adb5bd;
    cursor: not-allowed;
}

.offline-status {
    margin-top: 10px;
    font-size: 14px;
    text-align: center;
    min-height: 1.2em;
}

.offline-status.success {
    color: #198754;
}

.offline-status.error {
    color: #dc3545;
}


.chat-footer {
    padding: 8px 15px;
    text-align: center;
    font-size: 0.75rem;
    color: #adb5bd;
    background-color: var(--chat-background-widget);
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    /* Fixed element */
}

.chat-footer-link {
    color: #6c757d;
    text-decoration: none;
    font-weight: 500;
}

.chat-footer-link:hover {
    color: var(--chat-primary-color);
    text-decoration: underline;
}

@media (max-width: 440px) {
    .chat-popup {
        width: 280px;
    }
}

.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgb(20 25 77 / 46%);
    z-index: 1040;
    backdrop-filter: saturate(180%) blur(10px);
    transition: opacity 0.3s ease-in-out;
    opacity: 0;
    pointer-events: none;
}

.chat-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.chat-popup {
    z-index: 1050;
}

.chat-toggle-button {
    z-index: 1060;
}

.chat-widget-container.with-overlay .chat-popup {
    transform: scale(1.02);
    transition: transform 0.3s ease;
}

@media (max-width: 768px) {
    .chat-widget-container.with-overlay .chat-popup {
        transform: scale(0.95);
    }
}