/**
 * Weiwei Assistant - global floating chat widget chrome.
 * Structure: a fixed bottom-right floating icon (#weiwei-fab) with a
 * rotating speech bubble above it (#weiwei-bubble), opening a slide-in
 * chat panel (#weiwei-panel) - a third of the viewport width on desktop,
 * the large majority of the viewport on mobile.
 */

#weiwei-assistant-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2147483000; /* above virtually everything else on the page, including other fixed widgets */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#weiwei-fab {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    overflow: hidden;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    flex-shrink: 0;
}

#weiwei-fab:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

#weiwei-fab img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Speech bubble with rotating suggestions, sitting above the icon. */
.weiwei-bubble {
    max-width: 240px;
    background: #fff;
    color: #222;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    position: relative;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}

.weiwei-bubble.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#weiwei-assistant-root.is-open .weiwei-bubble {
    display: none;
}

/* Backdrop (mobile mainly, where the panel takes most of the screen). */
.weiwei-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 2147482998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

#weiwei-assistant-root.is-open .weiwei-panel-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.weiwei-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: clamp(320px, 33vw, 480px);
    background: #f7f9fc;
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.18);
    z-index: 2147482999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

#weiwei-assistant-root.is-open .weiwei-panel {
    transform: translateX(0);
}

/* Mobile/tablet event detail pages (event_detail_mobile.blade.php, served
   by server-side user-agent detection rather than a CSS breakpoint - see
   event_detail.blade.php) have their own full-width sticky action footer
   (.mb-register-div - Register/Inquire/Review/Gallery/Results/Donate,
   stacked, height varies per event) fixed to the bottom of the screen. A
   generous bottom offset here keeps the widget clear of it in the common
   case; this is a best-effort estimate (that footer's real height isn't
   knowable from CSS alone across every event) - worth a final visual check
   on a real device/event with every optional button present. */
@media (max-width: 768px) {
    #weiwei-assistant-root {
        bottom: 90px;
    }
}

@media (max-width: 720px) {
    .weiwei-panel {
        width: 92vw;
    }
}

.weiwei-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #0057A0, #1e88d8);
    color: #fff;
    flex-shrink: 0;
}

.weiwei-panel-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
}

.weiwei-panel-title {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.weiwei-panel-title strong {
    font-size: 15px;
    line-height: 1.2;
}

.weiwei-panel-title span {
    font-size: 12px;
    opacity: 0.85;
}

#weiwei-panel-close,
#weiwei-escalate-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    opacity: 0.9;
}

#weiwei-panel-close {
    font-size: 24px;
}

#weiwei-escalate-btn:hover,
#weiwei-panel-close:hover {
    opacity: 1;
}

.weiwei-rating-prompt {
    align-self: center;
    background: #fff;
    border: 1px solid #e3e8f0;
    border-radius: 12px;
    padding: 10px 14px;
    text-align: center;
    font-size: 12.5px;
    color: #556;
    max-width: 90%;
}

.weiwei-rating-stars {
    margin-top: 6px;
    font-size: 20px;
}

.weiwei-rating-stars button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 3px;
    opacity: 0.4;
    filter: grayscale(1);
}

.weiwei-rating-stars button:hover,
.weiwei-rating-stars button:hover ~ button {
    opacity: 1;
    filter: none;
}

.weiwei-rating-stars button.is-selected,
.weiwei-rating-stars button.is-selected ~ button {
    opacity: 1;
    filter: none;
}

.weiwei-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.weiwei-msg {
    max-width: 85%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.weiwei-msg.is-user {
    align-self: flex-end;
    background: #0057A0;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.weiwei-msg.is-assistant {
    align-self: flex-start;
    background: #fff;
    color: #222;
    border: 1px solid #e3e8f0;
    border-bottom-left-radius: 4px;
}

.weiwei-msg.is-typing {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e3e8f0;
    color: #999;
    font-style: italic;
}

.weiwei-event-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
    align-self: stretch;
}

.weiwei-event-card {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
    border: 1px solid #e3e8f0;
    border-radius: 10px;
    padding: 8px;
    text-decoration: none;
    color: #222;
}

.weiwei-event-card:hover {
    border-color: #0057A0;
    text-decoration: none;
    color: #222;
}

.weiwei-event-card img {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    background: #eee;
    flex-shrink: 0;
}

.weiwei-event-card-body {
    min-width: 0;
}

.weiwei-event-card-title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.weiwei-event-card-meta {
    font-size: 11.5px;
    color: #667;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.weiwei-panel-input {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e3e8f0;
    background: #fff;
    flex-shrink: 0;
}

.weiwei-panel-input input {
    flex: 1;
    border: 1px solid #d7dee8;
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 13.5px;
    outline: none;
}

.weiwei-panel-input input:focus {
    border-color: #0057A0;
}

.weiwei-panel-input button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: #0057A0;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
}

.weiwei-panel-input button:disabled {
    opacity: 0.5;
    cursor: default;
}

@media (max-width: 480px) {
    #weiwei-assistant-root {
        right: 14px;
    }
    #weiwei-fab {
        width: 56px;
        height: 56px;
    }
}
