/* lib/app-shell/mobile-nav.css — мобильная навигация v1 (Законы 15.22 brand-palette + 15.28 breakpoints). Изоляция: .ft-shell-root[data-mobile-nav="v1"]. Активно на ≤768. */

/* =========================================================
   6.1. Variables
   ========================================================= */
.ft-shell-root[data-mobile-nav="v1"] {
  --mn-topbar-h: 54px;
  --mn-bottomnav-h: 64px;
  --mn-sheet-radius: 16px;
  --mn-z-bottomnav: 60;
  --mn-z-sheet-backdrop: 70;
  --mn-z-sheet: 71;
}

/* =========================================================
   6.5 (база). На >768 bottom-nav скрыт по умолчанию
   ========================================================= */
.ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav {
  display: none;
}

/* =========================================================
   ≤768: мобильная шапка + bottom-nav + sheet
   ========================================================= */
@media (max-width: 768px) {

  /* ---- 6.2. Мобильная шапка ---- */
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar {
    height: var(--mn-topbar-h);
    min-height: var(--mn-topbar-h);
    padding: 0 8px;
    gap: 6px;
    display: flex;
    align-items: center;
    grid-template-rows: var(--mn-topbar-h);
  }

  /* Скрываем десктопные элементы топбара */
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-search,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-term-bar,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-spacer,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-balance,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar #ft-tb-ai,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar #ft-tb-notif,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-lang,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-theme,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-acc,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-nav,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-btn[aria-label*="Donate"],
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar .ft-tb-btn[aria-label*="donate"] {
    display: none !important;
  }

  /* Мобильные кнопки топбара (инжектит bottom-nav.js) */
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-mobile-notif,
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-mobile-overflow {
    height: 44px;
    width: 44px;
    background: transparent;
    color: var(--text);
    border: none;
    border-radius: 10px;
    position: relative;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
  }
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-mobile-overflow { margin-left: 0; }

  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-mobile-notif:focus-visible,
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-mobile-overflow:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: -2px;
  }

  /* Бейдж счётчика на колокольчике */
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-mobile-notif[data-count]:not([data-count="0"])::after {
    content: attr(data-count);
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 16px;
    height: 16px;
    background: var(--red, #ef4444);
    color: #fff;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }

  /* ---- 6.3. main padding под bottom-nav ---- */
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-main {
    padding-bottom: calc(var(--mn-bottomnav-h) + env(safe-area-inset-bottom, 0px)) !important;
  }
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-route {
    padding-bottom: calc(var(--mn-bottomnav-h) + env(safe-area-inset-bottom, 0px));
  }

  /* ---- 6.4. Bottom-nav ---- */
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mn-bottomnav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    z-index: var(--mn-z-bottomnav);
    margin: 0;
  }

  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    color: var(--text);
    opacity: 0.55;
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    padding: 6px 4px;
    min-height: 44px;
    position: relative;
    font-family: inherit;
  }

  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item .mn-ic {
    font-size: 20px;
    line-height: 1;
  }

  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item[aria-current="page"] {
    color: var(--green);
    opacity: 1;
  }

  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item:active {
    background: rgba(255, 255, 255, 0.04);
  }

  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: -2px;
    border-radius: 8px;
  }

  /* Индикатор обновлений на кнопке Виджеты */
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item--widgets[data-has-updates="1"]::after {
    content: "";
    position: absolute;
    top: 10px;
    right: calc(50% - 16px);
    width: 8px;
    height: 8px;
    background: var(--green-accent, var(--green));
    border-radius: 50%;
    box-shadow: 0 0 6px var(--green-accent, var(--green));
  }

  /* Bottom-nav показан на мобиле */
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav {
    display: flex;
  }

  /* ---- 6.6. Bottom-sheet ---- */
  .ft-mobile-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: var(--mn-z-sheet-backdrop, 70);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .ft-mobile-sheet-backdrop[data-open="1"] {
    opacity: 1;
    pointer-events: auto;
  }

  .ft-mobile-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 85vh;
    max-height: 85vh;
    background: var(--bg2);
    border-top-left-radius: var(--mn-sheet-radius, 16px);
    border-top-right-radius: var(--mn-sheet-radius, 16px);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    z-index: var(--mn-z-sheet, 71);
    transform: translateY(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
  }
  .ft-mobile-sheet[data-open="1"] {
    transform: translateY(0);
  }

  .ft-mobile-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--text);
    opacity: 0.3;
    border-radius: 2px;
    margin: 8px auto 4px;
    cursor: grab;
    touch-action: none;
  }

  .ft-mobile-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
  }

  .ft-mobile-sheet-close {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .ft-mobile-sheet-close:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: -2px;
  }

  .ft-mobile-sheet-content {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
  }
}

