/* ========================================
   移动端响应式适配 - 完美版
   ======================================== */

/* 平板设备 (768px - 1024px) */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    
    .stat-card {
        padding: 16px;
    }
    
    .filters {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .content-container {
        padding: 24px;
    }
}

/* 移动设备 (小于768px) */
@media (max-width: 768px) {
    /* ========== 主布局 ========== */
    .main-app {
        flex-direction: column;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100); /* iOS 视口修正 */
    }
    
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100); /* iOS 视口修正 */
        width: 280px;
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        overscroll-behavior: contain; /* 防止过度滚动 */
    }
    
    .sidebar.mobile-open {
        left: 0;
    }
    
    /* 移动端顶部栏 */
    .mobile-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        background: white;
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 999;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        min-height: 56px;
    }
    
    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        border: none;
        background: var(--bg-secondary);
        border-radius: var(--radius-md);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        color: var(--text-primary);
        transition: var(--transition);
    }
    
    .mobile-menu-btn:active {
        transform: scale(0.95);
        background: var(--bg-tertiary);
    }
    
    .mobile-header-title {
        font-size: 16px;
        font-weight: 600;
        color: var(--text-primary);
    }
    
    /* ========== 主内容区 ========== */
    .main-content {
        margin-left: 0;
        width: 100%;
        height: calc(100vh - 56px);
        display: flex;
        flex-direction: column;
    }
    
    /* 顶部导航栏 - 移动端隐藏 */
    .top-bar {
        display: none;
    }
    
    /* 内容容器 */
    .content-container {
        flex: 1;
        padding: 16px;
        padding-bottom: max(32px, env(safe-area-inset-bottom)); /* 增加底部间距，支持iOS安全区域 */
        overflow-y: auto;
        overflow-x: hidden; /* 防止横向滚动 */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain; /* 防止过度滚动 */
        scroll-padding-bottom: 32px; /* 滚动时留出底部空间 */
    }
    
    /* 确保没有多余的底部空白 */
    .content-container > *:last-child {
        margin-bottom: 0;
    }
    
    /* ========== 统计卡片 ========== */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .stat-card {
        padding: 16px;
        display: flex;
        align-items: center;
        gap: 16px;
    }
    
    .stat-icon {
        width: 56px;
        height: 56px;
        font-size: 24px;
        flex-shrink: 0;
    }
    
    .stat-content {
        flex: 1;
    }
    
    .stat-value {
        font-size: 24px;
        font-weight: 700;
        margin-bottom: 4px;
    }
    
    .stat-label {
        font-size: 13px;
        color: var(--text-secondary);
        margin-bottom: 4px;
    }
    
    .stat-change {
        font-size: 12px;
    }
    
    /* 小型统计卡片 */
    .stats-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .mini-stat-card {
        padding: 12px;
    }
    
    .mini-stat-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .mini-stat-value {
        font-size: 20px;
    }
    
    .mini-stat-label {
        font-size: 12px;
    }
    
    /* ========== 卡片 ========== */
    .card {
        padding: 16px;
        border-radius: var(--radius-md);
        margin-bottom: 16px;
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }
    
    .card-title {
        font-size: 16px;
        font-weight: 600;
    }
    
    /* ========== 表格优化 ========== */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
    
    .data-table {
        display: block;
        width: 100%;
    }
    
    .data-table thead {
        display: none;
    }
    
    .data-table tbody {
        display: block;
    }
    
    .data-table tr {
        display: block;
        margin-bottom: 12px;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: 12px;
        background: white;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }
    
    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 8px 0;
        border: none;
        min-height: 36px;
    }
    
    .data-table td:not(:last-child) {
        border-bottom: 1px solid var(--bg-secondary);
    }
    
    .data-table td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 12px;
        text-transform: uppercase;
        flex-shrink: 0;
        margin-right: 12px;
    }
    
    .data-table td > * {
        text-align: right;
    }
    
    /* 表格按钮组 */
    .data-table .table-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: flex-end;
    }
    
    .data-table td .btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* ========== 筛选器 ========== */
    .filter-bar {
        flex-direction: column;
        gap: 12px;
    }
    
    .search-box {
        width: 100%;
    }
    
    .filter-group {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    
    .filter-select {
        width: 100%;
    }
    
    .filters {
        flex-direction: column;
        gap: 10px;
    }
    
    .filters input,
    .filters select {
        width: 100%;
    }
    
    /* ========== 分页 ========== */
    .pagination {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
        padding: 16px 0;
    }
    
    .page-btn {
        min-width: 40px;
        height: 40px;
        padding: 0 12px;
        font-size: 14px;
        border-radius: var(--radius-md);
    }
    
    /* ========== 模态框 ========== */
    .modal-box {
        width: 95% !important;
        max-width: none !important;
        max-height: 90vh !important;
        margin: 16px auto;
        overflow-y: auto;
    }
    
    .modal-header {
        padding: 16px;
        position: sticky;
        top: 0;
        background: white;
        z-index: 1;
    }
    
    .modal-header h3 {
        font-size: 18px;
    }
    
    .modal-content {
        padding: 16px !important;
    }
    
    .modal-footer {
        padding: 16px;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid var(--border-color);
        z-index: 1;
    }
    
    /* ========== 表单 ========== */
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .form-row .col-md-6,
    .form-row .col-md-4,
    .form-row .col-md-3,
    .form-row .form-group {
        flex: 1 1 100%;
        margin-bottom: 16px;
    }
    
    /* ========== 页面头部 ========== */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .header-left {
        width: 100%;
    }
    
    .page-title {
        font-size: 20px;
        margin-bottom: 4px;
    }
    
    .page-desc {
        font-size: 13px;
        color: var(--text-secondary);
    }
    
    .header-actions,
    .page-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .header-actions .btn,
    .page-actions .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* ========== 图表 ========== */
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .chart-card {
        padding: 16px;
    }
    
    .chart-select {
        width: 100%;
        max-width: 150px;
    }
    
    /* ========== 登录页面 ========== */
    .login-box {
        width: 90%;
        max-width: 400px;
        padding: 32px 24px;
    }
    
    .logo-container {
        width: 70px;
        height: 70px;
    }
    
    .logo-container i {
        font-size: 35px;
    }
    
    .login-header h1 {
        font-size: 24px;
    }
    
    .login-header p {
        font-size: 13px;
    }
    
    /* ========== Toast提示 ========== */
    .toast {
        top: auto;
        bottom: 24px;
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(100px);
        width: calc(100% - 32px);
        max-width: 400px;
        padding: 16px 20px;
        font-size: 14px;
        line-height: 1.5;
        text-align: center;
        z-index: 10001;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .toast.show {
        transform: translateX(-50%) translateY(0);
    }
    
    /* Toast 可点击关闭 */
    .toast {
        cursor: pointer;
    }
    
    /* ========== 按钮 ========== */
    .btn {
        padding: 12px 20px;
        font-size: 14px;
        min-height: 44px;
        border-radius: var(--radius-md);
    }
    
    .btn-sm {
        padding: 8px 14px;
        font-size: 13px;
        min-height: 36px;
    }
    
    .btn-lg {
        padding: 14px 24px;
        font-size: 15px;
        min-height: 48px;
    }
    
    /* ========== 通知中心 ========== */
    .notifications-container {
        padding: 0;
    }
    
    .notification-item {
        padding: 14px;
        border-radius: var(--radius-md);
    }
    
    .notification-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .notifications-footer {
        padding: 16px;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .notifications-footer .btn {
        width: 100%;
    }
}

/* 小屏幕手机 (小于480px) */
@media (max-width: 480px) {
    .content-container {
        padding: 12px;
    }
    
    .stat-card {
        padding: 12px;
        gap: 12px;
    }
    
    .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
    
    .stat-value {
        font-size: 22px;
    }
    
    .stat-label {
        font-size: 12px;
    }
    
    .mini-stat-card {
        padding: 10px;
    }
    
    .mini-stat-value {
        font-size: 18px;
    }
    
    .card {
        padding: 12px;
    }
    
    .card-title {
        font-size: 15px;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }
    
    .btn-sm {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .modal-box {
        width: 98% !important;
        margin: 10px auto;
    }
    
    .modal-header {
        padding: 12px;
    }
    
    .modal-content {
        padding: 12px !important;
    }
    
    .form-group {
        margin-bottom: 14px;
    }
    
    .form-group label {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    .form-control {
        font-size: 14px;
        padding: 10px 12px;
    }
    
    .page-title {
        font-size: 18px;
    }
    
    .page-desc {
        font-size: 12px;
    }
}

/* 横屏模式优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        width: 240px;
        left: -240px;
    }
    
    .mobile-header {
        padding: 8px 16px;
    }
    
    .modal-box {
        max-height: 85vh;
    }
    
    .login-box {
        padding: 24px;
        max-width: 500px;
    }
}

/* 隐藏桌面端元素 */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
}

/* 显示移动端元素 */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }
}

/* 触摸设备优化 - 增大触摸区域 */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .nav-item,
    .action-btn,
    .mobile-menu-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .form-control,
    select.form-control,
    .filter-select {
        min-height: 44px;
        font-size: 16px; /* 防止iOS自动缩放 */
    }
    
    .page-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* 优化触摸反馈 */
    .btn:active,
    .nav-item:active,
    .action-btn:active {
        transform: scale(0.98);
        opacity: 0.8;
    }
}

/* 暗色模式支持 */
@media (prefers-color-scheme: dark) {
    @media (max-width: 768px) {
        .mobile-header {
            background: #1f2937;
            border-bottom-color: #374151;
        }
        
        .mobile-header-title {
            color: white;
        }
        
        .mobile-menu-btn {
            background: #374151;
            color: white;
        }
    }
}

/* 缩放优化 - 阻止iOS双击缩放 */
@media (max-width: 768px) {
    * {
        touch-action: manipulation;
    }
    
    input,
    textarea,
    select {
        touch-action: auto;
    }
}

