/* Mobile layout patch: keep charts visible and prevent desktop min-width rules
   from forcing the whole app wider than the phone viewport. */
@media (max-width: 860px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    min-width: 0;
  }

  .app-shell {
    display: block !important;
    width: 100%;
    min-width: 0;
  }

  .topbar {
    position: sticky !important;
    top: 0;
    width: 100% !important;
    max-width: 100vw;
    min-height: 0;
    padding: 10px 12px !important;
    gap: 10px;
    overflow: hidden;
  }

  .brand-lockup {
    min-width: 0;
  }

  .brand-mark {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .topbar nav {
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .topbar nav::-webkit-scrollbar {
    display: none;
  }

  .topbar nav a {
    flex: 0 0 auto;
    height: 34px;
    padding: 0 12px;
    white-space: nowrap;
    border-radius: 999px;
    font-size: 13px;
  }

  main {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 12px !important;
    gap: 12px;
    overflow: hidden;
  }

  .statusbar {
    position: static !important;
    width: 100%;
    min-width: 0;
    margin: 0 0 12px !important;
    padding: 12px;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    border-radius: 18px;
  }

  .status-actions {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .status-actions::-webkit-scrollbar {
    display: none;
  }

  .status-actions > * {
    flex: 0 0 auto;
  }

  .band {
    width: 100%;
    min-width: 0;
    padding: 14px;
    border-radius: 20px;
    overflow: hidden;
  }

  .section-head {
    display: grid !important;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 12px;
  }

  #portfolio .section-head {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    flex-direction: initial;
    flex-wrap: initial;
    justify-content: initial;
  }

  #portfolio .section-head > div:first-child,
  #portfolio-symbol-filter {
    flex: none;
  }

  #portfolio-symbol-filter,
  .quote-form,
  .portfolio-profile-bar.compact {
    width: 100%;
    min-width: 0 !important;
  }

  .portfolio-profile-bar.compact {
    grid-template-columns: 1fr;
    border-radius: 18px;
  }

  .portfolio-inline-picker {
    position: fixed;
    inset: auto 10px 16px 10px;
    width: auto;
    max-height: min(70vh, 620px);
    border-radius: 24px;
  }

  .portfolio-inline-picker::before {
    content: none;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  .plan-form .field,
  #trade-entry .plan-form .field {
    width: 100%;
  }

  .metrics article {
    min-width: 0;
    padding: 12px;
  }

  .metrics strong {
    font-size: clamp(18px, 5vw, 24px);
  }

  .portfolio-review {
    padding: 12px;
  }

  .compare-head {
    display: grid !important;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
  }

  .compare-head > div,
  .compare-legend,
  .benchmark-dropdown,
  .compare-floating-tools {
    min-width: 0;
    width: 100%;
    flex-basis: auto;
    margin-left: 0;
  }

  .compare-legend {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .compare-floating-tools {
    justify-content: flex-start;
  }

  .benchmark-multi {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 18px;
    width: auto;
    max-height: 58vh;
    overflow: auto;
    border-radius: 22px;
  }

  .compare-stage {
    width: 100%;
    min-height: 360px !important;
    height: 360px !important;
    overflow: hidden;
    border-radius: 18px;
  }

  .compare-chart {
    display: block;
    width: 100% !important;
    height: 360px !important;
    min-height: 360px !important;
  }

  .strategy-list {
    width: 100%;
    display: grid;
    gap: 12px;
    overflow: visible;
    padding-bottom: 0;
  }

  .strategy-card:not(.expanded) {
    width: 100%;
    min-width: 0 !important;
    grid-template-columns: 1fr !important;
    gap: 12px;
    padding: 14px;
  }

  .strategy-card:not(.expanded) .strategy-title {
    width: 100%;
  }

  .strategy-card:not(.expanded) .strategy-compact {
    width: 100%;
    min-width: 0 !important;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
  }

  .strategy-compact span,
  .strategy-compact b,
  .strategy-compact em {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .strategy-compact b {
    font-size: clamp(15px, 4.2vw, 19px);
  }

  .instrument-modal,
  .review-modal {
    position: fixed !important;
    inset: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)) 8px !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    transform: none !important;
    border-radius: 22px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .instrument-modal-head {
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 10px;
    padding: 14px;
  }

  .instrument-modal-title {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .instrument-modal-quote {
    grid-column: 1 / -1;
    grid-row: 2;
    align-items: flex-start;
    text-align: left;
  }

  .instrument-modal .modal-close {
    grid-column: 2;
    grid-row: 1;
    width: auto !important;
    min-width: 64px;
    justify-self: end;
    align-self: start;
  }

  .instrument-modal-tabs {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 10px 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .instrument-modal-tabs::-webkit-scrollbar {
    display: none;
  }

  .instrument-modal-tabs button {
    flex: 0 0 auto;
    height: 36px;
    padding: 0 12px;
    white-space: nowrap;
  }

  .instrument-modal-kpis {
    flex: 0 0 auto;
    display: flex;
    grid-template-columns: none !important;
    gap: 8px;
    padding: 10px 14px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .instrument-modal-kpis::-webkit-scrollbar {
    display: none;
  }

  .instrument-modal-kpis article {
    flex: 0 0 158px;
    min-width: 0;
    padding: 10px;
  }

  .instrument-modal-kpis strong {
    font-size: clamp(17px, 4.8vw, 22px);
    overflow-wrap: anywhere;
  }

  .instrument-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 12px 14px 16px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .instrument-modal .chart,
  .review-modal .chart,
  .instrument-modal .review-panel,
  .review-modal .review-panel {
    width: 100%;
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 10px;
    overflow: visible;
  }

  .instrument-modal .chart-with-sidebar,
  .review-modal .chart-with-sidebar {
    width: 100%;
    min-width: 0 !important;
    min-height: 0 !important;
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .review-toolbar {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .review-toolbar::-webkit-scrollbar {
    display: none;
  }

  .review-toolbar button,
  .review-toolbar span {
    flex: 0 0 auto;
  }

  .instrument-modal .chart-stage,
  .review-modal .chart-stage,
  .instrument-modal .chart-loading,
  .review-modal .chart-loading {
    width: 100%;
    min-width: 0 !important;
    min-height: 370px !important;
    height: 370px !important;
    border-radius: 16px;
    overflow: hidden;
  }

  .instrument-modal .chart-stage svg,
  .review-modal .chart-stage svg,
  .instrument-modal .chart-dark svg,
  .review-modal .chart-dark svg {
    display: block;
    width: 100% !important;
    height: 370px !important;
    min-width: 0 !important;
    min-height: 370px !important;
  }

  .chart-stats {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
  }

  .chart-stats article {
    min-width: 0;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 430px) {
  .metrics,
  .instrument-modal-kpis,
  .chart-stats {
    grid-template-columns: 1fr !important;
  }

  .compare-stage,
  .compare-chart {
    height: 340px !important;
    min-height: 340px !important;
  }

  .instrument-modal .chart-stage,
  .review-modal .chart-stage,
  .instrument-modal .chart-stage svg,
  .review-modal .chart-stage svg,
  .instrument-modal .chart-dark svg,
  .review-modal .chart-dark svg {
    height: 340px !important;
    min-height: 340px !important;
  }
}
