/* ==========================================================================
   SP12 — слой интерфейса в духе FireCategories
   (легенда, панель свойств, предпросмотр отчёта, мобильная навигация)
   Формулы и расчёт не затрагиваются — только представление.
   ========================================================================== */

/* ------------------------------ легенда -------------------------------- */
.fcx-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin: 10px 0 4px;
  padding: 10px 12px;
  border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
  border-left: 4px solid var(--fcx-accent, #0a5cbd);
  border-radius: var(--r-md, 8px);
  background: var(--tz-f8fafc-card, #f8fafc);
  color: var(--tz-334155-text, #334155);
  font-size: 13px;
  line-height: 1.45;
}
.fcx-legend b { color: var(--fcx-accent, #0a5cbd); }
.fcx-legend__i { color: var(--tz-94a3b8-text-2, #94a3b8); }
html.dark-theme .fcx-legend {
  background: #101a2e;
  border-color: #2b3a5c;
  color: #cbd5e1;
}

/* --------------------------- панель свойств ---------------------------- */
.sp12-props {
  min-width: 0;
  align-self: start;
  max-height: 72vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--tz-ffffff-card, #fff);
  border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
  border-radius: var(--r-md, 8px);
  padding: 12px 12px 16px;
  font-size: 13px;
}
.sp12-props__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.sp12-props__title {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .01em;
}
.sp12-props__close {
  display: none;
  margin-left: auto;
  width: 44px;
  flex: 0 0 44px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
  border-radius: var(--r-sm, 6px);
  background: transparent;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.sp12-props__head-t {
  font-weight: 700;
  font-size: 14px;
  margin: 2px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
}
.sp12-props__group {
  margin: 14px 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--tz-94a3b8-text-2, #94a3b8);
}
.sp12-props__row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 0;
  border-bottom: 1px dashed rgba(148, 163, 184, .28);
}
.sp12-props__row:last-child { border-bottom: 0; }
.sp12-props__label {
  font-size: 12px;
  color: var(--tz-64748b-text-2, #64748b);
}
.sp12-props__value {
  font-size: 14px;
  font-weight: 600;
  color: var(--tz-1e293b-text, #1e293b);
  word-break: break-word;
}
.sp12-props__hint {
  font-size: 11px;
  line-height: 1.35;
  color: var(--tz-94a3b8-text-2, #94a3b8);
}
.sp12-props__acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.sp12-props__btn {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
  border-radius: var(--r-sm, 6px);
  background: var(--tz-f8fafc-card, #f8fafc);
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}
.sp12-props__btn--primary {
  background: var(--fcx-accent, #0a5cbd);
  border-color: var(--fcx-accent, #0a5cbd);
  color: #fff;
}
.sp12-props__btn--danger { color: #b91c1c; }
.sp12-props__empty { padding: 8px 0; }
.sp12-props__empty-t { font-weight: 700; margin-bottom: 4px; }
.sp12-props__empty-x { font-size: 12px; color: var(--tz-64748b-text-2, #64748b); line-height: 1.45; }

/* ------------------------ предпросмотр отчёта -------------------------- */
.sp12-preview__t {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}
.sp12-preview__empty {
  font-size: 13px;
  color: var(--tz-64748b-text-2, #64748b);
  padding: 6px 0;
}
.sp12-preview__warn {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 12px;
  color: #b45309;
}

/* ---------------------- десктоп: три колонки --------------------------- */
@media (min-width: 1180px) {
  .fcx-shell .project-container {
    grid-template-columns: var(--sp12-tree-w, 300px) minmax(0, 1fr) minmax(300px, 340px) !important;
    align-items: start;
  }
  .fcx-shell .project-container.sp12-tree-collapsed {
    grid-template-columns: 0 minmax(0, 1fr) minmax(300px, 340px) !important;
  }
  .fcx-shell.fcx-tree-hidden .project-container,
  .fcx-shell.fcx-results-collapsed .project-container {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 340px) !important;
  }
}

/* ---------------------- мобильная навигация ---------------------------- */
.fcx-mnav {
  display: none;
  position: sticky;
  top: var(--site-header-h, 68px);
  z-index: 60;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 6px;
  padding: 8px;
  border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
  border-radius: var(--r-md, 8px);
  background: var(--tz-ffffff-card, #fff);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .06);
}
.fcx-mnav__btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 8px 6px;
  border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
  border-radius: var(--r-sm, 6px);
  background: var(--tz-f8fafc-card, #f8fafc);
  color: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}
.fcx-mnav__btn--wide { flex: 0 0 100%; }
.fcx-mnav__btn--primary {
  background: var(--fcx-accent, #0a5cbd);
  border-color: var(--fcx-accent, #0a5cbd);
  color: #fff;
}

@media (max-width: 900px) {
  .fcx-mnav { display: flex; }

  /* меню — выпадающей панелью, без горизонтальной прокрутки */
  .fcx-shell { position: relative; }
  .fcx-shell .fcx-menubar {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 70;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 8px;
    border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
    border-radius: var(--r-md, 8px);
    background: var(--fcx-panel, #fff);
    box-shadow: 0 12px 28px rgba(15, 23, 42, .18);
  }
  .fcx-shell.fcx-menu-open .fcx-menubar { display: flex; }
  .fcx-shell .fcx-menu__btn {
    min-height: 44px;
    width: 100%;
    justify-content: space-between;
    font-size: 15px;
  }
  .fcx-shell .fcx-menu__list {
    position: static;
    box-shadow: none;
    border: 0;
    margin: 2px 0 6px;
  }
  .fcx-shell .fcx-menu__item { min-height: 44px; font-size: 15px; }

  /* панель инструментов — свёрнута в кнопку «Инструменты» и раскрывается */
  .fcx-shell .fcx-toolbar {
    display: none;
    flex-wrap: wrap;
    overflow-x: visible;
    row-gap: 8px;
    column-gap: 8px;
    padding: 10px;
    border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
    border-radius: var(--r-md, 8px);
    background: var(--tz-ffffff-card, #fff);
  }
  .fcx-shell.fcx-tools-open .fcx-toolbar { display: flex; }
  .fcx-shell .fcx-tool {
    width: auto;
    min-width: 0;
    flex: 1 1 calc(50% - 4px);
    min-height: 44px;
    height: auto;
    padding: 8px 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: var(--r-sm, 6px);
    overflow: hidden;
  }
  .fcx-shell .fcx-tool svg { flex: 0 0 auto; width: 18px; height: 18px; }
  .fcx-tool__lbl {
    display: inline;
    min-width: 0;
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fcx-toolbar__cap {
    flex: 0 0 100%;
    margin: 6px 0 0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--tz-94a3b8-text-2, #94a3b8);
  }
  .fcx-shell .fcx-grip { display: none; }

  /* переключатель видов — компактной сеткой, без горизонтальной ленты */
  .fcx-shell .sa-toolbar { gap: 8px; }
  .fcx-shell .sa-toolbar__group--views {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }
  .fcx-shell .sa-toolbar__group--views .sa-btn {
    min-height: 44px;
    padding: 6px 4px;
    font-size: 12px;
    line-height: 1.2;
    white-space: normal;
  }
  .fcx-shell .sa-toolbar__status { font-size: 12px; }
  .fcx-shell .title-meta-toggle { min-height: 44px; font-size: 13px; }

  /* подсказка над деревом объектов */
  .sp12-tree-hint {
    margin: 0 0 8px;
    padding: 8px 10px;
    border: 1px solid var(--tz-e2e8f0-border, #e2e8f0);
    border-left: 3px solid var(--fcx-accent, #0a5cbd);
    border-radius: var(--r-sm, 6px);
    background: var(--tz-f8fafc-card, #f8fafc);
    color: var(--tz-64748b-text-2, #64748b);
    font-size: 12px;
    line-height: 1.4;
  }

  /* мелкие кнопки дерева — довести до 44 px */
  .fcx-shell .sp12-tree-toggle,
  .fcx-shell .delete-building-btn,
  .fcx-shell .sp12-tree-panel button {
    min-height: 44px;
  }
  .fcx-shell .sp12-tree-toggle,
  .fcx-shell .delete-building-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    padding: 0 6px;
  }
  .fcx-shell .sp12-tree-toggle { right: 4px; top: 4px; }

  /* дерево — компактная карточка со своей прокруткой */
  .fcx-shell .project-tree-panel {
    max-height: 46vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .fcx-shell .project-tree-panel .sa-btn,
  .fcx-shell .project-tree-panel .sp12-tree__add,
  .fcx-shell .project-tree-panel .sp12-tree__toggle {
    min-height: 44px;
  }

  /* панель свойств — отдельный лист поверх, ничего не перекрывает */
  .sp12-props {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 9999;
    max-height: 78vh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    transform: translateY(102%);
    transition: transform .22s ease;
    box-shadow: 0 -10px 34px rgba(15, 23, 42, .28);
    padding-bottom: 24px;
  }
  .fcx-shell.fcx-props-open .sp12-props { transform: translateY(0); }
  .sp12-props__close { display: block; width: 44px; flex: 0 0 44px; }
  body.sp12-props-open .aic-fab { display: none !important; }
  .sp12-props__btn { min-height: 44px; }
  #sp12-props-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(15, 23, 42, .45);
  }
}

/* на десктопе панель инструментов — как в программе: иконки + подсказки */
@media (min-width: 901px) {
  .fcx-tool__lbl { display: none; }
  .fcx-toolbar__cap { display: none; }
}

/* ------------------------- печать ------------------------------------- */
@media print {
  .fcx-legend, .fcx-mnav, .sp12-props, #sp12-props-backdrop { display: none !important; }
}
