/**
 * 火神面板 - 全设备响应式设计
 * 支持：手机 (< 768px)、平板 (768px - 1024px)、桌面 (> 1024px)
 */

/* ======================== 基础响应式 ======================== */
* {
    box-sizing: border-box;
}

/* 确保图片和媒体元素不会溢出 */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* 防止文本溢出 */
h1, h2, h3, h4, h5, h6, p {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

/* ======================== 移动端优先 (< 768px) ======================== */
@media (max-width: 767.98px) {
    /* 导航栏优化 */
    .navbar {
        padding: 0.5rem 1rem;
    }
    
    .navbar-brand {
        font-size: 1.2rem;
    }
    
    /* 侧边导航栏 */
    #mySidenav {
        width: 0;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1050;
        transition: 0.3s;
    }
    
    .sidenav-btn {
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 1060;
    }
    
    /* 标题优化 */
    h1 {
        font-size: 1.8rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.3rem;
    }
    
    /* 卡片优化 */
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    /* 按钮优化 */
    .btn {
        font-size: 0.9rem;
        padding: 0.5rem 1rem;
    }
    
    /* 表单优化 */
    .form-control, .form-select {
        font-size: 0.9rem;
    }
    
    /* 表格优化 */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* 网格系统优化 */
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    .col, .col-1, .col-2, .col-3, .col-4, .col-5, .col-6, 
    .col-7, .col-8, .col-9, .col-10, .col-11, .col-12,
    .col-sm, .col-md, .col-lg, .col-xl {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    /* Dashboard 统计卡片 */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    .stat-card {
        padding: 1.2rem !important;
    }
    
    .stat-info h4 {
        font-size: 0.8rem;
    }
    
    .stat-info h5 {
        font-size: 1.5rem;
    }
    
    .stat-icon {
        width: 50px !important;
        height: 50px !important;
        font-size: 1.3rem !important;
    }
    
    /* 页脚优化 */
    footer .row > div {
        text-align: center;
        margin-bottom: 2rem;
    }
    
    footer ul {
        padding: 0;
    }
    
    /* 间距优化 */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .py-6 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
    
    /* 侧边栏按钮 */
    .navbar-toggler {
        display: block !important;
    }
}

/* ======================== 平板设备 (768px - 1024px) ======================== */
@media (min-width: 768px) and (max-width: 1023.98px) {
    /* 导航栏 */
    .navbar {
        padding: 0.75rem 1.5rem;
    }
    
    /* 网格优化 */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* 卡片优化 */
    .card {
        margin-bottom: 1.5rem;
    }
    
    /* Dashboard 优化 */
    .dashboard-section {
        padding: 1.5rem;
    }
    
    .dashboard-title {
        font-size: 1.5rem;
    }
    
    /* 表格优化 */
    table {
        font-size: 0.9rem;
    }
    
    /* 侧边导航 */
    #mySidenav {
        width: 250px;
    }
}

/* ======================== 桌面设备 (> 1024px) ======================== */
@media (min-width: 1024px) {
    .container {
        max-width: 1200px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ======================== 超大屏幕 (> 1440px) ======================== */
@media (min-width: 1440px) {
    .container {
        max-width: 1400px;
    }
    
    .container-fluid {
        padding-left: 5%;
        padding-right: 5%;
    }
}

/* ======================== 横向模式优化 ======================== */
@media (max-width: 767.98px) and (orientation: landscape) {
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .navbar {
        padding: 0.3rem 1rem;
    }
    
    h1 {
        font-size: 1.5rem;
    }
}

/* ======================== 触摸设备优化 ======================== */
@media (hover: none) and (pointer: coarse) {
    /* 增大触摸目标 */
    .btn, 
    a, 
    button, 
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* 禁用 hover 效果 */
    .stat-card:hover,
    .info-card:hover {
        transform: none;
    }
    
    /* 优化表单输入 */
    input, select, textarea {
        font-size: 16px !important; /* 防止 iOS 自动缩放 */
    }
}

/* ======================== 高分辨率屏幕优化 ======================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* 优化边框和阴影 */
    .card {
        border-width: 0.5px;
    }
}

/* ======================== 打印优化 ======================== */
@media print {
    .navbar,
    footer,
    .sidenav-btn,
    #mySidenav,
    .btn,
    .no-print {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .card {
        border: 1px solid #ddd;
        box-shadow: none;
    }
}

/* ======================== 暗色模式支持 ======================== */
@media (prefers-color-scheme: dark) {
    /* 自动适配系统暗色模式 */
    body {
        background-color: #1a1a2e;
    }
}

/* ======================== 减少动画偏好 ======================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ======================== 通用响应式工具类 ======================== */

/* 显示/隐藏类 */
.d-mobile-only {
    display: none;
}

@media (max-width: 767.98px) {
    .d-mobile-only {
        display: block !important;
    }
    
    .d-mobile-none {
        display: none !important;
    }
}

.d-tablet-only {
    display: none;
}

@media (min-width: 768px) and (max-width: 1023.98px) {
    .d-tablet-only {
        display: block !important;
    }
    
    .d-tablet-none {
        display: none !important;
    }
}

.d-desktop-only {
    display: none;
}

@media (min-width: 1024px) {
    .d-desktop-only {
        display: block !important;
    }
    
    .d-desktop-none {
        display: none !important;
    }
}

/* 响应式字体大小 */
.fs-mobile {
    font-size: 0.9rem;
}

@media (min-width: 768px) {
    .fs-mobile {
        font-size: 1rem;
    }
}

@media (min-width: 1024px) {
    .fs-mobile {
        font-size: 1.1rem;
    }
}

/* 响应式间距 */
.m-responsive {
    margin: 1rem;
}

@media (min-width: 768px) {
    .m-responsive {
        margin: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .m-responsive {
        margin: 2rem;
    }
}

.p-responsive {
    padding: 1rem;
}

@media (min-width: 768px) {
    .p-responsive {
        padding: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .p-responsive {
        padding: 2rem;
    }
}

/* ======================== 修复 Bootstrap 响应式问题 ======================== */

/* 确保 Bootstrap 网格在移动端正确显示 */
@media (max-width: 767.98px) {
    .col-md-6,
    .col-lg-4,
    .col-lg-3,
    .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* 响应式表格 */
.table {
    width: 100%;
    max-width: 100%;
}

@media (max-width: 767.98px) {
    .table td,
    .table th {
        white-space: nowrap;
    }
}

/* 响应式按钮组 */
.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (max-width: 767.98px) {
    .btn-group .btn {
        flex: 1 1 auto;
        width: 100%;
    }
}

/* 响应式模态框 */
.modal-dialog {
    margin: 0.5rem;
}

@media (min-width: 576px) {
    .modal-dialog {
        max-width: 500px;
        margin: 1.75rem auto;
    }
}

/* 响应式下拉菜单 */
.dropdown-menu {
    max-width: 100%;
}

@media (max-width: 767.98px) {
    .dropdown-menu {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        border-radius: 1rem 1rem 0 0;
        max-height: 70vh;
        overflow-y: auto;
    }
}

/* ======================== 性能优化 ======================== */

/* 使用 GPU 加速动画 */
.stat-card,
.info-card,
.card {
    will-change: transform;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* 优化移动端滚动 */
body {
    -webkit-overflow-scrolling: touch;
}

/* 防止内容溢出 */
main {
    overflow-x: hidden;
    width: 100%;
}

.container {
    max-width: 100%;
}

/* ======================== 可访问性优化 ======================== */

/* 焦点可见性 */
*:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* 跳过链接 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #667eea;
    color: white;
    padding: 8px;
    z-index: 10000;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}
