/* History has its own scroll surfaces; studio and training pages keep their layout. */
body.history-mode {
  height: 100dvh;
  overflow: hidden;
}

body.history-mode #app,
body.history-mode .workspace {
  height: 100%;
  min-height: 0;
}

body.history-mode .workspace {
  display: flex;
  flex-direction: column;
}

body.history-mode .topbar #breadcrumb,
body.history-mode .topbar .text-button { white-space: nowrap; }

body.history-mode .topbar {
  flex: 0 0 64px;
  height: 64px;
}

body.history-mode .workspace main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 22px 26px 22px;
}

body.history-mode .page-intro {
  display: none;
}

body.history-mode .page-footer {
  display: none;
}

#history-mobile-toggle {
  display: none;
}

body.history-mode #history-shell {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(300px, 320px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "filters filters" "records detail";
  gap: 16px 18px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

body.history-mode #history-filters {
  grid-area: filters;
  min-width: 0;
  padding: 14px 16px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

body.history-mode #history-workspace {
  grid-area: records;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
  border-radius: 14px;
}

body.history-mode .history-rail-heading {
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

body.history-mode .history-rail-heading h2 {
  font-size: 13px;
  white-space: nowrap;
}

body.history-mode .history-rail-heading .count {
  white-space: nowrap;
}

body.history-mode .history-toolbar {
  display: grid;
  flex-shrink: 0;
  grid-template-columns: minmax(150px, 1.5fr) repeat(3, minmax(108px, 1fr)) minmax(92px, .8fr) minmax(86px, .75fr) auto auto;
  align-items: end;
  gap: 9px;
  padding: 0;
}

body.history-mode .history-toolbar label {
  display: grid;
  min-width: 0;
  margin: 0;
  gap: 6px;
  font-size: 11px;
  color: #71806a;
  font-weight: 500;
}

body.history-mode .history-toolbar .history-search-field {
  min-width: 0;
}

body.history-mode .history-toolbar input,
body.history-mode .history-toolbar select {
  height: 40px;
  min-height: 40px;
  min-width: 0;
  padding: 9px 10px;
  font-size: 12px;
  border-radius: 8px;
  text-overflow: ellipsis;
}

body.history-mode .history-toolbar button {
  min-height: 40px;
  padding: 9px 12px;
  font-size: 12px;
  white-space: nowrap;
}

body.history-mode .history-toolbar [data-exp-clear] {
  padding-left: 8px;
  padding-right: 8px;
  color: #6d7b65;
  background: transparent;
}

body.history-mode .history-toolbar [data-exp-clear]:hover {
  background: #f2f5ed;
}

body.history-mode #experiment-sync {
  flex-shrink: 0;
  padding: 9px 0 10px;
  margin: 0;
  color: #7f8b76;
  font-size: 10px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

body.history-mode .history-records {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 6px 8px 10px;
}

body.history-mode #experiment-list {
  min-width: 0;
}

body.history-mode .history-entry-group {
  margin: 0 0 8px;
}

body.history-mode .history-group-heading {
  position: sticky;
  top: -6px;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  padding: 9px 9px;
  border-radius: 7px;
  background: #fff;
  color: #43533c;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
}

body.history-mode .history-group-heading:hover {
  background: #f5f7f0;
}

body.history-mode .history-group-icon {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: #eef3e6;
  color: #6a8355;
  font-size: 13px;
  font-weight: 400;
}

body.history-mode .history-group-label {
  flex: 1;
  min-width: 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

body.history-mode .history-group-count {
  flex-shrink: 0;
  min-width: 21px;
  padding: 1px 5px;
  border-radius: 5px;
  background: #f1f4ed;
  color: #7b8a6e;
  font-size: 10px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

body.history-mode .history-group-chevron {
  flex-shrink: 0;
  width: 13px;
  text-align: center;
  color: #8b9780;
  transform-origin: center;
  transition: transform .15s;
}

body.history-mode .history-group-heading[aria-expanded="false"] .history-group-chevron {
  transform: rotate(-90deg);
}

body.history-mode .history-group-items {
  padding: 2px 0 0;
}

body.history-mode #history-workspace .experiment-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  padding: 11px 12px;
  margin: 0 0 5px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #fafbf7;
  transition: background .15s, border-color .15s;
}

body.history-mode #history-workspace .experiment-card:hover {
  background: #f2f6eb;
  border-color: #dde6d4;
}

body.history-mode #history-workspace .experiment-card.selected {
  background: #edf4e4;
  border-color: #b0c696;
  box-shadow: inset 3px 0 0 #729258;
}

body.history-mode #history-workspace .experiment-title {
  display: block;
  width: 100%;
  padding: 0;
  font-size: 13px;
  line-height: 1.55;
  color: #304b32;
  overflow-wrap: anywhere;
}

body.history-mode #history-workspace .experiment-title[aria-current] {
  color: #234428;
}

body.history-mode #history-workspace .experiment-main p {
  margin: 6px 0;
  font-size: 10px;
  line-height: 1.7;
}

body.history-mode #history-workspace .experiment-main .experiment-card-caption {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 5px;
  color: #829076;
  font-size: 10px;
  line-height: 1.5;
}

