* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    background: #f4f7fb;
    color: #1f2937;
}

a {
    color: #0b6c88;
    text-decoration: none;
}

.topbar {
    background: linear-gradient(120deg, #0b6c88, #2563eb);
    color: #fff;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.topbar h1 {
    margin: 0 0 4px;
    font-size: 22px;
}

.topbar p {
    margin: 0;
    font-size: 13px;
    opacity: 0.9;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.permission {
    font-size: 12px;
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 10px;
    border-radius: 999px;
}

.container {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    padding: 16px;
}

.sidebar {
    background: #fff;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    height: fit-content;
}

.menu-item {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: #334155;
}

.menu-item:hover {
    background: #eef7ff;
}

.menu-item.active {
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 600;
}

.menu-group {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

.menu-group-title {
    padding: 4px 6px 6px;
    font-size: 13px;
    color: #475569;
    font-weight: 600;
}

.menu-child {
    margin-left: 8px;
    padding-left: 16px;
    position: relative;
}

.menu-child::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 50%;
    width: 6px;
    height: 1px;
    background: #94a3b8;
}

.menu-btn-quick {
    width: 100%;
    border: 0;
    text-align: left;
    cursor: pointer;
    margin-bottom: 8px;
    background: #0b6c88;
    color: #fff;
}

.menu-btn-quick:hover {
    background: #0a5f77;
}

.content {
    min-width: 0;
}

.panel {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    padding: 16px;
}

.panel-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-title-row h2 {
    margin: 0;
    font-size: 20px;
}

.panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    /* 按钮变多（新增 / 下载模板 / 导入）时允许换行，窄屏不撑破标题行 */
    flex-wrap: wrap;
}

.import-form {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn {
    border: 0;
    background: #2563eb;
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.btn.secondary {
    background: #64748b;
}

.text-btn {
    border: 0;
    background: transparent;
    color: #0b6c88;
    cursor: pointer;
    padding: 0;
    margin-right: 8px;
    font-size: 13px;
}

.text-btn.danger {
    color: #dc2626;
}

.flash {
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
}

.flash.success {
    background: #dcfce7;
    color: #166534;
}

.flash.error {
    background: #fee2e2;
    color: #991b1b;
}

.filter-form {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
    align-items: end;
}

.filter-form label,
.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}

input,
select,
textarea {
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px;
    font-size: 14px;
}

textarea {
    resize: vertical;
}

.filter-actions {
    display: flex;
    gap: 8px;
}

/* 勾选式筛选（线控/节流阀/液压锁/手动泵）：勾上 = 只看「是」 */
.filter-form label.filter-check {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    user-select: none;
}

.filter-form label.filter-check span {
    white-space: nowrap;
}

.filter-form label.filter-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    padding: 0;
    margin: 0;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    accent-color: #2563eb;
    cursor: pointer;
}

.filter-form label.filter-check:has(input:checked) {
    border-color: #2563eb;
    background: #eff6ff;
}

.table-wrap {
    overflow-x: auto;
}

/* 列表分页条 */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
    font-size: 13px;
    color: #475569;
}

.pager-info {
    white-space: nowrap;
}

.pager-links {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.pager-links a,
.pager-links .pager-current,
.pager-links .pager-disabled {
    min-width: 34px;
    padding: 5px 9px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #2563eb;
    text-align: center;
    text-decoration: none;
    line-height: 1.2;
}

.pager-links a:hover {
    background: #eff6ff;
    border-color: #2563eb;
}

.pager-links .pager-current {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
    font-weight: 600;
}

.pager-links .pager-disabled {
    color: #cbd5e1;
    border-color: #e5e7eb;
    background: #f8fafc;
    cursor: default;
}

.pager-gap {
    color: #94a3b8;
    min-width: 12px;
    text-align: center;
}

.pager-size {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.pager-size select {
    padding: 4px 6px;
    font-size: 13px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th,
td {
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 8px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

th {
    background: #f8fafc;
    position: sticky;
    top: 0;
}

.empty {
    text-align: center;
    color: #64748b;
}

.actions {
    min-width: 130px;
}

dialog {
    border: 0;
    border-radius: 12px;
    width: min(760px, 96vw);
    padding: 0;
    max-height: 92vh;
}

dialog::backdrop {
    background: rgba(15, 23, 42, 0.5);
}

#recordForm {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    max-height: 92vh;
    overflow-y: auto;
}

.form-field-wide {
    grid-column: 1 / -1;
}

#recordForm .dialog-actions {
    grid-column: 1 / -1;
    position: sticky;
    bottom: -16px;
    background: #fff;
    padding: 10px 0;
    margin-bottom: -16px;
}

#recordForm h3 {
    grid-column: 1 / -1;
    margin: 0 0 8px;
}

#quickQuoteForm {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    max-height: 92vh;
    overflow-y: auto;
}

