/* Phone Physical view (static/phone-physical.js). Phones only: at 600px and below it
   replaces the NEM tab's Overview. Geometry inside .pp-map is a design frame 402 wide and as
   tall as the screen allows (the script sets its aspect ratio), scaled to the phone width, so
   type in the boxes and chips scales with vw between sensible floors and ceilings. */
.pp { display: none; }
.pp-sheet[hidden] { display: none; }

@media (max-width: 600px) {
  /* Only the Overview sub-tab becomes Physical: a deep link to Event Feed or Asset
     Intelligence still lands on that screen, with its sub-tab bar. */
  #tab-nem:has(> #sub-overview.active) > :not(.pp) { display: none !important; }
  #tab-nem:has(> #sub-overview.active) > .pp { display: block; }
  /* The help/desk bubble covers the cards; on phones the desk lives on one screen only. */
  body[data-mobile-tab="nem"]:has(#sub-overview.active) .contact-desk-fab { display: none; }

  .pp { --pp-gutter: max(16px, env(safe-area-inset-left, 0px)); min-width: 0; color: var(--text); }
  .pp-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
  .pp-k { font-size: 11px; color: var(--text-muted); }
  .pp-k-lg { font-size: 13px; }
  .pp-eyebrow { margin: 0; font: 600 12px/1.3 var(--font-sans); letter-spacing: var(--track-normal); color: var(--text-muted); }
  .pp-dot { display: inline-block; flex: none; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
  .pp-up { color: var(--positive); }
  .pp-down { color: var(--negative); }
  .pp-flat { color: var(--text-muted); }

  /* Map: full bleed under the top bar. */
  .pp-map {
    position: relative;
    margin: -12px calc(-1 * var(--pp-gutter)) 0;
    aspect-ratio: 402 / 520;
    overflow: hidden;
  }
  .pp-map-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
  .pp-state { fill: var(--surface-elevated); stroke: #3E6E74; stroke-width: 1; stroke-linejoin: round; transition: fill .4s ease; }
  .pp-state { cursor: pointer; }
  .pp-map-svg { pointer-events: none; }
  .pp-map-svg .pp-state { pointer-events: auto; }
  /* Interconnectors: line coloured by % of limit (currentColor), white dots moving towards the
     importer at one speed, a glow at the limit, dim and dashed when idle. */
  .pp-ic path { fill: none; stroke-linecap: round; }
  .pp-ic-halo { stroke: var(--bg-primary); stroke-opacity: 0.75; stroke-width: 7; }
  .pp-ic-glow { stroke: currentColor; stroke-opacity: 0.3; stroke-width: 9; }
  .pp-ic-line { stroke: currentColor; stroke-width: 3; }
  .pp-ic-flow { stroke: #fff; stroke-opacity: 0.9; stroke-width: 1.5; stroke-dasharray: 0.5 8.5; animation: pp-ic-flow 1.5s linear infinite; }
  @keyframes pp-ic-flow { to { stroke-dashoffset: -9; } }
  .pp-ic-head { fill: currentColor; }
  .pp-ic--idle .pp-ic-line { stroke-opacity: 0.7; stroke-dasharray: 2 4; stroke-width: 2; }
  @media (prefers-reduced-motion: reduce) { .pp-ic-flow { animation: none; } }

  /* As wide as its figures need (it sits over empty sea): "22,800 MW" must not wrap on a small phone. */
  .pp-nem { position: absolute; left: 4%; top: 2.7%; width: max-content; max-width: 46%; display: flex; flex-direction: column; gap: 8px; }
  .pp-nem-row .pp-small { white-space: nowrap; }
  .pp-nem .pp-eyebrow { font-size: 11px; letter-spacing: var(--track-wide); }
  .pp-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .pp-nem-avg { font-size: clamp(18px, 5.5vw, 22px); font-weight: 600; line-height: 1.1; letter-spacing: var(--track-display); }
  .pp-nem-row { display: flex; gap: 14px; }
  .pp-small { font-size: 13px; font-weight: 500; }
  .pp-hint { font-size: 11px; line-height: 1.35; color: var(--text-muted); }
  .pp-legend { position: absolute; left: 4%; top: 86.9%; width: 28%; display: flex; flex-direction: column; gap: 5px; }
  .pp-legend .pp-k { font-weight: 600; white-space: nowrap; }
  .pp-legend .pp-legend-sub { margin-top: -4px; font-weight: 400; font-size: 10px; }
  .pp-legend-bar { height: 6px; border-radius: 3px; background: linear-gradient(90deg, #3FB950 0%, #FFAA00 60%, #FF4444 100%); }
  .pp-legend-ends { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-muted); }

  .pp .pp-box, .pp .pp-chip {
    position: absolute;
    box-sizing: border-box;
    margin: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    color: var(--text);
    font-family: var(--font-sans);
    text-align: left;
    cursor: pointer;
    touch-action: manipulation;
  }
  .pp .pp-box {
    justify-content: space-between;
    padding: 6px 7px;
    border-radius: 10px;
    border: 1px solid var(--border-strong);
    background: color-mix(in srgb, var(--bg-primary) 90%, transparent);
    box-shadow: var(--shadow-card);
  }
  .pp .pp-box--open, .pp .pp-box:focus-visible { border-color: var(--accent); }
  .pp-box-head { display: flex; justify-content: space-between; align-items: center; width: 100%; gap: 4px; }
  .pp-box-code { display: flex; align-items: center; gap: 5px; font-size: clamp(11px, 2.736vw, 12px); font-weight: 700; letter-spacing: var(--track-normal); }
  .pp-box-chg { font-family: var(--font-mono); font-size: clamp(9px, 2.612vw, 11.5px); white-space: nowrap; }
  .pp-box-price { font-family: var(--font-mono); font-size: clamp(15px, 4.726vw, 20.8px); font-weight: 600; line-height: 1; letter-spacing: var(--track-display); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .pp-box-sub { font-size: clamp(9.5px, 2.488vw, 10.95px); letter-spacing: -0.01em; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  /* A link label: the frame is the tap target; the pill inside it is what shows. */
  .pp .pp-chip { align-items: center; justify-content: center; padding: 0; border: 0; background: none; }
  .pp .pp-chip--end { align-items: flex-end; }
  .pp .pp-chip--start { align-items: flex-start; }
  .pp-chip-pill { display: flex; flex-direction: column; gap: 3px; padding: 4px 7px 5px; border-radius: 7px; border: 1px solid var(--border-light); background: color-mix(in srgb, var(--bg-primary) 88%, transparent); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28); }
  .pp .pp-chip:focus-visible .pp-chip-pill { border-color: var(--accent); }
  .pp-chip-row { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
  .pp-chip-name { font-size: clamp(9.5px, 2.5vw, 11px); font-weight: 600; letter-spacing: 0.01em; color: var(--text-muted); }
  .pp-chip-val { font-size: clamp(10.5px, 2.86vw, 12.5px); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
  .pp-chip-row2 { display: flex; align-items: center; gap: 5px; }
  .pp-chip-lim { display: none; font-size: 7.5px; font-weight: 800; line-height: 1; letter-spacing: 0.08em; color: #ff6b6b; }
  .pp-chip-bar { flex: 1; height: 2px; border-radius: 1px; background: color-mix(in srgb, var(--text) 14%, transparent); overflow: hidden; }
  .pp-chip-bar i { display: block; height: 100%; border-radius: inherit; }
  .pp-chip--limit .pp-chip-pill { border-color: #ff4444; box-shadow: 0 0 0 1px rgba(255, 68, 68, 0.3), 0 0 14px rgba(255, 68, 68, 0.35); }
  .pp-chip--limit .pp-chip-lim { display: inline; }
  .pp-chip--idle .pp-chip-pill { opacity: 0.7; }

  /* Region picker sticks under the fixed top bar. */
  .pp-regions {
    position: sticky;
    top: calc(var(--top-bar-h) + env(safe-area-inset-top, 0px));
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    margin: 0 calc(-1 * var(--pp-gutter));
    padding: 10px var(--pp-gutter);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
  }
  .pp .pp-region {
    height: 40px;
    min-width: 0;
    padding: 0;
    border-radius: 20px;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text);
    font: 600 13px/1 var(--font-sans);
  }
  .pp .pp-region[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-muted); color: var(--accent); }

  .pp-card { margin-top: 12px; padding: 16px; border-radius: 14px; background: var(--bg-card); border: 1px solid var(--border); }
  .pp-card[hidden] { display: none; }
  .pp-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
  .pp-card-head .pp-k { font-size: 12px; }
  .pp-today-nums { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 12px; }
  .pp-stat-r { align-items: flex-end; text-align: right; gap: 4px; }
  .pp-stat-r.pp-mono { font-size: 13px; }
  .pp-hero { font-size: clamp(32px, 10vw, 40px); font-weight: 600; line-height: 1; letter-spacing: -0.03em; }
  .pp-big { font-size: 28px; font-weight: 600; line-height: 1; letter-spacing: var(--track-display); }
  .pp-mid { font-size: 18px; font-weight: 600; }
  .pp-empty { margin: 14px 0 4px; font-size: 13px; color: var(--text-muted); }
  .pp-foot { margin: 10px 0 0; font-size: 11px; line-height: 1.45; color: var(--text-muted); }

  /* Price charts: full card width, prices on the right, a finger slides along to read any time
     (touch-action keeps vertical scrolling on the page). */
  .pp-chart-wrap { position: relative; margin: 12px -4px 0; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
  .pp-chart { display: block; width: 100%; height: auto; overflow: visible; }
  .pp-grid { stroke: var(--border-subtle); stroke-width: 1; stroke-opacity: 0.5; }
  .pp-grid-zero { stroke: var(--border-light); stroke-dasharray: none; }
  .pp-axis { font-family: var(--font-mono); font-size: 10px; fill: var(--text-dim); }
  /* A card-coloured outline keeps the peak price off the line it labels. */
  .pp-peak-label { font-weight: 600; paint-order: stroke; stroke: var(--bg-card); stroke-width: 4px; stroke-linejoin: round; }
  .pp-line-actual { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
  .pp-line-forecast { fill: none; stroke-width: 2; stroke-dasharray: 1 4.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.95; }
  .pp-now { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 2 3; }
  .pp-now-dot { stroke: var(--bg-card); stroke-width: 2; }
  .pp-now-t { fill: var(--text-muted); paint-order: stroke; stroke: var(--bg-card); stroke-width: 4px; stroke-linejoin: round; }
  .pp-pulse { transform-box: fill-box; transform-origin: center; opacity: 0.5; animation: pp-pulse 2.2s ease-out infinite; }
  @keyframes pp-pulse { from { transform: scale(1); opacity: 0.55; } to { transform: scale(3.2); opacity: 0; } }
  .pp-logzone { fill: var(--text-primary, #fff); fill-opacity: 0.03; }
  .pp-logzone-t { font-size: 8.5px; letter-spacing: 0.08em; fill: var(--text-dim); }
  .pp-spike-glow line { stroke-width: 10; stroke-linecap: butt; stroke-opacity: 0.7; }
  .pp-spike-glow--run line { stroke-width: 6; stroke-opacity: 0.3; }
  .pp-line-halo { fill: none; stroke: var(--bg-card); stroke-width: 5; stroke-linejoin: round; stroke-linecap: round; }
  .pp-spike rect { fill: color-mix(in srgb, currentColor 22%, var(--bg-card)); stroke: currentColor; stroke-opacity: 0.9; }
  .pp-spike text { font-family: var(--font-mono); fill: currentColor; }
  .pp-spike-v { font-size: 12px; font-weight: 700; }
  .pp-spike-t { font-size: 10px; font-weight: 500; fill-opacity: 0.7; }
  .pp-scrub-line { stroke: var(--text-muted); stroke-width: 1; }
  .pp-scrub-dot { stroke: var(--bg-card); stroke-width: 2.5; }
  /* While a finger reads the chart, the card's big number shows the price under it. */
  .pp-scrubbing .pp-peak-label { opacity: 0.25; }
  [data-pp-hero] { transition: color 0.12s ease; }
  .pp-card--scrub [data-pp-hero-k] { color: var(--text); font-variant-numeric: tabular-nums; }
  .pp-legend-row { display: flex; align-items: center; gap: 16px; margin-top: 6px; font-size: 11px; color: var(--text-muted); }
  .pp-legend-row > span { display: flex; align-items: center; gap: 6px; }
  .pp-legend-hint { margin-left: auto; color: var(--text-dim); }
  .pp-swatch { display: inline-block; width: 18px; }
  .pp-swatch-actual { height: 2.5px; border-radius: 2px; background: linear-gradient(90deg, var(--price-cool), var(--accent) 35%, var(--price-warm) 70%, var(--price-hot)); }
  .pp-swatch-forecast { height: 0; border-top: 2.5px dotted var(--accent); }

  .pp-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
  .pp-tile { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 10px; background: var(--surface-tint-1); min-width: 0; }
  .pp-tile-v { font-size: 17px; font-weight: 600; }
  .pp-tile-v .pp-k { font-weight: 400; font-size: 12px; }

  .pp-cells { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
  .pp-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0; border-radius: 8px; }
  .pp-cell-t { font-size: 11px; color: var(--text-muted); }
  .pp-cell-v { font-size: 15px; font-weight: 600; }
  .pp-t-cool { background: color-mix(in srgb, var(--price-cool) 16%, transparent); }
  .pp-t-neutral, .pp-t-none { background: var(--surface-tint-1); }
  .pp-t-warm { background: color-mix(in srgb, var(--price-warm) 15%, transparent); }
  .pp-t-hot { background: color-mix(in srgb, var(--price-hot) 18%, transparent); }
  .pp-t-critical { background: color-mix(in srgb, var(--price-critical) 22%, transparent); }


  .pp-pasa-list { list-style: none; margin: 10px 0 0; padding: 0; }
  .pp-pasa-row { display: flex; align-items: center; gap: 10px; min-height: 44px; border-top: 1px solid var(--border-subtle); }
  .pp-pasa-day { width: 58px; flex: none; font-size: 13px; font-weight: 600; }
  .pp-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
  .pp-pill-ok { color: var(--positive); background: color-mix(in srgb, var(--positive) 13%, transparent); }
  .pp-pill-warn { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
  .pp-pill .pp-dot { width: 6px; height: 6px; }
  .pp-pasa-spare { margin-left: auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }

  .pp-source { margin: 14px 0 8px; font-size: 11px; color: var(--text-dim); }
  /* Generator trips */
  .pp-trip-list { list-style: none; margin: 10px 0 0; padding: 0; }
  .pp-trip { display: grid; grid-template-columns: 68px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 10px 0; border-top: 1px solid var(--border-subtle); }
  .pp-trip-t { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
  .pp-trip-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .pp-trip-name { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pp-trip-mw { font-size: 14px; font-weight: 600; color: var(--negative); white-space: nowrap; }
  .pp-more { width: 100%; min-height: 44px; margin-top: 4px; border: 0; border-top: 1px solid var(--border-subtle); background: transparent; color: var(--accent); font: 600 14px/1 var(--font-sans); cursor: pointer; }

  /* Detail sheet: slides over everything, bottom nav included. */
  body.pp-sheet-open { overflow: hidden; }
  .pp-sheet { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; flex-direction: column; justify-content: flex-end; }
  .pp-sheet-scrim { flex: 1 1 auto; border: 0; padding: 0; background: var(--scrim); backdrop-filter: blur(var(--scrim-blur)); cursor: pointer; }
  .pp-sheet-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 86dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 16px max(24px, calc(env(safe-area-inset-bottom, 0px) + 12px));
    border-radius: 18px 18px 0 0;
    background: var(--surface-elevated);
    box-shadow: var(--shadow-overlay);
    color: var(--text);
    animation: pp-rise .22s ease-out;
  }
  @keyframes pp-rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
  .pp-grabber { align-self: center; width: 36px; height: 5px; border-radius: 3px; background: var(--border-strong); }
  .pp-sheet-head { display: flex; align-items: center; gap: 10px; }
  .pp-sheet-head h2 { margin: 0; font: 600 20px/1.2 var(--font-sans); }
  .pp-dot-lg { width: 10px; height: 10px; }
  .pp-close {
    margin-left: auto;
    width: 44px;
    height: 44px;
    border-radius: 22px;
    border: 0;
    background: var(--surface-tint-2);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .pp-close .icon { width: 18px; height: 18px; }
  .pp-sheet-price { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
  .pp-sheet-big { font-size: 44px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
  .pp-sheet-panel .pp-pair { margin-top: 0; }
  .pp-sheet-panel .pp-tile { background: var(--surface-tint-2); }
  .pp-sheet-links { display: flex; flex-direction: column; }
  .pp-sheet-links .pp-eyebrow { margin-bottom: 4px; }
  .pp-link { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-top: 1px solid var(--border-light); }
  .pp-link-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
  .pp-bar { height: 6px; border-radius: 3px; background: var(--surface-tint-2); overflow: hidden; }
  .pp-bar > span { display: block; height: 100%; border-radius: 3px; }
  .pp-primary {
    min-height: 48px;
    border-radius: 12px;
    border: 0;
    background: var(--cta);
    color: #04191B;
    font: 600 15px/1 var(--font-sans);
    cursor: pointer;
  }
  .pp-primary:focus-visible, .pp-close:focus-visible, .pp .pp-region:focus-visible { outline: none; box-shadow: var(--focus-ring); }
}

@media (prefers-reduced-motion: reduce) {
  .pp-pulse { animation: none; opacity: 0; }
  .pp-sheet-panel { animation: none; }
  .pp-state { transition: none; }
}
