/*
 * Legacy parity layer (icon nav retained, layout alignment, compact density).
 * Scoped to legacy theme to avoid cross-theme side effects.
 */

body[data-theme='legacy'] {
  --page-max-width: 100%;

  --layout-text: #1a2233;
  --layout-muted: #4b5563;
  --layout-surface: #f5f7fc;
  --layout-surface-strong: #ffffff;
  --layout-surface-muted: #e5edff;
  --layout-border: rgba(110, 135, 168, 0.45);
  --layout-accent: #4b73c4;
  --layout-accent-soft: rgba(75, 115, 196, 0.16);
  --layout-focus-ring: 0 0 0 3px rgba(75, 115, 196, 0.35);

  --table-font-size: 0.88rem;
  --table-font-size-dense: 0.82rem;
  --table-header-font-size: 0.86rem;
  --table-cell-padding-y: 0.25rem;
  --table-cell-padding-x: 0.45rem;
  --table-header-padding-y: 0.3rem;
  --table-header-padding-x: 0.45rem;
  --table-border-color: rgba(110, 135, 168, 0.45);
  --table-border-color-strong: rgba(110, 135, 168, 0.55);
  --table-header-bg: #d7e3ff;
  --table-row-zebra: rgba(232, 238, 252, 0.8);
  --table-row-hover: rgba(110, 168, 254, 0.28);
  --table-wrapper-bg: #ffffff;
  --table-wrapper-border: rgba(110, 135, 168, 0.45);
  --table-radius: 8px;

  /* Form-Layout Tokens (Tiersuchmaske als Referenz) */
  --form-label-width: clamp(120px, 16vw, 160px);
  --form-label-min: 110px;
  --form-label-max: 180px;
  --form-control-min: 140px;
  --form-control-max: 320px;
  --form-control-width: clamp(var(--form-control-min), 22vw, var(--form-control-max));
  --form-inline-control-min: 120px;
  --form-inline-control-max: 220px;
  --form-inline-control-width: clamp(
    var(--form-inline-control-min),
    16vw,
    var(--form-inline-control-max)
  );
  --form-inline-select-min: 90px;
  --form-inline-select-max: 140px;
  --form-inline-select-width: clamp(
    var(--form-inline-select-min),
    10vw,
    var(--form-inline-select-max)
  );
  --form-paired-label-min: 150px;
  --form-paired-label-max: 220px;
  --form-paired-label-width: clamp(
    var(--form-paired-label-min),
    18vw,
    var(--form-paired-label-max)
  );
  --form-paired-control-min: 110px;
  --form-paired-control-max: 170px;
  --form-paired-control-width: clamp(
    var(--form-paired-control-min),
    16vw,
    var(--form-paired-control-max)
  );
  --form-gap-width: 12px;
  --form-cell-padding-v: 0.2rem;
  --form-cell-padding-h: 0.35rem;
  --form-font-size: 0.875rem;
  --form-input-height: 24px;
  --form-panel-bg: #f7efe1;
  --form-panel-border: #e2d6c6;
  --form-panel-radius: 6px;
  --form-label-bg: #dfe9fb;
  --form-control-bg: #ffffff;
  --form-cell-radius: 4px;

  --animals-surface: #f8f1e6;
  --animals-surface-strong: #f2e5d4;
  --animals-focus-ring: rgba(139, 94, 60, 0.25);
  --color-primary: #8b5e3c;
  --color-primary-light: #caa77a;
  --color-primary-dark: #7a4f32;
  --color-primary-darker: #6a432b;
  --gradient-tab-active: linear-gradient(135deg, #d3b48d 0%, #8b5e3c 100%);
  --gradient-button-primary: linear-gradient(135deg, #b67a4d 0%, #8b5e3c 100%);
  --gradient-button-hover: linear-gradient(135deg, #9b653f 0%, #7a4f32 100%);
  --nav-active-bg: #8b5e3c;
  --accent: #8b5e3c;
  --focus: #8b5e3c;

  line-height: 1.2;
}

body[data-theme='legacy'].app-layout {
  background: #eef1f7;
  color: #1a2233;
}

body[data-theme='legacy'].wide-desktop {
  --page-spacing: 1rem;
  --page-gap: 0.6rem;
  --page-radius: 8px;
  --page-border: #b6c6e2;
  --page-surface: #ffffff;
  --page-shadow: 0 8px 18px rgba(30, 45, 70, 0.18);
}

body[data-theme='legacy'].wide-desktop .app-main__viewport {
  padding: 8px 10px;
  gap: 6px;
  display: block;
  overflow-y: auto !important;
  overflow-x: hidden;
  scrollbar-width: auto;
  scrollbar-gutter: stable both-edges;
}

body[data-theme='legacy'].wide-desktop .app-main__viewport::-webkit-scrollbar {
  width: 12px;
}

body[data-theme='legacy'].wide-desktop .app-main__viewport::-webkit-scrollbar-thumb {
  background: rgba(111, 127, 156, 0.55);
  border-radius: 999px;
}

body[data-theme='legacy'].wide-desktop .page-surface {
  gap: 8px;
}

body[data-theme='legacy'].wide-desktop .page-content {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: 10px 12px;
  border: 1px solid var(--page-border);
  border-radius: var(--page-radius);
  background: var(--page-surface);
  box-shadow: var(--page-shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow-x: hidden;
}

body[data-theme='legacy'].wide-desktop #content {
  max-height: none !important;
  overflow: visible !important;
}

body[data-theme='legacy'] #content,
body.theme-legacy #content,
body[data-theme='legacy'] .page-content,
body.theme-legacy .page-content {
  min-height: 0 !important;
  height: auto !important;
}

body[data-theme='legacy']:not(.is-mobile-portrait) #content table[data-layout='form-legacy'],
body.theme-legacy:not(.is-mobile-portrait) #content table[data-layout='form-legacy'],
body[data-theme='legacy']:not(.is-mobile-portrait) #content .params-table,
body.theme-legacy:not(.is-mobile-portrait) #content .params-table {
  display: table !important;
  table-layout: fixed;
}

body[data-theme='legacy']:not(.is-mobile-portrait) #content table[data-layout='form-legacy'] tr,
body.theme-legacy:not(.is-mobile-portrait) #content table[data-layout='form-legacy'] tr,
body[data-theme='legacy']:not(.is-mobile-portrait) #content .params-table tr,
body.theme-legacy:not(.is-mobile-portrait) #content .params-table tr {
  display: table-row !important;
}

body[data-theme='legacy']:not(.is-mobile-portrait) #content table[data-layout='form-legacy'] td,
body.theme-legacy:not(.is-mobile-portrait) #content table[data-layout='form-legacy'] td,
body[data-theme='legacy']:not(.is-mobile-portrait) #content .params-table td,
body.theme-legacy:not(.is-mobile-portrait) #content .params-table td,
body[data-theme='legacy']:not(.is-mobile-portrait) #content table[data-layout='form-legacy'] th,
body.theme-legacy:not(.is-mobile-portrait) #content table[data-layout='form-legacy'] th,
body[data-theme='legacy']:not(.is-mobile-portrait) #content .params-table th,
body.theme-legacy:not(.is-mobile-portrait) #content .params-table th {
  display: table-cell !important;
}

body[data-theme='legacy'].wide-desktop .page-content__actions {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: 0 14px 12px;
}

body[data-theme='legacy'] .app-header__breadcrumbs {
  max-width: var(--page-max-width);
  margin: 0 auto;
}

body[data-theme='legacy'] .ct-header__inner {
  max-width: none !important;
  width: 100%;
  margin: 0 !important;
  padding: 0 18px;
  min-height: 58px;
  justify-content: flex-start !important;
  gap: 18px;
}

body[data-theme='legacy'] .app-header__breadcrumbs {
  padding: 10px 18px 12px !important;
  margin-top: 12px !important;
}

/* Override ui-fixes modal link colors (uses !important) to keep labels visible */
body[data-theme='legacy'] .ct-modal__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.5rem;
  border-radius: 999px;
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  color: #475569 !important;
  font-weight: 600;
  text-decoration: none;
  min-width: 200px;
}

body[data-theme='legacy'] .ct-modal__link:hover,
body[data-theme='legacy'] .ct-modal__link:focus-visible {
  background: #f8fafc !important;
  border-color: #94a3b8 !important;
  color: #1e293b !important;
}

body[data-theme='legacy'] .page-surface {
  max-width: var(--page-max-width);
  margin: 0 auto;
  width: 100%;
}

body[data-theme='legacy'] #toptabs {
  margin: 4px 0 8px;
  padding: 0;
}

body[data-theme='legacy'] #toptabs:empty {
  display: none;
}

body[data-theme='legacy'] #toptabs.tab-strip--empty {
  display: none !important;
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

body[data-theme='legacy'] #toptabs .nav-tabs {
  gap: 6px;
}

body[data-theme='legacy'] #toptabs .nav-tabs a {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #b6c6e2;
  background: #e8efff;
  color: #1a2233;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: none;
}

body[data-theme='legacy'] #toptabs .nav-tabs a.active {
  background: #bcd0f3;
  border-color: #8fa7dc;
  color: #101c2f;
  box-shadow: inset 0 -2px 0 rgba(55, 80, 130, 0.45);
}

body[data-theme='legacy'] #content > div[id^='tab'] {
  padding: 4px;
}

/* Restore pill-shaped icon nav (override final-fixes.css) */
body[data-theme='legacy'] #main_nav,
body[data-theme='legacy'] .ct-main-nav {
  width: auto !important;
  max-width: 100% !important;
  flex: 0 1 auto !important;
  min-width: 0;
  justify-content: flex-start !important;
  margin-left: 0 !important;
}

body[data-theme='legacy'] #main_nav {
  background: linear-gradient(180deg, #2f3540 0%, #262b33 100%) !important;
  border-radius: 999px !important;
  padding: 4px 10px !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 14px 30px rgba(12, 16, 24, 0.55) !important;
  margin-right: auto;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(124, 184, 255, 0.6) transparent;
  justify-content: flex-start !important;
}

body[data-theme='legacy'] .ct-main-nav__list,
body[data-theme='legacy'] .main-nav__list {
  margin-left: 0 !important;
  padding-left: 8px;
  padding-right: 8px;
}

body[data-theme='legacy'] .ct-main-nav__link,
body[data-theme='legacy'] .main-nav__link,
body[data-theme='legacy'] .main-nav__sublink {
  border-radius: 999px !important;
  border: 1px solid transparent !important;
  border-bottom: 1px solid transparent !important;
  background: transparent !important;
  padding: 8px 14px !important;
  transform: none !important;
}

body[data-theme='legacy'] .ct-main-nav__item.is-active > .ct-main-nav__link,
body[data-theme='legacy'] .main-nav__item.is-active > .main-nav__link {
  background: linear-gradient(
    180deg,
    rgba(124, 184, 255, 0.9) 0%,
    rgba(90, 152, 228, 0.85) 100%
  ) !important;
  color: #10141d !important;
  border-color: rgba(124, 184, 255, 0.75) !important;
  box-shadow: 0 8px 18px rgba(26, 64, 110, 0.45) !important;
}

