:host(:not(:is([hydrated], .hydrated))) {
  @apply not-hydrated;
}


mds-button {
  &:not(:is([hydrated], .hydrated)) {
    @apply not-hydrated;
  }
}


/**
 * @prop --mds-calendar-cell-background: Public. Background of calendar cells.
 * @prop --mds-calendar-cell-boundaries-background: Deprecated, read by nothing: the selection boundaries take the `-selection-*-boundaries-background` and `-preselection-*-boundaries-background` properties.
 * @prop --mds-calendar-cell-boundaries-color: Deprecated, read by nothing: the selection boundaries take the `-selection-*-boundaries-color` and `-preselection-*-boundaries-color` properties.
 * @prop --mds-calendar-cell-boundaries-padding: Padding inside selection boundaries.
 * @prop --mds-calendar-cell-color: Public. Text color of calendar cells.
 * @prop --mds-calendar-cell-other-month-background: Background of days from adjacent months.
 * @prop --mds-calendar-cell-other-month-color: Text color of days from adjacent months.
 * @prop --mds-calendar-cell-disabled-background: Background for disabled days.
 * @prop --mds-calendar-cell-disabled-color: Text color for disabled days.
 * @prop --mds-calendar-cell-weekend-background: Background for weekend days.
 * @prop --mds-calendar-cell-weekend-color: Text color for weekend days.
 * @prop --mds-calendar-cell-size: Deprecated, read by nothing: a cell takes the width of its column in the calendar, and is square.
 * @prop --mds-calendar-cell-selection-boundaries-border-radius: Border radius for day selection boundaries.
 * @prop --mds-calendar-cell-selection-week-boundaries-border-radius: Border radius for week selection boundaries.
 * @prop --mds-calendar-cell-preselection-today-background: Background for today's date in preselection state.
 * @prop --mds-calendar-cell-preselection-today-color: Text color for today's date in preselection state.
 * @prop --mds-calendar-cell-preselection-current-month-background: Background of the band of a preview, from the start to the day under the pointer (current month).
 * @prop --mds-calendar-cell-preselection-current-month-color: Text color of the band of a preview (current month).
 * @prop --mds-calendar-cell-preselection-current-month-boundaries-color: Text color of the day under the pointer, the end a click there would pick (current month).
 * @prop --mds-calendar-cell-preselection-current-month-boundaries-background: Fill of the ring of the day under the pointer (current month).
 * @prop --mds-calendar-cell-preselection-current-month-boundaries-border-color: Ring of the day under the pointer, not chosen yet (current month).
 * @prop --mds-calendar-cell-preselection-other-month-background: Background of the band of a preview (other months).
 * @prop --mds-calendar-cell-preselection-other-month-color: Text color of the band of a preview (other months).
 * @prop --mds-calendar-cell-preselection-other-month-boundaries-color: Text color of the day under the pointer (other months).
 * @prop --mds-calendar-cell-preselection-other-month-boundaries-background: Fill of the ring of the day under the pointer (other months).
 * @prop --mds-calendar-cell-preselection-other-month-boundaries-border-color: Ring of the day under the pointer, not chosen yet (other months).
 * @prop --mds-calendar-cell-selection-current-month-background: Background of the band of a range, between and behind its ends (current month).
 * @prop --mds-calendar-cell-selection-current-month-color: Text color of the band of a range (current month).
 * @prop --mds-calendar-cell-selection-current-month-boundaries-background: Fill of the dot of a chosen day: either end of a range, or the day of a single picker (current month).
 * @prop --mds-calendar-cell-selection-current-month-boundaries-color: Text color of the dot of a chosen day (current month).
 * @prop --mds-calendar-cell-selection-current-month-weekend-background: Background of the band of a range on weekend days (current month).
 * @prop --mds-calendar-cell-selection-current-month-weekend-color: Text color of the band of a range on weekend days (current month).
 * @prop --mds-calendar-cell-selection-current-month-weekend-boundaries-background: Background of the band behind an end of a range on a weekend day.
 * @prop --mds-calendar-cell-selection-current-month-weekend-boundaries-color: Text color of the dot of an end of a range on a weekend day.
 * @prop --mds-calendar-cell-selection-other-month-background: Background of the band of a range (other months).
 * @prop --mds-calendar-cell-selection-other-month-color: Text color of the band of a range (other months).
 * @prop --mds-calendar-cell-selection-other-month-boundaries-background: Fill of the dot of a chosen day (other months).
 * @prop --mds-calendar-cell-selection-other-month-boundaries-color: Text color of the dot of a chosen day (other months).
 */

