/* 前台模板切换器 - 浮窗样式 v2.2.0 */
.ts-wrap { position: fixed !important; z-index: 99998 !important; font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif !important; }

/* 面板传送容器：绝不允许成为内部 fixed 面板的包含块（禁 transform/filter/perspective/contain） */
.ts-portal {
    position: static !important;
    top: auto !important; right: auto !important; bottom: auto !important; left: auto !important;
    width: auto !important; height: auto !important;
    margin: 0 !important; padding: 0 !important;
    transform: none !important;
    filter: none !important;
    perspective: none !important;
    contain: none !important;
    will-change: auto !important;
    z-index: auto !important;
}

/* ============ 出发点位置 ============ */
.ts-pos-right-bottom { right: 24px !important; bottom: 24px !important; left: auto !important; top: auto !important; }
.ts-pos-right-top    { right: 24px !important; top: 24px !important; left: auto !important; bottom: auto !important; }
.ts-pos-left-bottom  { left: 24px !important; bottom: 24px !important; right: auto !important; top: auto !important; }
.ts-pos-left-top     { left: 24px !important; top: 24px !important; right: auto !important; bottom: auto !important; }
.ts-pos-right-center { right: 24px !important; top: 50% !important; transform: translateY(-50%) !important; left: auto !important; bottom: auto !important; }

/* ============ 触发按钮 ============ */
.ts-trigger {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--ts-theme, #FF6B35);
    color: #fff; padding: 9px 18px;
    border-radius: 24px;
    font-size: 14px; font-weight: 500;
    cursor: pointer; box-shadow: 0 4px 16px rgba(255, 107, 53, 0.35);
    transition: transform .2s, box-shadow .2s;
    user-select: none; line-height: 1;
}
.ts-trigger:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255, 107, 53, 0.45); }
.ts-btn-icon { flex-shrink: 0; }
.ts-btn-text { white-space: nowrap; }

.ts-entry-settings-entry .ts-trigger { padding: 10px; border-radius: 50%; width: 40px; height: 40px; justify-content: center; }
.ts-entry-settings-entry .ts-btn-text { display: none; }

/* ============ 面板基础（flex 列布局：头固定 / 中间滚动 / 底固定） ============ */
.ts-panel {
    position: absolute; background: #fff; border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.18), 0 4px 12px rgba(0,0,0,0.08);
    width: 600px; max-width: calc(100vw - 32px);
    max-height: calc(100vh - 48px);
    overflow: hidden;
    display: flex; flex-direction: column;
    opacity: 0; transform: translateY(8px) scale(.98); pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
}
.ts-panel.ts-show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.ts-panel[hidden] { display: none !important; }

/* 面板定位（风格2下拉：相对触发按钮） */
.ts-pos-right-bottom .ts-panel { right: 0; bottom: calc(100% + 12px); }
.ts-pos-right-top .ts-panel    { right: 0; top: calc(100% + 12px); }
.ts-pos-left-bottom .ts-panel  { left: 0; bottom: calc(100% + 12px); }
.ts-pos-left-top .ts-panel     { left: 0; top: calc(100% + 12px); }
.ts-pos-right-center .ts-panel { right: 0; top: 50%; transform: translateY(-50%); }

