/* ==========================================================================
   Design tokens + shared base components (panel, customer site, receipt)
   ========================================================================== */
@font-face {
  font-family: "Vazirmatn";
  src: url("/assets/fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --primary: #4f5bd5;
  --primary-600: color-mix(in srgb, var(--primary) 86%, #000);
  --primary-700: color-mix(in srgb, var(--primary) 70%, #000);
  --primary-soft: color-mix(in srgb, var(--primary) 9%, #fff);
  --primary-soft-2: color-mix(in srgb, var(--primary) 16%, #fff);
  --on-primary: #fff;

  --navy: #141935;
  --navy-2: #1c2247;
  --navy-line: rgba(255, 255, 255, .08);

  --bg: #f3f4f9;
  --surface: #fff;
  --surface-2: #f8f9fc;
  --line: #e6e8f1;
  --line-strong: #d5d9e8;
  --text: #171a33;
  --text-2: #555b77;
  --text-3: #8a90a8;

  --success: #0f9358;
  --success-soft: #e5f6ed;
  --danger: #d5344a;
  --danger-soft: #fdebee;
  --warn: #b26a0a;
  --warn-soft: #fff3dc;
  --info: #2a6fdb;
  --info-soft: #e8f0fd;

  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  --sh-xs: 0 1px 2px rgba(23, 26, 51, .05);
  --sh-sm: 0 1px 2px rgba(23, 26, 51, .04), 0 4px 14px rgba(23, 26, 51, .05);
  --sh-md: 0 2px 4px rgba(23, 26, 51, .04), 0 12px 32px rgba(23, 26, 51, .09);
  --sh-lg: 0 8px 20px rgba(23, 26, 51, .1), 0 32px 64px rgba(23, 26, 51, .18);
  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 24%, transparent);

  --font: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { font-weight: 700; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--ring); }
::selection { background: var(--primary-soft-2); }
.num, .ltr { direction: ltr; unicode-bidi: isolate; }
.tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* icons */
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i.sm { width: 16px; height: 16px; }
.i.lg { width: 24px; height: 24px; }
.i.xl { width: 32px; height: 32px; }
.i.flip { transform: scaleX(-1); }

/* boot spinner */
.boot { display: grid; place-items: center; min-height: 60vh; }
.boot-spinner, .spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line-strong); border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  border-radius: var(--r-sm);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .08s, opacity .15s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn:disabled, .btn.loading { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), inset 0 1px 0 rgba(255, 255, 255, .14); }
.btn-primary:hover { background: var(--primary-600); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--text); box-shadow: var(--sh-xs); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn-soft { background: var(--primary-soft); color: var(--primary-700); }
.btn-soft:hover { background: var(--primary-soft-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 86%, #000); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-success { background: var(--success); color: #fff; }
.btn-lg { min-height: 52px; padding: 0 24px; font-size: 15.5px; border-radius: var(--r-md); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--r-xs); }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }
.btn.loading::after { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: spin .7s linear infinite; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.field .err { font-size: 12.5px; color: var(--danger); display: none; }
.field.invalid .err { display: block; }
.field.invalid .input, .field.invalid .select, .field.invalid .textarea { border-color: var(--danger); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 9px 13px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  color: var(--text); transition: border-color .15s, box-shadow .15s; appearance: none; -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-3); }
.textarea { min-height: 88px; resize: vertical; line-height: 1.7; }
.select {
  padding-inline-end: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a90a8' stroke-width='2.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: left 12px center;
}
.input.num-in { direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.input-wrap { position: relative; }
.input-wrap .i { position: absolute; inset-inline-start: 13px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-wrap .input { padding-inline-start: 40px; }
.input-suffix { position: relative; }
.input-suffix .input { padding-inline-end: 56px; }
.input-suffix .suffix { position: absolute; inset-inline-end: 13px; top: 50%; transform: translateY(-50%); font-size: 12.5px; color: var(--text-3); pointer-events: none; }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line-strong); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .22s var(--ease); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(-18px); }
.switch input:focus-visible + span { box-shadow: var(--ring); }
.switch input:disabled + span { opacity: .5; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; }

.seg { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.seg button { min-height: 34px; padding: 0 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--text-2); transition: background .15s, color .15s, box-shadow .15s; white-space: nowrap; }
.seg button[aria-pressed="true"], .seg button.on { background: var(--surface); color: var(--primary-700); box-shadow: var(--sh-sm); }
.seg.block { display: flex; } .seg.block button { flex: 1; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-xs); }
.card-pad { padding: 20px; }
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; padding: 0 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary-700); }

