/**
 * Mobile Optimization - 移动端优化样式
 * 提供响应式设计、触摸优化、移动端专用样式
 */

/* ==================== 基础响应式 ==================== */

/* 移动端视口优化 */
@viewport {
    width: device-width;
    zoom: 1.0;
}

/* 防止iOS文本自动调整大小 */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* 移动端平滑滚动 */
body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* ==================== 触摸优化 ==================== */

/* 增大触摸区域 */
@media (max-width: 768px) {
    button,
    a,
    input[type="button"],
    input[type="submit"],
    .clickable {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }

    /* 表单输入框 */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: var(--text-base); /* 防止iOS缩放 */
        min-height: 44px;
        padding: var(--spacing-3);
    }
}

/* 触摸反馈 */
.touchable {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.touchable:active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* 禁用双击缩放 */
.no-zoom {
    touch-action: manipulation;
}

/* ==================== 移动端布局 ==================== */

/* 容器响应式 */
@media (max-width: 768px) {
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* 侧边栏移动端适配 */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        transition: left 0.3s ease;
    }

    .sidebar.active {
        left: 0;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

    /* 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* 主内容区域 */
    .main-content {
        margin-left: 0;
        padding-top: 60px; /* 给顶部导航栏留空间 */
    }

    /* 卡片网格 */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* 统计卡片 */
    .stat-card {
        padding: var(--spacing-4);
    }

    /* 表格响应式 */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: var(--text-sm);
    }

    th, td {
        padding: 8px 12px;
    }
}

/* 超小屏幕 */
@media (max-width: 480px) {
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }

    h1 {
        font-size: var(--text-2xl);
    }

    h2 {
        font-size: var(--text-xl);
    }

    h3 {
        font-size: var(--text-lg);
    }

    .button {
        font-size: var(--text-sm);
        padding: 10px 14px;
    }
}

/* ==================== 移动端导航 ==================== */

@media (max-width: 768px) {
    /* 顶部导航栏 */
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--card-bg);
        border-bottom: 1px solid #e5e7eb;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        z-index: 1001;
    }

    /* 汉堡菜单 */
    .hamburger-menu {
        width: 28px;
        height: 24px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        cursor: pointer;
    }

    .hamburger-menu span {
        width: 100%;
        height: 3px;
        background: #1f2937;
        border-radius: 2px;
        transition: all 0.3s ease;
    }

    .hamburger-menu.active span:nth-child(1) {
        transform: translateY(10.5px) rotate(45deg);
    }

    .hamburger-menu.active span:nth-child(2) {
        opacity: 0;
    }

    .hamburger-menu.active span:nth-child(3) {
        transform: translateY(-10.5px) rotate(-45deg);
    }

    /* 底部导航栏 */
    .bottom-navigation {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--card-bg);
        border-top: 1px solid #e5e7eb;
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 1001;
        padding: 0 8px;
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: var(--spacing-2);
        color: #6b7280;
        text-decoration: none;
        font-size: var(--text-xs);
        transition: color 0.2s;
    }

    .bottom-nav-item.active {
        color: #007aff;
    }

    .bottom-nav-item svg {
        width: 24px;
        height: 24px;
    }
}

/* ==================== 手势优化 ==================== */

/* 下拉刷新提示 */
.pull-to-refresh {
    position: absolute;
    top: -60px;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-size: var(--text-sm);
    transition: transform 0.2s;
}

.pull-to-refresh.pulling {
    transform: translateY(60px);
}

/* 滑动操作 */
.swipeable {
    position: relative;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.swipe-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
}

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

@media (max-width: 768px) {
    /* 表单组 */
    .form-group {
        margin-bottom: var(--spacing-5);
    }

    /* 标签 */
    label {
        display: block;
        margin-bottom: 8px;
        font-size: var(--text-sm);
        font-weight: var(--font-medium);
    }

    /* 输入框 */
    input,
    textarea,
    select {
        width: 100%;
        border-radius: var(--radius-lg);
        border: 1px solid #d1d5db;
        transition: border-color 0.2s;
    }

    input:focus,
    textarea:focus,
    select:focus {
        outline: none;
        border-color: #007aff;
        box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
    }

    /* 复选框和单选框 */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 8px;
    }

    /* 提交按钮 */
    .form-submit {
        width: 100%;
        padding: 14px;
        font-size: var(--text-base);
        font-weight: var(--font-semibold);
        border-radius: var(--radius-lg);
        border: none;
        background: #007aff;
        color: var(--text-inverse);
        cursor: pointer;
    }

    .form-submit:active {
        background: #0051d5;
    }
}

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

