/* The phone and touch tablet layer (Mobile Build). Loaded LAST on the app page and the sign in page, so every rule here wins a tie with app.css, theme.css and glow.css; that is why the phone
   overrides live in this one file and not in the three above. Nothing here types a colour or a company word: colours are the variables of theme.css (so both themes and the owner's own main colour
   work), and tests/test_mobile_menu.py reads this file the way tests/test_glow_kit.py reads glow.css. Motion is only transform and visibility, and it stops when the person asked for less motion.

   Part 1, the menu sheet. Under 761 pixels for everyone, and from 761 to 1024 pixels only on a touch screen (a coarse pointer), the left menu is a sheet that slides in over the page from the left
   (static/js/menu.js, mountSheet, adds the close button and the dimmed page behind it and watches the open class that app.js toggles). The words of the width rule are the same in menu.js
   (SHEET_QUERY); a test fails the build if they ever differ. A laptop never meets any rule in the query below. */

/* The two helpers menu.js adds exist everywhere but show only inside the sheet. */
.menu-close, .app button.menu-close { display: none; }
.menu-backdrop { display: none; }

@media (max-width: 760px), (min-width: 761px) and (max-width: 1024px) and (pointer: coarse) {
  /* The Menu button: the desktop page hides it (app.css), a phone and a touch tablet need it. */
  .topbar .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }

  /* The sheet. Closed it is hidden, not only moved off the screen (so a finger, Tab and a screen reader cannot reach it); open it slides in. The edge is a shadow, not a line. */
  .menu {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 80;
    display: flex; flex-direction: column; box-sizing: border-box;
    width: min(86vw, 340px); max-width: 100%;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 12px calc(16px + env(safe-area-inset-bottom, 0px) + var(--bar-call-h, 0px) + max(var(--bar-saved-h, 0px), var(--bar-ask-h, 0px)) + var(--bar-update-h, 0px)) calc(12px + env(safe-area-inset-left, 0px));       /* the saved note and the update bar sit above the sheet (900 and 1000), so the end of the sheet leaves room for the whole stack they stand in, the same words as the update bar's own offset in part 4: the call bar's height, the taller of the saved note and the room the Ask button declares, then the update bar (room.js and askpanel.js publish those heights, 0 when a bar is not showing) */
    overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    border: 0; box-shadow: inset -1px 0 0 var(--border-strong), var(--shadow-pop);       /* the edge is a shadow, not a border (the old check wants no border); the inset line keeps it visible on the dark theme */
    visibility: hidden; transform: translateX(-105%);
    transition: transform 0.22s ease, visibility 0s linear 0.22s;       /* closing: slides out, then goes hidden */
  }
  /* display again: app.css gives .menu.open display block on a phone, and that rule outranks .menu above. Opening shows it at once (visibility 0s, no delay) so the focus call that follows is not ignored, then it slides in. */
  .menu.open { display: flex; visibility: visible; transform: none; transition: transform 0.22s ease, visibility 0s; }
  .menu > * { flex: none; }
  .menu:focus, .menu:focus-visible { outline: none; }

  /* The close button: first in the sheet, on the right, a full 44 by 44 target. */
  .app button.menu-close { display: flex; align-items: center; justify-content: center; align-self: flex-end; min-width: 44px; min-height: 44px; margin: 0 0 4px; padding: 0; }

  /* Rows are 48 pixels high: a group header, and every page link under it. */
  .app button.menu-group-head { min-height: 48px; }
  .menu .menu-group-list li a { min-height: 48px; display: flex; align-items: center; }

  /* The dimmed page behind the open sheet: a tap on it closes the sheet. It sits above the top bar (50) and the call bar (50) and below the sheet (80), the saved note (900) and the update bar (1000). */
  .menu-backdrop { display: block; position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 70; background: var(--scrim); overscroll-behavior: none; touch-action: none; }
  .menu-backdrop[hidden] { display: none; }
}

/* The page behind the open sheet does not scroll (menu.js puts the class on the html element only while the sheet is open). The lock is on the html element alone: a lock on the body as well would make the body
   a scroll box of its own, and the sticky top bar would stop sticking while the sheet is open. */
html.menu-sheet-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .menu, .menu.open { transition: none; }
}

/* Paper never shows the dimmed page or the close button (app.css already hides the menu itself). */
@media print {
  .menu-backdrop, .app button.menu-close { display: none !important; }
}

