:root {
    --primary-color: #4361ee;
    --secondary-color: #3f37c9;
    --success-color: #4cc9f0;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --border-radius: 12px;
    --box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    margin: 0;
    background-color: #f8f9fa;
    color: var(--dark-color);
    line-height: 1.6;
    max-width: 100vw;
    overflow-x: hidden;
    /* 让页面本身不滚动，由内部内容区域接管滚动 */
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none; /* 阻止 iOS 边界回弹影响固定底部栏 */
}

.container {
    margin: 15px auto;
    max-width: 95%;
    background-color: #fff;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 18px;
}

/* 让首页容器在视口内自适应，内部滚动，不越界 */
.container.my-3 {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0; /* 允许子元素正确滚动 */
    /* 留出底部固定按钮的空间，避免被遮挡 */
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
    overflow: auto; /* 兜底：无专属滚动区时由容器自身滚动 */
}

/* 顶部工具栏 */
.top-toolbar{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    z-index: 1600;
}

.toolbar-left,
.toolbar-right {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1;
}

.toolbar-left {
    left: 16px;
}

.toolbar-right {
    right: 16px;
}

.page-title{
    color: white;
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.5px;
    position: relative;
    z-index: 2;
}

.toolbar-btn{
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toolbar-btn:hover{
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.toolbar-btn:active{
    transform: scale(0.95);
}

/* 同步状态指示器 */
.sync-status {
    position: relative;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 8px;
}

.sync-icon {
    color: white;
    font-size: 1.3rem;
    transition: transform 0.3s ease;
}

/* 上传中 - 旋转动画 */
.sync-status.syncing .sync-icon {
    animation: rotate 1.5s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* 状态指示点 */
.sync-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s ease;
}

/* 正常状态 - 绿色 */
.sync-status.success .sync-dot {
    background-color: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

/* 上传中 - 黄色 */
.sync-status.syncing .sync-dot {
    background-color: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
    animation: pulse 1.5s ease-in-out infinite;
}

/* 错误/离线 - 红色 */
.sync-status.error .sync-dot {
    background-color: #ef4444;
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* 内容区域 */
.content-area{
    margin-top: 70px;
    margin-bottom: 10px;
    padding: 0 16px;
    padding-bottom: 100px; /* 为底部按钮留出空间 */
    transition: margin-bottom 0.3s ease;
}

/* 底部按钮栏 */
.bottom-buttons {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    padding: 10px 12px 14px;
    background: linear-gradient(to top, #ffffff 0%, #f8f9fa 100%);
    box-shadow: 0 -2px 16px rgba(0,0,0,0.1);
    z-index: 1000;
    border-top: 1px solid #e5e7eb;
    transition: bottom 0.3s ease;
}

/* 当全键盘显示时，底部按钮栏移到全键盘上方 */
body.full-keyboard-visible .bottom-buttons {
    bottom: 280px;
}

@media (max-width: 768px){
    body.full-keyboard-visible .bottom-buttons {
        bottom: 260px;
    }
}

@media (max-width: 576px){
    body.full-keyboard-visible .bottom-buttons {
        bottom: 240px;
    }
}

.bottom-btn {
    flex: 1;
    margin: 0 6px;
    border-radius: 12px;
    padding: 12px 8px;
    font-weight: 600;
    transition: all 0.25s ease;
    border: 1px solid #e5e7eb;
    background: white;
    color: #374151;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.bottom-btn i {
    font-size: 1.2rem;
}

.bottom-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
}

.bottom-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.bottom-btn.btn-primary{
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
}

.bottom-btn.btn-success{
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    border: none;
    color: white;
}

h1 {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 20px;
    text-align: center;
}

/* DataTables 外层包装滚动区域，作为主要的垂直滚动容器 */
#orderTable_wrapper {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto; /* 垂直/水平在此滚动 */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch; /* 提升移动端滚动手感 */
}

/* 固定 DataTables 表头不滚动 */
.dataTables_scrollHead {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    background-color: #fff;
}

.dataTables_scrollBody {
    overflow-y: auto !important;
}

/* 表格样式 */
#orderTable {
    width: 100% !important;
    table-layout: fixed; /* 启用固定布局 */
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    box-shadow: var(--box-shadow);
}

#orderTable thead th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    padding: 8px 10px;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* 列宽定义 - 适配 4 列布局 */
#orderTable th:nth-child(1), #orderTable td:nth-child(1) { width: 25%; } /* Code */
#orderTable th:nth-child(2), #orderTable td:nth-child(2) { width: 40%; } /* Name */
#orderTable th:nth-child(3), #orderTable td:nth-child(3) { width: 20%; } /* Option */
#orderTable th:nth-child(4), #orderTable td:nth-child(4) { width: 15%; } /* Qty */

#orderTable td {
    padding: 8px 10px;
    border-bottom: 1px solid #e9ecef;
    transition: all 0.2s;
    font-size: 0.85rem;
}

/* 优化表格内容显示 */
#orderTable td:nth-child(2) { /* Name */
    font-size: 0.8rem;
    line-height: 1.3;
}

