/*
 * 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'] #content table[data-layout='form-legacy'],
body.theme-legacy #content table[data-layout='form-legacy'],
body[data-theme='legacy'] #content .params-table,
body.theme-legacy #content .params-table {
  display: table !important;
  table-layout: fixed;
}

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

body[data-theme='legacy'] #content table[data-layout='form-legacy'] td,
body.theme-legacy #content table[data-layout='form-legacy'] td,
body[data-theme='legacy'] #content .params-table td,
body.theme-legacy #content .params-table td,
body[data-theme='legacy'] #content table[data-layout='form-legacy'] th,
body.theme-legacy #content table[data-layout='form-legacy'] th,
body[data-theme='legacy'] #content .params-table th,
body.theme-legacy #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;
}

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;
}

/* 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'] #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;
}

/* 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: widen right column controls */
body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] {
  width: 100%;
  table-layout: fixed;
}

body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(5),
body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(6) {
  width: clamp(160px, 20vw, 240px);
}

body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(5) input,
body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(5) select,
body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(5) textarea,
body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(6) input,
body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(6) select,
body[data-theme='legacy'][data-command='animals_create'] table[data-layout='form-legacy'] td:nth-child(6) textarea {
  min-width: 160px;
  width: 100%;
  box-sizing: border-box;
}

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

body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > table td:nth-child(1),
body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > 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'][data-subcommand='select_tasks'] #content > table td:nth-child(2),
body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > 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'][data-subcommand='select_tasks'] #content > table td:nth-child(3) {
  width: var(--form-gap-width);
}

body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > table td:has(.find) {
  position: relative;
  padding-right: 30px;
}

body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > table td:has(.find) input,
body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > table td input,
body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > table td select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

body[data-theme='legacy'][data-density='compact'][data-command='tasks'][data-subcommand='select_tasks'] #content > table td:has(.find) .find {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  min-width: 22px;
  height: 22px;
  padding: 0;
}

/* 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;
  }
}

/* Litters search: tighten widths so right controls stay visible */
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] {
  --litters-label-left: 70px;
  --litters-label-right: 90px;
  --litters-control-left-min: 90px;
  --litters-control-left-max: 130px;
  --litters-control-right-min: 120px;
  --litters-control-right-max: 170px;
  --litters-control-left: clamp(var(--litters-control-left-min), 10vw, var(--litters-control-left-max));
  --litters-control-right: clamp(var(--litters-control-right-min), 12vw, var(--litters-control-right-max));
  --form-gap-width: 6px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table {
  width: 100%;
  table-layout: fixed;
  border-spacing: 0.1rem 0.06rem;
  font-size: 0.82rem;
  max-width: 1360px;
  margin: 0 auto;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(1),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(3) {
  width: var(--litters-label-left);
  min-width: var(--litters-label-left);
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(5),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(7) {
  width: var(--litters-label-right);
  min-width: var(--litters-label-right);
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(2),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(4) {
  width: var(--litters-control-left);
  min-width: var(--litters-control-left-min);
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(6),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(8) {
  width: var(--litters-control-right);
  min-width: var(--litters-control-right-min);
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td label {
  white-space: normal;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(1),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(3) {
  max-width: 90px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(5),
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(7) {
  max-width: 120px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td {
  padding: 1px 4px !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:has(.find) {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td input,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td select,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  height: 22px !important;
  min-height: 22px !important;
  padding: 1px 4px !important;
  display: inline-block !important;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(2) input,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(4) input,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(2) select,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(4) select {
  max-width: 120px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(6) input,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(8) input,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(6) select,
body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td:nth-child(8) select {
  max-width: 170px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search'] #content table td[colspan='3'] select {
  min-width: 180px;
  max-width: 100%;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table
  .iso-date-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  max-width: 170px;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table
  .iso-date-wrapper
  input {
  flex: 1 1 auto;
  min-width: 0;
}

body[data-theme='legacy'][data-density='compact'][data-command='animals_litters'][data-subcommand='search']
  #content
  table
  .iso-date-wrapper
  button {
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0 !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;
}

/* 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%);
  }
}
