/* Chat page styles — extracted from chat.html */
:root {
    --primary: #00cc99;
    --primary-light: #00ffcc;
    --bg-dark: #121212;
    --bg-card: #1e1e1e;
    --bg-secondary: #2c2c2c;
    --text-light: #fff;
    --text-muted: #9ca3af;
    --muted: #aaa;
    --accent: #00cc99;
    --border: rgba(255,255,255,0.08);
    --gradient-primary: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    --chat-header-offset: calc(72px + env(safe-area-inset-top, 0px));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body.chat-page {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Visibility utilities – use these instead of inline display to avoid inconsistent state */
.chat-page .is-hidden { display: none !important; }
.chat-page .chat-messages.is-visible { display: block !important; }
.chat-page .chat-messages.is-hidden { display: none !important; }
.chat-page .chat-welcome.is-visible { display: flex !important; }
.chat-page .chat-welcome.is-hidden { display: none !important; }
.chat-page .message-input-container.is-visible { display: block !important; }
.chat-page .message-input-container.is-hidden { display: none !important; }
.chat-page .chat-list.is-hidden { display: none !important; }
.chat-page .chat-list.is-visible { display: block !important; }

/* Header owns the top safe area so Android does not inherit extra blank space. */
.chat-header {
    background: var(--bg-card);
    padding: calc(1rem + env(safe-area-inset-top, 0px)) 1rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 100;
    flex: 0 0 auto;
}

.back-button {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.back-button:hover {
    background: var(--bg-secondary);
}

.header-title-wrap {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}

.header-title {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.role-chip {
    flex-shrink: 0;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--primary, #00cc99);
    background: var(--primary, #00cc99);
    color: #0b0f14;
    line-height: 1.2;
}
.role-chip.is-selling {
    background: var(--primary, #00cc99);
    color: #0b0f14;
    border-color: var(--primary, #00cc99);
}
.role-chip.is-agent {
    border-color: rgba(96, 165, 250, 0.5);
    background: rgba(96, 165, 250, 0.15);
    color: #93c5fd;
}

.header-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.header-go-shop {
    display: none;
    align-items: center;
    gap: 0.4rem;
    background: var(--primary);
    color: var(--bg-dark);
    text-decoration: none;
    font-weight: 700;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
}
.header-go-shop i { font-size: 0.95rem; }
.header-go-shop:hover { filter: brightness(0.95); }

.header-cart {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-secondary);
    color: var(--text-light);
    text-decoration: none;
    font-weight: 700;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}
.header-cart i { font-size: 0.95rem; }
.header-cart:hover {
    background: var(--primary);
    color: var(--bg-dark);
    border-color: var(--primary);
}

.header-btn {
    background: var(--bg-secondary);
    border: none;
    color: var(--text-light);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
}

.header-btn:hover {
    background: var(--primary);
    color: var(--bg-dark);
}

/* Main Container – mobile-first: single column; desktop: two panels */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: var(--bg-dark);
}
@media (min-width: 769px) {
    .chat-container { flex-direction: row; }
}

/* Sidebar – mobile: full width overlay; desktop: fixed width column */
.chat-sidebar {
    width: 100%;
    max-width: 100%;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    position: relative;
    z-index: 10;
}
@media (min-width: 769px) {
    .chat-sidebar {
        width: 350px;
        max-width: 350px;
        border-right: 1px solid var(--bg-secondary);
    }
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--bg-secondary);
}

.sidebar-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}
.sidebar-title-row .sidebar-title {
    margin-bottom: 0;
    flex: 1;
    min-width: 0;
}
.sidebar-subtitle {
    margin: 0 0 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.35;
}
.chat-list-empty {
    padding: 1.5rem 1rem 2rem;
    text-align: center;
    color: var(--text-muted);
}
.chat-list-empty strong {
    display: block;
    color: var(--text-light);
    font-size: 0.95rem;
    margin-bottom: 0.35rem;
}
.chat-list-empty span {
    font-size: 0.82rem;
    line-height: 1.45;
}

.sidebar-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-title::before {
    content: '';
    width: 4px;
    height: 1em;
    background: var(--gradient-primary);
    border-radius: 2px;
}

.chat-search {
    position: relative;
    margin-bottom: 1rem;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    background: var(--bg-secondary);
    border: none;
    border-radius: 25px;
    color: var(--text-light);
    font-size: 0.9rem;
}

.search-input::placeholder {
    color: var(--muted);
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

.new-chat-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    color: var(--bg-dark);
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.new-chat-btn:hover {
    background: #00b894;
    transform: translateY(-1px);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    padding-bottom: 1rem; /* Extra space at bottom */
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 0.5rem;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
}

.chat-item:hover {
    background: var(--bg-secondary);
}

.chat-item.active {
    background: var(--primary);
    color: var(--bg-dark);
}

.chat-avatar {
    width: 45px;
    height: 45px;
    min-width: 45px;
    min-height: 45px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
    margin-right: 1rem;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-preview {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item.active .chat-preview {
    color: rgba(0, 0, 0, 0.7);
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--muted);
}

.chat-item.active .chat-time {
    color: rgba(0, 0, 0, 0.7);
}

.unread-badge {
    background: var(--primary);
    color: var(--bg-dark);
    font-size: 0.7rem;
    font-weight: bold;
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.chat-item.active .unread-badge {
    background: var(--bg-dark);
    color: var(--primary);
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    position: relative; /* Allow absolute positioning of input container */
}

.chat-welcome {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.welcome-content i {
    font-size: 4rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

.welcome-content h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-light);
}

.welcome-content p {
    color: var(--muted);
    font-size: 1rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    /* Reserve space: on mobile Make Offer is in makeOfferBarMobile (see .make-offer-bar-mobile); input bar + keyboard */
    padding-bottom: calc(80px + var(--chat-keyboard-height, 0px));
    display: none;
}
@media (min-width: 769px) {
    .chat-messages { padding-bottom: calc(180px + var(--chat-keyboard-height, 0px)); }
}
/* Mobile: Make Offer bar in flow above fixed input so fixed bar is input-only → better keyboard behavior */
.make-offer-bar-mobile {
    flex-shrink: 0;
    padding: 8px 1rem 12px;
    background: var(--bg-card);
    border-top: 1px solid var(--bg-secondary);
}
.make-offer-bar-mobile.keyboard-open { display: none !important; }
@media (max-width: 768px) {
    .chat-main { padding-bottom: 72px; }
}
@media (min-width: 769px) {
    .make-offer-bar-mobile { display: none !important; }
}

.message {
    display: flex;
    margin-bottom: 1rem;
    animation: fadeInUp 0.3s ease;
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    min-width: 3rem;
    min-height: 2rem;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}
/* Prevent empty or partial content from rendering as stray circles/ovals */
.message .message-sender + .message-content:empty,
.message .message-content:empty { min-height: 2.5rem; }
.message .message-content:empty::before { content: '\00a0'; display: block; }

.message.sent .message-content {
    background: var(--primary);
    color: var(--bg-dark);
    border-bottom-right-radius: 4px;
}

.message.received .message-content {
    background: var(--bg-secondary);
    color: var(--text-light);
    border-bottom-left-radius: 4px;
}
.chat-page .message.received .message-content {
    background: var(--bg-secondary) !important;
    color: var(--text-light) !important;
}

/* Product chip inside system messages */
.product-chip {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 10px;
    align-items: center;
    background: rgba(0,0,0,0.3); /* Darker background for better contrast */
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 10px;
    padding: 8px;
    text-decoration: none;
    color: inherit;
    margin-bottom: 6px;
}

/* Ensure product chip text is always readable */
.product-chip,
.product-chip * {
    color: rgba(255, 255, 255, 0.95) !important; /* Force high contrast white */
}
.product-chip-img {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    background: #111;
}
.product-chip-body {
    min-width: 0; /* Allow grid cell to shrink so long text can wrap */
}
.product-chip-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-light);
    line-height: 1.2;
    word-break: break-all;
    overflow-wrap: break-word;
}
.product-chip-vendor {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.95) !important; /* High contrast white for better readability */
    margin-top: 2px;
    font-weight: 500;
}
.product-chip-price {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 1) !important; /* Maximum contrast white for better readability */
    font-weight: 700;
    font-weight: 800;
    margin-top: 2px;
}

.message-time {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 0.25rem;
    text-align: right;
}

.message.received .message-time {
    text-align: left;
    color: rgba(255,255,255,0.75);
}

/* Improve contrast of timestamps on sent (green) bubbles */
.message.sent .message-time {
    color: rgba(0,0,0,0.65);
}

/* Message text wrapper – keeps content styled consistently (avoids "plain" look when DOM updates) */
.message-content .message-text {
    display: block;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.45;
    color: inherit;
    font-size: inherit;
}
.message.sent .message-content .message-text { color: var(--bg-dark); }
.message.received .message-content .message-text { color: var(--text-light); }

/* Offer chip and actions – class-based so layout stays consistent after offers */
.offer-chip {
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
}
.offer-chip-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.offer-chip-header .offer-chip-icon { color: var(--primary); font-size: 1.2rem; }
.offer-chip-title { font-weight: 600; color: var(--text-light); }
.offer-chip-subtitle { font-size: 0.85rem; color: var(--muted); }
.offer-chip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}
.offer-chip-label { font-size: 0.75rem; color: var(--muted); }
.offer-chip-price-struck { text-decoration: line-through; color: var(--muted); }
.offer-chip-price-highlight { font-size: 1.2rem; font-weight: 700; color: var(--primary); text-align: right; }
.offer-actions {
    margin-top: 10px;
    display: flex;
    gap: 10px;
}
.offer-actions .btn { flex: 1; padding: 8px 16px; font-size: 0.9rem; }

/* Date dividers between message days */
.date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    font-size: 0.8rem;
    margin: 12px 0;
    user-select: none;
}
.date-divider::before,
.date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--bg-secondary);
}
.date-divider span {
    padding: 2px 10px;
    background: var(--bg-card);
    border: 1px solid var(--bg-secondary);
    border-radius: 999px;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    color: var(--muted);
    font-style: italic;
    font-size: 0.9rem;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Message Input – safe area bottom for Capacitor home indicator; move up when keyboard open */
.message-input-container {
    position: fixed;
    bottom: var(--chat-keyboard-height, 0px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    padding: 0.75rem 1rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--bg-secondary);
    display: none;
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    transition: bottom 0.18s ease-out;
}
/* Home indicator is covered by the keyboard — don't stack safe-area on top of it */
html.chat-keyboard-open .message-input-container {
    padding-bottom: 0.75rem;
}
@media (min-width: 769px) {
    .message-input-container {
        left: 350px;
    }
}

.message-input {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 25px;
    padding: 0.5rem 1rem;
}

.btn-attach {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.btn-attach:hover {
    background: var(--bg-dark);
    color: var(--primary);
}

.btn-mic {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
    margin-left: 4px;
}

.btn-mic:hover {
    background: var(--bg-dark);
    color: var(--primary);
}

.btn-mic.recording {
    color: #e53935;
    background: var(--bg-dark);
}

		/* Recording timer pill */
		.record-timer {
			margin-left: 6px;
			align-self: center;
			font-size: 0.8rem;
			color: #e1e1e1;
			background: rgba(229,57,53,0.12);
			border: 1px solid rgba(229,57,53,0.35);
			border-radius: 999px;
			padding: 2px 8px;
			user-select: none;
		}

		/* Hide send button while recording so users don't click it; they must stop first */
		.btn-send.hidden-while-recording {
			display: none !important;
		}
		.record-hint {
			font-size: 0.75rem;
			color: var(--muted);
			align-self: center;
			margin-left: 6px;
			user-select: none;
		}

.message-textarea {
    flex: 1;
}

.message-textarea textarea {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 0.9rem;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 20px;
    line-height: 1.5;
    padding: 0.5rem 0;
    transition: height 0.2s ease;
}

/* Better focus state for input */
.message-textarea textarea:focus {
    outline: none;
}

/* Draft indicator */
.message-input-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.message-input-container.has-draft::before {
    opacity: 0.5;
}

.message-textarea textarea::placeholder {
    color: var(--muted);
}

.btn-send {
    background: var(--primary);
    border: none;
    color: var(--bg-dark);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send:hover {
    background: #00b894;
    transform: scale(1.05);
}

.btn-send:disabled {
    background: var(--muted);
    cursor: not-allowed;
    transform: none;
}

/* Loading States */
.btn-send.loading {
    background: var(--primary);
    cursor: not-allowed;
    position: relative;
}

.btn-send.loading i {
    display: none;
}

.btn-send.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid var(--bg-dark);
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.btn-attach.loading {
    color: var(--primary);
    cursor: not-allowed;
    position: relative;
}

.btn-attach.loading i {
    display: none;
}

.btn-attach.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid var(--primary);
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.message-input.loading {
    opacity: 0.7;
    pointer-events: none;
}

.upload-progress {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    min-width: 300px;
    text-align: center;
}

.upload-progress h3 {
    color: var(--primary);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.upload-progress p {
    color: var(--muted);
    margin-bottom: 1rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-light);
    font-size: 0.9rem;
}

.upload-status i {
    color: var(--primary);
}

.upload-status.success i {
    color: #00cc99;
}

.upload-status.error i {
    color: #ff6b6b;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Message sending indicator */
.message-sending {
    opacity: 0.7;
    position: relative;
}

.message-sending::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border: 2px solid var(--bg-dark);
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Mobile-first: touch targets and single-panel behavior (max-width 768px) */
@media (max-width: 768px) {
    :root {
        --chat-header-offset: calc(68px + env(safe-area-inset-top, 0px));
    }
    .header-cart span,
    .header-go-shop span {
        display: none;
    }
    .header-cart,
    .header-go-shop {
        padding: 0.5rem 0.75rem;
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
    }
    .back-button {
        min-width: 44px;
        min-height: 44px;
    }
    .chat-sidebar {
        position: fixed;
        top: var(--chat-header-offset);
        left: 0;
        width: 100%;
        height: calc(100dvh - var(--chat-header-offset));
        height: calc(100vh - var(--chat-header-offset));
        z-index: 200;
        transform: translateX(-100%);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .chat-sidebar.mobile-open {
        transform: translateX(0);
    }
    .chat-main {
        width: 100%;
        flex: 1;
        min-height: 0;
    }
    .message-content {
        max-width: 85%;
    }
    .chat-header {
        padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 0.75rem 0.75rem;
    }
    .header-title {
        font-size: 1rem;
    }
    /* Single-panel: list OR chat visible */
    .chat-container.mobile-show-list .chat-main { display: none !important; }
    .chat-container.mobile-show-list .chat-sidebar { transform: translateX(0); }
    .chat-container.mobile-show-chat .chat-main { display: flex !important; }
    .chat-container.mobile-show-chat .chat-sidebar { transform: translateX(-100%); }
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Scrollbar Styling - Enhanced */
.chat-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

.chat-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.chat-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Smooth scrolling enhancement */
.chat-messages {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* Better iOS scrolling */
}

/* Message status indicators */
.message-status {
    display: inline-flex;
    align-items: center;
    margin-left: 0.25rem;
    font-size: 0.7rem;
    opacity: 0.7;
}

.message-status.sent {
    color: var(--muted);
}

.message-status.delivered {
    color: var(--primary);
}

.message-status.read {
    color: var(--primary);
}

/* Better loading state for messages */
.message-sending {
    opacity: 0.6;
    position: relative;
}

.message-sending::after {
    content: '⏳';
    position: absolute;
    right: -20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Skeleton loading styles */
.skeleton-chat-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    background: var(--bg-card);
}
.skeleton-chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--bg-secondary);
    flex-shrink: 0;
    margin-right: 1rem;
    position: relative;
    overflow: hidden;
}
.skeleton-chat-avatar::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0) 100%);
    animation: skeleton-shimmer 1.2s infinite;
}
.skeleton-chat-info {
    flex: 1;
}
.skeleton-chat-name {
    height: 16px;
    width: 60%;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
}
.skeleton-chat-name::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0) 100%);
    animation: skeleton-shimmer 1.2s infinite;
}
.skeleton-chat-preview {
    height: 12px;
    width: 80%;
    background: var(--bg-secondary);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}
