@font-face {
  font-family: Vazirmatn;
  font-style: normal;
  font-weight: 200;
  src: url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-Medium.woff2') format('woff2'),
       url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-Medium.woff') format('woff');
}

@font-face {
  font-family: Vazirmatn;
  font-style: normal;
  font-weight: 400;
  src: url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-Regular.woff2') format('woff2'),
       url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-Regular.woff') format('woff');
}

@font-face {
  font-family: Vazirmatn;
  font-style: normal;
  font-weight: 700;
  src: url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-Bold.woff2') format('woff2'),
       url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-Bold.woff') format('woff');
}

@font-face {
  font-family: Vazirmatn;
  font-style: normal;
  font-weight: 800;
  src: url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-ExtraBold.woff2') format('woff2'),
       url('https://raw.githubusercontent.com/rastikerdar/vazirmatn/master/fonts/webfonts/Vazirmatn-ExtraBold.woff') format('woff');
}

.dashboard-float-btn {
  position: fixed;
  left: 20px;
  bottom: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 210px;
  min-height: 54px;
  padding: 0 22px;
  border-radius: 16px;
  text-decoration: none;
  background: linear-gradient(135deg, #111827 0%, #1f2937 45%, #0f172a 100%);
  color: #ffffff;
  font-weight: 800;
  font-size: 15px;
  box-shadow:
    0 12px 35px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    inset 0 -1px 0 rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  z-index: 9999;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.dashboard-float-btn .btn-text {
  position: relative;
  z-index: 2;
  letter-spacing: -0.2px;
}

.dashboard-float-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.03) 45%,
    rgba(255, 255, 255, 0.00) 100%
  );
  pointer-events: none;
  z-index: 1;
}

.dashboard-float-btn::after {
  content: "";
  position: absolute;
  top: -70%;
  left: -130%;
  width: 58%;
  height: 240%;
  background: linear-gradient(
    120deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.05) 30%,
    rgba(255, 255, 255, 0.42) 50%,
    rgba(255, 255, 255, 0.06) 70%,
    rgba(255, 255, 255, 0) 100%
  );
  transform: rotate(18deg);
  pointer-events: none;
  z-index: 2;
}

.dashboard-float-btn:hover {
  transform: translateY(-4px) scale(1.02);
  color: #ffffff;
  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.dashboard-float-btn:hover::after {
  animation: dashboardShine 1.15s ease forwards;
}

.dashboard-float-btn:active {
  transform: translateY(-1px) scale(0.99);
}

.dashboard-float-btn:focus {
  outline: none;
  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.28),
    0 0 0 4px rgba(59, 130, 246, 0.22);
}

@keyframes dashboardShine {
  0% { left: -130%; }
  100% { left: 170%; }
}

@media (max-width: 768px) {
  .dashboard-float-btn {
    left: 14px;
    right: 14px;
    bottom: 14px;
    min-width: auto;
    width: auto;
    min-height: 50px;
    border-radius: 14px;
    font-size: 14px;
    padding: 0 18px;
  }
}

.dashboard-float-btn .btn-icon {
  position: relative;
  z-index: 2;
  font-size: 18px;
  line-height: 1;
  opacity: 0.95;
}

.copyright-box.dark {
  position: relative;
  overflow: hidden;
}

.copyright-box.dark a {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  position: relative;
  z-index: 2;
}

.copyright-box.dark a:hover {
  text-decoration: underline;
  opacity: 0.9;
}

.copyright-box.dark::before {
  content: "";
  position: absolute;
  top: -60%;
  left: -120%;
  width: 60%;
  height: 220%;
  background: linear-gradient(
    120deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.08) 35%,
    rgba(255, 255, 255, 0.45) 50%,
    rgba(255, 255, 255, 0.08) 65%,
    rgba(255, 255, 255, 0) 100%
  );
  transform: rotate(18deg);
  pointer-events: none;
  z-index: 1;
}

.copyright-box.dark:hover::before {
  animation: glassShine 1.2s ease forwards;
}

@keyframes glassShine {
  0% { left: -120%; }
  100% { left: 160%; }
}

