:root {
  --ink: #17221e;
  --muted: #64716b;
  --line: #d8dfdb;
  --line-strong: #b9c5bf;
  --surface: #ffffff;
  --canvas: #f3f5f3;
  --soft: #edf1ee;
  --primary: #1f5b47;
  --primary-strong: #174534;
  --accent: #b9603a;
  --warn: #9a6700;
  --danger: #a63a37;
  --info: #2e6483;
  --shadow: 0 12px 30px rgba(23, 34, 30, 0.12);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--canvas); font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #e9eeeb; }
.auth-panel { width: min(420px, 100%); padding: 34px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.auth-brand, .brand { display: flex; align-items: center; gap: 12px; }
.auth-brand { margin-bottom: 32px; }
.auth-brand b, .brand b { display: block; font-size: 16px; }
.auth-brand small, .brand small { display: block; color: var(--muted); margin-top: 3px; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; background: var(--primary); color: white; font: 700 22px/1 Georgia, serif; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.brand-mark.small { width: 36px; height: 36px; font-size: 18px; }
.auth-panel h1 { margin: 0 0 6px; font-size: 24px; }
.auth-panel > p { color: var(--muted); margin: 0 0 24px; }
.auth-panel label { display: grid; gap: 7px; margin: 0 0 16px; color: #35423c; font-weight: 600; }
.inline-error { color: var(--danger); background: #fff0ef; border: 1px solid #efc4c2; padding: 10px 12px; margin-top: 14px; border-radius: 5px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 224px; display: flex; flex-direction: column; background: #132a22; color: #edf5f0; border-right: 1px solid #0d211a; z-index: 20; }
.brand { min-height: 76px; padding: 16px 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand small { color: #a9bbb3; }
.sidebar nav { display: grid; align-content: start; gap: 3px; padding: 14px 10px; overflow-y: auto; }
.sidebar nav button { display: flex; align-items: center; min-height: 42px; width: 100%; padding: 8px 12px; color: #c7d5cf; background: transparent; border: 0; border-radius: 5px; text-align: left; }
.sidebar nav button b { font-size: 14px; }
.sidebar nav button:hover { background: rgba(255,255,255,.07); color: white; }
.sidebar nav button.active { background: #2d614f; color: white; }
.nav-children { display: none; padding: 2px 0 5px 18px; }
.nav-group.open .nav-children { display: grid; gap: 1px; }
.sidebar nav .nav-children button { min-height: 30px; padding: 5px 8px; color: #9fb3aa; font-size: 12px; }
.sidebar nav .nav-children button.active { color: white; background: rgba(255,255,255,.1); }
.sidebar-foot { margin-top: auto; min-height: 58px; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid rgba(255,255,255,.1); color: #c7d5cf; }
.text-button { border: 0; background: transparent; color: #d7e2dd; padding: 6px; }

.workspace { grid-column: 2; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 15; height: 76px; display: flex; align-items: center; gap: 14px; padding: 0 28px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); }
.page-heading h1 { margin: 0; font-size: 20px; }
.page-heading p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#menuButton { display: none; }
main { padding: 24px 28px 56px; }
.view { display: none; }
.view.active { display: block; }

.section-head, .subsection-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 16px; }
.section-head h2, .subsection-head h3, .content-section h2 { margin: 0; font-size: 17px; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.content-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.split-layout, .settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; }
.split-layout .content-section, .settings-grid .content-section { min-width: 0; }

.button, .icon-button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); padding: 7px 12px; text-decoration: none; white-space: nowrap; }
.button:hover, .icon-button:hover { border-color: #87958e; background: #f8faf8; }
.button.primary { color: white; background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-strong); }
.button.danger { color: var(--danger); border-color: #d8aaa8; background: #fff8f7; }
.button.small { min-height: 30px; padding: 4px 8px; font-size: 12px; }
.button.wide { width: 100%; min-height: 42px; }
.icon-button { width: 36px; padding: 0; font-size: 20px; }
button:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea { width: 100%; min-height: 38px; padding: 8px 10px; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: 4px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,91,71,.1); }
textarea { min-height: 84px; resize: vertical; }
.filterbar { display: grid; grid-template-columns: minmax(150px, 220px) minmax(220px, 1fr) auto; gap: 8px; margin-bottom: 14px; }
.query-panel { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; padding: 13px; background: #eef2ef; border: 1px solid var(--line); border-radius: 6px; }
.query-fields { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.query-fields label { display: grid; gap: 5px; min-width: 0; color: #46534d; font-size: 12px; font-weight: 700; }
.query-fields input, .query-fields select { min-width: 0; background: white; }
.query-actions { display: flex; gap: 7px; padding-bottom: 1px; }
.pagination-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; color: var(--muted); }
.pagination-actions { display: flex; align-items: center; gap: 7px; }
.pagination-actions label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pagination-actions select { width: 72px; min-height: 32px; padding: 4px 7px; }
.loading-row { color: var(--primary); }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(135px, 1fr)); gap: 10px; }
.metric { min-height: 102px; padding: 15px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 10px; font-size: 24px; line-height: 1; }
.metric small { display: block; color: var(--muted); margin-top: 8px; }
.metric.attention { border-top: 3px solid var(--accent); }
.metric.info { border-top: 3px solid var(--info); }

.table-wrap { width: 100%; overflow: auto; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; }
.select-column { width: 42px; min-width: 42px; padding: 6px !important; text-align: center; }
.select-column input { width: 16px; height: 16px; margin: 0; vertical-align: middle; cursor: pointer; }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
.wide-table table { min-width: 1420px; }
th, td { padding: 11px 12px; border-bottom: 1px solid #e7ece9; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #e8eeeb; color: #33413b; font-size: 12px; font-weight: 700; white-space: nowrap; z-index: 1; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfb; }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; min-width: 150px; }
.primary-text { font-weight: 700; }
.subtext { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.money, .number { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.empty-row { padding: 34px 16px; color: var(--muted); text-align: center; }

.status { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 7px; border-radius: 4px; background: #e9eeeb; color: #53605a; font-size: 12px; white-space: nowrap; }
.status.good { background: #e4f1ea; color: #246248; }
.status.warn { background: #fff1cc; color: #805500; }
.status.bad { background: #fde5e3; color: #94332f; }
.status.info { background: #e3eef4; color: #285c78; }

.entity-list, .list-panel { display: grid; gap: 8px; }
.entity-row, .list-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.entity-row h3, .list-row b { margin: 0; font-size: 14px; }
.entity-row p, .list-row p { margin: 5px 0 0; color: var(--muted); }
.address-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.address-chip { padding: 5px 7px; color: #4f5d57; background: var(--soft); border-radius: 4px; font-size: 12px; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 5px; overflow: hidden; margin-bottom: 14px; }
.segmented button { min-height: 36px; padding: 6px 15px; border: 0; border-right: 1px solid var(--line-strong); background: white; color: #52605a; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { color: white; background: #385f51; }
.catalog-pane, .production-pane, .finance-pane, .inventory-pane, .settings-pane { display: none; }
.catalog-pane.active, .production-pane.active, .finance-pane.active, .inventory-pane.active, .settings-pane.active { display: block; }

.workspace-panel { min-height: calc(100vh - 160px); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.workspace-panel-head { position: sticky; top: 76px; z-index: 10; display: flex; align-items: flex-start; gap: 14px; padding: 18px 20px; background: white; border-bottom: 1px solid var(--line); }
.workspace-panel-head h2 { margin: 0; font-size: 18px; }
.workspace-panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.workspace-panel form { display: flex; min-height: calc(100vh - 230px); flex-direction: column; }
.workspace-body { flex: 1; padding: 22px; background: #fbfcfb; }
.workspace-head-actions { display: flex; gap: 8px; margin-left: auto; }
.workspace-panel.document-workspace .workspace-panel-head { align-items: center; padding: 10px 16px; }
.workspace-panel.document-workspace .workspace-panel-head h2 { font-size: 15px; }
.workspace-panel.document-workspace .workspace-panel-head p { display: none; }
.workspace-panel.document-workspace .workspace-body { padding: 18px 20px; }
.workspace-panel.receipt-workspace .workspace-panel-head, .workspace-panel.shipment-workspace .workspace-panel-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.workspace-panel.template-workspace .workspace-panel-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.workspace-panel.receipt-workspace .workspace-panel-head > .button, .workspace-panel.shipment-workspace .workspace-panel-head > .button, .workspace-panel.template-workspace .workspace-panel-head > .button { justify-self: start; }
.workspace-panel.receipt-workspace .workspace-panel-head > div:not(.workspace-head-actions), .workspace-panel.shipment-workspace .workspace-panel-head > div:not(.workspace-head-actions), .workspace-panel.template-workspace .workspace-panel-head > div:not(.workspace-head-actions) { text-align: center; }
.workspace-panel.receipt-workspace .workspace-head-actions, .workspace-panel.shipment-workspace .workspace-head-actions, .workspace-panel.template-workspace .workspace-head-actions { justify-self: end; margin-left: 0; }
.workspace-panel.compact-document-workspace .workspace-panel-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; }
.workspace-panel.compact-document-workspace .workspace-panel-head > .button { justify-self: start; }
.workspace-panel.compact-document-workspace .workspace-panel-head > div:not(.workspace-head-actions) { text-align: center; }
.app-shell.compact-form-active .page-heading { visibility: hidden; }
.app-shell.compact-form-active .topbar { height: 0; min-height: 0; padding: 0; overflow: hidden; border-bottom: 0; }
.app-shell.compact-form-active main { padding: 12px 16px 86px; }
.workspace-panel.compact-document-workspace { min-height: calc(100vh - 112px); }
.workspace-panel.compact-document-workspace .workspace-panel-head { top: 0; padding: 9px 14px; }
.workspace-panel.compact-document-workspace .workspace-panel-head h2 { font-size: 18px; }
.workspace-panel.compact-document-workspace .workspace-body { padding: 12px 14px 24px; }
.workspace-panel.compact-document-workspace .workspace-head-actions { position: fixed; z-index: 25; right: 0; bottom: 0; left: 224px; display: flex; justify-content: flex-end; gap: 8px; padding: 10px 18px calc(10px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.98); border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(23,34,30,.08); }
.workspace-panel.compact-document-workspace form { padding-bottom: 56px; }
.workspace-panel.compact-document-workspace input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.workspace-panel.compact-document-workspace input[type="number"]::-webkit-inner-spin-button, .workspace-panel.compact-document-workspace input[type="number"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }

.expand-button { width: 28px; min-height: 28px; padding: 0; font-size: 16px; }
.expandable-row { cursor: pointer; }
.expandable-row:focus { outline: 2px solid var(--primary); outline-offset: -2px; }
tbody tr.expandable-row:hover, tbody tr.expandable-row.is-expanded { background: #eef4f0; }
.row-expand-button[aria-expanded="true"] { color: white; background: var(--primary); border-color: var(--primary); }
.expanded-row td { padding: 0; background: #f6f8f6; }
.expanded-content { padding: 14px 18px 18px 48px; }
.expanded-content table { min-width: 600px; background: white; border: 1px solid var(--line); }
.negative-number { color: var(--danger); font-weight: 700; }

.attachment-uploader { grid-column: 1 / -1; display: grid; gap: 10px; }
.attachment-uploader > input[type="file"] { display: none; }
.attachment-dropzone { min-height: 108px; display: grid; place-items: center; padding: 18px; text-align: center; color: var(--muted); background: white; border: 1px dashed #91a39a; border-radius: 6px; }
.attachment-dropzone.dragging { border-color: var(--primary); background: #edf6f1; }
.attachment-dropzone input { display: none; }
.attachment-dropzone b { display: block; margin-bottom: 5px; color: var(--ink); }
.attachment-files { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.attachment-file { display: grid; grid-template-columns: 44px minmax(0,1fr) 32px; align-items: center; gap: 8px; min-height: 58px; padding: 7px; background: white; border: 1px solid var(--line); border-radius: 5px; }
.attachment-file img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; }
.attachment-file .file-icon { display: grid; place-items: center; width: 44px; height: 44px; background: var(--soft); color: var(--primary); font-size: 11px; font-weight: 700; border-radius: 4px; }
.attachment-file b, .attachment-file small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-file small { margin-top: 3px; color: var(--muted); }
.existing-attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.confirm-message { margin: 0; padding: 12px; line-height: 1.7; background: #fff8f7; border: 1px solid #e3c1bf; border-radius: 5px; }

.notice { position: fixed; right: 24px; top: 88px; z-index: 50; max-width: min(420px, calc(100vw - 48px)); padding: 12px 16px; color: #174534; background: #e5f2eb; border: 1px solid #a6cbb9; border-radius: 6px; box-shadow: var(--shadow); }
.notice.error { color: #8f302d; background: #fff0ef; border-color: #e4b5b2; }

dialog { width: min(820px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line-strong); border-radius: 7px; box-shadow: var(--shadow); overflow: hidden; }
dialog::backdrop { background: rgba(15, 28, 23, .48); }
dialog[open] { display: flex; flex-direction: column; }
dialog form { display: flex; flex-direction: column; min-height: 0; width: 100%; }
.dialog-head, .dialog-foot { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; background: white; }
.dialog-head { border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.dialog-body { flex: 1 1 auto; overflow: auto; padding: 20px; background: #fbfcfb; }
.dialog-foot { justify-content: flex-end; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid label { display: grid; align-content: start; gap: 6px; color: #3f4d47; font-weight: 600; font-size: 13px; }
.form-grid .full { grid-column: 1 / -1; }
.document-form { display: grid; gap: 18px; }
.document-section { min-width: 0; padding: 0 0 18px; border-bottom: 1px solid var(--line); }
.document-section:last-child { padding-bottom: 0; border-bottom: 0; }
.document-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.document-section-head h3 { margin: 0; color: #314139; font-size: 14px; }
.document-fields { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 10px 12px; align-items: start; }
.document-fields > label { display: grid; align-content: start; grid-column: span 4; min-width: 0; gap: 5px; color: #3f4d47; font-size: 13px; font-weight: 600; }
.document-fields .field-short { grid-column: span 3; }
.document-fields .field-medium { grid-column: span 4; }
.document-fields .field-wide { grid-column: span 6; }
.document-fields .field-full { grid-column: 1 / -1; }
.document-form input, .document-form select, .document-form textarea { min-width: 0; }
.document-form textarea { min-height: 38px; line-height: 1.55; overflow-y: hidden; resize: none; }
.document-form .line-editor { min-width: 0; padding-top: 0; border-top: 0; }
.document-form .line-list { min-width: 0; }
.document-form .line-row { min-width: 0; }
.document-form .line-row > * { min-width: 0; }
.document-attachment-section .attachment-dropzone { min-height: 88px; padding: 14px; }
.document-attachment-section .attachment-uploader > .primary-text { display: none; }
.compact-entry-form { gap: 13px; }
.compact-entry-form .document-section { padding-bottom: 13px; }
.compact-entry-form .document-section-head { margin-bottom: 8px; }
.compact-entry-form .document-section-head h3 { font-size: 14px; }
.compact-entry-form .document-fields { gap: 8px; }
.compact-entry-form .document-fields > label { min-height: 62px; padding: 7px 9px 9px; background: white; border: 1px solid var(--line); }
.entry-lines-wrap { width: 100%; overflow-x: auto; border: 1px solid #66736d; background: white; }
.entry-line-grid { display: grid; min-width: 900px; }
.item-entry-grid { grid-template-columns: 48px 66px 130px minmax(220px, 1fr) 110px 150px 86px 210px; min-width: 1080px; }
.product-entry-grid { grid-template-columns: 48px 66px 120px minmax(240px, 1fr) 100px 100px 78px 160px; min-width: 980px; }
.event-entry-grid, .adjustment-entry-grid { grid-template-columns: 48px 66px 120px minmax(260px, 1fr) 110px 78px 180px; }
.price-entry-grid { grid-template-columns: 48px 66px 130px minmax(280px, 1fr) 130px 82px 120px; min-width: 900px; }
.production-order-entry-grid { grid-template-columns: 48px 66px 130px minmax(240px, 1fr) 110px 100px 78px 170px 210px 160px; min-width: 1350px; }
.payment-entry-grid { grid-template-columns: 48px 66px 240px 200px 120px minmax(240px, 1fr); min-width: 920px; }
.entry-line-header { color: #26332e; background: #e8eeeb; font-size: 13px; font-weight: 700; }
.entry-line-header > span, .entry-line-row > span { display: flex; align-items: center; min-width: 0; min-height: 40px; padding: 4px 7px; border-right: 1px solid #66736d; border-bottom: 1px solid #66736d; }
.entry-line-header > span { justify-content: center; text-align: center; }
.entry-line-grid > span:last-child { border-right: 0; }
.entry-line-list .entry-line-row:last-child > span { border-bottom: 0; }
.entry-line-sequence, .entry-line-operations { justify-content: center; }
.entry-line-operations { gap: 4px; padding: 3px !important; }
.entry-line-operations button { display: inline-grid; place-items: center; width: 29px; min-height: 29px; padding: 0; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 18px; }
.entry-line-operations button:hover { color: white; background: var(--primary); border-color: var(--primary); }
.entry-line-edit-mark { color: var(--muted); }
.entry-line-display { color: #4d5b55; overflow-wrap: anywhere; }
.entry-line-input { padding: 0 !important; }
.entry-line-input input, .entry-line-input select { min-height: 39px; padding: 5px 7px; border: 0; border-radius: 0; box-shadow: none; }
.entry-line-input input:focus, .entry-line-input select:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--primary); }
.entry-line-checks { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 9px; font-size: 12px; }
.entry-line-checks label { display: inline-flex; align-items: center; gap: 3px; margin: 0; white-space: nowrap; font-weight: 500; }
.entry-line-checks input { width: 15px; height: 15px; margin: 0; }
.entity-select-native { display: none !important; }
.entity-search { position: relative; width: 100%; min-width: 0; font-weight: 400; }
.entity-search-input { width: 100%; }
.entity-search-menu { position: fixed; z-index: 120; max-height: min(320px, 45vh); overflow-y: auto; padding: 4px; background: white; border: 1px solid #87958e; border-radius: 5px; box-shadow: 0 10px 26px rgba(23,34,30,.2); }
.entity-search-option { display: grid; width: 100%; min-height: 42px; gap: 2px; padding: 6px 9px; color: var(--ink); background: white; border: 0; border-radius: 3px; text-align: left; }
.entity-search-option:hover, .entity-search-option.active { background: #e7f0eb; }
.entity-search-option b { overflow-wrap: anywhere; font-size: 13px; }
.entity-search-option small { color: var(--muted); font-size: 11px; }
.entity-search-empty { padding: 12px 10px; color: var(--muted); text-align: center; }
.receipt-entry-form { gap: 14px; }
.receipt-sheet-meta { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); border-top: 1px solid var(--line-strong); border-left: 1px solid var(--line-strong); background: white; }
.receipt-sheet-meta > label, .receipt-sheet-meta > div { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; min-width: 0; min-height: 36px; margin: 0; color: #2d3934; font-weight: 700; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.receipt-sheet-meta > label > span, .receipt-sheet-meta > div > span { padding: 0 11px; white-space: nowrap; }
.receipt-sheet-meta input, .receipt-sheet-meta select { min-height: 35px; padding: 5px 9px; border: 0; border-left: 1px solid var(--line); border-radius: 0; box-shadow: none; font-weight: 400; }
.receipt-sheet-meta input:focus, .receipt-sheet-meta select:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--primary); }
.receipt-meta-number, .receipt-meta-date, .receipt-meta-handler { grid-column: span 4; }
.receipt-meta-customer { grid-column: span 6; }
.receipt-meta-warehouse, .receipt-meta-reference { grid-column: span 3; }
.receipt-meta-number strong, .receipt-meta-handler strong { min-width: 0; padding: 0 10px; color: var(--primary-strong); overflow-wrap: anywhere; }
.receipt-meta-summary { grid-column: 1 / -1; }
.receipt-lines-section { min-width: 0; }
.receipt-lines-wrap { width: 100%; overflow-x: auto; border: 1px solid #66736d; background: white; }
.receipt-line-grid { display: grid; grid-template-columns: 48px 66px 120px minmax(240px, 1fr) 100px 92px 78px 160px; min-width: 980px; }
.receipt-line-header { color: #26332e; background: #e8eeeb; font-size: 13px; font-weight: 700; }
.receipt-line-header > span, .receipt-line-row > span { display: flex; align-items: center; min-width: 0; min-height: 40px; padding: 4px 7px; border-right: 1px solid #66736d; border-bottom: 1px solid #66736d; }
.receipt-line-header > span { justify-content: center; }
.receipt-line-grid > span:last-child { border-right: 0; }
.receipt-line-list .receipt-line-row:last-child > span { border-bottom: 0; }
.receipt-line-sequence, .receipt-line-operations { justify-content: center; }
.receipt-line-operations { gap: 4px; padding: 3px !important; }
.receipt-line-operations button { display: inline-grid; place-items: center; width: 29px; min-height: 29px; padding: 0; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 18px; }
.receipt-line-operations button:hover { color: white; background: var(--primary); border-color: var(--primary); }
.receipt-line-display { color: #4d5b55; overflow-wrap: anywhere; }
.receipt-line-input { padding: 0 !important; }
.receipt-line-input input, .receipt-line-input select { min-height: 39px; padding: 5px 7px; border: 0; border-radius: 0; box-shadow: none; }
.receipt-line-input input[name="quantity"] { appearance: textfield; -moz-appearance: textfield; }
.receipt-line-input input[name="quantity"]::-webkit-inner-spin-button, .receipt-line-input input[name="quantity"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.receipt-line-input input:focus, .receipt-line-input select:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--primary); }
.receipt-logistics-section { min-width: 0; }
.receipt-section-title { display: flex; align-items: baseline; gap: 14px; margin-bottom: 9px; }
.receipt-section-title h3 { margin: 0; font-size: 15px; }
.receipt-section-title span { color: var(--muted); font-size: 12px; }
.receipt-logistics-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); background: white; }
.receipt-logistics-grid label { display: grid; grid-column: span 3; min-width: 0; gap: 5px; padding: 8px 10px 10px; color: #3f4d47; font-size: 13px; font-weight: 600; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.shipment-entry-form { gap: 14px; }
.shipment-sheet-meta { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); border-top: 1px solid var(--line-strong); border-left: 1px solid var(--line-strong); background: white; }
.shipment-sheet-meta > label, .shipment-sheet-meta > div { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; min-width: 0; min-height: 36px; margin: 0; color: #2d3934; font-weight: 700; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.shipment-sheet-meta > label > span, .shipment-sheet-meta > div > span { padding: 0 11px; white-space: nowrap; }
.shipment-sheet-meta input, .shipment-sheet-meta select { min-height: 35px; padding: 5px 9px; border: 0; border-left: 1px solid var(--line); border-radius: 0; box-shadow: none; font-weight: 400; }
.shipment-sheet-meta input:focus, .shipment-sheet-meta select:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--primary); }
.shipment-meta-date, .shipment-meta-number, .shipment-meta-handler { grid-column: span 4; }
.shipment-meta-customer, .shipment-meta-warehouse { grid-column: span 6; }
.shipment-meta-number strong, .shipment-meta-handler strong { min-width: 0; padding: 0 10px; color: var(--primary-strong); overflow-wrap: anywhere; }
.shipment-meta-summary { grid-column: 1 / -1; }
.shipment-lines-section { min-width: 0; }
.shipment-lines-wrap { width: 100%; overflow-x: auto; border: 1px solid #66736d; background: white; }
.shipment-line-grid { display: grid; grid-template-columns: 48px 66px 112px minmax(190px, 1fr) 96px 78px 70px 112px 104px 94px 126px; min-width: 1100px; }
.shipment-line-header { color: #26332e; background: #e8eeeb; font-size: 13px; font-weight: 700; }
.shipment-line-header > span, .shipment-line-row > span, .shipment-line-total > span { display: flex; align-items: center; min-width: 0; min-height: 40px; padding: 4px 7px; border-right: 1px solid #66736d; border-bottom: 1px solid #66736d; }
.shipment-line-header > span { justify-content: center; text-align: center; }
.shipment-line-grid > span:last-child { border-right: 0; }
.shipment-line-total > span { min-height: 46px; border-bottom: 0; background: #fff2c7; font-weight: 700; }
.shipment-line-sequence, .shipment-line-operations { justify-content: center; }
.shipment-line-operations { gap: 4px; padding: 3px !important; }
.shipment-line-operations button { display: inline-grid; place-items: center; width: 29px; min-height: 29px; padding: 0; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 18px; }
.shipment-line-operations button:hover { color: white; background: var(--primary); border-color: var(--primary); }
.shipment-line-display { color: #4d5b55; overflow-wrap: anywhere; }
.shipment-line-input { padding: 0 !important; }
.shipment-line-input input, .shipment-line-input select { min-height: 39px; padding: 5px 7px; border: 0; border-radius: 0; box-shadow: none; }
.shipment-line-input input[name="quantity"], .shipment-line-input input[name="unitPrice"], .shipment-logistics-grid input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.shipment-line-input input[name="quantity"]::-webkit-inner-spin-button, .shipment-line-input input[name="quantity"]::-webkit-outer-spin-button, .shipment-line-input input[name="unitPrice"]::-webkit-inner-spin-button, .shipment-line-input input[name="unitPrice"]::-webkit-outer-spin-button, .shipment-logistics-grid input[type="number"]::-webkit-inner-spin-button, .shipment-logistics-grid input[type="number"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.shipment-line-input input:focus, .shipment-line-input select:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--primary); }
.shipment-consignee-grid { display: grid; grid-template-columns: 112px minmax(0, 1fr); border-top: 1px solid var(--line-strong); border-left: 1px solid var(--line-strong); background: white; }
.shipment-consignee-grid > strong { display: flex; align-items: center; padding: 10px 12px; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.shipment-consignee-grid label { display: block; min-width: 0; margin: 0; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.shipment-consignee-grid textarea { min-height: 45px; padding: 10px 12px; border: 0; border-radius: 0; box-shadow: none; resize: none; }
.shipment-logistics-grid { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(220px, 1.5fr) minmax(150px, .8fr) minmax(210px, 1fr); border-top: 1px solid var(--line-strong); border-left: 1px solid var(--line-strong); background: white; }
.shipment-logistics-grid > label, .shipment-receivable { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; min-width: 0; min-height: 46px; margin: 0; color: #2d3934; font-weight: 700; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.shipment-logistics-grid > label > span, .shipment-receivable > span { padding: 0 10px; white-space: nowrap; }
.shipment-logistics-grid input { min-height: 45px; padding: 7px 9px; border: 0; border-left: 1px solid var(--line); border-radius: 0; box-shadow: none; }
.shipment-receivable strong { display: flex; align-items: center; align-self: stretch; justify-content: flex-end; min-width: 0; padding: 0 12px; color: var(--primary-strong); background: #fff2c7; border-left: 1px solid var(--line); font-size: 16px; font-variant-numeric: tabular-nums; }
.shipment-advanced-section { padding: 10px 12px 12px; background: #f5f7f5; border: 1px solid var(--line); border-radius: 5px; }
.shipment-advanced-section summary { color: #43514b; cursor: pointer; font-size: 13px; font-weight: 700; }
.shipment-advanced-section[open] summary { margin-bottom: 12px; }
.template-entry-form { gap: 14px; }
.template-sheet-meta { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); border-top: 1px solid var(--line-strong); border-left: 1px solid var(--line-strong); background: white; }
.template-sheet-meta > label, .template-sheet-meta > div { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; min-width: 0; min-height: 36px; margin: 0; color: #2d3934; font-weight: 700; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.template-sheet-meta > label > span, .template-sheet-meta > div > span { padding: 0 10px; white-space: nowrap; }
.template-sheet-meta input, .template-sheet-meta select { min-height: 35px; padding: 5px 9px; border: 0; border-left: 1px solid var(--line); border-radius: 0; box-shadow: none; font-weight: 400; }
.template-sheet-meta input:focus, .template-sheet-meta select:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--primary); }
.template-meta-customer, .template-meta-output { grid-column: span 6; }
.template-meta-version, .template-meta-date, .template-meta-quantity, .template-meta-unit { grid-column: span 3; }
.template-meta-version strong { min-width: 0; padding: 0 10px; color: var(--primary-strong); overflow-wrap: anywhere; }
.template-meta-note { grid-column: 1 / -1; }
.template-lines-section { min-width: 0; }
.template-lines-wrap { width: 100%; overflow-x: auto; border: 1px solid #66736d; background: white; }
.template-line-grid { display: grid; grid-template-columns: 48px 66px 122px minmax(250px, 1fr) 120px 110px 82px; min-width: 900px; }
.template-line-header { color: #26332e; background: #e8eeeb; font-size: 13px; font-weight: 700; }
.template-line-header > span, .template-line-row > span { display: flex; align-items: center; min-width: 0; min-height: 40px; padding: 4px 7px; border-right: 1px solid #66736d; border-bottom: 1px solid #66736d; }
.template-line-header > span { justify-content: center; text-align: center; }
.template-line-grid > span:last-child { border-right: 0; }
.template-line-list .template-line-row:last-child > span { border-bottom: 0; }
.template-line-sequence, .template-line-operations { justify-content: center; }
.template-line-operations { gap: 4px; padding: 3px !important; }
.template-line-operations button { display: inline-grid; place-items: center; width: 29px; min-height: 29px; padding: 0; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 18px; }
.template-line-operations button:hover { color: white; background: var(--primary); border-color: var(--primary); }
.template-line-display { color: #4d5b55; overflow-wrap: anywhere; }
.template-line-input { padding: 0 !important; }
.template-line-input input, .template-line-input select { min-height: 39px; padding: 5px 7px; border: 0; border-radius: 0; box-shadow: none; }
.template-line-input input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.template-line-input input[type="number"]::-webkit-inner-spin-button, .template-line-input input[type="number"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.template-line-input input:focus, .template-line-input select:focus { position: relative; z-index: 1; box-shadow: inset 0 0 0 2px var(--primary); }
.checkbox-row { display: flex !important; align-items: center; min-height: 38px; gap: 8px !important; }
.checkbox-row input { width: 17px; min-height: 17px; }
.line-editor { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 14px; }
.line-editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.line-list { display: grid; gap: 7px; }
.line-row { display: grid; grid-template-columns: minmax(180px, 2fr) minmax(90px, .7fr) minmax(80px, .6fr) minmax(130px, 1fr) 36px; gap: 7px; align-items: center; }
.line-row.simple { grid-template-columns: minmax(200px, 2fr) minmax(100px, .8fr) minmax(140px, 1fr) 36px; }
.line-row.shipment-line { grid-template-columns: minmax(180px, 1.6fr) minmax(80px, .55fr) minmax(120px, .8fr) minmax(90px, .55fr) minmax(150px, 1fr) 36px; }
.line-labels { color: var(--muted); font-size: 12px; font-weight: 700; }
.line-labels span { padding: 0 10px; }
.form-note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.detail-field { min-height: 66px; padding: 10px; background: white; }
.detail-field small { display: block; color: var(--muted); margin-bottom: 5px; }
.detail-section { margin-top: 20px; }
.detail-section h3 { margin: 0 0 9px; font-size: 14px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.charge-picker { display: grid; gap: 7px; }
.charge-option { display: grid !important; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center !important; gap: 10px !important; min-height: 52px; padding: 9px 11px; background: white; border: 1px solid var(--line); border-radius: 5px; }
.charge-option > input[type="number"] { width: 130px; }
.charge-option span { min-width: 0; }
.charge-option b, .charge-option small { display: block; }
.charge-option small { margin-top: 3px; color: var(--muted); font-weight: 400; }

.migration-section { margin-top: 28px; }
.migration-controls { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; gap: 8px; align-items: center; }
.result-box { margin-top: 10px; min-height: 48px; padding: 12px; background: white; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); white-space: pre-wrap; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(135px, 1fr)); }
  .split-layout { grid-template-columns: 1fr; gap: 0; }
  .document-fields { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .document-fields > label, .document-fields .field-medium { grid-column: span 3; }
  .document-fields .field-short { grid-column: span 2; }
  .document-fields .field-wide, .document-fields .field-full { grid-column: 1 / -1; }
  .shipment-consignee-grid { grid-template-columns: 100px minmax(0, 1fr); }
  .shipment-logistics-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, .9fr) minmax(0, 1.2fr); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .workspace { width: 100%; }
  .topbar { height: 64px; padding: 0 14px; }
  #menuButton { display: inline-flex; }
  .page-heading h1 { font-size: 18px; }
  .page-heading p { display: none; }
  main { padding: 16px 12px 44px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 92px; }
  .metric strong { font-size: 21px; }
  .section-head { align-items: flex-start; }
  .section-head, .subsection-head { flex-wrap: wrap; }
  .section-head .actions { width: 100%; }
  .section-head .actions .button { flex: 1 1 auto; }
  .settings-grid { grid-template-columns: 1fr; gap: 0; }
  .filterbar { grid-template-columns: 1fr; }
  .query-panel { align-items: stretch; flex-direction: column; }
  .query-fields { grid-template-columns: 1fr; }
  .query-actions { width: 100%; }
  .query-actions .button { flex: 1; }
  .pagination-bar { align-items: flex-start; flex-direction: column; padding: 10px 0; }
  .pagination-actions { width: 100%; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .document-form { gap: 14px; }
  .document-section { padding-bottom: 14px; }
  .document-fields { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .document-fields > label, .document-fields .field-short, .document-fields .field-medium, .document-fields .field-wide, .document-fields .field-full { grid-column: 1; }
  .workspace-panel { min-height: calc(100vh - 110px); border-left: 0; border-right: 0; }
  .workspace-panel-head { top: 64px; }
  .workspace-panel-head, .workspace-body { padding-left: 14px; padding-right: 14px; }
  .workspace-panel.document-workspace .workspace-panel-head, .workspace-panel.document-workspace .workspace-body { padding-left: 12px; padding-right: 12px; }
  .app-shell.compact-form-active main { padding: 8px 0 90px; }
  .app-shell.compact-form-active .topbar { height: 52px; min-height: 52px; padding: 0 12px; overflow: visible; border-bottom: 1px solid var(--line); }
  .app-shell.compact-form-active .top-actions { display: none; }
  .workspace-panel.compact-document-workspace .workspace-panel-head { top: 52px; padding-left: 12px; padding-right: 12px; }
  .workspace-panel.compact-document-workspace .workspace-body { padding: 10px 12px 24px; }
  .workspace-panel.compact-document-workspace .workspace-head-actions { left: 0; padding-left: 12px; padding-right: 12px; }
  .workspace-head-actions { gap: 6px; }
  .workspace-head-actions .button { padding-left: 10px; padding-right: 10px; }
  .workspace-panel form { min-height: calc(100vh - 180px); }
  .attachment-uploader { grid-column: auto; }
  .attachment-files { grid-template-columns: 1fr; }
  .document-form .line-row, .document-form .line-row.simple, .document-form .line-row.shipment-line { grid-template-columns: minmax(0, 1fr) 36px; padding: 0 0 10px; border-bottom: 1px solid var(--line); }
  .document-form .line-row > * { grid-column: 1 / -1; }
  .document-form .line-row > :first-child { grid-column: 1; grid-row: 1; }
  .document-form .line-row > :last-child { grid-column: 2; grid-row: 1; }
  .receipt-entry-form { gap: 14px; }
  .receipt-sheet-meta { grid-template-columns: 1fr; }
  .receipt-meta-number, .receipt-meta-date, .receipt-meta-reference, .receipt-meta-customer, .receipt-meta-warehouse, .receipt-meta-handler, .receipt-meta-summary { grid-column: 1; }
  .receipt-sheet-meta > label, .receipt-sheet-meta > div { grid-template-columns: 92px minmax(0, 1fr); }
  .receipt-sheet-meta > label > span, .receipt-sheet-meta > div > span { padding: 0 8px; }
  .receipt-logistics-grid { grid-template-columns: 1fr; }
  .receipt-logistics-grid label { grid-column: 1; }
  .shipment-entry-form { gap: 14px; }
  .shipment-sheet-meta { grid-template-columns: 1fr; }
  .shipment-meta-date, .shipment-meta-number, .shipment-meta-customer, .shipment-meta-warehouse, .shipment-meta-handler, .shipment-meta-summary { grid-column: 1; }
  .shipment-sheet-meta > label, .shipment-sheet-meta > div { grid-template-columns: 92px minmax(0, 1fr); }
  .shipment-sheet-meta > label > span, .shipment-sheet-meta > div > span { padding: 0 8px; }
  .shipment-consignee-grid, .shipment-logistics-grid { grid-template-columns: 1fr; }
  .shipment-consignee-grid > strong { min-height: 44px; }
  .shipment-logistics-grid > label, .shipment-receivable { grid-template-columns: 92px minmax(0, 1fr); }
  .template-sheet-meta { grid-template-columns: 1fr; }
  .template-meta-customer, .template-meta-output, .template-meta-version, .template-meta-date, .template-meta-quantity, .template-meta-unit, .template-meta-note { grid-column: 1; }
  .template-sheet-meta > label, .template-sheet-meta > div { grid-template-columns: 112px minmax(0, 1fr); }
  .template-sheet-meta > label > span, .template-sheet-meta > div > span { padding: 0 8px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .migration-controls { grid-template-columns: 1fr 1fr; }
  .migration-controls input { grid-column: 1 / -1; }
  dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .dialog-body { padding: 15px; }
  .entity-row, .list-row { padding: 12px; }
}

@media (max-width: 420px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .segmented { display: flex; width: 100%; overflow-x: auto; }
  .segmented button { flex: 1 0 auto; }
}
