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

:root {
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --orange-50: #fff7ed;
  --orange-100: #ffedd5;
  --orange-200: #fed7aa;
  --orange-300: #fdba74;
  --orange-400: #fb923c;
  --orange-500: #f97316;
  --orange-600: #ea580c;
  --orange-700: #c2410c;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: var(--font-sans);
  background: var(--slate-100);
  color: var(--slate-800);
  line-height: 1.5;
  min-height: 100vh;
}

.mono { font-family: var(--font-mono); }

.navbar {
  background: var(--slate-900);
  color: white;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.nav-brand svg { color: var(--orange-500); }
.nav-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--orange-500);
  color: white;
}
.btn-primary:hover { background: var(--orange-600); }

.btn-ghost {
  background: transparent;
  color: var(--slate-300);
}
.btn-ghost:hover { background: var(--slate-800); color: white; }

.btn-add {
  background: transparent;
  color: var(--orange-500);
  border: 1px dashed var(--orange-300);
  width: 100%;
  padding: 10px;
  border-radius: var(--radius);
  margin-top: 8px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-add:hover { background: var(--orange-50); border-color: var(--orange-500); }

.btn-remove {
  background: none;
  border: none;
  color: var(--slate-400);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-remove:hover { color: #ef4444; background: #fef2f2; }

.btn-icon {
  background: none;
  border: 1px solid var(--slate-300);
  color: var(--slate-600);
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.btn-icon:hover { background: var(--slate-100); }

.app-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 56px);
}

.editor-panel {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 600px;
}

.preview-panel {
  background: var(--slate-200);
  border-left: 1px solid var(--slate-300);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-toolbar {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--slate-300);
  background: var(--slate-100);
}

.preview-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--slate-600);
}

.preview-scroll {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.invoice-preview-wrapper {
  transform-origin: top center;
  transition: transform 0.2s ease;
}

.invoice-preview {
  width: 794px;
  min-height: 1123px;
  background: white;
  box-shadow: var(--shadow-lg);
  border-radius: 4px;
  overflow: hidden;
}

.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--slate-200);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--slate-900);
}

.template-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--slate-600);
}

.template-selector select {
  padding: 6px 10px;
  border: 1px solid var(--slate-300);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 13px;
  background: white;
  cursor: pointer;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--slate-700);
}

.logo-card { padding: 12px; }

.logo-upload-area {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--slate-300);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.logo-upload-area:hover { border-color: var(--orange-400); background: var(--orange-50); }

.logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--slate-400);
  font-size: 13px;
}

.logo-preview {
  max-width: 160px;
  max-height: 60px;
  object-fit: contain;
}

.hidden { display: none !important; }

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

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

.form-group { display: flex; flex-direction: column; gap: 4px; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-group input,
.form-group textarea,
.form-group select {
  padding: 8px 10px;
  border: 1px solid var(--slate-300);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--slate-800);
  transition: border-color 0.15s ease;
  background: white;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--orange-500);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

.form-group textarea { resize: vertical; }

.line-items-table { overflow-x: auto; }

.line-items-header {
  display: grid;
  grid-template-columns: 1fr 80px 100px 100px 36px;
  gap: 8px;
  padding: 6px 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--slate-200);
  margin-bottom: 4px;
}

.line-item {
  display: grid;
  grid-template-columns: 1fr 80px 100px 100px 36px;
  gap: 8px;
  padding: 6px 0;
  align-items: center;
  border-bottom: 1px solid var(--slate-100);
}

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

.line-item input {
  padding: 6px 8px;
  border: 1px solid var(--slate-200);
  border-radius: 4px;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--slate-800);
  background: white;
}

.line-item input:focus {
  outline: none;
  border-color: var(--orange-400);
}

.line-item .amount-cell {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--slate-700);
  text-align: right;
  padding-right: 8px;
}

.totals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--slate-200);
}

