/* ==========================================================================
   Madina Natural Health Care — Invoice Letter Generator
   Clean A4 Precision Print & Web Application Stylesheet
   ========================================================================== */

:root {
  --primary: #006837;
  --primary-hover: #00502a;
  --secondary: #1e3a8a;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  --white: #ffffff;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  --font-invoice: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --sidebar-width: 480px;
}

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

html, body {
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: #0b1320;
  color: var(--slate-800);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Top Header Navigation
   ========================================================================== */
.app-header {
  background: #111c2e;
  border-bottom: 1px solid #1e2d42;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.brand-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.brand-titles h1 {
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-titles h1 .badge {
  background: rgba(0, 104, 55, 0.4);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.3);
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}

.brand-titles p {
  color: #94a3b8;
  font-size: 11px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: #007d43;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 12px rgba(0, 104, 55, 0.5);
}

.btn-secondary {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}
.btn-secondary:hover {
  background: #334155;
  color: #ffffff;
}

.btn-outline {
  background: transparent;
  color: #94a3b8;
  border-color: #334155;
}
.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #ffffff;
  border-color: #475569;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}
.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
}

/* ==========================================================================
   Main App Container (Split Layout)
   ========================================================================== */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 58px);
  overflow: hidden;
  background: #0f172a;
}

/* Mobile Tabs */
.mobile-view-tabs {
  display: none;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 6px;
  gap: 6px;
}
.mobile-view-tabs button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
}
.mobile-view-tabs button.active {
  background: var(--primary);
  color: #ffffff;
}

/* Left Sidebar (Editor) */
.editor-sidebar {
  width: var(--sidebar-width);
  min-width: 380px;
  background: #131d2e;
  border-right: 1px solid #1e2d42;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
}

.sidebar-tabs {
  display: flex;
  background: #0c1421;
  border-bottom: 1px solid #1e2d42;
}

.tab-btn {
  flex: 1;
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: #8b9bb4;
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
}
.tab-btn:hover {
  color: #e2e8f0;
}
.tab-btn.active {
  color: #4ade80;
  border-bottom-color: #4ade80;
  background: #131d2e;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}
.sidebar-content::-webkit-scrollbar {
  width: 6px;
}
.sidebar-content::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}

