:root {
    --chat-bg: #f8f9fa;
    --message-bg: #fff;
    --message-sent-bg: var(--primary-color);
    --message-received-bg: #fff;
    --chat-text: #2c3e50;
    --chat-text-light: #95a5a6;
    --chat-border: rgba(0,0,0,0.1);
}


body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; 
    
    position: fixed;
    width: 100%;
    
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}


input, textarea, select {
    font-size: 16px;
}

.chat-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: 1200px; 
    margin: 0;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    
    transition: height 0.3s ease;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--chat-border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.back-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    color: var(--text-dark);
    transition: all 0.3s ease;
}

.back-btn i {
    font-size: 1.1rem;
}

.back-btn:hover {
    background: var(--primary-color);
    transform: translateX(-2px);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info h2 {
    font-size: 1.1rem;
    color: var(--chat-text);
}

.user-info .status {
    font-size: 0.85rem;
    color: var(--chat-text-light);
}

.status.online::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #2ecc71;
    border-radius: 50%;
    margin-right: 5px;
}


.product-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--chat-border);
}

.product-preview {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.5rem 1rem;
    background: var(--bg-color);
    border-radius: 12px;
}

.product-image {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    overflow: hidden;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-details {
    flex: 1;
    min-width: 0;
}

.product-details h3 {
    font-size: 0.9rem;
    color: var(--chat-text);
    margin-bottom: 0.1rem;
}

.product-details .price {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--chat-text);
}

.view-btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-dark);
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.view-btn:hover {
    background: var(--primary-color);
    transform: translateY(-2px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
    scrollbar-width: thin;  
    scrollbar-color: var(--chat-border) transparent;  
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--chat-border);
    border-radius: 20px;
}

.date-divider {
    text-align: center;
    margin: 1rem 0;
    position: relative;
}

.date-divider span {
    background: var(--chat-bg);
    padding: 0 1rem;
    color: var(--chat-text-light);
    font-size: 0.85rem;
    position: relative;
    z-index: 1;
}

.date-divider::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    height: 1px;
    background: var(--chat-border);
}

.message-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 70%;
}

.message-group.sent {
    align-self: flex-end;
}

.message-group.received {
    align-self: flex-start;
}

.message {
    padding: 0.8rem 1rem;
    border-radius: 16px;
    position: relative;
    transition: all 0.3s ease;
}

.message-group.sent .message {
    background: var(--message-sent-bg);
    color: var(--text-dark);
    border-bottom-right-radius: 4px;
}

