/* Reseller Chat — customer-facing widget. Rendered on reseller storefronts
   (NOT on reuzeit.com — the bot stays there). Conditional include lives in
   views/layouts/main.php gated on Yii::$app->params['reseller']['enabled'].

   Visual language mirrors the Reuzeit "Support live Chat" bot widget
   (defined in global.css), but every colored surface uses CSS custom
   properties so each reseller's --primary/--primary-gradient theme paints
   the header + bubble in their own brand color.

   Layout:
     [floating bubble (closed) / X close (open) at bottom-right]
     [panel]
       [header: gradient + title + sparkle]
       [pill row: "support" tag]
       [body: empty-state illustration OR list of message rows]
         each row = [avatar circle (initial)] [name / text / timestamp]
       [input row: text input + paper-plane send] */

.rsl-chat-root,
.rsl-chat-root * {
    box-sizing: border-box;
}

/* Hard yield to the AI-Chat shop/support widget — the moment ANY .chat-box
   exists on the page (Reuzeit bot or AI-Chat product-search widget on
   shop/category pages), hide our standalone widget so the page never shows
   two stacked chat icons. This is the CSS-only safety net; the JS-side
   MutationObserver in reseller-chat-widget.js also tears the widget down
   when .chat-box is injected after our boot. Together they cover initial
   render, AJAX/pjax page swaps, and stale-state cases.
   :has() requires Chrome 105+ / Safari 15.4+ / Firefox 121+ — covers all
   evergreen browsers from late 2023 forward. */
body:has(.chat-box) .rsl-chat-root { display: none !important; }

.rsl-chat-root {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    /* Stack children top-down: panel first, X close button below it.
       align-items:flex-end keeps the X aligned to the right edge of the
       panel above it. */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #17181A;
}

/* Floating launcher — collapsed state. Gradient circle matches the
   support widget's .chat-box-btn. */
.rsl-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(90deg, var(--primary, #174E76), var(--primary-gradient, var(--primary, #174E76)));
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    position: relative;
}
.rsl-chat-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24);
}
.rsl-chat-bubble svg {
    width: 28px;
    height: 28px;
    stroke: #fff;
}
.rsl-chat-bubble .rsl-chat-unread-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #EF4444;
    border: 2px solid #fff;
    display: none;
}
.rsl-chat-bubble.has-unread .rsl-chat-unread-dot { display: block; }

/* Floating X close — appears UNDER the panel when the chat is open
   (matches Reuzeit Support widget). Centered horizontally below the panel
   with margin-top spacing. */
