/**
 * 移动端响应式设计优化
 * Mobile Responsive Design Optimization
 */

/* ==========================================================================
   Base Mobile Styles
   ========================================================================== */

/* 通用移动端优化 */
@media screen and (max-width: 768px) {
    /* 基础布局调整 */
    body {
        font-size: 14px;
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    /* 容器优化 */
    .container,
    .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    /* 文字大小调整 */
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    h4 { font-size: 16px; }
    h5 { font-size: 14px; }
    h6 { font-size: 12px; }
    
    /* 按钮优化 */
    .btn {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px;
        border-radius: 6px;
    }
    
    .btn-sm {
        padding: 8px 16px;
        font-size: 14px;
        min-height: 36px;
    }
    
    /* 表单元素优化 */
    .form-control,
    .form-select {
        padding: 12px 16px;
        font-size: 16px;
        min-height: 44px;
        border-radius: 6px;
    }
    
    /* 卡片组件优化 */
    .card {
        margin-bottom: 15px;
        border-radius: 8px;
    }
    
    .card-body {
        padding: 15px;
    }
    
    /* 导航优化 */
    .navbar {
        padding: 8px 15px;
    }
    
    .navbar-brand {
        font-size: 18px;
    }
    
    /* 表格优化 */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        font-size: 14px;
    }
    
    .table th,
    .table td {
        padding: 8px 6px;
        white-space: nowrap;
    }
}

/* ==========================================================================
   Navigation Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 侧边栏优化 */
    .sidebar {
        position: fixed;
        top: 0;
        left: -250px;
        width: 250px;
        height: 100vh;
        background: #fff;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        transition: left 0.3s ease;
        z-index: 1050;
    }
    
    .sidebar.show {
        left: 0;
    }
    
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }
    
    /* 移动端菜单按钮 */
    .mobile-menu-toggle {
        display: block;
        background: none;
        border: none;
        padding: 8px;
        font-size: 20px;
        color: #333;
        cursor: pointer;
    }
    
    /* 主内容区调整 */
    .main-content {
        margin-left: 0;
        padding: 15px;
    }
    
    /* 导航链接优化 */
    .nav-link {
        padding: 12px 20px;
        font-size: 16px;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .nav-link:last-child {
        border-bottom: none;
    }
}

/* ==========================================================================
   Dashboard Grid Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 仪表板网格调整 */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .dashboard-card {
        margin-bottom: 15px;
    }
    
    /* 统计卡片优化 */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .stat-card {
        padding: 15px;
        text-align: center;
    }
    
    .stat-value {
        font-size: 24px;
        font-weight: bold;
        margin-bottom: 5px;
    }
    
    .stat-label {
        font-size: 12px;
        color: #666;
    }
    
    /* 图表容器优化 */
    .chart-container {
        height: 250px;
        margin: 15px 0;
    }
    
    /* 控制面板优化 */
    .control-panel {
        flex-direction: column;
        gap: 10px;
    }
    
    .control-group {
        width: 100%;
    }
}

/* ==========================================================================
   Form and Input Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 表单布局优化 */
    .form-row {
        flex-direction: column;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
    
    .form-label {
        margin-bottom: 5px;
        font-weight: 500;
    }
    
    /* 输入组优化 */
    .input-group {
        flex-direction: column;
    }
    
    .input-group .form-control {
        margin-bottom: 10px;
        border-radius: 6px;
    }
    
    .input-group-text {
        border-radius: 6px;
        padding: 8px 12px;
    }
    
    /* 选择器优化 */
    .select2-container {
        width: 100% !important;
    }
    
    .select2-selection {
        min-height: 44px;
        padding: 8px 12px;
    }
    
    /* 日期选择器优化 */
    .datepicker {
        width: 100%;
    }
    
    /* 文件上传优化 */
    .file-upload-area {
        padding: 30px 15px;
        text-align: center;
        border: 2px dashed #ddd;
        border-radius: 8px;
        margin-bottom: 15px;
    }
}

/* ==========================================================================
   Table Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 响应式表格 */
    .table-mobile {
        border: 0;
    }
    
    .table-mobile thead {
        display: none;
    }
    
    .table-mobile tr {
        border: 1px solid #ccc;
        display: block;
        margin-bottom: 10px;
        padding: 15px;
        border-radius: 8px;
        background: #fff;
    }
    
    .table-mobile td {
        border: none;
        display: block;
        font-size: 14px;
        text-align: right;
        padding: 8px 0;
        border-bottom: 1px solid #eee;
    }
    
    .table-mobile td:last-child {
        border-bottom: none;
    }
    
    .table-mobile td:before {
        content: attr(data-label) ": ";
        float: left;
        font-weight: bold;
        color: #666;
    }
    
    /* 操作按钮优化 */
    .table-actions {
        display: flex;
        gap: 5px;
        justify-content: flex-end;
        margin-top: 10px;
    }
    
    .table-actions .btn {
        padding: 6px 12px;
        font-size: 12px;
        min-height: auto;
    }
}

