/* Mobile (< 768px) — Figma page «22 · Mobile» (390×844). Loaded after every other stylesheet.
   Desktop (≥ 768px) is untouched except for hiding the mobile-only elements below. Colors only from tokens. */
.mhead, .mtabs { display: none; }
.mnav-backdrop { display: none; }
@media (min-width: 768px) { .m-only { display: none !important; } }

@media (max-width: 767px) {
  :root { --m-gutter: 16px; --m-tabs: 72px; --m-head: 56px; }
  body { min-width: 0; overflow-x: hidden; }
  .d-only { display: none !important; }

  /* ---------- Shell: sidebar becomes an off-canvas drawer (opened by «بیشتر» / ⋮) ---------- */
  .shell, .shell.is-collapsed { display: block; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; right: 0; width: min(300px, 86vw); height: auto; z-index: 80;
    transform: translateX(100%); transition: transform .2s ease-out; box-shadow: var(--shadow-lg);
  }
  .mnav-open .sidebar { transform: none; }
  .sidebar__collapse { display: none; }
  .shell.is-collapsed .nav-item span, .shell.is-collapsed .user-card__meta, .shell.is-collapsed .sidebar__brand img.logo-full { display: revert; }
  .shell.is-collapsed .nav-item { justify-content: flex-start; padding-inline: 14px 10px; width: auto; }
  .shell.is-collapsed .nav-group { font-size: 11px; display: block; padding: 16px 14px 6px 10px; }
  .shell.is-collapsed .nav-group::after { display: none; }
  .nav-item { height: 44px; }
  .mnav-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; background: var(--color-overlay); z-index: 75; }
  .mnav-open body { overflow: hidden; }

  /* ---------- Top bar → mobile header (logo mark + title, bell + avatar on the left) ---------- */
  .topbar, .pshell__top { height: var(--m-head); padding: 0 var(--m-gutter); gap: 8px; }
  .topbar__search, .topbar__sep, .topbar__actions > .menu-wrap:has(> .btn-primary) { display: none; }
  .mhead { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
  .mhead__mark { width: 41px; height: 28px; flex: none; }
  .mhead__title { font: 700 18px/28px var(--font-family); color: var(--color-text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .mhead--back .mhead__title { font: 600 17px/28px var(--font-family); }
  .mhead__back, .mhead__more { width: 44px; height: 44px; margin-inline: -10px 0; display: grid; place-items: center; border: 0; background: none; color: var(--color-text-secondary); flex: none; cursor: pointer; border-radius: var(--radius-md); }
  .mhead__back .icon, .mhead__more .icon { width: 24px; height: 24px; }
  .mhead__more { margin-inline: auto -10px; }
  .topbar:has(.mhead--back) .topbar__actions, .pshell__top:has(.mhead--back) .pshell__actions { display: none; }
  .topbar__actions, .pshell__actions { gap: 4px; }
  .user-trigger { padding: 0; }
  .user-trigger > :not(.avatar) { display: none; }
  .topbar .avatar, .pshell__top .avatar { width: 32px; height: 32px; background: var(--color-brand-navy-50); color: var(--color-text-brand); font: 500 12px/1 var(--font-family); }
  .topbar .icon-btn, .pshell__top .icon-btn { width: 44px; height: 44px; }
  .topbar .icon-btn .icon, .pshell__top .icon-btn .icon { width: 24px; height: 24px; }
  .topbar .icon-btn .dot, .pshell__top .icon-btn .dot { top: 8px; inset-inline-end: 9px; }
  .menu--user { position: fixed; top: calc(var(--m-head) + 4px); left: var(--m-gutter); right: auto; }
  .ntf-panel { position: fixed !important; top: calc(var(--m-head) + 4px) !important; left: 8px !important; right: 8px !important; width: auto !important; max-height: calc(100vh - var(--m-head) - var(--m-tabs) - 16px); overflow: auto; }

  /* Partner shell: horizontal logo + tab nav hidden; nav shown as a drawer from «بیشتر» */
  .pshell__top > a:first-of-type { display: none; }
  .pshell__top .pnav { display: none; }
  .mnav-open .pshell__top .pnav {
    display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; right: 0; width: min(300px, 86vw); height: auto;
    background: var(--color-surface-card); z-index: 80; padding: 16px 12px; gap: 2px; box-shadow: var(--shadow-lg); overflow-y: auto;
  }
  .mnav-open .pshell__top { z-index: 81; }
  .mnav-open .pshell__top .pnav a { height: 48px; border-bottom: 0; border-radius: var(--radius-md); padding: 0 12px; }
  .mnav-open .pshell__top .pnav a.is-active { background: var(--color-brand-navy-50); }

  /* ---------- Content ---------- */
  .content, .pcontent { padding: 16px var(--m-gutter) calc(var(--m-tabs) + 24px); max-width: none; }
  .shell:has(.mhead--back) .content, .pshell:has(.mhead--back) .pcontent { padding-bottom: 24px; }

  /* ---------- Bottom tab bar (Figma 503:2939 / 508:4053) ---------- */
  .mtabs {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 55; height: calc(var(--m-tabs) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--color-surface-card); border-top: 1px solid var(--color-border);
  }
  body:has(.mhead--back) .mtabs { display: none; }
  .mtab {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 0;
    border: 0; background: none; color: var(--color-gray-400); font: 400 12px/18px var(--font-family); cursor: pointer; text-decoration: none; padding: 0;
  }
  .mtab:hover { text-decoration: none; }
  .mtab .icon { width: 24px; height: 24px; }
  .mtab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .mtab.is-active { color: var(--color-text-brand); font-weight: 600; }
  .mtab.is-active::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--color-brand-amber); }

  /* ---------- Page header, breadcrumb ---------- */
  .breadcrumb { display: none; }
  .page-header { flex-wrap: wrap; align-items: flex-start; gap: 12px; margin-block-end: 16px; }
  .page-header > div:first-child { min-width: 0; flex: 1 1 100%; }
  .page-header__title, .page-title { font: 700 20px/32px var(--font-family); }
  .page-header__actions { flex-wrap: wrap; gap: 8px; }
  .page-actions { flex-wrap: wrap; gap: 12px; }

  /* ---------- Touch targets ≥ 44px, single-column forms ---------- */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .btn-link { min-height: 0; }
  .input, .select, .input-affix, .topbar__search input { height: 44px; font-size: 16px; }
  .input-wrap__btn { top: 10px; }
  .textarea { font-size: 16px; }
  .icon-btn { width: 44px; height: 44px; }
  .icon-btn--sm { width: 36px; height: 36px; }
  .close-btn { width: 44px; height: 44px; }
  .check input { width: 22px; height: 22px; }
  .pagination a, .pagination span { min-width: 40px; height: 40px; }
  .menu a, .menu button { height: 44px; }
  .form-grid, .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4, .status-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .form-grid .span-2 { grid-column: auto; }
  .kv { grid-template-columns: 112px minmax(0, 1fr); }
  .form-actions { flex-wrap: wrap; }

  /* ---------- Tables scroll inside their wrapper; toolbars wrap ---------- */
  .table-wrap, .card { max-width: 100%; }
  .table-wrap, .card:has(> .table), .card:has(> form > .table), .qe-table-wrap, .opp-inner-table { position: relative; }
  .card:has(> .table), .card:has(> form > .table) { overflow-x: auto; }
  .table th, .table td { white-space: nowrap; }
  .table-toolbar, .toolbar, .table-footer, .pager { flex-wrap: wrap; gap: 8px; }
  .toolbar__search, .table-toolbar .input, .toolbar .select, .table-toolbar .select { width: 100%; min-width: 0; }
  .toolbar__end { margin-inline-start: 0; flex-wrap: wrap; }

  /* Settings: sub-nav becomes a horizontal scroller above the content */
  .settings-layout { display: block; }
  .settings-nav { position: static; display: flex; gap: 4px; overflow-x: auto; margin-block-end: 16px; padding: 6px; }
  .settings-nav__group { display: none; }
  .settings-nav a { flex: none; height: 40px; white-space: nowrap; }

  /* ---------- Modals & drawers → bottom sheets (Figma 506:3967) ---------- */
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal, .modal--sm, .modal--lg, dialog.modal {
    width: 100%; max-width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; margin: auto 0 0; animation: msheet-in .2s ease-out;
  }
  .modal::before, .drawer::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--color-gray-300); margin: 8px auto 0; }
  .modal__header, .drawer__header { padding: 12px var(--m-gutter); border-bottom: 0; align-items: center; }
  .modal__body, .drawer__body { padding: 8px var(--m-gutter) 16px; }
  .modal__footer, .drawer__footer { padding: 12px var(--m-gutter) calc(12px + env(safe-area-inset-bottom, 0px)); flex-wrap: wrap; }
  .modal__footer .btn, .drawer__footer .btn { flex: 1 1 0; }
  .drawer, .drawer--wide {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; border: 0; animation: msheet-in .2s ease-out;
  }
  @keyframes msheet-in { from { transform: translateY(100%); } to { transform: none; } }

  /* ---------- Toasts: bottom, full width above the tab bar ---------- */
  .toasts { inset-inline: var(--m-gutter); bottom: calc(var(--m-tabs) + 12px); }
  body:has(.mhead--back) .toasts { bottom: 12px; }
  .toast { width: auto; }

  /* ---------- Auth (Figma 502:86704) ---------- */
  .auth { justify-content: flex-start; padding: 72px 24px 32px; }
  .auth__sun { display: none; }
  .auth__mlogo-wrap { display: block; }
  .auth__mlogo { display: block; height: 86px; width: auto; margin: 0 auto 24px; }
  .auth-card { width: 100%; padding: 24px 20px 28px; box-shadow: none; border-radius: 16px; }
  .auth-card__logo { display: none; }
  .auth-card__title, .auth-card__sub { text-align: right; }
  .auth-card__title { font: 700 20px/32px var(--font-family); margin-block-end: 12px; }
  .auth-card__sub { margin-block-end: 20px; }
  .auth-card .btn-block { min-height: 48px; }
  .auth .m-forgot { display: block; text-align: center; margin-top: 24px; font: var(--text-body-strong); }
  .auth__foot { margin-top: auto; padding-top: 48px; }
}

