/* ========== RESET & BASE STYLES ========== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Poppins", "Segoe UI", Arial, sans-serif;
  background: #f5f7fa;
  color: #222;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-weight: 600;
  color: #222;
}

button, select, input, textarea {
  font-family: inherit;
}

/* ========== HEADER ========== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

header h1 {
  font-size: 1.4rem;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 20px;
}
.switch input {
  display: none;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 20px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}
input:checked + .slider {
  background-color: #4b6cff;
}
input:checked + .slider:before {
  transform: translateX(22px);
}

/* ========== APP CONTAINER ========== */
.app-container {
  max-width: 1300px;
  margin: auto;
  padding: 20px;
}

/* ========== CONTROLS ========== */
.controls {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* ========== BUTTONS ========== */
.btn {
  background: #fff;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.btn:hover {
  background: #f0f0f0;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.btn-primary {
  background: linear-gradient(135deg, #6b46ff 0%, #4a90e2 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px rgba(107,70,255,0.3);
}
.btn-primary:hover {
  box-shadow: 0 6px 16px rgba(107,70,255,0.4);
  transform: translateY(-1px);
}
.btn-danger {
  background: #e74c3c;
  color: #fff;
  border: none;
}
.btn-danger:hover {
  background: #c0392b;
}
.btn.small {
  font-size: 13px;
  padding: 6px 12px;
}

/* ========== GRID LAYOUT ========== */
.main-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  gap: 20px;
}

.form-column {
  background: #fff;
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.preview-column {
  position: sticky;
  top: 20px;
  align-self: start;
}

/* ========== FORM STYLES ========== */
.form-section h2 {
  font-size: 16px;
  margin-top: 20px;
  margin-bottom: 10px;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid #f0f0f0;
}

.form-section h2 i {
  color: #6b46ff;
  font-size: 18px;
}

.form-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 13px;
  margin-bottom: 5px;
  color: #555;
}

input, select, textarea {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: #6b46ff;
  box-shadow: 0 0 0 2px rgba(107,70,255,0.2);
}

input[type="file"] {
  padding: 10px;
  cursor: pointer;
  background: #f8f9fc;
  border: 2px dashed #ccc;
}

input[type="file"]:hover {
  border-color: #6b46ff;
  background: #f0f0ff;
}

/* ========== LOGO PREVIEW ========== */
.logo-preview-container {
  margin-top: 12px;
  position: relative;
  display: inline-block;
  border: 2px solid #e8e8e8;
  border-radius: 8px;
  padding: 8px;
  background: #f8f9fc;
}

.logo-preview-container img {
  max-width: 200px;
  max-height: 100px;
  display: block;
  object-fit: contain;
}

.btn-remove-logo {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.btn-remove-logo:hover {
  background: #c0392b;
  transform: scale(1.1);
}

.preview-logo {
  margin-bottom: 12px;
}

.preview-logo img {
  max-width: 150px;
  max-height: 80px;
  object-fit: contain;
  display: block;
}

/* ========== RADIO BUTTONS ========== */
.radio-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.radio-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.2s;
  font-size: 14px;
}

.radio-list label:hover {
  background: #f8f9fc;
}

.radio-list input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #6b46ff;
}

.payment-methods label.small {
  font-size: 13px;
  margin-top: 8px;
  color: #666;
}

.payment-methods label.muted {
  color: #888;
}

/* ========== ITEMS TABLE ========== */
.items-table {
  margin-top: 10px;
}

.items-header {
  display: flex;
  background: #f8f9fc;
  border: 1px solid #e2e5ea;
  padding: 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
}

.item-col {
  padding: 0 6px;
}
.description { flex: 2; }
.quantity, .price, .tax, .amount, .action { flex: 1; text-align: center; }

.item-row {
  display: flex;
  align-items: center;
  border: 1px solid #e2e5ea;
  border-top: none;
  padding: 6px;
  border-radius: 0;
}

.item-row input {
  width: 100%;
  text-align: center;
}

.item-row .desc-input {
  text-align: left;
}

.item-row .remove-item {
  color: #e74c3c;
  cursor: pointer;
  font-size: 16px;
}

.items-actions {
  text-align: right;
  margin-top: 8px;
}

/* ========== TOTALS & SUMMARY ========== */
.totals-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.discount-row {
  display: flex;
  gap: 8px;
}

.summary {
  border-top: 1px solid #e2e5ea;
  margin-top: 10px;
  padding-top: 8px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 4px 0;
}
.summary-row.total {
  font-weight: 600;
  color: #6b46ff;
}

/* ========== INLINE PREVIEW PANEL ========== */
.invoice-paper {
  background: #fff;
  padding: 24px;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.06);
  border: 1px solid #e8e8e8;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #6b46ff;
  margin-bottom: 20px;
  padding-bottom: 16px;
  gap: 20px;
}

.company-info {
  flex: 1;
}

.company-info h2 {
  font-size: 20px;
  color: #222;
  margin-bottom: 8px;
  font-weight: 700;
}

.company-info p {
  font-size: 13px;
  color: #666;
  line-height: 1.6;
  margin: 2px 0;
}

