/*
 * RIGMS — پوستهٔ «اپ موبایل»: نوار پایین، برگهٔ منو، کارت‌های پیشنهاد، حالت نصب‌شده.
 * بعد از main.css بارگذاری می‌شود و فقط روی ناوبری/لمس‌پذیری اثر می‌گذارد.
 */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
  --sheet-radius: 26px;
  --ease-out: cubic-bezier(.22, .9, .3, 1);
}

html { -webkit-tap-highlight-color: transparent; }
a, button, [role="button"], label, select, input[type="checkbox"], input[type="radio"] { touch-action: manipulation; }
body.sheet-open { overflow: hidden; }

/* ── ورود نرم صفحه ─────────────────────────────────────────────── */
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.app-main { animation: page-in .22s var(--ease-out); }
@media (prefers-reduced-motion: reduce) {
  .app-main, .menu-sheet__panel, .pwa-card, .pwa-toast { animation: none !important; transition: none !important; }
}

/* ── نوار بالا ────────────────────────────────────────────────── */
.navbar-razavi { padding-top: var(--safe-top); }
.app-topbar__title { display: none; margin: 0; font-size: .95rem; font-weight: 800; color: #fff; letter-spacing: -.01em; }
.offline-bar {
  position: fixed; top: 0; inset-inline: 0; z-index: 2000; padding: calc(var(--safe-top) + 4px) 12px 5px;
  background: #b45309; color: #fff; text-align: center; font-size: .72rem; font-weight: 700;
}
.offline-bar[hidden] { display: none; }

/* ── برگهٔ منو (فقط موبایل) ───────────────────────────────────── */
.menu-sheet { display: none; }

/* ── دسکتاپ: سایدبار به‌همان شکل قبل؛ منوی موبایل مخفی ─────────── */
.mobile-bottom-nav { display: none; }

/* ── موبایل و تبلت ────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  /* سایدبار کشویی قدیمی جایش را به «برگهٔ منو» داده است */
  .app-sidebar, .sidebar-overlay, .navbar-toggler { display: none !important; }
  .navbar-razavi .brand-wordmark { display: none !important; }
  .app-topbar__title { display: block; }
  .navbar-razavi .container-fluid { gap: .6rem; }

  .app-main { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px) !important; }
  /* صفحه روی موبایل به‌صورت عادی اسکرول می‌شود (قبلاً ظرف ارتفاع ثابت و overflow:hidden محتوا را می‌برید) */
  html, body { height: auto; min-height: 100%; }
  .app-layout { display: block; height: auto !important; overflow: visible !important; }
  .app-main { overflow: visible !important; height: auto !important; scrollbar-gutter: auto; }

  /* نوار پایین */
  .mobile-bottom-nav {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 1030;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: stretch;
    height: calc(var(--tabbar-h) + var(--safe-bottom)); padding: 6px 6px calc(var(--safe-bottom) + 4px);
    background: rgba(255, 255, 255, .92); backdrop-filter: saturate(1.4) blur(14px);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--app-border); box-shadow: 0 -6px 24px rgba(30, 30, 45, .07);
  }
  .mobile-bottom-nav a, .mobile-bottom-nav button {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-width: 0; padding: 4px 2px; border: 0; background: none; border-radius: 14px;
    color: #7b7d88; font: inherit; font-size: .64rem; line-height: 1.2; text-decoration: none;
    transition: color .15s, transform .12s;
  }
  .mobile-bottom-nav a span:last-child, .mobile-bottom-nav button span:last-child {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .mobile-bottom-nav i { font-size: 1.15rem; }
  .mobile-bottom-nav a:active, .mobile-bottom-nav button:active { transform: scale(.92); }
  .mobile-bottom-nav .tab-icon {
    position: relative; display: grid; place-items: center; width: 52px; height: 28px; border-radius: 14px;
    transition: background .2s var(--ease-out);
  }
  .mobile-bottom-nav a.active, .mobile-bottom-nav button.active { color: var(--razavi-red); font-weight: 800; }
  .mobile-bottom-nav a.active .tab-icon { background: #fff0f1; }
  .tab-badge {
    position: absolute; top: -4px; inset-inline-end: 6px; min-width: 17px; height: 17px; padding: 0 4px;
    display: grid; place-items: center; border-radius: 9px; background: var(--razavi-red); color: #fff;
    font-size: .6rem; font-weight: 800; border: 2px solid #fff; box-sizing: content-box; line-height: 1;
  }

  /* نوار ثبت/انصراف فرم‌ها بالای نوار پایین می‌ماند */
  .form-submit-bar { bottom: calc(var(--tabbar-h) + var(--safe-bottom)) !important; }

  /* برگهٔ منو */
  .menu-sheet {
    position: fixed; inset: 0; z-index: 1060; display: block; visibility: hidden; pointer-events: none;
    transition: visibility 0s linear .3s;
  }
  .menu-sheet.open { visibility: visible; pointer-events: auto; transition-delay: 0s; }
  .menu-sheet__backdrop {
    position: absolute; inset: 0; background: rgba(20, 20, 30, .5); opacity: 0;
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); transition: opacity .28s;
  }
  .menu-sheet.open .menu-sheet__backdrop { opacity: 1; }
  .menu-sheet__panel {
    position: absolute; inset-inline: 0; bottom: 0; display: flex; flex-direction: column;
    max-height: calc(100dvh - var(--safe-top) - 24px); background: #fbfbfc;
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0; box-shadow: 0 -12px 40px rgba(0, 0, 0, .22);
    transform: translateY(102%); transition: transform .32s var(--ease-out); padding-bottom: var(--safe-bottom);
  }
  .menu-sheet.open .menu-sheet__panel { transform: translateY(0); }
}

