/* RepairBill v2 — Invoice Editor + Preview + Print Styles */

/* ─── Editor Page Layout ─── */

/* Override page-content padding when invoice editor is active */
.page-content:has(.inv-editor-page) {
  padding: 0;
  overflow: hidden;
}

.inv-editor-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.inv-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  gap: 12px;
}

.inv-top-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.inv-page-title {
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.inv-num-badge {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.inv-top-right {
  display: flex;
  gap: 8px;
}

.inv-editor-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Form Side ─── */

.inv-form-wrap {
  width: 520px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 20px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.inv-section {
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.inv-section-head {
  padding: 10px 16px;
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.inv-section .form-row,
.inv-section .form-group {
  padding: 0 16px;
}
.inv-section .form-row { padding-top: 10px; }
.inv-section .form-group:first-child:not(.form-row .form-group) { padding-top: 10px; }
.inv-section .form-group:last-child,
.inv-section .form-row:last-child { padding-bottom: 14px; }

.inv-line-actions {
  display: flex;
  gap: 6px;
}

/* ─── Line Items ─── */

.inv-lines-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.inv-lines-empty p { margin-bottom: 10px; }

.inv-line-row {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-dim);
}
.inv-line-row:last-child { border-bottom: none; }

.inv-line-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.inv-line-nums {
  display: flex;
  align-items: center;
  gap: 6px;
}

.inv-line-qty { width: 60px; flex-shrink: 0; text-align: center; }
.inv-line-x { color: var(--text-3); font-size: 12px; flex-shrink: 0; }
.inv-line-price { width: 100px; flex-shrink: 0; }

.inv-line-total {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  min-width: 80px;
  text-align: right;
  flex-shrink: 0;
}

.inv-line-del {
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity var(--dur) var(--ease);
}
.inv-line-row:hover .inv-line-del { opacity: 1; }

/* ─── Totals in Editor ─── */

.inv-totals {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}
.inv-total-row.dim { color: var(--text-3); font-size: 12px; }
.inv-total-row.grand {
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.inv-total-row.balance {
  font-weight: 700;
  color: var(--warn);
}

/* ─── Preview Side ─── */

.inv-preview-pane {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--surface2);
  display: flex;
  justify-content: center;
}

.inv-preview-inner {
  width: 100%;
  max-width: 600px;
}

.inv-preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

/* Preview header */
.inv-pv-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--accent);
}

.inv-pv-shop-name {
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 4px;
}
.inv-pv-shop-detail { font-size: 12px; color: var(--text-3); line-height: 1.5; }

.inv-pv-meta { text-align: right; }
.inv-pv-type {
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: 4px;
}
.inv-pv-num {
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
.inv-pv-date { font-size: 12px; color: var(--text-3); margin-bottom: 6px; }

/* Preview details */
.inv-pv-details {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
}
.inv-pv-col { flex: 1; }
.inv-pv-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 4px;
}
.inv-pv-value { font-size: 14px; font-weight: 600; }
.inv-pv-sub { font-size: 12px; color: var(--text-2); line-height: 1.5; }

/* Preview table */
.inv-pv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 13px;
}
.inv-pv-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.inv-pv-table th:nth-child(2),
.inv-pv-table th:nth-child(3),
.inv-pv-table th:nth-child(4) { text-align: right; }
.inv-pv-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-dim);
}
.inv-pv-table td:nth-child(2),
.inv-pv-table td:nth-child(3),
.inv-pv-table td:nth-child(4) { text-align: right; }
.inv-pv-table td:nth-child(3),
.inv-pv-table td:nth-child(4) {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
}

/* Preview totals */
.inv-pv-totals { margin-bottom: 16px; }
.inv-pv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-2);
}
.inv-pv-total-row.grand {
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.inv-pv-total-row.balance { font-weight: 700; color: var(--warn); }

/* Preview footer */
.inv-pv-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border-dim);
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.6;
}
.inv-pv-warranty { font-style: italic; margin-bottom: 4px; }
.inv-pv-pay { margin-bottom: 2px; }

/* ─── Customer Autocomplete ─── */

.ac-dropdown {
  position: absolute;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  max-height: 200px;
  overflow-y: auto;
  margin-top: 2px;
  width: 100%;
}
.inv-section .form-group { position: relative; }

.ac-item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background var(--dur) var(--ease);
  font-size: 13px;
}
.ac-item:hover { background: var(--surface2); }
.ac-name { font-weight: 500; }
.ac-phone { font-size: 12px; color: var(--text-3); }

/* ─── Preset Picker ─── */

.preset-picker { max-height: 400px; overflow-y: auto; }
.preset-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.preset-list { display: flex; flex-direction: column; gap: 2px; }
.preset-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
  font-family: 'Satoshi', sans-serif;
  font-size: 13px;
  color: var(--text);
  transition: all var(--dur) var(--ease);
  text-align: left;
  width: 100%;
}
.preset-item:hover { border-color: var(--accent); background: var(--accent-dim); }
.preset-price {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

/* ─── Mobile Save Buttons ─── */

.inv-mobile-save {
  display: none;
  gap: 8px;
  padding: 16px;
}

/* ─── Print Preview Page ─── */

.inv-print-page {
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
}

.inv-print-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.inv-print-actions-right { display: flex; gap: 8px; }

.inv-print-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  gap: 16px;
  color: var(--text-3);
}

/* ─── A4 Invoice ─── */

