/* Page grids. 12-column hairline grid (1px gaps over var(--rule) background). Fixed panels by area class, mini-chart panels (.a-ser) auto-flow. */
.grid { grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: minmax(0, auto); align-content: start; }
.grid > .pnl { grid-column: span 12; }
.grid > .a-ser { grid-column: span 4; }

/* DESK: fills the viewport on desktop */
.pg-desk { grid-template-rows: 312px minmax(240px, 1fr) 288px; height: 100%; min-height: 860px; align-content: stretch; }
.pg-desk > .a-chart { grid-column: 1 / 10; grid-row: 1 / 3; }
.pg-desk > .a-hcp { grid-column: 10 / 13; grid-row: 1; }
.pg-desk > .a-lv { grid-column: 10 / 13; grid-row: 2; }
.pg-desk > .a-tv { grid-column: 1 / 4; grid-row: 3; }
.pg-desk > .a-news { grid-column: 4 / 10; grid-row: 3; }
.pg-desk > .a-health { grid-column: 10 / 13; grid-row: 3; }

/* CYCLE */
.pg-cycle > .a-hcp { grid-column: 1 / 5; grid-row: span 2; }
.pg-cycle > .a-clock { grid-column: 5 / 13; }
.pg-cycle > .a-bottom { grid-column: 5 / 13; }
.pg-cycle > .a-pl { grid-column: 1 / 5; }
.pg-cycle > .a-inputs { grid-column: 5 / 13; }

/* LEVELS */
.pg-levels > .a-lv { grid-column: 1 / 6; grid-row: span 2; }
.pg-levels > .a-pl { grid-column: 6 / 13; }
.pg-levels > .a-clock { grid-column: 6 / 13; }

/* MACRO, DERIVS, BREADTH, WIRE */
.pg-macro > .a-macro { grid-column: 1 / 5; }
.pg-macro > .a-eco { grid-column: 5 / 13; }
.pg-breadth > .a-sent { grid-column: span 4; }
.pg-wire > .a-tv { grid-column: 1 / 8; }
.pg-wire > .a-news { grid-column: 8 / 13; grid-row: span 2; }
.pg-wire > .a-eco { grid-column: 1 / 8; }
.pg-wire { grid-template-rows: auto 1fr; min-height: 100%; }

.pg-help > .a-help { grid-column: 1 / -1; }

/* Desk panels scroll inside their cells */
.pg-desk > .pnl { min-height: 0; }
.pg-desk .a-chart .chart-box { min-height: 0; }

/* Laptop / tablet */
@media (max-width: 1279px) and (min-width: 761px) {
  .grid > .a-ser { grid-column: span 6; }
  .pg-desk { grid-template-rows: 460px auto auto; height: auto; min-height: 0; }
  .pg-desk > .a-chart { grid-column: 1 / 13; grid-row: 1; }
  .pg-desk > .a-hcp { grid-column: 1 / 7; grid-row: 2; }
  .pg-desk > .a-lv { grid-column: 7 / 13; grid-row: 2; }
  .pg-desk > .a-tv { grid-column: 1 / 7; grid-row: 3; }
  .pg-desk > .a-news { grid-column: 7 / 13; grid-row: 3; max-height: 360px; }
  .pg-desk > .a-health { grid-column: 1 / 13; grid-row: 4; }
  .pg-cycle > .a-hcp, .pg-cycle > .a-pl, .pg-levels > .a-lv, .pg-macro > .a-macro { grid-column: 1 / 7; grid-row: auto; }
  .pg-cycle > .a-clock, .pg-cycle > .a-bottom, .pg-cycle > .a-inputs, .pg-levels > .a-pl, .pg-levels > .a-clock, .pg-macro > .a-eco { grid-column: 1 / 13; }
  .pg-breadth > .a-sent { grid-column: span 6; }
  .pg-wire > .a-tv, .pg-wire > .a-eco, .pg-wire > .a-news { grid-column: 1 / 13; grid-row: auto; }
}

/* Big monitors: denser */
@media (min-width: 1920px) {
  .grid > .a-ser { grid-column: span 3; }
  .pg-desk { grid-template-rows: 340px minmax(260px, 1fr) 320px; }
  .pg-desk > .a-chart { grid-column: 1 / 10; }
}
@media (min-width: 2560px) {
  .grid { grid-template-columns: repeat(24, minmax(0, 1fr)); }
  .grid > .pnl { grid-column: span 24; }
  .grid > .a-ser { grid-column: span 4; }
  .pg-desk { grid-template-rows: 380px minmax(320px, 1fr) 380px; }
  .pg-desk > .a-chart { grid-column: 1 / 19; grid-row: 1 / 3; }
  .pg-desk > .a-hcp { grid-column: 19 / 25; grid-row: 1; }
  .pg-desk > .a-lv { grid-column: 19 / 25; grid-row: 2; }
  .pg-desk > .a-tv { grid-column: 1 / 7; grid-row: 3; }
  .pg-desk > .a-news { grid-column: 7 / 19; grid-row: 3; }
  .pg-desk > .a-health { grid-column: 19 / 25; grid-row: 3; }
  .pg-cycle > .a-hcp, .pg-cycle > .a-pl { grid-column: 1 / 7; }
  .pg-cycle > .a-clock, .pg-cycle > .a-bottom { grid-column: 7 / 25; }
  .pg-cycle > .a-inputs { grid-column: 7 / 25; }
  .pg-levels > .a-lv { grid-column: 1 / 9; }
  .pg-levels > .a-pl, .pg-levels > .a-clock { grid-column: 9 / 25; }
  .pg-macro > .a-macro { grid-column: 1 / 7; }
  .pg-macro > .a-eco { grid-column: 7 / 25; }
  .pg-breadth > .a-sent { grid-column: span 8; }
  .pg-wire > .a-tv, .pg-wire > .a-eco { grid-column: 1 / 15; }
  .pg-wire > .a-news { grid-column: 15 / 25; }
  .pg-help > .a-help { grid-column: 1 / -1; }
}

