/* The tool rail — one look for the left rail beside a tool's content.
 *
 * Four tool pages keep a rail beside what they show: /nutrient (its seven
 * views and the greenhouse picker), /climate (greenhouse, date, crop),
 * /weather (station and period) and /energy's CHP workspace (its inputs). Each
 * used to draw it in its own sheet — four copies of the same two-column grid,
 * four panels that did not match, three ways of styling the one greenhouse
 * picker. Copies drift, and these had: climate's pickers set display:flex and
 * so ignored `hidden`, nutrient's items took the generic lift-and-gold hover,
 * and nutrient's hover and current item looked the same. This sheet is the one
 * copy; the pages that use it link it as
 *   <link rel="stylesheet" href="../css/tool-workspace.css?v=1">
 * directly after dashboard.css.
 *
 * Why there, and why it still wins. dashboard.css is the components layer, so
 * the rail sits with it: before the page sheets, which may adjust it, and
 * before modern-neutral.css, which the README puts last. Load order alone
 * would let modern-neutral's one-class rules (`input`, `.note-box`,
 * `.help-text`) repaint the rail, so every rule here is scoped .hh-workspace,
 * .hh-rail or .hh-fold and, inside the rail, reaches at least (0,2,0). That
 * beats them wherever this file loads — which matters for nutrient.css, which
 * loads after modern-neutral.
 *
 * What stays in page sheets: the rail's width (--hh-rail-w on the page's
 * workspace) and features only one page has — nutrient's icon mode, CHP's
 * label | control | unit field grid. Nothing else: a page sheet that draws
 * the workspace grid, styles its rail container or spaces its children,
 * gives a shared rail class a background, border, padding or margin of its
 * own, or restyles the greenhouse picker is a second copy, and
 * tests/frontend/tool_workspace_test.ts fails on it (the few deliberate
 * adjustments are listed there by selector).
 *
 * Deliberately NOT position:sticky: .dash-shell, .dash-main and .container
 * set overflow:hidden, and a sticky element cannot stick inside an ancestor
 * that does. And nothing here names a bare [aria-current] or a --dash-* token,
 * so the app's own left sidebar (.dash-sidebar) is out of reach.
 */

/* ── The workspace: rail, then content ───────────────────────────────────── */

.hh-workspace {
  display: grid;
  grid-template-columns: var(--hh-rail-w, 280px) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

/* A grid item's min-width is its content's; without this one wide table in
   the content pushes the rail off the page. */
.hh-workspace > * {
  min-width: 0;
}

/* A tab with nothing for the rail (climate's Columns and Model) hides it, and
   the content takes the whole row instead of leaving an empty column. */
.hh-workspace:has(> .hh-rail[hidden]) {
  grid-template-columns: minmax(0, 1fr);
}

/* ── The panel ───────────────────────────────────────────────────────────── */

.hh-workspace .hh-rail {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
}

/* `hidden` must win. A section or picker with display:flex in some other
   sheet otherwise stays on screen while hidden — climate's two greenhouse
   pickers both showed once Rules had drawn its own. */
.hh-rail[hidden],
.hh-rail [hidden] {
  display: none !important;
}

/* Nothing in the rail shown yet — greenhouses still loading, a tab whose
   sections are all hidden: keep the column, so the content does not jump
   sideways when they arrive, but draw no empty box.
   "Shown" here is looser than for the hairlines below: a section whose every
   child is hidden still counts, because that test is itself a :has(), and
   :has() cannot sit inside another. A rail whose only visible section is such
   a box would draw an empty panel; no page has one — climate hides a section
   by its own `hidden`, and CHP's folds are always there — and a page that
   needs one should hide the wrapper by attribute too. */
.hh-workspace .hh-rail:not(:has(> .hh-rail__section:not([hidden], :empty))) {
  visibility: hidden;
}

/* ── Sections ────────────────────────────────────────────────────────────────
   Each direct child of the rail is a section; a hairline separates two shown
   ones and never tops the first. "Shown" is: not hidden, not empty (a mount
   nothing has drawn into yet), and not a box whose every child is hidden. The
   last is spelled `:has(> [hidden]):not(:has(> :not([hidden])))` rather than
   the shorter `:not(:has(> :not([hidden])))` alone, because a section that
   holds only text, with no element child for :has() to find, would read as
   empty under the short form. No section is text-only today; the long form
   keeps one from vanishing the day it is. */
.hh-rail .hh-rail__section:empty,
.hh-rail .hh-rail__section:has(> [hidden]):not(:has(> :not([hidden]))) {
  display: none;
}

/* Before the spacing below, so a section's own children keep their gap. */
.hh-rail .note-box {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs);
  line-height: 1.45;
  background: var(--bg-card);
}

/* A note box's paragraphs are in its type. The base `p` rule
   (shared-styles.css) sets every paragraph at body size, which in a 12 px
   box is a 16 px block under a 12 px title — /weather's incomplete-period
   note was exactly that once its own copy of these rules went. */
.hh-rail .note-box p {
  margin: var(--space-1) 0 0;
  font: inherit;
}

