/* ==========================================================================
   INVOQRA — INVOICE TEMPLATES & ISOLATED A4 PRINT/EXPORT STYLESHEET
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. LIVE PREVIEW INVOICE PAPER (On-Screen Responsive Display)
   -------------------------------------------------------------------------- */
.invoice-paper {
  background-color: #ffffff;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 2.25rem 2.25rem 3rem;
  color: #1e293b;
  font-size: 0.875rem;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  box-sizing: border-box;
  position: relative;
  border-radius: 6px;
  --invoice-accent: var(--accent-color, #2563eb);
}

.invoice-paper h1, 
.invoice-paper h2, 
.invoice-paper h3, 
.invoice-paper h4 {
  color: #0f172a;
}

/* --------------------------------------------------------------------------
   2. DEDICATED A4 EXPORT CANVAS (PDF & Print Independent Container)
   -------------------------------------------------------------------------- */
.export-container {
  width: 210mm;
  min-height: 297mm;
  padding: 12mm 14mm;
  box-sizing: border-box;
  background-color: #ffffff;
  color: #1e293b;
  font-size: 12px;
  line-height: 1.45;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  position: relative;
  margin: 0 auto;
}

/* Shared Template Styles for both Live Preview and Export Containers */
.inv-top-bar {
  height: 6px;
  background-color: var(--invoice-accent, #2563eb);
  margin: -2.25rem -2.25rem 2rem -2.25rem;
}

.export-container .inv-top-bar {
  margin: -12mm -14mm 8mm -14mm;
}

.inv-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.75rem;
  gap: 1.5rem;
}

.inv-logo-box img {
  max-height: 65px;
  max-width: 220px;
  object-fit: contain;
}

.inv-title-box {
  text-align: right;
}

.inv-title-box h1 {
  font-family: var(--font-heading, sans-serif);
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--invoice-accent, #2563eb);
  letter-spacing: -0.02em;
  margin-bottom: 0.15rem;
  line-height: 1;
}

.inv-number-tag {
  font-weight: 700;
  font-size: 1rem;
  color: #475569;
}

.inv-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
  padding: 1rem 1.25rem;
  background-color: #f8fafc;
  border-radius: 6px;
  border-left: 4px solid var(--invoice-accent, #2563eb);
}

.info-group-title {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.725rem;
  letter-spacing: 0.05em;
  color: var(--invoice-accent, #2563eb);
  margin-bottom: 0.35rem;
}

.info-group p {
  margin: 0;
  line-height: 1.4;
  color: #334155;
  font-size: 0.85rem;
}

.info-group strong {
  color: #0f172a;
  font-weight: 600;
}

/* Items Table */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  table-layout: fixed;
}

.inv-table th {
  background-color: var(--invoice-accent, #2563eb);
  color: #ffffff;
  padding: 0.65rem 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-align: left;
}

.inv-table th:last-child,
.inv-table td:last-child {
  text-align: right;
}

.inv-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
  color: #334155;
  font-size: 0.85rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.inv-table tr:nth-child(even) td {
  background-color: #f8fafc;
}

.item-title {
  font-weight: 600;
  color: #0f172a;
  display: block;
}

.item-desc {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.15rem;
}

/* Summary & Totals Container */
.inv-summary-flex {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.inv-notes-column {
  flex: 1;
}

.inv-totals-column {
  width: 270px;
}

.inv-totals-table {
  width: 100%;
  border-collapse: collapse;
}

.inv-totals-table td {
  padding: 0.4rem 0;
  color: #475569;
  font-size: 0.875rem;
}

.inv-totals-table tr.grand-total-row td {
  padding: 0.75rem 0.85rem;
  background-color: #f1f5f9;
  border-radius: 6px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
  border-top: 2px solid var(--invoice-accent, #2563eb);
}

.inv-totals-table tr.grand-total-row .total-amount {
  color: var(--invoice-accent, #2563eb);
  font-weight: 800;
}

.inv-section-title {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.2rem;
}

.inv-notes-block, .inv-terms-block {
  margin-bottom: 1rem;
}

.inv-notes-block p, .inv-terms-block p {
  font-size: 0.825rem;
  color: #475569;
  white-space: pre-line;
  margin: 0;
}

/* --------------------------------------------------------------------------
   TEMPLATE 2 — MINIMAL SPECIFIC OVERRIDES
   -------------------------------------------------------------------------- */
.template-minimal {
  font-family: 'Inter', sans-serif;
  color: #1e293b;
}

.template-minimal .inv-header-flex {
  padding-bottom: 1.25rem;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 1.75rem;
}

.template-minimal .inv-title-box h1 {
  font-size: 1.75rem;
  font-weight: 600;
  color: #0f172a;
}

.template-minimal .inv-table th {
  background-color: transparent !important;
  color: #0f172a !important;
  border-bottom: 2px solid #0f172a;
  padding: 0.65rem 0;
}

.template-minimal .inv-table td {
  padding: 0.7rem 0;
  border-bottom: 1px solid #f1f5f9;
}

.template-minimal .inv-table tr:nth-child(even) td {
  background-color: transparent;
}

.template-minimal .inv-totals-table tr.grand-total-row td {
  background-color: transparent;
  border-top: 2px solid #0f172a;
  border-bottom: 2px solid #0f172a;
  padding: 0.65rem 0;
  color: #0f172a;
}

/* --------------------------------------------------------------------------
   TEMPLATE 3 — PROFESSIONAL SPECIFIC OVERRIDES
   -------------------------------------------------------------------------- */
.template-professional .inv-top-box {
  background-color: #0f172a;
  color: #ffffff;
  margin: -2.25rem -2.25rem 1.75rem -2.25rem;
  padding: 2rem 2.25rem;
  border-bottom: 4px solid var(--invoice-accent, #2563eb);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.export-container.template-professional .inv-top-box {
  margin: -12mm -14mm 8mm -14mm;
  padding: 8mm 14mm;
}

.template-professional .inv-top-box h1 {
  color: #ffffff;
  font-size: 1.85rem;
  margin-bottom: 0.15rem;
}

.template-professional .inv-top-box p {
  color: #94a3b8;
  font-size: 0.85rem;
  margin: 0;
}

.template-professional .info-box {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 1rem;
  background-color: #f8fafc;
}

.template-professional .inv-table {
  border: 1px solid #cbd5e1;
}

.template-professional .inv-table th {
  background-color: #f1f5f9 !important;
  color: #0f172a !important;
  border-bottom: 2px solid #cbd5e1;
}

.template-professional .inv-table td {
  border-right: 1px solid #e2e8f0;
}

.template-professional .inv-table td:last-child {
  border-right: none;
}

.template-professional .inv-totals-table tr.grand-total-row td {
  background-color: #0f172a;
  color: #ffffff;
}

.template-professional .inv-totals-table tr.grand-total-row .total-amount {
  color: #38bdf8;
}

/* --------------------------------------------------------------------------
   3. LIVE PREVIEW INVOICE PAPER RESPONSIVE OVERRIDES (Mobile Screens)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .invoice-paper {
    width: 100% !important;
    max-width: 100% !important;
    padding: 1rem 0.65rem 1.25rem !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    border-radius: 4px !important;
    font-size: 0.8rem !important;
  }

  .inv-top-bar {
    margin: -1rem -0.65rem 1rem -0.65rem !important;
  }

  .inv-header-flex {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.85rem !important;
    align-items: flex-start !important;
    margin-bottom: 1rem !important;
    width: 100% !important;
  }

  .inv-title-box {
    text-align: left !important;
  }

  .inv-title-box h1 {
    font-size: 1.5rem !important;
  }

  .inv-details-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
    padding: 0.75rem !important;
    margin-bottom: 1rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .inv-table {
    width: 100% !important;
    margin-bottom: 1rem !important;
    table-layout: fixed !important;
  }

  .inv-table th {
    padding: 0.45rem 0.35rem !important;
    font-size: 0.675rem !important;
  }

  .inv-table td {
    padding: 0.45rem 0.35rem !important;
    font-size: 0.75rem !important;
  }

  .inv-summary-flex {
    display: flex !important;
    flex-direction: column-reverse !important;
    gap: 1rem !important;
    margin-bottom: 1rem !important;
    width: 100% !important;
  }

  .inv-totals-column,
  .inv-notes-column {
    width: 100% !important;
  }

  /* Template Professional & Minimal Overrides */
  .template-professional .inv-top-box {
    margin: -1rem -0.65rem 1rem -0.65rem !important;
    padding: 1rem 0.75rem !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  .template-professional .inv-top-box > div:last-child {
    text-align: left !important;
  }

  .template-minimal .inv-header-flex {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.65rem !important;
  }

  .template-minimal .inv-title-box {
    text-align: left !important;
  }
}

@media (max-width: 480px) {
  .invoice-paper {
    padding: 0.85rem 0.5rem 1rem !important;
  }

  .inv-top-bar {
    margin: -0.85rem -0.5rem 0.85rem -0.5rem !important;
  }

  .template-professional .inv-top-box {
    margin: -0.85rem -0.5rem 0.85rem -0.5rem !important;
    padding: 0.85rem 0.5rem !important;
  }

  .inv-table th {
    padding: 0.4rem 0.25rem !important;
    font-size: 0.625rem !important;
  }

  .inv-table td {
    padding: 0.4rem 0.25rem !important;
    font-size: 0.725rem !important;
  }

  .item-desc {
    font-size: 0.675rem !important;
  }
}

/* --------------------------------------------------------------------------
   4. DEDICATED @media print CSS (HYPER-ISOLATED A4 PRINTING)
   -------------------------------------------------------------------------- */
@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  /* 1. Hide ALL body direct children completely from print flow */
  body > * {
    display: none !important;
  }

  /* 2. Show ONLY the dedicated print container */
  body > #print-export-container {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    min-height: 0 !important;
    height: auto !important;
    margin: 0 !important;
    padding: 4mm 6mm !important;
    background: #ffffff !important;
    box-shadow: none !important;
    visibility: visible !important;
  }

  #print-export-container * {
    visibility: visible !important;
  }

  /* 3. Page break safety */
  .inv-table tr,
  .inv-summary-flex,
  .inv-totals-table,
  .grand-total-row {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}
