/* ============================================================
 * Scenarios — the redesigned editor (EST-154)
 * Rules here belong to the scenario editor shell and what sits in it.
 * Tokens come from 01_tokens.css; nothing in this file names a colour.
 * ============================================================ */

/* The resting edge of every field in the editor. --border-control is 1.47:1
 * on the light surface, under the 3:1 a component boundary needs (WCAG
 * 1.4.11); --border-cell is the darker step made for exactly this. The shell
 * is wrapped in :where() so these rules tie the base field rules in
 * 03_components.css (same type list, same weight) and, coming later, win the
 * tie - while :hover and :focus there carry a pseudo-class more and still beat
 * them. */
:where(.scenario-editor-shell) input[type="text"],
:where(.scenario-editor-shell) input[type="email"],
:where(.scenario-editor-shell) input[type="password"],
:where(.scenario-editor-shell) input[type="search"],
:where(.scenario-editor-shell) input[type="url"],
:where(.scenario-editor-shell) input[type="number"],
:where(.scenario-editor-shell) textarea,
:where(.scenario-editor-shell) select {
  border-color: var(--border-cell);
}

.scenario-editor-shell input[aria-invalid="true"] {
  border-color: var(--error-border);
}

/* Row headers in the editor's tables read like the cells beside them: left,
 * regular, whichever table class the partial happens to carry. */
.scenario-editor-shell tbody th {
  font-weight: var(--weight-book);
  text-align: left;
}

/* The saved age is the quiet half of the indicator. */
.scenario-save-status__age {
  color: var(--text-tertiary);
}

.scenario-save-status__age:empty {
  display: none;
}

.scenario-save-status [data-scenario-save-retry] {
  margin-inline-start: var(--space-2);
}

/* ── The band ───────────────────────────────────────────────
 * Which scenario this is and the answer it gives. The one loud
 * figure on the tab is the delivery week (weight 700); the
 * readings beside it are a size smaller and never heavier. */

.scenario-band {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
}

.scenario-band__chips {
  display: flex;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-width: 0;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-default);
}

.scenario-chips {
  display: flex;
  flex: 1 1 auto;
  gap: var(--space-2);
  min-width: 0;
  margin: 0;
  /* Room for the 2px focus ring and its 2px offset: with 2px of padding the
   * scroller clipped the ring's top and bottom. */
  padding: var(--space-1);
  /* The snap edge sits on the padding too: without it the first chip snapped
   * to the padding box, the row rested 4px in, and scroll_edges faded the
   * selected chip at load. */
  scroll-padding-inline: var(--space-1);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  list-style: none;
}

.scenario-chips li {
  flex: none;
  scroll-snap-align: start;
}

/* The active chip is marked three ways and only one is colour: the weight,
 * a 2px rule under it, and aria-current for the ear. Every chip carries a 2px
 * bottom border so marking one moves nothing. */
.scenario-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  /* Without this the two rows share the chip's extra height: the star spans
   * both, the name sits in the first, and a chip with only its name read as a
   * star lower than its text. */
  align-content: center;
  column-gap: var(--space-2);
  min-height: var(--target-touch);
  max-width: 15rem;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border-control);
  border-bottom: 2px solid var(--border-control);
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  text-decoration: none;
}

.scenario-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  text-decoration: none;
}

