/* Root variables for consistent theming */
:root {
  --primary-color: #2c3e50;
  --secondary-color: #34495e;
  --accent-color: #3498db;
  --success-color: #27ae60;
  --danger-color: #e74c3c;
  --warning-color: #f39c12;
  --border-color: #e2e6ea;
  --background-color: #f8f9fa;
  --text-color: #2c3e50;
  --light-text: #6c757d;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Noto Serif Bengali', serif;
  background: var(--background-color);
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

/* Print button - only visible on screen */
.no-print {
  width: 100%;
  max-width: 800px;
  margin-bottom: 1rem;
  text-align: right;
}

.print-btn {
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-family: 'Noto Serif Bengali', serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

.print-btn:hover {
  background: #2980b9;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  transform: translateY(-1px);
}

/* Container for single invoice */
.invoice-wrapper {
  width: 100%;
  max-width: 800px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
  padding: 2rem;
  margin: 0;
}

/* Header section */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  border-bottom: 3px solid var(--primary-color);
  padding-bottom: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  flex: 1;
}

.header img {
  max-height: 80px;
  width: auto;
  margin-right: 1rem;
}

.company-info h1 {
  margin: 0;
  font-size: 2rem;
  color: var(--primary-color);
  font-weight: 700;
  letter-spacing: -0.5px;
}

.company-info p {
  margin: 0.25rem 0;
  font-size: 0.95rem;
  color: var(--light-text);
}

.header-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cash-memo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
  padding: 2px 10px 2px 4px; /* tighter left side */
  border-radius: 6px;
  background: rgba(52, 73, 94, 0.05);
  margin: 0; 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0;
  text-indent: 0;
  position: relative;
}
.cash-memo::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0; /* anchor to remove visual illusion of gap */
}

.date-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.date-label {
  font-weight: 600;
  color: var(--secondary-color);
}

.date-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-color);
}

/* Customer Information */
.customer-info {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 1.5rem;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 12px;
  border-left: 4px solid var(--accent-color);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.customer-row { display: flex; gap: 1rem; width: 100%; }
.customer-row.row-1 .customer-field { flex: 1; }
.customer-row.row-2 .customer-field.full-width { flex: 1; }

.customer-field.address-field input { width: 100%; }

.customer-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field-label {
  font-weight: 600;
  color: var(--primary-color);
  font-size: 0.9rem;
  min-width: 60px;
  text-align: left;
}

.customer-input {
  border: none;
  border-bottom: 2px solid var(--border-color);
  padding: 0.5rem 0;
  border-radius: 0;
  font-family: 'Noto Serif Bengali', serif;
  font-size: 1rem;
  width: 100%;
  transition: all 0.3s ease;
  background: transparent;
}

.customer-input:focus {
  outline: none;
  border-bottom-color: var(--accent-color);
  box-shadow: none;
  transform: none;
}

.invoice-number {
  margin-top: 0.5rem;
}

.invoice-label {
  font-weight: 600;
  color: var(--secondary-color);
}

.invoice-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-color);
}

/* Description / tagline */
.tagline {
  margin: 0 0 2rem 0;
  font-size: 0.9rem;
  color: var(--light-text);
  line-height: 1.5;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid var(--accent-color);
}

/* Table styles - improved for better UX */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1rem 0;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

thead th {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  text-align: center;
  padding: 0.75rem 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  z-index: 10;
}

tbody td {
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.9rem;
  transition: background-color 0.2s ease;
  vertical-align: middle;
}

tbody td.amount {
  text-align: right;
  padding-right: 1rem;
  font-weight: 600;
  color: var(--primary-color);
}

