/**
 * FitRoniX — قالب موبایل · پنل کاربری + مدیریت
 * breakpoint اصلی: 768px · فشرده: 480px · خیلی کوچک: 400px
 */

:root {
  --panel-bn-h: 64px;
  --panel-header-m: 56px;
  --panel-safe-b: env(safe-area-inset-bottom, 0px);
  --panel-safe-t: env(safe-area-inset-top, 0px);
}

/* ─── Bottom nav · مشترک ─── */
.ap-bottom-nav,
.up-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + var(--panel-safe-b));
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.ap-bottom-nav {
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
}

.up-bottom-nav {
  background: var(--up-surface, var(--bg-elevated));
  box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
}

.ap-bottom-nav button,
.up-bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  padding: 6px 4px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: 12px;
  transition: color 0.15s ease, background 0.15s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.ap-bottom-nav button .ico,
.up-bottom-nav button .ico {
  font-size: 18px;
  line-height: 1;
}

.ap-bottom-nav button.on,
.up-bottom-nav button.on {
  color: var(--accent);
  background: var(--accent-subtle, rgba(249, 115, 22, 0.1));
}

.ap-bottom-nav button:active,
.up-bottom-nav button:active {
  transform: scale(0.96);
}

.ap-bottom-nav button.ap-bn-menu.on {
  color: var(--text);
  background: var(--bg-hover);
}

.up-bottom-nav button.up-bn-menu.on {
  color: var(--text);
  background: var(--bg-hover);
}

.up-bottom-nav button.up-bn-live {
  color: #fff;
  background: linear-gradient(135deg, #f97316, #ea580c);
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.35);
}

.ap-bottom-nav button.ap-bn-urgent .ico {
  position: relative;
}

.ap-bottom-nav button.ap-bn-urgent.has-badge::after {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid var(--bg-elevated);
}

