/* ============================================================
   invoice generator — style
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: #1e293b;
  background: #f1f5f9;
  padding: 0 0 80px;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { margin: 0; }
:focus-visible { outline: 2px solid #10b981; outline-offset: 2px; border-radius: 4px; }

/* ============================================================
   NAVIGATION
   ============================================================ */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
  margin-bottom: 24px;
}
.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
}
.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  color: #0f172a;
  text-decoration: none;
  flex-shrink: 0;
}
.nav-brand:hover { text-decoration: none; }
.nav-mark {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #10b981, #6366f1);
  color: #fff;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 15px;
}
.nav-menu {
  display: flex;
  align-items: center;
  gap: 2px;
}
.nav-menu a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  color: #475569;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color .15s, color .15s;
  white-space: nowrap;
}
.nav-menu a:hover { background: #f1f5f9; color: #0f172a; text-decoration: none; }
.nav-menu a.active { background: #ecfdf5; color: #059669; }

.nav-hamburger {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 40px; height: 40px;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
  background: #fff;
  padding: 0;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-hamburger span {
  display: block;
  width: 18px; height: 2px;
  background: #0f172a;
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.nav-hamburger.is-open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-hamburger.is-open span:nth-child(2) { opacity: 0; }
.nav-hamburger.is-open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
  text-align: center;
}

/* ============================================================
   PAPER
   ============================================================ */
.paper {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 12px 40px -16px rgba(15, 23, 42, .18);
  padding: 40px 44px;
  text-align: left;
}

/* Inputs inside paper */
.paper input[type="text"],
.paper input[type="date"],
.paper input[type="number"],
.paper textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 9px 12px;
  background: #ffffff;
  color: #0f172a;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
.paper input:focus,
.paper textarea:focus {
  outline: none;
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .15);
}
.paper textarea {
  resize: vertical;
  min-height: 70px;
  font-family: inherit;
  line-height: 1.45;
}
.paper input[type="number"] { -moz-appearance: textfield; }
.paper input[type="number"]::-webkit-outer-spin-button,
.paper input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ============================================================
   HEADER: Logo + INVOICE
   ============================================================ */
.head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 32px;
}

.logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 230px;
  height: 120px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, background-color .15s;
  flex-shrink: 0;
}
.logo-box:hover { border-color: #10b981; background: #f0fdf9; }
.logo-placeholder {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #64748b;
  font-size: 15px;
}
.logo-placeholder .plus { font-size: 22px; font-weight: 300; line-height: 1; color: #94a3b8; }
#logoPreview { width: 100%; height: 100%; object-fit: contain; }

.head-right { text-align: right; flex-shrink: 0; }
.inv-title {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: .02em;
  color: #0f172a;
  margin: 0 0 10px;
  line-height: 1;
}
.inv-num {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 10px;
  background: #fff;
  min-width: 110px;
}
.inv-num span { color: #64748b; font-size: 14px; }
.inv-num input {
  border: 0 !important;
  padding: 4px 0 !important;
  text-align: right;
  font-weight: 600;
  font-size: 14px;
  background: transparent !important;
  box-shadow: none !important;
}

/* ============================================================
   FROM + DATES
   ============================================================ */
.from-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 26px;
}
.from-input { min-height: 90px !important; }

.dates { display: grid; gap: 8px; }
.d-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #334155;
}
.d-row input { padding: 7px 10px; font-size: 13px; }

/* ============================================================
   BILL TO / SHIP TO
   ============================================================ */
.parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 26px;
}
.party label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
}
.party textarea { min-height: 80px !important; }

/* ============================================================
   ITEMS TABLE
   ============================================================ */
