/* ===========================================
   茶叶进销存系统 - 移动端响应式样式
   仅在屏幕宽度 < 768px 时生效
   =========================================== */

/* ============ 基础布局 ============ */

@media (max-width: 767.98px) {
    
    /* 移动端侧边栏 */
    .sidebar {
        transform: translateX(-100%) !important;
        z-index: 2000 !important;
    }
    
    /* 侧边栏显示时 */
    .sidebar.show {
        transform: translateX(0) !important;
        z-index: 2000 !important;
    }
    
    /* 遮罩层 */
    .sidebar-overlay {
        z-index: 1990 !important;
    }
    
    /* 遮罩层显示 */
    .sidebar-overlay.show {
        z-index: 1990 !important;
    }
    
    /* 主内容区全宽 */
    .main-content {
        margin-left: 0 !important;
        padding: 10px !important;
        padding-bottom: 65px !important;
    }
    
    /* 页面内的 sticky 元素不能超过侧边栏层级 */
    .sticky-top,
    [style*="z-index: 100"],
    [style*="z-index: 50"],
    [style*="z-index: 20"] {
        z-index: 1 !important;
    }
    
    /* 顶部导航栏调整 */
    .navbar {
        padding: 8px 10px !important;
    }
    
    .navbar-brand {
        font-size: 16px !important;
    }
    
    /* 隐藏顶部导航中的部分元素 */
    .navbar .d-flex {
        gap: 5px !important;
    }
    
    .navbar .btn {
        padding: 4px 8px !important;
        font-size: 12px !important;
    }
    
    /* 页面标题 */
    h4, .h4 {
        font-size: 16px !important;
        margin-bottom: 10px !important;
    }
    
    /* 卡片 */
    .card {
        margin-bottom: 10px !important;
        border-radius: 8px !important;
    }
    
    .card-body {
        padding: 12px !important;
    }
    
    .card-header {
        padding: 10px 12px !important;
        font-size: 14px !important;
    }
}

/* ============ 底部导航栏 ============ */

/* 默认隐藏底部导航栏 */
.bottom-nav {
    display: none;
}

/* 移动端显示底部导航栏 */
@media (max-width: 767.98px) {
    .bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid #dee2e6;
        z-index: 1050;
        padding: 3px 0;
        padding-bottom: calc(3px + env(safe-area-inset-bottom, 0));
    }
    
    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 4px 0;
        color: #666;
        text-decoration: none;
        font-size: 9px;
        transition: all 0.2s;
    }
    
    .bottom-nav-item:active,
    .bottom-nav-item.active {
        color: #198754;
    }
    
    .bottom-nav-item i {
        font-size: 18px;
        margin-bottom: 1px;
    }
    
    .bottom-nav-item i.bi-plus-circle-fill {
        font-size: 24px;
    }
    
    .bottom-nav-item span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 50px;
    }
}

/* 电脑端确保隐藏 */
@media (min-width: 768px) {
    .bottom-nav {
        display: none !important;
    }
    
    /* 确保主内容区在电脑端有正确的底部间距 */
    .main-content {
        padding-bottom: 20px !important;
    }
}

/* ============ 表格响应式 ============ */

@media (max-width: 767.98px) {
    
    /* 隐藏传统表格 */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-responsive table {
        font-size: 12px !important;
        min-width: 600px;
    }
    
    .table th, .table td {
        padding: 8px 6px !important;
        white-space: nowrap;
    }
    
    /* 表格内复选框优化 - 确保在移动端可点击 */
    .table .form-check-input {
        width: 22px !important;
        height: 22px !important;
        min-width: 22px !important;
        cursor: pointer;
        touch-action: manipulation;
    }
    
    /* 复选框列确保有足够宽度 */
    .table th:first-child,
    .table td:first-child {
        min-width: 44px !important;
        width: 44px !important;
        text-align: center;
        padding: 8px 4px !important;
    }
    
    /* 复选框容器增加触摸区域 */
    .table td:first-child label,
    .table td:first-child .form-check {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 44px;
        min-width: 44px;
        margin: 0;
        padding: 0;
    }
    
    /* 表格操作按钮 */
    .table .btn-sm {
        padding: 3px 6px !important;
        font-size: 11px !important;
    }
}

