/* ── BLACK HEADER (same as friends.css) ── */
.black-header {
    width: 100%;
    height: 100px;
    background-color: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    flex-shrink: 0;            /* never collapse — always 100px */
}
.header-content {
    width: 100%;
    max-width: 1400px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 40px;
    box-sizing: border-box;
}
.center-logo { position: relative; height: 58px; }
.center-logo img { height: 58px; width: auto; cursor: pointer; transition: transform 0.2s ease; }
.black-header, .header-content, .center-logo, .center-logo img {
    user-select: none; -webkit-user-select: none;
}

/* ── BODY — default: normal scrolling for inbox view ── */
body {
    font-family: Arial, sans-serif;
    background: url("https://i.postimg.cc/0yZsTQcy/matteblack.png") no-repeat top center fixed;
    background-size: cover;
    margin: 0; padding: 0;
    animation: fade-in 0.6s ease-in;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* When chat is open: lock to exact screen height, no page scroll */
body.chat-open {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
}
@keyframes fade-in { 0% { opacity: 0; } 100% { opacity: 1; } }

/* ── MAIN CONTAINER ── */
.messages-container {
    display: flex;
    flex-direction: column;
    max-width: 700px;
    width: 100%;
    margin: 0 auto;
    flex: 1;
    min-height: 0;             /* critical: allows flex children to shrink and scroll */
    box-sizing: border-box;
    overflow: hidden;          /* container itself doesn't scroll */
}

/* ── HIDDEN UTILITY ── */
.hidden { display: none !important; }

/* ══════════════════════════════════════════════
   INBOX VIEW
   ══════════════════════════════════════════════ */
#inboxView {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.inbox-header {
    padding: 24px 20px 16px;
}
.inbox-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: 26px;
    color: white;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin: 0;
}

.inbox-list {
    display: flex;
    flex-direction: column;
    padding: 0 12px;
}

/* ── CONVERSATION CARD ── */
.convo-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 16px;
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
    position: relative;
}
.convo-card:hover {
    background: rgba(255,255,255,0.06);
}
.convo-card:active {
    background: rgba(255,255,255,0.1);
}
.convo-avatar {
    width: 52px; height: 52px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.12);
    flex-shrink: 0;
    background: #222;
}
.convo-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.convo-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.convo-name {
    font-size: 15px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.convo-time {
    font-size: 12px;
    color: rgba(255,255,255,0.35);
    flex-shrink: 0;
    white-space: nowrap;
}
.convo-preview {
    font-size: 13px;
    color: rgba(255,255,255,0.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
/* Unread state — bolder name + brighter preview */
.convo-card.unread .convo-name {
    color: #ffffff;
}
.convo-card.unread .convo-preview {
    color: rgba(255,255,255,0.85);
    font-weight: 600;
}
/* Unread dot */
.convo-unread-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #0084ff;
    flex-shrink: 0;
}

/* ── DIVIDER between cards ── */
.convo-card + .convo-card {
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* ── EMPTY STATE ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}
.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.6;
}
.empty-text {
    font-size: 18px;
    font-weight: 700;
    color: rgba(255,255,255,0.55);
    margin: 0 0 8px;
}
.empty-sub {
    font-size: 14px;
    color: rgba(255,255,255,0.35);
    margin: 0;
}
.empty-sub a {
    color: #0084ff;
    text-decoration: none;
}
.empty-sub a:hover {
    text-decoration: underline;
}

/* ══════════════════════════════════════════════
   CHAT VIEW — fills all space between R header and bottom of screen
   Chat header + input bar are fixed, only messages area scrolls
   ══════════════════════════════════════════════ */
#chatView {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;             /* allows flex shrink so messages area gets overflow */
    overflow: hidden;
}

/* ── CHAT HEADER ── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}
.chat-back {
    background: rgba(255,255,255,0.08);
    border: none;
    color: rgba(255,255,255,0.7);
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
    box-sizing: border-box;
}
.chat-back:hover {
    background: rgba(255,255,255,0.15);
    color: white;
}
.chat-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.15);
    flex-shrink: 0;
}
.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.chat-header-name {
    font-size: 16px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-header-status {
    font-size: 12px;
    color: rgba(255,255,255,0.35);
}

/* ── MESSAGES AREA — the ONLY scrollable element on the page ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;             /* critical for flex overflow scroll */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;           /* Firefox */
    -ms-overflow-style: none;        /* IE/Edge */
}
.chat-messages::-webkit-scrollbar {
    display: none;                   /* Chrome/Safari */
}

