/* === Theme colors === */
:root {
  --color-primary: #0d6efd;
  --color-primary-active: #007bff;
  --color-primary-soft: rgba(13, 110, 253, 0.08);
  --color-primary-border-soft: rgba(13, 110, 253, 0.35);
  --color-success: #198754;
  --color-success-text: #146c43;
  --color-danger: #dc3545;
  --color-warning: #fd7e14;
  --color-text: #212529;
  --color-text-black: #000;
  --color-text-strong: #343a40;
  --color-text-soft: #495057;
  --color-text-muted: #6c757d;
  --color-text-faint: #888;
  --color-handle: #777;
  --color-border: #ddd;
  --color-border-soft: #dee2e6;
  --color-border-subtle: #e9ecef;
  --color-border-muted: #ced4da;
  --color-border-group: #e0e0e0;
  --color-bg: #fff;
  --color-bg-muted: #f8f9fa;
  --color-danger-bg: #fff5f5;
  --color-warning-bg: #fff8ef;
  --color-success-bg: #eaf7ef;
  --color-parent: #111;
  --color-weak-link-bg: #e7f1ff;
  --color-backdrop: rgba(33, 37, 41, 0.35);
  --color-dialog-shadow: rgba(33, 37, 41, 0.22);
}

/* === Global page guards === */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* === Home/index page layout === */
body.home-page {
  height: 100vh;
  margin-top: 0 !important;
  display: flex;
  flex-direction: column;
}

.home-header {
  --trace-node-block-size: 1.125rem;
  --trace-node-gap: 0.25rem;
  --trace-diagram-padding-block: 0.75rem;
  --trace-diagram-clearance: 0.25rem;
  --trace-diagram-block-size: calc(
    var(--trace-node-block-size) +
    var(--trace-node-block-size) +
    var(--trace-node-block-size) +
    var(--trace-node-gap) +
    var(--trace-node-gap) +
    var(--trace-diagram-padding-block) +
    var(--trace-diagram-clearance)
  );
  flex: 0 0 auto;
  padding: 8px;
  border-bottom: 1px solid var(--color-border-subtle);
  background: var(--color-bg);
}

.home-header-main {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-start;
  min-height: var(--trace-diagram-block-size);
}

.home-title {
  flex: 0 0 auto;
  min-width: 220px;
  max-width: 30%;
}

.home-title h1 {
  line-height: 1.1;
}

.home-title p {
  font-size: 0.82rem;
}

.home-actions,
.home-mode-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.home-actions {
  flex: 0 0 auto;
  justify-content: flex-end;
  margin-left: auto;
  padding-left: 16px;
}

.home-mode-controls {
  flex: 0 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.home-actions #loadingIndicator {
  white-space: nowrap;
}

body.home-page > .d-flex {
  flex: 0 0 auto;
}

/* === Create/update/view field rows === */
body:not(.home-page) .row.g-3 > [class*="col-"]:has(> :is(.form-label, textarea.form-control, .min-vh-0)) {
  display: block;
}

body:not(.home-page) .row.g-3 > [class*="col-"]:has(> :is(textarea.form-control, .min-vh-0)) > .form-label {
  padding-top: 0;
}

body:not(.home-page) .form-label {
  display: block;
  margin-bottom: 0.25rem;
}

body:not(.home-page) .form-text {
  flex-basis: 100%;
  margin-left: 0;
}

body:not(.home-page) .row.g-3 > [class*="col-"]:has(> .form-label) > :is(.form-control, .form-select) {
  width: 100%;
}

body:not(.home-page) #mainForm :is(.form-control, .form-select) {
  background-color: var(--color-bg-muted);
  border-color: var(--color-border-muted);
}

body:not(.home-page) #mainForm :is(.form-control, .form-select):focus {
  background-color: var(--color-bg);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 0.16rem var(--color-primary-soft);
}

body:not(.home-page) .row.g-3 > [class*="col-"]:has(> .form-label) > :is(input[type="number"].form-control, #fieldGads) {
  flex: 0 0 6.5rem;
  max-width: 6.5rem;
}

body:not(.home-page) .row.g-3 > [class*="col-"]:has(> .form-label) > :is(input[name="Kods"].form-control, #fieldKods) {
  flex: 0 0 10rem;
  max-width: 10rem;
}

