/**
 * Live Chat v3 Styles
 * 
 * Extra styles for the Messenger-style live chat.
 * Loaded alongside the existing style.css — additive only.
 */

/* ──────────────────────────────────────────────
   CHAT MESSAGES AREA (inner wrapper — NOT the scroll container)
   Scroll is handled by .chat_messages_container in style.css.
   ────────────────────────────────────────────── */
.chat-messages-area {
    padding: 10px 0;
}

/* ──────────────────────────────────────────────
   LOADING INDICATOR (top of messages)
   ────────────────────────────────────────────── */
.chat-load-indicator {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
}

.chat-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid #e3e6ea;
    border-top-color: #8c0327;
    border-radius: 50%;
    animation: chat-spin 0.6s linear infinite;
}

@keyframes chat-spin {
    to { transform: rotate(360deg); }
}

.chat-no-more {
    text-align: center;
    padding: 8px;
    color: #999;
    font-size: 12px;
}

/* ──────────────────────────────────────────────
   NEW MESSAGE ANIMATION
   ────────────────────────────────────────────── */
.chat-msg-new {
    animation: chat-msg-enter 0.3s ease-out;
}

@keyframes chat-msg-enter {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ──────────────────────────────────────────────
   AJAX-RENDERED MESSAGES (lightweight HTML)
   These come from the poll/AJAX responses.
   ────────────────────────────────────────────── */
.chat-msg-row {
    padding: 3px 10px;
    display: flex;
}
.chat-msg-row.chat-msg-self {
    justify-content: flex-end;
}
.chat-msg-row.chat-msg-other {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 80%;
    padding: 8px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msg-bg-self {
    background-color: #8c0327;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-bg-other {
    background-color: #e3e6ea;
    color: #1c1e21;
    border-bottom-left-radius: 4px;
}

.chat-bubble .chat-text {
    margin: 0;
}

.chat-bubble .chat-text:only-child {
    margin-bottom: 0;
}

/* ──────────────────────────────────────────────
   MEDIA GRID (images in AJAX messages)
   ────────────────────────────────────────────── */
.chat-media-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.chat-media-thumb {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-media-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-video-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    color: #fff;
}

/* ──────────────────────────────────────────────
   PRODUCT CARD (in AJAX messages)
   ────────────────────────────────────────────── */
.chat-product-card {
    border: 1px solid #e3e6ea;
    border-radius: 10px;
    overflow: hidden;
    margin: 6px 0;
    max-width: 320px;
}

.chat-product-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f7f7f7;
    border-bottom: 1px solid #e3e6ea;
}

.chat-product-header h4 {
    margin: 0;
    font-size: 14px;
}

.chat-product-price {
    font-weight: 700;
    white-space: nowrap;
}

.chat-product-body {
    padding: 8px 12px;
}

.chat-product-body p {
    margin: 0 0 6px;
    font-size: 13px;
}

.chat-product-footer {
    padding: 8px 12px;
    border-top: 1px solid #e3e6ea;
    text-align: center;
}

.chat-product-btn {
    display: inline-block;
    padding: 6px 16px;
    background: #8c0327;
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.chat-product-btn:hover {
    background: #6e0220;
    color: #fff;
}

/* ──────────────────────────────────────────────
   DATE SEPARATOR (in AJAX messages)
   ────────────────────────────────────────────── */
.chat-date-sep {
    text-align: center;
    padding: 10px 0;
}

.chat-date-sep span {
    background: #f0f0f0;
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 11px;
    color: #888;
}

/* ──────────────────────────────────────────────
   READ STATUS (in AJAX messages)
   ────────────────────────────────────────────── */
.chat-read-status {
    text-align: right;
    font-size: 10px;
    color: #999;
    margin-top: 2px;
    padding-right: 14px;
}

/* ──────────────────────────────────────────────
   TYPING INDICATOR — floating overlay
   ────────────────────────────────────────────── */

/* The parent (.inner-message-container > .col-inner) needs position context */
.inner-message-container > .col-inner {
    position: relative;
}

.chat-typing-indicator {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    /* Slide-up entrance */
    animation: typing-slide-in 0.2s ease-out;
}

.typing-bubble {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 10px 18px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

@keyframes typing-slide-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ──────────────────────────────────────────────
   MESSENGER-STYLE FORM
   ────────────────────────────────────────────── */
.chat-form-live {
    border-top: 1px solid #e3e6ea;
    padding: 8px 10px;
    background: #fff;
}

.chat-form-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.chat-form-actions-left {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    padding-bottom: 4px;
}

.chat-attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    color: #8c0327;
    transition: background 0.15s;
}

.chat-attach-btn:hover {
    background: rgba(140, 3, 39, 0.08);
}

.chat-message-input {
    flex: 1;
    resize: none;
    border: none;
    outline: none;
    background: #e3e6ea;
    border-radius: 18px;
    padding: 8px 14px;
    font-size: 14px;
    line-height: 1.35;
    max-height: 120px;
    min-height: 36px;
    font-family: inherit;
    overflow-y: auto;
    -webkit-box-shadow: none;
    box-shadow: none;
}

.chat-message-input:focus {
    background: #dcdfe3;
}

.chat-message-input.drag-over {
    background: #d0e6ff;
    outline: 2px dashed #4a90d9;
}

.chat-message-input::placeholder {
    color: #999;
}

.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #ccc;
    cursor: default;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.chat-send-btn.has-content {
    color: #8c0327;
    cursor: pointer;
}

.chat-send-btn.has-content:hover {
    background: rgba(140, 3, 39, 0.08);
}

.chat-send-btn.sending {
    color: #ccc;
    cursor: wait;
}

.chat-send-btn:disabled {
    color: #ccc;
    cursor: default;
}

/* ──────────────────────────────────────────────
   FILE PREVIEW
   ────────────────────────────────────────────── */
.chat-file-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px 0;
    border-top: 1px solid #f0f0f0;
}

.file-preview-item {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e3e6ea;
}

.file-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.file-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 14px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    margin: 0 !important;
    min-height: auto;
}

