/* CSS Variables for Chatbox Configuration */
.ynm-langflow-chat-wrapper {
    --primary-color: #667eea;
    --background-color: #ffffff;
    --border-radius: 12px;
    --ynm-expand-transition: 150ms cubic-bezier(0.2, 0, 0, 1);
    --ynm-float-controls-bg: rgba(15, 23, 42, 0.28);
    --ynm-float-controls-border: rgba(255, 255, 255, 0.28);
    --ynm-float-controls-shadow: 0 8px 20px rgba(2, 6, 23, 0.24);
    --ynm-float-controls-blur: 10px;
}

.ynm-langflow-chat-container {
    position: relative;
    padding: 10px 0;
    margin: 0 auto !important;
    box-sizing: border-box;
    overflow: hidden;
    transition:
        width var(--ynm-expand-transition),
        max-width var(--ynm-expand-transition),
        margin-left var(--ynm-expand-transition),
        margin-right var(--ynm-expand-transition);
}

/* 清除 WordPress wpautop 在短代码后自动生成的空段落边距 */
.ynm-langflow-chat-container + p,
.ynm-langflow-chat-container + p:empty {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 0;
    height: 0;
}

/* 仅在 ai 页面模板中收紧页面容器的默认底部留白 */
body.page-template-ai .wp-block-post-content,
body.page-template-ai-page .wp-block-post-content,
body.page-id-5 .wp-block-post-content {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

body.page-template-ai main.wp-block-group,
body.page-template-ai-page main.wp-block-group,
body.page-id-5 main.wp-block-group {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

body.page-template-ai .wp-site-blocks,
body.page-template-ai-page .wp-site-blocks,
body.page-id-5 .wp-site-blocks {
    padding-bottom: 0 !important;
}

body.page-template-ai .wp-block-post-content > :last-child,
body.page-template-ai-page .wp-block-post-content > :last-child,
body.page-id-5 .wp-block-post-content > :last-child {
    margin-bottom: 0 !important;
}

.ynm-langflow-chat-container #ynm-langflow-chat-root {
    position: absolute;
    top: 10px;
    right: 0;
    bottom: 10px;
    left: 0;
    min-height: 0;
    height: auto !important;
}

/* Layout base */
.message {
    position: relative;
}

.message-header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.message.user-message .message-header {
    flex-direction: row-reverse;
    gap: 12px;
}

.message-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 auto;
    min-width: 0;
}

.message.user-message .message-header-info {
    flex-direction: row-reverse;
    gap: 8px;
}

.message-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}

.message.user-message .message-buttons {
    margin-left: 0;
    margin-right: auto;
}

.message-content-wrapper {
    width: 100%;
}

