/* ---------- App shell ---------- */
:root {
  --ink: #1c2130;
  --grey: #5e6472;
  --line: #e3e5ec;
  --card: #f2f3f7;
  --app-bg: #e9ebf0;
  --panel: #ffffff;
  --danger: #c0392b;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--app-bg);
  -webkit-font-smoothing: antialiased;
}

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.bar-title { font-weight: 700; font-size: 16px; white-space: nowrap; }
.bar-actions { display: flex; gap: 8px; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 999px; padding: 10px 16px;
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn.dark { background: var(--ink); color: #fff; }
.btn.dark:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--card); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); }

.tabs { display: none; }

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 440px) 1fr;
  align-items: start;
}

/* ---------- Form ---------- */
.form {
  height: calc(100vh - 61px);
  overflow-y: auto;
  padding: 16px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.sec {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  margin-bottom: 12px;
}
.sec[open] { padding-bottom: 14px; }
.sec summary {
  cursor: pointer; font-weight: 600; font-size: 15px;
  padding: 14px 0; list-style: none;
  display: flex; justify-content: space-between;
}
.sec summary::-webkit-details-marker { display: none; }
.sec summary::after { content: "+"; color: var(--grey); font-weight: 400; }
.sec[open] summary::after { content: "−"; }

label { display: block; font-size: 12px; font-weight: 500; color: var(--grey); margin-bottom: 10px; }
input, textarea, select {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; font-size: 16px; color: var(--ink);
  padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff;
}
textarea { resize: vertical; line-height: 1.4; }
input[type="color"] { height: 42px; padding: 3px; }
input:focus, textarea:focus, select:focus { outline: 2px solid #9aa3b8; outline-offset: 0; border-color: transparent; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); align-self: end; padding-bottom: 10px; }
label.check input { width: auto; margin: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { font-size: 12px; color: var(--grey); margin: 0 0 10px; line-height: 1.45; }

.item {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 10px 0; margin-bottom: 10px; background: #fafbfc;
}
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--grey); }
.x { border: 0; background: none; color: var(--danger); font: inherit; font-size: 12px; cursor: pointer; padding: 4px; }
.bank-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; align-items: end; }
.bank-row label { margin-bottom: 8px; }
.bank-row .x { margin-bottom: 14px; }

