/*
 * chat-widget.css — customer-facing live-chat widget (order detail page).
 * Dark "Unlinkify Night" palette. Loaded via @push('head') on the order page.
 * Floating Intercom/Crisp-style popup: a fixed launcher (bottom-right) toggles
 * a fixed panel anchored just above it. Self-contained vars scoped to .ux-chat.
 */
.ux-chat {
    --chat-violet: #7C5CFF;
    --chat-cyan: #22D3EE;
    --chat-online: #2DD4A7;
    --chat-amber: #F5B14C;
    --chat-surface: #131828;
    --chat-surface-2: #1B2236;
    --chat-border: rgba(138, 148, 173, 0.18);
    --chat-text: #E8ECF4;
    --chat-muted: #8A94AD;

    /* Full-viewport, click-through positioning context. Its fixed children
       (launcher + panel) opt back into pointer events. Sits above page content
       but below Bootstrap modals (1055) / toasts. */
    position: fixed;
    inset: 0;
    z-index: 1040;
    pointer-events: none;
}

/* ---- Floating launcher (always visible) ------------------------------ */
.ux-chat-launcher {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    width: 62px;
    height: 62px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: #fff;
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--chat-violet), var(--chat-cyan));
    box-shadow: 0 14px 34px -10px rgba(124, 92, 255, 0.65), 0 6px 16px -8px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ux-chat-launcher > * { grid-area: 1 / 1; } /* stack icons in one cell */
.ux-chat-launcher:hover { transform: translateY(-2px) scale(1.04); }
.ux-chat-launcher:active { transform: scale(0.97); }
.ux-chat-launcher:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.45), 0 14px 34px -10px rgba(124, 92, 255, 0.65);
}
/* Icon swap: comment when collapsed, × when open. */
.ux-chat-launcher-shut { display: none; }
.ux-chat.is-open .ux-chat-launcher-open { display: none; }
.ux-chat.is-open .ux-chat-launcher-shut { display: block; }

.ux-chat-launcher .ux-chat-presence-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2px solid var(--chat-surface);
    background: var(--chat-amber);
}

/* Unread badge — shown only while collapsed with pending staff/system msgs. */
.ux-chat-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #FF4D6D;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--chat-surface);
    box-shadow: 0 3px 10px -2px rgba(0, 0, 0, 0.5);
}
.ux-chat-badge[hidden] { display: none; }
/* Hide the badge whenever the panel is open (belt-and-braces with JS reset). */
.ux-chat.is-open .ux-chat-badge { display: none; }

/* ---- Floating panel -------------------------------------------------- */
.ux-chat-panel {
    position: fixed;
    right: 1.5rem;
    bottom: calc(1.5rem + 62px + 0.9rem); /* clear the launcher */
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 3rem));
    height: min(620px, 80vh);
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.75), 0 10px 28px -14px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    transform-origin: bottom right;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.96);
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.25, 1), visibility 0s linear 0.2s;
}
.ux-chat.is-open .ux-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.25, 1), visibility 0s;
}

/* ---- Header ---------------------------------------------------------- */
.ux-chat-head {
    display: flex;
    align-items: center;
    gap: 0.95rem;
    padding: 1.25rem 1.35rem;
    border-bottom: 1px solid var(--chat-border);
    background: linear-gradient(135deg, rgba(124, 92, 255, 0.12), rgba(34, 211, 238, 0.06));
}
.ux-chat-avatar {
    position: relative;
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 1.35rem;
    background: linear-gradient(135deg, var(--chat-violet), var(--chat-cyan));
}
.ux-chat-avatar .ux-chat-presence-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    border: 2px solid var(--chat-surface);
    background: var(--chat-amber);
}
.ux-chat.is-online .ux-chat-avatar .ux-chat-presence-dot,
.ux-chat.is-online .ux-chat-launcher .ux-chat-presence-dot {
    background: var(--chat-online);
}
.ux-chat.is-online .ux-chat-avatar .ux-chat-presence-dot {
    box-shadow: 0 0 0 0 rgba(45, 212, 167, 0.55);
    animation: ux-chat-pulse 2s infinite;
}
.ux-chat-titles { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.ux-chat-title {
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
    color: var(--chat-text);
    line-height: 1.15;
}
.ux-chat-sub {
    font-size: 0.92rem;
    color: var(--chat-text);
    opacity: 0.82;
    line-height: 1.3;
}
.ux-chat-presence {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    margin-top: 0.15rem;
    color: var(--chat-muted);
}
.ux-chat-presence .ux-chat-presence-mini {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-amber);
    flex: 0 0 auto;
}
.ux-chat.is-online .ux-chat-presence { color: var(--chat-online); font-weight: 600; }
.ux-chat.is-online .ux-chat-presence .ux-chat-presence-mini { background: var(--chat-online); }

