/* CSS Design System & Variables */
:root {
  /* Common System Colors */
  --accent-color: #4f46e5;
  --accent-light: rgba(79, 70, 229, 0.15);
  --accent-hover: #4338ca;
  
  /* Transition timings */
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* Light Editor Theme */
[data-editor-theme="light"] {
  --bg-app: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-input: #f1f5f9;
  --border-color: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-sidebar: 0 4px 20px -2px rgba(15, 23, 42, 0.06);
  --shadow-paper: 0 10px 40px -10px rgba(15, 23, 42, 0.12);
  --scroll-thumb: #cbd5e1;
}

/* Dark Editor Theme (Default) */
[data-editor-theme="dark"] {
  --bg-app: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-input: #0f172a;
  --border-color: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --shadow-sidebar: 0 4px 20px -2px rgba(0, 0, 0, 0.3);
  --shadow-paper: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  --scroll-thumb: #475569;
}

/* Base resets & styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.3s ease;
}

/* App Header styling */
.app-header {
  height: 64px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--accent-color);
}

.header-logo h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.header-logo h1 span {
  color: var(--accent-color);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Buttons */
.btn {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition-smooth);
}

.btn-primary {
  background-color: var(--accent-color);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-secondary {
  background-color: var(--bg-input);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background-color: var(--border-color);
  color: var(--text-primary);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn-small {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

/* Toggle Sun/Moon icons depending on active state */
[data-editor-theme="dark"] .sun-icon { display: block; }
[data-editor-theme="dark"] .moon-icon { display: none; }
[data-editor-theme="light"] .sun-icon { display: none; }
[data-editor-theme="light"] .moon-icon { display: block; }

/* Main app container */
.app-container {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar styling */
.editor-sidebar {
  width: 420px;
  flex-shrink: 0;
  min-height: 0;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sidebar);
  z-index: 50;
  transition: var(--transition-smooth);
}

/* Sidebar Tab buttons */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  padding: 0 1rem;
  background-color: rgba(0, 0, 0, 0.02);
}

.tab-btn {
  flex: 1;
  font-family: var(--font-sans);
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 1rem 0;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: var(--transition-smooth);
  text-align: center;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent-color);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background-color: var(--accent-color);
  border-radius: 3px 3px 0 0;
}

/* Scrollable tabs content */
.tabs-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem;
}

/* Hide scrollbar by default, style beautifully on hover */
.tabs-content::-webkit-scrollbar {
  width: 6px;
}
.tabs-content::-webkit-scrollbar-track {
  background: transparent;
}
.tabs-content::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 10px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.2s ease-in-out;
}

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

.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  letter-spacing: -0.2px;
}

.panel-header-inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.panel-header-inline .panel-title {
  margin-bottom: 0;
}

.panel-divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 1.75rem 0;
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

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

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  transition: var(--transition-smooth);
  outline: none;
}

.form-group textarea {
  resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Toggle label row — label + switch inline */
.toggle-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.toggle-label-row label:first-child {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0;
}

/* Toggle switch pill */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background-color: var(--border-color);
  border-radius: 18px;
  transition: var(--transition-smooth);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: var(--transition-smooth);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent-color);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* Logo Upload Container */
.logo-upload-box {
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  position: relative;
  cursor: pointer;
  transition: var(--transition-smooth);
  background-color: rgba(0, 0, 0, 0.01);
}

.logo-upload-box:hover {
  border-color: var(--accent-color);
  background-color: var(--accent-light);
}

.logo-upload-box .file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 5;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.upload-placeholder svg {
  stroke: var(--text-muted);
  transition: var(--transition-smooth);
}

.logo-upload-box:hover .upload-placeholder svg {
  stroke: var(--accent-color);
  transform: translateY(-2px);
}

.upload-placeholder span {
  font-size: 0.75rem;
  font-weight: 500;
}

.logo-preview-wrapper {
  position: relative;
  display: inline-block;
  max-width: 100%;
  padding: 0.25rem;
  background-color: #ffffff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 10;
}

.logo-preview-wrapper img {
  max-height: 80px;
  max-width: 100%;
  display: block;
  object-fit: contain;
}

