/* Адаптив: компактное меню и мобильные раскладки. Подключается последним и только переопределяет
   настольные стили. Цель: 360–430 px без горизонтальной прокрутки, цели нажатия не меньше 44 px. */

/* ---------- Настольная панель немного плотнее на средних экранах ---------- */
@media (min-width: 1381px) and (max-width: 1480px) {
  .nav-tab { padding: 8px 9px; font-size: 14px; }
  .nav-link-research { font-size: 13px; }
}

/* Кнопка меню и пункт «Биржевые счета» внутри списка нужны только в компактном режиме. */
.nav-menu-toggle, a.nav-sheet-accounts { display: none; }

/* ---------- Компактное меню разделов ---------- */
@media (max-width: 1380px) {
  .nav-tabs-wrapper {
    position: sticky;
    top: 8px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    width: auto;
    max-width: none;
    margin: 8px 12px 4px;
    padding: 6px 6px 6px 14px;
    overflow: visible;
  }
  .nav-brand { min-height: 44px; }
  .nav-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--e-line2);
    border-radius: 12px;
    background: transparent;
    color: var(--color-text-main);
    font: inherit;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
  }
  .nav-menu-toggle .nav-current { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-menu-toggle svg { flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s ease; }
  .nav-tabs-wrapper[data-menu-open] .nav-menu-toggle { background: var(--e-panel); }
  .nav-tabs-wrapper[data-menu-open] .nav-menu-toggle svg { transform: rotate(180deg); }
  .nav-menu-toggle:focus-visible { outline: 2px solid var(--color-text-main); outline-offset: 2px; }

  /* Список разделов: выпадающая панель на всю ширину под строкой меню. */
  .nav-tabs {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    z-index: 50;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    max-height: calc(100vh - 96px);
    max-height: calc(100dvh - 96px);
    overflow-y: auto;
    padding: 8px;
    background: var(--color-bg-surface);
    border: 1px solid var(--e-line2);
    border-radius: 16px;
    box-shadow: var(--e-shadow);
  }
  .nav-tabs-wrapper[data-menu-open] .nav-tabs { display: flex; }
  .nav-tabs .nav-tab,
  .nav-tabs .nav-link-research {
    width: 100%;
    min-height: 48px;
    justify-content: flex-start;
    padding: 0 14px;
    font-size: 16px;
    border-radius: 12px;
  }
  .nav-tabs .nav-more { display: block; }
  .nav-tabs .nav-more > summary { display: none; }
  .nav-tabs .nav-more-menu { position: static; display: grid; min-width: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  a.nav-sheet-accounts { display: inline-flex; margin-top: 4px; background: var(--color-accent); color: var(--color-on-accent) !important; font-weight: 600; }
  a.nav-sheet-accounts:hover { background: var(--color-accent-hover); }
  .nav-extra,
  body.btv2-active.workbench-active .nav-extra { display: flex; justify-content: flex-end; gap: 6px; width: auto; min-width: 0; margin: 0; padding: 0; }
  .nav-extra .nav-link-accounts { display: none; }
  .nav-extra .theme-toggle { width: 44px; height: 44px; }
}

/* ---------- Телефон ---------- */
@media (max-width: 700px) {
  /* Шапка: название и «Выйти» в одной строке, ниже компактные бейджи. */
  .app-header,
  body.btv2-active.workbench-active .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 12px 6px;
    background: transparent;
    border-bottom: 0;
  }
  .header-left,
  body.btv2-active.workbench-active .header-left { display: contents; }
  .app-title,
  body.btv2-active.workbench-active .app-title {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
    line-height: 1.3;
  }
  .badge-group,
  body.btv2-active.workbench-active .badge-group { grid-column: 1 / -1; grid-row: 2; gap: 6px; }
  .badge,
  body.btv2-active.workbench-active .badge { font-size: 10px; padding: 2px 7px; }
  .header-right { grid-column: 2; grid-row: 1; gap: 8px; }
  #auth-status-indicator,
  body.btv2-active #auth-status-indicator { display: none; }
  .header-right .btn { min-height: 44px; padding: 0 14px; }
  .platform-header .nav-back-link { grid-column: 1 / -1; grid-row: 3; justify-self: start; min-height: 44px; display: inline-flex; align-items: center; }

  .app-main { padding: 12px; }
  .section-title { font-size: 24px; }
}

@media (max-width: 700px) {
  /* Бренд в меню — только значок: название раздела важнее. */
  .nav-brand { font-size: 0; gap: 0; margin: 0; min-height: 44px; min-width: 44px; justify-content: center; }
  .nav-tabs-wrapper { padding-left: 10px; }

  /* Строка помощника: значок и поле, ниже «Собрать» и микрофон, затем пояснение. */
  .ai-strip { grid-template-columns: 24px minmax(0, 1fr) 44px; gap: 8px 10px; padding: 12px; }
  .ai-strip-icon { grid-column: 1; grid-row: 1; }
  .ai-strip-input { grid-column: 2 / 4; grid-row: 1; font-size: 16px; padding: 8px 0; }
  .ai-strip > .btn { grid-column: 1 / 3; grid-row: 2; min-height: 44px; }
  .ai-strip-mic { grid-column: 3; grid-row: 2; width: 44px; height: 44px; }
  .ai-strip-note { grid-column: 1 / -1; grid-row: 3; padding: 0; }

  .app-main > .alert { margin-bottom: 12px; }

  /* Поля не меньше 16 px, иначе iOS приближает страницу при фокусе. */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px; }

  /* Пустая область графика не должна занимать целый экран. */
  .workbench-active .backtest-price-chart-stage { min-height: 320px; }
  .btv2-primary-chart > #btv2-retry-chart { margin: 10px 12px; }
}

/* ---------- Сенсорные экраны и планшеты: цели нажатия не меньше 44 px (вкладка Alpha не затрагивается) ---------- */
@media (max-width: 1024px), (pointer: coarse) {
  input[type="checkbox"]:not(#section-hot-coins *), input[type="radio"]:not(#section-hot-coins *) { width: 22px; height: 22px; flex: none; }
  .app-main :is(button, summary, select, [role="button"]):not(#section-hot-coins *),
  .app-main input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]):not(#section-hot-coins *) { min-height: 44px; }
  .app-main .btn:not(#section-hot-coins *), .app-main .btn-sm:not(#section-hot-coins *) { min-height: 44px; }
  .chart-zoom-controls .btn { min-width: 44px; }
  /* Кнопки внутри полей выбора (очистить, открыть список) */
  .workbench-active .panel-search-select > .panel-search-toggle { width: 44px; }
  .workbench-active .panel-search-select > .panel-search-clear { right: 44px; width: 40px; }
  .workbench-active .panel-search-select > .panel-search-input { padding-right: 88px; }
  .platform-main :is(button, summary, select, [role="button"]),
  .platform-main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { min-height: 44px; }
}

@media (max-width: 1380px) {
  .platform-header .nav-back-link { display: none; }
}

@media (max-width: 700px) {
  /* Пустая таблица: без строки заголовков пояснение целиком помещается на экране. */
  .table-responsive:has(td[colspan]) .data-table thead { display: none; }
  .table-responsive:has(td[colspan]) .data-table td[colspan] { text-align: left; white-space: normal; padding: 16px 12px !important; }
}
