/* CSS resets and variables */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Strict Scrollbar Hiding for all scrollable wrappers */
.chat-list,
.chat-content,
.settings-content,
.profile-content,
.app-container,
html,
body,
* {
    -ms-overflow-style: none !important;  /* IE and Edge */
    scrollbar-width: none !important;  /* Firefox */
}

.chat-list::-webkit-scrollbar,
.chat-content::-webkit-scrollbar,
.settings-content::-webkit-scrollbar,
.profile-content::-webkit-scrollbar,
.app-container::-webkit-scrollbar,
html::-webkit-scrollbar,
body::-webkit-scrollbar,
*::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    background: transparent !important;
}

html {
    height: 100%;
    height: -webkit-fill-available;
    width: 100vw;
    overscroll-behavior-y: none;
}

body {
    background-color: #0b0c0e;
    color: #ffffff;
    font-family: 'Plus Jakarta Sans', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    overflow: hidden;
    width: 100vw;
    overscroll-behavior-y: none;
}

/* App container matching the mobile aspect ratio */
.app-container {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: -webkit-fill-available;
    height: 100dvh;
    max-height: 960px;
    background: linear-gradient(110deg, #000000 0%, #060708 35%, #464a4f 100%);
    display: flex;
    flex-direction: column;
    padding: clamp(20px, 4dvh, 40px) 20px calc(clamp(14px, 3dvh, 26px) + env(safe-area-inset-bottom, 0px)) 20px;
    position: relative;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

@media (max-width: 480px) {
    body {
        background-color: #000000;
    }
    .app-container {
        max-width: 100%;
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh;
        max-height: 100vh;
        max-height: -webkit-fill-available;
        max-height: 100dvh;
        border: none;
        box-shadow: none;
        padding: clamp(16px, 3dvh, 32px) 16px calc(clamp(10px, 2dvh, 20px) + env(safe-area-inset-bottom, 0px)) 16px;
    }
}

/* Header Layout */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: clamp(16px, 4dvh, 32px);
    flex-shrink: 0;
}

/* Circular Back Button */
.btn-back {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
}

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

/* Pill profile button */
.btn-profile-pill {
    height: 52px;
    padding: 4px 6px 4px 4px;
    border-radius: 26px;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-profile-pill:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.03);
}

.btn-profile-pill:active {
    transform: scale(0.97);
}

.pill-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
}

/* Circular background for arrow inside pill */
.pill-arrow-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    transition: all 0.2s ease;
}

.btn-profile-pill:hover .pill-arrow-circle {
    background: rgba(255, 255, 255, 0.28);
    transform: scale(1.05);
}

/* Chat Content area */
.chat-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 3dvh, 22px);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    margin-bottom: clamp(16px, 3dvh, 30px);
    padding-right: 4px;
}

