/* ==========================================================================
   栏目：自选（分组 / 口径 / 加自选）
   ========================================================================== */

/* ============================ 自选（分组 / 口径） ============================ */

/* 自选页没有 hero 了，分组条自己带一点上间距 */
.groupbar { margin: 18px 0 0; }

/* 分组条：左边分组按钮横向滚，右边固定一个「分组管理」入口 */
.groupbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.groupbar .seg {
    flex: 1 1 auto;
    min-width: 0;
    margin-bottom: 0;
}

.group-mgr-btn {
    flex: 0 0 auto;
    height: 40px;
    padding: 0 12px;
    font-size: 13px;
    border-radius: 11px;
}

/* 分组管理面板是页面内的遮罩，重命名 / 确认弹层要盖在它上面 */
#groupMgrMask { z-index: 90; }
#groupNameMask { z-index: 93; }

/* ============================ 分组管理面板 ============================ */

.sheet-mgr {
    max-width: 560px;
    display: flex;
    flex-direction: column;
    max-height: 88vh;
}

.gm-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.gm-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.4px;
    line-height: 1.19;
}

.gm-done {
    border: 0;
    background: transparent;
    color: var(--blue);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: -0.2px;
    cursor: pointer;
    padding: 4px 2px;
}

/* 列标题：分组名称 + 四个操作 */
.gm-cols {
    display: flex;
    align-items: center;
    padding: 0 0 8px;
    color: var(--text-3);
    font-size: 12.5px;
}

.gm-c-name { flex: 1 1 auto; }
.gm-c-act { flex: 0 0 34px; text-align: center; }

.gm-list {
    flex: 1 1 auto;
    overflow-y: auto;
    margin: 0 -20px;
    -webkit-overflow-scrolling: touch;
    /* 拖到边缘自动滚动时，别把整页也带着滚 */
    overscroll-behavior: contain;
}

.gm-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 20px;
    border-top: 1px solid var(--sep);
    background: var(--bg-elevated);
    touch-action: pan-y;
    /* 拖动时其它行靠 transform 平移，过渡让位移动画更顺 */
    transition: transform .18s cubic-bezier(.2, .7, .3, 1);
}

/* 拖起来的那一行：抬起、放大，跟随手指走 */
.gm-row.dragging {
    transition: none;
    position: relative;
    z-index: 5;
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
    cursor: grabbing;
}

.gm-row-all { background: var(--bg-soft); }

.gm-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: -0.2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gm-count {
    margin-left: 6px;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-3);
}

.gm-acts {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 2px;
}

