/* ============================================================
   PROFORMA INVOICE GENERATOR — Layout & UI
   OnlineInvoicesMaker.com
   ============================================================ */

/* ---- Page Layout ---- */
.generator-page {
  padding-top: var(--header-height);
  min-height: 100vh;
  background: var(--bg-page);
}

/* ---- Toolbar ---- */
.generator-toolbar {
  position: sticky;
  top: var(--header-height);
  z-index: var(--z-sticky);
  background: var(--bg-overlay);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.generator-toolbar::-webkit-scrollbar { display: none; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  margin: 0 var(--space-2);
  flex-shrink: 0;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
  border: none;
}

.toolbar-btn:hover {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}

.toolbar-btn.active {
  background: var(--brand-primary-light);
  color: var(--brand-primary);
}

.toolbar-btn.primary {
  background: var(--brand-primary);
  color: #fff;
  box-shadow: 0 1px 3px rgb(79 70 229 / 0.3);
}
.toolbar-btn.primary:hover { background: var(--brand-primary-hover); }

.toolbar-btn.success {
  background: var(--success-light);
  color: #059669;
}
.toolbar-btn.success:hover { background: #a7f3d0; }

.toolbar-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* Template Bar */
.template-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  height: 52px;
  overflow-x: auto;
  scrollbar-width: none;
}
.template-bar::-webkit-scrollbar { display: none; }

.template-bar-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
}

.template-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.3125rem var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-surface-2);
  border: 1.5px solid var(--border-color);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.template-chip:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  background: var(--brand-primary-light);
}

.template-chip.active {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
  box-shadow: 0 2px 8px rgb(79 70 229 / 0.3);
}

.template-chip .chip-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* Color Picker Row */
.color-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  margin-left: auto;
  flex-shrink: 0;
}

.color-bar-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  white-space: nowrap;
}

/* ---- Main Generator Layout ---- */
.generator-layout {
  display: grid;
  grid-template-columns: var(--editor-width) 1fr;
  min-height: calc(100vh - var(--header-height) - var(--toolbar-height) - 52px);
  align-items: start;
}

/* ---- Left Editor Panel ---- */
.editor-panel {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  height: calc(100vh - var(--header-height) - var(--toolbar-height) - 52px);
  overflow-y: auto;
  position: sticky;
  top: calc(var(--header-height) + var(--toolbar-height) + 52px);
  scrollbar-width: thin;
}

.editor-inner {
  padding: var(--space-4);
}

/* Editor Sections */
.editor-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.editor-section:focus-within { border-color: var(--brand-primary); }

.editor-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
  background: var(--bg-surface);
}

.editor-section-header:hover { background: var(--bg-surface-2); }

.editor-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
}

.editor-section-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-brand { background: var(--brand-primary-light); color: var(--brand-primary); }
.icon-green { background: var(--success-light); color: var(--success); }
.icon-orange { background: var(--warning-light); color: var(--warning); }
.icon-purple { background: #f5f3ff; color: #7c3aed; }
.icon-cyan { background: #ecfeff; color: #0891b2; }
.icon-red { background: var(--error-light); color: var(--error); }
.icon-gray { background: var(--bg-surface-3); color: var(--text-secondary); }

[data-theme="dark"] .icon-purple { background: #1e1b4b; }
[data-theme="dark"] .icon-cyan { background: #083344; }

.editor-section-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.editor-section.open .editor-section-chevron {
  transform: rotate(180deg);
}

.editor-section-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-top: 0 solid var(--border-color);
}

.editor-section.open .editor-section-body {
  max-height: 3000px;
  border-top-width: 1px;
}

.editor-section-content {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Two-column form layout */
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

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

/* Logo Upload */
.logo-upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--bg-surface-2);
  position: relative;
}

.logo-upload-zone:hover, .logo-upload-zone.dragover {
  border-color: var(--brand-primary);
  background: var(--brand-primary-light);
}

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

.logo-preview {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.logo-preview img {
  max-height: 60px;
  max-width: 120px;
  object-fit: contain;
  border-radius: var(--radius);
}

/* Line Items Table */
.line-items-table {
  width: 100%;
  border-collapse: collapse;
}

.line-items-header {
  display: grid;
  grid-template-columns: 2fr 60px 90px 70px 70px 32px;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-2);
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
}

.line-items-header span {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.line-item-row {
  display: grid;
  grid-template-columns: 2fr 60px 90px 70px 70px 32px;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-color);
  animation: fadeIn var(--transition-fast) forwards;
}

.line-item-row:last-child { border-bottom: none; }

.line-item-input {
  width: 100%;
  padding: 0.4375rem var(--space-3);
  background: var(--bg-surface);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.line-item-input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px rgb(79 70 229 / 0.1);
  outline: none;
}

.line-item-input.desc { font-size: var(--text-xs); }
.line-item-input.number { text-align: right; }

.line-item-delete {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: none;
}
.line-item-delete:hover { background: var(--error-light); color: var(--error); }

.line-item-ai-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  font-weight: 600;
  color: var(--brand-primary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--brand-primary-light);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  white-space: nowrap;
  margin-top: 2px;
}
.line-item-ai-btn:hover { background: var(--brand-primary); color: #fff; }

/* Totals */
.totals-block {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-sm);
}

.totals-row.grand-total {
  padding-top: var(--space-3);
  border-top: 2px solid var(--border-color);
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--text-primary);
}

