/* Cella007FX mobile.css — phones (< 768 px) and landscape phones (SPEC 2.3, 1.2 #14). Owner: WP-6.
   Header 2 lines (64 px), toolbar at the bottom (48 px + safe-area) with a horizontally scrolling TF strip (44 px
   targets), panel as a bottom sheet (#panel.sheet, snap 60 % / 90 %, drag handle #panel-grip), touch-action:none on
   the chart, 100dvh with a 100vh fallback, no horizontal page scroll. Landscape (max-height 500 px): header 1 line,
   status bar hidden. Loaded after app.css, so equal-specificity rules here win. */

@media (max-width: 767px) {
  :root { --hdr-h: 64px; --tb-h: 48px; }

  #app {
    grid-template-rows: var(--hdr-h) var(--legend-h) minmax(0, 1fr) auto var(--status-h) calc(var(--tb-h) + env(safe-area-inset-bottom, 0px));
    grid-template-areas: "hdr" "lg" "stage" "banner" "status" "tb";
    height: 100vh; height: 100dvh;
  }

  /* header: line 1 = brand (grows, so the quote wraps) + right cluster; line 2 = quote (priority) + stats (truncates) */
  #hdr { display: flex; flex-wrap: wrap; align-items: center; align-content: stretch; gap: 0 8px; padding: 0 10px; overflow: hidden; }
  #hdr::after { content: ""; order: 1; flex: 0 0 100%; height: 0; }          /* hard line break after the right cluster */
  #brand { order: 0; flex: 1 1 auto; height: 32px; line-height: 32px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
  #brand-sym { display: none; }
  #hdr-right { order: 0; flex: 0 0 auto; height: 32px; margin-left: 0; gap: 8px; }
  #hdr-quote, #hdr-stats { order: 2; display: block; height: 32px; line-height: 32px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #hdr-quote { flex: 1 1 0; }                                                /* bid / ask first; the tail truncates */
  #hdr-quote > * + * { margin-left: 8px; }
  #hdr-stats { flex: 1 1 auto; max-width: 62%; text-align: right; font-size: 11px; }
  #hdr-stats > * + * { margin-left: 8px; }
  #hdr-quote:empty, #hdr-stats:empty { display: none; }
  #hq-bid { font-size: 18px; }
  /* the per-timeframe arrows carry the signal on a phone; the words and the score would crowd them out */
  .mtf-hdr-bias, .mtf-hdr-score { display: none; }
  #hdr-stats { overflow: visible; }
  .mtf-hdr-tfs { gap: 4px; justify-content: flex-end; }
  .mtf-hdr-tf { font-size: 10px; line-height: 17px; padding: 0 4px; }
  #clock { display: none; }
  #srcpill { height: 20px; padding: 0 7px; font-size: 10px; }

  /* toolbar at the bottom: one horizontally scrolling strip, 44 px targets, safe-area padding */
  #toolbar {
    flex-wrap: nowrap; gap: 6px; padding: 2px 6px calc(2px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); border-bottom: 0;
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; overscroll-behavior-x: contain;
  }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar > div { flex: 0 0 auto; gap: 2px; }
  #toolbar > div + div { padding-left: 6px; }
  #tb-right { margin-left: 0; }
  #toolbar .btn { min-height: 44px; min-width: 44px; padding: 4px 8px; font-size: 13px; border-radius: 8px; }
  #tf-strip { gap: 2px; }
  #tf-strip .btn { min-width: 44px; padding: 4px 4px; }
  #tb-type select { min-height: 40px; padding: 2px 4px; }

  /* legend: single line, ellipsis */
  #legend { gap: 8px; padding: 0 8px; font-size: 11px; }

  /* stage: chart only; touch is owned by the chart (no page scroll / zoom) */
  #stage { grid-template-columns: minmax(0, 1fr); }
  #chart-wrap { touch-action: none; }
  #countdown { font-size: 10px; }

  /* panel: bottom sheet (snap 60 % / 90 %; ui/panel.js drives translateY during the drag and .open / .full after it) */
  #panel-grip {
    display: block; flex: 0 0 auto; height: 22px; position: relative; touch-action: none; cursor: grab;
  }
  #panel-grip::before {
    content: ""; position: absolute; left: 50%; top: 8px; width: 42px; height: 5px; margin-left: -21px; border-radius: 3px; background: var(--text-2);
  }
  #panel.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: 60vh; height: 60dvh; max-height: 90dvh;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(100%); transition: transform .24s ease, height .18s ease; visibility: hidden;
  }
  #panel.sheet.open { transform: none; visibility: visible; }
  #panel.sheet.full { height: 90vh; height: 90dvh; }
  #panel.sheet.dragging { transition: none; }
  #panel.sheet > section { padding: 8px 10px 14px; }
  #panel-tabs .tab { min-height: 40px; }

  /* overlays: keep toasts above the bottom toolbar; modals fill the width */
  #toast-root { right: 8px; left: 8px; width: auto; bottom: calc(var(--tb-h) + var(--status-h) + 10px + env(safe-area-inset-bottom, 0px)); }
  #modal-root { padding: 10px; align-items: flex-end; }
  .modal { width: 100%; max-height: min(88vh, 88dvh); margin-bottom: env(safe-area-inset-bottom, 0px); }
  #help { padding: 10px; align-items: flex-end; }
  .help-card { width: 100%; max-height: min(85vh, 85dvh); }
  .help-grid { grid-template-columns: 1fr; }

  /* forms: bigger targets */
  .field input, .field select { min-height: 36px; font-size: 14px; }
  .field input[type="checkbox"] { width: 20px; height: 20px; }
  .grid2 { grid-template-columns: 1fr 1fr; }

  /* banner / status: keep to one line */
  #banner { padding: 3px 10px; font-size: 11px; }
  #statusbar { padding: 0 8px; font-size: 10px; }
  #statusbar .sb-debug { display: none; }
}

/* landscape phones: 1-line header, status bar hidden, tighter legend */
@media (max-width: 767px) and (max-height: 500px) {
  :root { --hdr-h: 40px; --status-h: 0px; --legend-h: 18px; }
  #hdr { flex-wrap: nowrap; gap: 0 10px; }
  #hdr::after { display: none; }
  #brand { flex: 0 0 auto; height: 40px; line-height: 40px; }
  #hdr-quote { flex: 1 1 auto; height: 40px; line-height: 40px; }
  #hdr-stats { display: none; }
  #hdr-right { flex: 0 0 auto; height: 40px; }
  #hq-bid { font-size: 16px; }
  #statusbar { display: none; }
  #toast-root { bottom: calc(var(--tb-h) + 10px + env(safe-area-inset-bottom, 0px)); }
  #panel.sheet { height: 90vh; height: 90dvh; }
}

/* very narrow (<= 360 px): hide the tool group labels' padding so nothing forces page overflow */
@media (max-width: 360px) {
  #hdr { padding: 0 8px; }
  #hdr-quote { gap: 6px; }
  #hq-bid { font-size: 16px; }
  #toolbar > div + div { padding-left: 4px; }
}