body[data-theme='legacy'] .ct-main-nav__link:hover,
body[data-theme='legacy'] .ct-main-nav__link:focus-visible,
body[data-theme='legacy'] .main-nav__link:hover,
body[data-theme='legacy'] .main-nav__link:focus-visible {
  background: rgba(148, 163, 184, 0.24) !important;
  color: #ffffff !important;
  border-color: rgba(124, 184, 255, 0.4) !important;
}

body[data-theme='legacy'] .main-nav__sublink:hover,
body[data-theme='legacy'] .main-nav__sublink:focus-visible,
body[data-theme='legacy'] .ct-dropdown-link:hover,
body[data-theme='legacy'] .ct-dropdown-link:focus-visible {
  background: rgba(230, 220, 205, 0.92) !important;
  color: #3c3020 !important;
  box-shadow: inset 3px 0 0 rgba(230, 220, 205, 0.95) !important;
  border-left: 3px solid rgba(230, 220, 205, 0.95) !important;
}

body[data-theme='legacy'] .ct-header__actions {
  margin-left: auto;
  flex: 0 0 auto;
}

body[data-theme='legacy'] .ct-header__nav {
  flex: 1 1 auto;
  min-width: 0;
  margin-right: auto;
}

body[data-theme='legacy'] .ct-main-nav__list,
body[data-theme='legacy'] .main-nav__list,
body.theme-legacy .ct-main-nav__list,
body.theme-legacy .main-nav__list {
  justify-content: flex-start !important;
  align-items: center;
}

body[data-theme='legacy'] .ct-main-nav__list,
body.theme-legacy .ct-main-nav__list {
  min-width: 0;
}

/* Legacy icon nav: keep icons visible, disable icon->text hover transform from ui-fixes */
body[data-theme='legacy'] .ct-main-nav__item .ct-main-nav__icon,
body[data-theme='legacy'] .main-nav__item .main-nav__icon,
body.theme-legacy .ct-main-nav__item .ct-main-nav__icon,
body.theme-legacy .main-nav__item .main-nav__icon {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  opacity: 1 !important;
  max-width: none !important;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  min-height: 40px !important;
  margin-right: 0 !important;
}

body[data-theme='legacy'] .ct-main-nav__item .ct-main-nav__label,
body[data-theme='legacy'] .main-nav__item .main-nav__label,
body[data-theme='legacy'] .ct-main-nav__item:hover .ct-main-nav__label,
body[data-theme='legacy'] .ct-main-nav__item:focus-within .ct-main-nav__label,
body[data-theme='legacy'] .main-nav__item:hover .main-nav__label,
body[data-theme='legacy'] .main-nav__item:focus-within .main-nav__label,
body[data-theme='legacy'] .ct-main-nav__item.is-active .ct-main-nav__label,
body[data-theme='legacy'] .main-nav__item.is-active .main-nav__label,
body.theme-legacy .ct-main-nav__item .ct-main-nav__label,
body.theme-legacy .main-nav__item .main-nav__label,
body.theme-legacy .ct-main-nav__item:hover .ct-main-nav__label,
body.theme-legacy .ct-main-nav__item:focus-within .ct-main-nav__label,
body.theme-legacy .main-nav__item:hover .main-nav__label,
body.theme-legacy .main-nav__item:focus-within .main-nav__label,
body.theme-legacy .ct-main-nav__item.is-active .ct-main-nav__label,
body.theme-legacy .main-nav__item.is-active .main-nav__label {
  max-width: 0 !important;
  opacity: 0 !important;
  margin-left: 0 !important;
  overflow: hidden !important;
}

body[data-theme='legacy'] .ct-main-nav__item.is-active .ct-main-nav__icon,
body[data-theme='legacy'] .main-nav__item.is-active .main-nav__icon,
body.theme-legacy .ct-main-nav__item.is-active .ct-main-nav__icon,
body.theme-legacy .main-nav__item.is-active .main-nav__icon {
  opacity: 1 !important;
  max-width: none !important;
}

body[data-theme='legacy'] .main-nav__submenu a,
body[data-theme='legacy'] .ct-dropdown-link,
body[data-theme='legacy'] .main-nav__sublink {
  position: relative;
}

body[data-theme='legacy'] .main-nav__submenu a[aria-current='page'],
body[data-theme='legacy'] .main-nav__submenu a.is-current,
body[data-theme='legacy'] .main-nav__submenu-item.is-active > a,
body[data-theme='legacy'] .ct-dropdown-item.is-active > .ct-dropdown-link,
body[data-theme='legacy'] .ct-dropdown-link[aria-current='page'],
body[data-theme='legacy'] .ct-dropdown-link.is-current,
body[data-theme='legacy'] .main-nav__sublink[aria-current='page'] {
  box-shadow: inset 3px 0 0 rgba(230, 220, 205, 0.9) !important;
  background: rgba(230, 220, 205, 0.16) !important;
}

/* Verwaltung: kompaktere Dropdown-Breiten und funktionierender Left-Flip */
@media (min-width: 1025px) {
  body[data-theme='legacy'] .main-nav__submenu,
  body[data-theme='legacy'] .dropdown-menu,
  body[data-theme='legacy'] .ct-dropdown {
    width: max-content !important;
    min-width: 190px !important;
    max-width: min(320px, calc(100vw - 32px)) !important;
    padding: 0.2rem 0 !important;
  }

  body[data-theme='legacy'] .main-nav__submenu-item > a,
  body[data-theme='legacy'] .ct-dropdown-item > a,
  body[data-theme='legacy'] .dropdown-menu a,
  body[data-theme='legacy'] .main-nav__submenu .main-nav__sublink,
  body[data-theme='legacy'] .main-nav__submenu .ct-dropdown-link,
  body.theme-legacy .main-nav__submenu-item > a,
  body.theme-legacy .ct-dropdown-item > a,
  body.theme-legacy .dropdown-menu a,
  body.theme-legacy .main-nav__submenu .main-nav__sublink,
  body.theme-legacy .main-nav__submenu .ct-dropdown-link {
    padding: 0.42rem 0.72rem !important;
    line-height: 1.2;
    white-space: nowrap !important;
    word-break: normal;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    border-radius: 6px !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  body[data-theme='legacy'] .dropdown-submenu > .main-nav__submenu,
  body[data-theme='legacy'] .dropdown-submenu > .dropdown-menu {
    left: 100% !important;
    right: auto !important;
    margin-left: 2px !important;
    margin-right: 0 !important;
  }

  body[data-theme='legacy'] .dropdown-submenu > .main-nav__submenu.align-left,
  body[data-theme='legacy'] .dropdown-submenu > .dropdown-menu.align-left {
    left: auto !important;
    right: 100% !important;
    margin-left: 0 !important;
    margin-right: 2px !important;
  }
}

body[data-theme='legacy'] #buttons,
body.theme-legacy #buttons {
  max-width: var(--page-max-width);
  margin: 4px 0 10px;
  padding: 0 12px;
  text-align: left !important;
  display: block;
  visibility: visible;
  opacity: 1;
  width: 100%;
}

body[data-theme='legacy'].wide-desktop #buttons,
body.theme-legacy.wide-desktop #buttons {
  display: block;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  justify-content: flex-start;
}

body[data-theme='legacy'].wide-desktop #buttons ul,
body.theme-legacy.wide-desktop #buttons ul {
  justify-content: flex-start;
}

body[data-theme='legacy'] #bottomtabs,
body.theme-legacy #bottomtabs,
body[data-theme='legacy'] #buttons,
body.theme-legacy #buttons {
  position: static !important;
  background: transparent !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

body[data-theme='legacy'] #bottomtabs,
body.theme-legacy #bottomtabs {
  max-width: var(--page-max-width);
  margin: 0 auto 12px;
  padding: 0 12px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  overflow: visible;
}

body[data-theme='legacy'] #bottomtabs ul,
body.theme-legacy #bottomtabs ul {
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
}

body[data-theme='legacy'] #buttons ul,
body.theme-legacy #buttons ul {
  margin: 0;
  display: flex;
  justify-content: flex-start !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

body[data-theme='legacy'] .page-content__actions--animals,
body.theme-legacy .page-content__actions--animals {
  margin: 10px auto 0;
  padding: 0 12px 12px;
  max-width: var(--page-max-width);
  background: transparent;
  border-bottom: none;
  display: block !important;
  text-align: left !important;
}

body[data-theme='legacy'] .page-content__actions--animals #buttons,
body.theme-legacy .page-content__actions--animals #buttons {
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
  width: 100% !important;
  text-align: left !important;
}

body[data-theme='legacy'] .page-content__actions--animals #buttons ul,
body.theme-legacy .page-content__actions--animals #buttons ul {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  width: auto;
}

/* Paired layouts (e.g. Verpaarungssuche): balance label/control columns */
body[data-theme='legacy'] .params-table--paired,
body.theme-legacy .params-table--paired {
  --form-paired-label-min: 170px;
  --form-paired-label-max: 240px;
  --form-paired-control-min: 100px;
  --form-paired-control-max: 150px;
}

