:root {
    --navy: #43547b;
    --navy-dark: #263451;
    --red: #d51f32;
    --ink: #172033;
    --muted: #677189;
    --line: #d9dfeb;
    --soft: #f2f5fa;
    --paper: #ffffff;
    --page-shadow: 0 20px 60px rgba(26, 39, 68, .16);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: #e9edf4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { font-size: 14px; }
button, input, textarea { font: inherit; }
a { color: var(--navy); text-decoration: none; }

.app-shell { background: radial-gradient(circle at top left, #f8faff 0, #e9edf4 44%, #e2e7f0 100%); }
.app-header { height: 72px; padding: 0 34px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.92); border-bottom: 1px solid rgba(67,84,123,.12); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: white; background: linear-gradient(135deg, var(--navy), var(--navy-dark)); font-size: 22px; font-weight: 800; position: relative; overflow: hidden; }
.brand-mark::after { content: ""; width: 13px; height: 28px; background: var(--red); border-radius: 20px; position: absolute; left: 8px; bottom: -8px; transform: rotate(-25deg); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: .08em; }
.brand small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.header-meta { display: flex; align-items: center; gap: 16px; }
.status-chip { padding: 6px 10px; border-radius: 999px; background: #fff1d6; color: #8a5b00; font-size: 12px; font-weight: 700; }
.status-readonly { background: #e8f7ef; color: #176b43; }
.logout-button { border: 0; padding: 6px; color: var(--navy); background: transparent; cursor: pointer; }
.app-main { min-height: calc(100vh - 120px); padding: 50px 28px 64px; }
.app-footer { padding: 18px; text-align: center; color: var(--muted); font-size: 12px; }
.progress-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px; background: rgba(23,32,51,.42); backdrop-filter: blur(4px); }
.progress-dialog { width: min(420px, 100%); padding: 28px; border-radius: 18px; background: white; box-shadow: 0 24px 80px rgba(20,31,55,.28); text-align: center; }
.progress-dialog strong { display: block; color: var(--navy-dark); font-size: 16px; }
.progress-dialog small { display: block; margin-top: 12px; color: var(--muted); }
.progress-track { height: 8px; margin-top: 20px; border-radius: 999px; overflow: hidden; background: #e8ecf4; }
.progress-track span { display: block; width: 38%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--navy), var(--red)); animation: mecrt-progress 1.15s ease-in-out infinite; }
@keyframes mecrt-progress { from { transform: translateX(-110%); } to { transform: translateX(300%); } }

.lookup-card { max-width: 850px; margin: 8vh auto 0; padding: 54px; border-radius: 28px; background: rgba(255,255,255,.96); box-shadow: 0 26px 80px rgba(30,44,76,.16); border: 1px solid rgba(255,255,255,.8); }
.compact-card { max-width: 620px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px; color: var(--red); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.eyebrow::before { content: ""; width: 28px; height: 3px; border-radius: 3px; background: var(--red); }
.lookup-card h1 { margin: 0; font-size: clamp(30px, 5vw, 48px); line-height: 1.08; letter-spacing: -.04em; }
.lookup-card > p { max-width: 660px; color: var(--muted); line-height: 1.7; margin: 18px 0 32px; font-size: 15px; }
.lookup-form label { display: block; margin-bottom: 9px; font-weight: 750; font-size: 13px; }
.lookup-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.lookup-row input { min-width: 0; border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; outline: 0; background: #fbfcff; transition: .18s ease; }
.lookup-row input:focus { border-color: var(--navy); background: white; box-shadow: 0 0 0 4px rgba(67,84,123,.11); }
.lookup-form small { display: block; margin-top: 10px; color: var(--muted); }
.button { border: 0; border-radius: 12px; padding: 12px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; font-weight: 760; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: white; background: linear-gradient(135deg, var(--navy), var(--navy-dark)); box-shadow: 0 8px 20px rgba(38,52,81,.2); }
.button-secondary { color: white; background: var(--red); }
.button-ghost { color: var(--navy-dark); background: white; border: 1px solid var(--line); }
.alert { border-radius: 12px; padding: 13px 16px; margin: 0 0 20px; line-height: 1.55; }
.alert-error { color: #8f1725; background: #fff0f2; border: 1px solid #ffd0d7; }
.flow-hint { display: flex; align-items: center; gap: 10px; margin-top: 38px; color: var(--muted); font-size: 12px; }
.flow-hint span { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.flow-hint b { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--navy); font-size: 11px; }
.flow-hint i { flex: 1; height: 1px; background: var(--line); }

.editor-form { width: min(1380px, 100%); margin: 0 auto; }
.editor-toolbar { width: min(1200px, 100%); margin: 0 auto 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 18px; border: 1px solid rgba(67,84,123,.12); border-radius: 16px; background: rgba(255,255,255,.94); box-shadow: 0 10px 34px rgba(30,44,76,.1); position: sticky; top: 86px; z-index: 15; }
.editor-toolbar strong, .editor-toolbar span { display: block; }
.editor-toolbar strong { font-size: 16px; }
.editor-toolbar span { color: var(--muted); margin-top: 2px; font-size: 12px; }
.toolbar-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.inline-form { display: inline-flex; margin: 0; }

.pi-sheet { width: 210mm; min-height: 297mm; margin: 0 auto; padding: 11mm 11mm 10mm; background: var(--paper); color: #1a2130; box-shadow: var(--page-shadow); position: relative; overflow: hidden; }
.pi-sheet::before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 4mm; background: linear-gradient(90deg, var(--navy) 0 70%, var(--red) 70%); }
.pi-brand-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10mm; padding-top: 2mm; min-height: 28mm; }
.seller-block { flex: 1; min-width: 0; }
.seller-block h1, .seller-company { width: 100%; margin: 0 0 2mm; border: 0; padding: 0; color: var(--navy-dark); font-size: 16px; font-weight: 850; letter-spacing: .01em; }
.seller-block textarea, .seller-block input { border: 0; border-bottom: 1px dashed transparent; outline: 0; color: #485167; background: transparent; padding: 1px 2px; }
.seller-block textarea:focus, .seller-block input:focus { border-bottom-color: var(--navy); background: #f8faff; }
.seller-block > textarea { width: 100%; resize: vertical; line-height: 1.35; }
.seller-inline { display: flex; gap: 5mm; color: var(--muted); font-size: 10px; margin-top: 1mm; }
.seller-inline span { display: flex; align-items: center; gap: 1.5mm; flex: 1; min-width: 0; font-weight: 700; }
.seller-inline input { flex: 1; min-width: 0; font-size: 10px; font-weight: 500; }
.static-seller h1 { font-size: 16px; margin: 0 0 2mm; color: var(--navy-dark); }
.static-seller p { margin: 1mm 0; color: #4f586b; font-size: 9.5px; line-height: 1.35; }
.logo-crop { width: 51mm; height: 14mm; overflow: hidden; position: relative; flex: 0 0 auto; margin-top: 3mm; }
.logo-crop img { position: absolute; width: 51mm; height: 51mm; left: 0; top: -19.3mm; max-width: none; }
.invoice-title { display: flex; justify-content: flex-end; align-items: baseline; gap: 2.5mm; margin: 4mm 0 5mm; color: var(--navy-dark); font-size: 26px; font-weight: 300; letter-spacing: .12em; }
.invoice-title span { font-weight: 900; letter-spacing: -.02em; }
.invoice-title::after { content: ""; width: 14mm; height: 1.2mm; margin-left: 2mm; border-radius: 2mm; background: var(--red); }
.party-grid { display: grid; grid-template-columns: 1.16fr .84fr; gap: 5mm; }
.party-panel { border: 1px solid var(--line); border-radius: 3mm; overflow: hidden; background: #fff; }
.section-label { padding: 2.3mm 3mm; color: white; background: var(--navy); font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.party-panel > label { display: grid; grid-template-columns: 21mm 1fr; align-items: center; min-height: 7mm; padding: 1.2mm 2.5mm; border-bottom: 1px solid #edf0f5; color: var(--muted); font-size: 8.5px; font-weight: 700; }
.party-panel input, .party-panel textarea { width: 100%; border: 0; outline: 0; padding: 1.3mm 1.8mm; background: #f8f9fc; color: var(--ink); font-size: 9.5px; resize: vertical; }
.split-fields { display: grid; grid-template-columns: 1fr 1fr; }
.split-fields label { display: block; min-width: 0; padding: 1.2mm 2.5mm; border-right: 1px solid #edf0f5; border-bottom: 1px solid #edf0f5; color: var(--muted); font-size: 8.5px; font-weight: 700; }
.split-fields label:last-child { border-right: 0; }
.split-fields input { display: block; margin-top: 1mm; }
.static-grid dl { margin: 0; padding: 1mm 0; }
.static-grid dl div { display: grid; grid-template-columns: 27mm 1fr; gap: 2mm; min-height: 6mm; padding: 1.2mm 3mm; border-bottom: 1px solid #edf0f5; align-items: start; }
.static-grid dl div:last-child { border-bottom: 0; }
.static-grid dt { color: var(--muted); font-size: 8px; font-weight: 750; }
.static-grid dd { margin: 0; color: var(--ink); font-size: 9px; line-height: 1.35; overflow-wrap: anywhere; }
.agreement { margin: 4mm 0 2.3mm; color: var(--muted); font-size: 8.5px; font-style: italic; }
.table-scroll { overflow-x: auto; }
.items-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.items-table th { padding: 2.5mm 1.2mm; color: white; background: var(--navy-dark); border-right: 1px solid rgba(255,255,255,.14); font-size: 7.5px; line-height: 1.2; text-align: center; text-transform: uppercase; letter-spacing: .03em; }
.items-table td { padding: 1.5mm 1.1mm; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 8px; line-height: 1.3; overflow-wrap: anywhere; }
.items-table td:first-child { border-left: 1px solid var(--line); }
.items-table tr { break-inside: avoid; page-break-inside: avoid; }
.items-table textarea, .items-table input { width: 100%; min-width: 0; border: 0; outline: 0; padding: 1.2mm; background: #f8f9fc; font-size: 8px; resize: vertical; }
.editor-table { min-width: 0; }
.editor-table th:nth-child(1) { width: 4%; }
.editor-table th:nth-child(2) { width: 23%; }
.editor-table th:nth-child(3) { width: 10%; }
.editor-table th:nth-child(4) { width: 13%; }
.editor-table th:nth-child(5), .editor-table th:nth-child(6) { width: 7%; }
.editor-table th:nth-child(7), .editor-table th:nth-child(8) { width: 10%; }
.editor-table th:nth-child(9) { width: 12%; }
.editor-table th:nth-child(10) { width: 4%; }
.row-number, .line-total { text-align: center; font-variant-numeric: tabular-nums; }
.editor-picture-cell { text-align: center; }
.editor-product-image { display: block; width: 17mm; height: 17mm; margin: 0 auto; object-fit: contain; }
.editor-picture-cell .image-placeholder { width: 17mm; height: 17mm; font-size: 6.5px; }
.row-action { text-align: center; }
.row-action button { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; color: #a51f2f; background: #fff0f2; cursor: pointer; }
.add-row { margin-top: 2mm; padding: 2mm 3mm; border: 1px dashed #b8c1d4; border-radius: 2mm; color: var(--navy); background: #f7f9fc; font-size: 9px; font-weight: 750; cursor: pointer; }
.summary-grid { display: grid; grid-template-columns: 1fr 72mm; gap: 5mm; margin-top: 4mm; align-items: start; }
.mark-field { display: block; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .08em; }
.mark-field textarea { width: 100%; margin-top: 1.5mm; border: 1px solid var(--line); border-radius: 2mm; padding: 2.5mm; outline: 0; resize: vertical; color: var(--ink); background: #fbfcfe; font-size: 9px; line-height: 1.45; }
.mark-field p { min-height: 18mm; margin: 1.5mm 0 0; padding: 2.5mm; border: 1px solid var(--line); border-radius: 2mm; color: var(--ink); font-size: 8.5px; font-weight: 400; line-height: 1.45; letter-spacing: 0; }
.totals-card { border: 1px solid var(--line); border-radius: 2.5mm; overflow: hidden; }
.totals-card > div, .totals-card > label { min-height: 7mm; padding: 1.4mm 2.5mm; display: flex; align-items: center; justify-content: space-between; gap: 3mm; border-bottom: 1px solid #edf0f5; font-size: 8.5px; }
.totals-card > div:last-child, .totals-card > label:last-child { border-bottom: 0; }
.totals-card span { color: var(--muted); font-weight: 700; }
.totals-card strong { font-variant-numeric: tabular-nums; }
.totals-card input { width: 29mm; padding: 1mm 1.5mm; border: 0; border-bottom: 1px solid #cfd6e3; outline: 0; text-align: right; background: #f8f9fc; }
.grand-total { min-height: 11mm !important; color: white; background: var(--navy-dark); }
.grand-total span, .grand-total strong { color: white; }
.grand-total em { font-style: normal; font-size: 8px; opacity: .8; }
.grand-total b { font-size: 13px; }
.final-table th:nth-child(1) { width: 5%; }
.final-table th:nth-child(2) { width: 26%; }
.final-table th:nth-child(3) { width: 11%; }
.final-table th:nth-child(4) { width: 14%; }
.final-table th:nth-child(5), .final-table th:nth-child(6) { width: 7%; }
.final-table th:nth-child(7), .final-table th:nth-child(8), .final-table th:nth-child(9) { width: 10%; }
.final-table tbody tr { min-height: 18mm; }
.final-table td { text-align: center; }
.final-table .item-name { text-align: left; font-weight: 650; }
.final-table .numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.final-table tfoot td { padding: 2mm; font-weight: 800; background: var(--soft); }
.product-image { display: block; width: 16mm; height: 16mm; margin: 0 auto; object-fit: contain; }
.image-placeholder { display: grid; place-items: center; width: 16mm; height: 16mm; margin: 0 auto; border: 1px dashed #c8cfdd; color: #a3abba; font-size: 7px; font-weight: 800; }
.static-totals strong { white-space: nowrap; }
.pi-footer { position: absolute; left: 11mm; right: 11mm; bottom: 7mm; display: flex; justify-content: space-between; padding-top: 2mm; border-top: 1px solid var(--line); color: #8a93a5; font-size: 7px; }

/* Simplified A4 picking list: seller spans the full page and monetary/buyer fields are omitted. */
.picking-document { padding-bottom: 11mm; overflow: visible; }
.picking-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10mm; min-height: 23mm; padding-top: 2mm; }
.picking-title { display: flex; align-items: baseline; gap: 2.5mm; color: var(--navy-dark); font-size: 27px; font-weight: 300; letter-spacing: .12em; }
.picking-title span { font-weight: 900; letter-spacing: -.02em; }
.picking-title::after { content: ""; width: 14mm; height: 1.2mm; margin-left: 2mm; border-radius: 2mm; background: var(--red); }
.picking-seller-panel { width: 100%; margin: 2mm 0 4mm; padding: 3.2mm 4mm; border: 1px solid var(--line); border-left: 2mm solid var(--navy); border-radius: 2mm; background: #fbfcff; }
.picking-seller-panel h1 { margin: 0 0 1.5mm; color: var(--navy-dark); font-size: 16px; }
.picking-seller-panel p { margin: 0 0 2mm; color: #4f586b; font-size: 10.5px; line-height: 1.45; }
.picking-seller-details { display: flex; flex-wrap: wrap; gap: 1.5mm 6mm; color: #4f586b; font-size: 10px; line-height: 1.4; }
.picking-seller-details b { color: var(--navy-dark); }
.picking-meta { display: grid; grid-template-columns: 1.6fr 1fr .7fr 1fr; gap: 2mm; margin-bottom: 4mm; }
.picking-meta div { min-width: 0; padding: 2.5mm 3mm; border-radius: 2mm; background: var(--soft); }
.picking-meta span, .picking-meta strong { display: block; }
.picking-meta span { margin-bottom: 1mm; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .08em; }
.picking-meta strong { color: var(--navy-dark); font-size: 11px; overflow-wrap: anywhere; }
.picking-table th:nth-child(1) { width: 5%; }
.picking-table th:nth-child(2) { width: 31%; }
.picking-table th:nth-child(3) { width: 12%; }
.picking-table th:nth-child(4) { width: 19%; }
.picking-table th:nth-child(5) { width: 10%; }
.picking-table th:nth-child(6) { width: 9%; }
.picking-table th:nth-child(7) { width: 14%; }
.picking-table td { text-align: center; font-size: 11px; }
.picking-table .item-name { text-align: left; font-weight: 650; }
.picking-table .numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.picking-table tfoot td { padding: 2.4mm; font-weight: 850; background: var(--soft); }
.picking-notes { margin-top: 4mm; padding: 3mm; border: 1px solid var(--line); border-radius: 2mm; }
.picking-notes strong { color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.picking-notes p { margin: 1.5mm 0 0; font-size: 10.5px; line-height: 1.5; }
.picking-footer { position: static; margin-top: 6mm; }

/* Readable A4 PI typography: approximately 7.5–9 pt for body content. */
.pi-sheet { font-size: 11px; }
.seller-inline, .seller-inline input { font-size: 11px; }
.static-seller p { font-size: 10.5px; line-height: 1.45; }
.section-label { font-size: 10px; }
.party-panel > label, .split-fields label { font-size: 9.5px; }
.party-panel input, .party-panel textarea { font-size: 11px; line-height: 1.4; }
.static-grid dt { font-size: 9.5px; }
.static-grid dd { font-size: 10.5px; line-height: 1.45; }
.agreement { font-size: 9.5px; line-height: 1.4; }
.items-table th { font-size: 10px; padding: 2.8mm 1.2mm; }
.items-table td { padding: 2mm 1.3mm; }
.items-table td, .items-table textarea, .items-table input { font-size: 11px; line-height: 1.45; }
.mark-field { font-size: 9.5px; }
.mark-field textarea, .mark-field p { font-size: 10px; line-height: 1.5; }
.totals-card > div, .totals-card > label { font-size: 10px; }
.grand-total em { font-size: 9px; }
.grand-total b { font-size: 15px; }
.pi-footer { font-size: 8px; }

@media (max-width: 900px) {
    .app-header { padding: 0 18px; }
    .app-main { padding: 26px 12px 50px; overflow-x: hidden; }
    .lookup-card { padding: 30px 22px; border-radius: 20px; margin-top: 5vh; }
    .lookup-row { grid-template-columns: 1fr; }
    .lookup-row input { min-height: 52px; font-size: 16px; }
    .lookup-row .button { min-height: 48px; width: 100%; font-size: 16px; touch-action: manipulation; }
    .flow-hint { align-items: flex-start; flex-direction: column; }
    .flow-hint i { display: none; }
    .editor-toolbar { top: 78px; align-items: stretch; flex-direction: column; }
    .toolbar-actions { justify-content: stretch; }
    .toolbar-actions .button, .toolbar-actions form { flex: 1; }
    .toolbar-actions form .button { width: 100%; }
    .pi-sheet { width: 100%; min-height: auto; padding: 22px 18px 80px; }
    .party-grid, .summary-grid { grid-template-columns: 1fr; }
    .picking-meta { grid-template-columns: 1fr 1fr; }
    .pi-brand-header { gap: 12px; }
    .logo-crop { transform: scale(.78); transform-origin: top right; margin-right: -10mm; }
}

@page { size: A4 portrait; margin: 0; }
@media print {
    :root, html, body { background: white !important; }
    body { margin: 0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .no-print, .app-header, .app-footer { display: none !important; }
    .app-main { padding: 0 !important; min-height: 0; }
    .pi-sheet { width: 210mm !important; min-height: 297mm !important; margin: 0 !important; box-shadow: none !important; overflow: visible; }
    .party-grid { grid-template-columns: 1.16fr .84fr !important; }
    .summary-grid { grid-template-columns: 1fr 72mm !important; }
    .picking-meta { grid-template-columns: 1.6fr 1fr .7fr 1fr !important; }
    .logo-crop { transform: none !important; margin-right: 0 !important; }
    .pi-footer { bottom: 7mm; }
    thead { display: table-header-group; }
    tfoot { display: table-row-group; }
}
