/* Phone pass, worker M2: charts, tables and card views for portrait phones (max-width 640px).
   Desktop (> 640px) is untouched: everything phone-only is hidden by default and switched on inside the media queries. */

/* ---- phone-only pieces: hidden everywhere else ---- */
.mx-phone, .tcards, .tr-chips, .readout, .phone-only, .tr-opt, .tr-lock-out, .m2-sheet { display: none; }
.tr-chips[hidden] { display: none !important; }

/* ================= shared phone pieces ================= */
@media (max-width: 640px) {
  .phone-only { display: block; }
  .tblx > .scroll { display: none; }
  .tblx > .tcards { display: block; }
  .tcards { margin: 8px 0 12px; }
  .tc-grp { margin: 14px 0 4px; font: 600 .75rem var(--font); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
  .tcard { border: 1px solid var(--line); border-radius: 8px; background: #fff; margin: 0 0 8px; }
  .tcard.is-me { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
  .tc-sum { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 12px; min-height: 48px; list-style: none; cursor: pointer; position: relative; }
  div.tcard > .tc-sum { cursor: default; }
  details.tcard > .tc-sum .tc-h { padding-right: 30px; }
  .tc-sum::-webkit-details-marker { display: none; }
  .tc-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; width: 100%; }
  .tc-t { font: 600 .9375rem var(--font); color: var(--ink); }
  .tc-m { font-size: .8125rem; color: var(--muted); white-space: nowrap; }
  .tc-m small, .tc-v small { font-size: .6875rem; color: var(--muted); font-weight: 500; }
  .tc-s { width: 100%; font-size: .8125rem; color: var(--ink-2); line-height: 1.35; }
  .tc-p { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; margin-top: 2px; }
  .tc-v { display: flex; flex-direction: column; gap: 1px; flex: 1 1 0; min-width: 72px; padding: 5px 8px; border-radius: 6px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
  .tc-val { font-size: .9375rem; font-weight: 600; color: var(--ink); line-height: 1.25; }
  .tc-val b { font-weight: 700; }
  .tc-val .mut { display: block; font-size: .6875rem; font-weight: 500; color: var(--muted); }
  .tc-chev { position: absolute; right: 8px; top: 9px; width: 28px; height: 28px; }
  .tc-chev::before { content: ""; position: absolute; left: 9px; top: 7px; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
  details[open] > .tc-sum .tc-chev::before { transform: rotate(-135deg); top: 11px; }
  .tc-d { margin: 0; padding: 4px 12px 10px; border-top: 1px solid var(--line); }
  .tc-d > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid #f0f0f0; font-size: .875rem; }
  .tc-d > div:last-child { border-bottom: 0; }
  .tc-d dt { color: var(--muted); }
  .tc-d dd { margin: 0; font-weight: 600; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
  .tc-d dd .mut { display: block; font-weight: 500; font-size: .75rem; color: var(--muted); }
  /* capacity heat bands, same colours as the desktop table */
  .tc-v.b0 { background: #cfe0f5; } .tc-v.b1 { background: #f3f3f3; } .tc-v.b2 { background: #fbd9a8; } .tc-v.b3 { background: #f08a5d; }
  .tc-v.bx { background: #fff; border: 1px dashed var(--line); } .tc-v.bx .tc-val { color: var(--muted); font-weight: 500; font-style: italic; }
  .tcards.is-strip .tc-p { flex-wrap: nowrap; gap: 4px; }
  .tcards.is-strip .tc-v { min-width: 0; padding: 4px 2px; align-items: center; text-align: center; }
  .tcards.is-strip .tc-v small { white-space: nowrap; font-size: .625rem; }
  .tcards.is-strip .tc-val { font-size: .8125rem; }
  .tcard .bias-up { color: var(--blue-deep); } .tcard .bias-dn { color: #a8400f; }
  .tc-d .fc-flag { white-space: normal; text-align: left; }

  /* value readout under a chart: a tap shows it, nothing depends on hover */
  .readout { display: block; margin: 6px 0 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-size: .8125rem; line-height: 1.4; color: var(--ink); min-height: 0; }
  .readout:empty { display: none; }
  .readout b { font-weight: 600; }
  .readout .row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
  .readout .row span:first-child { display: inline-flex; align-items: center; gap: 6px; }
  .readout i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
  .readout .sub { color: var(--muted); font-size: .75rem; }
  .readout .mut { color: var(--muted); font-weight: 500; }
  .chart svg { touch-action: pan-y; }

  /* small multiples: one per row, full width */
  .small-multiples, .fp-grid { grid-template-columns: 1fr; gap: 14px; }
  .pf-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .small-multiples .sm, .fp-grid .sm { padding-bottom: 4px; border-bottom: 1px solid var(--line); }
  .sm h4 { font-size: .9375rem; }
}

/* ================= trends: chip row ================= */
@media (max-width: 640px) {
  .tr-chips { display: block; margin: 4px 0 8px; }
  .trc-cap { display: block; font: 600 .6875rem var(--font); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
  .trc-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .trc-row::-webkit-scrollbar { display: none; }
  .trchip { flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid #b5b5b5; border-radius: 22px; background: #fff; color: var(--ink-2); font: 500 .875rem var(--font); cursor: pointer; white-space: nowrap; }
  .trchip i { width: 14px; height: 4px; border-radius: 2px; flex: none; }
  .trchip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
  .trc-all { display: inline-flex; align-items: center; min-height: 44px; padding: 0; border: 0; background: none; color: var(--red); font: 600 .875rem var(--font); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
}

/* ================= campus by grade: one-campus card ================= */
@media (max-width: 640px) and (orientation: portrait) {
  #mx-wrap .mx-desk { display: none; }
  .mx-phone { display: block; margin-top: 4px; }
  .mxp-levels { display: flex; width: 100%; margin-bottom: 10px; }
  .mxp-levels button { flex: 1 1 0; min-height: 44px; font-size: .9375rem; }
  .mxp-lv { margin: 0 0 8px; font-size: .9375rem; color: var(--muted); }
  .mxp-lv b { color: var(--ink); font-weight: 600; }
  .mxp-sort { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
  .mxp-sort select { width: 100%; min-height: 44px; }
  .mxp-chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .mxp-chips::-webkit-scrollbar { display: none; }
  .mxp-chip { flex: none; min-height: 44px; padding: 0 14px; border: 1px solid #b5b5b5; border-radius: 22px; background: #fff; color: var(--ink-2); font: 500 .875rem var(--font); cursor: pointer; white-space: nowrap; }
  .mxp-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
  .mxp-card { border: 1px solid var(--line); border-radius: 10px; background: #fff; touch-action: pan-y; padding: 0 0 12px; }
  .mxp-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 6px 6px 6px 6px; border-bottom: 1px solid var(--line); }
  .mxp-name { text-align: center; min-width: 0; }
  .mxp-name h4 { margin: 0; font: 700 1.125rem var(--font); color: var(--ink); }
  .mxp-name span { font-size: .75rem; color: var(--muted); }
  .mxp-nav { flex: none; width: 48px; height: 48px; border: 0; border-radius: 50%; background: none; color: var(--ink); font-size: 2rem; line-height: 1; cursor: pointer; }
  .mxp-nav:disabled { color: #8a8a8a; opacity: .45; cursor: default; }
  .mxp-card .nodata { margin: 8px 14px 0; font-size: .8125rem; color: var(--muted); }
  .mxp-rows { list-style: none; margin: 0; padding: 4px 6px 0; }
  .mxp-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) 56px 78px; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 0 8px; border: 0; border-radius: 6px; background: none; font: 500 .9375rem var(--font); color: var(--ink); text-align: left; cursor: pointer; }
  .mxp-row.sel { background: var(--red-tint, #fdecee); box-shadow: inset 0 0 0 1.5px var(--red); }
  .mxp-sw { width: 8px; height: 26px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.28); background: #fff; }
  .mxp-n { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
  .mxp-d { text-align: right; font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
  .mxp-d.up { color: var(--blue-deep); } .mxp-d.dn { color: #a8400f; } .mxp-d.m { font-size: .6875rem; white-space: normal; line-height: 1.15; }
  .mxp-total { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 8px; margin: 6px 14px 10px; padding-top: 10px; border-top: 2px solid var(--ink); font-size: .9375rem; color: var(--ink); }
  .mxp-total b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
  .mxp-total .mxp-d { white-space: nowrap; }
  .mxp-focus { display: block; width: calc(100% - 28px); margin: 0 14px; min-height: 44px; }
  .mxp-swipe { margin: 8px 0 0; font-size: .75rem; color: var(--muted); }
  .mxp-hint { display: block; margin: 10px 0 0; font-size: .8125rem; color: var(--muted); }
}
@media (max-width: 640px) and (orientation: landscape) { .mx-phone { display: none; } }

/* ================= forecasts, compare, transfers ================= */
@media (max-width: 640px) {
  .fc-tog { width: 100%; min-height: 44px; margin: 4px 0 2px; padding: 0 12px; border: 1px solid #b5b5b5; border-radius: 8px; background: #fff; color: var(--ink); font: 500 .875rem var(--font); text-align: left; cursor: pointer; }
  .fc-tog[aria-pressed="true"] { background: var(--surface-2); }
  #fc-root:not(.fc-all) .fc-old { display: none; }
  .cmp-scrollhint { display: none !important; }
  .cmp-sortp { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 8px; }
  .cmp-sortp select { width: 100%; min-height: 44px; }
  .cmp-chart { margin: 0 -4px; }
  .flm-x .note { margin-top: 8px; }
  .fl-split .fl-card { min-height: 0; }
}
@media (hover: none) { .chart svg:focus { outline: none; } }

@media (max-width: 640px) {
  #co-table .co-desk { display: none; }
  #co-table .co-cards { display: block; }
  #co-table { overflow: visible; }
  .co-card { display: block; width: 100%; padding: 10px 12px; text-align: left; font: inherit; cursor: pointer; color: inherit; }
  .co-card .tc-p { margin-top: 6px; }
  .co-card .tc-v { min-width: 84px; }
  .co-legend { margin-top: 6px; }
}
.nm-s { display: none; }
@media (max-width: 640px) { .cmp-nm .nm-l { display: none; } .cmp-nm .nm-s { display: inline; } }
@media (max-width: 640px) { .tc-p > .tc-v:only-child { flex: 0 0 auto; min-width: 120px; } }
@media (max-width: 640px) { .co-cell { min-height: 44px; } .fc-tog { min-height: 44px; } }

/* ================= PHONE FIX N2 ================= */
/* shared bottom sheet (charts.js openSheet) */
@media (max-width: 640px) {
  .m2-back { z-index: 3400; }
  .m2-sheet { display: flex; flex-direction: column; position: fixed; left: 0; right: 0; bottom: 0; max-height: 86vh; max-height: 86dvh; z-index: 3500; background: #fff; border-radius: 16px 16px 0 0; box-shadow: 0 -10px 34px rgba(0,0,0,.3); animation: sheetUp .2s ease-out; overflow: hidden; }
  .m2-sheet .sheet-grab { display: block; }
  .m2-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 16px; min-height: 48px; border-bottom: 1px solid var(--line); touch-action: none; }
  .m2-sheet-head strong { font-size: 1.125rem; }
  .m2-sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
  .m2-sheet-body .seg { width: 100%; flex-wrap: nowrap; }
  .m2-sheet-body .seg button { flex: 1 1 0; min-height: 48px; font-size: .9375rem; padding: 0 4px; }
  .m2-sheet-body .field > span { font-size: .75rem; }
  .m2-sheet-body .switches { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; border: 0; padding: 0; margin: 0; }
  .m2-sheet-body .switch { min-height: 48px; font-size: 1rem; }
  .m2-sheet-body .btn { min-height: 48px; width: 100%; }
}
/* trends: takeaway -> chip row -> chart -> readout -> Chart options */
@media (max-width: 640px) {
  #trends { display: flex; flex-direction: column; }
  #trends > .controls { order: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
  #trends > .controls > .field, #trends > .controls > .switches { display: none; }
  #trends > #tr-legend, #trends > #tr-fclink, #trends > #tr-tablewrap { order: 2; }
  .tr-opt { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 1px; flex: 1 1 0; min-width: 0; min-height: 48px; padding: 6px 14px; text-align: left; }
  .tr-opt b { font-size: .9375rem; }
  .tr-opt-s { font-size: .8125rem; color: var(--muted); font-weight: 500; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tr-lock-out { display: block; flex: 1 1 100%; }
  .tr-lock, .tr-lock p { margin: 0; font-size: .8125rem; line-height: 1.4; color: var(--ink-2); }
  .tr-lock { padding: 8px 10px; border-left: 3px solid var(--ink); background: var(--surface-2); border-radius: 0 6px 6px 0; display: flex; flex-direction: column; gap: 4px; }
  .m2-sheet .tr-lock { margin: 0; }
  #tr-chart + .readout { margin-top: 2px; min-height: 3.2em; }
  .tr-chips { margin-top: 6px; }
}

@media (max-width: 640px) and (orientation: portrait) {
  .mxp-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 10px; padding: 6px 6px 6px 12px; min-height: 48px; border-left: 3px solid var(--red); background: var(--red-tint, #fdecee); border-radius: 0 6px 6px 0; font-size: .875rem; }
  .mxp-banner .linkbtn { min-height: 44px; padding: 0 12px; }
  .mxp-row.open { background: var(--surface-2); }
  .mxp-rows > li { list-style: none; }
  .mxp-exp { margin: 2px 4px 8px; padding: 8px 10px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
  .mxp-exp-h { margin: 0 0 2px; font-size: .875rem; color: var(--ink-2); }
  .mxp-spark .readout { margin: 4px 0 6px; }
  .mxp-exp .btn { width: 100%; min-height: 48px; }
  .mxp-on { display: flex; flex-direction: column; gap: 8px; font-size: .8125rem; color: var(--ink-2); }
}

/* transfers: who goes where (phone) */
@media (max-width: 640px) {
  .fl-prompt { margin: 0; font-size: .9375rem; line-height: 1.4; color: var(--ink-2); }
  .fl-div svg rect[tabindex] { -webkit-tap-highlight-color: transparent; }
  .fl-div svg rect[tabindex]:focus { outline: none; }
  .fl-div svg rect[tabindex]:focus-visible { outline: 2px solid #cc0033; outline-offset: -2px; }
  .fl-sheet .fl-card { border: 0; padding: 0; min-height: 0; }
  .fl-sheet .fl-card-h { display: none; }
}

/* forecasts (phone): My school picker, accordion sections, folded sub-blocks */
@media (max-width: 640px) {
  .fc-mine { margin: 0 0 12px; padding: 10px 12px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
  .fc-mine select { width: 100%; min-height: 52px; font-size: 1rem; }
  .fc-mine .note { margin: 6px 0 0; }
  .fc-acc > h2 { max-width: none; display: flex; align-items: center; justify-content: flex-start; gap: 10px; min-height: 52px; cursor: pointer; margin-bottom: 0; }
  .fc-acc > h2::after { content: ""; flex: none; width: 10px; height: 10px; margin: 0 6px 4px auto; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg); transition: transform .15s; order: 9; }
  .fc-acc:not(.fc-collapsed) > h2::after { transform: rotate(-135deg); margin-bottom: -4px; }
  .fc-acc > h2:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
  .fc-acc.fc-collapsed > :not(h2) { display: none !important; }
  .fc-acc { border-bottom: 1px solid var(--line); }
  .fc-fold { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; background: #fff; }
  .fc-fold > summary { display: flex; justify-content: space-between; align-items: center; position: relative; min-height: 52px; padding: 0 44px 0 14px; list-style: none; cursor: pointer; font: 600 1rem var(--font); }
  .fc-fold > summary::-webkit-details-marker { display: none; }
  .fc-fold[open] > summary { border-bottom: 1px solid var(--line); }
  .fc-fold > summary .tc-chev { top: 12px; }
  .fc-fold[open] > summary .tc-chev::before { transform: rotate(-135deg); top: 11px; }
  .fc-fold > :not(summary) { margin-left: 10px; margin-right: 10px; }
  .tcards.is-strip .tc-v small { white-space: normal; text-align: center; line-height: 1.1; font-size: .6875rem; }
}

/* transfers: out-of-district students by campus as a compact two-column list (grades behind a tap) */
@media (max-width: 640px) {
  .oe-cards .tcards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .oe-cards .tcards .tcard { margin: 0; }
  .oe-cards .tc-sum { padding: 8px 34px 8px 10px; min-height: 56px; gap: 0; align-content: center; }
  .oe-cards .tc-h { display: block; }
  .oe-cards .tc-t { font-size: .875rem; display: block; }
  .oe-cards .tc-p { margin-top: 0; }
  .oe-cards .tc-v { background: none; padding: 0; min-width: 0; flex-direction: row; gap: 6px; align-items: baseline; }
  .oe-cards .tc-v small { display: inline; font-size: .75rem; }
  .oe-cards .tc-chev { right: 2px; top: 14px; }
  .oe-cards details[open] { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .fc-leg .phone-only { display: inline; }
  .fc-leg i.snapd { width: 8px; height: 8px; border: 2px solid #000; background: #fff; border-radius: 0; transform: rotate(45deg); margin: 0 8px 1px 3px; box-sizing: content-box; }
  .trc-row { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); }
}
@media (max-width: 640px) {
  .tc-v.b0 small, .tc-v.b1 small, .tc-v.b2 small, .tc-v.b3 small { color: #262626; }
  .tc-m small, .tc-v small, .tc-val .mut, .tc-d dd .mut { font-size: .75rem; }
  .readout .sub, .mxp-name span, .tc-s { font-size: .8125rem; }
  .tcards.is-strip .tc-v small { font-size: .6875rem; }
}

/* ---- tap card (phone): floating, never shifts the page. A dismissible bottom card for charts without a printed value on every mark. ---- */
.tapcard { display: none; }
@media (max-width: 640px) {
  .tapcard { display: block; position: fixed; z-index: 2300; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); max-height: 40vh; max-height: 40dvh; overflow: auto; overscroll-behavior: contain; padding: 10px 44px 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 22px rgba(0,0,0,.28); font-size: .8125rem; line-height: 1.4; color: var(--ink); }
  .tapcard[hidden] { display: none; }
  .tapcard b { font-weight: 600; }
  .tapcard .row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
  .tapcard .row span:first-child { display: inline-flex; align-items: center; gap: 6px; }
  .tapcard i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
  .tapcard .sub { color: var(--muted); font-size: .75rem; }
  .tapcard .mut { color: var(--muted); font-weight: 500; }
  .tapcard-x { position: absolute; top: 2px; right: 2px; width: 44px; height: 44px; display: grid; place-items: center; background: none; border: 0; color: var(--ink); cursor: pointer; }
  .tapcard-x svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
}
/* trends chips: three or fewer series wrap instead of scrolling, so none is cut off */
@media (max-width: 640px) { .trc-row.few { flex-wrap: wrap; overflow: visible; -webkit-mask-image: none; mask-image: none; } }