body.history-mode #history-workspace .experiment-card-caption > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.history-mode #history-workspace .experiment-card-caption time {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

body.history-mode #history-workspace .experiment-main .experiment-card-context {
  margin: 5px 0 0;
  color: #7c8971;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.history-mode #history-workspace .experiment-main > small.mono {
  display: none;
}

body.history-mode #history-workspace .experiment-progress {
  gap: 6px 8px;
  margin: 7px 0 0;
  font-size: 10px;
  line-height: 1.6;
}

body.history-mode #history-workspace .experiment-progress .status {
  padding: 3px 8px;
  font-size: 10px;
}

body.history-mode #history-workspace .experiment-actions {
  width: 100%;
  justify-content: flex-end;
  gap: 8px;
}

body.history-mode #history-workspace .experiment-actions [data-exp-open] {
  display: none;
}

body.history-mode #history-workspace .experiment-actions [data-exp-rename] {
  min-height: 26px;
  padding: 3px 0 0 8px;
  font-size: 10px;
}

body.history-mode #history-workspace .history-empty {
  padding: 36px 12px;
}

.history-pagination,
.history-page-jump { display: flex; align-items: center; gap: 3px; }
.history-pagination { flex: none; min-width: 0; }
.history-pagination button { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 28px; min-height: 28px; padding: 0; border-radius: 6px; font-size: 16px; line-height: 1; }
.history-pagination button:disabled { opacity: .4; }
.history-page-jump { margin: 0; color: #75836c; font-size: 11px; font-variant-numeric: tabular-nums; }
.history-page-jump input { width: 34px; min-width: 0; height: 28px; min-height: 28px; margin: 0; padding: 3px; border-radius: 6px; text-align: center; font-size: 12px; appearance: textfield; -moz-appearance: textfield; }
.history-page-jump input::-webkit-inner-spin-button,
.history-page-jump input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.history-page-jump [data-exp-total-pages] { min-width: 14px; text-align: center; }
.history-page-jump [data-exp-jump] { font-size: 13px; }


body.history-mode #history-detail {
  grid-area: detail;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  border-radius: 14px;
  scroll-padding-top: 18px;
}

body.history-mode #history-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  padding: 42px 28px;
  text-align: center;
  border: 1px dashed #cfdac5;
  border-radius: 14px;
  background: #fcfdf9;
  color: #7c8d6e;
}

body.history-mode #history-empty h2 {
  margin-bottom: 10px;
  color: #45613b;
  font-size: 20px;
}

body.history-mode #history-empty p {
  max-width: 340px;
  margin-bottom: 0;
  font-size: 12px;
  line-height: 1.9;
}

body.history-mode #task-panel {
  min-height: 100%;
  margin: 0;
  padding: 24px;
  border-radius: 14px;
}

body.history-mode .task-heading {
  align-items: flex-start;
}

body.history-mode .task-heading > div {
  min-width: 0;
}

body.history-mode .task-heading > .status {
  flex-shrink: 0;
}

/* A horizontal chain leaves the full detail width available for inputs and audio. */
body.history-mode #workflow-view {
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

body.history-mode .node-graph {
  position: static;
  display: flex;
  align-items: stretch;
  gap: 9px;
  padding: 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
}

body.history-mode .flow-node {
  flex: 0 0 188px;
  width: 188px;
  padding: 13px;
  scroll-snap-align: start;
}

body.history-mode .flow-node > strong {
  font-size: 13px;
}

body.history-mode .flow-node-top {
  margin-bottom: 9px;
}

body.history-mode .flow-node p {
  margin: 6px 0 9px;
  font-size: 10px;
}

body.history-mode .flow-endpoint {
  flex: 0 0 128px;
  justify-content: center;
}

body.history-mode .flow-edge {
  flex: 0 0 55px;
  justify-content: center;
  padding: 0;
}

body.history-mode .flow-edge b {
  transform: rotate(-90deg);
}

body.history-mode .flow-edge span {
  font-size: 9px;
}

body.history-mode .node-inspector {
  min-width: 0;
  padding: 19px;
}

body.history-mode .node-kv > div {
  grid-template-columns: minmax(105px, .4fr) minmax(0, 1fr);
}

@media (min-width: 1600px) {
  body.history-mode #history-shell {
    grid-template-columns: 340px minmax(0, 1fr);
    column-gap: 22px;
  }

  body.history-mode .workspace main {
    padding-left: 32px;
    padding-right: 32px;
  }
}

@media (max-width: 1279px) {
  body.history-mode .history-toolbar {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  body.history-mode .history-toolbar .history-search-field {
    grid-column: span 2;
  }

  body.history-mode .history-toolbar label:last-of-type {
    grid-column: span 2;
  }
}

@media (max-width: 1150px) {
  body.history-mode .workspace main {
    padding: 20px 18px 18px;
  }

  body.history-mode #history-shell {
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 14px;
  }

  body.history-mode #task-panel {
    padding: 19px;
  }

  body.history-mode .node-kv > div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