:root {
  --accent: #f4b400;
  --accent-soft: #fff4cc;
  --accent-dark: #cc9400;
  --accent-text: #14213d;
  --accent-contrast: #ffffff;

  --border: #7c8494;
  --soft: #f8f9fb;
  --text: #273043;
  --muted: #6b7280;
  --line: #d7dde7;
  --paper: #ffffff;
  --accent-shadow: rgba(244, 180, 0, 0.18);
  --accent-ring: rgba(244, 180, 0, 0.15);
}

* {
  box-sizing: border-box;
  font-family: 'Vazirmatn', sans-serif;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 15%, rgba(0, 0, 0, 0.02), transparent 28%),
    radial-gradient(circle at 85% 20%, rgba(0, 0, 0, 0.025), transparent 25%),
    radial-gradient(circle at 20% 80%, rgba(0, 0, 0, 0.015), transparent 30%),
    linear-gradient(180deg, #fafafa, #f2f2f2);
  color: var(--text);
}

.page-wrap {
  max-width: 1100px;
  margin: 32px auto 60px;
  padding: 0 16px;
}

.top-title {
  text-align: center;
  margin-bottom: 22px;
}

.top-title .icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-dark);
  font-size: 24px;
  margin-bottom: 10px;
  box-shadow: 0 8px 20px var(--accent-shadow);
}

.top-title h1 {
  font-size: clamp(28px, 4vw, 46px);
  margin: 0;
  font-weight: 800;
  color: var(--accent-text);
}

.top-title p {
  margin: 10px 0 0;
  color: #5f6b7a;
  font-size: 15px;
}

.toolbar {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.05);
}

.toolbar .btn,
.toolbar .form-control,
.toolbar .form-select {
  border-radius: 12px;
}

.invoice-paper {
  background: var(--paper);
  border: 2px solid var(--accent-dark);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.section-dashed {
  border-top: 2px dashed var(--accent-dark);
  margin: 18px 0;
}

.form-label {
  font-size: 13px;
  color: #4b5563;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-control,
.form-select,
textarea {
  border: 2px solid #adb5c2;
  border-radius: 10px !important;
  min-height: 44px;
  color: #1f2937;
  background: #fff;
  direction: rtl;
  text-align: right;
}

.form-control:focus,
.form-select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem var(--accent-ring);
}

.mini-field {
  max-width: 190px;
}

.invoice-head {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.head-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 210px;
}

.invoice-title-box {
  flex: 1;
  min-width: 260px;
  text-align: center;
  padding-top: 14px;
}

.invoice-title {
  font-size: clamp(28px, 4vw, 42px);
  margin: 0;
  font-weight: 800;
  color: var(--accent-text);
}

.logo-upload {
  width: 150px;
  min-height: 90px;
  border: 2px dashed var(--accent-dark);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--accent-text);
  font-size: 14px;
  padding: 10px;
  cursor: pointer;
  overflow: hidden;
}

.logo-upload img {
  max-width: 100%;
  max-height: 85px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}

.box-panel {
  border: 2px solid var(--accent-dark);
  border-radius: 14px;
  padding: 14px;
  height: 100%;
  background: #fff;
}

.box-title {
  font-weight: 700;
  color: var(--accent-text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px dashed var(--accent-dark);
  padding-bottom: 8px;
}

.table-wrap {
  border: 2px solid var(--accent-dark);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
}

thead th {
  background: var(--accent-soft);
  border-bottom: 2px solid var(--accent-dark);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 14px;
  padding: 12px 10px;
  text-align: center;
  white-space: nowrap;
}

tbody td {
  border-top: 1px solid var(--line);
  padding: 8px;
  vertical-align: middle;
  background: #fff;
}

tbody tr:first-child td {
  border-top: none;
}

.table-input {
  width: 100%;
  min-width: 80px;
  border: 1px solid #c9d1dc;
  border-radius: 10px;
  min-height: 40px;
  padding: 8px 10px;
  outline: none;
  direction: rtl;
  text-align: right;
}

.table-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.15rem var(--accent-ring);
}

.desc-input {
  min-width: 240px;
}

.row-total {
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  text-align: center;
  display: block;
}

.btn-soft {
  border: 2px dashed var(--accent-dark);
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  width: 100%;
}

.btn-soft:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-soft);
  filter: brightness(0.98);
}

.summary-card {
  border: 2px solid var(--accent-dark);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
  height: 100%;
}

.summary-title {
  font-size: 30px;
  font-weight: 800;
  color: var(--accent-text);
  margin-bottom: 10px;
  line-height: 1.2;
}

