/**
 * Microsite AI Chat Panel - v20260225f
 * Side-tab trigger + slide-in chat panel for business microsites
 * Based on workshop-chat.css pattern
 */

/* ============================================
   SIDE TAB TRIGGER
   ============================================ */
.ms-chat-trigger {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    background: var(--ms-chat-color, #059669);
    color: white;
    border: none;
    padding: 16px 10px;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    z-index: 9998;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, transform 0.2s;
}

.ms-chat-trigger:hover {
    filter: brightness(1.1);
}

.ms-chat-trigger svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.ms-chat-trigger.hidden {
    transform: translateY(-50%) translateX(100%);
    pointer-events: none;
}

/* ============================================
   PANEL CONTAINER
   ============================================ */
.ms-chat-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.ms-chat-panel.open {
    pointer-events: auto;
    opacity: 1;
    overscroll-behavior: contain;
}

/* Overlay */
.ms-chat-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
}

/* Panel Content */
.ms-chat-content {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 70%;
    max-width: 900px;
    min-width: 380px;
    background: #fff;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
}

.ms-chat-panel.open .ms-chat-content {
    transform: translateX(0);
}

/* ============================================
   HEADER
   ============================================ */
.ms-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #E5E7EB;
    background: #fff;
    flex-shrink: 0;
}

.ms-chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #1A1A1A;
}

.ms-chat-title svg {
    color: var(--ms-chat-color, #059669);
    width: 20px;
    height: 20px;
}

.ms-chat-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    color: #666;
    transition: background 0.15s;
}

.ms-chat-close:hover {
    background: #F3F4F6;
}

/* ============================================
   MESSAGES AREA
   ============================================ */
.ms-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overscroll-behavior: contain;
}

/* Welcome message */
.ms-chat-welcome {
    text-align: center;
    padding: 24px 16px;
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

.ms-chat-welcome strong {
    display: block;
    color: #1A1A1A;
    font-size: 15px;
    margin-bottom: 4px;
}

/* Crisis banner */
.ms-chat-crisis-banner {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 12px;
    color: #991B1B;
    line-height: 1.4;
    margin: 0 16px 8px;
    flex-shrink: 0;
}

.ms-chat-crisis-banner a {
    color: #991B1B;
    font-weight: 600;
}

/* Message bubble */
.ms-chat-msg {
    display: flex;
    gap: 8px;
    max-width: 100%;
}

.ms-chat-msg.user {
    flex-direction: row-reverse;
}

.ms-chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
}

.ms-chat-msg.assistant .ms-chat-msg-avatar {
    background: var(--ms-chat-color, #059669);
    color: white;
}

.ms-chat-msg.user .ms-chat-msg-avatar {
    background: var(--ms-chat-color, #059669);
    color: white;
}

.ms-chat-msg-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    max-width: calc(100% - 44px);
    word-wrap: break-word;
}

.ms-chat-msg.assistant .ms-chat-msg-content {
    background: #F3F4F6;
    color: #1A1A1A;
    border-bottom-left-radius: 4px;
}

.ms-chat-msg.user .ms-chat-msg-content {
    background: var(--ms-chat-color, #059669);
    color: white;
    border-bottom-right-radius: 4px;
}

.ms-chat-msg-content strong {
    font-weight: 600;
}

.ms-chat-msg-content ul {
    margin: 6px 0;
    padding-left: 18px;
}

.ms-chat-msg-content li {
    margin: 3px 0;
}

/* ============================================
   QUICK ACTION PILLS
   ============================================ */
.ms-chat-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px;
    border-bottom: 1px solid #E5E7EB;
    flex-shrink: 0;
    background: #fff;
}

.ms-chat-pills:empty {
    display: none;
}

.ms-chat-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border: 1px solid #E5E7EB;
    background: #fff;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: all 0.15s;
}

.ms-chat-pill:hover {
    border-color: var(--ms-chat-color, #059669);
    color: var(--ms-chat-color, #059669);
    background: rgba(5, 150, 105, 0.05);
}

/* ============================================
   COPY TRANSCRIPT
   ============================================ */
.ms-chat-copy-area {
    padding: 2px 16px 4px;
    flex-shrink: 0;
    text-align: center;
}

.ms-chat-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 400;
    color: #9CA3AF;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.ms-chat-copy-btn:hover {
    border-color: var(--ms-chat-color, #059669);
    color: var(--ms-chat-color, #059669);
}

.ms-chat-copy-btn.ms-chat-copy-success {
    border-color: #10B981;
    color: #10B981;
}

/* ============================================
   INPUT AREA
   ============================================ */
.ms-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #E5E7EB;
    background: #fff;
    flex-shrink: 0;
}

.ms-chat-input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #E5E7EB;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 100px;
    transition: border-color 0.15s;
}

.ms-chat-input-area textarea:focus {
    border-color: var(--ms-chat-color, #059669);
}

.ms-chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    background: var(--ms-chat-color, #059669);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
}

.ms-chat-send-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.05);
}

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

