/* =====================================================================
   Contact widget — floating WeChat QR card.
   Self-contained: uses the site's brand vars where available (index.html)
   and falls back to hardcoded values on the standalone legal pages.
   State is driven by a class on <html> (html.cw-collapsed) so a tiny
   inline head-script can set it pre-paint and avoid a flash.
   ===================================================================== */

.cw {
    /* anchor point at the top-right corner; children position from here */
    position: fixed;
    top: 96px;
    right: 22px;
    z-index: 900;
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    letter-spacing: -0.011em;

    --cw-wechat: #07c160;
    --cw-wechat-dark: #06ad56;
    --cw-text: var(--text-primary, #0f172a);
    --cw-text-soft: var(--text-secondary, #475569);
    --cw-text-faint: var(--text-light, #94a3b8);
    --cw-hairline: var(--hairline, rgba(15, 23, 42, 0.08));
}

/* ---- Collapsed: round WeChat bubble ---- */
.cw-bubble {
    position: absolute;
    top: 0;
    right: 0;
    display: none;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(135deg, #07c160 0%, #06ad56 100%);
    color: #fff;
    box-shadow: 0 10px 28px rgba(7, 193, 96, 0.38), 0 2px 6px rgba(15, 23, 42, 0.10);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s;
}

.cw-bubble:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 14px 34px rgba(7, 193, 96, 0.46);
}

.cw-bubble svg {
    width: 28px;
    height: 28px;
}

.cw-bubble-tip {
    position: absolute;
    bottom: -22px;
    right: 50%;
    transform: translateX(50%);
    white-space: nowrap;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: rgba(15, 23, 42, 0.82);
    padding: 3px 8px;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.cw-bubble:hover .cw-bubble-tip {
    opacity: 1;
}

/* ---- Expanded: QR card ---- */
.cw-card {
    position: absolute;
    top: 0;
    right: 0;
    width: 212px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--cw-hairline);
    border-radius: 18px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.12), 0 4px 12px rgba(15, 23, 42, 0.06);
    transform-origin: top right;
    animation: cw-pop 0.28s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes cw-pop {
    from { opacity: 0; transform: scale(0.92) translateY(-6px); }
    to   { opacity: 1; transform: none; }
}

.cw-head {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 11px;
}

.cw-head-icon {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(7, 193, 96, 0.12);
    color: var(--cw-wechat);
}

.cw-head-icon svg {
    width: 19px;
    height: 19px;
}

.cw-head-text {
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}

.cw-head-text strong {
    display: block;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--cw-text);
}

.cw-head-text span {
    display: block;
    font-size: 11px;
    color: var(--cw-text-faint);
}

.cw-min {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: rgba(15, 23, 42, 0.06);
    color: var(--cw-text-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.cw-min:hover {
    background: rgba(15, 23, 42, 0.12);
    color: var(--cw-text);
}

.cw-min svg {
    width: 15px;
    height: 15px;
}

.cw-qr {
    background: #fff;
    border-radius: 12px;
    padding: 8px;
    box-shadow: inset 0 0 0 1px var(--cw-hairline);
}

.cw-qr img {
    display: block;
    width: 100%;
    /* Personal WeChat "name card" QR is portrait (taller than wide),
       so show the whole thing instead of cropping to a square. */
    height: 220px;
    object-fit: contain;
    border-radius: 8px;
}

.cw-caption {
    margin: 10px 2px 0;
    font-size: 12.5px;
    color: var(--cw-text-soft);
    text-align: center;
    line-height: 1.4;
}

.cw-note {
    margin: 4px 2px 0;
    font-size: 11px;
    color: var(--cw-text-faint);
    text-align: center;
}

/* ---- State: which face is visible ---- */
.cw-card { display: block; }
.cw-bubble { display: none; }

html.cw-collapsed .cw-card { display: none; }
html.cw-collapsed .cw-bubble { display: flex; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .cw {
        top: 78px;
        right: 14px;
    }

    .cw-bubble {
        width: 50px;
        height: 50px;
    }

    .cw-bubble svg {
        width: 26px;
        height: 26px;
    }

    .cw-card {
        width: min(74vw, 220px);
    }

    .cw-qr img {
        height: 200px;
    }
}

@media (max-width: 380px) {
    .cw-card {
        width: min(82vw, 230px);
    }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    .cw-card,
    .cw-bubble,
    .cw-bubble-tip {
        animation: none !important;
        transition: none !important;
    }
}
