/**
 * 响应式适配样式
 * 适配1080P (1920x1080) 和更小的屏幕
 * Author: System
 * Date: 2026-01-14
 */

/* ==================== 基础响应式设置 ==================== */

/* 确保页面宽度自适应 */
body {
    min-width: 320px; /* 最小宽度 */
    overflow-x: hidden; /* 防止横向滚动 */
}

/* 容器自适应 */
.container-fluid {
    max-width: 100%;
    padding-left: 15px;
    padding-right: 15px;
}

/* ==================== 1080P及以下屏幕适配 ==================== */

@media (max-width: 1920px) {
    /* 调整表格容器 */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        /* 修复闪烁问题：使用will-change优化 */
        will-change: auto !important;
    }
    
    /* 调整卡片间距 */
    .card {
        margin-bottom: 15px;
    }
    
    /* 调整按钮大小 */
    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
    }
    
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.8125rem;
    }
    
    /* 调整表单控件 */
    .form-control {
        font-size: 0.875rem;
    }
    
    /* 调整表格字体 */
    .table {
        font-size: 0.875rem;
    }
    
    .table td, .table th {
        padding: 0.5rem;
    }
}

/* 1680x1050 及以下 */
@media (max-width: 1680px) {
    /* 更紧凑的布局 */
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    /* 缩小卡片内边距 */
    .card-body {
        padding: 1rem;
    }
    
    /* 缩小表格 */
    .table {
        font-size: 0.8125rem;
    }
    
    .table td, .table th {
        padding: 0.4rem;
    }
    
    /* 调整按钮组 */
    .btn-group .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    /* 调整模态框 */
    .modal-lg {
        max-width: 90%;
    }
}

/* 1366x768 及以下 */
@media (max-width: 1366px) {
    /* 小屏幕笔记本 */
    body {
        font-size: 14px;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    
    /* 表格更紧凑 */
    .table {
        font-size: 0.75rem;
    }
    
    .table td, .table th {
        padding: 0.3rem;
        white-space: nowrap;
    }
    
    /* 按钮更小 */
    .btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .btn-sm {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }
    
    /* 表单控件 */
    .form-control {
        font-size: 0.8125rem;
        padding: 0.3rem 0.6rem;
    }
    
    /* 卡片更紧凑 */
    .card-body {
        padding: 0.75rem;
    }
    
    /* 缩小边距 */
    .mb-3 { margin-bottom: 0.75rem !important; }
    .mt-3 { margin-top: 0.75rem !important; }
    .p-3 { padding: 0.75rem !important; }
}

/* ==================== 修复表格横向滚动闪烁 ==================== */

.table-responsive {
    /* 移除transition避免闪烁 */
    transition: none !important;
    /* 硬件加速 */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    /* 强制显示横向滚动条 */
    overflow-x: auto !important;
    overflow-y: visible !important;
    /* 优化滚动 */
    -webkit-overflow-scrolling: touch;
    /* 防止重排 */
    contain: layout style paint;
}

/* 强制显示滚动条 - Chrome/Safari/Edge（内部方案）*/
.table-responsive::-webkit-scrollbar {
    height: 18px !important;
    width: 18px !important;
    display: block !important;
    opacity: 1 !important;
    -webkit-appearance: none !important;
    /* 关键：让滚动条始终显示 */
    background: transparent !important;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f8f9fa !important;
    border-radius: 10px !important;
    display: block !important;
    /* 增加内边距，让轨道更明显 */
    margin: 0 4px !important;
    border: 1px solid #dee2e6 !important;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #6c757d !important;
    border-radius: 10px !important;
    border: 3px solid #f8f9fa !important;
    display: block !important;
    min-width: 50px !important;
    cursor: grab !important;
    /* 关键：增加点击区域 */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #495057 !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2) !important;
}

.table-responsive::-webkit-scrollbar-thumb:active {
    background: #343a40 !important;
    cursor: grabbing !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
}

/* Firefox滚动条强制显示 */
.table-responsive {
    scrollbar-width: thin !important;
    scrollbar-color: #6c757d #f8f9fa !important;
}

/* 确保滚动条区域可交互 */
.table-responsive::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-thumb {
    pointer-events: auto !important;
}

/* 防止table-responsive在hover时触发重新渲染 */
.table-responsive:hover {
    will-change: auto !important;
}

/* 优化表格渲染性能 */
.table-responsive table {
    /* 固定布局，提升性能 */
    table-layout: auto;
    /* 防止闪烁 */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ==================== 侧边栏自动收缩功能（优化版）==================== */

/* 强制覆盖原有样式 - 侧边栏默认收缩状态 */
body #wrapper #sidebar-wrapper {
    min-width: 70px !important;
    max-width: 70px !important;
    width: 70px !important;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08) !important;
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    z-index: 1030 !important;
    height: 100vh !important;
}