/*
  The cells live in the shadow DOM of mds-calendar, so these properties reach them only by
  inheritance: set them on mds-calendar (or on any ancestor of it). The cell therefore never
  declares a public property on its own :host, which would beat the inherited value: it reads
  each one through a var() fallback into a --private-calendar-cell-* copy, and the state rules
  (weekend, other month, selection, preview) switch between those copies.

  No css/mds-calendar-cell-property.css on purpose: a registered property always has a value,
  its initial-value, so every one of those fallbacks would stop firing and a cell would paint
  the light value the registration was resolved to on a dark page. See
  projects/styles/scripts/properties.ts for how the registrations are collected.
*/

:host {
  --private-calendar-cell-background: var(--mds-calendar-cell-background, transparent);
  --private-calendar-cell-boundaries-padding: var(
    --mds-calendar-cell-boundaries-padding,
    --spacing(100)
  );
  --private-calendar-cell-color: var(
    --mds-calendar-cell-color,
    var(--mds-calendar-day-number-color, rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5))))
  );
  --private-calendar-cell-other-month-background: var(
    --mds-calendar-cell-other-month-background,
    transparent
  );
  --private-calendar-cell-other-month-color: var(
    --mds-calendar-cell-other-month-color,
    rgb(var(--magma-text-disabled, var(--text-neutral-disabled, 119 119 119)))
  );
  --private-calendar-cell-disabled-background: var(
    --mds-calendar-cell-disabled-background,
    transparent
  );
  --private-calendar-cell-disabled-color: var(
    --mds-calendar-cell-disabled-color,
    rgb(var(--magma-text-disabled, var(--text-neutral-disabled, 119 119 119)))
  );
  --private-calendar-cell-weekend-background: var(
    --mds-calendar-cell-weekend-background,
    transparent
  );
  --private-calendar-cell-weekend-color: var(
    --mds-calendar-cell-weekend-color,
    rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)))
  );

  /* radius */
  --private-calendar-cell-selection-boundaries-border-radius: var(
    --mds-calendar-cell-selection-boundaries-border-radius,
    var(--magma-radius-full, var(--radius-full, 1000px))
  );
  --private-calendar-cell-selection-week-boundaries-border-radius: var(
    --mds-calendar-cell-selection-week-boundaries-border-radius,
    var(--magma-radius-full, var(--radius-full, 1000px))
  );

  /* today */
  --private-calendar-cell-preselection-today-background: var(
    --mds-calendar-cell-preselection-today-background,
    rgb(var(--magma-accent-surface, var(--variant-primary-09, 213 224 245)))
  );
  --private-calendar-cell-preselection-today-color: var(
    --mds-calendar-cell-preselection-today-color,
    rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)))
  );

  /* preview: the band from the start to the day under the pointer, paler than a range, and that
   * day drawn as a ring, not chosen yet; the start keeps the dot of a chosen day (#341) */

  --private-calendar-cell-preselection-current-month-background: var(
    --mds-calendar-cell-preselection-current-month-background,
    rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248)))
  );
  --private-calendar-cell-preselection-current-month-color: var(
    --mds-calendar-cell-preselection-current-month-color,
    rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)))
  );
  --private-calendar-cell-preselection-current-month-boundaries-color: var(
    --mds-calendar-cell-preselection-current-month-boundaries-color,
    rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)))
  );
  --private-calendar-cell-preselection-current-month-boundaries-background: var(
    --mds-calendar-cell-preselection-current-month-boundaries-background,
    transparent
  );
  --private-calendar-cell-preselection-current-month-boundaries-border-color: var(
    --mds-calendar-cell-preselection-current-month-boundaries-border-color,
    rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)))
  );
  --private-calendar-cell-preselection-other-month-background: var(
    --mds-calendar-cell-preselection-other-month-background,
    rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248)))
  );
  --private-calendar-cell-preselection-other-month-color: var(
    --mds-calendar-cell-preselection-other-month-color,
    rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)))
  );
  --private-calendar-cell-preselection-other-month-boundaries-color: var(
    --mds-calendar-cell-preselection-other-month-boundaries-color,
    rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)))
  );
  --private-calendar-cell-preselection-other-month-boundaries-background: var(
    --mds-calendar-cell-preselection-other-month-boundaries-background,
    transparent
  );
  --private-calendar-cell-preselection-other-month-boundaries-border-color: var(
    --mds-calendar-cell-preselection-other-month-boundaries-border-color,
    rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)))
  );

  /* selection: a pale band on the days of a range and a full dot on each chosen day, the start
   * and the end alike; the dot used to be a pale hole in a strong band, which read as a day left
   * out where a start fell on a Sunday, alone at the end of its row (#341). Inside the band the
   * weekend keeps a step of its own (#1142). The band takes the accent surface at rest, a step
   * over the subtle one of a preview: the selected role has the subtle value today, and would
   * draw a range and its preview alike */

  --private-calendar-cell-selection-current-month-background: var(
    --mds-calendar-cell-selection-current-month-background,
    rgb(var(--magma-accent-surface, var(--variant-primary-09, 213 224 245)))
  );
  --private-calendar-cell-selection-current-month-color: var(
    --mds-calendar-cell-selection-current-month-color,
    rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)))
  );
  --private-calendar-cell-selection-current-month-boundaries-background: var(
    --mds-calendar-cell-selection-current-month-boundaries-background,
    rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)))
  );
  --private-calendar-cell-selection-current-month-boundaries-color: var(
    --mds-calendar-cell-selection-current-month-boundaries-color,
    rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)))
  );
  --private-calendar-cell-selection-current-month-weekend-background: var(
    --mds-calendar-cell-selection-current-month-weekend-background,
    rgb(var(--magma-accent-surface-hover, var(--variant-primary-08, 195 212 245)))
  );
  --private-calendar-cell-selection-current-month-weekend-color: var(
    --mds-calendar-cell-selection-current-month-weekend-color,
    rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)))
  );
  --private-calendar-cell-selection-current-month-weekend-boundaries-background: var(
    --mds-calendar-cell-selection-current-month-weekend-boundaries-background,
    rgb(var(--magma-accent-surface-hover, var(--variant-primary-08, 195 212 245)))
  );
  --private-calendar-cell-selection-current-month-weekend-boundaries-color: var(
    --mds-calendar-cell-selection-current-month-weekend-boundaries-color,
    rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)))
  );
  --private-calendar-cell-selection-other-month-background: var(
    --mds-calendar-cell-selection-other-month-background,
    rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248)))
  );
  --private-calendar-cell-selection-other-month-color: var(
    --mds-calendar-cell-selection-other-month-color,
    rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)))
  );
  --private-calendar-cell-selection-other-month-boundaries-background: var(
    --mds-calendar-cell-selection-other-month-boundaries-background,
    rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)))
  );
  --private-calendar-cell-selection-other-month-boundaries-color: var(
    --mds-calendar-cell-selection-other-month-boundaries-color,
    rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)))
  );

  align-items: center;
  aspect-ratio: 1 / 1;
  display: flex;
  justify-content: center;
  padding: var(--private-calendar-cell-boundaries-padding);
  position: relative;
}