/* YNM LangFlow Chat Styles */
.ynm-langflow-chat-wrapper {
    max-width: 800px;
    margin: 0 auto;
    border: 1px solid #ddd;
    border-radius: var(--border-radius, 12px);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    background: var(--background-color, white);
    transition:
        border-radius var(--ynm-expand-transition),
        box-shadow var(--ynm-expand-transition);
    height: 100% !important;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.ynm-langflow-chat-wrapper .ynm-langflow-chat-input {
    flex-shrink: 0;
}

.ynm-langflow-chat-container--fullscreen {
    height: 100dvh !important;
    width: 100% !important;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
}

.admin-bar .ynm-langflow-chat-container--fullscreen {
    height: calc(100dvh - 32px) !important;
}

.ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-wrapper {
    max-width: none;
    height: 100%;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
}

/* 全屏壳层容器本身：覆盖所有主题元素（含 WP admin bar z-index:99999） */
.ynm-langflow-chat-container--with-shell {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    z-index: 100000 !important;
    background: #f3f4f6;
    overflow: hidden;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    box-sizing: border-box;
    z-index: 9998;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-topbar::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 220px;
    width: 1px;
    background: #e5e7eb;
}

.admin-bar .ynm-langflow-chat-container--with-shell .ynm-shell-topbar {
    top: 32px;
}

@media screen and (max-width: 782px) {
    .admin-bar .ynm-langflow-chat-container--with-shell .ynm-shell-topbar {
        top: 46px;
    }
}

.ynm-langflow-chat-container--with-shell .ynm-shell-topbar-brand {
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-topbar-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-topbar-center {
    flex: 1;
    max-width: 320px;
    height: 34px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin: 0 20px;
    background: #ffffff;
    position: relative;
    z-index: 1;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-menu-item {
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    color: #374151;
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-menu-item:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.ynm-langflow-chat-container--with-shell .ynm-shell-menu-item:active {
    transform: translateY(0);
}

.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    width: 220px;
    height: calc(100% - 56px);
    border-right: 1px solid #e5e7eb;
    background: #ffffff;
    padding: 12px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    z-index: 9997;
}

.admin-bar .ynm-langflow-chat-container--with-shell .ynm-shell-sidebar {
    top: calc(56px + 32px);
    height: calc(100% - 56px - 32px);
}

@media screen and (max-width: 782px) {
    .admin-bar .ynm-langflow-chat-container--with-shell .ynm-shell-sidebar {
        top: calc(56px + 46px);
        height: calc(100% - 56px - 46px);
    }
}

.ynm-langflow-chat-container--with-shell #ynm-langflow-chat-root {
    position: fixed;
    top: 56px;
    left: 220px;
    width: calc(100% - 220px);
    height: calc(100% - 56px);
    padding: 16px 10% 32px 10%;
    box-sizing: border-box;
    background: #f3f4f6;
}

.admin-bar .ynm-langflow-chat-container--with-shell #ynm-langflow-chat-root {
    top: calc(56px + 32px);
    height: calc(100% - 56px - 32px);
}

@media screen and (max-width: 782px) {
    .admin-bar .ynm-langflow-chat-container--with-shell #ynm-langflow-chat-root {
        top: calc(56px + 46px);
        height: calc(100% - 56px - 46px);
    }
}

.ynm-langflow-chat-container--with-shell .ynm-langflow-chat-wrapper {
    height: 100%;
}

