:root {
  --paper: #f5f2e9;
  --paper-deep: #ebe6d8;
  --paper-sunk: #e2dccb;
  --card: #fff;
  --field: #fffdf8;
  --ink: #17211f;
  --ink-2: #2a3633;
  --muted: #5a645d;
  --blue: #294be0;
  --blue-deep: #1f3ec7;
  --blue-wash: #eef1ff;
  --lime: #d9ef73;
  --red: #b8322a;
  --red-wash: #fdebe8;
  --amber: #8a5300;
  --amber-wash: #fff3d6;
  --green: #17845a;
  --green-wash: #e3f5ec;
  --line: rgba(23, 33, 31, 0.13);
  --line-strong: rgba(23, 33, 31, 0.26);
  --sans: "DM Sans", system-ui, sans-serif;
  --display: "Manrope", system-ui, sans-serif;
  --mono: "DM Mono", ui-monospace, monospace;
  --r-sm: 9px;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 1px 2px rgba(23, 33, 31, 0.06), 0 8px 24px rgba(23, 33, 31, 0.06);
  --shadow-page: 0 1px 2px rgba(23, 33, 31, 0.1), 0 14px 34px -8px rgba(23, 33, 31, 0.22);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --top-h: 64px;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top-h) + 16px); }
html, body { margin: 0; }
body {
  min-height: 100svh;
  background: linear-gradient(180deg, rgba(217, 239, 115, 0.24), transparent 240px), var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  caret-color: var(--blue);
}
::selection { background: var(--lime); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); text-underline-offset: 3px; text-decoration-thickness: 1px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.ico { width: 18px; height: 18px; flex: none; }
* { scrollbar-width: thin; scrollbar-color: rgba(23, 33, 31, 0.28) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(23, 33, 31, 0.22); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(23, 33, 31, 0.38); }
.num { font-variant-numeric: tabular-nums; }

.skip { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 14px; border-radius: var(--r-sm); background: var(--ink); color: #fff; font-weight: 600; text-decoration: none; }
.skip:focus { top: 12px; }

/* Top bar (matches /pdf-tools/) */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  height: var(--top-h); padding: 0 24px;
  background: rgba(245, 242, 233, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.wordmark { font: 800 22px var(--display); letter-spacing: -1.4px; text-decoration: none; color: inherit; }
.wordmark span:first-child { font-weight: 500; }
.wordmark-dot { color: var(--blue); }
.top-home { font: 700 14px var(--display); color: inherit; text-decoration: none; padding: 6px 10px; border-radius: 8px; background: var(--lime); }
.privacy { margin: 0 0 0 auto; font: 500 12px var(--mono); letter-spacing: 0; color: var(--muted); }
.back { font-size: 13px; font-weight: 600; color: inherit; }

/* App frame */
.app { max-width: 1560px; margin: 0 auto; padding: 22px 24px 40px; }
.app-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px; margin-bottom: 18px; }
.app-title h1 { margin: 0; font: 800 34px/1.05 var(--display); letter-spacing: -0.04em; text-wrap: balance; }
.app-title p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }

.tabs { display: flex; gap: 2px; padding: 4px; border-radius: 13px; background: var(--paper-deep); border: 1px solid var(--line); overflow-x: auto; max-width: 100%; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 8px 14px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 600; font-size: 14px; color: var(--ink-2);
  transition: background .18s var(--ease), color .18s;
}
.tab:hover { background: rgba(255, 255, 255, 0.6); }
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(23, 33, 31, 0.14); }
.tab .count { font: 500 11px var(--mono); padding: 1px 6px; border-radius: 6px; background: rgba(23, 33, 31, 0.08); color: var(--muted); }
.tab[aria-selected="true"] .count { background: var(--lime); color: var(--ink); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(440px, 0.92fr); gap: 22px; align-items: start; }
.app:not([data-tab="invoice"]):not([data-tab="business"]) .workspace { grid-template-columns: minmax(0, 1fr); }
.app:not([data-tab="invoice"]):not([data-tab="business"]) .preview { display: none; }
.editor { min-width: 0; outline: none; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; }
.loading { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 120px 0; color: var(--muted); margin: 0; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--ink); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  min-height: 38px; padding: 8px 14px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--card); color: var(--ink);
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-quiet { background: transparent; }
.btn-quiet:hover { background: rgba(255, 255, 255, .7); }
.btn-dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-dark:hover { background: var(--ink-2); }
.btn-primary {
  background: var(--blue); border-color: var(--blue); color: #fff;
  box-shadow: 0 6px 16px -4px rgba(41, 75, 224, .45);
}
.btn-primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.btn-lime { background: var(--lime); border-color: #c7dc5f; }
.btn-lime:hover { border-color: var(--ink); }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-lg { min-height: 46px; padding: 10px 20px; font-size: 15px; border-radius: 12px; }
.btn-link { background: none; border: 0; padding: 0; color: var(--blue); font-weight: 600; font-size: 13px; }
.btn-link:hover { text-decoration: underline; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  transition: border-color .15s, color .15s, background .15s;
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost:hover { background: rgba(23, 33, 31, .06); border-color: transparent; }
.icon-btn.danger:hover { color: var(--red); }

/* Banner */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px;
  padding: 14px 16px 14px 18px; border-radius: var(--r-lg);
  background: var(--ink); color: #fff;
}
.banner p { margin: 0; flex: 1 1 280px; color: rgba(255, 255, 255, .78); font-size: 14px; }
.banner strong { color: #fff; display: block; font: 700 16px var(--display); letter-spacing: -0.01em; margin-bottom: 2px; }
.banner .btn-quiet { color: #fff; border-color: rgba(255, 255, 255, .3); }
.banner .btn-quiet:hover { background: rgba(255, 255, 255, .08); border-color: #fff; }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ZATCA action sits after the total — fill invoice first, then clear/report */
.zatca-after-total { margin-top: 4px; }
.zatca-panel {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: var(--field);
}
.zatca-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.zatca-total strong {
  font: 800 22px/1.1 var(--display);
  letter-spacing: -0.03em;
  color: var(--ink);
}
.zatca-panel-main {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px 18px;
}
.zatca-panel-copy {
  display: grid;
  gap: 6px;
  flex: 1 1 220px;
  min-width: 0;
}
.zatca-panel-copy strong {
  font: 700 16px/1.25 var(--display);
  letter-spacing: -0.01em;
  color: var(--ink);
}
.zatca-panel-copy p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted);
}
.zatca-panel[data-state="ok"] {
  border-color: rgba(46, 125, 50, .35);
  background: var(--green-wash, #eef7ee);
}
.zatca-panel[data-state="warn"] {
  border-color: rgba(180, 120, 20, .35);
  background: var(--amber-wash);
}
.zatca-panel[data-state="err"] {
  border-color: rgba(184, 50, 42, .35);
  background: var(--red-wash);
}
.zatca-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
}
.zatca-notes {
  margin: 4px 0 0;
  padding-left: 1.15em;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-2);
}
.sa-more summary {
  cursor: pointer;
  font: 600 13px var(--display);
  color: var(--ink-2);
  list-style: none;
}
.sa-more summary::-webkit-details-marker { display: none; }
.sa-more summary::after { content: " ▾"; color: var(--muted); }
@media (max-width: 640px) {
  .zatca-actions { width: 100%; }
  .zatca-actions .btn { flex: 1 1 auto; }
}

/* Doc type picker */
.doctypes { display: flex; gap: 6px; overflow-x: auto; padding: 2px; margin: -2px; scrollbar-width: none; }
.doctypes::-webkit-scrollbar { display: none; }
.doctype {
  flex: none; padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: transparent;
  font-weight: 600; font-size: 14px; color: var(--ink-2);
  transition: background .15s, border-color .15s, color .15s;
}
.doctype:hover { border-color: var(--ink); color: var(--ink); }
.doctype[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* Sections */
.sec { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.sec-head {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 16px 18px; border: 0; background: none; text-align: left; border-radius: var(--r-lg);
}
.sec-head h2 { margin: 0; font: 800 18px/1.2 var(--display); letter-spacing: -0.02em; }
.sec-sum { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-head .chev { color: var(--muted); transition: transform .22s var(--ease); }
.sec[data-open="true"] .sec-head .chev { transform: rotate(180deg); }
.sec-body { padding: 2px 18px 18px; display: grid; gap: 14px; }
.sec[data-open="false"] .sec-body { display: none; }
.sec-flag { font: 500 11px var(--mono); letter-spacing: .04em; padding: 2px 7px; border-radius: 6px; background: var(--amber-wash); color: var(--amber); white-space: nowrap; }
.sec-flag.err { background: var(--red-wash); color: var(--red); }
.sub-h { margin: 6px 0 -4px; font: 700 13px var(--display); letter-spacing: -0.005em; color: var(--ink-2); }

/* Fields */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; }
.span-2 { grid-column: span 2; }
.f { display: grid; gap: 5px; min-width: 0; align-content: start; }
.f > span:first-child, .f-label { font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.f input:not([type=checkbox]):not([type=radio]):not([type=color]), .f select, .f textarea, .inp {
  width: 100%; min-height: 40px; padding: 8px 11px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--field);
  font-size: 15px; transition: border-color .15s, box-shadow .15s, background .15s;
}
.f textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
.f select, select.inp {
  appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a645d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
.f input:hover, .f select:hover, .f textarea:hover, .inp:hover { border-color: rgba(23, 33, 31, .42); }
.f input:focus, .f select:focus, .f textarea:focus, .inp:focus { outline: none; border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(41, 75, 224, .16); }
.f input::placeholder, .f textarea::placeholder, .inp::placeholder { color: #8a918a; }
.f .hint { font-size: 12.5px; color: var(--muted); }
.f .hint.ok { color: var(--green); }
.f .hint.warn { color: var(--amber); }
.f .hint.err { color: var(--red); }
.f.invalid input, .f.invalid select { border-color: var(--red); }
.f.invalid input:focus { box-shadow: 0 0 0 3px rgba(184, 50, 42, .16); }
.f input.mono, .inp.mono { font-family: var(--mono); font-size: 14px; letter-spacing: .02em; text-transform: uppercase; }
.f input.mono::placeholder { text-transform: none; }
.affix { position: relative; display: flex; align-items: center; }
.affix > b { position: absolute; left: 11px; color: var(--muted); font-weight: 500; pointer-events: none; font-size: 14px; }
.affix input { padding-left: 28px !important; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; }
.badge.ok { color: var(--green); }
.badge.err { color: var(--red); }
.badge .ico { width: 14px; height: 14px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; font-size: 14px; }
.toggle span { display: grid; gap: 1px; }
.toggle strong { font-weight: 600; }
.toggle small { color: var(--muted); font-size: 12.5px; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle i {
  flex: none; position: relative; width: 38px; height: 22px; border-radius: 999px;
  background: rgba(23, 33, 31, .18); transition: background .2s var(--ease);
}
.toggle i::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .2s var(--ease);
}
.toggle input:checked + i { background: var(--blue); }
.toggle input:checked + i::after { transform: translateX(16px); }
.toggle input:focus-visible + i { outline: 2px solid var(--blue); outline-offset: 2px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--paper-deep); }
.seg button { padding: 6px 12px; border: 0; border-radius: 8px; background: transparent; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(23, 33, 31, .14); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }
.seg.gst-type button { padding: 6px 8px; font-size: 12.5px; white-space: nowrap; }

.inline-panel { display: grid; gap: 12px; padding: 14px; border-radius: var(--r); background: var(--paper); border: 1px solid var(--line); }

/* Combobox suggestions */
.combo { position: relative; }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 25;
  max-height: 260px; overflow: auto; padding: 4px; margin: 0; list-style: none;
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--r);
  box-shadow: 0 16px 40px -10px rgba(23, 33, 31, .28);
}
.suggest li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.suggest li small { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--blue-wash); }

/* Items editor */
.items { display: grid; gap: 0; border-top: 1px solid var(--line); }
.item { position: relative; display: grid; gap: 8px 10px; padding: 14px 0; border-bottom: 1px solid var(--line);
  grid-template-columns: 26px minmax(0, 1fr) 76px 112px 112px;
  grid-template-areas:
    "n desc qty rate amt"
    ". meta meta meta meta";
}
.item-n { grid-area: n; padding-top: 10px; font: 500 12px var(--mono); color: var(--muted); }
.item-desc { grid-area: desc; }
.item-qty { grid-area: qty; }
.item-rate { grid-area: rate; }
.item-amt { grid-area: amt; display: grid; gap: 5px; align-content: start; text-align: right; }
.item-amt output { display: block; min-height: 40px; padding: 9px 0 0; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.item-amt small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-top: -6px; }
.item-meta { grid-area: meta; display: grid; grid-template-columns: minmax(0, 1.1fr) 92px minmax(0, 1.2fr) 92px auto; gap: 10px; align-items: end; }
.item .f > span:first-child { font-size: 10.5px; }
.item input, .item select { min-height: 36px !important; font-size: 14px !important; padding-top: 6px !important; padding-bottom: 6px !important; }
.item-desc textarea { min-height: 40px; resize: none; overflow: hidden; font-size: 15px; font-weight: 600; }
.disc { display: flex; }
.disc input { border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
.disc .unit-toggle { flex: none; width: 40px; border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 10px 10px 0; background: var(--paper-deep); font-weight: 600; font-size: 13px; }
.disc .unit-toggle:hover { background: var(--paper-sunk); }
.item-remove { align-self: end; margin-bottom: 1px; }
.items-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 4px; }
.items-actions .hint { margin-left: auto; font-size: 12.5px; color: var(--muted); }
kbd { font: 500 11px var(--mono); padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--paper); }

