/* ============================================
   SOHA Flow — SPY session map
   candles → NOW → implied cone + flow-tilted path
   ============================================ */

.page--flow {
  grid-template-columns: 1fr;
  /* fill the window, but never squeeze the chart below 380px — short screens scroll instead */
  grid-template-rows: auto minmax(380px, 1fr) 190px auto;
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--color-bg);
}

/* Tablets (touch, wider than a phone — iPad landscape, iPad Pro portrait): scroll like the phone
   layout with the header pinned, instead of the fixed-height desktop grid that couldn't scroll. */
@media (min-width: 901px) and (pointer: coarse) {
  .page--flow.page--active { display: flex; flex-direction: column; -webkit-overflow-scrolling: touch; }
  .page--flow > .flow-head { position: sticky; top: 0; z-index: 6; flex: none; box-shadow: 0 6px 12px -10px rgba(45,38,64,0.25); }
  .page--flow > .flow-stage { flex: none; height: clamp(420px, 62svh, 720px); }
  .page--flow > .flow-tape { flex: none; height: 190px; }
  .page--flow > .flow-foot { flex: none; }
  .page--flow::after { content: ''; display: block; flex: none; height: calc(env(safe-area-inset-bottom, 0px) + 32px); }
  /* price on the left, toggles on the right, chips on their own full-width row below — squeezed between
     the two, the chips wrapped into ~6 rows and the pinned header ate a third of the screen */
  .page--flow > .flow-head { row-gap: var(--space-2); }
  .page--flow .flow-head__chips { order: 3; flex: 1 1 100%; }
}

/* ── header strip ── */
.flow-head {
  display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
}
.flow-head__id { display: flex; align-items: baseline; gap: var(--space-3); min-width: 0; }
.flow-head__ticker { font-weight: 700; letter-spacing: 0.08em; font-size: var(--text-sm); color: var(--color-text-muted); }
.flow-head__price { font-family: var(--font-mono); font-size: 1.55rem; font-weight: 600; color: var(--color-text); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.flow-head__chg { font-family: var(--font-mono); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.flow-head__chg.is-up { color: var(--color-up); } .flow-head__chg.is-down { color: var(--color-down); }
.flow-head__status { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-faint); letter-spacing: 0.08em; text-transform: uppercase; }
.flow-head__status i { width: 7px; height: 7px; border-radius: 50%; background: var(--color-text-faint); }
.flow-head__status.is-live i { background: var(--color-up); box-shadow: 0 0 0 3px var(--color-up-dim); animation: flowPulse 1.6s ease-in-out infinite; }
.flow-head__status.is-pre i { background: var(--color-warning); }
@keyframes flowPulse { 0%,100% { box-shadow: 0 0 0 2px var(--color-up-dim); } 50% { box-shadow: 0 0 0 5px rgba(76,175,80,0.08); } }

.flow-head__chips { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; flex: 1; }
.flow-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: var(--radius-full);
  background: var(--color-surface-2); border: 1px solid var(--color-border-subtle);
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--color-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.flow-chip strong { color: var(--color-text); font-weight: 600; font-size: 0.82rem; }
.flow-chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--color-text-faint); flex-shrink: 0; }
.flow-chip.is-up i { background: var(--color-up); } .flow-chip.is-down i { background: var(--color-down); }
.flow-chip svg { display: block; }
.flow-chip__g { text-transform: none; font-style: normal; }
.flow-gauge { position: relative; width: 52px; height: 6px; border-radius: 3px; background: var(--color-surface-3); overflow: visible; }
.flow-gauge::before { content: ''; position: absolute; left: 50%; top: -2px; width: 1px; height: 10px; background: var(--color-border); }
.flow-gauge__fill { position: absolute; top: 0; height: 100%; border-radius: 3px; background: var(--color-text-faint); }
.flow-gauge__fill.is-up { background: var(--color-up); } .flow-gauge__fill.is-down { background: var(--color-down); }

.flow-head__controls { display: flex; align-items: center; gap: var(--space-3); margin-left: auto; }
.flow-pills { display: inline-flex; padding: 2px; border-radius: var(--radius-full); background: var(--color-surface-2); border: 1px solid var(--color-border-subtle); }
.flow-pills button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-family: var(--font-mono); font-size: var(--text-2xs); letter-spacing: 0.08em;
  color: var(--color-text-faint); transition: color var(--transition), background var(--transition);
}
.flow-pills button:hover { color: var(--color-text-muted); }
.flow-pills button.is-on { background: var(--color-primary-dim); color: var(--color-primary); }

