/* ================================================================
   CTH Vendor Chat — Stylesheet
   Brand: Close To Home Market
   Primary colour: #E8642A (orange)
   ================================================================ */

:root {
    --cth-orange:      #E8642A;
    --cth-orange-dark: #c9521d;
    --cth-orange-light:#fef0ea;
    --cth-text:        #1a1a1a;
    --cth-muted:       #6b6b6b;
    --cth-border:      #e5e0d8;
    --cth-bg:          #faf7f4;
    --cth-white:       #ffffff;
    --cth-radius:      8px;
}

/* ----------------------------------------------------------------
   MESSAGE SELLER BUTTON (store page & order confirmation)
---------------------------------------------------------------- */
.cth-message-btn,
.cth-send-btn,
.cth-reply-send {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--cth-orange);
    color: var(--cth-white) !important;
    border: none;
    border-radius: var(--cth-radius);
    padding: 11px 22px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    text-decoration: none;
    line-height: 1.3;
    font-family: inherit;
}
.cth-message-btn:hover,
.cth-send-btn:hover,
.cth-reply-send:hover {
    background: var(--cth-orange-dark);
    transform: translateY(-1px);
}
.cth-message-btn:active,
.cth-send-btn:active {
    transform: translateY(0);
}
.cth-message-btn svg,
.cth-send-btn svg {
    flex-shrink: 0;
}

/* Store page wrap */
.cth-store-message-wrap {
    margin: 12px 0;
    list-style: none !important;
}
.cth-store-message-wrap::before,
.cth-store-message-wrap::marker { content: none !important; }

/* Order confirmation section */
.cth-order-message-section {
    margin: 28px 0;
    padding: 24px;
    background: var(--cth-bg);
    border: 1px solid var(--cth-border);
    border-radius: var(--cth-radius);
}
.cth-order-message-heading {
    margin: 0 0 14px;
    font-size: 17px;
    color: var(--cth-text);
}
.cth-order-message-section .cth-message-btn {
    margin-right: 8px;
    margin-bottom: 8px;
}

/* ----------------------------------------------------------------
   MODAL
---------------------------------------------------------------- */
.cth-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex !important;
    align-items: center;
    justify-content: center;
}
.cth-modal[style*="display:none"],
.cth-modal[style*="display: none"] {
    display: none !important;
}
.cth-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    cursor: pointer;
}
.cth-modal-box {
    position: relative;
    background: var(--cth-white);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}
.cth-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    background: var(--cth-orange);
    flex-shrink: 0;
}
.cth-modal-vendor-name {
    margin: 0;
    color: var(--cth-white);
    font-size: 17px;
    font-weight: 700;
}
.cth-modal-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.2s;
}
.cth-modal-close:hover {
    color: var(--cth-white);
}

/* New thread form */
.cth-new-thread-form {
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}
.cth-field-row {
    display: flex;
    flex-direction: column;
}
.cth-field {
    padding: 11px 14px;
    border: 1.5px solid var(--cth-border);
    border-radius: var(--cth-radius);
    font-size: 14px;
    font-family: inherit;
    color: var(--cth-text);
    background: var(--cth-white);
    transition: border-color 0.2s;
    resize: vertical;
}
.cth-field:focus {
    outline: none;
    border-color: var(--cth-orange);
    box-shadow: 0 0 0 3px rgba(232, 100, 42, 0.12);
}
.cth-modal-notice {
    margin: 0;
    font-size: 12px;
    color: var(--cth-muted);
    text-align: center;
}

/* ----------------------------------------------------------------
   LIVE THREAD PANE (inside modal)
---------------------------------------------------------------- */
.cth-live-thread-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.cth-live-thread-pane .cth-messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 340px;
}
.cth-live-thread-pane .cth-reply-form {
    padding: 12px 16px;
    border-top: 1px solid var(--cth-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.cth-live-thread-pane .cth-reply-input {
    flex: 1;
    padding: 10px 12px;
    border: 1.5px solid var(--cth-border);
    border-radius: var(--cth-radius);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
}
.cth-live-thread-pane .cth-reply-input:focus {
    outline: none;
    border-color: var(--cth-orange);
}
.cth-live-thread-pane .cth-reply-send {
    padding: 10px 16px;
    font-size: 14px;
    white-space: nowrap;
}

/* Status message in modal */
.cth-status-msg {
    padding: 10px 22px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--cth-orange);
}

/* ----------------------------------------------------------------
   ORDER CONTEXT BANNER
---------------------------------------------------------------- */
.cth-order-context {
    padding: 8px 16px;
    background: var(--cth-orange-light);
    border-bottom: 1px solid #f0c9ae;
    font-size: 13px;
}
.cth-order-context a {
    color: var(--cth-orange-dark);
    font-weight: 600;
}

/* ----------------------------------------------------------------
   INBOX (My Account + Vendor Dashboard)
---------------------------------------------------------------- */
.cth-inbox-wrap {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    border: 1px solid var(--cth-border);
    border-radius: var(--cth-radius);
    overflow: hidden;
    min-height: 500px;
    background: var(--cth-white);
}

/* Thread list sidebar */
.cth-thread-list {
    border-right: 1px solid var(--cth-border);
    overflow-y: auto;
    background: var(--cth-bg);
}
.cth-no-threads {
    padding: 24px;
    color: var(--cth-muted);
    font-size: 14px;
    text-align: center;
}
.cth-thread-item {
    display: block;
    padding: 14px 16px;
    border-bottom: 1px solid var(--cth-border);
    text-decoration: none;
    transition: background 0.15s;
}
.cth-thread-item:hover {
    background: var(--cth-orange-light);
}
.cth-thread-item.cth-active {
    background: var(--cth-orange-light);
    border-left: 3px solid var(--cth-orange);
}
.cth-thread-name {
    display: block;
    font-weight: 700;
    font-size: 14px;
    color: var(--cth-text);
    margin-bottom: 2px;
}
.cth-thread-subject {
    display: block;
    font-size: 12px;
    color: var(--cth-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}
.cth-thread-time {
    display: block;
    font-size: 11px;
    color: var(--cth-muted);
}

/* Chat pane */
.cth-chat-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.cth-pane-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--cth-muted);
    padding: 40px;
    text-align: center;
}
.cth-pane-placeholder svg {
    opacity: 0.3;
}
.cth-pane-placeholder p {
    margin: 0;
    font-size: 14px;
}

