/* ============================================================
 * 全局消息铃铛浮窗
 * 文件：common/css/msg_bell.css
 * 创建：2026-10-30
 *
 * 用途：任意页面挂一个右上角 🔔 按钮 + 点击弹出的消息气泡
 *      气泡内容来自 /common/msg_hub_api.php（私信 / 通知 / 意见 三合一）
 *
 * 设计要点：
 *   - 颜色走全站 theme.css 的 --theme-* 变量，浅色/暗黑自动跟随
 *   - fixed 定位在右上角，避开首页右上角的主题切换器与订阅小按钮（--msg-bell-offset）
 *   - z-index 高于主题切换器/订阅小按钮(9996) 与意见箱 FAB(9990)，低于 layer 弹窗(9999+)
 *   - 移动端收窄为圆形按钮
 * ============================================================ */

.msg-bell-root {
    /* 2026-10-30：颜色变量兼容两套主题
       --theme-*  → common/css/theme.css（首页等用 light/dark/auto 三态的页面）
       --lo-*     → office/css/list_office.css（office / user 中心的 4 主题页面）
       绝大多数页面只加载其中一套，用 var() 的兜底链即可自动取到对应那套；
       两套都没加载时退回硬编码浅色值（不会破版）。 */
    --mb-bg:          var(--theme-bg-elevated, var(--lo-card, #ffffff));
    --mb-bg-soft:     var(--theme-bg-soft, var(--lo-card-hover-bg, #f8fafc));
    --mb-bg-hover:    var(--theme-bg-hover, var(--lo-card-hover-bg, #f1f5f9));
    --mb-text:        var(--theme-text, var(--lo-text, #1e293b));
    --mb-text-soft:   var(--theme-text-soft, var(--lo-text-soft, #475569));
    --mb-text-muted:  var(--theme-text-muted, var(--lo-muted, #94a3b8));
    --mb-border:      var(--theme-border, var(--lo-border, #e2e8f0));
    --mb-border-soft: var(--theme-border-soft, var(--lo-divider, #f1f5f9));
    --mb-primary:     var(--theme-primary, var(--lo-primary, #2563eb));
    --mb-primary-soft:var(--theme-primary-soft, var(--lo-stat-active-bg, rgba(37, 99, 235, 0.10)));
    --mb-shadow-sm:   var(--theme-shadow-sm, var(--lo-shadow, 0 1px 2px rgba(15, 23, 42, 0.06)));
    --mb-shadow-lg:   var(--theme-shadow-lg, 0 4px 6px rgba(15, 23, 42, 0.08), 0 12px 24px rgba(15, 23, 42, 0.10));

    position: fixed;
    top: 16px;
    right: 16px;
    /* 2026-10-30：给首页右上角的主题切换器(9996)/订阅小按钮(9996)留位
       铃铛整体左移一个按钮宽度，避免两者重叠。
       偏移量由 msg_bell.js 运行时实测被避让元素宽度后写入 --msg-bell-offset
       兜底改为 0px：没有右上角元素的页面（如 office / user 中心 / 意见箱）
       铃铛应贴右侧边缘，而不是凭空内缩 96px */
    right: calc(16px + var(--msg-bell-offset, 0px));
    /* 高于主题切换器(9996)/订阅小按钮(9996)，确保铃铛按钮永远可点；
       低于 layer 弹窗(9999+) */
    z-index: 9997;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ========== 铃铛按钮 ========== */
.msg-bell-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--mb-border);
    background: var(--mb-bg);
    color: var(--mb-text);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
    box-shadow: var(--mb-shadow-sm);
    -webkit-tap-highlight-color: transparent;
}
.msg-bell-btn:hover {
    background: var(--mb-bg-hover);
    border-color: var(--mb-primary);
    transform: translateY(-1px);
}
.msg-bell-btn:focus-visible {
    outline: 2px solid var(--mb-primary);
    outline-offset: 2px;
}

/* 未读角标 */
.msg-bell-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--mb-bg);
    display: none;
}
.msg-bell-badge.is-visible { display: block; }

/* ========== 气泡面板 ========== */
.msg-bell-panel {
    position: absolute;
    top: 46px;
    right: 0;
    width: 340px;
    max-width: calc(100vw - 32px);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: var(--mb-bg);
    border: 1px solid var(--mb-border);
    border-radius: 14px;
    box-shadow: var(--mb-shadow-lg);
    overflow: hidden;
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
    transform-origin: top right;
    transition: opacity 0.16s ease, transform 0.16s ease;
    pointer-events: none;
    z-index: 1;
}
.msg-bell-panel.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 面板头部 */
.msg-bell-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--mb-border-soft);
    background: var(--mb-bg-soft);
}
.msg-bell-head-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--mb-text);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.msg-bell-head-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
}
.msg-bell-head-btn {
    padding: 3px 9px;
    border: 1px solid var(--mb-border);
    border-radius: 6px;
    background: var(--mb-bg);
    color: var(--mb-text-soft);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.msg-bell-head-btn:hover {
    border-color: var(--mb-primary);
    color: var(--mb-primary);
}

/* 分类 Tab */
.msg-bell-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 10px 0;
    border-bottom: 1px solid var(--mb-border-soft);
    background: var(--mb-bg-soft);
}
.msg-bell-tab {
    padding: 5px 10px;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 6px 6px 0 0;
    background: none;
    color: var(--mb-text-muted);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.15s, border-color 0.15s;
}
.msg-bell-tab:hover { color: var(--mb-text); }
.msg-bell-tab.is-active {
    color: var(--mb-primary);
    border-bottom-color: var(--mb-primary);
    font-weight: 600;
}
.msg-bell-tab-badge {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 0 5px;
    border-radius: 999px;
    line-height: 15px;
    min-width: 15px;
    text-align: center;
    display: none;
}
.msg-bell-tab-badge.is-visible { display: inline-block; }

/* 列表 */
.msg-bell-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.msg-bell-item {
    display: flex;
    gap: 10px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--mb-border-soft);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.msg-bell-item:hover {
    background: var(--mb-bg-hover);
    text-decoration: none;
    color: inherit;
}
.msg-bell-item.is-unread {
    background: var(--mb-primary-soft);
}
.msg-bell-item.is-unread:hover {
    background: var(--mb-primary-soft);
    filter: brightness(0.97);
}
.msg-bell-item-icon {
    font-size: 16px;
    line-height: 1.4;
    flex-shrink: 0;
}
.msg-bell-item-body {
    flex: 1;
    min-width: 0;
}
.msg-bell-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--mb-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.msg-bell-item.is-unread .msg-bell-item-title { font-weight: 600; }
.msg-bell-item-preview {
    font-size: 12px;
    color: var(--mb-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}
.msg-bell-item-meta {
    font-size: 11px;
    color: var(--mb-text-muted);
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.msg-bell-item-count {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 0 5px;
    border-radius: 999px;
    line-height: 15px;
}

/* 空状态 */
.msg-bell-empty {
    padding: 36px 20px;
    text-align: center;
    color: var(--mb-text-muted);
    font-size: 13px;
}
.msg-bell-empty-icon {
    font-size: 36px;
    margin-bottom: 8px;
    opacity: 0.7;
}

/* 面板底部 */
.msg-bell-foot {
    padding: 9px 14px;
    border-top: 1px solid var(--mb-border-soft);
    background: var(--mb-bg-soft);
    display: flex;
    gap: 8px;
    justify-content: center;
}
.msg-bell-foot a {
    font-size: 12px;
    color: var(--mb-primary);
    text-decoration: none;
}
.msg-bell-foot a:hover { text-decoration: underline; }

/* ========== 移动端 ========== */
@media (max-width: 640px) {
    .msg-bell-root {
        top: 10px;
        right: 10px;
        right: calc(10px + var(--msg-bell-offset-mobile, 0px));
    }
    .msg-bell-btn {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }
    .msg-bell-panel {
        width: calc(100vw - 20px);
        right: -4px;
        max-height: 64vh;
    }
}