.rsl-chat-close-floating {
    display: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(90deg, var(--primary, #174E76), var(--primary-gradient, var(--primary, #174E76)));
    color: #fff;
    border: none;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    margin: 10px 0 0 auto;
}
.rsl-chat-close-floating:hover { transform: translateY(-2px); }
.rsl-chat-close-floating svg { width: 22px; height: 22px; stroke: #fff; }

/* Panel — expanded state. */
.rsl-chat-panel {
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.rsl-chat-root.open .rsl-chat-panel        { display: flex; }
.rsl-chat-root.open .rsl-chat-bubble       { display: none; }
.rsl-chat-root.open .rsl-chat-close-floating { display: flex; }

/* Header — gradient brand band with title + sparkle. */
.rsl-chat-header {
    background: linear-gradient(90deg, var(--primary, #174E76), var(--primary-gradient, var(--primary, #174E76)));
    color: #fff;
    padding: 16px 20px;
    flex-shrink: 0;
}
.rsl-chat-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}
.rsl-chat-header-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}
.rsl-chat-sparkle {
    width: 18px;
    height: 18px;
    color: #fff;
    opacity: 0.95;
}

/* Pill row — sits below the header, on the white surface. */
.rsl-chat-pill-row {
    background: #fff;
    padding: 10px 16px 6px;
    flex-shrink: 0;
}
.rsl-chat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: #fff;
    color: var(--primary, #174E76);
    border: 1px solid #E5E7EB;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    font-size: 13px;
    font-weight: 500;
}
.rsl-chat-pill svg { width: 14px; height: 14px; stroke: var(--primary, #174E76); }

/* Body — message list / empty state. */
.rsl-chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    background: #F3F4F6;
    padding: 12px 16px;
}
.rsl-chat-messages { display: flex; flex-direction: column; gap: 10px; }

/* Empty state — inline brand-color SVG + soft pitch text, centered. */
.rsl-chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 12px 40px;
    color: var(--primary, #174E76);   /* SVG inherits via currentColor */
    min-height: 280px;
}
.rsl-chat-empty-illu {
    width: 140px;
    height: 140px;
    display: block;
    margin: 0 auto 14px;
}
.rsl-chat-empty-text {
    margin: 0 auto;
    font-size: 14px;
    line-height: 1.5;
    color: #6B7280;
    max-width: 240px;
}

/* Message row — avatar + content stack. */
.rsl-chat-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.rsl-chat-message-content { flex: 1; min-width: 0; }

/* Agent rows: white card background for visual separation. Customer
   rows stay transparent on the gray body (matches the support widget
   which renders the visitor's own lines as plain text). */
.rsl-chat-message-agent {
    background: #fff;
    padding: 10px 12px;
    border-radius: 14px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.rsl-chat-avatar {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
/* Role-based avatar palette — mirrors the AI-Chat / Reuzeit Support
   widget so customer rows always read as orange and agent rows as a
   light-gray chip with brand-color initial, regardless of which page
   the widget is on. */
.rsl-chat-avatar-customer { background: #F27830; color: #FFF1E9; }
.rsl-chat-avatar-agent    { background: #F3F3F3; color: var(--primary, #174E76); }

.rsl-chat-name {
    font-weight: 700;
    color: #17181A;
    font-size: 14px;
    line-height: 18px;
}
.rsl-chat-text {
    font-size: 14px;
    line-height: 20px;
    color: #17181A;
    margin-top: 2px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.rsl-chat-timestamp {
    font-size: 11px;
    color: #9CA3AF;
    margin-top: 6px;
}

/* "Seen" receipt tag — appears under the customer's last bubble when
   admin opens the chat. */
.rsl-chat-seen-tag {
    font-size: 10px;
    color: var(--primary, #174E76);
    font-weight: 600;
    margin-top: 4px;
    text-align: left;
}

/* Typing hint — sits just above the input row. */
.rsl-chat-typing-hint {
    font-size: 12px;
    color: #878D99;
    font-style: italic;
    padding: 4px 16px 0;
    background: #fff;
}

/* Input row — pill-shaped text input + circular send button. */
.rsl-chat-input-bar {
    display: none;
    border-top: 1px solid #E5E7EB;
    background: #fff;
    padding: 10px 12px;
    gap: 8px;
    flex-shrink: 0;
    align-items: center;
}
.rsl-chat-root.open .rsl-chat-input-bar { display: flex; }
.rsl-chat-input {
    flex: 1;
    height: 38px;
    padding: 0 14px;
    border: 1px solid #E5E7EB;
    border-radius: 999px;
    font-size: 14px;
    font-family: inherit;
    background: #F9FAFB;
    color: #17181A;
    outline: none;
}
.rsl-chat-input::placeholder { color: #9CA3AF; }
.rsl-chat-input:focus {
    border-color: var(--primary, #174E76);
    background: #fff;
}
.rsl-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--primary-light, rgba(23, 78, 118, 0.12));
    color: var(--primary, #174E76);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.rsl-chat-send:hover {
    background: var(--primary, #174E76);
    color: #fff;
}
.rsl-chat-send svg { width: 18px; height: 18px; fill: currentColor; }
.rsl-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Compact mobile */
@media (max-width: 480px) {
    .rsl-chat-root { bottom: 12px; right: 12px; }
    .rsl-chat-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 120px);
        max-height: calc(100vh - 120px);
    }
}
