/**
 * 移动端适配增强样式
 * 针对各端页面的响应式优化
 */

/* ========================================
   通用移动端适配
   ======================================== */

/* 触摸友好的点击区域 */
@media (max-width: 768px) {
    button, .btn, a.btn, .action-btn, .op-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* 输入框增大 */
    input, select, textarea {
        min-height: 44px;
    }
}

/* ========================================
   管理后台侧边栏适配
   ======================================== */
@media (max-width: 768px) {
    /* 侧边栏隐藏，通过汉堡菜单打开 */
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        width: 260px;
        height: 100vh;
        transition: left 0.3s ease;
        z-index: 1001;
    }
    .sidebar.open {
        left: 0;
    }
    
    /* 汉堡菜单按钮 */
    .hamburger-btn {
        display: flex !important;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 1000;
        width: 44px;
        height: 44px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        border: none;
        border-radius: 10px;
        cursor: pointer;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    }
    .hamburger-btn span {
        display: block;
        width: 20px;
        height: 2px;
        background: #fff;
        border-radius: 2px;
        transition: all 0.3s;
    }
    .hamburger-btn.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    .hamburger-btn.active span:nth-child(2) {
        opacity: 0;
    }
    .hamburger-btn.active span:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -5px);
    }
    
    /* 侧边栏遮罩 */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
    }
    .sidebar-backdrop.show {
        display: block;
    }
}

/* ========================================
   数据表格响应式
   ======================================== */
@media (max-width: 768px) {
    /* 表格容器滚动提示 */
    .table-wrap::after, .table-card::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        width: 30px;
        height: 100%;
        background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s;
    }
    .table-wrap.scrollable::after, .table-card.scrollable::after {
        opacity: 1;
    }
    
    /* 表格单元格优化 */
    table td, table th {
        padding: 10px 8px !important;
        font-size: 13px !important;
    }
    
    /* 操作列固定宽度 */
    table td:last-child {
        white-space: nowrap;
    }
    
    /* 长文本截断 */
    table td.ellipsis {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* 卡片式表格（超小屏幕） */
@media (max-width: 480px) {
    .responsive-table {
        display: block;
    }
    .responsive-table thead {
        display: none;
    }
    .responsive-table tbody {
        display: block;
    }
    .responsive-table tr {
        display: block;
        background: #f8f9fa;
        border-radius: 10px;
        padding: 15px;
        margin-bottom: 10px;
        border: 1px solid #e8e8e8;
    }
    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0 !important;
        border: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
    }
    .responsive-table td:last-child {
        border-bottom: none !important;
    }
    .responsive-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #666;
        flex-shrink: 0;
        margin-right: 15px;
    }
}

/* ========================================
   表单响应式布局
   ======================================== */
@media (max-width: 768px) {
    /* 表单行变为堆叠 */
    .form-row, .form-inline {
        flex-direction: column !important;
        gap: 15px !important;
    }
    .form-row > *, .form-inline > * {
        width: 100% !important;
        max-width: none !important;
    }
    
    /* 表单组 */
    .form-group {
        margin-bottom: 15px !important;
    }
    .form-group label {
        margin-bottom: 6px !important;
    }
    
    /* 日期范围选择器 */
    .date-range {
        flex-direction: column !important;
    }
    .date-range input {
        width: 100% !important;
    }
}

/* ========================================
   统计卡片网格
   ======================================== */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    .stats-grid .stat-card {
        padding: 15px !important;
    }
    .stats-grid .stat-card .value {
        font-size: 22px !important;
    }
    .stats-grid .stat-card .label {
        font-size: 12px !important;
    }
    .stats-grid .stat-card .icon {
        font-size: 28px !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}

/* ========================================
   模态框/弹窗优化
   ======================================== */
