/* ==========================================================================
   xInvoice Premium Design System & Stylesheet
   ========================================================================== */

/* --- CSS Variables & Theme Definitions --- */
:root {
  /* Default Theme: Indigo */
  --theme-primary: hsl(238, 83%, 64%);
  --theme-primary-hover: hsl(238, 83%, 58%);
  --theme-primary-rgb: 99, 102, 241;
  --theme-accent-tint: rgba(99, 102, 241, 0.08);

  /* Paper Preview (Light Theme Inside A4 Template - Always Pristine Light Paper) */
  --paper-bg: #ffffff;
  --paper-text: #1f2937;
  --paper-text-muted: #4b5563;
  --paper-text-light: #9ca3af;
  --paper-border: #e5e7eb;
  --paper-zebra: #f9fafb;

  /* Global Settings */
  --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-glow: 0 0 20px rgba(var(--theme-primary-rgb), 0.2);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Dark Mode Variables (Default) --- */
body, body.mode-dark {
  --app-bg: radial-gradient(circle at 10% 20%, hsl(220, 30%, 12%) 0%, hsl(224, 35%, 8%) 90%);
  --panel-bg: rgba(22, 28, 45, 0.75);
  --input-bg: rgba(13, 17, 28, 0.55);
  --input-border: rgba(255, 255, 255, 0.08);
  --input-focus-border: var(--theme-primary);
  --input-focus-bg: rgba(13, 17, 28, 0.85);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border-light: rgba(255, 255, 255, 0.06);
  --placeholder-color: rgba(255, 255, 255, 0.25);
  --item-row-bg: rgba(13, 17, 28, 0.3);
  --select-option-bg: hsl(224, 35%, 10%);
  --btn-hover-bg: rgba(255, 255, 255, 0.08);
  --btn-hover-border: rgba(255, 255, 255, 0.2);
  --scrollbar-thumb: rgba(255, 255, 255, 0.15);
}

/* --- Day / Light Mode Variables --- */
body.mode-light {
  --app-bg: radial-gradient(circle at 10% 20%, hsl(210, 30%, 96%) 0%, hsl(210, 25%, 90%) 90%);
  --panel-bg: rgba(255, 255, 255, 0.85);
  --input-bg: rgba(243, 244, 246, 0.85);
  --input-border: rgba(0, 0, 0, 0.12);
  --input-focus-border: var(--theme-primary);
  --input-focus-bg: rgba(255, 255, 255, 0.95);
  --text-main: hsl(224, 35%, 12%);
  --text-muted: hsl(224, 20%, 45%);
  --border-light: rgba(0, 0, 0, 0.08);
  --placeholder-color: rgba(0, 0, 0, 0.35);
  --item-row-bg: rgba(0, 0, 0, 0.03);
  --select-option-bg: #ffffff;
  --btn-hover-bg: rgba(0, 0, 0, 0.04);
  --btn-hover-border: rgba(0, 0, 0, 0.15);
  --scrollbar-thumb: rgba(0, 0, 0, 0.15);
}

/* Theme Classes dynamically set on body */
body.theme-indigo {
  --theme-primary: hsl(238, 83%, 64%);
  --theme-primary-hover: hsl(238, 83%, 58%);
  --theme-primary-rgb: 99, 102, 241;
  --theme-accent-tint: rgba(99, 102, 241, 0.08);
}
body.theme-emerald {
  --theme-primary: hsl(162, 76%, 41%);
  --theme-primary-hover: hsl(162, 76%, 35%);
  --theme-primary-rgb: 16, 185, 129;
  --theme-accent-tint: rgba(16, 185, 129, 0.08);
}
body.theme-violet {
  --theme-primary: hsl(271, 91%, 65%);
  --theme-primary-hover: hsl(271, 91%, 59%);
  --theme-primary-rgb: 139, 92, 246;
  --theme-accent-tint: rgba(139, 92, 246, 0.08);
}
body.theme-amber {
  --theme-primary: hsl(38, 92%, 50%);
  --theme-primary-hover: hsl(38, 92%, 44%);
  --theme-primary-rgb: 245, 158, 11;
  --theme-accent-tint: rgba(245, 158, 11, 0.08);
}
body.theme-rose {
  --theme-primary: hsl(343, 90%, 60%);
  --theme-primary-hover: hsl(343, 90%, 54%);
  --theme-primary-rgb: 244, 63, 94;
  --theme-accent-tint: rgba(244, 63, 94, 0.08);
}

/* --- Base Styles --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  background: var(--app-bg);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

/* --- App Shell Layout --- */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
}

