/* store-profit — shell adapters (responsive chrome + the surfaces the design
 * never drew).
 *
 * Loaded AFTER static/store-profit.css, which is the design's own sheet ported
 * verbatim. Nothing here re-states a design value: this file only adds what a
 * single server-rendered document needs and a mockup does not.
 *
 *   a. the responsive shell. The reference ships two documents —
 *      `DashboardLive.html` (240px sidebar, `.top` breadcrumb bar) and
 *      `DashboardMobile.html` (`.mtop` store/bell bar, fixed `.tabs` bottom
 *      bar) — and this app ships one page, so exactly one place has to decide
 *      which chrome is on screen. 1024px is the breakpoint BUILD-SPEC §1 and
 *      HANDOFF §1 both name.
 *   b. `.wide-only` / `.narrow-only` — the two-document split for a region whose
 *      desktop and mobile compositions differ (the Dashboard metric strip and
 *      the store list are a joined `.metrics`/table on desktop and a `.panel` +
 *      `.mlist` of cards on a phone). No value changes; only which of the two
 *      reference forms is displayed.
 *   c. the store picker: the app's *existing* selected-store mechanism, which
 *      the reference does not draw at all (it links `#`).
 *   d. two accessibility/behaviour rules the app needs regardless of design:
 *      a visible focus ring (BUILD-SPEC §2 makes accent the focus colour) and
 *      the colour of a missing amount.
 *   e. the phone action-row wrap: the two page headers whose action buttons do
 *      not fit a 390px viewport (/meta, /access) stack them instead of pushing
 *      the document 58px/55px wider than the screen. Measured, not guessed —
 *      see the block at the end of this file.
 *
 * Verified by tests/test_phase1_foundation.py::test_shell_is_responsive.
 */

/* ------------------------------------------------ wide (>= 1024px) chrome -- */

@media (min-width: 1024px) {
  /* the reference desktop chrome is on; the phone chrome is off */
  .mtop, .tabs { display: none; }
  .narrow-only { display: none !important; }
}

/* ----------------------------------------------- narrow (< 1024px) chrome -- */

@media (max-width: 1023.98px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .top { display: none; }

  /* the bottom tab bar is fixed to the viewport, not to a 390px mock frame */
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    padding-bottom: max(22px, env(safe-area-inset-bottom));
  }

  /* room under the page for the fixed bar (the reference `.mpage` padding) */
  .page { padding: 20px 16px 110px; gap: 16px; max-width: none; }

  /* the header row stacks: title block, then the date control. `!important`
     because the reference sets `align-items:flex-end` inline (it means "bottom
     aligned" in a row) and in a column that would right-align the whole block. */
  .page > .row.between { flex-direction: column; align-items: stretch !important; gap: 12px; }
  .page > .row.between > .row { flex-wrap: wrap; }

  /* the date control takes the full width on a phone, with Apply under it.
     The phone document draws it 44px tall with the fields edge to edge
     (`DashboardMobile.html`: `<div class="dr" style="height:44px">`, each
     label `flex:1`, each input `width:100%`), and 44px is BUILD-SPEC §2's
     minimum touch target. Desktop keeps the sheet's own 34px, which is what
     `DashboardLive.html` draws. */
  .page > .row.between .dr { flex: 1 1 100%; height: 44px; }
  .page > .row.between .dr label { flex: 1; padding: 0 12px; }
  .page > .row.between .dr input { width: 100%; height: 100%; }
  .page > .row.between form { flex-wrap: wrap; }
  .page > .row.between form > .btn { flex: 1 1 100%; height: 44px; }

  /* the phone banner is the same element with the tighter padding the phone
     document gives it; its copy and its link swap via the markers above. */
  [data-testid="cogs-incomplete"] { padding: 12px; }

  /* a metrics strip the phone document never drew (the portfolio ad-spend
     panel) wraps two-up instead of squeezing four columns into 390px */
  [data-testid="portfolio-ad-spend"] .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

  .wide-only { display: none !important; }

  /* Safety net while screens are ported one at a time: a table that has not
     been given a stacked form yet scrolls instead of being clipped by
     `.tblwrap { overflow: hidden }`. Ported screens hide their table here. */
  .tblwrap { overflow-x: auto; }

  /* ---------------------------------------------------------- auth pages --
     The sign-in page is the reference's two-column grid
     (`minmax(0,1fr) minmax(0,560px)`, SignIn.html) with the ink panel marked
     `.wide-only`. Below 1024px the panel disappears; without this rule the
     form column keeps its 560px track and a 390px phone clips the form (the
     confirmed bug in PHASE1-AUTH-SLICE-HANDOFF.md). The `[data-auth-split]` /
     `[data-auth-form]` hooks are login.html's; they carry no styling of their
     own and exist only as this rule's selector. The padding is the phone
     document's own (SignInMobile.html).

     `!important` because login.html carries the reference's tracks INLINE
     (`style="display:grid;grid-template-columns:..."`), and an inline
     declaration out-ranks a stylesheet rule: without the flag the 560px track
     keeps the whole 390px viewport and the 1fr track collapses to 0px
     (measured: tracks "0px 390px", form centred on x=0 → 190px off-screen). */
  .main > [data-auth-split] { grid-template-columns: minmax(0, 1fr) !important; }
  [data-auth-form] { padding: 48px 20px; }
  [data-auth-form] form, [data-auth-form] > .col { width: 100% !important; }
}

