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

:root {
  --navy: #0f2744;
  --navy-deep: #091a30;
  --blue: #1d63dc;
  --blue-soft: #e8f0fe;
  --bg: #f4f7fb;
  --card: #ffffff;
  --muted: #edf2f7;
  --border: #dce3ee;
  --text: #0f172a;
  --text-sec: #475569;
  --green: #059669;
  --green-soft: #d1fae5;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --radius: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Vazirmatn", Tahoma, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.65;
  min-height: 100vh;
}

button, input, select, textarea {
  font-family: inherit;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* نوار کناری دسکتاپ */
.sidebar {
  width: 264px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 8px;
}

.brand img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
}

.brand-sub {
  font-size: 0.74rem;
  opacity: 0.78;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-align: right;
  transition: background 0.18s, color 0.18s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-btn.active {
  background: var(--blue);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.apk-download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.apk-download-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* محتوای اصلی */
.main-area {
  flex: 1;
  min-width: 0;
  padding: 20px 24px 90px;
  max-width: 1120px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--navy);
}

.page-sub {
  font-size: 0.85rem;
  color: var(--text-sec);
}

/* کارت‌ها و دکمه‌ها */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 2px 10px rgba(15, 39, 68, 0.04);
}

.hero-navy {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #fff;
  border: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.99);
}

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

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

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

.btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
}

.btn-lg {
  width: 100%;
  min-height: 54px;
  font-size: 1rem;
  border-radius: 16px;
}

/* گریدها */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* فرم‌ها */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-sec);
}

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 0.92rem;
}

.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid rgba(29, 99, 220, 0.25);
  border-color: var(--blue);
}

/* نشانگرها */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge-draft { background: var(--muted); color: var(--text-sec); }
.badge-final { background: var(--blue-soft); color: var(--blue); }
.badge-sent { background: var(--amber-soft); color: var(--amber); }
.badge-approved { background: var(--green-soft); color: var(--green); }
.badge-pro { background: var(--amber-soft); color: var(--amber); }

/* پیش‌نمایش سند */
.doc-sheet {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(15, 39, 68, 0.07);
}

.doc-sheet-header {
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.doc-sheet-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.doc-table th, .doc-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: right;
}

.doc-table th {
  font-weight: 700;
}

.stamp-box {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 2.5px solid #1d4ed8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #1d4ed8;
  font-size: 0.68rem;
  font-weight: 800;
  transform: rotate(-7deg);
  padding: 8px;
  margin: 4px auto;
}

/* صفحه ورود */
.auth-wrap {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 48%, var(--bg) 48%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 460px;
}

/* مودال و امضا */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 26, 48, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-box {
  background: #fff;
  border-radius: 22px;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}

.sig-canvas {
  width: 100%;
  height: 190px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: #fcfdff;
  touch-action: none;
  cursor: crosshair;
}

/* نوار پایین موبایل */
.mobile-nav {
  display: none;
}

/* پیام اسنک‌بار */
.toast {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  z-index: 1200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

@media (max-width: 900px) {
  .sidebar { display: none; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main-area { padding: 14px 14px 92px; }
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    justify-content: space-around;
    padding: 6px 4px;
    z-index: 900;
  }
  .mobile-nav button {
    border: none;
    background: transparent;
    color: var(--text-sec);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 6px 8px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
  }
  .mobile-nav button.active {
    color: var(--blue);
    background: var(--blue-soft);
  }
}

@media (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  html,
  body {
    background: #ffffff !important;
    color: #0f172a !important;
    margin: 0 !important;
    padding: 0 !important;
    min-height: auto !important;
  }

  .sidebar,
  .mobile-nav,
  .no-print,
  .toast,
  .page-header,
  button,
  .btn {
    display: none !important;
  }

  .app-shell {
    display: block !important;
    min-height: auto !important;
  }

  .main-area {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* وقتی پیش‌نمایش سند در مودال باز است، فقط برگه سند چاپ شود */
  body:has(.modal-backdrop .doc-sheet) .app-shell {
    display: none !important;
  }

  .modal-backdrop {
    position: static !important;
    inset: auto !important;
    background: transparent !important;
    padding: 0 !important;
    display: block !important;
  }

  .modal-box {
    max-width: 100% !important;
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
  }

  .doc-sheet {
    box-shadow: none !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 12px !important;
    width: 100% !important;
  }

  .doc-sheet-header,
  .doc-customer-box,
  .doc-totals-box,
  .doc-signatures-grid,
  .doc-table tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .doc-table thead {
    display: table-header-group;
  }
}

