/* ==========================================================================
   OPTION WIZARDS (brief §11, contract §9.4)
   --------------------------------------------------------------------------
   Everything this feature looks like, in one file, linked from `{% block head %}`
   so the page never paints unstyled the way the tools hub does.

   **Not one hex colour.**  Every value here is one of the tokens declared at the
   top of `app.css` — `--bg --panel --ink --muted --line --buy --buy-bg --sell
   --sell-bg --accent --warn --warn-bg --mono` — or a `color-mix()` of them.
   That is not tidiness: `app.css` redefines all of them under
   `prefers-color-scheme: dark`, so a literal `#fff` or `#e7f4ed` written here
   would be a colour that only works in one theme and would go on looking fine
   to whoever wrote it.  The chart reads the same custom properties out of
   `getComputedStyle` at draw time for exactly the same reason, so the canvas
   and the page around it cannot drift apart.

   **The one rule worth stating twice: filled controls use `color: var(--panel)`,
   never `#fff`.**  `--buy` is a dark green in light mode and a *light* green in
   dark mode; white text is legible on the first and unreadable on the second.
   `--panel` inverts with the theme in step with them, so panel-on-buy and
   panel-on-accent are readable in both.  (The site's older `.pills` and
   `.rangesel` rules do use `#fff` on `--accent` and are visibly weak in dark
   mode; this file does not repeat that.)

   **Order below follows the page**: shell and focus, region A globals, region B
   toolbar, region C table, region D chart, region E summary, the saved-list
   page, and last the sub-900px card layout, which is the only place any of the
   above is undone.
   ========================================================================== */

/* ---------------------------------------------------------------- the shell */

/* One wrapper around the whole tool, so the focus rules below can be scoped to
   it.  The site has no focus-visible styling at all — every control on every
   other page falls back to whatever the browser draws, which in Chrome on a
   panel-coloured button is very nearly nothing.  This page is dense with small
   controls and is meant to be driven from the keyboard (Tab across the cells,
   arrows to step a value), so it opts itself in rather than changing the rest
   of the site under pages that were never checked against it. */
.ow { --ow-ring: var(--accent); }
#options-form { display: block; }
.ow-chartcard svg{display:block;width:100%;height:auto;margin:1rem 0 0;border:1px solid var(--line);border-radius:8px;background:var(--panel)}
.ow-chartcard .keystats{margin-top:.8rem}
#options-form .ow-auth { flex-basis: 100%; }
#option-legs:not(tbody) { display: grid; gap: .55rem; }
#option-legs fieldset.option-leg {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .55rem .8rem;
  margin: 0; padding: .7rem .8rem; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel);
}
#option-legs fieldset.option-leg legend {
  grid-column: 1 / -1; padding: 0 .25rem; color: var(--muted);
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
#option-legs fieldset.option-leg label {
  display: flex; flex-direction: column; gap: .2rem; color: var(--muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
}
#option-legs fieldset.option-leg input,
#option-legs fieldset.option-leg select {
  width: 100%; min-width: 0; padding: .32rem .5rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); color: var(--ink); font: .88rem var(--mono);
}
#option-legs fieldset.option-leg button { align-self: end; justify-self: start; background: var(--panel); color: var(--ink); }

/* Worker parity uses the same editable table contract as the retained wizard;
   the older fieldset fallback above must not turn the tbody into a CSS grid. */
table.ow-legs #option-legs { display: table-row-group; }
@media (min-width: 901px) {
  table.ow-legs #option-legs > tr.option-leg { display: table-row; }
}
.ow :focus-visible,
.ow-tooltip :focus-visible {
  outline: 2px solid var(--ow-ring);
  outline-offset: 2px;
  border-radius: 6px;
}
.ow button:disabled,
.ow select:disabled,
.ow input:disabled { opacity: .48; cursor: not-allowed; }