/* Header action buttons (mute + minimize), grouped top-right. */
.ux-chat-head-actions {
    flex: 0 0 auto;
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.ux-chat-mute {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--chat-muted);
    background: rgba(255, 255, 255, 0.06);
    transition: background 0.15s ease, color 0.15s ease;
}
.ux-chat-mute:hover { background: rgba(255, 255, 255, 0.13); color: var(--chat-text); }
.ux-chat-mute:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.4); }
.ux-chat-mute > * { grid-area: 1 / 1; }
.ux-chat-mute .ux-chat-mute-off { display: none; }
.ux-chat.is-muted .ux-chat-mute { color: var(--chat-amber); }
.ux-chat.is-muted .ux-chat-mute .ux-chat-mute-on { display: none; }
.ux-chat.is-muted .ux-chat-mute .ux-chat-mute-off { display: block; }

/* Minimize / close button in the panel header. */
.ux-chat-close {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--chat-muted);
    background: rgba(255, 255, 255, 0.06);
    transition: background 0.15s ease, color 0.15s ease;
}
.ux-chat-close:hover { background: rgba(255, 255, 255, 0.13); color: var(--chat-text); }
.ux-chat-close:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.4); }

/* ---- Thread ---------------------------------------------------------- */
.ux-chat-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    padding: 1rem 1.05rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    scrollbar-width: thin;
    scrollbar-color: var(--chat-border) transparent;
}
.ux-chat-thread::-webkit-scrollbar { width: 8px; }
.ux-chat-thread::-webkit-scrollbar-thumb { background: var(--chat-border); border-radius: 8px; }

.ux-chat-msg {
    max-width: 82%;
    padding: 0.55rem 0.8rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--chat-text);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
/* staff / inbound on the left */
.ux-chat-msg.is-staff {
    align-self: flex-start;
    background: var(--chat-surface-2);
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
}
/* customer / outbound on the right */
.ux-chat-msg.is-me {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--chat-violet), #6D4DF2);
    border-bottom-right-radius: 4px;
    color: #fff;
}
/* system messages, distinct centred pill */
.ux-chat-msg.is-system {
    align-self: center;
    max-width: 90%;
    text-align: center;
    background: rgba(34, 211, 238, 0.08);
    border: 1px dashed rgba(34, 211, 238, 0.35);
    color: var(--chat-cyan);
    font-size: 0.78rem;
    border-radius: 10px;
    padding: 0.4rem 0.75rem;
}
.ux-chat-msg-meta {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.66rem;
    opacity: 0.7;
    letter-spacing: 0.01em;
}
.ux-chat-msg.is-system .ux-chat-msg-meta { display: none; }

/* ---- "Support is typing…" indicator ---------------------------------- */
.ux-chat-typing {
    align-self: flex-start;
    display: none;
    align-items: center;
    gap: 0.5rem;
    max-width: 82%;
    padding: 0.5rem 0.8rem;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    background: var(--chat-surface-2);
    border: 1px solid var(--chat-border);
    color: var(--chat-muted);
    font-size: 0.8rem;
}
.ux-chat-typing.is-visible { display: inline-flex; }
.ux-chat-typing-dots { display: inline-flex; align-items: flex-end; gap: 3px; }
.ux-chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-muted);
    animation: ux-chat-typing-bounce 1.2s infinite ease-in-out;
}
.ux-chat-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.ux-chat-typing-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes ux-chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .ux-chat-typing-dots span { animation: none; opacity: 0.7; }
}

.ux-chat-empty {
    margin: auto;
    text-align: center;
    color: var(--chat-muted);
    font-size: 0.85rem;
    padding: 1.5rem 1rem;
}
.ux-chat-empty i { font-size: 1.6rem; color: var(--chat-violet); display: block; margin-bottom: 0.5rem; }