/* 快速录入询盘：按分类分组的参数字段
   默认隐藏；激活时用 display:contents，让内部的 .form-field 直接参与
   #quickQuoteForm 的栅格布局，不会因为多包一层 <div> 而错位。 */
.quick-param-group {
    display: none;
}

.quick-param-group.is-active {
    display: contents;
}

#quickQuoteForm h3 {
    grid-column: 1 / -1;
    margin: 0 0 8px;
}

.menu-btn-quick + .menu-item {
    margin-top: 4px;
}

.quick-quote-full {
    grid-column: 1 / -1;
}

#orderShipForm,
#pendingShipForm {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}

#orderShipForm h3,
#pendingShipForm h3 {
    grid-column: 1 / -1;
    margin: 0 0 8px;
}

.permission-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.permission-group label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}

.dialog-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.file-tip {
    font-size: 12px;
    color: #475569;
    /* 剪贴板截图生成的文件名可能很长，避免撑破弹窗布局 */
    word-break: break-all;
}

/* 右键读取剪贴板截图：成功 / 失败两种反馈色 */
.file-tip.is-ok {
    color: #15803d;
}

.file-tip.is-error {
    color: #b91c1c;
}

/* 可发现性提示：只有支持 navigator.clipboard.read 的浏览器才会挂上这个 class；
   一旦写入反馈文案，:empty 不再成立，提示自动消失，不占额外布局 */
.file-tip.clipboard-hint:empty::before {
    content: "右键可粘贴截图";
    color: #94a3b8;
}

/* 编辑态「已有附件」区：缩略图 + 文件名 + 查看原图 + 删除 */
.file-existing {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.file-existing[hidden] {
    display: none;
}

.file-existing-thumb {
    /* 固定 150x150 预览框：object-fit:contain 等比缩放、完整显示，
       不裁切也不拉伸变形（多余的空白用底色填充，图片本身不压缩） */
    display: block;
    width: 150px;
    height: 150px;
    flex: 0 0 auto;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    object-fit: contain;
    background: #f8fafc;
}

.file-existing-thumb[hidden] {
    display: none;
}

.file-existing-name {
    /* 缩略图固定 150px 后，长文件名折行会把「删除」挤到很下面，
       这里压成单行省略，完整文件名放到 title 里（悬停可见） */
    max-width: 150px;
    font-size: 12px;
    color: #475569;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-existing-link {
    font-size: 12px;
    color: #1e40af;
}

.file-existing-link[hidden] {
    display: none;
}

/* 已标记删除：缩略图变灰，等保存后真正删除 */
.file-existing.is-marked .file-existing-thumb {
    opacity: .35;
    filter: grayscale(1);
}

.file-existing.is-marked .file-existing-link {
    display: none;
}

.file-existing.is-marked .file-existing-name {
    color: #b91c1c;
}

.file-remove-btn {
    padding: 3px 10px;
    font-size: 12px;
    line-height: 1.6;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
}

.file-remove-btn:hover {
    border-color: #ef4444;
    background: #fef2f2;
}

.bom-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bom-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bom-row {
    display: grid;
    grid-template-columns: 1.5fr 1fr auto;
    gap: 8px;
    align-items: center;
}

.kv-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kv-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kv-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 8px;
    align-items: center;
}

.kv-actions {
    display: flex;
    gap: 8px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at top left, #dbeafe, #e2e8f0);
}

