* { box-sizing: border-box; }

html, body { min-height: 100%; }

:root {
  --navy: #001051;
  --blue: #1B4F93;
  --ink: #243456;
  --muted: #637089;
  --soft: #7b869c;
  --line: #d5dcea;
  --line-soft: #e6ebf4;
  --focus: rgba(27, 79, 147, 0.16);
  --font: 'Inter Tight', 'Segoe UI', Arial, Helvetica, sans-serif;
}

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, rgba(27, 79, 147, 0.16), transparent 32%),
    linear-gradient(180deg, #f3f7ff 0%, #e7edf8 100%);
  background-attachment: fixed;
  color: var(--navy);
  min-height: 100vh;
  padding: 28px 24px 48px;
}

.wrap {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
}

/* ---------- Top bar & hero ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 30px;
}

.topbar-logo img {
  height: 34px;
  width: auto;
  display: block;
}

.saved {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid rgba(27, 79, 147, 0.12);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  box-shadow: 0 8px 30px rgba(0, 16, 81, 0.06);
}

.saved::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22a55a;
  box-shadow: 0 0 0 3px rgba(34, 165, 90, 0.16);
}

.saved.is-error { color: #b42318; }
.saved.is-error::before { background: #d92d20; box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.16); }

.hero { margin-bottom: 26px; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid rgba(27, 79, 147, 0.12);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 16px;
  box-shadow: 0 8px 30px rgba(0, 16, 81, 0.06);
}

.eyebrow img {
  height: 22px;
  width: 22px;
  border-radius: 6px;
  display: block;
}

h1 {
  margin: 0 0 8px;
  font-size: 36px;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--navy);
}

.sub {
  max-width: 760px;
  margin: 0;
  font-size: 17px;
  line-height: 1.65;
  color: #52607a;
}

/* ---------- Layout ---------- */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 470px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.96);
  border-radius: 28px;
  box-shadow: 0 24px 70px rgba(0, 16, 81, 0.10);
  backdrop-filter: blur(10px);
}

.form-card { padding: 10px; }

.preview-card {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  padding: 18px;
}

/* ---------- Form sections ---------- */

.sec {
  border-radius: 20px;
  transition: background 0.2s ease;
}

.sec + .sec { margin-top: 4px; }

.sec[open] { background: #f7f9fe; }

.sec > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px;
  cursor: pointer;
  border-radius: 20px;
  user-select: none;
}

.sec > summary::-webkit-details-marker { display: none; }

