/* ---------- 在线客服 /kefu（淡蓝配色，避免高饱和 #1989fa 刺眼） ---------- */

/* 独立客服页：无整站顶栏时顶边距拉满（不含内嵌，避免命中两套布局） */
body.kefu-standalone .main.page-kefu:not(.page-kefu--embed) {
    margin-top: 0;
    padding-top: 12px;
    padding-left: 12px;
    padding-right: 12px;
    box-sizing: border-box;
}

.kefu-wrap {
    display: flex;
    gap: 20px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 8px 0 32px;
    box-sizing: border-box;
}
.kefu-left {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.kefu-box {
    background: #fff;
    border-radius: 3px;
    border: var(--surface-border);
    box-shadow: var(--surface-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.kefu-hd {
    background: #f2f3f4;
    color: #1a4d6e;
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 600;
}
.kefu-msgs {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fff;
    -webkit-overflow-scrolling: touch;
}
.kefu-msgs .msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 3px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}
.kefu-msgs .msg.visitor {
    align-self: flex-end;
    background: #e0eff9;
    color: #2c4a6b;
    border: 1px solid rgba(44, 74, 107, 0.08);
    border-bottom-right-radius: 4px;
}
.kefu-msgs .msg.staff {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border: var(--surface-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.kefu-msgs .msg .time { font-size: 11px; opacity: 0.75; margin-top: 4px; }
.kefu-msgs .msg.visitor .time { text-align: right; }
.kefu-msgs .msg.sending { opacity: 0.55; }
.kefu-msgs .sys-tip { text-align: center; font-size: 13px; color: #999; padding: 10px 0; }
.kefu-ipt {
    display: flex;
    border-top: var(--divider-soft);
    background: #fff;
}
.kefu-ipt textarea {
    flex: 1;
    border: none;
    outline: none;
    padding: 12px 14px;
    font-size: 14px;
    resize: none;
    height: 60px;
    font-family: inherit;
}
/* 发送：与 layui 按钮同类交互——纯色 + background-color 过渡，悬停略亮、按下略暗 */
.kefu-ipt button {
    width: 80px;
    border: none;
    background-color: #000;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.2s ease;
}
.kefu-ipt button:hover {
    background-color: #4a4a4a;
}
.kefu-ipt button:active {
    background-color: #1a1a1a;
}

.kefu-right { width: 280px; flex-shrink: 0; }
.kefu-info {
    background: #fff;
    border-radius: 3px;
    border: var(--surface-border);
    box-shadow: var(--surface-shadow);
    padding: 22px 20px;
    text-align: center;
}
.kefu-info .tg-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    background: linear-gradient(135deg, #0088cc, #00aaff);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.kefu-info .tg-icon svg { width: 32px; height: 32px; fill: #fff; }
.kefu-info .tg-label { font-size: 13px; color: #666; margin-bottom: 8px; }
.kefu-info .tg-link {
    display: inline-block;
    font-size: 16px;
    font-weight: 600;
    color: #1989fa;
    text-decoration: none;
    padding: 8px 18px;
    background: #e8f4ff;
    border-radius: 3px;
    border: 1px solid rgba(25, 137, 250, 0.22);
    transition: background 0.2s, box-shadow 0.2s;
}
.kefu-info .tg-link:hover { background: #d6ebff; box-shadow: var(--surface-shadow); }
.kefu-info .notice--solo {
    margin-top: 0;
}
.kefu-info .notice {
    margin-top: 20px;
    padding: 14px 16px;
    background: #f3f8fc;
    border-radius: 3px;
    border: 1px solid rgba(61, 122, 158, 0.12);
    text-align: left;
}
.kefu-info .notice-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.kefu-info .notice-title::before { content: "📱"; font-size: 16px; }
.kefu-info .notice-text { font-size: 13px; color: #666; line-height: 1.75; }

/* 客服页（桌面）：整页不滚动，仅 .kefu-msgs 内滚动；排除内嵌 body，避免 iframe 里 100dvh/锁高把高度算成 0 */
body:has(.main.page-kefu):not(.kefu-embed-page) {
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}
/* 客服页主栏：仅全页 /kefu（内嵌用 page-kefu--embed，走下方专用段，避免 flex:1 1 0 + min-height:0 在窄屏把高度压没） */
.main.page-kefu:not(.page-kefu--embed) {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-top: 8px;
    margin-bottom: 0;
    padding-bottom: 8px;
}
.main.page-kefu:not(.page-kefu--embed) .kefu-wrap {
    flex: 1 1 0;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    padding: 0;
    overflow: hidden;
    align-items: stretch;
    align-self: stretch;
    width: 100%;
    box-sizing: border-box;
}
.main.page-kefu:not(.page-kefu--embed) .kefu-right {
    max-height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* 内嵌主栏：不参与全页 flex 吃高逻辑，用 auto + 最小高度保证 <768px 仍有内容区 */
.main.page-kefu.page-kefu--embed {
    flex: 1 1 auto;
    min-height: 320px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body:has(.main.page-kefu) .site-footer-wrap {
    margin-top: 0;
}

@media (max-width: 768px) {
    /* 勿作用于 .kefu-embed-page：窄 iframe/弹层会命中本断点，min-height:0 会把内嵌 body 压成高度0 */
    body:has(.main.page-kefu):not(.kefu-embed-page) {
        min-height: 0;
        max-height: none;
        overflow: visible;
    }
    /* 仅全页 /kefu：竖向 column，聊天在上、TG 在下 */
    .main.page-kefu:not(.page-kefu--embed) > .kefu-wrap {
        flex-direction: column;
        padding-bottom: 0;
    }
    .main.page-kefu:not(.page-kefu--embed) .kefu-right {
        width: 100%;
    }

    /* 手机全页客服：允许整页滚动；排除内嵌（由内嵌专用段负责） */
    html:has(.main.page-kefu):not(:has(body.kefu-embed-page)) {
        height: auto;
        min-height: 100%;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .main.page-kefu:not(.page-kefu--embed) {
        height: auto;
        max-height: none;
        min-height: 100dvh;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1 1 0;
    }
    .main.page-kefu:not(.page-kefu--embed) .kefu-wrap {
        flex: 1 1 0;
        min-height: 0;
        height: auto;
        max-height: none;
        overflow: hidden;
        align-self: stretch;
    }
    .main.page-kefu:not(.page-kefu--embed) .kefu-left {
        flex: 1 1 0;
        min-height: 0;
    }
    .main.page-kefu:not(.page-kefu--embed) .kefu-box {
        flex: 1 1 0;
        min-height: 0;
    }
    .main.page-kefu:not(.page-kefu--embed) .kefu-msgs {
        flex: 1 1 0;
        min-height: 0;
    }
    .main.page-kefu:not(.page-kefu--embed) .kefu-right {
        flex-shrink: 0;
        max-height: none;
        overflow: visible;
    }
}

/* ---------- 内嵌页 /kefu/embed（iframe 弹层等）：纵向占满 iframe，避免100dvh 按外层视口算高 ---------- */
html:has(body.kefu-embed-page) {
    margin: 0;
    min-height: 100%;
    min-height: max(420px, 100%);
    height: auto;
}
@supports (height: 100dvh) {
    html:has(body.kefu-embed-page) {
        min-height: max(420px, 100dvh);
    }
}
body.kefu-embed-page {
    margin: 0;
    box-sizing: border-box;
    /* 弹层 iframe 里父级高度常为 0，仅用 100% 会把整页 flex 压成 0；用 min兜底 */
    min-height: 100%;
    min-height: max(420px, 100%);
    height: auto;
    max-height: none;
}
/* 独立标签打开 /kefu/embed 时仍铺满视口 */
@supports (height: 100dvh) {
    body.kefu-embed-page {
        min-height: max(420px, 100dvh);
    }
}
/* 盖过 body:has(.main.page-kefu) 的 100dvh；勿对 embed 再用 max-height:100% 锁死 */
body.kefu-embed-page:has(.main.page-kefu) {
    overflow-x: hidden;
    overflow-y: auto;
    max-height: none;
 height: auto;
}
/* 内嵌：common.css 的 body 列 flex 下，用 auto 与 px 级 min-height，窄屏不依赖父级高度百分比 */
body.kefu-embed-page > .main.page-kefu--embed {
    flex: 1 1 auto;
    min-height: 360px;
    min-height: max(360px, min(55vh, 620px));
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}
body.kefu-embed-page.kefu-standalone > .main.page-kefu--embed {
    margin: 0;
    padding: 0;
}
body.kefu-embed-page .kefu-wrap {
    flex: 1 1 auto;
    padding: 0;
    margin: 0;
    min-height: 340px;
    height: auto;
    max-height: none;
    box-sizing: border-box;
    align-items: stretch;
    align-self: stretch;
    width: 100%;
    overflow: hidden;
}
body.kefu-embed-page .kefu-left {
    flex: 1 1 auto;
    min-height: 280px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
body.kefu-embed-page .kefu-box--embed {
    position: relative;
    flex: 1 1 auto;
    min-height: 260px;
    height: auto;
    border-radius: 0;
    box-shadow: none;
}
@media (max-width: 768px) {
    html:has(body.kefu-embed-page) {
        min-height: max(480px, 100%);
        height: auto;
    }
    body.kefu-embed-page:has(.main.page-kefu) {
        min-height: max(480px, 100%);
        max-height: none;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
    }
    body.kefu-embed-page > .main.page-kefu--embed {
        flex: 1 1 auto;
        min-height: 400px;
        max-height: none;
        height: auto;
        overflow: hidden;
    }
    body.kefu-embed-page .kefu-wrap {
        flex: 1 1 auto;
        min-height: 380px;
        height: auto;
        max-height: none;
        overflow: hidden;
    }
    body.kefu-embed-page .kefu-left {
        flex: 1 1 auto;
        min-height: 360px;
    }
    body.kefu-embed-page .kefu-box--embed {
        flex: 1 1 auto;
        min-height: 340px;
        height: auto;
    }
}