body:not(.home-page) .row.g-3 > [class*="col-"]:has(> .form-label) > :is(
  input[type="url"].form-control,
  input[name="Nosaukums"].form-control,
  input[name="Autori"].form-control,
  textarea.form-control,
  .form-select,
  #fieldURL,
  #fieldScholar,
  #fieldNosaukums,
  #fieldAutori,
  #fieldApraksts,
  #fieldParent,
  #fieldGroup
) {
  flex: 1 1 16rem;
  min-width: min(16rem, 100%);
}

.paper-url-field {
  font-size: 0.875rem;
}

.explorer-grid {
  flex: 1 1 auto;
  min-height: 0;
  height: 0;
  display: flex;
  width: 100%;
  overflow-x: hidden;
  position: relative;
}

.explorer-column {
  box-sizing: border-box;
  flex: 0 0 auto;
  min-width: 0;
  height: 100%;
  min-height: 0;
  position: relative;
}

.explorer-column .card {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.explorer-column .card-header {
  min-height: 48px;
  gap: 8px;
  flex-wrap: wrap;
}

.explorer-column .card-title {
  font-size: 1rem;
  white-space: nowrap;
}

.explorer-column .card-header > .d-flex {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-add-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.9375rem;
  padding: 0 0.5rem;
  gap: 0.25rem;
  border-color: var(--color-text-muted);
}

.header-icon-button {
  width: 1.9375rem;
  padding: 0;
}

.header-add-icon {
  width: 0.75rem;
  height: 0.75rem;
  display: block;
  opacity: 0.72;
}

.header-add-button:hover .header-add-icon {
  filter: invert(1);
  opacity: 1;
}

.explorer-column .card-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden !important;
}

/* === Trace mode summary === */
.trace-mode-summary-slot {
  flex: 1 1 auto;
  height: var(--trace-diagram-block-size);
  min-width: min(100%, 320px);
  min-height: var(--trace-diagram-block-size);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.trace-mode-summary {
  display: block;
  max-width: 100%;
  padding: 0;
  font-size: 0.72rem;
  line-height: 1.25;
}

.trace-example-diagram {
  display: grid;
  grid-template-columns: max-content 46px max-content 46px max-content 46px max-content;
  gap: 6px;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  max-height: var(--trace-diagram-block-size);
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-muted);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.trace-example-column {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--trace-node-gap);
  min-height: calc(
    var(--trace-node-block-size) +
    var(--trace-node-block-size) +
    var(--trace-node-block-size) +
    var(--trace-node-gap) +
    var(--trace-node-gap)
  );
}

.trace-example-node {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--trace-node-block-size);
  padding: 2px 6px;
  border: 1px solid var(--color-border-muted);
  border-radius: 4px;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}

.trace-example-node.source {
  background-color: var(--color-primary-active);
  border-color: var(--color-primary-active);
  color: white;
  font-weight: 700;
}

.trace-example-node.common {
  border-color: var(--color-success);
  box-shadow: inset 0 0 0 1px var(--color-success);
}

.trace-example-node.more,
.trace-example-node.empty {
  color: var(--color-text-muted);
  background: var(--color-bg);
}

.trace-example-lines {
  position: relative;
  height: var(--trace-line-height, 46px);
  width: 46px;
}

.trace-example-lines svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.trace-example-lines path {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 2;
  stroke-linecap: round;
}

.trace-example-lines.and path {
  stroke: var(--color-danger);
}

.trace-example-lines.or path {
  stroke: var(--color-success-text);
}

.trace-example-lines path.common {
  stroke: var(--color-success);
}

.trace-example-lines marker path {
  fill: var(--color-success-text);
  stroke: none;
  marker-end: none;
}

.trace-example-lines.and marker path {
  fill: var(--color-danger);
}

.trace-example-lines.and .trace-example-mode {
  color: var(--color-danger);
}

.trace-example-lines.or .trace-example-mode {
  color: var(--color-success-text);
}

.trace-example-mode {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  transform: translate(-50%, -50%);
  padding: 0 5px;
  border: 1px solid var(--color-border-muted);
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-text-strong);
  font-size: 0.62rem;
  font-weight: 700;
}

/* === Papers sort controls === */
.paper-sort-controls {
  flex-wrap: nowrap !important;
}

.paper-sort-select {
  width: 94px;
  min-width: 94px;
  height: 1.9375rem;
  border-color: var(--color-text-muted);
  color: var(--color-text);
  background-color: var(--color-bg);
  font-size: 0.75rem;
}

