/* ==========================================================================
   移动端 Mini Bar — 专为手机/平板替代桌面 aside 侧栏的交互
   只在 ≤1024px 显示，桌面完全看不到也不会生效
   功能：
     - 最左：当前用户头像 + 名字（点击进个人中心）
     - 中间：项目下拉 + 集数下拉（替代侧栏的树形选择）
     - 右侧：人员状态按钮（点开迷你弹窗）
   ========================================================================== */

#mobile-mini-bar {
    display: none;  /* 桌面默认不显示 */
}

@media (max-width: 1024px) {
    /* 外容器：两行布局（用户+导航一行，项目进度总览一行） */
    #mobile-mini-bar {
        display: grid;
        grid-template-columns: auto 1fr;          /* 左：用户条；右：导航一行 */
        grid-template-rows: auto auto;            /* 两行 */
        grid-template-areas:
            "user nav"
            "dash dash";
        align-items: stretch;
        gap: 6px 8px;
        padding: 8px 10px;
        background: #0a0a0a;
        border-bottom: 1px solid #1f1f1f;
        position: sticky;
        top: 0;
        z-index: 80;
        overflow: visible;
    }

    /* 用户信息（最左，跨两行保持外观） */
    .mmb-user {
        grid-area: user;
        display: flex; align-items: center; gap: 6px;
        flex-shrink: 0;
        padding: 2px 8px;
        background: #141414;
        border: 1px solid #222;
        border-radius: 20px;
        text-decoration: none;
        color: #ccc;
        cursor: pointer;
        min-height: 34px;
        box-sizing: border-box;
    }
    .mmb-user:hover { border-color: #d4af37; }
    .mmb-avatar {
        width: 26px; height: 26px; border-radius: 50%;
        background: #1a1a1a;
        display: flex; align-items: center; justify-content: center;
        overflow: hidden;
        flex-shrink: 0;
    }
    .mmb-avatar img { width: 100%; height: 100%; object-fit: cover; }
    .mmb-avatar .mmb-avatar-fallback { font-size: 14px; }
    .mmb-username {
        font-size: 12px; color: #e0e0e0; font-weight: 500;
        max-width: 80px;
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .mmb-user-level {
        font-size: 9px;
        background: linear-gradient(135deg, #d4af37, #b8932f);
        color: #000; padding: 1px 5px; border-radius: 8px;
        font-weight: bold;
    }

    /* 第一行右侧：作品 / 集数 / 人员状态 / 筛选 —— 左右拉伸、等分、统一高度 */
    .mmb-row-nav {
        grid-area: nav;
        display: flex;
        align-items: stretch;
        gap: 6px;
        min-width: 0;  /* 防 flex 子项把容器撑爆 */
    }
    /* 统一所有子元素的高度与占比 */
    .mmb-row-nav > .mmb-select,
    .mmb-row-nav > .mmb-staff-btn {
        flex: 1 1 0;
        min-width: 0;
        height: 34px;
        box-sizing: border-box;
    }

    /* 下拉菜单 */
    .mmb-select {
        background: #141414;
        border: 1px solid #2a2a2a;
        color: #e0e0e0;
        padding: 0 22px 0 8px;
        border-radius: 6px;
        font-size: 12px;
        line-height: 32px;
        appearance: none;
        -webkit-appearance: none;
        background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='%23888' d='M0 2l5 6 5-6z'/></svg>");
        background-repeat: no-repeat;
        background-position: right 6px center;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
    }
    .mmb-select:focus { border-color: #d4af37; outline: none; }
    .mmb-select option { background: #1a1a1a; color: #fff; }
    .mmb-select:disabled { opacity: 0.4; cursor: not-allowed; }

    /* 人员状态 / 筛选 按钮 */
    .mmb-staff-btn {
        background: #141414;
        border: 1px solid #2a2a2a;
        color: #d4af37;
        padding: 0 8px;
        border-radius: 6px;
        font-size: 12px;
        cursor: pointer;
        display: flex; align-items: center; justify-content: center; gap: 4px;
        position: relative;
    }
    .mmb-staff-btn:hover { border-color: #d4af37; }
    .mmb-staff-btn i { font-size: 14px; }
    .mmb-staff-badge {
        background: #4ade80;
        color: #000;
        font-size: 9px;
        padding: 0 5px;
        border-radius: 8px;
        font-weight: bold;
        min-width: 14px;
        text-align: center;
        position: absolute;
        top: -4px; right: -4px;
    }

    /* 第二行：项目进度总览按钮（整条） */
    .mmb-row-dash { grid-area: dash; display: flex; }
    .mmb-dash-btn {
        flex: 1 1 auto;
        height: 34px;
        background: linear-gradient(135deg, #1a1a1a, #141414);
        border: 1px solid #2a2a2a;
        color: #e0e0e0;
        border-radius: 6px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        display: flex; align-items: center; justify-content: center; gap: 6px;
        letter-spacing: 0.5px;
    }
    .mmb-dash-btn i { font-size: 14px; color: #E60012; }
    .mmb-dash-btn:hover, .mmb-dash-btn:active {
        border-color: #E60012;
        background: linear-gradient(135deg, #1e1417, #141414);
    }
}

/* 手机窄屏再紧凑 */
@media (max-width: 640px) {
    #mobile-mini-bar {
        gap: 5px 6px;
        padding: 6px 8px;
    }
    .mmb-username { max-width: 60px; font-size: 11px; }
    .mmb-user-level { display: none; }  /* 太挤 */
    .mmb-row-nav { gap: 4px; }
    .mmb-row-nav > .mmb-select,
    .mmb-row-nav > .mmb-staff-btn { height: 32px; }
    .mmb-select { padding: 0 20px 0 6px; font-size: 11px; line-height: 30px; }
    .mmb-staff-btn { font-size: 11px; padding: 0 6px; }
    .mmb-dash-btn { height: 32px; font-size: 11px; }

    /* 原桌面 nav 里的项目信息文字（t-proj/t-ep）跟 mini bar 重复，隐掉 */
    .proj-info { display: none !important; }
    /* 原顶部大操作按钮行太挤，折叠成一排可横向滚动 */
    .nav-actions {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start !important;
    }
    .nav-actions > * { flex-shrink: 0; }
    /* 人员状态大条隐（迷你按钮已经能弹窗查看） */
    #staff-online-row { display: none !important; }
    /* aside 完全隐藏（mini bar 替代） */
    aside { display: none !important; }
    .app-content-wrap > main { width: 100% !important; }
}

/* ========== 人员状态迷你弹窗（所有 ≤1024 都用这个） ========== */
.mmb-staff-popup {
    position: fixed;
    top: 96px; right: 8px;
    width: 280px; max-width: 92vw;
    max-height: 70vh;
    background: #141414;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 8500;
    overflow: hidden;
    display: none;
    flex-direction: column;
    animation: mmbStaffIn 0.12s ease;
}
.mmb-staff-popup.open { display: flex; }
@keyframes mmbStaffIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.mmb-staff-popup-header {
    padding: 10px 12px;
    border-bottom: 1px solid #222;
    display: flex; justify-content: space-between; align-items: center;
    font-size: 12px; color: #aaa;
}
.mmb-staff-popup-header button {
    background: none; border: none; color: #888;
    cursor: pointer; font-size: 14px;
}
.mmb-staff-popup-body {
    flex: 1; overflow-y: auto; padding: 8px;
    display: flex; flex-direction: column; gap: 4px;
}
.mmb-staff-popup-body .staff-pill {
    width: 100%;
    justify-content: flex-start;
    padding: 6px 10px !important;
    border-radius: 6px !important;
}
.mmb-staff-mask {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 8400;
    display: none;
}
.mmb-staff-mask.open { display: block; }

/* ========== 项目进度总览弹窗：手机端全屏覆盖 + 内部独立滚动 ========== */
/* 关键原则：
   - display 由 JS 的 style.display 控制（toggleDashboard() 里切换 '' / 'none'）
   - 这里用 body.is-mobile.dash-open 作为门禁，只有弹窗打开时才应用全屏布局
   - 绝不能写 display:flex !important，否则会覆盖 JS 的 display:none */
body.is-mobile.dash-open #dashboard-panel.dashboard-overlay {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border: none !important;
    border-radius: 0 !important;
    z-index: 9000 !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: none !important;
    background: #0a0a0a !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-overlay-header {
    position: sticky; top: 0; z-index: 2;
    background: #0d0d0d;
    padding: 10px 12px;
    border-bottom: 1px solid #222;
    flex-shrink: 0;
    font-size: 13px;
}
body.is-mobile.dash-open #dashboard-panel .dp-title { font-size: 14px; }
body.is-mobile.dash-open #dashboard-panel #dash-context-label {
    font-size: 11px !important;
    margin-left: 8px !important;
}
body.is-mobile.dash-open #dashboard-panel .dp-close {
    background: #1a1a1a; border: 1px solid #333; color: #ccc;
    width: 38px; height: 38px; border-radius: 50%;
    font-size: 22px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    margin-left: auto;
    padding: 0; line-height: 1;
    flex-shrink: 0;
}
body.is-mobile.dash-open #dashboard-panel .dp-close:active { background: #2a2a2a; }

/* 弹窗内部独立滚动，overscroll-behavior 阻止冒泡到后面的卡片区 */
body.is-mobile.dash-open #dashboard-panel .dash-overlay-body {
    flex: 1 1 auto;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 12px 12px 24px !important;
    gap: 10px !important;
}

/* 精简布局：单列 + 紧凑 section */
body.is-mobile.dash-open #dashboard-panel .dash-two-col {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-section {
    margin-bottom: 0 !important;
    padding: 10px !important;
    background: #0d0d0d;
    border: 1px solid #1f1f1f;
    border-radius: 8px;
}
body.is-mobile.dash-open #dashboard-panel .dash-section-title {
    font-size: 12px !important;
    margin-bottom: 6px !important;
}

/* 顶部概况 4 格紧凑 */
body.is-mobile.dash-open #dashboard-panel .dash-grid[style*="repeat(4"] {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-card {
    padding: 6px 2px !important;
    background: #161616 !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-card-value {
    font-size: 16px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-card-label {
    font-size: 9px !important;
    margin-top: 1px !important;
}

/* 每集进度条：精简 */
body.is-mobile.dash-open #dashboard-panel .dash-progress-row {
    padding: 4px 4px !important;
    margin-bottom: 2px !important;
    gap: 6px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-ep-label {
    width: 50px !important;
    font-size: 11px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-ep-stat {
    width: 34px !important;
    font-size: 10px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-prog-bar { height: 10px !important; }
body.is-mobile.dash-open #dashboard-panel .dash-stacked-bar { height: 8px !important; }
body.is-mobile.dash-open #dashboard-panel .dash-prog-fill { font-size: 8px !important; }

/* 人员占比：只显示前 5 名，减少滚动 */
body.is-mobile.dash-open #dashboard-panel .dash-artist-row {
    padding: 3px 0 !important;
    font-size: 11px !important;
    gap: 6px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-artist-row:nth-child(n+7) {
    display: none;
}
body.is-mobile.dash-open #dashboard-panel .dash-artist-name {
    width: 60px !important;
    font-size: 10px !important;
}
body.is-mobile.dash-open #dashboard-panel .dash-artist-stat {
    width: 40px !important;
    font-size: 10px !important;
}

/* 图例小字 */
body.is-mobile.dash-open #dashboard-panel .dash-section [style*="font-size:11px"] {
    font-size: 10px !important;
}

/* 弹窗打开时锁定后面卡片区的滚动（防止穿透） */
body.is-mobile.dash-open,
body.is-mobile.dash-open .app-content-wrap,
body.is-mobile.dash-open main#main-content {
    overflow: hidden !important;
}
