/**
 * AI 客服（知识库对话）- 前端样式
 *
 * 颜色跟随站点主题变量（--button_color / --el_bg_color / --text_color …，暗色模式自动切换），
 * 没有主题变量的站点用括号里的默认色。全部规则限定在 #ry-chat-container 下，不和主题样式互相影响。
 */

#ry-chat-container {
    --ryc-accent: var(--button_color, #4f46e5);
    --ryc-accent-text: var(--button_text_color, #ffffff);
    --ryc-accent-2: color-mix(in srgb, var(--ryc-accent) 70%, #000);
    --ryc-bg: var(--el_bg_color, #ffffff);
    --ryc-surface: color-mix(in srgb, var(--ryc-bg) 94%, var(--ryc-accent));
    --ryc-text: var(--text_color, #1f2937);
    --ryc-heading: var(--heading_color, #111827);
    --ryc-muted: var(--alternate_font_color_1, #6b7280);
    --ryc-border: color-mix(in srgb, var(--ryc-text) 10%, transparent);
    --ryc-radius: 20px;
    font-family: var(--font_family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
    -webkit-font-smoothing: antialiased;
}

#ry-chat-container *,
#ry-chat-container *::before,
#ry-chat-container *::after {
    box-sizing: border-box;
}

/* ── 启动按钮 ── */
#ry-chat-container .ry-chat-trigger {
    position: fixed;
    bottom: 22px;
    right: 22px;
    width: 58px;
    height: 58px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    color: var(--ryc-accent-text);
    background: linear-gradient(140deg, var(--ryc-accent), var(--ryc-accent-2));
    box-shadow: 0 12px 28px color-mix(in srgb, var(--ryc-accent) 42%, transparent), 0 3px 8px rgba(0, 0, 0, 0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#ry-chat-container .ry-chat-trigger.bottom-left {
    right: auto;
    left: 22px;
}

#ry-chat-container .ry-chat-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 34px color-mix(in srgb, var(--ryc-accent) 50%, transparent), 0 4px 10px rgba(0, 0, 0, 0.16);
}

#ry-chat-container .ry-chat-trigger:focus-visible,
#ry-chat-container .ry-chat-close:focus-visible,
#ry-chat-container .ry-chat-send:focus-visible,
#ry-chat-container .ry-chat-chip:focus-visible {
    outline: 2px solid var(--ryc-accent);
    outline-offset: 3px;
}

/* 呼吸光环（窗口打开时停） */
#ry-chat-container .ry-chat-trigger::before {
    content: "";
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid color-mix(in srgb, var(--ryc-accent) 45%, transparent);
    animation: ryc-pulse 2.6s ease-out infinite;
    pointer-events: none;
}

#ry-chat-container .ry-chat-trigger.is-open::before {
    animation: none;
    opacity: 0;
}

@keyframes ryc-pulse {
    0%   { transform: scale(0.94); opacity: 0.85; }
    70%  { transform: scale(1.22); opacity: 0; }
    100% { transform: scale(1.22); opacity: 0; }
}

/* 在线小绿点 */
#ry-chat-container .ry-chat-trigger .ryc-dot {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
}

/* 图标：气泡 ↔ ×（打开时） */
#ry-chat-container .ry-chat-trigger svg {
    position: absolute;
    width: 26px;
    height: 26px;
    fill: currentColor;
    transition: transform 0.3s ease, opacity 0.2s ease;
}

#ry-chat-container .ry-chat-trigger .ryc-ico-close {
    width: 22px;
    height: 22px;
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

#ry-chat-container .ry-chat-trigger.is-open .ryc-ico-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

#ry-chat-container .ry-chat-trigger.is-open .ryc-ico-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

#ry-chat-container .ry-chat-trigger.is-open .ryc-dot {
    opacity: 0;
}

/* ── 聊天窗口 ── */
#ry-chat-container .ry-chat-widget {
    position: fixed;
    bottom: 96px;
    right: 22px;
    width: 384px;
    height: min(600px, calc(100vh - 130px));
    background: var(--ryc-bg);
    color: var(--ryc-text);
    border-radius: var(--ryc-radius);
    border: 1px solid var(--ryc-border);
    box-shadow: 0 28px 70px rgba(15, 23, 42, 0.22), 0 6px 18px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
    transform-origin: bottom right;
    transform: translateY(14px) scale(0.96);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear 0.3s;
}

#ry-chat-container .ry-chat-widget.bottom-left {
    right: auto;
    left: 22px;
    transform-origin: bottom left;
}

#ry-chat-container .ry-chat-widget.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.22s ease, transform 0.3s cubic-bezier(.2, .8, .2, 1), visibility 0s;
}

