:root {
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-300: #93c5fd;
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --blue-900: #1e3a5f;
  --primary: #4a7fc1;
  --primary-dark: #3a6aad;
  --primary-light: #e8f1fb;
  --primary-soft: #f0f6fd;
  --accent: #6ba3e0;
  --danger: #e57373;
  --warning: #ffb74d;
  --success: #66bb6a;
  --bg: #f4f8fd;
  --card: #ffffff;
  --text: #1a2b42;
  --text-muted: #6b8299;
  --border: #d6e4f2;
  --shadow-sm: 0 1px 3px rgba(74,127,193,.06);
  --shadow: 0 4px 20px rgba(74,127,193,.1);
  --shadow-lg: 0 12px 40px rgba(74,127,193,.15);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 270px;
  --transition: .25s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: 'Vazirmatn', Tahoma, sans-serif !important;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

input, select, textarea, button {
  font-family: 'Vazirmatn', Tahoma, sans-serif !important;
}

/* ── Login ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111d2b;
  padding: 1.5rem;
}

.login-card {
  background: var(--card);
  border-radius: 24px;
  padding: 2.75rem 2.25rem;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  position: relative;
  z-index: 1;
}

.login-logo { text-align: center; margin-bottom: 2rem; }

.login-logo .icon {
  width: 72px; height: 72px;
  background: #2185d0;
  border-radius: 16px;
  margin-bottom: 1rem;
}
.login-logo h1 { font-size: 1.4rem; color: var(--blue-800); font-weight: 700; }
.login-logo p { color: var(--text-muted); font-size: .875rem; margin-top: .25rem; }

.forgot-link {
  display: block;
  text-align: left;
  color: var(--primary);
  font-size: .85rem;
  cursor: pointer;
  margin-top: -.5rem;
  margin-bottom: 1rem;
  background: none;
  border: none;
  font-family: inherit;
  transition: color var(--transition);
}
.forgot-link:hover { color: var(--blue-700); text-decoration: underline; }

/* ── Layout ── */
.layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
}

.sidebar {
  width: var(--sidebar-w);
  background: #111d2b;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
  box-shadow: -4px 0 30px rgba(0,0,0,.25);
}

.sidebar-brand {
  padding: 1.5rem 1.15rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: .85rem;
}

.sidebar-logo {
  width: 44px; height: 44px;
  background: #2185d0;
  border-radius: 12px;
  flex-shrink: 0;
}

