/* Mobile hardening shared by every Professional Markets workspace page. */

@media (max-width: 1200px) {
  .app-shell,
  .catalog-shell,
  .subscription-shell,
  .strategy-shell,
  .history-shell,
  .wallet-shell,
  .wallet-detail-shell,
  .shell {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

@media (max-width: 720px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .wrap,
  .catalog-shell,
  .subscription-shell,
  .strategy-shell,
  .history-shell,
  .wallet-shell,
  .wallet-detail-shell,
  .shell {
    width: 100%;
    max-width: 100%;
  }

  .catalog-shell,
  .subscription-shell,
  .strategy-shell {
    padding: 8px !important;
    gap: 10px !important;
  }

  .main,
  .history-main,
  .stage,
  .workspace,
  .module-view {
    width: 100%;
    min-width: 0;
  }

  main input:not([type="checkbox"]):not([type="radio"]),
  main select,
  main textarea {
    min-height: 44px;
    font-size: 16px !important;
  }

  main .button,
  main button:not(.favorite-btn):not(.market-trade-close) {
    min-height: 44px;
  }

  .hero-actions,
  .view-toolbar-actions,
  .market-card-actions,
  .monitor-head-actions,
  .subscription-toolbar,
  .trade-head-actions {
    width: 100%;
  }

  .hero-actions .hero-link,
  .hero-actions .button,
  .subscription-toolbar .button,
  .market-card-actions > *,
  .monitor-head-actions > button {
    flex: 1 1 140px;
    justify-content: center;
  }

  .table-wrap,
  .simulator-table-wrap {
    width: 100%;
    max-width: 100%;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .filter-scope,
  .filter-note,
  .statusbar,
  .wallet-status,
  .selector-trigger-copy,
  .selector-trigger-copy strong,
  .selector-trigger-copy small {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .section-panel,
  .wallet-section,
  .filter-panel,
  .results-panel,
  .favorites-panel,
  .summary-panel,
  .records-panel,
  .simulator-panel {
    min-width: 0;
  }

  /* Address research becomes a readable card list instead of a 900px table. */
  .results-panel .table-wrap {
    overflow: visible;
  }

  .results-panel .table-wrap > table {
    display: block;
    min-width: 0 !important;
  }

  .results-panel .table-wrap > table > thead {
    display: none;
  }

  .results-panel .table-wrap > table > tbody {
    display: grid;
    gap: 10px;
    padding-top: 10px;
  }

  .results-panel .table-wrap > table > tbody > tr {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 5px 16px rgba(25, 35, 30, .045);
  }

  .results-panel .table-wrap > table > tbody > tr > td {
    min-width: 0;
    padding: 0;
    display: block;
    border: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .results-panel .table-wrap > table > tbody > tr > td:first-child {
    display: none;
  }

  .results-panel .table-wrap > table > tbody > tr > td:nth-child(2) {
    position: absolute;
    top: 10px;
    right: 10px;
    width: auto;
  }

  .results-panel .table-wrap > table > tbody > tr > td:nth-child(3) {
    grid-column: 1 / -1;
    padding-right: 42px;
  }

  .results-panel .table-wrap > table > tbody > tr > td:nth-child(n+4)::before,
  #marketRows > tr > td::before,
  #tradeRows > tr > td::before {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
  }

  .results-panel tbody td:nth-child(4)::before { content: "确认 PnL"; }
  .results-panel tbody td:nth-child(5)::before { content: "已结算胜率"; }
  .results-panel tbody td:nth-child(6)::before { content: "市场"; }
  .results-panel tbody td:nth-child(7)::before { content: "Tier 命中"; }
  .results-panel tbody td:nth-child(8)::before { content: "完整操作"; }
  .results-panel tbody td:nth-child(9)::before { content: "场均操作"; }
  .results-panel tbody td:nth-child(10)::before { content: "操作额"; }
  .results-panel tbody td:nth-child(11)::before { content: "最近活动"; }

  .results-panel tbody td[colspan] {
    grid-column: 1 / -1;
    display: block !important;
    padding: 8px !important;
  }

  .favorite-btn {
    min-width: 38px;
    min-height: 38px;
  }

  /* Professional wallet market and trade rows use compact mobile cards. */
  .wallet-section .table-wrap:has(#marketRows),
  .wallet-section .table-wrap:has(#tradeRows) {
    overflow: visible;
  }

  .wallet-section table:has(#marketRows),
  .wallet-section table:has(#tradeRows) {
    display: block;
    min-width: 0 !important;
  }

  .wallet-section table:has(#marketRows) > thead,
  .wallet-section table:has(#tradeRows) > thead {
    display: none;
  }

  #marketRows,
  #tradeRows {
    display: grid;
    gap: 10px;
  }

  #marketRows > tr,
  #tradeRows > tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }

  #marketRows > tr > td,
  #tradeRows > tr > td {
    min-width: 0;
    padding: 0;
    display: block;
    border: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  #marketRows > tr > td:first-child,
  #marketRows > tr > td:last-child,
  #tradeRows > tr > td:nth-child(2),
  #tradeRows > tr > td:last-child {
    grid-column: 1 / -1;
  }

  #marketRows td:nth-child(1)::before { content: "市场"; }
  #marketRows td:nth-child(2)::before { content: "触发 / 操作方向"; }
  #marketRows td:nth-child(3)::before { content: "状态"; }
  #marketRows td:nth-child(4)::before { content: "首次触发"; }
  #marketRows td:nth-child(5)::before { content: "PnL"; }
  #marketRows td:nth-child(6)::before { content: "完整操作"; }
  #marketRows td:nth-child(7)::before { content: "操作额"; }
  #marketRows td:nth-child(8)::before { content: "操作"; }

  #tradeRows td:nth-child(1)::before { content: "时间"; }
  #tradeRows td:nth-child(2)::before { content: "市场"; }
  #tradeRows td:nth-child(3)::before { content: "方向"; }
  #tradeRows td:nth-child(4)::before { content: "结果 / Token"; }
  #tradeRows td:nth-child(5)::before { content: "Tier"; }
  #tradeRows td:nth-child(6)::before { content: "份额"; }
  #tradeRows td:nth-child(7)::before { content: "价格"; }
  #tradeRows td:nth-child(8)::before { content: "金额"; }
  #tradeRows td:nth-child(9)::before { content: "角色"; }
  #tradeRows td:nth-child(10)::before { content: "交易"; }

  #marketRows td[colspan],
  #tradeRows td[colspan] {
    grid-column: 1 / -1;
  }

  #marketRows .market-main {
    min-width: 0;
  }

  #marketRows .action-link,
  #tradeRows .action-link {
    width: 100%;
    min-height: 42px;
    justify-content: center;
  }

  .market-trade-popover {
    position: fixed !important;
    inset: auto 0 0 0 !important;
    width: 100% !important;
    max-width: none !important;
    max-height: min(78dvh, 640px) !important;
    border-radius: 18px 18px 0 0 !important;
  }

  .market-trade-body {
    max-height: calc(78dvh - 160px) !important;
    overflow: auto;
  }

  .market-trade-close {
    min-width: 40px;
    min-height: 40px;
  }

  #marketRows > tr.event-summary-row {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
  }

  #marketRows > tr.event-summary-row > td::before {
    display: none;
  }

  #marketRows > tr.event-child-market.event-collapsed {
    display: none;
  }

  .event-summary-button {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .event-summary-main strong,
  .event-summary-main span {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .event-summary-metrics {
    grid-column: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }

  .event-summary-metric {
    text-align: left;
  }

  .daily-pnl-calendar-panel {
    gap: 12px;
    padding: 12px;
  }

  .daily-pnl-calendar-head {
    display: grid;
    gap: 10px;
  }

  .daily-pnl-calendar-controls {
    width: max-content;
    max-width: 100%;
  }

  .daily-pnl-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .entry-grid,
  .overview,
  .stat-grid,
  .catalog-metrics,
  .summary,
  .summary-grid,
  .simulator-summary,
  .strategy-stats,
  .copy-summary,
  .cards {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .hero-actions,
  .view-toolbar-actions,
  .market-card-actions,
  .monitor-actions,
  .button-row,
  .tag-actions,
  .result-tabs {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .result-tabs > *,
  .button-row > *,
  .tag-actions > * {
    width: 100%;
  }

  .daily-pnl-summary,
  .smart-copy-tier-summary {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
