/* Invoice Generator — Base Styles */

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

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #1a1a2e;
  background: #f5f5f5;
}

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

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 24px 0;
  color: #0f0f23;
}

/* Site Header & Logo */
.site-header {
  text-align: center;
  padding: 8px 0 20px 0;
  margin-bottom: 4px;
}

.site-logo-link {
  display: inline-block;
  text-decoration: none;
}

.site-logo {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 3fr 2fr; /* 60% / 40% */
  gap: 24px;
  align-items: start;
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

/* Cards */
.card {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Form Sections */
.form-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid #e5e7eb;
}

.form-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.form-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 12px 0;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 12px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: #4b5563;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #1a1a2e;
  transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Logo Upload */
.logo-upload-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-upload-area.has-logo {
  align-items: flex-start;
}

.logo-thumb {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
}

.logo-upload-prompt {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-upload-btn {
  cursor: pointer;
  flex-shrink: 0;
}

.logo-formats {
  font-size: 0.75rem;
  color: #9ca3af;
}

.logo-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn-remove-logo {
  background: #fee2e2;
  color: #dc2626;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.btn-remove-logo:hover {
  background: #fecaca;
}

/* Logo in invoice preview */
.inv-logo-wrapper {
  text-align: center;
  margin-bottom: 12px;
}

.inv-logo {
  max-width: 200px;
  max-height: 80px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: inline-block;
  vertical-align: middle;
}

/* Line Items */
.item-row {
  display: grid;
  grid-template-columns: 1fr 80px 100px 40px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.item-row input {
  padding: 8px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #1a1a2e;
}

.item-row input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary {
  background: #e5e7eb;
  color: #374151;
}

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

.btn-remove {
  background: #fee2e2;
  color: #dc2626;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 6px 10px;
  line-height: 1;
}

.btn-remove:hover {
  background: #fecaca;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 32px;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: wait;
}

.btn-reset {
  background: #fff;
  color: #6b7280;
  border: 1px solid #d1d5db;
  font-size: 0.875rem;
  padding: 12px 24px;
}

.btn-reset:hover {
  background: #f9fafb;
  color: #374151;
  border-color: #9ca3af;
}

/* Ad Container (Google AdSense) */
.ad-container {
  width: 100%;
  max-width: 728px;
  margin: 24px auto 0 auto;
  min-height: 90px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.ad-container ins.adsbygoogle {
  display: block;
  width: 100%;
}

@media (max-width: 768px) {
  .ad-container {
    max-width: 100%;
    min-height: 60px;
  }
}

/* Download section */
.download-section {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

.spinner-hidden {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Preview Panel */
.preview-card {
  position: sticky;
  top: 24px;
}

@media (max-width: 768px) {
  .preview-card {
    position: static;
  }
}

.preview-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: #9ca3af;
  font-size: 0.875rem;
  border: 2px dashed #e5e7eb;
  border-radius: 8px;
}

/* ============================================================
   Invoice Preview Document Styles
   ============================================================ */

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.inv-company h3 {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0 0 4px 0;
  color: #0f0f23;
}

.inv-company p {
  margin: 0;
  font-size: 0.8125rem;
  color: #4b5563;
  line-height: 1.5;
}

.inv-title {
  text-align: right;
  flex-shrink: 0;
}

.inv-title h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0 0 4px 0;
  color: #0f0f23;
  letter-spacing: 0.05em;
}

.inv-title p {
  margin: 0;
  font-size: 0.8125rem;
  color: #6b7280;
}

.inv-client {
  margin-bottom: 24px;
  padding: 12px 0;
  border-top: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
}

.inv-client h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 4px 0;
  color: #6b7280;
}

.inv-client p {
  margin: 0;
  font-size: 0.875rem;
  color: #1f2937;
  line-height: 1.5;
}

/* Line items table */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 0.8125rem;
}

.inv-table thead th {
  text-align: left;
  padding: 8px 8px;
  border-bottom: 2px solid #d1d5db;
  font-weight: 600;
  color: #374151;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.inv-table thead th:last-child,
.inv-table thead th:nth-child(2),
.inv-table thead th:nth-child(3) {
  text-align: right;
}

.inv-table tbody td {
  padding: 8px 8px;
  border-bottom: 1px solid #f3f4f6;
  color: #1f2937;
  vertical-align: top;
}

.inv-table tbody td:last-child,
.inv-table tbody td:nth-child(2),
.inv-table tbody td:nth-child(3) {
  text-align: right;
  white-space: nowrap;
}

/* Totals */
.inv-totals {
  margin-left: auto;
  max-width: 220px;
  margin-bottom: 16px;
}

.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.8125rem;
  color: #4b5563;
}

.inv-total-grand {
  font-size: 0.9375rem;
  font-weight: 700;
  color: #0f0f23;
  border-top: 2px solid #0f0f23;
  padding-top: 8px;
  margin-top: 4px;
}

/* Notes */
.inv-notes {
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

.inv-notes h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 4px 0;
  color: #6b7280;
}

.inv-notes p {
  margin: 0;
  font-size: 0.8125rem;
  color: #4b5563;
  font-style: italic;
}

/* ============================================================
   Tab Navigation Bar
   ============================================================ */

.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid hsl(220, 13%, 91%);
  margin-bottom: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: 12px 24px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: hsl(220, 9%, 46%);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab:hover {
  color: hsl(221, 83%, 40%);
}

.tab.active {
  color: hsl(221, 83%, 53%);
  border-bottom-color: hsl(221, 83%, 53%);
}

@media (max-width: 480px) {
  .tab {
    padding: 10px 14px;
    font-size: 0.8125rem;
  }
}

/* ============================================================
   View Container Visibility
   ============================================================ */

.view-container {
  display: none;
}

.view-container.active {
  display: block;
}

/* ============================================================
   Profile Cards
   ============================================================ */

.profile-card {
  max-width: 640px;
}

.profile-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 4px 0;
  color: hsl(220, 20%, 14%);
}

.profile-desc {
  font-size: 0.875rem;
  color: hsl(220, 9%, 46%);
  margin: 0 0 20px 0;
}

/* Save confirmation flash */
.save-confirm {
  display: inline-block;
  margin-left: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(142, 71%, 35%);
  vertical-align: middle;
  animation: confirmFade 2s ease forwards;
}

@keyframes confirmFade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Placeholder for upcoming features */
.placeholder-content {
  padding: 32px 0;
  text-align: center;
  color: hsl(220, 9%, 60%);
  font-size: 0.9375rem;
}

/* ============================================================
   Products Catalog Table & Form
   ============================================================ */

.products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.products-table thead th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid hsl(220, 13%, 91%);
  font-weight: 600;
  color: hsl(220, 9%, 30%);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.products-table thead th:last-child {
  text-align: right;
  width: 60px;
}

.products-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid hsl(220, 14%, 96%);
  color: hsl(220, 20%, 14%);
  vertical-align: middle;
}

