/* ============================================================
 * ykadmin 移动端适配 (B方案: 渐进式响应式)
 * 加载于 Views/Shared/_Index.cshtml + _Layout.cshtml
 * 断点: 768px (平板) / 480px (手机)
 * ============================================================ */

/* === 1. 小屏基础字号/间距 === */
@media (max-width: 768px) {
    html, body { font-size: 14px; -webkit-text-size-adjust: 100%; }
    body:not(.login) { overflow-x: hidden; }
    body.gray-bg { background: #fff; } /* 覆盖gray-bg灰底, 内容区白底到底, 避免滚动露出灰 */
    /* 内容区白底铺满, 避免底部滚动区露出灰色(body.gray-bg) */
    .container-div { min-height: calc(100vh - 120px); background: #fff; }
    .container-div { padding: 8px !important; }

    /* 顶部统计卡 4→2 列 */
    .yk-stats { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
    .yk-stats .stat { padding: 12px 10px !important; }
    .yk-stats .stat .val { font-size: 20px !important; }
    .yk-stats .stat .lbl { font-size: 12px !important; }
    /* Inspection stats 卡 */
    .insp-stats { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
    .insp-stats .card { padding: 14px 12px !important; }
    .insp-stats .val { font-size: 22px !important; }
}

/* === 2. 搜索栏换行 (Ledger/Inspection/QuestionBank) === */
@media (max-width: 768px) {
    .ledger-search, .insp-search, .q-search {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 10px !important;
    }
    .ledger-search label, .insp-search label, .q-search label {
        margin-right: 0 !important;
        font-size: 12px !important;
    }
    .ledger-search input, .ledger-search select,
    .insp-search input, .insp-search select,
    .q-search input {
        margin-right: 0 !important;
        flex: 1 1 100px !important;
        min-width: 100px !important;
        font-size: 14px !important;  /* iOS 防弹键盘放大 */
        height: 36px !important;
    }
    .ledger-search .btn, .insp-search .btn, .q-search .btn,
    .ledger-search button, .insp-search button, .q-search button {
        flex: 1 1 auto !important;
        min-width: 80px !important;
        margin: 0 !important;
        height: 36px !important;
    }
    /* 浮动按钮在新行 */
    #btn-new, [onclick*="openForm"], [onclick*="openHoldingForm"] {
        flex-basis: 100% !important;
    }
}

/* === 3. 表格横向滚动 === */
@media (max-width: 768px) {
    .yk-table-wrap, .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 4px;
    }
    .yk-table, .table {
        font-size: 13px !important;
        min-width: 600px;  /* 触发横滚,保留列完整 */
    }
    .yk-table th, .yk-table td, .table th, .table td {
        padding: 6px 8px !important;
        white-space: nowrap;
    }
    /* 操作列按钮小一点 */
    .yk-table .btn, .table .btn { padding: 3px 8px !important; font-size: 12px !important; }
}

/* === 4. 弹窗全屏 (Ledger/Inspection/QuestionBank 都用 modal-X 类) === */
@media (max-width: 768px) {
    .modal, .modal-ledger, .modal-q {
        align-items: stretch !important;
    }
    .modal .modal-body, .modal-ledger .modal-body, .modal-q .modal-body {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 16px !important;
        overflow-y: auto;
    }
    .modal .grid-2 { grid-template-columns: 1fr !important; }
    /* 输入框字号防弹键盘 */
    .modal input, .modal select, .modal textarea,
    .modal-ledger input, .modal-ledger select, .modal-ledger textarea,
    .modal-q input, .modal-q select, .modal-q textarea {
        font-size: 16px !important;  /* 关键! iOS 16px 才不放大 */
        height: 40px !important;
        padding: 8px 10px !important;
    }
    .modal textarea { height: auto !important; min-height: 80px; }
    .modal .opt, .modal-q .opt {
        padding: 12px 16px !important;
        font-size: 14px !important;
        min-width: 60px;
    }
    /* 弹窗底部按钮固定 */
    .modal .form-actions, .modal-ledger .form-actions, .modal-q .form-actions {
        position: sticky !important;
        bottom: 0 !important;
        background: #fff !important;
        padding: 12px 0 !important;
        margin: 16px -16px -16px !important;
        border-top: 1px solid #eee !important;
    }
    .modal .btn, .modal-ledger .btn, .modal-q .btn {
        height: 44px !important;
        font-size: 15px !important;
    }
}

/* === 5. Chart / Tab 适配 === */
@media (max-width: 768px) {
    .yk-tab canvas { height: 220px !important; }
    .market-bar { gap: 16px !important; padding: 10px 14px !important; }
    .market-bar .item .val { font-size: 16px !important; }
    .yk-tab .nav-tabs { overflow-x: auto; white-space: nowrap; }
}

/* === 6. 首页 sidebar 抽屉式 === */
@media (max-width: 768px) {
    /* 默认收起 sidebar */
    body:not(.show-mobile-menu) .navbar-static-side {
        transform: translateX(-100%) !important;
        transition: transform 0.25s ease;
    }
    .navbar-static-side {
        position: fixed !important;
        top: 0; left: 0; bottom: 0;
        width: 240px !important;
        z-index: 10000 !important;
        transform: translateX(0);
        transition: transform 0.25s ease;
    }
    /* 遮罩 */
    body.show-mobile-menu::before {
        content: '';
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: 9999;
    }
    /* hamburger 显示 */
    .mobile-menu-btn {
        display: inline-block !important;
    }
    /* topnav 紧凑 */
    .navbar-static-top { padding: 0 8px !important; }
    /* 隐藏桌面端才需要的按钮 (全屏) — 注意: 不能藏整个 welcome-message, 里边的移动端退出 + 用户菜单需要保留 */
    .navbar-top-links > li.hidden-xs { display: none !important; }
    .navbar-top-links > li > a { padding: 0 8px !important; }
    /* 用户菜单头像在小屏只显示头像, 不显示名字 */
    .navbar-top-links .user-menu .hidden-xs { display: none !important; }
    /* 内容区让出 sidebar */
    #page-wrapper {
        margin-left: 0 !important;
        padding: 8px !important;
    }
    /* 隐藏 fixed-sidebar mini-navbar 兼容逻辑 */
    body.fixed-sidebar.mini-navbar .navbar-static-side {
        width: 240px !important;
        transform: translateX(-100%);
    }
}
@media (min-width: 769px) {
    .mobile-menu-btn { display: none !important; }
}

/* === 7. 顶部导航 hamburger 按钮 === */
.mobile-menu-btn {
    display: none;
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 22px;
    padding: 8px 12px;
    cursor: pointer;
    line-height: 1;
}
.mobile-menu-btn:active { opacity: 0.7; }

/* === 8. 更窄屏幕 (480px 以下) 单列 === */
@media (max-width: 480px) {
    .yk-stats, .insp-stats { grid-template-columns: 1fr !important; }
    .yk-table, .table { font-size: 12px !important; }
    .container-div { padding: 4px !important; }
    /* 隐藏次要列 (需要在 <th> 加 class="col-hide-mobile") */
    .yk-table .col-hide-mobile, .table .col-hide-mobile { display: none !important; }
}

/* === 9. 用户卡片/底部提示 === */
@media (max-width: 768px) {
    .pf-card { padding: 12px 14px !important; }
    .pf-card .name { font-size: 15px !important; }
    .pf-card .price { font-size: 18px !important; }
    #userCard { font-size: 13px !important; }
}

/* === 10. 移动端滚动条美化 (可选) === */
.yk-table-wrap::-webkit-scrollbar, .table-responsive::-webkit-scrollbar {
    height: 6px;
}
.yk-table-wrap::-webkit-scrollbar-thumb, .table-responsive::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

/* === 11. 登录页加固 (覆盖 login.css) === */
@media (max-width: 768px) {
    .login-panel .form-control { font-size: 16px !important; height: 42px !important; }
    .login-panel .btn { height: 44px !important; font-size: 16px !important; }
}

/* === 12. 2026-06-27: 显示 sidebar (覆盖 Hplus.css mini-navbar 默认隐藏) === */
@media (max-width: 768px) {
    body.show-mobile-menu .navbar-static-side,
    body.show-mobile-menu.fixed-sidebar.mini-navbar .navbar-static-side {
        transform: translateX(0) !important;
    }
}

/* === 13. 2026-06-27: 底部 tab bar (iOS/Android 风格, 1 步直达) === */
@media (max-width: 768px) {
    .mobile-tab-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: #fff;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
        display: flex;
        z-index: 9998;
        border-top: 1px solid #e7eaec;
    }
    .mobile-tab-bar a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #888;
        text-decoration: none;
        font-size: 11px;
    }
    .mobile-tab-bar a:active, .mobile-tab-bar a.active {
        color: #1ab394;
    }
    .mobile-tab-bar a i {
        font-size: 18px;
        margin-bottom: 2px;
    }
    /* 给内容区加底部 padding, 不被 tab bar 遮住 */
    body.has-tab-bar #page-wrapper { padding-bottom: 70px !important; }
}