:host([month='other']) {
  visibility: var(--mds-calendar-cell-other-month-visibility, hidden);
}

.inner-dot {
  aspect-ratio: 1 / 1;
  background-color: var(--private-calendar-cell-inner-background);
  border-radius: var(--private-calendar-cell-selection-boundaries-border-radius);

  /* the ring of a day not chosen yet, set by the selection states */
  box-shadow: inset 0 0 0 --spacing(50) var(--private-calendar-cell-dot-ring, transparent);
  display: flex;
  min-height: 0;
  min-width: 0;
  width: 100%;
  z-index: 1;
}

.area-background {
  background-color: var(--private-calendar-cell-background);
  color: var(--private-calendar-cell-color);
  inset: 0;
  position: absolute;
  z-index: 0;
}

.action {
  align-items: center;
  background-color: transparent;
  border-radius: 0;

  /* the text of a dot, where a selection state draws one, else the text of the cell */
  color: var(--private-calendar-cell-dot-color, var(--private-calendar-cell-color));
  display: flex;
  inset: calc(var(--mds-calendar-cell-gap) * -1);
  justify-content: center;
  min-height: 0;
  min-width: 0;
  padding: 0;

  /* mds-button sets align-self/justify-self: flex-start on its :host, which makes
     browsers supporting absolute-position self-alignment shrink the button to its
     label instead of stretching it between the insets: stretch restores the CSS2
     inset-driven sizing so the button always covers the whole cell. */
  place-self: stretch;
  position: absolute;
  width: auto;
  z-index: 2;
}

/* selection boundaries: any `selection` but `none`, which reads as no selection, tested in a
   :where() so these rules still lose to the start, end and single ones below them */

:host([selection]:not(:where([selection='none']))[orientation='horizontal']) .area-background {
  margin-left: calc(var(--mds-calendar-cell-gap) * -1);
  margin-right: calc(var(--mds-calendar-cell-gap) * -1);
}

