/* =========================================================
   css/mobile.css — لایه موبایل «رهاب»
   ---------------------------------------------------------
   هدف: تجربه اپ‌مانند روی اندروید و آیفون
   • نوار بالای اپ (اپ‌بار) + نوار پایین (تب‌بار)
   • پنل‌ها به‌صورت Bottom Sheet روی نقشه
   • رعایت safe-area (ناچ و Home Bar آیفون)
   • دکمه‌های بزرگ لمسی، بدون زوم ناخواسته iOS
   این فایل بعد از style.css بارگذاری می‌شود و فقط در
   عرض کمتر از ۹۰۰ پیکسل فعال است؛ دسکتاپ دست‌نخورده می‌ماند.
   ========================================================= */

/* ---------- اجزای موبایل: پیش‌فرض پنهان در دسکتاپ ---------- */

.m-appbar,
.m-tabbar,
.m-sheet-backdrop,
.m-install {
  display: none;
}

/* =========================================================
   حالت موبایل
   ========================================================= */

@media (max-width: 900px) {

  :root {
    --m-appbar-h: 54px;
    --m-tabbar-h: 60px;
    --m-safe-top: env(safe-area-inset-top, 0px);
    --m-safe-bottom: env(safe-area-inset-bottom, 0px);
    --m-sheet-h: min(76dvh, 620px);
  }

  html,
  body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    font-size: 13px;
    /* جلوگیری از انتخاب متن ناخواسته هنگام کشیدن نقشه */
    -webkit-text-size-adjust: 100%;
  }

  /* showApp کلاس is-scroll را برای چیدمان قدیمی اضافه می‌کند؛
     در حالت اپ نباید صفحه اسکرول شود */
  body.is-scroll {
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  /* ---------- نوار بالای اپ ---------- */

  .m-appbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 0 0 auto;
    padding: calc(var(--m-safe-top) + 8px) 12px 8px;
    background: linear-gradient(180deg, rgba(14, 33, 53, .97), rgba(8, 21, 34, .95));
    border-bottom: 1px solid var(--stroke);
    backdrop-filter: blur(12px);
    z-index: 1400;
  }

  .m-appbar__brand {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
  }

  .logo--sm {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border-radius: 9px;
  }

  .m-appbar__title {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
  }

  .m-appbar__title b {
    font-size: 15px;
    background: linear-gradient(92deg, #7ff2dd, #4fbdff 60%, #8fb4ff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .m-appbar__title small {
    font-size: 10px;
    color: var(--txt-mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 46vw;
  }

  .m-appbar__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
  }

  .m-icon-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--stroke);
    border-radius: 11px;
    background: rgba(22, 48, 74, .55);
    color: var(--txt-dim);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background .15s, color .15s, border-color .15s;
  }

  .m-icon-btn svg {
    width: 21px;
    height: 21px;
  }

  .m-icon-btn:active,
  .m-icon-btn.is-on {
    background: rgba(56, 205, 245, .18);
    border-color: rgba(56, 205, 245, .55);
    color: var(--cyan);
  }

  .m-icon-btn__badge {
    position: absolute;
    top: -5px;
    left: -5px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 99px;
    background: var(--cyan-2);
    color: #04141f;
    font-size: 10px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
  }

  /* ---------- نوار بالای دسکتاپ: فقط منوی آن را نگه می‌داریم ---------- */

  .topbar {
    display: contents;
  }

  .topbar .brand,
  .topbar .topbar__actions {
    display: none;
  }

  /* منوی «بیشتر» در موبایل یک Action Sheet پایینی است */
  .topmenu {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px 14px calc(var(--m-safe-bottom) + 74px);
    border: 0;
    border-top: 1px solid var(--stroke);
    border-radius: 20px 20px 0 0;
    background: rgba(10, 24, 38, .985);
    box-shadow: 0 -20px 48px rgba(0, 0, 0, .62);
    max-height: 82dvh;
    overflow-y: auto;
    z-index: 1500;
  }

  .topmenu[hidden] {
    display: none;
  }

  .topmenu__grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .topmenu__grid .toggle,
  .topmenu__grid .btn {
    min-height: 44px;
    font-size: 12px;
    justify-content: center;
  }

  .topmenu__label {
    font-size: 10.5px;
  }

  /* ---------- فضای کاری: نقشه تمام‌صفحه زیر پنل‌ها ---------- */

  .workspace {
    position: relative;
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
    direction: rtl;
  }

  .map-area {
    position: absolute;
    inset: 0;
    height: auto;
    min-height: 0;
    order: 0;
  }

  #map {
    position: absolute;
    inset: 0;
    height: 100%;
    min-height: 0;
  }

  /* ---------- پنل‌ها → Bottom Sheet ---------- */

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    height: var(--m-sheet-h);
    max-height: var(--m-sheet-h);
    padding: 6px 10px calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 10px);
    border: 0;
    border-top: 1px solid rgba(56, 205, 245, .28);
    border-radius: 20px 20px 0 0;
    background: linear-gradient(180deg, #0c1b29, #08141f);
    box-shadow: 0 -22px 54px rgba(0, 0, 0, .7);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 1200;
    transform: translateY(calc(100% + 30px));
    visibility: hidden;
    transition: transform .3s cubic-bezier(.22, .68, .28, 1), visibility .3s;
    will-change: transform;
  }

  .panel.is-open {
    transform: translateY(0);
    visibility: visible;
  }

  /* دستگیره کشیدن */
  .panel::before {
    content: "";
    position: sticky;
    top: 0;
    display: block;
    width: 44px;
    height: 4px;
    margin: 2px auto 6px;
    border-radius: 99px;
    background: rgba(154, 176, 196, .45);
    flex: 0 0 auto;
    z-index: 3;
  }

  .panel--left,
  .panel--right {
    border-right: 0;
    border-left: 0;
    border-top: 1px solid rgba(56, 205, 245, .28);
  }

  .panel__head {
    padding: 0 2px 7px;
  }

  .panel__head h2 {
    font-size: 13px;
  }

  .panel__hint {
    font-size: 11px;
  }

  /* تب‌های داخلی پنل راست: چسبیده بالای شیت */
  .tabs {
    position: sticky;
    top: 0;
    z-index: 4;
    gap: 4px;
    padding: 4px;
    background: #081522;
    border-radius: 10px;
    box-shadow: 0 8px 18px rgba(3, 10, 18, .7);
  }

  .tab {
    padding: 11px 2px;
    font-size: 11.5px;
    min-height: 42px;
    touch-action: manipulation;
  }

  .tabpane {
    gap: 9px;
  }

  /* کارت‌ها و کنترل‌ها بزرگ‌تر برای لمس */
  .card,
  .card--tight {
    padding: 12px;
  }

  .card__title {
    font-size: 12.5px;
  }

  .field span {
    font-size: 11.5px;
  }

  /* 16px = جلوگیری از زوم خودکار iOS هنگام فوکوس ورودی */
  .field input,
  .field select,
  .field textarea {
    font-size: 16px;
    padding: 11px 12px;
    min-height: 46px;
    border-radius: 10px;
  }

  .field-row {
    gap: 9px;
  }

  .btn {
    min-height: 46px;
    font-size: 13px;
    padding: 11px 14px;
    border-radius: 11px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .mini-btn {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 12px;
    touch-action: manipulation;
  }

  .btn-row,
  .btn-row--grid {
    gap: 8px;
  }

  .check {
    min-height: 44px;
    align-items: center;
    gap: 10px;
    font-size: 12.5px;
  }

  .check input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
  }

  .threshold input[type="range"] {
    height: 34px;
  }

  /* جدول و فهرست‌ها */
  .table-scroll,
  .table-scroll--report {
    max-height: none;
    height: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    font-size: 11.6px;
  }

  .data-table th,
  .data-table td {
    padding: 9px 7px;
  }

  .kpi-grid,
  .kpi-grid--report {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .kpi {
    padding: 10px;
  }

  .report-item {
    padding: 10px;
  }

  .scene-item {
    padding: 10px;
    min-height: 46px;
  }

  .layer-item {
    padding: 10px;
    gap: 8px;
  }

  .chart-box {
    height: 150px;
  }

  .chart-box--tall {
    height: 190px;
  }

  .donut-wrap canvas {
    max-height: 190px;
  }

  .dropzone {
    padding: 16px 12px;
  }

  .footnote {
    display: block;
    font-size: 10.5px;
  }

  /* ---------- نقشه: کنترل‌ها بالای نوار پایین ---------- */

  .leaflet-top.leaflet-left {
    top: 8px;
    left: 8px;
  }

  .leaflet-control-zoom a {
    width: 38px;
    height: 38px;
    line-height: 38px;
    font-size: 20px;
  }

  .leaflet-bottom.leaflet-right {
    bottom: calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 6px);
  }

  .leaflet-bottom.leaflet-left {
    bottom: calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 6px);
  }

  .leaflet-control-attribution {
    font-size: 8.5px !important;
    max-width: 52vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .map-overlay--scene,
  .map-badge {
    display: none;
  }

  .map-overlay--basemap {
    left: 8px;
    right: auto;
    top: auto;
    bottom: calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 46px);
    padding: 3px;
    border-radius: 11px;
  }

  .segmented__btn {
    padding: 8px 9px;
    font-size: 10.5px;
    min-height: 36px;
    touch-action: manipulation;
  }

  /* حالت خالی: کمی بالاتر تا با نوار پایین و کنترل‌ها تماس نداشته باشد */
  .map-empty {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 96px);
    transform: none;
    width: auto;
    max-width: none;
    padding: 14px 13px;
    gap: 6px;
    border-radius: 16px;
  }

  .map-empty b {
    font-size: 12.5px;
  }

  .map-empty span {
    font-size: 11px;
  }

  .map-empty__acts {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 7px;
    margin-top: 6px;
  }

  .map-empty__acts .btn {
    width: 100%;
    min-height: 42px;
    font-size: 12px;
    padding: 9px 10px;
    justify-content: center;
  }

  /* نوار رسم پلیگون بالای نوار پایین */
  .drawbar {
    left: 8px;
    right: 8px;
    bottom: calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 10px);
    padding: 10px;
    border-radius: 14px;
  }

  .drawbar__head {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }

  .drawbar__row {
    gap: 7px;
  }

  .drawbar__row .btn {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    font-size: 11.5px;
    padding: 10px 6px;
  }

  /* ---------- نوار پایین (تب‌بار) ---------- */

  .m-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1300;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    padding: 5px 6px calc(var(--m-safe-bottom) + 5px);
    background: rgba(9, 22, 36, .97);
    border-top: 1px solid var(--stroke);
    backdrop-filter: blur(14px);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
  }

  .m-tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: calc(var(--m-tabbar-h) - 12px);
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--txt-mute);
    font-family: inherit;
    font-size: 9.8px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: color .15s, background .15s;
  }

  .m-tab svg {
    width: 22px;
    height: 22px;
  }

  .m-tab:active {
    background: rgba(56, 205, 245, .12);
  }

  .m-tab.is-on {
    color: var(--cyan);
    background: linear-gradient(180deg, rgba(56, 205, 245, .18), rgba(56, 205, 245, .05));
  }

  .m-tab.is-on::after {
    content: "";
    position: absolute;
    top: 3px;
    width: 22px;
    height: 3px;
    border-radius: 99px;
    background: var(--cyan);
  }

  /* ---------- پرده پشت شیت ---------- */

  .m-sheet-backdrop {
    position: fixed;
    inset: 0;
    display: block;
    background: rgba(2, 8, 14, .55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s;
    z-index: 1100;
  }

  .m-sheet-backdrop.is-on {
    opacity: 1;
    pointer-events: auto;
  }

  /* ---------- توست ---------- */

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 14px);
    transform: none;
    text-align: center;
    font-size: 12.5px;
    z-index: 1600;
  }

  /* ---------- مودال کد GEE ---------- */

  .modal__box {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    margin-top: auto;
    padding: 14px 14px calc(var(--m-safe-bottom) + 16px);
  }

  .modal {
    align-items: flex-end;
  }

  .modal__head h2 {
    font-size: 13.5px;
    line-height: 1.5;
  }

  .modal__actions .btn {
    flex: 1 1 auto;
  }

  pre.code {
    font-size: 11px;
    max-height: 46dvh;
  }

  /* ---------- صفحه ورود ---------- */

  .auth {
    align-items: center;
    padding: max(18px, var(--m-safe-top)) 16px max(18px, var(--m-safe-bottom));
    min-height: 100dvh;
  }

  .auth__card {
    width: 100%;
    padding: 22px 18px 18px;
    border-radius: 20px;
  }

  .auth__brand h1 {
    font-size: 20px;
  }

  .auth__brand p {
    font-size: 11.5px;
  }

  .auth .field input {
    font-size: 16px;
    min-height: 48px;
  }

  .auth .btn {
    min-height: 50px;
    font-size: 14px;
  }

  .auth__foot {
    font-size: 10px;
  }
}

