* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; color: #1f2328; background: #f6f7f9; }
a { color: #0b62c4; text-decoration: none; }
a:hover { text-decoration: underline; }
.nav { display: flex; gap: 6px; align-items: center; padding: 0 24px; height: 68px; background: #1f2a37; }
.nav a { color: #cfd6df; padding: 8px 16px; border-radius: 6px; font-size: 17px; }
.nav a:hover { background: #2c3a4b; text-decoration: none; }
.nav a.on { color: #fff; background: #34465b; }
.nav .brand { color: #fff; font-weight: 700; font-size: 28px; letter-spacing: 1px; padding: 6px 4px; }
.nav .brand:hover { background: none; }
main { max-width: 1280px; margin: 0 auto; padding: 20px; }
h1 { font-size: 24px; margin: 4px 0 16px; font-weight: 600; }
h2 { font-size: 19px; margin: 24px 0 10px; font-weight: 600; }
.card { background: #fff; border: 1px solid #e3e6ea; border-radius: 8px; padding: 16px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 8px 12px; border-bottom: 1px solid #eceef1; text-align: left; vertical-align: top; }
th { background: #f2f4f7; font-weight: 600; white-space: nowrap; }
tr:hover td { background: #fafbfc; }
td.num, th.num { text-align: right; }
.mono { font-family: Consolas, "Courier New", monospace; }
.muted { color: #6b7280; }
.small { font-size: 14px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 14px; background: #eef1f5; color: #374151; }
.tag.ACTIVE { background: #e3f4e8; color: #166534; }
.tag.INACTIVE { background: #fdf3dc; color: #8a5a00; }
.tag.OBSOLETE { background: #fbe4e4; color: #9b1c1c; }
.tag.insert { background: #e3f0fd; color: #0b4f9c; }
.tag.update { background: #fdf3dc; color: #8a5a00; }
.tag.skip { background: #eef1f5; color: #6b7280; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.flash.ok { background: #e3f4e8; color: #166534; }
.flash.err { background: #fbe4e4; color: #9b1c1c; }
form.inline { display: inline; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
input[type=text], input[type=number], select, textarea { font: inherit; padding: 7px 10px; border: 1px solid #cfd4da; border-radius: 6px; background: #fff; }
input[type=text]:focus, select:focus, textarea:focus { outline: 2px solid #9cc3f5; border-color: #6aa5ec; }
.btn { font: inherit; padding: 7px 16px; border-radius: 6px; border: 1px solid #cfd4da; background: #fff; cursor: pointer; color: #1f2328; display: inline-block; }
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn.primary { background: #0b62c4; border-color: #0b62c4; color: #fff; }
.btn.primary:hover { background: #0a56ad; }
.btn.danger { color: #b42318; }
.btn.sm { padding: 3px 10px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px 20px; }
.field label { display: block; font-size: 14px; color: #4b5563; margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; }
.field.wide { grid-column: 1 / -1; }
.req::after { content: " *"; color: #b42318; }
dl.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: #6b7280; }
dl.kv dd { margin: 0; }
.err-list { color: #9b1c1c; margin: 0; padding-left: 18px; }
tr.bad td { background: #fff5f5; }
.pager { display: flex; gap: 6px; margin-top: 12px; align-items: center; }
.indent { display: inline-block; }
.summary { display: flex; gap: 12px; flex-wrap: wrap; }
.summary .box { background: #fff; border: 1px solid #e3e6ea; border-radius: 8px; padding: 10px 16px; min-width: 120px; }
.summary .box b { display: block; font-size: 24px; }

/* category picker */
[hidden] { display: none !important; }
.catpicker { position: relative; }
.catpicker-btn { width: 100%; min-width: 260px; display: flex; justify-content: space-between; align-items: center; gap: 8px; font: inherit; text-align: left; padding: 7px 10px; border: 1px solid #cfd4da; border-radius: 6px; background: #fff; cursor: pointer; color: #1f2328; }
.catpicker.open .catpicker-btn, .catpicker-btn:focus { outline: 2px solid #9cc3f5; border-color: #6aa5ec; }
.catpicker.invalid .catpicker-btn { border-color: #b42318; outline: 2px solid #f5b5ae; }
.catpicker-label.placeholder { color: #6b7280; }
.catpicker-caret { color: #6b7280; }
.catpicker-panel { position: absolute; z-index: 50; top: calc(100% + 6px); left: 0; display: flex; background: #fff; border: 1px solid #e3e6ea; border-radius: 12px; box-shadow: 0 10px 30px rgba(15, 23, 42, .15); }
.catpicker-col { list-style: none; margin: 0; padding: 8px; max-height: 440px; overflow-y: auto; min-width: 230px; }
.catpicker-col ul { list-style: none; margin: 0; padding: 0; }
.catpicker-minors { border-left: 1px solid #eceef1; min-width: 240px; }
.catpicker-col li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.catpicker-col li:hover, .catpicker-major.active { background: #eef3fb; }
.catpicker-col li.selected { background: #e3edfb; color: #0b4f9c; font-weight: 600; }
.catpicker-arrow { color: #9aa3ad; }
.catpicker-check { visibility: hidden; color: #0b62c4; }
.catpicker-col li.selected .catpicker-check { visibility: visible; }
.catpicker-empty, .catpicker-hint { color: #9aa3ad; cursor: default; padding: 8px 12px; }
.catpicker-empty:hover { background: none !important; }

/* documents */
.docs { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.doc-card { width: 200px; background: #fff; border: 1px solid #e3e6ea; border-radius: 8px; overflow: hidden; color: inherit; display: flex; flex-direction: column; }
a.doc-card:hover { border-color: #6aa5ec; text-decoration: none; box-shadow: 0 2px 8px rgba(15, 23, 42, .08); }
.doc-thumb { height: 150px; display: flex; align-items: center; justify-content: center; background: #f6f7f9; overflow: hidden; }
.doc-thumb img { max-width: 140px; max-height: 140px; object-fit: contain; }
.doc-pdf { font-weight: 700; color: #b42318; border: 2px solid #b42318; border-radius: 6px; padding: 8px 14px; }
.doc-name { padding: 8px 10px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-upload { padding: 10px; gap: 8px; justify-content: center; border-style: dashed; }
.doc-upload input[type=file] { font-size: 13px; width: 100%; }
.viewer-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.viewer { height: calc(100vh - 230px); min-height: 400px; overflow: auto; background: #e9ecef; border: 1px solid #dfe3e8; border-radius: 8px; position: relative; }
.viewer-stage { position: relative; margin: 0 auto; }
.viewer-stage img { position: absolute; left: 50%; top: 50%; transform-origin: center center; max-width: none; }
.viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.doc-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.doc-strip a { padding: 4px 10px; border: 1px solid #dfe3e8; border-radius: 6px; background: #fff; font-size: 14px; }
.doc-strip a.on { border-color: #0b62c4; color: #0b62c4; font-weight: 600; }

/* item page: info left, drawing right */
.detail-top { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: stretch; margin-bottom: 8px; }
@media (max-width: 1000px) { .detail-top { grid-template-columns: 1fr; } .drawing-main { min-height: 320px; } }
.detail-top .card { margin-bottom: 0; }
.detail-drawings { display: flex; flex-direction: column; padding: 12px; min-width: 0; }
.drawing-main { flex: 1 1 auto; min-height: 150px; display: flex; align-items: center; justify-content: center; background: #f6f7f9; border: 1px solid #eceef1; border-radius: 8px; overflow: hidden; cursor: zoom-in; }
.drawing-main { position: relative; }
.drawing-main img { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; }
.drawing-caption { margin-top: 8px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawing-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.drawing-thumbs a { width: 52px; height: 52px; border: 2px solid #e3e6ea; border-radius: 6px; background: #f6f7f9; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.drawing-thumbs a.on { border-color: #0b62c4; }
.drawing-thumbs a { position: relative; }
.drawing-thumbs img { position: absolute; inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); object-fit: contain; }
.drawing-empty { flex: 1 1 auto; min-height: 150px; padding: 12px; display: flex; align-items: center; justify-content: center; text-align: center; background: #f6f7f9; border-radius: 8px; line-height: 1.8; }
.drawing-upload { margin-top: 8px; font-size: 14px; }
.drawing-upload summary { cursor: pointer; color: #0b62c4; }
.catpicker-majorall { font-weight: 600; border-bottom: 1px solid #eceef1; border-radius: 8px 8px 0 0 !important; margin-bottom: 4px; }
.upload-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.upload-form input[type=file] { font-size: 13px; max-width: 100%; }
.upload-row { display: flex; gap: 6px; align-items: center; }
.upload-row select { flex: 0 0 auto; }
.upload-row input[type=text] { flex: 1 1 auto; min-width: 0; }
.upload-row .btn { flex: 0 0 auto; }

/* home */
.home-title { font-size: 32px; margin: 8px 0 4px; }
.home-section { font-size: 20px; margin: 32px 0 14px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.home-card { display: block; background: #fff; border: 1px solid #e3e6ea; border-radius: 12px; padding: 22px 22px 20px; color: inherit; min-height: 160px; transition: box-shadow .15s, transform .15s; }
a.home-card:hover { text-decoration: none; box-shadow: 0 6px 18px rgba(15, 23, 42, .10); transform: translateY(-1px); }
.home-card-static { background: #fbfbfc; }
.home-icon { font-size: 28px; line-height: 1; margin-bottom: 14px; }
.home-name { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.home-desc { color: #4b5563; font-size: 15px; }
.home-stat { margin-top: 12px; color: #15803d; font-weight: 600; font-size: 14px; }
.nav .nav-off { color: #6b7a8c; padding: 8px 16px; font-size: 17px; cursor: default; }
.subnav { display: flex; gap: 4px; padding: 0 24px; background: #fff; border-bottom: 1px solid #e3e6ea; }
.subnav a { padding: 12px 14px; color: #374151; border-bottom: 3px solid transparent; }
.subnav a:hover { text-decoration: none; color: #0b62c4; }
.subnav a.on { color: #0b62c4; border-bottom-color: #0b62c4; font-weight: 600; }
.home-card-off { background: #fafafa; color: #9aa3ad; }
.home-card-off .home-desc { color: #9aa3ad; }
.home-soon { margin-top: 12px; display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 10px; background: #eef1f5; color: #6b7280; }

/* leaf part: info full width, BOM collapsed, big drawing below */
.detail-solo { margin-bottom: 8px; }
.detail-solo .card { margin-bottom: 0; }
.bom-add { margin: 18px 0 8px; }
.bom-add > summary { cursor: pointer; font-size: 20px; font-weight: 600; color: #0b62c4; list-style: none; }
.bom-add > summary::-webkit-details-marker { display: none; }
.bom-add[open] > summary { margin-bottom: 10px; }
.drawing-big .detail-drawings { padding: 16px; }
.drawing-big .drawing-main { min-height: 72vh; }
.drawing-big .drawing-empty { min-height: 220px; }
.drawing-big .drawing-thumbs a { width: 72px; height: 72px; }
.drawing-big .upload-form { max-width: 640px; }

/* login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #1f2a37; }
.login-box { width: 380px; background: #fff; border-radius: 10px; padding: 32px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.login-brand { font-size: 30px; font-weight: 700; margin-bottom: 20px; letter-spacing: 1px; }
.login-box label, .form-stack label { display: block; font-weight: 600; margin: 12px 0 6px; }
.login-box input[type=text], .login-box input[type=password], .form-stack input[type=password] { width: 100%; }
.login-btn { width: 100%; margin-top: 20px; padding: 10px; font-size: 17px; }
input[type=password], input[type=date] { font: inherit; padding: 7px 10px; border: 1px solid #cfd4da; border-radius: 6px; background: #fff; }
.pw-row { position: relative; }
.pw-row input { padding-right: 40px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; cursor: pointer; opacity: .45; font-size: 16px; }
.pw-eye.on { opacity: 1; }
.narrow { max-width: 520px; }

/* user menu */
.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; color: #e6ebf1; padding: 8px 14px; border-radius: 6px; font-size: 16px; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover, .user-menu[open] > summary { background: #2c3a4b; }
.user-menu-pop { position: absolute; right: 0; top: 44px; z-index: 50; min-width: 180px; background: #fff; border: 1px solid #e3e6ea; border-radius: 8px; box-shadow: 0 6px 20px rgba(15,23,42,.15); padding: 6px; }
.user-menu-pop a, .user-menu-pop button { display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 6px; color: #1f2328; font: inherit; font-size: 15px; background: none; border: 0; cursor: pointer; }
.user-menu-pop a:hover, .user-menu-pop button:hover { background: #f2f4f7; text-decoration: none; }
.user-menu-acc { padding: 6px 12px 8px; border-bottom: 1px solid #eceef1; margin-bottom: 4px; }

/* 用户与权限 */
.users-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .users-layout { grid-template-columns: 1fr; } }
.users-list { padding: 6px; max-height: calc(100vh - 160px); overflow: auto; }
.user-row { display: block; padding: 8px 10px; border-radius: 6px; color: inherit; }
.user-row:hover { background: #f2f4f7; text-decoration: none; }
.user-row.on { background: #e3f0fd; }
.user-row.left { opacity: .55; }
.user-name { font-weight: 600; }
.tag.admin { background: #e3f0fd; color: #0b4f9c; }
.staff-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; }
.staff-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: #4b5563; }
.staff-form .wide { grid-column: 1 / -1; }
.temp-pw { background: #fff8e1; border-color: #f2d27a; }
.temp-pw-value { font-size: 22px; letter-spacing: 2px; margin-left: 8px; user-select: all; }
.perm-table td { border-bottom: 1px solid #eceef1; }
.perm-name { width: 140px; font-weight: 600; }
.perm-opt { margin-right: 18px; white-space: nowrap; }
td.ua { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.static-field { padding: 7px 0; }

/* 修改记录 */
.history { margin: 26px 0 8px; }
.history > summary { cursor: pointer; font-size: 19px; font-weight: 600; margin-bottom: 10px; }
table.audit td { font-size: 15px; }
.nowrap { white-space: nowrap; }
.audit-change { line-height: 1.5; }
.audit-old { color: #9b1c1c; text-decoration: line-through; text-decoration-color: #e5a0a0; }
.tag.audit-INSERT { background: #e3f4e8; color: #166534; }
.tag.audit-UPDATE { background: #fdf3dc; color: #8a5a00; }
.tag.audit-DELETE { background: #fbe4e4; color: #9b1c1c; }
.audit-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* 库存 */
td.num, th.num { text-align: right; white-space: nowrap; }
tr.zero td { color: #9ca3af; }
.doc-head { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px; }
.doc-head label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: #4b5563; }
.doc-head .wide { grid-column: 1 / -1; }
@media (max-width: 900px) { .doc-head { grid-template-columns: 1fr 1fr; } }
.doc-lines input[type=text] { padding: 4px 8px; }
.bulk-add { margin: 14px 0; }
.bulk-add > summary { cursor: pointer; color: #0b62c4; font-weight: 600; margin-bottom: 8px; }
.bulk-add textarea { width: 100%; font-family: Consolas, "Courier New", monospace; font-size: 14px; box-sizing: border-box; }
.doc-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.tag.doc-DRAFT { background: #fdf3dc; color: #8a5a00; }
.tag.doc-POSTED { background: #e3f4e8; color: #166534; }
.tag.doc-CANCELLED { background: #eef1f5; color: #6b7280; text-decoration: line-through; }
.doc-no { font-size: 20px; }
.doc-kv { grid-template-columns: 90px 1fr 90px 1fr; }
tr.row-err td { background: #fdf1f1; }
.err-text { color: #b42318; }
@media print {
  .nav, .subnav, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .doc-sheet { border: 0; padding: 0; }
}
tr.neg td { background: #fdf1f1; color: #b42318; }
.neg-text { color: #b42318; }
.tag.tag-neg { background: #fbe4e4; color: #9b1c1c; }
.warn-box { background: #fff8e1; border-color: #f2d27a; }
.warn-box ul { margin: 8px 0 12px; }
