/* ============================================================
   لایهٔ موبایل — صفحه تمام‌عرض، تجربهٔ اپ‌مانند
   روی صفحه‌های حساب، دمو، سیگنال و ثبت‌نام بارگذاری می‌شود.
   ============================================================ */

/* ---------- پایه: صفحه تمام‌عرض و بدون پرش ---------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body { max-width: 100%; overflow-x: hidden; }
body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: auto;
}
img, svg, canvas, iframe, table { max-width: 100%; }

/* ورودی‌ها در iOS زیر ۱۶px باعث زوم ناخواسته می‌شوند */
input, select, textarea, button { font-size: max(16px, 1em); }

/* نواحی لمس راحت */
button, .dash-tabs button, .seg button, .ac-btn, .dash-tile, .chip {
  min-height: 40px;
}

@media (max-width: 720px) {

  /* ---------- سربرگ سایت: جمع‌وجور و چسبیده ---------- */
  .site-header { position: sticky; top: 0; z-index: 60; }
  /* دو ردیف: برند بالا، منو زیرش تمام‌عرض و قابل‌اسکرول
     تا گزینهٔ «ثبت‌نام» هیچ‌وقت بیرون کادر نیفتد. */
  .site-header .header-inner {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px 6px;
    min-height: 0;
    row-gap: 4px;
  }
  .site-header .brand { flex: 1 1 auto; }
  .site-header .nav {
    flex: 1 0 100%;
    order: 3;
    justify-content: flex-start;
  }
  .site-header .brand-text small { display: none; }
  .site-header .brand-text strong { font-size: 14px; }
  .site-header .nav {
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .site-header .nav::-webkit-scrollbar { display: none; }
  .site-header .nav a { padding: 6px 10px; font-size: 12px; white-space: nowrap; border-radius: 8px; }
  .site-header .nav a[href="/register"] {
    background: rgba(34, 211, 238, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.28);
    color: #bae6fd;
    font-weight: 700;
  }
  .site-header .live-status { display: none; }

  /* ---------- محتوا تمام‌عرض ---------- */
  .container,
  .container-wide {
    width: 100%;
    max-width: 100%;
    padding-inline: 10px;
  }
  main { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }

  /* ---------- داشبورد: تمام‌صفحه ---------- */
  /* داشبورد سربرگ خودش را دارد؛ سربرگ سایت و پابرگ حذف می‌شوند */
  .login-page:has(.dash:not([hidden])) .site-header,
  .login-page:has(.dash:not([hidden])) .site-footer,
  .login-page:has(.dash:not([hidden])) .ambient,
  body.is-dashboard .site-header,
  body.is-dashboard .site-footer,
  body.is-dashboard .ambient { display: none; }

  .login-main:has(.dash:not([hidden])),
  .login-main {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: 0;
    margin: 0;
  }

  .dash {
    border-radius: 0;
    border-inline: 0;
    padding: calc(env(safe-area-inset-top, 0px)) 0 calc(18px + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
    min-height: 100dvh;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  /* سربرگ داشبورد چسبیده و جمع‌وجور */
  .dash-head {
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 40;
    margin: 0;
    padding: 10px 12px;
    gap: 8px;
    align-items: center;
    background: rgba(9, 14, 26, 0.94);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  }
  .dash-who small { font-size: 9.5px; }
  .dash-who h1 { font-size: 15px; margin: 0; }
  .dash-mail { font-size: 10px; display: block; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dash-side { gap: 8px; }
  .dash-balance {
    padding: 6px 10px;
    min-width: 0;
    text-align: left;
    border-radius: 11px;
  }
  .dash-balance small { font-size: 9px; }
  .dash-balance b { font-size: 14px; }
  .dash-balance em { font-size: 9px; }
  .dash-logout {
    padding: 9px;
    border-radius: 11px;
  }
  .dash-logout span { display: none; }   /* فقط آیکون */

  /* نوار بخش‌ها: داخل صفحه، چسبیده زیر سربرگ داشبورد
     نکته: top و bottom با هم ست نشوند وگرنه نوار کل ارتفاع صفحه را می‌گیرد. */
  .dash-tabs {
    position: sticky;
    top: calc(56px + env(safe-area-inset-top, 0px));
    bottom: auto;
    inset-inline: auto;
    z-index: 30;
    height: auto;
    margin: 0 10px 8px;
    padding: 5px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 13px;
    background: rgba(9, 14, 26, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 6px 18px rgba(2, 6, 23, 0.35);
    gap: 4px;
    align-items: stretch;
  }
  .dash-tabs button {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
    padding: 7px 4px;
    font-size: 10.5px;
    border-radius: 10px;
  }
  .dash-tabs button .dt-ico { font-size: 16px; opacity: .85; }
  .dash-tabs button.active .dt-ico { transform: translateY(-1px); }

  /* بدنه */
  .dash-body {
    min-height: 0;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .dash-pane.active { animation: paneIn .22s ease; }
  @keyframes paneIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
  }

  .dash-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
  .dash-stats .ds { padding: 10px 11px; border-radius: 12px; }
  .dash-stats b { font-size: 15px; }
  .dash-grid { grid-template-columns: 1fr; gap: 8px; }
  .dash-tile { padding: 13px; border-radius: 14px; }
  .dash-tile small { font-size: 10.5px; }
  .dash-info { gap: 6px; }
  .ac-row { padding: 10px 11px; border-radius: 11px; }
  .ac-row b { font-size: 11.5px; word-break: break-all; text-align: left; }
  .dash-foot { display: none; }

  /* قاب‌ها: پر کردن صفحه */
  .pane-frame {
    /* سربرگ ≈ ۵۶px، نوار بخش‌ها ≈ ۵۰px، حاشیه‌ها ≈ ۳۰px */
    height: calc(100vh - 140px);
    height: calc(100dvh - 140px);
    min-height: 340px;
    border-radius: 12px;
  }

  /* ---------- فرم ورود/ثبت‌نام: تمام‌عرض و قابل‌اسکرول ---------- */
  /* وسط‌چین کردن کارت بلندتر از صفحه، پایین فرم (دکمهٔ ثبت‌نام) را بیرون
     از ناحیهٔ اسکرول می‌انداخت. حالا از بالا شروع می‌شود. */
  .login-page { min-height: 100vh; height: auto; display: block; }
  .login-main {
    display: block;
    align-items: flex-start;
    justify-content: flex-start;
    min-height: 0;
    padding: 8px 0 28px;
  }
  .login-card {
    margin: 0;
    max-width: 100%;
    border-radius: 0;
    border-inline: 0;
    padding: 20px 16px;
    box-shadow: none;
    background: transparent;
  }
  .login-head h1 { font-size: 20px; }
  .login-alt { font-size: 11px; }

  /* ---------- صفحه‌های دمو و سیگنال: تمام‌عرض ---------- */
  .sig-hero, .sig-grid, .sig-archive, .sig-disclaimer { padding-inline: 10px !important; }
  .sig-hero-card { border-radius: 16px; padding: 16px 14px; }
  .sig-grid { grid-template-columns: 1fr; }
  .demo-terminal, .demo-create { padding-inline: 10px; }
  .panel { border-radius: 14px; }
  .term-grid { gap: 10px; }

  /* جدول‌ها: اسکرول افقی نرم */
  .table-shell, .present-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
  }
  .archive-table, .present-table { min-width: 560px; }

  /* مودال نمودار تمام‌صفحه */
  .chart-box {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  /* توست بالای نوار پایین، نه زیر آن */
  .toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- گوشی‌های کوچک ---------- */
@media (max-width: 420px) {
  .dash-stats { gap: 6px; }
  .dash-stats .ds { padding: 9px 10px; }
  .dash-stats b { font-size: 14px; }
  .dash-who h1 { font-size: 14px; }
  .dash-mail { max-width: 36vw; }
  .pane-frame {
    height: calc(100vh - 136px);
    height: calc(100dvh - 136px);
  }
}

/* ---------- صفحه‌های داخلی که داخل قاب داشبوردند ---------- */
html.sc-embed main { padding-bottom: 8px; }
html.sc-embed .container,
html.sc-embed .container-wide { padding-inline: 8px; }

@media (max-width: 720px) {
  /* داخل قاب، سربرگ سایت اصلاً نیست؛ محتوا از بالای صفحه شروع می‌شود */
  html.sc-embed .sig-hero-card { border-radius: 12px; }
  html.sc-embed .panel { border-radius: 12px; }
}

/* ---------- صفحه‌های لمسی: افکت‌های hover را خنثی کن ---------- */
@media (hover: none) {
  .dash-tile:hover,
  .ac-btn:hover,
  .dash-logout:hover { transform: none; }
}

/* ---------- چرخش گوشی به افقی ---------- */
@media (max-width: 900px) and (orientation: landscape) {
  .pane-frame { height: calc(100vh - 96px); height: calc(100dvh - 96px); }
  .dash-head { position: static; }
}

/* ---------- کاهش انیمیشن برای کاربرانی که ترجیح می‌دهند ---------- */
@media (prefers-reduced-motion: reduce) {
  .dash-pane, .dash-pane.active, .pane-frame iframe, .pane-loading {
    transition: none !important;
    animation: none !important;
  }
}
