/* ============================================================
   Workbench module, workstation 03: drawing sheet + nomenclature.
   Loaded after styles.css, so it overrides the
   "POSTE 03 - NOMENCLATURE" banner there.
   Two entries only (REF 004 / REF 005), shown bigger, each with a
   main view and a secondary view.
   ============================================================ */

/* ---------- Drawing sheet: figures ---------- */

/* The bottom band holds the numbered dots under the figures; it must
   clear the corner cartouche, which is anchored bottom right. */
.nomen-plate { margin: 1.2rem 0 5.9rem; }

/* Two figures: more air between them than between the views of one figure */
.nomen-figs { gap: clamp(1.8rem, 5vw, 3.2rem); }

/* The button carries the whole figure (views + captions) */
.nomen-fig .fiche-open {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* Two views per figure: a main view, then a smaller secondary view
   sitting on the same baseline, as on a technical drawing. */
.nomen-views {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: clamp(0.5rem, 1.4vw, 0.9rem);
  align-items: end;
}

/* .nomen-shot is a <span> here, so the <button> content stays valid */
.nomen-shot {
  display: block;
  background: var(--card);            /* CAD renders are on white: seamless */
}
.nomen-shot.is-main { aspect-ratio: 4 / 3; }
/* Square: fits the landscape view 1b and the portrait view 2b alike */
.nomen-shot.is-sub  { aspect-ratio: 1 / 1; }

.nomen-shot img {
  object-fit: contain;                /* never crop a CAD render */
  padding: 0.45rem;
  background: var(--card);
}

/* View tag, like a view label on a drawing */
.nomen-view-tag {
  position: absolute; z-index: 2;
  left: 0; bottom: 0;
  padding: 0.12rem 0.38rem;
  font-family: var(--font-mono); font-size: 0.58rem; line-height: 1.3;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  background: var(--card);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  transition: color 0.2s, border-color 0.2s;
}

/* FIG. n / project name caption: readable, not tiny */
.nomen-cap {
  align-items: baseline;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}
.nomen-cap b { font-size: 0.72rem; letter-spacing: 0.1em; }
.nomen-cap > span { text-align: right; }

/* View list under the caption */
.nomen-views-legend {
  display: block;
  margin-top: -0.2rem;
  font-family: var(--font-mono); font-size: 0.58rem; line-height: 1.4;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
}

/* Circled item mark, a bit larger now that the figures are larger */
.nomen-rep { width: 1.75rem; height: 1.75rem; font-size: 0.95rem; }

/* Leader band: 3rem tall for a 48 unit viewBox, so the vertical scale is
   1 and the dot is a real circle, not a squashed ellipse. The SVG is still
   stretched horizontally to follow the plate width. */
.nomen-leaders { bottom: -3rem; height: 3rem; }
.nomen-dot-num { bottom: -2.06rem; font-size: 0.72rem; }

/* Lit state: the view tag follows the brass accent */
.nomen-fig.is-lit .nomen-view-tag { color: var(--brass); border-color: var(--brass); }

/* Mouse hover on the figure: same signal as .is-lit, without JS */
.nomen-fig .fiche-open:hover .nomen-shot { border-color: var(--brass); }

/* ---------- Nomenclature table ---------- */

.nomen-col-rep { width: 3.2rem; }
.nomen-col-sta { width: 9.5rem; }

/* The whole row is the target, and it has to look like it */
.nomen-row { cursor: pointer; }
.nomen-row td { padding: 0.95rem 0.9rem; vertical-align: top; }

.nomen-cell-rep .fiche-open {
  width: 2.3rem; height: 2.3rem;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}
.nomen-rep-mark { font-size: 1.15rem; }

.nomen-cell-des { line-height: 1.45; }
.nomen-ref { display: block; margin: 0 0 0.15rem; font-size: 0.68rem; }
.nomen-title {
  display: block;
  font-size: 0.86rem;
  color: var(--ink);
  transition: color 0.2s;
}
.nomen-sub {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--font-body);
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 44ch;
}

/* Hierarchy: description in ink, tooling and deliverable in grey.
   Specificity has to beat `.nomen-row td { color: var(--ink) }`. */
.nomen-row td.nomen-cell-out,
.nomen-row td.nomen-cell-liv { color: var(--ink-soft); }

.nomen-cell-sta { white-space: nowrap; }