/* ─── موبایل · layout عمومی ─── */
@media (max-width: 768px) {
  html,
  body {
    overflow-x: hidden;
  }

  body.panel-sidebar-open {
    overflow: hidden;
    touch-action: none;
  }

  body.panel-sidebar-open .main {
    overflow: hidden;
  }

  .shell .main {
    width: 100% !important;
    margin-right: 0 !important;
    margin-left: 0 !important;
  }

  .sidebar {
    z-index: 101;
  }

  .sidebar.open {
    box-shadow: -16px 0 48px rgba(0, 0, 0, 0.45);
  }

  .menu-btn {
    display: flex !important;
    flex-shrink: 0;
    z-index: 2;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 12px;
  }

  /* ─── Header موبایل ─── */
  .admin-app .ap-header,
  .shell-user .up-header {
    position: sticky;
    top: 0;
    z-index: 80;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    padding-top: calc(8px + var(--panel-safe-t));
    min-height: var(--panel-header-m);
    background: color-mix(in srgb, var(--header-bg, var(--bg)) 88%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
  }

  .admin-app .ap-header h1,
  .shell-user .up-header-titles h1 {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .admin-app .ap-header .desc,
  .shell-user .up-header-titles .desc {
    display: none;
  }

  .admin-app .ap-header-site-nav,
  .shell-user .up-header-site-nav {
    display: none;
  }

  .admin-app .ap-header .search-inline {
    display: none;
  }

  .admin-app .ap-header .adm-cmd-search-trigger {
    display: inline-flex;
  }

  .shell-user .up-header .header-spacer {
    display: none;
  }

  .shell-user .up-header .up-live-btn {
    flex-shrink: 0;
    font-size: 11px;
    padding: 6px 10px;
    min-height: 36px;
  }

  .shell-user .up-header .up-live-long {
    display: none;
  }

  .shell-user .up-header .up-live-short {
    display: inline;
  }

  /* ─── Content padding · فضا برای bottom nav ─── */
  .admin-app .shell .content {
    padding: 12px 10px calc(var(--panel-bn-h) + 16px + var(--panel-safe-b)) 12px;
  }

  .shell-user .content {
    padding: 10px 0 calc(var(--panel-bn-h) + 20px + var(--panel-safe-b));
  }

  html[data-user-panel-theme="fitronix"] .shell-user .content {
    padding: 12px 0 calc(var(--panel-bn-h) + 20px + var(--panel-safe-b));
  }

  /* ─── Bottom nav نمایش ─── */
  .ap-bottom-nav,
  .up-bottom-nav {
    display: grid;
  }

  /* ─── Buddy · بالای ناو ─── */
  .admin-app .buddy--admin {
    bottom: calc(var(--panel-bn-h) + 12px + var(--panel-safe-b));
    left: 16px;
  }

  .user-app .buddy {
    bottom: calc(var(--panel-bn-h) + 12px + var(--panel-safe-b));
    left: calc(12px + env(safe-area-inset-left, 0px));
  }

  /* ─── Grid و متریک ─── */
  .row-5 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .row-4,
  .row-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dash-priority {
    grid-template-columns: 1fr;
  }

  .dash-feature-widgets {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .dash-fin-unified-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .dash-fin-total-wrap {
    text-align: right;
  }

  /* ─── Tab bar · اسکرول افقی ─── */
  .tab-bar,
  .filter-bar,
  .admin-filter-bar,
  .orders-filter-bar,
  .shop-filter-bar,
  .spec-filter-bar,
  .ai-filter-bar,
  .settings-tabs .settings-tab-bar {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 4px;
  }

  .tab-bar::-webkit-scrollbar,
  .filter-bar::-webkit-scrollbar,
  .admin-filter-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-bar .tab,
  .filter-bar .filter-chip,
  .admin-filter-bar .filter-chip,
  .orders-filter-bar .filter-chip,
  .settings-tabs .settings-tab-bar .tab {
    flex-shrink: 0;
    white-space: nowrap;
    min-height: 36px;
  }

  /* ─── Pin bar ─── */
  .pin-bar,
  .pin-bar--admin {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    max-width: 100%;
    padding-bottom: 6px;
  }

  .pin-bar .lbl,
  .pin-bar .pin-bar-hint,
  .pin-bar--admin .lbl,
  .pin-bar--admin .pin-bar-hint,
  .pin-bar label,
  .pin-bar--admin .pin-bar-group {
    flex-shrink: 0;
  }

  #view-dashboard .dash-quick,
  .dash-quick {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    max-width: 100%;
  }

  #view-dashboard .dash-quick .btn,
  .dash-quick .btn,
  .dash-quick-lbl {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* ─── کارت و بنر ─── */
  .action-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .action-row .btn {
    min-height: 40px;
  }

  .card-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  .banner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .banner .actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .banner .actions .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
    min-height: 40px;
  }

  .banner .banner-text {
    min-width: 0;
  }

  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .page-toolbar .search-inline {
    max-width: none;
    width: 100%;
  }

  .split,
  .split-wide {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* ─── نمودار ─── */
  .chart-box {
    min-height: 150px;
  }

  .chart-box.sm {
    min-height: 110px;
  }

  /* ─── جدول · اسکرول + hint ─── */
  .tbl-wrap {
    position: relative;
    margin: 0 -4px;
    padding: 0 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tbl-wrap::after {
    content: '';
    position: sticky;
    left: 0;
    display: block;
    width: 24px;
    height: 1px;
    pointer-events: none;
  }

  table.tbl {
    min-width: 520px;
  }

  table.tbl .btn-sm {
    min-height: 34px;
  }

  /* ─── فرم ─── */
  .form-grid.cols-2,
  .form-grid.cols-3,
  .form-grid.cols-4 {
    grid-template-columns: 1fr !important;
  }

  .field input,
  .field select,
  .field textarea,
  .search-inline input {
    min-height: 42px;
    font-size: 16px;
  }

  /* ─── مودال · تمام‌صفحه ─── */
  .ex-modal,
  .login-success-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .ex-modal-box,
  .login-success-box {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    margin: 0;
  }

  .live-overlay {
    padding: calc(12px + var(--panel-safe-t, 0px)) 10px max(10px, var(--panel-safe-b, 0px));
    box-sizing: border-box;
  }
  .live-body {
    width: 100%;
    max-width: 420px;
    padding-bottom: 12px;
    justify-content: center;
  }
  .live-overlay.on:has(#live-music:not([hidden])) .live-body {
    padding-bottom: clamp(190px, 38vh, 290px);
  }
  .live-close { top: calc(10px + var(--panel-safe-t, 0px)); right: 10px; padding: 8px 12px; }
  .live-close-label { display: none; }
  .live-music-panel {
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(calc(100vw - 20px), 340px);
    max-width: none;
    padding: 10px 12px 8px;
    gap: 6px;
    border-radius: 16px;
  }
  .live-music-panel.is-collapsed {
    width: min(calc(100vw - 28px), 320px);
  }
  .live-music-head-title { font-size: 10px; }
  .live-music-title { font-size: 12px; }
  .live-music-eq-wrap { height: 44px; }
  .live-music-eq { height: 44px; }
  .live-music-controls { gap: 8px; }
  .live-music-ctl {
    width: 38px; height: 38px; font-size: 13px;
    touch-action: manipulation;
  }
  .live-music-ctl--play { width: 46px; height: 46px; font-size: 15px; }
  .live-music-list { max-height: min(112px, 26vh); }
  .live-music-track { padding: 7px 9px; font-size: 11px; }
  .live-hud { padding-bottom: calc(16px + var(--panel-safe-b, 0px)); }
  .live-timer-wrap { width: 132px; height: 132px; margin-bottom: 1rem; }
  .live-action { width: 88px; height: 88px; }
  .live-action-inner { font-size: 15px; }

  /* ─── پشتیبانی ─── */
  .support-layout {
    grid-template-columns: 1fr !important;
  }

  .dash-zone-foot {
    flex-wrap: wrap;
    gap: 4px;
  }

  .dash-zone-foot button {
    min-height: 36px;
  }

  /* ─── داشبورد ادمین · موبایل ─── */
  #view-dashboard .admin-dash {
    gap: 12px;
    min-width: 0;
    overflow-x: hidden;
  }

  .ap-dash-greet-inner {
    padding: 0;
  }

  .ap-dash-greet-body {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    text-align: right;
    gap: 16px 20px;
    padding: 16px 14px 14px;
  }

  .ap-dash-greet-main {
    flex: 1 1 0;
    width: auto;
  }

  .ap-dash-greet-info-frame {
    padding: 18px 16px 16px;
  }

  .ap-dash-greet-info-head {
    flex-wrap: wrap;
  }

  .ap-dash-greet-datetime {
    font-size: 13px;
  }

  .ap-dash-greet-edit {
    margin-inline-start: auto;
  }

  .ap-dash-greet-avatar {
    width: 176px;
    height: 176px;
  }

  .ap-dash-greet-title {
    font-size: 1.25rem;
  }

  .ap-dash-greet-foot {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 14px 12px;
    gap: 8px;
  }

  .ap-dash-today-wrap {
    flex: 1 1 100%;
    align-self: stretch;
    width: 100%;
    max-width: none;
  }

  .ap-dash-today {
    max-width: none;
  }

  .ap-dash-greet-health {
    justify-content: center;
  }

  .ap-greet-chip {
    font-size: 10px;
    padding: 4px 9px;
  }

  .pin-bar--admin {
    flex-direction: row;
    align-items: center;
    padding: 10px 12px;
    gap: 8px;
  }

  .pin-bar--admin .pin-bar-group {
    border: none;
    padding: 0;
    gap: 6px;
  }

  .pin-bar--admin .pin-bar-group-lbl {
    display: none;
  }

  .pin-bar--admin label {
    font-size: 10px;
    white-space: nowrap;
  }

  /* ─── داشبورد کاربر · موبایل ─── */
  .up-dash-greet h2 {
    font-size: 16px;
  }

  .up-stat-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .up-macro-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .up-connect-hub,
  .up-connect-hub--mini {
    grid-template-columns: 1fr;
  }

  .up-programs-row {
    grid-template-columns: 1fr;
  }

  .up-quick-suite-hero {
    grid-template-columns: 1fr;
  }

  .up-quick-suite-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .shell-user .dash-zones {
    grid-template-columns: 1fr;
  }

  .shell-user .dash-zone-body {
    grid-template-columns: 1fr;
  }

  .up-coach-chart,
  .up-macro-chart {
    height: 88px;
    min-height: 88px;
    max-height: 88px;
  }

  .dash-sort-block:hover {
    transform: none;
  }

  /* ─── جستجوی شناور ادمین ─── */
  .ap-mobile-search-fab {
    display: flex;
    position: fixed;
    bottom: calc(var(--panel-bn-h) + 16px + var(--panel-safe-b));
    left: 16px;
    z-index: 85;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 18px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease, background 0.15s ease;
  }

  .ap-mobile-search-fab:active {
    transform: scale(0.94);
  }

  .ap-mobile-search-sheet {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    padding: calc(12px + var(--panel-safe-t)) 12px 12px;
    align-items: flex-start;
    justify-content: center;
  }

  .ap-mobile-search-sheet.open {
    display: flex;
  }

  .ap-mobile-search-sheet-inner {
    width: 100%;
    max-width: 480px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  }

  .ap-mobile-search-sheet input {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
  }

  .ap-mobile-search-sheet-hint {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-tertiary);
  }
}

/* ─── 480px · فشرده ─── */
@media (max-width: 480px) {
  .row-5,
  .row-4,
  .row-3,
  .row-2 {
    grid-template-columns: 1fr;
  }

  .dash-feature-widgets {
    grid-template-columns: 1fr !important;
  }

  .pin-bar--admin .pin-bar-hint,
  .shell-user .pin-bar .pin-bar-hint {
    display: none;
  }

  .header h1,
  .shell-user .up-header-titles h1,
  .admin-app .ap-header h1 {
    font-size: 14px !important;
  }

  .metric .val {
    font-size: 1.1rem;
  }

  .dash-priority-item {
    padding: 10px 12px;
  }

  .btn-sm {
    min-height: 36px;
    padding: 6px 10px;
  }

  .card {
    padding: 14px;
  }

  .card-head h3 {
    font-size: 14px;
  }

  #view-dashboard .dash-fin-breakdown {
    grid-template-columns: 1fr;
  }

  .pin-bar--admin label {
    font-size: 9px;
    padding: 3px 6px;
  }

  .up-stat-board {
    grid-template-columns: 1fr 1fr;
  }

  .up-quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .up-progress-grid {
    grid-template-columns: 1fr;
  }

  .up-profile-grid {
    grid-template-columns: 1fr;
  }

  .plan-order-steps {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .plan-order-pick-grid,
  .plan-order-summary-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── 400px · خیلی کوچک ─── */
@media (max-width: 400px) {
  .ap-bottom-nav button,
  .up-bottom-nav button {
    font-size: 9px;
    padding: 5px 2px;
    min-height: 44px;
  }

  .ap-bottom-nav button .ico,
  .up-bottom-nav button .ico {
    font-size: 16px;
  }

  .up-stat-board {
    grid-template-columns: 1fr;
  }

  .menu-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }
}

/* ─── دسکتاپ · مخفی کردن المان‌های موبایل ─── */
@media (min-width: 769px) {
  .ap-mobile-search-fab,
  .ap-mobile-search-sheet {
    display: none !important;
  }
}
