/* ============================================================
   BizModeler — переработанный layout
   Структура: верхняя панель (бренд · документ-переключатель · действия),
   настоящий таб-бар со скользящим индикатором, холст во всю ширину,
   докируемый правый инспектор. Тёмная тема, неоновый мятный акцент.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --canvas: #0e0c14;
  --surface: #16131f;
  --surface-2: #1e1a2b;
  --surface-3: #2a2440;

  --ink: #f4f2f9;
  --ink-soft: #aaa5bb;
  --muted: #716c83;

  --line: rgba(255,255,255,.07);
  --line-2: rgba(255,255,255,.12);
  --line-3: rgba(255,255,255,.2);

  --accent: #5eead4;
  --accent-2: #a78bfa;
  --accent-ink: #04221b;
  --accent-soft: rgba(94,234,212,.12);
  --violet-soft: rgba(167,139,250,.14);

  --danger: #fb7185;
  --danger-soft: rgba(251,113,133,.14);

  --indigo: #818cf8; --violet: #a78bfa; --rose: #fb7185; --amber: #fbbf24;
  --teal: #2dd4bf; --emerald: #34d399; --slate: #94a3b8;

  --r-xl: 18px; --r-card: 14px; --r-md: 10px; --r-sm: 8px;
  --shadow-2: 0 18px 50px rgba(0,0,0,.55);
  --shadow-pop: 0 24px 70px rgba(0,0,0,.6);
  --inspector-w: 340px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1000px 560px at 82% -10%, rgba(167,139,250,.10), transparent 60%),
    radial-gradient(820px 520px at -5% 110%, rgba(94,234,212,.07), transparent 55%),
    var(--canvas);
  font-size: 14px; line-height: 1.5; letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  /* dvh корректно учитывает iOS URL-бар; fallback на 100vh */
  height: 100vh; height: 100dvh;
  overflow: hidden;
  /* Safe area — все стороны на body, цвет единый везде */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Мобильный фон: маленькие экраны — меньшие градиенты */