@media (max-width: 960px) {
  body.history-mode {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }

  body.history-mode #app,
  body.history-mode .workspace {
    height: auto;
    min-height: 100dvh;
  }

  body.history-mode .workspace main {
    display: block;
    padding: 20px 18px;
  }

  body.history-mode .page-intro {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
  }

  body.history-mode .page-intro h1 {
    font-size: 22px;
  }

  body.history-mode #history-mobile-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 5px 10px;
    flex-shrink: 0;
    font-size: 12px;
  }

  body.history-mode #history-shell {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: visible;
  }

  body.history-mode #history-workspace {
    display: none;
    max-height: min(490px, 54dvh);
    flex: none;
  }

  body.history-mode.history-list-open #history-workspace {
    display: flex;
  }

  body.history-mode .history-rail-heading { padding: 9px 10px; }
  body.history-mode .history-pagination button,
  body.history-mode .history-page-jump input { height: 34px; min-height: 34px; }
  body.history-mode .top-right { gap: 12px; }
  body.history-mode .top-right .live-dot,
  body.history-mode #connection,
  body.history-mode .top-right .tag { display: none; }

  body.history-mode #experiment-sync {
    padding-top: 8px;
    padding-bottom: 9px;
  }

  body.history-mode .history-records {
    flex: 1 1 auto;
    min-height: 105px;
  }

  body.history-mode #history-detail {
    overflow: visible;
    scrollbar-gutter: auto;
    min-height: 300px;
  }

  body.history-mode #history-empty {
    min-height: 300px;
  }

  body.history-mode #task-panel {
    min-height: 300px;
  }
}

@media (max-width: 640px) {
  body.history-mode .topbar-prefix { display: none; }
  body.history-mode .workspace {
    min-height: 0;
  }

  body.history-mode .topbar {
    flex-basis: 48px;
    height: 48px;
  }

  body.history-mode .workspace main {
    padding: 18px 12px;
  }

  body.history-mode .page-intro {
    margin-bottom: 14px;
  }

  body.history-mode .page-intro h1 {
    font-size: 21px;
  }

  body.history-mode .page-intro .eyebrow {
    font-size: 8px;
  }

  body.history-mode #history-filters {
    padding: 13px 12px 0;
  }

  body.history-mode .history-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  body.history-mode .history-toolbar .history-search-field {
    grid-column: 1 / -1;
  }

  body.history-mode .history-toolbar label:last-of-type {
    grid-column: 1 / -1;
  }

  body.history-mode .history-toolbar input,
  body.history-mode .history-toolbar select,
  body.history-mode .history-toolbar button {
    min-height: 42px;
  }

  body.history-mode #task-panel {
    padding: 17px 14px;
  }

  body.history-mode .task-heading {
    gap: 10px;
  }

  body.history-mode .task-heading h2 {
    font-size: 17px;
  }

  body.history-mode .task-heading > .status {
    padding: 5px 8px;
    font-size: 10px;
  }

  body.history-mode .node-inspector {
    padding: 15px 12px;
  }

  body.history-mode .flow-heading > .pill {
    display: none;
  }

  body.history-mode .experiment-inputs {
    margin-top: 18px;
    padding-top: 16px;
  }

  body.history-mode .input-audition,
  body.history-mode .saved-prompt {
    padding: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.history-mode #history-workspace .experiment-card,
  body.history-mode .history-group-chevron {
    transition: none;
  }
}

/* Classification is independent metadata, shared by list cards and result detail. */
.experiment-classification {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 5px;
  margin: 8px 0;
  font-size: 10px;
  line-height: 1.6;
}
.experiment-classification > span {
  min-width: 0;
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 5px;
  overflow-wrap: anywhere;
  background: #eef2e9;
  color: #4c6244;
}
.experiment-classification b { font-weight: 500; color: #75836c; }
.experiment-classification .classification-experiment { background: #eff2f5; color: #4c5c6d; }
.experiment-classification .classification-stage,
.experiment-classification.is-unclassified > span { background: #f3f2ee; color: #807b6d; }
#task-classification { margin: 12px 0; font-size: 12px; color: #75836c; }
#task-classification .experiment-classification { font-size: 12px; }

.submitter-field { display: grid; grid-template-columns: auto minmax(150px, 280px) 1fr; align-items: center; gap: 12px; margin: 0 0 18px; padding: 14px 18px; background: #f4f7ef; border: 1px solid #e1e8d9; border-radius: 12px; }
.submitter-field label { margin: 0; font-size: 12px; font-weight: 600; }
.submitter-field label span { font-weight: 400; color: #7b8971; margin-left: 5px; }
.submitter-field input { min-height: 36px; margin: 0; padding: 8px 10px; font-size: 13px; }
.submitter-field small { color: #78866e; font-size: 11px; line-height: 1.6; }
.experiment-submitter { margin: 7px 0; color: #68765e; font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; }
.experiment-submitter b { font-weight: 500; color: #85907c; margin-right: 4px; }
#task-classification .experiment-submitter { font-size: 12px; }
@media (max-width: 640px) { .submitter-field { grid-template-columns: 1fr; gap: 8px; padding: 12px 14px; } }