/* --- Top Header Navigation --- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  background: var(--theme-primary);
  color: #fff;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  box-shadow: var(--shadow-glow);
}
.brand-icon svg {
  width: 24px;
  height: 24px;
}

.brand-text h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-main);
  line-height: 1.1;
}

.brand-text .sub-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.control-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 0.75rem;
}

.theme-picker-wrapper, .lang-switch-container, .mode-switch-container {
  display: flex;
  align-items: center;
}

/* Mode Switcher Toggle Button */
.btn-mode-toggle {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text-main);
  padding: 0.5rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  width: 36px;
  height: 36px;
}

.btn-mode-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: scale(1.05);
}

body.mode-light .btn-mode-toggle:hover {
  background: rgba(0, 0, 0, 0.04);
}

.btn-mode-toggle svg {
  width: 18px;
  height: 18px;
  transition: var(--transition-smooth);
}

/* Hide/Show Mode Icons */
body.mode-dark .btn-mode-toggle .icon-moon {
  display: none;
}
body.mode-dark .btn-mode-toggle .icon-sun {
  display: block;
  color: hsl(38, 92%, 50%);
}

body.mode-light .btn-mode-toggle .icon-sun {
  display: none;
}
body.mode-light .btn-mode-toggle .icon-moon {
  display: block;
  color: hsl(238, 83%, 64%);
}

/* Theme Dot Button Pickers */
.theme-picker {
  display: flex;
  gap: 0.5rem;
}

.theme-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-smooth);
  position: relative;
}
.theme-dot:hover {
  transform: scale(1.2);
}
.theme-dot.active {
  border-color: #fff;
  box-shadow: 0 0 8px currentColor;
}
.theme-dot.indigo { background-color: hsl(238, 83%, 64%); color: hsl(238, 83%, 64%); }
.theme-dot.emerald { background-color: hsl(162, 76%, 41%); color: hsl(162, 76%, 41%); }
.theme-dot.violet { background-color: hsl(271, 91%, 65%); color: hsl(271, 91%, 65%); }
.theme-dot.amber { background-color: hsl(38, 92%, 50%); color: hsl(38, 92%, 50%); }
.theme-dot.rose { background-color: hsl(343, 90%, 60%); color: hsl(343, 90%, 60%); }

/* Premium Slanted Language Switcher */
.lang-toggle {
  display: flex;
  position: relative;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  padding: 3px;
  border-radius: 20px;
  cursor: pointer;
  width: 80px;
  user-select: none;
}

.lang-option {
  flex: 1;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 0;
  z-index: 2;
  color: var(--text-muted);
  transition: var(--transition-smooth);
}
.lang-option.active {
  color: #fff;
}

.toggle-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 36px;
  height: calc(100% - 6px);
  background: var(--theme-primary);
  border-radius: 17px;
  z-index: 1;
  transition: var(--transition-smooth);
  box-shadow: var(--shadow-glow);
}
.lang-toggle.fr-active .toggle-slider {
  left: 39px;
}

/* --- Workspace Grid Structure --- */
.workspace {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* --- Left Column: Editor Config Panel --- */
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding-right: 4px;
}

/* Custom Scrollbar for Editor */
.editor-panel::-webkit-scrollbar {
  width: 6px;
}
.editor-panel::-webkit-scrollbar-track {
  background: transparent;
}
.editor-panel::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
}
.editor-panel::-webkit-scrollbar-thumb:hover {
  background: var(--theme-primary);
}