/* Verpaarungen - Neue Verpaarung: keep legacy paired form readable and aligned. */
body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy'],
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy'] {
  table-layout: auto !important;
  width: 100% !important;
  max-width: 100%;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td[colspan],
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td[colspan] {
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:first-child:not([colspan]),
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:first-child:not([colspan]) {
  width: clamp(160px, 17vw, 220px) !important;
  min-width: 160px !important;
  max-width: 220px !important;
  white-space: nowrap;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td.cell-inline,
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td.cell-inline {
  display: flex !important;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  min-width: 0;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td.cell-inline
  > :is(input, select, textarea),
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td.cell-inline
  > :is(input, select, textarea) {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  width: auto !important;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td.cell-inline
  > .find,
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td.cell-inline
  > .find {
  flex: 0 0 auto !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  min-width: 1.75rem;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper,
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.24rem;
  width: auto;
  max-width: 100%;
  min-width: 0;
  vertical-align: middle;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > input.iso-date-input,
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > input.iso-date-input {
  flex: 0 1 12ch !important;
  width: 12ch !important;
  min-width: 11ch !important;
  max-width: 13ch !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > button.iso-date-icon,
body.theme-legacy[data-command='animals_breedings'][data-subcommand='save']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > button.iso-date-icon {
  flex: 0 0 1.55rem;
  width: 1.55rem;
  min-width: 1.55rem;
  height: 1.55rem;
  min-height: 1.55rem;
  margin-left: 0 !important;
  padding: 0 !important;
  line-height: 1.55rem;
  box-sizing: border-box;
}

/* Verpaarungssuche: "Welche Verpaarungen anzeigen?" vollständig lesbar halten */
body[data-theme='legacy'][data-command='animals_breedings'] .breeding-current-only-label,
body.theme-legacy[data-command='animals_breedings'] .breeding-current-only-label {
  min-width: 220px;
  width: 220px;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

body[data-theme='legacy'][data-command='animals_breedings'] .breeding-current-only-label label,
body.theme-legacy[data-command='animals_breedings'] .breeding-current-only-label label {
  display: block;
  width: 100%;
  max-width: none;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: normal;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

body[data-theme='legacy'][data-command='animals_breedings'] .breeding-current-only-control select,
body.theme-legacy[data-command='animals_breedings'] .breeding-current-only-control select {
  min-width: 210px;
  max-width: 100%;
}

/* Align legacy form tables a bit tighter */
body[data-theme='legacy'] table.fbi-form td {
  padding: 0.25rem 0.4rem;
  line-height: 1.15;
}

body[data-theme='legacy'] .app-main table {
  font-size: var(--table-font-size);
  line-height: 1.05;
}

body[data-theme='legacy'] .app-main table thead th {
  padding: var(--table-header-padding-y) var(--table-header-padding-x);
  font-size: var(--table-header-font-size);
  text-transform: none;
  white-space: normal;
}

body[data-theme='legacy'] .app-main table tbody td {
  padding: var(--table-cell-padding-y) var(--table-cell-padding-x);
  line-height: 1.05;
}

body[data-theme='legacy'] .app-main table thead th,
body[data-theme='legacy'] .app-main table tbody td {
  border-bottom-width: 1px;
}

body[data-theme='legacy'] .app-main table tbody tr {
  height: 1.3em;
}

body[data-theme='legacy'] .ct-form {
  gap: 8px 12px;
}

body[data-theme='legacy'] .ct-field {
  gap: 4px;
}

body[data-theme='legacy'] .inline-controls {
  gap: 0.4rem;
}

body[data-theme='legacy'] .breadcrumbs,
body[data-theme='legacy'] .app-header__breadcrumbs {
  line-height: 1.2;
}

/* Tasks: action links + priority selects */
body[data-theme='legacy'] .task-link-action,
body.theme-legacy .task-link-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 150px;
  padding: 0.25rem 0.65rem;
}

body[data-theme='legacy'] select.task-priority-select,
body.theme-legacy select.task-priority-select {
  width: 52px;
  min-width: 52px;
  box-sizing: border-box;
}

/* Actions alignment: keep execute buttons left with page content */
body[data-theme='legacy'] .page-content__actions,
body.theme-legacy .page-content__actions,
body[data-theme='legacy'] .page-content__actions--animals,
body.theme-legacy .page-content__actions--animals {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: 0 12px 6px;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0.4rem;
  flex: 0 0 auto;
  min-height: 0;
  height: auto;
  align-self: stretch;
  min-width: 0;
  background: transparent;
}

body[data-theme='legacy'] .page-content__actions--stacked,
body.theme-legacy .page-content__actions--stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

body[data-theme='legacy'] .page-content__actions--with-extras,
body.theme-legacy .page-content__actions--with-extras {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 0.65rem;
}

body[data-theme='legacy'] .page-content__actions--with-extras #buttons,
body.theme-legacy .page-content__actions--with-extras #buttons {
  grid-column: 1;
  justify-self: start;
  width: auto !important;
  min-width: 0;
}

body[data-theme='legacy'] .page-content__actions--with-extras #buttons ul,
body.theme-legacy .page-content__actions--with-extras #buttons ul {
  flex-wrap: nowrap;
}

body[data-theme='legacy'] .page-content__actions--with-extras #bottomtabs,
body.theme-legacy .page-content__actions--with-extras #bottomtabs {
  grid-column: 3;
  justify-self: center;
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
  width: auto !important;
}

body[data-theme='legacy'] .page-content__actions--with-extras #bottomtabs ul,
body.theme-legacy .page-content__actions--with-extras #bottomtabs ul {
  flex-wrap: nowrap;
}

body[data-theme='legacy'] #buttons,
body.theme-legacy #buttons,
body[data-theme='legacy'] #buttons ul,
body.theme-legacy #buttons ul {
  justify-content: flex-start;
}

body[data-theme='legacy'] .page-content__actions #buttons,
body.theme-legacy .page-content__actions #buttons {
  margin: 0 !important;
  padding: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  display: block !important;
  margin-left: 0 !important;
  margin-right: auto !important;
  align-self: flex-start;
}

body[data-theme='legacy']
  :is(
    #buttons a.button,
    #buttons input.button,
    #buttons input[type='submit'],
    #buttons input[type='button']
  ),
body.theme-legacy
  :is(
    #buttons a.button,
    #buttons input.button,
    #buttons input[type='submit'],
    #buttons input[type='button']
  ),
body[data-theme='legacy']
  .page-content__actions
  :is(a.button, input.button, input[type='submit'], input[type='button']),
body.theme-legacy
  .page-content__actions
  :is(a.button, input.button, input[type='submit'], input[type='button']) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  text-align: center;
  min-height: 34px;
  box-sizing: border-box;
}

/* Zusatzbuttons unterhalb von Execute: gleiche Blautoene */
body[data-theme='legacy'] #bottomtabs a,
body.theme-legacy #bottomtabs a {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
  border: 1px solid #1d4ed8 !important;
  color: #ffffff !important;
}

body[data-theme='legacy'] #bottomtabs a:hover,
body.theme-legacy #bottomtabs a:hover,
body[data-theme='legacy'] #bottomtabs a:focus-visible,
body.theme-legacy #bottomtabs a:focus-visible {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
}

/* Tabellen-Wrapper: keine Vollhoehe, scrollbar sichtbar */
body[data-theme='legacy'] {
  --table-max-height: clamp(240px, 58vh, 620px);
}

body[data-theme='legacy'] .result-table-wrapper,
body[data-theme='legacy'] .table-scroll-x,
body[data-theme='legacy'] .table-wrap,
body[data-theme='legacy'] .table-wrapper,
body[data-theme='legacy'] .virtual-table-wrapper {
  flex: 0 1 auto;
  max-height: var(--table-max-height);
  scrollbar-width: auto;
}

body[data-theme='legacy'] .result-table-wrapper::-webkit-scrollbar,
body[data-theme='legacy'] .table-scroll-x::-webkit-scrollbar,
body[data-theme='legacy'] .table-wrap::-webkit-scrollbar,
body[data-theme='legacy'] .table-wrapper::-webkit-scrollbar,
body[data-theme='legacy'] .virtual-table-wrapper::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

body[data-theme='legacy'] .result-table-wrapper::-webkit-scrollbar-thumb,
body[data-theme='legacy'] .table-scroll-x::-webkit-scrollbar-thumb,
body[data-theme='legacy'] .table-wrap::-webkit-scrollbar-thumb,
body[data-theme='legacy'] .table-wrapper::-webkit-scrollbar-thumb,
body[data-theme='legacy'] .virtual-table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(111, 127, 156, 0.55);
  border-radius: 999px;
}