.items-wrap { margin-bottom: 0; }
.items {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
.items thead th {
  background: #0f172a;
  color: #ffffff;
  font-weight: 600;
  font-size: 13px;
  text-align: left;
  padding: 11px 14px;
  white-space: nowrap;
}
.items thead th:first-child { border-radius: 6px 0 0 6px; }
.items thead th:last-child { border-radius: 0 6px 6px 0; text-align: right; }
.items th.col-qty { width: 90px; }
.items th.col-rate { width: 130px; }
.items th.col-amt { width: 140px; text-align: right; }

.items tbody td {
  padding: 8px 6px 8px 0;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}
.items tbody td:first-child { padding-left: 0; }
.items tbody input {
  border: 0 !important;
  padding: 6px 4px !important;
  background: transparent !important;
  font-size: 13.5px;
  box-shadow: none !important;
  border-radius: 0 !important;
}
.items tbody input:focus { box-shadow: 0 0 0 0 transparent !important; border-bottom: 2px solid #10b981 !important; }
.items .cell-desc input { width: 100%; }
.items .cell-qty input,
.items .cell-rate input { text-align: center; }
.items .cell-amt {
  text-align: right;
  padding-right: 4px;
  font-variant-numeric: tabular-nums;
  color: #0f172a;
  font-weight: 500;
  white-space: nowrap;
}
.items .cell-del { width: 34px; text-align: center; padding: 0; }
.del-btn {
  width: 26px; height: 26px;
  border: 0; background: transparent;
  color: #94a3b8;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, background-color .15s;
}
.del-btn:hover { color: #ef4444; background: #fee2e2; }

.add-line {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  border: 0;
  border-radius: 6px;
  background: #f1f5f9;
  color: #334155;
  font-size: 13.5px;
  font-weight: 500;
  text-align: center;
  transition: background-color .15s, color .15s;
}
.add-line:hover { background: #e2e8f0; color: #0f172a; }
.add-line span { color: #64748b; margin-right: 4px; font-size: 16px; }

/* ============================================================
   NOTES/TERMS + TOTALS
   ============================================================ */
.bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-top: 32px;
}

.left-col label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
}
.left-col label:not(:first-child) { margin-top: 16px; }
.left-col textarea { font-size: 13px; }

.right-col { padding-top: 6px; }
.t-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: 14px;
  color: #334155;
}
.t-label { font-weight: 400; }
.t-value {
  font-variant-numeric: tabular-nums;
  color: #0f172a;
  font-weight: 500;
  text-align: right;
}
.t-row.t-total,
.t-row.t-due {
  border-top: 1px solid #e2e8f0;
  padding-top: 12px;
  margin-top: 6px;
  font-size: 16px;
  color: #0f172a;
}
.t-row.t-total .t-label,
.t-row.t-total .t-value,
.t-row.t-due .t-label,
.t-row.t-due .t-value { font-weight: 700; }
.t-row.t-total { border-top: 0; margin-top: 0; padding-top: 8px; }

/* Tax row */
.t-tax { display: inline-flex; align-items: center; gap: 6px; }
.t-tax input {
  width: 52px !important;
  text-align: right;
  padding: 5px 8px !important;
  font-size: 13.5px;
}
.pct { color: #64748b; font-size: 13px; }
.refresh {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 5px;
  color: #64748b;
  transition: color .15s, border-color .15s;
}
.refresh:hover { color: #10b981; border-color: #10b981; }

/* Discount / Shipping links */
.extra-links { display: flex; gap: 20px; padding: 6px 0; }
.link-btn {
  border: 0;
  background: transparent;
  color: #10b981;
  font-size: 13.5px;
  font-weight: 600;
  padding: 4px 0;
}
.link-btn:hover { color: #059669; text-decoration: underline; }

/* Hidden rows */
.t-row.hidden { display: none; }

.inline-num {
  width: 44px !important;
  padding: 3px 6px !important;
  font-size: 12px !important;
  margin-left: 6px;
  text-align: right;
}
.pct-sm { color: #64748b; font-size: 12px; margin-left: 3px; }
.inline-amt {
  width: 110px !important;
  padding: 5px 8px !important;
  text-align: right;
  font-size: 13px !important;
}
.remove-x {
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 12px;
  margin-left: 6px;
  padding: 2px 4px;
  border-radius: 4px;
}
.remove-x:hover { color: #ef4444; background: #fee2e2; }

/* Amount Paid */
.paid-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 10px;
  background: #fff;
  min-width: 130px;
  justify-content: space-between;
}
.currency-sym { color: #64748b; font-size: 13px; }
.paid-wrap input {
  border: 0 !important;
  padding: 2px 0 !important;
  width: 70px !important;
  text-align: right;
  background: transparent !important;
  box-shadow: none !important;
  font-size: 13.5px;
}

/* ============================================================
   ACTION BUTTONS
   ============================================================ */
.save-send {
  display: block;
  width: 100%;
  max-width: 900px;
  margin: 22px auto 0;
  padding: 16px;
  border: 0;
  border-radius: 6px;
  background: #10b981;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .01em;
  transition: background-color .15s;
  box-shadow: 0 4px 14px -6px rgba(16, 185, 129, .6);
}
.save-send:hover { background: #059669; }
.save-send:active { transform: translateY(1px); }

.download {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 18px auto 0;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: #10b981;
  font-size: 14px;
  font-weight: 600;
}
.download:hover { color: #059669; text-decoration: underline; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 24px);
  background: #0f172a;
  color: #fff;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 999;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #059669; }
.toast.err { background: #dc2626; }

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 720px) {
  body { padding-bottom: 60px; }
  .nav-inner { padding: 0 12px; min-height: 54px; }
  .nav-hamburger { display: flex; }
  .nav-menu {
    position: absolute;
    left: 0; right: 0;
    top: 100%;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .1);
    flex-direction: column;
    align-items: stretch;
    padding: 8px;
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease, opacity .2s;
    opacity: 0;
    gap: 2px;
  }
  .nav-menu.is-open {
    max-height: 400px;
    opacity: 1;
    overflow-y: auto;
  }
  .nav-menu a { padding: 12px 14px; font-size: 15px; }

  .app { padding: 0 10px; }
  .paper { padding: 22px 18px; border-radius: 6px; }

  .head { gap: 16px; margin-bottom: 22px; }
  .logo-box { width: 130px; height: 84px; }
  .logo-placeholder { font-size: 13px; gap: 5px; }
  .logo-placeholder .plus { font-size: 18px; }
  .inv-title { font-size: 26px; margin-bottom: 8px; }
  .inv-num { min-width: 90px; padding: 3px 8px; }
  .inv-num span { font-size: 13px; }
  .inv-num input { font-size: 13px; }

  .from-dates { grid-template-columns: 1fr; gap: 16px; margin-bottom: 20px; }
  .from-input { min-height: 70px !important; }
  .d-row { grid-template-columns: 100px 1fr; font-size: 12.5px; }

  .parties { grid-template-columns: 1fr; gap: 16px; margin-bottom: 20px; }
  .party textarea { min-height: 66px !important; }

  .items { font-size: 12.5px; }
  .items thead th { padding: 9px 8px; font-size: 11.5px; }
  .items th.col-qty { width: 55px; }
  .items th.col-rate { width: 70px; }
  .items th.col-amt { width: 80px; }
  .items tbody input { font-size: 12.5px; padding: 5px 3px !important; }
  .items .cell-amt { font-size: 12.5px; }

  .add-line { font-size: 13px; padding: 10px; }

  .bottom { grid-template-columns: 1fr; gap: 20px; margin-top: 22px; }
  .left-col textarea { min-height: 60px !important; font-size: 12.5px; }
  .t-row { font-size: 13.5px; padding: 7px 0; }
  .t-row.t-total, .t-row.t-due { font-size: 15px; }

  .paid-wrap { min-width: 110px; padding: 3px 8px; }
  .paid-wrap input { width: 55px !important; font-size: 13px; }

  .save-send { padding: 14px; font-size: 14.5px; margin-top: 18px; }
  .download { font-size: 13.5px; }
}

@media (max-width: 420px) {
  .paper { padding: 18px 14px; }
  .head { flex-direction: column; align-items: stretch; gap: 12px; }
  .head-right { text-align: left; }
  .inv-title { font-size: 22px; }
  .inv-num { align-self: flex-start; }
  .logo-box { width: 100%; height: 90px; }
  .items th.col-item,
  .items td.cell-desc { font-size: 12px; }
}

/* ============================================================
   PRINT — only the invoice paper
   ============================================================ */
@media print {
  @page { size: A4; margin: 12mm; }

  html, body {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 11pt;
  }
  .no-print,
  .toast,
  .save-send,
  .download,
  .site-nav { display: none !important; }

  .app { max-width: 100%; margin: 0; padding: 0; text-align: left; }
  .paper {
    box-shadow: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
    max-width: 100%;
  }

  .paper input,
  .paper textarea {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    color: #000 !important;
    resize: none;
    overflow: visible;
    height: auto !important;
    min-height: 0 !important;
    font-size: 11pt;
  }
  .paper textarea { white-space: pre-wrap; word-break: break-word; }
  .inv-num,
  .paid-wrap {
    border: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    min-width: 0 !important;
  }
  .inv-num input,
  .paid-wrap input {
    text-align: right;
    width: auto !important;
    display: inline !important;
  }
  .refresh,
  .remove-x,
  .del-btn,
  .add-line,
  .extra-links,
  .link-btn { display: none !important; }
  .t-row.hidden { display: none !important; }

  .items thead th {
    background: #0f172a !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .items tbody input { text-align: left !important; }
  .items .cell-qty input,
  .items .cell-rate input { text-align: center !important; }
  .items .cell-amt { padding-right: 0 !important; }

  .head { margin-bottom: 20pt; }
  .inv-title { font-size: 26pt; }
  .bottom { margin-top: 22pt; page-break-inside: avoid; }
  .items-wrap { page-break-inside: auto; }
  .items tbody tr { page-break-inside: avoid; }
}