/* ===== MOBILE MODULE — TLAP Season ===== */
/* Activated via @media (max-width: 768px) */

@media (max-width: 768px) {

  /* === HEADER === */
  .header {
    padding: 10px 12px;
    gap: 8px;
    flex-direction: column;
    align-items: stretch;
  }
  .header > .header-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .header h1 {
    font-size: 16px;
    margin-right: 0;
  }
  .header-controls {
    margin-left: 0;
    gap: 4px;
  }
  .toggle-btn {
    padding: 6px 10px;
    font-size: 14px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* === MARKET DROPDOWNS === */
  #marketSelects {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 4px !important;
    flex-wrap: unset !important;
    overflow-x: visible;
    padding-bottom: 0;
  }

  .custom-select {
    flex-shrink: unset;
    width: 100%;
  }
  .custom-select-trigger {
    padding: 8px 6px;
    font-size: 13px;
    gap: 4px;
    min-height: 38px;
    width: 100%;
    justify-content: center;
  }
  .custom-select-trigger .market-label {
    font-size: 12px;
    letter-spacing: 0.2px;
  }
  .custom-select-trigger .sym-label {
    font-size: 13px;
    display: none;
  }
  .custom-select-trigger.active-market .sym-label {
    display: inline;
  }
  .custom-select-trigger .arrow {
    font-size: 9px;
  }

  /* Dropdown panel — full-width bottom sheet */
  .custom-select-dropdown {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    margin-top: 0 !important;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
    z-index: 10000;
    padding-top: 8px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }
  .custom-select-dropdown::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #484f58;
    border-radius: 2px;
    margin: 0 auto 8px;
  }
  body.light .custom-select-dropdown::before {
    background: #d1d9e0;
  }
  .custom-select-option {
    padding: 12px 20px;
    font-size: 16px;
    min-height: 46px;
    display: flex;
    align-items: center;
  }

  /* Overlay behind bottom sheet */
  .mobile-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
  }

  /* === PERFORMANCE BAR === */
  .perf-bar {
    padding: 8px 12px;
    gap: 8px 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  .perf-item {
    flex-direction: column;
    gap: 2px;
    align-items: flex-start;
  }
  .perf-label {
    font-size: 9px;
  }
  .perf-value {
    font-size: 13px;
  }

  /* === SECTIONS === */
  .section {
    padding: 10px 8px;
  }
  .section h2 {
    font-size: 12px;
    margin-bottom: 6px;
  }

  /* === SEASONAL CHART === */
  .seasonal-container {
    border-radius: 6px;
  }
  .seasonal-container canvas {
    height: 260px !important;
  }
  .seasonal-toolbar {
    padding: 6px 8px;
    gap: 6px;
    flex-direction: column;
    align-items: flex-start;
  }
  .seasonal-legend {
    gap: 6px 10px;
    font-size: 11px;
  }
  .seasonal-legend-item {
    font-size: 11px;
    gap: 4px;
  }
  .seasonal-legend-item .swatch {
    width: 16px;
    height: 3px;
  }
  .seasonal-periods {
    gap: 3px;
    width: 100%;
  }
  .seasonal-periods button,
  .returns-periods button {
    padding: 5px 10px;
    font-size: 11px;
    flex: 1;
    min-height: 32px;
  }

  /* === RETURNS TABLE === */
  .returns-toolbar {
    gap: 6px;
    flex-direction: column;
    align-items: flex-start;
  }
  .returns-periods {
    gap: 3px;
    width: 100%;
  }

  /* Make returns container scrollable */
  #returnsContainer {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #returnsContainer table {
    table-layout: auto;
    width: max-content;
    min-width: 100%;
  }
  #returnsContainer .weekly-table {
    min-width: max-content;
  }

  /* Smaller cells on mobile */
  th {
    font-size: 10px;
    padding: 4px 2px;
    white-space: nowrap;
  }
  th:first-child {
    width: 40px;
    padding-left: 6px;
  }
  td {
    padding: 1px;
  }
  .cell {
    min-height: 36px;
    padding: 2px 0;
    border-radius: 3px;
  }
  .cell-value {
    font-size: 10px;
  }
  .cell canvas {
    height: 14px;
  }

  /* Weekly table mobile */
  .weekly-table th, .weekly-table td {
    font-size: 8px;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
  }
  .weekly-table .cell {
    min-height: 44px;
    width: 42px;
    height: 42px;
  }
  .weekly-table .cell-value {
    font-size: 8px;
  }

  /* === CYCLE SECTION === */
  .cycle-info {
    gap: 8px 12px;
    padding: 8px 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .cycle-stat .perf-label {
    font-size: 9px;
  }
  .cycle-stat .perf-value {
    font-size: 12px;
  }
  .cycle-bar-wrap {
    margin: 4px 0 8px;
  }
  .cycle-bar {
    height: 22px;
  }
  .cycle-bar-bull, .cycle-bar-bear {
    font-size: 9px;
  }
  .cycle-bar-ticks {
    font-size: 8px;
  }
  #cycleCanvas {
    height: 260px !important;
  }
  .cycle-legend-stat {
    font-size: 10px;
    margin-left: 0;
    margin-top: 4px;
  }

  /* Scrollbar styling for tables */
  #returnsContainer::-webkit-scrollbar { width: 4px; height: 4px; }
  #returnsContainer::-webkit-scrollbar-track { background: transparent; }
  #returnsContainer::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.18);
    border: 1px solid transparent;
    border-radius: 999px;
    background-clip: content-box;
  }
  body.light #returnsContainer::-webkit-scrollbar-thumb { background-color: rgba(148, 163, 184, 0.18); }

  /* First column sticky in returns */
  #returnsContainer table th:first-child,
  #returnsContainer table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #0d1117;
  }
  #returnsContainer table th:first-child {
    z-index: 3;
    background: #161b22;
  }
  body.light #returnsContainer table td:first-child {
    background: #ffffff;
  }
  body.light #returnsContainer table th:first-child {
    background: #f6f8fa;
  }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 480px) {
  #marketSelects {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 3px !important;
  }
  .custom-select-trigger {
    padding: 6px 4px;
    min-height: 34px;
  }
  .custom-select-trigger .market-label {
    font-size: 11px;
  }
  .custom-select-trigger .sym-label {
    font-size: 12px;
  }

  .perf-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .seasonal-container canvas {
    height: 220px !important;
  }
  #cycleCanvas {
    height: 220px !important;
  }
  .seasonal-legend {
    gap: 4px 8px;
  }
  .seasonal-legend-item {
    font-size: 10px;
  }
  #returnsContainer table {
    width: max-content;
    min-width: 100%;
  }
  th {
    font-size: 9px;
    padding: 3px 1px;
  }
  th:first-child {
    width: 36px;
    padding-left: 4px;
  }
  td {
    padding: 1px;
  }
  .cell {
    min-height: 32px;
  }
  .cell-value {
    font-size: 9px;
  }
  .cell canvas {
    height: 12px;
  }
}