/* =========================================================
   6.7. ≤480 — компакт
   ========================================================= */
@media (max-width: 480px) {
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item .mn-ic {
    font-size: 22px;
  }
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav .mn-item {
    font-size: 10px;
    gap: 2px;
  }
}

/* =========================================================
   6.8. body lock когда sheet открыт
   ========================================================= */
body.ft-mobile-sheet-open {
  overflow: hidden;
}

/* === FIX1 (2026-06-04): whitelist topbar children + brand stretch === */
@media (max-width: 768px) {
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar > *:not(.ft-tb-menu):not(.ft-tb-brand):not(.ft-tb-mobile-notif):not(.ft-tb-mobile-overflow) {
    display: none !important;
  }
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-brand {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 600;
    font-size: 14px;
  }
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-brand span,
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-brand b,
  .ft-shell-root[data-mobile-nav="v1"] .ft-tb-brand strong {
    display: inline !important;
  }
}

/* === FIX2 (2026-06-04): hide-all + show-whitelist hardstop === */
@media (max-width: 768px) {
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar > * { display: none !important; }
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar > .ft-tb-menu,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar > .ft-tb-brand,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar > .ft-tb-mobile-notif,
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar > .ft-tb-mobile-overflow { display: flex !important; }
}

/* === FIX3 (2026-06-04): nuke old topbar + render new ft-mobile-topbar === */
@media (max-width: 768px) {
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-topbar { display: none !important; }
  .ft-shell-root[data-mobile-nav="v1"] { grid-template-rows: 1fr !important; }
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-main { padding-top: var(--mn-topbar-h, 54px) !important; }

  .ft-mobile-topbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--mn-topbar-h, 54px);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 8px; gap: 6px;
    z-index: 65;
  }
  .ft-mobile-topbar .ft-mt-menu,
  .ft-mobile-topbar .ft-mt-notif,
  .ft-mobile-topbar .ft-mt-msg,
  .ft-mobile-topbar .ft-mt-overflow {
    height: 40px; min-width: 40px;
    border: none; background: transparent;
    color: var(--text);
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    position: relative;
  }
  .ft-mobile-topbar button:active { background: rgba(255,255,255,0.06); }
  .ft-mobile-topbar .ft-mt-brand {
    flex: 1 1 auto;
    display: flex; align-items: center; gap: 10px;
    min-width: 0;
    overflow: hidden; white-space: nowrap;
    padding-left: 4px;
  }
  .ft-mobile-topbar .ft-mt-logo {
    width: 26px; height: 26px; border-radius: 7px;
    background: linear-gradient(135deg, var(--green), var(--blue));
    color: #fff; font-weight: 700; font-size: 11px;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .ft-mobile-topbar .ft-mt-title {
    font-size: 14px; font-weight: 600; color: var(--text);
    overflow: hidden; text-overflow: ellipsis;
  }
  .ft-mobile-topbar .ft-mt-notif[data-count]:not([data-count="0"])::after {
    content: attr(data-count);
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px;
    background: var(--red, #ef4444);
    color: #fff; border-radius: 8px;
    font-size: 10px; font-weight: 700;
    padding: 0 4px;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
  }
  /* MOBMSG 2026-06-16: бейдж непрочитанных сообщений (зелёный бренд-акцент,
     чтобы визуально отличался от красного колокола уведомлений) */
  .ft-mobile-topbar .ft-mt-msg[data-count]:not([data-count="0"])::after {
    content: attr(data-count);
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px;
    background: var(--green, #0d9488);
    color: #fff; border-radius: 8px;
    font-size: 10px; font-weight: 700;
    padding: 0 4px;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
  }
  .ft-mobile-topbar button:focus-visible {
    outline: 2px solid var(--green); outline-offset: -2px;
  }
}
@media (min-width: 769px) {
  .ft-mobile-topbar { display: none !important; }
}

/* === FIX4 (2026-06-04): raise z-index above page-level modals/banners === */
@media (max-width: 768px) {
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav { z-index: 1000 !important; }
  .ft-mobile-topbar { z-index: 1001 !important; }
  .ft-mobile-sheet-backdrop { z-index: 1100 !important; }
  .ft-mobile-sheet { z-index: 1101 !important; }
}

/* === FIX5 (2026-06-04): bottom-nav and topbar above onboarding tour overlay === */
@media (max-width: 768px) {
  .ft-shell-root[data-mobile-nav="v1"] .ft-shell-bottom-nav { z-index: 999999 !important; }
  .ft-mobile-topbar { z-index: 999998 !important; }
  .ft-mobile-sheet-backdrop { z-index: 1000000 !important; }
  .ft-mobile-sheet { z-index: 1000001 !important; }
}

/* === FIX6 (2026-06-04): полноэкранный overflow tile-grid === */
@media (max-width: 768px) {
  .ft-mobile-overflow {
    position: fixed; inset: 0;
    background: var(--bg);
    z-index: 999999;
    display: none;
    flex-direction: column;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .ft-mobile-overflow[data-open="1"] { display: flex; animation: ft-mo-in .2s ease; }
  @keyframes ft-mo-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .ft-mo-header {
    display: flex; justify-content: space-between; align-items: center;
    height: 54px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
  }
  .ft-mo-title { font-size: 17px; font-weight: 600; color: var(--text); }
  .ft-mo-close {
    width: 44px; height: 44px;
    background: transparent; border: none; color: var(--text);
    border-radius: 10px; cursor: pointer; font-size: 22px;
  }
  .ft-mo-close:active { background: rgba(255,255,255,0.06); }
  .ft-mo-grid {
    flex: 1; overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 16px;
    align-content: start;
  }
  .ft-mo-tile {
    aspect-ratio: 1 / 1;
    min-height: 96px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    padding: 10px 6px;
    position: relative;
  }
  .ft-mo-tile:active { background: rgba(255,255,255,0.06); border-color: var(--green); }
  .ft-mo-tile i { font-size: 26px; color: var(--green); }
  .ft-mo-tile span { font-weight: 500; text-align: center; line-height: 1.2; }
  .ft-mo-tile-value {
    position: absolute; top: 6px; right: 8px;
    font-size: 10px; font-weight: 700; font-style: normal;
    color: var(--text); opacity: .55;
  }
  .ft-mo-tile:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
  .ft-mo-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); }
  .ft-mo-logout {
    width: 100%;
    padding: 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: #ef4444;
    font-size: 14px; font-weight: 600;
    cursor: pointer;
  }
  .ft-mo-logout:active { background: rgba(239,68,68,0.08); }
  body.ft-mobile-overflow-open { overflow: hidden; }
}