/* ==========================================================================
   Modal Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 模态框优化 */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }
    
    .modal-content {
        border-radius: 8px;
    }
    
    .modal-header {
        padding: 15px;
        border-bottom: 1px solid #dee2e6;
    }
    
    .modal-title {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 15px;
        max-height: 60vh;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 15px;
        border-top: 1px solid #dee2e6;
        justify-content: space-between;
    }
    
    .modal-footer .btn {
        margin: 0 5px;
        flex: 1;
    }
    
    /* 全屏模态框 */
    .modal-fullscreen-mobile {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        margin: 0;
        border-radius: 0;
    }
}

/* ==========================================================================
   Chart and Visualization Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 图表响应式 */
    .chart-wrapper {
        position: relative;
        height: 250px;
        margin: 15px 0;
    }
    
    .chart-legend {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
    }
    
    .legend-item {
        font-size: 12px;
        display: flex;
        align-items: center;
        gap: 5px;
    }
    
    /* 图表标题优化 */
    .chart-title {
        font-size: 16px;
        text-align: center;
        margin-bottom: 15px;
    }
    
    /* 图表控制器优化 */
    .chart-controls {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .chart-control-item {
        flex: 1;
        min-width: 120px;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 显示/隐藏工具类 */
    .d-mobile-none {
        display: none !important;
    }
    
    .d-mobile-block {
        display: block !important;
    }
    
    .d-mobile-flex {
        display: flex !important;
    }
    
    /* 间距工具类 */
    .m-mobile-0 { margin: 0 !important; }
    .m-mobile-1 { margin: 8px !important; }
    .m-mobile-2 { margin: 16px !important; }
    .m-mobile-3 { margin: 24px !important; }
    
    .p-mobile-0 { padding: 0 !important; }
    .p-mobile-1 { padding: 8px !important; }
    .p-mobile-2 { padding: 16px !important; }
    .p-mobile-3 { padding: 24px !important; }
    
    /* 文本对齐 */
    .text-mobile-center { text-align: center !important; }
    .text-mobile-left { text-align: left !important; }
    .text-mobile-right { text-align: right !important; }
    
    /* 宽度工具类 */
    .w-mobile-100 { width: 100% !important; }
    .w-mobile-75 { width: 75% !important; }
    .w-mobile-50 { width: 50% !important; }
    .w-mobile-25 { width: 25% !important; }
}

/* ==========================================================================
   Touch Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 触摸优化 */
    .touch-target {
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* 滑动优化 */
    .swipe-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .swipe-container::-webkit-scrollbar {
        display: none;
    }
    
    /* 长按优化 */
    .long-press {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* 禁用缩放 */
    .no-zoom {
        touch-action: pan-x pan-y;
    }
}

/* ==========================================================================
   Loading and Animation Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 加载动画优化 */
    .loading-spinner {
        width: 30px;
        height: 30px;
        margin: 20px auto;
    }
    
    .loading-text {
        text-align: center;
        font-size: 14px;
        color: #666;
        margin-top: 10px;
    }
    
    /* 过渡动画优化 */
    .fade-transition {
        transition: opacity 0.3s ease;
    }
    
    .slide-transition {
        transition: transform 0.3s ease;
    }
    
    /* 减少动画以节省电池 */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* ==========================================================================
   Print Optimization
   ========================================================================== */

@media print {
    /* 打印样式优化 */
    .no-print {
        display: none !important;
    }
    
    .page-break-before {
        page-break-before: always;
    }
    
    .page-break-after {
        page-break-after: always;
    }
    
    .page-break-inside-avoid {
        page-break-inside: avoid;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .chart-container {
        height: 300px;
    }
}

/* ==========================================================================
   Dark Mode Mobile Optimization
   ========================================================================== */

@media screen and (max-width: 768px) and (prefers-color-scheme: dark) {
    /* 暗色模式移动端优化 */
    body {
        background-color: #121212;
        color: #e0e0e0;
    }
    
    .card {
        background-color: #1e1e1e;
        border-color: #333;
    }
    
    .form-control,
    .form-select {
        background-color: #2a2a2a;
        border-color: #444;
        color: #e0e0e0;
    }
    
    .btn-primary {
        background-color: #0d6efd;
        border-color: #0d6efd;
    }
    
    .table {
        color: #e0e0e0;
    }
    
    .table-striped > tbody > tr:nth-of-type(odd) > td,
    .table-striped > tbody > tr:nth-of-type(odd) > th {
        background-color: #2a2a2a;
    }
}

/* ==========================================================================
   Performance Optimization
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* 性能优化 */
    * {
        -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    
    /* 硬件加速 */
    .hardware-accelerated {
        -webkit-transform: translateZ(0);
        -moz-transform: translateZ(0);
        -ms-transform: translateZ(0);
        -o-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* 图片优化 */
    img {
        max-width: 100%;
        height: auto;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* 字体优化 */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}