.hh-rail .hh-rail__section:not([hidden], :empty, :has(> [hidden]):not(:has(> :not([hidden]))))
  ~ .hh-rail__section:not([hidden], :empty, :has(> [hidden]):not(:has(> :not([hidden])))) {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

/* Inside a section, its parts are a step apart. Not the nav (its items have
   their own gap), not a picker (label sits on its select) and not a fold. */
.hh-rail .hh-rail__section:not(.hh-rail__nav, .hh-gh-picker, details) > * + * {
  margin-top: var(--space-3);
}

/* ── Headings, labels, notes ─────────────────────────────────────────────── */

.hh-rail .hh-rail__heading,
.hh-rail .hh-gh-picker label,
.hh-rail .input-item label {
  display: block;
  margin: 0 0 var(--space-1);
  padding: 0;
  border: 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: var(--lh-snug, 1.3);
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: normal;
}

/* A heading over a run of headed cards — CHP's buffer planning, "A." and
   "B." — is one step above the cards' own headings: larger, in the primary
   text colour, with more room above than a card has from the one before it.
   Padding rather than margin above, so a page's own heading margin still
   adds to it instead of replacing it. */
.hh-rail .hh-rail__heading--section {
  margin-bottom: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-primary);
}

.hh-rail .hh-rail__heading--section:not(:first-child) {
  padding-top: var(--space-2);
}

.hh-rail .hh-rail__note,
.hh-rail .help-text {
  font-size: var(--fs-xs);
  font-weight: 400;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* What a page draws inside a note takes the note's type: climate's "no
   greenhouse yet" prompt is a .climate-empty, centred and italic in the
   content column, and would be both in a 280 px panel. */
.hh-rail .hh-rail__note :is(p, div) {
  margin: 0;
  padding: 0;
  font: inherit;
  font-style: normal;
  text-align: left;
  color: inherit;
}

.hh-rail .hh-rail__note a,
.hh-rail .help-text a {
  color: var(--accent);
}

/* ── Controls ────────────────────────────────────────────────────────────── */

.hh-rail :is(input:not([type='checkbox'], [type='radio'], [type='file']), select) {
  font-family: inherit;
  font-size: var(--fs-sm);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
}

.hh-rail :is(input:not([type='checkbox'], [type='radio'], [type='file']), select):focus {
  outline: none;
  border-color: var(--accent-mid);
  box-shadow: 0 0 0 3px var(--accent-tint-12);
}

.hh-rail .input-group {
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: var(--space-3);
  margin: 0;
}

/* Dense: CHP's fifteen folds of label | control | unit rows. The greenhouse
   picker above them keeps the default size — it is the rail's one choice. */
.hh-rail--dense :is(.input-field, .cfg-field) :is(input:not([type='checkbox'], [type='radio'], [type='file']), select) {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-xs);
}

.hh-rail--dense :is(.input-field, .cfg-field) label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-secondary);
}

/* The shared greenhouse picker (greenhouse-picker.js puts .hh-gh-picker on
   every one it draws). No display rule on the container, so `hidden` works. */
.hh-rail .hh-gh-picker select {
  width: 100%;
  box-sizing: border-box;
}

/* shared-styles.css sizes a field's select to its options (18 October 2026).
   In the rail a choice is as wide as the rail, like the greenhouse picker
   above it — a station list half as wide would look like a different control. */
.hh-rail :is(.input-field, .input-item) > select {
  width: 100%;
}

/* ── Navigation (nutrient's views) ───────────────────────────────────────── */

.hh-rail .hh-rail__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.hh-rail .hh-rail__item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  width: 100%;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}

.hh-rail .hh-rail__item svg {
  flex: none;
}

.hh-rail .hh-rail__label {
  min-width: 0;
}

.hh-rail .hh-rail__item:hover {
  background: var(--accent-tint-08);
  color: var(--text-primary);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

/* The generic button hover lifts and casts a gold shadow (shared-styles.css,
   button:hover); in a panel of quiet controls that reads as a glitch. */
.hh-rail :is(button, .btn):hover {
  transform: none;
  box-shadow: none;
}

/* The current item, after the hover reset so its bar survives a hover. A
   white tab with a green bar on the left, as the app sidebar marks the open
   tool — different from hover's tint, so you can tell where you are from
   where the pointer is. */
.hh-rail .hh-rail__item[aria-current='page'] {
  background: var(--bg-card);
  color: var(--accent);
  box-shadow:
    inset 3px 0 0 var(--accent),
    var(--shadow-sm);
}

/* Small really is small: .btn-secondary's own padding would otherwise win. */
.hh-rail .btn--sm {
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-xs);
}

.hh-rail .hh-rail__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* The primary action takes a row of its own; shared-styles gives .btn-primary
   a width and a margin for page-level use that a wrapping row does not want.
   It is control-sized even when the markup says .btn--sm, as /weather's Apply
   does beside its small presets: the rail's main action should not be its
   smallest control. */
.hh-rail .hh-rail__actions > .btn-primary {
  flex: 1 1 100%;
  width: auto;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-sm);
}

/* ── Folds ───────────────────────────────────────────────────────────────────
   A <details> with one chevron. Not limited to rails: CHP's result panels use
   the same head without changing their frame. */