/* ======================= Page-specific mobile layouts ======================= */
@media (max-width: 767px) {
  /* Floating action button (Figma 503:2939 «ثبت سریع فعالیت», 505:3234 «ثبت نمایشگاهی») */
  .m-fab, .today__head .page-header__actions > .btn-primary {
    position: fixed; z-index: 54; left: var(--m-gutter); bottom: calc(var(--m-tabs) + 16px); height: 48px; min-height: 48px; padding: 0 24px;
    border-radius: var(--radius-full); box-shadow: var(--shadow-lg); font: 600 16px/24px var(--font-family); flex-direction: row-reverse; gap: 12px;
  }
  .m-fab .icon, .today__head .page-header__actions > .btn-primary .icon { width: 24px; height: 24px; opacity: .6; }

  /* ---------- امروز (503:2939) ---------- */
  .today__head { margin-bottom: 8px; }
  .today__head .page-header__actions > :not(.btn-primary) { display: none; }
  .today__head .page-header__sub { font: var(--text-body); margin-top: 12px; }
  .today__grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .today__main, .today__side { gap: 16px; }
  .today-tasks.card { background: none; border: 0; box-shadow: none; padding: 0; }
  .tsec-head, .today-sec__head { min-height: 48px; margin: 0; }
  .tsec-head h2, .today-sec__head h2 { font: 700 18px/28px var(--font-family); }
  .today .count--danger { background: var(--color-gray-100); color: var(--color-text-secondary); }
  .today .task-list { display: flex; flex-direction: column; gap: 12px; }
  .task-list + .tsec-head { margin-top: 8px; }
  .today .task-item {
    display: grid; grid-template-columns: 24px auto auto minmax(0, 1fr) 36px; grid-template-areas: "chk main main main snz" ". due flag . ."; align-items: center; column-gap: 8px;
    gap: 6px 8px; min-height: 0; padding: 16px; background: var(--color-surface-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  }
  .today .task-list:last-child .task-item:last-child { border-bottom: 1px solid var(--color-border); }
  .today .task-item:has(.due-pill) { border: 1.5px solid var(--color-danger); }
  .today .task-item > .tcheck, .today .task-item__check .tcheck { grid-area: chk; align-self: start; width: 18px; height: 18px; margin-top: 4px; }
  .today .task-item__check .tcheck::after { content: ""; position: absolute; inset: -13px; }
  .today .task-item__check .tcheck { position: relative; }
  .today .task-item__main { grid-area: main; gap: 6px; margin-inline-start: 8px; }
  .today .due-pill, .today .due-time { margin-inline-start: 8px; }
  .today .task-item__title { font: 500 16px/28px var(--font-family); }
  .today .ctx-link { color: var(--color-text-secondary); font: var(--text-body); }
  .today .ctx-link .icon { width: 18px; height: 18px; color: var(--color-text-brand); }
  .today .task-item__meta { display: contents; }
  .today .due-pill, .today .due-time { grid-area: due; background: none; padding: 0; height: auto; font: var(--text-body); }
  .today .due-pill .icon, .today .due-time .icon { width: 18px; height: 18px; }
  .today .due-pill .icon { color: var(--color-danger); }
  .today .task-flag { grid-area: flag; }
  .today .task-flag .icon { width: 20px; height: 20px; }
  .today .task-item .avatar-xs { display: none; }
  .today .snooze { grid-area: snz; align-self: start; justify-self: end; }
  .today .snooze > summary { width: 36px; height: 36px; }
  .today .snooze > summary .icon { width: 22px; height: 22px; color: var(--color-text-secondary); }
  .today .snooze__pop { left: 0; width: min(264px, calc(100vw - 48px)); }
  .today .na-grid { grid-template-columns: minmax(0, 1fr); }
  .today .side-row { flex-wrap: wrap; }
  .today .side-row__sub { white-space: normal; }
  .today-empty { min-height: 0; padding: 24px 16px; }
}

/* ---------- Mobile list cards (Card + Badge/Status) — shared ---------- */
@media (max-width: 767px) {
  .mlist { display: flex; flex-direction: column; gap: 12px; }
  .mcount { font: var(--text-body); color: var(--color-text-muted); margin: 0 0 16px; }
  .mcard {
    display: flex; align-items: center; gap: 12px; min-height: 92px; padding: 16px; background: var(--color-surface-card); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); color: var(--color-text-primary); text-decoration: none;
  }
  a.mcard:hover { text-decoration: none; border-color: var(--color-gray-300); }
  .mcard__icon { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--color-brand-navy-50); color: var(--color-text-brand); display: grid; place-items: center; }
  .mcard__icon .icon { width: 20px; height: 20px; }
  .mcard__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
  .mcard__title { font: 600 15px/24px var(--font-family); }
  .mcard__line { font: 400 13px/20px var(--font-family); color: var(--color-text-secondary); }
  .mcard__line--muted { color: var(--color-text-muted); }
  .mcard__side { flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; max-width: 45%; }
  .mcard__side .badge { height: 24px; font: 500 12px/20px var(--font-family); }
  .mcard__meta { font: var(--text-small); color: var(--color-text-muted); }
  .mcard__chev { flex: none; color: var(--color-gray-400); display: grid; }
  .mcard__chev .icon { width: 18px; height: 18px; }
  .mcard--danger .mcard__icon { background: var(--color-danger-bg); color: var(--color-danger); }

  /* A list page that has a .mlist hides its desktop table chrome on mobile (pagination stays) */
  .card:has(> .mlist) { background: none; border: 0; box-shadow: none; overflow: visible; }
  .card:has(> .mlist) > .table-wrap, .card:has(> .mlist) > .table-toolbar, .card:has(> .mlist) > form.table-toolbar { display: none; }
  .card:has(> .mlist) > .table-footer { border: 0; padding: 12px 0 0; justify-content: center; }
  .card:has(> .mlist) > .table-footer > .row { display: none; }

  /* ---------- سرنخ‌ها (505:3234) ---------- */
  .ld > .page-header, .ld > .ld-tabs, .ld-table > .table-toolbar { display: none; }
  .ld .filterbar { display: flex; flex-wrap: wrap; gap: 12px 8px; margin-bottom: 16px; }
  .ld .filterbar__search { flex: 1 1 100%; width: 100%; }
  .ld .filterbar__search .input { height: 44px; border-radius: var(--radius-md); padding-inline-start: 44px; }
  .ld .filterbar__search .icon { top: 12px; inset-inline-start: 14px; width: 22px; height: 22px; }
  .ld .fchip.is-add, .ld .filterbar__clear { display: none; }
  .ld .fchip > summary, .ld .fadd > summary { height: 32px; padding: 0 14px; border-radius: var(--radius-full); font: var(--text-body); }
  .ld .fadd > summary { border: 1px dashed var(--color-gray-300); background: none; color: var(--color-text-secondary); }
  .ld .pop, .pp .pop { position: fixed; inset-inline: var(--m-gutter); top: auto; bottom: calc(var(--m-tabs) + 12px); max-width: none; z-index: 85; box-shadow: var(--shadow-lg); }
  .ld .mcard__icon, .pl-mcard .mcard__icon { width: 40px; height: 40px; }
}

