/* Reaction tab (js/tabs/reaction.js). The stage holds a fixed head, the
   scene (2D drawing, or the 3D view placed in the same box) and the results
   under it; the run panel holds the two sides and Compute. Sizes are fixed
   per breakpoint so the first frame, the saved panes and the live page
   agree to the pixel. */

.mol-app[data-tab='reaction'] .mol-stage {
  --rx-top: 60px;
  --rx-scene-h: clamp(210px, 40%, 360px);
}

.mol-app[data-tab='reaction'] .tab-pane[data-pane='reaction'] {
  display: block;
  pointer-events: none;
}

.mol-app[data-tab='reaction'] .rx > * {
  pointer-events: auto;
}

.mol-app[data-tab='reaction'] .mol-3d { display: none; }

.mol-app[data-tab='reaction'][data-mode='3d'] .mol-3d {
  display: block;
  top: var(--rx-top);
  bottom: auto;
  height: var(--rx-scene-h);
}

.mol-app[data-tab='reaction'][data-mode='3d'] .rx-scene { pointer-events: none; }
.mol-app[data-tab='reaction'][data-mode='3d'] .rx-svg { display: none; }
.mol-app[data-tab='reaction'] .run-pane[data-run='reaction'] { display: block; }

.rx {
  position: relative;
  height: 100%;
}

.rx-head {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--rx-top);
  padding: 0 var(--space-6);
}

.rx-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
}