/* Every number the reader might compare vertically — the table, the net line,
   the summary, the tooltip — is tabular.  Proportional digits in a column of
   premiums make a butterfly's three legs look ragged even when they are equal. */
.ow-legs,
.ow-net,
.ow-legcount,
.ow-metrics,
.ow-tooltip,
.ow-num,
.ow-resolved { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------ region A: the global bar --
   Same bar as `.tickerbar` and `.filters` elsewhere on the site — a panel
   strip, micro-caps labels stacked over their control — because that is what
   "the inputs that govern this page" already looks like here, and a reader who
   has used the Financials picker should not have to learn a second one. */
.ow-globals,
.ow-toolbar {
  display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: end;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem .9rem; margin: .8rem 0;
}
.ow-globals label,
.ow-toolbar label {
  display: flex; flex-direction: column; gap: .2rem;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted);
}
.ow-globals input,
.ow-toolbar select {
  padding: .32rem .5rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink); font-size: .88rem;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}
.ow-globals input[type="number"] { width: 6.5rem; text-align: right; }
.ow-globals input[type="text"] { width: 9rem; text-transform: uppercase; }

/* ---------------------------------------------------- region B: the toolbar */
.ow-btns { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.ow-toolbar select { min-width: 12rem; max-width: 24rem; }
.ow-toolbar .sp { margin-left: auto; }

/* Destructive, and coloured as such — but still a ghost button, because a
   solid red Delete beside a solid blue Save is a dare rather than a control. */
.ow-danger {
  color: var(--sell);
  border-color: color-mix(in srgb, var(--sell) 40%, var(--line));
}
.ow-danger:hover:not(:disabled) { background: var(--sell-bg); border-color: var(--sell); }

/* The loaded strategy's name.  `:empty` and not a `hidden` attribute, because
   the controller writes this element's text and would have to remember to
   toggle an attribute as well; an empty chip that disappears on its own cannot
   be left behind as a stray blue box saying nothing. */
.ow-loaded {
  display: inline-block; padding: .16rem .5rem; border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--ink); font-family: var(--mono); font-size: .82rem;
}
.ow-loaded:empty { display: none; }
.ow-account { margin: .8rem 0; border: 1px dashed var(--line); border-radius: 8px; }
.ow-account summary { cursor: pointer; padding: .45rem .7rem; color: var(--muted); font-size: .8rem; }
.ow-account-fields { display: flex; flex-wrap: wrap; gap: .6rem 1rem; padding: .2rem .8rem .8rem; }
.ow-account-fields label { display: flex; flex-direction: column; gap: .2rem; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
.ow-account-fields input { padding: .32rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); font: .88rem var(--mono); }
.ow-toolbar .ow-account { position: relative; z-index: 2; flex: 0 0 auto; margin: 0; border: 0; }
.ow-toolbar .ow-account summary { display: block; padding: .38rem .55rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font-size: .72rem; white-space: nowrap; }
.ow-toolbar .ow-account summary::-webkit-details-marker { display: none; }
.ow-toolbar .ow-account summary.ow-loaded { display: inline-block; padding: .16rem .5rem; border: 0; border-radius: 6px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--ink); font-family: var(--mono); font-size: .82rem; }
.ow-toolbar .ow-account[open] { z-index: 10; }
.ow-toolbar .ow-account-fields { position: absolute; top: calc(100% + .3rem); right: 0; display: grid; width: min(22rem, calc(100vw - 2rem)); gap: .65rem; padding: .8rem; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); box-shadow: 0 8px 24px color-mix(in srgb, var(--ink) 16%, transparent); }
.ow-toolbar .ow-account-fields label { display: grid; gap: .25rem; margin: 0; font-size: .72rem; }
.ow-toolbar .ow-account-fields input { box-sizing: border-box; width: 100%; }

/* -------------------------------------------- region C: the positions table */
.ow-positions { margin: 1rem 0 0; }
table.ow-legs { font-size: .86rem; }
table.ow-legs th,
table.ow-legs td { padding: .3rem .5rem; vertical-align: middle; }
/* `app.css` right-aligns `td.num` but not `th.num`, because until now no table
   here had an editable numeric column whose header had to line up over it. */