.scenario-chip[aria-current="true"] {
  border-color: var(--primary-edge);
  background: var(--info-bg);
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.scenario-chip__star {
  grid-row: 1 / span 2;
  color: var(--link-color);
}

/* A name is user text, up to 60 unbroken characters: it ellipsizes inside the
 * chip rather than widening it. The full name is the chip's title. */
.scenario-chip__name,
.scenario-chip__figure {
  grid-column: 2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-chip__figure {
  color: var(--text-secondary);
  font-size: var(--text-caption);
  font-weight: var(--weight-book);
}

.scenario-band__tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
}

.scenario-band__tools [aria-disabled="true"] {
  color: var(--text-secondary);
  cursor: not-allowed;
}

.scenario-band__answer {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: var(--space-4) var(--space-6);
}

.scenario-answer {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.scenario-answer--state {
  grid-column: 1 / -1;
  justify-items: start;
}

.scenario-label {
  display: block;
}

.scenario-answer__figure {
  justify-self: start;
  margin: 0 calc(-1 * var(--space-1));
  padding: 0 var(--space-1);
  border-radius: var(--radius-xs);
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  font-weight: var(--weight-bold);
  line-height: 1.1;
  letter-spacing: var(--tracking-tight);
  transition: background-color var(--motion-slow) var(--ease-standard);
}

.scenario-state__title {
  font-size: var(--text-h4);
  font-weight: var(--weight-medium);
}

.scenario-answer__meta {
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
}

.scenario-answer__meta .scenario-link {
  margin-inline-start: var(--space-1);
}

/* A button that reads as a sentence's link: "¿Cómo se calcula?", "Ocultar",
 * "Reintentar". */
.scenario-link {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link-color);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.scenario-delta {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-eyebrow);
}

.scenario-delta b {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

/* The "Antes" line. Always rendered, so the height it needs is already
 * spent and filling it moves nothing; the nbsp keeps it while empty. */
.scenario-band .before {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 1.5rem;
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-eyebrow);
}

.scenario-band .before:empty::before {
  content: "\00a0";
}

.scenario-band .before .scenario-link {
  font-size: var(--text-caption);
}

.scenario-reading {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.scenario-reading__value {
  overflow: hidden;
  font-size: var(--text-h4);
  line-height: var(--leading-snug);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-reading__note {
  color: var(--text-secondary);
  font-size: var(--text-caption);
  letter-spacing: var(--tracking-caption);
}

.scenario-reading__note .icon {
  margin-inline-end: 2px;
  color: var(--warning-500);
  vertical-align: -3px;
}

.scenario-onboard {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-eyebrow);
}

/* A figure that just moved. Colour is not the only mark: with reduced motion
 * there is no fade, so it is underlined. */
.is-changed {
  background: var(--info-bg);
}

@media (prefers-reduced-motion: reduce) {
  .scenario-answer__figure.is-changed,
  .scenario-bar__figure.is-changed {
    background: none;
    text-decoration: underline;
    text-decoration-thickness: 2px;
  }
}

@media (max-width: 1180px) {
  .scenario-band__answer {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scenario-answer {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .scenario-band__chips {
    flex-wrap: wrap;
  }

  .scenario-chips {
    flex-basis: 100%;
  }

  .scenario-band__answer {
    grid-template-columns: minmax(0, 1fr);
  }

  .scenario-reading__value {
    white-space: normal;
  }
}

/* ── The compact bar ────────────────────────────────────────
 * Fixed, so showing it moves nothing below. Hidden with
 * visibility, which also takes it out of the tab order. The shell
 * decides (scenario_bar_controller puts .is-bar-on on it) because
 * the bar is morphed on every save and loses any class of its own. */

.scenario-editor-shell {
  --bar-h: 3.5rem;
}

.scenario-bar {
  position: fixed;
  top: 0;
  right: 0;
  left: var(--bar-left, var(--sidebar-w));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  height: var(--bar-h);
  padding: 0 var(--space-8);
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-surface);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--motion-fast) var(--ease-standard), visibility 0s var(--motion-fast);
}

.is-bar-on .scenario-bar {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--motion-fast) var(--ease-standard);
}

/* The sidebar's reveal button floats over the page's top-left when the
 * sidebar is collapsed, and the bar would run under it. */
:root[data-sidebar="collapsed"] .scenario-bar {
  padding-inline-start: calc(var(--space-8) + 40px + var(--space-3));
}

.scenario-bar__switch {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
}

.scenario-bar__name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 16rem;
  min-height: var(--control-h-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  list-style: none;
  cursor: pointer;
}

.scenario-bar__name::-webkit-details-marker {
  display: none;
}

.scenario-bar__name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-bar__menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  z-index: 1;
  display: grid;
  min-width: 14rem;
  max-width: min(22rem, 80vw);
  margin: 0;
  padding: var(--space-1);
  border: 1px solid var(--border-overlay);
  border-radius: var(--radius-sm);
  background: var(--bg-overlay);
  box-shadow: var(--shadow-popover);
  list-style: none;
}

.scenario-bar__switch:not([open]) .scenario-bar__menu {
  display: none;
}

.scenario-bar__menu a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target-touch);
  padding: 0 var(--space-3);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: var(--text-body-sm);
  text-decoration: none;
}

.scenario-bar__menu a:hover {
  background: var(--bg-subtle);
}

.scenario-bar__menu a[aria-current="true"] {
  font-weight: var(--weight-medium);
}

.scenario-bar__menu span:not(.visually-hidden) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The week gives way before the save state does: on a narrow screen a failed
 * save with its retry has to fit, and the week can lose its tail. */
