/**
 * MMB Messaging – Floating Bubble Widget CSS (Etsy-style)
 * v1.4.0
 */

/* ─── Bubble Button ──────────────────────────────────── */

.mmb-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999998;
}

.mmb-bubble-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #222222;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    position: relative;
}

.mmb-bubble-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.mmb-bubble-btn:active {
    transform: scale(0.95);
}

.mmb-bubble-icon-msg,
.mmb-bubble-icon-close {
    transition: opacity 0.2s ease, transform 0.2s ease;
    position: absolute;
}

.mmb-bubble-icon-close {
    opacity: 0;
    transform: rotate(180deg);
}

.mmb-bubble.open .mmb-bubble-icon-msg {
    opacity: 0;
    transform: rotate(-180deg);
}

.mmb-bubble.open .mmb-bubble-icon-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* Badge */
.mmb-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 2px solid #fff;
    box-sizing: border-box;
}

/* ─── Panel ──────────────────────────────────────────── */

.mmb-bubble-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    max-height: 560px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.04);
    z-index: 999997;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.mmb-bubble-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ─── Panel Header ───────────────────────────────────── */

.mmb-bp-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    background: #fff;
    flex-shrink: 0;
}

.mmb-bp-header-thread {
    padding: 12px 16px;
    gap: 8px;
}

.mmb-bp-title {
    font-size: 18px;
    font-weight: 700;
    color: #222;
    flex: 1;
    line-height: 1.3;
}

.mmb-bp-header-thread .mmb-bp-title {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mmb-bp-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: #666;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

.mmb-bp-close:hover {
    background: #f5f5f5;
    color: #222;
}

.mmb-bp-back {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.mmb-bp-back:hover {
    background: #f5f5f5;
    color: #222;
}

/* ─── Panel Body ─────────────────────────────────────── */

.mmb-bp-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.mmb-bp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.mmb-bp-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #eee;
    border-top-color: #222;
    border-radius: 50%;
    animation: mmb-bp-spin 0.7s linear infinite;
}

@keyframes mmb-bp-spin {
    to { transform: rotate(360deg); }
}

.mmb-bp-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #999;
}

.mmb-bp-empty svg {
    margin-bottom: 12px;
}

.mmb-bp-empty p {
    font-size: 14px;
    margin: 0;
}

/* ─── Thread List ────────────────────────────────────── */

.mmb-bp-thread-list {
    padding: 0;
}

.mmb-bp-thread-row {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f5f5f5;
    gap: 12px;
}

.mmb-bp-thread-row:hover {
    background: #fafafa;
}

.mmb-bp-thread-row:last-child {
    border-bottom: none;
}

.mmb-bp-thread-row.unread {
    background: #fef9f0;
}

.mmb-bp-thread-row.unread:hover {
    background: #fdf3e0;
}

.mmb-bp-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0.5px;
}

.mmb-bp-thread-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.mmb-bp-thread-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 3px;
}