.gm-act {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.gm-act svg { width: 17px; height: 17px; display: block; }
.gm-act:hover { background: var(--bg-soft); color: var(--text); }
.gm-act:active { transform: scale(0.92); }
.gm-act.on { color: var(--blue); }
.gm-act-danger { color: var(--danger); }
.gm-act-danger:hover { color: var(--danger); background: var(--danger-soft); }

/* 拖动把手：按住时不要跟着页面滚 */
.gm-drag { touch-action: none; cursor: grab; }
.gm-drag:active { cursor: grabbing; }
/* 手柄给个更大的点按区域，手指好按住 */
.gm-drag {
    width: 40px;
    height: 40px;
    margin: -2px;
}

.gm-add {
    margin-top: 16px;
    width: 100%;
    height: 48px;
    border: 0;
    border-radius: 10px;
    background: var(--blue-soft);
    color: var(--blue);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: -0.2px;
    cursor: pointer;
}

.gm-add:active { opacity: 0.85; }

/* ============================ 自选编辑模式 ============================ */

/* 编辑模式下把「口径 / 间隔 / 排序」收起来：手动排序要按自选原始顺序看，
   涨幅排序会让拖动的结果看起来没生效 */
.toolbar-tools.editing .tb-set { display: none; }

/* 勾选框 */
.watch-pick {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.watch-pick-box {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-soft);
    box-shadow: inset 0 0 0 1.5px var(--text-3);
    color: transparent;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.watch-pick.on .watch-pick-box { background: var(--blue); color: #fff; box-shadow: none; }

/* 拖动时其它行靠 transform 平移 */
.watch-card-edit {
    transition: transform .18s cubic-bezier(.2, .7, .3, 1);
}

.watch-card-edit.dragging {
    transition: none;
    position: relative;
    z-index: 5;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
}

/* 编辑模式底部操作条 */
.edit-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--tabbar-h) + var(--safe-b));
    z-index: 40;
    padding: 9px 16px 10px;
    background: var(--bg-nav-strong);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.edit-bar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.edit-bar-count {
    font-size: 13px;
    color: var(--text-2);
    letter-spacing: -0.2px;
}

.link-btn {
    border: 0;
    background: transparent;
    color: var(--blue);
    font-size: 13.5px;
    font-weight: 500;
    letter-spacing: -0.2px;
    cursor: pointer;
    padding: 2px 0;
}

.edit-bar-acts {
    display: flex;
    gap: 8px;
}

.edit-bar-acts .btn { flex: 1 1 0; justify-content: center; }

.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { color: var(--danger); background: var(--danger-soft); }

/* 操作条会压住最后一张卡片，列表底下留点空 */
body.watch-editing #watchList { padding-bottom: 108px; }

/* 移动分组弹层里的分组项 */
.mv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--bg-soft);
    cursor: pointer;
}

.mv-item:active { opacity: 0.8; }

@media (min-width: 900px) {
    .edit-bar {
        left: 50%;
        right: auto;
        bottom: 22px;
        transform: translateX(-50%);
        width: min(560px, calc(100% - 44px));
        border-radius: 16px;
        box-shadow: var(--shadow-pop);
    }

    body.watch-editing #watchList { padding-bottom: 0; }
}

/* H5：分组条吸在顶栏下面，滑动列表时一直可见，不跟着滚走 */
@media (max-width: 899px) {
    /* 自选页顶部不留空（分组条紧贴顶栏） */
    body[data-view="watch"] .page { padding-top: 0; }

    .groupbar {
        position: sticky;
        top: var(--header-h, 0px);
        z-index: 30;
        margin: 0 -16px;
        padding: 6px 16px 0;
        background: var(--bg);
    }

    .groupbar .seg { margin-bottom: 0; }
    .group-mgr-btn { height: 36px; padding: 0 11px; font-size: 12.5px; }
}

