/* ============================================================
   Адаптив: компактный десктоп, планшет, телефон.
   Базовые брейкпоинты каркаса живут в style.css — здесь только
   то, что относится к плотной раскладке и переносам.
   ============================================================ */

@media (max-width: 1180px) {
  .topbar { padding-inline: 12px; }
  .top-actions, .history-actions, .tool-group { gap: 5px; }
  .top-actions button:not(.editor-icon-btn), .tool-btn { padding-inline: 9px; }
}

@media (max-width: 900px) {
  body { overflow: hidden; }
  .app-shell { height: 100%; min-height: 0; }
  .topbar { position: relative; top: auto; height: 60px; gap: 8px; }
  .brand { min-width: 40px; }
  .brand-copy { display: none; }
  .context-btn { min-width: 126px; max-width: 156px; }
  .plan-title-wrap { min-width: 140px; }
  body:not(.view-only) .topbar .ghost-btn { display: inline-flex; }
  .workspace { min-height: 0; overflow: hidden; }
  .catalog-panel, .stage-panel { min-width: 0; min-height: 0; }
  .stage-toolbar { gap: 8px; padding-inline: 9px; }
  .stage-toolbar .tool-btn { padding-inline: 8px; }
  .compact-select { max-width: 120px; }
  #issueDetails { display: none; }
  .issue-bar { grid-template-columns: auto 1fr auto; }
  dialog, .business-dialog, .section-template-dialog {
    width: min(620px, calc(100vw - 28px));
    max-height: calc(100dvh - 28px);
    overflow: auto;
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 100px;
    flex-wrap: wrap;
    align-content: center;
    padding: 8px 10px;
  }
  .brand { order: 1; }
  .brand-mark { width: 32px; height: 32px; }
  .context-btn { order: 2; flex: 1; min-width: 0; max-width: none; }
  .top-actions { order: 3; margin-left: auto; }
  .top-actions #saveBtn { display: none; }
  .plan-title-wrap { order: 4; flex: 1 1 calc(100% - 84px); min-width: 0; max-width: none; }
  .history-actions { order: 5; }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(360px, 62dvh) minmax(390px, 58dvh);
    align-content: start;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .stage-panel { order: 1; }
  .catalog-panel { order: 2; }

  .stage-toolbar {
    min-height: 78px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    padding: 7px 8px;
  }
  .stage-toolbar > .tool-group { min-width: 0; justify-content: center; }
  .stage-toolbar > .tool-group:first-child {
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: thin;
  }
  .stage-toolbar .tool-btn,
  .stage-toolbar .icon-btn,
  .stage-toolbar select { min-height: 30px; }
  .stage-toolbar .compact-select { max-width: none; flex: 1; }
  .stage { min-height: 250px; }

  .issue-bar #issueSummary { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .issue-bar button { padding-inline: 7px; }

  .product-card { grid-template-columns: 38px minmax(0, 1fr) auto; padding: 6px; }
  .product-card img { width: 34px; height: 46px; }

  .export-menu {
    position: fixed;
    top: 56px;
    right: 8px;
    left: auto;
    width: min(260px, calc(100vw - 16px));
    max-height: calc(100dvh - 68px);
  }

  .launch-header { gap: 8px; padding-inline: 12px; }
  .launch-header-actions button { padding-inline: 9px; }
  .structure-heading { padding-inline: 12px; }
  .launch-card-actions { flex-wrap: wrap; }
  .tree-children { padding-left: 44px; }
  .tree-children::before { left: 29px; }

  .section-template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-placement { grid-template-columns: 1fr; gap: 7px; }
  .dialog-head, .section-template-body, .business-form { padding: 14px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions button { flex: 1; }

  body.view-only .workspace { grid-template-rows: minmax(0, 1fr); overflow: hidden; }
  body.view-only .stage-panel { height: 100%; }
  body.view-only .stage-toolbar { min-height: 42px; grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 480px) {
  .topbar { min-height: 104px; gap: 6px; }
  .context-btn span, .plan-title-wrap .eyebrow { display: none; }
  .top-actions button:not(.editor-icon-btn) { padding-inline: 8px; }
  #planName { font-size: var(--t-md); }
  .stage-toolbar .tool-btn b { display: none; }
  .zoom-value { width: 36px; }
  .filter-grid { gap: 5px; }
  .launch-main { width: calc(100% - 16px); }
  .launch-selection-card { padding-inline: 18px; }
  .sync-summary { grid-template-columns: 1fr; }
  .mobile-guard-card { padding: 20px; border-radius: var(--r-3); }
}

/* Невысокие ноутбуки: подтягиваем вертикальный ритм. Рельс шапок
   сжимается одним токеном — иначе каталог и сцена расходятся по высоте. */
@media (min-width: 901px) and (max-height: 720px) {
  :root { --rail-h: 46px; }
  .topbar { height: 58px; }
  .brand-mark { width: 32px; height: 32px; }
  .inspector { padding: var(--s-3); }
  .context-btn, .plan-title-wrap { height: 42px; }
}
