/* ==========================================================================
   INVOICEFLOW — INVOICE GENERATOR STYLES (invoice.css)
   Dual-panel layout, editor controls, dynamic items table, and A4 paper preview.
   Updated for Part 2: Complete Functionality (Calculations, Storage, PDF, Validation)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Generator Workspace Layout
   -------------------------------------------------------------------------- */
.generator-workspace {
  padding-top: var(--space-6);
  padding-bottom: var(--space-16);
  background-color: var(--color-slate-50);
}

/* Draft Restore Alert Banner */
.draft-restore-banner {
  background-color: var(--color-primary-50);
  border: 1px solid var(--color-primary-200);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  margin-bottom: var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  box-shadow: var(--shadow-xs);
}

.draft-banner-content {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 0.875rem;
  color: var(--color-primary-900);
}

.draft-banner-icon {
  color: var(--color-primary-600);
  flex-shrink: 0;
}

.draft-banner-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Generator Toolbar */
.generator-toolbar {
  background-color: var(--color-white);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  box-shadow: var(--shadow-xs);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.8125rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate-600);
}

.select-control {
  appearance: none;
  background-color: var(--color-white);
  border: 1px solid var(--color-slate-300);
  border-radius: var(--radius-md);
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-slate-800);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 14px;
}

.select-control:focus {
  border-color: var(--color-primary-600);
  box-shadow: 0 0 0 3px var(--color-primary-100);
  outline: none;
}

/* Mobile View Mode Switcher (Hidden on Desktop) */
.mobile-view-tabs {
  display: none;
  background-color: var(--color-slate-200);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: var(--space-4);
  width: 100%;
}

.mobile-tab-btn {
  flex: 1;
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate-600);
  border-radius: var(--radius-sm);
  text-align: center;
  transition: all var(--transition-fast);
}

.mobile-tab-btn.active {
  background-color: var(--color-white);
  color: var(--color-slate-900);
  box-shadow: var(--shadow-xs);
}

/* Split Pane Workspace Grid */
.workspace-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: var(--space-8);
  align-items: flex-start;
}

/* --------------------------------------------------------------------------
   2. Left Pane: Invoice Editor Form
   -------------------------------------------------------------------------- */
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.editor-card {
  background-color: var(--color-white);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-xs);
}

.editor-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-slate-100);
}

.editor-card-title {
  font-size: 1.0625rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-slate-900);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.editor-card-title svg {
  color: var(--color-primary-600);
}

.editor-card-subtitle {
  font-size: 0.8125rem;
  color: var(--color-slate-500);
  font-weight: 400;
  margin-top: calc(-1 * var(--space-3));
  margin-bottom: var(--space-4);
  line-height: 1.45;
}

/* Helper text below input */
.form-helper-text {
  display: block;
  font-size: 0.75rem;
  color: var(--color-slate-500);
  font-weight: 400;
  line-height: 1.35;
  margin-top: 0.25rem;
}

/* Form Input & Textarea Placeholder Styling */
.form-input::placeholder,
.form-textarea::placeholder,
.items-table input::placeholder {
  color: var(--color-slate-400);
  font-weight: 400;
  opacity: 1;
}

/* Form Controls & Grid */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-4);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: var(--space-4);
  position: relative;
}

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

.form-label {
  font-size: 0.8125rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate-700);
}

.form-input,
.form-textarea {
  width: 100%;
  padding: 0.5625rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-slate-900);
  background-color: var(--color-white);
  border: 1px solid var(--color-slate-300);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--color-primary-600);
  box-shadow: 0 0 0 3px var(--color-primary-100);
  outline: none;
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}

#inputDiscountValue,
#inputTaxRate {
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