/* ---------- ثبت سرنخ نمایشگاهی (505:3480) ---------- */
@media (max-width: 767px) {
  .ld:has(.ld-exh) > .page-header, .ld .ld-exh__side, .ld .ld-exh__sep, .ld .ld-exh__form > .form-grid:has(#x_camp), .ld .ld-exh__form .field:has(#x_prov) { display: none; }
  .ld .ld-exh { grid-template-columns: minmax(0, 1fr); }
  .ld .ld-exh__form.card { background: none; border: 0; box-shadow: none; padding: 0; gap: 20px; }
  .ld .ld-exh__mbanner { margin: 0; padding: 16px; border-radius: var(--radius-lg); }
  .ld .ld-exh__mbanner .alert__title { font: 500 15px/28px var(--font-family); }
  .ld .ld-exh__mbanner > .icon { width: 22px; height: 22px; }
  .ld .ld-exh__actions {
    position: sticky; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; margin: 8px calc(-1 * var(--m-gutter)) -24px;
    padding: 16px var(--m-gutter) calc(16px + env(safe-area-inset-bottom, 0px)); background: var(--color-surface-card); border-top: 1px solid var(--color-border);
  }
  .ld .ld-exh__actions .hint { grid-column: 1 / -1; font: var(--text-body); color: var(--color-text-primary); }
  .ld .ld-exh__actions .btn { height: 48px; min-height: 48px; font: 600 16px/24px var(--font-family); }
  .ld .ld-exh__actions .btn-primary { order: 1; grid-row: 2; grid-column: 1; }
  .ld .ld-exh__actions .btn-secondary { grid-row: 2; grid-column: 2; }
}

/* ---------- Detail pages: header card, segmented tabs, sticky action bar (506:3504, 507:3841) ---------- */
@media (max-width: 767px) {
  .is-mseg-hidden { display: none !important; }
  .mdetail { padding: 20px 16px; margin-bottom: 16px; }
  .mdetail__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
  .mdetail__title { font: 700 18px/30px var(--font-family); margin: 0; }
  .mdetail__top .badge { flex: none; height: 28px; padding: 0 10px; font: var(--text-body); margin-top: 2px; }
  .mdetail__eyebrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
  .mdetail__eyebrow .badge { height: 28px; padding: 0 10px; font: var(--text-body); }
  .mdetail__num { direction: ltr; font: 500 13px/20px var(--font-family); }
  .mdetail__sub { margin-top: 12px; font: var(--text-body); color: var(--color-text-secondary); }
  .mdetail__phone { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--color-border); }
  .mdetail__phone > .ltr { font: 600 15px/24px var(--font-family); }
  .mdetail__call { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: 1px solid var(--color-gray-300); border-radius: var(--radius-md); color: var(--color-text-brand); }
  .mdetail__call .icon { width: 22px; height: 22px; }
  .mdetail__phone .msgr { margin-inline-start: auto; gap: 4px; }
  .mdetail__phone .msgr__btn { width: 32px; height: 32px; }
  .mdetail__kv { margin: 0; padding-top: 4px; display: flex; flex-direction: column; }
  .mdetail__kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; }
  .mdetail__kv dt { color: var(--color-text-muted); font: var(--text-body); flex: none; }
  .mdetail__kv dd { margin: 0; font: 500 15px/24px var(--font-family); text-align: left; }
  .mdetail__stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 16px 0; padding-bottom: 16px; border-bottom: 1px solid var(--color-border); }
  .mdetail__stat { background: var(--color-gray-50); border-radius: var(--radius-md); padding: 12px; display: flex; flex-direction: column; gap: 4px; }
  .mdetail__stat span { font: var(--text-small); color: var(--color-text-muted); }
  .mdetail__stat b { font: 700 18px/28px var(--font-family); }
  .mdetail__stat small { font: var(--text-small); color: var(--color-text-secondary); }

  .mseg { display: flex; gap: 24px; border-bottom: 1px solid var(--color-border); margin: 8px 0 16px; overflow-x: auto; }
  .mseg a { position: relative; flex: none; height: 48px; display: flex; align-items: center; padding: 0 12px; color: var(--color-text-secondary); font: var(--text-body); text-decoration: none; }
  .mseg a.is-active { color: var(--color-text-brand); font-weight: 600; }
  .mseg a.is-active::after { content: ""; position: absolute; inset-inline: 0; bottom: -1px; height: 2px; background: var(--color-brand-amber); }

  .m-actionbar {
    position: fixed; z-index: 55; inset-inline: 0; bottom: 0; display: flex; gap: 12px; padding: 12px var(--m-gutter) calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--color-surface-card); border-top: 1px solid var(--color-border);
  }
  .m-actionbar .btn { flex: 1 1 0; height: 48px; min-height: 48px; font: 600 16px/24px var(--font-family); flex-direction: row-reverse; gap: 12px; }
  .m-actionbar .btn .icon { width: 24px; height: 24px; opacity: .6; }
  body:has(.m-actionbar) .content, body:has(.m-actionbar) .pcontent { padding-bottom: 96px; }
  body:has(.m-actionbar) .toasts { bottom: 88px; }

  /* Next action card (shared) */
  .na-card { padding: 16px; }
  .na-card__actions { flex-wrap: wrap; gap: 12px; padding-top: 4px; }
  .na-card__actions .btn-sm { min-height: 40px; height: 40px; padding: 0 16px; font: var(--text-body-strong); }

  /* سرنخ: reorder — header card, next action, tabs, panels */
  .ld:has(.mdetail) .ld-detail-head { display: none; }
  .ld .ld-grid { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
  .ld .ld-main, .ld .ld-side { display: contents; }
  .ld .ld-side > .na-card { order: -2; }
  .ld .ld-grid > .mseg { order: -1; margin: 0; }
  .ld .ld-card { padding: 16px; }
  .ld .ld-kv { grid-template-columns: minmax(0, 1fr); }
  .ld .ld-tl.card { background: none; border: 0; box-shadow: none; padding: 0; }
  .ld .ld-tl .ld-card__head { display: none; }
}

