/* DPX v0.6.1 Patches 7-13. Loaded last; layout only. */

/* Patch 7: an open manual prediction keeps the ordinary action button. */
body#dpxRoot .trade-card #predictions .has-open-manual > .prediction-mobile-action-stack,
body#dpxRoot .trade-card #predictions .has-open-manual > .prediction-action-wrap,
body#dpxRoot .trade-card #predictions .prediction-action-wrap.has-open-manual {
  display: block !important;
  grid-template-columns: none !important;
  width: 100% !important;
  min-width: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  overflow: visible !important;
}
body#dpxRoot .trade-card #predictions .has-open-manual .prediction-action-cell {
  grid-column: auto !important;
  width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
}

/* Patches 10, 11 and 13: readable, scrollable ledger with stable values. */
body#dpxRoot #ledgerTableWrap,
body#dpxRoot #ledgerTableWrap.no-h-scroll {
  overflow-x: auto !important;
  overscroll-behavior-x: contain;
}
body#dpxRoot #ledgerTable th,
body#dpxRoot #ledgerTable td {
  box-sizing: border-box !important;
  min-width: max-content !important;
  white-space: nowrap !important;
  overflow: visible !important;
  text-overflow: clip !important;
}
body#dpxRoot #ledgerTable .ledger-col-brokerControl { min-width: 122px !important; }
body#dpxRoot #ledgerTable .ledger-col-brokerFees { min-width: 108px !important; }
body#dpxRoot #ledgerTable .ledger-col-duration { min-width: 88px !important; }
body#dpxRoot #ledgerTable .ledger-col-pnl { min-width: 82px !important; }
body#dpxRoot #ledgerTable .ledger-col-brokerControl { min-width: 142px !important; }
body#dpxRoot #ledgerTable .ledger-col-brokerFees { min-width: 132px !important; }
body#dpxRoot #ledgerTable .ledger-col-duration { width: 100px !important; min-width: 100px !important; max-width: none !important; }
body#dpxRoot #ledgerTable .ledger-col-pnl { width: 100px !important; min-width: 100px !important; max-width: none !important; }
body#dpxRoot #ledgerTable .ledger-col-brokerControl { width: 160px !important; min-width: 160px !important; max-width: none !important; }
body#dpxRoot #ledgerTable .ledger-col-brokerFees { width: 145px !important; min-width: 145px !important; max-width: none !important; }
body#dpxRoot #ledgerTable .broker-live-summary,
body#dpxRoot #ledgerTable .broker-fee-stack { min-width: max-content !important; }
body#dpxRoot #ledgerTable .sticky-col {
  position: static !important;
  left: auto !important;
  z-index: auto !important;
}

/* Patch 9: use the available laptop strip height instead of pushing it down. */
@media (min-width: 901px) and (max-width: 1800px) and (max-height: 1000px) and (min-height: 601px) {
  body#dpxRoot.desktop-tab-layout .trade-card .trade-market-row {
    align-items: start !important;
    min-height: 42px !important;
    height: 42px !important;
    max-height: 42px !important;
  }
  body#dpxRoot.desktop-tab-layout .trade-card #effectiveTradeSettings {
    align-self: start !important;
    margin-top: 0 !important;
    transform: translateY(-4px) !important;
  }
}

@media (max-width: 600px) and (orientation: portrait) {
  /* Patch 8: largest safe one-line prediction headings at phone width. */
  body#dpxRoot .prediction-mobile-head {
    grid-template-columns: minmax(112px, 1.18fr) minmax(58px, .62fr) minmax(43px, .46fr) minmax(40px, .43fr) minmax(50px, .52fr) !important;
    gap: 1px !important;
  }
  body#dpxRoot .prediction-mobile-head > span {
    min-width: 0 !important;
    padding-inline: 1px !important;
    font-size: clamp(7px, 2.15vw, 9px) !important;
    line-height: 1.05 !important;
    letter-spacing: 0 !important;
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }
  body#dpxRoot .prediction-mobile-row > span b {
    font-size: clamp(7px, 2.05vw, 8.5px) !important;
    white-space: nowrap !important;
  }

  /* Patch 10: every visible header remains one line; scroll reveals all. */
  body#dpxRoot #phoneHistoryPanel #ledgerTable {
    width: max-content !important;
    min-width: 100% !important;
    table-layout: auto !important;
  }
  body#dpxRoot #phoneHistoryPanel #ledgerTable th {
    min-width: max-content !important;
    padding: 5px 6px !important;
    font-size: clamp(9px, 2.8vw, 11px) !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }
}

