/* =====================================================
   右侧悬浮区统一纵向排列（从屏幕底部向上）：
   ① 回到顶部 #back-to-top          (44px)
   ② 语言切换 .pll-fab-switch        (48px)
   ③ 主题侧边客服 .side-contact 💬   (70px)   ← 原 bottom:100px，被压住，这里纳入排列
   ④ 在线聊天 #dcssi-chat-float      (52px)
   ⑤ 聊天窗口 #dcssi-chat-window     (在④上方弹出)
   两两间距 10px；覆盖主题位置，禁用插件即恢复原样式。
   ===================================================== */
#back-to-top {
    bottom: 16px !important;
    right: 20px !important;
}
.pll-fab-switch {
    bottom: 70px !important;    /* ① 16+44 +10 */
    right: 20px !important;
}
/* 语言列表改为向左弹出：原向上展开（list 在 button 上方的 column 布局）
   会被上面的侧边客服/聊天按钮遮住。改为绝对定位到按钮左侧、垂直居中。 */
.pll-fab-switch .pll-fab-list {
    position: absolute !important;
    right: 56px !important;                 /* 按钮 48px + 8px 间距，列表在按钮左侧 */
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important; /* 列表垂直居中于按钮 */
}
.side-contact {
    bottom: 128px !important;   /* ② 70+48 +10 */
    right: 20px !important;
    z-index: 99999 !important;  /* 高于语言切换，低于聊天窗口，避免被压住 */
}

/* 侧边客服图标：原 💬 emoji 与在线聊天重复，且 s.w.org 境外 CDN 加载慢。
   替换为本地耳机客服 SVG（电话/邮件/微信 联系顾问） */
.side-contact-toggle .icon-message {
    font-size: 0 !important;             /* 隐藏 emoji 文字 */
    line-height: 0 !important;
    width: 28px !important;
    height: 28px !important;
    background: url("icon-contact.svg") center center / contain no-repeat !important;
}
.side-contact-toggle .icon-message img {
    display: none !important;            /* 隐藏 wp-emoji-release 替换出的 s.w.org 图片 */
}

/* 浮动按钮：fixed 定位，不参与页面布局流，不影响 CLS */
#dcssi-chat-float {
    position: fixed;
    right: 20px;
    bottom: 208px;              /* ③ 128+70 +10，位于侧边客服上方 */
    width: 52px;
    height: 52px;
    border-radius: 26px;
    background: #1a73e8;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,.18);
    z-index: 999999;
    transition: transform .12s ease;
}
#dcssi-chat-float:hover { transform: scale(1.04); }

#dcssi-chat-window {
    position: fixed;
    right: 20px;
    bottom: 270px;              /* ④ 208+52 +10，位于聊天按钮上方 */
    width: 340px;
    height: 460px;
    max-height: calc(100vh - 280px);  /* 小屏笔记本防顶部溢出 */
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0,0,0,.22);
    display: flex;
    flex-direction: column;
    z-index: 999998;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
}
#dcssi-chat-window[hidden] { display: none !important; }

.dcssi-chat-header {
    flex: 0 0 auto;
    padding: 12px 16px;
    background: #1a73e8;
    color: #fff;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#dcssi-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
}

#dcssi-chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px;
    background: #f7f8fa;
}

.dcssi-chat-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: flex-start;
}
.dcssi-chat-row.admin { flex-direction: row; }
.dcssi-chat-row.visitor { flex-direction: row-reverse; }

.dcssi-chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #fff;
}

.dcssi-chat-body {
    max-width: 75%;
    display: flex;
    flex-direction: column;
}
.dcssi-chat-row.visitor .dcssi-chat-body { align-items: flex-end; }

.dcssi-chat-name {
    font-size: 12px;
    color: #646970;
    margin-bottom: 2px;
}
.dcssi-chat-row.visitor .dcssi-chat-name { color: #1a73e8; }

.dcssi-chat-msg {
    padding: 8px 12px;
    border-radius: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
}
.dcssi-chat-msg.admin {
    background: #ffffff;
    color: #222222;
    border: 1px solid #e5e7eb;
}
.dcssi-chat-msg.visitor {
    background: #1a73e8;
    color: #ffffff;
}

/* 微信风格气泡小尾巴 */
.dcssi-chat-row.admin .dcssi-chat-msg {
    position: relative;
}
.dcssi-chat-row.admin .dcssi-chat-msg::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 10px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 6px solid #ffffff;
}
.dcssi-chat-row.admin .dcssi-chat-msg::after {
    content: "";
    position: absolute;
    left: -7px;
    top: 10px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 6px solid #e5e7eb;
    z-index: -1;
}
.dcssi-chat-row.visitor .dcssi-chat-msg {
    position: relative;
}
.dcssi-chat-row.visitor .dcssi-chat-msg::before {
    content: "";
    position: absolute;
    right: -6px;
    top: 10px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 6px solid #1a73e8;
}