.paper-sort-select:focus {
  border-color: var(--color-text-muted);
  box-shadow: 0 0 0 0.16rem rgba(108, 117, 125, 0.2);
}

/* === Column layout controls === */
.column-layout-controls {
  display: none;
}

.column-layout-enabled button.column-layout-controls {
  display: inline-flex;
}

.column-layout-enabled .column-resizer {
  display: block;
}

.column-drag-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.column-drag-title::before {
  content: "⋮⋮";
  flex: 0 0 auto;
  display: none;
  align-items: center;
  justify-content: center;
  width: 14px;
  align-self: stretch;
  color: var(--color-handle);
  border-right: 1px solid var(--color-border);
  padding-right: 4px;
  font-size: 0.85rem;
  line-height: 1;
}

.column-layout-enabled .column-drag-title {
  cursor: grab;
}

.column-layout-enabled .column-drag-title::before {
  display: inline-flex;
}

.column-layout-enabled .column-drag-title:active {
  cursor: grabbing;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -5px;
  bottom: 0;
  width: 10px;
  z-index: 20;
  cursor: col-resize;
}

.column-resizer::after {
  content: "";
  position: absolute;
  top: 48px;
  bottom: 4px;
  left: 4px;
  width: 2px;
  background: transparent;
  border-radius: 2px;
}

.column-layout-enabled .column-resizer:hover::after,
.column-resizing .column-resizer::after {
  background: var(--color-primary);
}

.column-dragging {
  opacity: 0.65;
}

.column-drop-before::before,
.column-drop-after::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--color-primary);
  border-radius: 3px;
  z-index: 25;
}

.column-drop-before::before {
  left: 1px;
}

.column-drop-after::before {
  right: 1px;
}

.column-resizing {
  cursor: col-resize;
  user-select: none;
}

/* === Data import/export panels === */
.data-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.data-panel {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 16px;
  background: var(--color-bg);
}

/* === Link panel containers === */
#requirements,
#taxonomy,
#papers,
#methods {
  display: flex;
  flex-direction: column;
}

#taxonomy,
#papers,
#methods {
  gap: 2px;
}

#requirements {
  gap: 0;
}

/* === Shared link item base style === */
.taxonomy-item,
.method-item,
.requirement-item,
.paper-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.65rem;
  padding: 4px 8px;
  margin: 0;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word; 
  transition: background 0.2s, opacity 0.2s;
}

/* === Connection side color scheme === */
.taxonomy-item.parent-node,
.method-item.parent-node {
  border-left: 4px solid var(--color-parent);
  background-color: var(--color-bg);
  opacity: 1;
}

.taxonomy-item.parent-node {
  border-right: 4px solid var(--color-parent);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).conn-side-left-green {
  border-left: 4px solid var(--color-success);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).conn-side-left-orange {
  border-left: 4px solid var(--color-warning);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).conn-side-left-red {
  border-left: 4px solid var(--color-danger);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).conn-side-right-green {
  border-right: 4px solid var(--color-success);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).conn-side-right-orange {
  border-right: 4px solid var(--color-warning);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).conn-side-right-red {
  border-right: 4px solid var(--color-danger);
}

:is(.taxonomy-item, .paper-item).conn-bg-orange,
.requirement-item.conn-side-right-orange,
.method-item.conn-side-left-orange {
  background-color: var(--color-warning-bg);
}

:is(.taxonomy-item, .paper-item).conn-bg-red,
.requirement-item.conn-side-right-red,
.method-item.conn-side-left-red {
  background-color: var(--color-danger-bg);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).context-link {
  background-color: var(--color-weak-link-bg);
  color: var(--color-text);
  opacity: 1;
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).dimmed { opacity: 0.35; }

.gap-explanation-message {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--color-warning);
  border-radius: 6px;
  background-color: var(--color-warning-bg);
  color: var(--color-text);
  font-size: 0.72rem;
}

.gap-explanation-title {
  font-weight: 700;
  color: var(--color-text-strong);
}

.gap-explanation-entry {
  display: grid;
  gap: 2px;
}

.gap-explanation-entry strong {
  font-size: 0.68rem;
}

.gap-explanation-entry span {
  line-height: 1.3;
}

.gap-explanation-reasons {
  margin: 0;
  padding-left: 16px;
  line-height: 1.3;
}

.gap-explanation-reasons li + li {
  margin-top: 2px;
}

/* === AI link suggestion markers === */
:is(.taxonomy-item, .method-item).ai-link-added {
  outline: 2px solid var(--color-success);
  outline-offset: -2px;
  background-color: var(--color-success-bg) !important;
}

