/* ===========================================
   فونت‌های موردنیاز
   =========================================== */
@font-face {
  font-family: 'iransansdn';
  src: url('/iransansdnweb.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url('/MaterialIcons-Regular.ttf') format('truetype');
}
.material-icon,
.micon {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 18px;                /* کمی بزرگ‌تر برای وضوح */
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===========================================
   متغیرهای Material Design (تم روشن)
   =========================================== */
:root {
  /* فونت */
  --mdc-font-family: 'iransansdn', 'Roboto', system-ui, sans-serif;
  --mdc-font-size: 14px;                 /* سایز پایه کمی کوچک‌تر */
  --mdc-line-height: 1.5;

  /* رنگ‌های اصلی متریال */
  --mdc-primary: #1976d2;                /* آبی Material */
  --mdc-on-primary: #ffffff;
  --mdc-primary-hover: #1565c0;
  --mdc-primary-focus: rgba(25, 118, 210, 0.25);

  --mdc-secondary: #455a64;
  --mdc-on-secondary: #ffffff;

  --mdc-surface: #ffffff;
  --mdc-background: #fafafa;
  --mdc-error: #d32f2f;
  --mdc-on-error: #ffffff;

  --mdc-text: #212121;
  --mdc-text-secondary: #757575;
  --mdc-border: rgba(0,0,0,0.12);
  --mdc-divider: rgba(0,0,0,0.08);

  /* سایه‌های متریال */
  --mdc-elevation-1: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --mdc-elevation-2: 0 3px 6px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
  --mdc-elevation-3: 0 6px 12px rgba(0,0,0,0.12), 0 3px 6px rgba(0,0,0,0.08);

  /* شعاع گوشه */
  --mdc-radius-sm: 4px;
  --mdc-radius-md: 8px;
  --mdc-radius-lg: 12px;

  /* مقیاس فاصله‌گذاری (مبنای 4px) – تا حد امکان جمع‌وجور */
  --sp-1: 0.25rem;   /* 4px */
  --sp-2: 0.5rem;    /* 8px */
  --sp-3: 0.625rem;  /* 10px */
  --sp-4: 0.75rem;   /* 12px */
  --sp-5: 1rem;      /* 16px */
  --sp-6: 1.25rem;   /* 20px */

  /* سایز فونت */
  --fs-xs: 0.75rem;   /* 12px */
  --fs-sm: 0.8125rem; /* 13px */
  --fs-base: 0.875rem;/* 14px */
  --fs-lg: 1rem;      /* 16px */
  --fs-h1: 1.25rem;   /* 20px */

  /* ارتفاع کنترلی (دکمه‌ها/ورودی‌ها) */
  --ctrl-h: 2.25rem;  /* 36px – استاندارد Dense متریال */

  /* سایز آیکن */
  --icon-sz: 1.125rem; /* 18px */

  /* عرض سایدبار */
  --sidebar-w: 256px;

  /* اختصاص‌دهی به متغیرهای قدیمی */
  --bg: var(--mdc-background);
  --surface: var(--mdc-surface);
  --text: var(--mdc-text);
  --primary: var(--mdc-primary);
  --on-primary: var(--mdc-on-primary);
  --border: var(--mdc-border);
  --danger: var(--mdc-error);
  --shadow: var(--mdc-elevation-1);
  --r-sm: var(--mdc-radius-sm);
  --r-md: var(--mdc-radius-md);
  --r-lg: var(--mdc-radius-lg);

  font-family: var(--mdc-font-family);
  font-size: var(--mdc-font-size);
  line-height: var(--mdc-line-height);
  color: var(--text);
  background: var(--bg);
  transition: background 0.25s, color 0.25s;
}

/* ===========================================
   تم دارک Material
   =========================================== */
[data-theme="dark"] {
  --mdc-primary: #90caf9;
  --mdc-on-primary: #0d47a1;
  --mdc-primary-hover: #64b5f6;
  --mdc-primary-focus: rgba(144, 202, 249, 0.25);

  --mdc-secondary: #b0bec5;
  --mdc-surface: #1e1e1e;
  --mdc-background: #121212;
  --mdc-error: #ef5350;

  --mdc-text: #e0e0e0;
  --mdc-text-secondary: #9e9e9e;
  --mdc-border: rgba(255,255,255,0.12);
  --mdc-divider: rgba(255,255,255,0.08);

  --mdc-elevation-1: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --mdc-elevation-2: 0 3px 6px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.3);
  --mdc-elevation-3: 0 6px 12px rgba(0,0,0,0.6), 0 3px 6px rgba(0,0,0,0.4);

  --bg: var(--mdc-background);
  --surface: var(--mdc-surface);
  --text: var(--mdc-text);
  --primary: var(--mdc-primary);
  --on-primary: var(--mdc-on-primary);
  --border: var(--mdc-border);
  --shadow: var(--mdc-elevation-1);
  
  --label-width: 0px;
}

/* ===========================================
   ریست و پایه
   =========================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  direction: rtl;
  -webkit-text-size-adjust: 100%;
}

body, .app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* اسکرول بار */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-thumb {
  background: var(--mdc-text-secondary);
  border-radius: 4px;
}

/* ===========================================
   هدر و فوتر (ثابت)
   =========================================== */
header {
  flex-shrink: 0;
  background: var(--surface);
  padding: 0 var(--sp-4);
  height: calc(48px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--mdc-divider);
  z-index: 10;
}

/* ===========================================
   بخش میانی اسکرول‌شونده
   =========================================== */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===========================================
   دکمه‌ها – سبک Material
   =========================================== */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  height: var(--ctrl-h);
  min-width: var(--ctrl-h);
  padding: 0 var(--sp-2);           /* 8px افقی */
  font-family: inherit;
  font-size: var(--fs-sm);          /* 13px */
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0.025em;
  border: none;                     /* بدون حاشیه، از elevation استفاده می‌شود */
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--mdc-elevation-1);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  user-select: none;
}
button:hover {
  background: rgba(0,0,0,0.04);
  box-shadow: var(--mdc-elevation-2);
}
button:active {
  transform: scale(0.97);
  box-shadow: var(--mdc-elevation-1);
}
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* دکمه اصلی (filled) */
button.bt-p {
  background: var(--primary);
  color: var(--on-primary);
}
button.bt-p:hover {
  background: var(--mdc-primary-hover);
  box-shadow: var(--mdc-elevation-2);
}