.sums { background: var(--card); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.sums div { display: flex; justify-content: space-between; padding: 3px 0; }
.sums div:last-child { font-weight: 700; }

.upload { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.upload img { height: 44px; max-width: 120px; object-fit: contain; background: var(--card); border-radius: 8px; padding: 4px; }
.upload img:not([src]), .upload img[src=""] { display: none; }

/* ---------- Preview ---------- */
.preview { padding: 24px; height: calc(100vh - 61px); overflow-y: auto; }
.stage { position: relative; margin: 0 auto; max-width: 794px; }
.paper {
  width: 794px; min-height: 1123px;
  background: #fff;
  transform-origin: top left;
  box-shadow: 0 8px 30px rgba(28, 33, 48, .12);
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; font-size: 14px;
  padding: 12px 18px; border-radius: 12px; max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Phone and small tablet ---------- */
@media (max-width: 860px) {
  .bar-title { font-size: 15px; }
  .bar .btn { padding: 9px 12px; font-size: 13px; }
  .tabs {
    display: flex; gap: 4px; padding: 8px 16px;
    background: var(--panel); border-bottom: 1px solid var(--line);
    position: sticky; top: 59px; z-index: 9;
  }
  .tab {
    flex: 1; font: inherit; font-size: 14px; font-weight: 600;
    padding: 8px; border-radius: 999px; border: 0; background: transparent; color: var(--grey);
  }
  .tab.on { background: var(--card); color: var(--ink); }
  .layout { display: block; }
  .form, .preview { height: auto; overflow: visible; border: 0; }
  .preview { padding: 16px; }
  body[data-tab="form"] .preview { display: none; }
  body[data-tab="preview"] .form { display: none; }
}
@media (max-width: 400px) {
  .bar-title { display: none; }
  .bar-actions { width: 100%; }
  .bar-actions .btn { flex: 1; }
  .grid2 { grid-template-columns: 1fr; }
}

/* =========================================================
   The invoice itself. Sized to A4 (794 x 1123 px).
   Measurements copied from the original template.
   ========================================================= */
.inv {
  width: 794px;
  padding: 20px 21px 16px;
  font-family: Inter, sans-serif;
  font-size: 13.2px;
  line-height: 1.55;
  color: #1c2130;
  background: #fff;
}
.inv .card {
  background: #f2f3f7;
  border-radius: 26px;
  padding: 18px 21px;
  margin-bottom: 14px;
  break-inside: avoid;
  page-break-inside: avoid;
}
.inv .card:last-child { margin-bottom: 0; }
.inv .two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.inv .two .card { margin-bottom: 0; }
.inv b, .inv .strong { font-weight: 600; color: #1c2130; }
.inv .muted { color: #5e6472; }

.inv .card.head { padding: 14px 21px; }
.inv .head { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: 16px; }
.inv .head .right { display: flex; gap: 18px; }

.inv .party { padding: 18px 21px 18px; }
.inv .party .label { font-weight: 600; margin-bottom: 7px; color: #1c2130 !important; }
.inv .party .name { font-weight: 600; color: #5e6472; margin-bottom: 2px; }
.inv .party div { color: #5e6472; }

.inv .ref { font-size: 19px; color: #5e6472; padding: 13px 21px; }

.inv .table { padding: 44px 21px 40px; }
.inv .t-head { display: flex; justify-content: space-between; font-weight: 600; padding-bottom: 10px; border-bottom: 3px solid #fff; }
.inv .t-row { display: flex; justify-content: space-between; gap: 24px; padding: 12px 0 11px; border-bottom: 2px solid #fff; }
.inv .t-row:last-of-type { border-bottom-width: 3px; }
.inv .t-row .title { font-weight: 600; }
.inv .t-row .desc { color: #5e6472; margin-top: 3px; white-space: pre-line; }
.inv .t-row .amt { color: #5e6472; white-space: nowrap; }
.inv .totals { margin-left: auto; width: 290px; }
.inv .totals div { display: flex; justify-content: space-between; padding: 11px 0 10px; border-bottom: 2px solid #fff; }
.inv .totals div:last-child { border-bottom: 0; padding-bottom: 0; }
.inv .totals span:first-child { font-weight: 600; }
.inv .totals span:last-child { color: #5e6472; }
.inv .totals .due span { font-weight: 700; color: #1c2130; }

.inv .sign { text-align: center; padding: 16px 21px 18px; }
.inv .sign .sig { height: 46px; display: flex; align-items: flex-end; justify-content: center; }
.inv .sign .sig img { max-height: 46px; max-width: 220px; object-fit: contain; }
.inv .sign .rule { width: 290px; margin: 6px auto 8px; border-top: 2px solid #fff; }
.inv .sign .who { color: #5e6472; }
.inv .sign .role { font-weight: 600; margin-top: 4px; }

.inv .notes .t { font-weight: 600; margin-bottom: 6px; }
.inv .notes ol { margin: 0; padding: 0; list-style: none; color: #5e6472; }
.inv .bank { display: grid; grid-template-columns: auto 1fr; column-gap: 28px; row-gap: 3px; align-content: center; }
.inv .bank .k { font-weight: 600; }
.inv .bank .v { color: #5e6472; word-break: break-word; }

.inv .foot { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: 16px; padding: 12px 21px; }
.inv .foot .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.inv .foot .brand img { max-height: 30px; max-width: 120px; object-fit: contain; }
.inv .foot .contact { display: flex; align-items: center; gap: 14px; color: #5e6472; white-space: nowrap; }
.inv .foot .pipe { width: 1px; height: 18px; background: #d5d8e0; }
