/*
 * 前台浮动语言切换器
 * 由 addons/ldcms/utils/LangSwitcher.php 注入，样式全部带 ld-langsw 前缀，
 * 不依赖任何主题样式，也不会影响页面其它元素。
 *
 * 三个维度：
 *   data-pos    位置（right-center / right-top / ... ）
 *   data-style  形态（pill / edge / circle / text / list）
 *   data-preset 配色（light / dark / glass / brand / minimal）
 */

.ld-langsw {
    /* 兜底值：没有内联变量时也不会飘到文档流里 */
    --ldsw-x: 24px;
    --ldsw-y: 24px;
    position: fixed;
    z-index: 2147482000;
    font: 14px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--ldsw-fg);
    -webkit-tap-highlight-color: transparent;
}

/* ---------- 位置 ---------- */
.ld-langsw[data-pos="right-top"] {
    top: var(--ldsw-y);
    right: var(--ldsw-x);
}

.ld-langsw[data-pos="right-center"] {
    top: 50%;
    right: var(--ldsw-x);
    transform: translateY(-50%);
}

.ld-langsw[data-pos="right-bottom"] {
    bottom: var(--ldsw-y);
    right: var(--ldsw-x);
}

.ld-langsw[data-pos="left-center"] {
    top: 50%;
    left: var(--ldsw-x);
    transform: translateY(-50%);
}

.ld-langsw[data-pos="top-center"] {
    top: var(--ldsw-y);
    left: 50%;
    transform: translateX(-50%);
}

.ld-langsw[data-pos="bottom-center"] {
    bottom: var(--ldsw-y);
    left: 50%;
    transform: translateX(-50%);
}

.ld-langsw[data-pos="bottom-left"] {
    bottom: var(--ldsw-y);
    left: var(--ldsw-x);
}

.ld-langsw[data-pos="bottom-right"] {
    bottom: var(--ldsw-y);
    right: var(--ldsw-x);
}

/* ---------- 配色预设 ---------- */
.ld-langsw[data-preset="light"] {
    --ldsw-bg: #ffffff;
    --ldsw-fg: #2b333b;
    --ldsw-bd: #dfe4e9;
    --ldsw-sh: 0 8px 24px rgba(17, 24, 32, .14);
    --ldsw-acc: #1a73e8;
    --ldsw-hover: rgba(17, 24, 32, .06);
}

.ld-langsw[data-preset="dark"] {
    --ldsw-bg: #232a31;
    --ldsw-fg: #eef1f4;
    --ldsw-bd: #3b454f;
    --ldsw-sh: 0 8px 24px rgba(0, 0, 0, .4);
    --ldsw-acc: #5aa9ff;
    --ldsw-hover: rgba(255, 255, 255, .1);
}

.ld-langsw[data-preset="glass"] {
    --ldsw-bg: rgba(255, 255, 255, .68);
    --ldsw-fg: #232a31;
    --ldsw-bd: rgba(255, 255, 255, .8);
    --ldsw-sh: 0 8px 28px rgba(17, 24, 32, .16);
    --ldsw-acc: #1a73e8;
    --ldsw-hover: rgba(17, 24, 32, .08);
}

.ld-langsw[data-preset="glass"] .ld-langsw__btn,
.ld-langsw[data-preset="glass"] .ld-langsw__menu {
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
}

.ld-langsw[data-preset="brand"] {
    --ldsw-bg: var(--primary-color, #1a73e8);
    --ldsw-fg: #ffffff;
    --ldsw-bd: rgba(255, 255, 255, .32);
    --ldsw-sh: 0 8px 24px rgba(0, 0, 0, .18);
    --ldsw-acc: #ffffff;
    --ldsw-hover: rgba(255, 255, 255, .16);
}

.ld-langsw[data-preset="minimal"] {
    --ldsw-bg: transparent;
    --ldsw-fg: #2b333b;
    --ldsw-bd: transparent;
    --ldsw-sh: none;
    --ldsw-acc: inherit;
    --ldsw-hover: rgba(17, 24, 32, .06);
}

/* ---------- 按钮 ---------- */
.ld-langsw__btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 13px;
    margin: 0;
    border: 1px solid var(--ldsw-bd);
    border-radius: 999px;
    background: var(--ldsw-bg);
    color: var(--ldsw-fg);
    box-shadow: var(--ldsw-sh);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    line-height: 1;
    white-space: nowrap;
    transition: transform .15s ease, box-shadow .15s ease;
}

