/**
 * ============================================================
 *  mobile.css — 移动端体验专项优化
 *  [v1.8.0] 阶段八：手机浏览器 + 小程序webview适配
 *
 *  核心优化：
 *  - 表格横向滚动 + 首列固定
 *  - 表单/弹窗自适应屏幕
 *  - 侧边栏移动端收起
 *  - 按钮/操作项触控区域增大
 *  - 桌面端样式完全不变，仅移动端触发
 * ============================================================
 */

/* ========== PC端隐藏移动端专属元素 ========== */
@media (min-width: 769px) {
    .mobile-user-dropdown-overlay {
        display: none !important;
    }
}

/* ========== 平板及以下 (≤768px) ========== */
@media (max-width: 768px) {

    /* 布局：侧边栏隐藏 */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1050;
        transition: left 0.3s ease;
        box-shadow: none;
    }
    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
    }
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* 移动端顶部栏 */
    .mobile-top-bar {
        display: flex !important;
    }

    /* 移动端右上角更多按钮 */
    .mobile-more-toggle {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        background: none;
        border: none;
        color: #FFF;
        font-size: 24px;
        font-weight: bold;
        letter-spacing: 1px;
        margin-left: auto;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
        border-radius: 50%;
        transition: background 0.2s;
    }
    .mobile-more-toggle:hover,
    .mobile-more-toggle:active {
        background: rgba(255,255,255,0.1);
    }

    /* 移动端顶部栏logo居中 */
    .mobile-top-bar .mobile-logo {
        flex: 1;
        text-align: center;
        pointer-events: none;
    }

    /* 隐藏PC端用户操作区 */
    .top-bar .user-area {
        display: none !important;
    }

    /* 移动端用户操作下拉面板 */
    .mobile-user-dropdown {
        display: none;
        position: absolute;
        top: 56px;
        right: 8px;
        min-width: 160px;
        background: #1E1E1E;
        border: 1px solid #2A2A2A;
        border-radius: 8px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.6);
        z-index: 1200;
        overflow: hidden;
        animation: mud-fade-in 0.18s ease-out;
    }
    .mobile-user-dropdown.open {
        display: block;
    }
    .mobile-user-dropdown .mud-username {
        padding: 12px 16px 10px;
        font-size: 14px;
        font-weight: 600;
        color: #FFFFFF;
        border-bottom: 1px solid #2A2A2A;
        letter-spacing: 0.5px;
    }
    .mobile-user-dropdown .mud-item {
        padding: 14px 16px;
        font-size: 15px;
        color: #E0E6ED;
        cursor: pointer;
        transition: background 0.15s;
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-user-dropdown .mud-item:hover,
    .mobile-user-dropdown .mud-item:active {
        background: #2A2A2A;
        color: #FFFFFF;
    }
    .mobile-user-dropdown .mud-item:active {
        background: #333;
    }

    /* 下拉面板遮罩 */
    .mobile-user-dropdown-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1099;
        background: transparent;
    }
    .mobile-user-dropdown-overlay.open {
        display: block;
    }

    @keyframes mud-fade-in {
        from { opacity: 0; transform: translateY(-8px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    /* 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1000;
    }
    .sidebar-overlay.active {
        display: block;
    }

    /* ===== 生产监控大屏三列→单列堆叠 ===== */
    .bs-body {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
        padding: 8px !important;
        gap: 8px !important;
    }
    .bs-col-left,
    .bs-col-center,
    .bs-col-right,
    .bs-col-bottom {
        grid-column: unset !important;
        grid-row: unset !important;
        width: 100% !important;
        min-height: 0 !important;
    }
    .bs-module {
        min-height: auto !important;
    }
    .bs-module-body {
        max-height: none !important;
        overflow: visible !important;
    }
    .bs-header {
        padding: 10px 12px 8px !important;
    }
    .bs-title {
        font-size: 14px !important;
        letter-spacing: 1px !important;
    }
    .bs-header-right {
        position: static !important;
        transform: none !important;
        margin-top: 6px;
        justify-content: flex-end;
    }
    .bs-output-value {
        font-size: 28px !important;
    }
    .bs-mini-cards {
        flex-wrap: wrap !important;
    }
    .bs-mini-card {
        min-width: calc(50% - 8px) !important;
    }
    /* 核心数字防断裂 */
    .bs-mc-value,
    .bs-output-value span,
    .pd-stat-value,
    .pd-metric-val {
        white-space: nowrap;
        word-break: keep-all;
    }
    /* 大屏表格横向滚动 */
    .bs-stream-scroll {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .bs-table {
        min-width: 560px !important;
    }
    .bs-table th:first-child,
    .bs-table td:first-child {
        position: sticky;
        left: 0;
        z-index: 5;
        background: inherit;
    }

    /* 生产进度看板响应式 */
    .pd-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        padding: 8px !important;
    }
    .pd-stat-value {
        font-size: 24px !important;
    }
    .pd-toolbar {
        flex-direction: column;
        gap: 8px;
        padding: 8px 12px;
    }
    .pd-tabs {
        flex-wrap: wrap;
        gap: 4px;
    }
    .pd-section {
        padding: 0 8px 8px !important;
    }
    .pd-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .pd-line-grid {
        grid-template-columns: 1fr !important;
    }

    /* 表格：横向滚动 */
    .table-scroll-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-section table {
        min-width: 600px;
    }

    /* 首列冻结优化 */
    .table-section .frozen-left {
        position: sticky;
        left: 0;
        z-index: 20;
        background: inherit;
    }
    .table-section thead .frozen-left {
        z-index: 110;
    }
    /* 通用表格滚动容器 */
    .table-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 工具栏换行 */
    .page-toolbar {
        flex-direction: column;
        gap: 8px;
    }
    .toolbar-left, .toolbar-filter {
        flex-wrap: wrap;
        gap: 6px;
    }
    .toolbar-filter input,
    .toolbar-filter select {
        min-width: 100px;
        flex: 1;
    }

    /* 二维码管理工具栏平板适配 */
    .qr-toolbar-wrap {
        flex-wrap: wrap !important;
    }
    .qr-toolbar-wrap select {
        max-width: none !important;
        min-width: 120px !important;
        flex: 1 1 120px;
    }
    .qr-toolbar-wrap input[type="text"] {
        min-width: 100px;
        flex: 1 1 100px;
    }
    .qr-toolbar-wrap button {
        min-height: 36px;
    }

    /* 按钮触控区域增大（44px最小触控高度） */
    .page-toolbar button,
    .toolbar-filter button,
    .toolbar-left button,
    .btn-default, .btn-primary, .btn-danger {
        min-height: 44px;
        padding: 8px 16px;
        font-size: 14px;
    }

    /* 分页栏适配 */
    .pagination-bar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px;
    }
    .pagination-bar .page-btns {
        flex-wrap: wrap;
    }

    /* 弹窗适配 */
    .modal-content {
        width: 95% !important;
        max-width: 95vw !important;
        max-height: 90vh;
        margin: 5vh auto;
    }
    .modal-body {
        max-height: 60vh;
        padding: 12px;
    }
    .modal-footer {
        position: sticky;
        bottom: 0;
        background: #1a1a2e;
        padding: 12px;
        border-top: 1px solid #333;
        display: flex;
        gap: 8px;
        justify-content: flex-end;
    }
    .modal-footer button {
        min-height: 40px;
        padding: 8px 20px;
        font-size: 14px;
    }

    /* 表单适配 */
    .form-row {
        flex-direction: column;
    }
    .form-row label {
        min-width: auto;
        margin-bottom: 4px;
        font-size: 13px;
    }
    .form-row input,
    .form-row select,
    .form-row textarea {
        width: 100% !important;
        min-height: 38px;
        font-size: 14px;
    }

    /* Dashboard 统计卡片 */
    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .stat-card {
        padding: 10px;
    }
    .stat-card .value {
        font-size: 18px;
    }

    /* 行操作按钮增大 */
    td.row-actions a {
        display: inline-block;
        padding: 4px 8px;
        min-height: 28px;
        line-height: 20px;
    }

    /* 导航分组优化 */
    .nav-group-title {
        padding: 7px 16px;
        font-size: 13px;
    }
    .menu-item {
        padding: 7px 16px;
        font-size: 13px;
    }
}

/* ========== 手机竖屏 (≤480px) ========== */
@media (max-width: 480px) {

    /* 表格字体缩小 */
    .table-section th,
    .table-section td {
        font-size: 12px;
        padding: 6px 8px;
    }

    /* 工具栏单列 */
    .toolbar-filter {
        flex-direction: column;
    }
    .toolbar-filter input,
    .toolbar-filter select {
        width: 100%;
    }

    /* 弹窗全屏 */
    .modal-content {
        width: 100% !important;
        max-width: 100vw !important;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }
    .modal-body {
        max-height: calc(100vh - 120px);
    }

    /* Dashboard 统计单列 */
    .stat-cards {
        grid-template-columns: 1fr;
    }

    /* 导出选择框适配 */
    .export-select {
        min-height: 36px;
        font-size: 13px;
    }

    /* 批量操作栏换行 */
    .batch-toolbar {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* [v2.9.87] 不良品配置页：产品搜索框全宽 */
    #defect-cfg-product-search {
        min-width: 100% !important;
    }

    /* [v2.9.87] 不良品统计页：筛选区单列堆叠+卡片纵向排列 */
    #defect-stats-cards {
        flex-direction: column !important;
    }
    #defect-stats-tabs {
        flex-wrap: wrap;
    }
}

/* ========== 横屏手机 + 小平板 (481-768px) ========== */
@media (min-width: 481px) and (max-width: 768px) {
    .stat-cards {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ========== 打印样式 ========== */
@media print {
    .sidebar,
    .mobile-top-bar,
    .page-toolbar,
    .pagination-bar,
    .modal-overlay,
    td.row-actions {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
    }
    .table-section table {
        min-width: auto;
    }
}
