/* ==========================================================================
   移动端优化样式 - Mobile Optimization Styles
   ========================================================================== */

/* 基础移动端适配 */
@media (max-width: 768px) {
    /* 根元素 */
    html {
        font-size: 14px;
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
    }

    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
        overscroll-behavior-y: contain;
    }

    /* 移动端隐藏桌面元素 */
    .desktop-only {
        display: none !important;
    }

    /* 移动端显示 */
    .mobile-only {
        display: block !important;
    }

    /* 容器全宽 */
    .container {
        padding-left: 12px;
        padding-right: 12px;
        max-width: 100%;
    }

    /* 卡片优化 */
    .card {
        border-radius: 8px;
        margin-bottom: 12px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    .card-body {
        padding: 12px;
    }

    .card-header {
        padding: 12px;
        font-size: 0.9375rem;
    }

    /* 表格优化 */
    .table-responsive {
        margin: 0 -12px;
        padding: 0 12px;
        border: none;
    }

    .table-responsive::-webkit-scrollbar {
        height: 4px;
    }

    .table {
        font-size: 0.8125rem;
        margin-bottom: 0;
    }

    .table th,
    .table td {
        padding: 10px 8px;
        white-space: nowrap;
        vertical-align: middle;
    }

    /* 表格卡片视图 - 小屏幕时 */
    .table-mobile-stack {
        display: block;
    }

    .table-mobile-stack thead {
        display: none;
    }

    .table-mobile-stack tbody {
        display: block;
    }

    .table-mobile-stack tr {
        display: block;
        margin-bottom: 12px;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        background: #fff;
    }

    .table-mobile-stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 12px;
        border: none;
        border-bottom: 1px solid #f0f0f0;
        text-align: left;
    }

    .table-mobile-stack td:last-child {
        border-bottom: none;
    }

    .table-mobile-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #495057;
        margin-right: 12px;
        flex-shrink: 0;
    }

    .table-mobile-stack td .actions {
        display: flex;
        gap: 4px;
    }

    /* 按钮优化 */
    .btn {
        padding: 10px 16px;
        font-size: 0.9375rem;
        border-radius: 6px;
        touch-action: manipulation;
    }

    .btn-sm {
        padding: 8px 12px;
        font-size: 0.8125rem;
    }

    .btn-lg {
        padding: 12px 24px;
        font-size: 1rem;
    }

    /* 按钮组优化 */
    .btn-group-mobile-stack {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .btn-group-mobile-stack .btn {
        width: 100%;
    }

    /* 表单优化 */
    .form-control,
    .form-select {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 12px;
        border-radius: 6px;
    }

    .form-label {
        font-size: 0.9375rem;
        font-weight: 600;
        margin-bottom: 6px;
    }

    .form-group,
    .mb-3 {
        margin-bottom: 16px;
    }

    /* 复选框和单选按钮 */
    .form-check {
        padding: 12px 0;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .form-check-input {
        width: 20px;
        height: 20px;
        margin-right: 12px;
    }

    /* 搜索框优化 */
    .search-box {
        position: relative;
        margin-bottom: 12px;
    }

    .search-box .form-control {
        padding-left: 44px;
    }

    .search-box .search-icon {
        position: absolute;
        left: 14px;
        top: 50%;
        transform: translateY(-50%);
        color: #6c757d;
    }

    /* 分页优化 */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
    }

    .pagination .page-link {
        padding: 8px 12px;
        min-width: 40px;
        text-align: center;
    }

    .pagination .page-item.disabled .page-link,
    .pagination .page-item:not(.disabled):not(.active) .page-link {
        background: #fff;
        border: 1px solid #dee2e6;
    }

    /* 模态框优化 */
    .modal-dialog {
        margin: 8px;
        max-width: calc(100vw - 16px);
    }

    .modal-content {
        border-radius: 12px;
    }

    .modal-header {
        padding: 16px;
        border-bottom: 1px solid #f0f0f0;
    }

    .modal-body {
        padding: 16px;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        padding: 12px 16px;
        flex-direction: column;
        gap: 8px;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }

    /* 下拉菜单优化 */
    .dropdown-menu {
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border: none;
        padding: 8px;
    }

    .dropdown-item {
        padding: 12px 16px;
        border-radius: 6px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* 导航栏优化 */
    .navbar {
        padding: 8px 12px;
    }

    .navbar-brand {
        font-size: 0.9375rem;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* 面包屑优化 */
    .breadcrumb {
        padding: 8px 0;
        margin-bottom: 12px;
        font-size: 0.8125rem;
        flex-wrap: wrap;
    }

    .breadcrumb-item {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* 标签页优化 */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs .nav-link {
        padding: 10px 16px;
        white-space: nowrap;
        font-size: 0.875rem;
    }

    /* 徽章优化 */
    .badge {
        padding: 4px 8px;
        font-size: 0.75rem;
        font-weight: 500;
    }

    /* 警告框优化 */
    .alert {
        padding: 12px;
        border-radius: 8px;
        font-size: 0.875rem;
    }

    /* 进度条优化 */
    .progress {
        height: 8px;
        border-radius: 4px;
    }

    /* 列表组优化 */
    .list-group-item {
        padding: 12px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* 数据统计卡片 */
    .stats-card {
        padding: 16px;
        border-radius: 8px;
        margin-bottom: 12px;
    }

    .stats-card .stats-value {
        font-size: 1.5rem;
        font-weight: 600;
    }

    .stats-card .stats-label {
        font-size: 0.8125rem;
        color: #6c757d;
    }

    /* 快捷操作按钮 */
    .quick-actions {
        position: fixed;
        bottom: 16px;
        right: 16px;
        z-index: 1040;
    }

    .quick-actions .btn {
        width: 56px;
        height: 56px;
        border-radius: 50%;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .quick-actions .btn i {
        font-size: 1.25rem;
    }

    /* 文件上传优化 */
    .file-upload-zone {
        padding: 24px;
        border: 2px dashed #dee2e6;
        border-radius: 8px;
        text-align: center;
        min-height: 120px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .file-upload-zone input[type="file"] {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        opacity: 0;
        cursor: pointer;
    }

    /* 加载动画优化 */
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 9999;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }

    /* 图片优化 */
    .img-responsive,
    img {
        max-width: 100%;
        height: auto;
    }

    /* 隐藏滚动条但保持功能 */
    .scrollable {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .scrollable::-webkit-scrollbar {
        display: none;
    }
}

/* 极小屏幕优化 (< 576px) */
@media (max-width: 576px) {
    .container {
        padding-left: 8px;
        padding-right: 8px;
    }

    .card-body {
        padding: 10px;
    }

    .btn {
        padding: 10px 14px;
    }

    .form-control {
        padding: 10px;
    }

    .table th,
    .table td {
        padding: 8px 6px;
        font-size: 0.75rem;
    }

    h1, .h1 { font-size: 1.25rem; }
    h2, .h2 { font-size: 1.125rem; }
    h3, .h3 { font-size: 1rem; }
    h4, .h4 { font-size: 0.9375rem; }
}

/* 横屏优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-dialog {
        max-width: 80vw;
        max-height: 90vh;
    }

    .modal-body {
        max-height: calc(90vh - 120px);
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    /* 增加点击区域 */
    .btn,
    .nav-link,
    .dropdown-item,
    .list-group-item {
        min-height: 44px;
    }

    /* 禁用hover效果 */
    .btn:hover,
    .nav-link:hover,
    .dropdown-item:hover {
        transform: none;
    }

    /* 激活状态 */
    .btn:active,
    .nav-link:active,
    .dropdown-item:active {
        transform: scale(0.98);
    }
}

/* 安全区域适配 (iPhone X+) */
@supports (padding: max(0px)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .fixed-bottom {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .modal-dialog {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* 暗色模式支持 */
@media (prefers-color-scheme: dark) {
    .dark-mode-auto {
        --bs-body-bg: #1a1a1a;
        --bs-body-color: #f0f0f0;
        --bs-card-bg: #2d2d2d;
        --bs-border-color: #404040;
    }
}

/* 打印优化 */
@media print {
    .no-print {
        display: none !important;
    }

    .sidebar,
    .navbar {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}