.summary-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 15px;
  color: #334155;
}

.summary-item strong {
  font-size: 15px;
}

.summary-divider {
  border-top: 3px solid var(--accent-dark);
  margin: 12px 0;
}

.payable {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 28px;
  font-weight: 800;
  color: #111827;
  flex-wrap: wrap;
}

.amount-big {
  color: #111827;
  font-size: 30px;
  font-weight: 800;
}

.currency-toggle .btn {
  min-width: 76px;
  border-radius: 10px !important;
  font-weight: 700;
  margin-left: 10px;
}

/* ========== پالت رنگ تم فاکتور (اصلاح‌شده) ========== */
.color-palette {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.color-palette .swatch,
.color-palette button.swatch,
.color-palette .btn.swatch {
  display: block;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  margin: 0;
  line-height: 30px;

  border: 2px solid #ffffff;
  border-radius: 8px;
  outline: 1px solid #d1d5db;

  cursor: pointer;
  opacity: 1;
  visibility: visible;

  -webkit-appearance: none;
  appearance: none;

  /* مهم: Bootstrap با background شورت‌هند رنگ را خالی می‌کند */
  background-image: none !important;
  background-repeat: no-repeat !important;
  background-size: auto !important;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.14),
    0 0 0 1px rgba(0, 0, 0, 0.04);

  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.color-palette .swatch:hover {
  transform: scale(1.12);
  outline: 2px solid #6b7280;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.22),
    0 0 0 2px rgba(255, 255, 255, 0.9);
}

.color-palette .swatch:focus,
.color-palette .swatch:focus-visible {
  outline: 2px solid #6b7280;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.22),
    0 0 0 2px rgba(255, 255, 255, 0.9);
}

.color-palette .swatch.active,
.color-palette .swatch.is-active {
  outline: 3px solid #111827;
  transform: scale(1.08);
}

/* رنگ هر سوآچ — مستقیم روی background */
.color-palette .swatch.palette-yellow,
.color-palette .swatch.palette-yellow.btn {
  background: #f4b400 !important;
  background-color: #f4b400 !important;
}

.color-palette .swatch.palette-blue,
.color-palette .swatch.palette-blue.btn {
  background: #1d4ed8 !important;
  background-color: #1d4ed8 !important;
}

.color-palette .swatch.palette-teal,
.color-palette .swatch.palette-teal.btn {
  background: #0f766e !important;
  background-color: #0f766e !important;
}

.color-palette .swatch.palette-purple,
.color-palette .swatch.palette-purple.btn {
  background: #7c3aed !important;
  background-color: #7c3aed !important;
}

.color-palette .swatch.palette-red,
.color-palette .swatch.palette-red.btn {
  background: #dc2626 !important;
  background-color: #dc2626 !important;
}

.color-palette .swatch.palette-dark,
.color-palette .swatch.palette-dark.btn {
  background: #111827 !important;
  background-color: #111827 !important;
}

.notes-box textarea {
  min-height: 250px;
  resize: vertical;
}

.stamp-area {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent-dark);
  border-radius: 12px;
  color: var(--accent-text);
  cursor: pointer;
  overflow: hidden;
  text-align: center;
  padding: 12px;
}

.stamp-area img {
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}

.signature-line {
  border-top: 2px solid var(--accent-dark);
  margin-top: 26px;
  padding-top: 8px;
  text-align: center;
  color: var(--accent-text);
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.remove-row {
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.remove-row:hover {
  color: #dc2626;
}

.hide-on-export {
  transition: all 0.2s ease;
}

.invoice-badge {
  display: inline-block;
  font-size: 13px;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  padding: 5px 10px;
  border-radius: 999px;
  font-weight: 700;
  margin-top: 8px;
}

.invoice-badge[contenteditable="true"] {
  cursor: text;
  outline: none;
  min-width: 120px;
}

.invoice-badge[contenteditable="true"]:focus {
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.money-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 6px 10px;
  font-weight: 700;
  min-width: 110px;
  text-align: left;
  direction: ltr;
}

.print-note {
  font-size: 12px;
  color: #64748b;
}

.stats-float-box {
  position: fixed;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9998;
  width: 200px;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 55%, #111827 100%);
  color: #fff;
  border-radius: 20px;
  padding: 18px 16px 16px;
  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stats-float-box::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.07) 0%,
    rgba(255, 255, 255, 0.02) 40%,
    transparent 100%
  );
  pointer-events: none;
}

