/* 订单明细表列显隐：避免不含税与含税列同时显示造成冗余 */
/* 税率>0: 隐藏不含税单价与金额列，仅显示含税与含税金额 */
.items-table.tax-mode .untaxed-price-col,
.items-table.tax-mode .untaxed-amount-col {
    display: none !important;
}
/* 税率=0: 隐藏含税与含税金额列，仅显示不含税单价与金额 */
.items-table:not(.tax-mode) .taxed-price-col,
.items-table:not(.tax-mode) .taxed-amount-col {
    display: none !important;
}

/* ====== 生产单查看模式：税率>0时同时显示不含税列和含税列 ====== */
/* .show-all-tax-cols class 由 updateTaxColumnsVisibility 在查看模式 + 有税率时添加 */
.production-items-table.show-all-tax-cols .untaxed-price-col,
.production-items-table.show-all-tax-cols .untaxed-amount-col,
.production-items-table.show-all-tax-cols .taxed-price-col,
.production-items-table.show-all-tax-cols .taxed-amount-col {
    display: table-cell !important;
}

/* ====== 库存调整类单据(报升/报损/调拨)：只显示不含税单价+金额 ====== */
/* 隐藏：税率(%)、含税价、含税金额 三列 */
/* 保留：单价(不含税)、金额(不含税) */
.items-table.stock-adj-mode .tax-rate-col,
.items-table.stock-adj-mode .taxed-price-col,
.items-table.stock-adj-mode .taxed-amount-col {
    display: none !important;
}

/* ====== 生产领料(doc_type=9)：只对成本负责，只显示单价(不含税)+金额(不含税) ====== */
/* 隐藏：税率(%)、含税价、含税金额（价格由库存平均成本自动计算，领料只对成本负责） */
/* 保留：单价(不含税)、金额(不含税) */
.items-table.production-issue-mode .tax-rate-col,
.items-table.production-issue-mode .taxed-price-col,
.items-table.production-issue-mode .taxed-amount-col {
    display: none !important;
}
/* production-issue-mode 强制覆盖 tax-mode 的样式（让不含税单价/金额列始终可见） */
.items-table.production-issue-mode.tax-mode .untaxed-price-col,
.items-table.production-issue-mode.tax-mode .untaxed-amount-col {
    display: table-cell !important;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #555;
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #2563eb;
}

/* 收货地址：只读无框，长地址自适应 */
.address-readonly {
    width: 100%;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 8px 0 !important;
    font-size: 14px;
    color: #374151;
    cursor: default;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: thin;
}
.address-readonly:focus {
    outline: none;
    border: none;
    box-shadow: none;
    background: transparent;
}
.address-readonly::-webkit-scrollbar {
    height: 4px;
}
.address-readonly::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
}

/* 收款/付款账户合并列：占据原账户+账号两列宽度 */
#payment-bank-group {
    grid-column: span 2;
}