@media (max-width: 768px) {
    .modal-content, .popup-content {
        width: calc(100% - 20px) !important;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
        margin: 10px;
    }
    
    .modal-content .form-row {
        flex-direction: column !important;
    }
    
    /* 底部固定按钮 */
    .modal-footer {
        position: sticky;
        bottom: 0;
        background: inherit;
        padding-top: 15px;
        margin-top: 15px;
        border-top: 1px solid #f0f0f0;
    }
}

/* ========================================
   页面头部/工具栏
   ======================================== */
@media (max-width: 768px) {
    /* 页面头部 */
    .page-header, .header {
        padding: 15px !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    .page-header h1, .header h2 {
        font-size: 18px !important;
    }
    
    /* 工具栏 */
    .toolbar {
        padding: 10px !important;
        flex-direction: column !important;
        gap: 10px !important;
    }
    .toolbar > * {
        width: 100%;
    }
    
    /* 搜索框 */
    .search-box {
        flex-direction: column !important;
    }
    .search-box input {
        width: 100% !important;
    }
    .search-box button {
        width: 100%;
    }
}

/* ========================================
   Tab 标签页
   ======================================== */
@media (max-width: 768px) {
    .tab-nav, .tabs-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        gap: 5px !important;
        padding: 5px !important;
    }
    .tab-nav button, .tabs-nav button, .tab-item {
        flex-shrink: 0;
        padding: 8px 12px !important;
        font-size: 13px !important;
        white-space: nowrap;
    }
    /* 隐藏Tab图标，只显示文字 */
    .tab-nav button i, .tabs-nav button i {
        display: none;
    }
}

/* ========================================
   主题切换按钮位置调整
   ======================================== */
@media (max-width: 768px) {
    .admin-theme-toggle {
        bottom: 15px !important;
        right: 15px !important;
        width: 40px !important;
        height: 40px !important;
    }
}

/* ========================================
   图表容器
   ======================================== */
@media (max-width: 768px) {
    .chart-container {
        height: 250px !important;
    }
    .chart-wrapper {
        height: 200px !important;
    }
    .chart-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    .chart-range {
        width: 100%;
        justify-content: flex-start;
    }
}

/* ========================================
   列表项/卡片项
   ======================================== */
@media (max-width: 768px) {
    .list-item, .card-item {
        padding: 12px !important;
    }
    
    .list-item-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }
    
    .list-item-actions {
        width: 100%;
        display: flex;
        gap: 8px;
    }
    .list-item-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* ========================================
   底部固定操作栏
   ======================================== */
@media (max-width: 768px) {
    .fixed-bottom-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        padding: 12px 15px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
        z-index: 100;
        display: flex;
        gap: 10px;
    }
    .fixed-bottom-bar .btn {
        flex: 1;
    }
    
    /* 为固定底栏留出空间 */
    .has-fixed-bottom {
        padding-bottom: 70px !important;
    }
}

/* ========================================
   安全区域适配（iPhone X 等）
   ======================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .fixed-bottom-bar {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ========================================
   横屏适配
   ======================================== */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: calc(100vh - 20px);
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* ========================================
   打印样式
   ======================================== */
@media print {
    .sidebar, .hamburger-btn, .sidebar-backdrop,
    .theme-toggle-btn, .admin-theme-toggle,
    .fixed-bottom-bar, .pagination {
        display: none !important;
    }
    
    .content, .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    table {
        min-width: 0 !important;
    }
}

/* ========================================
   面包屑导航移动端适配
   ======================================== */
