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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f5f5f5;
  color: #222;
  line-height: 1.5;
  padding: 16px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

.app-header h1 {
  font-size: 1.25rem;
  text-align: center;
  padding: 12px 0;
  color: #1a1a2e;
  border-bottom: 2px solid #1a1a2e;
  margin-bottom: 20px;
}

.invoice-form {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Form elements */
.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: #1a1a2e;
  box-shadow: 0 0 0 2px rgba(26, 26, 46, 0.1);
}

.form-group textarea {
  resize: vertical;
}

/* Meta row */
.meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

fieldset {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

legend {
  font-weight: 700;
  font-size: 0.9rem;
  color: #1a1a2e;
  padding: 0 6px;
}

/* Table */
.table-container {
  overflow-x: auto;
  margin-bottom: 12px;
}

#itemsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 1000px;
}

#itemsTable th {
  background: #1a1a2e;
  color: #fff;
  padding: 8px 6px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

#itemsTable td {
  padding: 4px 6px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}

#itemsTable td input,
#itemsTable td select {
  width: 100%;
  padding: 6px 4px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 0.85rem;
  font-family: inherit;
  background: #fff;
}

#itemsTable td input:focus,
#itemsTable td select:focus {
  outline: none;
  border-color: #1a1a2e;
}

#itemsTable td input.calculated {
  background: #f0f0f0;
  color: #444;
}

#itemsTable td input.exempt {
  background: #f0f0f0;
  color: #999;
  font-style: italic;
}

#itemsTable td .remove-btn {
  background: none;
  border: none;
  color: #c0392b;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

#itemsTable td .remove-btn:hover {
  color: #e74c3c;
}

/* Table actions */
.table-actions {
  margin-bottom: 20px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: #1a1a2e;
  color: #fff;
}

.btn-primary:hover {
  background: #2d2d5e;
}

.btn-secondary {
  background: #e0e0e0;
  color: #333;
}

.btn-secondary:hover {
  background: #ccc;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
}

.btn-danger:hover {
  background: #e74c3c;
}

.action-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* Totals */
.totals-section {
  background: #f9f9f9;
  border: 2px solid #1a1a2e;
  border-radius: 6px;
  padding: 16px;
  margin-top: 16px;
}

.grand-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.grand-total-label {
  font-size: 1.1rem;
  font-weight: 700;
}

.grand-total-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: #1a1a2e;
}

.amount-in-words-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.words-label {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.words-value {
  font-style: italic;
  font-size: 0.9rem;
  color: #555;
}

/* ===== PDF Template Styles (for html2pdf) ===== */
#invoice-pdf-template {
  display: none;
}

.pdf-page {
  width: 190mm;
  margin: 0 auto;
  padding: 10mm 8mm;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: #000;
  line-height: 1.3;
  position: relative;
}

.pdf-top-line {
  display: flex;
  justify-content: space-between;
  font-size: 8pt;
  margin-bottom: 6mm;
  color: #333;
}

.pdf-title {
  text-align: center;
  font-size: 22pt;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 3mm;
}

.pdf-business {
  text-align: center;
  font-size: 13pt;
  font-weight: 700;
  margin-bottom: 2mm;
}

.pdf-tagline {
  text-align: center;
  font-size: 8pt;
  color: #555;
  margin-bottom: 1.5mm;
}

.pdf-address {
  text-align: center;
  font-size: 7.5pt;
  color: #555;
  margin-bottom: 1.5mm;
}

.pdf-mobile {
  text-align: center;
  font-size: 7.5pt;
  color: #555;
  margin-bottom: 3mm;
}

.pdf-hr {
  border: none;
  border-top: 1px solid #000;
  margin: 2mm 0;
}

.pdf-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10mm;
  margin-bottom: 1mm;
}

.pdf-buyer {
  flex: 1;
}

.pdf-section-title {
  font-weight: 700;
  font-size: 9pt;
  margin-bottom: 1.5mm;
}

.pdf-field {
  font-size: 8pt;
  margin-bottom: 1mm;
  line-height: 1.4;
}

.pdf-fl {
  font-weight: 600;
}

.pdf-fv {
  font-weight: 700;
}

.pdf-inv-meta-box {
  border: 1px solid #999;
  padding: 2.5mm 3mm;
  min-width: 70mm;
}

.pdf-meta-item {
  font-size: 8pt;
  margin-bottom: 1mm;
  display: flex;
  gap: 4mm;
}

.pdf-ml {
  min-width: 22mm;
  color: #555;
}

.pdf-mv {
  font-weight: 700;
}

/* Table */
.pdf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 7pt;
  margin-bottom: 1mm;
  page-break-inside: auto;
}

.pdf-table thead {
  display: table-header-group;
  page-break-after: avoid;
}

.pdf-table th {
  background: #1a1a2e;
  color: #fff;
  padding: 2.5mm 1mm;
  text-align: center;
  font-weight: 600;
  font-size: 7pt;
}

.pdf-table td {
  padding: 1.5mm 1mm;
  border: 0.5px solid #999;
  text-align: center;
  vertical-align: middle;
}

