/* ============================================================
   Invoice Maker — invoice-maker.css
   Scoped to .qm-wrap — zero global pollution
   ============================================================ */

/* ── Layout ──────────────────────────────────────────────── */
.qm-wrap {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #2d3748;
  max-width: 1100px;
  margin: 0 auto;
}

.qm-form {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 8px rgba(0,0,0,.08);
  padding: 24px;
}

/* ── Top row: left + right cols ──────────────────────────── */
.qm-row-top {
  display: flex;
  gap: 16px;
}
.qm-left-col  { flex: 1; }
.qm-right-col { width: 340px; flex-shrink: 0; }
.qm-mt { margin-top: 12px; }

/* ── Fields ──────────────────────────────────────────────── */
.qm-field-box { position: relative; }

.qm-float-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #718096;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.qm-input,
.qm-select,
.qm-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  font-size: 14px;
  color: #2d3748;
  background: #f7fafc;
  transition: border-color .18s, background .18s;
  font-family: inherit;
  resize: none;
}
.qm-input:focus,
.qm-select:focus,
.qm-textarea:focus {
  outline: none;
  border-color: #5b9bd5;
  background: #fff;
}
.qm-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23718096' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

/* ── Logo box ────────────────────────────────────────────── */
.qm-logo-box {
  position: relative;
  width: 100%;
  height: 120px;
  border: 2px dashed #cbd5e0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  background: #f7fafc;
  transition: border-color .2s;
}
.qm-logo-box:hover { border-color: #5b9bd5; }
.qm-logo-box.qm-drag-over { border-color: #5b9bd5; background: #ebf4ff; }

.qm-logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #5b9bd5;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
}

.qm-logo-remove {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,.45);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 12px;
  cursor: pointer;
  line-height: 22px;
  text-align: center;
  padding: 0;
}

/* ── Line items ──────────────────────────────────────────── */
.qm-items-section { margin-top: 24px; }

.qm-items-head,
.qm-item-row {
  display: grid;
  grid-template-columns: 1fr 120px 90px 100px 32px;
  gap: 8px;
  align-items: center;
}

.qm-items-head {
  background: #4a6fa5;
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px 6px 0 0;
  font-size: 13px;
  font-weight: 600;
}
.qm-items-head span { display: block; }
.qm-col-price, .qm-col-qty, .qm-col-amount { text-align: right; }

.qm-item-row {
  padding: 6px 8px;
  border-bottom: 1px solid #edf2f7;
}
.qm-item-row:last-child { border-bottom: none; }