.sec > summary:hover { background: #f3f6fd; }
.sec[open] > summary:hover { background: transparent; }

.sec-num {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  background: var(--navy);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.sec-title {
  flex: 1;
  min-width: 0;
}

.sec-title b {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
}

.sec-title small {
  display: block;
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sec-chev {
  color: var(--soft);
  transition: transform 0.2s ease;
}

.sec[open] .sec-chev { transform: rotate(180deg); }

.sec-body { padding: 2px 16px 18px; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

#wiseFields { margin-bottom: 18px; }

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.row2 .field { margin-bottom: 14px; }

label,
.label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.req {
  margin-left: 2px;
  color: #d92d20;
  font-weight: 700;
}

label .opt,
.label .opt {
  font-weight: 500;
  color: var(--soft);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  font-size: 15px;
  color: var(--navy);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  font-family: var(--font);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
select {
  height: 46px;
  padding: 0 14px;
}

textarea {
  min-height: 84px;
  padding: 12px 14px;
  line-height: 1.5;
  resize: vertical;
}

input::placeholder,
textarea::placeholder { color: #a3adbf; }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--focus);
}

input:disabled,
select:disabled {
  background: #f1f4fa;
  color: #6d7890;
  cursor: not-allowed;
}

input.is-invalid,
textarea.is-invalid {
  border-color: #d92d20;
  box-shadow: 0 0 0 4px rgba(217, 45, 32, 0.12);
}

/* Windows has no flag emoji glyphs, so flags come from this font. */
@font-face {
  font-family: 'Twemoji Country Flags';
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
  src: url('https://cdn.jsdelivr.net/npm/country-flag-emoji-polyfill@0.1/dist/TwemojiCountryFlags.woff2') format('woff2');
  font-display: swap;
}

#invCurrency,
#invCurrency option {
  font-family: 'Twemoji Country Flags', var(--font);
}

select {
  background: #ffffff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23001051' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  padding-right: 34px;
  cursor: pointer;
  appearance: none;
}

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.hint {
  margin: 6px 2px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--soft);
}

.input-affix {
  position: relative;
}

.input-affix span {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  font-weight: 600;
  color: var(--soft);
  pointer-events: none;
}

.input-affix input { padding-right: 34px; }

.stepper {
  display: flex;
  align-items: stretch;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.stepper:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--focus);
}

.stepper input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 0;
  padding: 0 4px;
  text-align: center;
  font-weight: 600;
  box-shadow: none;
}

.stepper input[type="text"]:focus { box-shadow: none; }

.step-btn {
  width: 40px;
  flex: 0 0 40px;
  background: transparent;
  color: var(--navy);
  display: grid;
  place-items: center;
}

.step-btn:first-child { border-radius: 13px 0 0 13px; border-right: 1px solid var(--line-soft); }
.step-btn:last-child { border-radius: 0 13px 13px 0; border-left: 1px solid var(--line-soft); }
.step-btn:hover { background: #eef2fb; }
.step-btn svg { display: block; }

.period-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.period-head .label { margin: 0; }

.period-chips { display: flex; gap: 6px; }

.period-chips .chip { height: 30px; padding: 0 12px; font-size: 12.5px; }

.number-hint { margin: -6px 2px 16px; }

.prorate-box {
  margin-bottom: 14px;
  padding: 14px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.prorate-box .field { margin-bottom: 0; }

.prorate-full {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 12px;
  background: #f2f5fb;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

label.sub-label {
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--soft);
}

.split {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
}

/* ---------- Buttons ---------- */

button {
  font-family: var(--font);
  cursor: pointer;
  border: 0;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

button:disabled { cursor: progress; opacity: 0.7; }

.btn {
  height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn svg { display: block; flex: 0 0 auto; }

.btn-primary {
  background: var(--navy);
  color: #ffffff;
  box-shadow: 0 16px 35px rgba(0, 16, 81, 0.22);
}

.btn-primary:hover:not(:disabled) {
  background: #0a1f67;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #ffffff;
  color: var(--navy);
  border: 1px solid #c5d0e8;
}

.btn-secondary:hover:not(:disabled) {
  background: #f3f6fd;
  transform: translateY(-1px);
}

.btn-ghost {
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  background: transparent;
  color: var(--blue);
  font-size: 13px;
}

.btn-ghost:hover { background: #eef2fb; color: var(--navy); }

.btn-danger {
  background: #b42318;
  color: #ffffff;
  box-shadow: 0 12px 28px rgba(180, 35, 24, 0.22);
}

.btn-danger:hover { background: #912018; }

.btn-block { width: 100%; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #c5d0e8;
  color: var(--navy);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip:hover { background: #eef2fb; }

.chip img {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  display: block;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.icon-btn:hover { background: #eef2fb; color: var(--navy); }
.icon-btn.is-danger:hover { background: #fdecea; color: #b42318; }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }
.icon-btn svg { display: block; }

/* ---------- Logo upload ---------- */

.logo-drop {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 16px;
  border: 1.5px dashed #b9c5de;
  background: #ffffff;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.logo-drop:hover,
.logo-drop.is-over {
  border-color: var(--blue);
  background: #f3f6fd;
}

.logo-thumb {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  border-radius: 12px;
  background: #eef2fb;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--blue);
}

.logo-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.logo-copy { flex: 1; min-width: 0; }

.logo-copy b {
  display: block;
  font-size: 14px;
  color: var(--navy);
}

.logo-copy span {
  display: block;
  font-size: 12.5px;
  color: var(--soft);
  margin-top: 2px;
}

/* ---------- Line items ---------- */

.items { display: grid; gap: 10px; margin-bottom: 12px; }

.item {
  padding: 12px 12px 14px;
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid var(--line-soft);
  box-shadow: 0 4px 14px rgba(0, 16, 81, 0.04);
}

.item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.item-num {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
}

.item-actions { display: flex; gap: 2px; }

.item input[data-f="description"] { margin-bottom: 8px; font-weight: 600; }

.item textarea {
  min-height: 42px;
  height: 42px;
  margin-bottom: 10px;
  padding: 10px 14px;
  font-size: 14px;
}

.item-nums {
  display: grid;
  grid-template-columns: 0.8fr 0.9fr 1.1fr 1fr;
  gap: 8px;
  align-items: end;
}

.item .item-label,
.item-nums label {
  margin-bottom: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--soft);
}

.item-nums input { height: 42px; font-size: 14px; padding: 0 10px; }

.item-prorate {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--soft);
  cursor: pointer;
}

.item-prorate input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); }

.item-amount {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-item {
  width: 100%;
  height: 46px;
  border-radius: 14px;
  border: 1.5px dashed #b9c5de;
  background: transparent;
  color: var(--blue);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.add-item:hover { background: #ffffff; border-color: var(--blue); }

.totals-mini {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid var(--line-soft);
}

.totals-mini div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 13.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.totals-mini div b { color: var(--navy); font-weight: 600; }

.totals-mini .is-due {
  margin-top: 6px;
  padding-top: 9px;
  border-top: 1px solid var(--line-soft);
  font-size: 15px;
  color: var(--navy);
  font-weight: 700;
}

.totals-mini .is-due b { font-weight: 700; }

/* ---------- Toggles ---------- */

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  margin: 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  border-top: 1px solid var(--line-soft);
}

.toggle small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--soft);
}

.toggle input {
  appearance: none;
  width: 42px;
  height: 24px;
  flex: 0 0 42px;
  margin: 0;
  border-radius: 999px;
  background: #cfd7e6;
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
}

.toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 16, 81, 0.25);
  transition: transform 0.2s ease;
}

.toggle input:checked { background: var(--blue); }
.toggle input:checked::after { transform: translateX(18px); }
.toggle input:focus-visible { box-shadow: 0 0 0 4px var(--focus); }

/* ---------- Design pickers ---------- */

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.tpl-card {
  position: relative;
  margin: 0;
  cursor: pointer;
}

.tpl-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tpl-thumb {
  display: block;
  aspect-ratio: 0.77;
  border-radius: 12px;
  background: #ffffff;
  border: 1.5px solid var(--line);
  overflow: hidden;
  position: relative;
  padding: 10% 12%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tpl-card input:checked + .tpl-thumb {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--focus);
}

.tpl-card input:focus-visible + .tpl-thumb { box-shadow: 0 0 0 4px var(--focus); }

.tpl-name {
  display: block;
  margin-top: 7px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.tpl-thumb i {
  display: block;
  height: 5px;
  border-radius: 3px;
  background: #e3e8f1;
  margin-bottom: 6%;
}

.tpl-thumb .t-title { width: 45%; height: 8px; background: var(--tpl-accent, var(--blue)); margin-left: auto; }
.tpl-thumb .t-box { height: 14px; border-radius: 4px; background: var(--tpl-soft, #e8eef8); }
.tpl-thumb .t-head { height: 7px; background: var(--tpl-accent, var(--blue)); }
.tpl-thumb .t-short { width: 60%; }
.tpl-thumb .t-total { width: 45%; height: 8px; margin-left: auto; background: var(--tpl-accent, var(--blue)); }

.tpl-studio::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--tpl-accent, var(--blue));
}

.tpl-classic .t-title { background: #1d2939; margin-left: 0; }
.tpl-classic .t-head { background: transparent; border-top: 2px solid #1d2939; border-bottom: 1px solid #1d2939; border-radius: 0; height: 7px; }
.tpl-classic .t-box { background: transparent; border: 1px solid #e3e8f1; border-left: 3px solid var(--tpl-accent, var(--blue)); }
.tpl-classic .t-total { background: #1d2939; }

.tpl-bold .t-band {
  display: block;
  margin: -14% -14% 10%;
  height: 34%;
  background: var(--tpl-accent, var(--blue));
  border-radius: 0;
  padding: 12% 14%;
}

.tpl-bold .t-band::after {
  content: "";
  display: block;
  width: 50%;
  height: 8px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.85);
}

.tpl-bold .t-head { background: transparent; border-bottom: 2px solid var(--tpl-accent, var(--blue)); border-radius: 0; }

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  padding: 0;
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 1px var(--line);
}

.swatch:hover { transform: scale(1.08); }

.swatch.is-active { box-shadow: 0 0 0 2px var(--navy); }

.swatch-custom {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line);
  background: conic-gradient(#ef4444, #f59e0b, #22c55e, #06b6d4, #3b82f6, #a855f7, #ef4444);
  margin: 0;
  cursor: pointer;
}

.swatch-custom.is-active { box-shadow: 0 0 0 2px var(--navy); }

.swatch-custom input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: #e8edf7;
  margin-bottom: 14px;
}

.segmented label {
  margin: 0;
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #52607a;
  transition: 0.2s ease;
}

.segmented input:checked + span {
  background: #ffffff;
  color: var(--navy);
  box-shadow: 0 2px 8px rgba(0, 16, 81, 0.08);
}

.segmented input:focus-visible + span { box-shadow: 0 0 0 3px var(--focus); }

.privacy {
  display: flex;
  gap: 12px;
  margin: 10px 6px 6px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #eef3fc;
  font-size: 13px;
  line-height: 1.55;
  color: #52607a;
}

.privacy svg { flex: 0 0 auto; color: var(--blue); margin-top: 1px; }
.privacy b { color: var(--navy); }

/* ---------- Preview ---------- */

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 4px 14px;
}

.preview-title h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--navy);
}

.preview-title p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--soft);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar .btn-secondary { height: 42px; padding: 0 14px; font-size: 13.5px; }
.toolbar .btn-primary { height: 42px; padding: 0 18px; }

.stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-radius: 22px;
  border: 1px solid #d3dced;
  background:
    radial-gradient(circle at 12% 0%, rgba(27, 79, 147, 0.08), transparent 28%),
    linear-gradient(180deg, #e8eef8 0%, #dfe6f2 100%);
  padding: 24px;
}

.stage-inner {
  margin: 0 auto;
  position: relative;
}

.pages {
  transform-origin: top left;
  position: absolute;
  top: 0;
  left: 0;
}

.pages .page {
  box-shadow: 0 18px 50px rgba(0, 16, 81, 0.14);
  border-radius: 4px;
}

.pages .page + .page { margin-top: 28px; }

#measure {
  position: absolute;
  left: -100000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

#printRoot { display: none; }

/* ---------- Invoice page ---------- */

.page {
  --ink-strong: #0b1324;
  --ink-muted: #5b6678;
  --ink-soft: #8a94a6;
  --rule: #e6e9ef;
  position: relative;
  width: var(--pw);
  height: var(--ph);
  background: #ffffff;
  color: var(--ink-strong);
  font-family: var(--font);
  font-size: 12.5px;
  line-height: 1.5;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.page.is-measure { height: auto; }

.page-body { padding: var(--pad-top) var(--pad-x) var(--pad-bottom); }
.page.is-measure .page-body { padding-bottom: 0; }

.page-bar { display: none; }

.page-foot {
  position: absolute;
  left: var(--pad-x);
  right: var(--pad-x);
  bottom: 30px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  font-size: 9.5px;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

.page .ph { color: #b7c0cd; }

.inv-label {
  display: block;
  margin-bottom: 8px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.b-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  padding-bottom: 34px;
}

.inv-brand { min-width: 0; max-width: 55%; }

.inv-logo {
  display: block;
  height: 60px;
  width: auto;
  max-width: 240px;
  object-fit: contain;
  object-position: left center;
}

.inv-brand-name {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}

.inv-title { text-align: right; flex: 0 0 auto; }

.inv-title h2 {
  margin: 0;
  font-size: 32px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.inv-number {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
}

.inv-paid {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1.5px solid #15803d;
  color: #15803d;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.b-parties {
  display: grid;
  grid-template-columns: 1fr 1fr 0.95fr;
  gap: 28px;
  padding-bottom: 26px;
}

.inv-party-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}

.inv-party-lines {
  margin-top: 3px;
  color: var(--ink-muted);
  font-size: 11.5px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.inv-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 11.5px;
}

.inv-meta-row:first-of-type { padding-top: 0; }
.inv-meta-row span { color: var(--ink-muted); }
.inv-meta-row b { font-weight: 600; text-align: right; overflow-wrap: anywhere; }

.b-due { padding-bottom: 26px; }

.inv-due {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 22px;
  border-radius: 14px;
  background: var(--accent-soft);
}

.inv-due .inv-label { margin-bottom: 2px; }

.inv-due strong {
  display: block;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent-ink);
}

.inv-due-by {
  text-align: right;
  font-size: 12px;
  color: var(--ink-muted);
}

.inv-due-by b {
  display: block;
  font-size: 14px;
  color: var(--ink-strong);
  font-weight: 600;
}

.inv-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 104px 112px;
  gap: 14px;
  align-items: start;
}

.inv-grid > :not(:first-child) { text-align: right; }

.b-thead {
  padding: 9px 14px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.b-row {
  padding: 13px 14px;
  border-bottom: 1px solid var(--rule);
  font-size: 12px;
}

.b-row > span { padding-top: 1px; color: var(--ink-muted); white-space: nowrap; }
.b-row > span:last-child { color: var(--ink-strong); font-weight: 600; }

.inv-desc b {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}

.inv-desc small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.inv-desc small.inv-prorate { color: var(--accent); font-weight: 600; }

.b-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 40px;
  padding-top: 22px;
}

.inv-pay-text,
.inv-note-text {
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.inv-pay-rows { max-width: 300px; }

.inv-pay-rows div {
  display: flex;
  gap: 12px;
  padding: 3px 0;
  font-size: 11.5px;
}

.inv-pay-rows span {
  width: 58px;
  flex: 0 0 58px;
  color: var(--ink-muted);
}

.inv-pay-rows b {
  font-weight: 600;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}

.inv-pay-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #9fe870;
  color: #163300;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.inv-pay-link svg { display: block; }

.inv-pay-url {
  margin-top: 6px;
  font-size: 10px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.inv-pay-rows + .inv-pay-text,
.inv-pay-url + .inv-pay-text { margin-top: 10px; }

.inv-tot-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 0;
  font-size: 12px;
  color: var(--ink-muted);
}

.inv-tot-row b { color: var(--ink-strong); font-weight: 600; white-space: nowrap; }

.inv-tot-row.is-total {
  margin-top: 4px;
  padding-top: 9px;
  border-top: 1px solid var(--rule);
  color: var(--ink-strong);
  font-weight: 600;
}

.inv-tot-row.is-due {
  align-items: center;
  margin-top: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 13px;
  font-weight: 600;
}

.inv-tot-row.is-due b {
  color: var(--on-accent);
  font-size: 16px;
  font-weight: 700;
}

.b-notes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  padding-top: 30px;
}

.b-notes.is-single { grid-template-columns: 1fr; }

/* Studio */

.tpl-studio .page-bar {
  display: block;
  position: absolute;
  inset: 0 0 auto;
  height: 7px;
  background: var(--accent);
}

/* Classic */

.tpl-classic .b-head {
  align-items: flex-end;
  padding-bottom: 22px;
  border-bottom: 2px solid var(--ink-strong);
}

.tpl-classic .inv-title h2 {
  font-size: 22px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-strong);
}

.tpl-classic .inv-number { color: var(--accent); }

.tpl-classic .b-parties { padding-top: 26px; }

.tpl-classic .inv-label { color: var(--ink-strong); }

.tpl-classic .inv-due {
  background: transparent;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
}

.tpl-classic .inv-due .inv-label { color: var(--ink-muted); }

.tpl-classic .b-thead {
  padding: 9px 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-strong);
  border-top: 2px solid var(--ink-strong);
  border-bottom: 1px solid var(--ink-strong);
}

.tpl-classic .b-row { padding: 13px 0; }

.tpl-classic .inv-tot-row.is-due {
  padding: 11px 0 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-strong);
  border-top: 2px solid var(--ink-strong);
}

.tpl-classic .inv-tot-row.is-due b { color: var(--accent-ink); }

/* Bold */

.tpl-bold .b-head {
  align-items: center;
  margin: calc(-1 * var(--pad-top)) calc(-1 * var(--pad-x)) 0;
  padding: 44px var(--pad-x) 38px;
  background: var(--accent);
  color: var(--on-accent);
}

.tpl-bold .inv-brand-name { color: var(--on-accent); }

.tpl-bold .inv-logo {
  height: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #ffffff;
  box-sizing: content-box;
}

.tpl-bold .inv-title h2 {
  font-size: 40px;
  color: var(--on-accent);
}

.tpl-bold .inv-number {
  color: var(--on-accent);
  opacity: 0.8;
}

.tpl-bold .inv-paid {
  border-color: var(--on-accent);
  color: var(--on-accent);
}

.tpl-bold .b-parties { padding-top: 34px; }

.tpl-bold .b-thead {
  padding: 9px 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent-ink);
  border-bottom: 2px solid var(--accent);
}

.tpl-bold .b-row { padding: 13px 0; }

.tpl-bold .inv-due { border-radius: 0 14px 14px 0; border-left: 5px solid var(--accent); }

/* ---------- Dialogs ---------- */

dialog {
  width: 520px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: #ffffff;
  color: var(--navy);
  box-shadow: 0 30px 80px rgba(0, 16, 81, 0.28);
}

dialog::backdrop { background: rgba(0, 16, 81, 0.55); }

.dialog-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 16px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.dialog-bar strong { font-size: 16px; }

.dialog-body {
  padding: 18px 22px 22px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.dialog-intro {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.6;
  color: #52607a;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.hist-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.hist-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line-soft);
  background: #fbfcff;
}

.hist-main b {
  display: block;
  font-size: 14.5px;
  color: var(--navy);
}

.hist-main span {
  display: block;
  font-size: 12.5px;
  color: var(--soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hist-amt {
  font-size: 14.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.hist-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.hist-actions .chip { height: 30px; font-size: 12.5px; }
.hist-actions .icon-btn { margin-left: auto; }

.empty {
  padding: 28px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--soft);
  border: 1.5px dashed var(--line);
  border-radius: 16px;
}

.data-actions { display: grid; gap: 10px; }

.data-actions .btn { justify-content: flex-start; }

.data-actions .btn-danger-soft {
  background: #fff5f4;
  color: #b42318;
  border: 1px solid #f5c6c1;
}

.data-actions .btn-danger-soft:hover { background: #fdecea; }

/* ---------- Toast & mobile bar ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 12px 12px 12px 18px;
  border-radius: 16px;
  background: var(--navy);
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 20px 50px rgba(0, 16, 81, 0.3);
  transform: translate(-50%, 140%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}

.toast.is-open {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}

.toast.is-error { background: #b42318; }

.toast button {
  height: 34px;
  padding: 0 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.toast button:hover { background: rgba(255, 255, 255, 0.24); }
.toast button[hidden] { display: none; }

.mobile-bar { display: none; }

.site-foot {
  margin-top: 28px;
  text-align: center;
  font-size: 13px;
  color: var(--soft);
}

.site-foot a { color: var(--blue); font-weight: 600; text-decoration: none; }
.site-foot a:hover { text-decoration: underline; }

.spin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- PIN gate ---------- */

.pin-gate { display: none; }

body.is-locked .wrap,
body.is-locked .mobile-bar { display: none; }

body.is-locked .pin-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 76px);
}

.pin-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px 26px;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.96);
  border-radius: 28px;
  box-shadow: 0 24px 70px rgba(0, 16, 81, 0.10);
}

.pin-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  margin: 0 auto 16px;
  display: block;
}

.pin-card h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 600;
  color: var(--navy);
}