/* --------------------------------------------------------- region pair -- */

/* `.wide-only` / `.narrow-only` carry no styling of their own: the two media
   queries above decide which one exists on screen. A region that is only in one
   of the two reference documents is marked, not restyled. */

/* --------------------------------------------- the store picker (sheet) -- */

/* Not in the reference: the reference's switcher links to `#`. This is the
   app's existing picker (shell.js opens it, the links carry ?store_id=), so it
   is drawn in the reference language rather than invented. */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  background: rgba(20, 21, 24, .42);
}
.sheet-card {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow: auto;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 64px rgba(20, 21, 24, .22), 0 0 0 1px rgba(20, 21, 24, .06);
  padding: 8px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 8px;
}
.sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r);
  color: inherit;
  text-decoration: none;
  min-height: 44px;
}
.sheet-item:hover { background: var(--subtle); text-decoration: none; }
.sheet-item.on { background: var(--sunk); box-shadow: 0 0 0 1px var(--line); }
.sheet-links {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sheet-links .nav {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  min-height: 44px;
}

@media (min-width: 1024px) {
  .sheet { align-items: center; padding: 32px; }
}

/* ------------------------------------------------- form + money + focus -- */

/* The date control is a GET form; a form must not add its own margins. */
.filter-bar { margin: 0; }

/* A missing amount is a warning, never a zero: the same amber the reference
   uses for `.nocost` / `.miss`. */
.money-missing { color: var(--warn); }

/* BUILD-SPEC §2: accent is the focus colour. The reference zeroes the outline
   on the inputs it draws itself, so those are named explicitly here. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
.nav:focus-visible,
.tab:focus-visible,
.dr input:focus-visible,
.affix input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------- wide-screen centring (1440+) -- */

/* The sheet caps `.page` at 1264px (`store-profit.css` line 45) but never
   centres it, and `.top` pads a flat `0 32px`. So on a canvas wider than the
   240px sidebar plus the cap, the column stays pinned to the sidebar's right
   edge while the dead space grows to its right — measured in
   `phase1-center/measure.json`: at 2560px `.page` sits at 240..1504 with
   528px of unused canvas on the right, and the breadcrumb does not line up
   with the content it labels.

   The cap itself is NOT changed. The rule is the *measured default* (keep the
   sheet's 1264px, centre it); the wider 1440px-cap variant was measured too
   (`phase1-center/variantB.json`) and was not the one chosen.

   Below 1440px `.page` is already only as wide as `.main` — the cap cannot
   bite until 1505px (`phase1-center/sweep.json`: 1504px unchanged, 1505px the
   first 0.5px shift) — so `margin-inline: auto` resolves to 0px and the
   `max(0px, …)` term resolves to 0px. Nothing moves at 1440px or under, which
   is what the 1440px/390px screenshots pin.

   The inset reuses the sheet's own cap as its one literal because percentage
   padding on `.top` resolves against the same `.main` inline size that caps
   `.page`. `test_phase1_wide_screen_centering.py` reads both files and fails
   if the two literals ever drift apart.

   The `.app >` prefix is load-bearing: a signed-out document renders `.main`
   with no `.app` ancestor (`base.html`), so the sign-in page cannot reach these
   rules and stays byte-identical. */

@media (min-width: 1440px) {
  .app > .main > .page { margin-inline: auto; }

  .app > .main > .top {
    padding-inline: calc(32px + max(0px, (100% - 1264px) / 2));
  }
}

/* ------------------------------------------------- phone action rows (390) -- */

/* The Meta and Hermes-access page headers end in a `.row.gap8` of action
   buttons that does not wrap. At a true 390px viewport (no mobile emulation —
   the device-metrics flag widens the layout viewport to 432px and hides this)
   the row's right edge lands at 433px / 430px against a 375px content box, so
   the document overflows **58px** on `/meta` and **55px** on `/access`.
   Sweeping the width: `/meta` overflows up to and including 447px and is clean
   from 448px; `/access` up to 444px and clean from 445px. The wrap is therefore
   scoped to exactly those two widths on exactly those two pages — every width
   above them keeps the reference row.

   `.panel-h > .row.gap8` is the action row itself, not the `.row.gap8` that
   holds the title and its status pill (that one is nested inside `.col.grow`).
   The buttons stack at full width and keep BUILD-SPEC §2's 44px minimum touch
   target; the row grows taller instead of wider. Nothing is hidden, nothing is
   clipped, and no `overflow` is introduced to make a measurement read zero.

   Measured with the same CDP harness that found the defect: at 375/390/414px
   (plain) and at 375/390px (emulated) both pages read 0px afterwards, at
   834/1440/1920px the action row's own geometry is unchanged, and `/meta`'s
   834/1440/1920 screenshots are byte-identical before and after. */
@media (max-width: 447px) {
  [data-page="meta"] .panel-h > .row.gap8 { flex-wrap: wrap; }
  [data-page="meta"] .panel-h > .row.gap8 > .btn { flex: 1 1 100%; min-height: 44px; }
}

@media (max-width: 444px) {
  [data-page="access"] .panel-h > .row.gap8 { flex-wrap: wrap; }
  [data-page="access"] .panel-h > .row.gap8 > .btn { flex: 1 1 100%; min-height: 44px; }
}

/* ------------------------------------------------------ pairing view phone -- */

/* `/access?view=pair` is the one screen the §8 action-row wrap does not reach,
   and it carried two phone defects of its own, measured on the shipped sheet at
   a true (non-emulated) viewport. One media query holds both fixes, because the
   step strip's boundary (632px) is the wider of the two needs and the layout
   must not change shape twice on the way up:

     1 · the two-column grid (`minmax(0,1.3fr) minmax(0,1fr)`, inline in
         access.html) gives the pairing-code panel a 132px track at 375px and a
         139px one at 390px. The panel's own status row — `.pill.n` "No request
         received yet" (156px, `white-space:nowrap` from the sheet) plus
         `<span class="help">Run the setup command above</span>`, centred in the
         row — then pushes the document past the viewport. Measured 28px at a
         375px request **with** the classic scrollbar gutter (clientWidth 360,
         document scrollWidth 388; 25px at 390px: 375 against 400) and 25px/22px
         in the no-gutter state a full-page capture leaves behind, which is how
         §8 recorded it. Swept one pixel at a time in both states: the document
         overflows up to and including **503px** and is clean from 504px (the
         gutter state is the wider of the two, so the bound covers both). The
         template's *other* branch carries a wider pill — `pill.ok` "Request
         received · 10:31 PM" plus its clock icon measures 198px in a DOM stress
         (`evidence/browser/pair/pending-branch.txt`) — and with the two columns
         still in place that branch overflows by **21px at 504px** and by 1px at
         600px, so the stack is needed up to ~601px for it, inside this query's
         632px. Stacking is what removes both, and it keeps the pill inside its
         own card (in two columns at 375px the 156px pill straddles the card
         border by 12px each side; at 504px the 198px one hangs outside it).
     2 · the four-across step strip (`ol[data-sp-access="pair-steps"]`) needs
         585px of content while its track is the page width less 34px, so steps
         3 and 4 were cut off by the `overflow:hidden` the reference sets inline
         on that `<ol>` — measured: the strip's scrollWidth exceeds its
         clientWidth up to and including **632px** (1px at 632px) and is level
         from 633px. All four steps now wrap to one per row instead of being
         clipped.

   `!important` on the two declarations that restate an **inline** attribute
   (`grid-template-columns` on the grid div, `border-right` on each `<li>`): an
   inline declaration out-ranks any stylesheet rule, the same reason the auth
   split and the Shopify panel bodies above carry the flag.

   Nothing is hidden and nothing is clipped: no declaration in this block sets
   `overflow` to a clipping value or touches `display`. */
@media (max-width: 632px) {
  [data-page="access"] div:has(> section[data-sp-access="pcode-panel"]) {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  [data-page="access"] [data-sp-access="pcode-panel"] .panel-b > .row.gap8 {
    flex-wrap: wrap;
  }
  [data-page="access"] [data-sp-access="pair-steps"] { flex-wrap: wrap; }
  [data-page="access"] [data-sp-access="pair-steps"] > li {
    flex: 1 1 100%;
    border-right: 0 !important;
  }
}

/* ---------------------------------------------- f. shell fill + brand link -- */
/* The shell grid fills the window even when a page is short (the error card,
   an empty list), so the sidebar never stops halfway down the screen. */
html, body { height: 100%; }
.app { min-height: 100vh; }
/* the wordmark is a link to the dashboard, but it reads as the logo: ink, not link blue */
a.brand, a.brand:visited { color: var(--ink); text-decoration: none; }

/* ------------------------------------------------ g. tables never clip -- */
/* A long product name wraps instead of pushing the action column off the
   card, and if a table is still wider than its card it scrolls sideways
   rather than hiding columns under the card's edge. */
.tbl td.first:not(.ck) { white-space: normal; min-width: 180px; }
.tblwrap { overflow-x: auto; }

/* ------------------------------------------ h. search box (list filters) -- */
/* the design's .input with a leading icon: same height, border and radius */
.search { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); color: var(--muted); }
.search input { border: 0; outline: 0; background: transparent; font: inherit; font-size: 13.5px;
  color: var(--ink); width: 100%; min-width: 0; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------------------------- i. store page "where net revenue went" -- */
/* the split bar's segments reuse the name `.seg`, which the design sheet also
   gives the segmented control; these rules undo the control's chrome so the
   segments are plain coloured bars (Store.html draws them as bare divs) */
.seg.cogs, .seg.gp, .seg.loss { display: block; flex: none; height: 100%; padding: 0; border: 0; border-radius: 0; }
.seg.cogs { background: #B9B7AE; }
.seg.gp { background: var(--ink); }
.seg.loss { background: var(--neg); }

/* --------------------------------------- j. ad-spend strips on small screens -- */
@media (max-width: 1023.98px) {
  [data-testid="portfolio-ad-spend"] .metrics,
  [data-testid="store-ad-spend-panel"] .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  [data-testid="portfolio-ad-spend"] .tblbar,
  [data-testid="store-ad-spend-panel"] .tblbar { flex-wrap: wrap; gap: 4px 12px; }
}
@media (max-width: 599.98px) {
  [data-testid="portfolio-ad-spend"] .metrics,
  [data-testid="store-ad-spend-panel"] .metrics { grid-template-columns: minmax(0, 1fr) !important; }
}

/* --------------------------------------------- k. notifications on phones -- */
/* the time moves under the text so the headline gets the full width */
@media (max-width: 1023.98px) {
  .nrow { grid-template-columns: 32px minmax(0, 1fr); gap: 12px; padding: 14px 16px; }
  .nrow > :nth-child(3) { grid-column: 2; }
  .nrow .row.gap8 { flex-wrap: wrap; }
}
/* a wrapped first cell keeps its secondary line (domain, id) on one line */
.tbl td.first .idline .s { white-space: nowrap; }

/* ------------------------------------------------- l. sticky sidebar -- */
/* The sidebar stays put while the page scrolls (it used to stretch to the
   page's full height and scroll away with it). Its own list scrolls if the
   window is shorter than the menu. */
@media (min-width: 1024px) {
  .side { position: sticky; top: 0; height: 100vh; align-self: start; overflow-y: auto; }
  .top { position: sticky; top: 0; z-index: 20; }
}