/* 侧边栏hover或展开时 */
body #wrapper #sidebar-wrapper:hover,
body #wrapper #sidebar-wrapper.expanded {
    min-width: 260px !important;
    max-width: 260px !important;
    width: 260px !important;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15) !important;
}

/* 主内容区域自动调整 - 强制覆盖 */
body #wrapper #page-content-wrapper {
    margin-left: 70px !important;
    transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    width: calc(100% - 70px) !important;
    min-height: 100vh !important;
    flex: 1 !important;
}

/* 顶部导航栏适配 */
#page-content-wrapper .navbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 1020 !important;
    margin-left: 0 !important;
    width: 100% !important;
}

/* 当侧边栏展开时，主内容区域不需要调整（flex会自动处理） */
#wrapper {
    display: flex !important;
    min-height: 100vh !important;
}

/* Logo区域优化 */
#sidebar-wrapper .sidebar-heading {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    overflow: hidden !important;
    padding: 1rem !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
    background: linear-gradient(180deg, rgba(255,255,255,0.8), rgba(255,255,255,0.4));
    backdrop-filter: blur(10px);
}

#sidebar-wrapper:not(:hover):not(.expanded) .sidebar-heading {
    padding: 0.75rem 0.5rem !important;
}

#sidebar-wrapper:not(:hover):not(.expanded) .sidebar-heading img {
    max-width: 36px !important;
    max-height: 36px !important;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

#sidebar-wrapper:hover .sidebar-heading img,
#sidebar-wrapper.expanded .sidebar-heading img {
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15));
}

/* 侧边栏菜单项 */
#sidebar-wrapper .list-group-item {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    padding: 1rem 0.75rem !important;
    border-radius: 12px !important;
    margin: 0.25rem 0.5rem !important;
    position: relative !important;
}

/* 菜单项hover效果 */
#sidebar-wrapper .list-group-item:hover {
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.1), rgba(88, 86, 214, 0.08)) !important;
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.15);
}

#sidebar-wrapper .list-group-item.active {
    background: linear-gradient(135deg, #007AFF, #5856D6) !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

#sidebar-wrapper .list-group-item.active i {
    color: white !important;
}

/* 收缩状态：图标居中显示 */
#sidebar-wrapper:not(:hover):not(.expanded) .list-group-item {
    justify-content: center !important;
    padding: 1rem 0 !important;
    margin: 0.4rem 0.3rem !important;
    min-height: 56px !important;
}

#sidebar-wrapper:not(:hover):not(.expanded) .list-group-item i {
    margin-right: 0 !important;
    margin-left: 0 !important;
    font-size: 1.4rem !important;
    transition: all 0.3s ease !important;
}

/* 图标hover放大效果 */
#sidebar-wrapper:not(:hover):not(.expanded) .list-group-item:hover i {
    transform: scale(1.2);
    filter: drop-shadow(0 2px 4px rgba(0, 122, 255, 0.4));
}