/* ============================================
   LOADING DOTS
   ============================================ */
.ms-chat-loading-dots {
    display: flex;
    gap: 4px;
}

.ms-chat-loading-dots span {
    width: 7px;
    height: 7px;
    background: #9CA3AF;
    border-radius: 50%;
    animation: msChatBounce 1.4s infinite ease-in-out both;
}

.ms-chat-loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.ms-chat-loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes msChatBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ============================================
   COMMERCE: PRODUCT CARDS
   ============================================ */
.ms-chat-product-section {
    padding: 4px 0;
}

.ms-chat-product-label {
    font-size: 12px;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.ms-chat-product-row {
    display: flex !important;
    gap: 10px;
    overflow-x: auto !important;
    overflow-y: visible !important;
    scroll-snap-type: x mandatory;
    padding: 8px 0;
    min-height: 210px !important;
    height: auto !important;
    align-items: stretch;
    -webkit-overflow-scrolling: touch;
}

.ms-chat-product-row::-webkit-scrollbar {
    height: 4px;
}

.ms-chat-product-row::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 2px;
}

.ms-chat-product-card {
    flex: 0 0 220px !important;
    min-width: 220px !important;
    min-height: 200px !important;
    height: auto !important;
    scroll-snap-align: start;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    overflow: visible !important;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ms-chat-product-img {
    width: 100% !important;
    height: 110px !important;
    max-height: 110px;
    object-fit: cover;
    display: block;
}

.ms-chat-product-placeholder {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: #F3F4F6;
    color: #9CA3AF;
    height: 110px !important;
    min-height: 110px;
}

.ms-chat-product-info {
    padding: 8px 10px;
}

.ms-chat-product-name {
    font-size: 13px;
    font-weight: 600;
    color: #1A1A1A;
    line-height: 1.3;
    margin-bottom: 2px;
}

.ms-chat-product-desc {
    font-size: 11px;
    color: #6B7280;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 6px;
}

.ms-chat-product-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ms-chat-product-price {
    font-size: 13px;
    font-weight: 700;
    color: #1A1A1A;
}

.ms-chat-product-add {
    padding: 4px 12px;
    border: none;
    background: var(--ms-chat-color, #059669);
    color: white;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: filter 0.15s;
}

.ms-chat-product-add:hover:not(:disabled) {
    filter: brightness(1.1);
}

.ms-chat-product-add:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

a.ms-chat-product-link {
    text-decoration: none;
    display: inline-block;
}

/* ============================================
   COMMERCE: CART SUMMARY
   ============================================ */
.ms-chat-cart-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
}

.ms-chat-cart-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
}

.ms-chat-cart-info svg {
    color: #6B7280;
    flex-shrink: 0;
}

.ms-chat-cart-checkout {
    padding: 6px 16px;
    border: none;
    background: var(--ms-chat-color, #059669);
    color: white;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: filter 0.15s;
}

.ms-chat-cart-checkout:hover {
    filter: brightness(1.1);
}

/* ============================================
   COMMERCE: CHECKOUT CTA
   ============================================ */
.ms-chat-checkout-cta {
    padding: 4px 0;
}

.ms-chat-checkout-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: var(--ms-chat-color, #059669);
    color: white;
    text-align: center;
    text-decoration: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: filter 0.15s;
}

.ms-chat-checkout-btn:hover {
    filter: brightness(1.1);
    color: white;
}

/* ============================================
   MOBILE
   ============================================ */
@media (max-width: 640px) {
    .ms-chat-content {
        width: 100%;
        min-width: unset;
    }

    .ms-chat-trigger {
        padding: 12px 8px;
        font-size: 13px;
    }

    .ms-chat-pills {
        padding: 8px 12px;
    }

    /* Prevent iOS zoom on input focus */
    .ms-chat-input-area textarea {
        font-size: 16px;
    }

    /* Larger tap targets for product buttons */
    .ms-chat-product-add,
    a.ms-chat-product-link {
        padding: 8px 14px;
        font-size: 13px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .ms-chat-cart-checkout {
        padding: 8px 16px;
        font-size: 13px;
        min-height: 36px;
    }

    /* Smaller product cards on narrow screens */
    .ms-chat-product-card {
        flex: 0 0 180px !important;
        min-width: 180px !important;
        min-height: 180px !important;
    }

    .ms-chat-product-img,
    .ms-chat-product-placeholder {
        height: 90px !important;
        min-height: 90px;
    }

    .ms-chat-product-row {
        min-height: 180px !important;
    }

    /* Pill tap targets */
    .ms-chat-pill {
        padding: 8px 14px;
        font-size: 13px;
    }
}