.mmb-bp-thread-name {
    font-size: 14px;
    font-weight: 600;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mmb-bp-thread-row.unread .mmb-bp-thread-name {
    font-weight: 700;
}

.mmb-bp-thread-time {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
    flex-shrink: 0;
}

.mmb-bp-thread-preview {
    font-size: 13px;
    color: #777;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.mmb-bp-thread-row.unread .mmb-bp-thread-preview {
    color: #555;
    font-weight: 500;
}

/* ─── Panel Footer ───────────────────────────────────── */

.mmb-bp-footer {
    padding: 12px 16px;
    border-top: 1px solid #f0f0f0;
    background: #fff;
    flex-shrink: 0;
}

.mmb-bp-new-msg {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: #222;
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.mmb-bp-new-msg:hover {
    background: #333;
    transform: translateY(-1px);
}

.mmb-bp-new-msg:active {
    transform: translateY(0);
}

.mmb-bp-new-msg svg {
    flex-shrink: 0;
}

.mmb-bp-send-new {
    width: 100%;
    padding: 12px 20px;
    background: #222;
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.mmb-bp-send-new:hover {
    background: #333;
}

.mmb-bp-send-new:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ─── Messages / Conversation View ───────────────────── */

.mmb-bp-messages {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mmb-bp-date-sep {
    text-align: center;
    font-size: 11px;
    color: #999;
    padding: 8px 0;
    font-weight: 500;
}

.mmb-bp-bubble {
    max-width: 82%;
    margin-bottom: 4px;
}

.mmb-bp-bubble-mine {
    align-self: flex-end;
}

.mmb-bp-bubble-other {
    align-self: flex-start;
}

.mmb-bp-bubble-sender {
    font-size: 11px;
    font-weight: 600;
    color: #666;
    margin-bottom: 3px;
    padding-left: 2px;
}

.mmb-bp-bubble-text {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
}

.mmb-bp-bubble-mine .mmb-bp-bubble-text {
    background: #222;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.mmb-bp-bubble-other .mmb-bp-bubble-text {
    background: #f2f2f2;
    color: #222;
    border-bottom-left-radius: 4px;
}

.mmb-bp-bubble-time {
    font-size: 10px;
    color: #aaa;
    margin-top: 3px;
    padding: 0 4px;
}

.mmb-bp-bubble-mine .mmb-bp-bubble-time {
    text-align: right;
}

/* Attachments in bubbles */
.mmb-bp-bubble-attachments {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.mmb-bp-bubble-img-link {
    display: block;
}

.mmb-bp-bubble-img {
    max-width: 180px;
    max-height: 140px;
    border-radius: 10px;
    object-fit: cover;
    cursor: pointer;
    transition: opacity 0.15s;
}

.mmb-bp-bubble-img:hover {
    opacity: 0.85;
}

.mmb-bp-bubble-file {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #f5f5f5;
    border-radius: 8px;
    font-size: 12px;
    color: #444;
    text-decoration: none;
    transition: background 0.15s;
}

.mmb-bp-bubble-file:hover {
    background: #eee;
}

/* Offer cards in bubble */
.mmb-bp-offer-card {
    margin-top: 6px;
    padding: 10px 14px;
    background: #fffbf0;
    border: 1px solid #f0e6cc;
    border-radius: 12px;
    font-size: 13px;
}

.mmb-bp-offer-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.mmb-bp-offer-header strong {
    font-size: 13px;
    color: #222;
}

.mmb-bp-offer-product {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.mmb-bp-offer-detail {
    font-size: 16px;
    font-weight: 700;
    color: #222;
    margin-bottom: 4px;
}

.mmb-bp-offer-code {
    font-size: 12px;
    color: #666;
    padding: 4px 8px;
    background: #f5f0e0;
    border-radius: 6px;
    display: inline-block;
    margin-top: 4px;
}

/* ─── Compose Area (in thread view) ──────────────────── */

.mmb-bp-compose {
    border-top: 1px solid #f0f0f0;
    background: #fff;
    flex-shrink: 0;
    padding: 8px 12px 12px;
}

.mmb-bp-compose-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0;
}

.mmb-bp-compose-files:not(:empty) {
    margin-bottom: 8px;
}

.mmb-bp-file-preview {
    position: relative;
    display: inline-block;
}

.mmb-bp-file-preview img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #eee;
}

.mmb-bp-file-preview.mmb-bp-file-doc {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #f5f5f5;
    border-radius: 8px;
    font-size: 12px;
    color: #444;
}

.mmb-bp-file-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #e74c3c;
    color: #fff;
    border: none;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.mmb-bp-file-doc .mmb-bp-file-remove {
    position: static;
    margin-left: 4px;
}

.mmb-bp-compose-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.mmb-bp-attach {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.mmb-bp-attach:hover {
    background: #f5f5f5;
    color: #222;
}

.mmb-bp-compose-row textarea {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 100px;
    transition: border-color 0.2s;
}

.mmb-bp-compose-row textarea:focus {
    border-color: #222;
}

.mmb-bp-send {
    width: 36px;
    height: 36px;
    border: none;
    background: #222;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s, transform 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.mmb-bp-send:hover {
    background: #333;
    transform: scale(1.05);
}

.mmb-bp-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── Compose Form (New Message / Guest) ─────────────── */

.mmb-bp-compose-form {
    padding: 16px 20px;
}

.mmb-bp-guest-intro {
    font-size: 14px;
    color: #555;
    margin: 0 0 16px;
    line-height: 1.5;
}

.mmb-bp-field {
    margin-bottom: 14px;
}

.mmb-bp-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.mmb-bp-field label .req {
    color: #e74c3c;
}

.mmb-bp-field label small {
    font-weight: 400;
    color: #999;
}

.mmb-bp-field input[type="text"],
.mmb-bp-field input[type="email"],
.mmb-bp-field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.mmb-bp-field input[type="text"]:focus,
.mmb-bp-field input[type="email"]:focus,
.mmb-bp-field textarea:focus {
    border-color: #222;
}

.mmb-bp-field input[type="file"] {
    font-size: 13px;
    color: #666;
}

.mmb-bp-file-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.mmb-bp-file-tag {
    display: inline-block;
    padding: 4px 10px;
    background: #f5f5f5;
    border-radius: 6px;
    font-size: 12px;
    color: #555;
}

/* Guest status */
.mmb-bp-guest-status {
    font-size: 13px;
    margin-top: 8px;
}

.mmb-bp-guest-status.error {
    color: #e74c3c;
}

/* Success view */
.mmb-bp-success {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 30px 20px;
}

.mmb-bp-success svg {
    margin-bottom: 16px;
}

.mmb-bp-success h3 {
    font-size: 18px;
    font-weight: 700;
    color: #222;
    margin: 0 0 8px;
}

.mmb-bp-success p {
    font-size: 14px;
    color: #666;
    margin: 0;
    line-height: 1.5;
}

/* ─── Product Context Card (auto-bound from product page) ── */

.mmb-bp-product-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 10px;
}

.mmb-bp-product-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.mmb-bp-product-info {
    flex: 1;
    min-width: 0;
}

.mmb-bp-product-info strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.mmb-bp-product-info small {
    font-size: 12px;
    color: #888;
}

/* ─── Guest Thread View (returning guest via token) ──── */

.mmb-bp-guest-thread-reply {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 12px 12px;
    border-top: 1px solid #f0f0f0;
    background: #fff;
}

.mmb-bp-guest-thread-reply textarea {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 80px;
    transition: border-color 0.2s;
}

.mmb-bp-guest-thread-reply textarea:focus {
    border-color: #222;
}

.mmb-bp-guest-thread-reply .mmb-bp-send {
    flex-shrink: 0;
}

/* ─── Custom Order Card in Bubble ───────────────────── */

.mmb-bp-custom-order-card {
    margin-top: 6px;
    padding: 12px 14px;
    background: #f0f7ff;
    border: 1px solid #d0e3f5;
    border-radius: 12px;
    font-size: 13px;
}

.mmb-bp-co-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.mmb-bp-co-header strong {
    font-size: 13px;
    color: #222;
}

.mmb-bp-co-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
}

.mmb-bp-co-badge.pending {
    background: #fff3cd;
    color: #856404;
}

.mmb-bp-co-badge.paid {
    background: #d4edda;
    color: #155724;
}

.mmb-bp-co-badge.expired {
    background: #f0f0f0;
    color: #666;
}

.mmb-bp-co-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
    font-size: 14px;
}

.mmb-bp-co-items {
    border-top: 1px solid #d0e3f5;
    padding-top: 6px;
    margin-top: 4px;
}

.mmb-bp-co-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
    color: #444;
}

.mmb-bp-co-item span:last-child {
    font-weight: 600;
    white-space: nowrap;
}

.mmb-bp-co-total {
    border-top: 1px solid #d0e3f5;
    margin-top: 6px;
    padding-top: 6px;
    text-align: right;
    font-size: 14px;
    color: #222;
}

.mmb-bp-co-pay-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    background: #222;
    color: #fff;
    text-align: center;
    border-radius: 20px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
    box-sizing: border-box;
}

.mmb-bp-co-pay-btn:hover {
    background: #333;
    color: #fff;
    text-decoration: none;
}

/* ─── Mobile Responsive ──────────────────────────────── */

@media (max-width: 480px) {
    .mmb-bubble {
        bottom: 16px;
        right: 16px;
    }

    .mmb-bubble-btn {
        width: 50px;
        height: 50px;
    }

    .mmb-bubble-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }

    .mmb-bubble-panel.open {
        transform: translateY(0);
    }

    .mmb-bp-bubble-img {
        max-width: 140px;
        max-height: 110px;
    }

    .mmb-bp-product-card {
        padding: 8px 10px;
    }

    .mmb-bp-product-thumb {
        width: 40px;
        height: 40px;
    }

    .mmb-bp-custom-order-card {
        padding: 10px 12px;
    }

    .mmb-bp-co-pay-btn {
        padding: 8px;
        font-size: 12px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .mmb-bubble-panel {
        width: 340px;
        max-height: 500px;
    }
}

/* ─── Print: hide widget ─────────────────────────────── */

@media print {
    .mmb-bubble,
    .mmb-bubble-panel {
        display: none !important;
    }
}