@media (max-width: 768px) {
  body {
    background:
      radial-gradient(60vw 40vw at 90% -5%, rgba(167,139,250,.13), transparent 70%),
      radial-gradient(50vw 35vw at -5% 105%, rgba(94,234,212,.09), transparent 70%),
      var(--canvas);
  }
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.app { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; height: 100dvh; }

/* ---- Верхняя панель -------------------------------------- */
.appbar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.appbar__brand { display: flex; align-items: center; gap: 9px; flex: none; }
.appbar__logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: var(--accent-ink); background: linear-gradient(140deg, var(--accent), #6ee7c7); box-shadow: 0 5px 16px rgba(94,234,212,.32); }
.appbar__name { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 15px; }

.docbar { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; }
.docbar__name {
  font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 16px; color: var(--ink); letter-spacing: -0.01em;
  border: 1px solid transparent; background: transparent; border-radius: var(--r-sm); padding: 5px 9px;
  min-width: 0; width: auto; max-width: 360px;
}
.docbar__name:hover { background: var(--surface); }
.docbar__name:focus { background: var(--surface); border-color: var(--line-2); outline: none; }
.docbar__name::placeholder { color: var(--muted); }
.docbar__switch { background: none; border: 1px solid transparent; color: var(--ink-soft); cursor: pointer; padding: 6px; border-radius: var(--r-sm); display: inline-flex; transition: background .15s, color .15s, border-color .15s; }
.docbar__switch:hover { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.docbar__status { font-size: 11.5px; color: var(--muted); white-space: nowrap; margin-left: 8px; }

.appbar__actions { display: flex; align-items: center; gap: 6px; flex: none; }
.appbar__sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 2px; }

/* ---- Кнопки ---------------------------------------------- */
.btn {
  font-family: inherit; font-weight: 500; font-size: 13px; color: var(--ink);
  border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--surface-2);
  padding: 7px 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .04s; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--line-3); }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--primary { background: linear-gradient(140deg, var(--accent), #6ee7c7); border-color: transparent; color: var(--accent-ink); font-weight: 600; box-shadow: 0 6px 18px rgba(94,234,212,.2); }
.btn--primary:hover { filter: brightness(1.05); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--icon { padding: 7px; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #2a0710; font-weight: 600; }
.btn--guide { color: var(--accent-2); }
.btn--guide:hover { background: var(--violet-soft); border-color: rgba(167,139,250,.4); }
.btn--guide.active { background: var(--accent-2); border-color: var(--accent-2); color: #1b1030; font-weight: 600; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 5px; border-radius: var(--r-sm); display: inline-flex; transition: color .15s, background .15s; }
.icon-btn:hover { color: var(--ink); background: var(--surface-2); }

/* ---- Таб-бар (настоящие табы) ---------------------------- */
.tabstrip { display: flex; align-items: stretch; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tabstrip__tabs { position: relative; display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabstrip__tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; font-family: inherit; font-weight: 500; font-size: 13px; color: var(--muted);
  background: none; border: 0; cursor: pointer; padding: 13px 4px; margin: 0 8px; white-space: nowrap;
  transition: color .15s;
}
.tab:first-child { margin-left: 0; }
.tab:hover { color: var(--ink-soft); }
.tab.active { color: var(--ink); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.tabstrip__ink { position: absolute; bottom: -1px; left: 0; width: 0; height: 2px; border-radius: 2px 2px 0 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); box-shadow: 0 0 10px rgba(94,234,212,.5); transition: left .28s cubic-bezier(.4,.1,.2,1), width .28s cubic-bezier(.4,.1,.2,1); opacity: 0; }

.tabstrip__meta { display: flex; align-items: center; flex: none; }
.progress { display: flex; align-items: center; gap: 8px; }
.progress__text { font-size: 11.5px; font-weight: 600; color: var(--ink-soft); min-width: 30px; text-align: right; }
.progress__track { width: 90px; height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress__bar { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .35s ease; }

/* ---- Рабочая область ------------------------------------- */
.workspace { position: relative; display: flex; min-height: 0; overflow: hidden; }
.canvas-area { flex: 1; min-width: 0; min-height: 0; overflow: hidden; padding: 14px 18px 16px; }
.canvas { height: 100%; display: grid; grid-template-columns: repeat(var(--cols, 10), 1fr); gap: 10px; min-height: 0; max-width: 100%; }

.block {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  transition: border-color .15s, box-shadow .15s, opacity .2s;
}
.block::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 2px; background: var(--blk, var(--line-2)); opacity: .55; }
.block:hover { border-color: var(--line-2); }
.block:focus-within { border-color: rgba(94,234,212,.4); box-shadow: 0 0 0 1px rgba(94,234,212,.22); }

.block__head { display: flex; align-items: center; gap: 8px; padding: 11px 13px 8px; flex: none; }
.block__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blk, var(--muted)); flex: none; opacity: .5; transition: opacity .2s, box-shadow .2s; }
.block.is-filled .block__dot { opacity: 1; box-shadow: 0 0 10px var(--blk); }
.block__title { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--ink); flex: 1; line-height: 1.3; }
.block__count { font-size: 11px; font-weight: 600; color: var(--muted); min-width: 12px; text-align: center; }
.block__info { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 2px; border-radius: 5px; display: flex; transition: color .15s, background .15s; }
.block__info:hover { color: var(--blk, var(--accent)); background: var(--surface-2); }

.block__items { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 9px; display: flex; flex-direction: column; gap: 3px; scrollbar-width: thin; }
.block__items::-webkit-scrollbar { width: 8px; }
.block__items::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; border: 2px solid var(--surface); }

.item { display: flex; align-items: flex-start; gap: 4px; padding: 6px 5px 6px 3px; border-radius: var(--r-sm); transition: background .12s; }
.item:hover { background: var(--surface-2); }
.item.dragging { opacity: .5; background: var(--accent-soft); }
.item__grip { flex: none; color: var(--muted); cursor: grab; opacity: 0; transition: opacity .12s; padding-top: 2px; display: flex; }
.item:hover .item__grip { opacity: .7; }
.item__grip:active { cursor: grabbing; }
.item__text { flex: 1; font-size: 13px; line-height: 1.45; color: var(--ink); outline: none; min-height: 19px; word-break: break-word; padding: 1px 3px; border-radius: 5px; }
.item__text:empty::before { content: attr(data-ph); color: var(--muted); }
.item__text:focus { background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line-3); }
.item__del { flex: none; background: none; border: 0; cursor: pointer; color: var(--muted); padding: 2px; border-radius: 5px; display: flex; opacity: 0; transition: opacity .12s, color .12s, background .12s; }
.item:hover .item__del { opacity: 1; }
.item__del:hover { color: var(--danger); background: var(--danger-soft); }

/* Touch-устройства: кнопка удаления всегда видна, grip скрыт */
@media (pointer: coarse) {
  .item__del { opacity: 1; }
  .item__grip { display: none; }
}
.item-add { display: inline-flex; align-items: center; gap: 5px; align-self: flex-start; font-family: inherit; font-size: 12px; font-weight: 500; color: var(--muted); background: none; border: 0; cursor: pointer; padding: 5px 7px; border-radius: var(--r-sm); margin-top: 1px; transition: color .15s, background .15s; }
.item-add:hover { color: var(--accent); background: var(--accent-soft); }

.block--indigo { --blk: var(--indigo); } .block--violet { --blk: var(--violet); } .block--rose { --blk: var(--rose); }
.block--amber { --blk: var(--amber); } .block--teal { --blk: var(--teal); } .block--emerald { --blk: var(--emerald); } .block--slate { --blk: var(--slate); }

body.guiding .block { opacity: .4; }
body.guiding .block.is-active { opacity: 1; border-color: var(--accent-2); box-shadow: 0 0 0 1px rgba(167,139,250,.5); }

/* ---- Правый инспектор (плавающий оверлей, не двигает холст) */
.inspector {
  position: absolute; top: 0; right: 0; bottom: 0; width: var(--inspector-w);
  background: var(--surface); border-left: 1px solid var(--line-2);
  box-shadow: -24px 0 60px rgba(0,0,0,.45);
  transform: translateX(100%); transition: transform .26s cubic-bezier(.4,.1,.2,1);
  z-index: 30; will-change: transform;
}
.inspector.open { transform: translateX(0); }
.inspector__inner { width: var(--inspector-w); height: 100%; display: flex; flex-direction: column; }
.inspector__head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; flex: none; }
.inspector__step { font-size: 11.5px; font-weight: 600; color: var(--accent-2); background: var(--violet-soft); border-radius: 99px; padding: 3px 10px; }
.inspector__step[hidden] { display: none; }
.inspector__title { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; flex: 1; }
.inspector__body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 16px; }
.inspector__desc { margin: 0 0 14px; font-size: 13px; color: var(--ink-soft); line-height: 1.55; }
.inspector__label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 8px; }
.inspector__qs { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.inspector__qs li { font-size: 13px; color: var(--ink); line-height: 1.45; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.inspector__nav { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); flex: none; }
.inspector__nav[hidden] { display: none; }
.inspector__nav .btn { flex: 1; justify-content: center; }
.inspector__nav .btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---- Поповер подсказки ----------------------------------- */
.popover {
  position: fixed; z-index: 65; width: 300px; max-width: calc(100vw - 24px);
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow-pop); padding: 14px 16px;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s, transform .15s, visibility .15s;
}
.popover.show { opacity: 1; visibility: visible; transform: translateY(0); }
.popover__title { font-weight: 600; font-size: 13.5px; margin-bottom: 5px; }
.popover__desc { margin: 0 0 12px; font-size: 12.5px; color: var(--ink-soft); line-height: 1.55; }
.popover__label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 7px; }
.popover__qs { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.popover__qs li { font-size: 12.5px; color: var(--ink); line-height: 1.4; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }

/* ---- Меню моделей (дропдаун) ----------------------------- */
.menu { position: fixed; z-index: 75; width: 280px; max-width: calc(100vw - 24px); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 6px; opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.98); transform-origin: top right; transition: opacity .16s, transform .16s, visibility .16s; }
.menu.show { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.menu__heading { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 8px 10px 6px; }
.menu__list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.menu-model { display: flex; align-items: stretch; border-radius: var(--r-md); transition: background .12s; }
.menu-model:hover { background: var(--surface-3); }
.menu-model.active { background: var(--surface-3); }
.menu-model__pick { flex: 1; min-width: 0; text-align: left; background: none; border: 0; cursor: pointer; padding: 8px 10px; display: flex; flex-direction: column; gap: 1px; font-family: inherit; color: var(--ink); }
.menu-model__name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-model.active .menu-model__name { color: var(--accent); }
.menu-model__sub { font-size: 11px; color: var(--muted); }
.menu-model__del { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0 10px; border-radius: var(--r-md); display: flex; align-items: center; opacity: 0; transition: opacity .12s, color .12s, background .12s; }
.menu-model:hover .menu-model__del { opacity: 1; }
.menu-model__del:hover { color: var(--danger); background: var(--danger-soft); }
.menu__sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu__item { width: 100%; text-align: left; background: none; border: 0; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 500; color: var(--ink); padding: 9px 10px; border-radius: var(--r-md); display: flex; align-items: center; gap: 8px; transition: background .12s, color .12s; }
.menu__item:hover { background: var(--surface-3); }
.menu__item--accent { color: var(--accent); }

/* ---- Модал примеров -------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 70; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(6,5,10,.6); backdrop-filter: blur(4px); }
.modal.show { display: flex; }
.modal__panel { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); width: min(800px, 100%); max-height: 86vh; overflow: auto; padding: 24px; }
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.modal__title { margin: 0 0 3px; font-family: 'Space Grotesk', sans-serif; font-size: 19px; font-weight: 700; }
.modal__sub { margin: 0; font-size: 13px; color: var(--ink-soft); }
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 11px; }
.ex-card { text-align: left; cursor: pointer; font-family: inherit; border: 1px solid var(--line-2); background: var(--surface-2); border-radius: 14px; padding: 15px; display: flex; flex-direction: column; gap: 3px; color: var(--ink); transition: border-color .15s, box-shadow .15s, transform .04s, background .15s; }
.ex-card:hover { border-color: var(--ex, var(--accent)); box-shadow: 0 12px 30px rgba(0,0,0,.4); background: var(--surface-3); }
.ex-card:active { transform: translateY(1px); }
.ex-card__name { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.ex-card__name::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ex, var(--accent)); box-shadow: 0 0 10px var(--ex, var(--accent)); }
.ex-card__tag { font-size: 12.5px; color: var(--ink-soft); }
.ex-card__method { font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 5px; }
.ex-card--indigo { --ex: var(--indigo); } .ex-card--violet { --ex: var(--violet); } .ex-card--rose { --ex: var(--rose); }
.ex-card--amber { --ex: var(--amber); } .ex-card--teal { --ex: var(--teal); } .ex-card--emerald { --ex: var(--emerald); } .ex-card--slate { --ex: var(--slate); }

/* ---- Диалог ---------------------------------------------- */
.dialog-overlay { position: fixed; inset: 0; z-index: 85; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(6,5,10,.6); backdrop-filter: blur(4px); opacity: 0; transition: opacity .18s; }
.dialog-overlay.show { opacity: 1; }
.dialog { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); width: min(400px, 100%); padding: 24px; transform: scale(.96); transition: transform .18s; }
.dialog-overlay.show .dialog { transform: scale(1); }
.dialog__title { margin: 0 0 6px; font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 700; }
.dialog__msg { margin: 0 0 18px; font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Тосты ----------------------------------------------- */
.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 95; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { display: flex; align-items: center; gap: 9px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--ink); border-radius: 12px; padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow-2); cursor: pointer; transform: translateX(120%); opacity: 0; transition: transform .25s cubic-bezier(.2,.7,.3,1), opacity .25s; max-width: 320px; }
.toast.show { transform: translateX(0); opacity: 1; }
.toast__icon { display: flex; flex: none; }
.toast--ok .toast__icon { color: var(--accent); }
.toast--warn .toast__icon { color: var(--amber); }
.toast--info .toast__icon { color: var(--accent-2); }

