/* ==========================================================================
   [mobile v1] لایه‌ی موبایل — تاریخ‌نگاری علوی
   - آخرِ <head> همه‌ی صفحه‌ها بار می‌شود (بعد از style.css، theme.css و <style>های خود صفحه).
   - فقط «اضافه» می‌کند؛ در دسکتاپ (پهنای بیشتر از ۷۶۰) تقریباً هیچ اثری ندارد، به‌جز رفع باگ «فیلد مخفی ثبت‌نام».
   - همراهش mobile.js: برچسب ستون‌ها برای جدول‌های کارتی، کشوی گفتگوها، فیلترِ جمع‌شونده، فهرست بخش‌های پنل.
   ========================================================================== */

/* ---------- رفع باگ (همه‌ی اندازه‌ها): فیلد تله‌ی ضدربات در ثبت‌نام صفحه را ۱۰ هزار پیکسل عریض می‌کرد ---------- */
.sf-trap {
  position: absolute !important; left: auto !important; right: 0 !important; top: 0 !important;
  width: 1px !important; height: 1px !important; overflow: hidden !important;
  clip-path: inset(50%) !important; white-space: nowrap !important; opacity: 0 !important; pointer-events: none;
}
.sf-root { position: relative; }

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

/* عناصر ساخته‌شده توسط mobile.js در دسکتاپ پنهان‌اند */
.m-only { display: none !important; }

/* ==========================================================================
   تبلت و موبایل (≤ ۷۶۰)
   ========================================================================== */