/* گروه فرم form-group */
.fg {
  margin-top: 10px;
  width: 100%;
}

/* دکمه آیکن (مربعی) */
button.bt-i {
  width: var(--ctrl-h);
  min-width: var(--ctrl-h);
  padding: 0;
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: var(--icon-sz);
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}
button.bt-i span { font-size: var(--icon-sz); }

/* دکمه ترکیبی (متن + آیکن) */
button.bt-p.bt-i {
  width: auto;
  min-width: var(--ctrl-h);
  padding: 0 var(--sp-3);
  font-family: inherit;
}
button.bt-p.bt-i .micon {
  font-family: 'Material Icons';
}

/* دکمه خطر */
button.bt-danger {
  background: var(--danger);
  color: var(--mdc-on-error);
}
button.bt-danger:hover {
  background: #b71c1c;
}

/* ===========================================
   ورودی‌ها – استایل Outlined
   =========================================== */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  height: var(--ctrl-h);
  padding: 0 var(--sp-2);            /* 8px */
  font-family: inherit;
  font-size: var(--fs-base);        /* 14px */
  line-height: 1.4;
  border: 1px solid var(--mdc-border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: none;
}
textarea {
  height: auto;
  min-height: calc(var(--ctrl-h) * 2);
  padding: var(--sp-1) var(--sp-2);
  resize: vertical;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--mdc-primary-focus);
}

/* ===========================================
   لیبل
   =========================================== */
label {
  display: block;
  margin-bottom: var(--sp-1);        /* 4px */
  font-size: var(--fs-xs);          /* 12px */
  font-weight: 500;
  color: var(--mdc-text-secondary);
}

/* ===========================================
   نوار ابزار
   =========================================== */

/* ===========================================
   جدول
   =========================================== */
.tbl-wrap {
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--mdc-divider);
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
table.tbl thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: var(--sp-1) var(--sp-2);  /* 4px 8px */
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: right;
  border-bottom: 2px solid var(--mdc-border);
  white-space: nowrap;
  z-index: 2;
  color: var(--mdc-text-secondary);
}
table.tbl tbody td {
  padding: var(--sp-1) var(--sp-2);  /* 4px 8px */
  border-bottom: 1px solid var(--mdc-divider);
  font-size: var(--fs-sm);
}
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover {
  background: rgba(0,0,0,0.03);
}

/* ===========================================
   حالت کارتی جدول در موبایل
   =========================================== */
