/* PlotLab — page-specific layout and components (Build Pass 1c: three-zone workbench) */

/* Wider work surface for the workbench (scoped to PlotLab's <main>) */
.site-inner--wide {
  max-width: 1440px;
}

.plotlab-page {
  display: grid;
  gap: 14px;
}

/* ---------- Brand bar (page title, fused to the data panel) ---------- */

.plotlab-brandbar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #8b5cf6 0%, var(--accent) 100%);
  color: #ffffff;
}

:root[data-theme="dark"] .plotlab-brandbar {
  background: linear-gradient(180deg, #a78bfa 0%, #8b5cf6 100%);
}

.plotlab-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: #ffffff;
}

.plotlab-beta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
}

.plotlab-beta__icon {
  width: 10px;
  height: 12px;
}

/* ---------- Theme toggle (shared pattern with the timers) ---------- */

.site-header__theme {
  flex-shrink: 0;
}

.theme-segment {
  display: inline-flex;
  align-items: stretch;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--line-strong);
  box-shadow: 0 1px 2px rgba(76, 29, 149, 0.05);
}

.theme-segment__btn {
  position: relative;
  z-index: 1;
  margin: 0;
  padding: 7px 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.theme-segment__btn[aria-pressed="true"] {
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(76, 29, 149, 0.1);
}

:root[data-theme="dark"] .theme-segment__btn[aria-pressed="true"] {
  background: var(--panel-hover);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.theme-segment__btn:hover:not([aria-pressed="true"]) {
  color: var(--text);
}

.theme-segment__btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* ---------- Workbench grid: data | graph | inspector ---------- */

.plotlab-workbench {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 264px;
  gap: 16px;
  align-items: start;
}

/* ---------- Data panel (left) ---------- */

.plotlab-data-panel {
  padding: 0;
  overflow: hidden;
  position: sticky;
  top: calc(var(--nav-height) + 14px);
}

.plotlab-data-body {
  padding: 12px;
}

.plotlab-data-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.plotlab-data-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.plotlab-table-wrap {
  max-height: min(58vh, 560px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
}

.plotlab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.plotlab-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--line-strong);
  padding: 7px 6px;
  font-size: 0.84rem;
  font-weight: 600;
  text-align: center;
}

.plotlab-table td {
  border-bottom: 1px solid var(--line);
  padding: 0;
}

.plotlab-table tr:last-child td {
  border-bottom: none;
}

.plotlab-table__index {
  width: 30px;
}

td.plotlab-table__index {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 6px 4px;
}

input.plotlab-cell {
  width: 100%;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 7px 10px;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

input.plotlab-cell:focus {
  outline: none;
  border-color: transparent;
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}

input.plotlab-cell--invalid {
  box-shadow: inset 0 0 0 2px var(--warning);
  background: var(--warning-soft);
}

.plotlab-data-note {
  min-height: 0;
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--warning);
}

.plotlab-data-note:empty {
  margin: 0;
}

.plotlab-data-panel .plotlab-hint {
  margin-top: 8px;
}

/* ---------- Main panel (centre): fit bar fused to the graph card ---------- */

.plotlab-main-panel {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* Fixed by the viewport, not the row, so opening inspector sections
     can't stretch the graph card. Same thin accent border as the
     Activity Timer's timer card. */
  height: clamp(400px, calc(100vh - 160px), 800px);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line-strong));
}

/* Fit readout bar — near-white field, eyebrow label, colour-coded pills */
.plotlab-fitslab {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  min-height: 50px;
  padding: 9px 18px;
  background: color-mix(in srgb, var(--accent) 3.5%, var(--panel));
  border-bottom: 1px solid var(--line-strong);
  font-variant-numeric: tabular-nums;
}

/* equation = headline (small left pad now the label's gone) */
.plotlab-fitslab__equation {
  display: flex;
  align-items: baseline;
  flex: 0 1 auto;
  gap: 0.3em;
  min-width: 0;
  white-space: nowrap;
  padding-left: 4px;
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text);
}