#orderTable td:nth-child(3) { /* Option */
    font-size: 0.8rem;
    color: #666;
}

#orderTable th, #orderTable td {
    white-space: normal;
    word-break: break-word;
}

#orderTable tr:last-child td {
    border-bottom: none;
}

#orderTable tr:nth-child(even) {
    background-color: rgba(0,0,0,0.02);
}

#orderTable td[contenteditable="true"]:hover {
    background-color: rgba(67, 97, 238, 0.05);
}

#orderTable td[contenteditable="true"]:focus {
    background-color: rgba(67, 97, 238, 0.1);
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

/* Toast消息 */
.toast-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--success-color);
    color: #fff;
    padding: 12px 25px;
    border-radius: 50px;
    z-index: 1100;
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 25px rgba(76, 201, 240, 0.3);
}

/* 扫描模态框样式 */
.modal {
    z-index: 2000 !important; /* 确保高于顶部工具栏(1600) */
}

.modal-backdrop {
    z-index: 1990 !important;
}

.modal-fullscreen .modal-content {
    height: calc(100vh - 200px);
    border: none;
    border-radius: 0;
    background-color: #000;
    position: relative;
    overflow: hidden;
}

.modal-header {
    background-color: rgb(60, 60, 60);
    border-bottom: none;
    padding: 15px;
    height: 60px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1050;
}

.modal-header .modal-title {
    color: white;
    font-weight: 600;
}

.btn-close {
    filter: invert(1);
    opacity: 0.8;
}

.modal-body {
    padding: 0 !important;
    margin-top: 60px;
    height: calc(100% - 60px);
    overflow: hidden;
    background-color: #ffffff;
}

#scanner-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 260px - 60px);
    background-color: #000;
    overflow: hidden;
}

.viewport {
    width: 100%;
    height: 100%;
    position: relative;
}

.viewport > video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 数量调整界面 */
.quantity-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.98);
    padding: 25px;
    border-radius: 20px;
    width: 85%;
    max-width: 350px;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
    z-index: 2000;
}

.modal-footer{
    background-color: rgba(255, 255, 255, 0.9);
}

.scanned-info {
    background-color: rgba(67, 97, 238, 0.1);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
}

.scanned-label {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 8px;
    text-align: left;
}

.scanned-code {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--dark-color);
    word-break: break-all;
    text-align: left;
}

.quantity-label {
    font-size: 1rem;
    color: #495057;
    margin-bottom: 15px;
    font-weight: 500;
}

.quantity-control {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
}

.qty-display {
    font-size: 2.5rem;
    font-weight: 700;
    width: 80px;
    text-align: center;
    color: var(--primary-color);
}

#increaseQty, #decreaseQty {
    width: 55px;
    height: 55px;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background-color: #f1f3f5;
    color: var(--dark-color);
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#increaseQty:active, #decreaseQty:active {
    transform: scale(0.92);
    background-color: #e9ecef;
}

#confirmQty {
    padding: 14px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 12px;
    margin-top: 25px;
    background-color: var(--primary-color);
    border: none;
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
    transition: all 0.3s;
}

