/**
 * ED-ARM — супер-мобильная адаптация
 * Телефоны и планшеты: прокрутка, крупные зоны нажатия, вертикальный стек вместо «рабочего стола».
 */

/* === Safe area (вырезы, home indicator) === */
@supports (padding: env(safe-area-inset-bottom)) {
  body.ed-app-shell {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .edarm-mobile-nav {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .wrapper.app-outer {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* === Планшет: rail и прокрутка === */
@media (max-width: 1100px) {
  html,
  body.ed-app-shell {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.ed-noscroll {
    overflow-y: auto !important;
  }

  .wrapper.app-outer {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
  }

  .app-shell {
    min-height: 0;
    overflow: visible;
  }

  .app-main,
  .app-main-inner.container {
    overflow: visible;
    min-height: 0;
  }

  .app-rail {
    max-height: none;
    border-top: 1px solid var(--border);
  }

  .app-rail-inner {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 12px 12px 16px;
  }

  .gh-excel-hub {
    height: auto;
    min-height: min(70dvh, 520px);
    overflow: visible;
  }

  .gh-screen-main {
    overflow: visible;
    min-height: 0;
    flex: none;
  }

  .win-pc,
  .win-desktop {
    min-height: 0;
    overflow: visible;
  }
}

/* === Планшет и телефон: вертикальный стек окон === */
@media (max-width: 900px) {
  .win-desktop-wall,
  .win-pc-wall {
    display: none;
  }

  .win-desktop-windows {
    position: static;
    inset: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 8px;
  }

  .win-desktop-taskbar {
    display: none;
  }

  .win-win,
  .win-win--explorer,
  .win-win--excel {
    position: static !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: none;
    min-height: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  }
}

/* === Телефон: компактная шапка Excel === */
@media (max-width: 768px) {
  .xl-formula-bar {
    display: none;
  }

  .xl-titlebar {
    height: auto;
    min-height: 44px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  .xl-titlebar-sub {
    flex: 1 1 100%;
    order: 3;
  }

  .xl-titlebar-h1 {
    max-width: 100%;
    white-space: normal;
    font-size: 11px;
    line-height: 1.35;
  }

  .xl-statusbar {
    height: auto;
    min-height: 40px;
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 6px 10px;
  }

  .xl-statusbar-left,
  .xl-statusbar-right {
    flex-wrap: wrap;
    gap: 6px 8px;
  }

  .xl-statusbar-counter {
    font-size: 10px;
    padding: 2px 6px;
  }

  .xl-sheet-tabs {
    display: none;
  }

  .app-main-inner.container {
    padding: 6px 8px 8px !important;
  }

  /* Проводник + Excel — вертикальный стек, без «рабочего стола» */
  .win-desktop-wall,
  .win-pc-wall {
    display: none;
  }

  .win-desktop {
    border-radius: 8px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
  }

  /* дублирующие правила win-desktop-windows / win-win — см. блок max-width: 900px выше */

  .win-win--excel.win-win--hidden {
    display: none !important;
  }

  .win-win--excel:not(.win-win--hidden) {
    display: flex !important;
  }

  .win-ex-body {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .win-ex-tree {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 6px 8px;
    background: #fff;
  }

  .win-ex-tree-item {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fff;
    min-height: 36px;
    font-size: 12px;
  }

  .win-ex-tree-item--on {
    background: #cce8ff;
    border-color: #0078d4;
  }

  .win-ex-tree-item--sub {
    padding-left: 12px;
  }

  .win-ex-list {
    min-height: 140px;
    max-height: min(42dvh, 320px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .win-xl-sheetlist {
    max-height: min(36dvh, 280px);
  }

  .win-ex-ribbon {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px;
  }

  .win-ex-rib-btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .win-ex-rib-btn--action {
    flex: 1 1 100%;
    order: -1;
    min-height: 44px;
    font-size: 14px;
  }

  .win-ex-drop {
    margin: 8px;
    padding: 20px 12px;
  }

  .win-ex-browse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 20px;
    font-size: 14px;
  }

  .win-toast {
    left: 12px;
    right: 12px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    max-width: none;
    font-size: 13px;
  }

  /* Шаги мастера */
  .gh-pipeline {
    padding: 8px;
  }

  .gh-pipeline-steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
  }

  .gh-pstep {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
    padding: 6px 4px;
    font-size: 9px;
  }

  .gh-pstep-num {
    width: 22px;
    height: 22px;
    font-size: 10px;
  }

  .gh-pstep strong {
    font-size: 9px;
    line-height: 1.2;
  }

  /* Панель инструментов */
  .hub-tool summary {
    min-height: 44px;
    padding: 12px 10px;
    font-size: 13px;
    display: flex;
    align-items: center;
  }

  .hub-btn,
  .hub-inp,
  .gh-btn-secondary,
  .hub-rail-dl {
    min-height: 44px;
    font-size: 14px;
  }

  .hub-tool-form--scroll {
    max-height: min(40dvh, 260px);
  }

  .hub-rail-hint {
    font-size: 13px;
    line-height: 1.5;
    padding: 8px 4px;
  }

  .gh-flow-actions {
    grid-template-columns: 1fr;
  }

  .gh-btn-flow,
  .gh-btn-submit {
    min-height: 44px;
    font-size: 14px;
  }

  /* SEO-диалог */
  .seo-dialog {
    width: calc(100vw - 16px);
    max-width: none;
    margin: auto;
  }

  .seo-kw-list {
    columns: 1;
  }
}

/* === Маленькие телефоны === */
@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  .win-ex-cols,
  .win-ex-row {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 6px;
    padding: 6px 8px;
  }

  .win-ex-cols span:nth-child(3),
  .win-ex-cols span:nth-child(4),
  .win-ex-row .win-ex-type,
  .win-ex-row .win-ex-st {
    display: none;
  }

  .win-ex-address {
    font-size: 10px;
  }

  .win-ex-addr-path {
    white-space: normal;
    word-break: break-word;
    line-height: 1.35;
  }

  .win-xl-sheet {
    grid-template-columns: 22px minmax(0, 1fr);
    padding: 10px 8px;
    min-height: 44px;
  }

  .win-xl-sheet-lock,
  .win-xl-sheet-ok {
    grid-column: 1 / -1;
    padding-left: 28px;
  }

  .gh-stats {
    grid-template-columns: 1fr;
  }

  .gh-sheet-table-wrap {
    max-height: min(50dvh, 240px);
  }

  .xl-statusbar-item:not(#xl-status-sheets):not(.xl-statusbar-counter) {
    display: none;
  }
}

/* === Нижняя мобильная навигация === */
.edarm-mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  .edarm-mobile-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9000;
    gap: 4px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  }

  body.ed-app-shell.has-mobile-nav {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .edarm-mobile-nav__btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 48px;
    padding: 6px 4px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .edarm-mobile-nav__btn span:first-child {
    font-size: 18px;
    line-height: 1;
  }

  .edarm-mobile-nav__btn.is-active {
    color: var(--xl-green-dark);
    background: var(--accent-light);
    border-color: rgba(33, 115, 70, 0.25);
  }

  .edarm-mobile-nav__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* Подсветка активной секции */
  .edarm-mobile-panel.is-mobile-focus {
    outline: 2px solid rgba(33, 115, 70, 0.45);
    outline-offset: 2px;
    border-radius: 8px;
  }
}

/* === Ландшафт на телефоне === */
@media (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
  .win-desktop-windows {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .win-win--explorer,
  .win-win--excel:not(.win-win--hidden) {
    flex: 1 1 calc(50% - 8px);
    width: calc(50% - 8px) !important;
  }

  .win-ex-list,
  .win-xl-sheetlist {
    max-height: 160px;
  }

  .edarm-mobile-nav__btn {
    flex-direction: row;
    gap: 6px;
    font-size: 11px;
  }
}