.plotlab-fitslab__equation var {
  font-style: italic;
  font-weight: 600;
}

.plotlab-fitslab__equation .plotlab-eq__num {
  font-weight: 700;
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

.plotlab-fitslab__equation .plotlab-eq__op {
  color: color-mix(in srgb, var(--text) 50%, var(--muted));
  font-weight: 400;
  font-style: normal;
}

.plotlab-fitslab__equation--empty {
  color: var(--muted);
  font-weight: 500;
  font-size: 1.1rem;
}

/* metrics = pills, pushed right */
.plotlab-fitslab__metrics {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.plotlab-fitslab__metric {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--bg-subtle);
  font-size: 0.82rem;
  white-space: nowrap;
}

.plotlab-fitslab__metric-key {
  color: var(--accent-2);
  font-weight: 700;
}

.plotlab-fitslab__metric-key var {
  font-style: italic;
}

.plotlab-fitslab__metric-eq {
  color: var(--muted);
  font-weight: 500;
}

.plotlab-fitslab__metric-val {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.plotlab-metric__unit {
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.22em;
}

.plotlab-sup {
  font-size: 0.66em;
  vertical-align: super;
  line-height: 0;
  font-weight: 600;
  font-style: normal;
}

/* r strength badge — 3-tier, coloured by |r| (set in analysis-ui.js) */
.plotlab-fitslab__metric.is-weak {
  background: var(--danger-soft);
}

.plotlab-fitslab__metric.is-weak .plotlab-fitslab__metric-key,
.plotlab-fitslab__metric.is-weak .plotlab-fitslab__metric-val {
  color: var(--danger);
}

.plotlab-fitslab__metric.is-moderate {
  background: var(--warning-soft);
}

.plotlab-fitslab__metric.is-moderate .plotlab-fitslab__metric-key,
.plotlab-fitslab__metric.is-moderate .plotlab-fitslab__metric-val {
  color: var(--warning);
}

.plotlab-fitslab__metric.is-strong {
  background: var(--success-soft);
}

.plotlab-fitslab__metric.is-strong .plotlab-fitslab__metric-key,
.plotlab-fitslab__metric.is-strong .plotlab-fitslab__metric-val {
  color: var(--success);
}

/* status note — unchanged: full-width row when present */
.plotlab-fitslab__note {
  flex: 1 1 100%;
  margin: 0;
  padding: 0 4px 2px;
  font-size: 0.78rem;
  color: var(--warning);
}

.plotlab-fitslab__note:empty {
  display: none;
  padding: 0;
}

/* Graph: the dominant element — fills the rest of the centre column */

.plotlab-svg-wrap {
  position: relative;
  flex: 1;
  min-height: 320px;
  background: #ffffff;
  line-height: 0;
}

/* Fullscreen control — attached to the graph frame, not the fit slab */

.plotlab-graph-fs {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 12%, var(--line-strong));
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  box-shadow: 0 1px 4px rgba(76, 29, 149, 0.08);
  cursor: pointer;
  line-height: 0;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.plotlab-graph-fs:hover {
  color: var(--accent-2);
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(76, 29, 149, 0.12);
}

.plotlab-graph-fs:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.plotlab-graph-fs svg {
  width: 16px;
  height: 16px;
}

.plotlab-graph-fs[hidden] {
  display: none;
}

#plotSvg {
  display: block;
  width: 100%;
  height: 100%;
  background: #ffffff;
  font-family: var(--font);
}

/* Fullscreen graph view */

.plotlab-svg-wrap:fullscreen {
  background: #ffffff;
  border: none;
  border-radius: 0;
  height: 100%;
}

.plotlab-fs-exit {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  line-height: 1.2;
}

.plotlab-fs-exit[hidden] {
  display: none;
}

/* ---------- Inspector (right): stacked collapsible sections ---------- */

.plotlab-inspector {
  display: grid;
  gap: 10px;
  align-content: start;
  position: sticky;
  top: calc(var(--nav-height) + 14px);
}

.plotlab-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.plotlab-section__head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  list-style: none;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.plotlab-section__head::-webkit-details-marker {
  display: none;
}

.plotlab-section__head:hover {
  background: var(--panel-hover);
}

.plotlab-section__head:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.plotlab-section[open] > .plotlab-section__head {
  border-radius: var(--radius) var(--radius) 0 0;
}

.plotlab-section__icon {
  width: 15px;
  height: 15px;
  color: var(--accent-2);
  flex-shrink: 0;
}

.plotlab-section__title {
  flex: 1;
  min-width: 0;
}

.plotlab-section__head .plotlab-badge {
  flex-shrink: 0;
}

.plotlab-section__chevron {
  width: 14px;
  height: 14px;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.plotlab-section[open] > .plotlab-section__head .plotlab-section__chevron {
  transform: rotate(180deg);
}

.plotlab-section__body {
  display: grid;
  gap: 10px;
  padding: 2px 12px 13px;
}

.plotlab-section__row {
  display: grid;
  gap: 6px;
}

.plotlab-range {
  display: flex;
  align-items: center;
  gap: 6px;
}

.plotlab-range input {
  flex: 1;
  min-width: 0;
}

.plotlab-section__btnrow {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

/* ---------- Shared control styles ---------- */

.plotlab-inline__label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.plotlab-inline__dash {
  color: var(--muted);
}

.plotlab-input-sm,
.plotlab-section__body input.plotlab-input-sm {
  width: 74px;
  padding: 7px 9px;
  font-size: 0.86rem;
}

.plotlab-select,
.plotlab-section__body select.plotlab-select {
  width: 100%;
  padding: 7px 9px;
  font-size: 0.86rem;
}

/* Variable metadata: title + name on the first row, symbol/unit below */

.plotlab-vargroup {
  display: grid;
  grid-template-columns: 22px 1fr 1fr;
  gap: 6px 8px;
  align-items: center;
}

.plotlab-vargroup input {
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  font-size: 0.86rem;
}

.plotlab-vargroup__title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 700;
  font-style: italic;
  grid-row: 1;
  grid-column: 1;
}

.plotlab-vargroup__name {
  grid-row: 1;
  grid-column: 2 / 4;
}

.plotlab-vargroup__sym {
  grid-row: 2;
  grid-column: 2;
}

.plotlab-vargroup__unit {
  grid-row: 2;
  grid-column: 3;
}

.plotlab-vargroup__pm {
  grid-row: 3;
  grid-column: 1;
  justify-self: center;
}

.plotlab-vargroup__delta {
  grid-row: 3;
  grid-column: 2 / 4;
}

.plotlab-btn-sm {
  padding: 7px 12px;
  font-size: 0.84rem;
}

/* ---------- Planned ("Next pass") controls ---------- */

.plotlab-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
}

.plotlab-planned,
.plotlab-planned label,
.plotlab-planned .plotlab-check {
  color: var(--muted);
  cursor: not-allowed;
}

.plotlab-planned input,
.plotlab-planned select,
.plotlab-planned button {
  cursor: not-allowed;
}

.plotlab-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
  font-size: 0.88rem;
  margin: 0;
  cursor: pointer;
  white-space: nowrap;
}

.plotlab-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
}

.plotlab-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ---------- Utilities ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.tablenum {
  font-variant-numeric: tabular-nums;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  /* Single column: table, then graph, then inspector */
  .plotlab-workbench {
    grid-template-columns: minmax(0, 1fr);
  }

  .plotlab-data-panel {
    order: 0;
    position: static;
  }

  .plotlab-main-panel {
    order: 1;
    height: auto;
  }

  .plotlab-inspector {
    order: 2;
    position: static;
  }

  .plotlab-svg-wrap {
    flex: none;
    height: clamp(320px, 52vh, 560px);
    min-height: 0;
  }

  .plotlab-table-wrap {
    max-height: 44vh;
  }
}