/* ---------- Quick activity / next action sheets (506:3967) ---------- */
@media (max-width: 767px) {
  .qa .modal__header { padding: 12px var(--m-gutter) 4px; }
  .qa .modal__title { font: 700 18px/28px var(--font-family); }
  .qa .segmented--fill { overflow-x: auto; scrollbar-width: none; }
  .qa .segmented--fill .segmented__item { flex: none; height: 40px; padding: 0 14px; }
  .qa .segmented { flex-wrap: wrap; }
  .qa .segmented--fill { flex-wrap: nowrap; }
  .qa__grid, .na-panel__grid--row, .na-panel__grid--stack { grid-template-columns: minmax(0, 1fr); }
  .qa .combo__icon, .qa .combo__chev { top: 13px; }
  .dt-field { height: 44px; }
  .dt-field .input { height: 42px; }
  .qa__footer { position: sticky; bottom: 0; background: var(--color-surface-card); }
  .qa__footer .check { flex: 1 1 100%; }
  .qa__close { margin: 0; }
  .na-panel { padding: 16px 12px; }
}

/* ---------- فرصت (507:3841): summary first, then tabs + tab content ---------- */
@media (max-width: 767px) {
  .opp-ws:has(.mdetail) { display: flex; flex-direction: column; gap: 16px; }
  .opp-ws:has(.mdetail) > *, .opp-ws .opp-main, .opp-ws .opp-side > * { margin-block: 0; min-width: 0; max-width: 100%; }
  .opp-ws:has(.mdetail) .opp-hero { display: none; }
  .opp-ws .opp-grid, .opp-ws .opp-side { display: contents; }
  .opp-ws > .mdetail { order: 1; }
  .opp-ws .opp-side > .na-card { order: 2; }
  .opp-ws > .mquote { order: 3; }
  .opp-ws > .opp-wtabs { order: 4; }
  .opp-ws .opp-main { order: 5; }
  .opp-ws .opp-side > :not(.na-card) { order: 6; }
  .opp-ws .mdetail { margin: 0; }
  .msec-title { font: 700 18px/28px var(--font-family); margin: 8px 0 12px; }
  .opp-wtab { flex: none; min-height: 44px; }

  /* «تغییر وضعیت» → bottom sheet form */
  .m-sheetpop { flex: 1 1 0; display: flex; }
  .m-sheetpop > summary { flex: 1; list-style: none; height: 48px; min-height: 48px; font: 600 16px/24px var(--font-family); }
  .m-sheetpop > summary::-webkit-details-marker { display: none; }
  .m-sheetpop:not([open]) .m-sheetpop__body { display: none; }
  .m-sheetpop[open]::before { content: ""; position: fixed; inset: 0; background: var(--color-overlay); z-index: 1; }
  .m-sheetpop__body {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 2; display: flex; flex-direction: column; gap: 12px; padding: 24px var(--m-gutter) calc(20px + env(safe-area-inset-bottom, 0px));
    background: var(--color-surface-card); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg); animation: msheet-in .2s ease-out;
  }
}