.btn-remove-logo {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #dc2626;
  border: none;
  color: white;
  font-size: 14px;
  line-height: 18px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Items editor */
.items-editor-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.item-editor-row {
  display: grid;
  grid-template-columns: 2.5fr 0.8fr 1.2fr 0.5fr;
  gap: 0.4rem;
  align-items: center;
  animation: fadeIn 0.2s ease;
}

.item-editor-row input {
  padding: 0.625rem 0.5rem;
  font-size: 0.85rem;
  min-width: 0;
}

.item-editor-row .btn-delete-item {
  height: 38px;
  width: 100%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.item-editor-row .btn-delete-item:hover {
  color: #dc2626;
  background-color: rgba(220, 38, 38, 0.08);
}

/* Calculations Summary Grid */
.calculations-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 0.75rem;
}

/* Design configs */
.template-selector {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.template-option {
  cursor: pointer;
}

.template-option input {
  display: none;
}

.template-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-input);
  transition: var(--transition-smooth);
}

.template-option input:checked + .template-card {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px var(--accent-light);
  background-color: rgba(0, 0, 0, 0.05);
}

.template-thumb {
  width: 50px;
  height: 35px;
  border-radius: 4px;
  background-color: #cbd5e1;
  display: inline-block;
  border: 1px solid rgba(0,0,0,0.1);
  position: relative;
  overflow: hidden;
}

.thumb-modern {
  background: linear-gradient(to bottom, #4f46e5 20%, #f8fafc 20%);
}

.thumb-classic {
  background: #f8fafc;
}
.thumb-classic::before {
  content: '';
  position: absolute;
  top: 10%; left: 10%; right: 10%; height: 2px;
  background-color: #1e293b;
}

.thumb-bold {
  background: #f8fafc;
}
.thumb-bold::before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0; width: 8px;
  background-color: #4f46e5;
}

.template-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.color-picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--accent-color);
}

.custom-color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.custom-color-input-wrapper input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  background: none;
}

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

.custom-color-input-wrapper input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border-color);
  border-radius: 50%;
}

/* Preview Panel Container */
.preview-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 2rem;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: rgba(0, 0, 0, 0.15);
}

/* Preview panel scrollbar styling */
.preview-panel::-webkit-scrollbar {
  width: 6px;
}
.preview-panel::-webkit-scrollbar-track {
  background: transparent;
}
.preview-panel::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 10px;
}

/* Ensure the invoice stands tall in responsive views */
.invoice-container-outer {
  width: 100%;
  max-width: 820px;
  min-height: 1000px;
  margin: 0 auto 2rem auto;
}

/* The actual invoice sheet style (Simulating paper standard A4) */
.invoice-paper {
  background-color: #ffffff;
  color: #1e293b;
  width: 100%;
  min-height: 1120px; /* A4 aspect ratio height approx */
  padding: 3.5rem;
  box-shadow: var(--shadow-paper);
  border-radius: 12px;
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  box-sizing: border-box;
}

/* Accent top-bar for standard designs */
.invoice-accent-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  background-color: var(--accent-color);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

/* Invoice details styling inside sheet */
.invoice-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 1.5rem;
  gap: 2rem;
}

.invoice-company-block {
  flex: 1;
}

.invoice-logo-container {
  max-height: 75px;
  margin-bottom: 1.25rem;
}

.invoice-logo-container img {
  max-height: 75px;
  max-width: 250px;
  object-fit: contain;
  display: block;
}

.invoice-company-block h2 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #0f172a;
  margin-bottom: 0.5rem;
}

.editable-fallback-title {
  color: #94a3b8 !important;
  font-style: italic;
  font-weight: 400 !important;
}

.invoice-sender-details {
  font-size: 0.875rem;
  line-height: 1.5;
  color: #475569;
}

.invoice-sender-details p {
  margin-bottom: 0.25rem;
  white-space: pre-line;
}

.contact-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-top: 0.5rem;
  font-weight: 500;
}

.contact-info span::before {
  font-size: 0.8rem;
  color: var(--accent-color);
  margin-right: 0.25rem;
  font-weight: 800;
}

#invSenderPhone::before { content: '📞 '; }
#invSenderEmail::before { content: '✉️ '; }
#invClientPhone::before { content: '📞 '; }
#invClientEmail::before { content: '✉️ '; }

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

.invoice-title {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--accent-color);
  margin-bottom: 1.5rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.5rem 1.5rem;
  justify-content: end;
  text-align: left;
}

/* Transparent wrapper so due-date rows participate in the parent grid */
#invDueDateWrapper {
  display: contents;
}

.meta-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  letter-spacing: 0.5px;
  align-self: center;
}

.meta-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: #0f172a;
  font-family: var(--font-mono);
}

.invoice-divider {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 2rem 0;
}

/* Bill to styling */
.invoice-billto-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.billto-col h3 {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #64748b;
  margin-bottom: 0.75rem;
}

.billto-col h4 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 0.5rem;
}

