/*
 * Enhanced Responsive Design CSS
 * 增强响应式设计样式表
 * Version: 1.0
 * Last Updated: 2024
 */

/* ===== 现代响应式设计增强 ===== */

/* 容器查询支持 */
@container (min-width: 400px) {
    .card {
        display: grid;
        grid-template-columns: 1fr 2fr;
        gap: 1rem;
    }
}

@container (min-width: 600px) {
    .card {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* 现代网格布局 */
.auto-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: clamp(1rem, 3vw, 2rem);
}

.masonry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    grid-auto-rows: masonry;
    gap: 1rem;
}

/* 流体排版 */
.fluid-text {
    font-size: clamp(1rem, 2.5vw, 2rem);
    line-height: clamp(1.4, 1.5vw, 1.6);
}

.fluid-heading {
    font-size: clamp(1.5rem, 4vw, 3rem);
    line-height: clamp(1.2, 1.3vw, 1.4);
}

.fluid-subheading {
    font-size: clamp(1.2rem, 3vw, 2rem);
    line-height: clamp(1.3, 1.4vw, 1.5);
}

/* 响应式间距 */
.responsive-padding {
    padding: clamp(1rem, 5vw, 3rem);
}

.responsive-margin {
    margin: clamp(0.5rem, 2vw, 1.5rem) 0;
}

.responsive-gap {
    gap: clamp(0.5rem, 2vw, 2rem);
}

/* 移动端优化 */
@media (max-width: 768px) {
    /* 触摸友好的按钮 */
    .btn, button, [role="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 16px; /* 防止iOS缩放 */
    }
    
    /* 移动端导航优化 */
    .mobile-nav {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        height: 100vh;
        background: var(--bg-color);
        transition: left 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .mobile-nav.active {
        left: 0;
    }
    
    .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 999;
    }
    
    .mobile-nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    /* 移动端表单优化 */
    input, textarea, select {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 12px;
        border-radius: 8px;
    }
    
    /* 移动端卡片布局 */
    .card-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* 移动端图片优化 */
    img {
        max-width: 100%;
        height: auto;
        object-fit: cover;
    }
    
    /* 移动端文字优化 */
    .mobile-center {
        text-align: center;
    }
    
    .mobile-hide {
        display: none;
    }
    
    /* 移动端滚动优化 */
    .mobile-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .mobile-scroll::-webkit-scrollbar {
        display: none;
    }
}

/* 平板端优化 */
@media (min-width: 769px) and (max-width: 1024px) {
    .tablet-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
    
    .tablet-hide {
        display: none;
    }
    
    .tablet-show {
        display: block;
    }
}

/* 桌面端优化 */
@media (min-width: 1025px) {
    .desktop-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 2rem;
    }
    
    .desktop-hide {
        display: none;
    }
    
    .desktop-show {
        display: block;
    }
    
    /* 桌面端悬浮效果 */
    .desktop-hover:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    }
}

/* 超宽屏优化 */
@media (min-width: 1400px) {
    .ultra-wide-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 2.5rem;
    }
    
    .container {
        max-width: 1320px;
    }
}

/* 高分辨率屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .high-dpi-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 500px) {
    .landscape-optimize {
        height: 80vh;
        overflow-y: auto;
    }
    
    .landscape-hide {
        display: none;
    }
}

/* 竖屏模式优化 */
@media (orientation: portrait) {
    .portrait-stack {
        flex-direction: column;
    }
    
    .portrait-full-width {
        width: 100%;
    }
}

/* 打印样式优化 */
@media print {
    .print-hide {
        display: none !important;
    }
    
    .print-show {
        display: block !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
        color: #000;
        background: #fff;
    }
    
    .container {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
    }
    
    .page-break {
        page-break-before: always;
    }
    
    .no-page-break {
        page-break-inside: avoid;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }
    
    .btn {
        border: 1px solid #000;
        background: transparent;
        color: #000;
    }
}

/* 可访问性增强 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .parallax {
        transform: none !important;
    }
}

@media (prefers-contrast: high) {
    .card {
        border: 2px solid currentColor;
    }
    
    .btn {
        border: 2px solid currentColor;
        font-weight: bold;
    }
    
    .link {
        text-decoration: underline;
        font-weight: bold;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #ffffff;
        --card-bg: #2d2d2d;
        --border-color: #404040;
    }
    
    .dark-mode-invert {
        filter: invert(1);
    }
    
    .dark-mode-image {
        opacity: 0.8;
    }
}

/* 减少数据使用偏好 */
@media (prefers-reduced-data: reduce) {
    .data-heavy {
        display: none;
    }
    
    .background-image {
        background-image: none;
    }
    
    video {
        display: none;
    }
    
    .low-data-alternative {
        display: block;
    }
}

/* 现代CSS特性支持检测 */
@supports (display: grid) {
    .grid-fallback {
        display: none;
    }
    
    .grid-enhanced {
        display: grid;
    }
}

@supports (backdrop-filter: blur(10px)) {
    .glassmorphism-enhanced {
        backdrop-filter: blur(10px);
        background: rgba(255, 255, 255, 0.1);
    }
}

@supports (container-type: inline-size) {
    .container-query-enhanced {
        container-type: inline-size;
    }
}

/* 弹性布局增强 */
.flex-responsive {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(0.5rem, 2vw, 1.5rem);
}

.flex-responsive > * {
    flex: 1 1 clamp(250px, 30%, 400px);
}

/* 响应式图片容器 */
.responsive-image-container {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 比例 */
    overflow: hidden;
}

.responsive-image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.responsive-image-container.square {
    padding-bottom: 100%; /* 1:1 比例 */
}

.responsive-image-container.portrait {
    padding-bottom: 133.33%; /* 3:4 比例 */
}

/* 响应式视频容器 */
.responsive-video {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
    overflow: hidden;
}

.responsive-video iframe,
.responsive-video video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

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

.responsive-table table {
    min-width: 600px;
    width: 100%;
}

@media (max-width: 768px) {
    .responsive-table-stack {
        display: block;
    }
    
    .responsive-table-stack thead {
        display: none;
    }
    
    .responsive-table-stack tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 1rem;
    }
    
    .responsive-table-stack td {
        display: block;
        text-align: left;
        padding: 0.5rem 0;
        border: none;
    }
    
    .responsive-table-stack td:before {
        content: attr(data-label) ": ";
        font-weight: bold;
        display: inline-block;
        width: 120px;
    }
}

/* 响应式导航 */
.responsive-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

@media (max-width: 768px) {
    .responsive-nav {
        flex-direction: column;
        align-items: stretch;
    }
    
    .responsive-nav-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .responsive-nav-menu.active {
        display: flex;
    }
    
    .responsive-nav-toggle {
        display: block;
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
    }
}

@media (min-width: 769px) {
    .responsive-nav-toggle {
        display: none;
    }
    
    .responsive-nav-menu {
        display: flex !important;
        flex-direction: row;
        gap: 2rem;
    }
}