/* 头部：渐变 + 头像 + 在线状态 */
#ry-chat-container .ry-chat-header {
    position: relative;
    padding: 18px 18px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--ryc-accent-text);
    background:
        radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, #fff 18%, transparent) 0%, transparent 55%),
        linear-gradient(140deg, var(--ryc-accent), var(--ryc-accent-2));
    flex-shrink: 0;
}

#ry-chat-container .ryc-head-avatar {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: color-mix(in srgb, #fff 18%, transparent);
    border: 1px solid color-mix(in srgb, #fff 30%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#ry-chat-container .ryc-head-avatar svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

#ry-chat-container .ryc-head-avatar::after {
    content: "";
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--ryc-accent-2);
}

#ry-chat-container .ryc-head-text {
    flex: 1;
    min-width: 0;
}

#ry-chat-container .ryc-head-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ry-chat-container .ryc-head-status {
    margin-top: 2px;
    font-size: 12px;
    opacity: 0.85;
}

#ry-chat-container .ry-chat-close {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 10px;
    background: color-mix(in srgb, #fff 14%, transparent);
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

#ry-chat-container .ry-chat-close:hover {
    background: color-mix(in srgb, #fff 26%, transparent);
}

#ry-chat-container .ry-chat-close svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* 消息区 */
#ry-chat-container .ry-chat-messages {
    flex: 1;
    padding: 18px 16px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--ryc-surface);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

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

#ry-chat-container .ry-chat-messages::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--ryc-text) 18%, transparent);
    border-radius: 3px;
}

#ry-chat-container .ry-chat-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: ryc-in 0.28s ease;
}

@keyframes ryc-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

#ry-chat-container .ry-chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

#ry-chat-container .ry-chat-message.assistant {
    align-self: flex-start;
}

#ry-chat-container .ry-chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: linear-gradient(140deg, var(--ryc-accent), var(--ryc-accent-2));
    color: var(--ryc-accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#ry-chat-container .ry-chat-avatar svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* 用户消息不显示头像，气泡贴右 */
#ry-chat-container .ry-chat-message.user .ry-chat-avatar {
    display: none;
}

#ry-chat-container .ry-chat-bubble {
    padding: 11px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

#ry-chat-container .ry-chat-message.assistant .ry-chat-bubble {
    background: var(--ryc-bg);
    color: var(--ryc-text);
    border: 1px solid var(--ryc-border);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
}

#ry-chat-container .ry-chat-message.user .ry-chat-bubble {
    background: linear-gradient(140deg, var(--ryc-accent), var(--ryc-accent-2));
    color: var(--ryc-accent-text);
    border-bottom-right-radius: 6px;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--ryc-accent) 25%, transparent);
}

#ry-chat-container .ry-chat-bubble a {
    color: var(--ryc-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

#ry-chat-container .ry-chat-message.user .ry-chat-bubble a {
    color: inherit;
}

#ry-chat-container .ry-chat-bubble strong {
    font-weight: 700;
    color: var(--ryc-heading);
}

#ry-chat-container .ry-chat-message.user .ry-chat-bubble strong {
    color: inherit;
}

#ry-chat-container .ryc-time {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.55;
}

/* 正在输入 */
#ry-chat-container .ry-chat-message.loading .ry-chat-bubble {
    display: flex;
    gap: 5px;
    padding: 14px 16px;
}

#ry-chat-container .typing-dot {
    width: 7px;
    height: 7px;
    background: var(--ryc-accent);
    border-radius: 50%;
    animation: ryc-typing 1.3s infinite ease-in-out;
}

#ry-chat-container .typing-dot:nth-child(2) { animation-delay: 0.18s; }
#ry-chat-container .typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes ryc-typing {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
    40%           { transform: translateY(-4px); opacity: 1; }
}

/* 快捷问题 */
#ry-chat-container .ry-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: -2px 0 4px 38px;
}

#ry-chat-container .ry-chat-chip {
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--ryc-accent) 35%, transparent);
    background: var(--ryc-bg);
    color: var(--ryc-accent);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

#ry-chat-container .ry-chat-chip:hover {
    background: var(--ryc-accent);
    color: var(--ryc-accent-text);
    transform: translateY(-1px);
}

/* 输入区：胶囊输入框 + 内嵌发送按钮 */
#ry-chat-container .ry-chat-input-area {
    padding: 12px 14px 8px;
    background: var(--ryc-bg);
    border-top: 1px solid var(--ryc-border);
    flex-shrink: 0;
}