.menu-sheet__head { padding: 10px 18px 6px; touch-action: none; }
.menu-sheet__grab { width: 42px; height: 5px; margin: 0 auto 12px; border-radius: 3px; background: #d4d5db; }
.menu-sheet__user { display: flex; align-items: center; gap: .75rem; }
.menu-sheet__avatar {
  display: grid; place-items: center; flex: 0 0 46px; width: 46px; height: 46px; border-radius: 15px;
  background: linear-gradient(135deg, var(--razavi-red), var(--razavi-red-dk)); color: #fff; font-size: 1.1rem;
}
.menu-sheet__user strong { display: block; font-size: .92rem; color: var(--app-text); }
.menu-sheet__user small { display: block; color: var(--app-muted); font-size: .72rem; }
.menu-sheet__close {
  margin-inline-start: auto; display: grid; place-items: center; width: 40px; height: 40px; border: 0;
  border-radius: 12px; background: #eeeff2; color: #555761;
}
.menu-sheet__search { position: relative; margin: 10px 16px 4px; }
.menu-sheet__search i { position: absolute; top: 50%; inset-inline-start: 14px; transform: translateY(-50%); color: #9a9ba4; }
.menu-sheet__search input {
  width: 100%; height: 46px; padding: 0 42px 0 14px; border: 1px solid var(--app-border); border-radius: 14px;
  background: #fff; font: inherit; font-size: .88rem;
}
.menu-sheet__search input:focus { outline: 0; border-color: var(--razavi-red); box-shadow: 0 0 0 .22rem rgba(212, 32, 39, .1); }
.menu-sheet__body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 18px; -webkit-overflow-scrolling: touch; }
.menu-group { margin-top: 14px; }
.menu-group[hidden], .menu-tile[hidden] { display: none; }
.menu-group h3 { margin: 0 4px 8px; font-size: .72rem; font-weight: 800; color: #8b8d96; letter-spacing: .01em; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.menu-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 7px; min-height: 92px;
  padding: 12px 6px 10px; border: 1.5px solid transparent; border-radius: 18px; background: #fff;
  box-shadow: 0 1px 2px rgba(30, 30, 45, .05), 0 4px 14px rgba(30, 30, 45, .04);
  color: #3a3b45; text-align: center; text-decoration: none; font-size: .72rem; font-weight: 700; line-height: 1.45;
  transition: transform .12s, border-color .15s;
}
.menu-tile:active { transform: scale(.95); }
.menu-tile__icon {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: #fff0f1;
  color: var(--razavi-red); font-size: 1.1rem;
}
.menu-tile.active { border-color: var(--razavi-red); }
.menu-tile.active .menu-tile__icon { background: var(--razavi-red); color: #fff; }
.menu-empty { padding: 28px 8px; text-align: center; color: var(--app-muted); font-size: .85rem; }
.menu-empty[hidden] { display: none; }

.menu-list { margin: 0; padding: 0; list-style: none; background: #fff; border-radius: 18px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(30, 30, 45, .05), 0 4px 14px rgba(30, 30, 45, .04); }
.menu-list > li + li { border-top: 1px solid #f0f0f3; }
.menu-row {
  display: flex; align-items: center; gap: .8rem; width: 100%; min-height: 54px; padding: 8px 14px; border: 0;
  background: none; color: #3a3b45; font: inherit; font-size: .86rem; font-weight: 700; text-align: start; text-decoration: none;
}
.menu-row[hidden] { display: none; }
.menu-row:active { background: #f6f6f8; }
.menu-row > i:first-child { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: #f2f2f5; color: #666873; }
.menu-row small { display: block; margin-top: 1px; font-size: .68rem; font-weight: 500; color: var(--app-muted); }
.menu-row--danger { color: #c62828; }
.menu-row--danger > i:first-child { background: #fdecec; color: #c62828; }
.menu-row form { display: contents; }
.menu-switch {
  margin-inline-start: auto; position: relative; flex: 0 0 46px; width: 46px; height: 28px; border-radius: 14px;
  background: #d4d5db; transition: background .2s;
}
.menu-switch::after {
  content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s var(--ease-out);
}
.is-on .menu-switch { background: #2e9d57; }
.is-on .menu-switch::after { transform: translateX(-18px); }
[dir="rtl"] .menu-switch::after { inset-inline-start: auto; right: 3px; }
[dir="rtl"] .is-on .menu-switch::after { transform: translateX(-18px); }

/* ── پیام‌ها و کارت‌های پیشنهاد (نصب/اعلان) ───────────────────── */
.pwa-toasts {
  position: fixed; z-index: 1070; inset-inline: 12px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none;
}
@media (min-width: 992px) { .pwa-toasts { inset-inline: auto; left: 20px; bottom: 20px; align-items: flex-start; width: min(420px, 94vw); } }
.pwa-toast, .pwa-card { pointer-events: auto; opacity: 0; transform: translateY(14px); transition: opacity .25s, transform .3s var(--ease-out); }
.pwa-toast.in, .pwa-card.in { opacity: 1; transform: none; }
.pwa-toast {
  max-width: 100%; padding: 11px 18px; border-radius: 14px; background: #2b2c38; color: #fff; font-size: .82rem; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.pwa-toast--success { background: #1f7a45; }
.pwa-toast--error { background: #b3261e; }
.pwa-toast--warning { background: #a15c07; }
.pwa-card {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; width: 100%; max-width: 440px; padding: 14px;
  border-radius: 20px; background: #fff; border: 1px solid var(--app-border); box-shadow: 0 16px 44px rgba(20, 20, 35, .22);
}
.pwa-card__icon { grid-row: span 2; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 15px; background: #fff0f1; color: var(--razavi-red); font-size: 1.15rem; }
.pwa-card__text strong { display: block; font-size: .92rem; color: var(--app-text); }
.pwa-card__text p { margin: 3px 0 0; font-size: .78rem; line-height: 1.8; color: var(--app-muted); }
.pwa-card__actions { grid-column: 2; display: flex; gap: 8px; margin-top: 6px; }
.pwa-btn {
  min-height: 42px; padding: 0 18px; border: 1px solid var(--app-border); border-radius: 12px; background: #fff; color: #4a4b57;
  font: inherit; font-size: .84rem; font-weight: 800;
}
.pwa-btn--primary { border-color: var(--razavi-red); background: var(--razavi-red); color: #fff; box-shadow: 0 5px 12px rgba(212, 32, 39, .22); }
.pwa-btn:active { transform: scale(.96); }

/* ── صفحهٔ اعلان‌ها: وضعیت اعلان فوری ──────────────────────────── */
.push-card { margin-bottom: 1rem; }
.push-card .menu-list { box-shadow: none; border: 1px solid var(--app-border); }

/* ── ماتریس دسترسی‌ها روی موبایل: هر بخش یک کارت ─────────────── */
@media (max-width: 767.98px) {
  .perm-table thead, .uperm-table thead { display: none; }
  .perm-table, .perm-table tbody, .uperm-table, .uperm-table tbody { display: block; width: 100%; }
  .perm-table tr, .uperm-table tr {
    display: grid; gap: 6px; margin: 10px 12px; padding: 12px; border: 1px solid var(--app-border); border-radius: 16px; background: #fff;
  }
  .perm-table tr { grid-template-columns: repeat(3, 1fr); }
  .perm-table td, .uperm-table td { display: block; padding: 0 !important; border: 0 !important; }
  .perm-table td:first-child, .uperm-table td:first-child { grid-column: 1 / -1; margin-bottom: 4px; }
  .perm-table tr.perm-group-row, .uperm-table tr.uperm-group-row { display: block; margin: 16px 14px 2px; padding: 0; border: 0; background: none; }
  .perm-table .perm-group-row td, .uperm-table .uperm-group-row td { background: none !important; color: #8b8d96; }
  .perm-table td.level-col {
    width: auto; padding: 8px 4px !important; border: 1.5px solid var(--app-border) !important; border-radius: 12px; text-align: center;
  }
  .perm-table td.level-col::before { content: attr(data-label); display: block; margin-bottom: 6px; font-size: .64rem; color: #8b8d96; }
  .perm-table td.level-col:has(input:checked) { border-color: var(--razavi-red) !important; background: #fff0f1; }
  .perm-choice input { width: 24px !important; height: 24px !important; }
  .uperm-table td[data-label]::before { content: attr(data-label) ': '; font-size: .68rem; color: #8b8d96; }
  .uperm-table td { font-size: .8rem; }
  .uperm-select { width: 100%; min-width: 0; }
}

/* ── حالت نصب‌شده (standalone): حس اپ واقعی ───────────────────── */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: contain; -webkit-user-select: none; user-select: none; }
  input, textarea, select, [contenteditable], .app-main p, .app-main td, .app-main h1, .app-main h2 { -webkit-user-select: text; user-select: text; }
  .navbar-razavi { position: sticky; top: 0; z-index: 1040; }
}


/* ── موبایل: داشبورد جمع‌وجور ───────────────────────────────── */
@media (max-width: 767.98px) {
  .worker-welcome { margin-bottom: .6rem !important; }
  .worker-welcome h1 { font-size: 1.15rem !important; margin: 0 0 .15rem !important; }
  .worker-welcome__date { font-size: .74rem !important; margin: 0 !important; }
  .worker-home .row.g-3 { --bs-gutter-y: .6rem; }
  .today-action { padding: .8rem .9rem !important; gap: .7rem; }
  .today-action h3 { margin-bottom: .45rem !important; }
  .today-action__label { margin-bottom: .15rem !important; font-size: .68rem !important; }
  .simple-action { min-height: 58px !important; }
  .more-tools__toggle { padding: .7rem .9rem !important; }
  .action-queue__items { flex-wrap: nowrap; overflow-x: auto; gap: .5rem; padding-bottom: 2px; }
  .queue-item { flex: 0 0 auto; width: auto !important; gap: .5rem; }
  .worker-home .mb-4 { margin-bottom: .8rem !important; }
}