/* Part 2, tap targets. On a phone (under 761 pixels) and on any touch screen (a coarse pointer) every button, drop-down, text box, check box and standalone link is at least 44 by 44 pixels, the
   owner's strict guide. A laptop with a mouse meets none of this: the rules sit inside the one query below, so the desktop look is exactly what it was (before and after pictures prove it). */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  .app button, .app select, .app summary, .app textarea, .app input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { min-height: 44px; }
  .app button { min-width: 44px; }

  /* An icon button holds a small picture or only the word Edit. The plain rule gives it line-height 0 (app.css), which made the Edit button 45 by 12; centred in its 44 by 44 box it looks the same and is a real target.
     The Menu button and the sheet's Close button are left out on purpose: they are hidden everywhere except inside the sheet query (part 1), and this rule outranks the rules that hide them, so on an iPad turned
     sideways (a touch screen wider than 1024) it would have shown both on a page that has no sheet. */
  .app button.icon-button:not(.menu-toggle):not(.menu-close) { display: inline-flex; align-items: center; justify-content: center; }

  /* A check box with no label around it (the board's, the advertiser list's) is drawn here: a 44 by 44 target with the 20 pixel box and its tick drawn inside it, from the theme's variables. A box inside a label
     keeps its own look, and the label is the 44 pixel target (the next rule). */
  .app input[type="checkbox"]:not(label *) {
    -webkit-appearance: none; appearance: none; position: relative; flex: none;
    width: 44px; height: 44px; margin: 0; padding: 0; border: 0; background: transparent; cursor: pointer;
  }
  .app input[type="checkbox"]:not(label *)::before {
    content: ""; position: absolute; left: 12px; top: 12px; box-sizing: border-box; width: 20px; height: 20px;
    border: 2px solid var(--border-strong); border-radius: 6px; background: var(--card);
  }
  .app input[type="checkbox"]:not(label *):checked::before { background: var(--primary); border-color: var(--primary); }
  .app input[type="checkbox"]:not(label *):checked::after {
    content: ""; position: absolute; left: 19px; top: 15px; box-sizing: border-box; width: 6px; height: 12px;
    border: solid var(--on-primary); border-width: 0 2px 2px 0; transform: rotate(45deg);
  }
  .app input[type="checkbox"]:not(label *):disabled { opacity: 0.5; cursor: not-allowed; }

  /* A label that holds a check box or a radio is the target a finger meets, so the label is 44 high (a label is a block in app.css, or a flex row for label.check, and both take a height). Both rules are written
     with :where(), which has no weight of its own: a label that app.css already lays out (the Ad work radio rows that are 48 high, the renewal question) keeps its own height. Only the height is set here; the words
     of a bare label sit at the top of its 44 pixel box (app.css's own label rule outweighs a rule with no weight, so display and alignment are left alone on purpose). */
  :where(.app label.check) { min-height: 44px; }
  /* its own rule: a browser that does not know :has() drops the whole rule, and the line above must not go with it */
  :where(.app label:has(> input[type="checkbox"])), :where(.app label:has(> input[type="radio"])) { min-height: 44px; }

  /* A link that stands alone (a name in a table cell, a card or a heading, a link on a line of its own) is a 44 by 44 target. A link inside a paragraph of words stays a plain inline link, so a sentence still
     wraps; a paragraph that holds only a link gets the class link-line from rows.js (markLinkLines). Written with :where() so a link app.css already lays out (a button link, a whole card that is a link) keeps its own display. */
  :where(#main a[href]:not(p a)), :where(#main p.link-line > a[href]) { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }

  /* The small round "what this means" mark on Home is 14 pixels. Its box becomes 44 by 44 and its negative margin gives back the room, so the labels around it do not move; the picture stays in the middle. */
  .app .info-mark { width: 44px; height: 44px; margin: -15px; place-items: center; flex: none; }       /* flex none: in a flex row (the tile label) the box would otherwise be squeezed narrower than 44 */

  /* A pill that is a link (the Onboarding pill on My ad work) sits among other pills in a paragraph, so the rule above leaves it alone; it is a link standing alone in its own pill. */
  .app a.pill { display: inline-flex; align-items: center; min-height: 44px; }

  /* The 44 pixel rules are a floor, never a ceiling: the Install page asks for 48 pixel boxes (app.css), and the rules above, which have more weight, would have lowered them to 44. They stay 48. */
  .app .install input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), .app .install select { min-height: 48px; }

  /* The Screens Map. Each placed screen is an SVG link inside a drawing that is scaled to the width of the page, so its dot is about 7 pixels wide on a phone and about 17 on a touch tablet, and a CSS minimum
     size does not enlarge an SVG link. pages/screens.js (drawMap) puts an invisible square of 44 by 44 SCREEN pixels around every dot (class map-hit, sized from the drawing's width on screen) and leaves it
     inert; here it takes the tap. The wrapper gets a little padding and the drawing may show past its own edge, so the squares of the dots nearest the edge are not cut off (the wrapper still clips at its own
     edge). A laptop with a mouse meets none of this: the square stays inert and the wrapper is as it was. */
  .app .map-hit { fill: transparent; pointer-events: all; }
  .app .map-wrap { padding: 12px; }
  .app svg.screen-map { overflow: visible; }
}