.ld-langsw__btn:hover {
    transform: translateY(-1px);
}

.ld-langsw__btn:focus-visible {
    outline: 2px solid var(--ldsw-acc);
    outline-offset: 2px;
}

.ld-langsw__flag {
    display: block;
    width: 20px;
    height: 14px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .08);
    flex: none;
}

.ld-langsw__globe {
    display: block;
    flex: none;
}

.ld-langsw__name {
    font-size: 13px;
    line-height: 1;
    white-space: nowrap;
}

.ld-langsw__caret {
    width: 0;
    height: 0;
    margin-left: 1px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: .5;
    transition: transform .18s ease;
}

.ld-langsw.is-open .ld-langsw__caret {
    transform: rotate(180deg);
}

/* ---------- 下拉菜单 ---------- */
.ld-langsw__menu {
    position: absolute;
    z-index: 1;
    min-width: 176px;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: var(--ldsw-bg);
    border: 1px solid var(--ldsw-bd);
    border-radius: 12px;
    box-shadow: var(--ldsw-sh);
    opacity: 0;
    visibility: hidden;
    transition: opacity .16s ease, transform .16s ease, visibility .16s;
}

/* 按位置决定展开方向，始终朝屏幕内侧弹 */
.ld-langsw[data-pos^="right"] .ld-langsw__menu {
    right: 0;
    top: calc(100% + 8px);
    transform: translateY(6px);
}

.ld-langsw[data-pos^="right"].is-open .ld-langsw__menu {
    transform: none;
}

.ld-langsw[data-pos="left-center"] .ld-langsw__menu {
    left: 0;
    top: calc(100% + 8px);
    transform: translateY(6px);
}

.ld-langsw[data-pos="left-center"].is-open .ld-langsw__menu {
    transform: none;
}

.ld-langsw[data-pos^="bottom"] .ld-langsw__menu {
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translate(-50%, 6px);
}

.ld-langsw[data-pos^="bottom"].is-open .ld-langsw__menu {
    transform: translate(-50%, 0);
}

.ld-langsw[data-pos="bottom-left"] .ld-langsw__menu {
    left: 0;
    transform: translateY(6px);
}

.ld-langsw[data-pos="bottom-left"].is-open .ld-langsw__menu {
    transform: translateY(0);
}

.ld-langsw[data-pos="top-center"] .ld-langsw__menu {
    left: 50%;
    top: calc(100% + 8px);
    transform: translate(-50%, 6px);
}

.ld-langsw[data-pos="top-center"].is-open .ld-langsw__menu {
    transform: translate(-50%, 0);
}


/* 下方空间不够时脚本会加 is-up，改成向上弹，避免菜单被视口底部截断 */
.ld-langsw.is-up .ld-langsw__menu {
    top: auto;
    bottom: calc(100% + 8px);
}

.ld-langsw.is-open .ld-langsw__menu {
    opacity: 1;
    visibility: visible;
}

.ld-langsw__menu li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ld-langsw__menu a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--ldsw-fg);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.3;
    white-space: nowrap;
}

.ld-langsw__menu a:hover,
.ld-langsw__menu a:focus {
    background: var(--ldsw-hover);
    text-decoration: none;
}

.ld-langsw__menu img {
    display: block;
    width: 20px;
    height: 14px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .08);
    flex: none;
}

.ld-langsw__menu li.is-active a {
    color: var(--ldsw-acc);
    font-weight: 600;
}

/* ---------- 形态：贴边 ---------- */
.ld-langsw[data-style="edge"] .ld-langsw__btn {
    height: 54px;
    padding: 0 10px;
}