.skeleton-chat-preview::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0) 100%);
    animation: skeleton-shimmer 1.2s infinite;
}
.skeleton-chat-time {
    width: 40px;
    height: 12px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-left: auto;
    position: relative;
    overflow: hidden;
}
.skeleton-chat-time::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0) 100%);
    animation: skeleton-shimmer 1.2s infinite;
}
.skeleton-message {
    display: flex;
    margin-bottom: 1rem;
    padding: 0 1rem;
}
.skeleton-message.sent {
    justify-content: flex-end;
}
.skeleton-message.received {
    justify-content: flex-start;
}
.skeleton-message-content {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    background: var(--bg-secondary);
    position: relative;
    overflow: hidden;
}
.skeleton-message.sent .skeleton-message-content {
    background: var(--primary);
    opacity: 0.3;
}
.skeleton-message-content::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0) 100%);
    animation: skeleton-shimmer 1.2s infinite;
}
.skeleton-message-line {
    height: 12px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    margin-bottom: 6px;
}
.skeleton-message-line:last-child {
    margin-bottom: 0;
    width: 60%;
}
@keyframes skeleton-shimmer {
    100% { transform: translateX(100%); }
}

/* Align with buyer chrome: icon header, readable list, 44px composer */
.chat-page .header-cart span,
.chat-page .header-go-shop span { display: none; }
.chat-page .header-cart,
.chat-page .header-go-shop {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text-light);
}
.chat-page .header-cart:hover,
.chat-page .header-go-shop:hover {
    background: rgba(255,255,255,0.06);
    color: var(--primary);
    border-color: transparent;
}
.chat-page .chat-item.active {
    background: rgba(0, 204, 153, 0.14);
    color: var(--text-light);
    box-shadow: inset 3px 0 0 var(--primary);
}
.chat-page .chat-item.active .chat-preview,
.chat-page .chat-item.active .chat-time {
    color: var(--muted);
}
.chat-page .chat-item.active .unread-badge {
    background: var(--primary);
    color: #00110b;
}
.chat-page .search-input {
    border: 1px solid var(--border);
    min-height: 44px;
}
.chat-page .new-chat-btn {
    min-height: 44px;
    border-radius: 12px;
}
.chat-page .sidebar-title::before {
    background: var(--primary);
}
.chat-page .btn-attach,
.chat-page .btn-mic,
.chat-page .btn-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
}
.chat-page .message-input {
    align-items: center;
    border-radius: 16px;
    padding: 4px 8px;
}