/* A thin outline keeps the pill readable once the row is tinted on
   hover or focus (the IN PROGRESS pill shares that tint). */
.nomen-status { border: 1px solid transparent; }
.nomen-status.is-done { border-color: color-mix(in srgb, var(--brass) 35%, transparent); }
.nomen-status.is-wip  { border-color: color-mix(in srgb, var(--blue-deep) 30%, transparent); }

.nomen-go {
  display: inline-block;
  margin-left: 0.45rem;
  font-family: var(--font-mono);
  font-size: 1rem; line-height: 1;
  color: color-mix(in srgb, var(--ink-soft) 60%, transparent);
  transition: transform 0.2s, color 0.2s;
}

/* Hover and keyboard focus: the whole row responds */
.nomen-row:hover .nomen-title,
.nomen-row:focus-within .nomen-title { color: var(--brass); }
.nomen-row:hover .nomen-go,
.nomen-row:focus-within .nomen-go { color: var(--brass); transform: translateX(3px); }
.nomen-row:hover .nomen-cell-rep,
.nomen-row:focus-within .nomen-cell-rep { box-shadow: inset 3px 0 0 var(--brass); }
.nomen-row:hover .nomen-rep-mark { color: var(--brass); }
.nomen-row:has(.fiche-open:focus-visible) { background: var(--blue-tint); }

/* ---------- Tablets: stack the views, or the main one gets too small ---------- */
@media (max-width: 900px) {
  .nomen-views { grid-template-columns: 1fr; gap: 0.55rem; }
  .nomen-shot.is-sub { width: 72%; justify-self: end; }
}

/* ---------- 760 px and under (the phone flow, js/rail.js) ----------
   The single column layout stacked four full width renders and three
   label rows per card: close to three screens of scrolling for two
   projects. Here the table becomes one compact parts list: mark, REF and
   status on one line, the description at full width, tooling and
   deliverable side by side. Every cell is still there, only tighter.
   Real text never goes under 11 px (audit M16). This range also holds
   small tablets in portrait and small phones in landscape (641 to
   760 px), where the five column table left the description ~150 px. */
@media (max-width: 760px) {

  .nomen-cap,
  .nomen-views-legend,
  .nomen-view-tag,
  .nomen-ref,
  .nomen-status,
  .nomen-cartouche { font-size: 0.6875rem; }

  /* Table: one parts list under the sheet, a ruled row per item. The
     frame is drawn by the rows and not by the table: app.js fades the rows
     in on scroll, and an empty framed box would show until they arrive. */
  .nomen-table { margin-top: 0.85rem; font-size: 0.75rem; }
  .nomen-table thead { display: none; }
  .nomen-table,
  .nomen-table tbody,
  .nomen-row,
  .nomen-row td { display: block; width: 100%; }

  /* The circled mark and the status sit on the REF line: both are placed
     over the description cell, which spans the whole first row, so the
     title and the description keep the full width of the card. */
  .nomen-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "des des"
      "out liv";
    gap: 0.5rem 0.9rem;
    align-items: start;
    padding: 0.65rem 0.8rem 0.7rem;
    border: 1px solid var(--line);
    background: var(--card);
  }
  .nomen-row:first-child { border-radius: 4px 4px 0 0; }
  .nomen-row:last-child { border-radius: 0 0 4px 4px; }
  .nomen-row + .nomen-row { border-top: 0; }
  .nomen-row td { padding: 0; }

  .nomen-row td.nomen-cell-rep { grid-area: 1 / 1; justify-self: start; width: auto; }
  .nomen-cell-rep .fiche-open { width: 1.6rem; height: 1.6rem; }
  .nomen-row td.nomen-cell-des { grid-area: des; line-height: 1.4; }
  .nomen-row td.nomen-cell-out { grid-area: out; }
  .nomen-row td.nomen-cell-liv { grid-area: liv; }
  .nomen-row td.nomen-cell-sta {
    grid-area: 1 / 2;
    justify-self: end;
    width: auto;
    display: flex; align-items: center; gap: 0.45rem;
    height: 1.6rem;
  }

  .nomen-ref {
    margin: 0;
    padding-left: 2.1rem;               /* clears the circled mark */
    line-height: 1.6rem;
  }
  .nomen-title { margin-top: 0.2rem; font-size: 0.8rem; }
  .nomen-sub {
    margin-top: 0.2rem;
    font-size: 0.8125rem; line-height: 1.42;
    max-width: none;
  }

  /* Tooling and deliverable: two columns, the label above the value */
  .nomen-row td.nomen-cell-out,
  .nomen-row td.nomen-cell-liv {
    display: flex; flex-direction: column; gap: 0.05rem;
    padding-top: 0.4rem;
    border-top: 1px dashed var(--line);
    line-height: 1.38;
    text-wrap: balance;                 /* no lone "V2" on a narrow phone */
  }
  .nomen-cell-out::before,
  .nomen-cell-liv::before,
  .nomen-cell-sta::before {
    content: attr(data-label);
    font-family: var(--font-mono); font-size: 0.6875rem;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
  }
  .nomen-status { padding: 0.1rem 0.5rem; }
  .nomen-go { display: none; }        /* the whole row is already the target */

  /* There is no hover with a finger: keep the brass cue for focus only */
  .nomen-row:hover,
  .nomen-row:focus-within { background: var(--card); }
  .nomen-row:hover .nomen-cell-rep,
  .nomen-row:focus-within .nomen-cell-rep { box-shadow: none; }
  .nomen-row:has(.fiche-open:focus-visible) {
    background: var(--blue-tint);
    box-shadow: inset 3px 0 0 var(--brass);
  }
}