/* ---- Composer -------------------------------------------------------- */
.ux-chat-composer {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.75rem 0.85rem;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-surface);
}
.ux-chat-composer-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}
.ux-chat-composer textarea {
    flex: 1 1 auto;
    resize: none;
    max-height: 120px;
    min-height: 42px;
    padding: 0.55rem 0.75rem;
    font-size: 0.88rem;
    color: var(--chat-text);
    background: var(--chat-surface-2);
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    outline: none;
    line-height: 1.35;
}
.ux-chat-composer textarea::placeholder { color: var(--chat-muted); }
.ux-chat-composer textarea:focus {
    border-color: var(--chat-violet);
    box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.25);
}
.ux-chat-send {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 0.95rem;
    cursor: pointer;
    background: linear-gradient(135deg, var(--chat-violet), var(--chat-cyan));
    transition: transform 0.08s ease, opacity 0.15s ease;
}
.ux-chat-send:hover { transform: translateY(-1px); }
.ux-chat-send:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ---- Staged-attachment preview strip (composer) ---------------------- */
.ux-chat-attach {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.55rem;
    background: var(--chat-surface-2);
    border: 1px solid var(--chat-border);
    border-radius: 12px;
}
.ux-chat-attach[hidden] { display: none; }
.ux-chat-attach-thumb {
    position: relative;
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.25);
}
.ux-chat-attach-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.ux-chat-attach-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 2px solid var(--chat-surface);
    border-radius: 50%;
    display: grid;
    place-items: center;
    line-height: 1;
    font-size: 0.85rem;
    color: #fff;
    background: #FF4D6D;
    cursor: pointer;
}
.ux-chat-attach-remove:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.5); }
.ux-chat-attach-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.8rem;
    color: var(--chat-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Attachments inside message bubbles ------------------------------ */
.ux-chat-msg.has-attachment { padding: 0.4rem; }
.ux-chat-msg-body { white-space: pre-wrap; }
.ux-chat-msg.has-attachment .ux-chat-msg-body {
    display: block;
    padding: 0.2rem 0.4rem 0.1rem;
}
.ux-chat-img {
    display: block;
    border-radius: 10px;
    overflow: hidden;
}
.ux-chat-img img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 10px;
}
.ux-chat-file {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.65rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.22);
    text-decoration: none;
    color: var(--chat-text);
    max-width: 260px;
}
.ux-chat-msg.is-me .ux-chat-file { background: rgba(255, 255, 255, 0.14); color: #fff; }
.ux-chat-file:hover { background: rgba(0, 0, 0, 0.32); }
.ux-chat-file-icon {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 1rem;
    color: var(--chat-cyan);
    background: rgba(34, 211, 238, 0.12);
}
.ux-chat-file-meta { display: flex; flex-direction: column; min-width: 0; }
.ux-chat-file-name {
    font-size: 0.82rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ux-chat-file-size { font-size: 0.7rem; opacity: 0.7; }

/* ---- Drag-and-drop highlight over the panel -------------------------- */
.ux-chat-drop {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(19, 24, 40, 0.86);
    border: 2px dashed var(--chat-violet);
    border-radius: 16px;
    pointer-events: none;
}
.ux-chat.is-dragover .ux-chat-drop { display: flex; }
.ux-chat-drop-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--chat-text);
    font-size: 0.9rem;
    font-weight: 600;
}
.ux-chat-drop-inner i { font-size: 2rem; color: var(--chat-violet); }

/* ---- Launcher preview bubble (red speech bubble) --------------------- */
.ux-chat-peek {
    position: fixed;
    right: 1.5rem;
    bottom: calc(1.5rem + 62px + 0.7rem); /* just above the launcher */
    z-index: 1041;
    max-width: min(300px, calc(100vw - 3rem));
    margin: 0;
    padding: 0.7rem 0.9rem;
    border: 0;
    border-radius: 14px 14px 4px 14px;
    text-align: left;
    color: #fff;
    background: #E5384E;
    box-shadow: 0 14px 30px -12px rgba(229, 56, 78, 0.7), 0 6px 16px -8px rgba(0, 0, 0, 0.55);
    cursor: pointer;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(8px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.25, 1);
}
.ux-chat-peek[hidden] { display: none; }
.ux-chat-peek.is-visible { opacity: 1; transform: translateY(0) scale(1); }
.ux-chat-peek::after { /* little tail pointing at the launcher */
    content: '';
    position: absolute;
    right: 18px;
    bottom: -6px;
    width: 12px;
    height: 12px;
    background: #E5384E;
    transform: rotate(45deg);
    border-radius: 0 0 3px 0;
}
.ux-chat-peek-text {
    display: block;
    position: relative;
    z-index: 1;
    font-size: 0.85rem;
    line-height: 1.35;
    color: #fff;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
/* Hide the preview bubble whenever the panel is open. */
.ux-chat.is-open .ux-chat-peek { display: none; }

/* ---- Guest "sign in to chat" card ----------------------------------- */
.ux-chat-signin {
    text-align: center;
    padding: 0.5rem 0.25rem 0.25rem;
}
.ux-chat-signin .ux-chat-avatar { margin: 0 auto 0.75rem; }

@keyframes ux-chat-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(45, 212, 167, 0.5); }
    70%  { box-shadow: 0 0 0 7px rgba(45, 212, 167, 0); }
    100% { box-shadow: 0 0 0 0 rgba(45, 212, 167, 0); }
}

/* ---- Mobile: full-screen panel --------------------------------------- */
@media (max-width: 575.98px) {
    .ux-chat-panel {
        right: 0;
        left: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        height: 92vh;
        height: 92dvh;
        border-radius: 18px 18px 0 0;
        transform-origin: bottom center;
        transform: translateY(16px) scale(0.99);
    }
    .ux-chat.is-open .ux-chat-panel { transform: none; }
    .ux-chat-launcher { right: 1rem; bottom: 1rem; }
    .ux-chat-peek { right: 1rem; bottom: calc(1rem + 62px + 0.7rem); }
    /* Panel fills the screen; the header chevron is the minimize control, so
       the FAB would only overlap the composer — hide it while open. */
    .ux-chat.is-open .ux-chat-launcher { display: none; }
}

/* ---- Reduced motion -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .ux-chat-launcher,
    .ux-chat-panel { transition: opacity 0.01ms linear; }
    .ux-chat-launcher:hover,
    .ux-chat-launcher:active { transform: none; }
    .ux-chat.is-online .ux-chat-avatar .ux-chat-presence-dot { animation: none; }
    .ux-chat-panel { transform: none; }
    .ux-chat.is-open .ux-chat-panel { transform: none; }
    .ux-chat-peek { transition: opacity 0.01ms linear; transform: none; }
    .ux-chat-peek.is-visible { transform: none; }
}
