/* 在线客服 · 通用样式（悬浮窗 / 独立客服页） */
.chat-widget-root,
.chat-page-body {
    --chat-primary: #4f7cff;
    --chat-primary-dark: #355ee8;
    --chat-bg: #f4f6fb;
    --chat-panel: #ffffff;
    --chat-text: #1f2937;
    --chat-muted: #8a94a6;
    --chat-line: #e8ecf4;
    --chat-admin-bubble: #ffffff;
    --chat-user-bubble: linear-gradient(135deg, #5b8cff 0%, #4f7cff 100%);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--chat-text);
    -webkit-font-smoothing: antialiased;
}

.chat-widget-root {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 99999;
    font-size: 14px;
    line-height: 1.5;
}

.chat-widget-root *,
.chat-page-body * {
    box-sizing: border-box;
}

/* 悬浮按钮 */
.chat-launcher {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #5b8cff 0%, #4f7cff 55%, #3f6df0 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(79, 124, 255, .38), 0 2px 8px rgba(31, 41, 55, .12);
    transition: transform .22s ease, box-shadow .22s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.chat-launcher:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 16px 36px rgba(79, 124, 255, .46), 0 3px 10px rgba(31, 41, 55, .14);
}

.chat-launcher:active {
    transform: scale(.97);
}

.chat-launcher svg {
    width: 27px;
    height: 27px;
    fill: currentColor;
}

.chat-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #ff4d4f;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(255, 77, 79, .35);
}

.chat-badge[hidden] {
    display: none !important;
}

/* 主面板 */
.chat-panel {
    position: absolute;
    right: 0;
    bottom: 74px;
    display: flex;
    flex-direction: column;
    width: 384px;
    height: 568px;
    max-height: calc(100vh - 110px);
    overflow: hidden;
    background: var(--chat-panel);
    border: 1px solid rgba(226, 232, 240, .9);
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(31, 41, 55, .2), 0 8px 24px rgba(31, 41, 55, .08);
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(.98);
    transform-origin: right bottom;
    transition: opacity .22s ease, transform .22s ease, visibility .22s ease;
}

.chat-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.chat-opened .chat-launcher {
    opacity: 0;
    visibility: hidden;
    transform: scale(.8);
}

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    min-height: 68px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #5b8cff 0%, #4f7cff 55%, #3f6df0 100%);
    color: #fff;
}

.chat-brand {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
}

.chat-brand-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .18);
    border: 1px solid rgba(255, 255, 255, .24);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
}

.chat-brand-meta {
    min-width: 0;
}

.chat-brand-meta strong {
    display: block;
    max-width: 210px;
    overflow: hidden;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-brand-meta small {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    color: rgba(255, 255, 255, .78);
    font-size: 11.5px;
}

.chat-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #7ef0b2;
    box-shadow: 0 0 0 3px rgba(126, 240, 178, .18);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: rgba(255, 255, 255, .9);
    font-size: 20px;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background .18s ease;
}

.chat-icon-btn:hover,
.chat-icon-btn:focus {
    background: rgba(255, 255, 255, .16);
    color: #fff;
    text-decoration: none;
    outline: none;
}

.chat-icon-btn svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

/* 消息区 */
.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 18px 14px 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background:
        radial-gradient(circle at 0 0, rgba(79, 124, 255, .06), transparent 36%),
        radial-gradient(circle at 100% 100%, rgba(91, 140, 255, .05), transparent 34%),
        var(--chat-bg);
    scrollbar-width: thin;
    scrollbar-color: #c9d3e5 transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #c9d3e5;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin-bottom: 16px;
    animation: chat-in .2s ease both;
}

.chat-message.is-user {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    margin-top: 2px;
    border-radius: 10px;
    background: #e8eefc;
    color: #4f7cff;
    font-size: 12px;
    font-weight: 700;
}

.chat-message.is-user .chat-message-avatar {
    background: #dfe8ff;
    color: #355ee8;
}

.chat-message-main {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: calc(100% - 46px);
}

.chat-message.is-user .chat-message-main {
    align-items: flex-end;
}

.chat-message-bubble {
    max-width: 100%;
    padding: 10px 13px;
    border-radius: 4px 14px 14px 14px;
    background: var(--chat-admin-bubble);
    color: var(--chat-text);
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 2px 10px rgba(31, 41, 55, .06);
}

.chat-message.is-user .chat-message-bubble {
    border-radius: 14px 4px 14px 14px;
    background: var(--chat-user-bubble);
    color: #fff;
    box-shadow: 0 6px 16px rgba(79, 124, 255, .22);
}

.chat-message-bubble img {
    display: block;
    max-width: 100%;
    max-height: 220px;
    border-radius: 8px;
}

.chat-message-time {
    margin-top: 5px;
    padding: 0 2px;
    color: #a0a9b8;
    font-size: 10.5px;
    line-height: 1;
}

.chat-system {
    display: block;
    width: fit-content;
    max-width: 90%;
    margin: 8px auto 18px;
    padding: 5px 12px;
    border-radius: 999px;
    background: rgba(31, 41, 55, .055);
    color: #8a94a6;
    font-size: 11.5px;
    line-height: 1.5;
    text-align: center;
}

.chat-system-error {
    background: #fff1f0;
    color: #d4380d;
}

.chat-closed-tip {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    width: fit-content;
    max-width: 92%;
    margin: 10px auto 16px;
    padding: 7px 10px 7px 14px;
    border: 1px solid #ffe0d9;
    border-radius: 12px;
    background: #fff7f4;
    color: #d46b3c;
    font-size: 11.5px;
    line-height: 1.5;
    text-align: center;
}