/* --- Accordions --- */
.accordion-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.accordion-item {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition-smooth);
}
.accordion-item:hover {
  border-color: rgba(255, 255, 255, 0.12);
}
.accordion-item.active {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.accordion-trigger {
  width: 100%;
  padding: 1.1rem 1.25rem;
  background: transparent;
  border: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  text-align: left;
  color: var(--text-main);
  transition: var(--transition-smooth);
}

.trigger-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.2px;
}
.trigger-title svg.icon {
  width: 18px;
  height: 18px;
  color: var(--theme-primary);
  transition: var(--transition-smooth);
}

.accordion-trigger svg.chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform 0.3s ease;
}

.accordion-item.active .accordion-trigger svg.chevron {
  transform: rotate(180deg);
  color: var(--text-main);
}

/* Accordion Expand/Collapse Content Box */
.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0 1.25rem;
}

.accordion-item.active .accordion-content {
  max-height: 800px; /* high limit to allow smooth expanding auto */
  padding-bottom: 1.25rem;
  overflow-y: visible;
}

/* --- Form Fields & Grid Layout --- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group.full-width {
  grid-column: span 2;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea,
.form-group select {
  font-family: var(--font-family);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  color: var(--text-main);
  font-size: 0.85rem;
  transition: var(--transition-smooth);
  width: 100%;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--placeholder-color);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--input-focus-border);
  background: var(--input-focus-bg);
  box-shadow: 0 0 0 3px rgba(var(--theme-primary-rgb), 0.2);
}

.form-group select option {
  background: var(--select-option-bg);
  color: var(--text-main);
}

.form-group textarea {
  resize: vertical;
}

/* --- Company Logo Drag/Drop Area --- */
.logo-uploader {
  margin-bottom: 0.5rem;
}

.logo-dropzone {
  border: 2px dashed var(--input-border);
  background: var(--input-bg);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: var(--transition-smooth);
}
.logo-dropzone:hover {
  border-color: var(--theme-primary);
  background: rgba(var(--theme-primary-rgb), 0.03);
}

.logo-dropzone input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dropzone-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}

.icon-cloud {
  width: 32px;
  height: 32px;
  color: var(--theme-primary);
}

.dropzone-placeholder p {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-main);
}

.dropzone-placeholder .file-limits {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Image preview in uploader */
.dropzone-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto;
  border-radius: var(--radius-md);
  background: #fff;
  padding: 4px;
  border: 1px solid var(--border-light);
}

.dropzone-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: calc(var(--radius-md) - 4px);
}

.btn-remove-logo {
  position: absolute;
  top: -8px;
  right: -8px;
  background: hsl(343, 90%, 60%);
  color: #fff;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  transition: var(--transition-smooth);
  z-index: 10;
}
.btn-remove-logo:hover {
  background: hsl(343, 90%, 50%);
  transform: scale(1.1);
}
.btn-remove-logo svg {
  width: 12px;
  height: 12px;
}

.hidden {
  display: none !important;
}

/* --- Dynamic Items Form Builder --- */
.items-builder {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.item-row-edit {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--item-row-bg);
  border: 1px solid var(--border-light);
  padding: 0.8rem;
  border-radius: var(--radius-md);
  position: relative;
  animation: slideIn 0.25s ease-out;
}

.item-row-edit .input-desc {
  width: 100%;
  resize: vertical;
  min-height: 48px;
}

.item-row-edit .btn-delete-row {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 50%;
  transition: var(--transition-smooth);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-row-edit .btn-delete-row:hover {
  color: hsl(343, 90%, 60%);
  background: rgba(244, 63, 94, 0.1);
}

.item-row-edit .inputs-details-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1.2fr 0.9fr 0.9fr;
  gap: 0.5rem;
  width: 100%;
}