.products-table tbody td:last-child {
  text-align: right;
  white-space: nowrap;
}

.products-table tbody tr:hover {
  background: hsl(220, 20%, 98%);
}

.product-price-cell {
  font-weight: 500;
  white-space: nowrap;
}

.btn-delete-product {
  background: hsl(0, 79%, 92%);
  color: hsl(0, 72%, 51%);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}

.btn-delete-product:hover {
  background: hsl(0, 84%, 85%);
}

.btn-edit-customer {
  background: hsl(217, 91%, 92%);
  color: hsl(221, 83%, 40%);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
  margin-right: 6px;
}

.btn-edit-customer:hover {
  background: hsl(217, 88%, 86%);
}

.customer-actions-cell {
  white-space: nowrap;
}

/* Validation error styling */
.field-error {
  display: inline-block;
  margin-left: 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(0, 72%, 51%);
}

.empty-msg {
  text-align: center;
  color: hsl(220, 9%, 60%);
  font-size: 0.875rem;
  padding: 20px 0;
  margin: 0;
}

/* ============================================================
   Autocomplete Suggestion Dropdown
   ============================================================ */

.suggestion-wrapper {
  position: relative;
}

.suggestion-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  background: #fff;
  border: 1px solid hsl(221, 83%, 53%);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
}

.suggestion-dropdown.visible {
  display: block;
}

.suggestion-dropdown li {
  padding: 10px 12px;
  font-size: 0.875rem;
  color: hsl(220, 20%, 14%);
  cursor: pointer;
  transition: background 0.1s ease;
}

.suggestion-dropdown li:hover,
.suggestion-dropdown li.highlighted {
  background: hsl(221, 90%, 96%);
  color: hsl(221, 83%, 40%);
}

.suggestion-dropdown li .suggestion-label {
  font-size: 0.75rem;
  color: hsl(220, 9%, 55%);
  display: block;
}

/* ============================================================
   Product Selector in Invoice Form
   ============================================================ */

.product-selector-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.product-selector {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #1a1a2e;
  cursor: pointer;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.product-selector:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.product-selector option.placeholder-option {
  color: hsl(220, 9%, 60%);
}

/* ============================================================
   CSV Product Import
   ============================================================ */

.csv-format-hint {
  font-size: 0.8125rem;
  color: hsl(220, 9%, 46%);
  margin: 0 0 12px 0;
}

.csv-format-hint strong {
  font-weight: 600;
  color: hsl(220, 20%, 14%);
}

.csv-import-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.csv-upload-btn {
  cursor: pointer;
  flex-shrink: 0;
}

.csv-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.csv-file-name {
  font-size: 0.8125rem;
  color: hsl(220, 9%, 55%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.csv-template-link {
  font-size: 0.8125rem;
  color: hsl(220, 60%, 45%);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.csv-template-link:hover {
  color: hsl(220, 60%, 35%);
}

/* ============================================================
   Privacy Footer
   ============================================================ */

.privacy-footer {
  max-width: 1200px;
  margin: 40px auto 0 auto;
  padding: 16px 16px;
  border-top: 1px solid hsl(220, 13%, 91%);
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.privacy-footer p {
  margin: 0 auto;
  font-size: 0.75rem;
  color: hsl(220, 9%, 55%);
  line-height: 1.6;
  max-width: 720px;
  font-family: inherit;
}

.privacy-footer a {
  color: hsl(220, 60%, 45%);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.privacy-footer a:hover {
  color: hsl(220, 60%, 35%);
}

/* ============================================================
   Print Styles
   ============================================================ */

@media print {
  .ad-container {
    display: none !important;
  }
}