/* Secondary chat styles (modals, voice, support) */
.new-chat-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 0;
    max-width: 500px;
    width: 90%;
    position: relative;
    z-index: 1001;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--bg-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: var(--primary);
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.close-btn:hover {
    background: var(--bg-secondary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body p {
    color: var(--muted);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-outline {
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--bg-secondary);
}

.btn-outline:hover {
    background: var(--bg-secondary);
}

.btn-primary {
    background: var(--primary);
    color: var(--bg-dark);
}

.btn-primary:hover {
    background: #00b894;
}

/* File Attachment Styles */
.message-attachments {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.attachment-image {
    position: relative;
    max-width: 200px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.attachment-preview {
    width: 100%;
    height: 150px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.attachment-preview:hover {
    transform: scale(1.05);
}

.attachment-info {
    padding: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
}

.attachment-name {
    font-size: 0.8rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.attachment-download {
    color: var(--primary);
    text-decoration: none;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.attachment-download:hover {
    background: var(--bg-dark);
}

.attachment {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-light);
    transition: background 0.2s ease;
    max-width: 250px;
}

.attachment:hover {
    background: var(--bg-dark);
}

.attachment i {
    font-size: 1.2rem;
    color: var(--primary);
}

/* Voice Message Player Styles */
.voice-message-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    min-width: 200px;
    max-width: 280px;
    position: relative;
    user-select: none;
}

.message.sent .voice-message-player {
    background: rgba(0, 0, 0, 0.15);
}

.message.received .voice-message-player {
    background: rgba(255, 255, 255, 0.08);
}

.voice-play-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.message.sent .voice-play-btn {
    background: rgba(0, 0, 0, 0.3);
    color: var(--bg-dark);
}

.voice-play-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.message.sent .voice-play-btn:hover {
    background: rgba(0, 0, 0, 0.4);
}


.voice-waveform {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
}

.waveform-bars {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 24px;
    overflow: hidden;
}

.waveform-bar {
    flex: 1;
    min-width: 2px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 1px;
    transition: height 0.1s ease, background 0.2s ease;
    animation: waveform-idle 1.5s ease-in-out infinite;
}

.message.sent .waveform-bar {
    background: rgba(0, 0, 0, 0.4);
}

.waveform-bar:nth-child(odd) {
    animation-delay: 0.1s;
}

.waveform-bar:nth-child(even) {
    animation-delay: 0.2s;
}

.voice-message-player.playing .waveform-bar {
    animation: waveform-playing 0.8s ease-in-out infinite;
    background: rgba(255, 255, 255, 0.7);
}

.message.sent .voice-message-player.playing .waveform-bar {
    background: rgba(0, 0, 0, 0.6);
}

@keyframes waveform-idle {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(0.8); }
}

@keyframes waveform-playing {
    0%, 100% { transform: scaleY(0.3); }
    50% { transform: scaleY(1); }
}

.voice-progress-bar {
    width: 100%;
    height: 2px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 1px;
    overflow: hidden;
    position: relative;
}

.message.sent .voice-progress-bar {
    background: rgba(0, 0, 0, 0.2);
}

.voice-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 1px;
    transition: width 0.1s linear;
}

.message.sent .voice-progress-fill {
    background: var(--bg-dark);
}

.voice-duration {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
    white-space: nowrap;
}

.message.sent .voice-duration {
    color: rgba(0, 0, 0, 0.7);
}

.voice-current-time {
    min-width: 35px;
}

.voice-total-time {
    color: rgba(255, 255, 255, 0.5);
}

.message.sent .voice-total-time {
    color: rgba(0, 0, 0, 0.5);
}

.voice-download {
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    padding: 0.4rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.sent .voice-download {
    color: rgba(0, 0, 0, 0.6);
}

.voice-download:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--primary);
}

.message.sent .voice-download:hover {
    background: rgba(0, 0, 0, 0.2);
    color: rgba(0, 0, 0, 0.8);
}

/* Uploading state for voice messages */
.voice-message-player.uploading {
    opacity: 0.8;
    pointer-events: none;
}

.voice-upload-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--primary);
    font-size: 1rem;
}

