/* Global Styles - 布局样式移动到layout.css */
html {
    height: 100%;
}

html, body {
    margin: 0;
    /* padding-top for fixed header is owned by layout.css */
}

@media (min-width: 992px) {
    html, body {
        overflow: hidden;
        height: 100vh;
        max-height: 100vh;
    }
}

@media (max-width: 991.98px) {
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
        max-height: none;
        -webkit-overflow-scrolling: touch;
    }
}

/* 移动端触摸滚动优化 */
@media (max-width: 991.98px) {
    html, body {
        touch-action: pan-x pan-y; /* 允许水平和垂直滚动，让子元素决定具体行为 */
        /* body 保持默认滚动行为，子元素（.table-responsive）会使用 contain 来隔离自己的滚动 */
    }
}

/* 强制所有滚动条始终显示 - 全局设置 */
* {
    scrollbar-width: thin !important; /* Firefox: 始终显示滚动条 */
    scrollbar-color: #888 #f1f1f1 !important; /* Firefox: 滚动条颜色 */
    -ms-overflow-style: scrollbar !important; /* IE/Edge: 始终显示滚动条 */
}

/* WebKit浏览器（Chrome, Safari, Edge）强制滚动条始终显示（更小尺寸：10px） */
/* macOS系统会隐藏滚动条，使用更强的规则来覆盖 */
*::-webkit-scrollbar {
    -webkit-appearance: none !important;
    width: 10px !important; /* 滚动条宽度 */
    height: 10px !important;
    display: block !important; /* 强制显示滚动条 */
    visibility: visible !important;
    opacity: 1 !important;
}

*::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 10px;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.1) !important; /* 添加阴影使其更明显 */
}

*::-webkit-scrollbar-thumb {
    background: #888 !important;
    border-radius: 10px;
    border: 2px solid #f1f1f1;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3) !important; /* 添加阴影使其更明显 */
}

*::-webkit-scrollbar-thumb:hover {
    background: #555 !important;
}

/* 移动端滚动条优化 - 简化样式以提升性能 */
@media (max-width: 991.98px) {
    /* 移动端简化滚动条样式，移除阴影以提升性能 */
    *::-webkit-scrollbar {
        width: 6px !important;
        height: 6px !important;
    }
    
    *::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.05) !important;
        border-radius: 3px !important;
        /* 移动端移除阴影以提升滚动性能 */
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
    }
    
    *::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2) !important;
        border-radius: 3px !important;
        border: none !important;
        /* 移动端移除阴影以提升滚动性能 */
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
    }
    
    *::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.3) !important;
    }
}

/* 对于垂直滚动条 */
*::-webkit-scrollbar:vertical {
    width: 10px !important;
}

/* 对于水平滚动条 */
*::-webkit-scrollbar:horizontal {
    height: 10px !important;
}

/* 强制所有overflow元素使用scroll而不是auto */
/* 注意：这个规则会被内联样式覆盖，需要通过JavaScript动态处理 */

/* 特殊处理：强制table-responsive始终显示滚动条 */
.table-responsive[style*="overflow"] {
    overflow-x: scroll !important;
    overflow-y: scroll !important;
}

/* Make the offcanvas menu icon yellow */
.offcanvas-body a i {
    color: #E8FE04 !important;
}

/* Make the menu list items' text black */
.offcanvas-body a {
    color: black !important;
}

/* Underline the links on hover */
.offcanvas-body a:hover {
    text-decoration: underline !important;
}


/* Main Content Layout - moved to layout.css */

/* Left Section - Legacy styles (kept for compatibility) */
.left-section {
    width: 25%;
    background: #f4f4f4;
    padding: 15px;
    flex-direction: column;
}
/* User Info (Upper part) */
.user-info {
    display: flex; 
    align-items: center; 
    text-align: center;
}

/* Sidebar (Lower part) */
.sidebar {
    width: 100%;
}

.sidebar h4 {
    text-align: center;
}

.sidebar ul {
    list-style: none;
    padding: 0;
}

.sidebar ul li {
    padding: 10px;
}

.sidebar ul li a {
    text-decoration: none;
    color: black;
    align-items: center;
}

