/* THE iPAD'S LANDSCAPE FIT (docs/IPAD-WEB-APP.md step 3). Linked after app.css by web/build.js
   page(), which also puts class "ipad" on <html>. The Mac page carries neither, and every rule here
   is gated on `html.ipad`, so nothing in this file can reach the Mac app.

   Sizes walked: iPad Pro 11" 1194x834 and 1210x834, iPad Pro 13" 1366x1024 and 1376x1032, in
   home-screen mode (no Safari bars). The 11" is the tight one: 62px shorter than the Mac's
   896px floor (main.js minHeight).

   THE RULE IT KEEPS is LOOK-WALK.md's: the view never scrolls; one specific, bounded panel per
   screen may scroll inside itself, bar hidden (app.css hides every bar already). Text sizes, hit
   targets and the copyright strip are app.css's own and are not touched here.

   HOW A PANEL IS BOUNDED: the open folder (or, on a card screen, main itself) hands the grid the
   height that is left (flex:1 1 0), the grid gives its last row minmax(0,1fr), and the bounded
   sheet sits at the top of that row with max-height:100%. A sheet shorter than the row keeps its
   own height, so a screen that already fits looks exactly as it does on the Mac; a taller one stops
   at the foot and its body scrolls. The height comes off the flex chain, never a subtracted
   constant (app.css `.conn-fit` says why). */

/* ---------- the "turn it back" notice ---------- */
.ipad-turn{display:none}
@media (orientation:portrait){
  html.ipad body{background:#000}
  html.ipad body > :not(.ipad-turn){display:none !important}
  html.ipad .ipad-turn{
    display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px;
    position:fixed; inset:0; padding:16px; background:#000; color:#fff; text-align:center;
    font:19px/1.5 -apple-system, system-ui, sans-serif;
  }
  html.ipad .ipad-turn h2{margin:0; font-size:1.75rem; font-weight:600}
  html.ipad .ipad-turn p{margin:0; font-size:19px}
}

/* ---------- the flex chain, on the screens that need it ---------- */
/* Open folders: Finances > Sales > Shopify, Faire, Whimsy Way; Stock > Market restocks. */
html.ipad main:has(.sheet-pair [data-panel="sales-breakdown"], [data-panel="channel-seal"], .rs-list) .folder[data-open]{
  flex:1 1 0; min-height:0;
}
html.ipad main:has(.sheet-pair [data-panel="sales-breakdown"], [data-panel="channel-seal"], .rs-list) .folder[data-open] > .grid,
html.ipad main .grid:has(> [data-panel="traffic-landing-pages"]){
  flex:1 1 0; min-height:0;
}

/* Sales channel screens (Shopify, Faire, Etsy share the left tile and the breakdown): the pair, then
   the channel's own wide sheet when there is one. That wide sheet is the bounded one; with no wide
   sheet (Shopify), the breakdown's list is. */
html.ipad .grid:has(> .sheet-pair [data-panel="sales-breakdown"]){grid-template-rows:minmax(0,1fr)}
html.ipad .grid:has(> .sheet-pair [data-panel="sales-breakdown"]):has(> .panel.wide){grid-template-rows:auto minmax(0,1fr)}
html.ipad .grid > .sheet-pair:has([data-panel="sales-breakdown"]),
html.ipad .grid:has(> .sheet-pair [data-panel="sales-breakdown"]) > .panel.wide{
  align-self:start; max-height:100%; min-height:0;
}
html.ipad .sheet-pair [data-panel="sales-breakdown"]{min-height:0}
html.ipad .sheet-pair [data-panel="sales-breakdown"] > .pbody{flex:1 1 auto; min-height:0}
html.ipad .sheet-pair [data-panel="sales-breakdown"] .swap{flex:1 1 auto; min-height:0; overflow-y:auto}
html.ipad .grid:has(> .sheet-pair [data-panel="sales-breakdown"]) > .panel.wide > .pbody{flex:1 1 auto; min-height:0; overflow-y:auto}

/* Whimsy Way: one wide sheet, bounded; its body scrolls. */
html.ipad .grid:has(> [data-panel="channel-seal"]){grid-template-rows:minmax(0,1fr)}
html.ipad .grid > [data-panel="channel-seal"]{align-self:start; max-height:100%; min-height:0}
html.ipad .grid > [data-panel="channel-seal"] > .pbody{flex:1 1 auto; min-height:0; overflow-y:auto}

/* Traffic: four sheets side by side in one row, each at its own height. At 1194 wide each is
   about 270px, which still holds the day chart, the live count, the channel bars and the
   landing-page list; the landing pages are the bounded one if a month's list grows past the row. */
html.ipad .grid:has(> [data-panel="traffic-landing-pages"]){
  grid-template-columns:repeat(4, minmax(0,1fr)); grid-template-rows:minmax(0,1fr);
}
html.ipad .grid:has(> [data-panel="traffic-landing-pages"]) > .panel{grid-column:auto; align-self:start; max-height:100%; min-height:0}
html.ipad [data-panel="traffic-landing-pages"] > .pbody{flex:1 1 auto; min-height:0; overflow-y:auto}
/* In a quarter-width sheet the folder's "Updated ..." stamp (#stamp, top right of the folder) lands
   on the heading itself, which it never does on the Mac's half-width sheet, so this one heading
   starts under the stamp instead. */
html.ipad [data-panel="traffic-landing-pages"] > .phead{padding-top:28px}

/* Stock > Market restocks: the three sections side by side instead of stacked -- what the levels
   are and the add form on the left, the list on the right, bounded, so a long list scrolls in
   place. */
html.ipad .grid:has(> .conn-view .rs-list){grid-template-rows:minmax(0,1fr)}
html.ipad .conn-view.conn-detail:has(.rs-list){
  max-width:none; min-height:0;
  display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); grid-template-rows:auto minmax(0,1fr);
  column-gap:22px; row-gap:22px;
}
html.ipad .conn-view.conn-detail:has(.rs-list) > .conn-section{align-self:start}
html.ipad .conn-view.conn-detail:has(.rs-list) > .conn-section:has(.rs-list){
  grid-column:2; grid-row:1 / 3; align-self:start; max-height:100%; min-height:0;
  display:flex; flex-direction:column;
}
html.ipad .conn-view.conn-detail:has(.rs-list) .rs-list{flex:1 1 auto; min-height:0; overflow-y:auto}

/* ---------- the "Updated ..." stamp ---------- */
/* A sheet with no heading that is empty shows one line of note at its very top. At iPad widths that
   line runs on under the folder's stamp (#stamp, top right) when the sheet is the top-right one:
   Sales > Etsy's "Nothing recorded" at 11", Profit & loss's "QuickBooks reported no expense
   categories" at 13". The note starts below the stamp instead. */
html.ipad .panel > .pbody:first-child > .empty:first-child{padding-top:28px}

/* ---------- 11" only ---------- */
@media (max-height:900px){
  /* Sales > Online, In-person and Total: the shared pie is drawn 160px across instead of 230 so
     the legend and its Open buttons fit under it (Online was 70px over at 834 tall). */
  html.ipad [data-panel="sales-split"] .pie svg{max-width:160px}
}