.inv-a4 {
  background: #fff;
  color: #1a1a1a;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.inv-a4-inner {
  padding: 40px;
  font-family: 'Satoshi', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  --inv-accent: #d4f522;
}

/* A4 Header */
.inv-a4-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 3px solid var(--inv-accent);
}

.inv-a4-logo {
  max-height: 48px;
  margin-bottom: 8px;
}
.inv-a4-shop-name {
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 20px;
  font-weight: 800;
  color: #111;
  margin-bottom: 4px;
}
.inv-a4-shop-line { font-size: 11px; color: #666; line-height: 1.6; }

.inv-a4-meta { text-align: right; }
.inv-a4-type {
  font-family: 'Cabinet Grotesk', sans-serif;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #111;
  margin-bottom: 8px;
}
.inv-a4-meta-table { margin-left: auto; }
.inv-a4-meta-table td {
  padding: 2px 0;
  font-size: 12px;
}
.inv-a4-meta-table td:first-child {
  color: #888;
  padding-right: 14px;
  text-align: right;
}
.inv-a4-meta-table td:last-child {
  font-weight: 600;
  color: #333;
}
.inv-a4-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.inv-a4-status-paid { background: #dcfce7; color: #16a34a; }
.inv-a4-status-unpaid { background: #fef2f2; color: #dc2626; }
.inv-a4-status-partial { background: #fef9c3; color: #ca8a04; }
.inv-a4-status-draft { background: #f3f4f6; color: #6b7280; }
.inv-a4-status-quote { background: #eff6ff; color: #2563eb; }

/* A4 Details */
.inv-a4-details {
  display: flex;
  gap: 32px;
  margin-bottom: 24px;
}
.inv-a4-detail-col { flex: 1; }
.inv-a4-detail-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #999;
  margin-bottom: 6px;
}
.inv-a4-detail-name {
  font-size: 15px;
  font-weight: 700;
  color: #111;
  margin-bottom: 2px;
}
.inv-a4-detail-line { font-size: 12px; color: #555; line-height: 1.6; }

/* A4 Table */
.inv-a4-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}
.inv-a4-table thead {
  background: #f8f8f6;
}
.inv-a4-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #888;
  border-bottom: 2px solid #eee;
}
.inv-a4-th-num { width: 36px; }
.inv-a4-th-qty { width: 50px; text-align: center !important; }
.inv-a4-th-price,
.inv-a4-th-total { width: 90px; text-align: right !important; }
.inv-a4-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
}
.inv-a4-table td:nth-child(3) { text-align: center; }
.inv-a4-table td:nth-child(4),
.inv-a4-table td:nth-child(5) {
  text-align: right;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
}
.inv-a4-line-desc { font-size: 11px; color: #888; }

/* A4 Totals */
.inv-a4-totals {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
}
.inv-a4-totals-inner { width: 250px; }
.inv-a4-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  color: #666;
}
.inv-a4-total-row span:last-child {
  font-family: 'DM Mono', monospace;
  font-weight: 500;
}
.inv-a4-total-row.grand {
  font-size: 18px;
  font-weight: 800;
  font-family: 'Cabinet Grotesk', sans-serif;
  color: #111;
  padding-top: 8px;
  margin-top: 6px;
  border-top: 2px solid #222;
}
.inv-a4-total-row.grand span:last-child {
  font-family: 'Cabinet Grotesk', sans-serif;
}
.inv-a4-total-row.balance { font-weight: 700; color: #ca8a04; }

/* A4 Footer */
.inv-a4-footer {
  padding-top: 16px;
  border-top: 1px solid #eee;
  font-size: 11px;
  color: #888;
  line-height: 1.7;
}
.inv-a4-footer-line { margin-bottom: 2px; }
.inv-a4-footer strong { color: #555; }

.inv-a4-brand {
  text-align: center;
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
  font-size: 10px;
  color: #ccc;
  letter-spacing: 0.5px;
}

/* ─── Responsive ─── */

@media (max-width: 1024px) {
  .inv-editor-body { flex-direction: column; }
  .inv-form-wrap {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    overflow-y: visible;
  }
  .inv-preview-pane { display: none; }
  .inv-mobile-save { display: flex; }
}

@media (max-width: 768px) {
  .inv-top-right { display: none; }
  .inv-top-bar { padding: 10px 14px; }
  .inv-form-wrap { padding: 14px; }
  .inv-section .form-row { flex-direction: column; gap: 0; }
  .inv-section .form-row > * { flex: none; }
  .inv-page-title { font-size: 14px; }

  .inv-print-page { padding: 12px; }
  .inv-a4-inner { padding: 20px; }
  .inv-a4-header { flex-direction: column; gap: 12px; }
  .inv-a4-meta { text-align: left; }
  .inv-a4-meta-table { margin-left: 0; }
  .inv-a4-type { font-size: 18px; }
  .inv-a4-details { flex-direction: column; gap: 14px; }
}

/* ─── Print Styles ─── */

@media print {
  * { box-shadow: none !important; }
  body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .sidebar, .mobile-nav, .page-header, .toast,
  .no-print, .inv-print-actions {
    display: none !important;
  }

  .main { margin: 0 !important; padding: 0 !important; }
  .page-content { padding: 0 !important; overflow: visible !important; }

  .inv-a4 {
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  .inv-a4-inner { padding: 20mm 15mm; }

  .inv-a4-header { border-bottom-color: #222 !important; }
  .inv-a4-total-row.grand { border-top-color: #222 !important; }

  .inv-a4-brand { color: #ccc; }

  @page {
    size: A4;
    margin: 0;
  }
}
