/* HY Support — Front-end Chat Widget (refined visual language) */

#hys-root, #hys-root * { box-sizing: border-box; }
#hys-root *, #hys-root *::before, #hys-root *::after {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#hys-root {
    position: fixed;
    z-index: 99990;
    bottom: 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: #0e1a26;
    --hys-c1: var(--hys-color, #1f2a44);
    --hys-c2: var(--hys-accent, #b9863e);
    /* Derived neutrals */
    --hys-bg-soft:  #fbfaf7;
    --hys-card:     #ffffff;
    --hys-text:     #1a2332;
    --hys-text-2:   #56657a;
    --hys-text-3:   #8a96a8;
    --hys-line:     #ece8df;
    --hys-line-2:   #f4efe5;
    --hys-shadow-1: 0 1px 2px rgba(14,26,38,.04);
    --hys-shadow-2: 0 8px 24px -10px rgba(14,26,38,.18);
    --hys-shadow-3: 0 18px 40px -18px rgba(0,0,0,.45);
}
#hys-root[data-pos="right"] { right: 24px; }
#hys-root[data-pos="left"]  { left: 24px; }

/* ================== Toggle FAB ================== */
.hys-toggle-btn {
    width: 60px; height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--hys-c1) 0%, color-mix(in srgb, var(--hys-c1) 80%, #000) 100%);
    color: #fff;
    border: 0;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow:
        0 14px 30px -8px color-mix(in srgb, var(--hys-c1) 50%, transparent),
        0 4px 12px rgba(14,26,38,.12),
        inset 0 1px 0 rgba(255,255,255,.16);
    transition: transform .25s cubic-bezier(.4,0,.2,1), box-shadow .25s;
    position: relative;
    overflow: visible;
}
.hys-toggle-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: radial-gradient(circle at center, color-mix(in srgb, var(--hys-c2) 40%, transparent) 0%, transparent 60%);
    opacity: 0;
    transition: opacity .3s;
    z-index: -1;
}
.hys-toggle-btn:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow:
        0 22px 40px -10px color-mix(in srgb, var(--hys-c1) 60%, transparent),
        0 6px 16px rgba(14,26,38,.16),
        inset 0 1px 0 rgba(255,255,255,.18);
}
.hys-toggle-btn:hover::after { opacity: 1; }
.hys-toggle-btn svg { width: 26px; height: 26px; transition: transform .25s; }
.hys-toggle-btn[data-open="true"] svg { transform: rotate(90deg) scale(.85); }

.hys-toggle-badge {
    position: absolute;
    top: -2px; right: -2px;
    background: linear-gradient(135deg, var(--hys-c2), color-mix(in srgb, var(--hys-c2) 70%, #ff5630));
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px; height: 20px;
    border-radius: 10px;
    padding: 0 6px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,.2);
    border: 2px solid #fff;
    animation: hys-bounce .4s ease-out;
}
@keyframes hys-bounce {
    0% { transform: scale(0); }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* ================== Window ================== */
.hys-win {
    position: absolute;
    bottom: 80px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--hys-card);
    border-radius: 20px;
    box-shadow: var(--hys-shadow-3);
    display: flex; flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(.92) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease-out, transform .26s cubic-bezier(.4,0,.2,1);
}
#hys-root[data-pos="right"] .hys-win { right: 0; transform-origin: bottom right; }
#hys-root[data-pos="left"]  .hys-win { left: 0; transform-origin: bottom left; }
.hys-win.is-open { opacity: 1; transform: none; pointer-events: auto; }

/* ================== Header ================== */
.hys-win__head {
    background:
        radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--hys-c2) 35%, transparent) 0%, transparent 55%),
        linear-gradient(135deg, var(--hys-c1) 0%, color-mix(in srgb, var(--hys-c1) 75%, #000) 100%);
    color: #fff;
    padding: 22px 96px 26px 22px;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 20px 20px 0 0;
}
.hys-win__head::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(255,255,255,.04) 0%, transparent 30%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,.06) 0%, transparent 30%);
    pointer-events: none;
}
.hys-win__head h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -.2px;
    position: relative;
    color: #fff;
}
.hys-win__head p {
    margin: 4px 0 0;
    font-size: 13px;
    opacity: .82;
    color: #fff;
    line-height: 1.4;
    position: relative;
}