.input-subgroup {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.input-subgroup label {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.btn-delete-row {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: var(--transition-smooth);
}
.btn-delete-row:hover {
  color: hsl(343, 90%, 60%);
  background: rgba(244, 63, 94, 0.1);
}
.btn-delete-row svg {
  width: 16px;
  height: 16px;
}

/* Button stylings */
button.btn-secondary {
  width: 100%;
  background: var(--theme-accent-tint);
  border: 1px dashed var(--theme-primary);
  color: var(--theme-primary);
  border-radius: var(--radius-sm);
  padding: 0.65rem;
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: var(--transition-smooth);
}
button.btn-secondary:hover {
  background: var(--theme-primary);
  color: #fff;
  box-shadow: var(--shadow-glow);
}
button.btn-secondary .btn-icon {
  width: 16px;
  height: 16px;
}

/* Actions footer */
.panel-actions {
  display: flex;
  justify-content: flex-end;
}

button.btn-danger {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.2);
  color: hsl(343, 90%, 65%);
  padding: 0.65rem 1rem;
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition-smooth);
}
button.btn-danger:hover {
  background: hsl(343, 90%, 60%);
  color: #fff;
}

.btn-icon {
  width: 14px;
  height: 14px;
}

/* --- Right Column: Preview Area Panel --- */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Preview Bar Controller */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.toolbar-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.preview-badge {
  background: rgba(16, 185, 129, 0.15);
  color: hsl(162, 76%, 50%);
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.toolbar-buttons {
  display: flex;
  gap: 0.75rem;
}

.btn-action {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: var(--transition-smooth);
}
.btn-action:hover {
  background: var(--btn-hover-bg);
  border-color: var(--btn-hover-border);
}

.btn-action.primary {
  background: var(--theme-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.btn-action.primary:hover {
  background: var(--theme-primary-hover);
  transform: translateY(-1px);
}

/* --- Realistic A4 Paper Sheet Preview --- */
.paper-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-bottom: 2rem;
}

.a4-sheet {
  background: var(--paper-bg);
  color: var(--paper-text);
  width: 210mm;
  min-height: 297mm;
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.invoice-accent-bar {
  height: 6px;
  background: var(--theme-primary);
  width: 100%;
}

.invoice-inner {
  padding: 15mm;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

/* Invoice Header */
.row-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8mm;
}

.company-brand-section {
  display: flex;
  gap: 5mm;
  align-items: center;
  max-width: 65%;
}

.invoice-logo-container {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}
.invoice-logo-container img {
  max-width: 60px;
  max-height: 60px;
  object-fit: contain;
}

.invoice-default-logo svg {
  color: var(--theme-primary);
}

.company-meta-details h2 {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--paper-text);
  letter-spacing: -0.3px;
  margin-bottom: 1mm;
}
.company-meta-details p {
  font-size: 0.75rem;
  color: var(--paper-text-muted);
  line-height: 1.4;
}

.document-title-section {
  text-align: right;
}

.invoice-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--paper-text);
  margin-bottom: 1.5mm;
}

.invoice-number-badge {
  display: inline-block;
  background: var(--theme-accent-tint);
  border: 1px solid rgba(var(--theme-primary-rgb), 0.15);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--theme-primary);
}

hr.separator {
  border: none;
  height: 1px;
  background: var(--paper-border);
  margin-bottom: 6mm;
}

/* Bill To & Metadata Details */
.row-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10mm;
  margin-bottom: 8mm;
}

.meta-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--paper-text-light);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 1.5mm;
}

.bill-to-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--paper-text);
  margin-bottom: 1mm;
}
.bill-to-section p {
  font-size: 0.75rem;
  color: var(--paper-text-muted);
  line-height: 1.4;
}

.invoice-dates-section {
  display: flex;
  flex-direction: column;
  gap: 1.5mm;
  justify-content: flex-start;
  align-items: flex-end;
}

.date-row {
  display: flex;
  justify-content: flex-end;
  gap: 2mm;
  font-size: 0.75rem;
  width: 100%;
}
.date-row .meta-label {
  margin-bottom: 0;
  text-align: right;
}
.date-row .meta-value {
  font-weight: 500;
  color: var(--paper-text);
  text-align: right;
  min-width: 80px;
}
.date-row .due-date-highlight {
  font-weight: 700;
  color: var(--theme-primary);
}

/* Items Table */
.table-container {
  margin-bottom: 8mm;
  flex-grow: 1;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.invoice-table th {
  padding: 3.5mm 4mm;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--paper-text-muted);
  border-bottom: 2px solid var(--theme-primary);
}

