
/* =========================================
   JOMBA MESSAGES — BASE
========================================= */

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

.messages-page {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: #080c12;
    color: #f5f5f5;
    font-family: "Segoe UI", Arial, sans-serif;
}

.messages-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 18px;
    padding: 16px clamp(16px, 4vw, 40px);
    background: #080c12;
    border-bottom: 1px solid #20272b;
}

.messages-logo {
    color: #e5c36d;
    font-size: 25px;
    font-weight: 800;
    letter-spacing: 1px;
    text-decoration: none;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--branding-accent);
    text-decoration: none;
    flex-shrink: 0;
}

.brand img {
    display: block;
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 50%;
    border: 1px solid var(--primary-accent);
}

.brand > span {
    display: flex;
    flex-direction: column;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: var(--text-main);
}

.brand small {
    margin-top: 2px;
    color: var(--branding-accent);
    font-size: 9px;
    letter-spacing: 2px;
}


.messages-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.messages-nav a {
    color: #c5cbd0;
    font-size: 13px;
    text-decoration: none;
}

.messages-nav a:hover {
    color: #e5c36d;
}

.messages-container {
    width: min(1250px, 94%);
    margin: 0 auto;
    padding: 30px 0;
    flex: 1;
}

.messages-page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 24px;
}

.messages-eyebrow {
    margin: 0 0 8px;
    color: #e5c36d;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
}

.messages-page-heading h1 {
    margin: 0 0 10px;
    font-size: clamp(28px, 4vw, 38px);
}

.messages-page-heading > div > p:last-child {
    color: #9ca3af;
    font-size: 14px;
    line-height: 1.6;
}

.messages-heading-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.messages-shop-button,
.messages-checkout-button {
    display: inline-block;
    padding: 12px 17px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.messages-shop-button {
    background: #e5c36d;
    color: #080c12;
}

.messages-shop-button:hover {
    background: #f4d98b;
}

.messages-checkout-button {
    background: #22c55e;
    color: #06130b;
}

.messages-checkout-button:hover {
    background: #4ade80;
}

/* =========================================
   CONVERSATION AND CHAT LAYOUT
========================================= */

.messaging-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    min-height: 620px;
    overflow: hidden;
    border: 1px solid #252d34;
    border-radius: 12px;
    background: #0c1118;
}

.conversation-panel {
    min-width: 0;
    border-right: 1px solid #252d34;
    background: #080c12;
}

.conversation-panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 18px 16px;
}

.conversation-panel-heading h2 {
    margin: 0;
    font-size: 17px;
}

.conversation-count {
    display: grid;
    place-items: center;
    min-width: 25px;
    height: 25px;
    padding: 0 6px;
    border-radius: 20px;
    background: #153b30;
    color: #d9fdd3;
    font-size: 12px;
}

.conversation-search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 14px 14px;
    padding: 0 13px;
    border-radius: 9px;
    background: #20272b;
    color: #aebac1;
}

.conversation-search input {
    width: 100%;
    min-width: 0;
    padding: 13px 0;
    border: none;
    outline: none;
    background: transparent;
    color: #fff;
    font-size: 13px;
}

.conversation-search input::placeholder {
    color: #8696a0;
}