/* Part 3, one line rows and one lane at a time. The rows come from static/js/rows.js, which only adds attributes and one arrow button to a table; this is the whole phone look. Everything that changes a table or a
   board sits inside the sheet query (a phone, and a touch tablet up to 1024) AND a screen only block, so a laptop and a printed page keep the tables and the boards exactly as they are. The arrow and the lane
   tabs are hidden everywhere else. The stronger second selector keeps a touch screen wider than 1024 pixels from showing the arrow (the tap rules above reach every button there). */
.row-toggle, .app button.row-toggle { display: none; }
.lane-tabs { display: none; }

@media (max-width: 760px), (min-width: 761px) and (max-width: 1024px) and (pointer: coarse) {
  @media screen {
    /* A table that has rows stops being a table box and becomes a stack of grid lines, so it can never be wider than the screen. */
    table[data-rowkit] { display: block; width: 100%; }
    table[data-rowkit] > thead, table[data-rowkit] > tbody { display: block; }
    table[data-rowkit] > thead > tr { display: flex; }
    table[data-rowkit] > thead th:not([data-rk="select"]) { display: none; }       /* the header words are each cell's label now; only a select all box stays */
    table[data-rowkit] td { overflow-wrap: anywhere; }                               /* a long address or link wraps inside its cell */

    /* One line: the name, then the one or two numbers that matter stacked at its right, then room for the arrow. Everything else waits behind the arrow. The numbers' column is as wide as they are but never more
       than 45 percent of the row, so a long value cannot squeeze the name to a few letters. The two lines are at least 28 high each, so an opened row always has 56 pixels above its details for the arrow. */
    table[data-rowkit] > tbody > tr[data-rkey] { display: grid; position: relative; grid-template-columns: minmax(0, 1fr) fit-content(45%) 44px; grid-template-rows: minmax(28px, auto) minmax(28px, auto); align-items: center; min-height: 56px; border-bottom: 1px solid var(--border); }
    table[data-rowkit] > tbody > tr[data-rkey] > td { display: none; min-width: 0; padding: 6px 12px; border: 0; text-align: left; }
    table[data-rowkit] > tbody > tr[data-rkey] > td[data-rk="name"] { display: block; grid-column: 1; grid-row: 1 / span 2; padding-right: 8px; }
    table[data-rowkit] > tbody > tr[data-rkey] > td[data-rk="key1"] { display: block; grid-column: 2; grid-row: 1; text-align: right; }
    table[data-rowkit] > tbody > tr[data-rkey] > td[data-rk="key2"] { display: block; grid-column: 2; grid-row: 2; text-align: right; }
    table[data-rowkit] > tbody > tr[data-rkey] > td[data-rk="name"]::after { content: attr(data-summary); display: block; color: var(--text-muted); font-size: 0.8rem; }
    table[data-rowkit] td[data-rk="key1"]::before, table[data-rowkit] td[data-rk="key2"]::before { content: attr(data-label); display: block; color: var(--text-muted); font-size: 0.72rem; }
    table[data-rowkit] td[data-empty] { display: none !important; }       /* rows.js never marks the name cell (the arrow lives in it), so a row with no name still has its arrow */

    /* A table with a column of check boxes (the Advertisers list for an admin) gets a first column of its own for them: 44 wide, so a person can tick one row, not only the whole page. The select all box in the
       header is the same 44 wide. */
    table[data-rowselect] > tbody > tr[data-rkey] { grid-template-columns: 44px minmax(0, 1fr) fit-content(45%) 44px; }
    table[data-rowselect] > tbody > tr[data-rkey] > td[data-rk="select"] { display: block; grid-column: 1; grid-row: 1 / span 2; padding: 0; }
    table[data-rowselect] td[data-rk="select"] > input { display: block; }
    table[data-rowselect] > tbody > tr[data-rkey] > td[data-rk="name"] { grid-column: 2; }
    table[data-rowselect] > tbody > tr[data-rkey] > td[data-rk="key1"], table[data-rowselect] > tbody > tr[data-rkey] > td[data-rk="key2"] { grid-column: 3; }

    /* The arrow: a 44 by 44 target at the right of the row, centred without a transform (glow.css replaces a button's transform on hover, and a tap leaves hover on). The picture inside turns. */
    .app button.row-toggle {
      display: inline-flex; align-items: center; justify-content: center; position: absolute; top: 0; right: 0; bottom: 0; margin: auto 0; width: 44px; height: 44px; padding: 0;
      background: transparent; color: var(--text-muted); box-shadow: none; border-radius: 8px; line-height: 0;
    }
    /* Open: the arrow stays beside the first line (the details below are full width and would sit under it if it stayed centred on the tall row). */
    .app table[data-rowkit] tr[data-open] button.row-toggle { top: 6px; bottom: auto; margin: 0; }
    table[data-rowkit] tr[data-open] .row-toggle svg { transform: rotate(90deg); }

    /* Open: the buttons of the row first (order puts them before the other columns), then each other column as a small label over its value, full width. */
    table[data-rowkit] tr[data-open] > td[data-rk="act"], table[data-rowkit] tr[data-open] > td[data-rk="more"] { display: block; grid-column: 1 / -1; }
    table[data-rowkit] tr[data-open] > td[data-rk="act"] { order: -1; }
    table[data-rowkit] td[data-rk="more"]::before { content: attr(data-label); display: block; color: var(--text-muted); font-size: 0.8rem; }
    table[data-rowkit] tr[data-open] { background: var(--card-raised); }

    /* glow.css paints the hover tint on each cell (table.list tr:hover td); with the cells laid out as a grid that shows as patches of different shades, and on a phone a tap leaves the row hovered. The tint
       goes on the whole row instead, and an open row keeps its own background. */
    table[data-rowkit] tr:hover td { background: none; }
    table[data-rowkit] > tbody > tr[data-rkey]:not([data-open]):hover { background: color-mix(in srgb, var(--primary) 6%, transparent); }

    /* A form the page inserts under a row (one cell across the table) is a plain block. */
    table[data-rowkit] > tbody > tr:not([data-rkey]) { display: block; }
    table[data-rowkit] > tbody > tr:not([data-rkey]) > td { display: block; }

    /* The two boards: one lane at a time. The tabs name the lanes (and carry the counts), so the heading inside a lane is not repeated. */
    .lanes, .ad-lanes { display: block; overflow: visible; }
    .lanes > .lane, .ad-lanes > .lane { display: none; }
    .lanes > .lane.is-active, .ad-lanes > .lane.is-active { display: block; }
    .lanes > .lane > .lane-title, .ad-lanes > .lane > .lane-title { display: none; }
    .lanes .lane-body, .ad-lanes .lane-body { grid-template-columns: minmax(0, 1fr); }       /* with the scroll box gone, one long unbroken word in a card can no longer widen the page */
    .lanes .deal-card, .ad-lanes .deal-card { overflow-wrap: anywhere; }
    .lane-tabs { display: flex; }
    .lane-tabs button { flex: 1 1 30%; min-height: 44px; }
  }
}