.sidebar-brand-text h2 { font-size: 1rem; font-weight: 700; color: #fff; line-height: 1.3; }
.sidebar-brand-text span { font-size: .72rem; color: rgba(255,255,255,.5); display: block; margin-top: .15rem; }

.sidebar-nav { flex: 1; padding: 1rem .65rem; overflow-y: auto; }

.nav-section {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .5;
  padding: .75rem 1rem .35rem;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .8rem 1rem;
  border-radius: 12px;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  transition: all var(--transition);
  font-size: .9rem;
  margin-bottom: .3rem;
  border: none;
  background: none;
  width: calc(100% - .5rem);
  margin-right: .25rem;
  text-align: right;
  font-family: inherit;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: #2185d0;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(33,133,208,.35);
}
.nav-item .nav-icon { display: inline-flex; align-items: center; justify-content: center; width: 22px; flex-shrink: 0; }
.nav-item .nav-icon .icon-svg { color: currentColor; }
.nav-group { margin-bottom: .3rem; }
.nav-parent { position: relative; }
.nav-parent .nav-caret { margin-right: auto; display: inline-flex; transition: transform .2s ease; opacity: .7; }
.nav-group.open .nav-parent .nav-caret { transform: rotate(-90deg); }
.nav-submenu { display: none; padding: .15rem .35rem .35rem 0; }
.nav-group.open .nav-submenu { display: block; }
.nav-item.nav-sub { width: calc(100% - 1rem); margin-right: 1rem; padding: .65rem .85rem; font-size: .85rem; background: rgba(255,255,255,.03); }
.nav-item.nav-sub.active { background: #2185d0; }

.icon-svg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  vertical-align: middle;
}
.icon-svg svg { width: 100%; height: 100%; display: block; }

.icon-lg .icon-svg, .icon-lg.icon-svg { width: 40px !important; height: 40px !important; }
.report-menu-item .icon { color: #2185d0; margin-bottom: .6rem; }
.report-menu-item .icon .icon-svg { width: 40px; height: 40px; }

.login-logo .icon, .sidebar-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.login-logo .icon { margin: 0 auto 1rem; }
.login-logo .icon .icon-svg { width: 36px; height: 36px; color: #fff; }
.sidebar-logo .icon-svg { width: 24px; height: 24px; color: #fff; }

.empty-state .icon .icon-svg { width: 48px; height: 48px; color: var(--text-muted); opacity: .5; }

.btn .icon-svg { margin-left: .35rem; }
.btn .icon-svg:only-child { margin: 0; }

.section-title .icon-svg { margin-left: .4rem; vertical-align: -4px; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: .8rem;
  opacity: .75;
}

.main {
  margin-right: var(--sidebar-w);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: calc(100% - var(--sidebar-w));
  max-width: calc(100% - var(--sidebar-w));
  min-width: 0;
  box-sizing: border-box;
}

.topbar {
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 { font-size: 1.2rem; font-weight: 700; color: var(--blue-800); }

.menu-toggle {
  display: none;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .45rem .65rem;
  cursor: pointer;
  color: var(--primary);
  align-items: center;
  justify-content: center;
}
.menu-toggle .icon-svg { color: var(--primary); }

.content {
  padding: 1.75rem;
  flex: 1;
  width: 100%;
  max-width: none !important;
  min-width: 0;
  box-sizing: border-box;
}

#page-content {
  width: 100%;
  max-width: none;
  display: block;
}
#page-content > * {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* فرم‌های ثبت (موتر، مشتری، کاربر...) تمام‌عرض ناحیه محتوا */
.form-card {
  width: 100%;
  max-width: none !important;
}
.form-card .form-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.page-block {
  width: 100% !important;
  max-width: none !important;
  display: block;
  box-sizing: border-box;
}

/* ── Cards & Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-card .label { font-size: .88rem; color: var(--text-muted); font-weight: 600; }
.stat-card .value { font-size: 2rem; font-weight: 700; color: var(--blue-700); margin-top: .2rem; }
.stat-card .sub { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

.stat-card.clickable {
  cursor: pointer;
  border-right: 4px solid var(--primary);
}
.stat-card.clickable:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: #2185d0;
}
.stat-card.clickable .hint { font-size: .7rem; color: var(--primary); margin-top: .35rem; opacity: .8; }

.dashboard-stats .stat-card .value { font-size: 2.2rem; }
.dashboard-stats .stat-card .label { font-size: .95rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  max-width: 100%;
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }

.card-header {
  padding: 1.1rem 1.35rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  background: var(--primary-soft);
}
.card-header h3 { font-size: 1rem; font-weight: 700; color: var(--blue-800); }
.card-body { padding: 1.35rem; }

/* جداول داخل کارت قابل اسکرول افقی — بدون display:block روی خود table */
.table-wrap {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card > table,
.invoice-print > table,
.page-block > table {
  width: 100%;
}

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.1rem;
}

.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
}
label .req { color: var(--danger); margin-right: 2px; }

.field-value {
  padding: .65rem 0;
  font-weight: 600;
  color: var(--blue-800);
  font-size: .95rem;
}

input, select, textarea {
  font-size: .9rem;
  padding: .7rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: all var(--transition);
  width: 100%;
}

input:hover, select:hover, textarea:hover { border-color: var(--blue-300); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(74,127,193,.12);
}

input[readonly], input:disabled {
  background: var(--primary-soft);
  color: var(--blue-700);
  font-weight: 600;
}

input[type="date"] { cursor: pointer; }

textarea { resize: vertical; min-height: 90px; }

/* ── Autocomplete ── */
.ac-wrap { position: relative; }

.ac-dropdown {
  position: absolute;
  top: 100%;
  right: 0; left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  display: none;
  margin-top: 4px;
}

.ac-dropdown.open { display: block; }

.ac-item {
  padding: .65rem 1rem;
  cursor: pointer;
  font-size: .88rem;
  transition: background var(--transition);
  border-bottom: 1px solid var(--primary-soft);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.highlighted { background: var(--primary-light); color: var(--blue-800); }
.ac-item .ac-meta { font-size: .75rem; color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  font-size: .875rem;
  font-weight: 600;
  padding: .65rem 1.35rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--blue-600));
  color: #fff;
  box-shadow: 0 2px 8px rgba(74,127,193,.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(74,127,193,.4); }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--blue-500); }

.btn-outline {
  background: #fff;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: .4rem .85rem; font-size: .8rem; }
.btn-group { display: flex; gap: .6rem; flex-wrap: wrap; }

.btn.is-busy,
.btn:disabled.is-busy {
  opacity: .75;
  cursor: wait;
  pointer-events: none;
  transform: none !important;
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  width: 100%;
}

table {
  display: table;
  width: 100% !important;
  border-collapse: collapse;
  font-size: .875rem;
  min-width: 0;
  table-layout: auto;
}

thead th {
  background: var(--primary-soft);
  color: var(--blue-800);
  font-weight: 700;
  padding: .85rem 1rem;
  text-align: right;
  white-space: nowrap;
  font-size: .82rem;
}

tbody td {
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--primary-soft); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: .25rem .7rem;
  border-radius: 20px;
  font-size: .74rem;
  font-weight: 600;
}

.badge-blue { background: var(--blue-100); color: var(--blue-700); }
.badge-green { background: #e8f5e9; color: #2e7d32; }
.badge-orange { background: #fff3e0; color: #e65100; }
.badge-red { background: #ffebee; color: #c62828; }
.badge-gray { background: #f5f5f5; color: #616161; }
.badge-purple { background: #ede7f6; color: #5e35b1; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: .35rem;
  background: var(--primary-soft);
  padding: .4rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.tab {
  padding: .65rem 1.2rem;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: all var(--transition);
  font-family: inherit;
}

.tab.active {
  background: #fff;
  color: var(--blue-700);
  box-shadow: var(--shadow-sm);
}

.tab-panel { display: none; animation: fadeIn .3s ease; }
.tab-panel.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Expenses ── */
.expense-list { display: flex; flex-direction: column; gap: .65rem; }

.expense-row {
  display: grid;
  grid-template-columns: 1fr 150px 130px auto;
  gap: .85rem;
  align-items: end;
  padding: .9rem 1rem;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.expense-row.fixed .exp-label {
  padding: .7rem 0;
  font-weight: 600;
  color: var(--blue-800);
  font-size: .9rem;
}

.expense-row.custom .exp-label-input { font-weight: 500; }

.expense-totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1.5rem;
}

.total-box {
  text-align: center;
  padding: 1.25rem;
  background: #fff;
  border-radius: var(--radius);
  border: 2px solid var(--border);
}

.total-box.usd { border-color: var(--blue-400); background: var(--blue-50); }
.total-box.afn { border-color: var(--success); background: #f1f8f1; }

.total-box .currency-label { font-size: .82rem; color: var(--text-muted); font-weight: 600; }
.total-box .amount { font-size: 1.55rem; font-weight: 700; margin-top: .25rem; }
.total-box.usd .amount { color: var(--blue-700); }
.total-box.afn .amount { color: #2e7d32; }

/* ── Search ── */
.search-wrap { position: relative; flex: 1; min-width: 220px; }

.search-bar { display: flex; gap: .75rem; margin-bottom: 1.25rem; flex-wrap: wrap; align-items: flex-start; }

.quick-search {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.quick-search h3 { font-size: .95rem; margin-bottom: .85rem; color: var(--blue-800); font-weight: 700; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30,58,95,.45);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn .2s ease;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal h3 { color: var(--blue-800); margin-bottom: 1rem; font-size: 1.1rem; }

/* ── Toast / Notification ── */
#toast-container {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--blue-800);
  color: #fff;
  padding: .9rem 1.5rem;
  border-radius: 50px;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .4s cubic-bezier(.4,0,.2,1);
  display: flex;
  align-items: center;
  gap: .5rem;
  pointer-events: auto;
  min-width: 280px;
  justify-content: center;
}
.toast .icon-svg { color: #fff; flex-shrink: 0; }

.toast.success { background: linear-gradient(135deg, #43a047, #66bb6a); }
.toast.error { background: linear-gradient(135deg, #e53935, #ef5350); }
.toast.info { background: linear-gradient(135deg, var(--primary), var(--blue-600)); }

@keyframes toastIn {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Invoice / صورت‌حساب ── */
.invoice-print {
  background: #fff;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.invoice-sheet {
  width: 100%;
  padding: 0 0 1.75rem;
  box-sizing: border-box;
  position: relative;
}

.invoice-topbar {
  height: 6px;
  background: linear-gradient(90deg, #111d2b 0%, #2185d0 55%, #6ba3e0 100%);
}

.invoice-sheet-inner {
  padding: 1.5rem 1.75rem 0;
}

.invoice-brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.invoice-brand-main h2 {
  color: var(--blue-800);
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0 0 .35rem;
  line-height: 1.3;
}
.invoice-brand-main .invoice-sub {
  color: var(--text-muted);
  font-size: .88rem;
  line-height: 1.65;
}
.invoice-brand-meta {
  text-align: left;
  min-width: 200px;
  padding: 1rem 1.15rem;
  background: linear-gradient(145deg, #111d2b, #1a3350);
  color: rgba(255,255,255,.85);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  line-height: 1.75;
  box-shadow: 0 6px 18px rgba(17,29,43,.18);
}
.invoice-brand-meta strong {
  color: #fff;
  font-size: 1.05rem;
  display: block;
  margin-bottom: .35rem;
  letter-spacing: .02em;
}
.invoice-doc-no {
  display: inline-block;
  margin-top: .55rem;
  padding: .2rem .65rem;
  background: rgba(255,255,255,.12);
  border-radius: 6px;
  font-weight: 700;
  color: #93c5fd;
  font-size: .82rem;
}

.invoice-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--primary);
}
.invoice-header h2 { color: var(--blue-800); font-size: 1.35rem; }

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.35rem;
}
.invoice-party {
  padding: 1rem 1.15rem;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  border-right: 4px solid #2185d0;
}
.invoice-party h4 {
  margin: 0 0 .65rem;
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: none;
}
.invoice-party .party-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--blue-800);
  margin-bottom: .35rem;
}
.invoice-party .party-line {
  font-size: .85rem;
  color: var(--text);
  line-height: 1.7;
}

.invoice-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem 1.15rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.invoice-meta .meta-item .meta-label {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: .1rem;
}
.invoice-meta .meta-item .meta-value {
  font-weight: 700;
  color: var(--blue-800);
  font-size: .92rem;
  word-break: break-word;
}

.invoice-print .section-title {
  margin-top: .25rem;
}

.invoice-print table {
  width: 100% !important;
  min-width: 0;
  margin-bottom: 1.25rem;
}
.invoice-print thead th {
  background: #111d2b;
  color: #fff;
  font-size: .82rem;
}
.invoice-print tbody td { padding: .75rem 1rem; }
.invoice-print tbody tr:nth-child(even) { background: #f7fafc; }
.invoice-print tbody td:nth-child(3) {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.invoice-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: .5rem;
}
.invoice-totals .total-box {
  padding: 1.35rem 1.25rem;
}
.invoice-totals .total-box .amount {
  font-size: 1.75rem;
}

.invoice-footer-note {
  margin-top: 1.5rem;
  padding: 1rem 1.15rem;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  color: var(--text-muted);
  line-height: 1.75;
}
.invoice-footer-note strong { color: var(--blue-800); }

/* مهر و امضا — برای چاپ و تحویل به مشتری */
.invoice-auth {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-top: 2.25rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
  break-inside: avoid;
  page-break-inside: avoid;
}
.invoice-auth-box {
  text-align: center;
  padding: .85rem .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.invoice-auth-box .auth-title {
  font-size: .9rem;
  font-weight: 800;
  color: var(--blue-800);
  margin-bottom: .75rem;
}
.invoice-auth-box .auth-stamp {
  width: 110px;
  height: 110px;
  border: 2px dashed #94a3b8;
  border-radius: 50%;
  margin: .25rem auto .65rem;
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 6px,
    rgba(148,163,184,.08) 6px,
    rgba(148,163,184,.08) 12px
  );
}
.invoice-auth-box .auth-sign-space {
  flex: 1;
  width: 100%;
  min-height: 72px;
}
.invoice-auth-box .auth-line {
  width: 85%;
  border-top: 1.5px solid #111d2b;
  margin: 0 auto .55rem;
}
.invoice-auth-box .auth-caption {
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ── Report submenu ── */
.report-menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.report-menu-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.report-menu-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.report-menu-item .icon { font-size: inherit; }
.report-menu-item h4 { color: var(--blue-800); font-size: .95rem; }
.report-menu-item p { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

/* ── Action icons in table ── */
.actions-cell { display: flex; gap: .35rem; flex-wrap: wrap; }

/* ── Empty ── */
.empty-state { text-align: center; padding: 3.5rem 1rem; color: var(--text-muted); }
.empty-state .icon { font-size: 3.5rem; margin-bottom: .75rem; opacity: .6; }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 99; }

.section-title {
  font-size: .92rem;
  font-weight: 700;
  color: var(--blue-700);
  margin: 1.5rem 0 .85rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--primary-light);
}
.section-title:first-child { margin-top: 0; }

.tab-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); font-size: .85rem; }
.text-danger { color: #c62828; font-weight: 600; }
.text-success { color: #2e7d32; font-weight: 600; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }

.hidden { display: none !important; }

.date-range-bar {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: end;
  padding: 1rem 1.25rem;
  background: var(--primary-soft);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
}

.print-section { margin-bottom: 1.5rem; }

.backup-box {
  padding: 1.25rem;
  background: var(--primary-soft);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  margin-top: 1.5rem;
}
.backup-box h4 { color: var(--blue-800); margin-bottom: .75rem; font-size: .95rem; display: flex; align-items: center; gap: .5rem; }
.backup-box h4 .icon-svg { color: var(--primary); }

@media print {
  .sidebar, .topbar, .btn, .no-print, #toast-container, .sidebar-overlay, .menu-toggle { display: none !important; }
  html, body { background: #fff !important; width: 100% !important; color: #000 !important; }
  .layout { display: block !important; }
  .main {
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .content {
    padding: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }
  .card, .form-card, .invoice-print {
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
  }
  .invoice-print { padding: 0 !important; }
  .invoice-sheet { padding-bottom: 0 !important; }
  .invoice-sheet-inner { padding: .5rem .25rem 0 !important; }
  .invoice-brand-meta {
    box-shadow: none !important;
    border: 1px solid #111d2b !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .invoice-topbar,
  .invoice-print thead th,
  .total-box {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  table { min-width: 0 !important; width: 100% !important; }
  .expense-totals,
  .invoice-totals,
  .invoice-auth { break-inside: avoid; page-break-inside: avoid; }
  .invoice-auth {
    margin-top: 2.5rem;
    gap: 1rem;
  }
  .invoice-auth-box {
    min-height: 190px;
    border-color: #334155 !important;
  }
  .invoice-auth-box .auth-stamp {
    border-color: #64748b !important;
  }
}

/* ═══════════════════════════════════════════════════
   Responsive — تبلت و موبایل (صفر تا صد)
   ═══════════════════════════════════════════════════ */

@media (max-width: 1024px) {
  :root { --sidebar-w: 250px; }
  .content { padding: 1.25rem; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .expense-row { grid-template-columns: 1fr 1fr; }
  .expense-row > *:last-child { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 768px) {
  /* سایدبار کشویی */
  .sidebar {
    width: min(86vw, 300px);
    max-width: 300px;
    transform: translateX(110%);
    box-shadow: -8px 0 40px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none;
    z-index: 99;
  }
  .sidebar-overlay.open {
    display: block;
  }
  .main { margin-right: 0; width: 100%; max-width: 100vw; }
  .menu-toggle {
    display: inline-flex !important;
    min-width: 44px;
    min-height: 44px;
  }

  /* تاپ‌بار */
  .topbar {
    padding: .75rem 1rem;
    gap: .5rem;
  }
  .topbar h1 {
    font-size: 1rem;
    line-height: 1.35;
    max-width: calc(100vw - 5rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .content {
    padding: .85rem .75rem 1.5rem;
    max-width: 100%;
  }

  /* ورود */
  .login-page { padding: 1rem; align-items: flex-start; padding-top: 8vh; }
  .login-card { padding: 1.75rem 1.25rem; border-radius: 18px; }
  .login-logo h1 { font-size: 1.2rem; }

  /* آمار و کارت‌ها */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
    margin-bottom: 1rem;
  }
  .stat-card { padding: 1rem; }
  .stat-card .value,
  .dashboard-stats .stat-card .value { font-size: 1.45rem; }
  .stat-card .label,
  .dashboard-stats .stat-card .label { font-size: .8rem; }

  .card-header { padding: .85rem 1rem; }
  .card-body { padding: 1rem; }

  /* فرم‌ها */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: .85rem;
  }
  .form-group.full { grid-column: 1; }

  input, select, textarea, .btn {
    font-size: 16px; /* جلوگیری از زوم iOS */
  }
  input, select, textarea {
    padding: .75rem .9rem;
    min-height: 44px;
  }

  /* تب‌های ثبت بار */
  .tabs {
    gap: .25rem;
    padding: .3rem;
    margin-bottom: 1rem;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: .6rem .85rem;
    font-size: .8rem;
    flex: 0 0 auto;
  }
  .tab-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: .65rem;
  }
  .tab-actions .btn { width: 100%; justify-content: center; }

  /* مصارف */
  .expense-row {
    grid-template-columns: 1fr !important;
    gap: .55rem;
  }
  .expense-totals { grid-template-columns: 1fr; gap: .75rem; }
  .total-box .amount { font-size: 1.3rem; }

  /* دکمه‌ها و هدر لیست‌ها */
  .flex-between {
    flex-direction: column;
    align-items: stretch !important;
  }
  .flex-between > .btn,
  .flex-between > .btn-group {
    width: 100%;
  }
  .flex-between > .btn-group { display: flex; }
  .flex-between > .btn-group .btn { flex: 1; justify-content: center; }
  .btn-group { width: 100%; }
  .btn-group .btn { flex: 1 1 auto; justify-content: center; min-height: 44px; }
  .list-count-title { font-size: .95rem; width: 100%; }

  .actions-cell {
    flex-direction: column;
    align-items: stretch;
  }
  .actions-cell .btn {
    width: 100%;
    justify-content: center;
  }

  /* جداول — اسکرول افقی نرم روی موبایل */
  .table-wrap table,
  .card .table-wrap table {
    min-width: 620px;
    font-size: .8rem;
  }
  .main {
    width: 100%;
    max-width: 100%;
  }
  .invoice-sheet-inner { padding: 1rem 1rem 0; }
  .invoice-brand { flex-direction: column; }
  .invoice-brand-meta { text-align: right; width: 100%; min-width: 0; }
  .invoice-parties { grid-template-columns: 1fr; }
  .invoice-auth { grid-template-columns: 1fr; gap: .85rem; }
  .invoice-auth-box { min-height: 140px; }
  thead th, tbody td {
    padding: .65rem .7rem;
  }

  /* گزارش‌ها */
  .report-menu {
    grid-template-columns: 1fr !important;
    gap: .75rem;
  }
  .report-menu-item { padding: 1.25rem 1rem; }

  /* بازه تاریخ */
  .date-range-bar {
    flex-direction: column;
    align-items: stretch;
    gap: .65rem;
    padding: .85rem 1rem;
  }
  .date-range-bar .form-group,
  .date-range-bar .btn { width: 100%; }
  .date-range-bar .btn { justify-content: center; min-height: 44px; }

  /* جستجو */
  .search-wrap { min-width: 0; width: 100%; }
  .search-bar { flex-direction: column; }
  .quick-search { padding: 1rem; }

  /* مودال */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: 18px 18px 0 0;
    padding: 1.35rem 1.15rem calc(1.35rem + env(safe-area-inset-bottom, 0px));
    max-height: 92vh;
    overflow-y: auto;
  }

  /* بک‌آپ / تنظیمات */
  .backup-box .btn-group {
    flex-direction: column;
  }
  .backup-box .btn,
  .backup-box label.btn {
    width: 100%;
    justify-content: center;
  }

  /* toast */
  #toast-container {
    top: auto;
    bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
    left: .75rem;
    right: .75rem;
    transform: none;
    max-width: none;
    width: auto;
    align-items: stretch;
  }
  .toast {
    width: 100%;
    border-radius: 14px;
    justify-content: center;
    text-align: center;
  }

  /* ناوبری موبایل */
  .nav-item { min-height: 44px; padding: .75rem .9rem; }
  .sidebar-brand { padding: 1.15rem 1rem; }
  .sidebar-brand-text h2 { font-size: .95rem; }

  /* فاکتور / چاپ */
  .invoice-print { padding: .25rem; }
  .invoice-header h2 { font-size: 1.1rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card .value,
  .dashboard-stats .stat-card .value { font-size: 1.65rem; }

  .topbar h1 { font-size: .92rem; }
  .content { padding: .7rem .6rem 1.25rem; }

  .login-card { padding: 1.5rem 1rem; }
  .login-logo .icon { width: 60px; height: 60px; }

  .table-wrap table { min-width: 540px; font-size: .75rem; }
  .badge { font-size: .68rem; padding: .2rem .55rem; }

  .card-header h3 { font-size: .9rem; }
  .section-title { font-size: .85rem; margin: 1.1rem 0 .65rem; }

  .btn { padding: .7rem 1rem; }
  .btn-sm { padding: .5rem .75rem; font-size: .78rem; min-height: 40px; }

  .count-badge { font-size: .72rem; }
}

/* افقی موبایل / تبلت کوتاه */
@media (max-height: 500px) and (orientation: landscape) {
  .login-page { align-items: flex-start; padding-top: 1rem; }
  .sidebar { width: min(70vw, 280px); }
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); max-height: 88vh; }
}

.count-badge {
  display: inline-flex;
  align-items: center;
  background: #2185d0;
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  padding: .2rem .65rem;
  border-radius: 999px;
  margin-right: .4rem;
}
.list-count-title { display: flex; align-items: center; flex-wrap: wrap; gap: .35rem; font-size: 1rem; }
.nav-count {
  margin-right: auto;
  margin-left: .35rem;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 .4rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-item.active .nav-count { background: rgba(255,255,255,.25); }

/* قفل اسکرول بدنه وقتی منو باز است */
body.sidebar-open { overflow: hidden; touch-action: none; }