/* ===========================================
   chat-ui.css
   ===========================================
   Styles for in-app messaging components
   =========================================== */

/* =========================
   Chat Header (Pinned Load Summary)
   ========================= */
.chat-header {
    position: sticky;
    top: 0;
    z-index: 50; /* Changed from 100 */
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 14px 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chat-header-compact {
    background: #f8fafc;
    border-radius: 10px;
    padding: 12px;
    margin: 0;
    border: 1px solid #e2e8f0;
}

.chat-header-title {
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    color: #0b7d62; /* Always green to indicate it's tappable */
    cursor: pointer;
    user-select: none;
    padding: 10px 12px;
    margin: -10px -12px;
    border-radius: 8px;
    transition: background 0.15s ease;
    -webkit-tap-highlight-color: rgba(11, 125, 98, 0.1);
}

/* ✅ ADD THIS NEW RULE */
.chat-header-title:hover {
    color: #0b7d62;
}

.chat-header-title:active {
    background: rgba(11, 125, 98, 0.08);
}

.chat-load-route {
    font-size: 13px;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.chat-load-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: #64748b;
    margin-top: 6px;
}

.chat-load-price {
    font-weight: 700;
    color: #0b7d62;
}

.chat-load-id {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
}

/* =========================
   Messages Container - FIXED
   ========================= */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1; /* Take all remaining space after header */
    background: #fafafa;
    overflow: hidden;
    position: relative;
    min-height: 0; /* Important for flexbox scrolling */
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    padding-bottom: 16px; /* Normal padding */
    margin-bottom: 65px; /* THIS pushes content up from fixed input */
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.chat-input {
    flex: 1;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    font-size: 15px;
    color: #1e293b;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
    font-family: inherit;
    padding: 9px 16px;
    overflow-y: auto;
    
    /* Hide scrollbar completely */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.chat-input::-webkit-scrollbar {
    display: none; /* Chrome/Safari/Opera */
}

/* =========================
   Message Bubbles
   ========================= */
.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    position: relative;
    animation: messageAppear 0.2s ease-out;
    line-height: 1.4;
    word-wrap: break-word;
}

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

.message-sent {
    align-self: flex-end;
    background: linear-gradient(135deg, #0b7d62, #20a58a);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-received {
    align-self: flex-start;
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.message-timestamp {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.message-received .message-timestamp {
    color: #64748b;
}

.message-sent .message-timestamp {
    color: rgba(255, 255, 255, 0.9);
}

/* =========================
   Message Input - FIXED
   ========================= */
.chat-input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    z-index: 45;
    -webkit-transform: translate3d(0, 0, 0);
}

.chat-input-container > * {
    pointer-events: auto;
}

/* =========================
   Message Input - FIXED
   ========================= */
.chat-input-wrapper {
    flex: 1;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    min-height: 40px;
    max-height: 120px;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    border-radius: 20px;
    font-size: 15px;
    color: #1e293b;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
    font-family: inherit;
    padding: 9px 16px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: #94a3b8;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0b7d62, #20a58a);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(11, 125, 98, 0.3);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* =========================
   Conversation List (Inbox)
   ========================= */
.conversations-list {
    background: white;
}

.conversation-item {
    display: flex;
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.2s ease;
    align-items: flex-start;
    gap: 0; /* Changed from 12px to remove gap */
}

.conversation-item:hover {
    background: #f8fafc;
}

.conversation-avatar {
    display: none; /* Hide the avatar */
}

.conversation-content {
    flex: 1;
    min-width: 0;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.conversation-title {
    font-weight: 700;
    color: #1e293b;
    font-size: 15px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conversation-time {
    font-size: 12px;
    color: #94a3b8;
    flex-shrink: 0;
    margin-left: 8px;
}

.conversation-preview {
    font-size: 14px;
    color: #64748b;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.conversation-unread {
    background: #ef4444;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

/* =========================
   Empty States
   ========================= */
.empty-conversations {
    text-align: center;
    padding: 48px 20px;
    color: #64748b;
}

.empty-conversations-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-conversations h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #1e293b;
}

.empty-conversations p {
    font-size: 14px;
    line-height: 1.5;
    max-width: 300px;
    margin: 0 auto;
}

/* =========================
   AI Assistant Card (Afi) - Conversation Style
   ========================= */
.afi-conversation-item {
    display: flex;
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.2s ease;
    align-items: center;
    gap: 12px;
    background: white;
}

.afi-conversation-item:hover {
    background: rgba(11, 125, 98, 0.04);
}

.afi-conversation-item .afi-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0b7d62, #20a58a);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.afi-conversation-item .afi-avatar svg {
    stroke: white;
}

.afi-conversation-item .afi-content {
    flex: 1;
    min-width: 0;
}

.afi-conversation-item .afi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.afi-conversation-item .afi-name {
    font-weight: 700;
    color: #1e293b;
    font-size: 15px;
    line-height: 1.3;
}

.afi-conversation-item .afi-description {
    font-size: 14px;
    color: #64748b;
    line-height: 1.3;
}

.afi-conversation-item .afi-arrow {
    flex-shrink: 0;
    color: #cbd5e1;
    transition: transform 0.2s ease, color 0.2s ease;
}

.afi-conversation-item:hover .afi-arrow {
    transform: translateX(2px);
    color: #0b7d62;
}

/* =========================
   Account Tabs with Page Indicator
   ========================= */
/* Compact floating tabs - outside card container */
.account-tabs-indicator {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 2px 0; /* 🔥 tighter */
    background: transparent;
}

.indicator-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #cbd5e1;
    transition: background 0.3s ease;
}

.indicator-dot.active {
    background: #0b7d62;
    transform: scale(1.2);
}

.account-tabs-scroll {
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: 0 16px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0; /* 🔥 IMPORTANT: removes gap */
}

.account-tabs-scroll::-webkit-scrollbar {
    display: none;
}

.account-tab-btn-enhanced {
    padding: 10px 16px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
    white-space: nowrap;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.account-tab-btn-enhanced:hover {
    color: #0b7d62;
}

.account-tab-btn-enhanced.active {
    color: #0b7d62;
}

.account-tab-btn-enhanced.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: #0b7d62;
    border-radius: 2px 2px 0 0;
}

.tab-count-badge {
    background: #0b7d62;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 6px;
}

.tab-count-badge.unread {
    background: #ef4444;
}

/* Make account tabs behave like a fixed header */
.account-tabs-scroll {
    position: sticky;
    top: 0;
    z-index: 40; /* Changed from 20 - below chat-header, above content */
    background: white;
    border-bottom: 1px solid #e5e7eb;
}

/* =========================
   Chat Screen (Full Screen)
   ========================= */
.chat-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100dvh; /* Dynamic viewport height - adjusts for keyboard */
    background: white;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    animation: slideInUp 0.3s ease;
    overflow: hidden;
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.chat-screen-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: white;
    position: sticky;
    top: 0;
    z-index: 50; /* Ensure it stays on top within chat screen */
}

.chat-back-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #f1f5f9;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-back-btn:hover {
    background: #e2e8f0;
    transform: scale(1.05);
}

.chat-header-title {
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
}

/* =========================
   Responsive Adjustments
   ========================= */
@media (max-width: 640px) {
    .chat-header {
        padding: 12px;
    }
    
    .chat-messages {
        padding: 12px;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .conversation-item {
        padding: 12px;
    }
    
    .conversation-avatar {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
    
    .account-tabs-scroll {
        padding: 0 12px;
    }
    
    .account-tab-btn-enhanced {
        padding: 12px 14px;
        font-size: 14px;
    }
}

/* Force 2 tabs per viewport width */
.account-tab-btn-enhanced {
    flex: 0 0 50%;
    text-align: center;
}

/* Tighten spacing under Account header card */
#account .card {
    margin-bottom: 6px; /* was likely 16px+ */
}

/* Pull tabs closer to dots */
.account-tabs-scroll {
    margin-top: 0;
}

/* DEBUG: remove spacing coming from acctState content */
#acctState > *:last-child {
    margin-bottom: 0 !important;
}


/* Pull My Posts section closer to Account header */
#myPostsContainer {
    margin-top: -12px;
}

/* ===========================================
   FIXES FOR REQUIREMENTS 1, 3, 4
   =========================================== */

/* 1. FIX SPACING - Equal distance between cards and dots */
.account-tabs-indicator {
    padding: 1px 0 8px 0; /* 1px top, 8px bottom */
    margin: 0;
    background: transparent;
}

#account .card + .account-tabs-indicator {
    margin-top: 0; /* Remove negative margin */
}