#inputDiscountValue::-webkit-inner-spin-button,
#inputDiscountValue::-webkit-outer-spin-button,
#inputTaxRate::-webkit-inner-spin-button,
#inputTaxRate::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Selection Highlight for Inputs & Textareas */
.items-table input::selection,
.form-input::selection,
.form-textarea::selection {
  background-color: var(--color-primary-200, #bfdbfe);
  color: var(--color-slate-900, #0f172a);
}

/* Validation Error UI */
.form-group.has-error .form-input,
.form-group.has-error .form-textarea {
  border-color: var(--color-danger-600);
  background-color: var(--color-danger-50);
}

.field-error {
  font-size: 0.75rem;
  color: var(--color-danger-600);
  font-weight: var(--font-weight-medium);
  margin-top: 2px;
}

/* Logo Upload Dropzone */
.logo-upload-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1.5px dashed var(--color-slate-300);
  border-radius: var(--radius-md);
  background-color: var(--color-slate-50);
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-bottom: var(--space-4);
}

.logo-upload-box:hover {
  border-color: var(--color-primary-500);
  background-color: var(--color-primary-50);
}

.logo-left-details {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-preview-thumb {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background-color: var(--color-slate-200);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--color-slate-400);
  flex-shrink: 0;
}

.logo-preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-upload-text {
  font-size: 0.8125rem;
  color: var(--color-slate-600);
}

.logo-upload-text strong {
  color: var(--color-primary-600);
}

.btn-remove-logo {
  font-size: 0.75rem;
  color: var(--color-danger-600);
  background: var(--color-white);
  border: 1px solid var(--color-slate-300);
  padding: 0.3125rem 0.625rem;
  border-radius: var(--radius-sm);
  font-weight: var(--font-weight-medium);
}

.btn-remove-logo:hover {
  background-color: var(--color-danger-50);
  border-color: var(--color-danger-600);
}

/* Line Items Editor Table */
.items-table-container {
  overflow-x: auto;
  margin-bottom: var(--space-4);
  -webkit-overflow-scrolling: touch;
}

.items-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

.items-table th {
  font-size: 0.75rem;
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-slate-500);
  padding: var(--space-2) var(--space-2);
  border-bottom: 2px solid var(--color-slate-200);
  white-space: nowrap;
}

.items-table th.col-desc { text-align: left; }
.items-table th.col-qty { text-align: center; }
.items-table th.col-rate { text-align: right; }
.items-table th.col-tax { text-align: center; }
.items-table th.col-discount { text-align: center; }
.items-table th.col-amount { text-align: right; }
.items-table th.col-actions { text-align: center; }

.items-table td {
  padding: 0.375rem var(--space-2);
  vertical-align: middle;
}

.items-table .col-desc { width: 34%; min-width: 180px; }
.items-table .col-qty { width: 10%; min-width: 64px; text-align: center; }
.items-table .col-rate { width: 18%; min-width: 115px; text-align: right; }
.items-table .col-tax { width: 10%; min-width: 64px; text-align: center; }
.items-table .col-discount { width: 10%; min-width: 64px; text-align: center; }
.items-table .col-amount { width: 14%; min-width: 120px; text-align: right; }
.items-table .col-actions { width: 4%; min-width: 38px; text-align: center; }

/* Table Inputs — Optimized for Full Digit Visibility */
.items-table .form-input {
  box-sizing: border-box;
  width: 100%;
  padding: 0.5rem 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-sm);
}

.items-table .item-desc-input {
  text-align: left;
}

.items-table .item-qty-input {
  text-align: center;
  padding: 0.5rem 0.25rem;
}

.items-table .item-rate-input {
  text-align: right;
  padding: 0.5rem 0.5rem;
}

.items-table .item-tax-input,
.items-table .item-disc-input {
  text-align: center;
  padding: 0.5rem 0.25rem;
}

/* Remove Stepper Spinners so Digits Are Never Blocked or Clipped */
.items-table input[type=number]::-webkit-inner-spin-button,
.items-table input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.items-table input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.item-amount-display {
  padding: 0.5rem 0.25rem;
  font-size: 0.9375rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate-900);
  text-align: right;
  display: block;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.item-mobile-label {
  display: none;
}

