/* ============================================================
   Masu Chatbot - frontend widget styles
   Professional, modern, mobile-friendly. Scoped under #masu-chat-*
   ============================================================ */

#masu-chat-root,
#masu-chat-root * {
    box-sizing: border-box;
}

#masu-chat-root {
    --masu-primary:       #4f46e5;
    --masu-primary-dark:  #4338ca;
    --masu-accent:        #7c3aed;
    --masu-bg:            #ffffff;
    --masu-bg-alt:        #f8fafc;
    --masu-text:          #0f172a;
    --masu-muted:         #64748b;
    --masu-bot-bubble:    #ffffff;
    --masu-bot-border:    #e2e8f0;
    --masu-border:        #e2e8f0;
    --masu-shadow:        0 18px 50px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.06);
    --masu-online:        #10b981;
    --masu-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

/* ---------- Floating button ---------- */
#masu-chat-button {
    position: fixed;
    right: 24px;
    bottom: 100px;
    z-index: 99998;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.42), 0 4px 10px rgba(0, 0, 0, 0.10);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    font-family: var(--masu-font);
}
#masu-chat-button:hover {
    transform: scale(1.07);
    box-shadow: 0 14px 30px rgba(79, 70, 229, 0.55), 0 6px 14px rgba(0, 0, 0, 0.14);
}
#masu-chat-button:active { transform: scale(0.96); }
#masu-chat-button:focus { outline: none; box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.35), 0 10px 24px rgba(79, 70, 229, 0.42); }
#masu-chat-button svg.masu-bot-icon { width: 34px; height: 34px; position: relative; z-index: 2; }
#masu-chat-button .masu-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(124, 58, 237, 0.35);
    animation: masu-pulse 2.4s ease-out infinite;
    pointer-events: none;
}
#masu-chat-button.masu-is-open .masu-pulse { display: none; }
@keyframes masu-pulse {
    0%   { transform: scale(1);   opacity: 0.6; }
    100% { transform: scale(1.6); opacity: 0; }
}
#masu-chat-button .masu-toggle-close {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
}
#masu-chat-button.masu-is-open .masu-bot-icon { display: none; }
#masu-chat-button.masu-is-open .masu-toggle-close { display: flex; }
#masu-chat-button .masu-toggle-close svg { width: 22px; height: 22px; color: #fff; }