#confirmQty:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(67, 97, 238, 0.3);
}

/* 加载指示器 */
.loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.loading-indicator .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* 扫描区域样式 */
.qr-shaded-region {
    border: 3px solid rgba(255,255,255,0.9) !important;
    border-radius: 15px !important;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.7) !important;
}

.qr-shaded-region.success {
    border-color: #4cc9f0 !important;
}

.d-none {
    display: none !important;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .container {
        padding: 15px;
        margin: 10px auto;
    }
    
    h1 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    #orderTable thead th {
        padding: 6px 8px;
        font-size: 0.7rem;
    }
    
    #orderTable td {
        padding: 6px 8px;
        font-size: 0.8rem;
    }
    
    .bottom-buttons {
        padding: 12px 10px;
    }
    
    .bottom-buttons button {
        font-size: 0.9rem;
    }
    
    .quantity-modal {
        width: 90%;
        padding: 20px;
    }
}

/* iPhone X 及以上设备优化 */
@media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-min-device-pixel-ratio: 3) {
    .bottom-buttons {
        padding-bottom: 25px; /* 适应底部安全区域 */
    }
}

/* Safari特定优化 */
@supports (-webkit-touch-callout: none) {
    .modal-fullscreen .modal-content {
        height: 100%;
        min-height: 100vh;
    }
    
    #scanner-container {
        height: calc(100vh - 56px);
    }
}

/* 为原生扫描器添加样式 */
#interactive video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 添加扫描区域指示 */
.scan-region-highlight {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 250px;
    height: 100px;
    transform: translate(-50%, -50%);
    border: 3px solid rgba(255,255,255,0.9);
    border-radius: 15px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.7);
    z-index: 10;
}

.scan-region-highlight.success {
    border-color: #4cc9f0;
    transition: border-color 0.3s ease;
}

/* iOS 特定优化 */
@supports (-webkit-touch-callout: none) {
    #interactive video {
        object-position: center;
    }
    
    /* 增加 iOS 上的对比度 */
    .modal-content {
        background-color: #000 !important;
    }
    
    /* 优化 iOS 上的扫描区域 */
    .scan-region-highlight {
        box-shadow: 0 0 0 9999px rgba(0,0,0,0.8);
    }
}

/* 扫描框样式 */
.scanner-box {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 250px;
    height: 100px;
    transform: translate(-50%, -50%);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    z-index: 10;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* 扫描线动画 */
.scan-line {
    position: absolute;
    width: 100%;
    height: 2px;
    background: linear-gradient(to right, 
        rgba(76, 201, 240, 0), 
        rgba(76, 201, 240, 0.8) 50%, 
        rgba(76, 201, 240, 0));
    top: 0;
    box-shadow: 0 0 8px 1px rgba(76, 201, 240, 0.5);
    animation: scanAnimation 2s ease-in-out infinite;
}

@keyframes scanAnimation {
    0% {
        top: 5%;
    }
    50% {
        top: 95%;
    }
    100% {
        top: 5%;
    }
}

/* 四个角样式 */
.corner {
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: #4cc9f0;
    border-style: solid;
    border-width: 0;
}

.corner.top-left {
    top: 0;
    left: 0;
    border-top-width: 3px;
    border-left-width: 3px;
    border-top-left-radius: 8px;
}

.corner.top-right {
    top: 0;
    right: 0;
    border-top-width: 3px;
    border-right-width: 3px;
    border-top-right-radius: 8px;
}

.corner.bottom-left {
    bottom: 0;
    left: 0;
    border-bottom-width: 3px;
    border-left-width: 3px;
    border-bottom-left-radius: 8px;
}

.corner.bottom-right {
    bottom: 0;
    right: 0;
    border-bottom-width: 3px;
    border-right-width: 3px;
    border-bottom-right-radius: 8px;
}

/* 扫描成功效果 */
.scanner-box.success {
    border-color: #4cc9f0;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6), 
                inset 0 0 20px rgba(76, 201, 240, 0.5);
}

/* 在iOS设备上的特殊优化 */
@supports (-webkit-touch-callout: none) {
    .scanner-box {
        box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
    }
    
    .scan-line {
        background: linear-gradient(to right, 
            rgba(76, 201, 240, 0), 
            rgba(76, 201, 240, 1) 50%, 
            rgba(76, 201, 240, 0));
        box-shadow: 0 0 12px 2px rgba(76, 201, 240, 0.7);
    }
}

/* 横屏模式优化 */
@media (orientation: landscape) {
    .scanner-box {
        width: 280px;
        height: 100px;
    }
}

/* 小屏幕设备优化 */
@media (max-width: 375px) {
    .scanner-box {
        width: 220px;
        height: 90px;
    }
    
    .corner {
        width: 15px;
        height: 15px;
    }
}

#ocrScannerBox {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 900;
    width: 250px;
    height: 100px;
    border: 3px solid rgba(255,255,255,0.9);
    border-radius: 15px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.7);
    pointer-events: none;
}