@media (max-width: 760px) {
  html, body { overflow-x: clip; }
  .m-only { display: revert !important; }
  button.m-only, a.m-only { display: inline-flex !important; }
  body { -webkit-tap-highlight-color: rgba(139, 111, 71, .15); }

  /* ---------- قاب صفحه ---------- */
  .page-wrap { padding: 8px 10px calc(24px + env(safe-area-inset-bottom)); }
  .admin-page .page-wrap { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }

  /* ---------- هدر: یک ردیف جمع‌وجور ---------- */
  .app-header-sticky { padding-top: 6px; padding-bottom: 10px; }
  .app-header {
    flex-wrap: nowrap !important; gap: 4px !important; padding: 5px 6px 5px 8px !important;
    border-radius: 12px !important; min-height: 50px;
  }
  .app-header .brand {
    width: auto !important; border: none !important; padding: 0 4px 0 6px !important; margin: 0 !important;
    font-size: 14px !important; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  }
  .header-nav {
    width: auto !important; flex: 1 1 auto !important; min-width: 0; flex-wrap: nowrap !important;
    justify-content: flex-start !important; gap: 2px !important;
  }
  .header-nav a {
    flex: 0 0 auto !important; width: 40px; height: 40px; padding: 0 !important;
    justify-content: center !important; border-radius: 10px !important;
  }
  .header-nav a span.nav-text { display: none !important; }
  .header-nav a .nav-icon { font-size: 17px !important; }
  .app-header .theme-switch { flex: 0 0 auto; }
  .theme-toggle { width: 40px !important; height: 40px !important; }
  .user-menu { width: auto !important; flex: 0 0 auto; }
  .user-menu-btn {
    width: 40px !important; height: 40px; padding: 0 !important; justify-content: center !important;
    border-radius: 50% !important; gap: 0 !important;
  }
  .user-menu-btn > span:not(.user-avatar) { display: none; }
  .user-menu-btn .user-avatar,
  .user-menu-btn .user-avatar.has-photo { width: 30px !important; height: 30px !important; font-size: 14px !important; }
  .user-menu-dropdown {
    left: 0 !important; right: auto !important; width: auto !important; min-width: 190px;
    border-radius: 12px !important;
  }
  .user-menu-dropdown::before {
    content: attr(data-m-user); display: block; padding: 10px 14px 8px; font-size: 12px;
    color: var(--ink-soft); border-bottom: 1px solid var(--line-soft); overflow-wrap: anywhere;
  }
  .user-menu-dropdown:not([data-m-user])::before { display: none; }
  .user-menu-dropdown a { padding: 13px 14px !important; font-size: 14px !important; }
  .theme-menu { right: auto !important; left: 0 !important; }
  .theme-menu button { padding: 12px 14px; font-size: 14px; }
  .maint-banner { border-radius: 10px; font-size: 12px; }

  /* هدرِ پر (ادمین: ۵ آیکن) در گوشی‌های باریک: نام سایت جا نمی‌شود */
  .app-header:has(.header-nav a:nth-child(4)) .brand { display: none; }

  /* ---------- فیلدها: ۱۶ پیکسل تا آیفون با لمس، صفحه را زوم نکند ---------- */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
  select, textarea { font-size: 16px !important; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }

  /* ---------- دکمه‌ها: اندازه‌ی انگشت ---------- */
  .btn-mini { min-height: 36px; padding: 6px 12px; font-size: 12.5px; }
  .btn-ghost, .btn-solid, .avatar-btn, .da-btn, .sf-btn { min-height: 40px; }
  .btn-primary { min-height: 44px; }
  .tab-btn { min-height: 42px; }
  .ua-modal-close, .cv-close, .cite-quick-close {
    min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center;
  }
  .toolbar-check { min-height: 40px; }

  /* ---------- تب‌ها: یک ردیفِ قابل‌کشیدن ---------- */
  .tab-bar, .prompt-tab-bar {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-btn { flex: 0 0 auto; white-space: nowrap; padding: 8px 14px; }

  /* ---------- نوار ابزار ---------- */
  .toolbar { gap: 8px; }
  .toolbar-search { flex: 1 1 100% !important; min-width: 0 !important; max-width: none !important; height: 42px !important; }
  .toolbar-select { flex: 1 1 calc(50% - 4px) !important; min-width: 0 !important; height: 42px !important; }
  #usersBox .toolbar { flex-wrap: wrap !important; }
  #usersBox .toolbar > .toolbar-search:not(:first-child) { flex: 1 1 calc(50% - 4px) !important; max-width: none !important; }
  .pager { flex-wrap: wrap; gap: 8px; }

  /* ---------- پنجره‌ها: برگه‌ی پایین‌صفحه (bottom sheet) ---------- */
  .ua-modal-overlay, .entry-modal-overlay, .cv-overlay, .cite-quick {
    padding: 0 !important; align-items: flex-end !important;
  }
  .ua-modal, .ua-modal.ua-modal-wide, #uaModalOverlay .ua-modal, .ua-modal.da-modal,
  .ua-modal.ua-modal-wide:has(.sf-mosaic-top) {
    max-width: none !important; width: 100% !important; max-height: 94dvh !important;
    border-radius: 16px 16px 0 0 !important; border-bottom: none !important;
  }
  .ua-modal-header { padding: 10px 14px 10px 8px; position: relative; }
  .ua-modal-header h3 { font-size: 15px; min-width: 0; overflow-wrap: anywhere; }
  .ua-modal-body { padding: 14px 14px 18px; }
  .ua-modal-footer {
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom)) !important;
    flex-direction: column; align-items: stretch !important;
  }
  .ua-modal-footer .editor-buttons { justify-content: stretch; }
  .ua-modal-footer .editor-buttons > * { flex: 1 1 0; }
  .ua-modal-footer .editor-note { min-width: 0; }
  .entry-modal-box {
    max-width: none !important; max-height: 92dvh !important; border-radius: 16px 16px 0 0 !important;
    padding: 12px 16px calc(22px + env(safe-area-inset-bottom)) !important;
  }
  .entry-modal-close {
    position: sticky !important; top: 0 !important; float: left; z-index: 3;
    width: 38px !important; height: 38px !important; margin: 0 0 4px 0;
  }
  .cite-quick-box {
    max-width: none !important; max-height: 92dvh !important; border-radius: 16px 16px 0 0 !important;
    padding: 18px 16px calc(22px + env(safe-area-inset-bottom)) !important;
  }
  .cv-modal { height: 96dvh !important; max-width: none !important; border-radius: 16px 16px 0 0 !important; border-bottom: none !important; }
  .cv-head { padding: 10px 14px 10px 8px !important; }
  .cv-chat { padding: 12px !important; }
  .cv-msg, .cv-error { max-width: 100% !important; }
  .cv-side { max-height: 38% !important; }
  /* دستگیره‌ی کوچک بالای برگه */
  .ua-modal::before, .entry-modal-box::before, .cite-quick-box::before, .cv-modal::before {
    content: ""; display: block; width: 38px; height: 4px; border-radius: 4px; background: var(--line);
    margin: 8px auto 0; flex-shrink: 0;
  }
  .entry-modal-box::before { margin: 0 auto 6px; }
  .cite-quick-box::before { margin: -8px auto 8px; }

  /* پیش‌نمایشِ ارجاع روی لمسی بی‌معنی است؛ با لمس، خودِ مدخل باز می‌شود */
  .cite-pop { max-width: calc(100vw - 16px); }

  /* ---------- جدول‌ها: هر ردیف یک کارت (برچسب ستون‌ها را mobile.js می‌گذارد) ---------- */
  table.m-cards, table.m-cards tbody { display: block !important; width: 100% !important; overflow: visible !important; white-space: normal !important; }
  table.m-cards thead, table.m-cards tr.m-head-row { display: none !important; }
  table.m-cards tr {
    display: block !important; background: var(--surface, #fff); border: 1px solid var(--line-soft, var(--line));
    border-radius: 12px; padding: 6px 12px; margin-bottom: 8px;
  }
  table.m-cards tr:hover td { background: transparent !important; }
  table.m-cards td {
    display: flex !important; gap: 10px; align-items: baseline; justify-content: space-between;
    width: auto !important; max-width: none !important; min-width: 0 !important;
    padding: 7px 0 !important; border: none !important; border-bottom: 1px solid var(--line-soft, var(--line)) !important;
    white-space: normal !important; text-align: start !important; overflow-wrap: anywhere !important; line-height: 1.7;
  }
  table.m-cards td *:not(button):not(select):not(input) { white-space: normal !important; overflow-wrap: anywhere !important; }
  table.m-cards td .badge { white-space: nowrap !important; }
  table.m-cards td:last-child { border-bottom: none !important; }
  table.m-cards td[data-label]::before {
    content: attr(data-label); flex: 0 0 34%; max-width: 34%; font-size: 11.5px; color: var(--ink-soft);
    font-weight: 600; line-height: 1.7;
  }
  table.m-cards td[data-label] > * { min-width: 0; }
  table.m-cards td[data-label=""]::before { display: none; }
  table.m-cards td.m-td-actions { justify-content: flex-start; flex-wrap: wrap; }
  table.m-cards td.m-td-actions::before { display: none; }
  table.m-cards td.m-td-actions > * { flex-wrap: wrap; gap: 6px; }
  table.m-cards td.m-td-empty { display: none !important; }
  table.m-cards td[colspan] { justify-content: center; }
  table.m-cards td[colspan]::before { display: none; }
  table.m-cards .row-actions, table.m-cards .sf-row-actions, table.m-cards .actions-cell { flex-wrap: wrap; }
  /* جدول‌های بی‌سرستون: اسکرول افقی داخل خودشان */
  table.m-scroll { display: block !important; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ---------- پنل مدیریت و مانیتورینگ ---------- */
  .admin-layout { flex-direction: column !important; gap: 14px; }
  .admin-main { width: 100%; gap: 14px; }
  .admin-title-row { flex-direction: row !important; align-items: center !important; flex-wrap: wrap; gap: 6px 10px !important; }
  .admin-title { font-size: 19px; }
  .admin-title-sub { font-size: 12px; }
  .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 6px !important; }
  .kpi-tile { padding: 9px 4px !important; border-radius: 10px !important; }
  .kpi-value { font-size: 16px !important; overflow-wrap: anywhere; }
  .kpi-label { font-size: 10.5px !important; }
  .panel { border-radius: 12px; scroll-margin-top: 72px; }
  .panel-head { border-radius: 12px 12px 0 0; padding: 11px 12px !important; flex-wrap: wrap; }
  .panel-title { font-size: 14px; min-width: 0; }
  .panel-head-actions { flex-wrap: wrap; min-width: 0; max-width: 100%; }
  .panel-head-actions > * { flex: 1 1 auto; }
  .panel-hint, .toolbar, .tab-bar, .schema-report, .engine-settings-row, .prompt-tab-bar,
  #profileMsg, #displaySettingsMsg, #engineSettingsMsg { margin-left: 12px !important; margin-right: 12px !important; }
  .panel-body, .prompt-editor-wrap { padding-left: 12px !important; padding-right: 12px !important; }
  .panel-compact .panel-body { max-height: none; }
  .engine-setting-item { min-width: 0 !important; flex: 1 1 100%; }
  .engine-setting-controls { flex-wrap: wrap; }
  .prompt-editor-textarea { min-height: 55dvh !important; font-size: 16px !important; line-height: 1.9; padding: 10px; }
  .prompt-editor-toolbar .btn-solid { flex: 1 1 100%; }
  .prompt-history-item { flex-wrap: wrap; }
  .prompt-history-meta { white-space: normal; }
  .display-settings-grid { grid-template-columns: 1fr !important; }
  .display-setting-item { min-height: 44px; }
  #infoGatePanel input#igTokens { width: 100% !important; flex: 1 1 100%; }
  #infoGatePanel .btn-solid { flex: 1 1 100%; }
  /* [registry removal v1] */ .editor-form, .da-grid { grid-template-columns: 1fr !important; }
  .review-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .review-actions { flex-wrap: wrap; justify-content: flex-start; }
  .review-actions select, .review-actions .review-level-select {
    flex: 1 1 100% !important; max-width: none !important; width: 100% !important; min-height: 42px; font-size: 16px !important;
  }
  .review-actions .btn-mini { flex: 1 1 0; min-height: 40px; }
  .review-name { white-space: normal; overflow-wrap: anywhere; }
  .schema-line code { overflow-wrap: anywhere; }

  /* ستون کناری (آنلاین‌ها، حالت به‌روزرسانی، پشتیبان) زیر صفحه */
  .side-col { width: 100% !important; position: static !important; max-height: none !important; }
  .users-sidebar, .side-col > .users-sidebar { width: 100% !important; position: static !important; max-height: none !important; border-radius: 12px; scroll-margin-top: 72px; }
  .users-scroll { max-height: 60dvh; }
  .user-mini-card { padding: 10px 12px; }
  .maint-box, .bk-box { border-radius: 12px; }
  .maint-switch { width: 46px; height: 26px; }
  .maint-knob { width: 22px; height: 22px; }
  .maint-box.on .maint-knob { right: 22px; }

  /* ویرایشگر سؤال‌های فرم ثبت‌نام */
  .sf-ed-row { flex-wrap: wrap; align-items: flex-start; gap: 8px 10px; padding: 10px; }
  .sf-ed-order { flex-direction: row; gap: 6px; }
  .sf-ed-order .btn-mini { min-width: 40px; min-height: 36px; font-size: 12px; padding: 0 8px; }
  .sf-ed-main { flex: 1 1 calc(100% - 110px); min-width: 0; }
  .sf-ed-main input, .sf-ed-label { width: 100% !important; min-width: 0 !important; max-width: 100% !important; box-sizing: border-box; }
  .sf-ed-help { max-width: 100%; white-space: normal; }
  .sf-ed-toggles { width: 100%; flex-wrap: wrap; gap: 6px 14px; }
  .sf-ed-toggles label { min-height: 36px; display: inline-flex; align-items: center; gap: 6px; }
  .sf-ed-actions { width: 100%; }
  .sf-ed-actions .btn-mini { flex: 1 1 0; }

  /* پرونده و فعالیت کاربر (کاشی‌ها) */
  .sf-dcard { min-width: calc(50% - 4px); flex-basis: calc(50% - 4px); }
  .sf-dcard-wide, .sf-mosaic-top > .sf-dcard { flex-basis: 100%; }
  .uam-tile { min-width: calc(50% - 4px); }
  .uam-value { white-space: normal; overflow-wrap: anywhere; }
  #uaModalOverlay .ua-conv-item { flex-wrap: wrap; gap: 4px 10px; }
  #uaModalOverlay .ua-conv-title { white-space: normal; flex-basis: 100%; }

  /* ---------- مانیتورینگ ---------- */
  .mon-toolbar { gap: 8px; }
  .mon-toolbar .tab-bar { margin: 0 !important; flex: 1 1 100%; }
  .mon-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 12px; }
  .mon-bar-row { grid-template-columns: minmax(0, 96px) minmax(0, 1fr) 40px !important; gap: 8px; }
  .mon-bar-row > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mon-legend { padding: 4px 12px 12px; }
  .verdict-list li { min-width: 0; }
  .verdict-list li > * { min-width: 0; overflow-wrap: anywhere; }
  .verdict-detail { display: block; margin-inline-start: 0; }
  .mon-pager { gap: 8px; }
  .mon-select { min-height: 40px; }

  /* ---------- فهرست کاربران (users_list.php) و کارت‌های قدیمی ---------- */
  .admin-container, .upload-card, .auth-card { border-radius: 12px; }
  .admin-container { padding: 18px 14px !important; max-width: 100% !important; }
  table.admin-table { white-space: normal; }

  /* ---------- پرش به بخش‌ها (فقط صفحه‌های بلند پنل؛ mobile.js می‌سازد) ---------- */
  .m-jump {
    display: flex !important; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 4px;
    -webkit-overflow-scrolling: touch; margin: 0 -2px;
  }
  .m-jump::-webkit-scrollbar { display: none; }
  .m-jump button {
    flex: 0 0 auto; font: inherit; font-size: 12.5px; padding: 0 14px; height: 36px; border-radius: 999px;
    border: 1px solid var(--line); background: var(--surface, #fff); color: var(--ink-soft); cursor: pointer; white-space: nowrap;
  }
  .m-jump button:active { background: var(--paper-raised); color: var(--ink); }
  .m-top {
    position: fixed; left: 14px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 90;
    width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
    background: var(--surface, #fff); color: var(--ink); font-size: 18px; cursor: pointer;
    box-shadow: 0 4px 14px rgba(28, 26, 23, .18); align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s, transform .2s;
  }
  .m-top.show { opacity: 1; pointer-events: auto; transform: none; }

  /* ---------- اسناد ---------- */
  .docs-search-row input, .docs-search-row button { height: 44px !important; }
  .overview-stats { justify-content: center; }
  .pagination-bar button { min-width: 40px; min-height: 40px; }
  .detail-panel { border-radius: 12px; }
  .dp-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .dp-actions button { flex: 1 1 auto; margin: 0 !important; min-height: 44px; }
  #docAdminBar .da-btn { flex: 1 1 auto; }
  .doc-meta-row .dmr-value { overflow-wrap: anywhere; }
  .dp-text { font-size: 15px; overflow-wrap: anywhere; }
  .breadcrumb { display: inline-flex; align-items: center; min-height: 40px; }

  /* ---------- ویرایش مدخل ---------- */
  .search-row input, .search-row button { min-height: 44px; }
  .result-item { padding: 12px 14px; border-radius: 10px; }
  .back-link { display: inline-flex; align-items: center; min-height: 40px; }
  .save-row {
    position: sticky; bottom: 0; z-index: 5; margin-left: -14px; margin-right: -14px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--surface, #fff);
    border-top: 1px solid var(--line-soft, var(--line));
  }
  .save-row .btn-primary { flex: 1 1 auto; width: 100% !important; }

  /* ---------- آپلود ---------- */
  .upload-card { padding: 18px 14px !important; }
  .upload-card textarea { min-height: 220px; font-size: 16px !important; }
  .upload-card .instructions code { white-space: nowrap; }

  /* ---------- فرم ثبت‌نام / اطلاعات من ---------- */
  .auth-card.sf-card, .auth-card { padding: 20px 14px !important; }
  .sf-page { padding-top: 16px !important; }
  body:has(.theme-switch-floating) .page-wrap { padding-top: 64px !important; }
  .theme-switch-floating { top: calc(10px + env(safe-area-inset-top)) !important; }
  .sf-pill { min-height: 44px; }
  .sf-check { min-height: 36px; align-items: center; }
  .sf-check input { margin-top: 0; }
  .sf-row { padding: 10px; }
  .sf-cell-year_from, .sf-cell-year_to, .sf-cell-cohort_no { flex: 1 1 calc(33% - 8px); }
  .sf-nav { position: sticky; bottom: 0; z-index: 5; background: var(--surface, #fff); margin: 8px -14px 0;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .sf-nav .sf-btn { min-height: 46px; }
  .sf-nav .sf-btn-primary { min-width: 0; flex: 1 1 auto; }

  /* ---------- گفتگو: مثل یک پیام‌رسان، تمام‌ارتفاع ---------- */
  body.fit-page:has(.chat-layout) { overflow: hidden; }
  body.fit-page:has(.chat-layout) .page-wrap {
    height: 100vh; height: 100dvh; min-height: 0; padding: 6px 8px 0; overflow: hidden;
  }
  body.fit-page:has(.chat-layout) .app-header-sticky { flex: none; position: relative; padding-bottom: 8px; }
  body.fit-page:has(.chat-layout) .maint-banner { flex: none; }
  .chat-layout { flex: 1 1 0 !important; min-height: 0; width: 100%; flex-direction: column !important; gap: 0 !important; }
  .chat-box {
    order: 1; flex: 1 1 0 !important; min-height: 0; width: 100%; display: flex !important; flex-direction: column;
    overflow: hidden; border-radius: 14px 14px 0 0 !important; border-bottom: none !important;
  }
  .chat-header.chat-header-row {
    flex: none; flex-wrap: wrap !important; gap: 8px !important; padding: 8px 10px !important; align-items: center;
  }
  .chat-header-row .chat-header-text { flex: 1 1 0 !important; min-width: 0; order: 2; }
  .chat-header-row .chat-header-text .title {
    font-size: 15px !important; margin: 0 !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .chat-header-row .chat-header-text .subtitle { display: none; }
  .chat-header-row .filters.filters-compact { display: none !important; order: 9; flex: 1 1 100% !important; }
  .chat-box.m-filters-open .chat-header-row .filters.filters-compact { display: flex !important; }
  .chat-header-row .filters-compact .filters-label { display: none; }
  .chat-header-row .filters-compact .filters-row input { height: 40px !important; border-radius: 10px !important; }
  .m-chat-btn {
    order: 1; flex: 0 0 auto; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: 10px;
    font: inherit; font-size: 13px; font-weight: 700; color: var(--ink); background: var(--paper-raised);
    border: 1px solid var(--line); cursor: pointer; position: relative;
  }
  .m-chat-btn.m-filter-btn { order: 3; font-weight: 400; color: var(--ink-soft); }
  .m-chat-btn.m-filter-btn.on { color: var(--ink); border-color: var(--sepia); }
  .m-chat-btn.m-filter-btn.has-value::after {
    content: ""; position: absolute; top: 6px; left: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--sepia);
  }
  .m-chat-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
  .chat-messages {
    flex: 1 1 0 !important; min-height: 0 !important; max-height: none !important;
    padding: 14px 12px !important; gap: 12px; overscroll-behavior: contain;
  }
  .msg { max-width: 92%; overflow-wrap: anywhere; }
  .msg.bot { max-width: 100%; font-size: 15px; line-height: 1.9; }
  .msg.user { font-size: 15px; }
  .msg table { display: block; max-width: 100%; overflow-x: auto; }
  .msg pre, .msg code { white-space: pre-wrap; overflow-wrap: anywhere; }
  .msg-actions { flex-wrap: wrap; row-gap: 2px; }
  .msg-copy-btn { min-height: 34px; padding: 4px 10px; }
  .retrieval-note { overflow-wrap: anywhere; }
  .chat-input {
    flex: none; display: grid !important; grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "q send" "mode mode"; gap: 8px !important;
    padding: 10px 10px 4px !important;
  }
  .chat-input #userInput { grid-area: q; height: 46px; border-radius: 12px !important; padding: 0 14px !important; min-width: 0; }
  .chat-input #sendBtn, .chat-input button { grid-area: send; height: 46px; min-width: 76px; padding: 0 16px !important; border-radius: 12px !important; }
  .chat-input .ask-mode-select {
    grid-area: mode; justify-self: start; height: 36px; padding: 0 10px !important; border-radius: 999px !important;
    background: var(--paper-raised); max-width: 100%;
  }
  .ask-mode-hint {
    flex: none; margin: 0 !important; padding: 0 12px calc(8px + env(safe-area-inset-bottom)) !important;
    text-align: start !important; font-size: 11px;
  }

  /* کشوی گفتگوها */
  .chat-sidebar {
    position: fixed !important; top: 0; bottom: 0; right: 0; z-index: 210; order: 0;
    width: min(86vw, 330px) !important; max-width: none; margin: 0;
    display: flex !important; flex-direction: column; border-radius: 16px 0 0 16px !important;
    border: none !important; border-left: 1px solid var(--line) !important;
    box-shadow: -8px 0 30px rgba(0, 0, 0, .18);
    transform: translateX(105%); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  body.m-drawer-open .chat-sidebar { transform: none; visibility: visible; transition: transform .22s ease; }
  .m-drawer-head {
    display: flex !important; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 14px 8px; flex: none;
  }
  .m-drawer-head b { font-size: 15px; }
  .m-drawer-close {
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper-raised);
    color: var(--ink-soft); font-size: 18px; cursor: pointer; align-items: center; justify-content: center;
  }
  .chat-sidebar .sidebar-new-btn { flex: none; margin: 0 14px 10px; width: auto; border-radius: 12px; min-height: 46px; font-size: 14.5px; }
  .chat-sidebar .sidebar-list { flex: 1 1 0; min-height: 0; max-height: none !important; overscroll-behavior: contain; border-top: 1px solid var(--line-soft); }
  .sidebar-item { padding: 6px 14px; min-height: 52px; font-size: 14px; }
  .sidebar-item .s-delete {
    width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
    font-size: 16px; padding: 0 !important; border-radius: 50%;
  }
  .m-drawer-backdrop {
    position: fixed; inset: 0; z-index: 205; background: rgba(28, 26, 23, .45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.m-drawer-open .m-drawer-backdrop { opacity: 1; pointer-events: auto; }
  :root[data-theme="dark"] .m-drawer-backdrop { background: rgba(0, 0, 0, .6); }
}

@media (max-width: 640px) {
  .docs-search-row input, .docs-search-row button { width: 100%; }
}

/* تبلت (۷۶۱ تا ۱۱۰۰): جدول‌های پهن پنل داخل خودشان اسکرول می‌شوند تا کل صفحه به چپ و راست نرود */
@media (min-width: 761px) and (max-width: 1100px) {
  .admin-main, .panel, .panel-body { min-width: 0; }
  .admin-layout > .admin-main { align-self: stretch; }
  #usersBox .toolbar { flex-wrap: wrap !important; }   /* ستونیِ ≤۹۰۰: بدون این، پهنای ستون اصلی به اندازه‌ی جدول کش می‌آمد */
  .panel-body table.data-table, .panel-body table.admin-table, #usersBox table {
    display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
}

/* هدر پنل و نوار پرش: کمتر از ۴۰۰ پیکسل */
@media (max-width: 400px) {
  .header-nav a { width: 36px; height: 38px; }
  .theme-toggle, .user-menu-btn { width: 38px !important; height: 38px !important; }
  .kpi-value { font-size: 15px !important; }
  table.m-cards td[data-label]::before { flex-basis: 38%; max-width: 38%; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-sidebar, .m-drawer-backdrop, .m-top { transition: none !important; }
}
