/* Телефон: те же токены, что у оболочки G. */
@media (max-width: 899px) {
  body {
    --mobile-dock-space: calc(90px + env(safe-area-inset-bottom, 0px));
    --mobile-glass: color-mix(in srgb, var(--panel) 86%, transparent);
    -webkit-text-size-adjust: 100%;
  }

  .mob, #mob-left, #mob-right, #mob-title { display: none !important; }

  /* v9 (владелец: «плашка снизу — как у меня в „Деньгах“»): стеклянная капсула с бегущей «линзой» под выбранной вкладкой
     и круглая кнопка ИИ справа с градиентом и ореолом; капсулу можно вести пальцем — линза едет следом (mobile.js).
     Остаётся доступной и поверх полноэкранного ИИ. */
  #mobile-dock {
    --mdk-glass: color-mix(in srgb, var(--panel) 72%, transparent);
    --mdk-edge: rgba(255, 255, 255, .7);
    --mdk-shadow: 0 10px 34px -8px rgba(20, 20, 40, .22), 0 2px 6px rgba(0, 0, 0, .05), inset 0 1px 0 rgba(255, 255, 255, .9), inset 0 -1px 0 rgba(0, 0, 0, .04);
    --mdk-lens: color-mix(in srgb, var(--sel) 12%, transparent);
    --mdk-lens-edge: inset 0 1px 0 rgba(255, 255, 255, .7), inset 0 0 0 .5px color-mix(in srgb, var(--sel) 22%, transparent);
    position: fixed;
    z-index: 55;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 620px;
    margin: 0 auto;
    padding: 0 max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    pointer-events: none;
  }
  :root[data-theme="dark"] #mobile-dock {
    --mdk-edge: rgba(255, 255, 255, .12);
    --mdk-shadow: 0 12px 36px -8px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .14), inset 0 -1px 0 rgba(0, 0, 0, .3);
    --mdk-lens: rgba(255, 255, 255, .12);
    --mdk-lens-edge: inset 0 1px 0 rgba(255, 255, 255, .16);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) #mobile-dock {
      --mdk-edge: rgba(255, 255, 255, .12);
      --mdk-shadow: 0 12px 36px -8px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .14), inset 0 -1px 0 rgba(0, 0, 0, .3);
      --mdk-lens: rgba(255, 255, 255, .12);
      --mdk-lens-edge: inset 0 1px 0 rgba(255, 255, 255, .16);
    }
  }
  .mdk-cap, .mdk-ai {
    pointer-events: auto;
    background: var(--panel);
    background: var(--mdk-glass);
    border: 1px solid var(--mdk-edge);
    -webkit-backdrop-filter: blur(22px) saturate(2) brightness(1.04);
    backdrop-filter: blur(22px) saturate(2) brightness(1.04);
    box-shadow: var(--mdk-shadow);
  }
  .mdk-cap {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 64px;
    display: flex;
    align-items: center;
    padding: 6px;
    border-radius: 99px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .mdk-lens {
    position: absolute;
    top: 6px;
    bottom: 6px;
    left: 0;
    width: 0;
    border-radius: 99px;
    pointer-events: none;
    background: var(--mdk-lens);
    box-shadow: var(--mdk-lens-edge);
    opacity: 0;
    transition: transform .46s cubic-bezier(.34, 1.4, .64, 1), width .46s cubic-bezier(.34, 1.4, .64, 1), opacity .2s ease;
  }
  .mdk-lens.drag { transition: opacity .2s ease; }
  .mdk-cap button {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0;
    border: 0;
    border-radius: 99px;
    background: none;
    color: color-mix(in srgb, var(--text) 72%, transparent);
    -webkit-tap-highlight-color: transparent;
  }
  .mdk-cap button[aria-current="page"], .mdk-cap button.hot { color: var(--sel); }
  .mdk-cap svg { width: 22px; height: 22px; flex: none; transition: transform .3s cubic-bezier(.34, 1.56, .64, 1); }
  .mdk-cap button[aria-current="page"] svg { transform: scale(1.06); stroke-width: 2.3; }
  .mdk-cap button.hot svg { transform: scale(1.16) translateY(-1px); }
  .mdk-cap span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 10.5px/1.1 Inter, system-ui, sans-serif; letter-spacing: -.01em; }
  /* ИИ — круглая кнопка: градиент и ореол; открыт — кольцом */
  .mdk-ai {
    position: relative;
    width: 64px;
    height: 64px;
    flex: none;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(140deg, #5B9BFF 0%, #3D6BFF 48%, #7A4DFF 100%);
    border-color: rgba(255, 255, 255, .35);
    box-shadow: 0 10px 26px -6px rgba(61, 107, 255, .65), 0 0 0 6px color-mix(in srgb, #3D6BFF 14%, transparent), inset 0 1px 0 rgba(255, 255, 255, .35);
    transition: transform .15s ease, box-shadow .2s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .mdk-ai:active { transform: scale(.9); }
  .mdk-ai svg { width: 26px; height: 26px; }
  .mdk-ai[aria-current="page"] { box-shadow: 0 10px 26px -6px rgba(61, 107, 255, .65), 0 0 0 3px var(--panel), 0 0 0 6px #3D6BFF; }
  .mdk-cap button:focus-visible, .mdk-ai:focus-visible, .mobile-back button:focus-visible,
  .mobile-sheet-head button:focus-visible {
    outline: 2px solid var(--sel);
    outline-offset: -3px;
  }
  .mdk-ai:focus-visible { outline-offset: 3px; }

  /* Профиль не заполнен — красный «!» у «Профиль» в нижней панели */
  body.pf-miss #mobile-dock [data-mobile-tab="profile"]::after {
    content: "!";
    position: absolute;
    top: 6px;
    left: calc(50% + 5px);
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #E5484D;
    color: #fff;
    font: 800 12px/1 Inter, sans-serif;
    box-shadow: 0 0 0 2px var(--panel);
  }

  /* Меню разделов (v8) — экран на весь экран: «←» с экрана «Документы» или «← Разделы» на странице раздела */
  body.open-left:not(.lp-docs) #nav {
    display: flex;
    z-index: 29;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    padding: calc(16px + env(safe-area-inset-top, 0px)) 14px var(--mobile-dock-space);
    border: 0;
    border-radius: 0;
    background: var(--canvas);
    box-shadow: none;
    overflow-y: auto;
  }
  #nav .nav-brand { flex-direction: row; gap: 12px; text-align: left; padding: 0 4px; }
  #nav .nav-brand img { width: 52px; margin: 0; }
  #nav .nav-brand b { font-size: 19px; }
  #nav .nav-brand span { margin: 0 0 0 auto; }
  #nav .nav-list { flex: none; margin-top: 18px; gap: 6px; overflow: visible; }
  #nav .nav-it { min-height: 54px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); font-size: 16px; }
  #nav .nav-it.on { background: var(--sel-weak); }
  #nav .nav-admin { margin-top: 10px; }
  #nav .nav-admin::before { display: none; }
  #nav .nav-foot { margin-top: auto; padding-top: 16px; }
  #nav #acct .acct-card { border: 1px solid var(--line); }
  #nav #acct .acct-guest .dc-btn { width: 100%; height: 48px; padding: 0 14px; font-size: 15px; }
  #nav #acct .acct-guest .acct-note { margin: 6px 0 0; text-align: center; }

  /* Экран меню — без списка документов под ним (app.css показывает #left при open-left) */
  body.open-left:not(.lp-docs) #left { display: none !important; }
  /* Список документов занимает весь экран. */
  body.open-left.lp-docs #left {
    display: flex;
    z-index: 29;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 14px var(--mobile-dock-space);
    border: 0;
    border-radius: 0;
    background: var(--canvas);
    box-shadow: none;
  }
  #left .dl-head { flex: none; }
  #left .dl-head h2 { font-size: 24px; }
  #left .dl-add { width: 44px; height: 44px; }
  #left .dl-search { min-height: 48px; flex: none; }
  #left #layers { min-height: 0; overscroll-behavior: contain; }
  #layers .layer { min-height: 52px; }
  #layers .dl-body { min-height: 48px; }
  #left .dl-back { width: 44px; height: 44px; }
  /* «← Разделы» сверху страницы раздела (mobile.js) */
  .mobile-back { display: flex; align-items: center; flex: none; padding: 0 0 6px; }
  .mobile-back button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 44px;
    padding: 0 14px 0 8px;
    border-radius: 999px;
    background: var(--panel);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
  }
  .mobile-back svg { width: 22px; height: 22px; }
  #page-host {
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px var(--mobile-dock-space);
    border-radius: 0;
    background: var(--canvas);
    overscroll-behavior: contain;
  }
  #page-host > .mobile-back {
    position: sticky;
    top: calc(-12px - env(safe-area-inset-top, 0px));
    z-index: 8;
    padding-top: 8px;
    background: var(--canvas);
  }

  /* Одна строка: название и существующая выгрузка. */
  #editor {
    top: env(safe-area-inset-top, 0px);
    left: max(6px, env(safe-area-inset-left, 0px));
    right: max(6px, env(safe-area-inset-right, 0px));
    bottom: calc(var(--mobile-dock-space) + 26px);
    gap: 6px;
    min-width: 0;
  }
  #editor .ed-bar {
    flex: none;
    flex-wrap: nowrap;
    gap: 8px;
    min-height: 60px;
    padding: 7px 6px;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  #editor .ed-title { flex: 1 1 0; min-width: 0; }
  #editor .ed-title .ed-name { gap: 0; }
  #editor .ed-title .ed-name b { font-size: clamp(18px, 4vw, 25px); }
  #editor .ed-crumbs, #editor .ed-tag, #editor #ed-ai, #editor #ed-create,
  #editor .ed-zoom { display: none; }
  #editor .ed-acts { margin-left: 0; }
  #editor .ed-split .btn { height: 44px; padding: 0 10px; }
  #editor .ed-split #ed-png { background: var(--sel); border-radius: 14px 0 0 14px; }
  #editor .ed-split #ed-png .l { display: none; }
  #editor .ed-split #ed-png::after { content: "Скачать"; font-size: 14px; }
  #editor .ed-split #ed-dl { background: var(--sel); min-width: 44px; border-radius: 0 14px 14px 0; }
  #editor .ed-scroll {
    min-height: 0;
    padding: 0 0 80px;
    border-radius: 10px;
    overscroll-behavior: contain;
  }
  #editor .ed-pages .doc { border-radius: 10px; }
  #editor .ed-title .ed-saved {
    display: inline-flex;
    position: fixed;
    left: 50%;
    bottom: calc(var(--mobile-dock-space) + 5px);
    transform: translateX(-50%);
    max-width: calc(100vw - 24px);
    font-size: 12px;
  }
  #editor .ed-warn { top: calc(100% + 4px); max-width: 90vw; }

  /* Правка появляется только при активном текстовом поле. */
  #editor .ed-fmt { display: none; }
  body.mobile-text-edit #editor .ed-fmt {
    display: flex;
    position: fixed;
    z-index: 21;
    left: 12px;
    right: 12px;
    bottom: max(calc(var(--mobile-dock-space) + 30px), calc(var(--mobile-keyboard, 0px) + 8px));
    max-width: 540px;
    margin: 0 auto;
  }
  #editor .ed-fmt #fmt {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 4px 7px;
    border: 1px solid var(--line);
    background: var(--panel);
    background: var(--mobile-glass);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    border-radius: 24px;
    box-shadow: var(--shadow-pop);
    touch-action: pan-x;
  }
  #editor .ed-fmt #fmt button { min-width: 44px; height: 44px; }
  #editor .ed-fmt::before, #editor .ed-fmt::after {
    content: "";
    position: absolute;
    top: 4px;
    bottom: 4px;
    width: 22px;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
  }
  #editor .ed-fmt::before { left: 1px; border-radius: 24px 0 0 24px; background: linear-gradient(90deg, var(--panel), transparent); }
  #editor .ed-fmt::after { right: 1px; border-radius: 0 24px 24px 0; background: linear-gradient(270deg, var(--panel), transparent); }
  #editor .ed-fmt.mobile-overflow-start::before,
  #editor .ed-fmt.mobile-overflow-end::after { opacity: 1; }

  /* Свойства — шторка; меню приложения остаются выше неё. */
  #mobile-scrim {
    position: fixed;
    inset: 0;
    z-index: 31;
    width: 100%;
    height: 100%;
    border-radius: 0;
    background: rgba(0, 0, 0, .48);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
  }
  #mobile-scrim[hidden] { display: none; }
  body.open-right #right {
    display: flex;
    position: fixed;
    z-index: 32;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: 85vh;
    height: 85dvh;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 12px);
    padding: 0 0 var(--mobile-dock-space);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 28px 28px 0 0;
    background: var(--panel);
    box-shadow: var(--shadow-pop);
    transform: translateY(var(--mobile-sheet-drag, 0px));
    overflow: hidden;
  }
  .mobile-sheet-head { display: flex; align-items: center; padding: 0 12px; flex: none; border-bottom: 1px solid var(--line); }
  .mobile-sheet-handle {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    height: 58px;
    padding-left: 44px;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    touch-action: none;
  }
  .mobile-sheet-handle::before { content: ""; width: 38px; height: 4px; border-radius: 99px; background: var(--muted); opacity: .6; }
  .mobile-sheet-close { display: grid; place-items: center; color: var(--muted); border-radius: 50%; }
  .mobile-sheet-close svg { width: 21px; height: 21px; }
  #right #props { min-height: 0; padding-bottom: 14px; overscroll-behavior: contain; }

  /* ИИ заполняет экран, нижняя навигация не перекрывает ввод. */
  #ai-panel.aip {
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: auto;
    max-height: none;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: var(--mobile-dock-space);
    animation: none;
  }
  #ai-panel .aip-grab, .aip-scrim { display: none !important; }
  body.ai-open #editor { margin-right: 0; }
  #toast { bottom: calc(var(--mobile-dock-space) + 8px); z-index: 56; }
  /* Разовое предложение «Подписант — я» (profile.js) — над нижней панелью, а не под ней */
  .pf-offer { bottom: calc(var(--mobile-dock-space) + 6px); }

  /* Размеры целей и полей не меняют геометрию самого бланка. */
  body :is(button, [role="button"], summary) { min-width: 44px; min-height: 44px; }
  body :is(input, textarea, select) { font-size: 16px !important; }
  body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select) { min-height: 44px; }
  body :is(.chk, .sw, a[href]:not(.doc a)) { min-height: 44px; }
  body a[href]:not(.doc a) { display: inline-flex; align-items: center; }
  body input[type="range"] { min-height: 44px; }
  body .swatch { width: 44px; height: 44px; }
  body .swatch input { width: 58px; height: 58px; }
  body .seg, body .btns { min-width: 0; }
  body .seg { flex-wrap: wrap; }
}