/* ============ 头部 / 主体 / 底部 ============ */
.ts-panel-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
}
.ts-panel-title { font-size: 16px; font-weight: 600; color: #333; display: flex; align-items: center; flex-wrap: wrap; row-gap: 2px; column-gap: 6px; min-width: 0; flex: 1 1 auto; }
.ts-panel-icon { color: var(--ts-theme, #FF6B35); font-size: 18px; font-weight: 700; }
/* 标题中的模板数量（主题色文字）；后缀整体不可拆行，窄面板时整段换到第二行 */
.ts-panel-count-wrap { white-space: nowrap; }
.ts-panel-count { color: var(--ts-theme, #FF6B35); font-weight: 700; padding: 0 1px; }
.ts-panel-close { color: #999; font-size: 24px; text-decoration: none; line-height: 1; padding: 0 4px; transition: color .2s; flex-shrink: 0; }
.ts-panel-close:hover { color: #333; }
.ts-panel-body {
    padding: 20px;
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.ts-panel-foot {
    padding: 14px 20px; border-top: 1px solid #f0f0f0;
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    flex-shrink: 0;
}
.ts-remember { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #666; cursor: pointer; }
.ts-remember input { width: 14px; height: 14px; accent-color: var(--ts-theme, #FF6B35); cursor: pointer; }
.ts-warn { color: var(--ts-theme, #FF6B35); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.ts-dot { display: inline-block; width: 6px; height: 6px; background: var(--ts-theme, #FF6B35); border-radius: 50%; }

/* 细滚动条 */
.ts-panel-body::-webkit-scrollbar { width: 6px; height: 6px; }
.ts-panel-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 3px; }
.ts-panel-body::-webkit-scrollbar-track { background: transparent; }

/* ============ 卡片通用 ============ */
.ts-card {
    border: 1px solid #e8e8e8; border-radius: 10px;
    background: #fff; cursor: pointer;
    transition: border-color .2s, box-shadow .2s, transform .2s, background .2s;
    position: relative;
}
.ts-card:hover { border-color: var(--ts-theme, #FF6B35); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.08); }
.ts-card-cover { position: relative; background: #f5f7fa; overflow: hidden; }
.ts-card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ts-card-name { font-weight: 600; color: #333; display: flex; align-items: center; gap: 6px; }
.ts-card-name-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 模板名后的复制按钮（主题色实心按钮） */
.ts-copy-btn {
    flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
    height: 22px; padding: 0 12px; border-radius: 11px;
    font-size: 11px; font-weight: 500; line-height: 1;
    color: #fff; background: var(--ts-theme, #FF6B35);
    box-shadow: 0 2px 6px rgba(0,0,0,.12);
    cursor: pointer; user-select: none;
    -webkit-tap-highlight-color: transparent; transition: opacity .15s, transform .15s;
}
.ts-copy-btn:hover, .ts-copy-btn:active { opacity: .85; transform: translateY(-1px); }
.ts-copy-btn.ts-copied { background: #67c23a !important; }
.ts-card-desc { font-size: 12px; color: #999; line-height: 1.5; }

/* 复制结果轻提示 */
.ts-copy-toast {
    position: fixed; left: 50%; bottom: 70px; z-index: 100000;
    transform: translate(-50%, 10px);
    background: rgba(0,0,0,.8); color: #fff;
    font-size: 13px; line-height: 1; padding: 10px 20px; border-radius: 18px;
    max-width: 82vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.ts-copy-toast.ts-show { opacity: 1; transform: translate(-50%, 0); }

/* 卡片右上角勾选标记（卡片级，所有风格通用） */
.ts-check {
    position: absolute; top: 8px; right: 8px;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--ts-theme, #FF6B35); color: #fff;
    font-size: 14px; display: none; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2); z-index: 2;
}
.ts-check::before { content: '✓'; font-weight: 700; }
.ts-card.ts-selected .ts-check { display: flex; }
.ts-card.ts-selected { border-color: var(--ts-theme, #FF6B35); }

/* ============================================================
   风格1：居中弹窗（大图 + 标题 + 描述，大屏一行4个，小屏自适应）
   ============================================================ */
.ts-style-popup-card .ts-panel {
    position: fixed !important;
    z-index: 99999 !important;
    top: 50% !important; left: 50% !important; right: auto !important; bottom: auto !important;
    width: 1000px !important;
    max-width: calc(100vw - 40px);
    max-height: 88vh;
    border-radius: 16px;
    transform: translate(-50%, -46%) scale(.98);
}
.ts-style-popup-card .ts-panel.ts-show { transform: translate(-50%, -50%) scale(1); }
.ts-style-popup-card .ts-panel-head { padding: 22px 26px 14px; border-bottom: none; }
.ts-style-popup-card .ts-panel-title { font-size: 21px; font-weight: 700; }
.ts-style-popup-card .ts-panel-body { padding: 8px 26px 22px; }
.ts-style-popup-card .ts-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.ts-style-popup-card .ts-card { border-radius: 14px; padding: 14px 14px 16px; }
.ts-style-popup-card .ts-card-cover { aspect-ratio: 16 / 10; border-radius: 10px; margin-bottom: 12px; }
.ts-style-popup-card .ts-card-name { padding: 0 0 4px; font-size: 15px; justify-content: center; }
.ts-style-popup-card .ts-card-name-text { white-space: normal; }
.ts-style-popup-card .ts-card-desc {
    padding: 0; text-align: center;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ts-style-popup-card .ts-card.ts-selected {
    box-shadow: 0 0 0 1px var(--ts-theme, #FF6B35);
    background: rgba(255, 107, 53, 0.05);
}
.ts-style-popup-card .ts-panel-foot { padding: 14px 26px 20px; }
@media (min-width: 640px)  { .ts-style-popup-card .ts-cards { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1080px) { .ts-style-popup-card .ts-cards { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 380px)  { .ts-style-popup-card .ts-cards { grid-template-columns: 1fr; } }

/* ============================================================
   风格2：右侧贴边下拉（左小缩略图 + 标题）
   ============================================================ */
.ts-style-dropdown .ts-panel { width: 300px; }
.ts-style-dropdown .ts-panel-head { padding: 12px 14px; gap: 8px; }
.ts-style-dropdown .ts-panel-title { font-size: 14px; }
.ts-style-dropdown .ts-panel-icon { font-size: 16px; }
.ts-style-dropdown .ts-panel-close { font-size: 20px; }
.ts-style-dropdown .ts-panel-body { padding: 12px; }
.ts-style-dropdown .ts-cards { display: flex; flex-direction: column; gap: 8px; }
.ts-style-dropdown .ts-card {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 10px; border-radius: 8px;
}
.ts-style-dropdown .ts-card-cover { width: 64px; height: 44px; flex: 0 0 64px; border-radius: 6px; }
.ts-style-dropdown .ts-card-name {
    flex: 1 1 auto; padding: 0; font-size: 14px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ts-style-dropdown .ts-card-desc { display: none; }
.ts-style-dropdown .ts-check { top: 6px; right: 6px; width: 16px; height: 16px; font-size: 10px; }
.ts-style-dropdown .ts-card.ts-selected { background: rgba(255, 107, 53, 0.06); }

/* ============================================================
   风格3：右侧抽屉（纯文字 标题+描述 列表，无图）
   ============================================================ */
.ts-style-drawer .ts-panel {
    position: fixed !important;
    z-index: 99999 !important;
    top: 0 !important; right: 0 !important; bottom: 0 !important; left: auto !important;
    width: 380px !important; max-width: 86vw !important;
    height: 100vh !important; max-height: 100vh !important;
    border-radius: 14px 0 0 14px;
    transform: translateX(100%);
    transition: transform .3s ease;
}
.ts-style-drawer .ts-panel.ts-show { transform: translateX(0); }
.ts-style-drawer .ts-panel-head { padding: 14px 16px; gap: 8px; }
.ts-style-drawer .ts-panel-title { font-size: 15px; }
.ts-style-drawer .ts-panel-icon { font-size: 17px; }
.ts-style-drawer .ts-panel-close { font-size: 22px; }
.ts-style-drawer .ts-panel-body { padding: 14px 16px; }
.ts-style-drawer .ts-cards { display: flex; flex-direction: column; gap: 10px; }
.ts-style-drawer .ts-card { border-radius: 8px; padding: 14px 16px 14px 18px; border-left: 3px solid transparent; }
.ts-style-drawer .ts-card-cover { display: none; }
.ts-style-drawer .ts-card-name { padding: 0 0 6px; font-size: 15px; line-height: 1.4; }
.ts-style-drawer .ts-card-name-text { white-space: normal; }
.ts-style-drawer .ts-card-desc {
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    color: #888; font-size: 13px;
}
.ts-style-drawer .ts-card.ts-selected {
    border-left-color: var(--ts-theme, #FF6B35);
    background: rgba(255, 107, 53, 0.06);
}

/* ============================================================
   风格4：底部横向滑条（上图 + 标题，可左右拉动）
   ============================================================ */
.ts-style-tab-segment .ts-panel {
    position: fixed !important;
    z-index: 99999 !important;
    left: 0 !important; right: 0 !important; bottom: 0 !important; top: auto !important;
    width: 100vw !important; max-width: 100vw !important;
    max-height: 56vh;
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
}
.ts-style-tab-segment .ts-panel.ts-show { transform: translateY(0); }
.ts-style-tab-segment .ts-panel-body {
    flex: 0 0 auto;
    overflow-x: auto; overflow-y: hidden;
    padding: 16px 20px;
}
.ts-style-tab-segment .ts-cards { display: flex; flex-wrap: nowrap; gap: 14px; }
.ts-style-tab-segment .ts-card { flex: 0 0 156px; border-radius: 10px; padding: 10px 10px 12px; }
.ts-style-tab-segment .ts-card-cover { aspect-ratio: 16 / 10; border-radius: 8px; margin-bottom: 10px; }
.ts-style-tab-segment .ts-card-name {
    padding: 0; font-size: 14px; font-weight: 500; justify-content: center;
    white-space: nowrap;
}
.ts-style-tab-segment .ts-card-desc { display: none; }
.ts-style-tab-segment .ts-card:hover { transform: translateY(-2px); }

/* ============ 遮罩 ============ */
.ts-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    z-index: 99997; opacity: 0; pointer-events: none; transition: opacity .25s;
    backdrop-filter: blur(2px);
}
.ts-mask.ts-show { opacity: 1; pointer-events: auto; }

/* ============ 移动端适配 ============ */
@media (max-width: 640px) {
    .ts-pos-right-bottom, .ts-pos-left-bottom { bottom: 16px; }
    .ts-pos-right-bottom { right: 16px; }
    .ts-pos-left-bottom { left: 16px; }
    .ts-pos-right-center { right: 14px !important; }

    /* 风格1：近全宽弹窗 */
    .ts-style-popup-card .ts-panel { width: calc(100vw - 24px) !important; max-height: 90vh; border-radius: 12px; }
    .ts-style-popup-card .ts-panel-head { padding: 16px 18px 10px; }
    .ts-style-popup-card .ts-panel-title { font-size: 18px; }
    .ts-style-popup-card .ts-panel-body { padding: 4px 18px 16px; }
    .ts-style-popup-card .ts-cards { gap: 12px; }
    .ts-style-popup-card .ts-card { padding: 10px 10px 12px; }
    .ts-style-popup-card .ts-panel-foot { padding: 12px 18px 14px; }

    /* 风格2：贴边窄下拉 */
    .ts-style-dropdown .ts-panel { width: calc(100vw - 28px) !important; }

    /* 风格3：近全宽抽屉 */
    .ts-style-drawer .ts-panel { width: 88vw !important; max-width: 88vw !important; }

    /* 风格4：底部横滑条，卡片更紧凑 */
    .ts-style-tab-segment .ts-panel { max-height: 48vh; }
    .ts-style-tab-segment .ts-panel-head { padding: 12px 16px; }
    .ts-style-tab-segment .ts-panel-body { padding: 12px 16px; }
    .ts-style-tab-segment .ts-card { flex-basis: 128px; padding: 8px 8px 10px; }
    .ts-style-tab-segment .ts-panel-foot { padding: 10px 16px; }
    .ts-style-tab-segment .ts-remember { font-size: 12px; }
    .ts-style-tab-segment .ts-warn { display: none; }
}

/* Loading 旋转 */
.ts-loading { display: inline-block; width: 14px; height: 14px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: ts-spin 0.7s linear infinite; }
@keyframes ts-spin { to { transform: rotate(360deg); } }