#ocrResult {
    position: absolute;
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    background-color: rgba(0,0,0,0.6);
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    text-align: center;
    z-index: 1201;
    max-height: 100px;
    overflow-y: auto;
    font-size: 1rem;
    pointer-events: none;
    line-height: 1.4;
}

.mb-3{
    color: black;
    background-color: #f8f9fa;
}

/* === 解决统计面板在移动端过宽的样式 === */
#tableSection,
.dataTables_wrapper {
    /* 允许横向滚动，保证背景始终覆盖表格 */
    overflow-x: auto;
}

/* 统计面板表格的通用最小宽度，防止列被过度压缩 */
#inventoryTable {
    width: 100%;
    table-layout: fixed;
    min-width: 600px; /* 若列很多可自行横向滚动 */
}

#inventoryTable th,
#inventoryTable td {
    white-space: normal;
    word-break: break-word;
    padding: 14px 10px;
}

/* 表头更小字体并减小内边距 */
#inventoryTable thead th {
    font-size: 0.9rem;
    padding: 10px 8px;
    white-space: nowrap;
}

/* 移动端再缩小 */
@media (max-width: 768px) {
    #inventoryTable thead th {
        font-size: 0.75rem;
        padding: 6px 6px;
    }
    #inventoryTable {
        min-width: 480px;
    }
}

/* --- 滑动提示 --- */
.scroll-hint{
    position:absolute;
    bottom:6px;
    left:50%;
    transform:translateX(-50%);
    background:rgba(0,0,0,0.6);
    color:#fff;
    font-size:0.75rem;
    padding:4px 10px;
    border-radius:12px;
    pointer-events:none;
    white-space:nowrap;
    z-index:2000;
    animation:bounceX 1s ease-in-out infinite;
}

@keyframes bounceX{
    0%,100%{transform:translate(-50%,0);}
    50%{transform:translate(-46%,0);}
}

/* orderTable 表头字体与间距调整 */
#orderTable thead th {
    font-size: 0.9rem;
    padding: 10px 8px;
    white-space: nowrap;
}

@media (max-width: 768px) {
    #orderTable thead th {
        font-size: 0.75rem;
        padding: 6px 6px;
    }
}

.btn-dark{
    background-color:#4a4a4a !important;
    border:none !important;
}

/* mode2 盘点表格字体更小 */
#inventoryTable thead th{
    font-size:0.8rem;
    padding:6px 6px;
}
#inventoryTable td{
    font-size:0.85rem;
    padding:6px 6px;
}
/* 日期列更小 */
.date-col{
    font-size:0.75rem !important;
    white-space:nowrap;
}
/* Count列窄 */
.count-col{
    width:70px !important;
}
/* DataTables分页缩小 */
.dataTables_wrapper .dataTables_paginate .paginate_button{
    padding:2px 6px !important;
    font-size:0.75rem !important;
    margin:0 2px !important;
}
.dataTables_wrapper .dataTables_info{
    font-size:0.75rem;
}

.count-col, .date-col, #inventoryTable td.text-center{
    text-align:center !important;
}

