/* App shell: fixed sidebar on the left, scrolling main area on the right.
 * Tuned for an iPad mini in landscape; collapses to a bottom bar on phones. */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Logged out, the app IS the login screen: no sidebar, no header, nothing
 * that hints at data nobody may see yet. `body.is-logged-out` is toggled
 * once from app.js, not per element — one flag, not five places to keep in
 * sync (GSN-0037). */
body.is-logged-out .app {
  grid-template-columns: 1fr;
}

body.is-logged-out .sidebar,
body.is-logged-out .main__header,
body.is-logged-out #timer-host,
body.is-logged-out #status-strip {
  display: none;
}

body.is-logged-out .main {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar__brand {
  font-size: 0.8rem;
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sidebar-mute);
  padding: 0 var(--space-1) var(--space-1);
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar__spacer {
  flex: 1;
  min-height: var(--space-4);
}

.sidebar__tools {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  padding-top: var(--space-3);
}

/* ---------- Main ---------- */

.main {
  min-width: 0;
  padding: var(--space-4);
  padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
}

/* The header stays capped — it is a title and a meta line, nothing that
 * benefits from stretching. `#view` itself does NOT get a max-width here;
 * `.card` (components.css) caps its own width instead, so most panels read
 * at a comfortable measure while a specific panel (the assignment board)
 * can opt out with `.card--wide`. Capping `#view` as a whole — the previous
 * approach — squeezed the board into ~992px on any screen wider than that
 * (reported on a Mac Mini driving a wide external display: a bare gray
 * strip past the cap, and the fifth group lane sitting just out of view
 * with no obvious way to scroll to it). */
.main__header {
  max-width: var(--content-max);
}

.main__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}

.main__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.main__meta {
  margin-left: auto;
  color: var(--text-mute);
  font-size: 0.85rem;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Wide content scrolls inside its own box; the page never scrolls sideways. */
.scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Phone: sidebar becomes a bottom bar ---------- */

@media (max-width: 34rem) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 40;
  }

  .sidebar__brand,
  .sidebar__spacer {
    display: none;
  }

  .sidebar__nav {
    flex-direction: row;
    gap: var(--space-1);
  }

  /* Bottom bar: the Admin submenu (GSN-0084) extends the row rather than
   * stacking, so an open submenu just adds three more scrollable buttons. */
  .sidebar__nav .navgroup {
    flex-direction: row;
  }

  .sidebar__nav .navsub {
    flex-direction: row;
    padding-left: 0;
  }

  .sidebar__tools {
    flex-direction: row;
    border-top: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.18);
    padding-top: 0;
    padding-left: var(--space-2);
  }

  .main {
    padding-bottom: 6rem;
  }
}

/* ---------- "Turnier" board reclaims the sidebar column (GSN-0079) ---------- */

/* Only above the phone breakpoint: there the sidebar is already a bottom bar
 * and stays the navigation. On tablet/desktop the board takes the full width
 * and its own slide-out menu (turnier.js) replaces the sidebar. Header and the
 * round timer stay visible — both matter while a round is running. */
@media (min-width: 34.0625rem) {
  body.turnier-active .app {
    grid-template-columns: 1fr;
  }

  body.turnier-active .sidebar {
    display: none;
  }

  /* The board fills the window below the header + timer (GSN-0084): make the
   * main column a full-height flex stack and let #view take the rest, so the
   * group lanes grow and the courts sit flush under them with no dead space. */
  body.turnier-active .main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    padding-bottom: var(--space-3);
    overflow: hidden;
  }

  body.turnier-active #view {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
  }

  /* Menu pinned open (turnier.js, desktop only): shift the main column clear
   * of the fixed 12rem drawer, and drop the pull-tab. */
  body.turnier-pinned .main {
    padding-left: calc(12rem + var(--space-4));
  }

  body.turnier-pinned .turnier__handle {
    display: none;
  }

  body.turnier-pinned .turnier__drawer {
    transition: none;
  }
}