.stats-float-box:hover {
  transform: translateY(-50%) scale(1.03);
  box-shadow:
    0 22px 55px rgba(0, 0, 0, 0.32),
    0 0 0 1px rgba(255, 255, 255, 0.12);
}

.stats-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  position: relative;
  z-index: 2;
}

.stats-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f4b400, #eab308);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 8px 18px rgba(244, 180, 0, 0.35);
  flex-shrink: 0;
}

.stats-title {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
  color: #f8fafc;
}

.stats-body {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-item {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px 12px 10px;
  text-align: center;
}

.stats-item .stats-label {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 600;
  margin-bottom: 4px;
}

.stats-item .stats-value {
  font-size: 28px;
  font-weight: 800;
  color: #fbbf24;
  line-height: 1.2;
  letter-spacing: -0.5px;
  direction: ltr;
}

.stats-item .stats-unit {
  font-size: 12px;
  color: #cbd5e1;
  font-weight: 600;
  margin-top: 2px;
}

.stats-footer {
  margin-top: 12px;
  text-align: center;
  font-size: 11px;
  color: #64748b;
  position: relative;
  z-index: 2;
  line-height: 1.6;
}

.stats-reset-btn {
  margin-top: 10px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  z-index: 2;
}

.stats-reset-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

@media (max-width: 1100px) {
  .stats-float-box {
    right: 10px;
    width: 170px;
    padding: 14px 12px;
  }
  .stats-item .stats-value {
    font-size: 24px;
  }
  .page-wrap {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 768px) {
  .stats-float-box {
    position: fixed;
    right: 12px;
    left: 12px;
    top: auto;
    bottom: 80px;
    transform: none;
    width: auto;
    max-width: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 16px;
  }
  .stats-float-box:hover {
    transform: none;
  }
  .stats-header {
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .stats-body {
    flex-direction: row;
    flex: 1;
    gap: 8px;
  }
  .stats-item {
    flex: 1;
    padding: 8px 6px;
  }
  .stats-item .stats-value {
    font-size: 20px;
  }
  .stats-footer,
  .stats-reset-btn {
    display: none;
  }
}

@media (max-width: 768px) {
  .invoice-paper {
    padding: 14px;
    border-radius: 16px;
  }
  .invoice-title {
    font-size: 28px;
  }
  .summary-title {
    font-size: 24px;
  }
  .amount-big {
    font-size: 24px;
  }
  .logo-upload {
    width: 100%;
  }
  .mini-field {
    max-width: 100%;
  }
  .invoice-head {
    flex-direction: column;
  }
  .table-wrap {
    overflow: auto;
  }
  table {
    min-width: 900px;
  }
}

@media print {
  .stats-float-box {
    display: none !important;
  }
  body {
    background: #fff !important;
  }
  .page-wrap {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  .toolbar,
  .top-title,
  .hide-on-export {
    display: none !important;
  }
  .invoice-paper {
    box-shadow: none;
    margin: 0;
    border-radius: 0;
  }
}

.copyright-box.dark {
  background: linear-gradient(135deg, #111827, #1f2937);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #f9fafb;
  padding: 16px 20px;
  border-radius: 14px;
  font-family: "Vazirmatn", sans-serif;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  max-width: 520px;
  margin: 20px auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

.watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-30deg);
  z-index: 0;
  pointer-events: none;
  user-select: none;
  opacity: 0.08;
  width: 75%;
  max-width: 900px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.watermark img {
  width: 100%;
  height: auto;
  display: block;
  filter: grayscale(0%);
}

.invoice-container,
.main-content,
.card,
.form-container {
  position: relative;
  z-index: 1;
}

@media print {
  .watermark {
    display: none !important;
  }
}

#invoiceCapture {
  direction: rtl;
  text-align: right;
}

input[type="number"],
.item-qty,
.item-price,
.item-discount,
#invoiceNumber,
#invoiceDate,
.row-total,
.amount-big,
#subtotalText,
#itemsDiscountText,
#globalDiscountText,
#taxText,
#finalAmountText {
  direction: ltr !important;
  text-align: left !important;
}
