/*
 * THE MONTH GRID. Two layers per day, because the two states have different
 * shapes: the SLOT paints the range's CONTINUOUS band edge to edge, rounding only
 * where the span ends, and the DISC inside it carries selection.
 *
 * The disc is narrower than its slot, which keeps two neighbouring discs apart;
 * the room comes from the slot being wider, never from shrinking the disc.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-date-calendar {
    /* A day's disc, and the narrowest its slot may be: the disc plus the air
       that keeps two of them apart. Seven slots is the month's minimum width. */
    --lotics-date-calendar-disc: 36px;
    --lotics-date-calendar-slot: 40px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  /* Two months side by side, for a range on a screen with room for both. */
  .lotics-date-calendar[data-layout="pair"] {
    flex-direction: row;
    gap: var(--lotics-space-24);
  }

  .lotics-date-calendar__month {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 280px;
  }

  .lotics-date-calendar__header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--lotics-space-8);
  }

  .lotics-date-calendar__pickers {
    display: flex;
    flex-direction: row;
    justify-content: center;
    flex: 1;
    min-width: 0;
    gap: var(--lotics-space-8);
  }

  .lotics-date-calendar__title {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
  }

  .lotics-date-calendar__grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .lotics-date-calendar__weekdays {
    display: flex;
    flex-direction: row;
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--lotics-space-8);
    margin-bottom: var(--lotics-space-4);
  }

  /* Shares the day slots' sizing so the column heads stay over their columns. */
  .lotics-date-calendar__weekday {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: var(--lotics-date-calendar-slot);
    height: 32px;
  }

  /* Rows are separated so one week's band cannot touch the next one's: edge to
     edge a range that wraps reads as one block. */
  .lotics-date-calendar__week {
    display: flex;
    flex-direction: row;
    margin-bottom: var(--lotics-space-2);
  }

  .lotics-date-calendar__day {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: var(--lotics-date-calendar-slot);
    height: var(--lotics-date-calendar-disc);
    margin: 0;
    padding: 0;
    border: 0 solid transparent;
    /* The cell IS the press target, so it corners like a control. A span resets it
       below: a band across a week is one shape, not seven. */
    border-radius: var(--lotics-radius-control);
    background-color: transparent;
    color: var(--lotics-ink-default);
    font: inherit;
    appearance: none;
    /* A day SETS a value rather than acting on its own — the kit's cursor rule. */
    cursor: default;
  }

  .lotics-date-calendar__day[data-span] {
    border-radius: 0;
    background-color: var(--lotics-wash-selected);
  }

  /* Rounded only where the span actually ends — including at a row's edge, so a
     span that wraps closes on one line and reopens on the next. */
  .lotics-date-calendar__day[data-span][data-capstart] {
    border-start-start-radius: var(--lotics-radius-full);
    border-end-start-radius: var(--lotics-radius-full);
  }

  .lotics-date-calendar__day[data-span][data-capend] {
    border-start-end-radius: var(--lotics-radius-full);
    border-end-end-radius: var(--lotics-radius-full);
  }

  /* THE SAME SIZE IN EVERY STATE — nothing grows under the pointer. */
  .lotics-date-calendar__disc {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--lotics-date-calendar-disc);
    height: var(--lotics-date-calendar-disc);
    border-radius: var(--lotics-radius-full);
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  /* A day already in the span keeps the band: the wash is lighter than the fill
     it would replace. */
  .lotics-date-calendar__day:not([data-selected]):not([data-span]):hover
    .lotics-date-calendar__disc {
    background-color: var(--lotics-wash-hover);
  }

  /* The picked day is the calendar's one filled mark — the same claim as a ticked
     checkbox, so it reads the same token. */
  .lotics-date-calendar__day[data-selected] .lotics-date-calendar__disc {
    background-color: var(--primary);
  }

  /* The ring lands on the DISC rather than on the slot the button is: the disc is
     the shape a day IS. */
  .lotics-date-calendar__day:focus-visible {
    outline: none;
  }

  .lotics-date-calendar__day:focus-visible .lotics-date-calendar__disc {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }

  /* TODAY IS A RING, NOT A DOT: `0 0 0 1px` inset, so the disc does not grow, and
     it steps aside for the selected fill, the stronger claim on the same shape. */
  .lotics-date-calendar__day[data-today]:not([data-selected]) .lotics-date-calendar__disc {
    box-shadow: inset 0 0 0 1px var(--primary);
  }
}
