/* The analysis dialog (js/analysis.js): type tabs, the choices on the left,
   the rows on the right, More settings, and the footer. */

dialog.dlg.analysis-dlg { max-width: min(1000px, calc(100vw - 32px)); }

/* ---- Type tabs: each says what it does; the chosen one opens into the form ---- */

.an-types {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}
.an-type {
  font: inherit;
  text-align: left;
  color: var(--text-primary);
  background: none;
  border: 0;
  border-left: 1px solid var(--border-subtle);
  border-top: 2px solid transparent;
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
  padding: 8px 12px 10px;
  cursor: pointer;
}
.an-type:first-child { border-left: 0; }
.an-type:hover:not(.on) { background: var(--bg-hover); }
.an-type b { display: block; font-weight: 600; }
.an-type span {
  display: block;
  margin-top: 2px;
  font-size: var(--font-size-sm);
  line-height: 1.35;
  color: var(--text-muted);
}
.an-type.on {
  background: var(--bg-elevated);
  border-top-color: var(--accent);
  border-bottom-color: var(--bg-elevated);
}
.an-type.on b { color: var(--accent); }
.an-type.on span { color: var(--text-secondary); }

/* ---- Body: choices left, rows right ---- */

.an-body {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
}

.an-form {
  padding: 14px 16px 16px;
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  column-gap: 12px;
  row-gap: 14px;
  align-content: start;
}
.an-lab { font-weight: 600; color: var(--text-secondary); padding-top: 4px; }
.an-ctl { min-width: 0; position: relative; }
.an-split { grid-column: 1 / -1; border-top: 1px solid var(--border-subtle); }
.an-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.an-hint { margin: 4px 0 0; font-size: var(--font-size-sm); color: var(--text-muted); }
.an-select { min-width: 180px; max-width: 100%; }

.an-num { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.an-num.chg { font-weight: 600; border-color: var(--accent); }
.an-num.invalid { border-color: var(--error); color: var(--error); }

.an-warnline {
  display: inline-block;
  margin-top: 5px;
  padding: 3px 7px;
  font-size: var(--font-size-sm);
  color: var(--warning);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
}

.an-median { margin-top: 7px; }
.an-median label { cursor: pointer; }

/* ---- Covariates: formula field with a fixed ~ ---- */

.an-formula {
  display: flex;
  align-items: stretch;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.an-formula:focus-within { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.an-tilde {
  padding: 3px 8px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-right: 1px solid var(--border-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.an-formula input.an-formula-text {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.an-formula input.an-formula-text:focus { outline: none; }

.an-tools { display: flex; gap: 6px; margin-top: 6px; }
.analysis-dlg .btn.pressed { background: var(--accent-muted); }

.an-menu {
  position: absolute;
  z-index: 3;
  min-width: 270px;
  max-height: 260px;
  overflow: auto;
  padding: 4px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.an-menu-item {
  font: inherit;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 5px 10px;
  text-align: left;
  color: var(--text-primary);
  background: none;
  border: 0;
  cursor: pointer;
}
.an-menu-item:hover, .an-menu-item:focus-visible { background: var(--accent-muted); outline: none; }
.an-menu-item code { color: var(--text-secondary); }
.an-menu-type { font-size: var(--font-size-sm); color: var(--text-muted); }
.an-menu-empty { padding: 5px 10px; font-size: var(--font-size-sm); color: var(--text-muted); }

/* ---- Many-outcome PLS: the outcome checklist ---- */

.an-checklist {
  max-height: 240px;
  overflow: auto;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.an-check {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
}
.an-check:last-child { border-bottom: 0; }
.an-check small { margin-left: auto; font-size: var(--font-size-sm); color: var(--text-muted); }

/* ---- Groups list ---- */

.an-groups-wrap { max-height: 240px; max-width: 360px; overflow: auto; }
.an-groups { width: 100%; border-collapse: collapse; }
.an-groups td { padding: 3px 0; border-bottom: 1px solid var(--border-subtle); }
.an-groups td.n { padding-left: 16px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.an-groups tr.out td { color: var(--disabled-text); }

/* ---- More settings ---- */

.an-more { grid-column: 1 / -1; border-top: 1px solid var(--border-subtle); }
.an-fold {
  font: inherit;
  font-weight: 600;
  color: var(--text-primary);
  background: none;
  border: 0;
  padding: 8px 0 4px;
  cursor: pointer;
}
.an-fold-n { font-weight: 400; color: var(--text-secondary); }
.an-settings {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  gap: 6px 12px;
  align-items: center;
  padding: 4px 0 2px 16px;
}
.an-set-lab { color: var(--text-secondary); }
.an-set-lab.chg { color: var(--text-primary); font-weight: 600; }
.an-set-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.an-set-def { font-size: var(--font-size-sm); color: var(--text-muted); margin-left: 2px; }
.an-reset { margin-left: 4px; }

/* ---- Rows: a subtraction from the file's rows to the rows the analysis uses ---- */

.an-rows {
  padding: 14px 16px 16px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
}
.an-rows h4 { margin: 0 0 8px; font-size: var(--font-size-base); font-weight: 600; }
.an-funnel { width: 100%; border-collapse: collapse; }
.an-funnel td { padding: 3px 0; vertical-align: baseline; }
.an-funnel td.n {
  width: 1%;
  padding-right: 12px;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.an-funnel tr.start td { color: var(--text-secondary); padding-bottom: 5px; }
.an-funnel tr.out td { border-top: 1px solid var(--border-subtle); }
.an-funnel tr.out td.n { color: var(--error); }
.an-funnel tr.kept td { border-top: 2px solid var(--border); padding-top: 6px; font-weight: 600; }
.an-funnel tr.kept td.n { font-size: var(--font-size-xl); }
.an-bar {
  height: 6px;
  margin: 8px 0 0;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--error-bg);
}
.an-bar span { display: block; height: 100%; background: var(--accent); }
.an-rows .an-hint { margin-top: 10px; }
.an-empty { margin: 4px 0 0; color: var(--text-muted); }

/* ---- Footer: a run error on its own line above the buttons ---- */

.analysis-dlg .dlg-footer { flex-wrap: wrap; }
.an-error {
  flex-basis: 100%;
  padding: 6px 10px;
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
}
.an-why { font-size: var(--font-size-sm); color: var(--text-secondary); margin-right: 4px; }

@media (max-width: 720px) {
  .an-types { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-body { grid-template-columns: minmax(0, 1fr); }
  .an-rows { border-left: 0; border-top: 1px solid var(--border-subtle); }
  .an-form { grid-template-columns: minmax(0, 1fr); row-gap: 6px; }
  .an-lab { padding-top: 8px; }
  .an-settings { grid-template-columns: minmax(0, 1fr); padding-left: 0; }
}