/* Forms */
.form-group {
  margin-bottom: 14px;
}
.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.form-row > .form-group {
  flex: 1;
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-control {
  width: 100%;
  padding: 8px 10px;
  font-size: 12.5px;
  color: #f1f5f9;
  background: #0b1320;
  border: 1px solid #28374d;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
  border-color: #006837;
  box-shadow: 0 0 0 2px rgba(0, 104, 55, 0.35);
}
textarea.form-control {
  resize: vertical;
  min-height: 48px;
}

/* Line Items Editor in Sidebar */
.line-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.line-item-card {
  background: #0c1421;
  border: 1px solid #1e2d42;
  border-radius: 6px;
  margin-bottom: 8px;
  position: relative;
  transition: all 0.2s ease;
  overflow: hidden;
}
.line-item-card:hover {
  border-color: #2b3d56;
}
.line-item-card.is-expanded {
  border-color: #2563eb;
  background: #09101d;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.item-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  background: #0c1421;
  transition: background 0.15s ease;
  gap: 8px;
}
.item-card-header:hover {
  background: #111c2e;
}
.is-expanded .item-card-header {
  background: #0d1728;
  border-bottom: 1px solid #17263d;
}

.item-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.item-card-sl {
  font-size: 11px;
  font-weight: 700;
  color: #4ade80;
  background: rgba(74, 222, 128, 0.12);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.item-header-title {
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 135px;
}
.item-header-title.empty-name {
  color: #64748b;
  font-style: italic;
  font-weight: 500;
}

.item-header-summary {
  font-size: 11px;
  color: #94a3b8;
  background: #1e293b;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  font-family: monospace;
}

.item-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-view-details {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-view-details:hover {
  background: rgba(59, 130, 246, 0.22);
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.5);
}
.is-expanded .btn-view-details {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.25);
  color: #cbd5e1;
}

.chevron-icon {
  width: 12px;
  height: 12px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.is-expanded .chevron-icon {
  transform: rotate(180deg);
}

.item-remove-btn {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 14px;
  padding: 3px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}
.item-remove-btn:hover {
  background: rgba(239, 68, 68, 0.15);
}

.item-card-dropdown {
  padding: 12px;
  background: #080d16;
  animation: dropdownSlide 0.18s ease-out;
}
@keyframes dropdownSlide {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.item-calc-preview {
  display: flex;
  justify-content: space-between;
  background: #05080f;
  border: 1px dashed #1e2d42;
  border-radius: 4px;
  padding: 6px 10px;
  margin-top: 8px;
  font-size: 11px;
}
.item-calc-preview span {
  color: #94a3b8;
}
.item-calc-preview strong {
  color: #f1f5f9;
}

/* ==========================================================================
   Right Side (Interactive Preview Pane)
   ========================================================================== */
.preview-pane {
  flex: 1;
  background: #080f1a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-toolbar {
  background: #0e1726;
  border-bottom: 1px solid #1a273b;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.preview-badge {
  background: rgba(2, 132, 199, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(2, 132, 199, 0.4);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.preview-scale-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #94a3b8;
  font-size: 11px;
}
.scale-btn {
  background: #182436;
  border: 1px solid #28374d;
  color: #cbd5e1;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.scale-btn:hover {
  background: #28374d;
  color: #fff;
}

.preview-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

/* ==========================================================================
   THE A4 INVOICE SHEET
   Strict 1-Page A4 Precision Box.
   Standard A4: 210mm x 297mm.
   Sheet calibrated to 290mm with internal margins to guarantee exact 1-page fit.
   ========================================================================== */
.sheet {
  background: #ffffff;
  color: #0f172a;
  width: 210mm;
  height: 290mm;
  min-height: 290mm;
  max-height: 292mm;
  padding: 12mm 15mm 12mm 15mm;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  border-radius: 2px;
  position: relative;
  font-family: var(--font-invoice);
  font-size: 11px;
  line-height: 1.35;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: 0 auto;
  overflow: visible;
  flex-shrink: 0;
}

/* Header Section */
.header-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 4px;
}
.header-table td {
  vertical-align: middle;
}

.logo-cell {
  width: 78px;
  text-align: center;
}
.logo-cell img {
  width: 70px;
  height: 70px;
  object-fit: contain;
  display: block;
}

.brand-cell {
  text-align: center;
}
.brand-name {
  font-size: 24px;
  font-weight: 800;
  color: #006837;
  letter-spacing: 0.01em;
  margin: 0;
  line-height: 1.15;
}
.brand-subtitle {
  font-size: 10px;
  color: #15803d;
  font-weight: 600;
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.brand-address {
  font-size: 10.5px;
  color: #1e293b;
  margin-top: 2px;
  font-weight: 500;
}
.brand-phone {
  font-size: 11px;
  color: #1e293b;
  margin-top: 2px;
  font-weight: 600;
}

/* Invoice Title */
.invoice-title-block {
  text-align: center;
  margin: 6px 0 10px;
}
.invoice-title-block span {
  display: inline-block;
  font-size: 20px;
  font-weight: 700;
  color: #006837;
  border-bottom: 2px solid #006837;
  padding: 0 20px 2px;
  letter-spacing: 0.05em;
  text-transform: capitalize;
}

/* Top Meta Row (Invoice No & Referred Dealer Code) */
.meta-top-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-bottom: 8px;
}
.meta-top-table td {
  vertical-align: middle;
}
.invoice-no-text {
  font-size: 12.5px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
}
.referred-code-box {
  display: inline-block;
  border: 1px solid #64748b;
  padding: 3px 12px;
  font-size: 10.5px;
  font-weight: 600;
  background: #ffffff;
  border-radius: 2px;
  white-space: nowrap;
}

/* Dealer Info & Date Section */
.dealer-date-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}
.dealer-date-table td {
  vertical-align: top;
}

.dealer-box-framed {
  border: 1.5px solid #1e3a8a;
  padding: 6px 10px;
  background: #ffffff;
  border-radius: 3px;
  box-sizing: border-box;
}
.dealer-info-subtable {
  width: 100%;
  border-collapse: collapse;
}
.dealer-info-subtable td {
  padding: 1.5px 0;
  font-size: 10.5px;
  vertical-align: top;
  color: #0f172a;
  line-height: 1.35;
}
.dealer-info-subtable .label-k {
  width: 125px;
  min-width: 125px;
  max-width: 125px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  padding-right: 4px;
}
.dealer-info-subtable .val-v {
  color: #0f172a;
  word-break: break-word;
}

.date-text-cell {
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  vertical-align: bottom !important;
  padding-bottom: 4px;
}

/* ==========================================================================
   Items Table
   ========================================================================== */
.items-table-wrapper {
  margin-top: 6px;
  flex: 1;
}

table.invoice-items {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

table.invoice-items th {
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  padding: 6px 3px;
  border-top: 1.5px solid #0f172a;
  border-bottom: 1.5px solid #0f172a;
  color: #0f172a;
  text-transform: capitalize;
  letter-spacing: 0.01em;
  background: #ffffff;
  white-space: nowrap;
}
table.invoice-items th.col-name {
  text-align: left;
  padding-left: 6px;
  white-space: normal;
}

table.invoice-items td {
  font-size: 10.5px;
  padding: 5px 3px;
  border-bottom: 0.5px solid #94a3b8;
  text-align: center;
  vertical-align: middle;
  color: #0f172a;
  line-height: 1.35;
  overflow: visible;
}

table.invoice-items td.col-name {
  text-align: left;
  padding-left: 6px;
  font-weight: 600;
}

/* Totals Row */
table.invoice-items tr.row-total td {
  font-weight: 700;
  border-top: 1.5px solid #0f172a;
  border-bottom: 1.5px solid #0f172a;
  padding-top: 6px;
  padding-bottom: 6px;
  font-size: 11px;
}
table.invoice-items tr.row-total td.col-name {
  text-align: left;
  padding-left: 6px;
}

/* In Words Section */
.in-words-box {
  margin-top: 10px;
  font-size: 11px;
  color: #0f172a;
}
.in-words-box strong {
  font-weight: 700;
}

/* Signatures Section */
.signs-table {
  width: 100%;
  margin-top: 28px;
  margin-bottom: 6px;
  border-collapse: collapse;
}
.signs-table td {
  width: 50%;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #0f172a;
  vertical-align: bottom;
}
.signs-table .sign-line {
  border-top: 1px solid #0f172a;
  margin: 0 auto 6px;
  width: 55%;
}

/* Watermark */
.sheet-watermark {
  display: none;
  position: absolute;
  top: 45%;
  left: 5%;
  width: 90%;
  text-align: center;
  font-size: 56px;
  font-weight: 800;
  color: rgba(0, 104, 55, 0.08);
  transform: rotate(-28deg);
  letter-spacing: 0.08em;
  pointer-events: none;
  z-index: 0;
  text-transform: uppercase;
}
.sheet-watermark.visible {
  display: block;
}

/* ==========================================================================
   Modals & Drawers
   ========================================================================== */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: #111c2e;
  border: 1px solid #1e2d42;
  border-radius: 8px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid #1e2d42;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 {
  font-size: 15px;
  color: #ffffff;
  font-weight: 700;
}
.modal-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover {
  color: #ffffff;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  color: #cbd5e1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #1e2d42;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.history-table th {
  background: #0b1320;
  color: #94a3b8;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #1e2d42;
  font-weight: 600;
}
.history-table td {
  padding: 10px;
  border-bottom: 1px solid #1b283b;
  color: #e2e8f0;
}
.history-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Saved Products Modal & Chips */
.saved-products-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 10px;
  background: #080d16;
  border: 1px solid #1e2d42;
  border-radius: 6px;
  min-height: 60px;
  align-content: flex-start;
}

.saved-product-pill {
  display: inline-flex;
  align-items: center;
  background: #131f32;
  border: 1px solid #23354d;
  border-radius: 20px;
  padding: 4px 10px 4px 12px;
  gap: 6px;
  font-size: 12px;
  color: #e2e8f0;
  transition: all 0.15s ease;
}
.saved-product-pill:hover {
  border-color: #3b82f6;
  background: #182840;
}
.saved-product-pill .pill-name {
  cursor: pointer;
  font-weight: 500;
}
.saved-product-pill .pill-name:hover {
  color: #60a5fa;
  text-decoration: underline;
}
.saved-product-pill .pill-delete-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.saved-product-pill .pill-delete-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

.empty-saved-products {
  width: 100%;
  text-align: center;
  color: #64748b;
  font-size: 12px;
  padding: 16px 8px;
}

/* Sidebar Sort Button Highlight */
.btn-active-sort {
  border-color: #38bdf8 !important;
  color: #38bdf8 !important;
  background: rgba(56, 189, 248, 0.1) !important;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #1e293b;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  border-left: 4px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   PRINT MEDIA RULES — STRICT 1-PAGE A4 ZERO CUT-OFF
   ========================================================================== */
@page {
  size: A4 portrait;
  margin: 10mm 15mm 10mm 15mm !important;
}

@media print {
  html, body {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #0f172a !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .app-header,
  .editor-sidebar,
  .mobile-view-tabs,
  .preview-toolbar,
  .modal-backdrop,
  .toast-container,
  .no-print {
    display: none !important;
  }

  .app-container,
  .preview-pane,
  .preview-container,
  .sheet-scale-wrapper {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    overflow: visible !important;
    transform: none !important;
  }

  .sheet {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    box-sizing: border-box !important;
    transform: none !important;
  }

  .signs-table {
    margin-top: 36px !important;
    margin-bottom: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Sharp lines and colors */
  .brand-name {
    color: #006837 !important;
  }
  .brand-subtitle {
    color: #15803d !important;
  }
  .invoice-title-block span {
    color: #006837 !important;
    border-bottom: 2px solid #006837 !important;
  }
  .dealer-box-framed {
    border: 1.5px solid #1e3a8a !important;
  }
  .referred-code-box {
    border: 1px solid #64748b !important;
  }
  table.invoice-items th {
    border-top: 1.5px solid #0f172a !important;
    border-bottom: 1.5px solid #0f172a !important;
  }
  table.invoice-items td {
    border-bottom: 0.5px solid #94a3b8 !important;
  }
  table.invoice-items tr.row-total td {
    border-top: 1.5px solid #0f172a !important;
    border-bottom: 1.5px solid #0f172a !important;
  }
  .signs-table .sign-line {
    border-top: 1px solid #0f172a !important;
  }
}

/* ==========================================================================
   Cross-Platform & Mobile Optimization
   iOS Safari, Android Chrome, Tablet & Responsive Views
   ========================================================================== */

/* Universal Touch & Mobile Polish */
button, select, input, a {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media screen and (max-width: 1024px) {
  :root {
    --sidebar-width: 100%;
  }
  .app-container {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .mobile-view-tabs {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 95;
    background: #0c1421;
    border-bottom: 1px solid #1e2d42;
    padding: 8px 12px;
    gap: 8px;
  }
  .mobile-view-tabs button {
    flex: 1;
    min-height: 42px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    border: 1px solid #1e2d42;
    background: #131f32;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .mobile-view-tabs button.active {
    background: #0284c7;
    color: #ffffff;
    border-color: #38bdf8;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
  }
  .editor-sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #1e2d42;
  }
  .editor-sidebar.hidden-mobile {
    display: none !important;
  }
  .preview-pane.hidden-mobile {
    display: none !important;
  }
  .preview-container {
    padding: 16px 8px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sheet-scale-wrapper {
    margin: 0 auto;
    position: relative;
    display: block;
    flex-shrink: 0;
  }
  .sheet {
    transform-origin: top left;
    flex-shrink: 0 !important;
  }
}

@media screen and (min-width: 1025px) {
  .editor-sidebar {
    display: flex !important;
  }
  .preview-pane {
    display: flex !important;
  }
}

/* Tablet & Mobile Screens (<= 768px) */
@media screen and (max-width: 768px) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }

  .app-header {
    padding: 10px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .brand-info {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .brand-titles h1 {
    font-size: 14px;
    line-height: 1.25;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .brand-titles p {
    display: none;
  }

  .header-actions {
    display: flex;
    overflow-x: auto;
    width: 100%;
    padding: 2px 0 4px 0;
    gap: 6px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .header-actions::-webkit-scrollbar {
    display: none;
  }
  .header-actions .btn {
    white-space: nowrap;
    padding: 7px 11px;
    font-size: 12px;
    flex-shrink: 0;
    min-height: 38px;
    border-radius: 6px;
  }

  /* Prevent iOS Safari Viewport Auto-Zoom by ensuring font-size >= 16px on inputs */
  .form-control,
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px !important;
    min-height: 42px;
  }

  .line-items-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .line-items-header > div {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }
  .line-items-header > div .btn,
  .line-items-header > div select {
    flex: 1 1 auto;
    min-height: 36px;
  }

  /* Compact Preview Toolbar on Mobile */
  .preview-toolbar {
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .preview-info-text {
    display: none !important;
  }
  .preview-scale-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  /* Modals on Mobile */
  .modal-backdrop {
    padding: 10px;
    align-items: flex-end;
  }
  .modal-dialog {
    max-width: 100%;
    max-height: 88vh;
    border-radius: 12px 12px 0 0;
    margin: 0;
  }
  .modal-header {
    padding: 12px 16px;
  }
  .modal-body {
    padding: 14px;
    -webkit-overflow-scrolling: touch;
  }
  .modal-footer {
    padding: 10px 14px;
  }
}

/* Small Smartphone Screens (<= 480px) */
@media screen and (max-width: 480px) {
  .sidebar-content {
    padding: 12px 10px;
  }

  .item-card-header {
    padding: 8px 10px;
  }
  .item-header-title {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12.5px;
  }

  .btn-view-details {
    padding: 4px 7px;
    font-size: 11px;
  }

  .item-card-dropdown {
    padding: 12px 10px;
  }

  .form-row {
    flex-direction: column;
    gap: 8px;
  }

  /* For item card inputs (Qty, Rate, Comm) - keep side by side in 3 columns */
  .item-card-dropdown .form-row:nth-child(2) {
    flex-direction: row;
    gap: 6px;
  }
  .item-card-dropdown .form-row:nth-child(2) .form-group {
    flex: 1;
    min-width: 0;
  }
  .item-card-dropdown .form-row:nth-child(2) .form-control {
    padding: 6px 4px;
    text-align: center;
  }

  .item-calc-preview {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 8px;
    font-size: 11px;
  }

  .saved-products-chip-list {
    max-height: 180px;
    padding: 6px;
  }
  .saved-product-pill {
    font-size: 11.5px;
    padding: 4px 8px;
  }
}
