/* =====================================================================
   بهینه‌سازی موبایل و اندروید (سایت عمومی: کتابخانه، خواندن کتاب، حساب کاربری)
   این فایل آخرین فایل CSS است و فقط در صفحه‌های کوچک اثر می‌گذارد.
   ===================================================================== */

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { overflow-wrap: anywhere; }
.mobile-only { display: none !important; }
.btn-text { }

/* ---------------------------------------------------------------------
   ۱) صفحه‌ی اصلی کتابخانه — موبایل
   --------------------------------------------------------------------- */
@media (max-width: 640px) {
  .app-shell { flex-direction: column; min-height: 100dvh; }
  .app-main { padding-bottom: calc(66px + env(safe-area-inset-bottom)); width: 100%; }

  /* منوی کناری ← نوار پایین */
  .app-sidebar,
  .app-sidebar.is-expanded {
    position: fixed; inset: auto 0 0 0; width: 100%; height: calc(58px + env(safe-area-inset-bottom));
    margin: 0; padding: 0 6px env(safe-area-inset-bottom); flex-direction: row; align-items: stretch;
    justify-content: space-around; gap: 0; z-index: 55; overflow: visible;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, .25);
  }
  .sidebar-toggle, .sidebar-logo-img { display: none !important; }
  .sidebar-nav, .sidebar-bottom,
  .app-sidebar.is-expanded .sidebar-nav, .app-sidebar.is-expanded .sidebar-bottom {
    display: contents;
  }
  .sidebar-icon,
  .app-sidebar.is-expanded .sidebar-icon {
    flex: 1 1 0; width: auto; height: auto; min-width: 0; border-radius: 12px; margin: 5px 2px;
    flex-direction: column; gap: 2px; padding: 4px 2px; justify-content: center; align-items: center;
  }
  .sidebar-icon .ic { width: 22px; height: 22px; }
  .sidebar-label,
  .app-sidebar.is-expanded .sidebar-label {
    display: block !important; font-size: .68rem; line-height: 1.2; color: inherit; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  }

  /* نوار بالا */
  .app-topbar { padding: 8px 10px; gap: 8px; flex-wrap: nowrap; position: sticky; top: 0; z-index: 30; }
  .topbar-search { min-width: 0; padding: 4px 12px; }
  .topbar-search input { font-size: 16px; padding: 7px 0; min-width: 0; }
  .text-size-controls { display: flex; gap: 4px; flex-shrink: 0; }
  .text-size-controls button { width: 38px; height: 38px; padding: 0; border-radius: 10px; font-size: .85rem; }

  .content-toolbar { padding: 12px 0 0; gap: 8px; }
  .content-toolbar, .table-wrap, .pagination-bar, .filter-panel, .announcement { margin-inline: 10px; }
  .content-toolbar { margin-inline: 10px; }
  .content-title { font-size: 1.05rem; }
  .filter-btn { min-height: 40px; }
  .filter-panel { padding: 12px; }
  .filter-option { flex-wrap: wrap; width: 100%; }
  .filter-option select, .filter-option input[type=text] { min-height: 42px; font-size: 16px; flex: 1; min-width: 0; }
  .breadcrumb-area { min-width: 0; max-width: 100%; overflow-x: auto; white-space: nowrap; }

  /* جدول ← کارت */
  .table-wrap { overflow: visible; background: transparent; border: 0; margin-block: 10px; }
  .library-table, .library-table tbody, .library-table thead, .library-table tr, .library-table td { display: block; min-width: 0; width: auto; }
  .library-table { min-width: 0; width: 100%; }
  .library-table thead tr { display: flex; gap: 6px; padding: 0 0 8px; }
  .library-table thead th,
  .library-table thead .col-author, .library-table thead .col-count, .library-table thead .col-name {
    display: block; flex: 1 1 0; text-align: center; padding: 9px 4px; border: 1px solid var(--color-border);
    border-radius: 10px; background: var(--color-surface); font-size: .82rem; min-height: 40px;
  }
  .library-table thead th.sorted { background: var(--color-primary-soft); }
  .library-table thead .col-actions { display: none; }

  .library-table tbody tr {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 14px;
    margin-bottom: 8px; overflow: hidden; box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,.05));
  }
  .library-table tbody td { border: 0 !important; }
  tr.row-book { display: grid !important; grid-template-columns: 1fr auto; grid-template-areas: "name name" "author count" "actions actions"; padding: 4px 4px 12px; }
  tr.row-book .col-name { grid-area: name; }
  tr.row-book .col-author { grid-area: author; display: block !important; padding: 0 14px; align-self: center; font-size: .82rem; }
  tr.row-book .col-author:empty { display: none !important; }
  tr.row-book .col-count { grid-area: count; padding: 0 14px; align-self: center; }
  tr.row-book .col-actions { grid-area: actions; padding: 10px 12px 0; }
  .row-actions-inline { justify-content: stretch; gap: 8px; }
  .row-actions-inline .jump-page-input { flex: 1; width: auto; min-width: 0; height: 44px; font-size: 16px; border-radius: 10px; }
  .download-pdf-link { width: 48px; height: 44px; border-radius: 10px; }
  .download-pdf-link .ic { width: 22px; height: 22px; }

  tr.row-category { display: grid !important; grid-template-columns: 1fr auto; align-items: center; min-height: 54px; padding-inline-end: 12px; }
  tr.row-category .col-author, tr.row-category .col-actions { display: none !important; }
  tr.row-category .row-inner { min-height: 54px; }

  tr.row-section, tr.row-section-hit, tr.row-section-head, tr.row-skeleton, tr.row-loading { border-radius: 10px !important; }
  tr.row-section-head { background: transparent !important; border: 0 !important; box-shadow: none !important; margin-bottom: 0 !important; }
  tr.row-section .section-row-link { padding: 12px 14px; min-height: 46px; }
  .sections-toggle { min-height: 34px; padding: 4px 12px; font-size: .82rem; }
  .row-label-wrap { min-width: 0; }
  .row-label { overflow-wrap: anywhere; }

  .pagination-bar { flex-direction: column; gap: 10px; align-items: stretch; }
  .page-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .page-num-btn, .page-nav-btn { min-width: 40px; min-height: 40px; }

  /* پیش‌نمایش (کشوی پایین) */
  .preview-pane { height: 90dvh; z-index: 80; }
  .preview-inner { min-width: 0; padding: 18px 14px calc(24px + env(safe-area-inset-bottom)); gap: 14px; }
  .preview-body .btn-primary, .preview-body .btn-secondary, .preview-body a.btn-primary, .preview-body a.btn-secondary { min-height: 46px; width: 100%; justify-content: center; text-align: center; }
  .preview-body input { font-size: 16px; }
  .lock-toast { bottom: calc(76px + env(safe-area-inset-bottom)); width: calc(100% - 24px); max-width: 420px; text-align: center; }
}

