@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #fbfcfe;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --text: #0f1d35;
  --muted: #53617a;
  --line: #e2e8f0;
  --line-strong: #d6dee9;
  --blue: #1769ff;
  --blue-2: #2868ff;
  --navy: #0d1a30;
  --input-bg: #ffffff;
  --table-head: #f7f9fc;
  --shadow: 0 2px 12px rgba(15, 29, 53, 0.035), 0 1px 2px rgba(15, 29, 53, 0.02);
  --focus: 0 0 0 3px rgba(23, 105, 255, 0.12);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -250px, rgba(223, 231, 241, 0.26), transparent 520px),
    var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }

.app-shell {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 17px 17px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 88px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 24px;
  padding: 18px 22px;
  position: relative;
  z-index: 20;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: start;
  min-width: 0;
}
.icon-button,
.primary-button,
.send-button,
.mode-tab,
.outline-button,
.calendar-trigger,
.delete-item,
.send-menu button {
  border: 0;
  outline: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
}
.icon-button:focus-visible,
.primary-button:focus-visible,
.send-button:focus-visible,
.mode-tab:focus-visible,
.outline-button:focus-visible,
.calendar-trigger:focus-visible,
.delete-item:focus-visible,
.send-menu button:focus-visible { box-shadow: var(--focus); }