.empty { display: grid; place-items: center; text-align: center; gap: 10px; padding: 44px 20px; color: var(--text-3); }
.empty .ico { width: 64px; height: 64px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.empty h3 { color: var(--text); font-size: 16px; }
.empty p { max-width: 340px; font-size: 13.5px; }

.skeleton { position: relative; overflow: hidden; background: var(--line); border-radius: var(--r-xs); min-height: 14px; }
.skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, .6) 50%, transparent 80%); transform: translateX(100%); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(-100%); } }

.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r-sm); font-size: 13.5px; background: var(--info-soft); color: #1d4f9f; }
.alert.warn { background: var(--warn-soft); color: #8a5208; }
.alert.danger { background: var(--danger-soft); color: #a8263a; }
.alert.success { background: var(--success-soft); color: #0b7446; }
.alert .i { margin-top: 2px; }

/* ---------- overlay: modal / sheet ---------- */
.ov { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(15, 18, 40, .5); backdrop-filter: blur(3px); animation: fade .18s ease; }
.ov.closing { animation: fadeout .16s ease forwards; }
.dialog { width: min(100%, 520px); max-height: min(90dvh, 820px); display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-lg); animation: pop .22s var(--ease); overflow: hidden; }
.dialog.wide { width: min(100%, 760px); }
.dialog.narrow { width: min(100%, 400px); }
.ov.closing .dialog { animation: popout .16s ease forwards; }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px 12px; }
.dialog-head h3 { flex: 1; font-size: 17px; }
.dialog-body { padding: 8px 22px 22px; overflow: auto; overscroll-behavior: contain; flex: 1; }
.dialog-foot { display: flex; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface-2); justify-content: flex-start; flex-wrap: wrap; }
.dialog-foot .grow { flex: 1; }
.grab { display: none; }
@media (max-width: 640px) {
  .ov { align-items: end; padding: 0; }
  .dialog, .dialog.wide, .dialog.narrow { width: 100%; max-height: 92dvh; border-radius: 22px 22px 0 0; animation: sheet .28s var(--ease); }
  .ov.closing .dialog { animation: sheetout .2s ease forwards; }
  .grab { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 8px auto 0; }
  .dialog-head { padding-top: 12px; }
  .dialog-foot { padding-bottom: calc(14px + var(--safe-b)); }
  .dialog-foot .btn { flex: 1; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes fadeout { to { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes popout { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes sheet { from { transform: translateY(100%); } }
@keyframes sheetout { to { transform: translateY(100%); } }

/* ---------- toast ---------- */
#toast-root { position: fixed; z-index: 200; inset-inline: 0; bottom: calc(20px + var(--safe-b)); display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { display: flex; align-items: center; gap: 10px; max-width: min(100%, 460px); padding: 12px 16px; border-radius: 14px; background: #1b1f3f; color: #fff; box-shadow: var(--sh-md); font-size: 14px; pointer-events: auto; animation: toastin .28s var(--ease); }
.toast.out { animation: toastout .2s ease forwards; }
.toast .i { flex: none; }
.toast.success .i { color: #5fe0a2; }
.toast.error .i { color: #ff8a98; }
@keyframes toastin { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toastout { to { opacity: 0; transform: translateY(8px); } }

/* ---------- popover / dropdown ---------- */
.pop { position: fixed; z-index: 150; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-md); padding: 6px; min-width: 190px; animation: pop .16s var(--ease); }
.pop button.item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 8px; text-align: start; font-size: 14px; }
.pop button.item:hover { background: var(--surface-2); }
.pop button.item.danger { color: var(--danger); }

/* ---------- calendar (Jalali) ---------- */
.cal { padding: 10px; width: 292px; }
.cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cal-head .title { flex: 1; text-align: center; font-weight: 700; cursor: pointer; padding: 6px; border-radius: 8px; }
.cal-head .title:hover { background: var(--surface-2); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .dow { font-size: 11.5px; color: var(--text-3); padding: 4px 0; }
.cal-grid button { aspect-ratio: 1; border-radius: 10px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.cal-grid button:hover:not(:disabled) { background: var(--primary-soft); }
.cal-grid button.today { box-shadow: inset 0 0 0 1.5px var(--primary-soft-2); font-weight: 700; }
.cal-grid button.sel { background: var(--primary); color: #fff; font-weight: 700; }
.cal-grid button:disabled { color: var(--line-strong); cursor: default; }
.cal-years, .cal-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-height: 250px; overflow: auto; }
.cal-years button, .cal-months button { padding: 10px 0; border-radius: 10px; }
.cal-years button:hover, .cal-months button:hover { background: var(--primary-soft); }
.cal-years button.sel, .cal-months button.sel { background: var(--primary); color: #fff; }
.date-btn { justify-content: space-between; text-align: start; font-weight: 500; color: var(--text); width: 100%; min-height: 44px; padding: 0 13px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm); display: flex; align-items: center; gap: 8px; }
.date-btn:hover { border-color: var(--text-3); }
.date-btn .i { color: var(--text-3); }

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