.login-card {
    width: min(380px, 92vw);
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.login-card h1 {
    margin: 0 0 6px;
}

.hint {
    margin: 0 0 12px;
    color: #475569;
    font-size: 13px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

@media (max-width: 980px) {
    .container {
        grid-template-columns: 1fr;
    }
}

/* ============ 单据编辑器（报价/订单/发货） ============ */
.doc-header {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.doc-header .doc-col-2 {
    grid-column: span 2;
}

.doc-header .doc-col-3 {
    grid-column: 1 / -1;
}

.doc-section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 8px 0 10px;
}

.doc-section-title h3 {
    margin: 0;
    font-size: 15px;
    color: #111827;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1080px;
}

.items-table th,
.items-table td {
    padding: 6px;
    border-bottom: 1px solid #eef1f5;
    vertical-align: top;
    text-align: left;
}

.items-table th {
    font-size: 12px;
    color: #6b7280;
    font-weight: 600;
    white-space: nowrap;
    background: #fafbfc;
}

.items-table input,
.items-table select,
.items-table textarea {
    width: 100%;
    box-sizing: border-box;
}

.items-table td.col-actions {
    white-space: nowrap;
}

.doc-totals {
    display: flex;
    gap: 28px;
    justify-content: flex-end;
    align-items: baseline;
    margin: 14px 0 4px;
    font-size: 13px;
    color: #4b5563;
}

.doc-totals strong {
    font-size: 16px;
    color: #111827;
    margin-left: 4px;
}

#btnAddItem {
    margin-top: 10px;
}

.items-table td.col-product_select {
    min-width: 168px;
}

.items-table td.col-textarea {
    min-width: 240px;
}

.items-table td.col-actions,
.items-table th:last-child {
    width: 58px;
    text-align: center;
}

.items-table td.col-number input {
    min-width: 72px;
}

.items-table {
    min-width: 1160px;
}

.items-table td.col-textarea {
    min-width: 260px;
}

.items-table td.col-text input {
    min-width: 110px;
}

/* 产品型号点击查看详情 */
.link-detail {
    color: #2563eb;
    text-decoration: underline;
    cursor: pointer;
    background: none;
    border: 0;
    padding: 0;
    font-size: inherit;
}

#productDetailDialog .detail-panel {
    padding: 16px;
    max-height: 80vh;
    overflow-y: auto;
}

#productDetailDialog h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.detail-body table {
    width: 100%;
    border-collapse: collapse;
    /* 固定表格布局：否则长串会把表格最小内容宽度撑大，弹窗内部出现横向滚动 */
    table-layout: fixed;
}

.detail-body th,
.detail-body td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid #eef1f5;
    vertical-align: top;
    font-size: 13px;
    /* 全局 th,td 有 white-space: nowrap，这里必须复位，否则超长文本不会换行 */
    white-space: normal;
    /* 超长无空格字符串（长 URL、长 token、200 字符连续串）强制折行，避免弹窗内部出现横向滚动 */
    overflow-wrap: anywhere;
}

.detail-body th {
    color: #6b7280;
    font-weight: 600;
    width: 110px;
    white-space: nowrap;
}

.detail-params {
    /* pre-line 保留参数之间的换行；overflow-wrap 让单个超长参数值也能折行 */
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* 详情弹窗里横排的产品照片（产品图册的三张实拍图） */
.detail-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.detail-thumbs a {
    display: block;
    border-radius: 6px;
}

/* 弹窗打开时浏览器会自动聚焦第一个可聚焦元素（首张图），换成蓝色细环避免看起来像黑边框 */
.detail-thumbs a:focus {
    outline: none;
}

.detail-thumbs a:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.detail-thumbs img {
    display: block;
    /* 与编辑页预览统一为 150x150，等比完整显示，不裁切 */
    width: 150px;
    height: 150px;
    object-fit: contain;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
}

/* 表单必填校验：错误态 */
.form-field-invalid input,
.form-field-invalid select,
.form-field-invalid textarea {
    border-color: #d9534f;
}

.field-error {
    color: #c0392b;
    font-size: 12px;
    line-height: 1.4;
}

/* 提示为空时不占高度（含 flex 布局的 gap） */
.field-error:empty {
    display: none;
}

.form-alert {
    background: #fdecea;
    border: 1px solid #f5c6cb;
    color: #a94442;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 13px;
    /* #recordForm 是网格布局，汇总条需要整行铺满 */
    grid-column: 1 / -1;
}

/* 多明细列表（如订单）：跨行合并的订单级单元格垂直居中，视觉上与明细行对齐 */
.table-wrap td[rowspan] {
    vertical-align: middle;
}
