/* Any screen size. The page is the top bar plus one scrolling area (main); nothing has a fixed
   pixel position that depends on the screen. Three widths matter:
     wide    above 1100px   Overview is two columns (chart, insights)
     medium  up to 1100px   Overview stacks: tiles, chart, insights
     narrow  up to 700px    phone: tabs along the bottom (css/phone.css), tools and the time slider wrap
   layout.js keeps --topbar-h equal to the top bar's real height (it wraps on narrow screens).
   The printed report has its own fixed layout (print.css), so these rules step aside for it. */
html:not(.print-layout) #app { grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
html:not(.print-layout) .topbar { flex-wrap: wrap; row-gap: 6px; min-height: 52px; padding-top: 6px; padding-bottom: 6px; }
html:not(.print-layout) main { overflow-y: auto; scrollbar-width: thin; }
.progress { top: var(--topbar-h, 52px); }
.settings-page { top: var(--topbar-h, 52px); }

/* Map: the map takes the height that is left, and never less than a usable amount */
html:not(.print-layout)[data-view="map"] .work { flex: 1 0 auto; min-height: min(340px, 60vh); }
html:not(.print-layout)[data-view="map"] #mapWrap { min-height: min(340px, 60vh); }

/* Summary tiles scroll sideways rather than squeezing */
.kpi-bar { scroll-snap-type: x proximity; }
.kpi { scroll-snap-align: start; }

@media (max-width: 1100px) {
  html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) main { display: flex; flex-direction: column; }
  html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) .work { display: block; flex: none; }
  html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) #chartWrap, html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) #chartWrap.split { height: 400px; flex: none; order: 1; }
  html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) #chartWrap.split { height: 520px; }
  html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) .work { order: 2; }
  html:not(.print-layout) #insights { overflow: visible; }
  .seg.tabs { position: static; }
  .chart-bar .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .chart-bar .seg span { white-space: nowrap; }
}

@media (max-width: 700px) {
  .topbar { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .brand-txt, #busyText { display: none; }
  .brand { padding-right: 0; }
  .filterbar { gap: 6px 10px; padding: 8px; }
  .filt { flex: 1 1 150px; }
  .filt > span { min-width: 54px; }
  .filt select, .filt.block select { flex: 1; min-width: 0; max-width: none; }
  .filterbar .crumb { display: none; }
  /* the six tabs move to a bar along the bottom: css/phone.css */
  main { padding: 8px; gap: 8px; }
  .maptools .place { flex-basis: 100%; max-width: none; }
  #blockActs { margin-left: 0; }
  .timebar { flex-wrap: wrap; row-gap: 4px; }
  .timebar input[type=range] { order: 5; flex-basis: 100%; }
  #timeFirst, #timeLast { display: none; }
  .time-label { min-width: 0; flex: 1; text-align: right; white-space: normal; }
  html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) #chartWrap { height: 340px; padding: 10px; }
  .kpi { min-width: 150px; }
  .kpi.wide { min-width: 240px; }
  #layerCard:not(.folded) { width: min(264px, calc(100% - 20px)); max-height: 70%; }
  .settings-head, .settings-body { padding-left: 10px; padding-right: 10px; }
  .menu-list { width: min(290px, calc(100vw - 20px)); }
}

/* Very wide screens: keep the Overview readable instead of stretching the side column's partner endlessly */
@media (min-width: 1700px) {
  html:not(.print-layout):is([data-view="overview"], [data-view="water"], [data-view="weather"]) main { grid-template-columns: minmax(0, 1fr) 420px; }
}