.message-group.received .message {
    background: var(--message-received-bg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.message-time {
    font-size: 0.75rem;
    color: var(--chat-text-light);
    margin-top: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.message-group.sent .message-time {
    justify-content: flex-end;
}

.message-status {
    display: flex;
    align-items: center;
}

.message-status i {
    font-size: 0.8rem;
}

.message-status.sent i { color: #bdc3c7; }
.message-status.delivered i { color: #3498db; }
.message-status.read i { color: #2ecc71; }


.chat-input {
    padding: 1rem 1.2rem;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid var(--chat-border);
    position: sticky;
    bottom: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    
    transition: transform 0.2s ease-out;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.8rem;
    background: var(--bg-color);
    padding: 0.8rem;
    border-radius: 24px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.input-wrapper:focus-within {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.message-input {
    flex: 1;
    min-height: 24px;
    max-height: 120px;
    padding: 0.4rem 0;
    font-size: 16px; 
    color: var(--chat-text);
    outline: none;
    overflow-y: auto;
    resize: none;
    border: none;
    background: transparent;
    line-height: 1.4;
    
    -webkit-user-select: text;
    user-select: text;
}

.message-input[placeholder]:empty::before {
    content: attr(placeholder);
    color: var(--chat-text-light);
}

.emoji-btn,
.attach-btn,
.send-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--chat-text);
    transition: all 0.3s ease;
}

.emoji-btn:hover,
.attach-btn:hover {
    background: var(--bg-color-dark);
    color: var(--text-dark);
}

.send-btn {
    background: var(--primary-color);
}

.send-btn:hover {
    transform: scale(1.05);
}

.send-btn i {
    font-size: 1rem;
    color: #fff;
}

.chat-divider {
    width: 2px;
    height: 36px;
    background: var(--chat-border);
    margin: 0 1rem;
}


.header-right {
    position: relative;
}

.action-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    color: var(--text-dark);
    transition: all 0.3s ease;
}

.action-btn:hover {
    background: var(--bg-color-dark);
    transform: translateY(-2px);
}

.header-actions-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 0.5rem;
    min-width: 200px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 100;
}

.header-actions-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.header-action-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    color: var(--text-dark);
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.header-action-item i {
    font-size: 1.1rem;
    width: 24px;
}

.header-action-item:hover {
    background: var(--bg-color);
}

.header-action-item.view-product:hover {
    background: rgba(76, 175, 80, 0.1);
    color: #4CAF50;
}

.header-action-item.block-user:hover {
    background: rgba(244, 67, 54, 0.1);
    color: #F44336;
}

.header-action-item.report:hover {
    background: rgba(255, 152, 0, 0.1);
    color: #FF9800;
}

.scroll-bottom-btn {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--card-bg);
    color: var(--text-dark);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 99999999;
}

.scroll-bottom-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-bottom-btn:hover {
    background: var(--primary-color);
    transform: translateY(-2px);
}

.scroll-bottom-btn i {
    font-size: 1.3rem;
    transition: transform 0.3s ease;
}

.scroll-bottom-btn:hover i {
    transform: translateY(2px);
}




@media (max-width: 768px) {
    
    .chat-container.keyboard-open {
        height: calc(100vh - env(keyboard-inset-height, 0px)) !important;
        height: calc(100dvh - env(keyboard-inset-height, 0px)) !important;
        max-height: calc(100vh - env(keyboard-inset-height, 0px)) !important;
        max-height: calc(100dvh - env(keyboard-inset-height, 0px)) !important;
        overflow: hidden;
    }
    
    body {
        
        height: -webkit-fill-available;
        
        overscroll-behavior: none;
        -webkit-overflow-scrolling: touch;
        
        touch-action: pan-y;
    }

    .chat-container {
        
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
        
        transition: height 0.2s ease-out, max-height 0.2s ease-out;
        
        position: relative;
    }

    
    .chat-container.keyboard-open .chat-messages {
        padding-bottom: 1rem;
        
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    
    .chat-container.keyboard-open .chat-input {
        position: sticky !important;
        bottom: 0 !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(10px);
        z-index: 1000 !important;
        
        box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
    }

    
    @supports (-webkit-appearance: none) {
        .chat-container.keyboard-open {
            
            height: 100vh !important;
            height: 100dvh !important;
        }
    }

    .chat-header {
        padding: 0.8rem 1rem;
        background: rgba(255, 255, 255, 0.98);
    }

    .header-left {
        gap: 1rem;
    }

    .back-btn {
        width: 36px;
        height: 36px;
    }

    .user-info h2 {
        font-size: 1rem;
    }

    .user-info .status {
        font-size: 0.8rem;
    }

    .product-preview {
        padding: 0.4rem 0.8rem;
        border-radius: 16px;
    }

    .product-image {
        width: 36px;
        height: 36px;
    }

    .product-details h3 {
        font-size: 0.85rem;
    }

    .product-details .price {
        font-size: 0.75rem;
    }

    .view-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .message-group {
        max-width: 85%;
    }

    .message {
        font-size: 0.95rem;
        padding: 0.7rem 1rem;
    }

    .chat-input {
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }

    .input-wrapper {
        padding: 0.8rem;
        border-radius: 20px;
    }

    .emoji-btn,
    .attach-btn,
    .send-btn {
        width: 36px;
        height: 36px;
    }

    .chat-messages {
        padding: 1rem;
    }

    .scroll-bottom-btn {
        bottom: calc(100px + env(safe-area-inset-bottom, 0px));
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 0.6rem 0.8rem;
    }

    .header-left {
        gap: 0.8rem;
    }

    .back-btn {
        width: 32px;
        height: 32px;
    }

    .user-info h2 {
        font-size: 0.9rem;
    }

    .user-info .status {
        font-size: 0.75rem;
    }

    .product-preview {
        padding: 0.3rem 0.6rem;
        border-radius: 14px;
    }

    .product-image {
        width: 32px;
        height: 32px;
    }

    .product-details h3 {
        font-size: 0.8rem;
    }

    .product-details .price {
        font-size: 0.7rem;
    }

    .view-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }

    .message-group {
        max-width: 88%;
    }

    .message {
        font-size: 0.9rem;
        padding: 0.6rem 0.8rem;
        border-radius: 14px;
    }

    .message-time {
        font-size: 0.7rem;
    }

    .chat-input {
        padding: 0.8rem;
        padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
    }

    .input-wrapper {
        padding: 0.6rem;
        border-radius: 18px;
    }

    .emoji-btn,
    .attach-btn,
    .send-btn {
        width: 32px;
        height: 32px;
    }

    .chat-messages {
        padding: 0.8rem;
    }

    .scroll-bottom-btn {
        bottom: calc(90px + env(safe-area-inset-bottom, 0px));
        width: 40px;
        height: 40px;
    }

    .header-actions-menu {
        min-width: 160px;
        right: -10px;
    }
}


@media (max-width: 768px) and (orientation: landscape) {
    .chat-header {
        padding: 0.5rem 1rem;
    }
    
    .chat-input {
        padding: 0.6rem 1rem;
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
    }
    
    .input-wrapper {
        padding: 0.5rem 0.8rem;
    }
}


@media (max-width: 360px) {
    .chat-header {
        padding: 0.5rem 0.6rem;
    }

    .header-left {
        gap: 0.6rem;
    }

    .back-btn {
        width: 28px;
        height: 28px;
    }

    .user-info h2 {
        font-size: 0.85rem;
    }

    .user-info .status {
        font-size: 0.7rem;
    }

    .product-preview {
        padding: 0.2rem 0.4rem;
    }

    .product-image {
        width: 28px;
        height: 28px;
    }

    .product-details h3 {
        font-size: 0.75rem;
    }

    .product-details .price {
        font-size: 0.65rem;
    }

    .view-btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }

    .message-group {
        max-width: 90%;
    }

    .message {
        font-size: 0.85rem;
        padding: 0.5rem 0.7rem;
        border-radius: 12px;
    }

    .message-time {
        font-size: 0.65rem;
    }

    .chat-input {
        padding: 0.6rem;
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
    }

    .input-wrapper {
        padding: 0.5rem;
        border-radius: 16px;
    }

    .emoji-btn,
    .attach-btn,
    .send-btn {
        width: 28px;
        height: 28px;
    }

    .chat-messages {
        padding: 0.6rem;
    }

    .scroll-bottom-btn {
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        width: 36px;
        height: 36px;
    }
}