/* CACHE BUST TIMESTAMP: 1732455200000 - TERMS 70% WIDTH IN PRINT ONLY */

/* ===== MODERN LOADING & TRANSITIONS ===== */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Loading indicator animations */
#loading-indicator {
  animation: slideDown 0.3s ease-out;
}

/* App container fade-in */
.app-container {
  animation: fadeIn 0.3s ease-in;
}

/* Skeleton loading effect for initial render */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Smooth transitions for all interactive elements */
button, .doc-tab, input, select, textarea {
  transition: all 0.2s ease-in-out;
}

/* Prevent flash of unstyled content */
.app-container[style*="display: none"] {
  visibility: hidden;
}

.app-container[style*="display: block"] {
  visibility: visible;
}

/* ===== END MODERN LOADING & TRANSITIONS ===== */

:root {
  --invoice-blue: #4a90e2;
  --quotation-green: #1fa67a;
  --delivery-red: #e64c4c;
  --grey-border: #e0e0e0;
  
  /* Light grey button colors - neutral and professional */
  --button-bg: #f0f0f0;
  --button-hover: #e5e5e5;
  --button-text: #333333;
  --button-border: #d0d0d0;
  --button-shadow: rgba(0, 0, 0, 0.1);
  
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --bg-light: #F9FAFB;
  --white: #FFFFFF;
  --footer-border: #333333;
  --lighter-color: #888888;
  --doc-base-font-size: 13px; /* increased for readability */
  --doc-small-font: 13px; /* match base */
  --doc-heading-font: 22px; /* document heading (Quotation/Invoice/Delivery) */
  --company-short-font: 34px; /* company short name in header */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Montserrat', 'Roboto', sans-serif, system-ui;
  background: var(--bg-light);
  min-height: 100vh;
  font-size: 17px; /* slight overall increase */
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body, html, input, textarea, select, button, table, th, td, label, .modal, .footer, .notes-section, .terms, .signatures, .signatory, .signature-space, .app-container, .tab-content, .header, .document-section, .document-title, .item-table, .totals, .footer, .notes-section label, .terms, .signatures span {
  font-family: 'Montserrat', 'Roboto', Arial, Helvetica, sans-serif !important;
  font-size: 1rem;
  font-weight: 400;
  color: #222;
}

body, .document, .document textarea, .document select, .document td, .document th {
  font-size: 0.95em !important;
}

.items-table input, .items-table textarea {
  font-size: 0.95em !important;
}

/* REMOVED: .customer-details input, .invoice-details input font-size override 
   so local 12px rules can work */

.document-title, h1, h2, h3, h4, h5, h6 {
  font-family: 'Montserrat', 'Roboto', Arial, Helvetica, sans-serif !important;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #222;
}

.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  align-items: center;
}

/* Header redesign: simpler, smaller controls */
.header-bar {
  width: 100%;
  max-width: 100vw;
  background: var(--white);
  padding: 6px 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1000;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: flex-start;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  justify-content: center;
  flex-wrap: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.header-left input, .header-left button, .header-center input, .header-center button, .header-right input, .header-right button {
  padding: 7px 10px;
  height: 34px;
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--button-text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: 0 1px 3px var(--button-shadow);
  transition: all 0.2s ease;
}

/* Left buttons - more compact */
.header-left button {
  padding: 7px 10px;
  font-size: 12px;
}

/* Dashboard and Customer SOA buttons should always be visible */
#tab-overview,
#tab-customer {
  display: flex !important;
}

/* Convert buttons - extra compact */
#create-invoice-btn,
#create-delivery-btn {
  padding: 7px 8px;
  font-size: 11.5px;
}

/* Right-side document tabs - slightly longer */
.header-right button {
  padding: 7px 14px;
  min-width: 110px;
  font-size: 13px;
}

.header-bar button:hover {
  background: var(--button-hover);
  box-shadow: 0 2px 6px var(--button-shadow);
  transform: translateY(-1px);
}

.header-bar button:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px var(--button-shadow);
}

/* Open file button states */
#open-file-btn {
  background: #c0392b; /* red by default */
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
}
#open-file-btn.file-btn--loaded {
  background: #27ae60; /* green when loaded */
}
#open-file-btn.file-btn--unloaded {
  background: #c0392b; /* red when not loaded */
}

/* Modal open button style consistency */
#modal-open-file-btn {
  background: #6366f1;
  color: #fff;
  font-size: 1em;
  padding: 10px 20px;
  border-radius: 8px;
}

#modal-open-file-btn:hover {
  background: #4f46e5;
}

/* Instruction ticker styles */
.instruction-ticker {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  transition: all 0.4s ease;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  display: none !important; /* Hidden - ticker notification removed */
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.instruction-ticker--unloaded {
  background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
  color: #c62828;
  border-bottom-color: #ef5350;
}

.instruction-ticker--loaded {
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
  color: #2e7d32;
  border-bottom-color: #66bb6a;
}

#ticker-icon {
  font-size: 18px;
  animation: pulse 2s ease-in-out infinite;
}

#ticker-message {
  letter-spacing: 0.3px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.1); }
}

.doc-tab.active-tab#tab-invoice {
  background: var(--invoice-blue);
}

.doc-tab.active-tab#tab-quotation {
  background: var(--quotation-green);
}

.doc-tab.active-tab#tab-delivery {
  background: var(--delivery-red);
}

