:root{
  --bg:#f4f6fb; --card:#ffffff; --line:#e5e9f2; --text:#1f2937; --muted:#6b7280;
  --primary:#4f46e5; --primary-weak:#eef2ff; --primary-dark:#4338ca;
  --green:#16a34a; --green-weak:#dcfce7;
  --amber:#b45309; --amber-weak:#fef3c7;
  --red:#dc2626; --red-weak:#fee2e2;
  --blue:#1d4ed8; --blue-weak:#dbeafe;
  --gray:#6b7280; --gray-weak:#f3f4f6;
  --radius:12px; --shadow:0 1px 3px rgba(15,23,42,.08);
}
*{box-sizing:border-box; margin:0; padding:0;}
body{font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif; background:var(--bg); color:var(--text); font-size:14px; line-height:1.55;}
button{font-family:inherit;}
input,select,textarea{font-family:inherit; font-size:14px; color:var(--text); background:#fff; border:1px solid var(--line); border-radius:8px; padding:8px 10px; outline:none; transition:border-color .15s, box-shadow .15s;}
input:focus,select:focus,textarea:focus{border-color:var(--primary); box-shadow:0 0 0 3px rgba(79,70,229,.12);}
input[type=number]{-moz-appearance:textfield;}
input[type=number]::-webkit-outer-spin-button,input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none; margin:0;}
label{display:block; font-size:13px; font-weight:600; margin-bottom:6px; color:#374151;}

.app{display:flex; min-height:100vh;}
.sidebar{width:220px; flex-shrink:0; background:#111827; color:#cbd5e1; padding:20px 14px; display:flex; flex-direction:column; gap:6px; position:sticky; top:0; height:100vh; overflow-y:auto;}
.brand{display:flex; align-items:center; gap:10px; padding:6px 10px 18px; color:#fff; font-size:16px; font-weight:700;}
.brand .logo{width:34px; height:34px; border-radius:9px; background:linear-gradient(135deg,#6366f1,#8b5cf6); display:flex; align-items:center; justify-content:center; font-size:18px;}
.nav-item{display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:9px; cursor:pointer; font-size:14px; color:#cbd5e1; border:none; background:transparent; text-align:left; width:100%; transition:background .15s,color .15s;}
.nav-item:hover{background:#1f2937; color:#fff;}
.nav-item.active{background:var(--primary); color:#fff; font-weight:600;}
.nav-item .ico{width:20px; text-align:center;}
.nav-group{border-radius:10px;overflow:hidden;}
.nav-group-title{justify-content:space-between;}
.nav-group-title .nav-label{display:flex;align-items:center;gap:10px;}
.nav-arrow{font-size:11px;transition:transform .18s;}
.nav-group.open .nav-arrow{transform:rotate(90deg);}
.nav-sub{display:none;padding:2px 0 4px 18px;}
.nav-group.open .nav-sub{display:block;}
.nav-sub .nav-item{padding:8px 10px;font-size:13px;}
.sidebar .foot{margin-top:auto; font-size:12px; color:#64748b; padding:12px 10px 0; border-top:1px solid #1f2937;}
.user-foot{display:flex;flex-direction:column;gap:7px;}
.user-foot b{color:#e5e7eb;font-size:13px;}
.user-foot button{color:#a5b4fc;border:0;background:transparent;text-align:left;cursor:pointer;padding:0;}

.main{flex:1; padding:26px 30px 60px; min-width:0;}
.page-head{display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:20px; flex-wrap:wrap;}
.page-head h1{font-size:22px; font-weight:700;}
.page-head .sub{color:var(--muted); font-size:13px; margin-top:4px;}
.head-actions{display:flex; gap:10px; flex-wrap:wrap;}

.btn{display:inline-flex; align-items:center; justify-content:center; gap:6px; border:1px solid var(--line); background:#fff; color:var(--text); border-radius:9px; padding:8px 16px; font-size:14px; cursor:pointer; transition:all .15s; white-space:nowrap;}
.btn:hover{border-color:#c7cede; background:#fafbfc;}
.btn-primary{background:var(--primary); border-color:var(--primary); color:#fff;}
.btn-primary:hover{background:var(--primary-dark); border-color:var(--primary-dark);}
.btn-danger{background:var(--red-weak); border-color:#fecaca; color:var(--red);}
.btn-danger:hover{background:#fecaca;}
.btn-ghost{background:transparent; border:none; color:var(--muted); padding:6px 8px;}
.btn-ghost:hover{background:var(--gray-weak); color:var(--text);}
.btn-sm{padding:5px 11px; font-size:13px; border-radius:7px;}
.btn:disabled{opacity:.5; cursor:not-allowed;}

.card{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow);}
.card .card-head{padding:14px 18px; border-bottom:1px solid var(--line); font-weight:600; display:flex; align-items:center; justify-content:space-between; gap:10px;}
.card .card-body{padding:16px 18px;}
.card .card-body.nopad{padding:0;}

.grid-stats{display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; margin-bottom:20px;}
.stat{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:16px 18px; box-shadow:var(--shadow);}
.stat .label{font-size:13px; color:var(--muted); margin-bottom:8px;}
.stat .value{font-size:26px; font-weight:700; letter-spacing:-.5px;}
.stat .value small{font-size:14px; font-weight:600; color:var(--muted);}
.stat .tip{font-size:12px; color:var(--muted); margin-top:6px;}
.stat.primary .value{color:var(--primary);}
.stat.green .value{color:var(--green);}
.stat.amber .value{color:var(--amber);}
.stat.red .value{color:var(--red);}.toolbar{display:flex; gap:10px; margin-bottom:14px; flex-wrap:wrap;}
.toolbar .search{flex:1; min-width:200px; max-width:380px; background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E"); background-repeat:no-repeat; background-position:10px center; padding-left:34px;}

table{width:100%; border-collapse:collapse; font-size:13.5px;}
thead th{background:#f8fafc; color:#475569; font-weight:600; text-align:left; padding:10px 14px; border-bottom:1px solid var(--line); white-space:nowrap; position:sticky; top:0;}
tbody td{padding:10px 14px; border-bottom:1px solid #eef1f6; vertical-align:middle;}
tbody tr:last-child td{border-bottom:none;}
tbody tr:hover{background:#fafbff;}
.tbl-wrap{overflow-x:auto;}
.tbl-empty{text-align:center; color:var(--muted); padding:36px 0;}
.tbl-empty .emoji{font-size:34px; display:block; margin-bottom:8px;}

.badge{display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:999px; font-size:12px; font-weight:600; white-space:nowrap;}
.badge.blue{background:var(--blue-weak); color:var(--blue);}
.badge.amber{background:var(--amber-weak); color:var(--amber);}
.badge.green{background:var(--green-weak); color:var(--green);}
.badge.red{background:var(--red-weak); color:var(--red);}
.badge.gray{background:var(--gray-weak); color:var(--gray);}

.text-muted{color:var(--muted);}
.text-right{text-align:right;}
.nowrap{white-space:nowrap;}
.mt16{margin-top:16px;}
.mt8{margin-top:8px;}
.mb12{margin-bottom:12px;}
.flex{display:flex; gap:10px; align-items:center; flex-wrap:wrap;}
.flex-between{display:flex; justify-content:space-between; align-items:center; gap:10px; flex-wrap:wrap;}

.modal-overlay{position:fixed; inset:0; background:rgba(15,23,42,.45); display:none; align-items:flex-start; justify-content:center; padding:40px 16px; z-index:100; overflow-y:auto;}
.modal-overlay.show{display:flex;}
.modal{background:#fff; border-radius:16px; width:100%; max-width:620px; box-shadow:0 20px 50px rgba(15,23,42,.25); animation:pop .18s ease;}
.modal.lg{max-width:820px;}
.modal.sm{max-width:440px;}
@keyframes pop{from{opacity:0; transform:translateY(10px) scale(.98);} to{opacity:1; transform:none;}}
.modal-head{padding:18px 22px; border-bottom:1px solid var(--line); display:flex; align-items:center; justify-content:space-between;}
.modal-head h3{font-size:16px;}
.modal-close{border:none; background:transparent; font-size:20px; color:var(--muted); cursor:pointer; padding:4px; line-height:1;}
.modal-close:hover{color:var(--text);}
.modal-body{padding:20px 22px; max-height:65vh; overflow-y:auto;}
.modal-foot{padding:14px 22px; border-top:1px solid var(--line); display:flex; justify-content:flex-end; gap:10px;}
.form-grid{display:grid; grid-template-columns:1fr 1fr; gap:14px;}
.form-grid .full{grid-column:1 / -1;}
.field-hint{font-size:12px; color:var(--muted); margin-top:5px;}
.product-image-upload{width:100%; height:190px; margin-top:6px; padding:0; border:1.5px dashed #cbd5e1; border-radius:8px; background:#f8fafc; color:var(--muted); cursor:pointer; overflow:hidden; display:flex; align-items:center; justify-content:center; transition:border-color .16s, background .16s, box-shadow .16s;}
.product-image-upload:hover{border-color:var(--primary); background:var(--primary-weak);}
.product-image-upload:focus-visible{outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(79,70,229,.16);}
.product-image-upload.has-image{border-style:solid; background:#fff;}
.product-image-upload img{width:100%; height:100%; object-fit:contain; display:none;}
.product-image-upload.has-image img{display:block;}
.product-image-upload.has-image .product-image-empty{display:none;}
.product-image-empty{display:flex; flex-direction:column; align-items:center; gap:7px; font-size:13px;}
.product-image-plus{width:42px; height:42px; border-radius:50%; display:grid; place-items:center; background:var(--primary); color:#fff; font-size:30px; font-weight:300; line-height:1;}
.product-image-empty small{font-size:12px; color:#94a3b8;}
.product-image-actions{display:none; gap:8px; align-items:center; margin-top:8px;}
.product-image-actions.show{display:flex;}
.product-image-actions .btn{padding:6px 10px; font-size:12px;}
.product-thumb{width:42px;height:42px;padding:0;border:1px solid var(--line);border-radius:6px;background:#fff;overflow:hidden;cursor:zoom-in;display:block;}
.product-thumb:hover{border-color:var(--primary);box-shadow:0 0 0 2px rgba(79,70,229,.12);}
.product-thumb img{width:100%;height:100%;object-fit:cover;display:block;}
.product-image-preview{display:flex;align-items:center;justify-content:center;min-height:260px;background:#f8fafc;border:1px solid var(--line);border-radius:8px;overflow:hidden;}
.product-image-preview img{display:block;max-width:100%;max-height:58vh;object-fit:contain;}
.segmented{display:inline-flex; padding:3px; border:1px solid var(--line); border-radius:8px; background:#f8fafc; gap:3px;}
.segmented button{border:0; border-radius:6px; background:transparent; color:var(--muted); padding:7px 14px; cursor:pointer; font-size:13px;}
.segmented button.active{background:#fff; color:var(--primary); font-weight:600; box-shadow:0 1px 3px rgba(15,23,42,.12);}
.warehouse-stock-editor{border:1px solid var(--line); border-radius:8px; overflow:hidden;}
.warehouse-stock-row{display:grid; grid-template-columns:minmax(140px,1fr) auto 140px; gap:12px; align-items:center; padding:9px 12px; border-bottom:1px solid #eef1f6;}
.warehouse-stock-row:last-child{border-bottom:none;}
.warehouse-stock-row .name{font-weight:600;}
.warehouse-stock-row input{text-align:right; width:100%;}
.warehouse-listing-toggle{display:flex;align-items:center;gap:7px;margin:0;font-weight:500;white-space:nowrap;}
.warehouse-listing-toggle input{width:16px;height:16px;accent-color:var(--primary);}
.order-group-start td{border-top:2px solid #dbe2ee;}
.linked-orders{margin-top:16px;padding-top:14px;border-top:1px solid var(--line);}
.linked-orders h4{font-size:14px;margin-bottom:8px;}
.dimension-grid{display:grid; grid-template-columns:repeat(3,1fr); gap:10px;}
.dimension-grid label{font-weight:500; color:var(--muted);}
.stock-breakdown{font-size:12px; color:var(--muted); margin-top:3px; max-width:260px; white-space:normal;}
.follow-list{display:flex; flex-direction:column; gap:10px; margin-bottom:16px;}
.follow-item{border-left:3px solid var(--primary); background:#f8fafc; padding:10px 12px; border-radius:0 6px 6px 0;}
.follow-item .meta{font-size:12px; color:var(--muted); margin-top:5px;}
.follow-form{border-top:1px solid var(--line); padding-top:14px;}
.follow-form textarea{width:100%; min-height:82px; resize:vertical;}
.source-order-picker{max-height:150px; overflow:auto; border:1px solid var(--line); border-radius:8px; background:#fff;}
.source-order-option{display:flex; align-items:center; gap:9px; padding:8px 10px; border-bottom:1px solid #eef1f6; cursor:pointer; font-weight:400; margin:0;}
.source-order-option:last-child{border-bottom:none;}
.source-order-option:hover{background:#f8fafc;}
.source-order-option input,.order-select{width:16px; height:16px; accent-color:var(--primary);}
.selection-actions{display:flex; align-items:center; gap:10px; margin-left:auto;}
.delivery-item-row{display:grid; grid-template-columns:1.6fr .6fr auto; gap:8px; align-items:center; margin-bottom:8px;}
.product-choice{min-height:38px;border:1px solid var(--line);border-radius:8px;background:#f8fafc;padding:8px 10px;display:flex;align-items:center;justify-content:space-between;gap:8px;min-width:0;}
.product-choice .product-choice-main{min-width:0;}
.product-choice .product-choice-name{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.product-choice .product-choice-meta{font-size:11px;color:var(--muted);}
.product-picker-overlay{position:fixed;inset:0;background:rgba(15,23,42,.58);display:none;align-items:flex-start;justify-content:center;padding:32px 16px;z-index:180;overflow:auto;}
.product-picker-overlay.show{display:flex;}
.product-picker{width:min(920px,100%);background:#fff;border-radius:16px;box-shadow:0 24px 60px rgba(15,23,42,.28);}
.product-picker-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(245px,1fr));gap:10px;max-height:46vh;overflow:auto;padding:2px;}
.product-picker-card{display:flex;gap:10px;align-items:flex-start;border:1px solid var(--line);border-radius:10px;padding:11px;cursor:pointer;background:#fff;}
.product-picker-card:hover,.product-picker-card.selected{border-color:var(--primary);background:var(--primary-weak);}
.product-picker-card input{width:17px;height:17px;accent-color:var(--primary);margin-top:2px;}
.product-picker-card .name{font-weight:600;}
.product-picker-card .meta{font-size:12px;color:var(--muted);margin-top:2px;}
.quick-product-form{display:none;background:#f8fafc;border:1px solid var(--line);border-radius:10px;padding:12px;margin:12px 0;}
.quick-product-form.show{display:block;}
.login-screen{position:fixed;inset:0;z-index:300;background:linear-gradient(135deg,#111827,#312e81);display:flex;align-items:center;justify-content:center;padding:20px;}
.login-card{width:min(430px,100%);background:#fff;border-radius:18px;padding:30px;box-shadow:0 30px 70px rgba(0,0,0,.3);}
.login-card h1{font-size:23px;margin-bottom:5px;}
.login-card .login-sub{color:var(--muted);margin-bottom:22px;}
.login-card .login-field{margin-bottom:14px;}
.login-card input{width:100%;padding:11px 12px;}
.login-card .btn{width:100%;padding:11px;}
.login-tip{font-size:12px;color:var(--muted);margin-top:14px;background:#f8fafc;border-radius:8px;padding:10px;}
.inventory-filter{display:grid;grid-template-columns:repeat(4,minmax(150px,1fr));gap:10px;align-items:end;}
.download-fab{position:fixed;right:24px;bottom:22px;z-index:55;box-shadow:0 8px 24px rgba(79,70,229,.24);}
@media(max-width:900px){.inventory-filter{grid-template-columns:1fr 1fr}.product-picker-list{grid-template-columns:1fr}}
@media (max-width:640px){.dimension-grid{grid-template-columns:1fr}.warehouse-stock-row{grid-template-columns:1fr}.segmented{width:100%}.segmented button{flex:1}}

.order-item-row{display:grid; grid-template-columns:1.6fr .6fr .8fr auto; gap:8px; align-items:end; margin-bottom:8px;}
.order-item-row.sale-item-row,.order-item-row.purchase-item-row{grid-template-columns:minmax(185px,1.35fr) 72px 100px 96px 132px auto;min-width:720px;}
#businessOrderItemsBox{overflow-x:auto;padding-bottom:2px;}
.order-item-field{display:flex; flex-direction:column; gap:4px; min-width:0;}
.order-item-field label{font-size:12px; line-height:1.2; font-weight:500; color:var(--muted); margin:0;}
.order-item-field input{width:100%;}
.items-total{margin-top:10px; text-align:right; font-size:15px;}
.items-total b{color:var(--primary); font-size:19px;}
.accessory-editor{border:1px solid var(--line);border-radius:10px;overflow:hidden;background:#fff;}
.accessory-row{padding:12px;border-bottom:1px solid #eef1f6;}
.accessory-row:last-child{border-bottom:0;}
.accessory-row-grid{display:grid;grid-template-columns:1.2fr 1fr .8fr .8fr .55fr .7fr auto;gap:8px;align-items:end;}
.accessory-row-grid label{font-size:11px;color:var(--muted);font-weight:500;}
.accessory-row-grid input{width:100%;}
.accessory-check{display:flex;align-items:center;gap:7px;margin:0 0 8px;font-weight:500;white-space:nowrap;}
.accessory-check input{width:16px;height:16px;accent-color:var(--primary);}
.accessory-plan{display:grid;grid-template-columns:1.35fr .45fr .58fr .78fr 1fr;gap:10px;align-items:end;padding:10px 0;border-bottom:1px solid #eef1f6;}
.accessory-plan:last-child{border-bottom:0;}
.contract-preview{background:#f8fafc;border:1px solid var(--line);border-radius:9px;padding:10px 12px;font-size:12px;line-height:1.7;}
@media(max-width:900px){.accessory-row-grid{grid-template-columns:1fr 1fr}.accessory-row-grid .accessory-check,.accessory-row-grid .accessory-remove{grid-column:auto}.accessory-plan{grid-template-columns:1fr}}

.dash-cols{display:grid; grid-template-columns:1.4fr 1fr; gap:16px; align-items:start;}
@media (max-width:1100px){.dash-cols{grid-template-columns:1fr;}}
.mini-list .row{display:flex; align-items:center; gap:12px; padding:10px 4px; border-bottom:1px solid #eef1f6;}
.mini-list .row:last-child{border-bottom:none;}
.mini-list .name{flex:1; min-width:0;}
.mini-list .name .t{font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.mini-list .name .s{font-size:12px; color:var(--muted);}

.toast-wrap{position:fixed; top:18px; left:50%; transform:translateX(-50%); z-index:200; display:flex; flex-direction:column; gap:8px; align-items:center;}
.toast{background:#111827; color:#fff; padding:10px 18px; border-radius:10px; font-size:14px; box-shadow:0 8px 24px rgba(15,23,42,.25); animation:slideDown .2s ease; display:flex; gap:8px; align-items:center;}
.toast.warn{background:#b45309;}
.toast.error{background:#dc2626;}
.toast.ok{background:#15803d;}
@keyframes slideDown{from{opacity:0; transform:translateY(-8px);} to{opacity:1; transform:none;}}

.detail-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:12px; margin-bottom:16px;}
.detail-item{background:#f8fafc; border:1px solid var(--line); border-radius:10px; padding:10px 14px;}
.detail-item .k{font-size:12px; color:var(--muted); margin-bottom:4px;}
.detail-item .v{font-weight:600;}

.setting-row{display:flex; align-items:center; justify-content:space-between; gap:16px; padding:16px 0; border-bottom:1px solid #eef1f6;}
.setting-row:last-child{border-bottom:none;}
.setting-row .t{font-weight:600;}
.setting-row .s{font-size:12.5px; color:var(--muted); margin-top:2px; max-width:520px;}
.btn-ghost{background:transparent; border:1px solid var(--line); color:var(--primary);}
.btn-ghost:hover{background:var(--primary-weak);}
.detail-wrap{max-height:62vh; overflow:auto; padding-right:4px;}
.detail-row{display:flex; gap:12px; padding:9px 0; border-bottom:1px solid #eef1f6; font-size:13.5px;}
.detail-row:last-child{border-bottom:none;}
.detail-k{flex:0 0 150px; color:var(--muted); font-size:12.5px; padding-top:1px;}
.detail-v{flex:1; word-break:break-all; white-space:pre-wrap;}
.detail-v a{color:var(--primary);}

/* ── A1 补丁（登录页两个 view 复用 .login-card；hidden 属性优先级） ── */
[hidden]{display:none !important;}
.login-screen{display:flex;align-items:center;justify-content:center;}
.login-card a{color:inherit;}
