:root {
  --ink: #111827;
  --muted: #64748b;
  --line: #111827;
  --panel: #ffffff;
  --soft: #f8fafc;
  --screen: #eef2f7;
  --accent: #0f172a;
  --accent2: #047857;
  --danger: #b91c1c;
  --border: #cbd5e1;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--screen);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  line-height: 1.25;
}
button, .button, select, input, textarea { font-family: inherit; font-size: 12px; }
button, .button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 11px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover, .button:hover { filter: brightness(1.08); }
button.secondary, .button.secondary { background: #fff; color: var(--accent); }
button.green { background: var(--accent2); border-color: var(--accent2); }
button.danger { background: var(--danger); border-color: var(--danger); }
button.small { padding: 5px 8px; border-radius: 6px; font-size: 11px; }
button.icon { width: 30px; height: 30px; padding: 0; border-radius: 6px; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, textarea, select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 9px;
  background: #fff;
  width: 100%;
  color: var(--ink);
}
textarea { min-height: 78px; resize: vertical; }
label { font-weight: 700; color: #334155; display: block; margin-bottom: 5px; }
.checkbox-label { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 4px; font-weight: 800; }
.checkbox-label input { width: auto; margin-top: 2px; }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 18px rgba(15, 23, 42, .12);
  padding: 10px 12px;
}
.toolbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.toolbar-title { font-weight: 900; color: var(--accent); margin-right: 8px; }
.toolbar select { max-width: 310px; min-width: 260px; }
.status { color: var(--muted); font-weight: 700; margin-left: auto; }
.status.ok { color: var(--accent2); }
.status.err { color: var(--danger); }
.helper { color: var(--muted); flex-basis: 100%; font-size: 11px; }
.helper-inline { color: var(--muted); font-size: 11px; }

.app-wrap {
  max-width: 1180px;
  margin: 18px auto 40px;
  padding: 0 12px;
  overflow-x: auto;
}
.notice-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 5px 18px rgba(15, 23, 42, .08);
}
.notice-card strong { color: var(--accent); }

