/* ============================================================
   chat.css — Shared Chat Styles
   Used by: contact.html (user side) + chat-admin.html (admin side)
   VERSION: 3.0 — Compact WhatsApp-style bubbles
   ------------------------------------------------------------
   FIXES (v3.0):
     ✅ min-width removed → bubble shrinks to content
     ✅ Tight padding (4px 9px 3px 9px) — WhatsApp-like
     ✅ Meta inline (float right, no margin-top) → no extra line
     ✅ line-height 1.35 (compact)
     ✅ white-space: pre-line (collapses extra spaces)
     ✅ Reduced message margin-bottom
     ✅ Supports both .chat-bubble-meta AND .chat-meta-inline
     ✅ Mobile padding also tightened
     ✅ .chat-text inline (not block)
   ============================================================ */

/* ============================================
   CHAT CSS VARIABLES (fallback if not defined)
   ============================================ */
:root {
    /* Fallbacks — override via style.css if needed */
    --chat-user-bubble: var(--accent, #00d4aa);
    --chat-user-bubble-dim: var(--accent-dim, #00b894);
    --chat-user-text: #080c10;

    --chat-admin-bubble: var(--bg-card, #14181f);
    --chat-admin-text: var(--text-primary, #f0f5f8);

    --chat-system-bubble: var(--bg-secondary, #11151b);
    --chat-system-text: var(--text-muted, rgba(240, 245, 248, 0.5));

    --chat-bubble-radius: 14px;
    --chat-bubble-tail: 4px;

    --chat-max-bubble-width: 72%;
    --chat-max-bubble-mobile: 88%;

    /* Message tick colors */
    --chat-tick-default: rgba(240, 245, 248, 0.6);
    --chat-tick-read: #4fc3f7;
    --chat-tick-failed: #ff4d4d;

    /* Chat bg pattern */
    --chat-bg-pattern: transparent;

    /* Animation */
    --chat-anim-fast: 0.18s ease;
    --chat-anim-base: 0.25s ease;
    --chat-anim-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* ✅ NEW: Compact spacing tokens */
    --chat-bubble-pad-y: 4px;
    --chat-bubble-pad-y-bottom: 4px;   
    --chat-bubble-pad-x: 9px;/* 4 → 2 */
    --chat-bubble-line-height: 1.35;
    --chat-bubble-font-size: 13.5px;
    --chat-bubble-meta-size: 10px;
}

/* Light theme overrides */
[data-theme="light"] {
    --chat-tick-default: rgba(13, 27, 42, 0.55);
    --chat-admin-bubble: #ffffff;
    --chat-admin-text: #0d1b2a;
}

/* ============================================
   CHAT MESSAGES AREA
   ============================================ */
.chat-messages,
.chat-messages-area {
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.chat-messages-container {
    padding: 6px 4px;
    max-width: 100%;
}

/* ============================================
   DATE SEPARATOR
   ============================================ */
.chat-date-separator {
    text-align: center;
    margin: 12px 0 8px;
    position: relative;
    display: flex;
    justify-content: center;
}

.chat-date-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 8%;
    right: 8%;
    height: 1px;
    background: var(--border, rgba(255, 255, 255, 0.08));
    transform: translateY(-50%);
    z-index: 0;
}

.chat-date-separator span {
    background: var(--bg-card-solid, var(--bg-card, #14181f));
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 999px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    position: relative;
    z-index: 1;
    letter-spacing: 0.3px;
    text-transform: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ============================================
   MESSAGE WRAPPER
   NOTE: Alignment (.user left/right) handled by page-specific CSS
   to support both user-side and admin-side perspectives
   ============================================ */
.chat-message {
    display: flex;
    margin-bottom: 1px;                    
    animation: chatMessageIn 0.25s ease;
    position: relative;
    padding: 0 4px;
}

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

/* ✅ Remove extra gap between consecutive messages */
.chat-message + .chat-message {
    margin-top: 0;
}

/* Default alignment (user side — safe default) */
.chat-message.user {
    justify-content: flex-end;
}

.chat-message.admin {
    justify-content: flex-start;
}

.chat-message.system {
    justify-content: center;
    margin: 6px 0;
}

/* ✅ Override for admin panel: user left, admin right */
[data-chat-perspective="admin"] .chat-message.user {
    justify-content: flex-start;
}

[data-chat-perspective="admin"] .chat-message.admin {
    justify-content: flex-end;
}

/* ============================================
   BUBBLE WRAPPER
   ============================================ */
.chat-bubble-wrap {
    max-width: var(--chat-max-bubble-width);
    position: relative;
    display: flex;
    flex-direction: column;
    transition: transform var(--chat-anim-fast);
}

.chat-message.user .chat-bubble-wrap {
    align-items: flex-end;
}

.chat-message.admin .chat-bubble-wrap {
    align-items: flex-start;
}

/* Admin panel perspective flip */
[data-chat-perspective="admin"] .chat-message.user .chat-bubble-wrap {
    align-items: flex-start;
}

[data-chat-perspective="admin"] .chat-message.admin .chat-bubble-wrap {
    align-items: flex-end;
}

.chat-message:hover .chat-bubble-wrap {
    transform: translateY(-1px);
}

/* ============================================
   CHAT BUBBLE (Base)
   ✅ v3.0: Compact — shrinks to content, tight padding
   ============================================ */
.chat-bubble {
    padding: var(--chat-bubble-pad-y) var(--chat-bubble-pad-x) calc(var(--chat-bubble-pad-y) - 1px) var(--chat-bubble-pad-x);
    border-radius: var(--chat-bubble-radius);
    font-size: var(--chat-bubble-font-size);
    line-height: var(--chat-bubble-line-height);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-line;                  /* ✅ pre-wrap → pre-line */
    position: relative;
    min-width: 0;                           /* ✅ 70px → 0 */
    max-width: 100%;
    width: fit-content;                     /* ✅ shrink to content */
    display: inline-block;                  /* ✅ inline-block */
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
    transition: box-shadow var(--chat-anim-fast);
    vertical-align: bottom;
}

/* User's bubble (default: right side, accent colored) */
.chat-message.user .chat-bubble {
    background: linear-gradient(135deg, var(--chat-user-bubble), var(--chat-user-bubble-dim));
    color: var(--chat-user-text);
    border-top-right-radius: var(--chat-bubble-tail);
    box-shadow: 0 2px 6px rgba(0, 212, 170, 0.18);
}

/* Admin/other's bubble (default: left side, subtle) */
.chat-message.admin .chat-bubble {
    background: var(--chat-admin-bubble);
    color: var(--chat-admin-text);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-top-left-radius: var(--chat-bubble-tail);
}

/* ✅ Admin panel perspective: flip the tails */
[data-chat-perspective="admin"] .chat-message.user .chat-bubble {
    border-top-right-radius: var(--chat-bubble-radius);
    border-top-left-radius: var(--chat-bubble-tail);
}

[data-chat-perspective="admin"] .chat-message.admin .chat-bubble {
    border-top-left-radius: var(--chat-bubble-radius);
    border-top-right-radius: var(--chat-bubble-tail);
}

/* System message bubble */
.chat-message.system .chat-bubble {
    background: var(--chat-system-bubble);
    color: var(--chat-system-text);
    border: 1px dashed var(--border, rgba(255, 255, 255, 0.1));
    font-style: italic;
    font-size: 12.5px;
    padding: 5px 12px;
    text-align: center;
    border-radius: 999px;
    max-width: 500px;
    box-shadow: none;
}

/* ============================================
   TEXT CONTENT
   ✅ v3.0: inline (not block) — flows with meta
   ============================================ */
.chat-text-content,
.chat-text {
    display: inline;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    unicode-bidi: plaintext;
}

/* ============================================
   BUBBLE META (time + ticks)
   ✅ v3.0: INLINE — floats at end of text, no extra line
   ============================================ */
.chat-bubble-meta,
.chat-meta-inline {
    display: inline-block;                  /* ✅ inline raho */
    float: none;                            /* ✅ float hatao */
    margin-left: 6px;                       /* text se gap */
    margin-top: 0;
    padding-left: 2px;
    font-size: var(--chat-bubble-meta-size);
    opacity: 0.72;
    line-height: 1;
    user-select: none;
    white-space: nowrap;
    vertical-align: baseline;               /* ✅ text ke saath baseline align */
    position: relative;
    top: 0.5px;                             /* ✅ tiny nudge for optical alignment */
    pointer-events: none;
}

.chat-message.user .chat-bubble-meta,
.chat-message.user .chat-meta-inline {
    color: rgba(8, 12, 16, 0.68);
}

.chat-message.admin .chat-bubble-meta,
.chat-message.admin .chat-meta-inline {
    color: var(--chat-tick-default);
}

/* ✅ CHAT-TICK (✓, ✓✓) — inline alignment */
.chat-tick {
    display: inline-block;
    margin-left: 2px;
    font-size: 11px;
    line-height: 1;
    vertical-align: middle;                 /* ✅ tick text ke middle pe */
    font-weight: 600;
}

/* ✅ CHAT-TIME — inline with text */
.chat-time {
    display: inline;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.2px;
}

.chat-tick.read {
    color: var(--chat-tick-read);
    filter: drop-shadow(0 0 2px rgba(79, 195, 247, 0.4));
}

.chat-tick.failed {
    color: var(--chat-tick-failed);
}

/* Edited / starred markers */
.chat-edited {
    display: inline;
    font-size: 10px;
    opacity: 0.7;
    font-style: italic;
    margin-right: 2px;
}

.chat-star {
    display: inline;
    color: var(--warning, #f0b429);
    font-size: 11px;
    filter: drop-shadow(0 0 2px rgba(240, 180, 41, 0.4));
    margin-right: 2px;
}

/* ============================================
   REPLY QUOTE (inside bubble)
   ============================================ */
.chat-reply-quote {
    padding: 5px 9px;
    border-left: 3px solid var(--accent, #00d4aa);
    background: rgba(0, 212, 170, 0.1);
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 11.5px;
    cursor: pointer;
    transition: background var(--chat-anim-fast);
    overflow: hidden;
    display: block;
}

.chat-reply-quote:hover {
    background: rgba(0, 212, 170, 0.18);
}

.chat-message.user .chat-reply-quote {
    background: rgba(8, 12, 16, 0.15);
    border-left-color: #080c10;
}

.chat-message.user .chat-reply-quote:hover {
    background: rgba(8, 12, 16, 0.25);
}

.chat-reply-quote strong {
    display: block;
    font-size: 10.5px;
    font-weight: 700;
    margin-bottom: 2px;
    color: var(--accent, #00d4aa);
    letter-spacing: 0.2px;
}

.chat-message.user .chat-reply-quote strong {
    color: #080c10;
}

.chat-reply-quote .reply-text,
.chat-reply-quote > div,
.chat-reply-quote > span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.85;
    display: block;
}

/* ============================================
   ATTACHMENTS
   ============================================ */
.chat-attachment-img {
    display: block;
    max-width: 260px;
    max-height: 260px;
    width: auto;
    height: auto;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 4px;
    object-fit: cover;
    border: 1px solid rgba(0, 0, 0, 0.1);
    transition: transform var(--chat-anim-fast), box-shadow var(--chat-anim-fast);
    background: rgba(0, 0, 0, 0.05);
}

.chat-attachment-img:hover {
    transform: scale(1.015);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.chat-attachment-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    font-size: 12.5px;
    margin-bottom: 4px;
    transition: background var(--chat-anim-fast);
    word-break: break-all;
}

.chat-attachment-file:hover {
    background: rgba(0, 0, 0, 0.25);
}

.chat-attachment-file i {
    font-size: 16px;
    color: var(--accent, #00d4aa);
    flex-shrink: 0;
}

.chat-message.user .chat-attachment-file {
    background: rgba(8, 12, 16, 0.15);
}

.chat-message.user .chat-attachment-file:hover {
    background: rgba(8, 12, 16, 0.25);
}

.chat-message.user .chat-attachment-file i {
    color: #080c10;
}

/* ============================================
   DELETED MESSAGE
   ============================================ */
.chat-bubble.deleted {
    background: transparent !important;
    border: 1px dashed var(--border, rgba(255, 255, 255, 0.15));
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    font-style: italic;
    font-size: 13px;
    padding: 5px 12px;
    box-shadow: none;
}

.chat-message.user .chat-bubble.deleted,
.chat-message.admin .chat-bubble.deleted {
    background: transparent !important;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
}

/* ============================================
   MESSAGE ACTIONS (hover)
   ============================================ */
.chat-msg-actions {
    position: absolute;
    top: -2px;
    display: none;
    gap: 2px;
    background: var(--bg-card-solid, var(--bg-card, #14181f));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 999px;
    padding: 3px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    z-index: 12;
    animation: chatActionsIn 0.15s ease;
}

@keyframes chatActionsIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* Default position (user side): actions appear on opposite side */
.chat-message.user .chat-msg-actions {
    right: 100%;
    margin-right: 8px;
}

.chat-message.admin .chat-msg-actions {
    left: 100%;
    margin-left: 8px;
}

/* Admin perspective: flip */
[data-chat-perspective="admin"] .chat-message.user .chat-msg-actions {
    right: auto;
    left: 100%;
    margin-right: 0;
    margin-left: 8px;
}

[data-chat-perspective="admin"] .chat-message.admin .chat-msg-actions {
    left: auto;
    right: 100%;
    margin-left: 0;
    margin-right: 8px;
}

.chat-message:hover .chat-msg-actions {
    display: flex;
}

/* On very small screens — position above */
@media (max-width: 480px) {
    .chat-message.user .chat-msg-actions {
        right: 0;
        top: -36px;
        margin-right: 0;
    }
    .chat-message.admin .chat-msg-actions {
        left: 0;
        top: -36px;
        margin-left: 0;
    }

    [data-chat-perspective="admin"] .chat-message.user .chat-msg-actions {
        left: 0;
        right: auto;
        margin-left: 0;
    }
    [data-chat-perspective="admin"] .chat-message.admin .chat-msg-actions {
        right: 0;
        left: auto;
        margin-right: 0;
    }
}

.chat-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 999px;
    font-size: 12px;
    transition: all var(--chat-anim-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    font-family: inherit;
}

.chat-action-btn:hover {
    background: var(--accent-glow, rgba(0, 212, 170, 0.15));
    color: var(--accent, #00d4aa);
    transform: scale(1.08);
}

.chat-action-btn:active {
    transform: scale(0.95);
}

/* ============================================
   TYPING INDICATOR
   ============================================ */
.chat-typing-wrap {
    display: flex;
    margin-bottom: 4px;
    padding: 0 4px;
    animation: chatMessageIn 0.25s ease;
}

/* Admin side (default): typing indicator on left */
.chat-typing-wrap.chat-message.admin {
    justify-content: flex-start;
}

/* Flip for admin panel */
[data-chat-perspective="admin"] .chat-typing-wrap.chat-message.admin {
    justify-content: flex-start;
}

[data-chat-perspective="admin"] .chat-typing-wrap.chat-message.user {
    justify-content: flex-start;
}

.chat-typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 9px 14px;
    background: var(--chat-admin-bubble, var(--bg-card, #14181f));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: var(--chat-bubble-radius);
    border-top-left-radius: var(--chat-bubble-tail);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    min-width: 50px;
    justify-content: center;
}

.chat-message.admin .chat-typing-indicator {
    background: linear-gradient(135deg, var(--chat-user-bubble), var(--chat-user-bubble-dim));
    border-color: transparent;
    border-top-left-radius: var(--chat-bubble-radius);
    border-top-right-radius: var(--chat-bubble-tail);
}

.chat-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted, rgba(240, 245, 248, 0.5));
    animation: chatTypingBounce 1.4s ease-in-out infinite;
    display: inline-block;
}

.chat-message.admin .chat-typing-indicator span {
    background: rgba(8, 12, 16, 0.6);
}

.chat-typing-indicator span:nth-child(2) {
    animation-delay: 0.18s;
}

.chat-typing-indicator span:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes chatTypingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* ============================================
   CHAT AVATAR
   ============================================ */
.chat-avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #ffffff;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    overflow: visible;
    user-select: none;
    /* Default size — can be overridden by page CSS */
    width: 44px;
    height: 44px;
    font-size: 16px;
}

.chat-avatar-status {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-sidebar, var(--bg-secondary, #11151b));
    background: var(--text-muted, rgba(240, 245, 248, 0.4));
    transition: background 0.2s;
}

.chat-avatar-status.online {
    background: var(--success, #25d366);
    box-shadow: 0 0 8px var(--success, #25d366);
    animation: chatOnlinePulse 2s ease-in-out infinite;
}

@keyframes chatOnlinePulse {
    0%, 100% {
        box-shadow: 0 0 8px var(--success, #25d366);
    }
    50% {
        box-shadow: 0 0 14px var(--success, #25d366), 0 0 0 4px rgba(37, 211, 102, 0.15);
    }
}

/* ============================================
   CHAT INPUT AREA (shared)
   ============================================ */
.chat-input-area {
    position: relative;
}

.chat-input-wrap,
.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-textarea {
    flex: 1;
    background: var(--bg-secondary, #11151b);
    border: 1.5px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 20px;
    padding: 10px 16px;
    color: var(--text-primary, #f0f5f8);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    outline: none;
    resize: none;
    max-height: 120px;
    min-height: 42px;
    transition: border-color var(--chat-anim-fast), box-shadow var(--chat-anim-fast);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.chat-textarea::-webkit-scrollbar {
    width: 5px;
}

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

.chat-textarea::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.chat-textarea:focus {
    border-color: var(--accent, #00d4aa);
    box-shadow: 0 0 0 3px var(--accent-glow, rgba(0, 212, 170, 0.15));
}

.chat-textarea::placeholder {
    color: var(--text-muted, rgba(240, 245, 248, 0.4));
}

/* Send button */
.chat-send-btn,
.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent, #00d4aa), var(--accent-dim, #00b894));
    color: #080c10;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: all var(--chat-anim-fast);
    box-shadow: 0 3px 12px var(--accent-glow, rgba(0, 212, 170, 0.25));
    font-family: inherit;
}

.chat-send-btn:hover:not(:disabled),
.send-btn:hover:not(:disabled) {
    transform: scale(1.06) translateY(-1px);
    box-shadow: 0 6px 18px var(--accent-glow-strong, rgba(0, 212, 170, 0.35));
}

.chat-send-btn:active:not(:disabled),
.send-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.chat-send-btn:disabled,
.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.chat-send-btn.sending,
.send-btn.sending {
    pointer-events: none;
    opacity: 0.8;
}

.chat-send-btn.sending i,
.send-btn.sending i {
    animation: chatSpin 0.8s linear infinite;
}

@keyframes chatSpin {
    to { transform: rotate(360deg); }
}

/* Tool buttons */
.chat-tool-btn,
.tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all var(--chat-anim-fast);
    font-family: inherit;
}

.chat-tool-btn:hover,
.tool-btn:hover {
    background: var(--bg-hover, rgba(0, 212, 170, 0.06));
    color: var(--accent, #00d4aa);
    transform: scale(1.1);
}

.chat-tool-btn:active,
.tool-btn:active {
    transform: scale(0.95);
}

/* ============================================
   REPLY BANNER (above input)
   ============================================ */
.chat-reply-banner {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--accent-glow, rgba(0, 212, 170, 0.12));
    border-left: 3px solid var(--accent, #00d4aa);
    padding: 7px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 12px;
    animation: chatReplyIn 0.2s ease;
}

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

.chat-reply-banner.active {
    display: flex;
}

.chat-reply-banner .reply-info,
.chat-reply-banner .reply-body {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-reply-banner strong {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent, #00d4aa);
    margin-bottom: 2px;
    letter-spacing: 0.2px;
}

.chat-reply-banner .reply-text,
.chat-reply-banner .reply-body div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted, rgba(240, 245, 248, 0.6));
}

.chat-reply-cancel,
.reply-cancel {
    background: transparent;
    border: none;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--chat-anim-fast);
    flex-shrink: 0;
    font-family: inherit;
}

.chat-reply-cancel:hover,
.reply-cancel:hover {
    background: rgba(255, 77, 77, 0.15);
    color: var(--danger, #ff4d4d);
}

/* ============================================
   QUICK REPLIES
   ============================================ */
.chat-quick-replies,
.quick-replies-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
}

.chat-quick-replies::-webkit-scrollbar,
.quick-replies-bar::-webkit-scrollbar {
    display: none;
}

.quick-reply-chip {
    background: var(--bg-card, rgba(20, 25, 32, 0.85));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    color: var(--text-secondary, rgba(240, 245, 248, 0.7));
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all var(--chat-anim-fast);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}

.quick-reply-chip:hover {
    background: var(--accent-glow, rgba(0, 212, 170, 0.15));
    border-color: var(--accent, #00d4aa);
    color: var(--accent, #00d4aa);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.quick-reply-chip:active {
    transform: translateY(-1px) scale(0.98);
}

/* ============================================
   EMOJI PICKER (shared)
   ============================================ */
.chat-emoji-picker,
.emoji-picker {
    position: absolute;
    bottom: 100%;
    right: 12px;
    margin-bottom: 8px;
    background: var(--bg-card-solid, var(--bg-card, #14181f));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 14px;
    padding: 10px;
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    z-index: 60;
    max-width: 340px;
    max-height: 300px;
    overflow-y: auto;
    animation: chatEmojiIn 0.18s ease;
}

@keyframes chatEmojiIn {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-emoji-picker.show,
.emoji-picker.show {
    display: grid;
}

.chat-emoji-picker::-webkit-scrollbar,
.emoji-picker::-webkit-scrollbar {
    width: 6px;
}

.chat-emoji-picker::-webkit-scrollbar-thumb,
.emoji-picker::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.3);
    border-radius: 3px;
}

.emoji-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    border-radius: 8px;
    transition: all var(--chat-anim-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    line-height: 1;
    font-family: inherit;
}

.emoji-btn:hover {
    background: var(--accent-glow, rgba(0, 212, 170, 0.15));
    transform: scale(1.2);
}

.emoji-btn:active {
    transform: scale(0.95);
}

/* ============================================
   SCROLL TO BOTTOM BUTTON
   ============================================ */
.chat-scroll-bottom,
.scroll-bottom-btn {
    position: absolute;
    bottom: 100px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card-solid, var(--bg-card, #14181f));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    color: var(--text-secondary, rgba(240, 245, 248, 0.7));
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
    z-index: 20;
    font-size: 16px;
    transition: all var(--chat-anim-fast);
    font-family: inherit;
}

.chat-scroll-bottom.visible,
.scroll-bottom-btn.visible {
    display: flex;
    animation: chatScrollBtnIn 0.25s var(--chat-anim-bounce);
}

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

.chat-scroll-bottom:hover,
.scroll-bottom-btn:hover {
    background: var(--accent, #00d4aa);
    color: #080c10;
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px var(--accent-glow-strong, rgba(0, 212, 170, 0.35));
}

.chat-scroll-bottom .badge-count,
.scroll-bottom-btn .badge-count {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--danger, #ff4d4d);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-card-solid, var(--bg-card, #14181f));
    animation: chatBadgePop 0.4s var(--chat-anim-bounce);
}

@keyframes chatBadgePop {
    0% { transform: scale(0); }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ============================================
   MESSAGE HIGHLIGHT (scroll-to)
   ============================================ */
.chat-message-highlight .chat-bubble {
    animation: chatHighlight 1.8s ease;
}

@keyframes chatHighlight {
    0% {
        box-shadow: 0 0 0 3px var(--accent, #00d4aa), 0 0 20px rgba(0, 212, 170, 0.3);
        transform: scale(1.02);
    }
    40% {
        box-shadow: 0 0 0 3px var(--accent, #00d4aa), 0 0 20px rgba(0, 212, 170, 0.3);
        transform: scale(1.02);
    }
    100% {
        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
        transform: scale(1);
    }
}

/* ============================================
   SEARCH HIGHLIGHT
   ============================================ */
.chat-search-highlight {
    background: rgba(240, 180, 41, 0.35);
    color: inherit;
    padding: 0 2px;
    border-radius: 3px;
    font-weight: 600;
}

/* ============================================
   CHAT WELCOME / EMPTY STATE
   ============================================ */
.chat-welcome {
    text-align: center;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    padding: 40px 20px;
    animation: chatMessageIn 0.4s ease;
}

.chat-welcome .welcome-icon,
.chat-welcome > div:first-child {
    font-size: 42px;
    margin-bottom: 12px;
    animation: chatWelcomeFloat 3s ease-in-out infinite;
    display: inline-block;
}

@keyframes chatWelcomeFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.chat-welcome h4 {
    color: var(--text-secondary, rgba(240, 245, 248, 0.7));
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}

.chat-welcome p {
    font-size: 13px;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    line-height: 1.5;
    max-width: 320px;
    margin: 0 auto;
}

/* ============================================
   SECURE BADGE
   ============================================ */
.chat-secure-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 11.5px;
    color: var(--text-muted, rgba(240, 245, 248, 0.45));
    text-align: center;
}

.chat-secure-badge i {
    color: var(--accent, #00d4aa);
    font-size: 12px;
}

/* ============================================
   CHAT ATTACHMENT PREVIEW (pending upload)
   Supports both .chat-attachment-preview and #pendingAttachmentPreview
   ============================================ */
.chat-attachment-preview,
#pendingAttachmentPreview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--accent-glow, rgba(0, 212, 170, 0.12));
    border: 1px solid var(--accent, #00d4aa);
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 12.5px;
    animation: chatReplyIn 0.2s ease;
}

.chat-attachment-preview img,
#pendingAttachmentPreview img {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
}

.chat-attachment-preview .preview-info,
#pendingAttachmentPreview .preview-info {
    flex: 1;
    min-width: 0;
}

.chat-attachment-preview .preview-name,
#pendingAttachmentPreview .preview-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-attachment-preview .preview-size,
#pendingAttachmentPreview .preview-size {
    font-size: 11px;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
}

.chat-attachment-preview .preview-remove,
#pendingAttachmentPreview .preview-remove {
    background: transparent;
    border: none;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    border-radius: 50%;
    transition: all var(--chat-anim-fast);
    flex-shrink: 0;
    font-family: inherit;
}

.chat-attachment-preview .preview-remove:hover,
#pendingAttachmentPreview .preview-remove:hover {
    background: rgba(255, 77, 77, 0.15);
    color: var(--danger, #ff4d4d);
}

/* ============================================
   LOADING SKELETON (for chat list)
   Supports both .chat-skeleton and .chat-skeleton-item
   ============================================ */
.chat-skeleton,
.chat-skeleton-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.06));
    animation: chatSkeletonPulse 1.5s ease-in-out infinite;
}

@keyframes chatSkeletonPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.85; }
}

.chat-skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-secondary, #11151b);
    flex-shrink: 0;
}

.chat-skeleton-body,
.chat-skeleton-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.chat-skeleton-line {
    height: 10px;
    background: var(--bg-secondary, #11151b);
    border-radius: 5px;
}

.chat-skeleton-line.short {
    width: 40%;
}

.chat-skeleton-line.medium {
    width: 70%;
}

/* ============================================
   CHAT LIST EMPTY STATE
   ============================================ */
.chat-list-empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
}

.chat-list-empty i {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 12px;
    display: block;
}

.chat-list-empty p {
    font-size: 13px;
    line-height: 1.5;
}

.chat-list-empty strong {
    color: var(--text-secondary, rgba(240, 245, 248, 0.7));
}

/* ============================================
   CHAT LIST ITEM (admin sidebar)
   ============================================ */
.chat-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.06));
    transition: background var(--chat-anim-fast);
    position: relative;
}

.chat-list-item:hover {
    background: var(--bg-hover, rgba(0, 212, 170, 0.06));
}

.chat-list-item.active {
    background: var(--accent-glow, rgba(0, 212, 170, 0.12));
    border-left: 3px solid var(--accent, #00d4aa);
}

.chat-list-item.pinned::after {
    content: '📌';
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 11px;
}

.chat-item-body {
    flex: 1;
    min-width: 0;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 3px;
}

.chat-item-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #f0f5f8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-item-time {
    font-size: 11px;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-item-time.unread {
    color: var(--accent, #00d4aa);
    font-weight: 700;
}

.chat-item-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.chat-item-preview {
    font-size: 12.5px;
    color: var(--text-muted, rgba(240, 245, 248, 0.5));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-item-preview.typing {
    color: var(--success, #25d366);
    font-style: italic;
}

.chat-item-badge {
    background: var(--accent, #00d4aa);
    color: #080c10;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.chat-item-labels {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}

.chat-label-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

/* ============================================
   ADMIN CHAT HEADER (extended)
   ============================================ */
.chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    position: relative;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.chat-header-meta .online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success, #25d366);
    box-shadow: 0 0 6px var(--success, #25d366);
    display: inline-block;
}

.chat-header-meta.typing {
    color: var(--success, #25d366);
    font-style: italic;
}

/* ============================================
   RESPONSIVE — Mobile
   ============================================ */
@media (max-width: 900px) {
    .chat-bubble-wrap {
        max-width: var(--chat-max-bubble-mobile);
    }

    .chat-message {
        padding: 0 2px;
        margin-bottom: 2px;
    }

    .chat-messages-area,
    .chat-messages {
        padding: 12px 10px;
    }
}

@media (max-width: 600px) {
    .chat-bubble {
        font-size: 13.5px;
        padding: 3px 8px 2px 8px;           /* ✅ tighter */
        line-height: 1.35;
    }

    .chat-bubble-meta,
    .chat-meta-inline {
        font-size: 9.5px;
    }

    .chat-attachment-img {
        max-width: 200px;
        max-height: 200px;
    }

    .chat-date-separator {
        margin: 10px 0 6px;
    }

    .chat-date-separator span {
        font-size: 10.5px;
        padding: 3px 10px;
    }

    .chat-scroll-bottom,
    .scroll-bottom-btn {
        width: 40px;
        height: 40px;
        right: 16px;
        bottom: 90px;
        font-size: 14px;
    }

    .chat-emoji-picker,
    .emoji-picker {
        max-width: 280px;
        grid-template-columns: repeat(7, 1fr);
        right: 6px;
        padding: 8px;
    }

    .emoji-btn {
        font-size: 18px;
    }

    .chat-textarea {
        font-size: 13.5px;
        padding: 9px 14px;
        border-radius: 18px;
    }

    .chat-send-btn,
    .send-btn {
        width: 40px;
        height: 40px;
        font-size: 15px;
    }

    .chat-tool-btn,
    .tool-btn {
        width: 36px;
        height: 36px;
        font-size: 15px;
    }

    .chat-avatar {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
}

@media (max-width: 400px) {
    .chat-emoji-picker,
    .emoji-picker {
        grid-template-columns: repeat(6, 1fr);
        max-width: 240px;
    }

    .chat-attachment-img {
        max-width: 160px;
        max-height: 160px;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .chat-message,
    .chat-typing-indicator span,
    .chat-welcome .welcome-icon,
    .chat-avatar-status.online,
    .chat-badge-pop,
    .chat-list-item,
    .chat-list-item.pinned::after {
        animation: none !important;
    }

    .chat-message,
    .chat-bubble,
    .chat-action-btn,
    .chat-send-btn,
    .send-btn,
    .chat-tool-btn,
    .tool-btn,
    .quick-reply-chip,
    .chat-list-item {
        transition: none !important;
    }
}

/* Focus visible ring for keyboard navigation */
.chat-action-btn:focus-visible,
.chat-send-btn:focus-visible,
.send-btn:focus-visible,
.chat-tool-btn:focus-visible,
.tool-btn:focus-visible,
.quick-reply-chip:focus-visible,
.emoji-btn:focus-visible,
.chat-list-item:focus-visible {
    outline: 2px solid var(--accent, #00d4aa);
    outline-offset: 2px;
}

/* ============================================
   UTILITY HELPERS
   ============================================ */
.chat-hidden {
    display: none !important;
}

.chat-noselect {
    user-select: none;
    -webkit-user-select: none;
}

.chat-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-text-center {
    text-align: center;
}

/* ============================================
   END chat.css v3.0 — Compact WhatsApp-style bubbles
   ============================================ */