/* ── DATE SEPARATOR ── */
.chat-date-sep {
    text-align: center;
    padding: 12px 0 8px;
}
.chat-date-sep span {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.06);
    padding: 4px 14px;
    border-radius: 12px;
    letter-spacing: 0.5px;
}

/* ── MESSAGE WRAPPER — groups bubble + timestamp tightly ── */
.msg-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    gap: 2px;                  /* consistent spacing between pill / bubble / timestamp */
}
.msg-wrapper.sent {
    align-self: flex-end;
    align-items: flex-end;
}
.msg-wrapper.received {
    align-self: flex-start;
    align-items: flex-start;
}

/* ── MESSAGE BUBBLES ── */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;           /* wrapper already constrains width */
    animation: msg-appear 0.2s ease;
}
@keyframes msg-appear {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Sent = right side (me) */
.msg-row.sent {
    flex-direction: row-reverse;
}
/* Received = left side (friend) */
.msg-row.received {
    /* default left alignment */
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-break: break-word;
    position: relative;
    max-width: 100%;
}

/* Sent bubble — white with black text */
.msg-row.sent .msg-bubble {
    background: #ffffff;
    color: #000000;
    border-bottom-right-radius: 4px;
}

/* Received bubble — dark glass */
.msg-row.received .msg-bubble {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.92);
    border-bottom-left-radius: 4px;
}

/* Consecutive same-sender: tighter spacing, uniform radius */
.msg-row.sent + .msg-row.sent { margin-top: -2px; }
.msg-row.received + .msg-row.received { margin-top: -2px; }
.msg-row.sent + .msg-row.sent .msg-bubble { border-radius: 18px; border-bottom-right-radius: 4px; }
.msg-row.received + .msg-row.received .msg-bubble { border-radius: 18px; border-bottom-left-radius: 4px; }

/* Timestamp under bubble — aligned by wrapper, spaced by wrapper gap */
.msg-time {
    font-size: 11px;
    color: rgba(255,255,255,0.25);
    padding: 0 4px;
}

/* Read receipt */
.msg-read-receipt {
    font-size: 11px;
    color: rgba(255,255,255,0.25);
    text-align: right;
    padding-right: 4px;
    margin-top: 1px;
}

/* ── TYPING INDICATOR ── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 16px;
}
.typing-indicator.hidden { display: none; }
.typing-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── CHAT INPUT BAR ── */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

#chatInput {
    flex: 1;
    padding: 12px 16px;
    border-radius: 22px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.07);
    color: white;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.4;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
#chatInput:focus {
    border-color: rgba(0,132,255,0.5);
}
#chatInput::placeholder {
    color: rgba(255,255,255,0.3);
}

.chat-send-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    border: none;
    background: #0084ff;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
    padding: 0;
    box-sizing: border-box;
}
.chat-send-btn:hover {
    background: #0073e6;
    transform: scale(1.05);
}
.chat-send-btn:active {
    transform: scale(0.95);
}
.chat-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

/* ── LOADING / STATUS MESSAGES ── */
.loading-msg {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255,255,255,0.4);
    font-size: 15px;
}

/* ── LOAD MORE BUTTON ── */
.load-more-btn {
    display: block;
    margin: 8px auto 12px;
    padding: 8px 20px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.load-more-btn:hover {
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.8);
}

/* ── DELETED MESSAGE BUBBLE ── */
.msg-bubble.deleted {
    font-style: italic;
    opacity: 0.45;
    font-size: 13px;
}

/* ── MESSAGE BUBBLES: text not selectable (tap to select message instead) ── */
.msg-bubble {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;   /* prevents iOS callout menu on long-press */
}

/* ── SELECTED MESSAGE STATE (subtle highlight) ── */
.msg-wrapper.selected .msg-bubble {
    outline: 2px solid rgba(255,255,255,0.4);
    outline-offset: 2px;
}