/* 隐藏收缩状态下的文字节点 */
#sidebar-wrapper:not(:hover):not(.expanded) .list-group-item {
    font-size: 0 !important;
}

/* 展开状态恢复文字 */
#sidebar-wrapper:hover .list-group-item,
#sidebar-wrapper.expanded .list-group-item {
    font-size: 0.95rem !important;
    font-weight: 500 !important;
}

#sidebar-wrapper:hover .list-group-item i,
#sidebar-wrapper.expanded .list-group-item i {
    font-size: 1.1rem !important;
    margin-right: 0.75rem !important;
}

/* 子菜单项 */
#sidebar-wrapper .collapse .list-group-item {
    padding-left: 3.5rem !important;
    font-size: 0.875rem !important;
    background: rgba(0, 0, 0, 0.02) !important;
    margin-left: 1rem !important;
    margin-right: 1rem !important;
}

#sidebar-wrapper:not(:hover):not(.expanded) .collapse {
    display: none !important;
}

/* 徽章样式优化 */
#sidebar-wrapper .badge {
    transition: all 0.3s ease !important;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

#sidebar-wrapper:not(:hover):not(.expanded) .badge {
    display: none !important;
}

/* 展开时徽章位置调整 */
#sidebar-wrapper:hover .badge,
#sidebar-wrapper.expanded .badge {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

/* 收缩状态添加tooltip提示 */
#sidebar-wrapper:not(:hover):not(.expanded) .list-group-item::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    margin-left: 12px;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    border-radius: 8px;
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1040;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#sidebar-wrapper:not(:hover):not(.expanded) .list-group-item:hover::after {
    opacity: 1;
}

/* 侧边栏滚动条美化 */
body #wrapper #sidebar-wrapper::-webkit-scrollbar {
    width: 6px !important;
}

body #wrapper #sidebar-wrapper::-webkit-scrollbar-track {
    background: transparent !important;
}

body #wrapper #sidebar-wrapper::-webkit-scrollbar-thumb {
    background: rgba(0, 122, 255, 0.3) !important;
    border-radius: 3px !important;
}

body #wrapper #sidebar-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 122, 255, 0.5) !important;
}

/* ==================== 侧边栏响应式 ==================== */

@media (max-width: 1366px) {
    /* 小屏幕下进一步优化 */
    #sidebar-wrapper {
        width: 50px !important;
    }
    
    #sidebar-wrapper:hover {
        width: 220px !important;
    }
    
    #page-content-wrapper {
        margin-left: 50px !important;
        width: calc(100% - 50px) !important;
    }
}

/* ==================== 导航栏响应式 ==================== */

@media (max-width: 1366px) {
    .navbar-nav .nav-item {
        padding: 0 0.5rem;
    }
    
    .navbar-nav .nav-link {
        font-size: 0.875rem;
        padding: 0.4rem 0.5rem;
    }
}

/* ==================== 表单行响应式 ==================== */