@media (max-width: 768px) {
    .modal {
        padding: var(--spacing-4);
    }

    .modal-content {
        width: 100%;
        max-width: none;
        margin: auto;
        border-radius: 16px 16px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        animation: slideUp 0.3s ease;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

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

    .modal-body {
        padding: 20px 16px;
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: var(--spacing-4);
        border-top: 1px solid #e5e7eb;
    }
}

/* ==================== 加载状态 ==================== */

@media (max-width: 768px) {
    .loading-spinner {
        width: 40px;
        height: 40px;
        border: 3px solid #f3f4f6;
        border-top-color: #007aff;
        border-radius: var(--radius-full);
        animation: spin 0.8s linear infinite;
    }

    @keyframes spin {
        to {
            transform: rotate(360deg);
        }
    }

    .skeleton {
        background: linear-gradient(
            90deg,
            #f0f0f0 25%,
            #e0e0e0 50%,
            #f0f0f0 75%
        );
        background-size: 200% 100%;
        animation: loading 1.5s ease-in-out infinite;
    }

    @keyframes loading {
        0% {
            background-position: 200% 0;
        }
        100% {
            background-position: -200% 0;
        }
    }
}

/* ==================== 通知/Toast ==================== */

@media (max-width: 768px) {
    .toast {
        position: fixed;
        bottom: 80px; /* 避免遮挡底部导航 */
        left: 16px;
        right: 16px;
        padding: var(--spacing-4);
        border-radius: var(--radius-xl);
        background: var(--card-bg);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 9020;
        animation: toastSlideUp 0.3s ease;
    }

    @keyframes toastSlideUp {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}

/* ==================== 图片优化 ==================== */

@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }

    .image-placeholder {
        background: #f3f4f6;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 200px;
    }

    .lazy-image {
        opacity: 0;
        transition: opacity 0.3s;
    }

    .lazy-image.loaded {
        opacity: 1;
    }
}

/* ==================== 可访问性 ==================== */

/* 大触摸目标 */
.touch-target {
    position: relative;
    padding: var(--spacing-3);
}

.touch-target::after {
    content: '';
    position: absolute;
    top: -8px;
    right: -8px;
    bottom: -8px;
    left: -8px;
}

/* 焦点可见性 */
:focus-visible {
    outline: 2px solid #007aff;
    outline-offset: 2px;
}

/* 屏幕阅读器 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ==================== 性能优化 ==================== */

/* GPU加速 */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* 减少重绘 */
.no-repaint {
    contain: layout style paint;
}

/* 防止内容跳动 */
.prevent-shift {
    content-visibility: auto;
}

/* ==================== 暗色模式适配 ==================== */

@media (prefers-color-scheme: DISABLED-dark) {
    /* 移动端导航栏 */
    @media (max-width: 768px) {
        .mobile-header {
            background: #1f2937;
            border-bottom-color: #374151;
        }

        .hamburger-menu span {
            background: #f3f4f6;
        }

        .bottom-navigation {
            background: #1f2937;
            border-top-color: #374151;
        }

        .bottom-nav-item {
            color: #9ca3af;
        }

        .bottom-nav-item.active {
            color: #667eea;
        }

        /* 侧边栏 */
        .sidebar {
            background: #1f2937;
            box-shadow: 2px 0 8px rgba(0, 0, 0, 0.5);
        }

        /* 表单 */
        label {
            color: #d1d5db;
        }

        input,
        textarea,
        select {
            background: #111827;
            border-color: #374151;
            color: #f3f4f6;
        }

        input:focus,
        textarea:focus,
        select:focus {
            border-color: #667eea;
            background: #1f2937;
        }

        .form-submit {
            background: #667eea;
        }

        .form-submit:active {
            background: #5568d3;
        }

        /* 模态框 */
        .modal-content {
            background: #1f2937;
        }

        .modal-header,
        .modal-footer {
            border-color: #374151;
        }

        /* Toast 通知 */
        .toast {
            background: #1f2937;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
        }

        /* 图片占位符 */
        .image-placeholder {
            background: #111827;
        }
    }

    /* 下拉刷新 */
    .pull-to-refresh {
        color: #9ca3af;
    }

    /* 骨架屏 */
    .skeleton {
        background: linear-gradient(
            90deg,
            #1f2937 25%,
            #374151 50%,
            #1f2937 75%
        );
    }

    /* 加载动画 */
    .loading-spinner {
        border-color: #374151;
        border-top-color: #667eea;
    }
}