.totals-label { color: var(--text-secondary); }
.totals-value { font-weight: 600; color: var(--text-primary); }
.totals-row.grand-total .totals-value { color: var(--brand-primary); font-size: var(--text-xl); }

/* ---- Right Preview Panel ---- */
.preview-panel {
  background: var(--bg-page);
  padding: var(--space-6) var(--space-8);
  min-height: calc(100vh - var(--header-height) - var(--toolbar-height) - 52px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.preview-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 820px;
}

.preview-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.preview-zoom {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.zoom-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  transition: all var(--transition-fast);
}
.zoom-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }

.zoom-level {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
}

/* Preview Document Wrapper */
.preview-wrapper {
  width: 100%;
  max-width: 820px;
  transform-origin: top center;
  transition: transform var(--transition);
}

.preview-document {
  background: white;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -1px rgb(0 0 0 / 0.05), 0 0 0 1px rgb(0 0 0 / 0.05);
  border-radius: var(--radius-lg);
  min-height: 1000px;
  width: 100%;
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.preview-document:hover {
  box-shadow: var(--shadow-xl);
}

/* ---- Mobile Tab Switcher ---- */
.mobile-tab-bar {
  display: none;
  position: sticky;
  top: calc(var(--header-height) + var(--toolbar-height));
  z-index: calc(var(--z-sticky) - 1);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-2) var(--space-4);
}

.mobile-tabs {
  display: flex;
  background: var(--bg-surface-2);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.mobile-tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: calc(var(--radius) - 2px);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.mobile-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ---- Quick Preset Strip ---- */
.preset-strip {
  background: linear-gradient(135deg, #f5f3ff 0%, #eef2ff 100%);
  border-bottom: 1px solid #e0e7ff;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  overflow-x: auto;
  scrollbar-width: none;
}

[data-theme="dark"] .preset-strip {
  background: linear-gradient(135deg, #1e1b4b 0%, #1e1b4b 100%);
  border-bottom-color: #2d3748;
}

.preset-strip::-webkit-scrollbar { display: none; }

.preset-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--brand-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--brand-primary);
  background: rgba(79, 70, 229, 0.08);
  border: 1px solid rgba(79, 70, 229, 0.2);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.preset-chip:hover {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
}

/* ---- Status Badge ---- */
.status-selector {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.status-option {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.status-option:hover { border-color: var(--gray-400); color: var(--text-primary); }

.status-option.active.draft { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-400); }
.status-option.active.sent { background: var(--info-light); color: var(--info); border-color: var(--info); }
.status-option.active.approved { background: var(--success-light); color: #059669; border-color: var(--success); }
.status-option.active.expired { background: var(--error-light); color: var(--error); border-color: var(--error); }
.status-option.active.converted { background: #f5f3ff; color: #7c3aed; border-color: #7c3aed; }

/* ---- Signature Area ---- */
.signature-area {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-2);
}

.signature-area:hover {
  border-color: var(--brand-primary);
  background: var(--brand-primary-light);
}

.signature-canvas {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: white;
  cursor: crosshair;
  touch-action: none;
}

/* ---- QR Code Block ---- */
.qr-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

/* ---- Autosave Bar ---- */
.editor-bottom-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  backdrop-filter: blur(8px);
}

/* ---- Share Modal Styles ---- */
.share-link-box {
  display: flex;
  gap: var(--space-2);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  align-items: center;
}

.share-link-url {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  background: none;
  border: none;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-methods {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.share-method-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
}

.share-method-btn:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  background: var(--brand-primary-light);
}

/* ---- Saved Docs Sidebar ---- */
.saved-docs-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  z-index: calc(var(--z-modal) - 1);
  transform: translateX(100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

.saved-docs-panel.open { transform: translateX(0); }

.saved-docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.saved-docs-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.saved-doc-item {
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--bg-surface);
}

.saved-doc-item:hover {
  border-color: var(--brand-primary);
  background: var(--brand-primary-light);
}

.saved-doc-number {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--brand-primary);
  margin-bottom: 2px;
}

.saved-doc-client {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  truncate: true;
}

.saved-doc-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-2);
}

.saved-doc-amount {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
}

/* ---- Responsive: Generator ---- */
@media (max-width: 1100px) {
  .generator-layout {
    grid-template-columns: 420px 1fr;
  }
  --editor-width: 420px;
}

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

  .editor-panel {
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .preview-panel {
    padding: var(--space-4);
  }

  .mobile-tab-bar { display: block; }

  .generator-layout.preview-mode .editor-panel { display: none; }
  .generator-layout.edit-mode .preview-panel { display: none; }
}

@media (max-width: 600px) {
  .generator-toolbar { padding: 0 var(--space-3); gap: var(--space-1); }
  .toolbar-btn span { display: none; }
  .template-bar { padding: 0 var(--space-3); }
  .preview-panel { padding: var(--space-3); }
  .form-row-2 { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
  .line-items-header { display: none; }
  .line-item-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
  }
  .line-item-row .desc-col { grid-column: 1 / -1; }
  .share-methods { grid-template-columns: 1fr 1fr; }
}