/* 641 to 760 px: each figure column is ~280 px wide, enough for the
   desktop composition (main view and secondary view on one baseline),
   which halves the sheet compared with the stacked tablet views. */
@media (min-width: 641px) and (max-width: 760px) {
  .nomen-views { grid-template-columns: 1.7fr 1fr; }
  .nomen-shot.is-sub { width: auto; }
}

/* ---------- Phones: the sheet on about half a screen ----------
   The sheet keeps the two figure columns of the tablet layout (main view,
   secondary view under it) instead of one full width figure per row:
   every view, tag and caption is still there, at half the height. */
@media (max-width: 640px) {

  /* Section foot: the AI band follows, it brings its own rule and air */
  #workbench { padding-bottom: 2.25rem; }
  /* Placeholder height while the block is skipped (content-visibility in
     styles.css): the real phone height, so the page does not shrink by
     400 px the first time the sheet is rendered. */
  .poste .nomen { contain-intrinsic-size: auto 790px; }

  .nomen-sheet { padding-top: 1.35rem; padding-bottom: 1.35rem; }

  /* Leaders stay hidden (styles.css): the band under the plate is only
     there to clear the corner cartouche. */
  .nomen-plate { margin: 0.1rem 0 3rem; }
  /* The title block is decoration (aria-hidden), but it is still read as
     text on a drawing: it keeps the 11 px floor, in tighter cells. */
  .nomen-cartouche { line-height: 1.25; }
  .nomen-cartouche b { padding: 0.22rem 0.5rem; }
  .nomen-cartouche .cart-grid span { padding: 0.18rem 0.45rem; letter-spacing: 0; }
  .nomen-figs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.85rem; }
  .nomen-fig .fiche-open { gap: 0.4rem; }
  .nomen-views { gap: 0.4rem; }
  .nomen-shot.is-sub { width: 68%; }
  .nomen-shot img { padding: 0.25rem; }

  .nomen-rep {
    top: -0.45rem; left: -0.45rem;
    width: 1.45rem; height: 1.45rem; font-size: 0.8rem;
  }
  .nomen-view-tag { padding: 0.02rem 0.28rem; }

  .nomen-cap { margin-top: 0; letter-spacing: 0.03em; }
  .nomen-cap b { font-size: 0.72rem; letter-spacing: 0.06em; }
  /* One line per view: a wrapped "1a ... ·" left the dot dangling */
  .nomen-views-legend {
    margin-top: -0.2rem;
    line-height: 1.35;
    letter-spacing: 0;
  }
  .nomen-views-legend > span { display: block; }
  .nomen-views-legend > .nomen-legend-sep { display: none; }
}

/* 360 px phones: one more hair of width per column, so the longest view
   name ("2a thermoelectric core") still holds on one line */
@media (max-width: 380px) {
  .nomen-figs { gap: 0.6rem; }
  .nomen-views-legend { letter-spacing: -0.02em; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .nomen-go,
  .nomen-title,
  .nomen-view-tag,
  .nomen-cell-rep .fiche-open { transition: none; }
  .nomen-row:hover .nomen-go,
  .nomen-row:focus-within .nomen-go { transform: none; }
}