/* Totals */
.totals { display: grid; gap: 6px; padding: 14px 16px; border-radius: var(--r); background: var(--paper); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.totals dt, .totals dd { margin: 0; }
.totals dt { color: var(--muted); }
.totals .grand { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line-strong); font-size: 18px; font-weight: 800; font-family: var(--display); letter-spacing: -0.01em; }
.totals .grand dt { color: var(--ink); }
.totals .words { display: block; font-size: 12.5px; color: var(--muted); font-style: italic; }

/* Upload tiles */
.uploads { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.upload {
  position: relative; display: grid; place-items: center; gap: 4px; min-height: 120px; padding: 14px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--r); background: var(--paper);
  text-align: center; font-size: 13px; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload:hover { border-color: var(--ink); background: #fff; }
.upload strong { color: var(--ink); font-size: 14px; }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload img { max-width: 100%; max-height: 70px; object-fit: contain; }
.upload.has { border-style: solid; background: #fff; }
.upload .icon-btn { position: absolute; top: 8px; right: 8px; z-index: 2; }

/* Preview pane */
.preview {
  position: sticky; top: calc(var(--top-h) + 14px);
  display: flex; flex-direction: column;
  height: calc(100svh - var(--top-h) - 28px); min-height: 520px;
  border-radius: var(--r-lg); background: var(--paper-deep); border: 1px solid var(--line);
  overflow: hidden;
}
.preview-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: rgba(245, 242, 233, .7); }
.template-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 10px 7px 12px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card);
  font-size: 14px; transition: border-color .15s;
}
.template-btn:hover, .template-btn[aria-expanded="true"] { border-color: var(--ink); }
.template-btn-label { font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.template-btn .chev { width: 16px; height: 16px; transition: transform .22s var(--ease); }
.template-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.preview-status { margin-left: auto; display: flex; align-items: center; gap: 8px; font: 500 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.preview-status .spin { width: 12px; height: 12px; border-width: 1.5px; }
.preview-close { display: none; }

.design-panel {
  max-height: 58%; overflow: auto; padding: 14px; display: grid; gap: 16px; grid-auto-rows: max-content;
  background: var(--card); border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 24px -14px rgba(23, 33, 31, .35);
  animation: drop .24s var(--ease);
}
@keyframes drop { from { clip-path: inset(0 0 100% 0); opacity: .4; } to { clip-path: inset(0 0 0 0); opacity: 1; } }
.thumbs { display: grid; grid-auto-flow: column; grid-auto-columns: 92px; gap: 10px; overflow-x: auto; padding: 3px 3px 6px; margin: -3px -3px -6px; scroll-snap-type: x proximity; }
.thumb { scroll-snap-align: start; }
.thumb { display: grid; gap: 6px; padding: 0; border: 0; background: none; text-align: left; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.thumb-img {
  position: relative; aspect-ratio: 1 / 1.3; border-radius: 8px; overflow: hidden; background: #fff;
  border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(23, 33, 31, .08);
  transition: border-color .15s, box-shadow .15s, transform .15s var(--ease);
}
.thumb-img canvas, .thumb-img img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; }
.thumb-img.thermal canvas { object-fit: contain; background: var(--paper); }
.thumb-img .spin { position: absolute; inset: 0; margin: auto; }
.thumb:hover .thumb-img { transform: translateY(-2px); border-color: var(--ink); }
.thumb[aria-pressed="true"] .thumb-img { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue); }
.thumb[aria-pressed="true"] { color: var(--blue); }
.design-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: center; }
.design-row > .f-label { margin: 0; }
.design-row > .seg { justify-self: start; }
.design-row .seg { justify-self: start; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sw { position: relative; width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14); transition: transform .15s var(--ease); }
.sw:hover { transform: scale(1.08); }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); }
.sw-custom { position: relative; width: 28px; height: 28px; border-radius: 50%; overflow: hidden; background: conic-gradient(#d23a2f, #e0a12f, #1f9d6b, #2d8bd6, #294be0, #8a3fc2, #d23a2f); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14); }
.sw-custom input { position: absolute; inset: -4px; width: 40px; height: 40px; opacity: 0; cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: transparent; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .ico { width: 13px; height: 13px; }

.stage { position: relative; flex: 1; overflow: auto; padding: 22px; background: radial-gradient(circle at 50% 0, rgba(255, 255, 255, .5), transparent 60%), var(--paper-deep); }
.pages { display: grid; gap: 18px; justify-items: center; }
.page { position: relative; background: #fff; box-shadow: var(--shadow-page); border-radius: 2px; line-height: 0; }
.page canvas { display: block; width: 100%; height: auto; border-radius: 2px; }
.pages.updating .page { transition: opacity .2s; opacity: .55; }
.stage-error { margin: 40px auto; max-width: 360px; padding: 16px; border-radius: var(--r); background: var(--red-wash); color: var(--red); font-size: 14px; display: grid; gap: 8px; }
.stage-skeleton { width: min(100%, 560px); aspect-ratio: 1 / 1.414; margin: 0 auto; border-radius: 2px; background: linear-gradient(100deg, #fff 40%, #f6f3ec 50%, #fff 60%) 0 0 / 200% 100%; animation: sheen 1.4s linear infinite; box-shadow: var(--shadow-page); }
@keyframes sheen { to { background-position: -200% 0; } }

.preview-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--card); }
.foot-total { display: grid; margin-right: auto; min-width: 0; }
.foot-total small { font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.foot-total strong { font: 800 22px/1.15 var(--display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.foot-checks { border: 0; background: none; padding: 0; text-align: left; font-size: 12.5px; font-weight: 600; color: var(--amber); }
.foot-checks.err { color: var(--red); }
.foot-checks.ok { color: var(--green); cursor: default; }
.foot-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.menu { position: fixed; z-index: 60; min-width: 220px; padding: 6px; margin: 0; list-style: none; background: #fff; border: 1px solid var(--line-strong); border-radius: var(--r); box-shadow: 0 18px 44px -12px rgba(23, 33, 31, .32); animation: pop .16s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: none; font-size: 14px; font-weight: 600; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: var(--blue-wash); outline: none; }
.menu small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

/* Lists: history, customers, items */
.list-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.list-head h2 { margin: 0 auto 0 0; font: 800 24px/1.1 var(--display); letter-spacing: -0.03em; }
.search { position: relative; min-width: 220px; flex: 0 1 300px; }
.search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { padding-left: 34px !important; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font: 500 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 12px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: rgba(245, 242, 233, .6); }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .icon-btn { width: 32px; height: 32px; }
.table strong { font-weight: 700; }
.table .sub { display: block; color: var(--muted); font-size: 12.5px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 6px; font: 500 11.5px var(--mono); letter-spacing: .02em; background: var(--paper-deep); color: var(--ink-2); white-space: nowrap; }
.pill.t-tax-invoice { background: var(--blue-wash); color: var(--blue-deep); }
.pill.t-quotation { background: #f3ecff; color: #6a2fb0; }
.pill.t-credit-note { background: var(--green-wash); color: var(--green); }
.pill.t-debit-note { background: var(--amber-wash); color: var(--amber); }
.pill.t-proforma { background: #e8f4f8; color: #0f5a72; }
.pill.t-delivery-challan { background: #fdf0e6; color: #9a4a12; }
.pill.pay { border: 0; cursor: pointer; font-weight: 600; }
.pill.pay.paid { background: var(--green-wash); color: var(--green); }
.pill.pay.unpaid { background: var(--amber-wash); color: var(--amber); }
.pill.pay:hover { filter: brightness(.96); }
.empty { display: grid; justify-items: center; gap: 10px; padding: 48px 20px; text-align: center; }
.empty h3 { margin: 0; font: 800 20px var(--display); letter-spacing: -0.02em; }
.empty p { margin: 0; color: var(--muted); max-width: 420px; }
.list-card { padding: 18px; }
.list-stats { display: flex; flex-wrap: wrap; gap: 8px 22px; color: var(--muted); font-size: 13px; }
.list-stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.edit-row td { background: var(--paper); }
.edit-form { display: grid; gap: 12px; padding: 4px 0; }
.edit-form .row { display: flex; gap: 8px; justify-content: flex-end; }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Country tax dropdown (India GST / Saudi VAT) */
.country-bar {
  display: grid;
  gap: 4px;
  margin: 0 0 2px;
  max-width: 420px;
}
.country-bar-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.country-select {
  width: 100%;
  min-height: 42px;
  padding: 0 36px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23555' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--ink);
  font: 650 14.5px/1.2 var(--sans);
  appearance: none;
  cursor: pointer;
}
.country-select:hover,
.country-select:focus {
  border-color: var(--ink);
  outline: none;
}
.country-bar-hint { margin: 0; }

/* Invoice tab details */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.doc-bar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.doc-bar .doctypes { flex: 1; min-width: 0; }
.from-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: -2px 2px 0; font-size: 13.5px; color: var(--muted); }
.from-line strong { color: var(--ink); font-weight: 700; }
.from-line.warn { color: var(--amber); }
.from-line .ico { width: 15px; height: 15px; }
.mono-s { font-family: var(--mono); font-size: 12.5px; letter-spacing: .02em; }
.mono-n { font-family: var(--mono); letter-spacing: .01em; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; }
.name-row .btn { flex: none; min-height: 40px; }
.affix-r { position: relative; }
.affix-r input { padding-right: 58px !important; }
.auto-tag {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: inline-grid; place-items: center; min-width: 28px; height: 26px; padding: 0 8px;
  border-radius: 7px; border: 0; background: var(--lime); color: var(--ink);
  font: 500 11px var(--mono); letter-spacing: .04em; text-transform: uppercase;
}
.auto-tag.reset { background: var(--paper-deep); color: var(--muted); padding: 0 6px; }
.auto-tag.reset:hover { color: var(--ink); background: var(--paper-sunk); }
.auto-tag .ico { width: 14px; height: 14px; }
.tax-mode { margin: 0; min-height: 40px; display: flex; align-items: center; padding: 0 12px; border-radius: 10px; background: var(--paper); border: 1px dashed var(--line-strong); font-size: 14px; font-weight: 600; }
.round-f { align-content: end; padding-bottom: 8px; }
.pay-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 0; font-size: 13px; color: var(--muted); }
.pay-line .ico { width: 15px; height: 15px; color: var(--green); }
.pay-line strong { color: var(--ink); font-weight: 600; }
.item-btns { display: flex; gap: 0; align-items: end; justify-content: flex-end; padding-bottom: 1px; }
.biz-intro h2 { margin: 0; font: 800 26px/1.1 var(--display); letter-spacing: -0.03em; }
.biz-intro p { margin: 6px 0 0; color: var(--muted); max-width: 60ch; }
.muted-p { margin: 0; color: var(--muted); font-size: 14px; max-width: 64ch; }
.num-table td { padding: 8px 12px 8px 0; }
.num-table .inp { min-height: 36px; padding: 6px 10px; max-width: 120px; }
.num-table .too-long { color: var(--red); }

/* Mobile bottom bar */
.mobile-bar { display: none; }

/* Toast + dialog */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 80; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 11px 16px; border-radius: 12px; background: var(--ink); color: #fff;
  font-size: 14px; font-weight: 600; box-shadow: 0 16px 40px -12px rgba(23, 33, 31, .5);
  animation: toast .28s var(--ease);
}
.toast .ico { color: var(--lime); }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 10px); } }
.confirm { border: 0; border-radius: var(--r-lg); padding: 22px; max-width: 420px; width: calc(100vw - 32px); box-shadow: 0 30px 80px -20px rgba(23, 33, 31, .5); }
.confirm::backdrop { background: rgba(23, 33, 31, .38); }
.confirm h2 { margin: 0 0 8px; font: 800 20px var(--display); letter-spacing: -0.02em; }
.confirm p { margin: 0 0 18px; color: var(--muted); }
.confirm .row { display: flex; gap: 8px; justify-content: flex-end; }

/* Explainer */
.explain { border-top: 1px solid var(--line); margin-top: 24px; }
.explain-inner { max-width: 1200px; margin: 0 auto; padding: 56px 24px 40px; }
.explain h2 { margin: 0 0 28px; max-width: 760px; font: 800 34px/1.08 var(--display); letter-spacing: -0.035em; text-wrap: balance; }
.explain-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px 36px; }
.explain h3 { margin: 0 0 6px; font: 700 17px/1.25 var(--display); letter-spacing: -0.015em; }
.explain p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; max-width: 62ch; }
.explain-sub { margin-top: 44px; padding-top: 32px; border-top: 1px dashed var(--line-strong); }
.seo-links { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; margin: 0; }
.seo-links a { display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--field); color: var(--ink); font-size: 13.5px; font-weight: 600; text-decoration: none; transition: border-color .15s, background .15s; }
.seo-links a:hover { border-color: var(--ink); background: #fff; }
.foot { max-width: 1200px; margin: 0 auto; padding: 18px 24px 40px; color: var(--muted); font-size: 13px; }
.foot p { margin: 0; }

/* Responsive */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(380px, 0.85fr); }
  .preview-foot .btn-label { display: none; }
}
@media (max-width: 960px) {
  .privacy { display: none; }
  .back { margin-left: auto; }
  .app { padding: 16px 16px 120px; }
  .app-title h1 { font-size: 28px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .preview {
    position: fixed; inset: 0; z-index: 70; height: 100svh; min-height: 0; border-radius: 0; border: 0;
    transform: translateY(100%); visibility: hidden;
    transition: transform .32s var(--ease), visibility 0s linear .32s;
  }
  .app.show-preview .preview { transform: none; visibility: visible; transition: transform .32s var(--ease); }
  .app:not([data-tab="invoice"]):not([data-tab="business"]) .preview { display: flex; }
  .preview-close { display: inline-grid; }
  .preview-bar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .preview-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .stage { padding: 14px; }
  .preview-foot .foot-checks.ok { display: none; }
  .preview-foot .foot-total strong { font-size: 20px; }
  .mobile-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); box-shadow: 0 -8px 24px -16px rgba(23, 33, 31, .3);
  }
  .app:not([data-tab="invoice"]):not([data-tab="business"]) .mobile-bar { display: none; }
  .mobile-bar .foot-total strong { font-size: 19px; }
  .explain-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .top { padding: 0 14px; gap: 10px; }
  .top-home { display: none; }
  .app-head { align-items: stretch; }
  .tabs { width: 100%; }
  .tab { flex: 1 0 auto; justify-content: center; padding: 8px 7px; font-size: 13px; gap: 5px; }
  .tab .ico { display: none; }
  .sec-head { padding: 14px; }
  .sec-body { padding: 0 14px 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .grid-2.keep { grid-template-columns: 1fr 1fr; }
  .item { grid-template-columns: 72px minmax(0, 1fr); grid-template-areas: "desc desc" "qty rate" "meta meta" "amt amt"; }
  .item-n { display: none; }
  .item-amt { grid-area: amt; display: flex; justify-content: space-between; align-items: baseline; text-align: left; }
  .item-amt > span { display: none; }
  .item-amt output { min-height: 0; padding: 0; }
  .item-amt small { margin: 0; }
  .item-meta { grid-template-columns: 1fr 1fr; }
  .item-meta .item-btns { position: absolute; top: 8px; right: 0; }
  .item-desc { padding-right: 72px; }
  .uploads { grid-template-columns: 1fr; }
  .design-row { grid-template-columns: 1fr; gap: 6px; }
  .design-panel { max-height: 62%; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .table td { padding: 2px 0; border: 0; }
  .table .r, .table .actions { text-align: left; }
  .table .actions { padding-top: 8px; }
  .explain-grid { grid-template-columns: 1fr; }
  .explain h2 { font-size: 27px; }
  .preview-foot .foot-actions .btn-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  body > *:not(.app) { display: none !important; }
}