.file-preview-remove:hover {
    background: rgba(0,0,0,0.85);
}

.video-preview-thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    color: #fff;
    gap: 2px;
}

.video-preview-thumb svg {
    opacity: 0.7;
}

.video-name {
    font-size: 9px;
    opacity: 0.7;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 56px;
}

/* ──────────────────────────────────────────────
   FORM ERROR
   ────────────────────────────────────────────── */
.chat-form-error {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
    border-radius: 6px;
    padding: 6px 12px;
    margin: 4px 10px;
    font-size: 13px;
}

/* ──────────────────────────────────────────────
   FORM OPTIONS (email checkbox)
   ────────────────────────────────────────────── */
.chat-form-options {
    padding: 4px 10px 8px;
    font-size: 12px;
    color: #666;
}

.chat-form-options input[type="checkbox"] {
    margin-right: 4px;
    vertical-align: middle;
}

.chat-form-options label {
    font-size: 12px;
    cursor: pointer;
}

/* ──────────────────────────────────────────────
   OPTIMISTIC / FAILED MESSAGE STATUS
   ────────────────────────────────────────────── */

/* Lightweight placeholder while message is sending */
.chat-optimistic-placeholder {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 5px 14px;
    opacity: 0.55;
    animation: chatOptimisticPulse 1.2s ease-in-out infinite;
}

.chat-optimistic-text {
    display: inline-block;
    max-width: 75%;
    background: #8c0327;
    color: #fff;
    padding: 8px 14px;
    border-radius: 16px 16px 4px 16px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.chat-optimistic-files {
    display: inline-block;
    font-size: 12px;
    color: #999;
    margin-top: 3px;
}

.chat-optimistic-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #999;
    margin-top: 3px;
}

.chat-sending-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: chatSendingBlink 0.8s ease-in-out infinite alternate;
}

@keyframes chatOptimisticPulse {
    0%, 100% { opacity: 0.55; }
    50%      { opacity: 0.8; }
}

@keyframes chatSendingBlink {
    0%   { opacity: 0.3; }
    100% { opacity: 1; }
}

/* When finalized, the wrapper fades out before replacement */
.chat-msg-sending {
    transition: opacity 0.15s ease;
}

.chat-msg-status {
    display: block;
    font-size: 10px;
    margin-top: 3px;
    text-align: right;
}

.chat-msg-status.failed {
    color: #ff6b6b;
}

.chat-msg-status.unconfirmed {
    color: #8a6500;
}

.chat-msg-failed .chat-bubble {
    opacity: 0.7;
    border: 1px dashed #ff6b6b;
}

.chat-msg-unconfirmed .chat-optimistic-placeholder {
    animation: none;
    opacity: 0.8;
}

.chat-msg-unconfirmed .chat-optimistic-text {
    border: 1px dashed #c39a24;
}

.chat-retry-btn {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 10px;
    border: 1px solid #ff6b6b;
    border-radius: 4px;
    background: transparent;
    color: #ff6b6b;
    font-size: 11px;
    cursor: pointer;
}

.chat-retry-btn:hover {
    background: #ff6b6b;
    color: #fff;
}

.chat-new-message-button {
    position: sticky;
    z-index: 12;
    bottom: 12px;
    display: block;
    margin: 0 auto;
    padding: 7px 14px;
    border: 0;
    border-radius: 18px;
    background: #8c0327;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.chat-new-message-button[hidden] {
    display: none;
}

.chat-send-disabled {
    opacity: 0.65;
}

.chat-connection-status {
    margin: 0;
    padding: 6px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: #fff8e8;
    color: #66501b;
    font-size: 12px;
    line-height: 1.4;
    text-align: center;
}

.chat-connection-status[hidden] {
    display: none;
}

.chat-connection-status a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
}

/* ──────────────────────────────────────────────
   SIDEBAR ENHANCEMENTS
   ────────────────────────────────────────────── */