/* ── FLOATING ACTION PILL (appears above selected message — WhatsApp style) ── */
.msg-action-pill {
    display: flex;
    gap: 2px;
    background: #1c1e21;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 22px;
    padding: 4px 6px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.5);
    animation: pill-appear 0.12s ease;
    z-index: 100;
    width: fit-content;
}
@keyframes pill-appear {
    from { opacity: 0; transform: scale(0.9) translateY(4px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
/* Sent messages: pill aligned right */
.msg-wrapper.sent .msg-action-pill {
    margin-left: auto;
}
/* Received messages: pill aligned left */
.msg-wrapper.received .msg-action-pill {
    margin-right: auto;
}
.msg-action-pill button {
    padding: 7px 16px;
    border-radius: 18px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.12s;
    white-space: nowrap;
}
.msg-action-pill button:hover {
    background: rgba(255,255,255,0.1);
}
.msg-action-pill button.danger {
    color: #ff5c5c;
}
.msg-action-pill button.danger:hover {
    background: rgba(255,92,92,0.12);
}

/* ── CONFIRMATION MODAL (for clear conversation / delete message) ── */
.confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 20px;
    box-sizing: border-box;
}
.confirm-modal.hidden { display: none; }
.confirm-card {
    background: #1c1e21;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 18px;
    padding: 24px 22px 20px;
    width: min(340px, 100%);
    text-align: center;
    color: white;
    box-shadow: 0 16px 50px rgba(0,0,0,0.7);
}
.confirm-card p {
    font-size: 15px;
    color: rgba(255,255,255,0.75);
    margin: 0 0 20px;
    line-height: 1.5;
}
.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.confirm-actions button {
    padding: 12px 24px;
    border-radius: 24px;
    border: none;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    box-sizing: border-box;
}
.confirm-btn-cancel {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.12) !important;
}
.confirm-btn-cancel:hover {
    background: rgba(255,255,255,0.15);
}
.confirm-btn-danger {
    background: #dc143c;
    color: white;
}
.confirm-btn-danger:hover {
    background: #c0112f;
}

/* ── TOAST (same as friends.css) ── */
.toast {
    position: fixed; bottom: 30px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1c1e21; color: white;
    padding: 14px 28px; border-radius: 30px;
    font-size: 14px; font-weight: bold;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    opacity: 0; transition: all 0.3s ease;
    z-index: 9999; white-space: nowrap;
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: #c0392b; }

/* ═══════════════════════════════════════════
   MOBILE
   ═══════════════════════════════════════════ */
@media screen and (max-width: 800px) {
    .black-header { height: 90px; flex-shrink: 0; }
    .header-content { padding: 0 20px; }
    .center-logo { height: 48px; }
    .center-logo img { height: 48px; }

    .messages-container {
        margin-top: 0;
        min-height: 0;
    }

    .inbox-header { padding: 20px 16px 12px; }
    .inbox-title { font-size: 22px; letter-spacing: 2px; }

    .convo-card { padding: 14px 14px; gap: 12px; }
    .convo-avatar { width: 48px; height: 48px; }
    .convo-name { font-size: 14px; }
    .convo-preview { font-size: 13px; }

    .chat-header { padding: 12px 12px; }
    .chat-avatar { width: 36px; height: 36px; }
    .chat-header-name { font-size: 15px; }

    .msg-wrapper { max-width: 85%; }
    .msg-bubble { font-size: 15px; }

    .chat-input-bar { padding: 10px 12px; }
    #chatInput { font-size: 16px; /* prevents iOS zoom */ padding: 10px 14px; }
    .chat-send-btn { width: 42px; height: 42px; }
}

/* ═══════════════════════════════════════════
   DESKTOP — bars stretch edge-to-edge (black background)
   Inner controls (buttons, avatar, input) stay centered at 700px
   ═══════════════════════════════════════════ */
@media screen and (min-width: 801px) {
    /* Container goes full width when chat is open */
    .messages-container:has(#chatView:not(.hidden)) {
        max-width: 100%;
    }

    /* Chat header: background full width, content centered at 700px */
    .chat-header {
        padding-left: calc(50% - 350px + 16px);
        padding-right: calc(50% - 350px + 16px);
    }

    /* Input bar: background full width, content centered at 700px */
    .chat-input-bar {
        padding-left: calc(50% - 350px + 16px);
        padding-right: calc(50% - 350px + 16px);
    }

    /* Messages area stays centered and constrained */
    .chat-messages {
        max-width: 700px;
        width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    /* Typing indicator matches messages width */
    .typing-indicator {
        max-width: 700px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* ═══════════════════════════════════════════
   WIDE SCREENS
   ═══════════════════════════════════════════ */
@media screen and (min-width: 1920px) {
    .header-content { max-width: 1800px; padding: 0 13px; }
}

/* ── Block selection on UI chrome ── */
.black-header, .header-content, .center-logo, .center-logo img,
.chat-header, .chat-back, .chat-send-btn, .chat-input-bar,
.convo-card, .inbox-header, .typing-indicator,
.msg-bubble, .msg-wrapper, .msg-time, .msg-action-pill {
    user-select: none;
    -webkit-user-select: none;
}