/* ---------------------------------------------------------------------
   ۲) نمایشگر کتاب — گوشی و تبلت کوچک
   --------------------------------------------------------------------- */
@media (max-width: 860px) {
  .mobile-only { display: inline-flex !important; }
  .viewer-body, .viewer-shell, .viewer-reading-area { height: 100vh; height: 100dvh; }

  .viewer-header { padding: 6px 8px; gap: 6px; }
  .viewer-header .back-link { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.14); flex-shrink: 0; }
  .viewer-header .back-link .btn-text { display: none; }
  .viewer-title { font-size: .92rem; text-align: right; min-width: 0; }
  .viewer-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
  .viewer-header-actions .btn-text, #memberSlotTop { display: none !important; }
  .viewer-header-actions .theme-btn, .viewer-header-actions #copyLinkBtn { width: 38px; height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; }
  .viewer-header-actions .info-panel-toggle { display: inline-flex; align-items: center; gap: 5px; min-height: 38px; padding: 0 12px; border-radius: 10px; font-size: .82rem; white-space: nowrap; }
  .viewer-header-actions .info-panel-toggle .ic { width: 16px; height: 16px; }

  .viewer-main { padding: 6px; }

  /* نوار پایین: شماره‌ی صفحه و دکمه‌ها در یک ردیف */
  .viewer-controls { flex-wrap: wrap; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .viewer-controls button { min-height: 42px; padding: 0 14px; }
  .page-input-group input { width: 62px; height: 42px; font-size: 16px; padding: 0 4px; }
  .part-switch button { min-height: 40px !important; padding: 0 10px !important; font-size: .8rem; }
  #partSwitch[hidden] { display: none !important; }

  /* پنل اطلاعات ← کشوی پایین */
  .viewer-shell { flex-direction: column; }
  .viewer-info-panel {
    position: fixed; inset: auto 0 0 0; width: 100%; height: auto; max-height: 78dvh; z-index: 70;
    border: 0; border-radius: 20px 20px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
    box-shadow: 0 -14px 44px rgba(0, 0, 0, .4); overflow-y: auto; overscroll-behavior: contain; display: none;
  }
  .viewer-info-panel.open { display: block; animation: sheet-up .3s ease both; }
  .viewer-info-panel::before { content: ""; display: block; width: 44px; height: 5px; border-radius: 5px; background: var(--color-border); margin: -6px auto 14px; }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  .sheet-actions { display: flex !important; gap: 8px; margin-bottom: 14px; }
  .sheet-actions .btn-secondary { flex: 1; min-height: 44px; justify-content: center; text-align: center; display: inline-flex; align-items: center; gap: 6px; }
  .view-tools-row { gap: 10px; }
  .view-tools button { min-height: 42px; min-width: 44px; }
  .viewer-info-panel .btn-primary, .viewer-info-panel .btn-secondary { min-height: 46px; display: flex !important; align-items: center; justify-content: center; }
  .viewer-info-panel input, .viewer-info-panel select, .viewer-info-panel textarea { font-size: 16px; }
  .sections-list { max-height: 34dvh; }
  .section-link { min-height: 44px; }
  .copy-toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ---------------------------------------------------------------------
   ۳) حساب کاربری و صفحه‌ی ۴۰۴
   --------------------------------------------------------------------- */
@media (max-width: 480px) {
  .account-body { padding: 12px 10px calc(20px + env(safe-area-inset-bottom)); }
  .account-box { padding: 18px 14px; border-radius: 14px; }
  .acc-form input { font-size: 16px; min-height: 46px; }
  .acc-form button, .tabs .tab { min-height: 46px; }
  .account-box .back-library { min-height: 46px; }
}

/* نمایشگر کتاب: زوم فقط با کد خودِ نمایشگر انجام می‌شود، نه زوم مرورگر */
.viewer-body { touch-action: pan-x pan-y; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
.viewer-body .viewer-info-panel, .viewer-body input, .viewer-body textarea { -webkit-user-select: text; user-select: text; }
.viewer-main { touch-action: pan-x pan-y; overscroll-behavior: contain; }
.viewer-info-panel [hidden], .preview-body [hidden], body [hidden] { display: none !important; }