.totals-summary { display: flex; flex-direction: column; gap: 8px; }

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--slate-600);
}

.total-final {
  font-size: 18px;
  font-weight: 700;
  color: var(--slate-900);
  padding-top: 8px;
  border-top: 2px solid var(--slate-800);
}

.adsense-placeholder {
  background: white;
  border: 2px dashed var(--slate-200);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
}

.adsense-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--slate-400);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.adsense-content {
  font-size: 12px;
  color: var(--slate-300);
}

.mobile-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--orange-500);
  color: white;
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 200;
  align-items: center;
  justify-content: center;
}

@media (max-width: 900px) {
  .app-container { grid-template-columns: 1fr; }
  .preview-panel { display: none; }
  .preview-panel.active { display: flex; }
  .editor-panel.active { display: none; }
  .mobile-toggle { display: flex; }
  .editor-panel { max-width: none; }
}

@media (max-width: 600px) {
  .form-grid, .address-grid { grid-template-columns: 1fr; }
  .navbar { padding: 0 12px; }
  .editor-panel { padding: 12px; }
}

/* === Professional Template === */
.tpl-professional { padding: 48px; font-family: 'Inter', sans-serif; color: #1e293b; }
.tpl-professional .inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 40px; padding-bottom: 24px; border-bottom: 3px solid #f97316; }
.tpl-professional .inv-logo { max-height: 60px; object-fit: contain; }
.tpl-professional .inv-title { font-size: 36px; font-weight: 700; color: #f97316; letter-spacing: -0.02em; }
.tpl-professional .inv-meta { text-align: right; }
.tpl-professional .inv-meta-row { display: flex; justify-content: flex-end; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.tpl-professional .inv-meta-label { color: #64748b; font-weight: 500; }
.tpl-professional .inv-meta-value { color: #1e293b; font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-professional .inv-addresses { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 32px; }
.tpl-professional .inv-address-block h4 { font-size: 11px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.tpl-professional .inv-address-block p { font-size: 13px; color: #475569; line-height: 1.6; white-space: pre-line; }
.tpl-professional .inv-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.tpl-professional .inv-table thead { background: #0f172a; color: white; }
.tpl-professional .inv-table th { padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; text-align: left; }
.tpl-professional .inv-table th:last-child, .tpl-professional .inv-table td:last-child { text-align: right; }
.tpl-professional .inv-table td { padding: 12px 14px; font-size: 13px; border-bottom: 1px solid #e2e8f0; }
.tpl-professional .inv-table td.mono-cell { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-professional .inv-totals { display: flex; justify-content: flex-end; margin-bottom: 32px; }
.tpl-professional .inv-totals-box { width: 280px; background: #f8fafc; border-radius: 8px; padding: 16px; }
.tpl-professional .inv-total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; color: #64748b; }
.tpl-professional .inv-total-row.final { font-size: 18px; font-weight: 700; color: #0f172a; border-top: 2px solid #0f172a; padding-top: 10px; margin-top: 6px; }
.tpl-professional .inv-total-row .inv-total-val { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-professional .inv-notes { padding: 16px; background: #fff7ed; border-radius: 8px; border-left: 3px solid #f97316; }
.tpl-professional .inv-notes h4 { font-size: 11px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.tpl-professional .inv-notes p { font-size: 13px; color: #475569; white-space: pre-line; }

/* === Minimal Template === */
.tpl-minimal { padding: 48px; font-family: 'Inter', sans-serif; color: #1e293b; }
.tpl-minimal .inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 48px; }
.tpl-minimal .inv-logo { max-height: 50px; object-fit: contain; }
.tpl-minimal .inv-title { font-size: 14px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.15em; }
.tpl-minimal .inv-meta { text-align: right; }
.tpl-minimal .inv-meta-row { display: flex; justify-content: flex-end; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.tpl-minimal .inv-meta-label { color: #94a3b8; }
.tpl-minimal .inv-meta-value { color: #1e293b; font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-minimal .inv-addresses { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 40px; }
.tpl-minimal .inv-address-block h4 { font-size: 10px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 8px; }
.tpl-minimal .inv-address-block p { font-size: 13px; color: #475569; line-height: 1.6; white-space: pre-line; }
.tpl-minimal .inv-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.tpl-minimal .inv-table thead { border-bottom: 2px solid #1e293b; }
.tpl-minimal .inv-table th { padding: 8px 0; font-size: 11px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em; text-align: left; }
.tpl-minimal .inv-table th:last-child, .tpl-minimal .inv-table td:last-child { text-align: right; }
.tpl-minimal .inv-table td { padding: 10px 0; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.tpl-minimal .inv-table td.mono-cell { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-minimal .inv-totals { display: flex; justify-content: flex-end; margin-bottom: 32px; }
.tpl-minimal .inv-totals-box { width: 260px; }
.tpl-minimal .inv-total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; color: #64748b; }
.tpl-minimal .inv-total-row.final { font-size: 16px; font-weight: 700; color: #1e293b; border-top: 1px solid #e2e8f0; padding-top: 10px; margin-top: 6px; }
.tpl-minimal .inv-total-row .inv-total-val { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-minimal .inv-notes { padding: 16px 0; border-top: 1px solid #e2e8f0; }
.tpl-minimal .inv-notes h4 { font-size: 10px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; }
.tpl-minimal .inv-notes p { font-size: 13px; color: #475569; white-space: pre-line; }

/* === Creative Template === */
.tpl-creative { padding: 0; font-family: 'Inter', sans-serif; color: #1e293b; }
.tpl-creative .inv-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 40px 48px 32px; background: linear-gradient(135deg, #0f172a 0%, #334155 100%); color: white; }
.tpl-creative .inv-logo { max-height: 50px; object-fit: contain; }
.tpl-creative .inv-title { font-size: 42px; font-weight: 700; color: #f97316; letter-spacing: -0.03em; }
.tpl-creative .inv-meta { text-align: right; }
.tpl-creative .inv-meta-row { display: flex; justify-content: flex-end; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.tpl-creative .inv-meta-label { color: #94a3b8; }
.tpl-creative .inv-meta-value { color: white; font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-creative .inv-body { padding: 40px 48px; }
.tpl-creative .inv-addresses { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 32px; }
.tpl-creative .inv-address-block h4 { font-size: 11px; font-weight: 600; color: #f97316; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.tpl-creative .inv-address-block p { font-size: 13px; color: #475569; line-height: 1.6; white-space: pre-line; }
.tpl-creative .inv-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.tpl-creative .inv-table thead { background: #f97316; color: white; }
.tpl-creative .inv-table th { padding: 12px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; text-align: left; }
.tpl-creative .inv-table th:last-child, .tpl-creative .inv-table td:last-child { text-align: right; }
.tpl-creative .inv-table td { padding: 12px 14px; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.tpl-creative .inv-table tr:nth-child(even) { background: #fff7ed; }
.tpl-creative .inv-table td.mono-cell { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-creative .inv-totals { display: flex; justify-content: flex-end; margin-bottom: 32px; }
.tpl-creative .inv-totals-box { width: 280px; background: #0f172a; color: white; border-radius: 8px; padding: 16px; }
.tpl-creative .inv-total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; color: #94a3b8; }
.tpl-creative .inv-total-row.final { font-size: 18px; font-weight: 700; color: #f97316; border-top: 1px solid #334155; padding-top: 10px; margin-top: 6px; }
.tpl-creative .inv-total-row .inv-total-val { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.tpl-creative .inv-notes { padding: 16px; background: #fff7ed; border-radius: 8px; border-left: 3px solid #f97316; }
.tpl-creative .inv-notes h4 { font-size: 11px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.tpl-creative .inv-notes p { font-size: 13px; color: #475569; white-space: pre-line; }
