/* Invoice Editor Styles */
:root {
  --bg: #F8F5F0;
  --fg: #1A1614;
  --accent: #D4613A;
  --accent-light: #F0D9CF;
  --muted: #7A7067;
  --border: #E2D9CE;
  --surface: #FFFFFF;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  line-height: 1.2;
}

/* Navbar (reused from theme.css) */
.navbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-logo {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--fg);
}
.nav-links { display: flex; gap: 32px; }
.nav-links a { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; transition: color 0.15s; }
.nav-links a:hover { color: var(--fg); }

/* App Layout */
.invoice-app {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - 57px);
}

/* Editor Panel */
.editor-panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.editor-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.editor-scroll::-webkit-scrollbar { width: 6px; }
.editor-scroll::-webkit-scrollbar-track { background: transparent; }
.editor-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Section label */
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
  margin: 16px 0 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.section-label:first-child { border-top: none; padding-top: 0; margin-top: 4px; }

/* Template grid */
.template-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}
.template-btn {
  background: none;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s;
}
.template-btn:hover { border-color: var(--accent); }
.template-btn.active { border-color: var(--accent); background: var(--accent-light); }
.template-btn span { font-size: 10px; color: var(--muted); font-weight: 500; }
.template-btn.active span { color: var(--accent); }

/* Template mini-cards */
.tmpl-card {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 4px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.tmpl-minimal { background: #fff; border: 1px solid #eee; }
.tmpl-minimal .tmpl-line { height: 3px; background: #ddd; border-radius: 2px; }
.tmpl-bold { background: var(--fg); }
.tmpl-bold .tmpl-block { height: 8px; background: var(--accent); border-radius: 2px; margin-bottom: 2px; }
.tmpl-bold .tmpl-line { height: 3px; background: rgba(255,255,255,0.4); border-radius: 2px; }
.tmpl-editorial { background: #fff; border: 1px solid #eee; }
.tmpl-editorial .tmpl-serif-line { height: 6px; background: var(--fg); border-radius: 2px; margin-bottom: 2px; }
.tmpl-editorial .tmpl-line { height: 3px; background: #ddd; border-radius: 2px; }
.tmpl-classic { background: #fff; border: 1px solid #ddd; }
.tmpl-classic .tmpl-header-bar { height: 6px; background: var(--fg); border-radius: 2px 2px 0 0; }
.tmpl-classic .tmpl-line { height: 3px; background: #ccc; border-radius: 2px; }

.tmpl-line.long { width: 100%; }
.tmpl-line.medium { width: 70%; }
.tmpl-line.short { width: 45%; }

/* Fields */
.field-group { display: flex; flex-direction: column; gap: 2px; }
.field-group input, .field-group select, .field-group textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--fg);
  width: 100%;
  transition: border-color 0.15s;
  outline: none;
}
.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
  border-color: var(--accent);
  background: #fff;
}
.field-group label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.field-group.half { flex: 1; }
.detail-row { display: flex; gap: 8px; }

textarea { resize: vertical; min-height: 64px; }

/* Line items */
#lineItems { display: flex; flex-direction: column; gap: 6px; }
.line-item-row {
  display: grid;
  grid-template-columns: 1fr 60px 80px 24px;
  gap: 6px;
  align-items: center;
}
.line-item-row input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 12px;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--fg);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
.line-item-row input:focus { border-color: var(--accent); background: #fff; }
.line-item-row input.qty, .line-item-row input.rate { text-align: right; }
.remove-line-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.remove-line-btn:hover { color: #c0392b; background: #fee; }
.add-line-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  width: 100%;
  font-family: 'DM Sans', sans-serif;
  transition: border-color 0.15s, color 0.15s;
}
.add-line-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Preview Panel */
.preview-panel {
  display: flex;
  flex-direction: column;
  background: #E8E3DC;
  overflow: hidden;
}
.preview-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.preview-info { font-size: 13px; color: var(--muted); font-weight: 500; }
.toolbar-actions { display: flex; gap: 8px; }
.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  color: var(--fg);
  cursor: pointer;
  font-weight: 500;
  transition: border-color 0.15s;
}
.toolbar-btn:hover { border-color: var(--fg); }
.toolbar-btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.toolbar-btn-primary:hover { opacity: 0.85; }

.preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 40px 24px;
  display: flex;
  justify-content: center;
}
.preview-page {
  background: #fff;
  width: 100%;
  max-width: 680px;
  min-height: 900px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  border-radius: 2px;
  padding: 64px 56px;
}

/* Invoice Preview Styles */
.inv-from, .inv-to { margin-bottom: 32px; }
.inv-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.inv-name { font-size: 15px; font-weight: 600; }
.inv-address { font-size: 13px; color: var(--muted); margin-top: 2px; }
.inv-email { font-size: 12px; color: var(--accent); margin-top: 2px; }

.inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 48px; }
.inv-title { font-family: 'Fraunces', serif; font-size: 36px; font-weight: 500; letter-spacing: -0.02em; }
.inv-meta { text-align: right; }
.inv-number { font-size: 13px; font-weight: 600; }
.inv-dates { font-size: 12px; color: var(--muted); margin-top: 4px; }

.inv-details-grid { display: flex; gap: 24px; margin-bottom: 40px; }

/* Table */
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.inv-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.inv-table th:nth-child(2), .inv-table th:nth-child(3), .inv-table th:last-child { text-align: right; }
.inv-table td { padding: 10px 0; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: top; }
.inv-table td:nth-child(2), .inv-table td:nth-child(3), .inv-table td:last-child { text-align: right; }
.inv-table .desc-col { width: 50%; }
.inv-table .qty-col, .inv-table .rate-col { width: 15%; }
.inv-table .amount-col { width: 20%; }

.inv-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; margin-bottom: 40px; }
.inv-total-row { display: flex; gap: 40px; font-size: 13px; }
.inv-total-row .key { color: var(--muted); min-width: 120px; text-align: right; }
.inv-total-row .val { min-width: 80px; text-align: right; font-weight: 500; }
.inv-total-row.grand-total { font-size: 16px; font-weight: 600; padding-top: 8px; border-top: 1.5px solid var(--fg); margin-top: 4px; }
.inv-total-row.grand-total .key { color: var(--fg); }
.inv-total-row.discount .val { color: var(--accent); }