@media (max-width: 768px) {
  table.tbl thead { display: none; }
  table.tbl, table.tbl tbody, table.tbl tr, table.tbl td {
    display: block;
  }
  table.tbl tr {
    padding: var(--sp-2);
  }
  table.tbl td {
    display: flex;
	gap: var(--sp-2);
    align-items: baseline;
  border: none !important;
  }
  table.tbl td::before {
    content: attr(data-label);
    display: inline-block;
    width: 78px;
    text-align: left;
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
  }
}

/* ===========================================
   کارت – با سایهٔ متریال
   =========================================== */
.crd {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-3);             /* 10px */
  box-shadow: var(--mdc-elevation-1);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);                /* 8px */
  border: 1px solid var(--mdc-divider);
}

/* ===========================================
   دیالوگ – Modal
   =========================================== */
dialog {
  border: none;
  border-radius: var(--r-lg);
  padding: var(--sp-4);             /* 12px */
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--mdc-elevation-3);
  max-width: 400px;
  width: 90%;
  margin: auto;
  animation: dialogIn 0.2s ease;
}
dialog[open] {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
dialog::backdrop {
  background: rgba(0,0,0,0.4);
}
@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.95); }
}
.dlg-actions {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  margin-top: var(--sp-2);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ===========================================
   Toast – نوار اعلان
   =========================================== */
.toast {
  position: fixed;
  bottom: var(--sp-3);
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: var(--sp-2) var(--sp-4);
  border-radius: 20px;
  box-shadow: var(--mdc-elevation-2);
  z-index: 9999;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
}

/* ===========================================
   سایدبار (Drawer)
   =========================================== */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
}
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  box-shadow: var(--mdc-elevation-2);
  padding: var(--sp-3);
  z-index: 60;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}
.sidebar.open {
  transform: translateX(0);
}
.menu-item {
  padding: var(--sp-1) 0;
  cursor: pointer;
}
.menu-sub {
  padding-right: var(--sp-3);
  font-size: var(--fs-xs);
  opacity: 0.7;
}
.sidebar a {
  display: block;
  padding: var(--sp-2);
  border-radius: var(--r-md);
  color: var(--text);
  transition: background 0.15s;
}
.sidebar a:active {
  background: rgba(128,128,128,0.15);
}

.child {
  all: inherit;
}

/* ===========================================
   چیدمان اصلی اپ (top/center/down)
   =========================================== */
#top-content {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--mdc-divider);
  background: var(--surface);
  z-index: 5;
}
#top-content>div {
  display: flex;
  padding: var(--sp-2) var(--sp-3);
  gap: var(--sp-2);
  min-width: 100%;
}
#center-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  animation: pageIn 0.15s ease;
}
#down-content {
  flex: 0 0 auto;
  border-top: 1px solid var(--mdc-divider);
  background: var(--surface);
  z-index: 5;
}
#down-content>div {
  display: flex;
  padding: var(--sp-2) var(--sp-3);
  gap: var(--sp-2);
  min-width: 100%;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(4px); }
}

/* ===========================================
   لودینگ بار
   =========================================== */
body.is-loading::after {
  content: '';
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: var(--primary);
  z-index: 999;
  animation: loadingSlide 1.5s ease infinite;
}
@keyframes loadingSlide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ===========================================
   کلاس‌های کمکی
   =========================================== */
[x-cloak] { display: none !important; }
html, body { overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; }
button, a, input, select, textarea { touch-action: manipulation; }

/* متن وسط‌چین */
.text-center { text-align: center; }

/* صفحهٔ وسط‌چین (برای لاگین) */
.page-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
/* کارت ورود */
.login-card {
  width: 90%;
  max-width: 360px;
  padding: var(--sp-5);           /* 16px */
}
/* تیتر ورود */
.login-title {
  text-align: center;
  color: var(--primary);
  margin-bottom: var(--sp-4);
  font-size: var(--fs-h1);
  font-weight: 500;
}
/* ناحیهٔ خطا */
.login-error {
  min-height: 1.2rem;
  font-size: var(--fs-xs);
  color: var(--danger);
  margin-top: var(--sp-1);
}
/* حاشیه‌های کمکی */
.mt-2 { margin-top: var(--sp-2); }
.mr-2 { margin-right: var(--sp-2); }
.htmx-request {
  pointer-events: none;
  opacity: 0.6;
  cursor: not-allowed;
}
#lr, .loader {
	animation: spin 1s linear infinite;
}