table.ow-legs th.num { text-align: right; }

table.ow-legs td input,
table.ow-legs td select {
  width: 100%; min-width: 3.6rem; padding: .24rem .4rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink);
  font-size: .85rem; font-family: var(--mono); font-variant-numeric: tabular-nums;
}
table.ow-legs td.num input { text-align: right; }
table.ow-legs td input:disabled { background: transparent; }

/* Column widths carried on the cells rather than a <colgroup>: the same cells
   are re-laid-out as a card grid below 900px, where a colgroup would have no
   meaning at all, and one selector per field keeps the two layouts describing
   the same nine things. */
table.ow-legs td[data-field="side"]     { width: 5.8rem; }
table.ow-legs td[data-field="quantity"] { width: 5.2rem; }
table.ow-legs td[data-field="type"]     { width: 6.6rem; }
table.ow-legs td[data-field="strike"]   { width: 6.8rem; }
table.ow-legs td[data-field="dte"]      { width: 5.2rem; }
table.ow-legs td[data-field="vol"],
table.ow-legs td[data-field="volatility"] { width: 6.4rem; }
table.ow-legs td[data-field="premium"]  { width: 6.8rem; }
table.ow-legs td[data-field="cash"]     { width: 7.4rem; }
table.ow-legs td[data-field="actions"]  { width: 9.2rem; }

/* ---- the buy/sell toggle -------------------------------------------------
   The most-clicked control on the page (brief §11) and the one with the largest
   consequence per click: it flips the sign of a leg, which flips the sign of
   the P/L curve.  So it is a full-width, 44×28 minimum target — a thumb size,
   not a mouse size — and its state is carried by four signals at once, because
   colour alone fails for the eight per cent of readers who cannot separate this
   particular green from this particular red:

     the word            Buy / Sell, spelled out, never an arrow;
     the ground          `--buy-bg` / `--sell-bg`;
     the text            `--buy` / `--sell`, bold, upper case;
     a 3px inset bar     solid `--buy` / `--sell` down the leading edge.

   Styled off `aria-pressed` and off nothing else.  A `.buy`/`.sell` class would
   be the obvious alternative and is a trap: the controller is specified to
   toggle `aria-pressed`, so a class it does not also maintain would go stale on
   the first flip and — at equal specificity — would win over the attribute rule
   and paint a Sell leg green. */
.ow-side {
  display: block; width: 100%;
  min-width: 44px; min-height: 28px; padding: .24rem .5rem;
  border: 1px solid transparent; border-radius: 7px;
  font-family: var(--mono); font-size: .78rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; text-align: center;
  cursor: pointer;
}
.ow-side[aria-pressed="true"] {
  background: var(--buy-bg); color: var(--buy);
  border-color: color-mix(in srgb, var(--buy) 45%, var(--line));
  box-shadow: inset 3px 0 0 0 var(--buy);
}
.ow-side[aria-pressed="false"] {
  background: var(--sell-bg); color: var(--sell);
  border-color: color-mix(in srgb, var(--sell) 45%, var(--line));
  box-shadow: inset 3px 0 0 0 var(--sell);
}
.ow-side[aria-pressed="true"]:hover  { border-color: var(--buy); }
.ow-side[aria-pressed="false"]:hover { border-color: var(--sell); }
.ow-side:active { transform: translateY(1px); }

/* ---- row actions --------------------------------------------------------- */
.ow-acts { display: flex; gap: .25rem; flex-wrap: wrap; }
.ow-acts button {
  padding: .16rem .42rem; font-size: .74rem;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
}
.ow-acts button:hover { color: var(--ink); border-color: var(--accent); }
.ow-acts button[data-act="del"]:hover { color: var(--sell); border-color: var(--sell); }

