.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.empty-icon {
    font-size: 48px;
    color: #ddd;
    margin-bottom: 20px;
}

.empty-state h3 {
    margin: 0 0 10px 0;
    color: #333;
}

.threads-list {
    border-radius: 1rem;
    overflow: hidden;
    background: white;
}

.thread-item {
    border-bottom: 1px solid #e1e8ed;
    transition: background-color 0.2s;
}

.thread-item:last-child {
    border-bottom: none;
}

.thread-item:hover {
    background-color: #f8f9fa;
}

.thread-link {
    display: block;
    padding: 16px;
    text-decoration: none;
    color: inherit;
}

.thread-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.thread-avatar {
    position: relative;
    flex-shrink: 0;
}

.thread-avatar img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.thread-content {
    flex: 1;
    min-width: 0;
}

.thread-title {
    font-weight: 600;
    color: #333;
}

.user-name {
    color: #333;
}

.product-name {
    color: #666;
    font-weight: normal;
}

.thread-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.order-badge {
    background: #e3f2fd;
    color: #1976d2;
}

.seller-badge {
    background: #fff3e0;
    color: #f57c00;
}

.buyer-badge {
    background: #e8f5e8;
    color: #388e3c;
}

.unread-count {
    background: #ff4757;
    color: white;
}

.chat-thread-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    max-height: 600px;
    border: 1px solid #e1e8ed;
    border-radius: 1rem;
    overflow: hidden;
}

.chat-header {
    background: white;
    border-bottom: 1px solid #e1e8ed;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-button {
    flex-shrink: 0;
}

.btn-back {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f5f5f5;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    text-decoration: none;
    transition: background-color 0.2s;
}

.btn-back:hover {
    background: #e9e9e9;
    color: #333;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.user-avatar {
    position: relative;
}

.user-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.user-details h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.user-status {
    margin: 0;
    font-size: 12px;
    color: #666;
}

.chat-context {
    display: flex;
    gap: 16px;
    flex-shrink: 0;
}

.context-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #666;
    background: #f8f9fa;
    padding: 4px 8px;
    border-radius: 4px;
}

.context-item a {
    color: #3f8cff;
    text-decoration: none;
}

.context-item a:hover {
    text-decoration: underline;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    background: #f8f9fa;
}

.messages-container {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    max-width: 70%;
}

.message.sent {
    align-self: flex-end;
}

.message.received {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    max-width: 80%;
}

.message-content {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
}

.message.sent .message-content {
    flex-direction: row-reverse;
}

.sender-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.message-bubble {
    background: white;
    border-radius: 18px;
    padding: 12px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    position: relative;
    word-wrap: break-word;
}

.message.sent .message-bubble {
    background: #3f8cff;
    color: white;
}

.message.system .message-bubble {
    background: #f0f0f0;
    color: #666;
    font-style: italic;
    text-align: center;
}

.message-text {
    line-height: 1.4;
    margin: 0;
}

.message-image img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

.message.sent .message-file {
    background: rgba(255, 255, 255, 0.2);
}

.message-file a {
    color: inherit;
    text-decoration: none;
    font-weight: 500;
}

.message-file a:hover {
    text-decoration: underline;
}

.file-size {
    font-size: 11px;
    opacity: 0.7;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.message.sent .message-time {
    color: rgba(255, 255, 255, 0.8);
}

.message.received .message-time {
    color: #666;
    text-align: left;
}

.chat-input-area {
    background: white;
    border-top: 1px solid #e1e8ed;
    padding: 16px;
}

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 12px;
    border: 1px solid #e1e8ed;
    border-radius: 20px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
    overflow: hidden;
}

#message-input:focus {
    border-color: #3f8cff;
}

.input-actions {
    display: flex;
    gap: 4px;
}

.btn-attachment,
.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.btn-attachment {
    background: #f5f5f5;
    color: #666;
}

.btn-attachment:hover {
    background: #e9e9e9;
    color: #333;
}

.btn-send {
    background: #3f8cff;
    color: white;
}

.btn-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-send:not(:disabled):hover {
    background: #2980b9;
}

.character-count {
    font-size: 11px;
    color: #666;
    text-align: right;
}

/* Chat Buttons */
.chat-with-seller,
.chat-with-seller.seller-page {
    margin: 16px 0;
}

.btn-chat-seller,
.btn-contact-seller, .btn-login-to-chat {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 20px;
    background: #f0f0f078;
    color: #949494;
    width: 100%;
    font-size: 0.8rem;
    text-align: center;
    margin-top: 10px;
    border-radius: 0.5em;
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
    justify-content: center;
}