.btn-remove-item {
  padding: 0.5rem;
  color: var(--color-slate-400);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.btn-remove-item:hover {
  color: var(--color-danger-600);
  background-color: var(--color-danger-50);
}

.btn-add-item {
  width: 100%;
  border: 1.5px dashed var(--color-primary-300);
  color: var(--color-primary-700);
  background-color: var(--color-primary-50);
  padding: 0.625rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: var(--font-weight-semibold);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: all var(--transition-fast);
}

.btn-add-item:hover {
  background-color: var(--color-primary-100);
  border-color: var(--color-primary-500);
}

/* Empty State Message */
.items-empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  background-color: var(--color-slate-50);
  border: 1px dashed var(--color-slate-300);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  color: var(--color-slate-600);
  font-size: 0.875rem;
}

/* --------------------------------------------------------------------------
   3. Right Pane: Live A4 Invoice Preview
   -------------------------------------------------------------------------- */
.preview-panel {
  position: sticky;
  top: calc(var(--header-height) + var(--space-4));
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.preview-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 var(--space-1);
  flex-wrap: wrap;
}

.preview-title-tag {
  font-size: 0.8125rem;
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-slate-500);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.preview-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-success-600);
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);
}

/* Zoom Controls Toolbar */
.zoom-toolbar {
  display: inline-flex;
  align-items: center;
  background-color: var(--color-white);
  border: 1px solid var(--color-slate-300);
  border-radius: var(--radius-md);
  padding: 2px 4px;
  box-shadow: var(--shadow-xs);
  gap: 2px;
}

.btn-zoom {
  background: transparent;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-slate-600);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-zoom:hover {
  background-color: var(--color-slate-100);
  color: var(--color-slate-900);
}

.btn-zoom:active {
  background-color: var(--color-slate-200);
}

.btn-zoom-reset {
  background: transparent;
  border: none;
  font-size: 0.75rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate-700);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-width: 44px;
  text-align: center;
  transition: all 0.15s ease;
}

.btn-zoom-reset:hover {
  background-color: var(--color-slate-100);
  color: var(--color-primary-600);
}

/* Preview Action Group */
.preview-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* High Fidelity A4 Document Container */
.preview-viewport {
  background-color: var(--color-slate-200);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  overflow: auto;
  display: flex;
  justify-content: center;
  min-height: 880px;
}

.invoice-paper {
  --invoice-accent: var(--color-primary-600);
  --invoice-accent-light: rgba(37, 99, 235, 0.08);
  font-family: var(--invoice-font, var(--font-sans));
  background-color: var(--color-white);
  width: 100%;
  max-width: 680px;
  min-height: 860px;
  padding: 48px;
  box-shadow: var(--shadow-paper);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  position: relative;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-slate-800);
  box-sizing: border-box;
  transform-origin: top center;
  transition: transform 0.15s ease-out;
}

/* Invoice Paper Header */
.invoice-paper-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: 2px solid var(--color-slate-100);
}

.paper-company-meta {
  max-width: 320px;
}

.paper-logo-container {
  max-width: 150px;
  max-height: 65px;
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
}

.paper-logo-container img {
  max-height: 65px;
  max-width: 100%;
  width: auto;
  object-fit: contain;
}

.paper-company-name {
  font-size: 1.375rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-slate-900);
  line-height: 1.2;
  margin-bottom: var(--space-1);
}

.paper-tax-id {
  font-size: 0.75rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate-500);
  margin-bottom: var(--space-1);
}

.paper-company-details {
  font-size: 0.8125rem;
  color: var(--color-slate-600);
  line-height: 1.5;
  white-space: pre-line;
}

.paper-invoice-meta {
  text-align: right;
}

.paper-invoice-title {
  font-size: 2rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-600);
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: var(--space-3);
}

.paper-meta-table {
  font-size: 0.8125rem;
  margin-left: auto;
}

.paper-meta-table td {
  padding: 3px 0;
}

.paper-meta-label {
  color: var(--color-slate-500);
  padding-right: var(--space-3);
  font-weight: var(--font-weight-medium);
}

.paper-meta-value {
  color: var(--color-slate-900);
  font-weight: var(--font-weight-semibold);
}