/* Part 4, the bottom of the screen. On a phone and on any touch screen the bars that sit fixed at the bottom stack instead of covering each other: the call bar at the bottom, the saved note above it, the update bar
   above that. How tall each one is comes from static/js/room.js (--bar-call-h and the others: the bar's height and an 8 pixel gap, 0 when it is not on screen). The home bar of an iPhone (the safe area) is kept
   clear of everything, and the end of a page leaves room for all of it plus the 56 pixel round button a later job puts at the bottom right. A laptop with a mouse keeps today's bottom exactly.
   The round button (the Ask job) sits beside the saved note and under the update bar, which is centred and too wide to sit beside it: while that button is on screen the Ask job sets --bar-ask-h on the root
   element (64 pixels: its height and a gap) and the update bar rises above it. Nothing sets it today, so it counts as 0. */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  .call-bar { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  #crm-saved { bottom: calc(16px + var(--bar-call-h, 0px) + env(safe-area-inset-bottom, 0px)); max-width: calc(100% - 96px); }       /* from 16 pixels in, so it ends 8 pixels before the round Ask button (56 wide, 16 from the edge) */
  #crm-update-bar { bottom: calc(16px + var(--bar-call-h, 0px) + max(var(--bar-saved-h, 0px), var(--bar-ask-h, 0px)) + env(safe-area-inset-bottom, 0px)); }
  .content { padding-bottom: calc(120px + var(--bar-call-h, 0px) + var(--bar-saved-h, 0px) + var(--bar-update-h, 0px) + env(safe-area-inset-bottom, 0px)); }
  #ai-usage-slot { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* Part 5, the top bar (Way A: My login and Sign out stay in the bar, the sun and moon switch stays). On a phone and on any touch screen every control in the bar is a 44 pixel target. The Menu button and the two
   buttons of words already are (part 2); the two sun and moon buttons (glow.css asks for 36 under 761 pixels) and the three alert icons (alerts.css asks for 36) get their 44 here, with one more class in the
   selector so these rules win. The bar wraps into two rows on a phone, the Menu button, the logo and name and the alert icons first, then the switch, My login and Sign out; the gaps are smaller than on a laptop
   so the sticky bar costs the screen as little as it can. */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  body.app .topbar { gap: 6px 8px; padding: 8px 16px; }
  .app .topbar .alert-btn, .app .topbar .theme-switch button.icon-button { min-width: 44px; min-height: 44px; }
}
/* Where the menu is a sheet (the same width rule as part 1, word for word): the company name is the size of the page text (1 rem, which is 18 pixels) with a tight line, so a name that needs two lines is 43
   pixels tall, no taller than the 44 pixel buttons beside it, and the first row stays one button high; and the person's name and role (app.css already hides it under 761 pixels) is hidden on a touch tablet too, because with it the bar needs about 930
   pixels and on a tablet 820 wide Sign out would sit alone on a second row. */
