@layer components {
  /* A calendar read at a few sites: where there is room they stand in a rail down its side, each a box that is ticked
     or not, the month starting at the rail; where there is not, they open from a button on the row of controls. */
  .calendar-layout--railed {
    --calendar-rail-gap: 24px;

    @media (width >= 800px) {
      display: grid;
      grid-template-columns: 220px minmax(0, 1fr);

      .calendar-layout__main {
        min-inline-size: 0;
        padding-inline-start: var(--calendar-rail-gap);
      }

      :is(.weeks, .agenda) {
        margin-inline-start: calc(var(--calendar-rail-gap) * -1);
      }

      :is(.agenda__month, .agenda__day) {
        padding-inline-start: var(--calendar-rail-gap);
      }
    }
  }

  .calendar-rail {
    display: none;

    @media (width >= 800px) {
      border-inline-end: var(--border);
      display: flex;
      flex-direction: column;
      gap: 2px;
      padding-inline-end: 16px;
    }
  }

  .calendar-rail__choice {
    align-items: start;
    border-radius: var(--radius-md);
    color: var(--color-ink);
    display: flex;
    font-size: 14px;
    font-weight: 600;
    gap: 10px;
    line-height: 20px;
    margin-inline-start: -6px;
    padding: 6px;
    text-decoration: none;

    @media (any-hover: hover) {
      &:hover {
        background-color: var(--color-ink-lightest);
      }
    }
  }

  .calendar-rail__box {
    --icon-size: 12px;

    block-size: 20px;
    border: 1px solid var(--color-ink-medium);
    border-radius: var(--radius-sm);
    color: transparent;
    display: grid;
    flex: none;
    inline-size: 20px;
    place-items: center;

    [aria-checked="true"] > & {
      background-color: var(--color-ink);
      border-color: var(--color-ink);
      color: var(--color-ink-inverted);
    }
  }

  .calendar-rail__name {
    min-inline-size: 0;
    overflow-wrap: anywhere;
  }

  .calendar-rail-menu {
    min-inline-size: 0;

    @media (width >= 800px) {
      display: none;
    }
  }

  /* Month or agenda: words where there is room, their icons on a phone. */
  .calendar-views .icon {
    --icon-size: 16px;

    @media (width >= 640px) {
      display: none;
    }
  }

  @media (width < 640px) {
    .calendar-views__word,
    .calendar-kinds__rest {
      display: none;
    }
  }

  .calendar-kinds .segments__item {
    gap: 0.3em;
  }

  /* Beside the rail the agenda's sheet is the narrow one, so the kinds are said short and the row keeps to a line. */
  .calendar-layout--railed.calendar-layout--agenda .calendar-kinds__rest {
    display: none;
  }

  /* The agenda: each day a row from one edge of the sheet to the other, its date on a tile at the left and what it
     holds beside it; a month's name stands between two hairlines where the list enters it. */
  .agenda {
    list-style: none;
    margin: 0 calc(var(--sheet-padding) * -1);
    padding: 0;
  }

  .agenda__month {
    border-block: var(--border);
    padding: 12px var(--sheet-padding);

    h2 {
      font-size: 24px;
      font-weight: 800;
      line-height: 1.2;
      margin: 0;
    }
  }

  .agenda__day {
    align-items: start;
    border-block-end: var(--border);
    display: flex;
    gap: 24px;
    min-block-size: 102px;
    padding: 16px var(--sheet-padding);
    scroll-margin-block-start: calc(var(--strip-height) + var(--top-bar-height));
  }

  .agenda__day--today {
    background-color: color-mix(in srgb, var(--color-highlight) 30%, var(--color-canvas));
  }

  .agenda__tile {
    align-items: center;
    display: flex;
    flex: none;
    flex-direction: column;
    inline-size: 48px;
    text-transform: uppercase;
  }

  .agenda__tile-month {
    background-color: var(--color-ink);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    color: var(--color-ink-inverted);
    font-size: 11px;
    font-weight: 700;
    inline-size: 100%;
    line-height: 18px;
    text-align: center;
  }

  .agenda__tile-number {
    background-color: var(--color-canvas);
    border-inline: var(--border);
    font-size: 24px;
    font-weight: 700;
    inline-size: 100%;
    line-height: 30px;
    text-align: center;
  }

  .agenda__tile-weekday {
    background-color: var(--color-canvas);
    border: var(--border);
    border-block-start: 0;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    color: var(--color-meta);
    font-size: 11px;
    inline-size: 100%;
    line-height: 22px;
    text-align: center;
  }

  .agenda__tile-today {
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
  }

  .agenda__items {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
    min-inline-size: 0;
    padding-block-start: 4px;

    .weeks__item {
      font-size: 16px;
      gap: 10px;
      margin: 0;
    }

    .weeks__mark {
      block-size: 16px;
      inline-size: 16px;
      margin-block-start: 2px;
    }

    .weeks__item--finding .weeks__mark {
      block-size: 13px;
      inline-size: 13px;
      margin: 3px 2px 0;
    }

    .weeks__item--work-permit .weeks__mark {
      block-size: 10px;
      inline-size: 18px;
      margin-block-start: 6px;
    }

    .weeks__context {
      font-size: 14px;
      white-space: normal;
    }
  }

  .agenda__nothing {
    color: var(--color-meta);
    font-size: 16px;
    line-height: 30px;
  }
}
