/* tokens.css */
/* Design tokens + self-hosted Vazirmatn (no external requests, bnd 3) */
@font-face {
  font-family: 'Vazirmatn';
  src: url('/assets/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/assets/fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/assets/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-family: 'Vazirmatn', Tahoma, sans-serif;

  --color-bg: #f4f6fa;
  --color-surface: #ffffff;
  --color-border: #dde3ec;
  --color-border-strong: #b9c2d0;
  --color-text: #1c2430;
  --color-text-muted: #6b7686;
  --color-accent: #1f6feb;
  --color-accent-hover: #1a5fd0;
  --color-accent-soft: #e8f0fe;
  --color-danger: #d33b3b;
  --color-danger-soft: #fdeaea;
  --color-ok: #1a7f4b;
  --color-table-head: #e6e9ee;
  --color-print-line: #4a4a4a;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.12);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

/* base.css */
/* Base: reset-ish, RTL typography, buttons, links */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.7;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 700;
}

p {
  margin: 0;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

.muted {
  color: var(--color-text-muted);
}

.danger-text {
  color: var(--color-danger) !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: inherit;
  font-size: 14px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-accent-soft);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #b52f2f;
}

.btn-ghost {
  background: transparent;
  color: var(--color-accent);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-accent-soft);
}

.btn-sm {
  font-size: 13px;
  padding: 4px 10px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* layout.css */
/* App layout: header, page scaffolding, cards, auth screens */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 10px var(--space-5);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-side {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.brand {
  display: flex;
  align-items: center;
}

.brand-logo {
  width: 34px;
  height: 34px;
  display: block;
  border-radius: 8px;
}

.app-nav {
  display: flex;
  gap: var(--space-2);
}

.nav-link {
  color: var(--color-text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}

.nav-link:hover {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.header-user {
  color: var(--color-text-muted);
  font-size: 14px;
}

.app-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-5);
}

.page-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.page-title {
  font-size: 22px;
}

.section-title {
  font-size: 16px;
  margin-bottom: var(--space-3);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.toolbar {
  display: flex;
  gap: var(--space-3);
}

.search-input {
  max-width: 420px;
  width: 100%;
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-6);
}

/* auth screens */
.auth-wrap {
  min-height: calc(100vh - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-6);
  width: 100%;
  max-width: 420px;
}

.auth-title {
  font-size: 20px;
  margin-bottom: var(--space-2);
}

.auth-lead {
  color: var(--color-text-muted);
  font-size: 14px;
  margin-bottom: var(--space-4);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* editor */
.editor-header {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: var(--space-4);
}

.items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.items-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.item-row {
  display: grid;
  grid-template-columns: 3fr 90px 1.2fr 1.2fr 2fr auto;
  gap: var(--space-2);
  align-items: end;
}

.item-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-cell-label {
  font-size: 12px;
  color: var(--color-text-muted);
}

.line-total {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}

.qty-input,
.tax-input {
  text-align: center;
}

.item-remove {
  padding-bottom: 2px;
}

.totals-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-4);
  align-items: end;
}

.stat-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
}

.total-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.payable-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

.stat-emphasized {
  background: var(--color-accent-soft);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
}

.words-line {
  margin-top: var(--space-3);
  font-size: 14px;
}

.editor-actions {
  display: flex;
  gap: var(--space-3);
}

/* settings */
.settings-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.logo-block {
  margin-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.logo-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-preview {
  width: 84px;
  height: 84px;
  object-fit: contain;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}

.logo-hidden {
  display: none !important;
}

.logo-placeholder {
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.logo-actions {
  display: flex;
  gap: var(--space-2);
}

.version-line {
  text-align: center;
}

/* print view screen chrome */
.print-toolbar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

/* forms.css */
/* Forms, inputs, jalali date picker, money input */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  color: var(--color-text-muted);
}

.input {
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.input[aria-invalid='true'],
.jalali-date.invalid .jalali-date-input {
  border-color: var(--color-danger);
}

.money-input,
.qty-input {
  font-variant-numeric: tabular-nums;
}

.form-error {
  color: var(--color-danger);
  font-size: 13px;
  min-height: 18px;
}

.field-error {
  color: var(--color-danger);
  font-size: 12px;
}

/* jalali date picker */
.jalali-date {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.jalali-date-input {
  text-align: center;
}

.jalali-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-3);
  width: 280px;
}

.jalali-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.jalali-pop-title {
  font-weight: 700;
  font-size: 14px;
}

.jalali-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.jalali-weekday {
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
  padding: 4px 0;
}

.jalali-day {
  font-family: inherit;
  font-size: 13px;
  text-align: center;
  padding: 6px 0;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text);
}

.jalali-day:hover {
  background: var(--color-accent-soft);
}

.jalali-day-selected {
  background: var(--color-accent);
  color: #fff;
}

.jalali-day-empty {
  visibility: hidden;
}

/* table.css */
/* Data tables (list view) */
.table-card {
  padding: 0;
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 14px;
  text-align: right;
  border-bottom: 1px solid var(--color-border);
}

.data-table th {
  background: var(--color-table-head);
  font-weight: 700;
  font-size: 13px;
}

.data-table tbody tr:hover {
  background: var(--color-accent-soft);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.amount-cell {
  font-variant-numeric: tabular-nums;
  text-align: left !important;
  direction: ltr;
}

.actions-cell {
  white-space: nowrap;
  text-align: left !important;
}

.table-count {
  padding: var(--space-3) var(--space-4);
  font-size: 13px;
}

/* toast */
.toast-container {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 100;
}

.toast {
  background: var(--color-text);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  animation: toast-in 0.25s ease;
}

.toast-error {
  background: var(--color-danger);
}

.toast-ok {
  background: var(--color-ok);
}

.toast-out {
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
  }
}