@media (orientation: landscape) and (max-height: 600px) and (max-width: 1100px) {
  /* Patch 8: readable prediction labels and values in rotated-phone layout. */
  body#dpxRoot .trade-card .prediction-workbench {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100% !important;
    gap: 4px !important;
  }
  body#dpxRoot .trade-card .prediction-workbench > .prediction-order-row,
  body#dpxRoot .trade-card .prediction-workbench > .prediction-panel {
    grid-column: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  body#dpxRoot .trade-card .prediction-workbench > .prediction-panel {
    position: static !important;
    margin-top: 58px !important;
  }
  body#dpxRoot .trade-card .prediction-workbench > .prediction-order-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: 50px 20px !important;
    min-height: 72px !important;
    height: 72px !important;
    gap: 2px !important;
  }
  body#dpxRoot .trade-card .prediction-workbench > .prediction-order-row > .preset-field {
    grid-column: 1 !important;
    grid-row: 1 !important;
    width: 160px !important;
    max-width: 160px !important;
    height: 50px !important;
    min-height: 50px !important;
  }
  body#dpxRoot .trade-card .prediction-workbench > .prediction-order-row > #effectiveTradeSettings {
    grid-column: 1 !important;
    grid-row: 2 !important;
    display: grid !important;
    grid-template-columns: repeat(3, max-content) !important;
    justify-content: start !important;
    gap: 14px !important;
    width: 100% !important;
    height: 20px !important;
    padding: 0 !important;
    transform: none !important;
  }
  body#dpxRoot .trade-card .prediction-workbench > .prediction-order-row > #effectiveTradeSettings .effective-trade-item {
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    font-size: 9px !important;
    line-height: 20px !important;
    white-space: nowrap !important;
  }
  body#dpxRoot .trade-card #predictions.prediction-table-layout {
    display: grid !important;
    grid-template-columns: minmax(140px, 1.55fr) minmax(74px, .82fr) minmax(54px, .58fr) minmax(49px, .54fr) minmax(64px, .68fr) !important;
    grid-auto-rows: minmax(30px, auto) !important;
    gap: 2px !important;
    width: 100% !important;
    overflow: visible !important;
  }
  body#dpxRoot .trade-card #predictions > .prediction-table-head,
  body#dpxRoot .trade-card #predictions > .prediction-info-cell,
  body#dpxRoot .trade-card #predictions > .prediction-action-wrap {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 30px !important;
  }
  body#dpxRoot .trade-card #predictions > .prediction-action-wrap { display: block !important; }
  body#dpxRoot .prediction-table-head { font-size: 8px !important; line-height: 1 !important; white-space: nowrap !important; }
  body#dpxRoot .prediction-info-cell,
  body#dpxRoot .prediction-info-cell * { font-size: 8.5px !important; white-space: nowrap !important; overflow: visible !important; }

  /* Patch 11: never squeeze or truncate landscape ledger values. */
  body#dpxRoot #ledgerTable {
    width: max-content !important;
    min-width: 100% !important;
    table-layout: auto !important;
  }
  body#dpxRoot #ledgerTable th,
  body#dpxRoot #ledgerTable td {
    min-width: max-content !important;
    padding-inline: 7px !important;
  }
  body#dpxRoot #ledgerTable .ledger-stack,
  body#dpxRoot #ledgerTable .ledger-stack-line,
  body#dpxRoot #ledgerTable .phone-value-stack,
  body#dpxRoot #ledgerTable .phone-trade-stack {
    width: max-content !important;
    min-width: max-content !important;
    overflow: visible !important;
  }

  /* Patch 12: display-only removal; entry logic remains unchanged. */
  body#dpxRoot .entry-min-est-label .entry-only-note { display: none !important; }
}