/* ---------- Chat window ---------- */
#masu-chat-window {
    position: fixed;
    right: 24px;
    bottom: 102px;
    z-index: 99999;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--masu-bg);
    border-radius: 18px;
    box-shadow: var(--masu-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--masu-font);
    color: var(--masu-text);
    transform: translateY(14px) scale(0.98);
    opacity: 0;
    transition: transform 0.22s ease, opacity 0.22s ease;
    border: 1px solid rgba(15, 23, 42, 0.06);
}
#masu-chat-window.masu-open {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ---------- Header ---------- */
.masu-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}
.masu-header .masu-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
    border: 2px solid rgba(255, 255, 255, 0.25);
}
.masu-header .masu-avatar svg { width: 24px; height: 24px; }
.masu-header .masu-title { flex: 1; line-height: 1.25; }
.masu-header .masu-title .name { font-weight: 700; font-size: 15px; letter-spacing: 0.1px; }
.masu-header .masu-title .status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}
.masu-header .masu-title .status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--masu-online);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.35);
}
.masu-header .masu-close {
    background: transparent;
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.masu-header .masu-close:hover { background: rgba(255, 255, 255, 0.2); }
.masu-header .masu-close svg { width: 18px; height: 18px; }

/* ---------- Body / messages ---------- */
.masu-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    background: var(--masu-bg-alt);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.masu-body::-webkit-scrollbar { width: 6px; }
.masu-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.masu-body::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.masu-msg { display: flex; max-width: 86%; animation: masu-fadeIn 0.22s ease-out; }
.masu-msg.bot  { align-self: flex-start; }
.masu-msg.user { align-self: flex-end; }

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

.masu-bubble {
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.48;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.masu-msg.bot .masu-bubble {
    background: var(--masu-bot-bubble);
    color: var(--masu-text);
    border: 1px solid var(--masu-bot-border);
    border-bottom-left-radius: 4px;
}
.masu-msg.user .masu-bubble {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* typing indicator */
.masu-typing { display: inline-flex; gap: 4px; padding: 2px 2px; }
.masu-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: masu-dot 1.2s infinite ease-in-out;
}
.masu-typing span:nth-child(2) { animation-delay: 0.15s; }
.masu-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes masu-dot {
    0%, 60%, 100% { transform: translateY(0);   opacity: 0.55; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Footer (input) ---------- */
.masu-footer {
    border-top: 1px solid var(--masu-border);
    padding: 10px 12px 12px;
    background: #fff;
    flex: 0 0 auto;
}
.masu-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid var(--masu-border);
    border-radius: 14px;
    padding: 6px 6px 6px 12px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.masu-input-row:focus-within {
    border-color: var(--masu-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
    background: #fff;
}
.masu-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    color: var(--masu-text);
    padding: 8px 0;
    max-height: 120px;
    line-height: 1.4;
}
.masu-input::placeholder { color: #94a3b8; }
.masu-send {
    border: none;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
    flex: 0 0 36px;
}
.masu-send:disabled { opacity: 0.5; cursor: not-allowed; }
.masu-send:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(79, 70, 229, 0.35); }
.masu-send svg { width: 18px; height: 18px; }

.masu-foot-meta {
    font-size: 11px;
    color: var(--masu-muted);
    text-align: center;
    margin-top: 8px;
    letter-spacing: 0.2px;
}

.masu-char-counter {
    font-size: 11px;
    color: var(--masu-muted);
    text-align: right;
    margin-top: 4px;
    height: 14px;
}
.masu-char-counter.masu-over { color: #b91c1c; font-weight: 600; }

/* ---------- Attach button ---------- */
.masu-attach {
    width: 36px; height: 36px;
    flex: 0 0 36px;
    background: #f1f5f9;
    color: #475569;
    border: none;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.masu-attach:hover { background: #e2e8f0; color: #1e293b; }
.masu-attach svg { width: 18px; height: 18px; }

.masu-upload img { max-width: 220px; border-radius: 10px; display: block; }
.masu-upload a { color: var(--masu-primary, #4f46e5); word-break: break-all; }

/* ---------- Rich bot messages ---------- */
.masu-rich-intro { margin: 0 0 8px; font-weight: 600; color: #1e293b; }
.masu-hint       { margin: 8px 0 0; font-size: 12px; color: #64748b; }

/* Product card grid */
.masu-products {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin: 6px 0;
}
.masu-pcard {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.masu-pcard:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
    border-color: #c7d2fe;
}
.masu-pcard-img {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #f8fafc center/cover no-repeat;
    display: block;
}
.masu-pcard-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.masu-pcard-body { padding: 8px 10px 10px; }
.masu-pcard-num {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    background: #4f46e5;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    padding: 0 6px;
    margin-bottom: 4px;
}
.masu-pcard-title {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.35;
    margin: 0 0 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.masu-pcard-price {
    font-size: 13px;
    color: #15803d;
    font-weight: 700;
}
/* Blue "View product →" link inside each card so the card is clearly clickable. */
.masu-pcard-link {
    display: inline-block;
    margin-top: 6px;
    color: #1d4ed8;
    text-decoration: underline;
    font-weight: 600;
    font-size: 13px;
}
.masu-pcard:hover .masu-pcard-link { color: #1e40af; }

/* Make any plain <a> inside a bot bubble visibly blue + underlined too. */
.masu-msg.bot .masu-bubble a,
.masu-rich a {
    color: #1d4ed8;
    text-decoration: underline;
}
.masu-msg.bot .masu-bubble a:hover,
.masu-rich a:hover { color: #1e40af; }
/* Card itself shouldn't get default underline (its <span> link handles it). */
.masu-msg.bot .masu-bubble a.masu-pcard,
.masu-rich a.masu-pcard { text-decoration: none; color: inherit; }

/* Tracking */
.masu-track {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 6px 0;
    font-size: 13px;
}
.masu-track-head { font-weight: 700; color: #1e293b; margin-bottom: 6px; }
.masu-track-events {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    border-left: 2px solid #c7d2fe;
}
.masu-track-events li {
    position: relative;
    padding: 4px 0 4px 14px;
    color: #334155;
}
.masu-track-events li::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 10px;
    width: 8px; height: 8px;
    background: #4f46e5;
    border-radius: 50%;
}
.masu-track-events .masu-track-time { color: #64748b; font-size: 11px; }

/* Orders list */
.masu-orders {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: 6px 0;
}
.masu-orders th, .masu-orders td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid #e2e8f0;
}
.masu-orders th { background: #f1f5f9; font-weight: 600; }
.masu-orders a  { color: #4f46e5; text-decoration: none; }

/* Cart confirmation / CTA */
.masu-cart-confirm {
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 6px 0;
    font-size: 13px;
    color: #065f46;
}
.masu-cta {
    display: inline-block;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff !important;
    text-decoration: none;
    padding: 9px 16px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 13px;
    margin-top: 6px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    transition: transform .12s ease, box-shadow .12s ease;
}
.masu-cta:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4); }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
    #masu-chat-window {
        right: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        bottom: 90px;
        height: calc(100vh - 110px);
        border-radius: 16px;
    }
    #masu-chat-button {
        right: 20px;
        bottom: 110px;
        width: 56px;
        height: 56px;
    }
}