@media (max-width: 1200px) {
    .form-row {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1000px) {
    .form-row {
        grid-template-columns: repeat(3, 1fr);
    }
    #payment-bank-group {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================================
   订单明细表格 - Excel 风格（2026-10-17 升级）
   特性：标准网格边框 | 冻结首行 | 列宽拖拽 | 合计行 sticky
   ============================================================ */

/* 表格外层滚动容器：触发 sticky 冻结首行必须要有 overflow + max-height */
.items-table-wrap {
    border: 1px solid #b7b7b7;
    border-radius: 3px;
    overflow: auto;
    max-height: 480px;       /* 超过此高度后表格内部滚动，表头保持冻结 */
    margin-top: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

/* 表本身 */
.items-table {
    width: 100%;
    border-collapse: separate;   /* 关键：sticky 元素不能在 collapse 模式下工作 */
    border-spacing: 0;
    table-layout: auto;          /* auto：列宽按内容自适应，规格型号等长内容列自动获得更多空间 */
    font-size: 13px;
}

/* 独立边框类 —— 兼容旧码单页面引用 */
.excel-border-r { border-right: 1px solid #d0d0d0; }
.excel-border-b { border-bottom: 1px solid #d0d0d0; }
.excel-border-t { border-top: 1px solid #d0d0d0; }
.excel-border-l { border-left: 1px solid #d0d0d0; }

/* 单元格通用：浅灰网格线（比橄榄绿 #6B8E23 更像 Excel 默认样式） */
.items-table th,
.items-table td {
    padding: 0 8px;
    height: 28px;
    line-height: 28px;
    border-right: 1px solid #d0d0d0;
    border-bottom: 1px solid #d0d0d0;
    text-align: left;
    white-space: nowrap;
    background: #fff;
    position: relative;
}
.items-table th:last-child,
.items-table td:last-child { border-right: none; }

/* ---------- 表头：冻结首行核心 ---------- */
.items-table thead th {
    background: linear-gradient(#f7f9fc, #e9edf3);
    font-weight: 600;
    color: #1f2937;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: 1px solid #a8a8a8;   /* 表头下沿加粗 */
    padding: 0 6px;
    height: 30px;
    line-height: 30px;
    cursor: pointer;
    user-select: none;
}

/* 排序箭头（与公共组件 .exl-table 统一） */
.items-table thead th .sort-icon {
    display: inline-block;
    margin-left: 4px;
    font-size: 10px;
    line-height: 1;
    vertical-align: middle;
    color: transparent;
    transition: color 0.15s;
}
.items-table thead th.sorted-asc  .sort-icon { color: #165DFF; }
.items-table thead th.sorted-desc .sort-icon { color: #165DFF; }
.items-table thead th:hover .sort-icon { color: #9ca3af; }

/* ---------- 合计行：sticky 底部 ---------- */
.items-table tfoot td {
    background: #fff8e6;
    font-weight: 600;
    border-top: 2px solid #caa833;
    position: sticky;
    bottom: 0;
    z-index: 2;
}
/* 合计行数值列强制右对齐（与公共组件 .exl-table 统一） */
.items-table tfoot td.num-col {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

/* ---------- 列宽拖拽手柄（表头内右侧 6px 隐形区域） ---------- */
.items-table th .col-resizer {
    position: absolute;
    top: 0; right: -3px;
    width: 6px; height: 100%;
    cursor: col-resize;
    z-index: 4;
    user-select: none;
}
.items-table th .col-resizer:hover,
.items-table th .col-resizer.active {
    background: rgba(22, 93, 255, 0.35);
}

/* ---------- 输入框 / 数字 ---------- */
.items-table input[type=number]::-webkit-inner-spin-button,
.items-table input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.items-table input[type=number] { -moz-appearance: textfield; }

.items-table .num-input { text-align: right; }
.items-table .num-display { text-align: right; font-weight: 500; }

/* 数字列统一右对齐 + 等宽数字 */
.items-table td.num-col { text-align: right; font-variant-numeric: tabular-nums; }
.items-table thead th.num-col { text-align: right; }

/* Excel 风格输入框：absolute 铺满整个 td，透明无边框 */
/* 概念：整个 td 就是"单元格"，input 覆盖全部内容区 */
.items-table .excel-input {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0 8px;        /* 和 td 的 padding 对齐 */
    border: none;
    outline: none;
    /* 修复：input 始终白底，防止选中行 td 蓝色(#bfdbfe)穿透透明 input 显现 */
    background: #fff;
    font-size: 13px;
    font-family: inherit;
    line-height: 28px;     /* 和 td 的 height 对齐 */
    box-sizing: border-box;
}
.items-table .excel-input:focus {
    background: #fff;
}
/* 查看态：保持灰底，与 .view-mode input 规则一致 */
.view-mode .items-table .excel-input {
    background-color: #f8f9fa !important;
}
.items-table .excel-input.text-center { text-align: center; }
.items-table .excel-input.text-right { text-align: right; }

/* 颜色列 flex 容器 absolute 铺满 td（唯一规则） */
.items-table td[data-col="color"] {
    position: relative;
    padding: 0 8px;
}
.items-table .color-cell {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    box-sizing: border-box;
    /* 修复：白底覆盖整个 td，防止选中行 td 蓝色穿透 */
    background: #fff;
}
/* 查看态例外：灰底 */
.view-mode .items-table .color-cell {
    background: #f8f9fa;
}
/* 颜色列内 input 不使用 absolute 定位，参与 flex 布局 */
.items-table .color-cell .excel-input,
/* quotation.html 等直接用 flex 容器 + color-dot 结构的颜色列 */
.items-table td[data-col="color"] .excel-input {
    position: static !important;
    inset: auto;
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    padding: 0;
    outline: none;
}

/* 表格内居中对齐 */
.items-table td.text-center,
.items-table th.text-center { text-align: center; }

/* 颜色块 */
.items-table .color-block {
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 3px;
    flex-shrink: 0;
    vertical-align: middle;
    border: 1px solid rgba(0,0,0,.08);
}

/* ---------- 选中/hover 样式（与公共组件 excel-table.css 统一） ---------- */
.items-table tr {
    cursor: pointer;
    transition: background-color 0.15s ease;
}
/* hover：与 .exl-table 统一使用 #e8ecf4 */
.items-table tbody tr:hover td { background-color: #e8ecf4 !important; }
/* 选中行：与 .exl-table 统一使用 #bfdbfe，移除自编的 outline 蓝边和网格线透明化 */
.items-table tbody tr.selected-row td,
.items-table tbody tr.exl-selected-row td {
    background-color: #bfdbfe !important;
    color: #2c3e50;
}
/* 表头不参与 hover 变色 */
.items-table thead tr:hover th { background: linear-gradient(#f7f9fc, #e9edf3); }

/* 测色状态指示器 */
.colorimeter-connected {
    background-color: #22c55e !important;
}
.colorimeter-disconnected {
    background-color: #ef4444 !important;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: #f8f9fa;
    flex-shrink: 0;
}

.btn {
    padding: 10px 24px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity 0.2s;
}

.btn-primary {
    background: #2563eb;
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: #e5e7eb;
    color: #374151;
}

.btn-secondary:hover {
    opacity: 0.9;
}

.btn-danger {
    background: #dc2626;
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-pending {
    background: rgba(22, 93, 255, 0.15);
    color: #1d4ed8;
}

.status-paid {
    background: #fef3c7;
    color: #d97706;
}

.status-shipped {
    background: #dcfce7;
    color: #16a34a;
}

.status-completed {
    background: #f3f4f6;
    color: #6b7280;
}

.status-cancelled {
    background: #fee2e2;
    color: #dc2626;
}

.view-mode input,
.view-mode select,
.view-mode textarea {
    background: #f8f9fa;
    cursor: default;
}

/* 自定义下拉组件样式 */
.custom-select {
    position: relative;
    width: 100%;
}

.custom-select select,
.custom-select input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
    cursor: pointer;
    background-color: white;
}

.custom-select select:focus,
.custom-select input[type="text"]:focus {
    outline: none;
    border-color: #2563eb;
}

.custom-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
    max-height: 300px;
    display: flex;
    flex-direction: column;
}

.dropdown-search {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-bottom: 1px solid #eee;
    font-size: 13px;
    outline: none;
}

.dropdown-search:focus {
    border-bottom-color: #2563eb;
}

.dropdown-options {
    flex: 1;
    overflow-y: auto;
    max-height: 200px;
}

.dropdown-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f5f5f5;
    transition: background-color 0.15s;
}

.dropdown-option:hover {
    background-color: #f0f4ff;
}

.dropdown-option.selected {
    background-color: #e0e7ff;
    color: #3730a3;
}

.dropdown-footer {
    padding: 8px;
    border-top: 1px solid #eee;
    background: #fafafa;
}

.dropdown-add-btn {
    width: 100%;
    padding: 8px;
    border: 1px dashed #2563eb;
    background: white;
    color: #2563eb;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.dropdown-add-btn:hover {
    background: #2563eb;
    color: white;
}

/* 隐藏原生select但保留功能 */
.custom-select select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.custom-select select:disabled {
    background-color: #f8f9fa;
    cursor: not-allowed;
}

.view-mode .custom-select select,
.view-mode .custom-select input[type="text"] {
    background: #f8f9fa;
    cursor: default;
    pointer-events: none;
}

/* Autocomplete Select Component */
.autocomplete-select {
    position: relative;
    display: inline-block;
}

.autocomplete-select .ac-input {
    width: 100%;
    min-width: 100px;
    padding: 6px 28px 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
    background: white;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.autocomplete-select .ac-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.autocomplete-select .ac-input:disabled {
    background-color: #f3f4f6;
    cursor: not-allowed;
    color: #9ca3af;
}

.autocomplete-select .ac-arrow {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #6b7280;
    font-size: 10px;
    transition: transform 0.2s;
}

.autocomplete-select.active .ac-arrow {
    transform: translateY(-50%) rotate(180deg);
}

/* 下拉框已移至body，使用fixed定位 */
.ac-dropdown {
    max-height: 240px;
    overflow-y: auto;
    overflow-x: hidden;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: none;
    box-sizing: border-box;
}

.ac-dropdown.active {
    display: block;
}

.ac-dropdown .ac-options {
    padding: 4px 0;
}

.ac-dropdown .ac-option {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ac-dropdown .ac-option:hover,
.ac-dropdown .ac-option.highlighted {
    background-color: rgba(22, 93, 255, 0.20);
}

.ac-dropdown .ac-option.selected {
    background-color: rgba(22, 93, 255, 0.30);
    color: #1e40af;
    font-weight: 500;
}

.ac-dropdown .ac-clear-option {
    border-bottom: 1px solid #e5e7eb;
    color: #6b7280;
    font-style: italic;
}

.ac-dropdown .ac-clear-option:hover {
    background-color: #f3f4f6;
    color: #374151;
}

.ac-dropdown .ac-empty {
    padding: 12px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
}

/* 滚动条样式 */
.ac-dropdown::-webkit-scrollbar {
    width: 8px;
}

.ac-dropdown::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.ac-dropdown::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.ac-dropdown::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.help-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
    color: #9ca3af;
    margin-left: 6px;
    font-size: 0.875rem;
}
.help-tip:hover,
.help-tip:focus {
    color: #165DFF;
}
.help-tip .help-tip-content {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px;
    padding: 10px 14px;
    background: #1f2937;
    color: #fff;
    font-size: 12px;
    font-weight: normal;
    line-height: 1.6;
    border-radius: 6px;
    white-space: normal;
    word-wrap: break-word;
    z-index: 10001;
    pointer-events: none;
    min-width: 300px;
    max-width: 380px;
}
.help-tip:hover .help-tip-content,
.help-tip:focus .help-tip-content {
    visibility: visible;
    opacity: 1;
}
.help-tip .help-tip-content::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: #1f2937;
}