.ynm-langflow-chat-container--with-shell .ynm-langflow-chat-header {
    display: none;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar-title {
    font-size: 12px;
    color: #6b7280;
    margin-top: 10px;
    margin-bottom: 2px;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar-action,
.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar-item {
    width: 100%;
    text-align: left;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    color: #374151;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar-action:hover,
.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar-item:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
    transform: translateX(2px);
}

.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar-action {
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-color, #667eea) 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.ynm-langflow-chat-container--with-shell .ynm-shell-sidebar-action:hover {
    opacity: 0.9;
    transform: translateX(2px) translateY(-1px);
}

.ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-messages {
    min-height: 0;
    height: auto;
    flex: 1;
}

.ynm-langflow-chat-header {
    background: linear-gradient(135deg, var(--primary-color, #667eea) 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
    min-height: 56px;
    position: relative;
    z-index: 2;
}

/* 兼容保护：无论旧缓存是否错误注入壳层，头部都保持可见 */
.ynm-langflow-chat-wrapper .ynm-langflow-chat-header {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.ynm-langflow-chat-container--with-shell .ynm-langflow-chat-header {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* 兼容保护：如果线上仍有旧版 JS 注入壳层，强制隐藏壳层并恢复普通聊天布局 */
.ynm-shell-topbar,
.ynm-shell-sidebar {
    display: none !important;
}

.ynm-langflow-chat-container--with-shell {
    position: static !important;
    width: auto !important;
    height: auto !important;
    z-index: auto !important;
    background: transparent !important;
    overflow: visible !important;
}

.ynm-langflow-chat-container--with-shell #ynm-langflow-chat-root {
    position: static !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
    background: transparent !important;
}

.ynm-langflow-chat-header-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.ynm-langflow-chat-header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ynm-langflow-chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ynm-chat-expand-btn,
.ynm-chat-settings-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
    color: #ffffff;
}

.ynm-chat-expand-btn {
    background: rgba(255, 255, 255, 0.2);
    font-size: 18px;
}

.ynm-chat-settings-btn {
    background: rgba(255, 255, 255, 0.2);
    font-size: 20px;
    line-height: 1;
    font-weight: 400;
    position: relative;
    padding: 0 !important;
    color: transparent !important;
    font-size: 0 !important;
    text-indent: -9999px;
    overflow: hidden;
    opacity: 1 !important;
    -webkit-text-fill-color: transparent;
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Noto Sans Symbols", "Arial Unicode MS", sans-serif !important;
}

/* 强制兜底：无论线上是否处理 SVG/字体，按钮都显示齿轮图标 */
.ynm-chat-settings-btn svg {
    display: none !important;
}

.ynm-chat-settings-btn > * {
    display: none !important;
}

.ynm-chat-settings-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    background-color: #ffffff;
    /* Use vector mask instead of font glyph to avoid gray halo artifacts */
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 8.5a3.5 3.5 0 1 1 0 7 3.5 3.5 0 0 1 0-7Zm8.66 2.76-1.55-.26a6.53 6.53 0 0 0-.54-1.29l.93-1.23a.75.75 0 0 0-.1-.98l-1.4-1.4a.75.75 0 0 0-.98-.1l-1.23.93c-.42-.24-.86-.43-1.33-.57l-.26-1.54A.75.75 0 0 0 13.5 3h-2a.75.75 0 0 0-.74.62l-.26 1.55c-.47.14-.91.33-1.33.57l-1.23-.93a.75.75 0 0 0-.98.1l-1.4 1.4a.75.75 0 0 0-.1.98l.93 1.23c-.24.42-.43.86-.57 1.33l-1.54.26A.75.75 0 0 0 3 10.5v2c0 .37.27.69.64.74l1.55.26c.14.47.33.92.57 1.34l-.93 1.22a.75.75 0 0 0 .1.98l1.4 1.4c.26.26.67.29.98.1l1.23-.93c.42.24.86.43 1.33.57l.26 1.54c.05.37.37.64.74.64h2c.37 0 .69-.27.74-.64l.26-1.55c.47-.14.91-.33 1.33-.57l1.23.93c.31.19.72.16.98-.1l1.4-1.4c.26-.26.29-.67.1-.98l-.93-1.23c.24-.42.43-.86.57-1.33l1.54-.26c.37-.05.64-.37.64-.74v-2c0-.37-.27-.69-.64-.74Z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 8.5a3.5 3.5 0 1 1 0 7 3.5 3.5 0 0 1 0-7Zm8.66 2.76-1.55-.26a6.53 6.53 0 0 0-.54-1.29l.93-1.23a.75.75 0 0 0-.1-.98l-1.4-1.4a.75.75 0 0 0-.98-.1l-1.23.93c-.42-.24-.86-.43-1.33-.57l-.26-1.54A.75.75 0 0 0 13.5 3h-2a.75.75 0 0 0-.74.62l-.26 1.55c-.47.14-.91.33-1.33.57l-1.23-.93a.75.75 0 0 0-.98.1l-1.4 1.4a.75.75 0 0 0-.1.98l.93 1.23c-.24.42-.43.86-.57 1.33l-1.54.26A.75.75 0 0 0 3 10.5v2c0 .37.27.69.64.74l1.55.26c.14.47.33.92.57 1.34l-.93 1.22a.75.75 0 0 0 .1.98l1.4 1.4c.26.26.67.29.98.1l1.23-.93c.42.24.86.43 1.33.57l.26 1.54c.05.37.37.64.74.64h2c.37 0 .69-.27.74-.64l.26-1.55c.47-.14.91-.33 1.33-.57l1.23.93c.31.19.72.16.98-.1l1.4-1.4c.26-.26.29-.67.1-.98l-.93-1.23c.24-.42.43-.86.57-1.33l1.54-.26c.37-.05.64-.37.64-.74v-2c0-.37-.27-.69-.64-.74Z'/%3E%3C/svg%3E");
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
    display: block;
}

.ynm-chat-expand-btn:hover,
.ynm-chat-settings-btn:hover {
    opacity: 0.95;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

/* 设置按钮保持纯色外观，避免线上出现边缘光晕 */
.ynm-chat-settings-btn,
.ynm-chat-settings-btn:hover,
.ynm-chat-settings-btn:focus,
.ynm-chat-settings-btn:focus-visible,
.ynm-chat-settings-btn:active {
    box-shadow: none !important;
    outline: none !important;
    border: none !important;
    transform: none !important;
    opacity: 1 !important;
    filter: none !important;
    text-shadow: none !important;
}

.ynm-chat-expand-btn:active,
.ynm-chat-settings-btn:active {
    transform: translateY(0);
}

/* 独立短代码展开模式：仅放大聊天组件，不注入站点壳层 */
.ynm-chat-container--expanded {
    width: 80vw !important;
    max-width: 80vw !important;
    margin-left: calc(50% - 40vw) !important;
    margin-right: calc(50% - 40vw) !important;
    position: relative;
    z-index: 20;
    box-sizing: border-box;
}

.ynm-langflow-chat-wrapper--expanded {
    max-width: min(1400px, 100%) !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0;
    margin: 0 !important;
    border-radius: 12px;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    position: relative;
}

.ynm-langflow-chat-wrapper--expanded .ynm-langflow-chat-messages {
    height: auto;
    min-height: 0;
    flex: 1;
}

/* Expanded/fullscreen immersion mode: keep only top-right action buttons */
.ynm-chat-container--expanded .ynm-langflow-chat-header,
.ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-header {
    position: absolute !important;
    top: 8px;
    right: 12px;
    left: auto;
    width: auto;
    background: transparent !important;
    border-bottom: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    justify-content: flex-end !important;
    z-index: 8;
    pointer-events: none;
}

.ynm-chat-container--expanded .ynm-langflow-chat-header-left,
.ynm-chat-container--expanded .ynm-langflow-chat-header-center,
.ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-header-left,
.ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-header-center {
    display: none !important;
}

.ynm-chat-container--expanded .ynm-langflow-chat-header-right,
.ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-header-right {
    margin-left: auto;
    pointer-events: auto;
    padding: 4px;
    border-radius: 999px;
    background: var(--ynm-float-controls-bg);
    border: 1px solid var(--ynm-float-controls-border);
    backdrop-filter: blur(var(--ynm-float-controls-blur));
    -webkit-backdrop-filter: blur(var(--ynm-float-controls-blur));
    box-shadow: var(--ynm-float-controls-shadow);
}

.ynm-chat-container--expanded .ynm-chat-expand-btn,
.ynm-chat-container--expanded .ynm-chat-settings-btn,
.ynm-langflow-chat-container--fullscreen .ynm-chat-expand-btn,
.ynm-langflow-chat-container--fullscreen .ynm-chat-settings-btn {
    display: inline-flex !important;
    background: rgba(37, 99, 235, 0.82) !important;
}

@media (prefers-reduced-motion: reduce) {
    .ynm-langflow-chat-container,
    .ynm-langflow-chat-wrapper {
        transition: none !important;
    }
}

@media (max-width: 820px) {
    .ynm-chat-container--expanded {
        width: 100vw !important;
        max-width: 100vw !important;
        margin-left: calc(50% - 50vw) !important;
        margin-right: calc(50% - 50vw) !important;
        left: auto !important;
        right: auto !important;
        transform: none !important;
        overflow-x: clip;
    }
}

.ynm-langflow-chat-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 1px;
    white-space: nowrap;
}

.ynm-langflow-chat-header .message-avatar {
    width: 40px;
    height: 40px;
}

.ynm-langflow-chat-header .avatar-placeholder {
    font-size: 18px;
}

.ynm-langflow-chat-messages {
    min-height: 0;
    height: auto;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
    scroll-behavior: smooth;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
}

.message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    max-width: 70%;
    animation: fadeIn 0.3s ease-in;
    position: relative;
} 

.message.user-message {
    align-self: flex-end;
}

.message.ai-message {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color, #667eea) 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
}

.avatar-placeholder.ai {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    display: inline-block;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 0 1 auto;
}

.message.user-message .message-sender {
    color: var(--primary-color, #667eea);
}

.message.ai-message .message-sender {
    color: #4b5563;
    font-weight: 700;
}

/* 仅保留头像徽章：隐藏名字区域，避免遗留样式在旧缓存版本中显示 */
.message-sender {
    display: none !important;
}

.message-header,
.message.user-message .message-header {
    gap: 8px;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.8;
    position: relative;
    letter-spacing: 0.3px;
}

.message.user-message .message-content {
    background: #e8eef7;
    color: #2c3e50;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 3px rgba(102, 126, 234, 0.15);
}

.message.ai-message .message-content {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.message.error .message-content {
    background: #fee;
    color: #c33;
    border: 1px solid #fcc;
}

.message.loading .message-content {
    color: #666;
    font-style: italic;
    background: #f0f0f0;
}

/* Markdown content styles */
.markdown-content {
    white-space: normal; /* Override pre-wrap for markdown */
}

.markdown-content p {
    margin: 1em 0;
    line-height: 1.8;
}

.markdown-content p:first-child {
    margin-top: 0;
}

.markdown-content p:last-child {
    margin-bottom: 0;
}

.markdown-content strong {
    font-weight: 700;
    color: inherit;
}

.markdown-content em {
    font-style: italic;
}

.markdown-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.9em;
    color: #c7254e;
}

.markdown-content pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 0.85em;
    line-height: 1.4;
}

.markdown-content ul,
.markdown-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.markdown-content li {
    margin: 1em 0;
    line-height: 1.8;
}

.markdown-content blockquote {
    border-left: 4px solid #667eea;
    padding-left: 1.2em;
    margin: 1em 0;
    color: #4b5563;
    font-style: italic;
    background: rgba(102, 126, 234, 0.05);
    padding: 0.8em 1.2em;
    border-radius: 4px;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    margin: 0.8em 0 0.4em 0;
    font-weight: 600;
    line-height: 1.3;
}

.markdown-content h1 {
    font-size: 1.4em;
}

.markdown-content h2 {
    font-size: 1.2em;
}

.markdown-content h3 {
    font-size: 1.1em;
}

.markdown-content a {
    color: var(--primary-color, #667eea);
    text-decoration: underline;
}

.markdown-content a:hover {
    opacity: 0.8;
}

.markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 0.5em 0;
}

.markdown-content hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin: 1em 0;
}

/* User message shouldn't have markdown (plain text only) */
.message.user-message .message-text {
    white-space: pre-wrap;
}

/* Custom shortcode styles */
.chat-tip {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 0.8em 0;
    border-left: 4px solid;
    background: rgba(0, 0, 0, 0.03);
    line-height: 1.6;
}

.chat-tip-info {
    border-left-color: var(--primary-color, #667eea);
    background: rgba(102, 126, 234, 0.08);
}

.chat-tip-warning {
    border-left-color: #f59e0b;
    background: rgba(245, 158, 11, 0.08);
}

.chat-tip-success {
    border-left-color: #10b981;
    background: rgba(16, 185, 129, 0.08);
}

.chat-tip-error {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

.chat-highlight {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.chat-highlight-yellow {
    background: #fef3c7;
    color: #92400e;
}

.chat-highlight-blue {
    background: #dbeafe;
    color: #1e40af;
}

.chat-highlight-green {
    background: #d1fae5;
    color: #065f46;
}

.chat-highlight-red {
    background: #fee2e2;
    color: #991b1b;
}

.message-time {
    font-size: 11px;
    color: rgba(153, 153, 153, 0.6);
    margin-top: 8px;
    padding: 0 4px;
    align-self: flex-start;
}

.message.user-message .message-time {
    align-self: flex-end;
}

.ynm-langflow-chat-input {
    display: flex;
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    gap: 12px;
    align-items: flex-end;
}

.ynm-langflow-chat-input textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 20px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 20px;
    max-height: 100px;
    position: relative;
    z-index: 10;
    pointer-events: auto !important;
    cursor: text !important;
}

.ynm-langflow-chat-input textarea:focus {
    border-color: var(--primary-color, #667eea);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.ynm-langflow-chat-input textarea:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.send-button {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary-color, #667eea) 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: opacity 0.2s, transform 0.1s;
    white-space: nowrap;
    position: relative;
    z-index: 12;
    pointer-events: auto;
}

.send-button:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.send-button:active:not(:disabled) {
    transform: translateY(0);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Dark theme */
.theme-dark .ynm-langflow-chat-wrapper {
    background: #1a1a1a;
    border-color: #333;
}

.theme-dark .ynm-langflow-chat-messages {
    background: #1a1a1a;
}

.theme-dark .message.ai .message-content {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: #444;
}

.theme-dark .ynm-langflow-chat-input {
    background: #1a1a1a;
    border-top-color: #333;
}

.theme-dark .ynm-langflow-chat-input textarea {
    background: #2a2a2a;
    border-color: #444;
    color: #e0e0e0;
}

.theme-dark .message-sender {
    color: #ccc;
}

.theme-dark .message.user .message-sender {
    color: #8bb9fe;
}

.theme-dark .message.ai .message-sender {
    color: #ff8b8b;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 820px) {
    /* Mobile full-width handled by JS (getBoundingClientRect measurement) */

    .ynm-langflow-chat-wrapper:not(.ynm-langflow-chat-wrapper--expanded) {
        margin: 0;
        border-radius: 8px;
    }

    .ynm-langflow-chat-wrapper.ynm-langflow-chat-wrapper--expanded {
        margin: 0 !important;
        border-radius: 0;
    }

    .ynm-langflow-chat-messages {
        height: auto;
        min-height: 0;
        flex: 1;
        /* Compensate right-side scrollbar/safe-area so both sides look balanced */
        padding: 15px calc(15px + env(safe-area-inset-right) + 8px) 15px 8px;
    }

    .message {
        max-width: 76%;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
    }

    .message-sender {
        font-size: 11px;
    }

    .ynm-langflow-chat-input {
        padding: 12px calc(15px + env(safe-area-inset-right) + 8px) 12px 8px;
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }

    .ynm-langflow-chat-input textarea {
        min-width: 0;
    }

    .send-button,
    .send-button-round {
        align-self: center !important;
        flex: 0 0 auto;
    }

    .ynm-langflow-chat-header {
        padding: 12px 16px;
        font-size: 16px;
    }

    .ynm-chat-expand-btn,
    .ynm-chat-settings-btn {
        width: 36px;
        height: 36px;
    }

    /* Compact devices always use expanded layout, so hide the expand toggle */
    .ynm-chat-expand-btn {
        display: none !important;
    }

    .ynm-chat-expand-btn {
        font-size: 16px;
    }

    .ynm-langflow-chat-wrapper--expanded {
        border-radius: 0;
    }

    .ynm-langflow-chat-container--fullscreen {
        height: 100dvh !important;
    }

    .admin-bar .ynm-langflow-chat-container--fullscreen {
        height: calc(100dvh - 46px) !important;
    }

    .ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-wrapper {
        border: 0;
        margin: 0;
        border-radius: 0;
    }

    .ynm-langflow-chat-container--fullscreen .ynm-langflow-chat-messages {
        padding: 12px;
    }

    .ynm-langflow-chat-container--with-shell .ynm-shell-sidebar {
        display: none;
    }

    .ynm-langflow-chat-container--with-shell #ynm-langflow-chat-root {
        left: 0;
        width: 100%;
        padding: 0;
        background: transparent;
    }

    .ynm-langflow-chat-container--with-shell .ynm-shell-topbar {
        padding: 0 12px;
    }

    .ynm-langflow-chat-container--with-shell .ynm-shell-topbar::before,
    .ynm-langflow-chat-container--with-shell .ynm-shell-topbar-center {
        display: none;
    }

    .ynm-langflow-chat-container--with-shell .ynm-shell-topbar-brand {
        font-size: 14px;
    }

    .ynm-langflow-chat-container--with-shell .ynm-shell-menu-item {
        padding: 5px 10px;
        font-size: 12px;
    }

    .ynm-langflow-chat-container--with-shell .ynm-shell-topbar-menu {
        gap: 4px;
    }
}

/* Loading animation */
.message.loading .message-content {
    display: flex;
    align-items: center;
    gap: 6px;
}

.message.loading .message-content::after {
    content: '';
    animation: dots 1.5s infinite;
}

/* Loading message with animated dots */
.loading-message {
    display: flex;
    align-items: center;
    gap: 8px;
    font-style: italic;
    color: #666;
}

.loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.loading-dots .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: inline-block;
    animation: bounce 1.4s infinite;
}

.loading-dots .dot:nth-child(1) {
    animation-delay: 0s;
}

.loading-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

.ynm-history-loading-state {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #6b7280;
}

.ynm-history-loading-text {
    font-size: 13px;
    letter-spacing: 0.2px;
}

.ynm-history-loading-dots .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: inline-block;
    animation: bounce 1.4s infinite;
}

.ynm-history-loading-dots .dot:nth-child(1) {
    animation-delay: 0s;
}

.ynm-history-loading-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ynm-history-loading-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.8;
    }
    40% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Toast notification */
.toast-notification {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 999999;
    animation: toastSlideIn 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@keyframes toastSlideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes dots {
    0%, 20% { content: 'Thinking'; }
    40% { content: 'Thinking.'; }
    60% { content: 'Thinking..'; }
    80%, 100% { content: 'Thinking...'; }
}

/* 调查表单样式 */
.survey-form-container {
    margin-top: 15px;
    padding: 15px;
    background: #f0f7ff;
    border: 1px solid #b3d9ff;
    border-radius: 8px;
    max-width: 100%;
}

/* 强制显示 Form Maker 表单 */
.survey-form-container .fm-form-container {
    display: block !important;
}

/* 隐藏空白标题字段 */
.survey-form-container .wdform-label-section.wd-hidden {
    display: none !important;
}

/* 隐藏第一个字段（通常是空白字段）*/
.survey-form-container .wdform-field-section:first-of-type {
    display: none !important;
}

.survey-form-container .wdform_column > div:first-child {
    margin-top: 0;
}

.survey-form-container h3,
.survey-form-container h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #2c5aa0;
    font-size: 14px;
    font-weight: 600;
}

.survey-form-container form {
    margin: 0;
}

.survey-form-container label {
    display: block;
    margin: 8px 0 4px;
    color: #333;
    font-weight: 500;
    font-size: 13px;
}

/* Form Maker 隐藏字段 */
.survey-form-container .fm-hide {
    display: none !important;
}

/* 星级金色效果 */
.survey-form-container #wdform_2_element6 img,
.survey-form-container [id^="wdform_2_element"] img {
    transition: filter 0.15s ease, opacity 0.15s ease;
}

.survey-form-container #wdform_2_element6 img.fm-star-selected,
.survey-form-container [id^="wdform_2_element"] img.fm-star-selected {
    filter: brightness(1.05) saturate(2.2) hue-rotate(-10deg);
}

.survey-form-container input[type="text"],
.survey-form-container input[type="email"],
.survey-form-container input[type="number"],
.survey-form-container textarea,
.survey-form-container select {
    width: 100%;
    padding: 8px 12px;
    margin: 5px 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    box-sizing: border-box;
}

.survey-form-container textarea {
    min-height: 80px;
    resize: vertical;
}

.survey-form-container button,
.survey-form-container input[type="submit"] {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
    font-size: 14px;
    transition: opacity 0.2s, transform 0.1s;
}

.survey-form-container button:hover,
.survey-form-container input[type="submit"]:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.survey-form-container button:active,
.survey-form-container input[type="submit"]:active {
    transform: translateY(0);
}

/* 表单元素特殊样式 */
.survey-form-container .rating-container,
.survey-form-container .radio-group {
    display: flex;
    gap: 10px;
    margin: 8px 0;
}

/* 星级评分样式 */
.survey-form-container .dm_star_rating img {
    width: 24px;
    height: 24px;
    cursor: pointer;
    transition: transform 0.2s;
}

.survey-form-container .dm_star_rating img:hover {
    transform: scale(1.2);
}

.survey-form-container .fm-field {
    margin-bottom: 15px;
}

.survey-form-container .fm-label {
    font-weight: 500;
    margin-bottom: 5px;
    display: block;
}

/* 暗色主题支持 */
.theme-dark .survey-form-container {
    background: #1a2332;
    border-color: #2a5298;
}

.theme-dark .survey-form-container h3,
.theme-dark .survey-form-container h4 {
    color: #6eb5ff;
}

.theme-dark .survey-form-container label {
    color: #e0e0e0;
}

.theme-dark .survey-form-container input,
.theme-dark .survey-form-container textarea,
.theme-dark .survey-form-container select {
    background: #2a2a2a;
    border-color: #444;
    color: #e0e0e0;
}