.main-content {
  flex-grow: 1;
  width: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.document {
  width: 210mm;
  height: 297mm;
  background: var(--white);
  padding: 6mm;
  margin: 10mm auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
  position: relative;
  display: none;
  overflow: hidden;
  font-size: var(--doc-base-font-size); /* use document base size */
}

.document.active {
  display: block;
  margin: 10mm auto;
}

.header {
  border-bottom: 3px solid transparent; /* thicker, color set per document */
  padding-bottom: 6px; /* reduced spacing */
  margin-bottom: 8px;
}

/* Per-document header color */
#invoice .header { border-color: var(--invoice-blue); }
#quotation .header { border-color: var(--quotation-green); }
#delivery .header { border-color: var(--delivery-red); }

.company-details {
  text-align: left;
}

.company-details p {
  font-size: 12px;
  line-height: 1.4;
  color: #555;
  margin-top: 4px;
}

.company-name {
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 8px;
}

.company-short-name {
  font-size: var(--company-short-font);
  font-weight: 800;
  letter-spacing: 1px;
}

#invoice .company-short-name { color: var(--invoice-blue); }
#quotation .company-short-name { color: var(--quotation-green); }
#delivery .company-short-name { color: var(--delivery-red); }

.company-full-name, .company-trn {
  font-size: 14px;
  color: #444;
  font-weight: 600;
}

/* ========================================
   CUSTOMER & INVOICE DETAILS SECTION
   EXTREME PRECISION - Matching table headers exactly
   ======================================== */

.details {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: 8px 0 10px 0;
  gap: 40px;
}

/* ===== LEFT SIDE: Customer Details ===== */
.customer-details {
  display: flex;
  flex-direction: column;
  gap: 2px; /* Compact vertical spacing on screen */
  flex: 1;
  max-width: 50%;
  margin-left: 0;
  padding-left: 0;
}

.customer-details div {
  display: flex;
  align-items: center;
  gap: 4px; /* Reduced gap - move values closer to labels */
  height: 26px;
}

/* ALL Labels - Regular weight on screen, BOLD only in print */
.customer-details label {
  font-family: Arial, sans-serif;
  font-size: 12px;
  font-weight: 400; /* Regular weight on screen */
  color: #000;
  width: 35px; /* Fixed width for alignment */
  flex-shrink: 0;
  text-align: left;
  margin: 0;
  padding: 0;
  line-height: 26px;
}

/* ALL Inputs - UNBOLD, SAME SIZE, SAME HEIGHT */
.customer-details input {
  flex: 1;
  font-family: Arial, sans-serif;
  font-size: 12px;
  font-weight: 400; /* UNBOLD */
  color: #333;
  border: 1px solid #ddd;
  border-radius: 3px;
  padding: 4px 6px; /* Compact padding */
  height: 26px;
  line-height: normal;
  box-sizing: border-box;
}

.customer-details input:focus {
  border-color: #0760a8;
  outline: none;
}

/* Customer Name - Borderless, keep full width for long names */
.customer-details input[data-cell="name"] {
  border: none;
  background: transparent;
  font-weight: 700; /* BOLD for name only */
  font-size: 12px; /* SAME as others */
  padding: 4px 2px;
  max-width: none; /* Allow full width for long company names */
}

.customer-details input[data-cell="name"]:focus {
  background: rgba(7, 96, 168, 0.05);
  border-radius: 3px;
}

/* ===== RIGHT SIDE: Invoice Details ===== */
.invoice-details {
  display: flex;
  flex-direction: column;
  gap: 2px; /* Compact vertical spacing - SAME as left */
  min-width: 200px;
  align-items: flex-end;
}

.invoice-details div {
  display: flex;
  align-items: center;
  gap: 4px; /* Reduced gap - move labels closer to values */
  height: 26px;
  width: 100%;
  justify-content: flex-end;
}

/* ALL Labels - Regular weight on screen, BOLD only in print */
.invoice-details label {
  font-family: Arial, sans-serif;
  font-size: 12px;
  font-weight: 400; /* Regular weight on screen */
  color: #000;
  width: 45px; /* Fixed width for alignment */
  flex-shrink: 0;
  text-align: left;
  margin: 0;
  padding: 0;
  line-height: 26px;
}

/* ALL Inputs - UNBOLD except doc number */
.invoice-details input,
.invoice-details select {
  font-family: Arial, sans-serif;
  font-size: 12px;
  font-weight: 400; /* UNBOLD */
  color: #333;
  border: none; /* Remove border by default */
  border-radius: 0;
  padding: 4px 6px; /* Compact padding */
  height: 26px;
  line-height: normal;
  box-sizing: border-box;
  text-align: right;
  width: 91px; /* Reduced by 30% from 130px */
  background: transparent;
}

.invoice-details input:focus,
.invoice-details select:focus {
  outline: 1px solid #0760a8;
}

/* Document number - BOLD on screen with box and rounded corners */
.invoice-details input[id$="-number"] {
  font-weight: 700; /* BOLD for document number */
  color: #000;
  border: 1px solid #ddd; /* Only doc number has border */
  border-radius: 5px; /* Rounded corners */
  background: white;
}

/* Date - Borderless but SAME font/size as other inputs */
.invoice-details .date-cell {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 4px 6px; /* Match other inputs */
  width: 95px; /* Slightly larger to fit date without wrapping */
  text-align: right;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap; /* Prevent wrapping */
}

.invoice-details .date-cell:hover {
  background: rgba(7, 96, 168, 0.05);
  border-radius: 3px;
}

.invoice-details .date-display {
  font-family: Arial, sans-serif;
  font-size: 12px; /* EXACT match */
  font-weight: 400; /* UNBOLD */
  color: #333;
  white-space: nowrap; /* Prevent wrapping */
}

/* Document Number - BOLD (only value that's bold) */
.invoice-details input[id$="-number"] {
  font-weight: 700; /* BOLD */
  color: #000;
}

/* Readonly numbers */
.invoice-details input[readonly] {
  background: #f9f9f9;
  cursor: not-allowed;
}

.logo {
  position: absolute;
  top: 6mm;
  right: 6mm;
  width: 80px;
  height: 50px;
}

.logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

h2 {
  font-size: var(--doc-heading-font);
  margin: 10px 0 14px 0;
  text-align: center;
  color: var(--invoice-blue);
  letter-spacing: 1px;
}

/* Per-document h2 color */
#invoice h2 { color: var(--invoice-blue); }
#quotation h2 { color: var(--quotation-green); }
#delivery h2 { color: var(--delivery-red); }

/* ===== Adjustments: compact item rows, single table spacing, boxed totals ===== */
/* Ensure no accidental gaps between tbody rows */
.items-table {
  width: 100%;
  border-collapse: collapse !important;
  border-spacing: 0 !important;
  margin: 8px 0 0 0 !important; /* no gap below table */
  table-layout: fixed;
}
/* Slightly reduce per-row height and tighten padding */
.items-table th, .items-table td {
  padding: 2px 6px !important;
  height: 18px !important; /* reduced for more compact rows */
  font-size: 13px !important;
  vertical-align: middle !important;
}
.items-table input {
  height: 14px !important; /* reduced to match row height */
  padding: 1px 3px !important;
  font-size: 13px !important;
}
/* Totals area: make each footer row look like a separate boxed row */
.items-table tfoot tr td {
  border: none !important; /* clear previous thin rules */
  padding: 0 !important;
  background: transparent !important;
}
.items-table tfoot tr {
  display: table-row;
}
/* ONLY style cells that have the .total-label or .total-value classes */
.items-table tfoot tr td.total-label,
.items-table tfoot tr td.total-value {
  background: #f6f8fa !important;
  border: 1px solid var(--grey-border) !important;
  padding: 4px 8px !important;
  height: 26px !important;
  box-sizing: border-box !important;
}
/* Ensure label cell(s) are right aligned and the value cell bold */
.items-table tfoot tr td.total-label { text-align: right !important; font-weight: 600 !important; }
.items-table tfoot tr td.total-value { text-align: right !important; font-weight: 800 !important; }
/* For delivery layout where totals sit in last two columns ensure left cells have proper text alignment */
#delivery .items-table tfoot td:nth-last-child(2) { text-align: left !important; }
#delivery .items-table tfoot td:last-child { text-align: right !important; }
/* Words cell - no borders */
.items-table tfoot tr td.words-cell-merged {
  background: transparent !important;
  border: none !important;
  padding: 4px 6px !important;
  vertical-align: top !important;
  line-height: 1.4 !important;
}
/* Print mirror: ensure boxed totals and compact rows print the same */
@media print {
  .items-table { margin: 6mm 0 8mm 0 !important; }
  .items-table th, .items-table td { padding: 2px 5px !important; height: 18px !important; }
  .items-table input { height: 14px !important; }
  /* ONLY style cells with .total-label or .total-value classes */
  .items-table tfoot tr td.total-label,
  .items-table tfoot tr td.total-value {
    background: #f6f8fa !important;
    border: 1px solid var(--grey-border) !important;
    padding: 4px 7px !important;
    height: 26px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  /* Words cell - absolutely no borders */
  .items-table tfoot tr td.words-cell-merged {
    background: transparent !important;
    border: none !important;
    padding: 4px 6px !important;
    vertical-align: top !important;
  }

  /* Add back bottom border under products table */
  #invoice .items-table tbody tr:last-child,
  #quotation .items-table tbody tr:last-child,
  #delivery .items-table tbody tr:last-child {
    border-bottom: 1px solid #ddd !important;
  }

  /* Add bottom border under products row number 14 in delivery order */
  #delivery .items-table tbody tr:nth-child(14) {
    border-bottom: 1px solid #ddd !important;
  }
  
  #delivery .items-table tbody tr:nth-child(14) td {
    border-bottom: 1px solid #ddd !important;
  }

  /* Totals area must be completely borderless except labeled totals cells */
  .items-table tfoot tr, .items-table tfoot td { border: none !important; background: transparent !important; padding: 0 !important; height: 0 !important; }

  /* For delivery, hide borders around totals row except top */
  #delivery .items-table tfoot tr {
    border-left: 1px solid white !important;
    border-right: 1px solid white !important;
    border-bottom: 1px solid white !important;
    border-top: 1px solid #ddd !important;
  }
  #delivery .items-table tfoot td {
    border-left: 1px solid white !important;
    border-right: 1px solid white !important;
    border-bottom: 1px solid white !important;
    border-top: 1px solid white !important;
  }

  /* Kill UA borders on form controls in print (prevents box around notes) */
  textarea, input, select { 
    -webkit-appearance: none !important; appearance: none !important;
    background: transparent !important; border: none !important; outline: none !important; box-shadow: none !important;
  }
  .terms-editable { padding: 0 !important; }
  
  /* Ensure the empty helper column in tfoot stays invisible */
  .items-table tfoot td:not(.total-label):not(.total-value):not(.words-cell-merged) {
    border: none !important; background: transparent !important; padding: 0 !important; height: 0 !important;
  }

  /* EXTRA HARD-KILL for the stray hairline under the words/above notes */
  /* 1) make sure last body row cells have no bottom border */
  .items-table tbody tr:last-child td { border-bottom: none !important; }
  /* 2) remove any borders applied by inner content in the words cell */
  .items-table tfoot td.words-cell-merged, 
  .items-table tfoot td.words-cell-merged * { border: 0 !important; background: transparent !important; }
  .total-in-words { border: 0 !important; padding-top: 0 !important; margin-top: 0 !important; }
  /* 3) notes/terms should print as plain text only */
  .notes-section, .terms, .account-details { border: 0 !important; background: transparent !important; padding: 0 !important; box-shadow: none !important; }
}

@media print {
  /* Ensure tfoot rows never draw a row border (overrides generic .items-table tr border-bottom) */
  .items-table tfoot, .items-table tfoot tr { border: none !important; border-bottom: none !important; }
}

@media print {
  /* Remove bottom border of the items table to avoid a hairline under the words cell */
  .items-table { border-bottom: none !important; }
  /* Ensure no bottom borders sneak in from the final rendered row/cells */
  .items-table tbody tr:last-child td,
  .items-table tfoot tr:last-child td { border-bottom: none !important; }
  /* Cancel the negative margin between table and terms for print to prevent overlap on the table edge */
  .items-table + .terms-editable { margin-top: 2mm !important; }
  /* Hard remove any residual top/bottom borders at the table-to-terms junction */
  .items-table tfoot td, .items-table tfoot tr { border-top: 0 !important; border-bottom: 0 !important; }
  .items-table tbody tr:last-child td { border-bottom: 0 !important; }

  /* Add a neat grey guide line only under the words area (as per green mark) */
  .items-table tfoot td.words-cell-merged { position: relative !important; }
  .items-table tfoot td.words-cell-merged::after {
    content: "" !important;
    display: block !important;
    height: 0 !important;
    border-top: 1px solid var(--grey-border) !important; /* light grey */
    margin-top: 2mm !important;
    width: 92% !important; /* stop before the totals columns */
  }
}

