/* ——— The calendar: its page and its toolbar ———
   The canvas "Chalet Calendar" (2026-11-03), accepted as drawn. A page
   sized to the screen, as a chat's is (layout.css): the toolbar and the
   month stand, and the weeks (calendar-weeks.css) or the days
   (calendar-agenda.css) scroll under them. Drawn at the app's 16px unit, a
   notch below a wide sheet's 17px — the record's notch (records.css). */
@layer components {
  .calendar {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-block-size: 0;

    @container main (width >= 35rem) {
      --text-notch: 0.0625rem;
    }
  }

  /* The sentinel below the weeks or the days (calendars/_sentinel) is the
     scroller's height. With none, it stood a fraction of a pixel past the
     bottom of rows whose heights are fractions, so it never came into view
     and nothing more loaded. And what is loaded then always reaches a view
     below the one on screen: a batch prepended lands its whole height
     above (keepScroll counts scrollHeight), so the week a month opens on
     stays at the top even where six weeks are shorter than the screen. */
  .calendar-sentinel:last-child {
    block-size: 100%;
  }

  /* Grid | Agenda · Mine | Everyone · Events | Events + to-dos · Filter…,
     the segments' own frame (segmented.css). */
  .calendar-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--block-space-half) 0.75rem;
  }

  /* On a desk the options stand in the row, no box of their own — nor the
     float's dismissing layer — and the circle and the phone's shorter word
     wait for a phone. */
  .calendar-options {
    display: contents;
  }

  .calendar-toolbar__more,
  .calendar-toolbar__narrow {
    display: none;
  }

  @container main (width >= 35rem) {
    .calendar-options > .popup__dismiss {
      display: none;
    }
  }

  /* The filter written on a line (filters.css) framed as the canvas draws
     it, its glyph inside: a filter among framed segments reads as one of
     them. */
  .calendar-filter {
    inline-size: 13.75rem;
    block-size: 2rem;
    padding-inline: 0.625rem;
    border: var(--border);
    border-radius: var(--border-radius);
  }

  /* Subscribe… and New event, the page's one filled button, at the row's
     end, the filled one outermost (HANSHI 02). On a phone Subscribe… waits
     with the options, New event at the foot (below). */
  @container main (width >= 35rem) {
    .calendar-toolbar__subscribe {
      margin-inline-start: auto;
    }
  }

  /* Held down while its float is up (calendar-feeds.css): the canvas's
     wash a step darker than a hover's, the surface twice, as a bar's is
     (calendar-weeks.css). */
  .calendar-toolbar:has(.calendar-feed:popover-open) .calendar-toolbar__subscribe {
    --btn-background: var(--color-surface);

    background-image: linear-gradient(var(--color-surface), var(--color-surface));
  }

  /* On a phone the float takes the options' place under the circle
     (calendar-feeds.css): they stand down while it is up, and are back when
     it goes, as a menu's parent is. */
  @media (width < 35rem) {
    .calendar-toolbar:has(.calendar-feed:popover-open) .calendar-options {
      visibility: hidden;
    }
  }

  /* A phone's New event stands at the foot instead (the canvas's 11, 11b):
     the agenda's, and a tapped day's. A desk has the toolbar's. */
  .calendar-foot {
    display: none;
  }

  /* A phone (the canvas's 11): Everyone says All, and Events | Events +
     to-dos, Filter… and Subscribe… wait behind one circle at the row's
     end. */
  @container main (width < 35rem) {
    .calendar-toolbar__new {
      display: none;
    }

    .calendar-foot {
      display: flex;
    }

    .calendar-toolbar {
      flex-wrap: nowrap;
      gap: var(--block-space-half);
    }

    .calendar-toolbar__wide {
      display: none;
    }

    .calendar-toolbar__narrow {
      display: inline;
    }

    .calendar-toolbar__more {
      display: inline-grid;
      margin-inline-start: auto;
    }

    .calendar-options {
      --popup-area: block-end span-inline-start;

      &:not(:popover-open) {
        display: none;
      }

      &:popover-open {
        display: flex;
        flex-direction: column;
        align-items: start;
        gap: var(--block-space);
        padding: var(--block-space);
      }
    }
  }
}