.message.sent .voice-upload-spinner {
    background: rgba(0, 0, 0, 0.3);
    color: var(--bg-dark);
}

.upload-status-text {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

.message.sent .upload-status-text {
    color: rgba(0, 0, 0, 0.7);
}

.voice-message-player.uploading .waveform-bar {
    animation: waveform-uploading 1.2s ease-in-out infinite;
    opacity: 0.6;
}

@keyframes waveform-uploading {
    0%, 100% { transform: scaleY(0.3); opacity: 0.4; }
    50% { transform: scaleY(0.7); opacity: 0.7; }
}

.attachment-size {
    font-size: 0.7rem;
    color: var(--muted);
    margin-left: auto;
}

/* Support Message Styles */
.message.support {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-left: 4px solid #00cc99;
}

.message.support .message-content {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.message-sender {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.sender-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    color: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.8rem;
}

.sender-info {
    flex: 1;
}

.sender-name {
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.9rem;
}

.sender-role {
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 500;
}

/* Support message special styling */
.message.support .message-content {
    border: 1px solid rgba(0, 204, 153, 0.3);
}

.message.support .message-time {
    color: rgba(255, 255, 255, 0.8);
}

/* Support Chat List Item Styles */
.chat-item.support-chat {
    border-left: 3px solid var(--primary);
    background: linear-gradient(90deg, rgba(0, 204, 153, 0.1) 0%, transparent 100%);
}

.chat-item.support-chat .chat-avatar {
    background: var(--primary);
    color: var(--bg-dark);
    position: relative;
}

.chat-item.support-chat .chat-avatar::after {
    content: '🎧';
    position: absolute;
    bottom: -2px;
    right: -2px;
    font-size: 0.6rem;
    background: var(--bg-dark);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-item.support-chat .chat-name {
    color: var(--primary);
    font-weight: 600;
}

.chat-item.support-chat .chat-preview {
    color: var(--text-light);
}
