/* ============================================================
   widgets.css —— 首页「组件看板」
   位于搜索框下方、网站快捷方式上方的响应式网格，深色玻璃拟态卡片
   （与快捷方式区一致，适配壁纸/深色背景）；空看板整体隐藏。
   本文件只提供卡片外壳样式，各组件内部样式由组件自带 CSS 负责
   （例如下班倒计时见 css/xbd.css，.xbd- 前缀）。
   ============================================================ */

/* ===== 首页主网格：组件卡片与网址图标共用同一套网格 =====
   主网格共 --icon-cols（默认 14）列，每个图标占 1 列 × 1 行（76px，图标 52 +
   间距 8 + 名称行 16）。组件看板 display:contents 不生成盒子，卡片升格为
   主网格项：大卡占 4×2、中卡 2×2、条卡 2×1 格（grid-column/grid-row 由
   widgets.js 按网格吸附写入）。
   grid-auto-flow: row dense 让 1×1 的网址图标自动回填卡片周围/后面的空位
   （图标补位），卡片拖到哪、图标就绕排补到哪（参考 nbtab.com / go.itab.link）。 */
.main-grid {
    width: var(--track-w);
    /* 底部为第二排图标名称预留空间（图标→名称间距 + 名称行高） */
    padding-bottom: calc(var(--icon-gap) + var(--icon-name-h));
    /* 与搜索框之间保持较大的呼吸间距 */
    margin-top: 40px;
    display: grid;
    /* 必须用 minmax(0,1fr)：裸 1fr 等价 minmax(auto,1fr)，大卡（日历/倒计时完整版）
       内部内容的最小宽度会把所占列撑大、导致整网溢出 --track-w、图标间距失真。
       归零后列严格等分，卡片 stretch 才严格等于整数个图标格，超出内容由卡片内滚动。 */
    grid-template-columns: repeat(var(--icon-cols), minmax(0, 1fr));
    grid-auto-flow: row dense;  /* 图标自动回填卡片周围的空位 */
    grid-auto-rows: var(--icon-row-h);  /* = 图标 + 间距 + 名称行，与图标行严格对齐 */
    column-gap: var(--icon-colgap);     /* 与网址图标列间距一致 */
    row-gap: var(--icon-rowgap);        /* 与网址图标行间距一致 */
    justify-items: center;
    align-items: start;
    position: relative; /* 作为快捷方式空状态提示、拖拽引导线的定位参考 */
}
/* 组件看板容器不生成盒子：卡片直接作为 .main-grid 的网格项落位
   （落位列/行由 widgets.js 装箱计算，写内联 grid-column/grid-row） */
.main-grid > .widgets-board {
    display: contents;
}
/* 网址快捷方式容器展开，让图标项直接作为 .main-grid 的网格项 */
.main-grid > .shortcuts,
.main-grid > .shortcuts > .shortcut-grid {
    display: contents;
}

/* 没有任何组件时隐藏看板容器；快捷方式项仍作为 .main-grid 网格项正常显示 */
.widgets-board.empty {
    display: none;
}

/* 看板有组件时内容可能较高：给主网格底部预留空间，
   避免最后一行图标被固定在视口底部的「每日一言」遮挡 */
.main-grid.has-widgets {
    margin-bottom: 72px;
}

/* ===== 组件卡片 ===== */
.widget-card {
    background: rgba(20, 20, 25, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
    padding: 14px 16px 16px;
    color: #fff;
    overflow: hidden;
    position: relative;
    /* 卡片高度固定 180，宽度撑满等宽网格列（与小图标排列一致）；超出内容在卡片内滚动 */
    width: 100%;
    height: 180px;
    display: flex;
    flex-direction: column;
    transition: transform 0.22s var(--ease-out), box-shadow 0.22s ease, border-color 0.22s ease;
    animation: widget-in 0.5s var(--ease-out) both;
}
.widget-card .widget-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}
.widget-card .widget-body::-webkit-scrollbar { width: 5px; }
.widget-card .widget-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
}
.widget-card .widget-body::-webkit-scrollbar-track { background: transparent; }
.widget-card:nth-child(2) { animation-delay: 0.06s; }
.widget-card:nth-child(3) { animation-delay: 0.12s; }
.widget-card:nth-child(4) { animation-delay: 0.18s; }
.widget-card:nth-child(5) { animation-delay: 0.24s; }
.widget-card:nth-child(6) { animation-delay: 0.3s; }
@keyframes widget-in {
    from { opacity: 0; transform: translateY(14px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}
.widget-card:hover {
    transform: translateY(-3px);
    border-color: rgba(255, 255, 255, 0.24);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.36);
}

/* 自由拖拽：标题栏作为拖拽手柄；拖动中的卡片浮起、置顶；
   transition 必须关掉，否则 transform 跟手会有 0.22s 拖影延迟 */
.widget-card.dragging {
    opacity: 0.92;
    z-index: 100;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
    cursor: grabbing;
    transition: none;
    will-change: transform;
}

/* 拖拽占位框：被拖卡片脱离网格后占据其目标位的虚线框（尺寸由 JS 按卡片 px 写入） */
.widget-drag-ghost {
    justify-self: center;
    align-self: start;
    border: 2px dashed rgba(255, 140, 26, 0.55);
    border-radius: 18px;
    background: rgba(255, 140, 26, 0.08);
    box-sizing: border-box;
    pointer-events: none;
    z-index: 0;
}
.widget-head {
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    /* 触摸设备从标题栏拖动时不触发页面滚动 */
    touch-action: none;
}
.widget-head:active { cursor: grabbing; }
/* 移除按钮保持普通指针，不表现为可拖 */
.widget-remove { cursor: pointer; }

/* 卡片头部：标题 + 移除按钮 */
.widget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.widget-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
}
.widget-ico { font-size: 16px; line-height: 1; }
/* 头部右侧按钮组（齿轮 + 移除），悬停卡片时才显现 */
.widget-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.widget-settings,
.widget-remove {
    width: 22px;
    height: 22px;
    line-height: 20px;
    text-align: center;
    border-radius: 50%;
    font-size: 13px;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.15s ease, transform 0.15s var(--ease-out), background 0.15s ease;
}
.widget-card:hover .widget-settings,
.widget-card:hover .widget-remove { opacity: 1; transform: scale(1); }
.widget-settings:hover { background: rgba(255, 255, 255, 0.3); transform: scale(1.12); }
.widget-remove { font-size: 14px; }
.widget-remove:hover { background: rgba(255, 95, 109, 0.9); transform: scale(1.12); }

.widget-body { font-size: 13px; }
.widget-error {
    color: rgba(255, 200, 200, 0.9);
    font-size: 13px;
    padding: 8px 0;
}

/* 窄屏适配（≤620px）：组件卡片整行独占、自上而下堆叠（widgets.js 已清空内联
   网格落位），图标照常排在卡片下方；自动行改为按内容撑高，固定高度的卡片
   不再被 80px 行裁切。大卡随列全宽，中卡/条卡保持组件自身固定宽并居中。 */
@media (max-width: 620px) {
    .main-grid { grid-auto-rows: auto; }
    .main-grid > .widgets-board > .widget-card {
        grid-column: 1 / -1;
        grid-row: auto;
        justify-self: center;
        width: 100%;
    }
}