:host([selection='start'][orientation='horizontal']) .area-background {
  border-bottom-left-radius: var(--private-calendar-cell-selection-boundaries-border-radius);
  border-top-left-radius: var(--private-calendar-cell-selection-boundaries-border-radius);
  margin-left: 0;
}

:host([selection='end'][orientation='horizontal']) .area-background {
  border-bottom-right-radius: var(--private-calendar-cell-selection-boundaries-border-radius);
  border-top-right-radius: var(--private-calendar-cell-selection-boundaries-border-radius);
  margin-right: 0;
}

/* vertical orientation */

:host([selection]:not(:where([selection='none']))[orientation='vertical']) .area-background {
  margin-bottom: calc(var(--mds-calendar-cell-gap) * -1);
  margin-top: calc(var(--mds-calendar-cell-gap) * -1);
}

:host([selection='start'][orientation='vertical']) .area-background {
  border-radius: var(--private-calendar-cell-selection-boundaries-border-radius)
    var(--private-calendar-cell-selection-boundaries-border-radius) 0 0;
  margin-top: 0;
}

:host([selection='end'][orientation='vertical']) .area-background {
  border-radius: 0 0 var(--private-calendar-cell-selection-boundaries-border-radius)
    var(--private-calendar-cell-selection-boundaries-border-radius);
  margin-bottom: 0;
}

:host([orientation='vertical']:not([selection='start'], [selection='end'])) .area-background {
  border-radius: 0;
}

/* first week-day */

:host(:nth-child(7n - 6)) .area-background,
:host([selection='end'][orientation='horizontal']:nth-child(7n - 6)) .area-background {
  border-bottom-left-radius: var(--private-calendar-cell-selection-week-boundaries-border-radius);
  border-top-left-radius: var(--private-calendar-cell-selection-week-boundaries-border-radius);
}

:host(:nth-child(7n)) .area-background,
:host([selection='end'][orientation='horizontal']:nth-child(7n)) .area-background {
  border-bottom-right-radius: var(--private-calendar-cell-selection-week-boundaries-border-radius);
  border-top-right-radius: var(--private-calendar-cell-selection-week-boundaries-border-radius);
}

:host([selection='end'][orientation='horizontal']:nth-child(7n)) .area-background {
  border-bottom-right-radius: var(--private-calendar-cell-selection-boundaries-border-radius);
  border-top-right-radius: var(--private-calendar-cell-selection-boundaries-border-radius);
}

:host([selection]:not(:where([selection='none']))[orientation='horizontal']:nth-child(7n - 6))
  .area-background {
  margin-left: 0;
}

:host([selection]:not(:where([selection='none']))[orientation='horizontal']:nth-child(7n))
  .area-background {
  margin-right: 0;
}

:host([selection='single'][orientation='horizontal']) .area-background {
  border-radius: var(--private-calendar-cell-selection-boundaries-border-radius);
  margin-left: 0;
  margin-right: 0;
}

/* weekend */

:host(:nth-child(7n - 1)),
:host(:nth-child(7n)) {
  --private-calendar-cell-color: var(--private-calendar-cell-weekend-color);
  --private-calendar-cell-background: var(--private-calendar-cell-weekend-background);
}

/* month */

:host([month='other']:not([selection]:not(:where([selection='none'])))) {
  --private-calendar-cell-color: var(--private-calendar-cell-other-month-color);
  --private-calendar-cell-background: var(--private-calendar-cell-other-month-background);
}

:host([disabled]) {
  --private-calendar-cell-color: var(--private-calendar-cell-disabled-color);
  --private-calendar-cell-background: var(--private-calendar-cell-disabled-background);

  cursor: auto;
  pointer-events: none;
}

/*
  A cell is selected by any `selection` but `none`, which reads as no selection. The test for
  `none` sits in a :where(), so these rules weigh what a plain [selection] did.

  Two layers draw a selection (#341):
  - the band, on .area-background: the days of a range, and the halves of its ends that reach
    them. A `preview` paints the band of a range not chosen yet, from the start to the day under
    the pointer, paler.
  - the dot, on .inner-dot, with its own text colour: a chosen day is a full dot, the start and
    the end of a range alike, a single day too; the day under the pointer, not chosen yet, is a
    ring. In a preview the start is the day already chosen and keeps its full dot, the end (or a
    `single`) is the day under the pointer.
  The band rules set --private-calendar-cell-background and -color, the dot rules
  --private-calendar-cell-inner-background, -dot-color and -dot-ring only: a dot never fights the
  band, on weekend days included, for its colours.
*/

:host(:not([selection]:not(:where([selection='none'])))[today]) {
  --private-calendar-cell-inner-background: var(
    --private-calendar-cell-preselection-today-background
  );
  --private-calendar-cell-color: var(--private-calendar-cell-preselection-today-color);
}

