/* ══════════════════════════════════════════════════════════════════════
   MENDFLOW — MOBILE LAYER (mf-m-*)
   Подключается последним, после всех <style> в index.html.
   Все правила — только внутри @media (max-width: 1024px) и ниже:
   десктоп (> 1024px) этот файл не затрагивает.

   Брейкпоинты:
     ≤ 1024px — планшет: нижняя навигация вместо бокового меню
     ≤  768px — большой телефон / маленький планшет
     ≤  480px — телефон
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --mf-m-nav-h: 64px;
  --mf-safe-top: env(safe-area-inset-top, 0px);
  --mf-safe-right: env(safe-area-inset-right, 0px);
  --mf-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mf-safe-left: env(safe-area-inset-left, 0px);
  --mf-dvh: 100vh;
}

@supports (height: 100dvh) {
  :root { --mf-dvh: 100dvh; }
}

/* ── Этап 1. Каркас ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  html,
  body {
    overflow-x: hidden;
    overflow-x: clip;
  }

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

  body.mf-app-active .page-shell {
    padding-left: max(10px, var(--mf-safe-left));
    padding-right: max(10px, var(--mf-safe-right));
    padding-bottom: calc(var(--mf-m-nav-h) + 8px + var(--mf-safe-bottom));
  }

  @media (display-mode: standalone) {
    body.mf-app-active .page-shell {
      padding-top: var(--mf-safe-top);
    }
  }

  button,
  a,
  [role="button"],
  input,
  select,
  textarea,
  label {
    touch-action: manipulation;
  }

  img,
  video {
    max-width: 100%;
  }

  /* Шапка: одна строка, без выхода за край экрана */
  .topbar-future {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
  }

  .topbar-future .brand {
    flex: 0 0 auto;
    min-width: 0;
  }

  .topbar-future .topbar-search-wrap {
    flex: 1 1 auto;
    min-width: 0;
  }

  .topbar-future .topbar-actions {
    width: auto;
    flex: 0 0 auto;
    justify-content: flex-end;
    min-width: 0;
  }

  .topbar-future .topbar-status {
    display: none;
  }

  /* Нижняя навигация и шторка «Ещё» — на всех ширинах до 1024px */
  body.mf-app-active {
    padding-bottom: 0;
  }

  .workspace-sidebar {
    display: none !important;
  }

  .app-layout {
    grid-template-columns: 1fr !important;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 300;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 2px;
    min-height: var(--mf-m-nav-h);
    padding: 6px max(8px, var(--mf-safe-left)) calc(6px + var(--mf-safe-bottom)) max(8px, var(--mf-safe-right));
    box-sizing: border-box;
    background: color-mix(in srgb, var(--surface, #fff) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border, rgba(15, 23, 42, 0.08));
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
  }

  .mobile-bottom-nav.is-hidden {
    display: none !important;
  }

  .mobile-nav-item {
    flex: 1;
    min-width: 44px;
    min-height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    border: none;
    background: transparent;
    color: var(--ink-soft, #625b70);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.1;
    border-radius: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav-item.is-active {
    color: #7c3aed;
    background: rgba(124, 58, 237, 0.08);
  }

  .mobile-more-backdrop {
    position: fixed;
    inset: 0;
    z-index: 299;
    background: rgba(15, 10, 30, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .mobile-more-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--mf-m-nav-h) + var(--mf-safe-bottom));
    z-index: 301;
    max-height: min(420px, calc(var(--mf-dvh) * 0.6));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--surface, #fff);
    border-radius: 20px 20px 0 0;
    padding: 16px max(16px, var(--mf-safe-right)) 20px max(16px, var(--mf-safe-left));
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.12);
    border-top: 1px solid var(--border, rgba(15, 23, 42, 0.08));
  }

  .mobile-more-sheet.is-hidden,
  .mobile-more-backdrop.is-hidden {
    display: none !important;
  }

  .mobile-more-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border, rgba(15, 23, 42, 0.06));
  }

  .mobile-more-sheet-head strong {
    font-size: 15px;
    font-weight: 800;
    color: var(--text, #111);
  }

  .mobile-more-close {
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-more-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .mobile-more-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 88px;
    padding: 14px 10px;
    border: 1.5px solid var(--border, rgba(15, 23, 42, 0.08));
    border-radius: 16px;
    background: var(--surface-2, #f7f7fb);
    color: var(--text, #111);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-more-item.is-hidden {
    display: none;
  }

  .mobile-more-item svg {
    flex-shrink: 0;
    color: #7c3aed;
  }

  .mobile-more-item.is-active {
    border-color: rgba(124, 58, 237, 0.45);
    background: rgba(124, 58, 237, 0.08);
    color: #7c3aed;
  }

  [data-theme="dark"] .mobile-more-item {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f0eaff;
  }

  body.mf-more-open {
    overflow: hidden;
  }

  [data-theme="dark"] .mobile-bottom-nav {
    background: color-mix(in srgb, #1a1523 92%, transparent);
    border-top-color: rgba(255, 255, 255, 0.08);
  }

  [data-theme="dark"] .mobile-more-sheet {
    background: #1a1523;
    border-color: rgba(255, 255, 255, 0.08);
  }

  /* Слот под Personal Development Assistant: над нижней панелью */
  .mf-m-assistant-slot {
    position: fixed;
    right: max(12px, var(--mf-safe-right));
    bottom: calc(var(--mf-m-nav-h) + 12px + var(--mf-safe-bottom));
    z-index: 290;
  }

  .mf-m-assistant-slot:empty {
    display: none;
  }
}

@media (max-width: 480px) {
  .mobile-more-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-future .topbar-search-kbd {
    display: none;
  }
}