@media (max-width: 768px) {
    .breadcrumb-nav {
        padding: 8px 15px !important;
        font-size: 12px !important;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .breadcrumb-nav .breadcrumb-item {
        flex-shrink: 0;
    }
    .breadcrumb-nav .breadcrumb-item a {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: inline-block;
        vertical-align: middle;
    }
}

/* ========================================
   安全验证弹窗移动端适配
   ======================================== */
@media (max-width: 768px) {
    .security-verify-modal .security-verify-content {
        width: calc(100% - 30px) !important;
        max-width: 360px;
        margin: 15px;
        padding: 25px 20px !important;
    }
    .security-verify-modal .security-verify-input-group {
        flex-direction: column !important;
        gap: 10px !important;
    }
    .security-verify-modal .security-verify-input-group input {
        width: 100% !important;
        text-align: center;
        font-size: 18px !important;
        letter-spacing: 3px;
    }
    .security-verify-modal .security-verify-input-group button {
        width: 100% !important;
    }
    .security-verify-modal .security-verify-footer {
        flex-direction: column !important;
        gap: 10px !important;
    }
    .security-verify-modal .security-verify-footer button {
        width: 100% !important;
    }
}

/* ========================================
   用户侧边栏移动端适配
   ======================================== */
@media (max-width: 768px) {
    .user-sidebar {
        transform: translateX(-100%);
        width: 280px !important;
    }
    .user-sidebar.open {
        transform: translateX(0);
    }
    .with-sidebar {
        margin-left: 0 !important;
        padding-top: 60px !important;
    }
    .user-hamburger {
        display: flex !important;
    }
    .user-sidebar-backdrop.show {
        display: block !important;
    }
}

/* ========================================
   余额卡片移动端适配
   ======================================== */
@media (max-width: 768px) {
    .balance-card {
        padding: 20px !important;
        border-radius: 12px !important;
    }
    .balance-card .balance-amount {
        font-size: 32px !important;
    }
    .balance-card .balance-stats {
        gap: 15px !important;
        flex-wrap: wrap !important;
    }
    .balance-card .balance-stat {
        min-width: calc(50% - 10px);
    }
}

/* ========================================
   商城首页移动端适配
   ======================================== */
@media (max-width: 768px) {
    /* 商品网格 */
    .products-grid, .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    /* 商品卡片 */
    .product-card {
        border-radius: 10px !important;
    }
    .product-card .product-name {
        font-size: 13px !important;
        -webkit-line-clamp: 2;
    }
    .product-card .product-price {
        font-size: 15px !important;
    }
    .product-card .product-info {
        padding: 10px !important;
    }
    
    /* 分类侧边栏改为顶部滚动 */
    .category-sidebar {
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        padding: 10px !important;
    }
    .category-list {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        gap: 8px !important;
        padding-bottom: 5px;
        -webkit-overflow-scrolling: touch;
    }
    .category-item {
        flex-shrink: 0;
        padding: 8px 15px !important;
        border-radius: 20px !important;
        font-size: 13px !important;
    }
    
    /* 搜索框 */
    .shop-search {
        padding: 10px !important;
    }
    .shop-search input {
        padding: 12px 15px !important;
    }
}

@media (max-width: 480px) {
    .products-grid, .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    .product-card .product-info {
        padding: 8px !important;
    }
    .product-card .product-name {
        font-size: 12px !important;
    }
    .product-card .product-price {
        font-size: 14px !important;
    }
}

/* ========================================
   Toast 提示移动端适配
   ======================================== */
@media (max-width: 768px) {
    .toast-container {
        left: 15px !important;
        right: 15px !important;
        transform: none !important;
    }
    .toast-item {
        max-width: 100% !important;
    }
}

/* ========================================
   新手引导移动端适配
   ======================================== */
@media (max-width: 768px) {
    .tour-tooltip {
        max-width: calc(100vw - 30px) !important;
        font-size: 13px !important;
    }
    .tour-tooltip-content {
        padding: 15px !important;
    }
    .tour-tooltip-actions {
        flex-direction: column !important;
        gap: 8px !important;
    }
    .tour-tooltip-actions button {
        width: 100% !important;
    }
}

/* ========================================
   分页组件移动端适配
   ======================================== */
@media (max-width: 480px) {
    .pagination {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
    .pagination a, .pagination span {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
    /* 隐藏部分页码，只显示首尾和当前附近 */
    .pagination .page-num:not(.active):not(:first-child):not(:last-child):not(.near-active) {
        display: none;
    }
}