.scenario-bar__figure {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: var(--radius-xs);
  font-size: var(--text-h4);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.scenario-bar__read,
.scenario-bar__before,
.scenario-bar__delta {
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  white-space: nowrap;
}

/* "Antes" takes the delta's place while there is one to show. */
.scenario-bar__before:not(:empty) + .scenario-bar__delta {
  display: none;
}

.scenario-bar__save {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  margin-inline-start: auto;
  color: var(--text-secondary);
  font-size: var(--text-eyebrow);
  white-space: nowrap;
}

.scenario-bar__save[data-state="failed"] {
  padding-left: var(--space-2);
  border-left: 2px solid var(--error-border);
  color: var(--text-primary);
}

/* Below the width the whole line fits, the readings go first: what the bar is
 * for is the week, and a failed save. */
@media (max-width: 1180px) {
  .scenario-bar {
    gap: var(--space-3);
    padding: 0 var(--space-4);
  }
}

@media (max-width: 900px) {
  .scenario-bar__read,
  .scenario-bar__before,
  .scenario-bar__delta {
    display: none;
  }
}

@media (max-width: 640px) {
  .scenario-bar__name {
    max-width: 8rem;
  }

  .scenario-bar__figure {
    font-size: var(--text-body);
  }

  /* A failed save and its retry take the room: the switcher steps aside, kept
   * for assistive technology by its aria-label but not drawn. */
  .scenario-bar:has([data-state="failed"]) .scenario-bar__switch {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .scenario-bar__save-text {
    max-width: 6rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ── Save status over the band ──────────────────────────────
 * In the card's top padding on a wide screen, where it costs no
 * line. A failure is a different order of news: it takes a line
 * of its own, because covering the buttons it sits over would
 * hide the one thing the person needs to press. Below 640px it is
 * always a line, reserved, so the first save moves nothing. */

.scenario-editor-shell .scenario-save-status {
  top: var(--space-2);
}

.scenario-editor-shell .scenario-save-status[data-state="failed"] {
  position: static;
  margin-bottom: var(--space-2);
}

@media (max-width: 640px) {
  .scenario-editor-shell .scenario-save-status {
    position: static;
    min-height: 1.5rem;
    margin-bottom: var(--space-1);
  }
}

/* ── The estimate card, on the Escenarios and the Supuestos tabs ─
 * The full summary is the Desglose's alone; the other two tabs keep the same
 * one line, so the card does not change shape from tab to tab. One line:
 * title, status, the figure, the base rates, the CSV as an icon and
 * "Volver a generar". The tabs controller keeps
 * data-active-tab on the page section. The card is the same
 * markup as on the other tabs; what changes here is which of its
 * parts show. */

.estimate-compact-summary,
.estimate-compact-rates {
  display: none;
}

.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-4) var(--space-6);
}

.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-card > .section-heading-row h1 {
  font-size: var(--text-h4);
}

/* Only the status stays of the meta row; the mode and the age are on the
 * other tabs. */
.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-meta > :not(.estimate-status) {
  display: none;
}

.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-compact-summary {
  display: block;
  flex: 1 1 8rem;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-compact-rates {
  display: inline-flex;
  gap: var(--space-2);
}

.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-result,
.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-regenerate__hint,
.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-csv__label,
.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-csv-original {
  display: none;
}

/* The download row joins the line instead of being one of its own. */
.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-download {
  display: contents;
}

.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-csv {
  justify-content: center;
  min-width: var(--control-h-sm);
  min-height: var(--control-h-sm);
  padding: 0;
}

.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-stale-notice,
.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .page-tabs,
.estimate-page:is([data-active-tab="scenarios"], [data-active-tab="notes"]) .estimate-preview {
  flex-basis: 100%;
}

/* ── The side panel ─────────────────────────────────────────
 * The shell is the workspace: the editor's frame is its first
 * column and the panel, when it is open, its second. Docked it is
 * a column beside the answer and never over it; under 1024px it is
 * a sheet from the bottom that repeats the answer in its header.
 * No shadow while docked - it is a column, not a layer - and the
 * dialog's own shadow once it is one. */

.scenario-editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0 var(--space-5);
  align-items: start;
}

.scenario-editor-shell.has-panel {
  grid-template-columns: minmax(0, 1fr) 360px;
}

/* The indicator is positioned against the shell, which now includes the
 * panel column: keep it over the frame's corner and out of the panel. */
.scenario-editor-shell.has-panel .scenario-save-status {
  right: calc(360px + var(--space-5) + var(--space-6));
}

.scenario-panel {
  position: sticky;
  top: calc(var(--bar-h) + var(--space-3));
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--bar-h) - var(--space-6));
  overflow: hidden;
  border: 1px solid var(--border-overlay);
  border-radius: var(--radius-sm);
  background: var(--bg-overlay);
  animation: fade-in var(--motion-fast) var(--ease-standard);
}