/* dialogs.css */
/* Dialogs (confirm + what's new) with the soft veil required by the standard */
.dialog-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-bg) 72%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 90;
  animation: veil-in 0.25s ease;
}

@supports not (backdrop-filter: blur(1px)) {
  .dialog-overlay {
    background: color-mix(in srgb, var(--color-bg) 85%, transparent);
  }
}

.dialog-card {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
  width: 100%;
  max-width: 440px;
  animation: card-in 0.25s ease;
}

/* corner ✕ button (the only visible way to close the what's new card) */
.dialog-close {
  position: absolute;
  inset-inline-end: var(--space-3);
  inset-block-start: var(--space-3);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.dialog-close:hover,
.dialog-close:focus-visible {
  background: var(--color-accent-soft);
  color: var(--color-text);
  outline: none;
}

.dialog-title {
  font-size: 17px;
  margin-bottom: var(--space-3);
}

.dialog-message {
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

.dialog-actions {
  display: flex;
  justify-content: flex-start;
  gap: var(--space-3);
}

@keyframes veil-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dialog-overlay,
  .dialog-card {
    animation: none;
  }
}

/* what's new popup */
.whats-new-card {
  max-width: 560px;
  max-height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
}

.whats-new-body {
  overflow-y: auto;
  padding-left: var(--space-1);
  margin-bottom: var(--space-4);
}

.whats-new-version {
  font-size: 15px;
  margin: var(--space-3) 0 var(--space-2);
}

.whats-new-heading {
  font-size: 13px;
  color: var(--color-accent);
  margin: var(--space-2) 0 var(--space-1);
}

.whats-new-list {
  margin: 0;
  padding-right: var(--space-5);
}

.whats-new-list li {
  font-size: 14px;
}

/* print-invoice.css */
/* Invoice print sheet — A4 landscape, laid out like the paper form.
   On screen it shows inside a shadowed page; @media print strips chrome. */
@page {
  size: A4 landscape;
  margin: 8mm;
}

.invoice-sheet {
  background: var(--color-surface);
  width: 281mm;
  min-height: 190mm;
  margin: 0 auto;
  padding: 6mm;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 4mm;
  font-size: 12.5px;
}

/* header */
.inv-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 4mm;
}

.inv-meta {
  justify-self: start;
  text-align: right;
  font-size: 12px;
  color: var(--color-text);
}

.inv-page {
  margin-bottom: 1mm;
}

.inv-meta-line {
  white-space: nowrap;
}

.inv-center {
  justify-self: center;
  text-align: center;
}

.inv-title {
  font-size: 20px;
  font-weight: 700;
}

.inv-seller {
  font-size: 16px;
  font-weight: 700;
  margin-top: 1mm;
}

.inv-logo-box {
  justify-self: end;
  width: 30mm;
  height: 34mm;
  border: 1px solid var(--color-print-line);
  border-radius: 2mm;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.inv-logo {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.inv-logo-placeholder {
  color: #9aa0a6;
  font-size: 11px;
  text-align: center;
  padding: 2mm;
}

/* items table */
.inv-items-table,
.inv-summary-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.inv-items-table th,
.inv-items-table td,
.inv-summary-table td {
  border: 1px solid var(--color-print-line);
  padding: 2.4mm 2mm;
  text-align: right;
  vertical-align: middle;
  overflow-wrap: break-word;
}

.inv-items-table th {
  background: var(--color-table-head);
  font-weight: 700;
  text-align: center;
}

.inv-cell-center {
  text-align: center !important;
}

.inv-desc {
  font-weight: 500;
}

.inv-amount {
  text-align: center !important;
  direction: ltr;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.inv-note {
  color: var(--color-text-muted);
}

/* summary */
.inv-summary-table td {
  padding: 2mm 2mm;
}

/* the description area: blank white space with no internal lines */
.inv-blank {
  border: none !important;
}

.inv-sum-label {
  font-weight: 700;
  text-align: center !important;
}

.inv-adj-label {
  text-align: center !important;
}

.inv-footer-text {
  display: inline-block;
  border: 1px solid var(--color-print-line);
  padding: 0 4mm;
  margin-inline-end: 4mm;
  font-size: 10.5px;
  color: var(--color-text-muted);
}

.inv-payable-label {
  text-align: center !important;
  font-size: 13px;
}

.inv-subtotal,
.inv-payable {
  font-weight: 700;
}

.inv-payable {
  font-size: 14px;
}

/* signatures */
.inv-signatures {
  display: flex;
  justify-content: center;
  gap: 30mm;
  margin-top: auto;
  padding-top: 2mm;
}

.inv-signature {
  font-size: 12px;
  color: var(--color-text);
  padding-top: 12mm;
}

/* print rules */
@media print {
  .app-header,
  .no-print {
    display: none !important;
  }

  body {
    background: var(--color-surface);
  }

  .app-content {
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .invoice-sheet {
    width: auto;
    min-height: auto;
    box-shadow: none;
    border: none;
    padding: 0;
    margin: 0;
  }

  .inv-items-table th {
    background: var(--color-table-head) !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .inv-logo-box,
  .inv-items-table th,
  .inv-items-table td,
  .inv-summary-table td {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