/* 带语言名时按钮会宽一些，别把文字挤成两行 */
.ld-langsw[data-style="edge"][data-name="1"] .ld-langsw__btn {
    height: 46px;
    padding: 0 16px;
}

.ld-langsw[data-style="edge"][data-pos^="right"] {
    right: 0;
}

.ld-langsw[data-style="edge"][data-pos^="right"] .ld-langsw__btn {
    border-radius: 14px 0 0 14px;
    border-right: 0;
}

.ld-langsw[data-style="edge"][data-pos^="left"] {
    left: 0;
}

.ld-langsw[data-style="edge"][data-pos^="left"] .ld-langsw__btn {
    border-radius: 0 14px 14px 0;
    border-left: 0;
}

.ld-langsw[data-style="edge"][data-pos^="bottom"] {
    bottom: 0;
}

.ld-langsw[data-style="edge"][data-pos="bottom-center"] .ld-langsw__btn,
.ld-langsw[data-style="edge"][data-pos="bottom-left"] .ld-langsw__btn,
.ld-langsw[data-style="edge"][data-pos="bottom-right"] .ld-langsw__btn {
    border-radius: 14px 14px 0 0;
    border-bottom: 0;
}

.ld-langsw[data-style="edge"][data-pos="top-center"] {
    top: 0;
}

.ld-langsw[data-style="edge"][data-pos="top-center"] .ld-langsw__btn {
    border-radius: 0 0 14px 14px;
    border-top: 0;
}

/* ---------- 形态：圆形 ---------- */
.ld-langsw[data-style="circle"] .ld-langsw__btn {
    width: 46px;
    height: 46px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
}

/* 带语言名就装不进正圆了，自动拉成胶囊 */
.ld-langsw[data-style="circle"][data-name="1"] .ld-langsw__btn {
    width: auto;
    height: 40px;
    padding: 0 14px;
    border-radius: 999px;
}

/* 只有图标时不显示下拉小三角 */
.ld-langsw[data-style="circle"][data-name="0"] .ld-langsw__caret {
    display: none;
}

.ld-langsw[data-style="circle"] .ld-langsw__flag {
    width: 22px;
    height: 15px;
}

/* ---------- 形态：纯文字 ---------- */
.ld-langsw[data-style="text"] .ld-langsw__btn {
    height: auto;
    padding: 4px 6px;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
}

.ld-langsw[data-style="text"] .ld-langsw__menu {
    min-width: 140px;
}

/* ---------- 形态：常驻横排 ---------- */
.ld-langsw[data-style="list"] .ld-langsw__btn {
    display: none;
}

.ld-langsw[data-style="list"] .ld-langsw__menu {
    position: static;
    display: flex;
    gap: 2px;
    min-width: 0;
    max-height: none;
    padding: 4px;
    border-radius: 999px;
    opacity: 1;
    visibility: visible;
    transform: none;
}

.ld-langsw[data-style="list"] .ld-langsw__menu a {
    padding: 6px 8px;
    border-radius: 999px;
}

/* 横排语言多时，只有图标更省地方 */
.ld-langsw[data-style="list"][data-name="0"] .ld-langsw__menu a {
    padding: 6px;
}

/* ---------- 手机 ---------- */
@media (max-width: 767px) {
    .ld-langsw[data-pos="right-center"],
    .ld-langsw[data-pos="left-center"] {
        top: auto;
        bottom: calc(var(--ldsw-y) + 12px);
        transform: none;
    }

    .ld-langsw[data-pos="left-center"] {
        left: var(--ldsw-x);
    }

    .ld-langsw[data-pos="right-center"] {
        right: var(--ldsw-x);
    }

    .ld-langsw__btn {
        height: 40px;
        padding: 0 11px;
    }
}

/* 显示规则矩阵：按终端显隐（断点与询盘浮窗保持一致） */
@media (min-width: 769px) {
    .ld-langsw[data-pc="0"] {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .ld-langsw[data-wap="0"] {
        display: none !important;
    }
}

/* 打印时不出现 */
@media print {
    .ld-langsw {
        display: none !important;
    }
}