:is(.taxonomy-item, .method-item).ai-link-added.checked {
  background-color: var(--color-success) !important;
  color: var(--color-bg);
}

:is(.taxonomy-item, .method-item).ai-link-removed {
  background-color: var(--color-danger) !important;
  color: var(--color-bg);
}

:is(.taxonomy-item, .method-item).ai-single-link-selected {
  outline: 3px solid var(--color-primary);
  outline-offset: -3px;
  box-shadow: inset 0 0 0 9999px rgba(13, 110, 253, 0.12);
}

:is(.taxonomy-item, .method-item).ai-single-link-selected::after {
  content: "TEST";
  flex: 0 0 auto;
  margin-left: auto;
  min-width: 2.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  color: var(--color-primary);
}

:is(.taxonomy-item, .method-item).ai-single-link-selected > span {
  min-width: 0;
}

.ai-link-mode-panel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-muted);
}

.ai-link-mode-description {
  flex: 1 1 16rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--color-text);
}

:is(.taxonomy-item, .requirement-item, .paper-item, .method-item):is(.active, .checked) {
  background-color: var(--color-primary-active);
  color: white;
  font-weight: bold;
  opacity: 1;
}

.paper-item:is(.active, .checked) a,
.paper-item:is(.active, .checked) a:visited { color: var(--color-bg) !important; }

/* === Checked item text contrast === */
:is(.taxonomy-item, .requirement-item, .paper-item, .method-item).checked :is(.text-muted, .text-secondary) {
  color: var(--color-bg) !important;
}

/* === Requirements panel and group headers === */
.req-group-header {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-faint);
  padding: 6px 4px 2px;
  border-bottom: 1px solid var(--color-border-group);
  margin-top: 4px;
  margin-bottom: 1px;
}
.req-group-header:first-child { margin-top: 0; }

/* === Scroll behavior for panels === */
#requirements,
#taxonomy,
#papers,
#methods {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  scrollbar-gutter: stable;
}

body.home-page #requirements,
body.home-page #taxonomy,
body.home-page #papers,
body.home-page #methods {
  height: 100%;
  max-height: none;
  overflow-y: scroll;
}

/* === Tree level indentation === */
:is(.taxonomy-item, .method-item).t-level-0 { margin-left: 0; }
:is(.taxonomy-item, .method-item).t-level-1 { margin-left: 12px; }
:is(.taxonomy-item, .method-item).t-level-2 { margin-left: 24px; }
:is(.taxonomy-item, .method-item).t-level-3 { margin-left: 36px; }
:is(.taxonomy-item, .method-item).t-level-4 { margin-left: 48px; }
:is(.taxonomy-item, .method-item).t-level-5 { margin-left: 60px; }

.item-label {
  flex: 1;
  min-width: 0;
}

/* === Drag and drop item states === */
.drag-handle {
  flex: 0 0 auto;
  width: 14px;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-handle);
  cursor: grab;
  user-select: none;
  border-right: 1px solid var(--color-border);
  padding-right: 4px;
}

.drag-handle:active {
  cursor: grabbing;
}

:is(.taxonomy-item, .method-item, .requirement-item, .req-group-header).dragging {
  opacity: 0.45;
}

:is(.taxonomy-item, .method-item).drag-branch-child {
  background-color: var(--color-primary-soft);
  border-color: var(--color-primary-border-soft);
}

:is(.taxonomy-item, .method-item, .requirement-item, .req-group-header).drag-over-before {
  box-shadow: inset 0 2px 0 var(--color-primary);
}

:is(.taxonomy-item, .method-item, .requirement-item, .req-group-header).drag-over-after {
  box-shadow: inset 0 -2px 0 var(--color-primary);
}

:is(.taxonomy-item, .method-item, .req-group-header).drag-over-inside {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
  background-color: var(--color-primary-soft);
}