@media print {
  /* Replace the underline with a top guide line exactly at the words row start */
  .items-table tfoot td.words-cell-merged { position: relative !important; }
  .items-table tfoot td.words-cell-merged::after { display: none !important; }
  .items-table tfoot td.words-cell-merged::before {
    content: "" !important;
    position: absolute !important;
    top: -1px !important; /* sit exactly on the row boundary */
    left: 0 !important;
    right: 0 !important;
    border-top: 1px solid var(--grey-border) !important; /* light grey line per design */
  }
}

@media print {
  /* Place a subtle grey line at the bottom of the words cell only */
  .items-table tfoot td.words-cell-merged { position: relative !important; }
  .items-table tfoot td.words-cell-merged::before { display: none !important; }
  .items-table tfoot td.words-cell-merged::after {
    content: "" !important;
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    border-bottom: 1px solid var(--grey-border) !important; /* light grey */
  }
}
/* End adjustments */

.items-table th, .items-table td {
  border: 1px solid var(--grey-border);
  padding: 6px 8px;
  font-size: 14px; /* slightly larger for print */
  height: 22px;
}

.items-table th {
  color: var(--white);
  font-weight: bold;
  text-align: center !important;
  vertical-align: middle;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.items-table td {
  vertical-align: middle;
  font-size: 13px;
}

#invoice .items-table th {
  background: var(--invoice-blue);
}

#quotation .items-table th {
  background: var(--quotation-green);
}

#delivery .items-table th {
  background: var(--delivery-red);
}

.items-table td:nth-child(3) {
  text-align: left;
}

.items-table td:nth-child(5), .items-table td:nth-child(6) {
  text-align: right;
}

.items-table input {
  width: 100%;
  border: none;
  padding: 1px 4px;
  font-size: 14px;
  text-align: inherit;
  height: 18px;
}

.items-table input:focus {
  outline: none;
}

.items-table input[type="number"] {
  -webkit-appearance: none;
  appearance: textfield;
}

.items-table input[type="number"]::-webkit-inner-spin-button,
.items-table input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

#invoice .items-table th:nth-child(1), #invoice .items-table td:nth-child(1) { width: 6%; text-align: center; }
#invoice .items-table th:nth-child(2), #invoice .items-table td:nth-child(2) { width: 12%; text-align: left; }
#invoice .items-table th:nth-child(3), #invoice .items-table td:nth-child(3) { width: 44%; text-align: left; }
#invoice .items-table th:nth-child(4), #invoice .items-table td:nth-child(4) { width: 7%; text-align: center; }
#invoice .items-table th:nth-child(5), #invoice .items-table td:nth-child(5) { width: 12%; text-align: right; }
#invoice .items-table th:nth-child(6), #invoice .items-table td:nth-child(6) { width: 14%; text-align: right; }

#quotation .items-table th:nth-child(1), #quotation .items-table td:nth-child(1) { width: 6%; text-align: center; }
#quotation .items-table th:nth-child(2), #quotation .items-table td:nth-child(2) { width: 12%; text-align: left; }
#quotation .items-table th:nth-child(3), #quotation .items-table td:nth-child(3) { width: 44%; text-align: left; }
#quotation .items-table th:nth-child(4), #quotation .items-table td:nth-child(4) { width: 7%; text-align: center; }
#quotation .items-table th:nth-child(5), #quotation .items-table td:nth-child(5) { width: 12%; text-align: right; }
#quotation .items-table th:nth-child(6), #quotation .items-table td:nth-child(6) { width: 14%; text-align: right; }

#delivery .items-table th:nth-child(1), #delivery .items-table td:nth-child(1) { width: 8%; text-align: center; }
#delivery .items-table th:nth-child(2), #delivery .items-table td:nth-child(2) { width: 20%; text-align: left; }
#delivery .items-table th:nth-child(3), #delivery .items-table td:nth-child(3) { width: 44%; text-align: left; }
#delivery .items-table th:nth-child(4), #delivery .items-table td:nth-child(4) { width: 14%; text-align: center; }
#delivery .items-table th:nth-child(5), #delivery .items-table td:nth-child(5) { width: 14%; text-align: center; }

.items-table tfoot td {
  height: 16px;
  padding: 2px 4px;
  line-height: 1.1;
  font-size: 14px;
  text-align: right;
  vertical-align: middle;
  border-top: 2px solid #e0e0e0;
}

/* Delivery Note/Quotation/Invoice table font consistency */
.item-table, .item-table th, .item-table td {
  font-family: 'Roboto', Arial, Helvetica, sans-serif !important;
  font-size: 1rem;
  color: #222;
}

/* Remove grey borders after 14th product row, except amount column boxes */
#invoice .items-table tbody tr:nth-child(n+15) td,
#quotation .items-table tbody tr:nth-child(n+15) td {
  border: none;
}

#invoice .items-table tfoot td:not(:last-child) {
  border: none;
}

#quotation .items-table tfoot td:not(:last-child) {
  border: none;
}

/* Right-align Subtotal, Vat5%, G.Total in price column */
#invoice .items-table tfoot td:nth-child(5),
#quotation .items-table tfoot td:nth-child(5) {
  text-align: right;
}

#delivery .items-table tfoot td:nth-child(4),
#delivery .items-table tfoot td:nth-child(5) {
  text-align: center;
}

#delivery .items-table tfoot #delivery-ordered-total,
#delivery .items-table tfoot #delivery-delivered-total {
  text-align: center !important;
}

#delivery .items-table tfoot tr {
  height: 1.5em;
}

#delivery .items-table tfoot td:nth-child(1) {
  border: none;
}

.items-table tfoot td:nth-child(5) {
  text-align: right;
  font-weight: normal;
}

#quotation .items-table tfoot td:nth-child(5) {
  padding-left: 30px;
}

.items-table tfoot td:last-child {
  text-align: right;
}

.items-table .line-total {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.total-in-words {
  font-size: 16px;
  line-height: 1.4;
  padding: 4px 0;
  text-align: left;
  display: inline-block;
  white-space: normal;
  word-break: break-word;
  font-style: italic;
  color: #666;
  padding: 8px;
  border-top: 1px solid var(--grey-border);
  white-space: normal !important;
  display: inline-block;
  min-width: 320px;
  max-width: 100%;
  white-space: pre-line;
  font-size: 0.98em;
  font-weight: 500;
  color: #0760a8;
  vertical-align: middle;
}

#invoice-words, #quotation-words {
  display: block;
  min-width: 320px;
  max-width: 100%;
  white-space: pre-line;
  font-size: 0.98em;
  font-weight: 500;
  color: #0760a8;
  margin-top: 4px;
  margin-bottom: 4px;
}

/* Total in words inline (inside table footer) - Screen styles */
.words-inline {
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
  color: #0760a8;
  font-weight: 600;
  font-style: normal;
  display: block;
  padding: 4px 0;
}

.total-label {
  text-align: right;
  padding-right: 8px;
  font-weight: 600;
  color: #333;
}

.total-value {
  text-align: right;
  font-weight: 700;
  font-size: 14px;
  padding-right: 6px;
}

.notes-section {
  margin-top: 0.5em;
  margin-bottom: 1em;
  font-size: 0.82rem !important;
  color: #333;
  background: #f8f8f8;
  padding: 0.4em 0.7em !important;
  border-radius: 5px !important;
  border: 1px solid #e0e0e0;
  max-width: 350px !important;
  width: 350px !important;
  box-sizing: border-box;
  overflow: hidden !important;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.4;
}

/* Notes, Terms, and Signatures sections */
.notes-section textarea, .terms, .signatures, .signatory, .signature-space {
  font-family: 'Roboto', Arial, Helvetica, sans-serif !important;
  font-size: 1rem;
  color: #222;
}

.center-align {
  display: block;
  text-align: center;
}

.account-details, .terms {
  font-size: 10px;
  color: #333;
  margin: 7px 0;
}

.terms {
  margin-top: 1.5em;
  margin-bottom: 1em;
  font-size: 0.95rem;
  color: #333;
  background: #f8f8f8;
  padding: 0.8em 1em;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  margin-top: 1em;
  margin-bottom: 0.7em;
  font-size: 0.88rem !important;
  color: #333;
  background: #f8f8f8;
  padding: 0.5em 0.8em;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  max-width: 480px;
}

.terms.small-box, .account-details.small-box {
  font-size: 0.82rem !important;
  padding: 0.4em 0.7em !important;
  max-width: 350px !important;
  width: 350px !important; /* enforce same length as terms */
  margin-top: 0.5em !important;
  margin-bottom: 0.5em !important;
  border-radius: 5px !important;
}

.terms.small-box {
  background: #f3f7fa !important;
}

.account-details.small-box {
  background: #f7f7f7 !important;
  width: 350px !important; /* match terms length */
  max-width: 350px !important;
}

.account-details {
  margin-top: 0.15em; /* slightly closer to terms */
  margin-bottom: 1em;
  font-size: 0.95rem;
  color: #333;
  background: #f8f8f8;
  padding: 0.7em 1em;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  max-width: 520px;
}