/* Subtitle + status pill on the same line — pill wraps below if no room */
.hys-win__head-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
    position: relative;
    min-width: 0;
}
.hys-win__head-row p {
    margin: 0;
    font-size: 13px;
    opacity: .82;
    color: #fff;
    line-height: 1.4;
    flex: 0 1 auto;
    min-width: 0;
}
.hys-win__head-row .hys-win__status {
    flex-shrink: 0;
}

.hys-win__avatar {
    position: absolute;
    right: 56px;
    top: 22px;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--hys-c2), color-mix(in srgb, var(--hys-c2) 70%, #fff));
    border: 2px solid rgba(255,255,255,.4);
    background-size: cover;
    background-position: center;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
.hys-win__avatar::after {
    content: '';
    position: absolute;
    bottom: -1px; right: -1px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #5fd87a;
    border: 2px solid var(--hys-c1);
}
.hys-win__head.is-offline .hys-win__avatar::after { background: #ff8a65; }

.hys-win__close {
    position: absolute;
    right: 14px;
    top: 14px;
    background: rgba(255,255,255,.1);
    border: 0;
    color: #fff;
    width: 32px; height: 32px;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .15s;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2;
}
.hys-win__close:hover { background: rgba(255,255,255,.2); }
.hys-win__close:active { transform: scale(.92); }
.hys-win__close svg { width: 14px; height: 14px; }

.hys-win__status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    margin-top: 0;
    padding: 2px 8px;
    background: rgba(255,255,255,.12);
    border-radius: 99px;
    backdrop-filter: blur(6px);
    color: #fff;
    font-weight: 600;
    letter-spacing: .4px;
    text-transform: uppercase;
    position: relative;
    flex-shrink: 0;
}
.hys-win__status::before {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #5fd87a;
    box-shadow: 0 0 0 2px rgba(95,216,122,.3);
    animation: hys-pulse 2s infinite;
}
.hys-win__status.is-offline::before {
    background: #ff8a65;
    box-shadow: 0 0 0 3px rgba(255,138,101,.3);
    animation: none;
}
@keyframes hys-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(95,216,122,.3); }
    50%      { box-shadow: 0 0 0 6px rgba(95,216,122,.05); }
}

/* ================== Body / message stream ================== */
.hys-win__body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 18px 8px;
    background:
        linear-gradient(180deg, var(--hys-bg-soft) 0%, #fff 30%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.hys-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    width: fit-content;
    animation: hys-slide-in .3s cubic-bezier(.4,0,.2,1);
}
.hys-msg > div:not(.hys-msg__avatar) {
    position: relative;
    display: inline-block;
    min-width: 0;
    max-width: 100%;
    padding-bottom: 16px;
}
@keyframes hys-slide-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

.hys-msg__b {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: var(--hys-shadow-1);
    max-width: 100%;
}
.hys-msg__t {
    position: absolute;
    bottom: 0;
    left: 4px;
    font-size: 10px;
    color: var(--hys-text-3);
    letter-spacing: .2px;
    white-space: nowrap;
}
.hys-msg--visitor .hys-msg__t {
    left: auto;
    right: 4px;
}