.account-tabs-indicator + #myPostsContainer {
    margin-top: 0; /* Remove negative margin */
}

/* Proper spacing between Account header and dots */
#account > .card:first-child {
    margin-bottom: 12px; /* Space before dots */
}

/* 3. INCREASE TAB FONT SIZE - Match original */
.account-tab-btn-enhanced {
    padding: 12px 16px;
    background: none;
    border: none;
    font-size: 16px; /* Increased from 14px */
    font-weight: 600;
    color: #64748b;
    white-space: nowrap;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

/* 4. SUBTLE GREEN HIGHLIGHT - Active tab background */
.account-tab-btn-enhanced.active {
    color: #0b7d62;
    background: rgba(11, 125, 98, 0.08); /* Subtle mint green tint */
    border-radius: 8px 8px 0 0;
}

.account-tab-btn-enhanced.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px; /* Slightly thicker */
    background: #0b7d62;
    border-radius: 2px 2px 0 0;
}

/* Ensure tabs maintain proper width when visibility changes */
.account-tab-btn-enhanced {
    flex: 0 0 50%;
    text-align: center;
}

/* Smooth transitions when tabs show/hide */
.account-tabs-scroll {
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: 0 16px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0;
    transition: all 0.3s ease;
}

.msg-status {
    margin-left: 4px;
    font-size: 11px;
    opacity: 0.7;
}