#ry-chat-container .ryc-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 14px;
    border-radius: 18px;
    border: 1px solid var(--ryc-border);
    background: var(--ryc-surface);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#ry-chat-container .ryc-input-wrap:focus-within {
    border-color: color-mix(in srgb, var(--ryc-accent) 60%, transparent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--ryc-accent) 14%, transparent);
}

#ry-chat-container .ry-chat-input {
    flex: 1;
    min-height: 24px;
    max-height: 110px;
    padding: 6px 0;
    margin: 0;
    border: 0;
    background: transparent;
    color: var(--ryc-text);
    font: inherit;
    font-size: 14px;
    line-height: 1.45;
    resize: none;
    outline: none;
    box-shadow: none;
}

#ry-chat-container .ry-chat-input::placeholder {
    color: var(--ryc-muted);
    opacity: 0.8;
}

#ry-chat-container .ry-chat-send {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(140deg, var(--ryc-accent), var(--ryc-accent-2));
    color: var(--ryc-accent-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

#ry-chat-container .ry-chat-send:hover:not(:disabled) {
    transform: translateY(-1px);
}

#ry-chat-container .ry-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#ry-chat-container .ry-chat-send svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

#ry-chat-container .ry-chat-footnote {
    margin-top: 7px;
    text-align: center;
    font-size: 11px;
    color: var(--ryc-muted);
    opacity: 0.75;
}

/* ── 回复里的卡片（产品 / 文章列表、详情） ── */
#ry-chat-container .widget-card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

#ry-chat-container .widget-card-item {
    display: flex;
    gap: 10px;
    padding: 8px;
    background: var(--ryc-surface);
    border-radius: 12px;
    border: 1px solid var(--ryc-border);
    transition: border-color 0.2s ease, transform 0.2s ease;
}

#ry-chat-container .widget-card-item:hover {
    border-color: color-mix(in srgb, var(--ryc-accent) 40%, transparent);
    transform: translateY(-1px);
}

#ry-chat-container .widget-card-thumb {
    width: 64px;
    height: 64px;
    border-radius: 9px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--ryc-border);
}

#ry-chat-container .widget-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#ry-chat-container .widget-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
}

#ry-chat-container .widget-card-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--ryc-heading);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#ry-chat-container .widget-card-title a {
    color: inherit !important;
    text-decoration: none !important;
}

#ry-chat-container .widget-card-excerpt {
    font-size: 12px;
    color: var(--ryc-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

#ry-chat-container .widget-card-link a,
#ry-chat-container .widget-detail-link a {
    font-size: 12px;
    font-weight: 600;
    color: var(--ryc-accent) !important;
    text-decoration: none !important;
}

#ry-chat-container .widget-card-link a:hover,
#ry-chat-container .widget-detail-link a:hover {
    text-decoration: underline !important;
}

#ry-chat-container .widget-detail-card {
    margin-top: 10px;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--ryc-border);
    background: var(--ryc-surface);
}

#ry-chat-container .widget-detail-thumb {
    width: 100%;
    max-height: 170px;
    overflow: hidden;
}

#ry-chat-container .widget-detail-thumb img {
    width: 100%;
    height: auto;
    display: block;
}

#ry-chat-container .widget-detail-body {
    padding: 10px 12px 12px;
}

#ry-chat-container .widget-detail-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--ryc-heading);
    margin-bottom: 6px;
}

#ry-chat-container .widget-detail-text {
    font-size: 12.5px;
    color: var(--ryc-muted);
    line-height: 1.55;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
}

#ry-chat-container .widget-detail-link {
    margin-top: 8px;
}

/* ── 手机：底部整屏面板 ── */
@media (max-width: 480px) {
    #ry-chat-container .ry-chat-widget,
    #ry-chat-container .ry-chat-widget.bottom-left {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: calc(100% - 56px);
        border-radius: 22px 22px 0 0;
        border-bottom: 0;
        transform-origin: bottom center;
        padding-bottom: env(safe-area-inset-bottom);
    }

    #ry-chat-container .ry-chat-trigger {
        width: 52px;
        height: 52px;
        bottom: 16px;
        right: 16px;
    }

    #ry-chat-container .ry-chat-trigger.bottom-left {
        left: 16px;
    }

    /* 面板打开时启动钮让位（面板头部有关闭按钮） */
    #ry-chat-container .ry-chat-trigger.is-open {
        opacity: 0;
        pointer-events: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #ry-chat-container .ry-chat-trigger::before { animation: none; }
    #ry-chat-container .ry-chat-widget,
    #ry-chat-container .ry-chat-message,
    #ry-chat-container .ry-chat-trigger svg { transition: none; animation: none; }
}
