/* ==========================================================================
   layout.css — the arrangement of the original window, made responsive.

     ≥ 1180px   two columns: the left column (300px) stacks the five boxes,
                the right column stacks the three cards. The right column is
                the original window's working area and fits the viewport: it
                stays in view while the page scrolls, the register panel
                scrolls inside its card when its rows do not fit (as the
                original's register frame has its own scroll bar), and the
                protocol card keeps a floor tall enough for a whole read —
                intro, request, reply, result — so a button press and its
                bytes are always on screen together. Both columns end on the
                same line, as in the original.
     760–1179   one column: the first four boxes form a 2×2 grid (the fifth
                spans both cells below them, shown only once a scan has
                found something), the cards follow.
     < 760      one column, tighter: boxes 2×2 while two fit side by side
                (≥ 560px), stacked below that; register card before protocol
                card (DOM order). No horizontal scroll down to 360px.

   Mount points (index.html) are `.slot` elements; each view renders its own
   `.box` or `.card` inside and that frame fills the slot.
   ========================================================================== */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- app bar -------------------------------------------------------------- */
.app__bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: var(--hairline) solid var(--line);
}

.app-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  min-height: var(--app-bar-h);
  max-width: 1680px;
  margin: 0 auto;
  padding: var(--space-2) var(--gutter);
}

.app-bar__brand {
  display: flex;
  flex: 1 1 auto;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 var(--space-3);
  min-width: min(14rem, 100%);
}

.app-bar__title {
  font-family: var(--font-title);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: var(--leading-tight);
  color: var(--ink);
}

.app-bar__version {
  font-family: var(--font-title);
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* Chip, connection and theme. On a phone this row wraps under the title
   instead of squeezing it. */
.app-bar__end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2) var(--space-3);
  margin-left: auto;
  min-width: 0;
}

/* --- startup notice ------------------------------------------------------- */
.app__notice-wrap {
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-4) var(--gutter) 0;
}

.app__notice-wrap:has(> .notice[hidden]) {
  display: none;
}

/* --- body: two columns ---------------------------------------------------- */
.app__body {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: var(--left-width) minmax(0, 1fr);
  align-items: stretch;
  gap: var(--space-4);
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: var(--space-4) var(--gutter) var(--space-8);
}

.app__left,
.app__right {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.slot {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.slot > .box,
.slot > .card {
  flex: 1 1 auto;
}

/* The fifth box takes whatever height is left, like the original's empty box
   that runs to the bottom of the window. */
.slot--session {
  flex: 1 0 auto;
}

/* The protocol card fills the right column down to the left column's end. */
.slot--protocol {
  flex: 1 0 auto;
}

/* --- ≥ 1180: the working area fits the window --------------------------------
   Without this the protocol card sat wherever the register card ended: below
   an eleven-row SMT500 panel that is 960 px down the page, so on a 768–900 px
   laptop no byte of a read was on screen, and from 1180 to ~1320 px, where
   SMT500's wells stack, the card ended 1.6 screens down behind a 530 px empty
   fifth box. Now the right column is exactly one viewport tall (never less
   than --work-min-h, where the page simply scrolls a little), pinned under
   the app bar while a long left column scrolls past it. */
@media (min-width: 1180px) {
  .app__body {
    --work-gap: var(--space-4);
    /* Floors of the two cards that give way (see below), and the least the
       column may be: their sum with the change-address card, so the cards
       never overflow it — a window shorter than that scrolls a little. */
    --registers-min-h: 15rem;
    --protocol-min-h: 18rem;
    --work-min-h: 40rem;
    row-gap: var(--work-gap);
    padding-top: var(--work-gap);
    /* Equal margins above and below the pinned column. */
    padding-bottom: var(--work-gap);
  }

  .app__right {
    gap: var(--work-gap);
    position: sticky;
    top: calc(var(--app-bar-h) + var(--hairline) + var(--work-gap));
    align-self: start;
    height: calc(100vh - var(--app-bar-h) - var(--hairline) - 2 * var(--work-gap));
    height: max(calc(100dvh - var(--app-bar-h) - var(--hairline) - 2 * var(--work-gap)), var(--work-min-h));
  }

  .slot--change-address {
    flex: none;
  }

  /* The register card takes its natural height while it fits and gives way
     first when it does not — its panel then scrolls — but never below a
     floor that still shows the title row, the tabs and two register rows. */
  .slot--registers {
    flex: 0 1 auto;
    min-height: var(--registers-min-h);
  }

  /* The protocol card takes the rest, and never less than a whole read:
     intro, request, reply, sensor address and the result line. */
  .slot--protocol {
    flex: 1 1 var(--protocol-min-h);
    min-height: var(--protocol-min-h);
  }

  .slot--registers > .card,
  .slot--protocol > .card {
    min-height: 0;
  }
}

/* Laptop windows (768–900 px screens, 650–800 px of page) cannot spare the
   tall layout's air: tighter gaps and card padding, and lower floors that
   still keep a read's request and reply rows in the protocol card. The
   column then fits from ~720 px of window height. */
@media (min-width: 1180px) and (max-height: 860px) {
  .app__body {
    --work-gap: var(--space-3);
    --registers-min-h: 13rem;
    --protocol-min-h: 16rem;
  }

  .app__right .card__top {
    min-height: calc(var(--control-h) + var(--space-2));
    padding-top: var(--space-2);
  }

  .app__right .card__body {
    padding-top: var(--space-2);
    padding-bottom: var(--space-3);
  }

  .app__right .well {
    padding-block: var(--space-3);
  }
}

/* A view that failed to load or mount says so in its own place. */
.mount-failure {
  padding: var(--space-4);
  border: var(--hairline) solid var(--fault);
  border-radius: var(--radius-box);
  background: var(--fault-soft);
  color: var(--ink);
  font-size: var(--text-sm);
  max-width: var(--measure);
}

/* --- 760–1179: left boxes 2×2 above the cards ------------------------------ */
@media (max-width: 1179.98px) {
  .app__body {
    grid-template-columns: minmax(0, 1fr);
    /* Two stacked rows must not share out the viewport's spare height (the
       boxes would balloon); the page simply ends where the content ends. */
    align-content: start;
  }

  .app__left {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  /* Below 1180 the fifth box spans both cells; left.css hides it while it
     lists no scan results (it would be a full-width slab holding only the
     version line). */
  .slot--session {
    grid-column: 1 / -1;
  }

  .slot--protocol {
    flex: 0 0 auto;
  }
}

/* --- < 760: phones ---------------------------------------------------------- */
@media (max-width: 759.98px) {
  .app__bar {
    position: static;
  }

  .app-bar {
    gap: var(--space-2);
  }

  /* 8 px between the connection chip and the theme control: at 360 px the
     two just share a row then (184 + 8 + 134 of 328 px while idle). */
  .app-bar__end {
    gap: var(--space-2);
  }

  .app-bar__title {
    font-size: var(--text-md);
  }

  .app__body {
    gap: var(--space-3);
    padding-top: var(--space-3);
    padding-bottom: var(--space-6);
  }

  .app__left,
  .app__right {
    gap: var(--space-3);
  }
}

/* One column of boxes, stacked tight (left.css compacts their insides), so
   the register card starts on the second screen rather than the third. */
@media (max-width: 559.98px) {
  .app__left {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
  }
}