/* ── stage ── */
.flow-stage { position: relative; min-height: 0; overflow: hidden; }
.flow-stage canvas, .flow-tape canvas { display: block; width: 100%; height: 100%; }
.flow-legend {
  position: absolute; left: var(--space-4); right: var(--space-4); bottom: 8px;
  /* one line at every width — wrapping pushed the legend up onto the time-axis labels; the tail
     (walls/flip/magnet) fades out on narrow screens, and those levels are labelled on the price axis */
  display: flex; gap: var(--space-3); flex-wrap: nowrap; white-space: nowrap; overflow: hidden; pointer-events: none;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 48px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 48px), transparent);
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em; color: var(--color-text-faint);
}
.flow-legend span { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.flow-legend svg { display: block; flex: none; }
.flow-tooltip {
  position: absolute; top: var(--space-3); left: 50%; transform: translateX(-50%);
  padding: 6px 10px; border-radius: var(--radius-md);
  background: var(--glass); border: 1px solid var(--glass-border); backdrop-filter: blur(8px);
  font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted);
  pointer-events: none; white-space: nowrap; letter-spacing: 0.03em; font-variant-numeric: tabular-nums;
}
.flow-tooltip strong { color: var(--color-text); font-weight: 500; }
.flow-tooltip[hidden] { display: none; }
.flow-empty[hidden] { display: none; }
.flow-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-faint); letter-spacing: 0.08em; text-transform: uppercase;
}

/* ── flow tape ── */
.flow-tape { position: relative; border-top: 1px solid var(--color-border-subtle); background: var(--color-surface); }
.flow-tape__label:empty { display: none; }
.flow-tape__label {
  position: absolute; left: var(--space-4); top: 6px; pointer-events: none;
  font-family: var(--font-mono); font-size: var(--text-2xs); letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-text-faint);
}
.flow-tape__label strong { color: var(--color-text-muted); font-weight: 500; }

/* ── footer ── */
.flow-foot {
  display: flex; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap;
  padding: 6px var(--space-5);
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.03em; color: var(--color-text-faint);
  border-top: 1px solid var(--color-border-subtle); background: var(--color-surface);
}

@media (max-width: 900px) {
  /* phone: the page scrolls, so the chart and tape get real height instead of being squeezed */
  .page--flow { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto clamp(360px, 60svh, 560px) 176px auto; overflow-y: auto; -webkit-overflow-scrolling: touch; align-content: start; }
  .flow-head { gap: 10px; padding: 12px 16px 10px; min-width: 0; }
  .flow-head > * { min-width: 0; }
  .flow-head__id { width: 100%; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
  .flow-head__ticker { font-size: 0.72rem; }
  .flow-head__price { font-size: 1.6rem; }
  .flow-head__chg { font-size: 0.78rem; }
  .flow-head__status { margin-left: auto; font-size: 0.62rem; letter-spacing: 0.06em; }
  /* chips: one calm row that scrolls sideways instead of wrapping into a pile */
  .flow-head__chips {
    flex: none; width: 100%; max-width: 100%;
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent 100%);
            mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent 100%);
  }
  .flow-head__chips::-webkit-scrollbar { display: none; }
  .flow-chip { padding: 5px 10px; font-size: 0.66rem; gap: 6px; scroll-snap-align: start; flex-shrink: 0; }
  .flow-chip strong { font-size: 0.74rem; }
  .flow-head__controls { margin-left: 0; width: 100%; justify-content: space-between; }
  .flow-pills button { padding: 4px 10px; font-size: 0.64rem; }
  .flow-legend { display: none; }
  .flow-foot { display: none; }
  /* A plain column (not grid) so the header can stay pinned while the chart and tape scroll under it —
     a sticky grid item can't move outside its own row, which left the price/LIVE line half-cut under the nav. */
  .page--flow.page--active { display: flex; flex-direction: column; }
  .page--flow > .flow-head { position: sticky; top: 0; z-index: 6; flex: none; box-shadow: 0 6px 12px -10px rgba(45,38,64,0.25); }
  .page--flow > .flow-stage { flex: none; height: clamp(360px, 60svh, 560px); }
  .page--flow > .flow-tape { flex: none; height: 176px; }
  /* iOS Safari's floating toolbar sits over the bottom of the page: leave room so the
     net-premium readout can scroll clear of it (home-indicator inset + toolbar). */
  .page--flow::after { content: ''; display: block; flex: none; height: calc(env(safe-area-inset-bottom, 0px) + 88px); }
  /* hover/touch tooltip wraps instead of running off a narrow screen */
  .flow-tooltip { white-space: normal; max-width: calc(100% - 16px); line-height: 1.5; }
}

