/* =====================================================================
   魔方办公 · 右键菜单 + 网址组件库 + 自定义网址
   仅作用于 lib-* / ctx-* / cu-* / wg-* 前缀，不影响既有磁贴样式
   ===================================================================== */

/* ---------------- 右键菜单（深色面板） ---------------- */
.ctx-menu {
    position: fixed;
    z-index: 9999;
    min-width: 208px;
    padding: 8px;
    border-radius: 14px;
    background: #1e2733;
    border: 1px solid rgba(255, 255, 255, .07);
    box-shadow: 0 20px 48px rgba(0, 0, 0, .42), 0 2px 8px rgba(0, 0, 0, .28);
    animation: ctxIn .12s ease-out;
}

@keyframes ctxIn {
    from { opacity: 0; transform: translateY(-4px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 14px;
    border-radius: 9px;
    color: #f3f6f9;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    transition: background .15s;
}

.ctx-item:hover,
.ctx-item:focus-visible {
    background: rgba(255, 255, 255, .09);
    outline: none;
}

.ctx-item svg {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    fill: none;
    stroke: #cdd8e4;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------------- 组件库弹窗 ---------------- */
.lib-mask {
    position: fixed;
    inset: 0;
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background: rgba(12, 20, 32, .45);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    animation: libFade .16s ease-out;
    /* 弹层内的滚轮不再把底层首页一起滚走 */
    overscroll-behavior: contain;
}

@keyframes libFade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.lib-panel {
    position: relative;
    display: flex;
    width: min(1180px, 94vw);
    height: min(748px, 88vh);
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 32px 80px rgba(0, 0, 0, .38);
    animation: libPanel .18s cubic-bezier(.2, .7, .3, 1);
}

@keyframes libPanel {
    from { opacity: 0; transform: translateY(10px) scale(.99); }
    to   { opacity: 1; transform: none; }
}

.lib-side {
    flex: 0 0 198px;
    width: 198px;
    padding: 22px 14px;
    border-right: 1px solid #eef1f5;
    background: #fdfdff;
}

.lib-brand {
    margin: 0 0 18px 6px;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: .5px;
    background: linear-gradient(92deg, #1f7bf5 0%, #2ea8ff 40%, #9b6bff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.lib-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lib-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    border-radius: 10px;
    font-size: 14px;
    color: #4b5462;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, color .15s;
}

.lib-nav-item:hover { background: #f4f6fa; }

.lib-nav-item.on {
    background: #f2f5fb;
    border-color: #e6ecf6;
    color: #1f7bf5;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(20, 40, 80, .04);
}

.lib-nav-item svg {
    width: 19px;
    height: 19px;
    flex: 0 0 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lib-main {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 22px 28px 10px;
    background: #fbfcfe;
}

.lib-close {
    position: absolute;
    top: 14px;
    right: 18px;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #a9b2c0;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.lib-close:hover { background: #eef1f6; color: #5b6472; }

.lib-search {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 16px;
    margin-right: 40px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid #e6eaf1;
}

.lib-search svg {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    fill: none;
    stroke: #a9b2c0;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.lib-search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    background: transparent;
    font-size: 14px;
    color: #2b3240;
    outline: none;
}

.lib-search input::placeholder { color: #b3bcc9; }

.lib-tabs {
    display: flex;
    align-items: center;
    gap: 26px;
    padding: 16px 2px 2px;
    margin-bottom: 14px;
    overflow-x: auto;
    scrollbar-width: none;
}

.lib-tabs::-webkit-scrollbar { display: none; }

.lib-tab {
    position: relative;
    flex: 0 0 auto;
    padding: 4px 0 10px;
    font-size: 15px;
    color: #3f4756;
    cursor: pointer;
    white-space: nowrap;
    transition: color .15s;
}

.lib-tab:hover { color: #1f7bf5; }

.lib-tab.on {
    color: #1f7bf5;
    font-weight: 700;
}

.lib-tab.on::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 22px;
    height: 3px;
    border-radius: 2px;
    background: #1f7bf5;
    transform: translateX(-50%);
}

.lib-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 2px 4px 16px 2px;
    overscroll-behavior: contain;
}

.lib-body::-webkit-scrollbar { width: 8px; }
.lib-body::-webkit-scrollbar-thumb { background: #dfe4ec; border-radius: 4px; }
.lib-body::-webkit-scrollbar-track { background: transparent; }

.lib-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

/* 小组件卡：紧凑 4 列，一屏能看到更多 */
.lib-grid.two { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.lib-card {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 12px 12px 10px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid #eceff4;
    transition: box-shadow .18s, transform .18s, border-color .18s;
}

.lib-card:hover {
    border-color: #dfe6f2;
    box-shadow: 0 8px 22px rgba(30, 60, 110, .08);
    transform: translateY(-1px);
}

.lib-card-top {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.lib-ico {
    position: relative;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 17px;
    font-weight: 800;
    color: #fff;
    background: #4a7cf7;
}

.lib-ico img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.lib-ico .ico-ph {
    display: block;
    line-height: 1;
}

.lib-info { flex: 1; min-width: 0; }

.lib-name {
    font-size: 13.5px;
    font-weight: 700;
    color: #20242b;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lib-desc {
    margin-top: 3px;
    font-size: 11px;
    line-height: 1.45;
    color: #98a0ad;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 32px;
}

.lib-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-top: auto;
    padding-top: 2px;
}

.lib-tag {
    padding: 2px 7px;
    border-radius: 5px;
    background: #f3f5f9;
    color: #98a0ad;
    font-size: 11px;
    line-height: 1.5;
    white-space: nowrap;
}

.lib-add {
    height: 24px;
    padding: 0 11px;
    border-radius: 12px;
    border: 1px solid #ccd7e5;
    background: #fff;
    color: #1f7bf5;
    font-size: 12px;
    cursor: pointer;
    transition: all .15s;
}

.lib-add:hover { border-color: #1f7bf5; background: #f4f8ff; }

.lib-add.done,
.lib-add.done:hover {
    border-color: transparent;
    background: #f2f4f8;
    color: #9aa4b2;
    cursor: pointer;
}

/* 已添加的按钮，鼠标移上去变「移除」，用暖色提示这是可以点掉的 */
.lib-add.done.will-remove {
    background: #fff1f0;
    color: #e2504a;
}

.lib-empty {
    padding: 70px 0;
    text-align: center;
    color: #a9b2c0;
    font-size: 14px;
}

/* ---------------- 小组件卡片（紧凑列 + 小预览区） ---------------- */
.wg-card { gap: 7px; }

.wg-prev {
    height: 84px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f5f7fb;
    position: relative;
}

.wg-prev-inner {
    width: 86%;
    min-height: 56px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #fff;
    font-weight: 700;
    text-align: center;
    padding: 7px;
    box-shadow: 0 6px 14px rgba(40, 70, 130, .14);
}

.wg-prev-inner .wg-big { font-size: 15px; letter-spacing: .5px; line-height: 1.2; }
.wg-prev-inner .wg-small { font-size: 9.5px; font-weight: 500; opacity: .92; }

/* ---------------- 已添加 / 未添加 筛选 ---------------- */
.lib-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 2px 12px;
}

.lib-fchip {
    padding: 4px 12px;
    border-radius: 14px;
    background: #f3f5f9;
    color: #5b6472;
    font-size: 12.5px;
    line-height: 1.6;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s;
}

.lib-fchip:hover { background: #eef2f8; color: #1f7bf5; }

.lib-fchip.on {
    background: #e8f1ff;
    color: #1f7bf5;
    font-weight: 700;
}

/* ---------------- 自定义网址表单 ---------------- */
.cu-form {
    max-width: 748px;
    padding: 4px 2px 20px;
}

.cu-row { margin-bottom: 20px; }

.cu-label {
    display: block;
    margin-bottom: 9px;
    font-size: 14px;
    color: #39404e;
}

.cu-input {
    width: 100%;
    height: 46px;
    padding: 0 14px;
    border-radius: 9px;
    border: 1px solid #e4e9f0;
    background: #fff;
    font-size: 14px;
    color: #2b3240;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    box-sizing: border-box;
}

.cu-input:focus {
    border-color: #9dc2f8;
    box-shadow: 0 0 0 3px rgba(31, 123, 245, .1);
}

.cu-input::placeholder { color: #b3bcc9; }

.cu-styles {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.cu-style {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: #f3f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #8e97a5;
    font-size: 26px;
    font-weight: 700;
    user-select: none;
    transition: border-color .15s, box-shadow .15s;
}

.cu-style.on {
    border-color: #1f7bf5;
    box-shadow: 0 0 0 3px rgba(31, 123, 245, .12);
    color: #1f7bf5;
}

.cu-check {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    background: #1f7bf5;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    border: 2px solid #fff;
}

.cu-style-cap {
    margin-top: 8px;
    font-size: 13px;
    color: #6c7482;
}

.cu-colors {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 2px;
}

.cu-color {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    cursor: pointer;
    border: 0;
    padding: 0;
    transition: transform .12s;
}

.cu-color:hover { transform: translateY(-1px); }

.cu-color.on::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 10px;
    border: 2px solid #1f7bf5;
}

.cu-color.rainbow {
    background: conic-gradient(#ff9a3d, #ff5d8f, #a55bff, #3d8bff, #33c8f7, #47d16c, #ffc93c, #ff9a3d);
}

.cu-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
    padding: 12px 14px;
    border-radius: 10px;
    background: #f6f8fc;
    color: #7b8492;
    font-size: 13px;
}

.cu-preview .pv-ico {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 19px;
    font-weight: 800;
}

.cu-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 4px;
}

.cu-submit {
    height: 40px;
    padding: 0 34px;
    border: 0;
    border-radius: 20px;
    background: #1f7bf5;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    transition: background .15s, transform .12s;
}

.cu-submit:hover { background: #1568dd; }
.cu-submit:active { transform: scale(.98); }

/* ---------------- 用户自建组件磁贴的删除按钮 ---------------- */
/* 放在卡片内侧右上角：以前是 -8px 出界，鼠标移到按钮上就离开了卡片，
   hover 断掉按钮随即消失，实际点不到。内嵌后任何位置、任何页签都能点到。
   默认半透明淡显（一眼能看到有删除入口），hover 卡片时完全显示。 */
.mine-del {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(20, 26, 36, .72);
    color: #fff;
    font-size: 11px;
    line-height: 22px;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    overflow: hidden;
    z-index: 9;
    transition: opacity .15s, background .15s;
}

.tile:hover .mine-del,
.mine-del:focus-visible { opacity: 1; }

.mine-del:hover { background: #e5405e; opacity: 1; }

/* 触屏没有 hover：淡显，保证删除入口找得到；桌面端（含窄窗口）一律悬停才显示 */
@media (hover: none) {
    .mine-del { opacity: .6; }
}

/* 有删除按钮的工具卡：右上角「工具」角标让位给 × */
.mine-deletable:hover .tool-tag { opacity: 0; }
.mine-deletable .tool-tag { margin-right: 20px; }
.t-tool .tool-tag { transition: opacity .15s ease; }

/* ---------------- 窄屏适配 ---------------- */
@media (max-width: 1080px) {
    .lib-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .lib-grid.two { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .lib-side { flex-basis: 168px; width: 168px; }
}

@media (max-width: 720px) {
    .lib-mask { padding: 0; }
    .lib-panel { width: 100vw; height: 100vh; border-radius: 0; }
    .lib-side { flex-basis: 118px; width: 118px; padding: 16px 8px; }
    .lib-brand { font-size: 15px; margin-left: 2px; }
    .lib-nav-item { padding: 10px; font-size: 13px; gap: 8px; }
    .lib-nav-item svg { width: 16px; height: 16px; flex-basis: 16px; }
    .lib-main { padding: 16px 14px 8px; }
    .lib-search { margin-right: 34px; height: 40px; }
    .lib-grid,
    .lib-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .wg-prev { height: 72px; }
    .wg-big { font-size: 13px; }
    .cu-colors { gap: 9px; }
    .cu-color { width: 28px; height: 28px; }
    .mine-del { opacity: 0; }
}

@media (max-width: 430px) {
    .lib-grid,
    .lib-grid.two { grid-template-columns: 1fr; }
}