@media (max-width: 760px), (min-width: 761px) and (max-width: 1024px) and (pointer: coarse) {
  .topbar .brand { font-size: 1rem; line-height: 1.2; }
  .topbar .who { display: none; }
}

/* Part 4, the Reminders tab (WCP-5 step W5-R8). On a phone the question card stacks its lines and its two buttons stack full width under it, each a 44 pixel target. The 16 pixel side gutter is the page's own
   (.content), so the card sits inside it, never wider than it; a long customer name or reason wraps instead of pushing the page sideways. Inside the same tap query as part 2 (a phone and any touch screen), because tests/test_mobile_taps.py allows a conditional rule only inside the allowed query blocks of this sheet. */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  #reminders-questions, #reminders-held { box-sizing: border-box; max-width: 100%; min-width: 0; }
  .reminder-ask { display: block; box-sizing: border-box; width: 100%; max-width: 100%; overflow-wrap: anywhere; }
  .reminder-ask .main > div { display: block; margin-top: 4px; }
  .reminder-ask .rq-note input { width: 100%; box-sizing: border-box; min-height: 44px; }
  .reminder-ask .rq-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
  .reminder-ask .rq-actions button { width: 100%; min-height: 44px; box-sizing: border-box; }
  .held-list { padding-left: 0; list-style: none; overflow-wrap: anywhere; }
  .outbox-row .send-again { min-height: 44px; }

/* Ad check (part WCP-3, step W3-6): the Ad check section on the deal page and the "Ad requests waiting for a person" box on the Ads page. Added at the end of the file by W3-6; the next step
   to add here (R8) goes after this block. Phone and touch screens: one column, the rows stack as cards, every button and field is at least a 44 pixel target, and long words wrap instead of widening
   the page. Colours come from the theme variables only; nothing here types one. */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  .ad-check, .ad-held { display: block; max-width: 100%; box-sizing: border-box; }
  .ad-check .ad-check-list, .ad-check .ad-check-requests, .ad-held .ad-held-list { display: block; margin: 0; padding: 0; list-style: none; }
  .ad-check .ad-check-row, .ad-held .ad-held-row { display: block; box-sizing: border-box; margin: 0 0 8px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; overflow-wrap: anywhere; }
  .ad-check .buttons, .ad-held .buttons { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .app .ad-check button, .app .ad-held button { min-height: 44px; min-width: 44px; width: 100%; box-sizing: border-box; }
  .ad-check a, .ad-held a { display: inline-flex; align-items: center; min-height: 44px; }
  .ad-check textarea, .ad-held textarea, .ad-check select, .ad-held input { box-sizing: border-box; width: 100%; max-width: 100%; min-height: 44px; }
  .ad-check .ad-check-verdict { overflow-wrap: anywhere; }
}