/* ---- Скрим (для меню/мобильных) -------------------------- */
.scrim { display: none; }

.print-head { display: none; }

/* ---- Кнопка только для мобильных ------------------------ */
.mobile-only { display: none; }

/* ---- Адаптив --------------------------------------------- */
/* === МОБИЛЬНЫЙ: портретный режим (узкий экран) === */
@media (max-width: 768px) and (orientation: portrait) {
  .mobile-only { display: inline-flex; }

  /* Хедер: grid-layout — три чётких зоны без flex-wrap сюрпризов */
  .appbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 0 8px;
    padding: 7px 12px 4px;
    align-items: center;
  }
  /* Строка 1: [brand] [пусто] [actions] */
  .appbar__brand { grid-column: 1; grid-row: 1; }
  .appbar__actions {
    grid-column: 3; grid-row: 1;
    display: flex; align-items: center; gap: 2px;
  }
  /* Строка 2: [docbar — на всю ширину] */
  .docbar {
    grid-column: 1 / -1; grid-row: 2;
    order: unset; flex-basis: auto;
    padding: 2px 0 0; gap: 4px;
    display: flex; align-items: center;
  }
  .docbar__name { font-size: 15px; max-width: none; padding: 3px 6px; }
  .docbar__status { font-size: 11px; }
  .appbar__sep { display: none; }
  /* Все кнопки — только иконки, компактный отступ */
  .btn__label { display: none; }
  .btn { padding: 6px; min-width: 0; }
  .btn--primary { padding: 6px 8px; }
  .appbar__name { font-size: 14px; }

  .tabstrip { padding: 0 12px; gap: 6px; }
  .tab { font-size: 12px; padding: 10px 2px; margin: 0 5px; }
  .progress__track { width: 50px; }
  .toast-wrap { right: 12px; }
}