.scenario-panel[hidden] {
  display: none;
}

/* The frame and the body are flex columns so the header stays put and only
 * the body scrolls, at any height the panel is given. */
.scenario-panel > turbo-frame,
.scenario-panel #scenario-panel-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

.scenario-panel__grip {
  display: none;
}

.scenario-panel__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px var(--space-2);
  padding: var(--space-4) var(--space-3) var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-overlay);
}

.scenario-panel__head h3 {
  font-size: var(--text-h4);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-panel__head h3:focus {
  outline: none;
}

.scenario-panel__head h3:focus-visible {
  outline: 2px solid var(--focus-ring, var(--primary-700));
  outline-offset: 2px;
}

.scenario-panel__context,
.scenario-panel__live {
  overflow: hidden;
  color: var(--text-tertiary);
  font-size: var(--text-eyebrow);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-panel__live {
  display: none;
  color: var(--text-primary);
  font-size: var(--text-body-sm);
}

.scenario-panel__close {
  grid-row: 1 / span 3;
  grid-column: 2;
  align-self: start;
  min-width: var(--control-h-sm);
  min-height: var(--control-h-sm);
  padding: 0;
}

.scenario-panel__body {
  display: grid;
  gap: var(--space-6);
  align-content: start;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5) var(--space-6);
}

.scenario-panel__lede,
.scenario-panel__hint {
  margin: 0;
  color: var(--text-tertiary);
  font-size: var(--text-eyebrow);
}

.scenario-panel__hint {
  font-size: var(--text-caption);
}

.scenario-panel__group {
  display: grid;
  gap: var(--space-3);
}

.scenario-panel__group-title {
  font-size: var(--text-body);
}

.scenario-panel__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  align-items: start;
}

.scenario-panel__buffer-tasks {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
}

/* A unit written after the number, inside the field. Drawn by the wrapper
 * so the input stays a plain text field to a screen reader. */
.scenario-panel__unit {
  position: relative;
  display: block;
}

.scenario-panel__unit::after {
  content: attr(data-unit);
  position: absolute;
  top: 50%;
  right: var(--space-3);
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: var(--text-caption);
  pointer-events: none;
}

.scenario-panel__unit > input {
  width: 100%;
  padding-right: 3.25rem;
}

.scenario-panel__rate {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr) var(--control-h-sm);
  gap: var(--space-1) var(--space-2);
  align-items: center;
}

.scenario-panel__rate input::placeholder {
  font-style: italic;
}

.scenario-panel__own {
  grid-column: 2;
}

.scenario-panel__reset {
  min-width: var(--control-h-sm);
  min-height: var(--control-h-sm);
  padding: 0;
}

.scenario-panel__advanced > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-h-sm);
  cursor: pointer;
  font-size: var(--text-body-sm);
  list-style: none;
}

.scenario-panel__advanced > summary::-webkit-details-marker {
  display: none;
}

.scenario-panel__advanced[open] > summary .scenario-epic__chevron {
  transform: rotate(90deg);
}

.scenario-panel__advanced-body {
  display: grid;
  gap: var(--space-3);
  padding-top: var(--space-3);
}

/* The band decides its layout by the width of the window, and with the panel
 * docked the editor has 360px less than the window says: above 1180 the
 * figure would share a row with three readings in a column that cannot hold
 * them. Docked, it takes the stacked layout the narrower windows get anyway. */