/* Terms editable textarea - match account details box styling */
.terms-editable {
  margin-top: 0 !important; /* tight */
  margin-bottom: 0.5em !important;
  font-size: 0.82rem !important;
  color: #333 !important;
  background: #f3f7fa !important;
  padding: 0.4em 0.7em !important;
  border-radius: 5px !important;
  border: 1px solid #e0e0e0 !important;
  max-width: 350px !important;
  width: 350px !important;
  box-sizing: border-box !important;
  resize: none !important;
  overflow: hidden !important;
  font-family: 'Roboto', Arial, Helvetica, sans-serif !important;
  line-height: 1.5 !important;
  height: auto !important;
  min-height: 60px !important;
  display: block !important;
}

.signatures {
  position: absolute;
  bottom: 15mm;
  width: calc(100% - 12mm);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 2em;
  margin-bottom: 1em;
}

#invoice .signatures {
  justify-content: flex-end;
}

#invoice .signatures .authorized {
  margin-left: auto;
}

.signatures .signatory {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  width: 40%;
}

.signatures .receiver .signature-space {
  width: 180px;
  height: 60px;
  border: 2px dashed #ccc;
  margin-bottom: 4px;
  border-bottom: 1px solid #888;
}

.signatures .authorized img {
  width: 280px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 4px;
}

.signatory img {
  height: 60px;
  width: auto;
  margin-bottom: 0.5em;
}

.signatory span {
  font-size: 1rem;
  color: #222;
}