/* the band */

:host([selection]:not(:where([selection='none']))[month='current']) {
  --private-calendar-cell-background: var(
    --private-calendar-cell-selection-current-month-background
  );
  --private-calendar-cell-color: var(--private-calendar-cell-selection-current-month-color);
}

:host([selection]:not(:where([selection='none']))[month='current']:nth-child(7n - 1)),
:host([selection]:not(:where([selection='none']))[month='current']:nth-child(7n)) {
  --private-calendar-cell-background: var(
    --private-calendar-cell-selection-current-month-weekend-background
  );
  --private-calendar-cell-color: var(--private-calendar-cell-selection-current-month-weekend-color);
}

:host([selection='start'][month='current']:nth-child(7n - 1)),
:host([selection='end'][month='current']:nth-child(7n - 1)),
:host([selection='start'][month='current']:nth-child(7n)),
:host([selection='end'][month='current']:nth-child(7n)) {
  --private-calendar-cell-background: var(
    --private-calendar-cell-selection-current-month-weekend-boundaries-background
  );
}

:host([selection]:not(:where([selection='none']))[month='other']) {
  --private-calendar-cell-background: var(--private-calendar-cell-selection-other-month-background);
  --private-calendar-cell-color: var(--private-calendar-cell-selection-other-month-color);
}

:host(
  [selection]:not(:where([selection='none']))[month='current'][preview]:not([preview='false'])
) {
  --private-calendar-cell-background: var(
    --private-calendar-cell-preselection-current-month-background
  );
  --private-calendar-cell-color: var(--private-calendar-cell-preselection-current-month-color);
}

:host([selection]:not(:where([selection='none']))[month='other'][preview]:not([preview='false'])) {
  --private-calendar-cell-background: var(
    --private-calendar-cell-preselection-other-month-background
  );
  --private-calendar-cell-color: var(--private-calendar-cell-preselection-other-month-color);
}

/* a day alone, chosen or under the pointer, reaches no other day: it has no band */

:host([selection='single']) .area-background {
  background-color: transparent;
}

/* the dot of a chosen day: full */

:host([selection='start'][month='current']),
:host([selection='end'][month='current']:not([preview]:not([preview='false']))),
:host([selection='single'][month='current']:not([preview]:not([preview='false']))) {
  --private-calendar-cell-inner-background: var(
    --private-calendar-cell-selection-current-month-boundaries-background
  );
  --private-calendar-cell-dot-color: var(
    --private-calendar-cell-selection-current-month-boundaries-color
  );
}

:host([selection='start'][month='current']:nth-child(7n - 1)),
:host([selection='start'][month='current']:nth-child(7n)),
:host([selection='end'][month='current']:not([preview]:not([preview='false'])):nth-child(7n - 1)),
:host([selection='end'][month='current']:not([preview]:not([preview='false'])):nth-child(7n)) {
  --private-calendar-cell-dot-color: var(
    --private-calendar-cell-selection-current-month-weekend-boundaries-color
  );
}

:host([selection='start'][month='other']),
:host([selection='end'][month='other']:not([preview]:not([preview='false']))),
:host([selection='single'][month='other']:not([preview]:not([preview='false']))) {
  --private-calendar-cell-inner-background: var(
    --private-calendar-cell-selection-other-month-boundaries-background
  );
  --private-calendar-cell-dot-color: var(
    --private-calendar-cell-selection-other-month-boundaries-color
  );
}

/* the dot of the day under the pointer, not chosen yet: a ring */

:host([selection='end'][month='current'][preview]:not([preview='false'])),
:host([selection='single'][month='current'][preview]:not([preview='false'])) {
  --private-calendar-cell-inner-background: var(
    --private-calendar-cell-preselection-current-month-boundaries-background
  );
  --private-calendar-cell-dot-color: var(
    --private-calendar-cell-preselection-current-month-boundaries-color
  );
  --private-calendar-cell-dot-ring: var(
    --private-calendar-cell-preselection-current-month-boundaries-border-color
  );
}

:host([selection='end'][month='other'][preview]:not([preview='false'])),
:host([selection='single'][month='other'][preview]:not([preview='false'])) {
  --private-calendar-cell-inner-background: var(
    --private-calendar-cell-preselection-other-month-boundaries-background
  );
  --private-calendar-cell-dot-color: var(
    --private-calendar-cell-preselection-other-month-boundaries-color
  );
  --private-calendar-cell-dot-ring: var(
    --private-calendar-cell-preselection-other-month-boundaries-border-color
  );
}