/* ---- derived, failed and invalid cells -----------------------------------
   Premium and volatility are two views of one number (brief §4.3).  Exactly one
   of them is typed and the other is solved for, and the reader has to be able
   to tell which at a glance or the binding is indistinguishable from the page
   randomly rewriting their input.  Grey italic is the site's existing vocabulary
   for "we worked this out" — the same reading `.vsrc` and `.muted` carry — and
   it is deliberately dropped on focus: the moment the box is focused it is
   about to become the driving field, so it stops looking derived before the
   first keystroke rather than after it. */
.ow-derived { color: var(--muted); }
table.ow-legs td.ow-derived input {
  color: var(--muted); font-style: italic;
  background: transparent;
  border-color: color-mix(in srgb, var(--line) 65%, transparent);
}
table.ow-legs td.ow-derived input:focus {
  color: var(--ink); font-style: normal; background: var(--bg);
  border-color: var(--line);
}

/* A volatility that would not solve.  The cell is empty — not zero, which would
   be a claim about the option — and says why in its `title`.  The triangle is
   absolutely positioned so the input keeps its full width and the row keeps its
   height; the padding on the input is what makes room for it. */
table.ow-legs td.ow-ivfail { position: relative; background: var(--warn-bg); }
table.ow-legs td.ow-ivfail::before {
  content: "\26A0"; position: absolute; left: .3rem; top: 50%;
  transform: translateY(-50%);
  color: var(--warn); font-size: .8rem; line-height: 1; pointer-events: none;
}
table.ow-legs td.ow-ivfail input {
  padding-left: 1.25rem; color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 55%, var(--line));
}

/* An invalid input.  Marked with an inset ring rather than a thicker border, so
   nothing moves: a border that grows from 1px to 2px on every keystroke that
   leaves the field momentarily invalid makes the whole row jitter while you
   type, which is the fastest way to make careful entry feel broken. */
.ow input.ow-bad,
.ow select.ow-bad,
.ow .ow-bad input,
.ow .ow-bad select,
table.ow-legs td input.ow-bad,
table.ow-legs td.ow-bad input {
  border-color: var(--sell);
  box-shadow: inset 0 0 0 1px var(--sell);
  background: var(--sell-bg);
}

/* ---- the cash column and the net line ------------------------------------
   Signed and coloured on the sign, which here is not a convention but the
   definition: `cash = -sign × qty × leg multiplier × premium`, so negative is
   money leaving the account.  Debits red, credits green — the same pair the
   whole site uses for a disclosed sale and a disclosed purchase. */
.ow-money { font-family: var(--mono); }
.ow-money.is-neg { color: var(--sell); }
.ow-money.is-pos { color: var(--buy); }

.ow-legfoot {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin: .55rem 0 0;
}
.ow-legfoot .sp { flex: 1 1 1rem; }
.ow-legcount { font-size: .8rem; color: var(--muted); font-family: var(--mono); }
.ow-net {
  font-family: var(--mono); font-size: 1rem; font-weight: 700;
  letter-spacing: -.01em; padding: .22rem .65rem; border-radius: 7px;
  background: var(--bg); border: 1px solid var(--line);
}

/* ------------------------------------- regions D and E: chart and summary --
   Chart left, summary right, one column under 1100px.  1100 and not 960 (the
   site's usual breakpoint) because the summary needs ~300px of its own before
   the greek labels wrap onto two lines, and the chart is unreadable under about
   640px of plot — the pair genuinely needs a wider viewport than a two-column
   table does.  `minmax(0, 1fr)` on the left column, not `1fr`: a canvas in a
   grid track that has no explicit minimum will happily push the track wider
   than the page and take the summary off the right-hand edge with it. */
.ow-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.2rem; align-items: start; margin: 1rem 0;
}
.ow-grid > * { min-width: 0; }
@media (max-width: 1100px) { .ow-grid { grid-template-columns: 1fr; } }