/* ============ 卡片列表样式（移动端替代表格） ============ */

.mobile-card-list {
    display: none;
}

@media (max-width: 767.98px) {
    .mobile-card-list {
        display: block;
    }
    
    .mobile-card-item {
        background: #fff;
        border-radius: 8px;
        padding: 12px;
        margin-bottom: 10px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        position: relative;
    }
    
    .mobile-card-item:active {
        background: #f8f9fa;
    }
    
    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;
        padding-bottom: 8px;
        border-bottom: 1px solid #eee;
    }
    
    .mobile-card-no {
        font-weight: bold;
        font-size: 14px;
        color: #333;
    }
    
    .mobile-card-status {
        font-size: 11px;
    }
    
    .mobile-card-body {
        font-size: 13px;
        color: #666;
    }
    
    .mobile-card-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 4px;
    }
    
    .mobile-card-label {
        color: #999;
    }
    
    .mobile-card-value {
        color: #333;
        font-weight: 500;
    }
    
    .mobile-card-actions {
        display: flex;
        gap: 8px;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid #eee;
    }
    
    .mobile-card-actions .btn {
        flex: 1;
        font-size: 12px;
        padding: 6px;
    }
}

/* 电脑端隐藏卡片列表 */
@media (min-width: 768px) {
    .mobile-card-list {
        display: none !important;
    }
}

/* ============ 表单优化 ============ */

@media (max-width: 767.98px) {
    
    .form-control, .form-select {
        font-size: 16px !important; /* 防止 iOS 自动缩放 */
        padding: 10px 12px !important;
        height: auto !important;
    }
    
    .form-label {
        font-size: 13px;
        margin-bottom: 4px;
    }
    
    .btn {
        padding: 10px 16px !important;
        font-size: 14px !important;
    }
    
    .btn-lg {
        padding: 12px 20px !important;
        font-size: 16px !important;
    }
    
    /* 表单行内布局调整 */
    .row > .col-md-6,
    .row > .col-md-4,
    .row > .col-md-3,
    .row > .col-md-2 {
        margin-bottom: 10px;
    }
    
    /* 搜索区域 - 保留并排布局能力 */
    .card-body form.row {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .card-body form.row > div {
        margin: 0 !important;
    }
    
    /* col-6 的元素在手机上各占一半宽度，实现并排 */
    .card-body form.row > .col-6 {
        width: calc(50% - 4px) !important;
        flex: 0 0 calc(50% - 4px) !important;
    }
    
    /* 非 col-6 的元素在手机上占满宽度 */
    .card-body form.row > div:not(.col-6) {
        width: 100% !important;
        flex: 0 0 100% !important;
    }
    
    /* 按钮组 */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        border-radius: 4px !important;
        margin-bottom: 4px;
    }
}

/* ============ 仪表盘优化 ============ */

@media (max-width: 767.98px) {
    
    .dashboard-btn {
        padding: 8px !important;
    }
    
    .dashboard-btn .card-body {
        padding: 8px !important;
    }
    
    .dashboard-btn h6 {
        font-size: 11px !important;
        margin-bottom: 2px !important;
    }
    
    .dashboard-btn h3 {
        font-size: 16px !important;
        margin-bottom: 0 !important;
    }
    
    .dashboard-btn i {
        font-size: 1.2rem !important;
    }
}

/* ============ 分页优化 ============ */

@media (max-width: 767.98px) {
    
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination .page-link {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* ============ 模态框优化 ============ */

@media (max-width: 767.98px) {
    
    .modal-dialog {
        margin: 10px;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .modal-footer {
        padding: 10px 15px;
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
}

/* ============ 下拉选择优化 ============ */

@media (max-width: 767.98px) {
    
    select.form-select {
        background-position: right 10px center;
        padding-right: 30px;
    }
    
    /* 多选框优化 */
    .form-check {
        padding: 10px 0 10px 30px;
        min-height: auto;
    }
    
    .form-check-input {
        width: 18px;
        height: 18px;
        margin-left: -28px;
    }
    
    .form-check-label {
        font-size: 14px;
        line-height: 1.5;
    }
}

/* ============ 打印隐藏底部导航 ============ */

@media print {
    .bottom-nav {
        display: none !important;
    }
}