.invoice-title {
  text-align: right;
  flex-shrink: 0;
}

.invoice-title h1 {
  font-size: 28px;
  color: #6b46ff;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: 1px;
}

.invoice-meta {
  font-size: 13px;
  color: #555;
  min-width: 200px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}

.meta-row span:first-child {
  color: #777;
  font-weight: 500;
}

.meta-row span:last-child {
  color: #222;
  font-weight: 600;
}

.client-info {
  background: #f8f9fc;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  border-left: 4px solid #6b46ff;
}

.client-info h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: #6b46ff;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.client-info p {
  font-size: 13px;
  color: #444;
  line-height: 1.6;
  margin: 2px 0;
}

/* ========== INVOICE ITEMS TABLE ========== */
.invoice-items {
  margin: 20px 0;
}

.invoice-items .items-header {
  display: grid;
  grid-template-columns: 2fr 0.8fr 1fr 0.8fr 1fr;
  gap: 12px;
  background: linear-gradient(135deg, #6b46ff 0%, #4a90e2 100%);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.invoice-items .items-header > div {
  text-align: left;
}

.invoice-items .items-header .col-qty,
.invoice-items .items-header .col-price,
.invoice-items .items-header .col-tax,
.invoice-items .items-header .col-total {
  text-align: right;
}

.invoice-items .item-row {
  display: grid;
  grid-template-columns: 2fr 0.8fr 1fr 0.8fr 1fr;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e8e8e8;
  font-size: 13px;
  align-items: center;
  transition: background 0.2s;
}

.invoice-items .item-row:hover {
  background: #f8f9fc;
}

.invoice-items .item-row:last-child {
  border-bottom: none;
}

.invoice-items .item-row.empty-message {
  display: block;
  text-align: center;
  color: #999;
  font-style: italic;
  padding: 24px;
  background: #f8f9fc;
  border-radius: 8px;
}

.invoice-items .col-desc {
  font-weight: 500;
  color: #333;
  text-align: left;
  word-break: break-word;
}

.invoice-items .col-qty,
.invoice-items .col-price,
.invoice-items .col-tax,
.invoice-items .col-total {
  text-align: right;
  color: #555;
}

.invoice-items .col-total {
  font-weight: 600;
  color: #222;
}

/* ========== INVOICE SUMMARY ========== */
.invoice-summary {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  gap: 24px;
  padding-top: 20px;
  border-top: 2px solid #e8e8e8;
}

.summary-notes {
  flex: 1;
  background: #f8f9fc;
  padding: 16px;
  border-radius: 8px;
}

.summary-notes h4 {
  font-size: 13px;
  color: #6b46ff;
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-notes p {
  font-size: 13px;
  color: #555;
  line-height: 1.6;
}

.summary-totals {
  min-width: 280px;
  background: #f8f9fc;
  padding: 16px;
  border-radius: 8px;
}

.summary-totals .total-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid #e0e0e0;
}

.summary-totals .total-row:last-child {
  border-bottom: none;
}

.summary-totals .total-row span:first-child {
  color: #666;
  font-weight: 500;
}

.summary-totals .total-row span:last-child {
  color: #222;
  font-weight: 600;
}

.summary-totals .grand-total {
  font-weight: 700;
  color: #fff;
  font-size: 16px;
  background: linear-gradient(135deg, #6b46ff 0%, #4a90e2 100%);
  padding: 12px 16px;
  margin: 8px -16px -16px -16px;
  border-radius: 0 0 8px 8px;
}

.summary-totals .grand-total span {
  color: #fff;
}

/* ========== INVOICE PAYMENT ========== */
.invoice-payment {
  margin-top: 24px;
  padding: 16px;
  background: #f8f9fc;
  border-radius: 8px;
  border-left: 4px solid #6b46ff;
}

.invoice-payment h4 {
  font-size: 13px;
  color: #6b46ff;
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.invoice-payment p {
  font-size: 13px;
  color: #444;
  line-height: 1.6;
  margin: 4px 0;
}

.invoice-payment .payment-details {
  white-space: pre-wrap;
  color: #666;
  font-family: monospace;
  background: #fff;
  padding: 8px;
  border-radius: 4px;
  margin-top: 8px;
}

.invoice-footer {
  text-align: center;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #e8e8e8;
  font-size: 13px;
  color: #777;
  font-style: italic;
}

/* ========== OVERLAY PREVIEW ========== */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.overlay.show {
  display: flex;
}

.overlay-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.overlay-panel {
  position: relative;
  background: #fff;
  width: 90%;
  max-width: 900px;
  max-height: 90vh;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: fadeIn 0.3s ease;
  display: flex;
  flex-direction: column;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 2px solid #e8e8e8;
  background: linear-gradient(135deg, #f8f9fc 0%, #fff 100%);
}

.overlay-header h3 {
  font-size: 18px;
  color: #222;
  font-weight: 600;
}

.overlay-actions {
  display: flex;
  gap: 10px;
}

.overlay-body {
  padding: 24px;
  overflow-y: auto;
  background: #f5f7fa;
}

.overlay-body .invoice-paper {
  margin: 0 auto;
  max-width: 800px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
  .preview-column {
    position: relative;
  }
  
  .invoice-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .invoice-title {
    text-align: left;
    margin-top: 12px;
  }
  
  .invoice-summary {
    flex-direction: column;
  }
  
  .summary-totals {
    min-width: 100%;
  }
  
  .invoice-items .items-header,
  .invoice-items .item-row {
    grid-template-columns: 1.5fr 0.6fr 0.8fr 0.6fr 0.9fr;
    gap: 8px;
    font-size: 11px;
    padding: 10px 12px;
  }
  
  .overlay-panel {
    width: 95%;
    max-height: 95vh;
  }
  
  .overlay-header {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
  
  .overlay-actions {
    width: 100%;
    justify-content: stretch;
  }
  
  .overlay-actions .btn {
    flex: 1;
  }
}

@media (max-width: 600px) {
  .controls {
    flex-direction: column;
  }
  
  .controls .btn {
    width: 100%;
    justify-content: center;
  }
  
  .invoice-items .items-header,
  .invoice-items .item-row {
    grid-template-columns: 2fr 0.7fr 1fr;
    font-size: 11px;
  }
  
  .invoice-items .col-tax,
  .invoice-items .col-price {
    display: none;
  }
}

/* ========== PRINT STYLES ========== */
@media print {
  body {
    background: #fff;
  }
  
  .no-print,
  .controls,
  header,
  .form-column,
  .overlay {
    display: none !important;
  }
  
  .app-container {
    max-width: 100%;
    padding: 0;
  }
  
  .main-grid {
    grid-template-columns: 1fr;
  }
  
  .preview-column {
    position: relative;
    top: 0;
  }
  
  .invoice-paper {
    box-shadow: none;
    border: none;
    padding: 20px;
  }
  
  .invoice-items .items-header {
    background: #333 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  
  .summary-totals .grand-total {
    background: #6b46ff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ========== DARK MODE ========== */
body.dark-mode {
  background: #1a1a2e;
  color: #e0e0e0;
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4 {
  color: #e0e0e0;
}

body.dark-mode .form-column,
body.dark-mode .invoice-paper {
  background: #16213e;
  border-color: #2a3a5a;
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  background: #0f1624;
  border-color: #2a3a5a;
  color: #e0e0e0;
}

body.dark-mode input:focus,
body.dark-mode select:focus,
body.dark-mode textarea:focus {
  border-color: #6b46ff;
  background: #1a1a2e;
}

body.dark-mode .btn {
  background: #2a3a5a;
  color: #e0e0e0;
  border-color: #3a4a6a;
}

body.dark-mode .btn:hover {
  background: #3a4a6a;
}

body.dark-mode .items-header {
  background: #2a3a5a;
  border-color: #3a4a6a;
}

body.dark-mode .item-row {
  border-color: #2a3a5a;
}

body.dark-mode .summary {
  border-color: #2a3a5a;
}

body.dark-mode .form-section h2 {
  color: #e0e0e0;
  border-color: #2a3a5a;
}

body.dark-mode .form-group label {
  color: #b0b0b0;
}

body.dark-mode .invoice-header {
  border-color: #6b46ff;
}

body.dark-mode .client-info,
body.dark-mode .summary-notes,
body.dark-mode .summary-totals,
body.dark-mode .invoice-payment {
  background: #0f1624;
}

body.dark-mode .client-info h3,
body.dark-mode .invoice-payment h4 {
  color: #8b7aff;
}

body.dark-mode .client-info p,
body.dark-mode .invoice-payment p {
  color: #b0b0b0;
}

body.dark-mode .company-info p,
body.dark-mode .invoice-meta,
body.dark-mode .invoice-footer {
  color: #999;
}

body.dark-mode .invoice-items .item-row:hover {
  background: #1a1a2e;
}

body.dark-mode .invoice-items .col-desc {
  color: #e0e0e0;
}

body.dark-mode .invoice-items .col-qty,
body.dark-mode .invoice-items .col-price,
body.dark-mode .invoice-items .col-tax,
body.dark-mode .invoice-items .col-total {
  color: #b0b0b0;
}

body.dark-mode .invoice-items .col-total {
  color: #e0e0e0;
}

body.dark-mode .overlay-backdrop {
  background: rgba(0,0,0,0.8);
}

body.dark-mode .overlay-panel {
  background: #16213e;
}

body.dark-mode .overlay-header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-color: #2a3a5a;
}

body.dark-mode .overlay-body {
  background: #1a1a2e;
}

body.dark-mode .logo-preview-container {
  background: #0f1624;
  border-color: #2a3a5a;
}

body.dark-mode input[type="file"] {
  background: #0f1624;
  border-color: #2a3a5a;
  color: #e0e0e0;
}

body.dark-mode input[type="file"]:hover {
  border-color: #6b46ff;
  background: #1a1a2e;
}

body.dark-mode .radio-list label:hover {
  background: #1a1a2e;
}

body.dark-mode .payment-details {
  background: #0f1624 !important;
  color: #b0b0b0 !important;
}