.hh-fold > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  cursor: pointer;
}

.hh-fold > summary::-webkit-details-marker {
  display: none;
}

.hh-fold > summary::marker {
  content: '';
}

.hh-fold > summary::after {
  content: '';
  flex: none;
  width: 0.45em;
  height: 0.45em;
  margin-left: auto;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: rotate(-45deg);
  transition: transform var(--dur-fast);
}

.hh-fold[open] > summary::after {
  transform: rotate(45deg);
}

@media (prefers-reduced-motion: reduce) {
  .hh-fold > summary::after {
    transition: none;
  }
}

/* In a rail the fold heads are the panel's section heads. */
.hh-rail .hh-fold > summary {
  min-height: var(--space-6);
  padding: var(--space-2) 0;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.hh-rail .hh-fold > summary :is(i, svg) {
  flex: none;
  width: 1rem;
  text-align: center;
  color: var(--accent);
}

.hh-rail .hh-fold > summary:hover {
  color: var(--accent);
}

.hh-rail .hh-fold + .hh-fold {
  border-top: 1px solid var(--border);
}

.hh-rail .hh-fold--sub > summary {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.hh-rail .hh-fold--sub[open] > summary {
  color: var(--text-primary);
}

/* ── Focus ───────────────────────────────────────────────────────────────── */

.hh-rail :is(button, summary, a, select, input):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Cards inside a rail ─────────────────────────────────────────────────── */

/* A page section card carried into the rail loses its own frame: the panel
   is the frame, and a card in a panel is a box in a box. */
.hh-rail :is(.input-section, .results-section) {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}

/* ── Phones and narrow tablets ───────────────────────────────────────────────
   The one width this sheet switches at. Below it two columns do not both fit,
   so the rail sits above its content; a nav becomes a strip that scrolls
   sideways, its current item marked by a bar underneath rather than beside;
   and controls go to 16 px, because iOS zooms in on focus below that. */
@media (max-width: 900px) {
  .hh-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .hh-rail :is(input:not([type='checkbox'], [type='radio'], [type='file']), select) {
    font-size: var(--fs-md, 16px);
  }

  .hh-rail .hh-rail__nav {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .hh-rail .hh-rail__item {
    flex: none;
    width: auto;
    white-space: nowrap;
  }

  .hh-rail .hh-rail__item[aria-current='page'] {
    box-shadow: inset 0 -3px 0 var(--accent);
  }

  /* A compact rail — /climate's: a greenhouse and a day — is one line above
     its content rather than a panel of stacked fields. Stacked, a phone's
     first screen was the greenhouse, the date and a crop box before anything
     about the day, and the tab row under them moved with every tab (ARR-18,
     X-28, BRIEF-26). The sections sit side by side and wrap only when they
     must; a lone field's label is kept for screen readers only, because its
     value says what it is (the greenhouse's name, a date), while a group of
     fields (From, To) keeps its labels to tell them apart. */
  .hh-rail.hh-rail--compact {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-2) var(--space-3);
  }

  .hh-rail.hh-rail--compact > .hh-rail__section {
    flex: 1 1 9rem;
    min-width: 0;
  }

  /* Side by side, not under each other: no hairline over the next section.
     The selector is the one that draws it, so it wins on specificity. */
  .hh-rail.hh-rail--compact
    .hh-rail__section:not([hidden], :empty, :has(> [hidden]):not(:has(> :not([hidden]))))
    ~ .hh-rail__section:not([hidden], :empty, :has(> [hidden]):not(:has(> :not([hidden])))) {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  /* Not an independent picker's label: Rules' "Rules for" keeps its own
     choice, and without its label it reads as the page's greenhouse. */
  .hh-rail.hh-rail--compact :is(.hh-gh-picker:not([data-independent]), .input-item:only-child) > label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .hh-rail.hh-rail--compact :is(input:not([type='checkbox'], [type='radio'], [type='file']), select) {
    width: 100%;
    box-sizing: border-box;
  }

  /* A group of fields (History's From and To) is one short line: side by
     side, each label in front of its field, the section twice as wide as a
     lone field. With the rail's 10rem columns they stacked in one narrow
     column that ran past its section, labels above, and the rail was three
     times as tall on History as on Upload (ARR-18). */
  .hh-rail.hh-rail--compact > .hh-rail__section:has(> .input-group) {
    flex: 2 1 14rem;
  }

  .hh-rail.hh-rail--compact .input-group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
  }

  .hh-rail.hh-rail--compact .input-group > .input-item {
    flex-direction: row;
    align-items: center;
    gap: var(--space-1);
    min-width: 0;
  }

  .hh-rail.hh-rail--compact .input-group > .input-item > label {
    flex: none;
    margin: 0;
  }

  .hh-rail.hh-rail--compact .input-group > .input-item > input {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* A fold (climate's crop) takes its own short line, closed. */
  .hh-rail.hh-rail--compact > .hh-rail__section:has(> .hh-fold) {
    flex-basis: 100%;
  }

  .hh-rail.hh-rail--compact .hh-fold > summary {
    min-height: 0;
    padding: var(--space-1) 0;
  }
}