.pdf-table tr {
  page-break-inside: avoid;
}

.pdf-table tbody tr:nth-child(even) td {
  background: #f8f8f8;
}

/* Column widths */
.pdf-c-sl { width: 4%; }
.pdf-c-particulars { width: 25%; text-align: left; }
.pdf-c-hsn { width: 8%; }
.pdf-c-qty { width: 5%; }
.pdf-c-rate { width: 8%; text-align: right; padding-right: 2mm; }
.pdf-c-taxable { width: 10%; text-align: right; padding-right: 2mm; }
.pdf-c-sgstp { width: 5%; }
.pdf-c-sgsta { width: 9%; text-align: right; padding-right: 2mm; }
.pdf-c-cgstp { width: 5%; }
.pdf-c-cgsta { width: 9%; text-align: right; padding-right: 2mm; }
.pdf-c-total { width: 10%; text-align: right; padding-right: 2mm; }

.pdf-table td:nth-child(1) { text-align: center; }
.pdf-table td:nth-child(2) { text-align: left; }
.pdf-table td:nth-child(3) { text-align: center; }
.pdf-table td:nth-child(4) { text-align: center; }
.pdf-table td:nth-child(5) { text-align: right; padding-right: 2mm; }
.pdf-table td:nth-child(6) { text-align: right; padding-right: 2mm; }
.pdf-table td:nth-child(7) { text-align: center; }
.pdf-table td:nth-child(8) { text-align: right; padding-right: 2mm; }
.pdf-table td:nth-child(9) { text-align: center; }
.pdf-table td:nth-child(10) { text-align: right; padding-right: 2mm; }
.pdf-table td:nth-child(11) { text-align: right; padding-right: 2mm; }

/* Grand Total */
.pdf-gt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1.5px solid #000;
  padding: 2mm 3mm;
  margin-bottom: 1.5mm;
  page-break-inside: avoid;
}

.pdf-gt-label {
  font-size: 11pt;
  font-weight: 700;
}

.pdf-gt-value {
  font-size: 12pt;
  font-weight: 800;
}

/* Amount in words */
.pdf-words-row {
  font-size: 8pt;
  margin-bottom: 1mm;
  page-break-inside: avoid;
}

.pdf-words-lbl {
  font-weight: 700;
}

.pdf-words-val {
  font-style: italic;
  margin-left: 3mm;
}

/* Bottom row */
.pdf-bottom-row {
  display: flex;
  gap: 4mm;
  margin-bottom: 1mm;
  page-break-inside: avoid;
}

.pdf-bank-box {
  flex: 1;
  border: 0.5px solid #999;
  padding: 2mm 3mm;
}

.pdf-bank-line {
  font-size: 7pt;
  margin-bottom: 0.8mm;
}

.pdf-sig-box {
  flex: 1;
  border: 0.5px solid #999;
  padding: 2mm 3mm;
  text-align: left;
}

.pdf-sig-title {
  font-weight: 700;
  font-size: 9pt;
  margin-bottom: 4mm;
  margin-top: 3mm;
}

.pdf-sig-line {
  border-bottom: 1px solid #999;
  width: 70%;
  margin-bottom: 1mm;
}

.pdf-sig-label {
  font-size: 7pt;
  color: #555;
}

/* Terms */
.pdf-terms {
  page-break-inside: avoid;
}

.pdf-term {
  font-size: 7pt;
  margin-bottom: 0.8mm;
}

.pdf-copy-line {
  font-size: 6.5pt;
  margin-top: 0.5mm;
}

/* ===== Print Styles ===== */
@media print {
  body {
    background: #fff;
    padding: 0;
    font-size: 10pt;
  }

  .app-header,
  .table-actions,
  .action-buttons,
  .remove-btn {
    display: none !important;
  }

  .invoice-form {
    box-shadow: none;
    border: none;
    padding: 0;
    border-radius: 0;
  }

  .container {
    max-width: 100%;
  }

  .meta-row {
    display: flex;
    gap: 20px;
  }

  .meta-row .form-group {
    flex: 1;
  }

  .form-group input,
  .form-group textarea {
    border: none;
    padding: 2px 4px;
    background: transparent;
  }

  .form-group label {
    font-size: 8pt;
  }

  fieldset {
    border: 1px solid #999;
    padding: 10px;
  }

  #itemsTable {
    min-width: auto;
    font-size: 8pt;
  }

  #itemsTable th {
    background: #333 !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #itemsTable td {
    border: 1px solid #999;
  }

  #itemsTable td input,
  #itemsTable td select {
    border: none;
    background: transparent;
    padding: 2px;
    font-size: 8pt;
  }

  #itemsTable td input.calculated {
    background: #f0f0f0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .totals-section {
    border-color: #000;
    background: #f9f9f9;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .grand-total-value {
    font-size: 14pt;
  }

  .btn {
    display: none !important;
  }

  @page {
    margin: 12mm;
    size: A4 portrait;
  }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .meta-row {
    grid-template-columns: 1fr;
  }

  .action-buttons {
    flex-direction: column;
  }

  .btn {
    width: 100%;
    text-align: center;
  }
}