.msg-failed {
    color: #ef4444;
    opacity: 1;
}

/* Status indicators for optimistic UI */
.msg-status {
    margin-left: 4px;
    font-size: 11px;
    opacity: 0.7;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.msg-failed {
    color: #ef4444;
    opacity: 1;
    font-weight: 600;
}

/* Date separators in chat */
.chat-date-separator {
    text-align: center;
    font-size: 12px;
    color: #94a3b8;
    margin: 16px 0 12px 0;
    position: relative;
}

.chat-date-separator::before,
.chat-date-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: #e2e8f0;
}

.chat-date-separator::before {
    left: 0;
}

.chat-date-separator::after {
    right: 0;
}

/* =========================
   Prevent Background Scroll
   ========================= */
body.chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

.chat-screen {
    overflow: hidden; /* Add to existing .chat-screen rules */
}

/* =========================
   Prevent Messages Tab Scroll When Chat Open
   ========================= */
#messagesTabContent.chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Also prevent body scroll as backup */
body.chat-open {
    overflow: hidden;
}

.chat-screen {
    overflow: hidden;
}

/* =========================
   Message Context Cards (Listing Metadata)
   ========================= */
.message-context {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 6px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    border-left: 3px solid rgba(255, 255, 255, 0.3);
}

.message-received .message-context {
    background: #f1f5f9;
    border-left-color: #0b7d62;
}

.message-context-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.message-context-content {
    flex: 1;
    min-width: 0;
}

.message-context-title {
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 2px;
}

.message-context-route,
.message-context-location {
    font-size: 11px;
    opacity: 0.8;
    margin-bottom: 2px;
}

.message-context-price {
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

.message-sent .message-context {
    color: white;
}

.message-received .message-context-title {
    color: #1e293b;
}

.message-received .message-context-route,
.message-received .message-context-location {
    color: #64748b;
}

.message-received .message-context-price {
    color: #0b7d62;
}

/* =========================
   Hub Nav Notification Dot
   ========================= */
.hub-notification-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tab-icon {
    position: relative;
}