/* === Item action buttons === */
.item-actions {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.item-action {
  border: none;
  background: transparent;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.65;
}
.item-action:hover {
  opacity: 1;
}
.item-action img {
  width: 0.65rem; 
  height: 0.65rem; 
  display: block;
}
.view-only-actions .item-action {
  font-size: 0.6rem;
  line-height: 1;
  color: var(--color-primary);
}

.link-count {
  color: var(--color-text-muted);
  font-weight: 600;
}

/* === Create/update page panel scroll === */
body:not(.home-page):not([data-entity]):has(.link-side) {
  box-sizing: border-box;
}

body:not([data-entity]) .link-side,
body:not([data-entity]) .link-side-col,
body:not([data-entity]) .link-side-col > .card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body:not([data-entity]) .link-side {
  overflow: hidden;
}

body:not([data-entity]) .link-side-row {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

body:not([data-entity]) .link-side-col {
  max-height: 100%;
}

body:not([data-entity]) .link-side-col > .card {
  flex: 1 1 auto;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

body:not([data-entity]) .panel-scroll {
  flex: 1 1 auto;
  min-height: 18rem;
  max-height: min(58vh, 640px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

body.llm-test-page {
  min-height: 100vh;
}

body.llm-test-page #resultPanel {
  min-height: 14rem;
}

body.llm-test-page .llm-test-result-scroll {
  overflow: visible;
}

body.llm-test-page #batchResults .llm-taxonomy-col {
  width: 22%;
}

body.llm-test-page #batchResults .llm-status-col {
  width: 16%;
}

body.llm-test-page #batchResults .llm-explanation-col,
body.llm-test-page #batchResults .llm-evidence-col {
  width: 31%;
}

.ai-taxonomy-results table,
body.llm-test-page #batchResults table {
  table-layout: fixed;
}

body.llm-test-page #batchResults :is(th, td),
.ai-taxonomy-results :is(th, td) {
  overflow-wrap: anywhere;
  vertical-align: top;
}

.ai-link-result-details {
  border: 1px solid var(--color-border-soft);
  border-radius: 6px;
  background: var(--color-bg);
  overflow: hidden;
}

.ai-link-result-details > summary {
  background: var(--color-bg-muted);
  color: var(--color-text-strong);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.5rem 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.ai-link-result-details .ai-taxonomy-results {
  border-top: 1px solid var(--color-border-soft);
}

@media (min-width: 1200px) and (min-height: 680px) {
  body:not(.home-page):not([data-entity]):has(.link-side) {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body:not(.home-page):not([data-entity]):has(.link-side) > .d-flex {
    flex: 0 0 auto;
  }

  body:not(.home-page):not([data-entity]):has(.link-side) > #mainForm {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
    padding-bottom: 0.25rem;
  }

  body:not([data-entity]) .link-side {
    height: calc(100% - var(--bs-gutter-y, 0px));
    max-height: calc(100% - var(--bs-gutter-y, 0px));
    min-height: 0;
    overflow: hidden;
  }

  body:not([data-entity]) .link-side > h5 {
    flex: 0 0 auto;
    margin-bottom: 0.5rem !important;
  }

  body:not([data-entity]) .panel-scroll {
    min-height: 0;
    max-height: none;
  }

}

body.llm-test-page {
  height: auto !important;
  min-height: 100vh !important;
  overflow-y: auto !important;
}

body.llm-test-page > #taxonomyEvalForm,
body.llm-test-page .llm-test-controls,
body.llm-test-page .llm-test-controls-inner,
body.llm-test-page .llm-test-result-slot {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

@media (min-width: 1200px) {
  body.llm-test-page {
    display: block !important;
    height: auto !important;
    min-height: 100vh !important;
    overflow-y: auto !important;
  }

  body.llm-test-page > #taxonomyEvalForm {
    align-items: flex-start;
    overflow: visible !important;
  }

  body.llm-test-page .link-side {
    position: sticky;
    top: 0.5rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 1rem) !important;
    max-height: calc(100vh - 1rem) !important;
    min-height: 0;
    overflow: visible !important;
  }

  body.llm-test-page .link-side-row {
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
    max-height: none !important;
    overflow: hidden !important;
  }

  body.llm-test-page .link-side-col {
    display: flex;
    flex-direction: column;
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0;
    overflow: hidden !important;
  }

  body.llm-test-page .link-side-col > .card {
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0;
    overflow: hidden !important;
  }

  body.llm-test-page .panel-scroll {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }
}

@media (min-width: 992px) {
  html:has(body.llm-test-page),
  body.llm-test-page {
    height: auto !important;
    min-height: 100vh !important;
    overflow-y: auto !important;
  }

  body.llm-test-page > #taxonomyEvalForm {
    overflow: visible !important;
    align-items: flex-start !important;
  }

  body.llm-test-page #taxonomyEvalForm > .link-side {
    position: sticky !important;
    top: 0.5rem !important;
    align-self: flex-start !important;
    display: flex !important;
    flex-direction: column !important;
    height: calc(100vh - 1rem) !important;
    max-height: calc(100vh - 1rem) !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  body.llm-test-page #taxonomyEvalForm > .link-side > .link-side-row {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  body.llm-test-page #taxonomyEvalForm .link-side-col,
  body.llm-test-page #taxonomyEvalForm .link-side-col > .card {
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

