/* Manual Analysis page only; loaded after styles.css. */

/* Column wrappers matter only on desktop (≥ 1024 px); below that they are not boxes at all. */
.analysis-left, .analysis-right { display: contents; }

/* Shown only when the browser curve does not match the Monitor. */
.reconciliation { max-width: 560px; margin: 12px 0 18px; padding: 12px 14px; border: 1px solid var(--red); border-radius: 12px; color: var(--red); background: #231a24; font-size: 15px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }
.reconciliation strong { font-weight: 850; }


/* Delta and Gamma of the portfolio with every change, right under the chart. */
.dg-section { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; padding: 8px 0 10px; border-bottom: 1px solid var(--line); }
.dg-section .greek-item { min-height: 0; padding: 6px 0; border-left: 0; }
.dg-section .greek-item + .greek-item { padding-left: 16px; border-left: 1px solid var(--line-soft); }
.dg-section .greek-item strong { display: block; max-width: 100%; overflow: hidden; font-size: clamp(32px, 3.3vw, 50px); }
.dg-section .greek-item span, .dg-section .greek-item small { font-size: 13px; }


/* Virtual trade panel: one finger-sized layout for phone and desktop (desktop: limited width).
   Every control is at least 56 px high with at least 8 px between controls. */
.manage-section { padding: 6px 0 18px; border-bottom: 1px solid var(--line); font-size: 17px; }
.manage-inner { max-width: 560px; display: flex; flex-direction: column; gap: 12px; }
.block-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 12px; min-height: 44px; }
.block-heading h2 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: .08em; }
.block-heading .count-badge { font-size: 13px; }
.block-heading small { flex-basis: 100%; color: var(--muted-2); font-size: 13px; font-weight: 600; }
.trade-group { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.trade-label { color: var(--muted); font-size: 13px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.trade-label small { margin-left: 6px; color: var(--muted-2); font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; }

.manage-section button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: pointer; }

.segmented { display: grid; grid-template-columns: repeat(var(--segments, 2), minmax(0, 1fr)); gap: 8px; }
.segmented button { min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: var(--surface); font-size: 18px; font-weight: 720; line-height: 1.1; }
.segmented button small { color: var(--muted-2); font-size: 13px; font-weight: 650; }
.segmented button.selected { border-color: var(--cyan); color: var(--text); background: #16324a; box-shadow: inset 0 0 0 1px var(--cyan); }
.segmented button.selected small { color: #bfe9f4; }
.segmented button:disabled, .big-button:disabled, .stepper button:disabled { opacity: .38; cursor: default; }
.segmented button.buy.selected { border-color: var(--green); color: #06170e; background: var(--green); box-shadow: none; }
.segmented button.sell.selected { border-color: var(--red); color: #22080b; background: var(--red); box-shadow: none; }

.stepper { display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; gap: 8px; }
.stepper button { min-height: 56px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface-2); font-size: 28px; font-weight: 600; line-height: 1; }
.stepper button:active { background: #1d3246; }
.stepper input, .price-input { width: 100%; min-width: 0; min-height: 56px; padding: 0 10px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface); font-family: inherit; font-size: 24px; font-weight: 720; text-align: center; font-variant-numeric: tabular-nums; }
.stepper select { width: 100%; min-width: 0; min-height: 56px; padding: 0 10px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface); font-family: inherit; font-size: 24px; font-weight: 720; text-align: center; text-align-last: center; font-variant-numeric: tabular-nums; -webkit-appearance: none; appearance: none; cursor: pointer; }
.stepper select:focus { outline: none; border-color: var(--cyan); box-shadow: inset 0 0 0 1px var(--cyan); }
.stepper input:focus, .price-input:focus { outline: none; border-color: var(--cyan); box-shadow: inset 0 0 0 1px var(--cyan); }
.price-input::placeholder { color: var(--muted-2); opacity: 1; }
.price-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 8px; align-items: center; }
.trade-quote { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.trade-quote-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; }
.trade-quote strong { font-size: 20px; font-weight: 720; }
.trade-amount { color: var(--text); font-size: 20px; font-weight: 720; white-space: nowrap; font-variant-numeric: tabular-nums; }
.trade-quote small { color: var(--muted); font-size: 13px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }

.trade-preview { color: var(--muted); font-size: 15px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.trade-preview.error { color: var(--red); }
.trade-preview.draft { color: var(--cyan); }
.expiry-picker { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.expiry-picker[hidden] { display: none; }
.date-input { width: 100%; min-width: 0; min-height: 56px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--bg); color-scheme: dark; font-family: inherit; font-size: 20px; font-weight: 700; -webkit-appearance: none; appearance: none; }
.field-error { color: var(--red); font-size: 15px; font-weight: 650; }
.field-error:empty { display: none; }

.position-edit-list { display: flex; flex-direction: column; gap: 10px; }
.position-group { margin-top: 4px; color: var(--muted); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.position-edit-row { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.position-edit-row.changed { border-color: var(--amber); background: #221c14; box-shadow: inset 4px 0 0 var(--amber); }
.position-edit-row.invalid { border-color: #6a4048; }
.position-edit-row .trade-row-head { grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; }
.position-edit-row .trade-contract { white-space: normal; overflow-wrap: anywhere; }
.position-current { grid-column: 1 / -1; color: var(--muted); font-size: 15px; font-weight: 700; }
.position-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.position-change { display: flex; flex-direction: column; gap: 8px; }
.position-change[hidden] { display: none; }
.position-change strong { color: var(--amber); font-size: 16px; font-weight: 760; }
.position-notices { display: flex; flex-direction: column; gap: 8px; }
.position-notices:empty { display: none; }
.position-notice { padding: 10px 12px; border: 1px solid #6a5a3a; border-radius: 12px; color: var(--amber); background: #221c14; font-size: 15px; font-weight: 650; }
.big-button { width: 100%; min-height: 56px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface-2); font-size: 18px; font-weight: 760; }
.big-button:hover { border-color: var(--cyan); }
.big-button.primary { border-color: var(--green); color: #06170e; background: var(--green); }
.big-button.danger { border-color: #6a4048; color: var(--red); background: transparent; }
/* Add | Reset under the new trade: Reset clears only this panel (quantity 0, estimated price). */
.trade-actions { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 10px; }

.trade-list { display: flex; flex-direction: column; gap: 10px; }
.trade-empty { margin: 0; color: var(--muted-2); font-size: 15px; }
.trade-row { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.trade-row.invalid { border-color: #6a4048; }
.trade-row-head { display: grid; grid-template-columns: auto minmax(0, 1fr) 56px; align-items: center; gap: 10px; }
.trade-contract { overflow: hidden; font-size: 19px; font-weight: 760; text-overflow: ellipsis; white-space: nowrap; }
.trade-row.invalid .trade-contract { color: var(--red); }
.trade-side { padding: 5px 9px; border-radius: 8px; font-size: 14px; font-weight: 820; letter-spacing: .06em; }
.trade-side.buy { color: #06170e; background: var(--green); }
.trade-side.sell { color: #22080b; background: var(--red); }
.trade-remove { min-height: 56px; border: 1px solid #6a4048; border-radius: 12px; color: var(--red); background: transparent; font-size: 22px; }
.trade-row-controls { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 8px; }
.trade-row .stepper { grid-template-columns: 56px minmax(0, 1fr) 56px; }
.trade-note { color: var(--muted); font-size: 14px; font-weight: 600; line-height: 1.3; }
.trade-note.error { color: var(--red); }

.report-block { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid #3b5a6e; border-radius: 14px; background: var(--surface); }
.report-block[hidden] { display: none; }
.report-block pre { margin: 0; color: var(--text); font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.report-copied { min-height: 1em; color: var(--green); font-size: 15px; font-weight: 700; }

@media (max-width: 700px) {
  .reconciliation { order: 3; }
  .manage-section { order: 3; }
  .dg-section { order: 3; }
}
@media (max-width: 380px) {
  .stepper { grid-template-columns: 56px minmax(0, 1fr) 56px; }
  .trade-row-controls { grid-template-columns: minmax(0, 1fr); }
  .price-row { grid-template-columns: minmax(0, 1fr); }
}

/* Desktop (≥ 1024 px): two columns. Left (~60 %) is pinned under the sticky header: Delta and
   Gamma, then the chart filling the rest of the window. Right (~40 %) scrolls with the page.
   Mouse-sized controls (36–40 px), regular type, hover states. --analysis-header is the height
   of the sticky header, measured by analysis.js. Nothing here applies below 1024 px. */
@media (min-width: 1024px) {
  .analysis-page .topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); }
  .analysis-page .refresh-bar { position: sticky; top: 43px; z-index: 19; background: var(--bg); }
  .analysis-page main { display: grid; grid-template-columns: minmax(0, 3fr) minmax(440px, 2fr); gap: 0 28px; align-items: start; }
  .analysis-page main > .load-error { grid-column: 1 / -1; }
  .analysis-left { display: flex; flex-direction: column; position: sticky; top: var(--analysis-header, 86px); height: calc(100vh - var(--analysis-header, 86px)); min-width: 0; }
  .analysis-right { display: block; min-width: 0; padding-bottom: 24px; }

  .analysis-left .dg-section { order: -1; flex: 0 0 auto; padding: 4px 0 6px; }
  .dg-section .greek-item strong { font-size: clamp(30px, 2.6vw, 44px); }
  .dg-section .greek-item span, .dg-section .greek-item small { font-size: 10px; }
  .analysis-left .stress-section { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; border-bottom: 0; }
  .analysis-left .stress-chart-wrap { flex: 1 1 auto; height: auto; min-height: 260px; }
  /* The left column is ~60 % wide: stress header and extrema as the Monitor lays them out at
     ≤ 1100 px; Stress IV min/max (model pending) hidden as on the phone; footnote may wrap. */
  .analysis-left .stress-heading { flex-wrap: wrap; padding: 6px 0; gap: 4px 16px; }
  .analysis-left .stress-title-group { margin-right: auto; }
  .analysis-left .stress-baseline { display: none; }
  .analysis-left .stress-extrema { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analysis-left .stress-extrema > div:nth-child(n+3) { display: none; }
  .analysis-left .model-footnote { flex-wrap: wrap; padding: 3px 0; }
  .analysis-left .model-footnote > span { white-space: normal; }

  .manage-section { padding: 0 0 14px; border-bottom: 0; font-size: 13px; }
  .manage-inner { max-width: none; gap: 8px; }
  .block-heading { min-height: 32px; margin-top: 10px; }
  .block-heading h2 { font-size: 12px; }
  .block-heading .count-badge { font-size: 10px; }
  .block-heading small { font-size: 11px; }
  .manage-inner > .block-heading:first-child { margin-top: 4px; }
  .trade-group { gap: 5px; }
  .trade-label { font-size: 10px; }
  .trade-label small { font-size: 10px; }

  .segmented { gap: 6px; grid-template-columns: repeat(var(--segments-desktop, var(--segments, 2)), minmax(0, 1fr)); }
  #expiry-buttons { --segments-desktop: 4; }
  .segmented button { min-height: 38px; padding: 3px 6px; border-radius: 7px; font-size: 13px; }
  .segmented button small { font-size: 10px; }
  .segmented button:not(:disabled):not(.selected):hover { border-color: var(--cyan); color: var(--text); }
  .stepper { grid-template-columns: 38px minmax(0, 1fr) 38px; gap: 6px; }
  .stepper button { min-height: 38px; border-radius: 7px; font-size: 18px; }
  .stepper button:not(:disabled):hover { border-color: var(--cyan); background: #1a2b3c; }
  .stepper input, .stepper select, .price-input { min-height: 38px; border-radius: 7px; font-size: 15px; }
  .stepper select:hover, .price-input:hover, .stepper input:hover { border-color: #3b5a6e; }
  .price-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 10px; }
  .trade-quote strong, .trade-amount { font-size: 15px; }
  .trade-quote small { font-size: 11px; }
  .trade-preview { font-size: 12px; }
  .expiry-picker { padding: 8px; border-radius: 9px; gap: 6px; }
  .date-input { min-height: 38px; border-radius: 7px; font-size: 14px; }
  .field-error { font-size: 12px; }
  .big-button { min-height: 40px; border-radius: 8px; font-size: 13px; }
  .big-button.primary:not(:disabled):hover { background: #80dfac; border-color: #80dfac; }
  .big-button.danger:hover { border-color: var(--red); background: #231a24; }
  .report-block { padding: 10px; border-radius: 9px; }
  .report-block pre { font-size: 12px; }
  .report-copied { font-size: 12px; }
  .reconciliation { max-width: none; margin: 10px 0; font-size: 12px; }

  /* Compact rows: added trades */
  .trade-list { gap: 0; }
  .trade-empty { font-size: 12px; }
  .trade-row { display: grid; grid-template-columns: auto minmax(0, 1fr) 136px 84px 36px; grid-template-areas: "side name qty price remove" "note note note note note"; align-items: center; gap: 2px 8px; padding: 6px 4px; border: 0; border-bottom: 1px solid var(--line-soft); border-radius: 0; background: transparent; }
  .trade-row:hover { background: var(--surface); }
  .trade-row .trade-row-head, .trade-row .trade-row-controls { display: contents; }
  .trade-row .trade-side { grid-area: side; }
  .trade-row .trade-contract { grid-area: name; font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
  .trade-row .stepper { grid-area: qty; grid-template-columns: 36px minmax(0, 1fr) 36px; gap: 4px; }
  .trade-row .price-input { grid-area: price; }
  .trade-row .trade-remove { grid-area: remove; }
  .trade-row .trade-note { grid-area: note; }
  .trade-row .stepper button, .trade-row .stepper input, .trade-row .price-input { min-height: 36px; font-size: 13px; }
  .trade-side { padding: 2px 6px; border-radius: 5px; font-size: 10px; }
  .trade-remove { min-height: 36px; border-radius: 6px; font-size: 13px; }
  .trade-remove:hover { border-color: var(--red); background: #231a24; }
  .trade-note { font-size: 11px; }

  /* Compact rows: my positions, one line each (current quantity under the contract) */
  .position-edit-list { gap: 0; }
  .position-group { margin-top: 8px; padding-bottom: 2px; border-bottom: 1px solid var(--line); font-size: 10px; }
  .position-edit-row { display: grid; grid-template-columns: auto minmax(0, 1fr) 160px 66px 66px; grid-template-areas: "side name target close revert" "side current target close revert" "change change change change change"; align-items: center; gap: 0 8px; padding: 5px 4px; border: 0; border-bottom: 1px solid var(--line-soft); border-radius: 0; background: transparent; }
  .position-edit-row:hover { background: var(--surface); }
  .position-edit-row.changed { background: #221c14; box-shadow: inset 3px 0 0 var(--amber); }
  .position-edit-row .trade-row-head, .position-edit-row .position-actions { display: contents; }
  .position-edit-row .trade-side { grid-area: side; }
  .position-edit-row .trade-contract { grid-area: name; font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
  .position-edit-row .position-current { grid-area: current; font-size: 11px; }
  .position-edit-row .stepper { grid-area: target; grid-template-columns: 36px minmax(0, 1fr) 36px; gap: 4px; }
  .position-edit-row .stepper button, .position-edit-row .stepper select { min-height: 36px; font-size: 13px; }
  .position-edit-row .position-actions .big-button { min-height: 36px; padding: 0 6px; font-size: 12px; }
  .position-edit-row .position-actions .big-button:first-child { grid-area: close; }
  .position-edit-row .position-actions .big-button:last-child { grid-area: revert; }
  .position-change { grid-area: change; display: grid; grid-template-columns: minmax(0, 1fr) 88px; grid-template-areas: "summary price" "note note"; align-items: center; gap: 2px 8px; margin-top: 4px; }
  .position-change strong { grid-area: summary; font-size: 12px; }
  .position-change .price-input { grid-area: price; min-height: 36px; font-size: 13px; }
  .position-change .trade-note { grid-area: note; }
  .position-notice { padding: 6px 10px; border-radius: 7px; font-size: 12px; }
}