/* Delivery: make the caption “Authorized Signatory” grey */
#delivery .signatures .authorized span { color: #777 !important; }
@media print { #delivery .signatures .authorized span { color: #777 !important; } }
/* Invoice: make the caption “Authorized Signature” grey to match */
#invoice .signatures .authorized span { color: #777 !important; }
@media print { #invoice .signatures .authorized span { color: #777 !important; } }

/* Footer: simplified — edge-to-edge border line, no pseudo-element */
.footer {
  /* use a single border-top line across the full footer width */
  border-top: 2px solid var(--footer-border) !important;
  position: absolute;
  bottom: 6mm;
  width: 100%;
  text-align: center;
  font-size: 14px;
  padding-top: 6px; /* space between the line and the text */
  color: #333; /* default fallback color */
  box-sizing: border-box;
}
/* disable legacy inset pseudo-line to avoid double lines */
.footer::before { content: none !important; display: none !important; }

/* Per-document border color and text color */
#invoice .footer { border-top-color: var(--invoice-blue) !important; color: #000 !important; }
#quotation .footer { border-top-color: var(--quotation-green) !important; color: #000 !important; }
#delivery .footer { border-top-color: var(--delivery-red) !important; color: #000 !important; }

/* Print: single edge-to-edge line, no pseudo-element, no duplication */
@media print {
  .footer {
    position: relative !important;
    bottom: auto !important;
    width: 100% !important;
    text-align: center !important;
    font-size: 12px !important;
    line-height: 1.3 !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    background: var(--white) !important;
    margin-top: 6mm !important;
    margin-bottom: 0 !important;
    page-break-inside: avoid !important;
    border-top-width: 2px !important; /* ensure visible in print */
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .footer::before { content: none !important; display: none !important; }
}

/* Hide Release Excel button if present */
#release-excel, .release-excel {
  display: none !important;
}

/* Remove release button style usage */
#release-file-btn { display: none !important; }

.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  min-width: 450px;
  max-width: 90vw;
}

.modal.active {
  display: block;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -48%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

/* Pull Record Form - Edit/Reprint Modal */
.pull-record-form {
  text-align: center;
  width: 450px;
  max-width: 90vw;
}

.pull-record-form h3 {
  margin: 0 0 24px 0;
  font-size: 24px;
  font-weight: 700;
  color: #111827;
}

.pull-error-message {
  background: #fee;
  border: 2px solid #fcc;
  border-radius: 8px;
  color: #c33;
  padding: 12px 16px;
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  line-height: 1.5;
}

.modal input {
  display: block;
  width: 100%;
  padding: 14px 16px;
  margin: 0 0 20px 0;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 16px;
  color: #111827;
  background: #ffffff;
  outline: none;
  box-sizing: border-box;
}

.modal input:focus {
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.modal input::placeholder {
  color: #9ca3af;
}

.modal button {
  padding: 12px 32px;
  margin: 8px 6px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 120px;
}

.modal button:first-of-type {
  background: #0ea5e9;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.modal button:first-of-type:hover {
  background: #0284c7;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.4);
}

.modal button:first-of-type:active {
  transform: translateY(0);
}

.modal button:last-of-type {
  background: #e5e7eb;
  color: #374151;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modal button:last-of-type:hover {
  background: #d1d5db;
  transform: translateY(-1px);
}

.modal button:last-of-type:active {
  transform: translateY(0);
}

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  z-index: 999;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.overlay.active {
  display: block;
  animation: overlayFadeIn 0.2s ease-out;
}

@keyframes overlayFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Customer Picker Panel - Modal Popup */
/* OLD STYLES REMOVED - Using dropdown styles at bottom of file */

.customer-item .cust-left {
  flex-shrink: 0;
}

.customer-item .cust-right {
  flex: 1;
  min-width: 0;
}

.customer-item .cust-name {
  color: #333;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-item .cust-meta {
  color: #666;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-item .cust-icon {
  flex-shrink: 0;
}

.no-results {
  padding: 20px;
  text-align: center;
  color: #999;
  font-style: italic;
}

.print-btn {
  display: flex !important;
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  width: 120px !important;
  height: 44px !important;
  background: var(--button-bg) !important;
  color: var(--button-text) !important;
  border: 1px solid var(--button-border) !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  box-shadow: 0 2px 8px var(--button-shadow) !important;
  transition: all 0.2s ease !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 999 !important;
  font-weight: 700 !important;
  font-size: 14px !important;
  padding: 6px 12px !important;
  gap: 8px !important;
}
.print-btn img { display: none !important; } /* hide old icon */

.print-btn:hover {
  background: var(--button-hover) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 12px var(--button-shadow) !important;
}

.print-btn:active {
  transform: translateY(0) !important;
  box-shadow: 0 1px 4px var(--button-shadow) !important;
}

/* PDF Download button - hidden per user request */
.pdf-btn {
  display: none !important;
}

.pdf-btn:hover {
  background: #45a049 !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4) !important;
}

.pdf-btn:active {
  transform: translateY(0) !important;
  box-shadow: 0 1px 4px rgba(76, 175, 80, 0.3) !important;
}

.pdf-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mobile: slightly smaller button */
@media (max-width: 480px) {
  .pdf-btn {
    right: 12px !important;
    bottom: 65px !important;
    width: 96px !important;
    height: 40px !important;
    font-size: 12px !important;
  }
  
  .print-btn {
    right: 12px !important;
    bottom: 12px !important;
    width: 96px !important;
    height: 40px !important;
    font-size: 13px !important;
  }
}

.dashboard-btn {
  display: flex !important;
  position: fixed !important;
  bottom: 20px !important;
  left: 20px !important;
  width: 120px !important;
  height: 44px !important;
  background: var(--button-bg) !important;
  color: var(--white) !important;
  border: none !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18) !important;
  transition: background 0.18s ease, transform 0.08s ease, box-shadow 0.18s ease !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 999 !important;
  font-weight: 800 !important;
  font-size: 14px !important;
  padding: 6px 12px !important;
  gap: 8px !important;
}

.dashboard-btn:hover {
  background: var(--button-hover) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 12px 30px rgba(0,0,0,0.22) !important;
}

/* Mobile: slightly smaller button */
@media (max-width: 480px) {
  .dashboard-btn {
    left: 12px !important;
    bottom: 12px !important;
    width: 96px !important;
    height: 40px !important;
    font-size: 13px !important;
  }
}

/* Excel modal styles - REMOVED (now using Google Sheets with loading indicator) */

/* Ensure the app interaction works properly */
body.excel-locked .app-container {
  pointer-events: none !important;
  user-select: none !important;
  filter: none !important;
}

@keyframes popIn {
  0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Legacy 480px breakpoint removed - now using comprehensive 768px mobile-first approach */

/* ============================================================ */
/* CONSOLIDATED PRINT STYLES - OPTIMIZED FOR SINGLE A4 PAGE    */
/* ============================================================ */
@media print {
  /* --- PAGE SETUP --- */
  @page {
    size: A4 portrait;
    margin: 6mm 8mm;
    orphans: 2;
    widows: 2;
  }
  
  /* --- GLOBAL DOCUMENT SETUP --- */
  html, body {
    width: 210mm !important;
    height: auto !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: white !important;
    color: black !important;
  }
  
  /* --- DOCUMENT CONTAINER --- */
  .document {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 6mm 8mm !important;
    padding-bottom: 35mm !important; /* Reserve space for signatures + footer */
    background: white !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    display: none !important;
    overflow: hidden !important;
    page-break-inside: avoid !important;
    position: relative !important;
    box-sizing: border-box !important;
  }
  
  .document.active {
    display: block !important;
    page-break-after: avoid !important;
  }
  
  /* --- HIDE UI ELEMENTS --- */
  .no-print, .print-btn, .modal, .overlay, .header-bar,
  .instruction-ticker, .pull-record-form,
  .contacts-overlay, .contacts-modal {
    display: none !important;
    visibility: hidden !important;
  }
  
  /* --- HIDE PLACEHOLDER TEXT --- */
  input::placeholder,
  input::-webkit-input-placeholder,
  input::-moz-placeholder,
  input:-ms-input-placeholder {
    color: transparent !important;
    opacity: 0 !important;
  }
  
  /* --- SHOW LOGO IN COLOR --- */
  .logo {
    display: block !important;
    width: 60px !important;
    height: 40px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  .logo img {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* --- HEADER OPTIMIZATION --- */
  .header {
    margin-bottom: 2mm !important;
    padding-bottom: 4mm !important;
    border-bottom: 1.5px solid #333 !important;
    page-break-inside: avoid !important;
  }
  
  .company-short-name {
    font-size: 28px !important;
    font-weight: 900 !important;
    line-height: 1.1 !important;
    margin: 0 0 1mm 0 !important;
    letter-spacing: 1px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Document-specific company name colors in print */
  #invoice .company-short-name {
    color: var(--invoice-blue) !important;
  }
  
  #quotation .company-short-name {
    color: var(--quotation-green) !important;
  }
  
  #delivery .company-short-name {
    color: var(--delivery-red) !important;
  }
  
  .company-full-name {
    font-size: 14px !important;
    line-height: 1.3 !important;
    margin: 0.5mm 0 !important;
    font-weight: 400 !important;
  }

  .company-trn {
    font-size: 14px !important;
    line-height: 1.3 !important;
    margin: 0.5mm 0 0 0 !important;
    font-weight: 400 !important;
  }
  
  /* --- DOCUMENT TITLE (h2) --- */
  h2 {
    font-size: 18px !important;
    font-weight: 700 !important;
    margin: 2mm 0 3mm 0 !important;
    line-height: 1.2 !important;
    text-align: center !important;
    letter-spacing: 1px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  #invoice h2 { 
    color: var(--invoice-blue) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  #quotation h2 { 
    color: var(--quotation-green) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  #delivery h2 { 
    color: var(--delivery-red) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* --- CUSTOMER & INVOICE DETAILS (PRINT) --- */
  .details {
    display: flex !important;
    justify-content: space-between !important;
    margin: 3mm 0 !important;
    gap: 8mm !important;
  }
  
  /* LEFT: Customer Details */
  .customer-details {
    flex: 1 !important;
    max-width: 95mm !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5mm !important; /* Minimal spacing - prevent extra rows */
  }
  
  .customer-details div {
    display: flex !important;
    align-items: center !important;
    gap: 1mm !important; /* Reduced gap - values closer to labels */
    min-height: 4mm !important; /* Reduced height */
    height: 4mm !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* ALL Labels - BOLD, same size, consistent font */
  .customer-details label {
    font-family: Arial, sans-serif !important;
    font-size: 11pt !important; /* Use pt for print consistency */
    font-weight: 400 !important; /* Regular weight - only bold for name and doc number */
    color: #000 !important;
    width: 9mm !important;
    text-align: left !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* ALL Inputs - UNBOLD, BORDERLESS for print, consistent font */
  .customer-details input {
    flex: 1 !important;
    font-family: Arial, sans-serif !important;
    font-size: 11pt !important; /* Use pt for print consistency */
    font-weight: 400 !important;
    color: #333 !important;
    border: none !important;
    background: transparent !important;
    padding: 0 1mm !important; /* Minimal padding */
    height: 4mm !important;
    min-height: 4mm !important;
    line-height: 1 !important;
    margin: 0 !important;
  }
  
  /* Customer name - BOLD, allow long company names */
  .customer-details input[data-cell="name"] {
    font-weight: 700 !important; /* BOLD for company name */
    font-size: 11pt !important;
    max-width: none !important; /* Allow full width for long names */
    word-wrap: break-word !important;
    word-break: break-word !important;
    white-space: normal !important;
    overflow-wrap: break-word !important;
    line-height: 1.2 !important;
  }
  
  /* RIGHT: Invoice Details */
  .invoice-details {
    min-width: 50mm !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5mm !important; /* Minimal spacing - SAME as left */
    align-items: flex-end !important;
  }
  
  .invoice-details div {
    display: flex !important;
    align-items: center !important;
    gap: 1mm !important; /* Reduced gap - labels closer to values */
    min-height: 4mm !important;
    height: 4mm !important;
    justify-content: flex-end !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* ALL Labels - Regular weight, consistent font */
  .invoice-details label {
    font-family: Arial, sans-serif !important;
    font-size: 11pt !important; /* Use pt for print consistency */
    font-weight: 400 !important; /* Regular weight - only bold for doc number */
    color: #000 !important;
    width: 12mm !important;
    text-align: left !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* ALL Inputs - UNBOLD except doc number, consistent font */
  .invoice-details input {
    font-family: Arial, sans-serif !important;
    font-size: 11pt !important; /* Use pt for print consistency */
    font-weight: 400 !important;
    color: #333 !important;
    border: none !important; /* No border by default */
    padding: 0 1mm !important; /* Minimal padding */
    height: 4mm !important;
    min-height: 4mm !important;
    line-height: 1 !important;
    text-align: right !important;
    width: 22mm !important; /* Reduced by 30% from 32mm */
    background: transparent !important;
    margin: 0 !important;
  }
  
  /* Date - borderless, UNBOLD, consistent font, match size */
  .invoice-details .date-cell,
  .invoice-details .date-display {
    border: none !important;
    background: transparent !important;
    font-weight: 400 !important;
    font-size: 11pt !important;
    line-height: 1 !important;
    padding: 0 1mm !important;
    margin: 0 !important;
    width: 24mm !important; /* Slightly larger to prevent date wrapping */
    text-align: right !important;
    white-space: nowrap !important; /* Prevent wrapping */
    overflow: hidden !important;
  }
  
  /* Document number - BOLD with box and rounded corners (only value that's bold besides company name) */
  .invoice-details input[id$="-number"] {
    font-weight: 700 !important;
    color: #000 !important;
    border: 1px solid #ddd !important; /* Only doc number has border */
    border-radius: 3px !important; /* Rounded corners */
    background: white !important;
  }
  
  /* Hide staff dropdown */
  .invoice-details select,
  .invoice-details div:has(select) {
    display: none !important;
  }
  
  /* Hide empty fields */
  .customer-details div:has(input[data-cell="mobile"]:placeholder-shown),
  .customer-details div:has(input[data-cell="trn"]:placeholder-shown),
  .invoice-details div:has(input[id$="-ref"]:placeholder-shown) {
    display: none !important;
  }
  
  /* --- ITEMS TABLE --- */
  .items-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 4mm 0 4mm 0 !important;
    page-break-inside: auto !important;
    border: 1px solid white !important;
  }
  
  .items-table thead {
    page-break-inside: avoid !important;
  }
  
  .items-table tbody {
    page-break-inside: auto !important;
  }
  
  .items-table tr {
    page-break-inside: avoid !important;
    border-bottom: 1px solid #ddd !important;
  }
  
  .items-table th {
    padding: 4px 6px !important;
    font-size: 14px !important;
    height: 22px !important;
    color: white !important;
    font-weight: 600 !important;
    text-align: center !important;
    border: 1px solid #ddd !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Document-specific table header colors in print */
  #invoice .items-table th {
    background: var(--invoice-blue) !important;
    border: 1px solid var(--invoice-blue) !important;
  }
  
  #quotation .items-table th {
    background: var(--quotation-green) !important;
    border: 1px solid var(--quotation-green) !important;
  }
  
  #delivery .items-table th {
    background: var(--delivery-red) !important;
    border: 1px solid var(--delivery-red) !important;
  }
  
  .items-table td {
    padding: 4px 6px !important;
    font-size: 12px !important;
    height: 22px !important;
    border: 1px solid #ddd !important;
  }

  /* Increase font size for Qty, Price, Amount columns by 2px */
  #invoice .items-table td:nth-child(4),
  #invoice .items-table td:nth-child(5),
  #invoice .items-table td:nth-child(6),
  #quotation .items-table td:nth-child(4),
  #quotation .items-table td:nth-child(5),
  #quotation .items-table td:nth-child(6) {
    font-size: 14px !important;
  }
  
  .items-table input {
    font-size: 12px !important;
    height: 18px !important;
    padding: 2px 4px !important;
    border: none !important;
    background: transparent !important;
  }
  
  /* --- TABLE FOOTER & TOTALS --- */
  .items-table tfoot {
    page-break-inside: avoid !important;
  }
  
  /* RESET ALL tfoot cells first */
  .items-table tfoot tr td {
    padding: 0 !important;
    font-size: 10px !important;
    height: auto !important;
    border: none !important;
    background: transparent !important;
  }
  
  /* Merged cell for Total in Words - left side spanning 3 rows */
  .items-table tfoot td.words-cell-merged {
    vertical-align: top !important;
    padding: 6px 8px !important;
    border: none !important;
    background: transparent !important;
    font-size: 10px !important;
    line-height: 1.4 !important;
  }

  #invoice .items-table tfoot td.words-cell-merged,
  #quotation .items-table tfoot td.words-cell-merged {
    border-left: 1px solid white !important;
    border-right: 1px solid white !important;
    border-bottom: 1px solid white !important;
  }
  
  /* ONLY apply borders to total cells */
  .items-table tfoot tr td.total-label,
  .items-table tfoot tr td.total-value {
    background: transparent !important;
    border: none !important;
    font-weight: normal !important;
    font-size: 14px !important;
    padding: 2px 4px !important;
    height: 20px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Make Grand Total label bold */
  #invoice .items-table tfoot tr:nth-child(3) td.total-label,
  #quotation .items-table tfoot tr:nth-child(3) td.total-label {
    font-weight: bold !important;
  }

  /* Remove bottom border under Grand Total cell */
  #invoice .items-table tfoot tr:last-child td.total-value,
  #quotation .items-table tfoot tr:last-child td.total-value {
    border-bottom: none !important;
  }

  /* Make only Grand Total value bold, others normal weight */
  #invoice .items-table tfoot tr:nth-child(1) td.total-value,
  #invoice .items-table tfoot tr:nth-child(2) td.total-value,
  #quotation .items-table tfoot tr:nth-child(1) td.total-value,
  #quotation .items-table tfoot tr:nth-child(2) td.total-value {
    font-weight: normal !important;
  }

  #invoice .items-table tfoot tr:nth-child(3) td.total-value,
  #quotation .items-table tfoot tr:nth-child(3) td.total-value {
    font-weight: bold !important;
  }
  
  /* --- WORDS IN TABLE FOOTER --- */
  .words-inline {
    font-size: 10px !important;
    text-align: left !important;
    page-break-inside: avoid !important;
    line-height: 1.4 !important;
    font-style: italic !important;
    color: #666 !important;
    font-weight: normal !important;
  }
  
  /* --- TERMS & ACCOUNT DETAILS --- */
  /* Show terms text but without any box/border in print */
  .terms-editable {
    display: block !important;
    margin-top: 3mm !important;
    margin-bottom: 2mm !important;
    padding: 0 !important;
    font-size: 9px !important;
    line-height: 1.3 !important;
    color: #666 !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    max-width: 70% !important;
    width: 70% !important;
    height: auto !important;
    min-height: 0 !important;
    resize: none !important;
    page-break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .account-details {
    margin-top: 3mm !important;
    margin-bottom: 0 !important;
    padding: 3mm 4mm !important;
    font-size: 10px !important;
    line-height: 1.3 !important;
    page-break-inside: avoid !important;
    background: white !important;
    border: 1px solid #999 !important;
    border-radius: 2px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  .account-details strong {
    font-size: 13px !important;
    font-weight: 700 !important;
  }

  /* Set color for "Thank you for your business!" to match document color */
  #invoice .account-details strong { color: var(--invoice-blue) !important; }
  #quotation .account-details strong { color: var(--quotation-green) !important; }
  #delivery .account-details strong { color: var(--delivery-red) !important; }

  /* Make footer text black and normal weight */
  .footer { color: #000 !important; font-weight: normal !important; }
  
  .notes-section {
    display: none !important; /* Hide to save space */
  }
  
  /* --- SIGNATURES --- */
  .signatures {
    display: flex !important;
    position: absolute !important;
    bottom: 18mm !important;
    left: 8mm !important;
    right: 8mm !important;
    width: calc(100% - 16mm) !important;
    justify-content: space-between !important;
    page-break-inside: avoid !important;
  }
  
  .signatures .signatory {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
  }
  
  .signatures .receiver .signature-space {
    width: 180px !important;
    height: 60px !important;
    border: 2px dashed #999 !important;
    margin-bottom: 3px !important;
  }
  
  .signatures .authorized img {
    display: block !important;
    width: 240px !important;
    height: 110px !important;
    object-fit: contain !important;
    margin-bottom: 3px !important;
  }
  
  .signatory span {
    font-size: 11px !important;
    color: #555 !important;
    font-weight: 500 !important;
  }
  
  #delivery .signatures .authorized span,
  #invoice .signatures .authorized span {
    color: #555 !important;
  }
  
  /* --- FOOTER --- */
  .footer {
    position: absolute !important;
    bottom: 0 !important;
    left: 8mm !important;
    right: 8mm !important;
    width: calc(100% - 16mm) !important;
    text-align: center !important;
    font-size: 10px !important;
    line-height: 1.2 !important;
    padding-top: 2mm !important;
    padding-bottom: 2mm !important;
    margin: 0 !important;
    border-top: 1.5px solid #333 !important;
    page-break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  .footer::before {
    content: none !important;
    display: none !important;
  }
  
  #invoice .footer {
    border-top-color: var(--invoice-blue) !important;
  }
  
  #quotation .footer {
    border-top-color: var(--quotation-green) !important;
  }
  
  #delivery .footer {
    border-top-color: var(--delivery-red) !important;
  }
  
  /* --- LAYOUT CONTAINERS --- */
  .main-content {
    width: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .app-container {
    width: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .header-bar {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }
}
/* ============================================================ */
/* END OF CONSOLIDATED PRINT STYLES                            */
/* ============================================================ */

/* --- Screen-only centering override --- */
@media screen {
  .app-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    align-items: center !important;
  }
  .main-content {
    width: 100% !important;
    margin: 0 auto !important;
    padding: 12px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
  }
  .header-bar {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
  }
  .document {
    margin: 10mm auto !important;
  }
}

/* Plain total-in-words area under the table (invoice) */
.words-below {
  margin: 8px 0 6px 0 !important; /* small gap under table */
  font-size: 0.98em !important;
  font-weight: 600 !important;
  color: #0760a8 !important; /* same tone used for words */
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  white-space: normal !important;
  word-break: break-word !important;
  line-height: 1.2 !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 2 !important; /* maximum two lines */
  line-clamp: 2 !important;
  -webkit-box-orient: vertical !important;
  overflow: hidden !important;
}

/* Inline total-in-words inside invoice table footer (left area) */
.items-table tfoot tr.words-row td.words-cell {
  border: none !important;
  background: transparent !important;
  padding: 0 6px !important; /* a touch tighter above totals */
  vertical-align: top !important;
  text-align: left !important; /* ensure left alignment */
  height: auto !important; /* allow 2 text lines comfortably */
}
/* Ensure any generic nth-child alignment doesn’t affect the words row */
.items-table tfoot tr.words-row td { text-align: left !important; }
@media print {
  .items-table tfoot tr.words-row td.words-cell { padding: 2px 4px !important; text-align: left !important; }
  .words-inline { font-size: 11px !important; page-break-inside: avoid !important; text-align: left !important; max-height: calc(1.25em * 2) !important; min-height: calc(1.25em * 2) !important; }
}

/* Collapse gap exactly after the items table */
.items-table + .terms-editable { margin-top: 0 !important; }
#delivery .terms-editable { margin-top: 40px !important; }
.terms-editable + .account-details { margin-top: 0.05em !important; /* a touch tighter */ }

/* General trims (screen) */
.terms-editable { margin-top: 0 !important; /* tight */ }
.account-details { margin-top: 0.1em !important; /* tighter */ }

/* Contacts modal styles */
.contacts-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 2400;
}
.contacts-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 900px; max-width: calc(100vw - 40px); max-height: calc(100vh - 40px);
  background: var(--white); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  display: flex; flex-direction: column; overflow: hidden; z-index: 2500;
}
.contacts-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--grey-border); background: #f7f9fc;
}
.contacts-title { font-size: 18px; font-weight: 700; color: #1f2d3d; }
.contacts-actions { display: flex; gap: 8px; align-items: center; }
.contacts-actions input[type="search"] {
  width: 280px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--grey-border);
  font-size: 14px;
}
.btn-primary { background: #2E5C8A; color: #fff; border: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.btn-secondary { background: #e8eef6; color: #1f2d3d; border: 1px solid #c7d5ea; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.btn-ghost { background: transparent; color: #1f2d3d; border: 1px solid var(--grey-border); padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.btn-danger { background: #e55353; color: #fff; border: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.contacts-body { display: grid; grid-template-columns: 1fr 1.2fr; gap: 0; min-height: 460px; }
.contacts-list { border-right: 1px solid var(--grey-border); overflow: auto; }
.contacts-list .contact-item { display: grid; grid-template-columns: 36px 1fr; gap: 8px; padding: 10px 12px; cursor: pointer; align-items: center; }
.contacts-list .contact-item:hover { background: #f5f8fb; }
.contacts-list .contact-name { font-weight: 600; color: #1f2d3d; }
.contacts-list .contact-meta { font-size: 12px; color: #5b6b7a; }
.contacts-detail { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #334e68; }
.detail-grid input, .detail-grid textarea { border: 1px solid var(--grey-border); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.detail-actions { display: flex; gap: 8px; justify-content: flex-end; }
@media (max-width: 820px) {
  .contacts-body { grid-template-columns: 1fr; }
  .contacts-list { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--grey-border); }
}
@media print {
  .contacts-overlay, .contacts-modal { display: none !important; }
}
/* End Contacts modal styles */

/* Print: ensure header underline uses document color */
@media print {
  #invoice .header { border-color: var(--invoice-blue) !important; }
  #quotation .header { border-color: var(--quotation-green) !important; }
  #delivery .header { border-color: var(--delivery-red) !important; }

  /* Table header top border matches document color */
  #invoice .items-table th { border-top: 1px solid var(--invoice-blue) !important; }
  #quotation .items-table th { border-top: 1px solid var(--quotation-green) !important; }
  #delivery .items-table th { border-top: 1px solid var(--delivery-red) !important; }
}

/* ===== MOBILE RESPONSIVE - OPTIMIZED FOR IPHONE 15 PRO MAX ===== */

/* iPhone 15 Pro Max: 430x932 px, 6.7" display */
/* General mobile optimization for all phones */

@media only screen and (max-width: 768px) {
  
  /* Body & Container */
  body {
    font-size: 14px;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }
  
  .app-container {
    padding: 0;
    margin: 0;
    max-width: 100%;
  }
  
  /* Header Bar - Make it mobile-friendly with compact layout */
  .header-bar {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px 6px;
    gap: 6px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    align-items: center;
  }
  
  .header-left, .header-center, .header-right {
    display: flex;
    width: auto;
    flex: 1 1 auto;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }
  
  .header-right {
    justify-content: flex-end;
    flex: 0 0 auto; /* Don't let it shrink */
    min-width: min-content; /* Ensure tabs stay visible */
  }
  
  /* Buttons - Touch-friendly with better sizing */
  .header-bar button, .doc-tab {
    font-size: 12px;
    padding: 8px 12px;
    min-height: 44px; /* iOS minimum touch target */
    border-radius: 8px;
    flex: 0 0 auto;
    white-space: nowrap;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    cursor: pointer;
  }
  
  /* Dashboard button */
  #tab-overview {
    font-size: 12px;
    padding: 8px 12px;
  }
  
  /* Convert buttons */
  #create-invoice-btn,
  #create-delivery-btn {
    font-size: 11px;
    padding: 8px 10px;
    min-height: 44px;
  }
  
  /* Document type tabs - IMPORTANT: Must be tappable */
  .header-right button {
    font-size: 13px;
    padding: 10px 14px;
    min-height: 44px;
    min-width: 80px;
    font-weight: 600;
  }
  
  /* Active tab styling for mobile */
  .doc-tab.active-tab {
    background: var(--primary-blue);
    color: white;
    font-weight: 700;
  }
  
  /* Print button - Fixed, prominent */
  .print-btn {
    position: fixed;
    bottom: 12px;
    right: 12px;
    width: auto;
    font-size: 13px;
    padding: 10px 16px;
    min-height: 44px; /* iOS touch target */
    border-radius: 10px;
    z-index: 1001;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  }
  
  /* Document Container - Full width on mobile */
  .document {
    padding: 10px;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    max-width: 100%;
    width: 100%;
  }
  
  /* Header Section */
  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    text-align: left;
    padding: 8px 0;
  }
  
  .logo {
    width: 60px;
    height: 60px;
    margin: 0;
    order: 2; /* Move logo to right */
  }
  
  .company-details {
    order: 1;
    flex: 1;
  }
  
  .company-short-name {
    font-size: 18px;
  }
  
  .company-full-name {
    font-size: 11px;
  }
  
  .company-trn {
    font-size: 10px;
  }
  
  /* Document Title */
  .document h2 {
    font-size: 16px;
    margin: 12px 0 8px;
  }
  
  /* Customer & Invoice Details - Mobile responsive */
  .details {
    flex-direction: column;
    gap: 12px;
    margin: 10px 0;
  }
  
  .customer-details,
  .invoice-details {
    width: 100%;
    max-width: 100%;
  }
  
  .customer-details {
    gap: 3px; /* CONSISTENT spacing */
  }
  
  .invoice-details {
    gap: 3px; /* CONSISTENT spacing - SAME as left */
    align-items: flex-start;
  }
  
  .customer-details div,
  .invoice-details div {
    gap: 8px;
    height: 36px; /* CONSISTENT height */
  }
  
  /* ALL Labels - BOLD, same size, left-aligned */
  .customer-details label,
  .invoice-details label {
    font-family: Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: #000;
    width: 40px;
    text-align: left;
  }
  
  /* ALL Inputs - UNBOLD except name and doc number */
  .customer-details input,
  .invoice-details input,
  .invoice-details select {
    font-family: Arial, sans-serif;
    font-size: 14px; /* Prevent iOS zoom */
    font-weight: 400;
    color: #333;
    padding: 6px 10px;
    height: 36px;
  }
  
  /* Customer name - BOLD */
  .customer-details input[data-cell="name"] {
    font-weight: 700;
    font-size: 14px;
  }
  
  /* Date - UNBOLD */
  .invoice-details .date-display {
    font-weight: 400;
  }
  
  /* Document number - BOLD */
  .invoice-details input[id$="-number"] {
    font-weight: 700;
    color: #000;
  }
  
  .invoice-details div {
    justify-content: flex-start;
  }
  
  /* Date display - NO BOX on mobile */
  .date-cell,
  .date-display {
    flex: 1;
    min-height: 36px;
    font-size: 13px;
    padding: 6px 8px;
    border: none !important;
    background: transparent !important;
    font-weight: 600;
  }
  
  /* Items Table - horizontal scroll wrapper */
  .main-content {
    padding: 8px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Wrap items-table in a scrollable container */
  .items-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 11px;
  }

  .items-table thead,
  .items-table tbody,
  .items-table tfoot,
  .items-table tr {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  /* Fixed column widths for mobile scroll */
  .items-table th:nth-child(1), .items-table td:nth-child(1) { width: 28px; }   /* Sno */
  .items-table th:nth-child(2), .items-table td:nth-child(2) { width: 90px; }   /* Model */
  .items-table th:nth-child(3), .items-table td:nth-child(3) { width: 110px; }  /* Description */
  .items-table th:nth-child(4), .items-table td:nth-child(4) { width: 48px; }   /* Qty */
  .items-table th:nth-child(5), .items-table td:nth-child(5) { width: 60px; }   /* Price */
  .items-table th:nth-child(6), .items-table td:nth-child(6) { width: 60px; }   /* Amount */

  .items-table th, .items-table td {
    padding: 4px 3px;
    font-size: 11px;
  }

  .items-table input, .items-table textarea {
    font-size: 14px; /* prevent iOS zoom */
    padding: 4px 3px;
    min-height: 30px;
    width: 100%;
    box-sizing: border-box;
  }

  /* Smaller number inputs */
  .items-table input.qty,
  .items-table input.price {
    font-size: 13px;
    padding: 3px 2px;
  }
  
  /* Line totals */
  .items-table .line-total {
    font-size: 11px;
    padding: 4px 3px;
  }
  
  /* Footer totals in table */
  .items-table tfoot td {
    font-size: 11px;
    padding: 4px 3px;
  }
  
  .items-table tfoot .total-label,
  .items-table tfoot .total-value {
    font-size: 11px;
  }
  
  /* Words inline */
  .words-inline {
    font-size: 10px;
    padding: 4px;
  }
  
  /* Notes & Terms */
  .terms-editable {
    font-size: 11px;
    padding: 8px;
    min-height: 60px;
    border-radius: 6px;
  }
  
  /* Account details box */
  .account-details {
    font-size: 10px;
    padding: 8px;
    margin: 8px 0;
  }
  
  /* Footer & Signatures */
  .footer {
    font-size: 10px;
    padding: 8px 0;
    margin-top: 12px;
  }
  
  .signatures {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    margin: 12px 0;
  }
  
  .signatory {
    width: auto;
  }
  
  .signatures .authorized img {
    max-width: 100px;
    height: auto;
  }
  
  .signatures span {
    font-size: 10px;
  }
  
  /* Modals - Full screen on mobile */
  .modal {
    width: 92%;
    max-width: 92%;
    margin: 15px auto;
    border-radius: 10px;
    padding: 16px;
  }
  
  .modal h3 {
    font-size: 16px;
    margin-bottom: 12px;
  }
  
  .modal input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 10px;
    min-height: 44px;
  }
  
  .modal button {
    font-size: 14px;
    padding: 10px 20px;
    min-height: 44px;
    border-radius: 8px;
    margin-top: 8px;
  }
  
  /* Pull record error message */
  .pull-error-message {
    font-size: 12px;
    padding: 8px;
  }
  
  /* Login Screen - Mobile optimized */
  #login-screen > div {
    width: 88%;
    max-width: 380px;
    padding: 28px 20px;
    border-radius: 14px;
  }
  
  #login-screen img {
    width: 100px;
  }
  
  #login-screen h1 {
    font-size: 24px;
  }
  
  #login-screen p {
    font-size: 13px;
  }
  
  #login-screen button {
    font-size: 15px;
    padding: 12px 28px;
    min-height: 48px;
    border-radius: 10px;
  }
  
  /* Loading spinner */
  #login-screen .spinner {
    width: 40px;
    height: 40px;
  }
  
  /* Loading Indicator */
  #loading-indicator {
    font-size: 12px;
    padding: 10px 12px;
  }
  
  /* Touch-friendly spacing and iOS optimizations */
  button, input, select, textarea {
    -webkit-tap-highlight-color: rgba(7, 96, 168, 0.2);
  }
  
  /* Prevent iOS zoom on input focus - Critical for mobile UX */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px !important; /* iOS won't zoom if >= 16px */
  }
  
  /* Override for table inputs - allow slightly smaller but still readable */
  .items-table input[type="text"],
  .items-table input[type="number"],
  .items-table textarea {
    font-size: 14px !important;
  }
  
  /* Smooth scrolling for iOS */
  * {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Safe area for iPhone notch/home indicator */
  .app-container {
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .header-bar {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(6px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
  }
  
  /* Fixed print button safe area */
  .print-btn {
    bottom: max(12px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-right));
  }
}

/* Portrait Mode Optimization - Less congested layout */
@media only screen and (max-width: 768px) and (orientation: portrait) {
  /* Header Bar - Better spacing in portrait */
  .header-bar {
    padding: 8px 6px;
    gap: 6px;
    min-height: auto;
  }
  
  /* Make header sections stack better */
  .header-left, .header-right {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar */
  }
  
  .header-left::-webkit-scrollbar,
  .header-right::-webkit-scrollbar {
    display: none; /* Hide scrollbar on WebKit */
  }
  
  /* Reduce header button sizes slightly in portrait */
  .header-bar button {
    font-size: 11px;
    padding: 8px 10px;
  }
  
  /* Document type tabs - Ensure visibility */
  .header-right button {
    font-size: 12px;
    padding: 10px 12px;
    min-width: 75px;
  }
  
  /* Company details - More compact */
  .company-short-name {
    font-size: 16px;
    margin-bottom: 2px;
  }
  
  .company-full-name {
    font-size: 10px;
    line-height: 1.2;
  }
  
  .company-trn {
    font-size: 9px;
  }
  
  .logo {
    width: 55px;
    height: 55px;
  }
  
  /* Document title - More compact */
  .document h2 {
    font-size: 15px;
    margin: 8px 0 6px;
  }
  
  /* Customer & Invoice details - Better spacing */
  .customer-details div,
  .invoice-details div {
    height: 34px;
    gap: 6px;
  }
  
  .customer-details,
  .invoice-details {
    gap: 2px;
  }
  
  /* Items table - More compact in portrait */
  .items-table {
    font-size: 10px;
    margin: 8px 0;
  }
  
  .items-table th,
  .items-table td {
    padding: 4px 2px;
    font-size: 10px;
  }
  
  .items-table input {
    font-size: 13px !important;
    padding: 4px 6px;
  }
  
  /* Footer elements - More compact */
  .terms-editable {
    font-size: 10px;
    padding: 6px 8px;
    margin: 8px 0;
    min-height: 60px;
  }
  
  .signatures {
    margin: 8px 0;
    gap: 12px;
  }
  
  .signatory {
    font-size: 10px;
  }
  
  .signatory img {
    max-height: 30px;
  }
  
  .footer {
    font-size: 9px;
    padding: 8px;
    margin-top: 8px;
  }
}

/* iPhone 15 Pro Max & similar large phones - Fine tuning */
@media only screen and (max-width: 430px) and (min-height: 900px) {
  /* Portrait mode - tall screen optimization */
  .document {
    min-height: auto;
    padding-bottom: 80px; /* Space for fixed print button */
  }
  
  /* Slightly larger text on bigger phones */
  .items-table th, .items-table td {
    font-size: 11px;
  }
  
  .customer-details input, .invoice-details input {
    font-size: 14px;
  }
}

/* Landscape mode on mobile - Ultra compact */
@media only screen and (max-height: 430px) and (orientation: landscape) {
  .header-bar {
    flex-direction: row;
    padding: 4px 6px;
    min-height: 40px;
  }
  
  .header-left, .header-right {
    width: auto;
    flex: 0 1 auto;
  }
  
  .header-bar button {
    font-size: 10px;
    padding: 5px 8px;
    min-height: 32px;
  }
  
  .print-btn {
    position: fixed;
    bottom: 8px;
    right: 8px;
    font-size: 12px;
    padding: 8px 14px;
    min-height: 38px;
  }
  
  .document {
    padding: 6px;
  }
  
  .header {
    padding: 4px 0;
  }
  
  .logo {
    width: 50px;
    height: 50px;
  }
  
  .company-short-name {
    font-size: 16px;
  }
}

/* Ultra compact phones (iPhone SE, 12 mini) - 375px and below */
@media only screen and (max-width: 375px) {
  .header-bar button, .doc-tab {
    font-size: 9px;
    padding: 5px 6px;
    min-height: 34px;
  }
  
  .header-right button {
    font-size: 10px;
    padding: 5px 8px;
  }
  
  .company-short-name {
    font-size: 16px;
  }
  
  .company-full-name {
    font-size: 10px;
  }
  
  .company-trn {
    font-size: 9px;
  }
  
  .document h2 {
    font-size: 14px;
  }
  
  .items-table th, .items-table td {
    font-size: 9px;
    padding: 3px 1px;
  }
  
  .items-table input {
    font-size: 13px; /* Keep readable despite smaller table */
    padding: 3px;
  }
  
  .print-btn {
    font-size: 12px;
    padding: 9px 14px;
    min-height: 42px;
  }
}

/* ===== END MOBILE RESPONSIVE ===== */

/* Customer Picker Modal */
/* ===== CUSTOMER PICKER MODAL POPUP ===== */
.customer-picker-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  justify-content: center;
  align-items: center;
}