/* Bill To & Details Grid */
.paper-parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.paper-section-label {
  font-size: 0.6875rem;
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-slate-400);
  margin-bottom: var(--space-2);
}

.paper-client-name {
  font-size: 1.0625rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-slate-900);
  margin-bottom: 2px;
}

.paper-client-details {
  font-size: 0.8125rem;
  color: var(--color-slate-600);
  line-height: 1.5;
  white-space: pre-line;
}

/* Preview Items Table */
.paper-items-table {
  width: 100%;
  margin-bottom: var(--space-8);
  border-collapse: collapse;
}

.paper-items-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-slate-500);
  padding: var(--space-3) var(--space-2);
  border-bottom: 2px solid var(--color-slate-200);
  white-space: nowrap;
}

.paper-items-table th.paper-col-desc { text-align: left; }
.paper-items-table th.paper-col-qty { text-align: center; }
.paper-items-table th.paper-col-rate { text-align: right; }
.paper-items-table th.paper-col-amount { text-align: right; }

.paper-items-table td {
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--color-slate-100);
  font-size: 0.875rem;
  vertical-align: top;
}

.paper-items-table .paper-item-qty {
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.paper-items-table .paper-item-rate,
.paper-items-table .paper-item-amount {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.paper-item-desc {
  font-weight: var(--font-weight-medium);
  color: var(--color-slate-900);
}

/* Totals Area */
.paper-totals-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-8);
}

.paper-totals-box {
  width: 290px;
  min-width: 260px;
}

.paper-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-1) 0;
  font-size: 0.875rem;
  color: var(--color-slate-600);
}

.paper-total-row span:last-child {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.paper-total-row.grand-total {
  font-size: 1.1875rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-slate-900);
  border-top: 2px solid var(--color-slate-200);
  padding-top: var(--space-3);
  margin-top: var(--space-2);
}

.paper-total-row.grand-total .value {
  color: var(--color-primary-600);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Payment Info Section in Preview */
.paper-payment-box {
  background-color: var(--color-slate-50);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
}

.paper-payment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2) var(--space-6);
  font-size: 0.8125rem;
  color: var(--color-slate-700);
}

/* Notes & Payment Terms */
.paper-footer-notes {
  margin-top: auto;
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-slate-200);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  font-size: 0.75rem;
  color: var(--color-slate-500);
  line-height: 1.5;
}

.paper-note-title {
  font-weight: var(--font-weight-bold);
  color: var(--color-slate-700);
  margin-bottom: 4px;
}

/* --------------------------------------------------------------------------
   4. Design & Customization Panel UI Styles
   -------------------------------------------------------------------------- */
.design-customization-card {
  border-left: 4px solid var(--color-primary-600);
}

.template-selection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
  gap: var(--space-3);
}

.template-choice-card {
  background-color: var(--color-white);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  user-select: none;
  position: relative;
}