.conversation-list {
    display: flex;
    flex-direction: column;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 15px;
    border: 0;
    border-top: 1px solid #172027;
    background: transparent;
    color: inherit;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.conversation-item:hover,
.conversation-item.active {
    background: #151c20;
}

.conversation-item.active {
    box-shadow: inset 3px 0 #e5c36d;
}

.conversation-avatar {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    overflow: hidden;
    border-radius: 50%;
    background: #263238;
    color: #d9fdd3;
    font-size: 13px;
    font-weight: 700;
}

.conversation-summary {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.conversation-name-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.conversation-name-row strong {
    overflow: hidden;
    color: #f5f5f5;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-name-row time {
    flex-shrink: 0;
    color: #8696a0;
    font-size: 10px;
}

.conversation-preview {
    overflow: hidden;
    color: #aebac1;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-product {
    align-self: flex-start;
    padding: 4px 7px;
    border-radius: 5px;
    background: #20272b;
    color: #c5cbd0;
    font-size: 10px;
}

.empty-conversations {
    padding: 20px;
    color: #9ca3af;
    font-size: 13px;
    text-align: center;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 620px;
    background: #0b141a;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid #252d34;
    background: #20272b;
}

.chat-contact {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-contact h2 {
    margin: 0 0 4px;
    font-size: 15px;
}

.chat-contact p {
    margin: 0;
    color: #aebac1;
    font-size: 11px;
}

.online-indicator {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
}

/* =========================================
   PRODUCT BANNER AND CHECKOUT
========================================= */

.chat-product-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px;
    padding: 12px;
    border: 1px solid #29343b;
    border-radius: 10px;
    background: #151c20;
}

.chat-product-thumb {
    flex-shrink: 0;
}

.chat-product-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border-radius: 8px;
    background: #263238;
    color: #e5c36d;
    font-size: 22px;
}

.chat-product-info {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.chat-product-info > span {
    color: #aebac1;
    font-size: 9px;
    letter-spacing: 1px;
}

.chat-product-info strong {
    overflow-wrap: anywhere;
    font-size: 13px;
}

.chat-product-info p {
    margin: 0;
    color: #22c55e;
    font-size: 12px;
    font-weight: 700;
}

.chat-product-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-checkout-btn {
    padding: 9px 12px;
    border: none;
    border-radius: 6px;
    background: #22c55e;
    color: #06130b;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
}

.chat-checkout-btn:hover {
    background: #4ade80;
}

.view-product-link {
    color: #e5c36d;
    font-size: 11px;
    text-decoration: none;
}

.view-product-link:hover {
    text-decoration: underline;
}

/* =========================================
   CHAT MESSAGES
========================================= */

.chat-messages {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 13px;
    min-height: 250px;
    max-height: 390px;
    overflow-y: auto;
    padding: 20px;
    background: #0b141a;
}

.chat-date-divider {
    align-self: center;
    margin: 0 0 5px;
    padding: 7px 11px;
    border-radius: 20px;
    background: #20272b;
    color: #aebac1;
    font-size: 10px;
    text-align: center;
}

.message-row {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message-row.received {
    align-self: flex-start;
    align-items: flex-start;
}

.message-row.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.message-bubble {
    padding: 10px 13px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.message-row.received .message-bubble {
    border-radius: 4px 12px 12px 12px;
    background: #202c33;
    color: #f1f5f6;
}

.message-row.sent .message-bubble {
    border-radius: 12px 4px 12px 12px;
    background: #005c4b;
    color: #f1f5f6;
}

.message-sender {
    margin-bottom: 4px;
    padding: 0 4px;
    color: #aebac1;
    font-size: 11px;
}

.message-time {
    margin-top: 4px;
    padding: 0 4px;
    color: #8696a0;
    font-size: 10px;
}

.chat-status-message {
    display: none;
    margin: 0;
    padding: 0 15px 10px;
    color: #22c55e;
    font-size: 12px;
}

.chat-status-message.is-visible {
    display: block;
}

.chat-compose {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid #20272b;
    background: #0b1014;
}

.chat-compose textarea {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: 120px;
    resize: vertical;
    padding: 12px 14px;
    border: 1px solid #29343b;
    border-radius: 22px;
    outline: none;
    background: #20272b;
    color: #fff;
    font: inherit;
    font-size: 14px;
}

.chat-compose textarea:focus {
    border-color: #00a884;
}

.chat-compose textarea::placeholder {
    color: #8696a0;
}

.chat-compose button {
    min-height: 44px;
    padding: 0 17px;
    border: none;
    border-radius: 22px;
    background: #00a884;
    color: #062b22;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.chat-compose button:hover {
    background: #25d3a6;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =========================================
   P2P TRADE DETAILS
========================================= */

.p2p-trade-banner {
    grid-column: 1 / -1;
    margin: 15px;
    padding: 18px;
    border: 1px solid #e5c36d;
    border-radius: 12px;
    background: #121820;
}

.p2p-trade-header {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.p2p-badge {
    color: #e5c36d;
    font-size: 11px;
    font-weight: 800;
}

.p2p-timer {
    color: #f97316;
    font-size: 12px;
}

.p2p-trade-details {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 14px 0;
    border-top: 1px solid #29343b;
    border-bottom: 1px solid #29343b;
}

.p2p-detail-item span {
    display: block;
    margin-bottom: 5px;
    color: #aebac1;
    font-size: 11px;
}

.p2p-detail-item strong {
    overflow-wrap: anywhere;
    color: #fff;
    font-size: 14px;
}

.p2p-amount {
    color: #22c55e !important;
}

.p2p-ref {
    color: #e5c36d !important;
}

.p2p-actions,
.mpesa-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.p2p-actions button,
.p2p-btn-paid {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: #e5c36d;
    color: #080c12;
    font-weight: 700;
    cursor: pointer;
}

.p2p-btn-confirm {
    background: #22c55e !important;
}

.mpesa-cancel-btn {
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: #29343b;
    color: #fff;
    cursor: pointer;
}

/* =========================================
   M-PESA MODAL
========================================= */

.p2p-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: none;
    place-items: center;
    padding: 18px;
    background: rgb(0 0 0 / 85%);
    backdrop-filter: blur(4px);
}

.p2p-modal:not([hidden]) {
    display: grid;
}

.p2p-modal-content {
    width: min(400px, 100%);
    padding: 24px;
    border: 1px solid #29343b;
    border-radius: 12px;
    background: #0c1118;
}

.p2p-modal-content h3 {
    margin: 0 0 10px;
    font-size: 18px;
}

.p2p-modal-content p {
    color: #aebac1;
    font-size: 13px;
    line-height: 1.5;
}

.p2p-modal-content input {
    width: 100%;
    margin: 12px 0;
    padding: 12px;
    border: 1px solid #29343b;
    border-radius: 6px;
    outline: none;
    background: #080c12;
    color: #fff;
}

/* =========================================
   FOOTER
========================================= */

.messages-footer {
    padding: 20px;
    border-top: 1px solid #20272b;
    background: #080c12;
    color: #8696a0;
    font-size: 11px;
    text-align: center;
}

/* =========================================
   MOBILE — WHATSAPP-INSPIRED DESIGN
========================================= */

@media (max-width: 768px) {

    .messages-page {
        min-height: 100vh;
        background: #0b1014;
    }

    .messages-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
        padding: 15px 18px 10px;
        border: none;
        background: #0b1014;
    }

    .messages-logo {
        color: #f5f5f5;
        font-size: 27px;
        letter-spacing: 0;
    }

    .messages-nav {
        width: 100%;
        justify-content: space-between;
        gap: 10px;
    }

    .messages-nav a {
        font-size: 11px;
    }

    .messages-container {
        width: 100%;
        padding: 10px 0 18px;
    }

    .messages-page-heading {
        display: block;
        margin: 0;
        padding: 0 18px 15px;
    }

    .messages-eyebrow,
    .messages-page-heading > div > p:last-child {
        display: none;
    }

    .messages-page-heading h1 {
        margin: 0 0 14px;
        font-size: 28px;
    }

    .messages-heading-actions {
        display: flex;
        width: 100%;
        gap: 8px;
    }

    .messages-shop-button,
    .messages-checkout-button {
        flex: 1;
        padding: 10px 7px;
        border-radius: 22px;
        font-size: 12px;
    }

    .messaging-layout {
        display: block;
        min-height: 0;
        overflow: visible;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .conversation-panel,
    .chat-panel {
        width: 100%;
        min-height: 0;
        border: 0;
        border-radius: 0;
        background: #0b1014;
    }

    /* Show the conversation list first */
    .messaging-layout:not(.chat-active) .conversation-panel {
        display: block;
    }

    .messaging-layout:not(.chat-active) .chat-panel {
        display: none;
    }

    /* Show only the chat after a conversation is selected */
    .messaging-layout.chat-active .conversation-panel {
        display: none;
    }

    .messaging-layout.chat-active .chat-panel {
        display: flex;
    }

    .conversation-panel-heading {
        padding: 12px 18px;
    }

    .conversation-panel-heading h2 {
        font-size: 16px;
    }

    .conversation-search {
        margin: 0 18px 10px;
        padding: 0 15px;
        border-radius: 25px;
        background: #20272b;
    }

    .conversation-search input {
        padding: 14px 0;
        font-size: 15px;
    }

    .conversation-list {
        max-height: none;
        overflow-y: visible;
    }

    .conversation-item {
        gap: 13px;
        padding: 14px 18px;
        border: 0;
    }

    .conversation-item:hover,
    .conversation-item.active {
        background: #151c20;
        box-shadow: none;
    }

    .conversation-avatar {
        width: 52px;
        height: 52px;
        flex-basis: 52px;
        font-size: 14px;
    }

    .conversation-name-row strong {
        font-size: 15px;
        font-weight: 600;
    }

    .conversation-name-row time {
        font-size: 11px;
    }

    .conversation-preview {
        font-size: 13px;
    }

    .conversation-product {
        display: none;
    }

    .empty-conversations {
        padding: 24px;
        color: #aebac1;
    }

    /* Full-height mobile conversation */
    .chat-panel {
        height: calc(100vh - 150px);
        min-height: 450px;
        overflow: hidden;
    }

    .chat-header {
        flex-shrink: 0;
        padding: 10px 12px;
        background: #20272b;
    }

    .chat-contact {
        gap: 9px;
    }

    .chat-contact h2 {
        font-size: 15px;
    }

    .back-to-chats-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 40px;
        padding: 0 !important;
        border: 0;
        background: transparent;
        color: #d9fdd3 !important;
        font-size: 27px !important;
        cursor: pointer;
    }

    .chat-product-banner {
        flex-shrink: 0;
        gap: 8px;
        margin: 0;
        padding: 10px;
        border: 0;
        border-bottom: 1px solid #29343b;
        border-radius: 0;
        background: #151c20;
    }

    .chat-product-icon {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    .chat-product-info > span {
        font-size: 8px;
    }

    .chat-product-info strong {
        font-size: 12px;
    }

    .chat-product-info p {
        font-size: 11px;
    }

    .chat-product-actions {
        gap: 6px;
    }

    .chat-checkout-btn {
        padding: 7px 8px;
        font-size: 10px;
    }

    .view-product-link {
        font-size: 10px;
    }

    .chat-messages {
        flex: 1;
        min-height: 0;
        max-height: none;
        padding: 16px 12px;
        gap: 12px;
    }

    .message-row {
        max-width: 86%;
    }

    .message-bubble {
        padding: 9px 12px;
        font-size: 14px;
    }

    .chat-compose {
        flex-shrink: 0;
        gap: 8px;
        padding: 9px;
        border: 0;
    }

    .chat-compose textarea {
        min-height: 44px;
        padding: 12px 14px;
        border: 0;
        border-radius: 24px;
        font-size: 14px;
    }

    .chat-compose button {
        min-height: 44px;
        padding: 0 14px;
    }

    .p2p-trade-banner {
        margin: 10px;
        padding: 12px;
    }

    .p2p-trade-details {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .messages-footer {
        padding: 12px;
    }

    .messages-footer p {
        margin: 0;
    }
}

@media (max-width: 380px) {

    .messages-nav a {
        font-size: 10px;
    }

    .messages-heading-actions {
        gap: 6px;
    }

    .messages-shop-button,
    .messages-checkout-button {
        font-size: 11px;
    }

    .chat-product-banner {
        flex-wrap: wrap;
    }

    .chat-product-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

@media (min-width: 769px) {
    .back-to-chats-btn {
        display: none !important;
    }
}

/* Unread message count — WhatsApp-inspired green badge */

.conversation-preview-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}

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

.unread-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    flex: 0 0 auto;
    padding: 0 6px;
    border-radius: 12px;
    background: #25d366;
    color: #062b22;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
}