/* =========================================================
   گوشی‌های کوچک (iPhone SE و مشابه)
   ========================================================= */

@media (max-width: 380px) {
  :root {
    --m-tabbar-h: 56px;
    --m-sheet-h: 80dvh;
  }

  .m-appbar__title small {
    display: none;
  }

  .m-tab {
    font-size: 9px;
  }

  .m-tab svg {
    width: 20px;
    height: 20px;
  }

  .tab {
    font-size: 10.5px;
  }

  .btn {
    font-size: 12px;
    padding: 10px 10px;
  }
}

/* =========================================================
   افقی (Landscape) روی گوشی: شیت کوتاه‌تر
   ========================================================= */

@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  :root {
    --m-sheet-h: 88dvh;
  }

  .tab {
    padding: 8px 2px;
  }
}

/* =========================================================
   نشانگر نصب (PWA)
   ========================================================= */

.m-install {
  align-items: center;
  gap: 10px;
  margin: 0 10px 8px;
  padding: 10px 12px;
  border: 1px solid rgba(94, 234, 212, .35);
  border-radius: 13px;
  background: linear-gradient(180deg, rgba(15, 46, 58, .95), rgba(9, 28, 38, .95));
  color: var(--txt);
  font-size: 11.8px;
  line-height: 1.6;
}

.m-install.is-shown {
  display: flex;
}

.m-install b {
  color: var(--teal);
}

.m-install__acts {
  margin-inline-start: auto;
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.m-install__acts .btn {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 11.5px;
}

.m-install__close {
  border: 0;
  background: transparent;
  color: var(--txt-mute);
  font-size: 15px;
  padding: 4px 6px;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .m-sheet-backdrop {
    transition: none !important;
  }
}