/* === FIX7 (2026-06-04): tile grid shrink — overflow tiles must fit 3 cols on 390px viewport === */
@media (max-width: 768px) {
  .ft-mo-tile { min-width: 0 !important; min-height: 88px !important; aspect-ratio: auto !important; }
  .ft-mo-tile span { font-size: 11px !important; overflow: hidden; text-overflow: ellipsis; width: 100%; }
}

/* === LEVEL-2 (2026-06-04) WCAG touch-target ≥44px === */
@media (max-width: 768px) {
  .ft-mobile-topbar .ft-mt-menu,
  .ft-mobile-topbar .ft-mt-notif,
  .ft-mobile-topbar .ft-mt-msg,
  .ft-mobile-topbar .ft-mt-overflow {
    height: 44px !important;
    min-width: 44px !important;
  }
}

/* === L2-FIX (2026-06-04): cookie consent banner компактнее на мобиле === */
@media (max-width: 768px) {
  #ft-cookie-consent-banner { padding: 12px !important; font-size: 12px !important; line-height: 1.3 !important; }
  #ft-cookie-consent-banner h3, #ft-cookie-consent-banner [class*='title'] { font-size: 13px !important; margin: 0 0 4px !important; }
  #ft-cookie-consent-banner p, #ft-cookie-consent-banner [class*='text'] { font-size: 12px !important; margin: 0 0 8px !important; max-height: 60px; overflow: hidden; }
  #ft-cookie-consent-banner button { min-height: 44px !important; padding: 8px 14px !important; font-size: 13px !important; }
  #ft-cookie-consent-banner [class*='actions'], #ft-cookie-consent-banner .cc-actions { gap: 8px !important; }
}

/* === V2 layout (2026-06-04): третья кнопка "Доп. меню" в правом углу шапки === */
@media (max-width: 768px) {
  .ft-mobile-topbar .ft-mt-widgets {
    height: 44px !important;
    min-width: 44px !important;
    border: none;
    background: transparent;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    position: relative;
  }
  .ft-mobile-topbar .ft-mt-widgets:active { background: rgba(255,255,255,0.06); }
  .ft-mobile-topbar .ft-mt-widgets:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
}

/* === V4 (2026-06-04): right-panel внутри sheet видим даже на мобиле === */
@media (max-width: 768px) {
  .ft-mobile-sheet .ft-shell-right[data-in-sheet="1"] { display: block !important; width: 100% !important; height: auto !important; }
}