.btn-chat-seller:hover,
.btn-contact-seller:hover, .btn-login-to-chat:hover {
    background: #d6d6d678;
    color: #838383;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    margin-left: 4px;
}

/* Modals */
.chat-start-modal,
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
    z-index: 1000;
}

.chat-start-modal .modal-content {
    width: 100%;
    max-width: 500px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 16px;
    border-bottom: 1px solid #e1e8ed;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background: #f5f5f5;
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #333;
}

#start-message {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    border: 1px solid #e1e8ed;
    border-radius: 6px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
}

#start-message:focus {
    outline: none;
    border-color: #3f8cff;
}

.char-count {
    text-align: right;
    font-size: 12px;
    color: #666;
    margin-top: 4px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

.btn-cancel,
.btn-send-chat {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel {
    background: #f5f5f5;
    color: #666;
    border: 1px solid #e1e8ed;
}

.btn-cancel:hover {
    background: #e9e9e9;
    color: #333;
}

.btn-send-chat {
    background: #3f8cff;
    color: white;
    border: none;
}

.btn-send-chat:hover {
    background: #2980b9;
}

.btn-send-chat:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Image Modal */
.image-modal .modal-content {
    background: transparent;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-modal .modal-close {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    margin-bottom: 10px;
    align-self: flex-end;
}

.image-modal img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 8px;
}

/* Upload Progress */
.upload-progress {
    background: #f8f9fa;
    border: 1px solid #e1e8ed;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
}

.upload-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 14px;
    color: #333;
}

.progress-bar {
    height: 4px;
    background: #e1e8ed;
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #3f8cff;
    width: 100%;
    animation: progress-indeterminate 1.5s infinite linear;
}

.unread-badge {
    background: #4285f4;
    color: white;
    padding: 3px 9px;
    border-radius: 20px;
    min-width: 24px;
    text-align: center;
    margin-left: 0.25rem;
}

.thread-item {
    display: block;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f1f3f4;
    transition: background-color 0.2s ease;
}

.thread-item:hover {
    background-color: #f8f9fa;
}

.thread-item.unread {
    background-color: #f8f9ff;
}

.thread-item:last-child {
    border-bottom: none;
}

.thread-link {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    text-decoration: none;
    color: inherit;
}

.thread-avatar {
    position: relative;
    margin-right: 16px;
    flex-shrink: 0;
}

.thread-avatar img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #f1f3f4;
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #34a853;
    border: 2px solid white;
    border-radius: 50%;
}

.thread-content {
    flex: 1;
    min-width: 0;
}

.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.thread-title {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    color: #1a1a1a;
    font-size: 16px;
}

.product-name {
    color: #5f6368;
    font-size: 14px;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #5f6368;
    flex-shrink: 0;
}

.thread-meta .message-time{
    margin-top: 0px;
}

.last-seen {
    color: #34a853;
    font-weight: 500;
}

.message-time {
    color: #80868b;
}

.last-message {
    font-size: 14px;
    color: #5f6368;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-prefix {
    font-weight: 600;
    color: #80868b;
}

.thread-badges {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ch-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.buyer-badge {
    background: #e8f5e8;
    color: #137333;
}

.seller-badge {
    background: #fef7e0;
    color: #b06000;
}

.unread-count {
    background: #4285f4;
    color: white;
    min-width: 20px;
    text-align: center;
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: #80868b;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 16px;
    margin-bottom: 8px;
}

.empty-state-subtext {
    font-size: 14px;
    color: #9aa0a6;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Responsive Design */
@media (max-width: 768px) {
    
    .thread-link {
        padding: 12px;
    }
    
    .thread-avatar img {
        width: 40px;
        height: 40px;
    }
    
    .chat-thread-page {
        flex-direction: column;
        max-height: 100%;
        border: 1px solid #e1e8ed;
        overflow: hidden;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        border-radius: 0;
    }
    
    .chat-header {
        padding: 12px;
        width: 100%;
    }

    #chat-messages{
        width: 100%;
    }

    .chat-input-area{
        width: 100%;
    }
    
    .user-details h3 {
        font-size: 14px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .messages-container {
        padding: 12px;
    }
    
    .chat-input-area {
        padding: 12px;
    }
    
    .modal-content {
        margin: 10px;
        max-width: none;
    }
    
    .modal-body {
        padding: 16px;
    }
}