.billto-col p {
  font-size: 0.875rem;
  line-height: 1.5;
  color: #475569;
  white-space: pre-line;
}

.invoice-status-col {
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-seal {
  border: 3px double #059669;
  color: #059669;
  font-size: 1.25rem;
  font-weight: 800;
  padding: 0.5rem 1.25rem;
  border-radius: 4px;
  transform: rotate(-10deg);
  letter-spacing: 2px;
  opacity: 0.7;
  display: none; /* Can be toggled if paid status is implemented */
}

/* Table Design */
.invoice-items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0 2.5rem;
}

.invoice-items-table th {
  border-bottom: 2px solid #e2e8f0;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.75rem 0.5rem;
  text-align: left;
}

.invoice-items-table td {
  padding: 1rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
  color: #334155;
}

.invoice-items-table tbody tr:last-child td {
  border-bottom: 2px solid #e2e8f0;
}

.invoice-items-table .text-right {
  text-align: right;
}

.col-qty { width: 80px; }
.col-price { width: 120px; }
.col-total { width: 140px; font-weight: 600; color: #0f172a; }

.table-desc-text {
  font-weight: 500;
  color: #0f172a;
}

/* Footer structure */
.invoice-footer-section {
  display: flex;
  justify-content: space-between;
  margin-top: auto; /* Push footer to bottom */
  gap: 3rem;
  padding-top: 2rem;
}

.invoice-notes-block {
  flex: 1.2;
}

.invoice-notes-block h4 {
  font-size: 0.75rem;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  letter-spacing: 0.5px;
}

.invoice-notes-block p {
  font-size: 0.8rem;
  line-height: 1.5;
  color: #64748b;
  white-space: pre-line;
}

.invoice-totals-block {
  flex: 0.8;
  min-width: 250px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  color: #475569;
  padding: 0.5rem 0;
}

.totals-row.grand-total {
  font-size: 1.25rem;
  font-weight: 800;
  color: #0f172a;
  border-top: 2px solid #cbd5e1;
  padding-top: 0.75rem;
  margin-top: 0.5rem;
}

.totals-row.grand-total span:last-child {
  color: var(--accent-color);
}

/* Payment Received row */
.totals-row.payment-received-row {
  font-size: 0.9rem;
  font-weight: 600;
  color: #059669;
  border-top: 1px dashed #cbd5e1;
  padding-top: 0.6rem;
  margin-top: 0.25rem;
}

.totals-row.payment-received-row span:last-child {
  color: #059669;
}

/* Remaining Amount row — highlighted */
.totals-row.remaining-amount-row {
  font-size: 1.1rem;
  font-weight: 800;
  color: #dc2626;
  border-top: 2px solid #fca5a5;
  border-bottom: 3px double #dc2626;
  padding: 0.6rem 0;
  margin-top: 0.25rem;
}

.totals-row.remaining-amount-row span:last-child {
  color: #dc2626;
}

/* Signature block */
.invoice-signature-block {
  display: flex;
  justify-content: flex-end;
  padding-top: 2rem;
  margin-top: 1.5rem;
  border-top: 1px dashed #e2e8f0;
}

.signature-line-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 200px;
  max-width: 260px;
}

.inv-signature-img {
  max-height: 80px;
  max-width: 220px;
  object-fit: contain;
  margin-bottom: 0.5rem;
  animation: fadeIn 0.3s ease;
}

