:root {
  --navy: #17395f;
  --teal: #137f87;
  --teal-dark: #0f6870;
  --page: #f4f7fa;
  --line: #d8e0e8;
  --text: #172334;
  --muted: #64748b;
  --input: #fff4cc;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; color: var(--text); background: var(--page); }
.topbar { position: sticky; top: 0; z-index: 1000; min-height: 66px; display: flex; align-items: center; gap: 28px; padding: 0 28px; background: var(--navy); color: white; box-shadow: 0 2px 8px rgba(15, 23, 42, .18); }
.brand { font-size: 21px; font-weight: 700; white-space: nowrap; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.topbar nav a, .link-button { color: white; text-decoration: none; border: 0; background: transparent; padding: 12px 14px; font: inherit; cursor: pointer; border-radius: 6px; }
.topbar nav a:hover, .link-button:hover { background: rgba(255,255,255,.12); }
.logout-form { margin: 0; }
.container { max-width: 1320px; margin: 0 auto; padding: 28px; }
h1 { margin: 0 0 8px; color: var(--navy); }
h2 { margin: 0; color: var(--navy); }
p { line-height: 1.45; }
.page-heading, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.heading-actions { display: flex; align-items: center; gap: 10px; }
.page-heading p { margin: 0; color: var(--muted); }
.card { background: white; border: 1px solid var(--line); border-radius: 9px; padding: 22px; box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.narrow { max-width: 620px; margin: 60px auto; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { display: flex; flex-direction: column; gap: 7px; padding: 20px; background: white; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); text-decoration: none; }
.stat span { font-size: 30px; font-weight: 700; color: var(--navy); }
.button, button { display: inline-block; padding: 10px 16px; border: 1px solid var(--teal); border-radius: 6px; background: var(--teal); color: white; text-decoration: none; font-weight: 700; cursor: pointer; }
.button:hover, button:hover { background: var(--teal-dark); }
.button.secondary, button.secondary { background: white; color: var(--teal); }
.button.secondary:hover, button.secondary:hover { background: #e8f6f6; }
.button.table-action { padding: 5px 9px; font-size: .82rem; white-space: nowrap; }
.message { margin-bottom: 18px; padding: 12px 16px; border-left: 4px solid var(--teal); background: #e8f6f6; }
.search { display: flex; gap: 10px; margin: 0 0 18px; }
.search input { flex: 1; }
.table-card { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #eaf1f7; color: var(--navy); }
.inquiry-table-card, .anf-table-card, .offer-position-table-card, .quotation-table-card { max-height: calc(100vh - 250px); overflow: auto; }
.inquiry-table { min-width: 1450px; }
.anf-table { min-width: 1450px; border-collapse: separate; border-spacing: 0; }
.offer-position-table { min-width: 3450px; }
.quotation-table { min-width: 3250px; border-collapse: separate; border-spacing: 0; }
.proforma-table { min-width: 5200px; }
.order-table { min-width: 3650px; border-collapse: separate; border-spacing: 0; }
.delivery-table { min-width: 4700px; }
.goods-receipt-table { min-width: 1900px; }
.goods-receipt-table-card { max-height: calc(100vh - 250px); overflow: auto; }
.goods-receipt-table thead th { position: sticky; top: 0; z-index: 2; background: #eaf1f7; box-shadow: 0 1px 0 var(--line); }
.goods-receipt-table th:first-child, .goods-receipt-table td:first-child { position: sticky; left: 0; z-index: 3; background: #fff; box-shadow: 2px 0 3px rgba(27, 58, 95, .12); }
.goods-receipt-table thead th:first-child { z-index: 5; background: #eaf1f7; }
.invoice-table { min-width: 3000px; }
.inquiry-table thead th, .anf-table thead th { position: sticky; top: 0; z-index: 2; background: #eaf1f7; box-shadow: 0 1px 0 var(--line); }
.offer-position-table thead th { position: sticky; top: 0; z-index: 2; background: #eaf1f7; box-shadow: 0 1px 0 var(--line); }
.quotation-table thead th { position: sticky; top: 0; z-index: 2; background: #eaf1f7; box-shadow: 0 1px 0 var(--line); }
.quotation-table th, .quotation-table td { white-space: nowrap; }
.quotation-table th:nth-child(1), .quotation-table td:nth-child(1) { position: sticky; left: 0; z-index: 3; min-width: 105px; width: 105px; background: #fff; }
.quotation-table th:nth-child(2), .quotation-table td:nth-child(2) { position: sticky; left: 105px; z-index: 3; min-width: 190px; background: #fff; box-shadow: 2px 0 3px rgba(27, 58, 95, .12); }
.quotation-table thead th:nth-child(1), .quotation-table thead th:nth-child(2) { z-index: 5; background: #eaf1f7; }
.offer-position-table th, .offer-position-table td { white-space: nowrap; }
.offer-position-table td:nth-child(5) { min-width: 260px; white-space: normal; }
.offer-position-table th:first-child, .offer-position-table td:first-child { position: sticky; left: 0; z-index: 3; background: #fff; box-shadow: 2px 0 3px rgba(27, 58, 95, .12); }
.offer-position-table thead th:first-child { z-index: 5; background: #eaf1f7; }
.offer-position-table .offer-total-row { background: #e8f6f6; font-weight: 700; }
.offer-position-table .offer-total-row td:first-child { background: #e8f6f6; }
.offer-position-table .offer-total-row:hover { background: #d9eeee; }
.inquiry-table th, .inquiry-table td { white-space: nowrap; }
.inquiry-table th:nth-child(1), .inquiry-table td:nth-child(1) { position: sticky; left: 0; width: 105px; min-width: 105px; z-index: 3; background: #fff; }
.inquiry-table th:nth-child(2), .inquiry-table td:nth-child(2) { position: sticky; left: 105px; width: 115px; min-width: 115px; z-index: 3; background: #fff; }
.inquiry-table th:nth-child(3), .inquiry-table td:nth-child(3) { position: sticky; left: 220px; width: 90px; min-width: 90px; z-index: 3; background: #fff; box-shadow: 2px 0 3px rgba(27, 58, 95, .12); }
.inquiry-table thead th:nth-child(-n+3) { z-index: 5; background: #eaf1f7; }
.inquiry-table td:nth-child(6) { min-width: 260px; white-space: normal; }
.anf-table th, .anf-table td { white-space: nowrap; }
.anf-table th:nth-child(1), .anf-table td:nth-child(1) { position: sticky; left: 0; width: 105px; min-width: 105px; z-index: 10; background: #fff; transform: translateZ(0); }
.anf-table th:nth-child(2), .anf-table td:nth-child(2) { position: sticky; left: 105px; width: 125px; min-width: 125px; z-index: 10; background: #fff; transform: translateZ(0); }
.anf-table th:nth-child(3), .anf-table td:nth-child(3) { position: sticky; left: 230px; width: 280px; min-width: 280px; z-index: 10; background: #fff; box-shadow: 2px 0 3px rgba(27, 58, 95, .12); white-space: normal; transform: translateZ(0); }
.anf-table thead th:nth-child(-n+3) { z-index: 5; background: #eaf1f7; }
.anf-table td:nth-child(9) { min-width: 280px; white-space: normal; }
tbody tr:hover { background: #f8fafc; }
td a { color: #006c7a; font-weight: 700; }
.form-card { max-width: 980px; margin: 0 auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 22px; }
.form-grid.single-column { grid-template-columns: 1fr; }
.form-grid > div { display: flex; flex-direction: column; gap: 6px; }
.form-grid label { font-weight: 700; color: var(--navy); }
.form-grid .helptext { color: var(--muted); font-size: 13px; }
.selected-offer-supplier {
  margin-top: 4px;
  padding: 10px 12px;
  border-left: 4px solid var(--teal);
  border-radius: 4px;
  background: #edf7f8;
  color: var(--navy);
}
.selected-offer-supplier span { font-weight: 600; }
.calculation-help { margin: 14px 0 8px; color: var(--muted); }
.calculation-help code { padding: 2px 5px; border-radius: 4px; background: #edf3f7; color: var(--navy); }
.project-position-edit-table .price-calculation-input { min-width: 185px; }
.project-position-edit-table .calculation-invalid { border-color: #b42318; background: #fff0ee; }
.order-table th, .order-table td { white-space: nowrap; }
.order-table thead th { position: sticky; top: 0; z-index: 2; box-shadow: 0 1px 0 var(--line); }
.order-table thead tr:nth-child(2) th { top: 42px; }
.order-table .order-group-row th { background: #dceaf4; text-align: center; border-bottom: 2px solid white; }
.order-table .order-group-row .order-customer-group { background: #dff1f2; }
.order-table .order-group-row .order-supplier-group { background: #fff0c9; }
.order-table td:nth-child(13), .order-table td:nth-child(14) { min-width: 260px; white-space: normal; }
.stacked-value { display: block; white-space: nowrap; }
.purchase-order-form-card { max-width: 1380px; }
.form-intro { margin: 0 0 20px; color: var(--muted); }
.order-form-section { margin-top: 20px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; }
.customer-order-section { border-top: 5px solid var(--teal); }
.supplier-order-section { border-top: 5px solid #d7a92d; }
.order-form-section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.order-form-section-heading p { margin: 0; color: var(--muted); }
.form-grid .form-span-2 { grid-column: 1 / -1; }
.advance-payment-box { margin-top: 20px; padding: 16px; border-radius: 7px; background: #f3f8fb; }
.advance-payment-box h3 { margin: 0 0 10px; color: var(--navy); }
.advance-payment-box p { margin: 0 0 8px; }
.errorlist { margin: 0; padding-left: 18px; color: #a61b1b; }
input, select, textarea { width: 100%; padding: 10px 11px; border: 1px solid #aab7c4; border-radius: 5px; background: var(--input); font: inherit; }
input[type="checkbox"] { width: auto; }
.actions { display: flex; gap: 10px; margin-top: 22px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }
.project-edit-card { max-width: none; margin: 0 auto; }
.project-position-table-wrap { max-height: calc(100vh - 260px); overflow: auto; border: 1px solid var(--line); border-radius: 7px; }
.project-position-edit-table { width: max-content; min-width: 100%; }
.project-position-edit-table th, .project-position-edit-table td { min-width: 155px; padding: 7px; vertical-align: top; }
.project-position-edit-table thead th { position: sticky; top: 0; z-index: 4; white-space: nowrap; background: #eaf1f7; box-shadow: 0 1px 0 var(--line); }
.project-position-edit-table tbody th { position: sticky; left: 0; z-index: 3; min-width: 175px; background: #f8fafc; box-shadow: 2px 0 3px rgba(27, 58, 95, .12); color: var(--navy); text-align: left; }
.project-position-edit-table thead th:first-child { left: 0; z-index: 6; }
.project-position-edit-table tbody th strong { display: block; margin-top: 5px; white-space: nowrap; }
.project-position-edit-table input, .project-position-edit-table select { min-width: 155px; }
.project-position-edit-table select { min-width: 240px; }
.project-position-edit-table textarea { min-width: 260px; height: 66px; resize: vertical; }
.project-position-edit-table .helptext { display: block; max-width: 240px; margin-top: 4px; color: var(--muted); font-size: 12px; }
.project-position-edit-table .errorlist { min-width: 180px; font-size: 12px; }
.project-position-edit-table .calculated-value { min-width: 135px; background: #f3f8fb; font-weight: 700; text-align: right; white-space: nowrap; }
.project-position-edit-table .offer-edit-total-row th,
.project-position-edit-table .offer-edit-total-row td { background: #dff1f2; border-top: 2px solid var(--teal); font-weight: 700; }
.project-position-edit-table .offer-edit-total-row th { z-index: 3; background: #dff1f2; }
.project-position-edit-table .offer-edit-total-row th span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; font-weight: 400; }
.project-position-edit-table .offer-edit-project-total-row th,
.project-position-edit-table .offer-edit-project-total-row td { background: #cfe8eb; border-top: 3px solid var(--navy); font-weight: 700; }
.project-position-edit-table .offer-edit-project-total-row th { position: sticky; left: 0; z-index: 3; background: #cfe8eb; }
.project-position-edit-table .offer-edit-project-total-row th span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; font-weight: 400; }
.project-position-edit-table .project-position-group-heading th,
.project-position-edit-table .project-position-group-heading td { background: #dff1f2; border-top: 2px solid var(--teal); color: var(--navy); font-weight: 700; }
.project-position-edit-table .project-position-group-heading th { z-index: 3; background: #dff1f2; }
.project-position-edit-table .local-freight-row th,
.project-position-edit-table .local-freight-row td { background: #fff6d8; border-top: 2px solid #d7a92d; }
.project-edit-actions { position: sticky; bottom: 0; z-index: 10; padding: 14px 0 4px; background: white; border-top: 1px solid var(--line); }
.receipt-selector-card { margin-bottom: 20px; }
.receipt-selector-row { display: flex; align-items: end; gap: 18px; flex-wrap: wrap; }
.receipt-selector-row > div:first-child { min-width: 360px; flex: 1; }
.receipt-selector-row label { display: block; font-weight: 700; margin-bottom: 6px; }
.receipt-selector-row select { width: 100%; }
.receipt-invoice-card { margin-bottom: 20px; padding: 16px 22px; }
.receipt-invoice-card .section-heading { margin-bottom: 12px; }
.receipt-invoice-card .section-heading p { margin: 4px 0 0; color: var(--muted); }
.receipt-history-card { margin-bottom: 20px; border-left: 4px solid var(--teal); }
.receipt-history-wrap { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 7px; }
.receipt-history-table { min-width: 3000px; }
.receipt-history-table th { position: sticky; top: 0; z-index: 2; white-space: nowrap; }
.receipt-history-table td { white-space: nowrap; }
.receipt-invoice-grid { display: grid; grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 10px 16px; }
.receipt-invoice-grid > div { display: flex; flex-direction: column; gap: 6px; }
.receipt-invoice-grid label { color: var(--navy); font-weight: 700; }
.receipt-invoice-grid input { padding-top: 8px; padding-bottom: 8px; }
.receipt-invoice-note { grid-column: auto; }
.receipt-items-card { margin-bottom: 0; }
.receipt-items-table { min-width: 3400px; }
.receipt-items-table th, .receipt-items-table td { vertical-align: top; }
.receipt-items-table td[rowspan] { background: #fbfdff; border-right: 1px solid var(--line); }
.receipt-items-table .receipt-auto-order { min-width: 180px; background: #f3f8fb; }
.receipt-items-table .receipt-auto-order span { color: var(--muted); }
.receipt-items-table .receipt-column-groups th { background: #dbe8f4; color: #163b63; text-align: center; }
.receipt-items-table .receipt-description { min-width: 320px; max-width: 520px; white-space: normal; }
.receipt-items-table input, .receipt-items-table select { min-width: 150px; }
.receipt-items-table textarea { min-width: 240px; min-height: 72px; resize: vertical; }
.receipt-items-table td:last-child input { min-width: 240px; }
.receipt-load-actions { margin-top: 16px; }
.receipt-position-table-wrap { max-height: calc(100vh - 300px); }
.receipt-save-actions { position: sticky; bottom: 0; z-index: 10; padding: 14px; background: var(--page); border-top: 1px solid var(--line); }
.receipt-header-card, .receipt-packing-card { margin-bottom: 20px; }
.receipt-header-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 15px 18px; }
.receipt-header-grid > div { display: flex; flex-direction: column; gap: 6px; }
.receipt-header-grid label { color: var(--navy); font-weight: 700; }
.readonly-field { min-height: 43px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 5px; background: #f3f8fb; font-weight: 700; }
.receipt-packing-table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 7px; }
.receipt-packing-table { min-width: 2500px; }
.receipt-packing-table thead th { position: sticky; top: 0; z-index: 2; white-space: nowrap; }
.receipt-packing-table td { vertical-align: top; }
.receipt-packing-table input, .receipt-packing-table select { min-width: 145px; }
.receipt-packing-table textarea { min-width: 210px; min-height: 72px; resize: vertical; }
.receipt-packing-table .packing-position-cell { min-width: 430px; }
.receipt-packing-table .packing-position-select { min-width: 410px; }
.receipt-packing-table .packing-quantity-cell { min-width: 210px; }
.packing-quantity-list { display: grid; gap: 7px; margin-top: 10px; }
.packing-quantity-list label { display: grid; grid-template-columns: minmax(220px, 1fr) 120px; align-items: center; gap: 8px; }
.packing-quantity-list input { min-width: 110px; }
.packing-quantity-list.packing-quantity-column label { grid-template-columns: minmax(90px, 1fr) 110px; margin-bottom: 8px; }
.packing-quantity-list.packing-quantity-column input { min-width: 100px; }
.packing-position-cell small { display: block; margin-top: 7px; color: var(--muted); }
.receipt-pack-actions { justify-content: flex-end; }
.receipt-entry-card { margin-bottom: 20px; padding: 18px 22px; border-left: 4px solid var(--teal); }
.receipt-entry-heading { margin-bottom: 14px; }
.receipt-entry-heading p, .receipt-packing-heading p { margin: 4px 0 0; color: var(--muted); }
.receipt-packing-heading { margin: 20px 0 12px; }
.receipt-packing-heading h3 { margin: 0; color: var(--navy); }
.receipt-next-actions { justify-content: flex-end; margin: 0 0 8px; }
.receipt-workflow-errors { margin: 0 0 16px; padding: 12px 30px; border: 1px solid #efb8b8; border-radius: 6px; background: #fff1f1; }

@media (max-width: 850px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 8px; padding: 16px; }
  .topbar nav { flex-wrap: wrap; }
  .container { padding: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .receipt-invoice-grid { grid-template-columns: 1fr; }
  .receipt-header-grid { grid-template-columns: 1fr; }
  .receipt-invoice-note { grid-column: auto; }
}
.document-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 560px;
}

.document-action-group {
  display: grid;
  grid-template-columns: minmax(145px, 1fr) auto auto auto auto;
  align-items: center;
  gap: 0.4rem;
}

.document-action-group form { margin: 0; }
.document-action-label small { display: block; margin-top: 2px; color: var(--muted); font-weight: 400; }

.document-inquiry-search {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto;
  align-items: center;
  gap: 12px;
}
.document-inquiry-search label { color: var(--navy); }
.document-start-card { border-left: 4px solid var(--teal); }
.document-project-summary {
  display: grid;
  grid-template-columns: minmax(150px, 0.55fr) minmax(280px, 1.4fr) minmax(260px, 1fr);
  gap: 24px;
  align-items: center;
  border-left: 5px solid var(--teal);
}
.document-project-summary h2 { margin: 3px 0 0; font-size: 2rem; }
.document-project-summary p { margin: 5px 0 0; }
.document-eyebrow { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; }
.document-section-list { display: grid; gap: 16px; }
.document-type-card { padding: 0; overflow: hidden; }
.document-type-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 20px;
  background: #eaf1f7;
  border-bottom: 1px solid var(--border);
}
.document-type-heading h2 { margin: 0; font-size: 1.25rem; }
.document-type-heading span { color: var(--muted); }
.document-work-row {
  display: grid;
  grid-template-columns: minmax(270px, 1fr) auto;
  gap: 20px;
  align-items: center;
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
}
.document-work-row:last-child { border-bottom: 0; }
.document-work-meta { display: grid; gap: 3px; }
.document-work-meta > strong { color: var(--navy); font-size: 1.05rem; }
.document-work-meta > span, .document-work-meta > small { color: var(--muted); }
.document-existing-note { color: #8a5a00 !important; font-weight: 600; }
.document-work-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.document-work-actions form { margin: 0; }
.archive-button { background: var(--navy); }
.document-empty-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  color: var(--muted);
}
.button.disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }

@media (max-width: 850px) {
  .document-inquiry-search { grid-template-columns: 1fr; }
  .document-project-summary { grid-template-columns: 1fr; gap: 12px; }
  .document-work-row { grid-template-columns: 1fr; }
  .document-work-actions { justify-content: flex-start; }
  .document-empty-row { align-items: flex-start; flex-direction: column; }
}