.btn-danger { background: rgba(255, 69, 58, 0.12); color: #ff453a; }
.btn-danger:hover { background: rgba(255, 69, 58, 0.2); }

.toolbar-tools {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* 工具条上的控件整体压小一号：字小一点、行矮一点，
   一整排（口径 / 间隔 / 排序 / 刷新 / 加自选 / 编辑）看着更紧凑 */
.toolbar-tools .select {
    height: 34px;
    padding: 0 24px 0 11px;
    font-size: 13px;
    background-position: calc(100% - 14px) 14px, calc(100% - 9px) 14px;
}

.toolbar-tools .btn {
    height: 34px;
    padding: 0 15px;
    font-size: 13.5px;
}

/* 排序按钮：文字只有「默认 / 涨幅↑ / 涨幅↓」，宽度收窄，跟其他控件挤在一起 */
.toolbar-tools .btn-sort {
    min-width: 64px;
    padding: 0 12px;
}

/* 工具条分成两组：设置（口径 / 间隔 / 排序）和 操作（刷新 / 加自选） */
.tb-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* H5 窄屏：整条工具栏压成一行
   —— 顶栏已经有刷新按钮了，工具条里的「刷新」在手机上省掉；
   下拉和按钮都收窄一点，保证 自动 / 间隔 / 涨幅 / 加自选 挤在一行。 */
@media (max-width: 899px) {
    #watchRefreshBtn { display: none; }

    .tb-set { width: auto; }
    .tb-act { width: auto; justify-content: flex-start; }

    .toolbar-tools { gap: 5px; }
    .tb-group { gap: 5px; }

    /* 手机上更紧一点，保证 自动 / 间隔 / 排序 / 加自选 / 编辑 挤在一行 */
    .toolbar-tools .select { padding: 0 22px 0 10px; }
    .toolbar-tools .btn { padding: 0 13px; }
    .toolbar-tools .btn-sort { padding: 0 10px; }
}

.select {
    appearance: none;
    -webkit-appearance: none;
    height: 40px;
    padding: 0 30px 0 14px;
    border: 0;
    border-radius: 12px;
    background: var(--bg-elevated);
    background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                      linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
    background-position: calc(100% - 16px) 17px, calc(100% - 11px) 17px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    color: var(--text);
    font-size: 14px;
    outline: none;
    cursor: pointer;
}

.select:focus { box-shadow: 0 0 0 2px var(--blue); }
.select-sm { height: 30px; font-size: 12px; padding: 0 26px 0 10px; background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px; }

/* ============================ 自选列表：表格模式 ============================ */

/* 表格容器：列多了可以横向滑，基金名列固定在左边 */
/* 列模板统一由 --wt-cols 控制，表头与所有行共用，保证列对齐 */
.wtbl {
    --wt-cols: minmax(240px, 420px) minmax(92px, 1fr) minmax(108px, 1fr) 74px 96px 44px;
    background: var(--bg-card);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.wtbl-head,
.wt-row {
    display: grid;
    grid-template-columns: var(--wt-cols);
    align-items: center;
    width: max-content;
    min-width: 100%;
}

/* 表头 */
.wtbl-head {
    background: var(--bg-soft);
    border-bottom: 1px solid var(--sep);
    border-radius: 14px 14px 0 0;
}

.wt-th {
    flex: 0 0 auto;
    margin: 0;
    padding: 9px 10px;
    border: 0;
    background: transparent;
    color: var(--text-3);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: -0.1px;
    white-space: nowrap;
    text-align: right;
}

.wt-th-name {
    text-align: left;
    padding-left: 14px;
    position: sticky;
    left: 0;
    z-index: 3;
    background: inherit;
}
.wt-th-val { }
.wt-th-pct { }
.wt-th-time { }
.wt-th-src { }
.wt-th-act { padding: 0; }

/* 可排序的表头：点一下切 升序 → 降序 → 默认 */
.wt-sort {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
}

.wt-sort:hover { color: var(--text-2); }
.wt-sort.on { color: var(--blue); }
.wt-sort-ic { font-style: normal; font-size: 9px; opacity: .65; }

/* 行 */
.wt-rows { list-style: none; margin: 0; padding: 0; }

.wt-row {
    border-bottom: 1px solid var(--sep);
    background: var(--bg-card);
    transition: background .15s, transform .18s cubic-bezier(.2, .7, .3, 1);
}

/* 拖动中的行：抬起 + 阴影 */
.wt-row.dragging {
    transition: none;
    position: relative;
    z-index: 5;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
}

.wt-row:last-child { border-bottom: 0; }
.wt-row:hover { background: var(--bg-soft); }

.wt-rows .empty { border-radius: 0; }

/* 没有数据时不横向滚动，避免空表格下面挂一条滚动条 */
.wtbl.wt-empty { overflow-x: hidden; }

/* 基金名列：横向滑动时固定在左边，多余空间优先给它 */
.wt-name {
    min-width: 0;
    overflow: hidden;
    padding: 9px 10px 9px 14px;
    position: sticky;
    left: 0;
    z-index: 2;
    background: inherit;
}

.wt-name-t {
    min-width: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

/* 名字太长就省略，类型标签始终完整 */
.wt-nm {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wt-name-s {
    margin-top: 2px;
    font-size: 11.5px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 数值列 */
.wt-cell {
    flex: 0 0 auto;
    padding: 9px 10px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.wt-val { }
.wt-pct { }
.wt-time { color: var(--text-3); font-size: 12px; }
.wt-src { }
.wt-act { padding: 0 4px; }

.wt-big {
    display: block;
    white-space: nowrap;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.2px;
    font-variant-numeric: tabular-nums;
}

.wt-small {
    display: block;
    margin-top: 1px;
    font-size: 11px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

/* 估值日期 */
.wt-date { min-height: 13px; }

/* 数据源下拉：描边药丸，展开走系统选择器（自带 ✓ 与高亮） */
.wt-src .src-pick {
    appearance: none;
    -webkit-appearance: none;
    flex: 0 0 auto;
    min-width: 62px;
    height: 28px;
    padding: 0 20px 0 10px;
    border: 1px solid var(--sep-strong);
    border-radius: 9px;
    background-color: var(--bg-elevated);
    background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                      linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
    background-position: calc(100% - 11px) 12px, calc(100% - 7px) 12px;
    background-size: 4px 4px, 4px 4px;
    background-repeat: no-repeat;
    color: var(--text);
    font-size: 12.5px;
    font-weight: 500;
    letter-spacing: -0.2px;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.wt-src .src-pick:hover { border-color: var(--blue); color: var(--blue); }
.wt-src .src-pick:focus { outline: none; box-shadow: 0 0 0 2px var(--blue); }

.wt-act .btn-icon { width: 26px; height: 26px; border-radius: 9px; }
.wt-act .btn-icon svg { width: 15px; height: 15px; }

/* 编辑模式：只留勾选框 + 基金名 + 拖动把手 */
.wt-lead { display: none; flex: 0 0 34px; align-items: center; justify-content: center; }
.wt-drag {
    display: none;
    flex: 0 0 30px;
    align-items: center;
    justify-content: center;
    /* 加大点按热区，H5 上更好抓 */
    padding: 9px 0;
    border: 0;
    background: transparent;
    color: var(--text-3);
    cursor: grab;
    /* 按住时不要跟着页面滚 */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.wt-drag:hover { color: var(--text-2); }
.wt-drag:active { cursor: grabbing; color: var(--text); }
.wt-drag svg { width: 16px; height: 16px; display: block; }
body.watch-editing .wt-lead {
    display: flex;
    position: sticky;
    left: 0;
    z-index: 3;
    background: inherit;
}
body.watch-editing .wt-drag { display: inline-flex; }
body.watch-editing .wt-cell { display: none; }
body.watch-editing .wtbl-head { display: none; }
body.watch-editing .wt-name { left: 34px; }

/* 未登录（本地自选）没有数据源这一列 */
.wt-local { --wt-cols: minmax(240px, 420px) minmax(92px, 1fr) minmax(108px, 1fr) 74px 44px; }
.wt-local .wt-th-src { display: none; }

/* 编辑模式：勾选框 + 基金名 + 拖动把手 */
body.watch-editing .wt-row { --wt-cols: 34px minmax(0, 1fr) 30px; }

/* H5 窄屏：数据源 / 删除只在 PC 显示；首列固定宽度，名字过长省略，
   表格可横向滑动查看后面的列 */
@media (max-width: 899px) {
    .wtbl,
    .wt-local { --wt-cols: 168px 92px 108px 74px; }
    .wt-src, .wt-act,
    .wt-th-src, .wt-th-act { display: none; }
}

.picklist {
    list-style: none;
    margin: 12px 0;
    padding: 0;
    max-height: 46vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.picklist:empty { display: none; }

.pick-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--bg-soft);
    cursor: pointer;
}

.pick-item.on { background: rgba(0, 113, 227, 0.12); }

.pick-box {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    border-radius: 6px;
    border: 1.5px solid var(--text-3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
}

.pick-item.on .pick-box { background: var(--blue); border-color: var(--blue); }

.pick-main { flex: 1 1 auto; min-width: 0; }

.pick-name {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pick-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