/* Phone: single column stack */
@media (max-width: 760px) {
  .grid, .pg-desk { display: flex; flex-direction: column; gap: 1px; height: auto; min-height: 0; }
  .grid > .pnl { flex: none; }
  .pg-desk > .a-chart .chart-box { min-height: 380px; flex: none; height: 380px; }
  .pg-desk > .a-news { max-height: 520px; }
  .pg-desk > .a-news .pnl-b { overflow: auto; }
  /* phone order: TV sits above levels so it can be started and then floated while reading levels */
  .pg-desk > .a-chart { order: 0; } .pg-desk > .a-hcp { order: 1; } .pg-desk > .a-tv { order: 2; }
  .pg-desk > .a-lv { order: 3; } .pg-desk > .a-news { order: 4; } .pg-desk > .a-health { order: 5; }
}

/* ---- integration fixes (PM) ---- */
body { grid-template-columns: minmax(0, 1fr); }
#top { min-width: 0; }
#fkeys { flex: 0 1 auto; min-width: 0; overflow: hidden; }
#page.grid > .pnl { min-width: 0; }
@media (max-width: 1699px) { #brand-tag { display: none; } }
@media (max-width: 1599px) { .fk { padding: 0 8px; } .fk-k { display: none; } }
@media (max-width: 1100px) {
  #fkeys { display: none; }
  #tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; }
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) {
  #page.grid { display: flex; flex-direction: column; gap: 1px; height: auto; min-height: 0; }
}

/* ---- Round A1 fixes: weight/legibility, touch targets, chart sizes ---- */
.num, .kv-v, .ldr-px, td.r, .tp-v, .stat-v { font-weight: 500; }
.huge, .big, .stat-v.huge { font-weight: 700; }
.tp-v { font-size: 13px; }
.mini { height: 184px; }
@media (max-width: 760px) {
  .seg-b, .btn { min-height: 32px; padding: 0 10px; }
  .mini { height: 200px; }
  .pnl-b { padding: 8px 10px; }
  .pg-desk > .a-news .news-i:nth-child(n+9) { display: none; }
}

/* ---- Round A2: DESK compact cells hide the long tail below 1920px; big screens show it ---- */
@media (max-width: 1919px) {
  .pg-desk .a-hcp .hcp-more, .pg-desk .a-hcp .hcp-def, .pg-desk .a-lv .lv-more { display: none; }
}
@media (max-width: 760px) {
  .pg-desk .a-hcp .hcp-more { display: block; }
}
.is-loading { color: var(--faint); }
@media (min-width: 761px) {
  .pg-desk .a-tv .pnl-b { display: flex; flex-direction: column; }
  .pg-desk .a-tv .tv-wrap { flex: 1; min-height: 0; display: flex; }
  .pg-desk .a-tv .tv-frame { aspect-ratio: auto; flex: 1; min-height: 120px; }
}

/* ---- Round A3: legibility of the dense lists ---- */
.ldr-r, .cnd, .news-i, .kv-k, .kv-v, .eco-i { font-size: 12px; }
.ldr-r { height: 24px; }
#utc { font-size: 12px; color: var(--text); }
.pnl-t { font-size: 12px; }
@media (max-width: 760px) {
  body { font-size: 13px; line-height: 18px; }
  .ldr-r, .cnd, .news-i, .kv-k, .kv-v, .eco-i, .tbl { font-size: 13px; }
  .ldr-r { height: 32px; }
  .cnd { min-height: 28px; }
  .label, .stat-k, .tp-k { font-size: 11px; }
}

/* ---- Round A4: empty trailing grid cells showed the grey gap colour as a "dead panel".
   Hairlines now come from each panel's 1px outline ring (spread only, no blur) so empty cells stay black. ---- */
#page.grid { background: var(--bg); }
#page.grid > .pnl { box-shadow: 0 0 0 1px var(--rule); }

/* ---- Round A5: narrow ladders (DESK cell, laptop, phone) use two-line rows so labels are never cut ---- */
.pg-desk .ldr-r, .pg-levels .ldr-r {
  grid-template-columns: 40px minmax(0, 1fr) 72px 40px;
  grid-template-areas: "id px dist st" "lbl lbl lbl lbl";
  height: auto; padding-top: 3px; padding-bottom: 3px; row-gap: 1px;
}
.pg-desk .ldr-r > .ldr-id, .pg-levels .ldr-r > .ldr-id { grid-area: id; }
.pg-desk .ldr-r > .ldr-lbl, .pg-levels .ldr-r > .ldr-lbl { grid-area: lbl; white-space: normal; overflow: visible; color: var(--dim); font-size: 11px; line-height: 14px; }
.pg-desk .ldr-r > .ldr-px, .pg-levels .ldr-r > .ldr-px { grid-area: px; justify-self: start; }
.pg-desk .ldr-r > .ldr-dist, .pg-levels .ldr-r > .ldr-dist { grid-area: dist; }
.pg-desk .ldr-r > .ldr-st, .pg-levels .ldr-r > .ldr-st { grid-area: st; }
.pg-desk .ldr-now > .ldr-lbl, .pg-levels .ldr-now > .ldr-lbl { color: #000; }
.pg-desk .cnd-lbl, .pg-levels .cnd-lbl { white-space: normal; overflow: visible; }
.pg-desk .news-t { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@media (max-width: 760px) { .pg-desk .ldr-r, .pg-levels .ldr-r { height: auto; min-height: 40px; } }