.signature-underline {
  width: 100%;
  height: 2px;
  background: linear-gradient(to right, transparent, #475569, transparent);
  margin-bottom: 0.4rem;
}

.signature-label-text {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.75px;
  text-align: center;
}

/* ----------------------------------------------------------------------------- */
/* TEMPLATE VARIATIONS */
/* ----------------------------------------------------------------------------- */


/* 1. Classic Corporate */
.invoice-paper.template-classic {
  font-family: var(--font-serif);
}

.invoice-paper.template-classic .invoice-accent-bar {
  display: none;
}

.invoice-paper.template-classic .invoice-title {
  font-family: var(--font-serif);
  color: #1e293b;
  letter-spacing: 2px;
  font-style: italic;
  font-weight: 400;
}

.invoice-paper.template-classic .invoice-items-table th {
  border-top: 1px solid #1e293b;
  border-bottom: 1px solid #1e293b;
  color: #1e293b;
  background-color: #f8fafc;
}

.invoice-paper.template-classic .invoice-items-table tbody tr:last-child td {
  border-bottom: 1px solid #1e293b;
}

.invoice-paper.template-classic .totals-row.grand-total {
  border-top: 1px solid #1e293b;
  border-bottom: 4px double #1e293b;
  padding-bottom: 0.5rem;
}

.invoice-paper.template-classic .totals-row.grand-total span:last-child {
  color: #1e293b;
}

/* 2. Bold Accent Template */
.invoice-paper.template-bold {
  border-left: 24px solid var(--accent-color);
  padding-left: 2.5rem;
}

.invoice-paper.template-bold .invoice-accent-bar {
  display: none;
}

.invoice-paper.template-bold .invoice-items-table th {
  background-color: var(--accent-color);
  color: #ffffff;
  border-bottom: none;
  padding: 0.75rem 1rem;
}

.invoice-paper.template-bold .invoice-items-table td {
  padding: 1rem;
}

.invoice-paper.template-bold .invoice-items-table th:first-child {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}
.invoice-paper.template-bold .invoice-items-table th:last-child {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.invoice-paper.template-bold .totals-row.grand-total {
  background-color: rgba(0, 0, 0, 0.02);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  border-top: none;
}

/* ----------------------------------------------------------------------------- */
/* MEDIA PRINT RULES */
/* ----------------------------------------------------------------------------- */
@media print {
  /* A4 page setup with margins */
  @page {
    size: A4 portrait;
    margin: 15mm 15mm 15mm 15mm;
  }

  html, body {
    width: 100% !important;
    height: auto !important;
    background-color: #ffffff !important;
    color: #1e293b !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Force display colors */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide all editor UI */
  .no-print,
  .app-header,
  .editor-sidebar {
    display: none !important;
  }

  /* Reset app container to plain block */
  .app-container {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  /* Reset preview panel */
  .preview-panel {
    display: block !important;
    background-color: #ffffff !important;
    padding: 0 !important;
    overflow: visible !important;
    width: 100% !important;
    min-height: 0 !important;
  }

  /* Invoice outer container */
  .invoice-container-outer {
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    margin: 0 !important;
  }

  /* The invoice paper itself — restore padding for print */
  .invoice-paper {
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    padding: 1.5rem 2rem 2rem 2rem !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    font-size: 10pt !important;
    display: block !important;
  }

  /* Accent top bar no radius */
  .invoice-accent-bar {
    border-radius: 0 !important;
    height: 6px !important;
  }

  /* Invoice title smaller for print */
  .invoice-title {
    font-size: 22pt !important;
    margin-bottom: 1rem !important;
  }

  /* Business name smaller */
  .invoice-company-block h2 {
    font-size: 16pt !important;
  }

  /* Ensure header row doesn't wrap */
  .invoice-header-row {
    margin-top: 1rem !important;
    display: flex !important;
    justify-content: space-between !important;
  }

  /* Footer layout */
  .invoice-footer-section {
    display: flex !important;
    justify-content: space-between !important;
    margin-top: 2rem !important;
  }

  /* Totals block */
  .invoice-totals-block {
    min-width: 220px !important;
  }

  /* Prevent page breaks inside sections */
  .invoice-header-row,
  .invoice-billto-row,
  .invoice-items-table tr,
  .invoice-footer-section {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Keep table header on each page if table overflows */
  .invoice-items-table thead {
    display: table-header-group !important;
  }

  /* Ensure table columns are visible */
  .invoice-items-table {
    width: 100% !important;
  }
}

/* ----------------------------------------------------------------------------- */
/* RESPONSIVE EDITOR LAYOUTS */
/* ----------------------------------------------------------------------------- */
@media (max-width: 900px) {
  body {
    overflow-y: auto;
  }

  .app-container {
    flex-direction: column;
    height: auto;
    overflow-y: visible;
  }

  .editor-sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .preview-panel {
    padding: 1.5rem 1rem;
    overflow-y: visible;
    min-height: auto;
  }

  .invoice-container-outer {
    width: 100%;
    min-height: auto;
  }

  .invoice-paper {
    padding: 2rem;
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .app-header {
    padding: 0 1rem;
  }

  .app-header h1 span {
    display: inline;
  }

  .header-actions span {
    display: none; /* Hide button text on extra small screens */
  }

  .header-actions .btn {
    padding: 0.5rem;
  }

  .tabs-content {
    padding: 1rem;
  }

  .invoice-paper {
    padding: 1rem;
  }

  .invoice-header-row {
    flex-direction: column;
    gap: 1.5rem;
  }

  .invoice-meta-block {
    text-align: left;
  }

  .meta-grid {
    justify-content: start;
  }

  .invoice-footer-section {
    flex-direction: column;
    gap: 2rem;
  }
}