.template-choice-card:hover {
  border-color: var(--color-primary-400);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.template-choice-card.is-selected {
  border-color: var(--color-primary-600);
  background-color: var(--color-primary-50);
  box-shadow: 0 0 0 2px var(--color-primary-500);
}

.template-choice-card:focus-visible {
  outline: 2px solid var(--color-primary-600);
  outline-offset: 2px;
}

/* Template Miniature Preview Cards */
.template-mini-preview {
  height: 60px;
  background-color: #ffffff;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  margin-bottom: var(--space-2);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* Modern Thumb */
.thumb-modern {
  display: flex;
}
.thumb-modern .mini-bar {
  width: 5px;
  height: 100%;
  background-color: var(--color-primary-600);
  flex-shrink: 0;
}
.thumb-modern .mini-content {
  flex: 1;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.thumb-modern .mini-title-bar {
  width: 45%;
  height: 5px;
  background-color: var(--color-primary-600);
  border-radius: 1px;
}
.thumb-modern .mini-rows span {
  display: block;
  height: 2.5px;
  background-color: var(--color-slate-200);
  margin-bottom: 2.5px;
  border-radius: 1px;
}
.thumb-modern .mini-rows span:first-child { width: 85%; }
.thumb-modern .mini-rows span:last-child { width: 65%; }
.thumb-modern .mini-badge {
  align-self: flex-end;
  width: 24px;
  height: 8px;
  background-color: var(--color-primary-100);
  border: 1px solid var(--color-primary-300);
  border-radius: 2px;
  margin-top: auto;
}

/* Classic Thumb */
.thumb-classic .mini-top-rule {
  height: 3px;
  background-color: #1e3a8a;
  width: 100%;
}
.thumb-classic .mini-content {
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.thumb-classic .mini-title-bar {
  width: 50%;
  height: 4px;
  background-color: #1e3a8a;
}
.thumb-classic .mini-box {
  width: 75%;
  height: 10px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
  border-radius: 1px;
}
.thumb-classic .mini-rows span {
  display: block;
  height: 2.5px;
  background-color: #cbd5e1;
  margin-bottom: 2px;
}
.thumb-classic .mini-rows span:first-child { width: 90%; }
.thumb-classic .mini-rows span:last-child { width: 70%; }

/* Minimal Thumb */
.thumb-minimal .mini-content {
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.thumb-minimal .mini-title-bar {
  width: 35%;
  height: 4px;
  background-color: var(--color-slate-800);
}
.thumb-minimal .mini-rows.thin span {
  display: block;
  height: 2px;
  background-color: var(--color-slate-200);
  margin-bottom: 3px;
  width: 90%;
}

/* Corporate Thumb */
.thumb-corporate .mini-banner {
  height: 16px;
  background-color: #0f172a;
  width: 100%;
  border-bottom: 2px solid var(--color-primary-600);
}
.thumb-corporate .mini-content {
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.thumb-corporate .mini-meta-strip {
  height: 5px;
  background-color: #f1f5f9;
  width: 100%;
  border-radius: 1px;
}
.thumb-corporate .mini-rows span {
  display: block;
  height: 2.5px;
  background-color: var(--color-slate-300);
  margin-bottom: 2.5px;
  width: 80%;
}

/* Elegant Thumb */
.thumb-elegant {
  background-color: #fafaf9;
}
.thumb-elegant .mini-content {
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.thumb-elegant .mini-title-bar {
  width: 45%;
  height: 4px;
  background-color: #44403c;
}
.thumb-elegant .mini-rule {
  height: 1px;
  background-color: #d6d3d1;
  width: 100%;
  margin: 1px 0;
}
.thumb-elegant .mini-rows span {
  display: block;
  height: 2px;
  background-color: #a8a29e;
  margin-bottom: 2.5px;
  width: 75%;
}

/* Template Info Labels */
.template-choice-name {
  font-size: 0.8125rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-slate-900);
  line-height: 1.2;
}

.template-choice-tagline {
  font-size: 0.6875rem;
  color: var(--color-slate-500);
  line-height: 1.2;
  margin-top: 2px;
}

.template-choice-card.is-selected .template-choice-name {
  color: var(--color-primary-800);
}

.template-choice-card.is-selected .template-choice-tagline {
  color: var(--color-primary-600);
}

/* Color Swatches Bar */
.color-palette-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  background-color: var(--color-slate-50);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.color-swatches-list {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1;
  background-color: var(--swatch-hex);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  padding: 0;
}

.color-swatch-btn:hover {
  transform: scale(1.18);
  box-shadow: 0 0 0 2px var(--color-slate-400);
}

.color-swatch-btn.is-active {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px var(--color-slate-900);
}

.custom-color-control {
  margin-left: auto;
}

.custom-color-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-slate-700);
  background-color: var(--color-white);
  border: 1px solid var(--color-slate-300);
  border-radius: var(--radius-md);
  padding: 4px 8px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.custom-color-label:hover {
  border-color: var(--color-primary-500);
}

.custom-color-label input[type="color"] {
  appearance: none;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  padding: 0;
}

.custom-color-label input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.custom-color-label input[type="color"]::-webkit-color-swatch {
  border: 1px solid #cbd5e1;
  border-radius: 50%;
}

/* Spacing Segmented Toggle */
.spacing-toggle-group {
  display: inline-flex;
  width: 100%;
  border: 1px solid var(--color-slate-300);
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: var(--color-white);
}

.spacing-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-right: 1px solid var(--color-slate-200);
  padding: 8px 12px;
  font-size: 0.8125rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-slate-600);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.spacing-btn:last-child {
  border-right: none;
}

.spacing-btn:hover {
  background-color: var(--color-slate-50);
  color: var(--color-slate-900);
}

.spacing-btn.is-active {
  background-color: var(--color-primary-600);
  color: #ffffff;
  font-weight: var(--font-weight-semibold);
}

/* --------------------------------------------------------------------------
   5. Spacing Density Layout Modes Applied to .invoice-paper
   -------------------------------------------------------------------------- */
.invoice-paper.layout-compact {
  padding: 30px;
}
.invoice-paper.layout-compact .invoice-paper-header {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
}
.invoice-paper.layout-compact .paper-parties-grid {
  margin-bottom: var(--space-5);
  gap: var(--space-4);
}
.invoice-paper.layout-compact .paper-items-table {
  margin-bottom: var(--space-5);
}
.invoice-paper.layout-compact .paper-items-table th,
.invoice-paper.layout-compact .paper-items-table td {
  padding: 6px 8px;
}
.invoice-paper.layout-compact .paper-totals-wrapper {
  margin-bottom: var(--space-5);
}
.invoice-paper.layout-compact .paper-payment-box {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
}
.invoice-paper.layout-compact .paper-footer-notes {
  padding-top: var(--space-4);
}

.invoice-paper.layout-standard {
  padding: 48px;
}

.invoice-paper.layout-spacious {
  padding: 60px;
}
.invoice-paper.layout-spacious .invoice-paper-header {
  margin-bottom: var(--space-10);
  padding-bottom: var(--space-8);
}
.invoice-paper.layout-spacious .paper-parties-grid {
  margin-bottom: var(--space-10);
  gap: var(--space-10);
}
.invoice-paper.layout-spacious .paper-items-table {
  margin-bottom: var(--space-10);
}
.invoice-paper.layout-spacious .paper-items-table th,
.invoice-paper.layout-spacious .paper-items-table td {
  padding: 12px 14px;
}
.invoice-paper.layout-spacious .paper-totals-wrapper {
  margin-bottom: var(--space-10);
}
.invoice-paper.layout-spacious .paper-payment-box {
  margin-bottom: var(--space-8);
  padding: var(--space-5) var(--space-6);
}
.invoice-paper.layout-spacious .paper-footer-notes {
  padding-top: var(--space-8);
}

/* --------------------------------------------------------------------------
   6. Five Distinct Invoice Templates Applied to .invoice-paper
   -------------------------------------------------------------------------- */

/* 1. MODERN TEMPLATE (Contemporary & Bold) */
.template-modern {
  border-left: 6px solid var(--invoice-accent, var(--color-primary-600));
}
.template-modern .paper-invoice-title {
  color: var(--invoice-accent, var(--color-primary-600));
  font-weight: 800;
  letter-spacing: -0.03em;
}
.template-modern .paper-items-table th {
  background-color: var(--invoice-accent-light, #eff6ff);
  color: var(--invoice-accent, var(--color-primary-700));
  border-bottom: 2px solid var(--invoice-accent, var(--color-primary-600));
  font-weight: 700;
}
.template-modern .paper-totals-box {
  background-color: var(--invoice-accent-light, #f8fafc);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.template-modern .paper-total-row.grand-total {
  border-top: 2px solid var(--invoice-accent, var(--color-primary-600));
}
.template-modern .paper-total-row.grand-total .value {
  color: var(--invoice-accent, var(--color-primary-600));
  font-size: 1.35rem;
}

/* 2. CLASSIC TEMPLATE (Traditional & Formal) */
.template-classic {
  border-top: 5px solid var(--invoice-accent, #1e3a8a);
  font-family: var(--invoice-font, Georgia, 'Times New Roman', serif);
}
.template-classic .paper-invoice-title {
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--invoice-accent, #1e3a8a);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 1.85rem;
}
.template-classic .paper-parties-grid {
  background-color: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  padding: var(--space-4) var(--space-5);
}
.template-classic .paper-section-label {
  color: var(--invoice-accent, #1e3a8a);
  font-weight: 800;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 3px;
  margin-bottom: var(--space-2);
}
.template-classic .paper-items-table {
  border-collapse: collapse;
}
.template-classic .paper-items-table th {
  background-color: #f1f5f9;
  border-top: 2px solid var(--invoice-accent, #1e3a8a);
  border-bottom: 2px solid var(--invoice-accent, #1e3a8a);
  color: var(--invoice-accent, #1e3a8a);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}
.template-classic .paper-items-table td {
  border-bottom: 1px solid #e2e8f0;
}
.template-classic .paper-total-row.grand-total {
  border-top: 1px solid #94a3b8;
  border-bottom: 3px double var(--invoice-accent, #1e3a8a);
  padding-bottom: var(--space-2);
  margin-top: var(--space-2);
}
.template-classic .paper-total-row.grand-total .value {
  color: var(--invoice-accent, #1e3a8a);
  font-size: 1.3rem;
}

/* 3. MINIMAL TEMPLATE (Pure & Clean) */
.template-minimal {
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.template-minimal .invoice-paper-header {
  border-bottom: 1px solid var(--color-slate-200);
}
.template-minimal .paper-invoice-title {
  color: var(--color-slate-900);
  font-weight: 300;
  font-size: 2.25rem;
  letter-spacing: -0.03em;
}
.template-minimal .paper-items-table th {
  border-bottom: 1px solid var(--color-slate-300);
  color: var(--color-slate-500);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: transparent;
}
.template-minimal .paper-items-table td {
  border-bottom: 1px solid var(--color-slate-100);
  padding: 10px 6px;
}
.template-minimal .paper-payment-box {
  background: transparent;
  border: 1px dashed var(--color-slate-300);
}
.template-minimal .paper-total-row.grand-total {
  border-top: 1px solid var(--color-slate-300);
}
.template-minimal .paper-total-row.grand-total .value {
  color: var(--invoice-accent, var(--color-slate-900));
  font-weight: 700;
}

/* 4. CORPORATE TEMPLATE (Structured & Authoritative) */
.template-corporate {
  border-top: 6px solid var(--invoice-accent, var(--color-primary-600));
}
.template-corporate .invoice-paper-header {
  background-color: #0f172a;
  border-bottom: 3px solid var(--invoice-accent, var(--color-primary-600));
  color: #ffffff;
  padding: 24px 32px;
  margin: -48px -48px 32px -48px;
  border-radius: 2px 2px 0 0;
}
.template-corporate.layout-compact .invoice-paper-header {
  margin: -30px -30px 20px -30px;
  padding: 16px 24px;
}
.template-corporate.layout-spacious .invoice-paper-header {
  margin: -60px -60px 40px -60px;
  padding: 32px 40px;
}
.template-corporate .paper-company-name {
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 800;
}
.template-corporate .paper-tax-id {
  color: #94a3b8;
}
.template-corporate .paper-company-details {
  color: #cbd5e1;
}
.template-corporate .paper-invoice-title {
  color: #ffffff;
  font-size: 2rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.template-corporate .paper-meta-label {
  color: #94a3b8;
}
.template-corporate .paper-meta-value {
  color: #ffffff;
}
.template-corporate .paper-items-table th {
  background-color: #1e293b;
  color: #ffffff;
  border-bottom: 2px solid var(--invoice-accent, var(--color-primary-600));
  padding: 10px 12px;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}
.template-corporate .paper-payment-box {
  border-left: 4px solid var(--invoice-accent, var(--color-primary-600));
  background-color: #f8fafc;
  border-radius: 2px;
}
.template-corporate .paper-total-row.grand-total {
  border-top: 2px solid #0f172a;
  border-bottom: 2px solid #0f172a;
  padding: 8px 0;
}
.template-corporate .paper-total-row.grand-total .value {
  color: var(--invoice-accent, #0f172a);
  font-weight: 800;
}

/* 5. ELEGANT TEMPLATE (Refined & Editorial) */
.template-elegant {
  background-color: #fafaf9;
  border: 1px solid #e7e5e4;
  font-family: var(--invoice-font, Georgia, 'Times New Roman', serif);
}
.template-elegant .invoice-paper-header {
  border-bottom: 1px solid #d6d3d1;
  padding-bottom: var(--space-6);
}
.template-elegant .paper-invoice-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  color: var(--invoice-accent, #44403c);
  font-weight: 600;
  font-size: 2.2rem;
  letter-spacing: 0.02em;
}
.template-elegant .paper-section-label {
  font-style: italic;
  font-family: Georgia, serif;
  text-transform: none;
  font-size: 0.8125rem;
  color: #78716c;
  border-bottom: 1px solid #e7e5e4;
  padding-bottom: 4px;
  margin-bottom: var(--space-2);
}
.template-elegant .paper-items-table th {
  border-top: 1px solid #a8a29e;
  border-bottom: 1px solid #a8a29e;
  color: #44403c;
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 0.8125rem;
  padding: 10px 8px;
  background: transparent;
}
.template-elegant .paper-items-table td {
  border-bottom: 1px solid #e7e5e4;
}
.template-elegant .paper-payment-box {
  background-color: #f5f5f4;
  border: 1px solid #e7e5e4;
  border-radius: 4px;
}
.template-elegant .paper-total-row.grand-total {
  border-top: 1px solid #a8a29e;
  border-bottom: 1px solid #a8a29e;
  padding: var(--space-2) 0;
}
.template-elegant .paper-total-row.grand-total .value {
  color: var(--invoice-accent, #292524);
  font-family: Georgia, serif;
}
.template-elegant .paper-footer-notes {
  border-top: 1px solid #e7e5e4;
  font-style: italic;
}

/* ==========================================================================
   PART 9 — ADVANCED INVOICE FEATURES & DATA ARCHITECTURE STYLES
   ========================================================================== */

/* 1. Autosave Status Indicator Badge */
.autosave-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: var(--font-weight-medium);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background-color: var(--color-slate-100);
  color: var(--color-slate-600);
  transition: all var(--transition-fast);
  user-select: none;
  border: 1px solid var(--color-slate-200);
  white-space: nowrap;
}

.autosave-status .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--color-slate-400);
  transition: background-color var(--transition-fast);
  flex-shrink: 0;
}

.autosave-status.status-saving {
  background-color: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

.autosave-status.status-saving .status-dot {
  background-color: #f59e0b;
  animation: pulse-saving 1s infinite alternate;
}

@keyframes pulse-saving {
  from { opacity: 0.4; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.2); }
}

.autosave-status.status-saved {
  background-color: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

.autosave-status.status-saved .status-dot {
  background-color: #10b981;
}

.autosave-status.status-error {
  background-color: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

.autosave-status.status-error .status-dot {
  background-color: #ef4444;
}

/* 2. Accessible Modals (Draft Recovery, PDF Fallback) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 10000;
  animation: modal-fade-in 0.2s ease-out;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background-color: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.05), 0 0 0 1px rgba(0, 0, 0, 0.05);
  width: 100%;
  max-width: 480px;
  padding: var(--space-6);
  position: relative;
  animation: modal-card-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-card-pop {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  margin-bottom: var(--space-3);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-slate-900);
  line-height: 1.3;
}

.modal-body {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--color-slate-600);
  margin-bottom: var(--space-6);
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* 3. Numbering Settings Box */
.numbering-settings-box {
  background-color: var(--color-slate-100);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-top: var(--space-2);
  animation: num-box-drop 0.15s ease-out;
}

@keyframes num-box-drop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 4. Local Data Management Card */
.btn-clear-local-data {
  transition: all var(--transition-fast);
}

.btn-clear-local-data:hover {
  background-color: #fee2e2 !important;
  color: #991b1b !important;
  border-color: #fca5a5 !important;
}