#inventoryTable thead th{
    line-height:1.2;
}

/* 手动输入日期按钮 */
#manualDateBtn{
    font-size:0.8rem;
    padding:4px 10px;
    margin: 10px;
}
@media (max-width: 768px){
    #manualDateBtn{font-size:0.75rem; padding:3px 8px;}
}

/* OCR 顶部提示文字向上贴近顶部 */
#ocrOverlayText{
    margin-top:0 !important;
    top:0.6rem !important;
    background: rgba(0,0,0,0.6);
    padding:4px 10px;
    border-radius:12px;
    color:#fff;
    z-index:1201;
}

/* 搜索框清除按钮 hover 效果 */
#codeSearchClear:hover{
    color:#dc3545;
}

/* 夜间模式文字样式已移除 */

/* 扫描中手电筒按钮 */
#flashToggleDuringScan.btn-success{background-color:#28a745 !important;}
#flashToggleDuringScan.btn-danger{background-color:#dc3545 !important;}

/* OCR 手电筒按钮 */
#flashToggleInOcr.btn-success{background-color:#28a745 !important;}
#flashToggleInOcr.btn-danger{background-color:#dc3545 !important;}

/* 表格容器 - 可滑动 */
.table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 220px);
    margin-bottom: 20px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: max-height 0.3s ease;
}

/* 添加按钮容器 */
.add-button-wrapper {
    text-align: center;
    margin: 20px 0 30px 0;
    transition: margin 0.3s ease;
}

.add-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 14px 40px;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    min-width: 160px;
}

.add-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.add-btn:active {
    transform: translateY(0);
}

.add-btn i {
    margin-right: 8px;
}

/* 虚拟软键盘 Overlay */

