/* ============================================
 * 移动端适配CSS
 * 适配分辨率：375x667、414x896等移动端屏幕
 * ============================================ */

/* 平板设备适配 (768px - 1024px) */
@media (max-width: 1024px) {
    /* 侧边栏收起 */
    .sidebar {
        width: 200px;
    }
    
    .main-content {
        margin-left: 200px;
    }
    
    /* 表格字体调小 */
    table {
        font-size: 12px;
    }
    
    /* 按钮间距减小 */
    .toolbar button {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* 移动设备适配 (<= 768px) */
@media (max-width: 768px) {
    /* 侧边栏变为汉堡菜单 */
    .sidebar {
        position: fixed;
        left: -250px;
        width: 250px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar.active {
        left: 0;
    }
    
    /* 主内容占满全屏 */
    .main-content {
        margin-left: 0;
        padding: 10px;
    }
    
    /* 侧边栏切换按钮 */
    .sidebar-toggle {
        display: block;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 1001;
        background: #007bff;
        color: white;
        border: none;
        padding: 10px;
        border-radius: 5px;
        cursor: pointer;
    }
    
    /* 工具栏换行 */
    .toolbar {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    /* 按钮全宽 */
    .toolbar button {
        flex: 1;
        min-width: 100px;
        padding: 10px 15px;
        margin-bottom: 10px;
        font-size: 14px;
    }
    
    /* 输入框全宽 */
    .toolbar input {
        width: 100%;
        max-width: none;
        margin-bottom: 10px;
        font-size: 14px;
    }
    
    /* 表格横向滚动 */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        font-size: 12px;
    }
    
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    tbody tr {
        border-bottom: 1px solid #ddd;
        margin-bottom: 10px;
        display: block;
    }
    
    tbody td {
        border: none;
        border-bottom: 1px solid #eee;
        position: relative;
        padding-left: 50%;
        min-height: 30px;
        display: block;
        text-align: left;
    }
    
    tbody td:before {
        position: absolute;
        top: 6px;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: bold;
        content: attr(data-label);
    }
    
    /* 模态框适配 */
    .modal {
        width: 90%;
        max-width: 90%;
        margin: 5% auto;
        padding: 15px;
    }
    
    .modal-content {
        max-height: 70vh;
        overflow-y: auto;
    }
    
    /* 标签页适配 */
    .tab-btn {
        padding: 10px 15px;
        font-size: 13px;
    }
    
    /* 消息提示适配 */
    .message {
        font-size: 14px;
        padding: 10px;
    }
    
    /* 头部适配 */
    .content-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 15px;
    }
    
    .content-header h1 {
        font-size: 18px;
        margin-bottom: 10px;
    }
    
    /* 统计信息适配 */
    .total-amount {
        font-size: 14px;
        margin-bottom: 10px;
    }
}

/* 小屏设备适配 (<= 480px) */
@media (max-width: 480px) {
    /* 侧边栏占满屏幕 */
    .sidebar {
        width: 100%;
        left: -100%;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    /* 主内容内边距减小 */
    .main-content {
        padding: 5px;
    }
    
    /* 按钮进一步优化 */
    .toolbar button {
        font-size: 12px;
        padding: 8px 12px;
        min-width: 80px;
    }
    
    /* 表格字体更小 */
    table {
        font-size: 11px;
    }
    
    /* 模态框占满屏幕 */
    .modal {
        width: 95%;
        margin: 2.5% auto;
        padding: 10px;
    }
    
    /* 输入框字体调整 */
    input[type="text"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px; /* 防止iOS缩放 */
    }
    
    /* 标题字体 */
    h1, h2, h3, h4, h5, h6 {
        font-size: 16px;
    }
}

/* 超小屏设备适配 (<= 360px) */
@media (max-width: 360px) {
    .toolbar button {
        font-size: 11px;
        padding: 6px 10px;
        min-width: 70px;
    }
    
    .tab-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    table {
        font-size: 10px;
    }
}

/* ============================================
 * 横屏适配
 * ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    /* 减少间距 */
    .main-content {
        padding: 5px;
    }
    
    .toolbar {
        gap: 5px;
    }
    
    .toolbar button {
        padding: 6px 10px;
        margin-bottom: 5px;
    }
    
    /* 表格更紧凑 */
    table {
        font-size: 11px;
    }
    
    /* 模态框更紧凑 */
    .modal {
        margin: 2% auto;
        max-height: 80vh;
    }
}

/* ============================================
 * iOS Safari特定适配
 * ============================================ */
@supports (-webkit-touch-callout: none) {
    input[type="text"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px; /* 防止iOS自动放大 */
    }
}

/* ============================================
 * 触摸设备适配
 * ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* 增大触摸目标 */
    .toolbar button,
    .tab-btn,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 20px;
    }
    
    /* 下拉菜单适配 */
    select {
        padding: 10px;
        min-height: 44px;
    }
}

/* ============================================
 * 打印适配
 * ============================================ */
@media print {
    .sidebar,
    .sidebar-toggle,
    .toolbar button:not(.print-button) {
        display: none;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    table {
        display: table;
    }
    
    thead tr {
        position: static;
    }
    
    tbody td {
        display: table-cell;
        padding-left: 10px;
    }
    
    tbody td:before {
        display: none;
    }
}

/* ============================================
 * 高对比度模式适配
 * ============================================ */
@media (prefers-contrast: high) {
    button {
        border: 2px solid currentColor;
    }
    
    input,
    select,
    textarea {
        border: 2px solid currentColor;
    }
    
    table {
        border: 2px solid currentColor;
    }
    
    th,
    td {
        border: 1px solid currentColor;
    }
}

/* ============================================
 * 减少动画（用户偏好）
 * ============================================ */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
 * 暗色模式适配
 * ============================================ */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }
    
    .sidebar {
        background-color: #2d2d2d;
        border-right: 1px solid #404040;
    }
    
    .main-content {
        background-color: #1a1a1a;
    }
    
    table {
        background-color: #2d2d2d;
        color: #e0e0e0;
    }
    
    th {
        background-color: #404040;
    }
    
    tr:hover {
        background-color: #3d3d3d;
    }
    
    .modal {
        background-color: #2d2d2d;
        border: 1px solid #404040;
    }
    
    input,
    select,
    textarea {
        background-color: #2d2d2d;
        color: #e0e0e0;
        border: 1px solid #404040;
    }
    
    button {
        background-color: #404040;
        color: #e0e0e0;
    }
    
    button:hover {
        background-color: #505050;
    }
}