.chat-restart {
    padding: 4px 10px;
    border: 1px solid #ffc7b8;
    border-radius: 999px;
    background: #fff;
    color: #d46b3c;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background .16s ease, color .16s ease;
}

.chat-restart:hover {
    background: #d46b3c;
    color: #fff;
}

.chat-panel.is-closed .chat-compose-inner {
    opacity: .7;
}

.chat-panel.is-closed .chat-input {
    cursor: not-allowed;
}

/* 输入区 */
.chat-compose {
    flex: 0 0 auto;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--chat-line);
    background: #fff;
}

.chat-compose-inner {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 7px 8px 7px 12px;
    border: 1px solid #e2e8f2;
    border-radius: 14px;
    background: #f8fafd;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.chat-compose-inner:focus-within {
    border-color: rgba(79, 124, 255, .55);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 124, 255, .1);
}

.chat-input {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    min-height: 24px;
    max-height: 110px;
    padding: 4px 0;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--chat-text);
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.5;
    scrollbar-width: thin;
}

.chat-input::placeholder {
    color: #a8b1c2;
}

.chat-attach {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 9px;
    background: #eef3ff;
    color: #4f7cff;
    cursor: pointer;
    transition: background .18s ease, color .18s ease, opacity .18s ease;
}

.chat-attach:hover {
    background: #e3ebff;
    color: #355ee8;
}

.chat-attach:disabled {
    cursor: not-allowed;
    opacity: .5;
}

.chat-attach svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.chat-file {
    display: none;
}

.chat-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 58px;
    height: 34px;
    padding: 0 14px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, #5b8cff, #4f7cff);
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .18s ease, transform .18s ease, box-shadow .18s ease;
    box-shadow: 0 6px 14px rgba(79, 124, 255, .24);
}

.chat-send:hover {
    box-shadow: 0 8px 18px rgba(79, 124, 255, .32);
    transform: translateY(-1px);
}

.chat-send:active {
    transform: translateY(0);
}

.chat-send:disabled {
    cursor: not-allowed;
    opacity: .55;
    box-shadow: none;
    transform: none;
}

.chat-send.is-loading::after {
    content: "";
    width: 11px;
    height: 11px;
    margin-left: 6px;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: chat-spin .7s linear infinite;
}

.chat-compose-tip {
    margin-top: 7px;
    color: #a6afbf;
    font-size: 10.5px;
    text-align: right;
}

.chat-toast {
    position: fixed;
    left: 50%;
    bottom: 108px;
    z-index: 100000;
    max-width: 78vw;
    padding: 8px 14px;
    border-radius: 10px;
    background: rgba(31, 41, 55, .9);
    color: #fff;
    font-size: 12.5px;
    line-height: 1.5;
    text-align: center;
    transform: translateX(-50%);
    animation: chat-toast-in .2s ease both;
    pointer-events: none;
}

.chat-toast.is-out {
    animation: chat-toast-out .2s ease both;
}

/* 独立客服页 */
.chat-page-body {
    min-height: 100vh;
    margin: 0;
    padding: 28px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(900px 500px at 8% 0%, rgba(91, 140, 255, .18), transparent 55%),
        radial-gradient(900px 500px at 100% 100%, rgba(63, 109, 240, .12), transparent 55%),
        #eef3fb;
}

.chat-page-card {
    width: 100%;
    max-width: 900px;
    height: min(82vh, 780px);
    min-height: 520px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .7);
    border-radius: 22px;
    background: #fff;
    box-shadow: 0 30px 80px rgba(31, 41, 55, .18), 0 8px 24px rgba(31, 41, 55, .06);
}

.chat-page-shell {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    width: 100%;
    max-width: 900px;
}

.chat-page-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: #7d8798;
    font-size: 12px;
}

.chat-page-footer a {
    color: #4f7cff;
    text-decoration: none;
}

.chat-page-footer a:hover {
    text-decoration: underline;
}

.chat-page-root {
    position: static;
    right: auto;
    bottom: auto;
    width: 100%;
    height: 100%;
}

.chat-page-root .chat-panel {
    position: static;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    opacity: 1;
    visibility: visible;
    transform: none;
}

.chat-page-root .chat-launcher {
    display: none;
}

.chat-page-root .chat-messages {
    padding: 26px 24px 14px;
}

.chat-page-root .chat-message-bubble {
    font-size: 14px;
}

.chat-page-root .chat-compose {
    padding: 14px 20px 18px;
}

.chat-page-root .chat-input {
    font-size: 14px;
}

@keyframes chat-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes chat-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes chat-toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes chat-toast-out {
    to {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
}

@media (max-width: 560px) {
    .chat-widget-root:not(.chat-page-root) {
        right: 14px;
        bottom: 14px;
    }

    .chat-widget-root:not(.chat-page-root) .chat-panel {
        position: fixed;
        inset: 0;
        width: auto;
        height: auto;
        max-height: none;
        border: 0;
        border-radius: 0;
        transform-origin: center;
    }

    .chat-launcher {
        width: 54px;
        height: 54px;
    }

    .chat-panel-header {
        min-height: 62px;
        padding: 10px 14px;
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .chat-page-body {
        padding: 0;
        background: #eef3fb;
    }

    .chat-page-shell {
        height: 100vh;
        max-width: none;
        gap: 0;
    }

    .chat-page-card {
        height: 100vh;
        min-height: 100vh;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-page-footer {
        display: none;
    }

    .chat-page-root .chat-messages {
        padding: 18px 12px 10px;
    }

    .chat-page-root .chat-compose {
        padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-panel,
    .chat-launcher,
    .chat-message,
    .chat-toast {
        animation: none !important;
        transition: none !important;
    }
}
