/**
 * FARMKORM — операционный UI «Кормление» и связанные экраны на base.html.
 * Подключается после extra_css; усиливает типографику, шапку, карточки, кнопки и панели.
 *
 * Цвета и тени — только токенами farmkorm/app.css (Д-7…Д-9).
 * Адаптивная шкала --fm-fluid-*, ширина страницы и модалок
 * (--fm-page-max-width, --fm-modal-width*) заданы в farmkorm/kor.css.
 */

/* Шрифт и палитра — общие, из farmkorm/app.css (единый каркас «Стадо»). */
body[class*="kor-ui-"],
body.kor-shell {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Прежняя плоская шапка кормления (.site-header / header:not(...)) удалена:
   её заменил общий topbar каркаса stado_base.html. */

body[class*="kor-ui-"] .main-inner.kor-main,
body.kor-shell .main-inner.kor-main {
  max-width: var(--fm-page-max-width, none);
  width: 100%;
}

body[class*="kor-ui-"] h1 {
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--ui-gray-900);
}

body[class*="kor-ui-"] .card,
body[class*="kor-ui-"] .filters.card {
  border-radius: var(--radius);
  box-shadow: var(--ui-shadow-sm);
  border-color: var(--ui-card-border);
  padding: calc(var(--fm-fluid-card-pad-y) + 0.08rem) calc(var(--fm-fluid-card-pad-x) + 0.12rem);
}

body[class*="kor-ui-"] .main-inner .btn,
body.kor-shell .main-inner .btn {
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: var(--ui-btn-shadow);
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

body[class*="kor-ui-"] .main-inner .btn:hover,
body.kor-shell .main-inner .btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--ui-btn-shadow-hover);
  filter: brightness(1.05);
}

body[class*="kor-ui-"] .main-inner .btn:focus-visible {
  outline: none;
  box-shadow: var(--ui-focus-ring), var(--ui-btn-shadow);
}

body[class*="kor-ui-"] table {
  border-collapse: separate;
  border-spacing: 0;
}

body[class*="kor-ui-"] .card table th:first-child,
body[class*="kor-ui-"] .card table td:first-child {
  padding-left: max(0.5rem, var(--fm-fluid-table-pad-x));
}

body[class*="kor-ui-"] .card table th:last-child,
body[class*="kor-ui-"] .card table td:last-child {
  padding-right: max(0.5rem, var(--fm-fluid-table-pad-x));
}

body[class*="kor-ui-"] tbody tr:hover {
  background: var(--ui-row-hover-bg);
}

body[class*="kor-ui-"] ul.nav-cards {
  gap: 0.85rem;
}