.customer-picker-overlay.active {
  display: flex;
}

.customer-picker-modal {
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.customer-picker-header {
  padding: 16px 20px;
  border-bottom: 2px solid #0760a8;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.customer-picker-header h3 {
  margin: 0;
  color: #0760a8;
  font-size: 18px;
  font-weight: 700;
}

.customer-picker-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.customer-picker-close:hover {
  background: #f0f0f0;
  color: #333;
}

.customer-picker-search {
  padding: 12px 20px;
  border-bottom: 1px solid #e0e0e0;
}

.customer-picker-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
}

.customer-picker-search input:focus {
  outline: none;
  border-color: #0760a8;
}

.customer-picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.customer-picker-item {
  background: #f5f5f5;
  padding: 12px 16px;
  margin-bottom: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.customer-picker-item:hover {
  background: #e8f0f8;
  transform: translateX(4px);
}

.customer-picker-item-name {
  font-weight: 700;
  font-size: 14px;
  color: #333;
  margin-bottom: 4px;
}

.customer-picker-item-details {
  font-size: 12px;
  color: #666;
  line-height: 1.4;
}

.customer-picker-loading {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

.customer-picker-empty {
  text-align: center;
  padding: 40px 20px;
  color: #999;
  font-style: italic;
}

/* Make To: label clickable without changing appearance */
.customer-details label[data-picker="true"] {
  cursor: pointer;
  user-select: none;
}

.customer-details label[data-picker="true"]:hover {
  opacity: 0.7;
}

/* ===== MOBILE-ONLY PRINT FIXES ===== */
/* Fix double margins on mobile browsers (Safari/iOS) and hide footer URL */
@media print and (max-width: 768px) {
  /* Attempt to remove Safari's auto-generated URL/timestamp/page numbers */
  @page {
    margin: 0 !important;
    padding: 0 !important;
    size: auto;
  }
  
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Adjust document container to fit on A4 */
  #invoice, #quotation, #delivery {
    margin: 1mm 8mm 15mm 8mm !important;
    padding: 0 !important;
    min-height: auto !important;
    max-height: 277mm !important; /* A4 height (297mm) - top/bottom margins */
    position: relative !important;
  }
  
  /* Footer - Absolute positioning at bottom of page */
  .footer {
    position: absolute !important;
    bottom: 2mm !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    font-size: 9px !important;
    line-height: 1.2 !important;
    padding: 1mm 0 !important;
    margin: 0 !important;
    page-break-inside: avoid !important;
  }
  
  /* Reduce signature area height on mobile to make room for footer */
  .signature-section {
    height: 20mm !important;
    margin: 3mm 0 8mm 0 !important;
  }
  
  .signature-section > div {
    height: 15mm !important;
  }
  
  /* Hide any auto-generated browser footers/headers (limited success on iOS) */
  .header-bar, .print-btn, .save-btn, .new-btn {
    display: none !important;
  }
  
  /* Attempt to hide Safari's auto-generated content */
  header, footer {
    display: none !important;
  }
}

/* Additional attempt to hide Safari print headers/footers globally */
@media print {
  @page {
    size: auto;
    margin: 0mm;
  }
  
  /* Try to hide browser-generated headers/footers */
  body::before,
  body::after {
    display: none !important;
  }
}