/* Scrollable sidebar — matches chat container height */
.chat-sidebar-profiles {
    max-height: 730px;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Subtle scrollbar styling */
.chat-sidebar-profiles::-webkit-scrollbar {
    width: 4px;
}
.chat-sidebar-profiles::-webkit-scrollbar-track {
    background: transparent;
}
.chat-sidebar-profiles::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}
.chat-sidebar-profiles:hover::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
}

/* Loading spinner at bottom of sidebar */
.sidebar-load-more {
    padding: 12px;
    text-align: center;
}
.sidebar-load-more .chat-spinner {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.sidebar-chat-item {
    transition: background-color 0.2s;
}

.sidebar-chat-item.unread {
    /* Slight highlight for unread */
}

/* ──────────────────────────────────────────────
   UNREAD BADGE (in header)
   ────────────────────────────────────────────── */
.chat-unread-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: -4px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: #8c0327;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}

/* ──────────────────────────────────────────────
   MOBILE ADJUSTMENTS (supplement existing)
   ────────────────────────────────────────────── */
@media only screen and (max-width: 600px) {
    .chat-bubble {
        max-width: 90%;
    }

    .chat-form-actions-left {
        gap: 0;
    }

    .chat-attach-btn {
        width: 30px;
        height: 30px;
    }

    .chat-message-input {
        font-size: 16px; /* Prevent iOS zoom */
    }

    .file-preview-item {
        width: 52px;
        height: 52px;
    }

    .chat-product-card {
        max-width: 100%;
    }
}

/* Conversation-wide presentation, identical after initial load and live merges. */
.chat-msg-wrapper [hidden], .chat-sidebar-typing[hidden] { display: none !important; }
.chat-msg-wrapper { margin-top: 2px; }
.chat-msg-wrapper.chat-group-start { margin-top: 14px; }
.chat-msg-wrapper > .row { padding-top: 0 !important; padding-bottom: 0 !important; }
.chat-msg-wrapper .chat_message { margin-top: 0; padding-bottom: 0; }
.chat-msg-wrapper:not(.chat-group-start) .current_user_comment.chat_message > .col-inner { border-top-right-radius: 5px; }
.chat-msg-wrapper:not(.chat-group-end) .current_user_comment.chat_message > .col-inner { border-bottom-right-radius: 5px; }
.chat-msg-wrapper:not(.chat-group-start) .sender_user_comment.chat_message > .col-inner { border-top-left-radius: 5px; }
.chat-msg-wrapper:not(.chat-group-end) .sender_user_comment.chat_message > .col-inner { border-bottom-left-radius: 5px; }
.chat-msg-wrapper .chat-date-sep { color: #666; font-size: 12px; padding: 8px 0 14px; }
.chat-msg-wrapper .chat-read-status {
    display: block; margin: 3px 12px 8px auto; padding: 0 2px; min-height: 0;
    border: 0; background: transparent; box-shadow: none; color: #6b6b6b;
    font-size: 11px; font-weight: 400; line-height: 1.5; text-transform: none;
}
.chat-read-status:focus-visible { outline: 2px solid #8c0327; outline-offset: 3px; }
.chat-unread-separator { color: #8c0327; text-align: center; font-size: 12px; padding: 10px; border-top: 1px solid #ead5db; margin-top: 12px; }
.chat-sidebar-typing { display: block; color: #8c0327; font-size: 12px; font-weight: 600; }
.chat-is-typing .comment_content { display: none; }
.chat-typing-name { font-size: 12px; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-typing-indicator { max-width: calc(100% - 24px); }
.chat-typing-indicator .typing-bubble { max-width: 100%; padding: 7px 12px; }
.chat-typing-indicator .typing-dot { flex-shrink: 0; width: 5px; height: 5px; }
@media (prefers-reduced-motion: reduce) {
    .chat-typing-indicator, .typing-dot { animation: none !important; }
}

/* Keep the sidebar steady while the selected conversation arrives. */
.chat-navigation-placeholder {
    min-height: 280px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 12px;
}
.chat-navigation-placeholder p { color: #666; margin: 0; }
.chat-navigation-retry { margin: 0; }

/* Persistent moderation warning shared by account and embedded profile chat. */
.chat_form_container .chat-moderation-warning {
    box-sizing: border-box;
    background: #fff1e8;
    color: #742c0c;
    border: 1px solid #d68b60;
    border-left: 4px solid #ad481c;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.chat_form_container .chat-moderation-warning[hidden] { display: none; }
.chat_form_container .chat-moderation-warning strong { display: block; color: inherit; margin-bottom: 4px; }
.chat_form_container .chat-moderation-warning p { margin: 0; color: inherit; font-size: inherit; }
.chat_form_container .chat-moderation-warning:focus-visible { outline: 2px solid #ad481c; outline-offset: 2px; }
@media (max-height: 600px) {
    /* Keep the composer usable when a mobile keyboard reduces the viewport. */
    .chat_form_container .chat-moderation-warning {
        max-height: 18vh;
        max-height: 18dvh;
        overflow-y: auto;
    }
}