body[class*="kor-ui-"] ul.nav-cards a {
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--ui-nav-card-border);
  box-shadow: var(--ui-shadow-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

body[class*="kor-ui-"] ul.nav-cards a:hover {
  border-color: var(--ui-nav-card-hover-border);
  box-shadow: var(--ui-shadow-md);
  transform: translateY(-2px);
}

body[class*="kor-ui-"] ul.nav-cards a p {
  line-height: 1.4;
}

/* Панели списков и рабочего места плана */
body[class*="kor-ui-"] .rt-toolbar,
body[class*="kor-ui-"] .fm-toolbar,
body[class*="kor-ui-"] .mx-toolbar,
body[class*="kor-ui-"] .fn-toolbar,
body[class*="kor-ui-"] .wh-toolbar,
body[class*="kor-ui-"] .fo-toolbar,
body[class*="kor-ui-"] .ig-toolbar,
body[class*="kor-ui-"] .fg-toolbar,
body[class*="kor-ui-"] .fs-toolbar,
body[class*="kor-ui-"] .mt-toolbar,
body[class*="kor-ui-"] .mtd-toolbar,
body[class*="kor-ui-"] .pw-toolbar {
  border-radius: var(--radius) !important;
  box-shadow: var(--ui-shadow-sm);
}

body[class*="kor-ui-"] .fm-toolbar .btn-create,
body[class*="kor-ui-"] .mx-toolbar .btn-create,
body[class*="kor-ui-"] .fn-toolbar .btn-create,
body[class*="kor-ui-"] .wh-toolbar .btn-create,
body[class*="kor-ui-"] .fo-toolbar .btn-create,
body[class*="kor-ui-"] .ig-toolbar .btn-create,
body[class*="kor-ui-"] .fg-toolbar .btn-create,
body[class*="kor-ui-"] .rt-toolbar .btn-create,
body[class*="kor-ui-"] .mt-toolbar .btn-create,
body[class*="kor-ui-"] .pw-toolbar .btn-save,
body[class*="kor-ui-"] .pw-toolbar button.btn-save {
  border-radius: var(--radius-sm);
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: var(--ui-btn-green-shadow);
  transition: transform 0.14s ease, filter 0.14s ease, box-shadow 0.14s ease;
}

body[class*="kor-ui-"] .fm-toolbar .btn-create:hover,
body[class*="kor-ui-"] .mx-toolbar .btn-create:hover,
body[class*="kor-ui-"] .fn-toolbar .btn-create:hover,
body[class*="kor-ui-"] .wh-toolbar .btn-create:hover,
body[class*="kor-ui-"] .fo-toolbar .btn-create:hover,
body[class*="kor-ui-"] .ig-toolbar .btn-create:hover,
body[class*="kor-ui-"] .fg-toolbar .btn-create:hover,
body[class*="kor-ui-"] .rt-toolbar .btn-create:hover,
body[class*="kor-ui-"] .mt-toolbar .btn-create:hover,
body[class*="kor-ui-"] .pw-toolbar .btn-save:hover,
body[class*="kor-ui-"] .pw-toolbar button.btn-save:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
  box-shadow: var(--ui-btn-green-shadow-hover);
}

body[class*="kor-ui-"] .mtd-btn-admin {
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: var(--ui-btn-green-shadow);
  transition: transform 0.14s ease, filter 0.14s ease, box-shadow 0.14s ease;
}

body[class*="kor-ui-"] .mtd-btn-admin:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