body.llm-test-page #taxonomyEvalForm .panel-scroll {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }
}

body.paper-form-page {
  height: auto !important;
  min-height: 100vh !important;
  overflow-y: auto !important;
}

body.paper-form-page > #mainForm,
body.paper-form-page > #mainForm > .col-12:first-child,
body.paper-form-page > #mainForm > .col-12:first-child > .row {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

body.paper-form-page .link-side {
  min-height: 0;
}

@media (min-width: 1200px) and (min-height: 680px) {
  body.paper-form-page {
    display: block !important;
    height: auto !important;
    min-height: 100vh !important;
    overflow-y: auto !important;
  }

  body.paper-form-page > #mainForm {
    display: flex;
    align-items: flex-start !important;
    overflow: visible !important;
  }

  body.paper-form-page .link-side {
    height: calc(100vh - 7rem) !important;
    max-height: calc(100vh - 7rem) !important;
    overflow: hidden !important;
  }
}

/* === Info modal and color legend === */
.color-legend-backdrop,
.action-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1040;
  background: var(--color-backdrop);
}

.color-legend-dialog,
.action-dialog {
  position: fixed;
  left: 50%;
  z-index: 1050;
  border: 1px solid var(--color-border-soft);
  border-radius: 8px;
  background: var(--color-bg);
  box-shadow: 0 12px 36px var(--color-dialog-shadow);
}

.color-legend-dialog {
  top: 50%;
  width: min(540px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  transform: translate(-50%, -50%);
}

.action-dialog {
  top: 16px;
  width: min(460px, calc(100vw - 24px));
  transform: translateX(-50%);
}

.color-legend-dialog-header,
.action-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border-subtle);
}

.color-legend-dialog-body {
  display: grid;
  gap: 14px;
  padding: 12px 14px 14px;
  font-size: 0.85rem;
  color: var(--color-text-soft);
}

.action-dialog-body {
  padding: 12px 14px;
  color: var(--color-text-soft);
  font-size: 0.9rem;
}

.action-dialog-body p {
  margin: 0;
}

.action-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 14px 14px;
}

.info-section {
  display: grid;
  gap: 8px;
}

.info-section-title {
  margin: 0;
  color: var(--color-text-strong);
  font-size: 0.86rem;
  font-weight: 700;
}

.color-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-legend-label {
  display: inline-flex;
  align-items: center;
  width: 142px;
  flex: 0 0 142px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-left-width: 4px;
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.65rem;
  line-height: 1.2;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.color-legend-label.side-many {
  border-left-color: var(--color-success);
}

.color-legend-label.side-none {
  border-left-color: var(--color-danger);
}

.color-legend-label.side-one {
  border-left-color: var(--color-warning);
}

.color-legend-label.parent-node {
  border-left-color: var(--color-parent);
  border-right: 4px solid var(--color-parent);
}

.color-legend-label.active {
  background: var(--color-primary-active);
  color: white;
  font-weight: bold;
}

.color-legend-label.weak-link {
  border-left-color: var(--color-border);
  background: var(--color-weak-link-bg);
}

.color-legend-label.bg-partial {
  border-left: 4px solid var(--color-warning);
  border-right: 4px solid var(--color-warning);
  background: var(--color-warning-bg);
}

.color-legend-label.bg-none {
  border-left: 4px solid var(--color-danger);
  border-right: 4px solid var(--color-danger);
  background: var(--color-danger-bg);
}

.shortcut-groups {
  display: grid;
  gap: 10px;
}

.shortcut-group {
  display: grid;
  gap: 5px;
}

.shortcut-group-title {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* === Keyboard shortcut list === */
.shortcut-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 12px;
}

.shortcut-pair {
  display: grid;
  gap: 4px;
}

.shortcut-list span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.shortcut-list kbd {
  min-width: 24px;
  padding: 2px 6px;
  border: 1px solid var(--color-border-muted);
  border-radius: 4px;
  background: var(--color-bg-muted);
  color: var(--color-text);
  font-size: 0.74rem;
  text-align: center;
  box-shadow: none;
}