.ow-chartcard {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: .8rem .9rem 1rem;
}
#ow-charttitle {
  margin: 0 0 .5rem; font-size: .95rem; font-weight: 600; letter-spacing: -.01em;
}
/* The summary rail is the single visible home for these metrics.  The legacy
   controller also wrote a compact copy into the live output region; keep that
   DOM output available to the status region without rendering a second summary
   above the payoff chart. */
.ow-chartcard #options-output > h2,
.ow-chartcard #options-output > dl { display: none; }

/* The banner (brief §4.3): non-blocking, above the chart, and never in place of
   it.  One leg whose implied volatility would not solve is charted at intrinsic
   and said so here while every other leg keeps its curve — degrade locally. */
.ow-banner {
  margin: 0 0 .6rem; padding: .4rem .6rem; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn);
  font-size: .82rem; line-height: 1.45;
}
.ow-banner p { margin: .12rem 0; }
.ow-banner p::before { content: "\26A0\00A0"; font-weight: 700; }
.ow-banner:empty { display: none; }
.ow-banner.ow-status-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* The wrapper exists for one reason — it is the tooltip's containing block —
   and holds nothing but the canvas and the tooltip, so that whatever the chart
   observes for its resize is the box the canvas actually occupies. */
#ow-chart-wrap { position: relative; width: 100%; }
#ow-chart-wrap.ow-chart-unavailable #options-output {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  margin: 0; padding: 1rem; text-align: center;
}
#ow-chart-wrap.ow-chart-unavailable #options-output > p { max-width: 32rem; }

/* The height is pinned in CSS and must stay pinned.  The renderer sets
   `canvas.width/height` in *device* pixels and scales the context by the device
   pixel ratio; with no CSS height the attribute would become the layout height
   and the chart would grow by a factor of the DPR on every redraw on a retina
   screen.  `touch-action: none` is what lets the spot marker be dragged on a
   phone without the page scrolling out from under the finger. */
#ow-chart {
  display: block; width: 100%; height: 440px;
  border-radius: 8px; background: var(--panel);
  touch-action: none; cursor: crosshair;
}
#ow-chart.ow-chart-unavailable { visibility: hidden; }
@media (max-width: 900px) { #ow-chart { height: 320px; } }

.ow-tooltip {
  position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none;
  min-width: 11rem; padding: .4rem .55rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--ink) 18%, transparent);
  font-family: var(--mono); font-size: .78rem; line-height: 1.45;
}

/* The preset paragraph, collapsible under the chart title (brief §3.1). */
.ow-preset-note {
  margin: .7rem 0 0; border: 1px dashed var(--line); border-radius: 9px;
  background: var(--panel);
}
.ow-preset-note summary {
  cursor: pointer; padding: .4rem .7rem; font-size: .8rem;
  font-weight: 600; color: var(--muted);
}
.ow-preset-note[open] summary { border-bottom: 1px solid var(--line); color: var(--ink); }
.ow-note-body {
  margin: 0; padding: .5rem .7rem; font-size: .83rem; line-height: 1.55;
  color: var(--muted); max-width: 72ch;
}

/* ---- the chart controls --------------------------------------------------
   Every one of the four is the same shape — a label, a slider, a number box, a
   resolved-value note and a reset — because they are the same kind of thing and
   the reader should only have to learn the row once.  The slider is for
   sweeping, the box is for saying 47 exactly, and the reset exists because a
   chart control that cannot be put back is a trap: the volatility override in
   particular silently replaces every leg's own vol, and a reader who has
   dragged it has no other way to find out what it was. */