/* Tabellen-Controls: Dropdowns/OK-Buttons nicht über volle Breite */
body[data-theme='legacy'] table.sortable select,
body.theme-legacy table.sortable select,
body[data-theme='legacy'] table.sortable input[type='button'],
body.theme-legacy table.sortable input[type='button'],
body[data-theme='legacy'] table.sortable input[type='submit'],
body.theme-legacy table.sortable input[type='submit'],
body[data-theme='legacy'] table.sortable button,
body.theme-legacy table.sortable button {
  width: auto;
  max-width: 220px;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body[data-theme='legacy'] select[name$='_action'],
body.theme-legacy select[name$='_action'],
body[data-theme='legacy'] .table-bulk-actions select,
body.theme-legacy .table-bulk-actions select {
  width: auto;
  max-width: 260px;
  min-width: 120px;
}

body[data-theme='legacy'] input[name='bt_ok'],
body.theme-legacy input[name='bt_ok'],
body[data-theme='legacy'] .table-bulk-actions .button,
body.theme-legacy .table-bulk-actions .button {
  width: auto;
  min-width: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body[data-theme='legacy'] input[type='text'],
body.theme-legacy input[type='text'],
body[data-theme='legacy'] input[type='email'],
body.theme-legacy input[type='email'],
body[data-theme='legacy'] input[type='password'],
body.theme-legacy input[type='password'],
body[data-theme='legacy'] input[type='number'],
body.theme-legacy input[type='number'],
body[data-theme='legacy'] input[type='date'],
body.theme-legacy input[type='date'],
body[data-theme='legacy'] input[type='search'],
body.theme-legacy input[type='search'],
body[data-theme='legacy'] select,
body.theme-legacy select,
body[data-theme='legacy'] textarea,
body.theme-legacy textarea {
  background-color: #ffffff;
}

body[data-theme='legacy'] input[type='text']:focus,
body.theme-legacy input[type='text']:focus,
body[data-theme='legacy'] input[type='email']:focus,
body.theme-legacy input[type='email']:focus,
body[data-theme='legacy'] input[type='password']:focus,
body.theme-legacy input[type='password']:focus,
body[data-theme='legacy'] input[type='number']:focus,
body.theme-legacy input[type='number']:focus,
body[data-theme='legacy'] input[type='date']:focus,
body.theme-legacy input[type='date']:focus,
body[data-theme='legacy'] input[type='search']:focus,
body.theme-legacy input[type='search']:focus,
body[data-theme='legacy'] select:focus,
body.theme-legacy select:focus,
body[data-theme='legacy'] textarea:focus,
body.theme-legacy textarea:focus {
  background-color: #ffffff;
}

body[data-theme='legacy'] input.field-error:not([type='checkbox']):not([type='radio']),
body.theme-legacy input.field-error:not([type='checkbox']):not([type='radio']),
body[data-theme='legacy'] select.field-error,
body.theme-legacy select.field-error,
body[data-theme='legacy'] textarea.field-error,
body.theme-legacy textarea.field-error,
body[data-theme='legacy'] input.input_red:not([type='checkbox']):not([type='radio']),
body.theme-legacy input.input_red:not([type='checkbox']):not([type='radio']),
body[data-theme='legacy'] select.input_red,
body.theme-legacy select.input_red,
body[data-theme='legacy'] textarea.input_red,
body.theme-legacy textarea.input_red {
  background: #ffe0e0;
  border-color: #cc0000;
}

body[data-theme='legacy'] #buttons[hidden],
body.theme-legacy #buttons[hidden],
body[data-theme='legacy'] #bottomtabs[hidden],
body.theme-legacy #bottomtabs[hidden] {
  display: block !important;
}

body[data-theme='legacy'] .access-table th,
body.theme-legacy .access-table th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ===== Legacy UI: Compact Density (Phase 2) ===== */
body[data-theme='legacy'][data-density='compact'] {
  --table-cell-padding-y: 0.2rem;
  --table-cell-padding-x: 0.4rem;
  --table-header-padding-y: 0.28rem;
  --table-header-padding-x: 0.45rem;
  --table-font-size: 0.84rem;
  --table-header-font-size: 0.84rem;
  --form-cell-padding-v: 0.08rem;
  --form-cell-padding-h: 0.2rem;
  --form-font-size: 0.84rem;
  --form-input-height: 20px;
  --form-gap-width: 8px;
}

body[data-theme='legacy'][data-density='compact'] .params-panel,
body.theme-legacy[data-density='compact'] .params-panel,
body[data-theme='legacy'][data-density='compact'] .form-panel,
body.theme-legacy[data-density='compact'] .form-panel {
  padding: 0.5rem 0.75rem;
}

body[data-theme='legacy'][data-density='compact'] table[data-layout='form-legacy'],
body.theme-legacy[data-density='compact'] table[data-layout='form-legacy'],
body[data-theme='legacy'][data-density='compact'] .params-table,
body.theme-legacy[data-density='compact'] .params-table {
  border-spacing: 0.1rem 0.06rem;
  line-height: 1.1;
}

body[data-theme='legacy'][data-density='compact']
  table[data-layout='form-legacy']
  input:not([type='checkbox']):not([type='radio']):not([type='button']):not([type='submit']),
body[data-theme='legacy'][data-density='compact'] table[data-layout='form-legacy'] select,
body[data-theme='legacy'][data-density='compact'] table[data-layout='form-legacy'] textarea,
body[data-theme='legacy'][data-density='compact']
  .params-table
  input:not([type='checkbox']):not([type='radio']):not([type='button']):not([type='submit']),
body[data-theme='legacy'][data-density='compact'] .params-table select,
body[data-theme='legacy'][data-density='compact'] .params-table textarea {
  padding: 0.1rem 0.3rem;
}

body[data-theme='legacy'][data-density='compact'] table[data-layout='form-legacy'] td,
body[data-theme='legacy'][data-density='compact'] .params-table td {
  padding: var(--form-cell-padding-v) var(--form-cell-padding-h);
  line-height: 1.05;
}

body[data-theme='legacy'][data-density='compact'] table.fbi-form td {
  padding: 0.15rem 0.3rem;
  line-height: 1.05;
}

/* Animals search: remove extra whitespace under Execute */
body[data-theme='legacy'][data-density='compact'][data-command='animals'] .page-content {
  flex: 0 0 auto !important;
  min-height: 0 !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals'] .app-shell {
  min-height: 0 !important;
  height: auto !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals'] .app-shell__form,
body[data-theme='legacy'][data-density='compact'][data-command='animals'] .app-main,
body[data-theme='legacy'][data-density='compact'][data-command='animals'] .app-main__viewport,
body[data-theme='legacy'][data-density='compact'][data-command='animals'] main {
  flex: 0 0 auto !important;
  min-height: 0 !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .page-content__actions--animals {
  margin-bottom: 4px;
  padding-bottom: 4px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals'] .screen-animals__table {
  border-spacing: 0.08rem 0.04rem;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  td {
  padding: 1px 4px !important;
  line-height: 1.05 !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  input:not([type='checkbox']):not([type='radio']):not([type='button']):not([type='submit']),
body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  select {
  padding: 1px 4px !important;
  height: 22px !important;
  min-height: 22px !important;
  display: inline-block !important;
}

/* Animals search: keep checkbox + control in one line for compact rows */
body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  td:has(input[type='checkbox']) {
  display: table-cell;
  white-space: nowrap;
  vertical-align: middle;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  td:has(input[type='checkbox'])
  input[type='checkbox'] {
  margin-right: 0;
  vertical-align: middle;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  td:has(input[type='checkbox'])
  input[type='text'],
body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  td:has(input[type='checkbox'])
  select {
  display: inline-block;
  vertical-align: middle;
  width: calc(100% - 26px);
  max-width: calc(100% - 26px);
  min-width: 0;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  td
  input[type='checkbox']
  + input[type='text'],
body[data-theme='legacy'][data-density='compact'][data-command='animals']
  .screen-animals__table
  td
  input[type='checkbox']
  + select {
  display: inline-block;
  vertical-align: middle;
  width: calc(100% - 26px);
  max-width: calc(100% - 26px);
}

/* Animals results: keep action icons on one line */
body[data-theme='legacy'] table.animals-result td.col-actions,
body[data-theme='legacy'] table.cages-result td.col-actions {
  white-space: nowrap;
}

body[data-theme='legacy'] table.animals-result .table-actions,
body[data-theme='legacy'] table.cages-result .table-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  white-space: nowrap;
  gap: 0.25rem;
}

body[data-theme='legacy'] table.animals-result .table-actions > *,
body[data-theme='legacy'] table.cages-result .table-actions > * {
  flex: 0 0 auto;
}

body[data-theme='legacy'] table.animals-result,
body[data-theme='legacy'] table.cages-result {
  --table-action-width: 9.5rem;
}

/* Animals results data tab: normalize value font weight (keep headings bold) */
body[data-theme='legacy'][data-density='compact'][data-command='animals'][data-subcommand='found']
  #content
  #tab2
  .params-table
  td,
body[data-theme='legacy'][data-density='compact'][data-command='animals'][data-subcommand='found']
  #content
  #tab2
  .params-table
  td
  * {
  font-weight: 400;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals'][data-subcommand='found']
  #content
  #tab2
  .params-table
  th {
  font-weight: 600;
}

/* Animals create (Tiere -> Neu Erstellen), Data tab: keep mixed legacy table readable. */
body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy'],
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy'] {
  width: 100% !important;
  max-width: 100%;
  table-layout: auto !important;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:first-child:not([colspan]),
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:first-child:not([colspan]),
body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(5):not([colspan]),
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(5):not([colspan]) {
  width: clamp(160px, 16vw, 220px) !important;
  min-width: 160px !important;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(2),
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(2),
body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(6),
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(6) {
  min-width: 0;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(2)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']),
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(2)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']),
body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(6)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']),
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  table.screen-animals-create__table--data[data-layout='form-legacy']
  tr
  > td:nth-child(6)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']) {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='animals_create'] #content #tab1 .animals-create-sex-cell,
body.theme-legacy[data-command='animals_create'] #content #tab1 .animals-create-sex-cell {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.4rem;
  white-space: nowrap;
  min-width: 0;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  .animals-create-sex-cell
  > input[type='radio'],
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  .animals-create-sex-cell
  > input[type='radio'] {
  margin: 0;
  flex: 0 0 auto;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  .animals-create-sex-cell
  > label,
body.theme-legacy[data-command='animals_create'] #content #tab1 .animals-create-sex-cell > label {
  display: inline-flex;
  align-items: center;
  margin: 0;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  .screen-animals-create__table--data
  :is(.iso-date-wrapper, .date-field),
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  .screen-animals-create__table--data
  :is(.iso-date-wrapper, .date-field) {
  display: inline-flex !important;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.25rem;
  max-width: 100%;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  .screen-animals-create__table--data
  :is(.iso-date-wrapper, .date-field)
  > input.iso-date-input,
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  .screen-animals-create__table--data
  :is(.iso-date-wrapper, .date-field)
  > input.iso-date-input {
  flex: 0 1 11.6ch !important;
  width: 11.6ch !important;
  min-width: 11ch !important;
  max-width: 12.8ch !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='animals_create']
  #content
  #tab1
  .screen-animals-create__table--data
  :is(.iso-date-wrapper, .date-field)
  > .iso-date-icon,
body.theme-legacy[data-command='animals_create']
  #content
  #tab1
  .screen-animals-create__table--data
  :is(.iso-date-wrapper, .date-field)
  > .iso-date-icon {
  flex: 0 0 24px;
  width: 24px;
  min-width: 24px;
}

/* Tasks search: align inputs and keep columns consistent */
body[data-theme='legacy'][data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table,
body.theme-legacy[data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table {
  width: 100%;
  table-layout: fixed;
  border-spacing: 0.15rem 0.1rem;
}

/* Tasks search: normalize control heights on the dedicated search table. */
body[data-theme='legacy'][data-command='tasks'] table.tasks-search-table,
body.theme-legacy[data-command='tasks'] table.tasks-search-table {
  --tasks-search-control-height: 28px;
}

body[data-theme='legacy'][data-command='tasks']
  table.tasks-search-table
  :is(input[type='text'], input[type='date'], input[type='number'], select):not([type='hidden']),
body.theme-legacy[data-command='tasks']
  table.tasks-search-table
  :is(input[type='text'], input[type='date'], input[type='number'], select):not([type='hidden']) {
  height: var(--tasks-search-control-height);
  min-height: var(--tasks-search-control-height);
  line-height: 1.2;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='tasks']
  table.tasks-search-table
  :is(.iso-date-wrapper, .date-field),
body.theme-legacy[data-command='tasks']
  table.tasks-search-table
  :is(.iso-date-wrapper, .date-field) {
  min-height: var(--tasks-search-control-height);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

body[data-theme='legacy'][data-command='tasks']
  table.tasks-search-table
  :is(.iso-date-wrapper, .date-field)
  input,
body.theme-legacy[data-command='tasks']
  table.tasks-search-table
  :is(.iso-date-wrapper, .date-field)
  input {
  height: var(--tasks-search-control-height);
  min-height: var(--tasks-search-control-height);
  line-height: 1.2;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='tasks']
  table.tasks-search-table
  :is(.iso-date-wrapper, .date-field)
  .iso-date-icon,
body.theme-legacy[data-command='tasks']
  table.tasks-search-table
  :is(.iso-date-wrapper, .date-field)
  .iso-date-icon {
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
}

body[data-theme='legacy'][data-command='tasks'] table.tasks-search-table :is(a.find, button),
body.theme-legacy[data-command='tasks'] table.tasks-search-table :is(a.find, button) {
  min-height: var(--tasks-search-control-height);
  line-height: 1.2;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(1),
body[data-theme='legacy'][data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(4),
body.theme-legacy[data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(1),
body.theme-legacy[data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(4) {
  width: var(--form-label-width);
  min-width: var(--form-label-min);
}

body[data-theme='legacy'][data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(2),
body[data-theme='legacy'][data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(5),
body.theme-legacy[data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(2),
body.theme-legacy[data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(5) {
  width: var(--form-control-width);
  min-width: var(--form-control-min);
}

body[data-theme='legacy'][data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(3),
body.theme-legacy[data-density='compact'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td:nth-child(3) {
  width: var(--form-gap-width);
}

body[data-theme='legacy'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td.tasks-inline-find-cell,
body.theme-legacy[data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td.tasks-inline-find-cell {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.35rem;
  min-width: 0;
  white-space: nowrap;
}

body[data-theme='legacy'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td.tasks-inline-find-cell
  > :is(input, select):not([type='hidden']),
body.theme-legacy[data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td.tasks-inline-find-cell
  > :is(input, select):not([type='hidden']) {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  max-width: 100%;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td
  input,
body[data-theme='legacy'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td
  select,
body.theme-legacy[data-command='tasks'] .tasks-search-panel table.tasks-search-table td input,
body.theme-legacy[data-command='tasks'] .tasks-search-panel table.tasks-search-table td select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td.tasks-inline-find-cell
  > .find,
body.theme-legacy[data-command='tasks']
  .tasks-search-panel
  table.tasks-search-table
  td.tasks-inline-find-cell
  > .find {
  flex: 0 0 auto;
  width: 1.9rem;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

/* Tasks results: keep right action column visible without horizontal scroll. */
body[data-theme='legacy'][data-command='tasks']
  #tasks-table-container
  .table-scroll-x.result-table-wrapper,
body.theme-legacy[data-command='tasks']
  #tasks-table-container
  .table-scroll-x.result-table-wrapper {
  overflow-x: hidden;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table,
body.theme-legacy[data-command='tasks'] #tasks-result-table {
  width: 100%;
  table-layout: fixed;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table th,
body[data-theme='legacy'][data-command='tasks'] #tasks-result-table td,
body.theme-legacy[data-command='tasks'] #tasks-result-table th,
body.theme-legacy[data-command='tasks'] #tasks-result-table td {
  padding: 0.14rem 0.24rem;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-select,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-select {
  width: 30px;
  min-width: 30px;
  max-width: 30px;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-id,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-id {
  width: 56px;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-status,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-status {
  width: 86px;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-priority,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-priority {
  width: 54px;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-deadline,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-deadline,
body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-issued-on,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-issued-on,
body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-completed-on,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-completed-on {
  width: 84px;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-link-type,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-link-type {
  width: 84px;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-issued-by,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-issued-by,
body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-completed-by,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-completed-by {
  width: 94px;
}

body[data-theme='legacy'][data-command='tasks'] #tasks-result-table :is(th, td).col-action,
body.theme-legacy[data-command='tasks'] #tasks-result-table :is(th, td).col-action {
  width: 62px;
  min-width: 62px;
  max-width: 62px;
  text-align: center;
}

body[data-theme='legacy'][data-command='tasks']
  #tasks-result-table
  :is(.col-name, .col-link-type, .col-issued-by, .col-completed-by),
body.theme-legacy[data-command='tasks']
  #tasks-result-table
  :is(.col-name, .col-link-type, .col-issued-by, .col-completed-by) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-result-action-cell,
body.theme-legacy[data-command='tasks'] .tasks-result-action-cell {
  overflow: visible;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-row-actions,
body.theme-legacy[data-command='tasks'] .tasks-row-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-trigger,
body.theme-legacy[data-command='tasks'] .tasks-privileges-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  min-width: 1.25rem;
  border: 1px solid #6e89b0;
  border-radius: 999px;
  background: #f3f7ff;
  color: #2b4f80;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: help;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-trigger:focus-visible,
body.theme-legacy[data-command='tasks'] .tasks-privileges-trigger:focus-visible {
  outline: 2px solid #3a7bd5;
  outline-offset: 1px;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-tooltip,
body.theme-legacy[data-command='tasks'] .tasks-privileges-tooltip {
  position: fixed;
  z-index: 1400;
  min-width: 240px;
  max-width: min(340px, calc(100vw - 16px));
  padding: 8px 10px;
  border: 1px solid #7f90b2;
  border-radius: 8px;
  background: #f7f9fe;
  box-shadow: 0 10px 20px rgba(27, 46, 76, 0.28);
  color: #1f3657;
  font-size: 0.82rem;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-2px);
  transition:
    opacity 90ms ease-out,
    transform 90ms ease-out;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-tooltip[data-open='true'],
body.theme-legacy[data-command='tasks'] .tasks-privileges-tooltip[data-open='true'] {
  opacity: 1;
  transform: translateY(0);
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-tooltip__section,
body.theme-legacy[data-command='tasks'] .tasks-privileges-tooltip__section {
  margin-bottom: 6px;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-tooltip__section:last-child,
body.theme-legacy[data-command='tasks'] .tasks-privileges-tooltip__section:last-child {
  margin-bottom: 0;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-tooltip__title,
body.theme-legacy[data-command='tasks'] .tasks-privileges-tooltip__title {
  display: block;
  margin-bottom: 2px;
  font-weight: 700;
  color: #17375d;
}

body[data-theme='legacy'][data-command='tasks'] .tasks-privileges-tooltip__row,
body.theme-legacy[data-command='tasks'] .tasks-privileges-tooltip__row {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 6px;
}

/* Tasks results: keep "Rows per page" on one line (desktop) */
@media (min-width: 1200px) {
  body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='search']
    .table-pagination,
  body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks']
    .table-pagination {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.4rem;
  }

  body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='search']
    .table-pagination__controls,
  body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks']
    .table-pagination__controls {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
  }
}

/* Reusable date field primitive: compact ISO input + adjacent picker button. */
body[data-theme='legacy'][data-layout-contract='search-results'] #content .date-field {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.24rem;
  max-width: 100%;
  min-width: 0;
  vertical-align: middle;
}

body[data-theme='legacy'][data-layout-contract='search-results']
  #content
  .date-field
  > input.iso-date-input {
  flex: 0 1 12ch !important;
  width: 12ch !important;
  min-width: 11ch !important;
  max-width: 12.8ch !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-layout-contract='search-results']
  #content
  .date-field
  > .iso-date-icon {
  flex: 0 0 1.55rem;
  width: 1.55rem;
  min-width: 1.55rem;
  height: 1.55rem;
  min-height: 1.55rem;
  margin-left: 0 !important;
  padding: 0 !important;
  line-height: 1.55rem;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-layout-contract='search-results']
  #content
  .date-field
  > .iso-date-hidden {
  position: absolute !important;
  left: -9999px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Paired search masks (Wuerfe + Verpaarungen): keep ISO input fully readable and icon adjacent. */
body[data-theme='legacy'][data-layout-contract='search-results']:is(
    [data-command='animals_litters'][data-subcommand='search'],
    [data-command='animals_breedings'][data-subcommand='search']
  )
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper,
body[data-theme='legacy'][data-layout-contract='search-results']:is(
    [data-command='animals_litters'][data-subcommand='search'],
    [data-command='animals_breedings'][data-subcommand='search']
  )
  #content
  table.params-table--paired[data-layout='form-legacy']
  .date-field {
  display: inline-flex !important;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.24rem;
  width: auto;
  max-width: 100%;
  min-width: 0;
  vertical-align: middle;
}

body[data-theme='legacy'][data-layout-contract='search-results']:is(
    [data-command='animals_litters'][data-subcommand='search'],
    [data-command='animals_breedings'][data-subcommand='search']
  )
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > input.iso-date-input,
body[data-theme='legacy'][data-layout-contract='search-results']:is(
    [data-command='animals_litters'][data-subcommand='search'],
    [data-command='animals_breedings'][data-subcommand='search']
  )
  #content
  table.params-table--paired[data-layout='form-legacy']
  .date-field
  > input.iso-date-input {
  flex: 0 1 12ch !important;
  width: 12ch !important;
  min-width: 11.2ch !important;
  max-width: 12.8ch !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-layout-contract='search-results']:is(
    [data-command='animals_litters'][data-subcommand='search'],
    [data-command='animals_breedings'][data-subcommand='search']
  )
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > button.iso-date-icon,
body[data-theme='legacy'][data-layout-contract='search-results']:is(
    [data-command='animals_litters'][data-subcommand='search'],
    [data-command='animals_breedings'][data-subcommand='search']
  )
  #content
  table.params-table--paired[data-layout='form-legacy']
  .date-field
  > button.iso-date-icon {
  flex: 0 0 1.55rem;
  width: 1.55rem;
  min-width: 1.55rem;
  height: 1.55rem;
  min-height: 1.55rem;
  margin-left: 0 !important;
  padding: 0 !important;
  line-height: 1.55rem;
  box-sizing: border-box;
}

/* Litters search: keep right-side controls aligned/readable in compact density. */
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] {
  --form-paired-label-min: 150px;
  --form-paired-label-max: 240px;
  --form-paired-control-min: 160px;
  --form-paired-control-max: 320px;
  --form-gap-width: 8px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy'] {
  width: 100%;
  table-layout: auto;
  border-spacing: 0.1rem 0.08rem;
  margin: 0;
  max-width: none;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td
  label {
  white-space: normal;
  word-break: normal;
  overflow-wrap: normal;
  padding: 2px 5px !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:has(> input + .find),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:has(> select + .find),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:has(> textarea + .find) {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:has(> input + .find)
  > :is(input, select, textarea),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:has(> select + .find)
  > :is(input, select, textarea),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:has(> textarea + .find)
  > :is(input, select, textarea) {
  flex: 1 1 auto;
  min-width: 0;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td
  .find {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.35rem;
  white-space: nowrap;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td
  input,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td
  select,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td
  textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  height: 26px !important;
  min-height: 26px !important;
  padding: 2px 6px !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td[colspan='3']
  select {
  min-width: 0;
  max-width: 100%;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.24rem;
  width: auto;
  max-width: 100%;
  min-width: 0;
  vertical-align: middle;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  td:has(> .iso-date-wrapper) {
  white-space: nowrap;
  overflow: visible;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > :is(input.iso-date-input, input[type='text']) {
  flex: 0 1 12ch !important;
  width: 12ch !important;
  min-width: 11.2ch !important;
  max-width: 12.8ch !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > button.iso-date-icon {
  flex: 0 0 1.55rem;
  width: 1.55rem;
  min-width: 1.55rem;
  height: 1.55rem;
  min-height: 1.55rem;
  margin-left: 0 !important;
  padding: 0 !important;
  line-height: 1.55rem;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table.params-table--paired[data-layout='form-legacy']
  .iso-date-wrapper
  > input.iso-date-hidden {
  position: absolute !important;
  left: -9999px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Reports: tighter columns in result tables */
body[data-theme='legacy'][data-density='compact'][data-command='reports'] #content table {
  border-collapse: collapse;
  border-spacing: 0.08rem 0.08rem;
  font-size: var(--table-font-size);
}

body[data-theme='legacy'][data-density='compact'][data-command='reports'] #content table th,
body[data-theme='legacy'][data-density='compact'][data-command='reports'] #content table td {
  padding: 0.18rem 0.3rem;
}

/* Shared multi-view pager placement: keep pager in top-right tab band (never overlay content). */
body[data-theme='legacy'] #toptabs.tab-strip--with-pager,
body.theme-legacy #toptabs.tab-strip--with-pager {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex-wrap: nowrap !important;
  gap: 10px;
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager .nav-tabs,
body.theme-legacy #toptabs.tab-strip--with-pager .nav-tabs {
  flex: 1 1 auto;
  min-width: 0;
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager #multi,
body.theme-legacy #toptabs.tab-strip--with-pager #multi {
  position: static !important;
  inset: auto !important;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
  margin: 0 0 0 auto !important;
  padding: 0 !important;
  width: auto;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  z-index: auto !important;
  white-space: nowrap !important;
  overflow: visible !important;
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager #m_view,
body.theme-legacy #toptabs.tab-strip--with-pager #m_view {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center;
  margin: 0;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #c9d7eb;
  border-radius: 8px;
  box-shadow: 0 1px 5px rgba(22, 44, 78, 0.12);
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager #m_view ul,
body.theme-legacy #toptabs.tab-strip--with-pager #m_view ul {
  display: inline-flex !important;
  align-items: center;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager #m_view ul li,
body.theme-legacy #toptabs.tab-strip--with-pager #m_view ul li {
  display: inline-flex !important;
  align-items: center;
  white-space: nowrap;
  margin: 0;
  padding: 0;
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager #m_view ul li:nth-child(2),
body.theme-legacy #toptabs.tab-strip--with-pager #m_view ul li:nth-child(2),
body[data-theme='legacy'] #toptabs.tab-strip--with-pager #m_view ul li.m_view__counter,
body.theme-legacy #toptabs.tab-strip--with-pager #m_view ul li.m_view__counter {
  min-width: 40px;
  justify-content: center;
  font-weight: 700;
  color: #1f3f68;
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager #m_view li a,
body.theme-legacy #toptabs.tab-strip--with-pager #m_view li a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #2f86cd;
  border-radius: 6px;
  background: #3291e8;
  color: #ffffff;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}

body[data-theme='legacy'] #toptabs.tab-strip--with-pager #m_view li a:hover,
body.theme-legacy #toptabs.tab-strip--with-pager #m_view li a:hover {
  background: #2a7fcc;
  border-color: #2a7fcc;
}

/* Litters multi-editor (Wuerfe editieren): keep pager inside panel and preserve non-collapsing label columns */
body[data-theme='legacy'][data-command='animals_litters_edit'] #main,
body.theme-legacy[data-command='animals_litters_edit'] #main {
  position: relative;
}

body[data-theme='legacy'][data-command='animals_litters_edit'] #content > div[id^='tab'],
body.theme-legacy[data-command='animals_litters_edit'] #content > div[id^='tab'] {
  padding-top: 2px;
  padding-bottom: 2px;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe,
body.theme-legacy[data-command='animals_litters_edit'] #tab1 .screen-animals-litters-edit__wurfe {
  width: 100%;
  margin-left: 0 !important;
  margin-right: 0 !important;
  text-align: left;
  overflow-x: hidden;
  padding-top: 0;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table {
  width: 100%;
  margin-top: 0;
  margin-left: 0 !important;
  margin-right: auto !important;
  table-layout: auto;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  tr:first-child,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  tr:first-child {
  display: none;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td,
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  th,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  th {
  padding: 1px 4px;
  line-height: 1.1;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td.screen-animals-litters-edit__label,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td.screen-animals-litters-edit__label {
  width: clamp(118px, 13vw, 168px);
  min-width: 110px;
  white-space: nowrap;
  vertical-align: middle;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td[rowspan]:first-child,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td[rowspan]:first-child {
  width: 15px;
  min-width: 15px;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td.screen-animals-litters-edit__control,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  td.screen-animals-litters-edit__control {
  min-width: 0;
  width: 34%;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  > tbody
  > tr
  > td:nth-child(3),
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  > tbody
  > tr
  > td:nth-child(3),
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  > tbody
  > tr
  > td:nth-child(5),
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  > tbody
  > tr
  > td:nth-child(5) {
  width: 34%;
  min-width: 15rem;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  input[type='text'],
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  input.input,
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  input.input_red,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  input[type='text'],
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  input.input,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  input.input_red {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  min-height: 24px;
  height: 24px;
  padding-top: 1px;
  padding-bottom: 1px;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  select,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  select,
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  textarea,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  textarea,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  textarea {
  min-height: 42px;
  height: 42px;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  .iso-date-wrapper,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  .iso-date-wrapper {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  .iso-date-visible,
body.theme-legacy[data-command='animals_litters_edit']
  #tab1
  .screen-animals-litters-edit__wurfe-table
  .iso-date-visible {
  width: 12ch;
  min-width: 12ch;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #toptabs.tab-strip--with-pager[data-active-tab='tab_wean_inline']
  #multi,
body.theme-legacy[data-command='animals_litters_edit']
  #toptabs.tab-strip--with-pager[data-active-tab='tab_wean_inline']
  #multi,
body[data-theme='legacy'][data-command='animals_litters_edit']
  #toptabs.tab-strip--with-pager[data-active-tab='tab_wean_inline']
  #m_view,
body.theme-legacy[data-command='animals_litters_edit']
  #toptabs.tab-strip--with-pager[data-active-tab='tab_wean_inline']
  #m_view {
  display: none !important;
}

body[data-theme='legacy'][data-command='animals_litters_edit'] .page-content__actions--animals,
body.theme-legacy[data-command='animals_litters_edit'] .page-content__actions--animals {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin-top: 2px;
  padding-top: 4px;
  padding-bottom: 8px;
  background: linear-gradient(180deg, rgba(238, 241, 247, 0) 0%, rgba(238, 241, 247, 0.97) 45%);
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  .page-content__actions--animals
  #buttons,
body.theme-legacy[data-command='animals_litters_edit'] .page-content__actions--animals #buttons {
  margin: 0 !important;
  padding: 0 !important;
}

/* Animals edit data tab (incl. tasks -> "Aufgabe vorbereiten" flow): prevent label collapse and overlaps. */
body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  .screen-animals-edit__data-tab,
body.theme-legacy[data-command='animals_edit'] #content #tab1 .screen-animals-edit__data-tab {
  width: 100%;
  margin: 0;
  text-align: left;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data,
body.theme-legacy[data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data {
  width: 100% !important;
  max-width: 100%;
  table-layout: auto !important;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(1):not([colspan]),
body.theme-legacy[data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(1):not([colspan]),
body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(5):not([colspan]),
body.theme-legacy[data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(5):not([colspan]) {
  width: clamp(150px, 18vw, 220px);
  min-width: 140px;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  vertical-align: middle;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(2),
body.theme-legacy[data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(2),
body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(6),
body.theme-legacy[data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(6) {
  min-width: 0;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(2)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']),
body.theme-legacy[data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(2)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']),
body[data-theme='legacy'][data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(6)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']),
body.theme-legacy[data-command='animals_edit']
  #content
  #tab1
  table.screen-animals-edit__table--data
  tr
  > td:nth-child(6)
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']) {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  :is(
    #tab2 table.screen-animals-edit__table--area,
    #tab3 table.screen-animals-edit__table--genetics
  ),
body.theme-legacy[data-command='animals_edit']
  #content
  :is(
    #tab2 table.screen-animals-edit__table--area,
    #tab3 table.screen-animals-edit__table--genetics
  ) {
  width: 100%;
  max-width: 100%;
  table-layout: auto;
  margin: 0;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  :is(
    #tab2 table.screen-animals-edit__table--area,
    #tab3 table.screen-animals-edit__table--genetics
  )
  tr
  > td:first-child:not([colspan]),
body.theme-legacy[data-command='animals_edit']
  #content
  :is(
    #tab2 table.screen-animals-edit__table--area,
    #tab3 table.screen-animals-edit__table--genetics
  )
  tr
  > td:first-child:not([colspan]) {
  width: clamp(140px, 17vw, 210px);
  min-width: 130px;
  white-space: nowrap;
  vertical-align: middle;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  .screen-animals-edit__inline-find-cell,
body.theme-legacy[data-command='animals_edit'] #content .screen-animals-edit__inline-find-cell {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.35rem;
  min-width: 0;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  .screen-animals-edit__inline-find-cell
  > :is(input, select, textarea):not([type='hidden']),
body.theme-legacy[data-command='animals_edit']
  #content
  .screen-animals-edit__inline-find-cell
  > :is(input, select, textarea):not([type='hidden']) {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  max-width: 100%;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  .screen-animals-edit__inline-find-cell
  > .find,
body.theme-legacy[data-command='animals_edit']
  #content
  .screen-animals-edit__inline-find-cell
  > .find {
  flex: 0 0 auto;
  min-width: 1.9rem;
  height: 1.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  padding: 0 0.35rem;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  .screen-animals-edit__genetics-inline-cell
  > input[type='text'],
body.theme-legacy[data-command='animals_edit']
  #content
  .screen-animals-edit__genetics-inline-cell
  > input[type='text'] {
  flex: 1 1 10rem;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  .screen-animals-edit__genetics-inline-cell
  > select[id^='gene_'][id$='_type'],
body.theme-legacy[data-command='animals_edit']
  #content
  .screen-animals-edit__genetics-inline-cell
  > select[id^='gene_'][id$='_type'] {
  flex: 0 1 8rem;
  min-width: 6.5rem;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  .screen-animals-edit__genotype-history
  .find,
body.theme-legacy[data-command='animals_edit']
  #content
  .screen-animals-edit__genotype-history
  .find {
  min-width: max-content;
  padding: 0 0.5rem;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  :is(
    #tab2 table.screen-animals-edit__table--area,
    #tab3 table.screen-animals-edit__table--genetics
  )
  td,
body.theme-legacy[data-command='animals_edit']
  #content
  :is(
    #tab2 table.screen-animals-edit__table--area,
    #tab3 table.screen-animals-edit__table--genetics
  )
  td {
  padding-top: 1px;
  padding-bottom: 1px;
}

body[data-theme='legacy'][data-command='animals_edit']
  #content
  .screen-animals-edit__genetics-spacer,
body.theme-legacy[data-command='animals_edit'] #content .screen-animals-edit__genetics-spacer {
  padding-top: 2px !important;
  padding-bottom: 2px !important;
  line-height: 0 !important;
  font-size: 0 !important;
}

body[data-theme='legacy'][data-command='animals_edit'] .page-content__actions--animals,
body.theme-legacy[data-command='animals_edit'] .page-content__actions--animals {
  position: sticky;
  bottom: 0;
  z-index: 8;
  margin-top: 2px;
  padding-top: 2px;
  padding-bottom: 6px;
  background: linear-gradient(180deg, rgba(238, 241, 247, 0) 0%, rgba(238, 241, 247, 0.96) 45%);
}

/* Litters save confirmation: keep question and Yes/No controls visible */
body[data-theme='legacy'][data-command='animals_litters_edit'][data-subcommand='save']
  .litters-save-confirm,
body.theme-legacy[data-command='animals_litters_edit'][data-subcommand='save']
  .litters-save-confirm {
  max-width: 620px;
  margin: 8px 12px 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #c8d6eb;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(22, 44, 78, 0.12);
}

body[data-theme='legacy'][data-command='animals_litters_edit'][data-subcommand='save']
  .litters-save-confirm__text,
body.theme-legacy[data-command='animals_litters_edit'][data-subcommand='save']
  .litters-save-confirm__text {
  margin-bottom: 8px;
  font-weight: 600;
  color: #1f3f68;
}

body[data-theme='legacy'][data-command='animals_litters_edit'][data-subcommand='save']
  .litters-save-confirm__actions,
body.theme-legacy[data-command='animals_litters_edit'][data-subcommand='save']
  .litters-save-confirm__actions {
  display: inline-flex;
  gap: 8px;
}

/* Legacy menu hover labels (env gated) */
@media (min-width: 1025px) {
  body[data-theme='legacy'][data-menu-hover-labels='1'] .ct-main-nav__item,
  body[data-theme='legacy'][data-menu-hover-labels='1'] .main-nav__item {
    position: relative;
  }

  body[data-theme='legacy'][data-menu-hover-labels='1'] .ct-main-nav__item::after,
  body[data-theme='legacy'][data-menu-hover-labels='1'] .main-nav__item::after {
    content: attr(data-menu-label);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 8px;
    padding: 4px 8px;
    background: rgba(20, 24, 32, 0.92);
    color: #ffffff;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
    transition:
      opacity 0.18s ease,
      transform 0.18s ease;
    z-index: 5;
  }

  body[data-theme='legacy'][data-menu-hover-labels='1'] .ct-main-nav__item:hover::after,
  body[data-theme='legacy'][data-menu-hover-labels='1'] .ct-main-nav__item:focus-within::after,
  body[data-theme='legacy'][data-menu-hover-labels='1'] .main-nav__item:hover::after,
  body[data-theme='legacy'][data-menu-hover-labels='1'] .main-nav__item:focus-within::after {
    opacity: 1;
    transform: translate(0, -50%);
  }
}

/* ===== Targeted Contract Pass 2026-02-24 ===== */

/* Animals search/results forms: use width more effectively and keep controls inside cells */
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals.params-panel,
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animalsn.params-panel {
  max-width: min(96rem, 100%);
  margin-inline: auto;
  padding: 0.5rem 0.7rem;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics) {
  --animals-right-control-width: clamp(11.5rem, 22vw, 16rem);
  --form-control-min: 11.5rem;
  --form-control-max: 16rem;
  --form-control-width: var(--animals-right-control-width);
  table-layout: auto !important;
  width: 100% !important;
  max-width: 100% !important;
}

/* Reusable primitive: checkbox + control stay on one row without overflow. */
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table
  td:has(> input[type='checkbox']),
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table
  td.check-control-row,
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table
  td.cell-inline {
  display: flex !important;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.35rem;
  min-width: 0;
  overflow: hidden;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table
  td:has(> input[type='checkbox'])
  > input[type='checkbox'] {
  flex: 0 0 auto;
  margin: 0 !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table
  td:has(> input[type='checkbox'])
  > :is(input, select, textarea):not([type='checkbox']):not([type='radio']):not([type='hidden']),
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table
  td:has(> input[type='checkbox'])
  > :is(.iso-date-wrapper, .date-field) {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  width: auto;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table
  td:has(> input[type='checkbox'])
  > :is(a.find, button, input[type='button'], input[type='submit']) {
  flex: 0 0 auto;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  td:has(
    > input[type='checkbox']
      + :is(
        select[name='specialityfilter'],
        select[name='lichistfilter'],
        select[name='scored'],
        select[name='breeding'],
        select[name='in_breeding'],
        select[name='alive'],
        select[name='deleted'],
        select[name='sterile'],
        select[name='fate'],
        select[name='m_breeding'],
        select[name='m_breeding_cage'],
        select[name='m_sterile'],
        select[name='m_status']
      )
  ) {
  display: grid !important;
  grid-template-columns: 1rem minmax(0, 1fr);
  /* Top-align checkbox + control so their top edges stay on one row in legacy table cells. */
  align-items: start;
  gap: 0.38rem;
  min-width: 0;
  padding-right: 0.35rem !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  td
  > input[type='checkbox'] {
  margin: 0 !important;
  justify-self: center;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  td
  > input[type='checkbox']
  + :is(
    select[name='specialityfilter'],
    select[name='lichistfilter'],
    select[name='scored'],
    select[name='breeding'],
    select[name='in_breeding'],
    select[name='alive'],
    select[name='deleted'],
    select[name='sterile'],
    select[name='fate'],
    select[name='m_breeding'],
    select[name='m_breeding_cage'],
    select[name='m_sterile'],
    select[name='m_status']
  ) {
  flex: none !important;
  min-width: 9.5rem !important;
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  td
  > input[type='checkbox']
  + :is(select[name='specialityfilter'], select[name='lichistfilter']) {
  width: 100% !important;
  min-width: 9.5rem !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  td
  > input[type='checkbox']
  + :is(
    select[name='scored'],
    select[name='breeding'],
    select[name='in_breeding'],
    select[name='alive'],
    select[name='deleted'],
    select[name='sterile'],
    select[name='fate'],
    select[name='m_breeding'],
    select[name='m_breeding_cage'],
    select[name='m_sterile'],
    select[name='m_status']
  ) {
  width: min(100%, var(--animals-right-control-width)) !important;
  min-width: 9.5rem !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  :is(input, select, textarea):not([type='checkbox']):not([type='radio']) {
  max-width: 100% !important;
  box-sizing: border-box;
}

/* Animals area tab: keep checkbox + linked controls top-aligned in mixed input rows. */
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--single
  td:has(
    > input[type='checkbox']
      ~ :is(#project_name, #experiment_name, select[name='breeding_cage'], #breeding_cage)
  ) {
  align-items: start !important;
}

/* Animals data tab (left column): keep yyyy-mm-dd fully readable without changing litters fields. */
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  .date-field
  > input.iso-date-input:is(#animal_bday, #arrival_date, #outgoing_date, #death_date),
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--gap:not(.params-table--genetics)
  .iso-date-wrapper
  > input.iso-date-input:is(#animal_bday, #arrival_date, #outgoing_date, #death_date) {
  flex: 0 1 12.2ch !important;
  width: 12.2ch !important;
  min-width: 11.4ch !important;
  max-width: 13ch !important;
}

/* Animals genetics: prevent gene controls from squeezing/overflowing */
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics {
  table-layout: auto !important;
  width: 100% !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.col-gap {
  width: 0.5rem !important;
  min-width: 0.5rem !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td:has(> label) {
  width: clamp(6.3rem, 10.5vw, 8rem) !important;
  min-width: clamp(6.3rem, 10.5vw, 8rem) !important;
  white-space: nowrap;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.cell-inline,
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.genetics-cell {
  display: flex !important;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  width: 100%;
  min-width: 0;
  overflow: visible;
}

/* Genetics checkbox+input guard: top-edge align keeps legacy checkbox/input row delta stable. */
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.genetics-cell {
  align-items: flex-start;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.cell-inline
  > input[type='checkbox'],
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.genetics-cell
  > input[type='checkbox'] {
  flex: 0 0 auto;
  margin: 0;
  align-self: flex-start;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.cell-inline
  > input[type='checkbox'][style*='visibility: hidden'],
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td.genetics-cell
  > input[type='checkbox'][style*='visibility: hidden'] {
  position: absolute !important;
  inline-size: 1px !important;
  block-size: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  :is(input[id^='animal_gene_'], input[id^='m_gene_']) {
  flex: 1 1 12rem !important;
  min-width: 10.5rem !important;
  max-width: 100% !important;
  width: auto !important;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  td:has(> input[type='checkbox'] + input[type='text'])
  > input[type='text'] {
  flex: 1 1 11rem !important;
  min-width: 9.75rem !important;
  max-width: 100% !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='animals']:is(
    [data-subcommand='search'],
    [data-subcommand='select'],
    [data-subcommand='back']
  )
  #content
  .screen-animals__table.params-table--genetics
  :is(select[name$='_typ'], select[id$='_typ'], select[name$='_type'], select[id$='_type']) {
  flex: 0 1 8.25rem !important;
  min-width: 7rem !important;
  max-width: 100% !important;
  width: auto !important;
  box-sizing: border-box;
}

/* Tasks editor: keep action labels fully visible and priority labels on one line. */
body[data-theme='legacy'][data-command='tasks'] .task-link-actions,
body.theme-legacy[data-command='tasks'] .task-link-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.25rem;
  white-space: nowrap;
  max-width: 100%;
}

body[data-theme='legacy'][data-command='tasks'] td.task-link-actions-row,
body.theme-legacy[data-command='tasks'] td.task-link-actions-row {
  white-space: nowrap;
  overflow: visible;
}

body[data-theme='legacy'][data-command='tasks'] .task-link-action,
body.theme-legacy[data-command='tasks'] .task-link-action {
  min-width: max-content !important;
  width: auto !important;
  max-width: 100% !important;
  box-sizing: border-box;
  white-space: nowrap;
  text-overflow: clip;
  overflow: visible;
  padding: 0.18rem 0.45rem !important;
  line-height: 1.15;
}

/* Override legacy cell-inline .find width clamps (28px) for task action links only. */
body[data-theme='legacy'][data-command='tasks'] td.cell-inline .task-link-action,
body.theme-legacy[data-command='tasks'] td.cell-inline .task-link-action {
  width: auto !important;
  min-width: max-content !important;
  max-width: 100% !important;
}

body[data-theme='legacy'][data-command='tasks'] .task-priority-cell,
body.theme-legacy[data-command='tasks'] .task-priority-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

body[data-theme='legacy'][data-command='tasks'] .task-priority-cell--combined,
body.theme-legacy[data-command='tasks'] .task-priority-cell--combined {
  gap: 0.45rem 0.6rem;
  flex-wrap: nowrap;
}

body[data-theme='legacy'][data-command='tasks'] .task-priority-label,
body.theme-legacy[data-command='tasks'] .task-priority-label {
  display: inline-block;
  min-width: 2.5rem;
  white-space: nowrap;
}

body[data-theme='legacy'][data-command='tasks'] select.task-priority-select,
body.theme-legacy[data-command='tasks'] select.task-priority-select {
  width: 4.8rem !important;
  min-width: 4.8rem !important;
  max-width: 4.8rem !important;
  box-sizing: border-box;
}

/* Cages result: denser rows and less wasted vertical space */
body[data-theme='legacy'][data-layout-contract='search-results'][data-command='cages'][data-subcommand='select']
  .cages-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.35rem;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='cages'][data-subcommand='select']
  #cages-table-container
  > .table-scroll-x.result-table-wrapper {
  max-height: clamp(220px, calc(100vh - 430px), 560px);
}

body[data-theme='legacy'][data-layout-contract='search-results']
  #animals-table-container
  > .table-scroll-x.result-table-wrapper,
body.theme-legacy[data-layout-contract='search-results']
  #animals-table-container
  > .table-scroll-x.result-table-wrapper,
body[data-theme='legacy'][data-layout-contract='search-results']
  #cages-table-container
  > .table-scroll-x.result-table-wrapper,
body.theme-legacy[data-layout-contract='search-results']
  #cages-table-container
  > .table-scroll-x.result-table-wrapper {
  max-height: clamp(220px, calc(100vh - 430px), 560px);
}

/* Fallback for result screens rendered under facility/init (no data-layout-contract). */
body[data-theme='legacy']:has(#animals-table-container)
  #animals-table-container
  > .table-scroll-x.result-table-wrapper,
body.theme-legacy:has(#animals-table-container)
  #animals-table-container
  > .table-scroll-x.result-table-wrapper {
  max-height: clamp(220px, calc(100vh - 430px), 560px);
}

body[data-theme='legacy'][data-layout-contract='search-results']:is(
    [data-command='animals'],
    [data-command='cages']
  )
  .page-content__actions,
body[data-theme='legacy'][data-layout-contract='search-results']:has(#animals-table-container)
  .page-content__actions,
body[data-theme='legacy'][data-layout-contract='search-results']:has(#cages-table-container)
  .page-content__actions {
  position: sticky;
  bottom: 0;
  z-index: 12;
  background: linear-gradient(180deg, rgba(238, 241, 247, 0) 0%, rgba(238, 241, 247, 0.98) 40%);
  padding-top: 2px !important;
  padding-bottom: 8px !important;
}

body[data-theme='legacy']:has(#animals-table-container) .page-content__actions,
body.theme-legacy:has(#animals-table-container) .page-content__actions {
  position: sticky;
  bottom: 0;
  z-index: 12;
  background: linear-gradient(180deg, rgba(238, 241, 247, 0) 0%, rgba(238, 241, 247, 0.98) 40%);
  padding-top: 2px !important;
  padding-bottom: 8px !important;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='cages'][data-subcommand='select']
  table.cages-result
  thead
  th {
  padding-top: 0.22rem !important;
  padding-bottom: 0.22rem !important;
  line-height: 1.15;
}

body[data-theme='legacy'][data-layout-contract='search-results'][data-command='cages'][data-subcommand='select']
  table.cages-result
  tbody
  td {
  padding-top: 0.12rem !important;
  padding-bottom: 0.12rem !important;
  line-height: 1.08;
}

/* Licence description tab: responsive textarea heights for 1330x900 fit */
body[data-theme='legacy'][data-command='licences']
  :is(textarea#description, textarea#keywords, textarea#literature) {
  min-height: clamp(6rem, 14vh, 8rem) !important;
  height: clamp(6.5rem, 18vh, 10rem) !important;
  max-height: 30vh !important;
  width: min(100%, 52rem);
  box-sizing: border-box;
}

/* Documents and reports lists: use remaining height for table wrappers */
body[data-theme='legacy'][data-command='documents']:is(
    [data-subcommand='found'],
    [data-subcommand='select'],
    [data-subcommand='select2']
  )
  #content {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 0;
}

body[data-theme='legacy'][data-command='documents']:is(
    [data-subcommand='found'],
    [data-subcommand='select'],
    [data-subcommand='select2']
  )
  .documents-bulk-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}

body[data-theme='legacy'][data-command='documents']:is(
    [data-subcommand='found'],
    [data-subcommand='select'],
    [data-subcommand='select2']
  )
  #content
  :is(.result-table-wrapper, .table-scroll-x) {
  flex: 1 1 auto;
  min-height: 0;
  max-height: clamp(320px, 72vh, 820px);
}

/* Reports lists: keep Execute action row visible while table fills remaining space. */
body[data-theme='legacy'][data-command='reports'] #content,
body[data-theme='legacy'][data-command='home'][data-subcommand='init']:is(
    :has(#breadcrumbs a[href*='command=reports']),
    :has(.breadcrumbs a[href*='command=reports'])
  )
  #content {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 0;
}

body[data-theme='legacy'][data-command='reports'] #content > table,
body[data-theme='legacy'][data-command='home'][data-subcommand='init']:is(
    :has(#breadcrumbs a[href*='command=reports']),
    :has(.breadcrumbs a[href*='command=reports'])
  )
  #content
  > table {
  margin-top: 0 !important;
}

body[data-theme='legacy'][data-command='reports']
  #content
  :is(.result-table-wrapper, .table-scroll-x),
body[data-theme='legacy'][data-command='home'][data-subcommand='init']:is(
    :has(#breadcrumbs a[href*='command=reports']),
    :has(.breadcrumbs a[href*='command=reports'])
  )
  #content
  :is(.result-table-wrapper, .table-scroll-x) {
  flex: 1 1 auto;
  min-height: 0;
  max-height: clamp(260px, calc(100vh - 255px), 760px);
}

body[data-theme='legacy'][data-command='reports'] .page-content__actions,
body[data-theme='legacy'][data-command='home'][data-subcommand='init']:is(
    :has(#breadcrumbs a[href*='command=reports']),
    :has(.breadcrumbs a[href*='command=reports'])
  )
  .page-content__actions {
  margin-top: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 6px !important;
  flex: 0 0 auto;
}

/* Litters search results: keep action icons visible at 1330px without horizontal scroll. */
body[data-theme='legacy'][data-command='animals_litters'] .litters-bulk-actions,
body.theme-legacy[data-command='animals_litters'] .litters-bulk-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
  margin: 0 0 0.5rem;
}

body[data-theme='legacy'][data-command='animals_litters'] table.litters-result,
body.theme-legacy[data-command='animals_litters'] table.litters-result {
  width: 100% !important;
  min-width: 100% !important;
  max-width: 100% !important;
  table-layout: fixed !important;
}

body[data-theme='legacy'][data-command='animals_litters'] table.litters-result th,
body.theme-legacy[data-command='animals_litters'] table.litters-result th {
  padding: 0.34rem 0.44rem !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

body[data-theme='legacy'][data-command='animals_litters'] table.litters-result td,
body.theme-legacy[data-command='animals_litters'] table.litters-result td {
  padding-inline: 0.3rem !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-select,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-select {
  width: 26px !important;
  min-width: 26px !important;
  max-width: 26px !important;
}

body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-sire-id,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-sire-id,
body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-dam-id,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-dam-id {
  width: 98px !important;
}

body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-sire-strain,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-sire-strain,
body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-dam-strain,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-dam-strain {
  width: 76px !important;
}

body[data-theme='legacy'][data-command='animals_litters'] table.litters-result :is(th, td).col-cage,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-cage {
  width: 58px !important;
}

body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-birthday,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-birthday,
body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-date-mating,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-date-mating,
body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-date-plug,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-date-plug {
  width: 70px !important;
}

body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td):nth-child(n + 8):nth-child(-n + 17),
body.theme-legacy[data-command='animals_litters']
  table.litters-result
  :is(th, td):nth-child(n + 8):nth-child(-n + 17) {
  width: 42px !important;
  text-align: center;
}

body[data-theme='legacy'][data-command='animals_litters']
  table.litters-result
  :is(th, td).col-action,
body.theme-legacy[data-command='animals_litters'] table.litters-result :is(th, td).col-action {
  width: 30px !important;
  min-width: 30px !important;
  max-width: 30px !important;
  overflow: visible !important;
  text-overflow: clip !important;
}

/* Classic "Wuerfe absetzen/Tote Jungtiere" tab: compact and remove legacy visual waste. */
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table {
  width: 100%;
  margin: 0;
  table-layout: auto;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table
  td,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table
  td {
  padding-left: 3px;
  padding-right: 3px;
  padding-top: 1px;
  padding-bottom: 1px;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-row--sex-header
  td,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-row--sex-header
  td {
  padding-top: 0;
  padding-bottom: 0;
  line-height: 1.1;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-parent-label
  label,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-parent-label
  label {
  font-weight: 700;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-row--line
  td:nth-child(3),
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-row--line
  td:nth-child(3) {
  padding-top: 0;
  padding-bottom: 0;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-inline-find,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-inline-find {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-inline-find
  :is(input[type='text'], input[type='input']),
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-inline-find
  :is(input[type='text'], input[type='input']) {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  width: auto !important;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-inline-find
  .find,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-inline-find
  .find {
  flex: 0 0 auto;
  white-space: nowrap;
  margin: 0;
}

/* ── Tab 2 Wean: 4-column table symmetric layout ── */
/* Column widths are now defined by inline style attributes on <col> elements.
   table-layout:fixed enforces equal Sire/Dam halves
   regardless of colspan patterns in individual rows. */
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table {
  table-layout: fixed;
  width: 100%;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table
  input[type='text'],
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table
  input[type='input'],
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table
  input[type='text'],
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-table
  input[type='input'] {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--project
  :is(input[type='text'], input[type='input']),
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--project
  :is(input[type='text'], input[type='input']) {
  max-width: 100%;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--project,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--project {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 6px;
  align-items: center;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--project
  .find,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--project
  .find {
  margin: 0;
  justify-self: start;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-label--first-earmark,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-label--first-earmark {
  white-space: nowrap;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--first-earmark
  input,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--first-earmark
  input {
  width: 100%;
  max-width: 220px;
}

body[data-theme='legacy'][data-command='animals_litters_edit'][data-active-tab='tab2'] #buttons,
body.theme-legacy[data-command='animals_litters_edit'][data-active-tab='tab2'] #buttons,
body[data-theme='legacy'][data-command='animals_litters_edit']
  #toptabs[data-active-tab='tab2']
  ~ #buttons,
body.theme-legacy[data-command='animals_litters_edit'] #toptabs[data-active-tab='tab2'] ~ #buttons {
  position: fixed !important;
  left: 0;
  right: 0;
  bottom: 24px;
  z-index: 42;
  margin: 0 !important;
  padding: 6px 12px 8px !important;
  background: linear-gradient(180deg, rgba(238, 241, 247, 0) 0%, rgba(238, 241, 247, 0.97) 42%);
}

body[data-theme='legacy'][data-command='animals_litters_edit'][data-active-tab='tab2'] #buttons ul,
body.theme-legacy[data-command='animals_litters_edit'][data-active-tab='tab2'] #buttons ul,
body[data-theme='legacy'][data-command='animals_litters_edit']
  #toptabs[data-active-tab='tab2']
  ~ #buttons
  ul,
body.theme-legacy[data-command='animals_litters_edit']
  #toptabs[data-active-tab='tab2']
  ~ #buttons
  ul {
  justify-content: flex-start !important;
}

body[data-theme='legacy'][data-command='animals_litters_edit'][data-active-tab='tab2'] #tab2,
body.theme-legacy[data-command='animals_litters_edit'][data-active-tab='tab2'] #tab2,
body[data-theme='legacy'][data-command='animals_litters_edit']
  #toptabs[data-active-tab='tab2']
  ~ #tab2,
body.theme-legacy[data-command='animals_litters_edit'] #toptabs[data-active-tab='tab2'] ~ #tab2 {
  padding-bottom: 58px;
}

/* Fix: Klassisches Wean-Tab scrollbar machen, damit alles im Viewport sichtbar ist */
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean {
  overflow-y: auto;
  max-height: calc(100vh - 175px);
}

/* Fix: Zielkäfig-Zelle in Tab 2 – Textfeld und Suchbutton in eine Zeile zwingen;
   Label-Spalten (1+3) schmäler, Zielkäfig-Spalten (2+4) breiter. */
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--cage,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--cage {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  min-width: 220px;
  white-space: nowrap;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--cage
  input[type='text'],
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--cage
  input[type='text'] {
  flex: 1 1 auto;
  min-width: 80px;
  max-width: 170px;
  width: auto !important;
}

body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--cage
  .find,
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  .screen-animals-litters-edit__classic-wean-control--cage
  .find {
  flex: 0 0 auto;
  white-space: nowrap;
  margin: 0;
}

/* Label-Spalten (1. + 3. Spalte der wean-compact-Tabelle) kompakter */
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  table.screen-animals-litters-edit__classic-wean-table
  > tbody
  > tr
  > td:nth-child(1),
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  table.screen-animals-litters-edit__classic-wean-table
  > tbody
  > tr
  > td:nth-child(1),
body[data-theme='legacy'][data-command='animals_litters_edit']
  #tab2
  table.screen-animals-litters-edit__classic-wean-table
  > tbody
  > tr
  > td:nth-child(3),
body.theme-legacy[data-command='animals_litters_edit']
  #tab2
  table.screen-animals-litters-edit__classic-wean-table
  > tbody
  > tr
  > td:nth-child(3) {
  width: 88px;
  min-width: 70px;
  max-width: 100px;
}

@media (min-width: 1200px) {
  body[data-theme='legacy']:is(
      [data-command='animals']:is(
        [data-subcommand='search'],
        [data-subcommand='select'],
        [data-subcommand='back']
      ),
      [data-command='tasks'][data-subcommand='select_tasks'],
      [data-command='cages'][data-subcommand='select'],
      [data-command='licences'][data-subcommand='search']
    )
    .page-content__actions {
    margin-top: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 4px !important;
  }
}
