/* ===========================================================
   Public Engagement Chat — Messenger-style UI
   =========================================================== */

.chat-header-btn { position: relative; }
.chat-header-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e0245e;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 999px;
    min-width: 16px;
    text-align: center;
}

/* ---------- Chat list ---------- */
.chat-list-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0f2f5;
    border-radius: 999px;
    padding: 9px 14px;
    margin: 10px 14px 6px;
    color: #667085;
}
.chat-list-search input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 0.9rem;
    color: inherit;
}
body.dark-mode .chat-list-search { background: #1f2b23; color: #9fb0a5; }

.chat-fab {
    position: fixed;
    right: 18px;
    bottom: 84px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--hp-primary), #1272c4);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 6px 18px rgba(11,83,158,0.4);
    z-index: 40;
    border: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.chat-fab:active { transform: scale(0.94); box-shadow: 0 4px 12px rgba(11,83,158,0.45); }

.chat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f0f2f5;
    transition: background 0.12s ease;
}
.chat-row:active, .chat-row:hover { background: #f7f8fa; color: inherit; }
body.dark-mode .chat-row { border-bottom-color: #223227; }
body.dark-mode .chat-row:active, body.dark-mode .chat-row:hover { background: #1a241d; }

.chat-row-avatar-wrap { position: relative; flex-shrink: 0; }
.chat-row-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    background: linear-gradient(135deg, var(--hp-primary), #1272c4);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chat-online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #31c48d;
    border: 2px solid #fff;
}
body.dark-mode .chat-online-dot { border-color: #16201a; }

.chat-row-body { flex-grow: 1; min-width: 0; }
.chat-row-name-line { display: flex; align-items: center; gap: 4px; }
.chat-row-name { font-weight: 700; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-preview {
    font-size: 0.82rem;
    color: #667085;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}
.chat-row.unread .chat-row-preview { color: #1a1a1a; font-weight: 600; }
body.dark-mode .chat-row-preview { color: #8fa093; }
body.dark-mode .chat-row.unread .chat-row-preview { color: #f2f4f2; }

.chat-row-meta { text-align: right; flex-shrink: 0; }
.chat-row-time { font-size: 0.72rem; color: #98a2b3; }
.chat-row-unread-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--hp-primary);
    margin-top: 4px;
}

.chat-row-name-line .verified-badge,
.chat-thread-header-name .verified-badge,
.new-chat-result-row .verified-badge { font-size: 0.8rem; }

/* ---------- New chat search sheet ---------- */
.new-chat-results { max-height: 60vh; overflow-y: auto; }
.new-chat-result-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid #f0f2f5;
    cursor: pointer;
}
body.dark-mode .new-chat-result-row { border-bottom-color: #223227; }

/* ---------- Chat thread (full-screen page) ---------- */
body.chat-thread-page .app-content { padding-bottom: 0 !important; margin: 0 !important; }
body.chat-thread-page .bottom-nav { display: none !important; }
body.chat-thread-page .app-header { display: none !important; }

body.chat-thread-page {
    height: 100vh;
    height: calc(var(--app-vh, 1vh) * 100);
    width: 100vw;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
}

.chat-thread-wrap {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    z-index: 9999;
    background: #eef2f0;
}
body.dark-mode .chat-thread-wrap { background: #0f1712; }

.chat-thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--hp-dark), var(--hp-primary) 65%, #1272c4);
    color: #fff;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 2px 10px rgba(6, 48, 92, 0.25);
    position: relative;
}
.chat-thread-back { color: #fff; font-size: 1.3rem; text-decoration: none; display: flex; opacity: 0.9; transition: opacity 0.15s ease; }
.chat-thread-back:hover { opacity: 1; }

.chat-thread-header-avatar-wrap { position: relative; flex-shrink: 0; }
.chat-thread-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.02rem;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.35);
}
.chat-thread-header-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #31c48d;
    border: 2px solid var(--hp-primary);
}
.chat-thread-header-info { flex-grow: 1; min-width: 0; }
.chat-thread-header-name {
    font-weight: 700;
    font-size: 0.96rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.1px;
}
.chat-thread-header-status { font-size: 0.73rem; opacity: 0.82; margin-top: 1px; }
.chat-thread-menu-btn {
    color: #fff;
    background: rgba(255,255,255,0.08);
    border: none;
    font-size: 1.15rem;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.chat-thread-menu-btn:hover { background: rgba(255,255,255,0.16); }

/* Desktop-only close button for the thread panel (see desktop-premium.css for the
   >=992px reveal). Hidden here so phones/tablets never see it. */
.chat-thread-close-desktop { display: none; }

/* ---------- Scrollable Messages Container ---------- */
.chat-messages-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    background:
        radial-gradient(rgba(11,83,158,0.05) 1px, transparent 1px),
        #eef2f0;
    background-size: 18px 18px, auto;
}
body.dark-mode .chat-messages-scroll {
    background:
        radial-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
        #0f1712;
    background-size: 18px 18px, auto;
}
.chat-messages-scroll::-webkit-scrollbar { width: 6px; }
.chat-messages-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-messages-scroll::-webkit-scrollbar-thumb { background: rgba(6,48,92,0.14); border-radius: 999px; }
body.dark-mode .chat-messages-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); }

.chat-msg-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 3px;
    animation: chatMsgIn 0.18s ease-out;
}
.chat-msg-row.mine { justify-content: flex-end; }
.chat-msg-row.theirs { justify-content: flex-start; }
@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-bubble {
    max-width: 76%;
    padding: 9px 14px;
    border-radius: 18px;
    font-size: 0.89rem;
    line-height: 1.42;
    word-wrap: break-word;
    white-space: pre-wrap;
    letter-spacing: 0.1px;
}
.chat-msg-row.mine .chat-bubble {
    background: linear-gradient(135deg, var(--hp-primary), #1272c4);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 6px rgba(11,83,158,0.22);
}
.chat-msg-row.theirs .chat-bubble {
    background: #fff;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
body.dark-mode .chat-msg-row.theirs .chat-bubble { background: #1f2b23; color: #e6e8e6; box-shadow: none; }

.chat-bubble-image { max-width: 76%; }
.chat-bubble-image img {
    max-width: 100%;
    border-radius: 14px;
    display: block;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* ---------- Per-message timestamp (Telegram-style, inline after bubble) ---------- */
.chat-msg-stamp {
    font-size: 0.64rem;
    color: #9aa2ad;
    flex-basis: 100%;
    text-align: right;
    margin: 1px 2px 4px;
}
.chat-msg-row.theirs .chat-msg-stamp { text-align: left; }
body.dark-mode .chat-msg-stamp { color: #6b7a71; }

.chat-bubble-legacy-voice {
    display: flex;
    align-items: center;
    gap: 6px;
    font-style: italic;
    opacity: 0.85;
}

.chat-typing-row { display: flex; justify-content: flex-start; margin-top: 2px; }
.chat-typing-bubble {
    background: #fff;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    padding: 10px 14px;
    display: inline-flex;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
body.dark-mode .chat-typing-bubble { background: #1f2b23; }
.chat-typing-bubble span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #98a2b3;
    display: inline-block;
    animation: chatTypingBounce 1.2s infinite ease-in-out;
}
.chat-typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-bubble span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Composer (Pinned Messenger-style bar) ---------- */
.chat-composer-wrap {
    position: relative;
    flex-shrink: 0;
    z-index: 20;
    background: #fff;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    box-shadow: 0 -1px 8px rgba(0,0,0,0.04);
}
body.dark-mode .chat-composer-wrap { background: #16201a; box-shadow: none; }

.chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 9px 10px;
    background: #fff;
    border-top: 1px solid #eef0f2;
}
body.dark-mode .chat-composer { background: #16201a; border-top-color: #223227; }

.chat-composer-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--hp-primary);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
}
.chat-composer-btn:hover { background: rgba(11,83,158,0.08); }
.chat-composer-btn:active { transform: scale(0.92); }
body.dark-mode .chat-composer-btn { color: var(--hp-secondary); }
body.dark-mode .chat-composer-btn:hover { background: rgba(245,218,7,0.1); }

.chat-composer-input {
    flex-grow: 1;
    border: 1px solid transparent;
    background: #f0f2f5;
    border-radius: 20px;
    padding: 10px 15px;
    resize: none;
    max-height: 110px;
    font-size: 0.9rem;
    line-height: 1.35;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.chat-composer-input:focus { background: #fff; border-color: rgba(11,83,158,0.3); }
body.dark-mode .chat-composer-input { background: #1f2b23; color: #e6e8e6; }
body.dark-mode .chat-composer-input:focus { background: #24312a; border-color: rgba(245,218,7,0.25); }

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--hp-primary), #1272c4);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(11,83,158,0.3);
    transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.chat-send-btn:hover { box-shadow: 0 3px 10px rgba(11,83,158,0.4); }
.chat-send-btn:active { transform: scale(0.92); }
.chat-send-btn:disabled { opacity: 0.5; box-shadow: none; }

.chat-image-preview-bar {
    display: none;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f7f8fa;
    border-top: 1px solid #eef0f2;
}
body.dark-mode .chat-image-preview-bar { background: #1a241d; border-top-color: #223227; }
.chat-image-preview-bar.active { display: flex; }
.chat-image-preview-bar img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; }
.chat-image-preview-remove { margin-left: auto; background: none; border: none; color: #667085; font-size: 1.1rem; }

/* ---------- File attachment bubble ---------- */
.chat-bubble-file {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 14px;
    padding: 10px 14px;
    max-width: 260px;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s ease;
}
.chat-bubble-file:hover { background: #f4f6fb; color: inherit; }
.chat-msg-row.mine .chat-bubble-file { background: #eaf1ff; }
body.dark-mode .chat-bubble-file { background: #1f2a22; border-color: #2b3a30; }
body.dark-mode .chat-msg-row.mine .chat-bubble-file { background: #1a3324; }
body.dark-mode .chat-bubble-file:hover { background: #24312a; }

.chat-file-icon { font-size: 26px; color: #1a5fce; flex-shrink: 0; }
body.dark-mode .chat-file-icon { color: #6ea8fe; }

.chat-file-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-file-name {
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-file-size { font-size: 12px; color: #7a7a7a; }
body.dark-mode .chat-file-size { color: #9aa5a0; }

.chat-file-download { color: #7a7a7a; font-size: 16px; flex-shrink: 0; }

.chat-file-preview-bar {
    display: none;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f7f8fa;
    border-top: 1px solid #eef0f2;
    font-size: 20px;
    color: #1a5fce;
}
body.dark-mode .chat-file-preview-bar { background: #1a241d; border-top-color: #223227; color: #6ea8fe; }
.chat-file-preview-bar.active { display: flex; }
.chat-file-preview-bar span.small { flex: 1; color: #333; font-size: 0.9rem; }
body.dark-mode .chat-file-preview-bar span.small { color: #e6e6e6; }
.chat-file-preview-remove { margin-left: auto; background: none; border: none; color: #667085; font-size: 1.1rem; }

/* ---------- "Seen"/"Sent" status under my last message ---------- */
.chat-seen-status {
    text-align: right;
    font-size: 0.72rem;
    color: #9aa2ad;
    margin: -2px 4px 8px;
    padding-right: 4px;
}
body.dark-mode .chat-seen-status { color: #7c8b83; }

/* ---------- Deleted message placeholder ---------- */
.chat-bubble-deleted {
    background: transparent !important;
    border: 1px dashed #c2c9d1;
    color: #9aa2ad !important;
    font-style: italic;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
body.dark-mode .chat-bubble-deleted { border-color: #3a463e; color: #7c8b83 !important; }
.chat-msg-row.deleted { opacity: 0.85; }


/* ---------- Emoji picker ---------- */
.chat-emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 8px;
    right: 8px;
    max-width: 340px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 -6px 24px rgba(6,48,92,0.18);
    border: 1px solid rgba(0,0,0,0.05);
    padding: 10px;
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
    z-index: 30;
}
.chat-emoji-picker.active { display: grid; }
body.dark-mode .chat-emoji-picker { background: #1f2b23; border-color: rgba(255,255,255,0.06); }
.chat-emoji-picker button {
    border: none;
    background: transparent;
    font-size: 1.3rem;
    padding: 5px;
    border-radius: 9px;
    transition: background 0.12s ease, transform 0.1s ease;
}
.chat-emoji-picker button:hover { background: rgba(11,83,158,0.08); transform: scale(1.12); }
.chat-emoji-picker button:active { background: rgba(0,0,0,0.06); }

/* ---------- Empty states & Blocked Banner ---------- */
.chat-empty-state {
    text-align: center;
    padding: 60px 24px;
    color: #98a2b3;
}
.chat-empty-state i {
    font-size: 2.8rem;
    margin-bottom: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(11,83,158,0.08);
    color: var(--hp-primary);
}
body.dark-mode .chat-empty-state i { background: rgba(245,218,7,0.08); color: var(--hp-secondary); }
.chat-empty-state { font-size: 0.92rem; font-weight: 500; }

.chat-blocked-banner {
    text-align: center;
    font-size: 0.78rem;
    color: #98a2b3;
    padding: 10px;
    background: rgba(0,0,0,0.02);
}
body.dark-mode .chat-blocked-banner { background: rgba(255,255,255,0.02); }