.ow-controls {
  margin-top: .8rem; padding-top: .7rem; border-top: 1px solid var(--line);
  display: grid; gap: .4rem;
}
.ow-ctl { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.ow-ctl > label {
  flex: 0 0 8.4rem; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.ow-ctl input[type="range"] {
  flex: 1 1 12rem; min-width: 7rem; height: 1.4rem; margin: 0;
  accent-color: var(--accent); cursor: ew-resize;
}
.ow-num {
  width: 5.6rem; text-align: right; padding: .24rem .4rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink);
  font-size: .85rem; font-family: var(--mono);
}
.ow-ctl select {
  padding: .24rem .4rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink); font-size: .8rem;
}
.ow-resolved {
  font-size: .78rem; color: var(--muted); font-family: var(--mono);
  min-width: 9rem;
}
.ow-reset {
  padding: .16rem .5rem; font-size: .76rem;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
}
.ow-reset:hover:not(:disabled) { color: var(--ink); border-color: var(--accent); }

/* ---- region E: the summary panel ---------------------------------------- */
#ow-summary {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  padding: .2rem .9rem .9rem; position: sticky; top: 5.4rem;
}
@media (max-width: 1100px) { #ow-summary { position: static; } }
#ow-summary h2,
.ow-subhead {
  margin: .9rem 0 .2rem; font-size: .78rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
}
.ow-metrics { margin: 0; }
.ow-metric {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .8rem; padding: .5rem 0; border-bottom: 1px solid var(--line);
}
.ow-metrics .ow-metric:last-child { border-bottom: 0; }
.ow-metric dt { color: var(--muted); font-size: .85rem; }
.ow-metric dd { margin: 0; text-align: right; }
.ow-val {
  display: block; font-family: var(--mono); font-size: 1.02rem;
  font-weight: 600; letter-spacing: -.01em; white-space: nowrap;
}
/* Coloured by *role*, not by sign: this is the upper bound and that is the
   lower one, whatever they currently read.  The controller re-renders the text
   of these spans and is not asked to re-derive a sign class, so a class that
   meant "positive" would be wrong the first time a strategy could only lose. */
.ow-val.is-pos { color: var(--buy); }
.ow-val.is-neg { color: var(--sell); }
.ow-unit { display: block; font-size: .72rem; color: var(--muted); }
.ow-sub {
  display: block; margin-top: .15rem; font-size: .78rem;
  font-family: var(--mono); color: var(--muted);
}
.ow-sub .ow-unit { display: inline; }
.ow-fineprint {
  margin: .8rem 0 .1rem; font-size: .76rem; line-height: 1.5; color: var(--muted);
}

/* ---- the JavaScript-off notes ------------------------------------------- */
.ow-noscript {
  margin: .6rem 0; padding: .5rem .7rem;
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: 9px; background: var(--panel);
  font-size: .83rem; line-height: 1.5;
}

/* ---- the saved-strategies page ------------------------------------------ */
table.ow-saved td[data-label="Legs"] { font-family: var(--mono); }
table.ow-saved td .btn { padding: .16rem .5rem; font-size: .78rem; }
.ow-delfail { color: var(--sell); }

/* ==========================================================================
   UNDER 900px — the row becomes a card (brief §4.5)
   --------------------------------------------------------------------------
   Nine editable columns do not fit a phone, and a horizontally scrolling table
   of number inputs is worse than useless on one: you cannot see the strike you
   are editing and its Buy/Sell at the same time.  So each `<tr>` becomes a
   3×3 card, and the header row is taken out of the flow and replaced by
   `td::before { content: attr(data-label) }` — which is why every `<td>` in
   `wizard.html` carries a `data-label`, including the ones whose label is
   obvious on a wide screen.

   The top line of the card is Side, Type and the row actions, so the two
   controls the brief names — the buy/sell toggle and delete — are reachable
   without touching anything else.  The header is hidden with the clip
   technique rather than `display: none`, so it stays in the accessibility tree
   and the cells keep their column names for a screen reader.
   ========================================================================== */
@media (max-width: 900px) {
  /* The wrapper's own frame would double every card's; the cards are the
     boxes now. */
  .ow-positions .tablewrap {
    overflow: visible; border: 0; border-radius: 0; background: transparent;
  }
  table.ow-legs,
  table.ow-legs tbody,
  table.ow-legs td { display: block; width: auto; }

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

  table.ow-legs tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .35rem .6rem;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--panel); padding: .55rem .65rem; margin: 0 0 .55rem;
  }
  #options-form table.ow-legs #option-legs > tr.option-leg {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  table.ow-legs tbody tr:last-child { margin-bottom: 0; }
  /* `app.css` gives table rows a hover tint; on a card that reads as a
     selection, and on a touch screen it sticks after a tap. */
  table.ow-legs tbody tr:hover { background: var(--panel); }

  table.ow-legs td,
  table.ow-legs tbody tr:last-child td {
    border: 0; padding: .1rem 0; width: auto; text-align: left;
  }
  table.ow-legs td::before {
    content: attr(data-label);
    display: block; margin-bottom: .1rem;
    font-family: inherit; font-size: .64rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  }
  table.ow-legs td.num input { text-align: right; }

  /* The desktop column widths are attribute selectors and outrank the plain
     `td` rule above, so they have to be undone at matching specificity or every
     card cell stays 5.8rem wide inside a 1fr grid track. */
  table.ow-legs td[data-field] { width: auto; }

  /* The 3×3 placement.  Written out cell by cell rather than left to source
     order, because source order would put Qty next to Side and push the delete
     button to the bottom of the card — the opposite of what §4.5 asks for. */
  table.ow-legs td[data-field="side"]     { grid-column: 1; grid-row: 1; }
  table.ow-legs td[data-field="type"]     { grid-column: 2; grid-row: 1; }
  table.ow-legs td[data-field="actions"]  { grid-column: 3; grid-row: 1; }
  table.ow-legs td[data-field="quantity"] { grid-column: 1; grid-row: 2; }
  table.ow-legs td[data-field="strike"]   { grid-column: 2; grid-row: 2; }
  table.ow-legs td[data-field="dte"]      { grid-column: 3; grid-row: 2; }
  table.ow-legs td[data-field="vol"],
  table.ow-legs td[data-field="volatility"] { grid-column: 1; grid-row: 3; }
  table.ow-legs td[data-field="premium"]  { grid-column: 2; grid-row: 3; }
  table.ow-legs td[data-field="cash"]     { grid-column: 3; grid-row: 3; }

  /* The warning triangle sat vertically centred against a one-line cell; in a
     card the cell is a label over an input, so it moves down to the input. */
  table.ow-legs td.ow-ivfail::before {
    top: auto; bottom: .42rem; transform: none;
  }

  /* Touch targets: the actions row and the toggle both grow. */
  .ow-side { min-height: 34px; }
  .ow-acts button { padding: .28rem .5rem; font-size: .78rem; }

  /* The bars stack their fields rather than squeezing them onto a line, and
     the five globals grow into whatever is left of the line they wrapped onto.
     The growth is the point: five fields at a 5.5rem basis wrap three and two,
     and without it the second row would stop a third of the way across and
     leave a hole in the strip. */
  .ow-globals,
  .ow-toolbar { gap: .55rem .7rem; }
  .ow-globals label { flex: 1 1 5.5rem; }
  .ow-globals input[type="number"],
  .ow-globals input[type="text"] { width: 100%; min-width: 5.5rem; }
  .ow-toolbar select { min-width: 0; width: 100%; }
  .ow-toolbar label { flex: 1 1 100%; }
  .ow-toolbar .sp { margin-left: 0; }

  .ow-ctl > label { flex: 1 1 100%; }
  .ow-resolved { min-width: 0; }

  .ow-legfoot { gap: .4rem; }
  .ow-legfoot .sp { flex-basis: 100%; height: 0; }
}

/* Below the phone breakpoint the summary rows stop being able to sit label-left
   value-right without the value wrapping mid-number. */
@media (max-width: 420px) {
  .ow-metric { display: block; }
  .ow-metric dd { text-align: left; margin-top: .1rem; }
}