/* Original arrival-notice / invoice layout: flat rows, no boxed party grid, print/download preserved. */
.invoice-sheet {
  background: #fff;
  width: 100%;
  max-width: 1000px;
  min-height: 1380px;
  margin: 0 auto;
  padding: 22px 24px 20px;
  border: 0;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .16);
  color: #000;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.08;
}
.sheet-flex {
  min-height: 1338px;
  display: flex;
  flex-direction: column;
}
.original-header {
  display: grid;
  grid-template-columns: 280px 1fr 190px;
  gap: 12px;
  align-items: start;
  min-height: 84px;
}
.original-logo-wrap {
  min-height: 80px;
  display: flex;
  align-items: flex-start;
}
.original-logo-wrap img {
  max-width: 270px;
  max-height: 78px;
  object-fit: contain;
}
.original-logo-text {
  font-size: 24px;
  font-weight: 900;
  line-height: .95;
  text-transform: uppercase;
  color: #111;
  max-width: 270px;
}
.original-company-block {
  padding-top: 2px;
  font-size: 16px;
  line-height: 1.08;
}
.original-company-name {
  font-weight: 900;
  font-size: 18px;
  margin-bottom: 2px;
}
.original-company-details { white-space: normal; }
.original-doc-meta {
  text-align: right;
  font-size: 12px;
  line-height: 1.25;
  padding-top: 4px;
}
.original-title {
  text-align: center;
  font-size: 29px;
  font-weight: 900;
  line-height: 1;
  margin: 8px 0 5px;
  letter-spacing: .3px;
}
.original-subtitle {
  text-align: center;
  font-size: 18px;
  margin-bottom: 5px;
  text-transform: uppercase;
}
.original-rule {
  border-top: 2px solid #000;
  height: 1px;
  margin-bottom: 5px;
}
.original-parties {
  margin: 0 6px 20px;
  font-size: 14px;
}
.original-row {
  display: grid;
  grid-template-columns: 205px 1fr;
  gap: 8px;
  min-height: 18px;
}
.original-label { color: #000; }
.original-value { color: #000; }
.party-spacer { height: 17px; }
.original-shipment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 62px;
  margin: 0 6px 6px;
  font-size: 14px;
}
.shipment-row {
  display: grid;
  grid-template-columns: 205px 1fr;
  gap: 8px;
  min-height: 18px;
}
.shipment-label, .shipment-value { color: #000; }
.table-section { margin: 0 0 8px; }
.invoice-table.original-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
  color: #000;
}
.invoice-table.original-table th,
.invoice-table.original-table td {
  border: 0;
  padding: 3px 8px;
  vertical-align: top;
  overflow-wrap: anywhere;
}
.invoice-table.original-table th {
  background: transparent;
  color: #000;
  font-size: 18px;
  line-height: 1.05;
  font-weight: 900;
  text-transform: none;
  letter-spacing: 0;
}
.invoice-table.original-table td { font-size: 14px; }
.invoice-table.original-table .left { text-align: left; }
.invoice-table.original-table .center { text-align: center; }
.invoice-table.original-table .num { text-align: right; white-space: nowrap; }
.charges-table th:nth-child(1), .charges-table td:nth-child(1) { width: 23%; }
.charges-table th:nth-child(2), .charges-table td:nth-child(2) { width: 12%; }
.charges-table th:nth-child(3), .charges-table td:nth-child(3) { width: 15%; }
.charges-table th:nth-child(4), .charges-table td:nth-child(4) { width: 17%; }
.charges-table th:nth-child(5), .charges-table td:nth-child(5) { width: 16%; }
.charges-table th:nth-child(6), .charges-table td:nth-child(6) { width: 17%; }
.charges-table tfoot td {
  border-top: 2px solid #000 !important;
  border-bottom: 2px solid #000 !important;
  background: transparent !important;
  font-style: italic;
  font-weight: 900;
  padding-top: 6px;
  padding-bottom: 5px;
}
.charges-table .total-label { text-align: center; }
.containers-section { margin-top: 8px; }
.containers-table thead th {
  border-top: 2px solid #000 !important;
  border-bottom: 2px solid #000 !important;
  padding-top: 7px !important;
  padding-bottom: 7px !important;
}
.containers-table th:nth-child(1), .containers-table td:nth-child(1) { width: 14%; }
.containers-table th:nth-child(2), .containers-table td:nth-child(2) { width: 8%; }
.containers-table th:nth-child(3), .containers-table td:nth-child(3) { width: 12%; }
.containers-table th:nth-child(4), .containers-table td:nth-child(4) { width: 13%; }
.containers-table th:nth-child(5), .containers-table td:nth-child(5) { width: 12%; }
.containers-table th:nth-child(6), .containers-table td:nth-child(6) { width: 12%; }
.containers-table th:nth-child(7), .containers-table td:nth-child(7) { width: 29%; }
.commodity-cell { white-space: normal; }
.bank-footer-wrap {
  margin-top: auto;
  padding-top: 20px;
}
.single-bank-box {
  margin: 0 auto 10px;
  width: 92%;
  border: 2px solid #000;
  padding: 10px 12px;
  min-height: 168px;
  page-break-inside: avoid;
}
.single-bank-box h3 {
  margin: -42px 0 16px 0;
  text-align: center;
  font-size: 22px;
  line-height: 1.1;
  text-decoration: underline;
  font-weight: 900;
}
.bank-details-text {
  font-size: 16px;
  line-height: 1.2;
  white-space: normal;
}
.invoice-footer {
  text-align: center;
  font-size: 12px;
  line-height: 1.2;
  margin-top: 10px;
}
.invoice-footer p { margin: 5px 0; }
.original-source-note {
  max-width: 1000px;
  margin: 8px auto 0;
  font-size: 11px;
  color: #475569;
  text-align: center;
}
/* Modal and editor styles */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .65);
  z-index: 200;
  display: none;
  align-items: stretch;
  justify-content: flex-end;
}
.modal-overlay.open { display: flex; }
.modal-panel {
  width: min(980px, 96vw);
  height: 100vh;
  background: var(--panel);
  overflow: auto;
  box-shadow: -12px 0 34px rgba(15, 23, 42, .25);
  display: flex;
  flex-direction: column;
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 18px; }
.modal-actions {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.form-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  background: #fff;
}
.form-section h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.grid-2, .grid-3, .grid-4 { display: grid; gap: 10px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.save-defaults-box {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #f8fafc;
}
.logo-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.logo-preview {
  width: 160px;
  height: 82px;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--muted);
  font-weight: 900;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th, .edit-table td { border: 1px solid var(--border); padding: 5px; vertical-align: top; }
.edit-table th { background: #f8fafc; text-transform: uppercase; font-size: 10px; color: #475569; }
.edit-table input, .edit-table textarea { border: 0; border-radius: 0; padding: 5px; background: transparent; }
.edit-table input:focus, .edit-table textarea:focus { outline: 2px solid #bfdbfe; background: #eff6ff; }
.row-remove { color: #fff; background: var(--danger); border-color: var(--danger); }
.table-actions { margin-top: 8px; display: flex; gap: 8px; }
.print-toolbar {
  max-width: 1050px;
  margin: 14px auto;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.print-toolbar-left, .print-toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .16);
}
.login-card h1 { margin-top: 0; }
.login-error { color: var(--danger); font-weight: 800; }

@media (max-width: 860px) {
  .invoice-sheet { padding: 18px 14px; min-width: 820px; }
  .original-header { grid-template-columns: 220px 1fr 160px; }
  .original-logo-wrap img { max-width: 210px; }
  .original-row, .shipment-row { grid-template-columns: 170px 1fr; }
  .original-shipment-grid { gap: 28px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2, .span-3, .span-4 { grid-column: span 1; }
  .table-section { overflow-x: visible; }
  .edit-table { min-width: 860px; }
}

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { width: 100%; margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body { font-size: 10px !important; }
  .no-print, .toolbar, .notice-card, .modal-overlay, .print-toolbar, .original-source-note { display: none !important; }
  .app-wrap {
    margin: 0 auto !important;
    padding: 0 !important;
    max-width: none !important;
    overflow: visible !important;
  }
  .invoice-sheet {
    width: 100% !important;
    max-width: none !important;
    min-height: calc(297mm - 16mm) !important;
    margin: 0 auto !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    page-break-after: avoid;
    font-size: 9.2pt !important;
  }
  .sheet-flex { min-height: calc(297mm - 16mm) !important; }
  .original-header { grid-template-columns: 70mm 1fr 38mm !important; min-height: 20mm !important; }
  .original-logo-wrap img { max-width: 68mm !important; max-height: 19mm !important; }
  .original-logo-text { font-size: 16pt !important; }
  .original-company-block { font-size: 10.2pt !important; }
  .original-company-name { font-size: 11pt !important; }
  .original-doc-meta { font-size: 7.5pt !important; }
  .original-title { font-size: 18pt !important; margin-top: 2mm !important; }
  .original-subtitle { font-size: 10.5pt !important; }
  .original-parties, .original-shipment-grid, .invoice-table.original-table td { font-size: 8.7pt !important; }
  .original-row, .shipment-row { grid-template-columns: 38mm 1fr !important; min-height: 4mm !important; }
  .party-spacer { height: 4mm !important; }
  .original-shipment-grid { gap: 12mm !important; }
  .invoice-table.original-table th { font-size: 10.3pt !important; }
  .single-bank-box { width: 92% !important; min-height: 30mm !important; }
  .single-bank-box h3 { font-size: 13pt !important; }
  .bank-details-text { font-size: 9.2pt !important; }
  .invoice-footer { font-size: 7.5pt !important; }
  @page { size: A4; margin: 8mm; }
}

.download-body { background: #fff; }
.download-wrap { margin: 0 auto; padding: 0; max-width: none; overflow: visible; }
.download-wrap .invoice-sheet { box-shadow: none; }