.rx-title h2 {
  flex: none;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.rx-title p {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rx-k {
  margin-right: 0.18em;
}

.rx-op {
  margin: 0 0.42em;
  color: var(--text-faint);
}

.rx-mode {
  flex: none;
}

/* The scene. */
.rx-scene {
  position: absolute;
  top: var(--rx-top);
  right: 0;
  left: 0;
  height: var(--rx-scene-h);
}

.rx-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.rx-s-op,
.rx-s-k {
  fill: var(--text-muted);
  font-family: var(--font-ui);
  text-anchor: middle;
  dominant-baseline: central;
}

.rx-s-k {
  fill: var(--text);
  font-weight: var(--weight-semibold);
}

.rx-s-name {
  fill: var(--text-muted);
  font-family: var(--font-ui);
  text-anchor: middle;
}

.rx-s-arrow line,
.rx-s-arrow path {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rx-s-hit {
  fill: transparent;
}

.rx-s-sp:hover .rx-s-hit {
  fill: var(--surface-hover);
}

.rx-empty {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-6);
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
  text-align: center;
}

.rx.is-empty .rx-empty {
  display: flex;
}

.rx.is-empty .rx-scene {
  pointer-events: auto;
  height: auto;
  bottom: 0;
}

.rx.is-empty .rx-results {
  display: none;
}

.rx-presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  max-width: 560px;
}

.rx-presets .btn {
  font-family: var(--font-ui);
}

.rx-presets .btn .rx-op {
  margin: 0 0.3em;
}

/* While a molecule is dragged from the library: the two halves of the scene take it. */
.rx-drop {
  position: absolute;
  inset: var(--space-2) var(--space-4);
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  pointer-events: none;
}

.mol-app.rx-dragging .rx-drop {
  display: grid;
}

.rx-drop > div {
  display: grid;
  place-items: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.rx-drop > div.is-over {
  border-color: var(--accent);
  background: var(--accent-wash);
  color: var(--text);
}

/* Results. */
.rx-results {
  position: absolute;
  top: calc(var(--rx-top) + var(--rx-scene-h));
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  align-content: start;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6) var(--space-5);
  border-top: var(--hairline) solid var(--border);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

.rx-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.rx-stat {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
}

.rx-stat-k {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.rx-stat-k i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--rx-c);
}

.rx-stat b {
  color: var(--text);
  font-family: var(--font-code);
  font-size: var(--text-lg);
  font-weight: 400;
  line-height: 22px;
}

.rx-stat b small {
  color: var(--text-muted);
  font-size: var(--text-2xs);
}

.rx-stat.is-none b {
  color: var(--text-faint);
}

.rx-stat-s {
  color: var(--text-faint);
  font-size: var(--text-2xs);
  line-height: 15px;
}

.is-hf { --rx-c: var(--warning); }
.is-exact { --rx-c: var(--accent); }
.is-exp { --rx-c: var(--success); }

.rx-res-body {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.rx-levels svg {
  display: block;
  width: 100%;
  height: auto;
}

.rx-lv-grid {
  stroke: var(--border);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.rx-lv-grid.is-zero {
  stroke: var(--border-strong);
}

.rx-lv-tick,
.rx-lv-unit {
  fill: var(--text-faint);
  font-family: var(--font-code);
  font-size: 10px;
  text-anchor: end;
}

.rx-lv-unit {
  font-family: var(--font-ui);
}

.rx-lv-lvl {
  stroke: var(--rx-c);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.rx-lv-link {
  stroke: var(--rx-c);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.8;
}

.rx-lv-val {
  fill: var(--text);
  font-family: var(--font-code);
  font-size: 10.5px;
  text-anchor: middle;
}

.rx-lv-name {
  fill: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 11px;
  text-anchor: middle;
}

.rx-lv-cap {
  fill: var(--text-faint);
  font-family: var(--font-ui);
  font-size: 10px;
}

.rx-lv-empty {
  fill: var(--text-faint);
  font-family: var(--font-ui);
  font-size: 12px;
  text-anchor: middle;
}

.rx-t {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}

.rx-t th,
.rx-t td {
  padding: 5px 8px;
  border-bottom: var(--hairline) solid var(--border);
  text-align: left;
  vertical-align: baseline;
}

.rx-t thead th {
  color: var(--text-muted);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.rx-t .num {
  font-family: var(--font-code);
  text-align: right;
  white-space: nowrap;
}

.rx-t thead th.num {
  font-family: var(--font-ui);
}

.rx-t tbody th {
  font-weight: var(--weight-regular);
}

.rx-t-name {
  display: block;
  color: var(--text);
}

.rx-t-f {
  color: var(--text-muted);
  font-size: var(--text-2xs);
}

.rx-t-spin {
  margin-left: 6px;
  padding: 0 5px;
  border: var(--hairline) solid color-mix(in oklab, var(--warning) 60%, transparent);
  border-radius: var(--radius-xs);
  color: var(--warning);
  font-size: 10px;
}

.rx-t-wait,
.rx-t-busy,
.rx-t-skip {
  color: var(--text-faint);
}

.rx-t-busy {
  color: var(--text);
  font-family: var(--font-code);
  font-size: var(--text-2xs);
}

.rx-t-err {
  color: var(--danger);
  line-height: var(--leading-ui);
}

.rx-t-skip {
  border-bottom: 1px dotted var(--text-faint);
  cursor: help;
}

.rx-note {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.rx-note.is-warn {
  color: var(--warning);
}

.rx-notes {
  display: grid;
  gap: var(--space-2);
  max-width: 760px;
}

.rx-notes p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
}

/* 3D scene labels (viewer tags). */
.mv-label.mv-scene {
  color: var(--mv-text);
  text-shadow: none;
}

.mv-label.mv-scene.rx-name {
  color: var(--mv-muted);
  font-size: 12px;
  font-weight: 500;
}

.mv-label.mv-scene.rx-op,
.mv-label.mv-scene.rx-arrow {
  color: var(--mv-muted);
  font-size: 24px;
  font-weight: 400;
}

.mv-label.mv-scene.rx-coef {
  font-size: 22px;
  font-weight: 600;
}

/* Run panel. */
.rx-side {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding: var(--space-2);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
}

.rx-side.is-over {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.rx-side-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 2px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.rx-side-n {
  color: var(--text-faint);
  font-size: var(--text-2xs);
}

.rx-chips {
  display: grid;
  gap: 4px;
}

.rx-hint {
  margin: 0;
  padding: 6px 2px;
  color: var(--text-faint);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
}

.rx-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 3px 3px 3px 4px;
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.rx-chip.is-busy {
  border-color: var(--accent);
}

.rx-chip.is-error {
  border-color: color-mix(in oklab, var(--danger) 55%, var(--border));
}

.rx-step {
  display: flex;
  flex: none;
  align-items: center;
  height: 26px;
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--mol-field, var(--bg-sunken));
}

.rx-step button {
  display: grid;
  place-items: center;
  width: 22px;
  height: 24px;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}

.rx-step button:hover:not(:disabled) {
  color: var(--text);
}

.rx-step button:disabled {
  color: var(--text-faint);
  opacity: 0.5;
  cursor: default;
}

.rx-step .icon {
  width: 12px;
  height: 12px;
}

.rx-step span {
  min-width: 18px;
  color: var(--text);
  font-size: var(--text-xs);
  text-align: center;
}

.rx-chip-main {
  display: grid;
  flex: 1;
  min-width: 0;
  line-height: 15px;
}

.rx-chip-name {
  overflow: hidden;
  color: var(--text);
  font-size: var(--text-xs);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rx-chip-f {
  color: var(--text-muted);
  font-size: var(--text-2xs);
}

.rx-add {
  position: relative;
  display: flex;
  align-items: center;
}

.rx-add > .icon {
  position: absolute;
  left: 8px;
  width: 14px;
  height: 14px;
  color: var(--text-faint);
  pointer-events: none;
}

.rx-add .input {
  width: 100%;
  height: 28px;
  padding-left: 28px;
  font-size: var(--text-xs);
}

.rx-pop {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  z-index: var(--z-popover);
  display: grid;
  max-height: 260px;
  padding: 4px;
  overflow-y: auto;
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
}

.rx-pop[hidden] {
  display: none;
}

.rx-opt {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--text-xs);
  text-align: left;
  cursor: pointer;
}

.rx-opt:hover,
.rx-opt.is-cur {
  background: var(--surface-hover);
}

.rx-opt-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rx-opt-f {
  flex: none;
  color: var(--text-muted);
  font-size: var(--text-2xs);
}

.rx-pop-empty {
  margin: 0;
  padding: 6px 8px;
  color: var(--text-faint);
  font-size: var(--text-xs);
}

.rx-yields {
  display: grid;
  place-items: center;
  height: 22px;
  margin: 6px 0 -6px;
}

.rx-yields svg {
  width: 22px;
  height: 22px;
  padding: 3px;
  border: var(--hairline) solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rx-balance {
  min-height: 0;
  margin: var(--space-3) 0 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
}

.rx-balance:empty {
  display: none;
}

.rx-balance[data-state='balanced'] {
  color: var(--success);
}

.rx-balance[data-state='unbalanced'] {
  color: var(--warning);
}

.rx-opts {
  margin-top: var(--space-3);
}

/* Library rows can be picked up on this tab. */
.mol-app[data-tab='reaction'] #lib-list .lib-row[draggable='true'] {
  cursor: grab;
  touch-action: pan-y;
}

.rx-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-toast);
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 10px;
  border: var(--hairline) solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
  color: var(--text);
  font-size: var(--text-xs);
  pointer-events: none;
}

.rx-ghost b {
  font-weight: var(--weight-medium);
}

@media (max-width: 1099px) {
  .rx-res-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .rx-levels {
    max-width: 420px;
  }
}

@media (max-width: 759px) {
  .mol-app[data-tab='reaction'] .mol-stage {
    --rx-top: 52px;
    --rx-scene-h: 260px;
    aspect-ratio: auto;
    max-height: none;
  }

  .mol-app[data-tab='reaction'] .tab-pane[data-pane='reaction'] {
    position: relative;
    inset: auto;
  }

  .rx {
    height: auto;
    padding-top: calc(var(--rx-top) + var(--rx-scene-h));
  }

  .rx.is-empty {
    padding-top: var(--rx-top);
  }

  .rx.is-empty .rx-scene {
    position: relative;
    top: auto;
    min-height: 320px;
  }

  .rx-head {
    padding: 0 var(--space-4);
  }

  .rx-title p {
    font-size: var(--text-xs);
  }

  .rx-results {
    position: relative;
    top: auto;
    padding: var(--space-4);
    overflow: visible;
  }

  .rx-stats {
    grid-template-columns: minmax(0, 1fr);
  }

  .rx-stat {
    grid-template-columns: auto 1fr;
    align-items: baseline;
    column-gap: var(--space-3);
  }

  .rx-stat-s {
    grid-column: 1 / -1;
  }

  .rx-levels {
    max-width: none;
  }
}

/* Correlation energy per molecule (#chart). */
.rx-corr .qc-grid-l {
  stroke: var(--border);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.rx-corr-name {
  fill: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 11px;
  text-anchor: end;
}

.rx-corr-bar {
  fill: var(--accent);
}

.rx-corr-v {
  fill: var(--text);
  font-family: var(--font-code);
  font-size: 10px;
}

.rx-corr-v.is-in {
  fill: var(--on-accent, #fff);
}