/* Item inputs */
.qm-item-desc,
.qm-item-price,
.qm-item-qty {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1.5px solid #e2e8f0;
  border-radius: 5px;
  font-size: 13.5px;
  color: #2d3748;
  background: #f7fafc;
  font-family: inherit;
}
.qm-item-desc:focus,
.qm-item-price:focus,
.qm-item-qty:focus { outline: none; border-color: #5b9bd5; background: #fff; }

/* Price has currency prefix */
.qm-price-wrap { position: relative; }
.qm-price-sym {
  position: absolute;
  left: 8px; top: 50%;
  transform: translateY(-50%);
  color: #718096;
  font-size: 13px;
  pointer-events: none;
}
.qm-price-wrap .qm-item-price { padding-left: 22px; }

.qm-item-price,
.qm-item-qty { text-align: right; }

.qm-item-amount {
  text-align: right;
  font-weight: 600;
  color: #2d3748;
  font-size: 13.5px;
}

.qm-item-del {
  background: none;
  border: none;
  color: #cbd5e0;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color .15s;
}
.qm-item-del:hover { color: #e53e3e; }

.qm-btn-add-item {
  margin-top: 10px;
  background: #4a6fa5;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 20px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
.qm-btn-add-item:hover { opacity: .85; }

/* ── Bottom: Notes + Totals ──────────────────────────────── */
.qm-bottom-row {
  display: flex;
  gap: 24px;
  margin-top: 24px;
  align-items: flex-start;
}
.qm-notes-col  { flex: 1; }
.qm-totals-col { width: 280px; flex-shrink: 0; }
.qm-notes { width: 100%; box-sizing: border-box; }

/* Totals */
.qm-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #edf2f7;
  font-size: 14px;
  color: #4a5568;
}
.qm-total-row:last-child { border-bottom: none; }

.qm-balance-row {
  font-size: 18px;
  font-weight: 700;
  color: #2d3748;
  padding-top: 12px;
  margin-top: 4px;
}

/* Addon toggles */
.qm-addon-toggle { cursor: pointer; }
.qm-addon-toggle:hover .qm-addon-label { color: #5b9bd5; }
.qm-addon-label { color: #5b9bd5; font-weight: 600; font-size: 13.5px; }

.qm-addon-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #edf2f7;
}
.qm-addon-input {
  width: 80px;
  padding: 6px 8px;
  border: 1.5px solid #e2e8f0;
  border-radius: 5px;
  font-size: 13px;
  text-align: right;
  background: #f7fafc;
}
.qm-addon-input:focus { outline: none; border-color: #5b9bd5; background: #fff; }
.qm-addon-pct  { color: #718096; font-size: 13px; }
.qm-addon-amt  { margin-left: auto; font-weight: 600; color: #2d3748; }

/* ── Sidebar ─────────────────────────────────────────────── */
.qm-sidebar {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 20px;
}

.qm-btn-download {
  background: #4a6fa5;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: opacity .2s;
}
.qm-btn-download:hover { opacity: .88; }

.qm-btn-preview,
.qm-btn-print,
.qm-btn-reset {
  background: #fff;
  color: #4a5568;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: border-color .2s, color .2s;
}
.qm-btn-preview:hover,
.qm-btn-print:hover   { border-color: #5b9bd5; color: #5b9bd5; }
.qm-btn-reset:hover   { border-color: #e53e3e; color: #e53e3e; }

/* ── Preview Modal ───────────────────────────────────────── */
.qm-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.qm-preview-modal {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
}

.qm-preview-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}

.qm-btn-close {
  margin-left: auto;
  background: #f7fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: #4a5568;
}
.qm-btn-close:hover { border-color: #e53e3e; color: #e53e3e; }

/* ── Preview Document ────────────────────────────────────── */
.qm-doc { font-size: 13.5px; line-height: 1.6; color: #2d3748; }

.qm-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}
.qm-doc-logo    { max-width: 180px; max-height: 80px; object-fit: contain; }
.qm-doc-type    { font-size: 30px; font-weight: 800; color: #4a6fa5; letter-spacing: .03em; }
.qm-doc-right   { text-align: right; }
.qm-doc-meta    { font-size: 12.5px; color: #718096; margin-top: 6px; line-height: 1.9; }

.qm-doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
  background: #f7fafc;
  border-radius: 8px;
  padding: 16px;
}
.qm-doc-party-lbl  { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #a0aec0; margin-bottom: 4px; }
.qm-doc-party-name { font-weight: 700; font-size: 14px; }
.qm-doc-party-addr { font-size: 12.5px; color: #718096; white-space: pre-line; margin-top: 2px; }

.qm-doc-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.qm-doc-table th {
  background: #4a6fa5; color: #fff;
  padding: 9px 12px; text-align: left;
  font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.qm-doc-table th.r, .qm-doc-table td.r { text-align: right; }
.qm-doc-table td { padding: 9px 12px; border-bottom: 1px solid #edf2f7; font-size: 13.5px; }
.qm-doc-table tr:nth-child(even) td { background: #f7fafc; }

.qm-doc-totals { max-width: 260px; margin-left: auto; margin-bottom: 20px; }
.qm-doc-total-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; font-size: 13.5px; color: #4a5568;
  border-bottom: 1px solid #edf2f7;
}
.qm-doc-total-balance {
  font-size: 17px; font-weight: 700; color: #2d3748;
  padding-top: 10px; border-bottom: none;
}

.qm-doc-notes {
  background: #f7fafc;
  border-left: 3px solid #5b9bd5;
  border-radius: 4px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: #4a5568;
  white-space: pre-line;
  margin-top: 8px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 700px) {
  .qm-wrap      { flex-direction: column; }
  .qm-sidebar   { width: 100%; flex-direction: row; flex-wrap: wrap; position: static; }
  .qm-row-top   { flex-direction: column; }
  .qm-right-col { width: 100%; }
  .qm-items-head, .qm-item-row { grid-template-columns: 1fr 90px 70px 80px 28px; }
  .qm-bottom-row { flex-direction: column; }
  .qm-totals-col { width: 100%; }
}

/* ── Print ───────────────────────────────────────────────── */
@media print {
  .qm-form, .qm-sidebar, .qm-preview-actions { display: none !important; }
  .qm-preview-overlay { position: static !important; background: none !important; padding: 0 !important; }
  .qm-preview-modal   { box-shadow: none !important; max-height: none !important; padding: 0 !important; }
}
