/*
 * The dashboard grid.
 *
 * The rule that defines the desk: **every block is exactly the same width and height.**
 * Only the header and footer are exempt. A uniform grid is what makes the whole desk
 * scannable — the eye learns one cell size and stops re-measuring, so finding the ladder
 * or the PnL tile costs no thought during a fast move.
 *
 * Columns are auto-fitted from `--block-w`, so the count follows the viewport without a
 * single media query, and every cell is exactly `--block-h` tall via `grid-auto-rows`.
 */

.app-shell {
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
  min-block-size: 100dvh;
  background: var(--bg);
}

/*
 * Every row of the shell may shrink to the viewport.
 *
 * A grid item's `min-width` defaults to `auto`, which means it refuses to shrink below its
 * own content's min-content width — so one long title or one wide canvas anywhere inside
 * pushes its whole row wider than the screen, and `overflow-x: hidden` on body then *hides*
 * the result rather than showing it. Measured on a 390px phone before this rule: the shell
 * was correctly 390px and every child of it — header, strip, grid, and so every block —
 * was 1883px, so roughly four fifths of the desk was clipped off the right edge with no
 * scrollbar to reveal it. 269 elements overflowed; this one line fixes 264 of them.
 *
 * `.block` has carried this same rule since the grid was built, for the same reason one
 * level down. It was simply never applied to the rows above it.
 */
.app-shell > * {
  min-inline-size: 0;
}

.app-header {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-inline: var(--sp-3);
  border-block-end: var(--border);
  background: var(--bg-block);
  position: sticky;
  inset-block-start: 0;
  z-index: var(--z-header);
}

.app-footer {
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-inline: var(--sp-3);
  border-block-start: var(--border);
  background: var(--bg-block);
  font-size: var(--fs-0);
  color: var(--ink-muted);
}

.app-grid {
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--block-w), 1fr));
  grid-auto-rows: var(--block-h); /* identical height, every cell, always */
  gap: var(--grid-gap);
  padding: var(--grid-gap);
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* A block is a fixed-size window onto its own scrolling content. */
.block {
  display: grid;
  grid-template-rows: auto 1fr;
  min-inline-size: 0; /* lets a grid child actually shrink instead of forcing overflow */
  min-block-size: 0;
  background: var(--bg-block);
  border: var(--border);
  border-radius: var(--radius-1);
  overflow: hidden;
  position: relative;
}

.block__bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  border-block-end: var(--border);
  background: var(--bg-raised);
  font-size: var(--fs-0);
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.block__title {
  flex: 1 1 auto;
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.block__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

/* The only place content is allowed to scroll: inside a block. */
.block__body {
  min-block-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-2);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

/* Armed and tripped states read at a glance, from across the room. */
.block.is-armed {
  border-color: var(--green);
}

.block.is-tripped {
  border-color: var(--orange-hot);
}

/* Header components */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  color: var(--green);
  text-decoration: none;
}

.brand__word {
  font-size: var(--fs-2);
  text-shadow: var(--glow-green);
}

.nav {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.nav__item {
  padding: var(--sp-1) var(--sp-2);
  background: transparent;
  border: var(--border-1) solid transparent;
  border-radius: var(--radius-1);
  color: var(--ink-muted);
  font: inherit;
  font-size: var(--fs-0);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  cursor: pointer;
}

.nav__item:hover {
  color: var(--ink);
}

.nav__item.is-active {
  color: var(--green);
  border-color: var(--green-dim);
  background: var(--green-ghost);
}

.venues {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  white-space: nowrap;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  inline-size: 1.75rem;
  block-size: 1.75rem;
  padding: 0;
  background: transparent;
  border: var(--border-1) solid transparent;
  border-radius: var(--radius-1);
  color: var(--ink-muted);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--green);
  border-color: var(--green-dim);
}

/*
 * Condensed header for narrow screens. Nav labels and the venue names go; the LEDs,
 * PnL and clock stay — on a phone the trader still needs to know if they are connected
 * and what they are carrying, which is exactly what does not fit by default.
 */
@media (max-width: 40rem) {
  .app-header {
    gap: var(--sp-2);
    padding-inline: var(--sp-2);
  }

  .brand__word,
  .status-line {
    display: none;
  }

  .nav__item {
    padding: var(--sp-1);
    font-size: 0.625rem;
  }

  .venues {
    font-size: 0;
    gap: var(--sp-1);
  }

  .venues .led {
    font-size: var(--fs-0);
  }
}