.invoice-table td {
  padding: 4mm 4mm;
  font-size: 0.75rem;
  color: var(--paper-text);
  border-bottom: 1px solid var(--paper-border);
  line-height: 1.4;
  vertical-align: middle;
}

.invoice-table tr:nth-child(even) td {
  background: var(--paper-zebra);
}

.col-ref { width: 12%; }
.col-desc { width: 32%; }
.col-qty { width: 8%; text-align: center; }
.col-price { width: 14%; text-align: right; }
.col-discount { width: 10%; text-align: center; }
.col-vat { width: 10%; text-align: center; }
.col-amount { width: 14%; text-align: right; font-weight: 600; }

.invoice-table th.col-qty, .invoice-table td.col-qty { text-align: center; }
.invoice-table th.col-price, .invoice-table td.col-price { text-align: right; }
.invoice-table th.col-discount, .invoice-table td.col-discount { text-align: center; }
.invoice-table th.col-vat, .invoice-table td.col-vat { text-align: center; }
.invoice-table th.col-amount, .invoice-table td.col-amount { text-align: right; }

/* Financial Breakdowns & Payment Instructions */
.row-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10mm;
  margin-top: auto; /* Push to bottom of content area */
  border-top: 1px solid var(--paper-border);
  padding-top: 5mm;
  margin-bottom: 6mm;
}

.payment-notes-section .notes-content {
  font-size: 0.7rem;
  line-height: 1.5;
  color: var(--paper-text-muted);
  white-space: pre-wrap;
}

.financials-breakdown {
  display: flex;
  flex-direction: column;
  gap: 2mm;
  justify-content: flex-start;
}

.financial-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--paper-text-muted);
}
.financial-row .amount-val {
  font-weight: 500;
  color: var(--paper-text);
  text-align: right;
}

.financial-row .discount-val {
  color: hsl(343, 90%, 55%);
}

.summary-divider {
  border: none;
  height: 1px;
  background: var(--paper-border);
  margin: 1mm 0;
}

.financial-row.total-row {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--paper-text);
}
.financial-row .grand-total {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--theme-primary);
}

/* Invoice Footer area */
.invoice-footer {
  text-align: center;
  border-top: 1px solid var(--paper-border);
  padding-top: 5mm;
  margin-top: auto;
}

.thank-you-msg {
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 600;
  color: var(--paper-text-muted);
  margin-bottom: 3mm;
}

.invoice-footer-details {
  font-size: 0.6rem;
  color: var(--paper-text-light);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ==========================================================================
   Responsive & Adaptive Grid Breakpoints
   ========================================================================== */
@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: 1fr; /* Stack panels */
  }
  
  .editor-panel {
    max-height: none; /* Let content expand naturally */
  }

  .preview-panel {
    height: auto;
    overflow-y: visible;
  }
  
  .paper-container {
    overflow-x: auto; /* Enable horizontal scrolling for A4 on small widths */
    justify-content: flex-start;
  }
  
  .a4-sheet {
    margin: 0 auto;
    /* keep full A4 width but scaling handled by layout scroll */
  }
}

@media (max-width: 600px) {
  .app-container {
    padding: 0.75rem;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
  }
  
  .header-controls {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1rem;
    width: 100%;
    justify-content: space-between;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .form-group.full-width {
    grid-column: span 1;
  }
  
  .item-row-edit {
    grid-template-columns: 1fr 50px 70px 30px;
  }
}


/* ==========================================================================
   Print Stylesheet Configuration
   ========================================================================== */
@media print {
  /* Hide all app shell elements */
  body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .app-container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    display: block !important;
  }

  .app-header,
  .editor-panel,
  .preview-panel .toolbar,
  .btn-remove-logo {
    display: none !important;
  }

  .workspace {
    display: block !important;
    gap: 0 !important;
  }

  .preview-panel {
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }

  .paper-container {
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }

  .a4-sheet {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100% !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
  }
  
  .invoice-inner {
    padding: 10mm !important; /* Smaller margins for actual printed paper */
  }

  /* Force background colors/images to print correctly */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Avoid page breaks inside layout segments */
  .row-header, .row-meta, .table-container, .row-summary, .invoice-footer {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}