/* Обёртки таблиц — горизонтальная прокрутка, таблица не сжимается ниже содержимого */
body[class*="kor-ui-"] .fm-table-wrap,
body[class*="kor-ui-"] .mx-table-wrap,
body[class*="kor-ui-"] .fn-table-wrap,
body[class*="kor-ui-"] .wh-table-wrap,
body[class*="kor-ui-"] .fo-table-wrap,
body[class*="kor-ui-"] .ig-table-wrap,
body[class*="kor-ui-"] .fg-table-wrap,
body[class*="kor-ui-"] .fs-table-wrap,
body[class*="kor-ui-"] .rt-table-wrap,
body[class*="kor-ui-"] .mt-table-wrap,
body[class*="kor-ui-"] .pw-table-wrap,
body[class*="kor-ui-"] .mtd-table-wrap,
body[class*="kor-ui-"] .ih-table-wrap,
body[class*="kor-ui-"] .iv-table-wrap,
body[class*="kor-ui-"] .fsf-table-wrap {
  display: block;
  width: 100%;
  min-width: 0;
  border-radius: var(--radius) !important;
  box-shadow: var(--ui-shadow-sm);
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

body[class*="kor-ui-"] .fm-table-wrap > table,
body[class*="kor-ui-"] .mx-table-wrap > table,
body[class*="kor-ui-"] .fn-table-wrap > table,
body[class*="kor-ui-"] .wh-table-wrap > table,
body[class*="kor-ui-"] .fo-table-wrap > table,
body[class*="kor-ui-"] .ig-table-wrap > table,
body[class*="kor-ui-"] .fg-table-wrap > table,
body[class*="kor-ui-"] .fs-table-wrap > table,
body[class*="kor-ui-"] .rt-table-wrap > table,
body[class*="kor-ui-"] .mt-table-wrap > table,
body[class*="kor-ui-"] .pw-table-wrap > table,
body[class*="kor-ui-"] .mtd-table-wrap > table,
body[class*="kor-ui-"] .ih-table-wrap > table,
body[class*="kor-ui-"] .iv-table-wrap > table,
body[class*="kor-ui-"] .fsf-table-wrap > table {
  width: max-content;
  min-width: 100%;
}

body[class*="kor-ui-"] .pw-main {
  border-radius: var(--radius) !important;
  box-shadow: var(--ui-shadow-sm);
}

body[class*="kor-ui-"] .pw-side {
  border-radius: var(--radius) !important;
  box-shadow: var(--ui-shadow-md);
}

body[class*="kor-ui-"] .pw-caption {
  font-weight: 500;
  letter-spacing: 0.01em;
}

body[class*="kor-ui-"] .mt-filters {
  border-radius: var(--radius) !important;
  box-shadow: var(--ui-shadow-sm);
}

/* Карточки форм справочников */
body[class*="kor-ui-"] .ff-card,
body[class*="kor-ui-"] .nf-card,
body[class*="kor-ui-"] .rt-card,
body[class*="kor-ui-"] .gf-card,
body[class*="kor-ui-"] .fo-card,
body[class*="kor-ui-"] .wh-card,
body[class*="kor-ui-"] .mf-card,
body[class*="kor-ui-"] .ig-card,
body[class*="kor-ui-"] .fsf-card {
  border-radius: var(--radius);
  box-shadow: var(--ui-shadow-md);
  border-color: var(--ui-card-border);
}

body[class*="kor-ui-"] .ff-toolbar .ff-btn-close,
body[class*="kor-ui-"] .nf-toolbar .nf-btn-close,
body[class*="kor-ui-"] .rt-toolbar .rt-btn-close,
body[class*="kor-ui-"] .gf-toolbar .gf-btn-close,
body[class*="kor-ui-"] .fo-toolbar .fo-btn-close,
body[class*="kor-ui-"] .wh-toolbar .wh-btn-close,
body[class*="kor-ui-"] .mf-toolbar .mf-btn-close,
body[class*="kor-ui-"] .ig-toolbar .ig-btn-close,
body[class*="kor-ui-"] .fsf-toolbar .fsf-btn-save,
body[class*="kor-ui-"] .fsf-toolbar .fsf-btn-rebuild {
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: transform 0.14s ease, filter 0.14s ease, box-shadow 0.14s ease;
}

body[class*="kor-ui-"] .ff-toolbar .ff-btn-close:hover,
body[class*="kor-ui-"] .nf-toolbar .nf-btn-close:hover,
body[class*="kor-ui-"] .rt-toolbar .rt-btn-close:hover,
body[class*="kor-ui-"] .gf-toolbar .gf-btn-close:hover,
body[class*="kor-ui-"] .fo-toolbar .fo-btn-close:hover,
body[class*="kor-ui-"] .wh-toolbar .wh-btn-close:hover,
body[class*="kor-ui-"] .mf-toolbar .mf-btn-close:hover,
body[class*="kor-ui-"] .ig-toolbar .ig-btn-close:hover,
body[class*="kor-ui-"] .fsf-toolbar .fsf-btn-save:hover,
body[class*="kor-ui-"] .fsf-toolbar .fsf-btn-rebuild:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

body[class*="kor-ui-"] .filters input:focus-visible,
body[class*="kor-ui-"] .filters select:focus-visible,
body[class*="kor-ui-"] .fm-toolbar input:focus-visible,
body[class*="kor-ui-"] .rt-toolbar input:focus-visible {
  outline: none;
  box-shadow: var(--ui-focus-ring);
  border-color: var(--brand);
}

/*
 * Универсальная адаптация узких экранов (/kor/): без отдельных URL.
 * — план кормления и прочие «main + сайдбар» → столбик;
 * — таблицы уже в *-table-wrap с overflow-x: auto;
 * — панели фильтров и поиск не уезжают за край.
 */
@media (max-width: 900px) {
  body[class*="kor-ui-"] .pw-body {
    flex-direction: column;
    align-items: stretch;
    gap: var(--fm-fluid-space);
  }

  body[class*="kor-ui-"] .pw-main {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  body[class*="kor-ui-"] .pw-side {
    width: 100%;
    max-width: none;
    flex-shrink: 1;
    position: static;
    top: auto;
    align-self: stretch;
    max-height: none;
    overflow-y: visible;
    overflow-x: visible;
  }

  body[class*="kor-ui-"] .pw-toolbar h1,
  body[class*="kor-ui-"] .mt-toolbar h1,
  body[class*="kor-ui-"] .mtd-toolbar h1,
  body[class*="kor-ui-"] .fm-toolbar h1,
  body[class*="kor-ui-"] .mx-toolbar h1,
  body[class*="kor-ui-"] .fn-toolbar h1,
  body[class*="kor-ui-"] .wh-toolbar h1,
  body[class*="kor-ui-"] .fo-toolbar h1,
  body[class*="kor-ui-"] .ig-toolbar h1,
  body[class*="kor-ui-"] .fg-toolbar h1,
  body[class*="kor-ui-"] .fs-toolbar h1,
  body[class*="kor-ui-"] .rt-toolbar h1,
  body[class*="kor-ui-"] .fsf-toolbar h1 {
    flex: 1 1 100%;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  body[class*="kor-ui-"] .card,
  body[class*="kor-ui-"] .filters.card {
    padding: var(--fm-fluid-card-pad-y) var(--fm-fluid-card-pad-x);
  }

  body[class*="kor-ui-"] .filters {
    gap: var(--fm-fluid-space);
  }

  body[class*="kor-ui-"] .filters label {
    min-width: 0;
    width: 100%;
    max-width: none;
  }

  body[class*="kor-ui-"] .filters input,
  body[class*="kor-ui-"] .filters select {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  body[class*="kor-ui-"] .mt-filters label.mx-search {
    flex: 1 1 100%;
    margin-left: 0 !important;
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
  }

  body[class*="kor-ui-"] .mt-filters label.mx-search input[type="search"] {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
  }

  body[class*="kor-ui-"] .fm-toolbar form.fm-search,
  body[class*="kor-ui-"] .mx-toolbar form.mx-search,
  body[class*="kor-ui-"] .fn-toolbar form.fn-search,
  body[class*="kor-ui-"] .wh-toolbar form.wh-search,
  body[class*="kor-ui-"] .fo-toolbar form.fo-search,
  body[class*="kor-ui-"] .ig-toolbar form.ig-search,
  body[class*="kor-ui-"] .fg-toolbar form.fg-search,
  body[class*="kor-ui-"] .rt-toolbar form.rt-search {
    flex: 1 1 100%;
    margin-left: 0;
    width: 100%;
  }

  body[class*="kor-ui-"] .fm-toolbar form.fm-search input,
  body[class*="kor-ui-"] .mx-toolbar form.mx-search input,
  body[class*="kor-ui-"] .fn-toolbar form.fn-search input,
  body[class*="kor-ui-"] .wh-toolbar form.wh-search input,
  body[class*="kor-ui-"] .fo-toolbar form.fo-search input,
  body[class*="kor-ui-"] .ig-toolbar form.ig-search input,
  body[class*="kor-ui-"] .fg-toolbar form.fg-search input,
  body[class*="kor-ui-"] .rt-toolbar form.rt-search input {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  body[class*="kor-ui-"] .gf-totals-grid {
    grid-template-columns: 1fr;
    max-width: none;
  }
}

/* Модальные окна — ширина под окно браузера (не уже main) */
body[class*="kor-ui-"] .mon-modal-backdrop,
body[class*="kor-ui-"] .fs-modal-backdrop {
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px));
}

body[class*="kor-ui-"] .mon-modal {
  width: var(--fm-modal-width, min(94vw, 1400px));
  max-width: var(--fm-modal-width, min(94vw, 1400px));
  min-width: min(20rem, 94vw);
}

body[class*="kor-ui-"] .fs-modal {
  width: var(--fm-modal-width-sm, min(92vw, 520px));
  max-width: var(--fm-modal-width-sm, min(92vw, 520px));
  margin: 0;
}

body[class*="kor-ui-"] dialog.pw-saved-dialog {
  width: var(--fm-modal-width-sm, min(92vw, 520px));
  max-width: var(--fm-modal-width-sm, min(92vw, 520px));
}