.inv-notes { font-size: 12px; color: var(--muted); line-height: 1.7; border-top: 1px solid var(--border); padding-top: 20px; }
.inv-notes-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; margin-bottom: 6px; color: var(--muted); }

/* Template: Bold */
.inv-bold .inv-title { font-family: 'Fraunces', serif; font-size: 48px; font-weight: 700; letter-spacing: -0.03em; color: var(--fg); }
.inv-bold .inv-label { color: var(--accent); }
.inv-bold .inv-table th { color: var(--accent); border-bottom-color: var(--fg); }
.inv-bold .inv-table td { border-bottom-color: var(--border); }
.inv-bold .inv-total-row.grand-total { color: var(--accent); }

/* Template: Editorial */
.inv-editorial { font-family: 'Georgia', serif; }
.inv-editorial .inv-label { font-family: 'DM Sans', sans-serif; }
.inv-editorial .inv-title { font-family: 'Fraunces', serif; font-size: 42px; font-style: italic; font-weight: 300; }
.inv-editorial .inv-table th { font-family: 'DM Sans', sans-serif; font-weight: 600; }

/* Template: Classic */
.inv-classic .inv-header { background: var(--fg); color: var(--bg); padding: 24px 28px; margin: -64px -56px 48px; }
.inv-classic .inv-title { font-size: 24px; letter-spacing: 0.1em; text-transform: uppercase; }
.inv-classic .inv-meta { text-align: right; }
.inv-classic .inv-number, .inv-classic .inv-dates { color: rgba(248,245,240,0.7); }
.inv-classic .inv-number { font-size: 16px; font-weight: 600; }
.inv-classic .inv-table th { border-bottom-color: var(--fg); }

/* Mobile */
@media (max-width: 900px) {
  .invoice-app { grid-template-columns: 1fr; }
  .editor-panel { height: 50vh; }
  .preview-scroll { padding: 20px; }
}

@media print {
  .preview-toolbar, .editor-panel, .navbar { display: none !important; }
  .preview-panel { background: white; }
  .preview-scroll { padding: 0; }
  .preview-page { box-shadow: none; max-width: none; padding: 0; }
}