/* ========================================
   INLINE CHAT NOTIFICATION (Telegram-style)
   Shows when a message arrives from a contact
   that is not the currently open chat.
   ======================================== */

/* Container that stacks individual toasts */
#chat-notif-container {
    position: fixed;
    /* Sit just below the iPhone safe area / Dynamic Island */
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;                 /* overlap managed by margin-top on front card */
    pointer-events: none;   /* let clicks fall through by default */
    width: min(460px, calc(100vw - 20px));
}

/* Individual notification card */
.chat-notif-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 13px 16px 13px 14px;
    background: rgba(14, 26, 40, 0.85);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 20px;
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.45),
        0 1px 0 rgba(255, 255, 255, 0.06) inset;
    cursor: pointer;
    pointer-events: all;
    user-select: none;
    overflow: hidden;

    /* Enter animation */
    opacity: 0;
    transform: translateY(-28px) scale(0.93);
    transition:
        opacity 0.32s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.32s cubic-bezier(0.16, 1, 0.3, 1),
        margin-top 0.30s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-notif-card.notif-enter {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Exit animation */
.chat-notif-card.notif-exit {
    opacity: 0;
    transform: translateY(-18px) scale(0.92);
    transition:
        opacity 0.22s ease,
        transform 0.22s ease;
    pointer-events: none;
}

/* Hover highlight */
.chat-notif-card:hover {
    background: rgba(20, 36, 54, 0.92);
    border-color: rgba(95, 149, 207, 0.25);
}

/* ── Stack layout ──────────────────────── */
/* Back card (oldest, behind the front card) */
.chat-notif-card.notif-stack-back {
    transform: scale(0.95);
    opacity: 0.48;
    z-index: 0;
    pointer-events: none;
    /* no margin — the FRONT card pulls itself up over this one */
}

/* Front card (newest, fully visible on top) */
.chat-notif-card.notif-stack-front {
    position: relative;
    z-index: 2;
}

/* When a back card precedes the front card, pull the front card
   up so the back card's top edge peeks above it (iOS-style deck). */
.chat-notif-card.notif-stack-back + .chat-notif-card.notif-stack-front {
    margin-top: -66px;
}

/* ── Avatar ────────────────────────────── */
.chat-notif-avatar {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0;
    overflow: hidden;
    background-color: #667eea; /* default, overridden inline */
}

.chat-notif-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Group badge overlaid on avatar */
.chat-notif-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.chat-notif-group-badge {
    position: absolute;
    bottom: -2px;
    left: -2px;   /* RTL: badge on left (visual right of avatar) */
    width: 18px;
    height: 18px;
    background: rgba(95, 149, 207, 0.85);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid rgba(14, 26, 40, 0.9);
}

.chat-notif-group-badge svg {
    width: 10px;
    height: 10px;
    fill: #fff;
}

/* ── Text body ─────────────────────────── */
.chat-notif-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-notif-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.chat-notif-name {
    font-size: 15px;
    font-weight: 700;
    color: #e8f2fb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-notif-group-label {
    font-size: 12.5px;
    color: rgba(95, 149, 207, 0.9);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 110px;
}

.chat-notif-time {
    font-size: 11px;
    color: rgba(200, 220, 240, 0.45);
    flex-shrink: 0;
}

.chat-notif-text {
    font-size: 14px;
    color: rgba(200, 220, 240, 0.75);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Lock icon for encrypted messages */
.chat-notif-text .notif-lock {
    font-style: normal;
    opacity: 0.6;
}

/* ── Dismiss button ────────────────────── */
.chat-notif-dismiss {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(200, 220, 240, 0.55);
    transition: background 0.18s, color 0.18s;
    padding: 0;
    margin-right: -4px;
    align-self: flex-start;
    margin-top: 2px;
}

.chat-notif-dismiss:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #e8f2fb;
}

.chat-notif-dismiss svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* ── Progress bar ──────────────────────── */
.chat-notif-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2.5px;
    background: rgba(95, 149, 207, 0.18);
    border-radius: 0 0 18px 18px;
    overflow: hidden;
}

.chat-notif-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #5f95cf, #7bd7ff);
    border-radius: inherit;
    transform-origin: left;
    transform: scaleX(1);
    transition: transform linear; /* duration set via JS */
}

/* ── Saved Messages card (bookmark colour) */
.chat-notif-card.notif-saved .chat-notif-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ── RTL adjustments ───────────────────── */
/* The container is centred; individual items flow RTL */
.chat-notif-card {
    direction: rtl;
    text-align: right;
}

.chat-notif-header {
    flex-direction: row-reverse;  /* time on left (visual right) */
}

.chat-notif-dismiss {
    margin-right: 0;
    margin-left: -4px;
    align-self: flex-start;
}

/* ── Responsive: on very small screens, go full-width ── */
@media (max-width: 768px) {
    #chat-notif-container {
        top: calc(env(safe-area-inset-top, 0px) + 10px);
        width: calc(100vw - 16px);
    }
    .chat-notif-card {
        border-radius: 16px;
    }
}