.sidebar ul li a i {
    margin-right: 10px;
}

/* Submenu */
.nav-item {
    margin-bottom: 3px;
}

.nav-link {
    padding: 5px 10px !important;
    color: black !important;
    text-decoration: none !important;
    transition: all 0.3s;
}

.nav-link:hover {
    background-color: rgba(0,0,0,0.05);
}
.nav-link[aria-expanded="true"] .fa-chevron-down {
    transform: rotate(180deg);
}

.fa-chevron-down {
    transition: transform 0.3s ease;
}


.collapse:not(.show) {
    display: none;
}

.submenu li {
    padding: 8px 0 !important;
}
.submenu li a:hover {
    background-color: rgba(0,0,0,0.05);
}
.submenu a {
    padding-left: 25px !important;
    display: block;
}

/* Table Styles */
.table {
    border-collapse: collapse !important;
    width: 100%;
    margin-bottom: 1rem;
    background-color: transparent;
}

.table th,
.table td {
    border: 1px solid #dee2e6 !important;
    padding: 0.4rem 0.6rem !important;
    font-size: 15px !important;
    line-height: 1.2 !important;
    vertical-align: middle !important;
}

.table thead th {
    background-color: #f8f9fa !important;
    border-bottom: 2px solid #dee2e6 !important;
    font-weight: 700 !important;
    font-size: 15px !important;
}

.table tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.02);
}

.table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

/* 通用表格容器滚动条样式 - 2025年行业标准方案 */
/* 适用于所有后台数据管理系统表格 */
.table-responsive {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-gutter: stable both-edges !important;
    width: 100%;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    -ms-overflow-style: scrollbar;
    /* 移动端滚动性能优化 - 强制允许水平和垂直滚动，覆盖父元素限制 */
    touch-action: pan-x pan-y !important; /* 允许水平和垂直滚动，!important 确保覆盖父元素限制 */
    /* 桌面端保持默认滚动行为，不设置 overscroll-behavior */
    /* 启用硬件加速 */
    transform: translateZ(0);
    will-change: scroll-position;
    backface-visibility: hidden;
    /* 桌面端使用smooth scrolling，移动端使用auto（通过媒体查询覆盖） */
    scroll-behavior: smooth;
}

/* 移动端禁用smooth scrolling以提升滚动性能，并防止滚动链冲突 */
@media (max-width: 768px) {
    .table-responsive {
        scroll-behavior: auto !important;
        /* 移动端允许垂直滚动，让容器自己处理滚动，避免冒泡到 body */
        /* 如果内容需要垂直滚动，允许容器内部滚动 */
        overflow-y: auto !important; /* 覆盖全局的 hidden，允许垂直滚动 */
        /* 启用原生触摸滚动，提升流畅度 */
        -webkit-overflow-scrolling: touch !important;
        /* 移除 overscroll-behavior，因为它可能阻止正常的触摸滚动 */
        /* 使用 touch-action 来控制滚动行为 */
        touch-action: pan-x pan-y !important;
        /* 确保容器可以独立滚动 */
        position: relative;
        /* 移除可能干扰滚动的属性 */
        transform: none !important; /* 移除 transform，避免创建新的层叠上下文 */
        will-change: auto !important; /* 移除 will-change */
        backface-visibility: visible !important; /* 移除 backface-visibility */
        /* 不设置固定的 max-height，让内容自然决定是否需要滚动 */
    }
}

/* WebKit 内核（Chrome、Edge、Safari）的横向滚动条样式 */
.table-responsive::-webkit-scrollbar {
    height: 12px;
}

.table-responsive::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.08);
    border-radius: 6px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.5);
}

/* 隐藏垂直滚动条 */
.table-responsive::-webkit-scrollbar:vertical {
    width: 0;
    display: none;
}

/* 确保表格内容不换行，保持横向滚动 */
.table-responsive table {
    white-space: nowrap;
    width: 100%;
    table-layout: auto;
}

/* 紧凑型表格样式 */
.table-sm th,
.table-sm td {
    padding: 0.3rem;
}

/* 表格边框样式 */
.table-bordered {
    border: 1px solid #dee2e6;
}