@media (max-width: 1366px) {
    /* 表单列在小屏幕上换行 */
    .row > .col-md-6,
    .row > .col-md-4,
    .row > .col-md-3 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ==================== 模态框响应式 ==================== */

@media (max-width: 1366px) {
    .modal-dialog {
        max-width: 95%;
        margin: 0.5rem auto;
    }
    
    .modal-lg {
        max-width: 95%;
    }
    
    .modal-xl {
        max-width: 98%;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-header {
        padding: 0.75rem 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem;
    }
}

/* ==================== 数据表格优化 ==================== */

/* 防止表格单元格内容换行 */
.table td, .table th {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* 特定列允许换行 */
.table td.allow-wrap,
.table th.allow-wrap {
    white-space: normal;
    max-width: none;
}

/* 操作列（最后一列）不截断 - 修复按钮显示问题 */
.table td:last-child,
.table th:last-child {
    width: auto !important;
    min-width: 150px !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
}

/* 确保按钮在操作列中正常显示 */
.table td:last-child .btn,
.table td:last-child .dropdown {
    white-space: nowrap !important;
    overflow: visible !important;
}

/* ==================== Badge响应式 ==================== */

@media (max-width: 1366px) {
    .badge {
        font-size: 0.7rem;
        padding: 0.2em 0.4em;
    }
}

/* ==================== 统计卡片响应式 ==================== */

@media (max-width: 1366px) {
    .stats-card {
        padding: 0.75rem !important;
    }
    
    .stats-card .stat-value {
        font-size: 1.25rem !important;
    }
    
    .stats-card .stat-label {
        font-size: 0.75rem !important;
    }
}

/* ==================== 搜索框响应式 ==================== */

@media (max-width: 1366px) {
    .search-box {
        width: 100%;
        max-width: 300px;
    }
    
    input[type="search"],
    input[type="text"].form-control {
        font-size: 0.8125rem;
    }
}

/* ==================== 分页响应式 ==================== */

@media (max-width: 1366px) {
    .pagination {
        font-size: 0.8125rem;
    }
    
    .pagination .page-link {
        padding: 0.3rem 0.6rem;
    }
}

/* ==================== 修复常见的超出屏幕问题 ==================== */

/* 防止长文本超出 */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 按钮组防止超出 */
.btn-group {
    flex-wrap: wrap;
}

/* 表单组防止超出 */
.form-inline {
    flex-wrap: wrap;
}

/* 工具栏防止超出 */
.toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ==================== 按钮布局优化 ==================== */

/* 响应式按钮组 */
.btn-group-responsive {
    display: inline-flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* 按钮基础样式 */
.btn-action {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

/* 1080P以下优化按钮 */
@media (max-width: 1920px) {
    .btn-action {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
}

/* 1680P以下进一步压缩 */
@media (max-width: 1680px) {
    .btn-action {
        padding: 0.35rem 0.7rem;
        font-size: 0.8rem;
    }
    
    .btn-action i {
        font-size: 0.9rem;
    }
}

/* 1366P以下隐藏按钮文字，只显示图标 */
@media (max-width: 1366px) {
    .btn-action {
        padding: 0.4rem;
        min-width: 36px;
        justify-content: center;
    }
    
    .btn-action .btn-text {
        display: none;
    }
    
    .btn-action i {
        margin-right: 0 !important;
        font-size: 1rem;
    }
}

/* ==================== Select2响应式 ==================== */

@media (max-width: 1366px) {
    .select2-container {
        font-size: 0.8125rem;
    }
    
    .select2-container--default .select2-selection--single {
        height: 32px;
        padding: 4px 8px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 22px;
    }
}

/* ==================== 图标响应式 ==================== */

@media (max-width: 1366px) {
    .fas, .far, .fab {
        font-size: 0.875rem;
    }
    
    .fa-lg {
        font-size: 1rem;
    }
    
    .fa-2x {
        font-size: 1.5rem;
    }
}

/* ==================== 打印样式 ==================== */

@media print {
    /* 打印时移除不必要的元素 */
    .navbar,
    .sidebar,
    .btn,
    .pagination {
        display: none !important;
    }
    
    /* 打印时展开所有内容 */
    .table-responsive {
        overflow: visible !important;
    }
    
    /* 调整页面大小 */
    @page {
        size: A4 landscape;
        margin: 1cm;
    }
}

/* ==================== 性能优化 ==================== */

/* 使用GPU加速 */
.table-responsive,
.modal,
.dropdown-menu {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* 优化动画性能 */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==================== 滚动条样式优化 ==================== */

/* 通用滚动条样式 - 已在table-responsive中定义 */

/* ==================== 修复特定浏览器问题 ==================== */

/* 修复IE11的flexbox问题 */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .row {
        display: block;
    }
}

/* 修复Safari的滚动问题 */
@supports (-webkit-touch-callout: none) {
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
}