/* Messages list in pane */
.cth-chat-pane .cth-messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.cth-message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}
.cth-msg-mine {
    align-self: flex-end;
    align-items: flex-end;
}
.cth-msg-theirs {
    align-self: flex-start;
    align-items: flex-start;
}
.cth-msg-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--cth-muted);
    margin-bottom: 4px;
}
.cth-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.cth-msg-mine .cth-msg-bubble {
    background: var(--cth-orange);
    color: var(--cth-white);
    border-bottom-right-radius: 4px;
}
.cth-msg-theirs .cth-msg-bubble {
    background: var(--cth-bg);
    color: var(--cth-text);
    border: 1px solid var(--cth-border);
    border-bottom-left-radius: 4px;
}
.cth-msg-time {
    font-size: 10px;
    color: var(--cth-muted);
    margin-top: 3px;
}

/* Reply form at bottom of pane */
.cth-chat-pane .cth-reply-form {
    padding: 14px 20px;
    border-top: 1px solid var(--cth-border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--cth-white);
}
.cth-reply-input {
    flex: 1;
    padding: 11px 14px;
    border: 1.5px solid var(--cth-border);
    border-radius: var(--cth-radius);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
}
.cth-reply-input:focus {
    outline: none;
    border-color: var(--cth-orange);
    box-shadow: 0 0 0 3px rgba(232, 100, 42, 0.12);
}

/* Unread badge */
.cth-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--cth-orange);
    color: var(--cth-white);
    font-size: 11px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
}

/* Chat pane header */
.cth-pane-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--cth-border);
    background: var(--cth-white);
    flex-shrink: 0;
}
.cth-pane-title { font-size: 15px; color: var(--cth-text); }
.cth-guest-tag {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 10px;
    background: var(--cth-orange-light);
    color: var(--cth-orange-dark);
}
.cth-pane-header .cth-order-context { margin-top: 4px; font-size: 13px; }
.cth-pane-header .cth-order-context a { color: var(--cth-orange); }
.cth-back-link { display: none; padding: 10px 20px 0; font-size: 13px; color: var(--cth-orange); text-decoration: none; }
.cth-thread-item.cth-unread .cth-thread-subject { color: var(--cth-text); font-weight: 600; }
.cth-chat-pane .cth-messages-list { max-height: 520px; }
.cth-status-msg.cth-status-error { color: #c0392b; }
.cth-status-msg.cth-status-success { color: var(--cth-orange); }
body.cth-modal-open { overflow: hidden; }

/* Vendor dashboard page */
.cth-vendor-messages-content .cth-inbox-wrap { margin-top: 16px; }
.cth-send-btn[disabled], .cth-reply-send[disabled] { opacity: .6; cursor: default; transform: none; }

/* Error */
.cth-error {
    padding: 20px;
    color: #c0392b;
    font-size: 14px;
}

/* ----------------------------------------------------------------
   RESPONSIVE
---------------------------------------------------------------- */
@media (max-width: 640px) {
    .cth-inbox-wrap {
        grid-template-columns: 1fr;
    }
    .cth-thread-list {
        border-right: none;
        border-bottom: 1px solid var(--cth-border);
        max-height: none;
    }
    /* Mobile: show list OR conversation, not both */
    .cth-inbox-wrap.cth-has-active .cth-thread-list { display: none; }
    .cth-inbox-wrap.cth-has-active .cth-back-link { display: block; }
    .cth-inbox-wrap:not(.cth-has-active) .cth-chat-pane { display: none; }
    .cth-inbox-wrap { min-height: 0; }
    .cth-message { max-width: 88%; }
    .cth-modal-box {
        max-height: 95vh;
        border-radius: 12px 12px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
    }
    .cth-modal {
        align-items: flex-end;
    }
}