.pin-intro {
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.pin-card input[type="password"] {
  height: 48px;
  margin-bottom: 12px;
  padding: 0 16px;
  text-align: center;
  font-size: 20px;
  letter-spacing: 0.3em;
}

.pin-error {
  min-height: 18px;
  margin: 12px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: #c0392b;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .preview-card { position: static; max-height: none; }
  .stage { max-height: none; }
  body { padding-bottom: 110px; }

  .mobile-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 40;
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 8px;
    padding: 8px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    box-shadow: 0 20px 50px rgba(0, 16, 81, 0.2);
  }

  .toast { bottom: 96px; }
}

@media (max-width: 640px) {
  body { padding: 18px 12px 110px; }
  h1 { font-size: 30px; }
  .sub { font-size: 15.5px; }
  .topbar-logo img { height: 28px; }
  .form-card { padding: 6px; }
  .sec-body { padding: 2px 12px 16px; }
  .sec > summary { padding: 14px 12px; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  .item-nums { grid-template-columns: 1fr 1fr; }
  .preview-card { padding: 12px; }
  .stage { padding: 12px; border-radius: 16px; }
  .toolbar { width: 100%; }
  .toolbar .btn { flex: 1; }
  .toolbar #downloadBtn { display: none; }
  .saved { font-size: 11.5px; padding: 6px 10px; }
}

/* ---------- Print ---------- */

@media print {
  html, body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
  }

  body > *:not(#printRoot) { display: none !important; }

  #printRoot { display: block; }

  #printRoot .page {
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    break-after: page;
    page-break-after: always;
  }

  #printRoot .page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
