:root {
  --paper: #f5f2eb;
  --surface: #fffefb;
  --ink: #1c2520;
  --muted: #68746c;
  --line: #dde2da;
  --nav: #173c32;
  --accent: #dd6b2f;
  --accent-dark: #b34d1b;
  --blue: #2f6f8c;
  --red: #b9413c;
  --green: #34785b;
  --shadow: 0 16px 45px rgba(39, 51, 43, .08);
  --font-ui: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
button, input, select { font: inherit; }
a { color: var(--accent-dark); text-decoration: none; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 26px 18px 18px; color: #f7fbf8; background: var(--nav); }
.brand, .login-brand { display: flex; align-items: center; gap: 12px; }
.brand { padding: 0 10px 25px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark, .login-brand > span { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: white; font-family: Georgia, serif; font-weight: 700; background: var(--accent); }
.brand strong, .brand small, .login-brand strong, .login-brand small, .sidebar-foot strong, .sidebar-foot small { display: block; }
.brand strong { font-family: var(--font-ui); font-size: 18px; }
.brand small, .sidebar-foot small { margin-top: 4px; color: #a9c2b8; }
.sidebar nav { display: grid; gap: 3px; margin-top: 22px; }
.nav-link { padding: 11px 13px; border-radius: 10px; color: #cddbd5; transition: .18s ease; }
.nav-link:hover, .nav-link.active { color: white; background: rgba(255,255,255,.1); transform: translateX(2px); }
.nav-link.active { box-shadow: inset 3px 0 var(--accent); }
.sidebar-foot { margin-top: auto; padding: 16px 10px 0; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid rgba(255,255,255,.12); }
.account-actions { display: flex; align-items: center; gap: 10px; }
.account-actions form { margin: 0; }
.account-actions a { text-decoration: none; }
.account-password-form { max-width: 980px; }
.text-button { padding: 0; border: 0; color: #f5a478; background: transparent; cursor: pointer; }

.main { min-width: 0; padding: 30px 34px 60px; }
.topbar { display: flex; justify-content: space-between; align-items: end; margin-bottom: 25px; }
.topbar h1 { margin: 4px 0 0; font: 700 30px/1.2 var(--font-ui); }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .18em; }
.today { padding: 8px 12px; border: 1px solid var(--line); border-radius: 20px; color: var(--muted); background: rgba(255,255,255,.55); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 15px; margin-bottom: 18px; }
.metric-grid.single { grid-template-columns: minmax(260px, 1fr) 3fr; }
.metric { position: relative; overflow: hidden; min-height: 140px; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.metric::after { content: ""; position: absolute; right: -22px; bottom: -30px; width: 95px; height: 95px; border-radius: 50%; background: currentColor; opacity: .08; }
.metric span, .metric small, .panel-head span { display: block; color: var(--muted); }
.metric strong { display: block; margin: 17px 0 8px; font: 700 27px/1 var(--font-ui); }
.metric.orange { color: var(--accent); } .metric.blue { color: var(--blue); } .metric.red { color: var(--red); } .metric.green { color: var(--green); }

.two-col { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.panel { margin-bottom: 18px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.panel h2, .panel-head h2 { margin: 0; font: 700 19px/1.3 var(--font-ui); }
.panel-head span { font-size: 13px; }
.create-panel summary { cursor: pointer; color: var(--accent-dark); font-weight: 700; }
.create-panel[open] summary { margin-bottom: 18px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 11px; text-align: left; white-space: nowrap; border-bottom: 1px solid #e9ede7; font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; letter-spacing: .02em; background: #f8f8f4; }
tbody tr:hover { background: #fbf8f2; }
tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.amount-due { color: var(--red); font-weight: 700; }
.qty-in { color: var(--green); font-weight: 700; } .qty-out { color: var(--red); font-weight: 700; }
.stock-negative { display: inline-block; padding: 4px 8px; border-radius: 7px; color: var(--red); background: #fff0ef; }
.stock-zero { display: inline-block; padding: 4px 8px; border-radius: 7px; color: var(--muted); background: #f0f2ed; }
.badge { display: inline-block; padding: 4px 8px; border-radius: 20px; color: var(--green); background: #e9f4ed; font-size: 12px; }
.settled { color: var(--green); font-weight: 700; }

.form-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 15px; margin-top: 15px; }
.form-grid.compact { margin-top: 0; }
.form-grid label, .stack-form label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.order-header-grid > label { align-content: start; }
.salesperson-field small { color: var(--green); font-size: 11px; }
.span-3 { grid-column: span 3; }
input, select { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid #ccd4ca; border-radius: 9px; color: var(--ink); background: white; }
input:focus, select:focus { outline: 3px solid rgba(221,107,47,.13); border-color: var(--accent); }
.form-actions { display: flex; align-items: end; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 9px 15px; border: 0; border-radius: 9px; cursor: pointer; }
.button.primary { color: white; background: var(--accent); box-shadow: 0 8px 18px rgba(221,107,47,.2); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { color: var(--nav); border: 1px solid #bfd0c8; background: #eef4f1; }
.button.ghost { color: var(--muted); border: 1px solid var(--line); background: white; }
.button.small { min-height: 34px; padding: 7px 11px; color: white; background: var(--green); }
.button.table-button { min-height: 30px; padding: 5px 10px; color: var(--nav); border: 1px solid #c8d7d0; background: #f0f5f2; font-size: 12px; }
.wide { width: 100%; }
.page-actions { display: flex; justify-content: flex-end; margin: -8px 0 14px; }
.panel-head-actions { display: flex; align-items: center; gap: 12px; }
.sales-entry-actions { justify-content: flex-start; gap: 10px; }
.sales-entry-button { min-width: 112px; color: white; font-weight: 700; box-shadow: 0 8px 18px rgba(39,51,43,.12); }
.sales-entry-button.entity-yatai { background: var(--accent); }
.sales-entry-button.entity-dequan { background: var(--blue); }
.sales-entry-button.entity-beads { background: var(--green); }
.sales-entity-tabs { display: flex; gap: 8px; margin-bottom: 16px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.62); }
.sales-entity-tab { display: inline-flex; align-items: center; gap: 8px; padding: 10px 15px; border-radius: 8px; color: var(--muted); font-weight: 700; }
.sales-entity-tab span { min-width: 22px; padding: 2px 7px; border-radius: 20px; text-align: center; color: var(--muted); background: #edf0eb; font-size: 11px; }
.sales-entity-tab.active { color: white; background: var(--nav); }
.sales-entity-tab.active span { color: var(--nav); background: white; }
.sales-list-tools { display: flex; align-items: stretch; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.sales-list-tools .sales-entity-tabs { align-self: flex-start; margin-bottom: 0; }
.sales-status-filter { display: flex; align-items: end; gap: 8px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.62); }
.sales-status-filter label { display: grid; gap: 3px; color: var(--muted); font-size: 11px; }
.sales-status-filter select { width: 132px; min-height: 34px; padding: 5px 8px; }
.sales-status-filter .button { min-height: 34px; padding: 6px 11px; }
.sales-order-filters { width: 100%; flex-wrap: wrap; padding: 10px; align-items: flex-start; }
.sales-order-filters > .button { margin-top: 17px; }
.sales-order-filters .customer-filter-field { min-width: 260px; }
.sales-order-filters .customer-filter-name { width: 260px; min-height: 34px; padding: 5px 8px; }
.sales-order-filters .matched-customer { max-width: 260px; margin-top: 1px; line-height: 1.25; }
.sales-order-filters .sku-filter-input { width: 170px; min-height: 34px; padding: 5px 8px; }
.sales-order-filters input[type="date"] { width: 150px; min-height: 34px; padding: 5px 8px; }
.sales-order-filters .export-orders-button { margin-left: auto; color: white; }
.order-status-form { display: none; }
.order-status-cell { display: flex; align-items: center; gap: 6px; min-width: 100px; }
.order-status-cell select { width: 100%; min-width: 96px; min-height: 32px; padding: 4px 7px; border-radius: 7px; font-size: 12px; }
.invoice-status-cell { min-width: 146px; }
.invoice-status-cell .button { flex: 0 0 auto; white-space: nowrap; }
.completion-badge { display: inline-flex; align-items: center; justify-content: center; min-height: 30px; padding: 4px 8px; border-radius: 7px; color: white; background: var(--green); font-size: 12px; }
.order-detail-actions { gap: 8px; }
.order-detail-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.order-detail-grid > div { padding: 13px 14px; border-radius: 10px; background: #f5f6f2; }
.order-detail-grid small, .order-detail-grid strong { display: block; }
.order-detail-grid small { margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.order-detail-grid strong { font-size: 14px; }
.shipment-create .panel-head p, .order-complete-panel p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.shipment-table { min-width: 760px; }
.shipment-table td:first-child { white-space: normal; }
.shipment-table td:first-child strong, .shipment-table td:first-child small { display: block; }
.shipment-table td:first-child small { margin-top: 4px; color: var(--muted); }
.shipment-table input[type="number"] { width: 100px; min-height: 34px; }
.shipment-meta { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 14px; padding: 16px 0 0; }
.shipment-meta label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.shipment-record { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 10px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcf9; }
.shipment-record:last-child { margin-bottom: 0; }
.shipment-record strong, .shipment-record small { display: block; }
.shipment-record small { margin-top: 5px; color: var(--muted); font-size: 12px; }
.shipment-record > span { color: var(--blue); font-size: 12px; text-align: right; }
.order-complete-panel { display: flex; align-items: center; justify-content: space-between; gap: 18px; border-color: #bfdac9; background: #f3faf5; }
.order-complete-panel h2 { color: var(--green); }
.row-actions { display: flex; align-items: center; gap: 10px; }
.row-actions form { margin: 0; }
.link-danger { padding: 0; border: 0; color: var(--red); background: transparent; cursor: pointer; }
.icon-button { width: 32px; height: 32px; border: 1px solid #ebc9c6; border-radius: 8px; color: var(--red); background: #fff4f3; cursor: pointer; }
.bulk-delete-form { margin: 0; }
.bulk-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding: 11px 13px; border-radius: 10px; background: #f5f6f2; }
.bulk-select-all { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; cursor: pointer; }
.bulk-delete-form input[type="checkbox"] { width: 18px; min-height: 18px; margin: 0; padding: 0; accent-color: var(--nav); cursor: pointer; }
.product-select { display: block; margin: 0 auto !important; }
.bulk-selected-count { color: var(--muted); font-size: 13px; }
.bulk-delete-button { min-height: 34px; margin-left: auto; padding: 7px 13px; color: white; background: var(--red); }
.bulk-delete-button:disabled { opacity: .42; cursor: not-allowed; }
.bulk-invoice-form { margin: 0; }
.invoice-bulk-toolbar { flex-wrap: wrap; }
.bulk-invoice-choice { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--muted); font-size: 13px; }
.bulk-invoice-choice select { width: 112px; min-height: 34px; padding: 5px 8px; }
.bulk-invoice-form input[type="checkbox"] { width: 18px; min-height: 18px; margin: 0; padding: 0; accent-color: var(--nav); cursor: pointer; }
.sales-order-select { display: block; margin: 0 auto !important; }
.bulk-invoice-form [data-bulk-submit]:disabled { opacity: .42; cursor: not-allowed; }
.inventory-bulk-form { margin: 0; }
.inventory-bulk-toolbar { flex-wrap: wrap; }
.inventory-bulk-form input[type="checkbox"] { width: 18px; min-height: 18px; margin: 0; padding: 0; accent-color: var(--nav); cursor: pointer; }
.inventory-row-select { display: block; margin: 0 auto !important; }
.inventory-bulk-reason { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--muted); font-size: 13px; }
.inventory-bulk-reason input { width: 240px; min-height: 34px; padding: 6px 9px; }
.inventory-bulk-submit:disabled { opacity: .42; cursor: not-allowed; }
.inventory-target { display: flex; align-items: center; gap: 7px; min-width: 126px; }
.inventory-target input { width: 88px; min-height: 36px; padding: 6px 8px; }
.inventory-target span { color: var(--muted); font-size: 12px; white-space: nowrap; }

.items-table { min-width: 840px; table-layout: fixed; }
.items-table .item-product-col { width: 29%; }
.items-table .item-number-col { width: 19%; }
.items-table .item-amount-col { width: 8%; }
.items-table .item-remark-col { width: 20%; }
.items-table .item-action-col { width: 44px; }
.items-table tbody td { vertical-align: top; }
.items-table input { min-width: 0; }
.items-table .product-code { min-width: 0; }
.product-match-cell { white-space: normal; }
.matched-product { display: block; margin-top: 5px; color: var(--green); font-size: 11px; }
.matched-product.invalid { color: var(--red); }
.matched-customer { display: block; margin-top: 5px; color: var(--green); font-size: 11px; }
.matched-customer.invalid { color: var(--red); }
.items-table input[name="item_remark"] { min-width: 0; }
.items-table input[type="number"] { min-width: 0; }
.locked-item-note { color: var(--muted); font-size: 11px; }
.items-table input:disabled { color: var(--muted); background: #f2f3ef; cursor: not-allowed; }
.line-amount { padding-top: 25px; font-weight: 700; }
.order-total { padding: 18px 12px 2px; text-align: right; color: var(--muted); }
.order-total strong { margin-left: 15px; color: var(--ink); font: 700 24px var(--font-ui); }
.sticky-actions { position: sticky; bottom: 14px; display: flex; justify-content: flex-end; gap: 10px; width: max-content; margin: 18px 0 0 auto; padding: 9px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,254,251,.92); box-shadow: var(--shadow); backdrop-filter: blur(8px); }
.settle-form { display: grid; grid-template-columns: 90px 130px 130px auto; gap: 6px; align-items: center; }
.settle-form input, .settle-form select { min-height: 34px; padding: 6px 8px; }
.cell-actions { display: flex; align-items: center; gap: 8px; }
.form-note { margin: 16px 0 0; padding: 11px 13px; border-radius: 9px; color: var(--muted); background: #f5f6f2; font-size: 13px; }
.import-guide { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.import-guide span { padding: 5px 9px; border-radius: 20px; color: var(--green); background: #e9f4ed; font-size: 12px; }
.import-form { display: grid; grid-template-columns: minmax(260px, 1fr) auto; align-items: end; gap: 16px; }
.import-form label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.import-form input[type="file"] { padding: 7px; }
.import-actions { display: flex; gap: 8px; }
.filter-form { display: flex; align-items: end; gap: 14px; }
.filter-form label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.filter-form input { min-width: 170px; }
.filter-form select { min-width: 170px; }
.inventory-search, .product-search, .customer-search { margin: 0 0 18px; padding: 14px; border-radius: 10px; background: #f5f6f2; }
.profit-positive { color: var(--green); }
.profit-negative { color: var(--red); }
.pagination-wrap { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px; padding: 18px 4px 2px; border-top: 1px solid var(--line); }
.page-summary { color: var(--muted); font-size: 13px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; }
.page-button { min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; border: 1px solid #d6ddd4; border-radius: 8px; color: var(--ink); background: white; font-size: 13px; }
.page-button:hover { border-color: var(--accent); color: var(--accent-dark); }
.page-button.active { color: white; border-color: var(--nav); background: var(--nav); }
.page-button.disabled { pointer-events: none; opacity: .4; }
.page-ellipsis { color: var(--muted); }
.page-jump { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.page-jump label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.page-jump input { width: 66px; min-height: 32px; padding: 5px 7px; text-align: center; }

.alert { margin-bottom: 18px; padding: 12px 15px; border-radius: 10px; color: #256144; background: #e6f3eb; border: 1px solid #cce5d7; }
.alert.error { color: #862f2b; background: #fff0ef; border-color: #efcdca; }
.error-state { padding: 42px; text-align: center; }
.error-state > span { color: var(--red); }
.error-state h2 { margin: 12px 0 24px; font-family: var(--font-ui); font-size: 24px; letter-spacing: 0; word-break: break-word; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 20% 20%, rgba(221,107,47,.2), transparent 30%), linear-gradient(135deg,#173c32 0 45%,#f5f2eb 45%); }
.login-card { width: min(430px,100%); padding: 38px; border-radius: 24px; background: rgba(255,254,251,.96); box-shadow: 0 30px 80px rgba(10,35,28,.28); }
.login-brand strong { font: 700 19px var(--font-ui); }
.login-brand small { color: var(--muted); margin-top: 3px; }
.login-card h1 { margin: 34px 0 7px; font: 700 31px var(--font-ui); }
.login-card > p { margin: 0 0 22px; color: var(--muted); }
.stack-form { display: grid; gap: 16px; }
.login-tip { margin-top: 18px; padding: 11px; border-radius: 9px; color: var(--muted); text-align: center; font-size: 12px; background: #f3f1ea; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { display: flex; overflow-x: auto; }
  .nav-link { white-space: nowrap; }
  .sidebar-foot { margin-top: 18px; }
  .metric-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .main { padding: 22px 14px 50px; }
  .topbar { align-items: start; }
  .today { display: none; }
  .metric-grid, .metric-grid.single, .form-grid { grid-template-columns: 1fr; }
  .span-3 { grid-column: auto; }
  .settle-form { grid-template-columns: 1fr 1fr; }
  .import-form { grid-template-columns: 1fr; }
  .import-actions { flex-wrap: wrap; }
  .filter-form { display: grid; grid-template-columns: 1fr; }
  .pagination-wrap { grid-template-columns: 1fr; justify-items: center; }
  .page-jump { justify-content: center; }
  .pagination { flex-wrap: wrap; }
  .panel-head-actions, .sales-entry-actions, .sales-entity-tabs { flex-wrap: wrap; }
  .sales-list-tools { align-items: stretch; flex-direction: column; }
  .sales-status-filter { align-self: flex-start; }
  .order-detail-grid { grid-template-columns: 1fr 1fr; }
  .shipment-meta { grid-template-columns: 1fr; }
  .shipment-record, .order-complete-panel { align-items: flex-start; flex-direction: column; }
  .shipment-record > span { text-align: left; }
  .sales-entry-button, .sales-entity-tab { flex: 1 1 120px; }
  .login-page { background: var(--nav); }
}
