/*
  The page frame: top bar, the sheet the work sits on, the footer, and the phone tab bar.

  The bar is quiet on purpose. The old one was a saturated blue band across the top of every
  screen; the work is what should carry the colour, and in this app colour means money.
*/

@layer layout {
  .page {
    width: min(100% - var(--s-4), var(--page));
    margin-inline: auto;
  }

  @media (max-width: 47.99em) {
    .page { width: 100%; }
  }

  /* Top bar ---------------------------------------------------------------- */

  .topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
    padding-inline: max(var(--s-4), env(safe-area-inset-left));
  }

  .topbar__inner {
    width: min(100%, var(--page));
    margin-inline: auto;
    display: flex;
    align-items: center;
    gap: var(--s-4);
    flex-wrap: wrap;
    min-height: 3.5rem;
  }

  .topbar__brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    margin-inline-end: auto;
  }

  /* The wordmark ships as white artwork. Rather than sit it on a chip of its own colour, which
     reads as a patch on the bar, it is inked to match the text beside it. */
  .topbar__brand img {
    height: 1.5rem;
    width: auto;
    filter: brightness(0) saturate(100%);
  }

  :root[data-theme="dark"] .topbar__brand img { filter: none; }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .topbar__brand img { filter: none; }
  }

  .topbar__toggle {
    display: none;
    background: none;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: var(--s-2);
    cursor: pointer;
    color: var(--ink);
  }

  .topbar__panel {
    display: contents;
  }

  .topbar__nav,
  .topbar__account {
    display: flex;
    align-items: center;
    gap: var(--s-1);
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .topbar__link {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--ink-2);
    white-space: nowrap;
  }

  .topbar__link:hover {
    color: var(--ink);
    background: var(--surface-sunk);
  }

  /* The current section is marked by a rule under it, the way a ledger marks a column. */
  .nav-item.active > .topbar__link {
    color: var(--accent);
    font-weight: 700;
    box-shadow: inset 0 -2px 0 var(--accent);
    border-radius: var(--radius) var(--radius) 0 0;
  }

  @media (max-width: 47.99em) {
    .topbar__toggle { display: inline-flex; }

    .topbar__panel {
      display: block;
      flex-basis: 100%;
      border-top: 1px solid var(--rule);
      padding-block: var(--s-2);
    }

    .topbar__panel.collapse:not(.show) { display: none; }
    .topbar__panel.collapsing { display: block; }

    .topbar__nav,
    .topbar__account {
      flex-direction: column;
      align-items: stretch;
      width: 100%;
    }

    .topbar__link {
      padding-block: var(--s-3);
    }

    .nav-item.active > .topbar__link {
      box-shadow: inset 2px 0 0 var(--ink);
    }
  }

  /* The sheet -------------------------------------------------------------- */

  main {
    display: block;
    background: var(--surface);
    padding:
      var(--s-5)
      max(var(--s-4), env(safe-area-inset-right))
      var(--s-7)
      max(var(--s-4), env(safe-area-inset-left));
  }

  @media (min-width: 48em) {
    main {
      margin-block: var(--s-5);
      padding: var(--s-6);
      border: 1px solid var(--rule);
      border-radius: var(--radius-lg);
    }
  }

  /* Phone tab bar ---------------------------------------------------------- */

  .tabbar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--rule);
    padding-bottom: env(safe-area-inset-bottom, 0);
    list-style: none;
    margin: 0;
    padding-inline: 0;
  }

  .tabbar .nav-item { flex: 1 1 0; }

  .tabbar__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding-block: var(--s-2);
    font-size: var(--text-xs);
    text-decoration: none;
    color: var(--ink-2);
    min-height: var(--tap);
  }

  .tabbar .nav-item.active .tabbar__link {
    color: var(--accent);
    font-weight: 700;
  }

  .tabbar__link svg { width: 20px; height: 20px; }

  @media (min-width: 36em) {
    .tabbar { display: none; }
  }

  /* Leave room for the tab bar so it never covers the last row of a list. */
  @media (max-width: 35.99em) {
    body { padding-bottom: 4.5rem; }
  }

  /* Footer ----------------------------------------------------------------- */

  .pagefoot {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
    justify-content: space-between;
    padding: var(--s-5) var(--s-4);
    font-size: var(--text-sm);
    color: var(--ink-2);
  }

  @media (max-width: 35.99em) {
    .pagefoot { display: none; }
  }

  /* A row of headings and actions that sits above a list. */
  .pagehead {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-3);
    margin-bottom: var(--s-5);
  }

  .pagehead__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  @media print {
    .topbar, .tabbar, .pagefoot { display: none; }
    main { border: 0; margin: 0; padding: 0; background: #fff; }
  }
}