.dcssi-chat-input-area {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    padding: 10px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}
#dcssi-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    min-height: 36px;
    max-height: 100px;
}
#dcssi-chat-input:focus { outline: none; border-color: #1a73e8; }
#dcssi-chat-send {
    flex: 0 0 auto;
    padding: 0 14px;
    border: none;
    background: #1a73e8;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
}
#dcssi-chat-send:active { background: #1557b0; }

@media (max-width: 480px) {
    /* 手机端：间距收紧为 10px，五个元素仍纵向排列不重叠
       主题会把 .side-contact-toggle 缩到 52×52（@768px） */
    #back-to-top {
        bottom: 12px !important;     /* h44 → 12~56 */
        right: 12px !important;
    }
    .pll-fab-switch {
        bottom: 66px !important;     /* 56+10 → 66~114 (h48) */
        right: 12px !important;
    }
    .side-contact {
        bottom: 124px !important;    /* 114+10 → 124~176 (h52) */
        right: 12px !important;
    }
    #dcssi-chat-float {
        right: 12px;
        bottom: 186px;               /* 176+10 → 186~238 (h52) */
    }
    #dcssi-chat-window {
        right: 8px;
        left: 8px;
        bottom: 248px;               /* 238+10，位于聊天按钮上方 */
        width: auto;
        height: 55vh;                /* 小屏缩短，防超屏 */
        max-height: none;
    }
}

/* =====================================================
   RTL（阿语）适配
   - flex 的 row/row-reverse 在 dir=rtl 下已自动镜像头像位置
   - 气泡小尾巴用的是 left/right 绝对定位，不随 flex 镜像，需手动翻转
   - 消息文本方向按内容自适应，避免中/英/阿混排时标点错乱
   ===================================================== */
html[dir="rtl"] .dcssi-chat-msg {
    unicode-bidi: plaintext;    /* 文本方向按首字符自动判断 */
    text-align: start;
}
html[dir="rtl"] .dcssi-chat-row.admin .dcssi-chat-msg::before {
    left: auto;
    right: -6px;
    border-right: none;
    border-left: 6px solid #ffffff;
}
html[dir="rtl"] .dcssi-chat-row.admin .dcssi-chat-msg::after {
    left: auto;
    right: -7px;
    border-right: none;
    border-left: 6px solid #e5e7eb;
}
html[dir="rtl"] .dcssi-chat-row.visitor .dcssi-chat-msg::before {
    right: auto;
    left: -6px;
    border-left: none;
    border-right: 6px solid #1a73e8;
}
/* 语言切换列表在 RTL 下同样向左弹出（物理方向，不受 dir 影响），无需改动 */

/* =====================================================
   全站移动端横向溢出修复（阿语 RTL 长内容撑破视口）
   根因：flex/grid 子项 min-width:auto 默认值，阿语长标题 nowrap 后
   固有宽度很大，把容器撑出视口，产生横向滚动。
   ===================================================== */
@media (max-width: 768px) {
    /* 数据表格：容器限宽，表格内部横向滚动，不撑破页面 */
    .geo-table-wrap {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* 新闻列表：移动端单列，标题允许换行，彻底避免 nowrap 溢出 */
    .news-list-grid { grid-template-columns: 1fr; }
    .news-list-item { min-width: 0; }
    .news-list-title {
        min-width: 0;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    /* 其它 grid 容器子项允许收缩，防止同类 min-content 撑破 */
    .news-focus-main,
    .news-focus-card { min-width: 0; }
}

/* =====================================================
   RTL（阿语）移动端导航修复
   现象：切到阿语后导航菜单默认展开、需往右滑才见正文。
   处理：菜单默认 visibility:hidden 强制隐藏（不依赖 left/right 定位，
   无论菜单实际落在哪都不会显示），点击汉堡按钮(.active)时才从右侧滑入；
   并兜底禁止 html/body 横向滚动。
   ===================================================== */
@media (max-width: 768px) {
    html, body { overflow-x: hidden !important; }

    html[dir="rtl"] .main-navigation {
        left: auto !important;
        right: 0 !important;
        transform: translateX(110%) !important;   /* 默认移出右缘外 */
        visibility: hidden !important;            /* 默认强制隐藏 */
        transition: transform .3s ease, visibility .3s ease !important;
    }
    html[dir="rtl"] .main-navigation.active {
        transform: translateX(0) !important;      /* 展开：滑入视口 */
        visibility: visible !important;
    }
}