/* --- Портретный вид: блоки вертикально --- */
@media (max-width: 768px) and (orientation: portrait) {
  /* Холст: однострочный список блоков */
  .canvas-area {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 10px 12px 20px;
    height: 100%;
  }
  .canvas {
    grid-template-columns: 1fr !important;
    grid-template-areas: none !important;
    grid-template-rows: none !important;
    height: auto !important;
    min-height: 0;
    gap: 8px;
    /* Не выходить за ширину экрана */
    width: 100%;
    min-width: 0;
  }
  .block { grid-area: auto !important; min-height: 130px; width: 100%; }
  body.guiding .block { opacity: 1; }

  /* Инспектор — шторка снизу */
  .inspector {
    position: fixed; top: auto; bottom: 0; right: 0; left: 0;
    width: 100%; height: 72vh;
    transform: translateY(100%);
    border-left: none; border-top: 1px solid var(--line-2);
    border-radius: 20px 20px 0 0;
  }
  .inspector.open { transform: translateY(0); }
  .inspector__inner { width: 100%; }
  .inspector__head { position: relative; padding-top: 24px; }
  .inspector__head::before {
    content: ''; display: block; position: absolute;
    top: 10px; left: 50%; transform: translateX(-50%);
    width: 36px; height: 4px;
    background: var(--line-3); border-radius: 99px;
  }
}