/* Premium Chat Bubble Styles */
.message-bubble-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 12px;
    max-width: 85%;
    position: relative;
    animation: bubbleAppear 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes bubbleAppear {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.bubble-left {
    margin-right: auto;
    flex-direction: row;
}

.bubble-right {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.message-bubble-content {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px 18px 18px 4px;
    padding: 10px 14px;
    color: #ffffff;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: background-color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.bubble-right .message-bubble-content {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.2);
    border-radius: 18px 18px 4px 18px;
}

.message-bubble-content:active {
    transform: scale(0.98);
}

/* Reply Context Inside Bubble */
.message-reply-preview {
    background: rgba(255, 255, 255, 0.06);
    border-left: 3px solid rgba(255, 255, 255, 0.6);
    border-radius: 4px;
    padding: 4px 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
}

.reply-sender {
    font-weight: 700;
    color: #ffffff;
}

.reply-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* Text and Meta styling */
.message-text {
    word-break: break-word;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.45);
    user-select: none;
}

.message-status svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Sent Date divider / badge */
.message-date-badge {
    align-self: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin: 8px auto;
    text-align: center;
    user-select: none;
}

/* Quick hover action buttons */
.message-hover-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    background: rgba(15, 15, 15, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 2px 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(8px);
    position: absolute;
    top: -16px;
    z-index: 10;
}

.bubble-left .message-hover-actions {
    right: -78px;
}

.bubble-right .message-hover-actions {
    left: -78px;
}

.message-bubble-wrapper:hover .message-hover-actions {
    opacity: 1;
    visibility: visible;
}

.hover-action-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.hover-action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.hover-action-btn svg {
    width: 14px;
    height: 14px;
}

/* Reply bar container above bottom input bar */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(15, 15, 15, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 10px 14px;
    margin-bottom: 10px;
    width: 100%;
    animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

.reply-bar-icon {
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
}

.reply-bar-icon svg {
    width: 18px;
    height: 18px;
}

.reply-bar-content {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reply-bar-title {
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
    text-align: left;
}

.reply-bar-text {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.reply-bar-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}

.reply-bar-close:hover {
    color: #ffffff;
}

/* Context Menu CSS */
.context-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.context-menu-overlay.active {
    opacity: 1;
}

.context-menu {
    background: rgba(20, 20, 20, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    width: 250px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transform: scale(0.92);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.context-menu-overlay.active .context-menu {
    transform: scale(1);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.context-menu-item:last-child {
    border-bottom: none;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.context-menu-item.danger {
    color: #ff3b30;
}

.context-menu-item.danger:hover {
    background: rgba(255, 59, 48, 0.15);
}

.context-menu-item svg {
    width: 18px;
    height: 18px;
    color: currentColor;
}

/* Toast Notifications styling */
.toast-notification {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translate(-50%, 20px);
    background: #ffffff;
    color: #000000;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.toast-notification.active {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* Bottom Input Bar */
.bottom-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    position: relative;
    z-index: 999;
}

.input-wrapper {
    flex-grow: 1;
    position: relative;
}

.message-input {
    width: 100%;
    height: 44px;
    max-height: 120px;
    border-radius: 22px;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: transparent;
    padding: 11px 46px;
    color: #ffffff;
    font-family: inherit;
    font-size: 16px;
    line-height: 20px;
    outline: none;
    resize: none;
    overflow-y: auto;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.input-action-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: all 0.2s ease;
    z-index: 2;
}

.input-action-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.input-action-btn:active {
    transform: translateY(-50%) scale(0.92);
}

.btn-emoji {
    left: 6px;
}

.btn-attachment {
    right: 6px;
}

.message-input::placeholder {
    color: rgba(255, 255, 255, 0.42);
}

.message-input:focus {
    border-color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.02);
}

/* Plus Action Button */
.btn-plus {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #ffffff;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-plus:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
}

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

/* Keyboard open dynamic layout overrides */
.app-container.keyboard-open .header {
    margin-bottom: clamp(6px, 2dvh, 12px);
}

.app-container.keyboard-open .chat-content {
    margin-bottom: clamp(10px, 2.5dvh, 16px);
    gap: clamp(8px, 2dvh, 14px);
}

/* Premium Chat Bubble Highlight & Local Context Menu */
.message-bubble-wrapper {
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), filter 0.3s ease, opacity 0.3s ease;
}

.message-bubble-wrapper.message-highlighted {
    position: relative;
    z-index: 10001 !important;
    transform: scale(1.01);
    pointer-events: auto !important;
}

.message-bubble-wrapper.message-highlighted .message-bubble-content {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.message-context-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.message-context-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.message-context-menu {
    position: fixed; /* so coordinates match getBoundingClientRect() directly */
    min-width: 185px;
    background: rgba(25, 25, 25, 0.85);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45);
    z-index: 10002;
    opacity: 0;
    transform: scale(0.92) translateY(-10px);
    transform-origin: top center;
    transition: opacity 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

.message-context-menu.active {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.context-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.88);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.context-menu-item:active {
    transform: scale(0.97);
}

.context-menu-item.danger {
    color: #ff453a;
}

.context-menu-item.danger:hover {
    background: rgba(255, 69, 58, 0.12);
    color: #ff453a;
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.8;
}

/* Pinned Message Banner Styles */
.pinned-message-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(20, 20, 20, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px 16px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    z-index: 10;
    position: relative;
    gap: 12px;
    animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.pinned-message-info {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.pinned-message-info svg {
    width: 14px;
    height: 14px;
    stroke: #00ca99;
    flex-shrink: 0;
}

.pinned-message-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.btn-unpin {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

.btn-unpin:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Multi-select Mode Styles */
.chat-content.multi-select-active .message-bubble-wrapper {
    cursor: pointer;
    user-select: none;
}

.message-checkbox-container {
    display: none;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    flex-shrink: 0;
    animation: fadeIn 0.2s ease;
}

.chat-content.multi-select-active .message-checkbox-container {
    display: flex;
}

.message-checkbox {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, border-color 0.2s;
}

.message-bubble-wrapper.selected .message-checkbox {
    background-color: #00ca99;
    border-color: #00ca99;
}

.message-checkbox svg {
    width: 12px;
    height: 12px;
    stroke: #000;
    stroke-width: 3.5;
    display: none;
}

.message-bubble-wrapper.selected .message-checkbox svg {
    display: block;
}

/* Multi-select Action Bar */
.multi-select-action-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(20, 20, 20, 0.9);
    backdrop-filter: blur(24px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.multi-select-action-bar.active {
    transform: translateY(0);
}

.multi-select-count {
    font-size: 14px;
    color: #fff;
    font-weight: 500;
}

.multi-select-actions {
    display: flex;
    gap: 12px;
}

.btn-multi-action {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, transform 0.1s;
}

.btn-multi-action:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-multi-action:active {
    transform: scale(0.97);
}

.btn-multi-action.danger {
    background: rgba(255, 69, 58, 0.15);
    border-color: rgba(255, 69, 58, 0.2);
    color: #ff453a;
}

.btn-multi-action.danger:hover {
    background: rgba(255, 69, 58, 0.25);
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* Hide bottom bar and reply bar during multi-select to avoid overlap/stacking */
.chat-view.multi-select-active .bottom-bar,
.chat-view.multi-select-active .reply-bar {
    display: none !important;
}

/* Adjust scroll container padding to prevent content overlap with multi-select bar */
.chat-view.multi-select-active #chat-messages-container {
    padding-bottom: 80px !important;
}