@media (min-width: 1181px) {
  .scenario-editor-shell.has-panel .scenario-band__answer {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scenario-editor-shell.has-panel .scenario-answer {
    grid-column: 1 / -1;
  }
}

/* Laptop: the panel gets less so the answer keeps more. */
@media (max-width: 1280px) and (min-width: 1024px) {
  .scenario-editor-shell.has-panel {
    grid-template-columns: minmax(0, 1fr) 340px;
  }

  .scenario-editor-shell.has-panel .scenario-save-status {
    right: calc(340px + var(--space-5) + var(--space-6));
  }

  /* Three readings share what is left of the editor, and a price band such as
   * "US$ 13.536 – 18.036" is wider than a third of it. */
  .scenario-editor-shell.has-panel .scenario-reading__value {
    white-space: normal;
  }
}

/* Tablet and below: a sheet from the bottom, 60% of the screen at most. Its
 * header says the answer, because the sheet is now over it. The page gets
 * the room underneath so the last thing on it can still be scrolled to. */
@media (max-width: 1023px) {
  .scenario-editor-shell.has-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .scenario-editor-shell.has-panel .scenario-save-status {
    right: var(--space-6);
  }

  .scenario-panel {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    max-height: 60vh;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    box-shadow: var(--shadow-dialog);
  }

  .scenario-panel__grip {
    display: block;
    width: 40px;
    height: 4px;
    margin: var(--space-2) auto 0;
    border-radius: 2px;
    background: var(--border-control);
  }

  .scenario-panel__live {
    display: block;
  }

  .scenario-panel__head {
    padding-top: var(--space-2);
  }

  html.sheet-open {
    scroll-padding-bottom: 62vh;
  }

  html.sheet-open main.app-shell {
    padding-bottom: 62vh;
  }
}

@media (max-width: 520px) {
  .scenario-panel__grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* A finger needs the platform minimum: the close button, the reset button and
 * the column that holds it. */
@media (pointer: coarse) {
  .scenario-panel__close,
  .scenario-panel__reset {
    min-width: var(--target-touch);
    min-height: var(--target-touch);
  }

  .scenario-panel__rate {
    grid-template-columns: 4.5rem minmax(0, 1fr) var(--target-touch);
  }
}

/* ── The team ───────────────────────────────────────────────
 * One row a person. The two numbers that size the work are edited
 * in the row; meetings, QA and removal are in the side panel. */

.scenario-team {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.scenario-team__foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.scenario-team__empty {
  margin: 0;
}

.scenario-team__empty[hidden],
.scenario-team__wrapper[hidden] {
  display: none;
}

/* The containing block of the visually hidden text in the cells: without it
 * that text is positioned against the page and the table's scroll cannot clip
 * it, which gave the whole page a sideways scroll at 390px. */
.scenario-team__wrapper {
  position: relative;
}

.scenario-table.scenario-team__table {
  min-width: 36rem;
}

.scenario-team__table tbody tr.is-open > * {
  background: var(--bg-subtle);
}

.scenario-team__who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}

.scenario-team__name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.scenario-team__adjust {
  flex: none;
}

.scenario-team__table select {
  min-width: 7.5rem;
}

.scenario-team__table input[type="number"] {
  width: 5rem;
}

.scenario-team__lane-col {
  white-space: nowrap;
}

.scenario-team__use-col {
  text-align: right;
  white-space: nowrap;
}

.scenario-team__use {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.scenario-team__use svg,
.scenario-team__badge svg {
  color: var(--warning-border);
}

.scenario-team__badge {
  gap: var(--space-1);
  border-color: var(--warning-border);
  background: var(--warning-bg);
}

/* Docked, the panel takes 340-360px from the table; the pace column is the
 * one that can be read in the panel instead, so "Ajustes" stays in view
 * without scrolling the table sideways. */
@media (min-width: 1024px) {
  .scenario-editor-shell.has-panel .scenario-team__lane-col {
    display: none;
  }

  .scenario-editor-shell.has-panel .scenario-table.scenario-team__table {
    min-width: 0;
  }

  .scenario-editor-shell.has-panel .scenario-team__adjust {
    padding-inline: var(--space-2);
  }

  /* What is left of the column once the panel is beside it: tighter cells and
   * narrower controls, so the table fits without a sideways scroll. */
  .scenario-editor-shell.has-panel .scenario-team__table th,
  .scenario-editor-shell.has-panel .scenario-team__table td {
    padding-inline: var(--space-2);
  }

  .scenario-editor-shell.has-panel .scenario-team__table thead th {
    white-space: normal;
  }

  .scenario-editor-shell.has-panel .scenario-team__table select {
    min-width: 6rem;
  }

  .scenario-editor-shell.has-panel .scenario-team__table input[type="number"] {
    width: 4rem;
  }
}

/* ── A member's panel ───────────────────────────────────────── */

.scenario-panel__wide {
  grid-column: 1 / -1;
}

.scenario-panel__note {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
}

.scenario-panel__removal {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
}

.scenario-panel__confirm {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-body-sm);
}

/* The confirm step is laid out with grid, which would override the [hidden]
 * attribute's own display:none. */
.scenario-panel__removal [hidden] {
  display: none;
}

.scenario-panel__confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* A finger needs the platform minimum on the fields too, and the row's
 * and the panel's are the ones this editor adds. */
@media (pointer: coarse) {
  .scenario-team__table input,
  .scenario-team__table select,
  .scenario-panel input,
  .scenario-panel select {
    min-height: var(--target-touch);
  }
}

.scenario-team__use--low {
  color: var(--text-primary);
}

/* ── Native dialogs ─────────────────────────────────────────
 * "Tarifas base", "¿Cómo se calcula?" and "Agregar escenario". A <dialog>
 * opened with showModal() sits in the top layer, so none of this positions
 * anything: the UA centres it. 512 px like the system's alert dialog, 640 for
 * the one that carries a table of steps. The padding is the box's own, which
 * is what lets dialog_controller tell it from the backdrop. */
.scenario-dialog {
  width: min(calc(100vw - 2 * var(--space-4)), var(--alert-dialog-w));
  max-height: calc(100dvh - 4 * var(--space-4));
  padding: var(--space-6);
  overflow: auto;
  border: 1px solid var(--border-overlay);
  border-radius: var(--radius-sm);
  background: var(--bg-overlay);
  color: var(--text-primary);
  box-shadow: var(--shadow-dialog);
}

.scenario-dialog[open] {
  display: grid;
  gap: var(--space-5);
  animation: fade-in var(--motion-base) var(--ease-out);
}

.scenario-dialog--wide {
  width: min(calc(100vw - 2 * var(--space-4)), 40rem);
}

.scenario-dialog::backdrop {
  background: var(--scrim);
}

.scenario-dialog__title {
  margin: 0;
  font-size: var(--text-h3);
}

.scenario-dialog__lede,
.scenario-dialog__note {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
}

.scenario-dialog__form {
  display: grid;
  gap: var(--space-5);
}

.scenario-dialog__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  align-items: start;
  gap: var(--space-4);
}

.scenario-dialog__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* The calculation: a number in the margin, what the step is, the figure it
 * lands on. The figures line up on the right and keep their digits tabular
 * because they stack in a column. */
.scenario-steps {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.scenario-steps__item {
  display: grid;
  grid-template-columns: var(--space-6) minmax(0, 1fr) auto;
  gap: var(--space-1) var(--space-3);
  align-items: baseline;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-overlay);
  font-size: var(--text-body-sm);
  counter-increment: step;
}

.scenario-steps__item::before {
  content: counter(step);
  color: var(--text-secondary);
  font-size: var(--text-caption);
}

.scenario-steps__item--total {
  border-bottom: 0;
}

.scenario-steps__label {
  font-weight: var(--weight-medium);
}

.scenario-steps__value {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.scenario-steps__people {
  display: grid;
  grid-column: 2 / -1;
  gap: var(--space-1);
  color: var(--text-secondary);
  font-size: var(--text-caption);
}

/* ── The heading and its menu ───────────────────────────────
 * The name, edited in place, with what is done to the scenario
 * beside it: the assumptions, making it the primary, and a
 * disclosure with the downloads, a copy and the deletion.
 * Composes 01_tokens.css; the only shadow is the popover's. */

.scenario-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.scenario-heading__title {
  display: flex;
  align-items: center;
  flex: 1 1 20rem;
  min-width: 0;
}

.scenario-heading__display {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.scenario-heading__display[hidden],
.scenario-heading__rename[hidden] {
  display: none;
}

/* A long name gives way with an ellipsis rather than wrapping the row. */
.scenario-heading__display h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-heading__rename {
  display: grid;
  gap: var(--space-1);
  width: min(28rem, 100%);
}

.scenario-heading__rename small {
  font-size: var(--text-caption);
}

.scenario-heading__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.scenario-heading__actions form {
  margin: 0;
}

.scenario-heading__note {
  margin: 0;
  font-size: var(--text-body-sm);
}

/* Square, and the platform minimum for a finger. */
.scenario-heading__icon {
  flex: none;
  justify-content: center;
  width: var(--control-h-sm);
  min-height: var(--control-h-sm);
  padding: 0;
}

@media (pointer: coarse) {
  .scenario-heading__icon {
    width: var(--target-touch);
    min-height: var(--target-touch);
  }
}

.scenario-menu {
  position: relative;
}

.scenario-menu__list {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  z-index: 1;
  display: grid;
  width: max-content;
  min-width: 14rem;
  max-width: min(22rem, 100vw - 2rem);
  margin: 0;
  padding: var(--space-1);
  border: 1px solid var(--border-overlay);
  border-radius: var(--radius-sm);
  background: var(--bg-overlay);
  box-shadow: var(--shadow-popover);
  list-style: none;
}

.scenario-menu__list[hidden] {
  display: none;
}

.scenario-menu__list li {
  margin: 0;
}

.scenario-menu__list form {
  display: contents;
}

/* Plain entries, links and buttons alike: the list is a disclosure, not an
 * ARIA menu, so they read as the actions they are. */
.scenario-menu__list a,
.scenario-menu__list li > button,
.scenario-menu__list li > form > button,
.scenario-menu__list [data-scenario-removal="trigger"] {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  width: 100%;
  min-height: var(--control-h-sm);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  color: var(--text-primary);
  font-size: var(--text-body-sm);
  text-align: left;
  text-decoration: none;
}

.scenario-menu__list a:hover,
.scenario-menu__list li > button:hover,
.scenario-menu__list li > form > button:hover,
.scenario-menu__list [data-scenario-removal="trigger"]:hover {
  background: var(--bg-subtle);
}

.scenario-menu__list [aria-disabled="true"],
.scenario-menu__list [aria-disabled="true"]:hover {
  background: none;
  color: var(--text-secondary);
  cursor: not-allowed;
}

.scenario-menu__danger {
  margin-top: var(--space-1);
  padding-top: var(--space-1);
  border-top: 1px solid var(--border-overlay);
}

.scenario-menu__why {
  margin: 0;
  padding: 0 var(--space-3) var(--space-2) calc(var(--space-3) + 1rem + var(--space-2));
  font-size: var(--text-caption);
  color: var(--text-secondary);
}

.scenario-menu__confirm {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

.scenario-menu__confirm[hidden],
.scenario-menu__list [hidden] {
  display: none;
}

.scenario-menu__question {
  font-size: var(--text-body-sm);
  overflow-wrap: anywhere;
}

.scenario-menu__answers {
  display: flex;
  gap: var(--space-2);
}

/* On a phone the list is anchored to the screen and not to its button, which
 * can be anywhere in a wrapped row. */
@media (max-width: 640px) {
  .scenario-menu__list {
    position: fixed;
    /* Over the assumptions sheet (50) it can be opened from. */
    z-index: 60;
    right: var(--space-4);
    bottom: var(--space-4);
    left: var(--space-4);
    top: auto;
    width: auto;
    max-width: none;
  }

  .scenario-menu__list a,
  .scenario-menu__list li > button,
  .scenario-menu__list li > form > button,
  .scenario-menu__list [data-scenario-removal="trigger"] {
    min-height: var(--target-touch);
  }
}

/* ── The task table ─────────────────────────────────────────
 * One table, one <tbody> per epic, fixed columns so they stay in
 * step from one epic to the next. Read mode lives in the editor's
 * card; edit mode is a card of its own beneath it (a frame the
 * shell keeps outside the editor's, see _scenario_editor) and
 * takes the read section's place while it is open. */

.scenario-editor-shell.is-editing-tasks [data-scenario-tasks-read] {
  display: none;
}

/* The shell is a grid: the edit card is its second row, and the panel,
 * which docks in the second column, spans both rows so it stays sticky
 * beside the edit card as well as beside the editor. */
.scenario-tasks--edit[hidden] {
  display: none;
}

.scenario-tasks--edit {
  grid-column: 1;
}

.scenario-editor-shell > .scenario-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.scenario-tasks {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  min-width: 0;
}

.scenario-tasks__head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-3);
}

.scenario-tasks__title {
  margin: 0;
  font-size: var(--text-body);
}

.scenario-tasks__edit {
  margin-left: auto;
}

.scenario-tasks__edit .icon {
  margin-right: var(--space-1);
}

.scenario-tasks__advanced {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  font-size: var(--text-body-sm);
}

/* Sideways only. The wrapper the editor gives its tables scrolls both ways
 * and sticks the header to it; a table that is a page of rows scrolls with
 * the page instead. */
.scenario-tasks .table-wrapper {
  max-height: none;
}

.scenario-tasks__table {
  width: 100%;
  min-width: 36rem;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
}

.scenario-tasks__table caption {
  text-align: left;
}

.scenario-tasks__col--task { width: 50%; }
.scenario-tasks__col--owner { width: 20%; }
.scenario-tasks__col--hours { width: 12%; }
.scenario-tasks__col--ends_on { width: 18%; }

/* Each set adds up to 100%: a fixed-layout table leaves what the columns do
 * not claim empty at the right, and the epic rows would run past it. Without
 * the advanced columns first, then with them. */
.scenario-tasks__table--edit .scenario-tasks__col--task { width: 35%; }
.scenario-tasks__table--edit .scenario-tasks__col--scope { width: 15%; }
.scenario-tasks__table--edit .scenario-tasks__col--buffer { width: 11%; }
.scenario-tasks__table--edit .scenario-tasks__col--effort { width: 13%; }
.scenario-tasks__table--edit .scenario-tasks__col--risk { width: 13%; }
.scenario-tasks__table--edit .scenario-tasks__col--hours { width: 13%; }

.scenario-tasks[data-advanced] .scenario-tasks__col--task { width: 20%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--scope { width: 10%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--buffer { width: 8%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--effort { width: 9%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--risk { width: 9%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--wave { width: 8%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--dep { width: 16%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--force { width: 12%; }
.scenario-tasks[data-advanced] .scenario-tasks__col--hours { width: 8%; }

/* Nine columns on a narrow screen: the percentages above leave a select
 * 28px of room at 36rem, so the table keeps a width where each one can be
 * read and the wrapper scrolls it. */
.scenario-tasks[data-advanced] .scenario-tasks__table--edit {
  min-width: 60rem;
}

/* Wave, dependency and forced owner are in the table either way; the checkbox over it
 * only shows them. The flag is on the frame (data-advanced), which a save
 * never replaces. */
.scenario-tasks:not([data-advanced]) .scenario-tasks__col--wave,
.scenario-tasks:not([data-advanced]) .scenario-tasks__col--dep,
.scenario-tasks:not([data-advanced]) .scenario-tasks__col--force,
.scenario-tasks:not([data-advanced]) .scenario-tasks__head--wave,
.scenario-tasks:not([data-advanced]) .scenario-tasks__head--dep,
.scenario-tasks:not([data-advanced]) .scenario-tasks__head--force,
.scenario-tasks:not([data-advanced]) .scenario-tasks__adv {
  display: none;
}

.scenario-tasks__table thead th {
  padding: 0 var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  font-weight: var(--weight-book);
  text-align: left;
  white-space: nowrap;
}

.scenario-tasks__table thead th.scenario-tasks__head--hours {
  text-align: right;
}

.scenario-tasks__table tbody th[scope="row"],
.scenario-tasks__table tbody td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-default);
  font-weight: var(--weight-book);
  text-align: left;
  vertical-align: middle;
}

.scenario-tasks__table tbody tr[tabindex]:focus-visible,
.scenario-tasks__table tbody tr[tabindex]:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

.scenario-tasks__table tbody tr[data-tasks-row]:hover > * {
  background: var(--bg-subtle);
}

.scenario-tasks__epic {
  padding: 0;
  border-bottom: 1px solid var(--border-default);
  text-align: left;
}

/* A whole-row button: the target is the epic's full width and 44px tall. */
.scenario-tasks__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-1);
  border: 0;
  background: none;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-body);
  text-align: left;
  cursor: pointer;
}

.scenario-tasks__chevron {
  flex: none;
  color: var(--text-tertiary);
  transition: transform var(--motion-base) var(--ease-standard);
}

.scenario-tasks__toggle[aria-expanded="true"] .scenario-tasks__chevron {
  transform: rotate(90deg);
}

/* The roadmap's own epic colour (.roadmap-bar--epic-N sets the fill and the
 * edge), so the swatch is the key to the bar. */
.scenario-tasks__swatch {
  flex: none;
  width: 0.625rem;
  height: 0.625rem;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
}

/* Fase 2 and the dropped tasks have no bar on the roadmap, so their swatch
 * keys no colour: an outline that holds the epics' alignment and says "not
 * on the chart". */
.scenario-tasks__swatch--phase {
  border-color: var(--border-strong);
  background: transparent;
}

.scenario-tasks__epic-meta {
  margin-left: auto;
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  white-space: nowrap;
}

.scenario-tasks__task-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* The line above the edit table that says edits stay in this estimate. */
.scenario-tasks__edit-note {
  margin: var(--space-3) 0 var(--space-2);
}

/* Why a dependency does nothing, under the select that holds it: a count at
 * the top of the page would not name the task. */
.scenario-tasks__dep-warning {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  margin-top: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-xs);
  background: var(--warning-bg);
  color: var(--text-primary);
  font-size: var(--text-caption);
}

.scenario-tasks__table td.scenario-tasks__figure {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* Struck through and badged rather than dimmed. Lowering the opacity of a
 * whole row is the usual move and it takes the notes under 4.5:1, so the cue
 * is the line and the badge. */
.scenario-tasks__row--out .scenario-tasks__task-text {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.scenario-tasks__check {
  text-align: left;
}

/* A 44px target around a 16px box: the cell is the hit area. */
.scenario-tasks__check input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0.625rem;
  accent-color: var(--text-secondary);
}

.scenario-tasks__table select,
.scenario-tasks__wave {
  width: 100%;
  min-height: 2.75rem;
}

.scenario-tasks__wave {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* The two disclosures that are not buttons: the bar's scenario switcher and
 * the panel's advanced block. */
@media (pointer: coarse) {
  .scenario-bar__name,
  .scenario-panel__advanced > summary {
    min-height: var(--target-touch);
  }
}