.hys-msg--visitor {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.hys-msg--visitor .hys-msg__b {
    background: linear-gradient(135deg, var(--hys-c1) 0%, color-mix(in srgb, var(--hys-c1) 80%, #000) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.hys-msg--agent .hys-msg__b,
.hys-msg--ai .hys-msg__b {
    background: #fff;
    color: var(--hys-text);
    border: 1px solid var(--hys-line);
    border-bottom-left-radius: 4px;
}

.hys-msg--ai .hys-msg__b {
    background: linear-gradient(135deg, #faf6ff 0%, #fff 100%);
    border-color: #ece1f7;
}
.hys-msg--ai .hys-msg__b::before {
    content: 'AI';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 16px;
    padding: 0 6px;
    margin-right: 8px;
    background: linear-gradient(135deg, #6b3fa0, #9056d4);
    color: #fff;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .5px;
    vertical-align: 2px;
}

.hys-msg--system {
    align-self: center;
    max-width: 92%;
}
.hys-msg--system .hys-msg__b {
    background: var(--hys-bg-soft);
    color: var(--hys-text-2);
    font-size: 12px;
    font-style: italic;
    padding: 6px 14px;
    border: 1px solid var(--hys-line-2);
    border-radius: 99px;
    box-shadow: none;
    text-align: center;
}

/* Avatar bubble (small, left of agent/ai messages) */
.hys-msg__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--hys-c2), color-mix(in srgb, var(--hys-c2) 60%, #fff));
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    margin-bottom: 14px;
}
.hys-msg--ai .hys-msg__avatar {
    background: linear-gradient(135deg, #6b3fa0, #9056d4);
}
.hys-msg--visitor .hys-msg__avatar { display: none; }
.hys-msg--system .hys-msg__avatar { display: none; }

/* Typing indicator */
.hys-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background: #fff;
    border: 1px solid var(--hys-line);
    border-radius: 16px;
    font-size: 11px;
    color: var(--hys-text-3);
    box-shadow: var(--hys-shadow-1);
}
.hys-typing__dot {
    width: 5px; height: 5px;
    background: var(--hys-text-3);
    border-radius: 50%;
    animation: hys-typing-dot 1.2s infinite;
}
.hys-typing__dot:nth-child(2) { animation-delay: .15s; }
.hys-typing__dot:nth-child(3) { animation-delay: .3s; }
@keyframes hys-typing-dot {
    0%, 80%, 100% { opacity: .3; transform: scale(.8); }
    40%           { opacity: 1; transform: scale(1.05); }
}

/* ================== Composer ================== */
.hys-win__compose {
    border-top: 1px solid var(--hys-line);
    padding: 14px 18px;
    background: #fff;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

/* Field wrapper — borderless, just gives layout for textarea + counter */
.hys-win__compose-field {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: transparent;
    border: 0;
    padding: 0;
    min-height: 26px;
}

.hys-win__compose textarea {
    flex: 1;
    border: 0;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 14.5px;
    line-height: 1.55;
    padding: 4px 0;
    margin: 0;
    max-height: 120px;
    min-height: 24px;
    background: transparent;
    color: var(--hys-text);
    overflow-y: auto;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none;
}
.hys-win__compose textarea::placeholder {
    color: var(--hys-text-3);
    opacity: 1;
}
.hys-win__compose textarea::-webkit-scrollbar { width: 4px; }
.hys-win__compose textarea::-webkit-scrollbar-thumb { background: var(--hys-line); border-radius: 2px; }
.hys-win__compose textarea::-webkit-scrollbar-track { background: transparent; }

/* Character counter */
.hys-win__compose-count {
    font-size: 10.5px;
    color: var(--hys-text-3);
    align-self: flex-end;
    line-height: 1;
    padding-bottom: 8px;
    letter-spacing: .3px;
    transition: opacity .2s, color .2s;
    opacity: 0;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.hys-win__compose-count.is-visible { opacity: 1; }
.hys-win__compose-count.is-warn { color: var(--hys-c2); }
.hys-win__compose-count.is-bad  { color: #b03a3a; }

/* Send button — small rounded square, no decoration outside the chip */
.hys-send-btn {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--hys-c1) 0%, color-mix(in srgb, var(--hys-c1) 78%, #000) 100%);
    color: #fff;
    border: 0;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform .2s cubic-bezier(.4,0,.2,1), box-shadow .2s, opacity .2s, background .25s;
    box-shadow:
        0 3px 8px -2px color-mix(in srgb, var(--hys-c1) 38%, transparent),
        0 1px 2px rgba(14,26,38,.08);
    flex-shrink: 0;
    align-self: flex-end;
    padding: 0;
}
.hys-send-btn svg {
    width: 16px; height: 16px;
    transform: translate(1px, -1px);
    transition: transform .2s cubic-bezier(.4,0,.2,1);
}
.hys-send-btn:hover {
    transform: translateY(-1px);
    box-shadow:
        0 6px 14px -3px color-mix(in srgb, var(--hys-c1) 50%, transparent),
        0 2px 3px rgba(14,26,38,.1);
}
.hys-send-btn:hover svg { transform: translate(2px, -2px); }
.hys-send-btn:active { transform: scale(.94); }
.hys-send-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.hys-send-btn:disabled svg { transform: translate(1px, -1px); }
.hys-send-btn.is-ready {
    background: linear-gradient(135deg, var(--hys-c2) 0%, color-mix(in srgb, var(--hys-c2) 60%, var(--hys-c1)) 100%);
    box-shadow:
        0 4px 12px -2px color-mix(in srgb, var(--hys-c2) 50%, transparent),
        0 1px 2px rgba(14,26,38,.1);
}
.hys-send-btn.is-ready:hover {
    box-shadow:
        0 6px 16px -3px color-mix(in srgb, var(--hys-c2) 60%, transparent);
}

/* ================== Footer ================== */
.hys-win__foot {
    padding: 8px 14px 10px;
    font-size: 10px;
    color: var(--hys-text-3);
    text-align: center;
    background: #fff;
    border-top: 1px solid var(--hys-line-2);
    flex-shrink: 0;
    letter-spacing: .3px;
}
.hys-win__foot a {
    color: var(--hys-c2);
    text-decoration: none;
    font-weight: 600;
}

/* ================== Pre-chat form ================== */
.hys-form {
    padding: 22px 22px 18px;
    background: #fff;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}
.hys-form h4 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: var(--hys-text);
    letter-spacing: -.1px;
}
.hys-form > p {
    font-size: 13px;
    color: var(--hys-text-2);
    margin: 0 0 4px;
    line-height: 1.5;
}
.hys-form input,
.hys-form textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--hys-line);
    border-radius: 12px;
    font-size: 14px;
    font-family: inherit;
    background: var(--hys-bg-soft);
    color: var(--hys-text);
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.hys-form input::placeholder,
.hys-form textarea::placeholder { color: var(--hys-text-3); }
.hys-form input:focus,
.hys-form textarea:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--hys-c1) 35%, var(--hys-line));
    background: #fff;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--hys-c1) 8%, transparent);
}
.hys-form textarea {
    min-height: 90px;
    resize: vertical;
    line-height: 1.55;
}
.hys-form button {
    margin-top: 4px;
    padding: 13px 14px;
    border: 0;
    background: linear-gradient(135deg, var(--hys-c1) 0%, color-mix(in srgb, var(--hys-c1) 80%, #000) 100%);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s, opacity .15s;
    box-shadow: 0 6px 14px -4px color-mix(in srgb, var(--hys-c1) 50%, transparent);
    letter-spacing: .2px;
}
.hys-form button:hover { transform: translateY(-1px); }
.hys-form button:active { transform: scale(.98); }
.hys-form button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.hys-form__err {
    font-size: 12px;
    color: #b03a3a;
    background: #fbe9e9;
    padding: 8px 12px;
    border-radius: 8px;
    border-left: 3px solid #b03a3a;
}

/* ================== Rating ================== */
.hys-rate {
    padding: 16px 18px;
    background: linear-gradient(180deg, #fff8ef 0%, #fff 100%);
    border-top: 1px solid var(--hys-line);
    text-align: center;
}
.hys-rate p {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--hys-text-2);
    font-weight: 500;
}
.hys-rate__stars {
    display: inline-flex;
    gap: 6px;
}
.hys-rate__stars button {
    background: transparent;
    border: 0;
    cursor: pointer;
    font-size: 26px;
    color: #d8d2c2;
    line-height: 1;
    padding: 4px 6px;
    transition: color .15s, transform .15s;
}
.hys-rate__stars button:hover,
.hys-rate__stars button.is-on {
    color: var(--hys-c2);
    transform: scale(1.12);
}

/* ================== Scrollbar ================== */
.hys-win__body::-webkit-scrollbar,
.hys-form::-webkit-scrollbar { width: 6px; }
.hys-win__body::-webkit-scrollbar-thumb,
.hys-form::-webkit-scrollbar-thumb { background: var(--hys-line); border-radius: 3px; }
.hys-win__body::-webkit-scrollbar-track,
.hys-form::-webkit-scrollbar-track { background: transparent; }

/* Stack the theme's back-to-top button directly above the chat FAB.
   We override its position + size so the two buttons read as a vertical pair. */
body .hy-back-top {
    bottom: 100px !important;        /* sits just above the 60px FAB at bottom:24 */
    right: 24px !important;          /* same right edge as the chat FAB */
    width: 60px !important;          /* same size — feels like a stacked pair */
    height: 60px !important;
    border-radius: 50% !important;   /* circle to mirror the FAB */
    z-index: 99989;                  /* one below FAB so they don't fight stacking */
}
@media (max-width: 480px) {
    body .hy-back-top {
        bottom: 84px !important;
        right: 14px !important;
        width: 56px !important;
        height: 56px !important;
    }
}

/* ================== Mobile ================== */
@media (max-width: 480px) {
    .hys-win {
        width: calc(100vw - 16px);
        height: calc(100vh - 90px);
        bottom: 76px;
        border-radius: 18px;
    }
    .hys-win__head {
        border-radius: 18px 18px 0 0;
    }
    #hys-root { bottom: 14px; }
    #hys-root[data-pos="right"] { right: 14px; }
    #hys-root[data-pos="left"]  { left: 14px; }
    .hys-toggle-btn { width: 56px; height: 56px; }
}