tbody tr:hover {
  background-color: rgba(52, 152, 219, 0.08);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody input[type="text"] {
  width: 100%;
  border: 1px solid transparent;
  background: rgba(248, 249, 250, 0.5);
  font-family: 'Noto Serif Bengali', serif;
  font-size: 0.9rem;
  padding: 0.4rem;
  text-align: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

tbody input:hover {
  background: white;
  border-color: var(--border-color);
}

tbody input:focus {
  outline: none;
  background: white;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.delete-btn {
  background: transparent;
  border: 2px solid var(--danger-color);
  color: var(--danger-color);
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.delete-btn:hover {
  background: var(--danger-color);
  color: white;
  transform: scale(1.1);
}

.add-row-btn {
  margin: 1rem 0;
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  font-family: 'Noto Serif Bengali', serif;
  background: var(--success-color);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

.add-row-btn:hover {
  background: #219150;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Totals section - enhanced visibility */
.totals-table {
  width: 100%;
  max-width: 400px;
  margin: 2rem 0 1rem auto;
  border-collapse: separate;
  border-spacing: 0;
  background: linear-gradient(to bottom, #ffffff, #f8f9fa);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.totals-table td {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.2s ease;
}

.totals-table tr:hover td {
  background-color: rgba(52, 152, 219, 0.05);
}

.totals-table tr:last-child td {
  border-bottom: none;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
}

.totals-table .label {
  text-align: left;
  font-weight: 600;
  width: 60%;
  color: var(--text-color);
  letter-spacing: normal;
}

.totals-table .value {
  text-align: right;
  font-weight: 600;
  width: 40%;
}

.totals-table .value span {
  display: inline-block;
  min-width: 80px;
  text-align: right;
}

/* Fix for subtotal and grand-total display */
#subtotal, #grand-total {
  display: inline-block !important;
  visibility: visible !important;
  color: inherit;
  font-weight: 600;
}

.totals-table input[type="text"] {
  width: 100%;
  text-align: right;
  border: 1px solid var(--border-color);
  background: white;
  font-family: 'Noto Serif Bengali', serif;
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 4px;
}

/* Discount composite controls */
#discount-row .discount-flex {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
}

#discount-type {
  border: 1px solid var(--border-color);
  background: white;
  font-family: 'Noto Serif Bengali', serif;
  font-size: 0.9rem;
  padding: 0.45rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
}

#discount-type:focus { outline: none; border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(52,152,219,0.1); }

#discount-applied {
  min-width: 70px;
  text-align: right;
  font-size: 0.85rem;
  color: var(--secondary-color);
}

/* Style the discount input */
#discount {
  width: 60px; /* Adjust width as needed */
  text-align: right;
  font-family: 'Noto Serif Bengali', serif;
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  transition: all 0.3s ease;
  background-color: white;
  color: var(--text-color);
}

#discount:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.totals-table input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.amount-in-words {
  margin: 1rem 0 2rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary-color);
  padding: 1rem;
  background: linear-gradient(135deg, #e8f4f8 0%, #d1e9f1 100%);
  border-radius: 8px;
  border-left: 4px solid var(--accent-color);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

/* Remove the money icon */
.amount-in-words::before {
  display: none;
}

/* Footer and signatures */
.footer-section {
  margin-top: 3rem;
  border-top: 2px solid var(--border-color);
  padding-top: 2rem;
}

.warning-notice {
  text-align: center;
  color: #dc3545;
  font-weight: 600;
  font-size: 0.75rem;
  font-style: italic;
  margin-top: 1rem;
}

.signature-container {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
}

.signature-box {
  flex: 1;
  text-align: center;
}

.signature-line {
  margin-top: 2rem;
  border-top: 1px solid var(--primary-color);
  height: 0;
  width: 60%;
  margin-left: auto;
  margin-right: auto;
}

.signature-label {
  margin-top: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary-color);
}

/* Responsive design for mobile */
@media (max-width: 768px) {
  body {
    padding: 0.5rem;
  }
  
  .invoice-wrapper {
    padding: 1rem;
    border-radius: 8px;
  }
  
  .header {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  
  .header-left {
    flex-direction: column;
    text-align: center;
  }
  
  .header img {
    margin-right: 0;
    margin-bottom: 0.5rem;
  }
  
  .company-info h1 {
    font-size: 1.5rem;
  }
  
  .cash-memo {
    font-size: 1.2rem;
  }
  
  table, thead, tbody, th, td, tr {
    display: block;
  }
  
  thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  
  tbody tr {
    border: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
    border-radius: 8px;
    padding: 0.5rem;
  }
  
  tbody td {
    border: none;
    position: relative;
    padding-left: 30%;
    text-align: left;
  }
  
  tbody td:before {
    content: attr(data-label);
    position: absolute;
    left: 6px;
    width: 25%;
    text-align: left;
    font-weight: 600;
    color: var(--primary-color);
  }
  
  .signature-container {
    flex-direction: column;
    gap: 2rem;
  }
  
  .totals-table {
    max-width: 100%;
  }
  
  .customer-row { flex-direction: column; gap: 0.5rem; }
  .customer-info { padding: 1rem !important; }
}

/* Print styles for half A4 size */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  body {
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  .no-print {
    display: none !important;
  }
  
  .invoice-wrapper {
    width: 100% !important;
    max-width: 14cm !important;
    margin: 0 auto !important;
    padding: 0.5cm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: white !important;
    font-size: 11px !important;
  }
  
  .header {
    margin-bottom: 1rem !important;
    padding-bottom: 0.5rem !important;
  }
  
  .company-info h1 {
    font-size: 1.2rem !important;
  }
  
  .cash-memo { font-size: 1rem !important; padding: 0.25rem 0.5rem !important; margin: 0 !important; }
  
  .tagline {
    font-size: 0.7rem !important;
    margin: 0 0 0.8rem 0 !important;
    padding: 0.4rem !important;
  }
  
  thead th { font-size: 0.75rem !important; padding: 0.4rem 0.2rem !important; }
  
  tbody td {
    font-size: 0.7rem !important;
    padding: 0.3rem 0.2rem !important;
  }
  
  .totals-table {
    font-size: 0.75rem !important;
    margin: 0.8rem 0 0.4rem auto !important;
  }
  
  .totals-table td {
    padding: 0.3rem 0.4rem !important;
  }
  
  .amount-in-words {
    font-size: 0.75rem !important;
    margin: 0.4rem 0 0.8rem 0 !important;
    padding: 0.4rem !important;
  }
  
  .footer-section {
    margin-top: 1.5rem !important;
    padding-top: 1rem !important;
  }
  
  .signature-line {
    margin-top: 2rem !important;
  }
  
  .signature-label {
    font-size: 0.8rem !important;
  }
  
  .add-row-btn, .delete-btn { display: none !important; }

  #discount-type { display: none !important; }
  #discount-applied { font-size: 0.7rem !important; }
  
  input[type="text"] {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
  }
  
  @page {
    size: A4 portrait;
    margin: 0.5cm;
  }
}