.icon-button {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.74);
  color: #15233a;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
}
.icon-button:hover { border-color: #c7d2e2; background: #fff; }
.icon-button:active { transform: translateY(1px); }
.icon-button svg { width: 24px; height: 24px; stroke-width: 1.8; }

.primary-button {
  height: 50px;
  padding: 0 20px;
  min-width: 158px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: #fff;
  border-radius: 11px;
  background: linear-gradient(180deg, #206dff 0%, #1763f1 100%);
  box-shadow: 0 7px 18px rgba(23, 105, 255, 0.17), inset 0 1px 0 rgba(255, 255, 255, 0.17);
  font-size: 16px;
  font-weight: 620;
  letter-spacing: -.01em;
  transition: transform .18s ease, box-shadow .18s ease;
}
.primary-button:hover { box-shadow: 0 9px 22px rgba(23, 105, 255, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.19); }
.primary-button:active { transform: translateY(1px); }
.primary-button svg { width: 20px; height: 20px; stroke-width: 1.8; }

.mode-switch {
  width: 224px;
  height: 50px;
  border-radius: 12px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  background: #f7f8fb;
  border: 1px solid #f0f2f6;
  justify-self: center;
  box-shadow: inset 0 1px 1px rgba(15, 29, 53, 0.02);
}
.mode-tab {
  position: relative;
  border-radius: 11px;
  color: #53617a;
  font-weight: 560;
  font-size: 15px;
  transition: color .18s ease, background .18s ease;
}
.mode-tab.active {
  background: #fff;
  color: #1769ff;
  box-shadow: 0 1px 6px rgba(15, 29, 53, 0.04);
}
.mode-tab.active::after {
  content: "";
  position: absolute;
  height: 2px;
  left: 0;
  right: 0;
  bottom: 0;
  background: #1769ff;
  border-radius: 2px 2px 0 0;
}

.send-wrap { position: relative; justify-self: end; min-width: 0; }
.send-button {
  width: 210px;
  height: 50px;
  padding: 0 17px;
  border-radius: 10px;
  background: linear-gradient(180deg, #111f37 0%, #0b172a 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 5px 12px rgba(6, 16, 31, 0.1), inset 0 1px 0 rgba(255,255,255,.08);
  font-weight: 590;
  font-size: 16px;
  transition: transform .18s ease, box-shadow .18s ease;
}
.send-button:hover { box-shadow: 0 7px 16px rgba(6, 16, 31, 0.14), inset 0 1px 0 rgba(255,255,255,.08); }
.send-button:active { transform: translateY(1px); }
.send-main { display: inline-flex; align-items: center; gap: 12px; }
.send-main svg { width: 20px; height: 20px; stroke-width: 1.7; }
.send-chevron { width: 17px; height: 17px; stroke-width: 1.8; transition: transform .18s ease; }
.send-button[aria-expanded="true"] .send-chevron { transform: rotate(180deg); }
.send-menu {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  width: 210px;
  padding: 7px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 16px 35px rgba(15, 29, 53, 0.14);
  overflow: hidden;
}
.send-menu[hidden] { display: none; }
.send-menu button {
  width: 100%;
  height: 41px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  color: #26344d;
  padding: 0 10px;
  text-align: right;
  font-weight: 520;
}
.send-menu button:hover { background: #f5f8fc; }
.send-menu svg { width: 17px; height: 17px; color: #53617a; }

main { margin-top: 27px; }
.editor-view { display: grid; gap: 21px; }
.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.card { padding: 28px 29px; }
.party-card { min-height: 350px; }
.details-card { min-height: 300px; }
.items-card { min-height: 470px; }

.section-heading {
  height: 45px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 25px;
}
.section-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1;
  font-weight: 640;
  letter-spacing: -.018em;
  color: #111e34;
}
.heading-icon {
  width: 43px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  flex: 0 0 auto;
}
.heading-icon.blue { color: #1769ff; background: #eaf1ff; }
.heading-icon.purple { color: #7044ed; background: #f2edff; }
.heading-icon.green { color: #13955f; background: #eaf8f1; }
.heading-icon.transparent { color: #152238; background: #f7f9fc; width: 43px; border: 1px solid #dfe6ef; box-shadow: inset 0 1px 0 rgba(255,255,255,.7); }
.heading-icon svg { width: 22px; height: 22px; stroke-width: 1.8; }

.form-grid { display: grid; column-gap: 24px; row-gap: 26px; }
.from-grid { grid-template-columns: .88fr 1.12fr; }
.bill-grid { grid-template-columns: .92fr 1.08fr; }
.details-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 23px 36px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 9px; color: #35445f; }
.field > span:first-child { font-size: 13px; font-weight: 530; color: #53617a; }
.field-wide { grid-column: 1 / -1; }
.field-address { grid-column: 1 / 2; }
.field-phone { grid-column: 2 / 3; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--input-bg);
  color: #122037;
  outline: none;
  box-shadow: inset 0 1px 2px rgba(15, 29, 53, 0.015);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input:hover, textarea:hover, select:hover { border-color: #c8d2df; }
input:focus, textarea:focus, select:focus { border-color: #8eb3ff; box-shadow: var(--focus); }
input, select { height: 47px; padding: 0 13px; }
textarea { height: 85px; min-height: 85px; padding: 12px 13px; resize: vertical; line-height: 1.72; }
select { appearance: none; -webkit-appearance: none; padding-right: 42px; }
.select-wrap, .date-wrap { position: relative; display: block; min-width: 0; }
.select-wrap > svg {
  position: absolute;
  right: 15px;
  top: 50%;
  width: 16px;
  height: 16px;
  color: #5b6a83;
  transform: translateY(-50%);
  pointer-events: none;
}
.date-wrap > input:first-child { padding-right: 48px; }
.calendar-trigger {
  position: absolute;
  right: 3px;
  top: 3px;
  width: 41px;
  height: 41px;
  display: grid;
  place-items: center;
  color: #5c6d87;
  border-radius: 8px;
}
.calendar-trigger:hover { background: #f5f8fc; }
.calendar-trigger svg { width: 18px; height: 18px; stroke-width: 1.8; }
.native-date {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.details-options {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.adjustment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.55fr;
  gap: 18px;
  align-items: stretch;
}
.adjustment-field,
.qr-option {
  min-width: 0;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(247, 249, 252, .62);
}
.adjustment-field { cursor: text; }
.qr-option { cursor: pointer; user-select: none; }
.adjustment-copy,
.qr-option-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.adjustment-copy strong,
.qr-option-copy strong {
  color: #152238;
  font-size: 13px;
  font-weight: 620;
}
.adjustment-copy small,
.qr-option-copy small {
  color: #6d7a90;
  font-size: 11px;
  line-height: 1.4;
}
.percent-input-wrap {
  width: 76px;
  height: 40px;
  position: relative;
  flex: 0 0 auto;
}
.percent-input-wrap input {
  height: 40px;
  padding: 0 28px 0 10px;
  text-align: right;
  font-weight: 600;
  -moz-appearance: textfield;
}
.percent-input-wrap input::-webkit-outer-spin-button,
.percent-input-wrap input::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; }
.percent-input-wrap > span {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #728098;
  font-size: 12px;
  pointer-events: none;
}
.switch-control {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
}
.switch-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.switch-track {
  width: 42px;
  height: 24px;
  padding: 2px;
  display: block;
  border-radius: 999px;
  background: #cfd7e3;
  box-shadow: inset 0 0 0 1px rgba(15, 29, 53, .06);
  transition: background .18s ease, box-shadow .18s ease;
}
.switch-thumb {
  width: 20px;
  height: 20px;
  display: block;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 29, 53, .22);
  transition: transform .18s ease;
}
.switch-control input:checked + .switch-track { background: #1769ff; }
.switch-control input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch-control input:focus-visible + .switch-track { box-shadow: var(--focus); }

.app-shell.preview-mode #editorView { display: none !important; }
.app-shell.preview-mode #previewView { display: block !important; }

.items-heading { margin-bottom: 8px; }
.items-table-shell {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.items-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.items-table thead { background: var(--table-head); }
.items-table th {
  height: 42px;
  padding: 0 14px;
  color: #142139;
  font-size: 12px;
  font-weight: 620;
  text-align: right;
  border-bottom: 1px solid var(--line);
}
.items-table td {
  height: 71px;
  padding: 8px 14px;
  border-bottom: 1px solid #e8edf3;
  vertical-align: middle;
}
.items-table tbody tr:last-child td { border-bottom: 0; }
.number-col { width: 7%; }
.qty-col { width: 16%; text-align: center !important; }
.rate-col { width: 19%; text-align: center !important; }
.amount-col { width: 19%; text-align: center !important; }
.delete-col { width: 7%; }
.item-number { text-align: center; color: #142139; font-size: 13px; }
.item-copy { min-width: 0; }
.item-copy input {
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  box-shadow: none;
  font-weight: 600;
  color: #16233a;
  background: transparent;
}
.item-copy input:focus { box-shadow: 0 0 0 2px rgba(23, 105, 255, .1); }
.item-copy input.item-desc { margin-top: 1px; font-size: 12px; font-weight: 430; color: #64728c; }
.table-input {
  height: 42px;
  text-align: center;
  padding: 0 8px;
  border-color: #e3e9f0;
  margin-left: auto;
  margin-right: auto;
  display: block;
}
.item-qty { width: 97px; }
.item-rate { width: 123px; }
.amount-display {
  width: 123px;
  margin-left: auto;
  margin-right: auto;
  height: 42px;
  border: 1px solid #e3e9f0;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #233149;
  font-weight: 500;
}
.delete-item {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  margin-left: auto;
  border-radius: 8px;
  color: #66748d;
}
.delete-item:hover { background: #fff2f2; color: #c43b3b; }
.delete-item svg { width: 17px; height: 17px; stroke-width: 1.7; }

.items-footer {
  display: grid;
  grid-template-columns: 1fr 371px;
  gap: 28px;
  align-items: start;
  margin-top: 19px;
}
.outline-button {
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
  border: 1px solid #bdd3ff;
  border-radius: 9px;
  color: #1263ef;
  background: #fff;
  font-weight: 560;
  width: max-content;
}
.outline-button:hover { background: #f7faff; border-color: #9fbfff; }
.outline-button svg { width: 18px; height: 18px; stroke-width: 1.8; }
.totals { width: 100%; }
.total-row {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: #152238;
  font-size: 13px;
}
.total-row strong { font-weight: 520; white-space: nowrap; }
.summary-edit-button {
  border: 0;
  outline: 0;
  padding: 2px 0;
  margin: 0;
  border-radius: 5px;
  background: transparent;
  color: #152238;
  font: inherit;
  text-align: right;
}
.summary-edit-button:hover { color: #1769ff; }
.summary-edit-button:focus-visible { box-shadow: var(--focus); }
.summary-money-button { margin-left: auto; text-align: right; font-weight: 520; white-space: nowrap; }
.total-divider { height: 1px; background: var(--line); margin: 3px 0 9px; }
.grand-total { min-height: 36px; font-size: 18px; font-weight: 650; }
.grand-total strong { font-size: 20px; font-weight: 700; }

.preview-view { padding: 4px 0 20px; }
.preview-view[hidden] { display: none !important; }
.invoice-preview-paper {
  width: min(840px, 100%);
  margin: 0 auto;
  min-height: 1080px;
  padding: 64px 64px 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #102037;
  box-shadow: 0 18px 50px rgba(15, 29, 53, .08);
}
.preview-header { display: flex; justify-content: space-between; gap: 40px; padding-bottom: 36px; border-bottom: 1px solid #e6ebf1; }
.preview-brand h1 { margin: 0 0 8px; font-size: 31px; letter-spacing: -.03em; }
.preview-brand p, .preview-meta p { margin: 5px 0; color: #66748b; white-space: pre-line; }
.preview-title { text-align: left; }
.preview-title h2 { margin: 0 0 16px; font-size: 30px; letter-spacing: .08em; font-weight: 680; }
.preview-meta { display: grid; gap: 6px; font-size: 13px; }
.preview-meta div { display: flex; justify-content: space-between; gap: 22px; }
.preview-meta strong { color: #1d2a42; }
.preview-billing { display: grid; grid-template-columns: 1fr 1fr; gap: 60px; padding: 38px 0; }
.preview-billing h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #7a879a; }
.preview-billing p { margin: 4px 0; white-space: pre-line; }
.preview-billing .name { font-weight: 650; font-size: 16px; }
.preview-items { width: 100%; border-collapse: collapse; }
.preview-items th { padding: 12px 10px; border-bottom: 1px solid #dfe5ed; text-align: right; font-size: 11px; color: #728098; text-transform: uppercase; letter-spacing: .05em; }
.preview-items td { padding: 16px 10px; border-bottom: 1px solid #eef1f5; }
.preview-items th:nth-child(n+2), .preview-items td:nth-child(n+2) { text-align: center; }
.preview-item-title { font-weight: 620; }
.preview-item-desc { margin-top: 4px; font-size: 12px; color: #78859a; }
.preview-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 42px;
  align-items: start;
  margin-top: 32px;
}
.preview-summary.no-qr { grid-template-columns: 1fr; }
.preview-summary.no-qr .preview-totals { margin-right: auto; margin-left: 0; }
.preview-qr {
  width: 150px;
  display: grid;
  gap: 8px;
  justify-items: start;
}
.preview-qr-code {
  width: 132px;
  height: 132px;
  display: block;
  padding: 7px;
  border: 1px solid #e1e6ed;
  border-radius: 8px;
  background: #fff;
}
.preview-qr-code svg { width: 100%; height: 100%; display: block; }
.preview-qr-label {
  margin: 0;
  color: #7b8798;
  font-size: 10px;
  line-height: 1.35;
}
.preview-qr-label strong { display: block; color: #39465a; font-size: 10px; font-weight: 650; }
.preview-totals { width: 320px; margin: 0 auto 0 0; }
.preview-totals-row { display: flex; justify-content: space-between; padding: 8px 0; }
.preview-totals-row.total { border-top: 1px solid #dfe5ed; margin-top: 6px; padding-top: 15px; font-size: 19px; font-weight: 700; }
.preview-footer { margin-top: 70px; padding-top: 20px; border-top: 1px solid #edf1f5; color: #8793a5; font-size: 12px; text-align: center; }


/* Invoice templates */
.invoice-preview-paper {
  --invoice-accent: #1769ff;
  --invoice-soft: #f3f7ff;
  --invoice-rule: #dfe6f0;
  transition: padding .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.invoice-preview-paper.template-modern {
  border-top: 5px solid var(--invoice-accent);
  box-shadow: 0 20px 56px rgba(23, 105, 255, .08), 0 8px 24px rgba(15, 29, 53, .05);
}
.template-modern .preview-title h2 { color: var(--invoice-accent); }
.template-modern .preview-items thead { background: var(--invoice-soft); }
.template-modern .preview-items th { color: #3565a9; border-bottom-color: #cddcf3; }
.template-modern .preview-billing h3 { color: #52709a; }
.template-modern .preview-totals-row.total { border-top: 2px solid var(--invoice-accent); color: #0f3c86; }

.invoice-preview-paper.template-classic {
  padding: 70px 68px 76px;
  border: 1px solid #d8d2c7;
  border-top: 7px double #253247;
  border-radius: 2px;
  box-shadow: 0 16px 44px rgba(36, 43, 54, .08);
}
.template-classic .preview-header { align-items: flex-end; border-bottom: 2px solid #253247; padding-bottom: 28px; }
.template-classic .preview-brand h1 { font-size: 34px; font-weight: 700; }
.template-classic .preview-title h2 {
  display: inline-block;
  padding: 7px 12px;
  border: 1px solid #253247;
  font-size: 24px;
  font-weight: 700;
}
.template-classic .preview-billing { border-bottom: 1px solid #d8d2c7; }
.template-classic .preview-billing h3 { color: #5f5548; font-weight: 700; }
.template-classic .preview-items { margin-top: 10px; }
.template-classic .preview-items thead { background: #f4f1eb; }
.template-classic .preview-items th { color: #443d34; border-top: 1px solid #b9b0a3; border-bottom: 1px solid #b9b0a3; }
.template-classic .preview-items td { border-bottom-color: #e2ddd4; }
.template-classic .preview-totals-row.total { border-top: 2px solid #253247; }
.template-classic .preview-footer { border-top-color: #d8d2c7; color: #6f675c; }

.invoice-preview-paper.template-compact {
  min-height: 900px;
  padding: 38px 42px 44px;
  border-top: 4px solid #102037;
  border-radius: 6px;
}
.template-compact .preview-header { gap: 24px; padding-bottom: 18px; }
.template-compact .preview-brand h1 { margin-bottom: 4px; font-size: 26px; }
.template-compact .preview-brand p, .template-compact .preview-meta p { margin: 2px 0; }
.template-compact .preview-title h2 { margin-bottom: 10px; font-size: 24px; }
.template-compact .preview-meta { gap: 2px; font-size: 12px; }
.template-compact .preview-billing { gap: 34px; padding: 20px 0; }
.template-compact .preview-billing h3 { margin-bottom: 5px; }
.template-compact .preview-billing p { margin: 2px 0; font-size: 12px; }
.template-compact .preview-billing .name { font-size: 14px; }
.template-compact .preview-items thead { background: #102037; }
.template-compact .preview-items th { height: 34px; padding: 8px 8px; color: #fff; border-bottom: 0; }
.template-compact .preview-items td { padding: 9px 8px; font-size: 12px; }
.template-compact .preview-item-desc { margin-top: 2px; font-size: 10px; }
.template-compact .preview-summary { gap: 28px; margin-top: 20px; }
.template-compact .preview-qr { width: 128px; gap: 5px; }
.template-compact .preview-qr-code { width: 112px; height: 112px; }
.template-compact .preview-totals { width: 290px; }
.template-compact .preview-totals-row { padding: 5px 0; font-size: 12px; }
.template-compact .preview-totals-row.total { padding-top: 10px; font-size: 16px; }
.template-compact .preview-footer { margin-top: 34px; padding-top: 13px; font-size: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(10px);
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: calc(100vw - 32px);
  padding: 11px 14px;
  border-radius: 10px;
  color: #fff;
  background: #0e1c31;
  box-shadow: 0 12px 30px rgba(15,29,53,.18);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 17px; height: 17px; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

body.dark {
  color-scheme: dark;
  --bg: #111111;
  --panel: rgba(24, 24, 24, .97);
  --panel-solid: #181818;
  --text: #f2f2f2;
  --muted: #a3a3a3;
  --line: #2f2f2f;
  --line-strong: #3a3a3a;
  --input-bg: #202020;
  --table-head: #1d1d1d;
  --shadow: 0 2px 14px rgba(0, 0, 0, .24);
  --focus: 0 0 0 3px rgba(255, 255, 255, .12);
  background: #111111;
}
body.dark {
  background-image: radial-gradient(circle at 50% -250px, rgba(255, 255, 255, .035), transparent 520px);
}
body.dark .section-heading h2,
body.dark input,
body.dark textarea,
body.dark select,
body.dark .items-table th,
body.dark .item-number,
body.dark .item-copy input,
body.dark .total-row,
body.dark .summary-edit-button,
body.dark .adjustment-copy strong,
body.dark .qr-option-copy strong { color: #f1f1f1; }
body.dark .field > span:first-child,
body.dark .item-copy input.item-desc,
body.dark .adjustment-copy small,
body.dark .qr-option-copy small,
body.dark .percent-input-wrap > span,
body.dark .select-wrap > svg,
body.dark .calendar-trigger { color: #a3a3a3; }
body.dark .heading-icon.blue,
body.dark .heading-icon.purple,
body.dark .heading-icon.green { color: #d6d6d6; background: #2a2a2a; }
body.dark .heading-icon.transparent { color: #d6d6d6; background: #242424; border-color: #383838; box-shadow: none; }
body.dark .mode-switch { background: #161616; border-color: #2d2d2d; }
body.dark .mode-tab { color: #a7a7a7; }
body.dark .mode-tab.active { background: #292929; color: #f4f4f4; box-shadow: none; }
body.dark .mode-tab.active::after { background: #d9d9d9; }
body.dark .icon-button,
body.dark .outline-button { background: #202020; border-color: #3a3a3a; color: #e8e8e8; }
body.dark .icon-button:hover,
body.dark .outline-button:hover { background: #292929; border-color: #505050; }
body.dark .primary-button {
  background: linear-gradient(180deg, #ededed 0%, #d8d8d8 100%);
  color: #151515;
  box-shadow: 0 7px 18px rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.45);
}
body.dark .primary-button:hover { box-shadow: 0 9px 22px rgba(0,0,0,.24), inset 0 1px 0 rgba(255,255,255,.5); }
body.dark .send-button { background: linear-gradient(180deg, #333333 0%, #262626 100%); color: #f6f6f6; }
body.dark .send-menu { background: #202020; border-color: #343434; }
body.dark .send-menu button { color: #e8e8e8; }
body.dark .send-menu button:hover { background: #2a2a2a; }
body.dark .send-menu svg { color: #a9a9a9; }
body.dark input:hover,
body.dark textarea:hover,
body.dark select:hover { border-color: #505050; }
body.dark input:focus,
body.dark textarea:focus,
body.dark select:focus { border-color: #6a6a6a; }
body.dark .calendar-trigger:hover { background: #292929; }
body.dark .items-table td { border-color: #303030; }
body.dark .amount-display { background: #202020; border-color: #393939; color: #eeeeee; }
body.dark .delete-item { color: #a8a8a8; }
body.dark .delete-item:hover { background: #292929; color: #f5f5f5; }
body.dark .toast { background: #2b2b2b; color: #f4f4f4; }
body.dark .adjustment-field,
body.dark .qr-option { background: #1d1d1d; border-color: #303030; }
body.dark .summary-edit-button:hover { color: #ffffff; }
body.dark .switch-track { background: #4b4b4b; }
body.dark .switch-control input:checked + .switch-track { background: #d8d8d8; }
body.dark .switch-control input:checked + .switch-track .switch-thumb { background: #181818; }

/* The printable invoice is deliberately theme-independent. */
.invoice-preview-paper,
body.dark .invoice-preview-paper {
  color-scheme: light;
  background: #fff;
  color: #102037;
  border-color: #e2e8f0;
}
body.dark .invoice-preview-paper .preview-brand p,
body.dark .invoice-preview-paper .preview-meta p,
body.dark .invoice-preview-paper .preview-item-desc { color: #78859a; }
body.dark .invoice-preview-paper .preview-billing .name,
body.dark .invoice-preview-paper .preview-meta strong { color: #1d2a42; }
body.dark .invoice-preview-paper .preview-billing h3 { color: #7a879a; }
body.dark .invoice-preview-paper .preview-items th { color: #728098; border-color: #dfe5ed; }
body.dark .invoice-preview-paper .preview-items td { color: #102037; border-color: #eef1f5; }
body.dark .invoice-preview-paper .preview-totals-row { color: #102037; }
body.dark .invoice-preview-paper .preview-footer { color: #8793a5; border-color: #edf1f5; }
body.dark .invoice-preview-paper .preview-qr-label { color: #7b8798; }
body.dark .invoice-preview-paper .preview-qr-label strong { color: #39465a; }

@media (max-width: 980px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "left send" "mode mode"; height: auto; min-height: 126px; padding: 14px 16px; column-gap: 12px; row-gap: 12px; }
  .topbar-left { grid-area: left; }
  .mode-switch { grid-area: mode; width: min(330px, 100%); }
  .send-wrap { grid-area: send; }
  main { margin-top: 16px; }
  .party-grid { grid-template-columns: 1fr; }
  .party-card { min-height: unset; }
  .details-grid { grid-template-columns: repeat(2, 1fr); }
  .adjustment-grid { grid-template-columns: 1fr 1fr; }
  .qr-option { grid-column: 1 / -1; }
  .items-footer { grid-template-columns: 1fr 330px; }
}

@media (max-width: 720px) {
  body { font-size: 14px; }
  .app-shell { padding: 14px 8px 18px; }
  .panel { border-radius: 12px; }
  .topbar { padding: 10px; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "theme new send" "mode mode mode"; column-gap: 8px; row-gap: 10px; }
  .topbar-left { display: contents; }
  .theme-button { grid-area: theme; width: 46px; height: 47px; }
  .new-invoice { grid-area: new; min-width: 0; width: 100%; padding: 0 15px; height: 47px; }
  .send-wrap { grid-area: send; }
  .send-button { width: 48px; height: 47px; padding: 0; justify-content: center; }
  .send-main span, .send-chevron { display: none; }
  .send-menu { right: 0; width: 220px; }
  .mode-switch { height: 46px; width: 100%; }
  main { margin-top: 12px; }
  .editor-view { gap: 12px; }
  .party-grid { gap: 12px; }
  .card { padding: 20px 16px; }
  .section-heading { margin-bottom: 18px; height: 40px; gap: 12px; }
  .heading-icon { width: 40px; height: 40px; }
  .section-heading h2 { font-size: 17px; }
  .form-grid, .details-grid, .adjustment-grid { grid-template-columns: 1fr; gap: 12px; }
  .qr-option { grid-column: auto; }
  .adjustment-field, .qr-option { min-height: 68px; }
  .field-wide, .field-address, .field-phone { grid-column: auto; }
  textarea { min-height: 82px; }
  .items-card { min-height: 0; }
  .items-table-shell { border: 0; overflow: visible; }
  .items-table, .items-table tbody { display: block; }
  .items-table thead { display: none; }
  .items-table tr {
    display: grid;
    grid-template-columns: 32px 1fr 42px;
    gap: 10px;
    padding: 13px;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--input-bg);
  }
  .items-table td { display: block; height: auto; min-height: 0; padding: 0; border: 0 !important; }
  .items-table td:nth-child(1) { grid-column: 1; grid-row: 1; align-self: center; }
  .items-table td:nth-child(2) { grid-column: 2; grid-row: 1; }
  .items-table td:nth-child(6) { grid-column: 3; grid-row: 1; align-self: center; }
  .items-table td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
  .items-table td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
  .items-table td:nth-child(5) { grid-column: 1 / -1; grid-row: 4; }
  .items-table td:nth-child(3)::before,
  .items-table td:nth-child(4)::before,
  .items-table td:nth-child(5)::before {
    display: block;
    margin: 0 0 6px;
    color: #6e7b91;
    font-size: 11px;
    font-weight: 600;
  }
  .items-table td:nth-child(3)::before { content: "تعداد"; }
  .items-table td:nth-child(4)::before { content: "نرخ"; }
  .items-table td:nth-child(5)::before { content: "مبلغ"; }
  .table-input, .item-qty, .item-rate, .amount-display { width: 100%; }
  .items-footer { grid-template-columns: 1fr; gap: 20px; }
  .add-item { width: 100%; }
  .totals { width: 100%; }
  .grand-total { font-size: 17px; }
  .grand-total strong { font-size: 19px; }
  .invoice-preview-paper { min-height: 0; padding: 30px 20px 40px; border-radius: 10px; }
  .preview-header { display: grid; gap: 24px; }
  .preview-title { text-align: right; }
  .preview-billing { grid-template-columns: 1fr; gap: 25px; }
  .preview-items { font-size: 12px; }
  .preview-items th, .preview-items td { padding-left: 5px; padding-right: 5px; }
  .preview-summary { grid-template-columns: 1fr; gap: 24px; }
  .preview-qr { width: 100%; justify-items: start; }
  .preview-totals { width: 100%; }
}

body.dark .items-table td:nth-child(3)::before,
body.dark .items-table td:nth-child(4)::before,
body.dark .items-table td:nth-child(5)::before { color: #9d9d9d; }


@media (max-width: 720px) {
  .invoice-preview-paper.template-classic,
  .invoice-preview-paper.template-compact { padding: 28px 22px 34px; }
}

@media print {
  body { background: #fff !important; }
  .app-shell > .topbar, #editorView { display: none !important; }
  main { margin: 0; }
  #previewView { display: block !important; padding: 0; }
  .app-shell { padding: 0; }
  .invoice-preview-paper {
    width: 100%;
    min-height: 0;
    margin: 0;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    background: #fff !important;
    color: #102037 !important;
    color-scheme: light !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .toast { display: none !important; }
}


/* Persian / RTL localization */
html, body { direction: rtl; }
body { text-align: right; }
.send-menu { right: auto; left: 0; }
.send-menu button { text-align: right; }
select { padding-right: 13px; padding-left: 42px; }
.select-wrap > svg { right: auto; left: 15px; }
.date-wrap > input:first-child { padding-right: 13px; padding-left: 48px; }
.calendar-trigger { right: auto; left: 3px; }
.percent-input-wrap input { padding: 0 10px 0 28px; text-align: left; direction: ltr; }
.percent-input-wrap > span { right: auto; left: 10px; }
.switch-control input:checked + .switch-track .switch-thumb { transform: translateX(-18px); }
input[type="email"], .item-rate, .amount-display, .currency-code,
.preview-meta strong, .preview-totals strong, .preview-items td:nth-child(n+2), .preview-qr-label {
  direction: ltr;
  unicode-bidi: embed;
}
input[type="email"] { text-align: left; }
#invoiceNumber { text-align: right; direction: rtl; }
.item-copy input { text-align: right; }
.delete-item { margin-left: 0; margin-right: auto; }
.summary-edit-button { text-align: right; }
.preview-brand, .preview-billing, .preview-items, .preview-footer { text-align: right; }
.preview-meta div, .preview-totals-row { direction: rtl; }
.preview-meta strong, .preview-totals-row strong { text-align: left; }
.preview-qr { justify-items: end; }
.preview-qr-label { text-align: right; direction: rtl; }
.preview-title h2 { letter-spacing: 0; }
.preview-billing h3, .preview-items th { text-transform: none; letter-spacing: 0; }
@media (max-width: 720px) {
  .send-menu { right: auto; left: 0; }
  .preview-qr { justify-items: end; }
}

[dir="rtl"] .section-heading h2, [dir="rtl"] .primary-button, [dir="rtl"] .send-button { letter-spacing: 0; }


/* v4: additional invoice templates */
.invoice-preview-paper.template-monochrome {
  --invoice-accent: #000;
  --invoice-soft: #fff;
  --invoice-rule: #000;
  background: #fff !important;
  color: #000 !important;
  border: 1px solid #000;
  border-top: 3px solid #000;
  box-shadow: 0 16px 42px rgba(0, 0, 0, .07);
}
.template-monochrome .preview-header {
  border-bottom: 2px solid #000 !important;
}
.template-monochrome .preview-brand h1,
.template-monochrome .preview-brand p,
.template-monochrome .preview-title h2,
.template-monochrome .preview-meta,
.template-monochrome .preview-meta strong,
.template-monochrome .preview-billing h3,
.template-monochrome .preview-billing p,
.template-monochrome .preview-billing .name,
.template-monochrome .preview-items th,
.template-monochrome .preview-items td,
.template-monochrome .preview-item-desc,
.template-monochrome .preview-totals-row,
.template-monochrome .preview-totals-row.total,
.template-monochrome .preview-footer,
.template-monochrome .preview-qr-label,
.template-monochrome .preview-qr-label strong {
  color: #000 !important;
}
.template-monochrome .preview-items thead {
  background: transparent !important;
}
.template-monochrome .preview-items th {
  border-top: 1px solid #000 !important;
  border-bottom: 1px solid #000 !important;
}
.template-monochrome .preview-items td { border-bottom-color: #b7b7b7 !important; }
.template-monochrome .preview-totals-row.total { border-top: 2px solid #000 !important; }
.template-monochrome .preview-footer { border-top-color: #000 !important; }
.template-monochrome .preview-qr-code { border-color: #000; border-radius: 0; }

.invoice-preview-paper.template-cards-rounded,
.invoice-preview-paper.template-cards-square {
  --invoice-accent: #1769ff;
  --invoice-soft: #f5f8ff;
  --invoice-card-bg: #fff;
  --invoice-card-line: #dfe6ef;
  padding: 34px;
  background: #f3f6fa !important;
  border: 1px solid #dfe6ef;
  box-shadow: 0 20px 58px rgba(15, 29, 53, .08);
}
.template-cards-rounded .preview-header,
.template-cards-square .preview-header {
  padding: 24px;
  border: 1px solid var(--invoice-card-line) !important;
  background: var(--invoice-card-bg) !important;
  box-shadow: 0 6px 18px rgba(15, 29, 53, .035);
}
.template-cards-rounded .preview-billing,
.template-cards-square .preview-billing {
  gap: 14px;
  padding: 14px 0;
}
.template-cards-rounded .preview-billing > div,
.template-cards-square .preview-billing > div {
  padding: 20px;
  border: 1px solid var(--invoice-card-line);
  background: var(--invoice-card-bg) !important;
  box-shadow: 0 6px 18px rgba(15, 29, 53, .03);
}
.template-cards-rounded .preview-items,
.template-cards-square .preview-items {
  border: 1px solid var(--invoice-card-line);
  border-collapse: separate;
  border-spacing: 0;
  background: var(--invoice-card-bg) !important;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(15, 29, 53, .03);
}
.template-cards-rounded .preview-items thead,
.template-cards-square .preview-items thead { background: var(--invoice-soft) !important; }
.template-cards-rounded .preview-items tr:last-child td,
.template-cards-square .preview-items tr:last-child td { border-bottom: 0; }
.template-cards-rounded .preview-summary,
.template-cards-square .preview-summary {
  gap: 14px;
  margin-top: 14px;
}
.template-cards-rounded .preview-qr,
.template-cards-square .preview-qr,
.template-cards-rounded .preview-totals,
.template-cards-square .preview-totals {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--invoice-card-line);
  background: var(--invoice-card-bg) !important;
  box-shadow: 0 6px 18px rgba(15, 29, 53, .03);
}
.template-cards-rounded .preview-qr,
.template-cards-square .preview-qr { width: 100%; }
.template-cards-rounded .preview-totals,
.template-cards-square .preview-totals { width: 320px; }
.template-cards-rounded .preview-summary.no-qr .preview-totals,
.template-cards-square .preview-summary.no-qr .preview-totals { margin-right: auto; }
.template-cards-rounded .preview-footer,
.template-cards-square .preview-footer {
  margin-top: 14px;
  padding: 15px 18px;
  border: 1px solid var(--invoice-card-line) !important;
  background: var(--invoice-card-bg) !important;
  box-shadow: 0 6px 18px rgba(15, 29, 53, .03);
}
.template-cards-rounded .preview-header,
.template-cards-rounded .preview-billing > div,
.template-cards-rounded .preview-items,
.template-cards-rounded .preview-qr,
.template-cards-rounded .preview-totals,
.template-cards-rounded .preview-footer { border-radius: 18px; }
.template-cards-rounded .preview-qr-code { border-radius: 12px; }

.template-cards-square .preview-header,
.template-cards-square .preview-billing > div,
.template-cards-square .preview-items,
.template-cards-square .preview-qr,
.template-cards-square .preview-totals,
.template-cards-square .preview-footer,
.template-cards-square .preview-qr-code { border-radius: 0; }

/* Dedicated 80 mm thermal-receipt layout. Height stays content-driven on screen
   and is converted to a custom page height before printing. */
.invoice-preview-paper.paper-thermal {
  width: 80mm;
  max-width: 80mm;
  min-height: 0;
  margin: 0 auto;
  padding: 5mm 4mm 6mm;
  border-radius: 6px;
  font-size: 10px;
  line-height: 1.45;
  box-shadow: 0 16px 42px rgba(15, 29, 53, .09);
}
.paper-thermal .preview-header {
  display: grid;
  gap: 3mm;
  padding-bottom: 4mm;
}
.paper-thermal .preview-brand h1 {
  margin-bottom: 1.5mm;
  font-size: 19px;
  line-height: 1.25;
}
.paper-thermal .preview-brand p { margin: 1mm 0; font-size: 9px; }
.paper-thermal .preview-title { text-align: right; }
.paper-thermal .preview-title h2 { margin-bottom: 2mm; font-size: 18px; }
.paper-thermal .preview-meta { gap: 1mm; font-size: 9px; }
.paper-thermal .preview-meta div { gap: 3mm; }
.paper-thermal .preview-billing {
  grid-template-columns: 1fr;
  gap: 3mm;
  padding: 4mm 0;
}
.paper-thermal .preview-billing h3 { margin-bottom: 1mm; font-size: 8px; }
.paper-thermal .preview-billing p { margin: .6mm 0; font-size: 9px; }
.paper-thermal .preview-billing .name { font-size: 11px; }
.paper-thermal .preview-items {
  table-layout: fixed;
  font-size: 8px;
}
.paper-thermal .preview-items th,
.paper-thermal .preview-items td {
  padding: 2mm .9mm;
  line-height: 1.35;
  vertical-align: top;
  overflow-wrap: anywhere;
}
.paper-thermal .preview-items th { font-size: 7px; }
.paper-thermal .preview-items th:first-child,
.paper-thermal .preview-items td:first-child { width: 38%; }
.paper-thermal .preview-items th:nth-child(2),
.paper-thermal .preview-items td:nth-child(2) { width: 12%; }
.paper-thermal .preview-items th:nth-child(3),
.paper-thermal .preview-items td:nth-child(3) { width: 24%; }
.paper-thermal .preview-items th:nth-child(4),
.paper-thermal .preview-items td:nth-child(4) { width: 26%; }
.paper-thermal .preview-item-title { font-size: 8px; }
.paper-thermal .preview-item-desc { margin-top: .7mm; font-size: 7px; line-height: 1.35; }
.paper-thermal .preview-summary,
.paper-thermal .preview-summary.no-qr {
  grid-template-columns: 1fr;
  gap: 3mm;
  margin-top: 4mm;
}
.paper-thermal .preview-qr {
  width: 100%;
  justify-items: center;
}
.paper-thermal .preview-qr-code {
  width: 28mm;
  height: 28mm;
  padding: 1.5mm;
}
.paper-thermal .preview-qr-label { text-align: center; font-size: 7px; }
.paper-thermal .preview-qr-label strong { font-size: 8px; }
.paper-thermal .preview-totals,
.paper-thermal .preview-summary.no-qr .preview-totals {
  width: 100%;
  margin: 0;
}
.paper-thermal .preview-totals-row { padding: 1.2mm 0; font-size: 9px; }
.paper-thermal .preview-totals-row.total { margin-top: 1mm; padding-top: 2.5mm; font-size: 13px; }
.paper-thermal .preview-footer { margin-top: 5mm; padding-top: 3mm; font-size: 8px; }

/* Card templates also have receipt-specific compact card spacing. */
.invoice-preview-paper.paper-thermal.template-cards-rounded,
.invoice-preview-paper.paper-thermal.template-cards-square {
  padding: 3mm;
}
.paper-thermal.template-cards-rounded .preview-header,
.paper-thermal.template-cards-square .preview-header,
.paper-thermal.template-cards-rounded .preview-billing > div,
.paper-thermal.template-cards-square .preview-billing > div,
.paper-thermal.template-cards-rounded .preview-qr,
.paper-thermal.template-cards-square .preview-qr,
.paper-thermal.template-cards-rounded .preview-totals,
.paper-thermal.template-cards-square .preview-totals,
.paper-thermal.template-cards-rounded .preview-footer,
.paper-thermal.template-cards-square .preview-footer {
  padding: 3mm;
}
.paper-thermal.template-cards-rounded .preview-header,
.paper-thermal.template-cards-rounded .preview-billing > div,
.paper-thermal.template-cards-rounded .preview-items,
.paper-thermal.template-cards-rounded .preview-qr,
.paper-thermal.template-cards-rounded .preview-totals,
.paper-thermal.template-cards-rounded .preview-footer { border-radius: 10px; }
.paper-thermal.template-cards-square .preview-header,
.paper-thermal.template-cards-square .preview-billing > div,
.paper-thermal.template-cards-square .preview-items,
.paper-thermal.template-cards-square .preview-qr,
.paper-thermal.template-cards-square .preview-totals,
.paper-thermal.template-cards-square .preview-footer { border-radius: 0; }

@media (max-width: 720px) {
  .invoice-preview-paper.paper-thermal {
    width: 80mm;
    max-width: calc(100vw - 16px);
    padding: 5mm 4mm 6mm;
  }
  .template-cards-rounded .preview-totals,
  .template-cards-square .preview-totals { width: 100%; }
  .template-cards-rounded .preview-header,
  .template-cards-square .preview-header { padding: 18px; }
}

@media print {
  .invoice-preview-paper.paper-a4 {
    width: 210mm !important;
    max-width: 210mm !important;
    min-height: 0 !important;
  }
  .invoice-preview-paper.paper-thermal {
    width: 80mm !important;
    max-width: 80mm !important;
    min-height: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}