/* --- Холст-режим в портрете (кнопка переключения) --- */
@media (max-width: 768px) and (orientation: portrait) {
  body.mobile-canvas .canvas-area {
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.mobile-canvas .canvas {
    grid-template-columns: repeat(var(--cols, 10), minmax(110px, 1fr)) !important;
    grid-template-areas: var(--canvas-areas) !important;
    grid-template-rows: var(--canvas-rows, auto) !important;
    min-width: calc(var(--cols, 10) * 110px);
    width: max-content;
    height: auto !important; gap: 6px;
  }
  body.mobile-canvas .block { grid-area: var(--block-area) !important; min-height: 160px; }
}

/* --- Ландшафтный режим: ВЕСЬ холст виден сразу, компактно --- */
@media (max-width: 1000px) and (orientation: landscape) {
  .mobile-only { display: inline-flex; }

  /* Хедер — компактная однострочная */
  .appbar {
    flex-wrap: nowrap; padding: 4px 12px; gap: 8px;
    min-height: 0;
  }
  .appbar__logo { width: 24px; height: 24px; border-radius: 7px; }
  .appbar__name { font-size: 13px; }
  .docbar { order: unset; flex-basis: auto; min-width: 0; }
  .docbar__name { font-size: 13px; padding: 3px 6px; max-width: 180px; }
  .docbar__status { display: none; }
  .btn__label { display: none; }
  .btn { padding: 5px 9px; }
  .btn--icon { padding: 5px; }

  /* Таб-бар компактнее */
  .tabstrip { padding: 0 10px; gap: 6px; }
  .tab { font-size: 11px; padding: 7px 2px; margin: 0 5px; }
  .progress__track { width: 50px; }
  .progress__text { font-size: 11px; }

  /* Холст: вся ширина, без горизонтального скролла */
  .canvas-area {
    overflow: hidden;
    padding: 6px 8px;
  }
  .canvas {
    height: 100%;
    gap: 4px;
    min-width: 0;
    /* minmax(0,1fr) разрешает колонкам сжиматься меньше контента */
    grid-template-columns: repeat(var(--cols, 10), minmax(0, 1fr)) !important;
  }
  /* Разрешаем блокам сжиматься, блокируем вылезание контента */
  .block { min-height: 0; min-width: 0; overflow: hidden; }
  .block__title { overflow: hidden; }
  .item-add span { display: none; }
  body.guiding .block { opacity: .4; }

  /* Блоки компактнее */
  .block__head { padding: 6px 9px 5px; gap: 5px; }
  .block__dot { width: 5px; height: 5px; }
  .block__title { font-size: 10.5px; line-height: 1.25; }
  .block__count { font-size: 10px; }
  .block__info { padding: 1px; }
  .block__items { padding: 0 6px 6px; gap: 2px; }
  .item { padding: 3px 3px 3px 2px; }
  .item__text { font-size: 11.5px; line-height: 1.35; }
  .item-add { font-size: 11px; padding: 3px 5px; }

  /* Инспектор — правая панель как на десктопе */
  .inspector {
    position: absolute; top: 0; bottom: 0; right: 0; left: auto;
    width: min(280px, 85vw); height: 100%;
    border-left: 1px solid var(--line-2);
    border-top: none; border-radius: 0;
    transform: translateX(100%);
  }
  .inspector.open { transform: translateX(0); }
  .inspector__inner { width: 100%; }
  .inspector__head::before { display: none; }
  .inspector__head { padding-top: 14px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- Печать / PDF: светлая, всё содержимое влезает -------- */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; color: #1a1a1a !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .appbar, .tabstrip, .inspector, .popover, .menu, .modal, .toast-wrap, .scrim,
  .item__grip, .item__del, .item-add, .block__info, .block__count, .block__dot { display: none !important; }
  .app { display: block !important; height: auto !important; padding: 10mm 12mm !important; box-sizing: border-box !important; }
  .workspace { display: block !important; overflow: visible !important; }

  /* Заголовок документа */
  .print-head { display: block !important; padding: 0 0 14px; margin-bottom: 14px; border-bottom: 1px solid #e3e3e6; }
  .print-head h1 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; color: #111; letter-spacing: -0.01em; }
  .print-head p { margin: 4px 0 0; color: #6b6b72; font-size: 12px; }

  /* Сетка холста — сохраняем раскладку, добавляем воздух */
  .canvas-area { overflow: visible !important; padding: 0 !important; height: auto !important; }
  .canvas { height: auto !important; grid-template-rows: none !important; grid-auto-rows: auto !important; gap: 10px !important; }

  /* Блоки: плоские тонкие линии, без теней и цветных «баров» */
  .block {
    background: #fff !important; border: 1px solid #dcdce0 !important; border-radius: 6px !important;
    overflow: visible !important; min-height: 0 !important; height: auto !important;
    break-inside: avoid; box-shadow: none !important;
  }
  .block::before { display: none !important; }

  /* Заголовок блока: выделяем — крупнее, жирнее, с тонкой линией снизу */
  .block__head { padding: 9px 12px 7px !important; margin-bottom: 6px !important; border-bottom: 1px solid #ededf0 !important; }
  .block__title {
    color: #111 !important; font-size: 12px !important; font-weight: 700 !important;
    letter-spacing: .02em !important; text-transform: uppercase !important;
  }

  /* Пункты: маркированный список с отступами и комфортным интервалом */
  .block__items { display: block !important; overflow: visible !important; height: auto !important; max-height: none !important; padding: 0 12px 10px !important; }
  .item { display: block !important; padding: 0 !important; margin: 0 0 5px 0 !important; background: none !important; padding-left: 13px !important; position: relative !important; }
  .item:last-child { margin-bottom: 0 !important; }
  .item::before { content: "" !important; position: absolute !important; left: 2px !important; top: 7px !important; width: 3px !important; height: 3px !important; border-radius: 50% !important; background: #9a9aa2 !important; }
  .item__text { color: #1a1a1a !important; font-size: 11px !important; line-height: 1.45 !important; padding: 0 !important; }
  .item__text:empty::before { display: none !important; }
}