/* 表格头部暗色主题 */
.table-dark thead th {
    background-color: #343a40;
    color: #fff;
    border-color: #454d55 !important;
}

/* 确保表格内的按钮组样式正确 */
.table .btn-group {
    display: flex;
    gap: 0.25rem;
}

/* 表格内的操作按钮样式 */
.table .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.2rem;
}

/* 表格内的图标样式 */
.table .fas,
.table .far,
.table .fa {
    font-size: 0.875rem;
}

/* 表格内 .form-check 包装的复选框/单选框（与 label 对齐） */
.table .form-check .form-check-input {
    margin-top: 0.3rem;
    margin-left: -1.25rem;
}

/* 直接放在 th/td 内的复选框（无 .form-check 包装） */
.table th > .form-check-input,
.table td > .form-check-input {
    margin: 0;
    vertical-align: middle;
    float: none;
}

/* 表格内的标签样式 */
.table .badge {
    font-size: 85%;
}

/* 确保actions列有足够宽度 */
.table th:last-child,
.table td:last-child,
.table .actions-column,
.table .action-column {
    min-width: 120px !important;
    white-space: nowrap !important;
}

/* 表格内按钮组样式 */
.table .btn-group {
    display: flex !important;
    gap: 0.1rem !important;
    flex-wrap: nowrap !important;
}

.table .btn-group .btn {
    margin: 0 !important;
}

/* 表格脚注样式 */
.table tfoot {
    border-top: 2px solid #dee2e6;
    background-color: #f8f9fa;
}

/* 表格caption样式 */
.table caption {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    color: #6c757d;
    text-align: left;
    caption-side: bottom;
}

/* 确保表格在小屏幕设备上也能正常显示 */
@media (max-width: 768px) {
    .table-responsive-sm {
        display: block;
        width: 100%;
        overflow-x: scroll !important; /* 使用scroll而不是auto，确保滚动条始终显示 */
        -webkit-overflow-scrolling: touch;
        scrollbar-width: auto; /* Firefox: 始终显示滚动条 */
        -ms-overflow-style: scrollbar; /* IE/Edge: 始终显示滚动条 */
    }
}

/* 统一搜索/筛选栏布局 */
.filter-row {
    --bs-gutter-x: 0.75rem;
    --bs-gutter-y: 0.5rem;
}

@media (min-width: 992px) {
    .filter-row > [class*="col"] {
        flex: 0 0 auto;
        width: auto !important;
    }

    .filter-row > .flex-grow-1 {
        flex: 1 1 280px !important;
        min-width: 260px;
    }
}

/* 日期输入字段统一样式 - 强制使用美式日期格式显示 */
input[type="date"].date-input-unified,
input[type="date"] {
    /* 强制使用美式日期格式（MM/DD/YYYY） */
    /* 注意：HTML5 date input的显示格式由浏览器和系统区域设置决定 */
    /* 设置lang="en-US"属性可以帮助统一显示格式 */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    direction: ltr;
    text-align: left;
}

/* 确保日期输入字段在所有浏览器中显示一致 */
input[type="date"].date-input-unified::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 1;
}

input[type="date"].date-input-unified::-webkit-inner-spin-button,
input[type="date"].date-input-unified::-webkit-clear-button {
    display: none;
}

/* Firefox日期输入样式 */
input[type="date"].date-input-unified::-moz-calendar-picker-indicator {
    cursor: pointer;
}

/* ===== Modal Mobile/Tablet Fit ===== */
@media (max-width: 992px) {
    .modal-dialog {
        margin: 0.75rem auto !important;
        max-height: calc(100vh - 1.5rem) !important;
        max-height: calc(100dvh - 1.5rem) !important;
        width: calc(100% - 1.5rem) !important;
        height: auto !important;
    }

    .modal-content {
        max-height: 80vh !important;
        max-height: 80dvh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .modal-body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        flex: 1 1 auto !important;
        min-height: 0 !important;
    }

    /* Override Bootstrap centered/scrollable dialog height so it can shrink */
    .modal-dialog-centered {
        align-items: flex-start !important;
        min-height: 0 !important;
    }

    .modal-dialog-scrollable {
        height: auto !important;
    }
}