/* ---------- Generic overflow guards (every other page must at least be usable < 768px) ---------- */
@media (max-width: 767px) {
  .segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .composer__foot, .composer__actions, .tl-toolbar, .filterbar, .row-between, .inline-actions, .card__header, .card-head--row, .side-row__line { flex-wrap: wrap; }
  .tabs, .opp-wtabs, .ld-tabs, .opp-tabs, .ntf-tabs, nav[class$="-tabs"], nav[class*="-tabs "] { overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .tabs > *, .ld-tabs > *, .opp-tabs > *, nav[class$="-tabs"] > *, nav[class*="-tabs "] > * { flex: none; }
  .qe-table-wrap, .opp-inner-table { overflow-x: auto; max-width: 100%; }
  .qp-sheet { max-width: 100%; overflow-x: auto; }
  img, svg, video, canvas { max-width: 100%; }
  pre, code { white-space: pre-wrap; word-break: break-word; }
}

/* ---------- اعلان‌ها (507:3971) ---------- */
@media (max-width: 767px) {
  .ntf-page > .page-header { display: none; }
  .ntf-tabs { margin-block-end: 16px; gap: 4px; }
  .ntf-tab { height: 48px; padding: 0 16px; font: var(--text-body); }
  .ntf-group { margin-block-end: 16px; }
  .ntf-group__label { display: flex; align-items: center; justify-content: space-between; min-height: 44px; font: var(--text-body); color: var(--color-text-secondary); margin: 0 0 8px; }
  .ntf-group__readall .link-btn { min-height: 44px; padding: 0 8px; }
  .ntf-list { display: flex; flex-direction: column; gap: 12px; }
  .ntf-item, .ntf-item.is-unread {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "icon title badge" "icon body meta"; align-items: center; gap: 4px 12px;
    padding: 16px; background: var(--color-surface-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  }
  .ntf-item__dot, .ntf-item__action { display: none; }
  .ntf-item__icon, .ntf-item.is-unread .ntf-item__icon { grid-area: icon; grid-row: 1 / span 2; width: 40px; height: 40px; background: var(--color-brand-navy-50); color: var(--color-text-brand); }
  .ntf-item__icon .icon { width: 20px; height: 20px; }
  .ntf-item__main, .ntf-item__title { display: contents; }
  .ntf-item__title a { grid-area: title; font: 600 15px/24px var(--font-family); }
  .ntf-item__title a::after { content: ""; position: absolute; inset: 0; }
  .ntf-item__title .badge { grid-area: badge; justify-self: start; height: 24px; font: 500 12px/20px var(--font-family); }
  .ntf-item__body { grid-area: body; margin: 0; font: 400 13px/22px var(--font-family); }
  .ntf-item__meta { grid-area: meta; margin: 0; justify-self: start; align-self: start; font: var(--text-small); max-width: 96px; }
}

/* ---------- Partner portal (508:4053, 508:4263, 509:4356, 509:4566) ---------- */
@media (max-width: 767px) {
  .pcontent { padding-top: 16px; }
  .ptl .ptl-head > div:first-child { display: none; }
  .ptl .ptl-head { margin: 0 0 12px; }
  .ptl .ptl-head:not(:has(.page-header__actions)), .ptl:has(.ptl-mhead) .ptl-head, .ptl:has(.ptl-tabs) .ptl-head, .ptl:has(.ptl-form) .ptl-head { display: none; }
  .ptl-foot { display: none; }
  .ptl-mhead h1 { font: 700 20px/32px var(--font-family); margin: 0; }
  .ptl-mhead p { margin: 8px 0 20px; font: var(--text-body); color: var(--color-text-secondary); }

  /* dashboard: compact tier card + KPI carousel */
  .ptl:has(.ptl-mtier) .ptl-tier, .ptl:has(.ptl-mtier) > section.ptl-card { display: none; }
  .ptl-mtier { padding: 20px 16px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 16px; }
  .ptl-mtier__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .ptl-mtier__top h2 { font: 700 18px/28px var(--font-family); margin: 0; }
  .ptl-mtier__top .badge { height: 28px; padding: 0 10px; font: var(--text-body); }
  .ptl-mtier__mw { display: flex; align-items: baseline; gap: 8px; }
  .ptl-mtier__mw b { font: 800 30px/40px var(--font-family); }
  .ptl-mtier__mw span { font: var(--text-body); color: var(--color-text-secondary); }
  .ptl-mtier__next { display: flex; justify-content: space-between; align-items: baseline; }
  .ptl-mtier__next b { font: 700 16px/24px var(--font-family); }
  .ptl-mtier__next span { font: var(--text-small); color: var(--color-text-secondary); }
  .ptl-mtier__bar { height: 8px; border-radius: 4px; background: var(--color-gray-200); overflow: hidden; margin-top: -8px; }
  .ptl-mtier__bar i { display: block; height: 100%; border-radius: 4px; background: var(--color-brand-navy); }
  .ptl-mtier__tip { display: flex; gap: 10px; margin: 0; padding: 12px; border-radius: var(--radius-md); background: var(--color-brand-amber-50); font: var(--text-body); }
  .ptl-mtier__tip .icon { width: 22px; height: 22px; flex: none; color: var(--color-brand-amber); }
  .ptl-kpis[data-mcarousel] { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; margin-block-end: 8px; scrollbar-width: none; padding-bottom: 2px; }
  .ptl-kpis[data-mcarousel] > .ptl-kpi { flex: 0 0 calc(100% - 128px); min-width: 230px; scroll-snap-align: start; min-height: 172px; }
  .mdots { display: flex; justify-content: center; gap: 6px; margin: 4px 0 20px; }
  .mdots i { width: 6px; height: 6px; border-radius: 3px; background: var(--color-gray-300); transition: width .15s; }
  .mdots i.is-on { width: 16px; background: var(--color-brand-amber); }
  .ptl-card__head { flex-wrap: wrap; }

  /* new lead form */
  .ptl-newlead { grid-template-columns: minmax(0, 1fr); }
  .ptl-tips, .ptl-form__title, .ptl-form__actions .btn-secondary { display: none; }
  .ptl-form.card { background: none; border: 0; box-shadow: none; padding: 0; }
  .ptl-form__grid { grid-template-columns: minmax(0, 1fr); row-gap: 20px; }
  .ptl-form__grid > div:empty { display: none; }
  .ptl-minfo { margin: 0 0 20px; padding: 16px; border-radius: var(--radius-lg); }
  .ptl-minfo .alert__title { font: 500 15px/28px var(--font-family); }
  .ptl-form__actions .btn-primary { width: 100%; height: 48px; font: 600 16px/24px var(--font-family); }
  .ptl-form__actions .btn-primary .icon { display: none; }

  /* leads list */
  .ptl-tabs { display: none; }
  .ptl-toolbar { gap: 12px 8px; margin-block-end: 16px; }
  .ptl-search { width: 100%; }
  .ptl-search .input { height: 44px; padding-inline-start: 44px; }
  .ptl-search .icon { top: 12px; inset-inline-start: 14px; width: 22px; height: 22px; }
  .ptl-fchip { height: 36px; padding: 0 14px; font: var(--text-body); }
  .ptl-addfilter { display: none; }
  .ptl-card--table:has(> .mlist) > .table-footer { border: 0; }

  /* commissions */
  .ptl:has(.ptl-mstats) .ptl-kpis, .ptl:has(.ptl-mstats) > section.ptl-card { display: none; }
  .ptl-mstats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
  .ptl-mstat { display: flex; flex-direction: column; gap: 4px; padding: 14px 10px; min-width: 0; background: var(--color-surface-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
  .ptl-mstat span { font: var(--text-small); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ptl-mstat b { font: 800 20px/32px var(--font-family); color: var(--color-text-brand); }
  .ptl-mstat small { font: var(--text-small); color: var(--color-text-primary); }
  .ptl-mstat--pending b { color: var(--color-warning); }
  .ptl-mstat--paid b { color: var(--color-success); }
}

/* ---------- Other pages (no mobile frame): collapse desktop grids so nothing overflows at 390px ---------- */
@media (max-width: 767px) {
  .row { flex-wrap: wrap; }
  .pl-page .p360__actions { flex-wrap: wrap; flex: 1 1 auto; }
  .dl-cc__row { flex-wrap: wrap; }
  .pt-tier__next { min-width: 0; }
  .msgr-test__row { flex-direction: column; }
  .msgr-test__field { width: 100%; }
  .qe-bar { margin: 24px calc(-1 * var(--m-gutter)) -24px; padding: 12px var(--m-gutter); flex-wrap: wrap; }
  .db-kpis, .db-kpis--4, .pt-kpis, .pr-kpis, .ct-kpis-row, .dl-lic .dl-kpis, .ld .ld-stats, .org-kpis, .pp .kpi-row, .pl-page .kpi-row, .rp-kpis,
  .pr-meta, .pl-page .fgrid, .pl-page .fgrid--3, .qe-fields, .dl-page .dl-photos, .pp .check-grid, .sd-page .sd-review-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
  }
  .db-grid, .ntf-bots, .nset .nset-bots, .pt-new__grid, .pr-grid, .pr-params, .dl-page .dl-grid, .ld .ld-kv, .ld .ld-modal--convert .modal__body,
  .org-create__body.has-dupes, .org-layout, .org-kv, .org-merge__cards, .ptl-agree, .pp .p360-grid, .pp .kv-grid, .pp .merge__pair, .pl-page .p360-grid,
  .pl-page .kv2, .pl-page .form-grid--3, .pl-page .form-grid--4, .pl-page .risks__row--edit, .pc-grid, .qe-grid, .apq-grid, .rp-grid, .rr-grid, .rr-grid--3,
  .sds-page .sds-fields, .wf-fields, .opp-grid, .today__grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .opp-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 12px; }
  .pl-page .capbox { grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .dl-page .dl-stepper, .ld .ld-import .stepper, .pp .stepper { overflow-x: auto; grid-auto-columns: minmax(96px, 1fr); }
  .wh-day { grid-template-columns: auto 1fr; grid-template-areas: "name switch" "times times" "err err"; row-gap: 8px; }
  .pt-tiered__head, .pt-tiered__row { grid-template-columns: 72px 1fr 1fr 1fr 36px; gap: 6px; }
  /* hero / side columns that had fixed widths */
  .qe-side, .apq-panel, .pt-hero__side, .opp-hero__side, .dl-hero__side, .org-side, .p360-side, .ld-side, .opp-side { width: auto; max-width: 100%; position: static; }
  .opp-hero, .pt-hero, .dl-hero, .org-hero, .p360-hero, .pl-hero, .ct-hero { flex-wrap: wrap; flex-direction: column; align-items: stretch; }
  .dl-hero__actions, .pt-hero__actions, .opp-hero__actions, .org-toolbar__end, .org-toolbar, .ct-hero__actions, .qe-actions { flex-wrap: wrap; }
  [class*="kpi"] { min-width: 0; }
  [class*="kpi__sub"], [class*="kpi-sub"] { white-space: normal; }
}
