/* ——— The calendar's grid ———
   The canvas's 1 and 2: the month in view between its neighbours, the
   weekdays, then week rows from Monday — the week's number (Swiss offices
   count weeks), the dates, the bars in lanes of their own, then each day's
   timed items. The row grows to fit. Kinds read without colour: a time, a
   call's or a series' glyph, a card's, a to-do's check; colour is state
   alone — shu for an answer waited on, straw for near, the strike for
   cancelled and done (HANSHI). On a phone (11b) the weeks are dots, three
   rows of them, and the day tapped opens under them. */
@layer components {
  /* The week's number, then the seven days: the weekdays' columns and every
     week's. */
  .calendar-grid {
    --calendar-number: 3.25rem;
    --calendar-columns: var(--calendar-number) repeat(7, minmax(0, 1fr));

    display: flex;
    flex: 1;
    flex-direction: column;
    min-block-size: 0;
  }

  /* ——— The month in view: ‹ November 2026 ›, Back to today at the start ——— */
  .calendar-title {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-block: 1.625rem 0.875rem;
  }

  .calendar-title__today {
    justify-self: start;
  }

  .calendar-title__month {
    grid-column: 2;
  }

  .calendar-weekdays {
    display: grid;
    grid-template-columns: var(--calendar-columns);
    padding-block-end: 0.375rem;
    /* Only to keep the weeks' gutter, below. */
    overflow: hidden;

    > :first-child {
      grid-column: 2;
    }

    > .label {
      padding-inline-start: 0.5rem;
    }
  }

  .calendar-weekdays__initial {
    display: none;
  }

  /* The weeks scroll; the title and the weekdays stand. A day's words are
     drawn a notch below the page's on a desk (the canvas's 12.5–13px), as
     a record's sheet is (records.css).

     Where a scrollbar takes room — a mouse's, not a trackpad's — the
     weekdays keep the same gutter as the weeks under them, so each name
     stands over its column; without it Sun stood 13px off its own. */
  .calendar-weekdays,
  .calendar-weeks {
    scrollbar-gutter: stable;
  }

  .calendar-weeks {
    flex: 1;
    min-block-size: 0;
    overflow-y: auto;
    overscroll-behavior: contain;

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

  /* ——— A week ———
     The dates, a row per lane (--lanes, at least one), then the items,
     which take what is left. The days' hairlines are the row's own
     background, under the bars. */
  .calendar-week {
    display: grid;
    grid-template-columns: var(--calendar-columns);
    grid-template-rows: auto repeat(var(--lanes), auto) 1fr;
    min-block-size: 7.625rem;
    border-block-start: var(--border);
    background: linear-gradient(to right, var(--color-line) var(--border-size), transparent 0)
      var(--calendar-number) 0 / calc((100% - var(--calendar-number)) / 7) 100% repeat-x;
  }

  .calendar-week > .calendar-week__number {
    grid-column: 1;
    grid-row: 1 / -1;
    padding-block-start: 0.5rem;
    padding-inline-start: 0.125rem;
  }

  .calendar-week__date {
    grid-row: 1;
    padding-block: 0.375rem 0.125rem;
    padding-inline: 0.5rem;
    font-size: var(--text-small);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--color-ink-subtle);

    /* A day is the phone's button: a desk reads its date. */
    > input {
      display: none;
    }

    > label {
      pointer-events: none;
    }
  }

  /* The 1st of a month names it, in ink, under an ink rule. */
  .calendar-week__date--first {
    font-weight: 600;
    color: var(--color-ink);
    box-shadow: inset 0 2px var(--color-ink);
  }

  /* Today, an ink disc around the number alone: on the 1st the month's
     name stands beside it, as on any other 1st. */
  .calendar-week__date--today .calendar-week__day {
    display: inline-grid;
    place-items: center;
    inline-size: 1.5rem;
    block-size: 1.5rem;
    margin-block-start: -0.1875rem;
    margin-inline-start: -0.3125rem;
    font-weight: 600;
    color: var(--color-canvas);
    background-color: var(--color-ink);
    border-radius: 50%;
  }

  .calendar-dots {
    display: none;
  }

  /* A day's empty room is the way to an event on it (S2): a link under the
     day's column, every row of it, the dates, bars and items standing over
     it; what lies between them lets the click through. */
  .calendar-week__new {
    grid-row: 1 / -1;
  }

  .calendar-week__date,
  .calendar-week__items {
    pointer-events: none;

    > li {
      pointer-events: auto;
    }
  }

  /* ——— Bars ———
     What takes more than a day, or all of one, in its lane. A piece that
     goes on into the next week, or came from the last, runs to the edge
     square. The surface twice, as a face's tile is layered (avatars.css):
     a bar is a step darker than a wash. */
  .calendar-bar {
    margin: 1px 0.25rem;
    padding: 1px 0.5rem;
    font-size: var(--text-small);
    font-weight: 500;
    line-height: 1.5;
    color: var(--color-ink);
    text-decoration: none;
    background-color: var(--color-surface);
    background-image: linear-gradient(var(--color-surface), var(--color-surface));
    border-radius: var(--border-radius);
  }

  .calendar-bar--before {
    margin-inline-start: 0;
    border-start-start-radius: 0;
    border-end-start-radius: 0;
  }

  .calendar-bar--after {
    margin-inline-end: 0;
    border-start-end-radius: 0;
    border-end-end-radius: 0;
  }

  /* ——— A day's items ——— */
  .calendar-week__items {
    grid-row: -2 / -1;
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-inline-size: 0;
    padding-block: 0.1875rem 0.625rem;
    padding-inline: 0.25rem;
  }

  .calendar-item {
    --check-size: 0.75rem;
    --icon-size: 0.8125rem;

    display: flex;
    align-items: center;
    gap: 0.3125rem;
    min-inline-size: 0;
    padding: 2px 0.25rem;
    font-size: var(--text-small);
    line-height: 1.35;
    border-radius: var(--border-radius);

    > form {
      display: contents;
    }

    .todo-check {
      margin-block-start: 0;
    }
  }

  .calendar-item__link {
    display: flex;
    align-items: center;
    gap: 0.3125rem;
    min-inline-size: 0;
    color: inherit;
    text-decoration: none;

    > .icon {
      color: var(--color-ink-subtle);
    }
  }

  .calendar-item__time {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    color: var(--color-ink-subtle);
  }

  /* ——— State, an item's or a bar's ———
     The "needs you" chip's tint and ink, the whole line (HANSHI, Colour);
     straw while a to-do or a card is near; cancelled and done sink to
     faint, struck through — a cancelled meeting whole, a done to-do its
     title (HANSHI, To-dos). The strike is the text's own rather than the
     one todos.css draws in: a cut-off title ran that one on past its
     ellipsis to the cell's edge. */
  .calendar-item--asked,
  .calendar-bar--asked {
    color: var(--color-accent-ink);
    background: var(--color-accent-tint);

    :is(.calendar-item__time, .icon) {
      color: inherit;
    }
  }

  .calendar-item--near:not(:has(.todo-check[aria-pressed="true"])),
  .calendar-bar--near {
    color: var(--color-warning-ink);
  }

  .calendar-item--cancelled,
  .calendar-item--done,
  .calendar-item:has(.todo-check[aria-pressed="true"]),
  .calendar-bar--cancelled,
  .calendar-bar--done {
    color: var(--color-ink-faint);
  }

  .calendar-item--cancelled,
  .calendar-item:has(.todo-check[aria-pressed="true"]) .calendar-item__title,
  .calendar-bar--cancelled,
  .calendar-bar--done {
    text-decoration: line-through;
  }

  /* The phone's day, under the dots. */
  .calendar-day-list {
    display: none;
  }

  /* ——— A phone (the canvas's 11b) ———
     The month in dots: three rows of days, a day a button; its marks are a
     bar's pill, a meeting's dot, shu for an answer waited on and a ring
     for a to-do. The tapped day wears the selected wash, and its items
     open under the rows. The month leads its row at the edge, Back to
     today at the end while today's month is out of view. */
  @container main (width < 35rem) {
    .calendar-grid {
      --calendar-number: 0px;
    }

    .calendar-title {
      grid-template-columns: 1fr auto;
      margin-block: 0.375rem;
    }

    .calendar-title .calendar-month {
      padding-inline-start: 0;
    }

    .calendar-title__step {
      display: none;
    }

    .calendar-title__month {
      grid-column: 1;
      grid-row: 1;
    }

    .calendar-title__today {
      grid-column: 2;
      grid-row: 1;
    }

    .calendar-weekdays {
      padding-block-end: 0.25rem;

      > .label {
        padding: 0;
        text-align: center;
      }
    }

    .calendar-weekdays__name {
      display: none;
    }

    .calendar-weekdays__initial {
      display: inline;
    }

    .calendar-weeks {
      flex: none;
      block-size: calc(3 * (3.25rem + var(--border-size)));
    }

    .calendar-week {
      min-block-size: 0;
      background: none;
    }

    .calendar-week > :is(.calendar-week__number, .calendar-bar, .calendar-week__items, .calendar-week__new),
    .calendar-week__month {
      display: none;
    }

    .calendar-week__date {
      padding: 0;
      font-size: var(--text-normal);
      font-weight: 400;
      color: var(--color-ink);
      box-shadow: none;

      /* Clipped by .for-screen-reader, and here a control: a keyboard
         steps through the days, and the day draws the ring. The day holds
         it, so it scrolls with the strip rather than standing where the
         strip's rows run on below. */
      position: relative;

      > input {
        display: revert;
      }

      > label {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.1875rem;
        block-size: 3.25rem;
        padding-block-start: 0.375rem;
        pointer-events: auto;
        cursor: pointer;
      }

      &:has(:checked) {
        background-color: var(--color-selected);
      }

      &:has(:focus-visible) {
        outline: var(--focus-ring);
        outline-offset: calc(-1 * var(--focus-ring-size));
      }
    }

    .calendar-week__day {
      display: inline-grid;
      place-items: center;
      inline-size: 1.625rem;
      block-size: 1.625rem;
    }

    .calendar-week__date--today .calendar-week__day {
      inline-size: 1.625rem;
      block-size: 1.625rem;
      margin: 0;
    }

    .calendar-dots {
      display: flex;
      gap: 3px;
      block-size: 6px;

      > i {
        inline-size: 5px;
        block-size: 5px;
        background-color: var(--color-ink-subtle);
        border-radius: 50%;
      }

      > .calendar-dots__bar {
        inline-size: 0.75rem;
        border-radius: 99rem;
      }

      > .calendar-dots__asked {
        background-color: var(--color-accent);
      }

      > .calendar-dots__todo {
        background-color: transparent;
        border: 1px solid var(--color-ink-subtle);
      }
    }

    .calendar-day-list {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-block-size: 0;
      margin-block-start: 0.625rem;
      padding-block-start: 0.75rem;
      overflow-y: auto;
      border-block-start: var(--border);
    }
  }

  .calendar-day-list__heading {
    margin-block-end: 0.375rem;
    font-size: var(--text-normal);
    font-weight: 600;
  }

  .calendar-day-list__today {
    font-weight: 400;
    color: var(--color-ink-subtle);
  }
}
