/* Layout is mobile-first: the phone layout is the default, and the desktop
   rail is added at 900px. The sidebar element is one element in both. */

.shell {
  min-height: 100dvh;
}

.workspace {
  min-width: 0;
  /* Keeps the last card clear of the floating nav. */
  padding-bottom: calc(var(--nav-h) + var(--s-8) + env(safe-area-inset-bottom, 0px));
}

.topbar {
  width: 100%;
  max-width: 72rem; /* the same column as the content below it, so the title lines up with the cards */
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap; /* the month picker drops to its own row on a phone */
  align-items: center;
  gap: var(--s-3);
  padding: calc(var(--s-4) + env(safe-area-inset-top, 0px)) var(--s-4) var(--s-2);
}

.topbar-logo {
  display: block;
  flex-shrink: 0;
  border-radius: 7px;
}

.topbar-controls {
  order: 10;
  flex: 1 0 100%;
  display: flex;
  justify-content: center;
}

.topbar-controls:empty {
  display: none;
}

.page-title {
  flex: 1;
  font-size: var(--fs-xl);
  letter-spacing: -0.02em;
}

.content {
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  padding: var(--s-2) var(--s-4) var(--s-4);
}

/* ---------- Phone: the sidebar becomes a floating pill at the bottom ---------- */

.sidebar {
  position: fixed;
  z-index: 20;
  left: var(--s-3);
  right: var(--s-3);
  bottom: calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
  padding: var(--s-2);
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-nav);
}

.brand,
.sidebar-actions {
  display: none;
}

.nav {
  display: flex;
  justify-content: space-between;
  gap: var(--s-1);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 48px;
  min-width: 48px;
  padding: 0 var(--s-3);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 700;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-link[aria-current="page"] {
  padding: 0 var(--s-4);
  background: var(--ink);
  color: var(--on-ink);
}

/* Labels stay in the page for screen readers but only show on the active item. */
.nav-link > span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: visible;
  clip-path: inset(50%);
  white-space: nowrap;
}

.nav-link[aria-current="page"] > span {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
}

@media (hover: hover) {
  .nav-link:not([aria-current="page"]):hover {
    color: var(--ink);
  }
}

/* ---------- Layout helpers ---------- */

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

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-3);
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: var(--s-4);
}

/* ---------- Desktop: a floating rail on the left ---------- */

@media (min-width: 900px) {
  .shell {
    display: grid;
    grid-template-columns: 17rem minmax(0, 1fr);
  }

  .workspace {
    padding-bottom: var(--s-8);
  }

  .topbar {
    padding: var(--s-6) var(--s-8) var(--s-2);
  }

  .topbar-logo {
    display: none;
  }

  .topbar-controls {
    order: 0;
    flex: 0 0 auto;
  }

  .content {
    padding: var(--s-4) var(--s-8) var(--s-8);
  }

  .sidebar {
    position: sticky;
    top: var(--s-4);
    left: auto;
    right: auto;
    bottom: auto;
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: var(--s-6);
    height: calc(100dvh - 2 * var(--s-4));
    margin: var(--s-4) 0 var(--s-4) var(--s-4);
    padding: var(--s-5);
    border-radius: 28px;
    box-shadow: var(--shadow-card);
  }

  .brand,
  .sidebar-actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
  }

  .brand-name {
    font-size: var(--fs-lg);
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  .nav {
    flex-direction: column;
    gap: var(--s-1);
  }

  .nav-link {
    justify-content: flex-start;
    height: 44px;
    padding: 0 var(--s-4);
    background: transparent;
  }

  .nav-link > span {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
  }

  .sidebar-actions {
    margin-top: auto;
    flex-direction: column;
  }
}