/* INVOBILLING — invoice-editor.css : split-screen editor */
.invoice-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (min-width: 1500px) {
  .invoice-workspace { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; }
}
.invoice-editor { min-width: 0; }
.invoice-preview-pane {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  min-width: 0;
}
@media (max-width: 1100px) {
  .invoice-workspace { grid-template-columns: 1fr; }
  .invoice-preview-pane { position: relative; top: 0; }
}

.editor-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.editor-section-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
}
.editor-section-header h3 {
  font-size: .98rem;
  display: flex; align-items: center; gap: 8px;
}
.editor-section-header .icon { color: var(--accent); }
.editor-section-body { padding: 16px; }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Invoice items table */
.items-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.items-table table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 12px; }
.items-table thead th {
  background: var(--bg-soft);
  padding: 8px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.items-table tbody td { padding: 6px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.items-table tbody tr:last-child td { border-bottom: none; }
.items-table .input, .items-table .select { padding: 6px 8px; font-size: 12.5px; min-width: 0; }
.items-table .col-num { width: 32px; text-align: center; color: var(--text-subtle); font-weight: 600; }
.items-table .col-action { width: 90px; white-space: nowrap; }
.items-table .row-actions { display: flex; gap: 2px; }
.items-table .row-actions .btn-icon { width: 28px; height: 28px; padding: 4px; }
.items-table .drag-handle { padding: 2px; }
.items-table .line-total { font-weight: 700; font-family: var(--font-mono); white-space: nowrap; }

.items-table-compact thead th { padding: 6px; font-size: 10px; }
.items-table-compact tbody td { padding: 4px; }

/* Totals panel */
.totals-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-muted);
}
.totals-row .val { font-family: var(--font-mono); color: var(--text); font-weight: 500; }
.totals-row.subtle .val { color: var(--text-muted); }
.totals-row.discount .val { color: var(--danger); }
.totals-row.tax .val { color: var(--info); }
.totals-row.grand {
  border-top: 1px solid var(--border-strong);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.totals-row.grand .val { color: var(--accent); font-size: 16px; }
.totals-row.balance .val { color: var(--danger); }

/* Add-item row */
.add-item-row {
  display: flex; gap: 8px; padding: 10px;
  border-top: 1px dashed var(--border);
  background: var(--surface-2);
}

/* Status segmented */
.status-segmented .segmented { width: 100%; display: flex; }
.status-segmented .segmented button { flex: 1; }

/* Small helpers for inline editing */
.input-prefix { position: relative; }
.input-prefix .prefix { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); font-size: 13px; }
.input-prefix input { padding-left: 32px; }

.field-stack { display: flex; flex-direction: column; gap: 12px; }
.checkbox-list { display: flex; flex-direction: column; gap: 8px; }
.checkbox-list label { padding: 6px 8px; border-radius: var(--radius-sm); cursor: pointer; }
.checkbox-list label:hover { background: var(--bg-hover); }

/* Template picker */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.template-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: all .15s ease;
  position: relative;
}
.template-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow); }
.template-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.template-card .thumb { aspect-ratio: 1 / 1.414; background: #fff; position: relative; overflow: hidden; }
.template-card .thumb .mini-invoice { transform: scale(.32); transform-origin: top left; width: 312%; pointer-events: none; }
.template-card .name { padding: 8px 10px; font-size: 12px; font-weight: 600; border-top: 1px solid var(--border); white-space: normal; word-break: break-word; line-height: 1.3; min-height: 36px; display: flex; align-items: center; }
.template-card .check { position: absolute; top: 6px; right: 6px; background: var(--accent); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: none; align-items: center; justify-content: center; }
.template-card.selected .check { display: flex; }

/* Color swatches */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
}
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.color-swatch.selected::after { content: '✓'; position: absolute; inset: 0; color: #fff; font-size: 14px; display: flex; align-items: center; justify-content: center; font-weight: 700; }