/* 虚拟软键盘 Overlay */
.virtual-keyboard{
    position:fixed;
    bottom:96px; /* 位于底部按钮之上 */
    right:20px;
    width: 240px; /* 尽可能小的尺寸 */
    background:#ffffff;
    border:1px solid #e5e7eb;
    border-radius:12px;
    box-shadow:0 12px 28px rgba(0,0,0,0.18);
    z-index:1600;
    user-select:none;
}
/* 头部用于拖动与关闭 */
.virtual-keyboard .vk-header{
    display:flex;
    align-items:center;
    justify-content:space-between;
    height:28px;
    padding:0 8px;
    background:#f3f4f6;
    border-bottom:1px solid #e5e7eb;
    border-top-left-radius:12px;
    border-top-right-radius:12px;
    cursor:move; /* 用于提示可拖动 */
    touch-action: none; /* 防止触摸滚动，允许拖动 */
}
.virtual-keyboard .vk-grip{
    position:absolute;
    top:6px;
    left:50%;
    transform:translateX(-50%);
    width:36px;
    height:4px;
    background:#cbd5e1;
    border-radius:2px;
    pointer-events:none;
}
.virtual-keyboard .vk-title{
    font-size:12px;
    color:#6b7280;
}
.virtual-keyboard .vk-close{
    border:none;
    background:transparent;
    color:#6b7280;
    font-size:16px;
    line-height:1;
    cursor:pointer;
}
.virtual-keyboard .vk-body{
    padding:8px;
}
.virtual-keyboard .vk-row{
    display:grid;
    grid-template-columns: repeat(3, 1fr);
    gap:6px;
    margin-bottom:6px;
}
.virtual-keyboard .vk-row:last-child{ margin-bottom:0; }
.virtual-keyboard .vk-key{
    background:#f5f5f7;
    border:1px solid #e5e7eb;
    border-radius:8px;
    padding:8px 0;
    text-align:center;
    font-weight:600;
    font-size:0.95rem;
}
.virtual-keyboard .vk-key:active{ background:#e9ecef; }
.virtual-keyboard .vk-key.danger{ background:#fdecec; }

/* 数字键盘切换按钮 */
.virtual-keyboard .vk-switch-btn{
    display: block;
    width: calc(100% - 16px);
    margin: 8px 8px;
    padding: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.virtual-keyboard .vk-switch-btn:hover{
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
.virtual-keyboard .vk-switch-btn:active{
    transform: translateY(0);
}

/* 嵌入式全键盘 */
.full-keyboard{
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    border-top: 2px solid #e5e7eb;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    z-index: 1500;
    user-select: none;
}

/* 当全键盘显示时，调整内容区域和表格高度 */
body.full-keyboard-visible .content-area {
    padding-bottom: 10px;
    margin-bottom: 370px; /* 全键盘280px + 底部按钮90px */
}

body.full-keyboard-visible .table-wrapper {
    max-height: calc(100vh - 530px); /* 顶部70px + 全键盘280px + 底部按钮90px + 添加按钮区域90px */
}

body.full-keyboard-visible .add-button-wrapper {
    margin: 15px 0 20px 0;
}

@media (max-width: 768px){
    body.full-keyboard-visible .content-area {
        margin-bottom: 350px; /* 全键盘260px + 底部按钮85px */
    }
    
    body.full-keyboard-visible .table-wrapper {
        max-height: calc(100vh - 500px);
    }
}

@media (max-width: 576px){
    body.full-keyboard-visible .content-area {
        margin-bottom: 330px; /* 全键盘240px + 底部按钮80px */
    }
    
    body.full-keyboard-visible .table-wrapper {
        max-height: calc(100vh - 470px);
    }
    
    body.full-keyboard-visible .add-button-wrapper {
        margin: 12px 0 15px 0;
    }
}

.full-keyboard .fk-header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    border-bottom: 1px solid #e5e7eb;
}

.full-keyboard .fk-title{
    font-size: 0.95rem;
    font-weight: 700;
    color: #2d3748;
}

.full-keyboard .fk-switch-btn{
    padding: 6px 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.full-keyboard .fk-switch-btn:hover{
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.full-keyboard .fk-close{
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.full-keyboard .fk-body{
    padding: 12px 16px 16px;
    max-width: 1000px;
    margin: 0 auto;
}

.full-keyboard .fk-row{
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
}

.full-keyboard .fk-row:last-child{
    margin-bottom: 0;
}

.full-keyboard .fk-key{
    background: linear-gradient(135deg, #f5f5f7 0%, #ffffff 100%);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 8px;
    min-width: 44px;
    text-align: center;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.full-keyboard .fk-key:hover{
    background: linear-gradient(135deg, #e9ecef 0%, #f8f9fa 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.full-keyboard .fk-key:active{
    background: #e9ecef;
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.full-keyboard .fk-key.danger{
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #dc2626;
}

.full-keyboard .fk-key.danger:hover{
    background: linear-gradient(135deg, #fecaca 0%, #fca5a5 100%);
}

.full-keyboard .fk-key.primary{
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.full-keyboard .fk-key.primary:hover{
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

@media (max-width: 768px){
    .virtual-keyboard{ width: 220px; bottom: 88px; right: 14px; }
    .virtual-keyboard .vk-key{ font-size:0.9rem; padding:7px 0; }
    
    .full-keyboard .fk-key{
        min-width: 32px;
        padding: 10px 4px;
        font-size: 0.85rem;
    }
    
    .full-keyboard .fk-body{
        padding: 10px 8px 12px;
    }
    
    .full-keyboard .fk-row{
        gap: 4px;
        margin-bottom: 6px;
    }
}

@media (max-width: 576px){
    .full-keyboard .fk-key{
        min-width: 28px;
        padding: 8px 2px;
        font-size: 0.8rem;
    }
    
    .full-keyboard .fk-row{
        gap: 3px;
        margin-bottom: 5px;
    }
}

/* 未填提示：现代化红框与警示角标 */
#orderTable td.cell-empty{
    outline: 2px solid #ef4444;
    outline-offset: -2px;
    position: relative;
    background: rgba(239, 68, 68, 0.06);
}
#orderTable td.cell-empty::after{
    content: '⚠';
    position: absolute;
    top: 2px;
    right: 6px;
    font-size: 12px;
    color: #ef4444;
}

/* 无效/不匹配提示：黄色警告风格 */
#orderTable td.cell-invalid {
    background-color: rgba(255, 193, 7, 0.15) !important; /* 柔和的黄色背景 */
    outline: 2px solid #ffc107;
    outline-offset: -2px;
    position: relative;
    padding-right: 35px !important; /* 为图标留出空间 */
}

/* 错误图标 - 使用伪元素避免污染单元格文本内容 */
#orderTable td.cell-invalid::after {
    content: '!';
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background-color: #ffc107;
    color: #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    z-index: 5;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 鼠标悬停在图标区域时显示手型（通过JS辅助判断，或者简单的视觉反馈） */
#orderTable td.cell-invalid:hover::after {
    transform: translateY(-50%) scale(1.1);
    transition: transform 0.2s;
}

/* Backdrop for manual date selection */
#manualBackdrop{
    position:fixed;
    inset:0;
    background:rgba(0,0,0,0.5);
    z-index:1450;
}

#rangeButtons .btn{
    border-radius: 12px;
    padding: .6rem 1rem;
    font-weight: 600;
    border: 1px solid var(--primary-color);
    background:#fff;
    color:var(--primary-color);
    transition:all .25s;
}
#rangeButtons .btn:hover{
    background:var(--primary-color);
    color:#fff;
    box-shadow:0 4px 12px rgba(0,0,0,.15);
}

/* 顶部工具栏和底部按钮的响应式优化 */
@media (max-width: 768px) {
    .top-toolbar {
        height: 56px;
        padding: 0 12px;
    }
    
    .toolbar-left {
        left: 12px;
    }
    
    .toolbar-right {
        right: 12px;
        gap: 4px;
    }
    
    .toolbar-btn {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }
    
    .sync-status {
        width: 38px;
        height: 38px;
        margin: 0;
    }
    
    .sync-icon {
        font-size: 1.1rem;
    }
    
    .sync-dot {
        width: 8px;
        height: 8px;
        top: 1px;
        right: 1px;
        border-width: 1.5px;
    }
    
    .page-title {
        font-size: 1.1rem;
    }
    
    .content-area {
        margin-top: 66px;
        margin-bottom: 10px;
        padding-bottom: 95px;
    }
    
    .table-wrapper {
        max-height: calc(100vh - 260px);
    }
    
    .add-btn {
        font-size: 0.9rem;
        padding: 12px 35px;
        min-width: 140px;
    }
    
    .bottom-buttons {
        height: 85px;
        padding: 10px 12px;
    }
    
    .bottom-btn {
        font-size: 0.85rem;
        padding: 8px 12px;
        min-width: 70px;
    }
}

@media (max-width: 576px) {
    .top-toolbar {
        height: 52px;
        padding: 0 10px;
    }
    
    .toolbar-left {
        left: 10px;
    }
    
    .toolbar-right {
        right: 10px;
        gap: 2px;
    }
    
    .toolbar-btn {
        width: 36px;
        height: 36px;
        font-size: 0.95rem;
    }
    
    .sync-status {
        width: 36px;
        height: 36px;
    }
    
    .sync-icon {
        font-size: 1rem;
    }
    
    .sync-dot {
        width: 7px;
        height: 7px;
    }
    
    .page-title {
        font-size: 0.95rem;
    }
    
    .content-area {
        margin-top: 62px;
        margin-bottom: 10px;
        padding-bottom: 90px;
    }
    
    .table-wrapper {
        max-height: calc(100vh - 240px);
        margin-bottom: 15px;
    }
    
    .add-btn {
        font-size: 0.85rem;
        padding: 11px 30px;
        min-width: 130px;
    }
    
    .bottom-buttons {
        height: 80px;
        padding: 8px 10px;
        gap: 6px;
    }
    
    .bottom-btn {
        font-size: 0.8rem;
        padding: 7px 10px;
        min-width: 65px;
    }
    
    .bottom-btn i {
        font-size: 0.9rem;
    }
}

/* 搜索页中页样式 */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #f8f9fa;
    z-index: 2100; /* 高于模态框 */
    display: flex;
    flex-direction: column;
    animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.search-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    background: #fff;
}

.search-header {
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
    /* 适配 iOS 顶部安全区域 */
    padding-top: calc(12px + env(safe-area-inset-top)); 
}

.search-input-wrapper {
    flex: 1;
    position: relative;
    background: #f1f3f5;
    border-radius: 12px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    height: 44px;
    transition: all 0.2s;
}

.search-input-wrapper:focus-within {
    background: white;
    box-shadow: 0 0 0 2px var(--primary-color);
}

.search-icon {
    color: #adb5bd;
    margin-right: 10px;
    font-size: 1.1rem;
}

#searchInput {
    border: none;
    background: transparent;
    width: 100%;
    height: 100%;
    outline: none;
    font-size: 1rem;
    color: var(--dark-color);
    padding: 0;
}

#clearSearchBtn {
    background: none;
    border: none;
    color: #adb5bd;
    padding: 0 0 0 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
}

#clearSearchBtn:hover {
    color: #868e96;
}

.btn-close-search {
    background: none;
    border: none;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1rem;
    padding: 8px 4px;
    white-space: nowrap;
}

.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: #f8f9fa;
    -webkit-overflow-scrolling: touch;
}

.search-item {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    transition: all 0.2s;
    cursor: pointer;
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.search-item:active {
    transform: scale(0.98);
    background-color: #f1f3f5;
}

.search-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.search-item-code {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.1rem;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-item-name {
    font-size: 0.95rem;
    color: var(--dark-color);
    margin-bottom: 8px;
    line-height: 1.4;
    font-weight: 500;
}

.search-item-option {
    font-size: 0.85rem;
    color: #495057;
    background: #e9ecef;
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
}

.search-placeholder, .no-results {
    text-align: center;
    color: #adb5bd;
    margin-top: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.search-placeholder i, .no-results i {
    font-size: 3rem;
    opacity: 0.5;
}

.search-highlight {
    color: #d63384;
    font-weight: bold;
    background: rgba(214, 51, 132, 0.1);
    padding: 0 2px;
    border-radius: 2px;
}

/* Row deleting animation */
.row-deleting {
    animation: fadeOutRight 0.4s ease forwards;
    background-color: #ffebee !important;
}

@keyframes fadeOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Delete row button */
.delete-row-btn {
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
}
.delete-row-btn:hover {
    transform: scale(1.2);
}

/* 移动端适配 */
@media (max-width: 768px) {
    .search-header {
        padding: 10px 12px;
        padding-top: calc(10px + env(safe-area-inset-top));
    }
    .search-input-wrapper {
        height: 40px;
    }
    .search-item {
        padding: 14px;
    }
}

/* 修复删除按钮列在移动端可能超出边界的问题 */
th.delete-col, td.delete-col {
    width: 50px !important;
    min-width: 50px !important;
    max-width: 50px !important;
    text-align: center !important;
    padding: 0 !important;
    vertical-align: middle !important;
    box-sizing: border-box;
}

/* 确保在删除模式下，删除列固定在右侧 */
body.delete-mode-on #orderTable th.delete-col, 
body.delete-mode-on #orderTable td.delete-col {
    position: sticky;
    right: 0;
    background-color: #fff;
    z-index: 5;
    box-shadow: -2px 0 8px rgba(0,0,0,0.1);
    border-left: 1px solid #eee;
}

/* 表头背景色修正 */
body.delete-mode-on .dataTables_scrollHead th.delete-col {
    background-color: #fff; 
    z-index: 10;
}

/* 适配 DataTables 的条纹背景 */
body.delete-mode-on table.dataTable.stripe tbody tr.odd td.delete-col,
body.delete-mode-on table.dataTable.display tbody tr.odd td.delete-col {
    background-color: #f9f9f9;
}

/* 适配 DataTables 的 Hover 背景 */
body.delete-mode-on table.dataTable.hover tbody tr:hover td.delete-col,
body.delete-mode-on table.dataTable.display tbody tr:hover td.delete-col {
    background-color: #f6f6f6;
}
