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


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


/**
 * @prop --mds-input-date-range-background: Public. Sets the background-color of the component
 * @prop --mds-input-date-range-calendar-width: Sets the width of each calendar shown in the dropdown
 * @prop --mds-input-date-range-fields-firefox-justify-content: Sets the justify-content of the component in Firefox
 * @prop --mds-input-date-range-fields-gap: Public. Sets the gap between the fields of the component
 * @prop --mds-input-date-range-icon-color: Sets the icon color of the component
 * @prop --mds-input-date-range-ring: Public. Sets the box-shadow of the component's input to perform the ring effect
 * @prop --mds-input-date-range-shadow: Public. Sets the box-shadow of the component's input
 * @prop --mds-input-date-range-variant-color-rgb: Public. Sets the variant colors of the component
 */

/* ❌ Not supported
@property --mds-input-date-range-ring {
  inherits: false;
  initial-value: 0 0 0 1px rgb(var(--mds-input-date-range-variant-color-rgb) / 0.1);
  syntax: "<box-shadow>";
}

@property --mds-input-date-range-shadow {
  inherits: false;
  initial-value: 0 1px 3px 0 rgb(var(--mds-input-date-range-variant-color-rgb) / 0.1), 0 1px 2px 0 rgb(var(--mds-input-date-range-variant-color-rgb) / 0.06);
  syntax: "<box-shadow>";
}
*/

:host {

  /* the size of the field, lg by default: its height and its padding; the calendar button sits
     in a square as tall as the field */
  --private-input-date-range-height: --spacing(1200);
  --private-input-date-range-padding-inline: --spacing(400);
  --private-input-date-range-calendar-area: --spacing(1200);

  /* a field stands a step off its surface: overlay on a page, the step below inside an overlay
     surface, which passes it as --magma-field-fill (#1193) */
  --mds-input-date-range-background: rgb(var(--magma-field-fill, var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255))));
  --mds-input-date-range-calendar-width: --spacing(8800);
  --mds-input-date-range-fields-firefox-justify-content: start;
  --mds-input-date-range-fields-gap: 0 --spacing(200);
  --mds-input-date-range-icon-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  --mds-input-date-range-ring: 0 0 0 1px rgb(var(--mds-input-date-range-variant-color-rgb, 0 0 0) / 0.1);
  --mds-input-date-range-shadow:
    0 1px --spacing(75) 0 rgb(var(--mds-input-date-range-variant-color-rgb, 0 0 0) / 0.1),
    0 1px --spacing(50) 0 rgb(var(--mds-input-date-range-variant-color-rgb, 0 0 0) / 0.06);
  --mds-input-date-range-variant-color-rgb: 0 0 0;
  --mds-input-date-range-transition-duration: var(--duration-300, 300ms);

  /* private */
  --private-input-date-range-transition-duration: var(--mds-input-date-range-transition-duration);

  @apply text-info-detail;

  /* capped at a part of the height of the field like mds-button's (#913) */
  border-radius: min(
    var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px)),
    var(--magma-corner-cap, 0.5) * var(--private-input-date-range-height)
  );
  color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  container-type: inline-size;
  corner-shape: var(--magma-corner-shape, squircle);
  cursor: text;
  display: flex;
  gap: --spacing(200);
  overflow: visible;
  position: relative;
}

.date-preselection {
  display: grid;
  gap: --spacing(200);
}

.inputs {
  @apply text-code-hack;

  align-items: center;
  background-color: var(--mds-input-date-range-background, rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255))));
  border: 0;
  border-radius: inherit;
  box-shadow: var(--mds-input-date-range-ring), var(--mds-input-date-range-shadow);
  box-sizing: border-box;
  color: inherit;
  corner-shape: inherit;
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--mds-input-date-range-fields-gap, 0 --spacing(200));
  margin: 0;
  min-height: var(--private-input-date-range-height);
  overflow: hidden;
  padding-left: var(--private-input-date-range-padding-inline);
  padding-right: var(--private-input-date-range-calendar-area);
  text-overflow: ellipsis;
  transition-duration: var(--private-input-date-range-transition-duration);
  transition-property:
    background-color, border-color, box-shadow, color, fill, margin, opacity, padding, transform;
  transition-timing-function: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
  width: 100%;
}

.input-element {
  align-items: baseline;
  display: inline-flex;
}

:host(:focus-within) .inputs {
  @apply outline-hidden transition-cosmetic;

  --mds-input-date-range-ring: 0 0 0 --spacing(75) rgb(var(--mds-input-date-range-variant-color-rgb, 0 0 0) / 1);
  --mds-input-date-range-shadow:
    0 --spacing(100) --spacing(150) --spacing(75) rgb(var(--mds-input-date-range-variant-color-rgb, 0 0 0) / 0.1),
    0 --spacing(50) --spacing(100) -1px rgb(var(--mds-input-date-range-variant-color-rgb, 0 0 0) / 0.06);

  transition-duration: var(--duration-300, 300ms);
  transition-timing-function: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
}

.input-wrapper {
  display: flex;
  flex-shrink: 0;
}

:host ::slotted(mds-input-date) {
  color: inherit;
}

.date-label {
  margin-left: --spacing(50);
  margin-right: --spacing(50);
  min-width: min-content;
  white-space: nowrap;
}

.date-label:first-child {
  margin-left: 0;
}

/* the panel: the header with the two ends of the range over the calendars */

.panel {
  display: grid;
  gap: --spacing(200);
}

/* the two ends share the width of the header, each growing from its own text: split in equal
   halves, "End: Pick a date" lost its last word beside a short start in a single calendar */

.ends mds-tab-item {
  flex: 1 1 auto;
  min-width: 0;
}

.calendars {
  display: flex;
  flex-wrap: nowrap;
  gap: --spacing(200);
  min-width: max-content;
}

.calendar-preselection-panel {
  align-content: start;
  background-color: rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225)));
  border-radius: var(--magma-radius-lg, var(--radius-squircle-lg, 28px));
  box-sizing: border-box;
  display: grid;
  min-inline-size: max-content;
  padding: --spacing(400);
}

.calendar-single {
  display: flex;
  flex-wrap: nowrap;
  gap: --spacing(200);
  min-width: max-content;
}

.calendar-single mds-calendar,
.calendars mds-calendar {
  flex: 0 0 var(--mds-input-date-range-calendar-width, --spacing(8800));
  inline-size: var(--mds-input-date-range-calendar-width, --spacing(8800));
  max-inline-size: var(--mds-input-date-range-calendar-width, --spacing(8800));
  min-inline-size: var(--mds-input-date-range-calendar-width, --spacing(8800));
}

.action-open-calendar-wrapper {
  align-items: center;
  aspect-ratio: 1;
  bottom: 0;
  display: flex;
  justify-content: center;
  position: absolute;
  right: 0;
  top: 0;
}

.action-open-calendar {
  --mds-button-color: var(--mds-input-date-range-icon-color, rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255))));

  /* mds-button aligns itself flex-start on its :host: re-center it inside the
     48px square wrapper so the icon sits on the input's vertical axis. */
  align-self: center;
}

mds-dropdown {
  padding: 0;
}

/* :disabled also covers a disabled fieldset around the range, which sets no attribute */

:host([disabled]:not([disabled='false'])),
:host(:disabled:not([disabled='false'])) {
  color: rgb(var(--magma-text-disabled, var(--text-neutral-disabled, 119 119 119)));
  cursor: default;
}

:host([disabled]:not([disabled='false'])) .inputs,
:host(:disabled:not([disabled='false'])) .inputs {
  background-color: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
}

/* The size of the field, with the heights of mds-button: md 36px and sm 28px here, lg 48px in
 * the base sheet. The calendar button sits in a square as tall as the field: the default md
 * button fills the one of an md field, an sm field gets an sm button (see the render). */

:host([size='md']) {
  --private-input-date-range-height: --spacing(900);
  --private-input-date-range-padding-inline: --spacing(300);
  --private-input-date-range-calendar-area: --spacing(1000);
}

:host([size='sm']) {
  --private-input-date-range-height: --spacing(700);
  --private-input-date-range-padding-inline: --spacing(200);
  --private-input-date-range-calendar-area: --spacing(800);
}

/* Motion, held back.
 *
 * Every component zeroes the private durations its own base CSS reads, which composes
 * with the public knobs - but that only reaches the declarations that read them. An audit
 * of the 52 sheets found 21 transitions in 15 components that did not: the host's own
 * transition in mds-button and mds-table, the focus ring of the input family, the tab
 * slider, the close button of mds-note. This reset reaches the whole shadow tree, which is
 * what the preference promises, and keeps reaching it when a declaration is added.
 *
 * Transitions only, on purpose. A keyframe animation is usually a loader, and a loader has
 * to keep saying "working": mds-spinner slows to 8s under reduced motion instead of
 * freezing, and a duration of nearly zero on an infinite animation would spin it out of
 * control instead of stopping it.
 *
 * 0.01ms rather than 0s, so a component that waits for its own transitionend still gets
 * one: mds-modal, mds-push-notification and mds-tree-item all listen for it, and a
 * transition of zero never fires it. */

/* stylelint-disable time-min-milliseconds -- the floor is there to keep a transition
   perceivable; the point of these two is that it is not. */

:host([pref-animation='reduce']),
:host([pref-animation='reduce']) *,
:host([pref-animation='reduce']) *::before,
:host([pref-animation='reduce']) *::after {
  transition-duration: 0.01ms !important;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host([pref-animation='system']) *,
  :host([pref-animation='system']) *::before,
  :host([pref-animation='system']) *::after,
  :host(:not([pref-animation])),
  :host(:not([pref-animation])) *,
  :host(:not([pref-animation])) *::before,
  :host(:not([pref-animation])) *::after {
    transition-duration: 0.01ms !important;
  }
}

/* stylelint-enable time-min-milliseconds */


/* Animation preference. The component mirrors the resolved mode from <html>
 * onto its host as pref-animation (see subscribePreference in @common/preference);
 * these plain shadow selectors then zero the private duration(s) the base CSS
 * reads. `reduce` always stops; `system` and no controller follow the OS via
 * @media; `no-preference` keeps the base value. Customization composes (the base
 * sets --private from the public token, this only overrides it when reduced). */

:host([pref-animation='reduce']) {
  --private-input-date-range-transition-duration: 0s;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host(:not([pref-animation])) {
    --private-input-date-range-transition-duration: 0s;
  }
}

/* Theme preference. The component reflects the resolved theme mode and scheme
 * from <html> onto its host as pref-mode + pref-theme-scheme (see
 * subscribePreference in @common/preference); these plain shadow selectors refine
 * for dark. `dark` is the explicit choice; `system` and no controller follow the
 * OS via @media; the scheme axis gates it. Cross-browser, no :host-context. */

:host([pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-theme-scheme='dark']) {
  --mds-input-date-range-ring: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));

  .counter-button:hover {
    --mds-button-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
  }
}

@media (prefers-color-scheme: dark) {
  :host([pref-mode='system']:not([pref-theme-scheme='light'])),
  :host(:not([pref-mode]):not([pref-theme-scheme='light'])) {
    --mds-input-date-range-ring: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));

    .counter-button:hover {
      --mds-button-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
    }
  }
}

/* Contrast preference. The component reflects the resolved mode from <html> onto
 * its host as pref-contrast (see subscribePreference in @common/preference); these
 * plain shadow selectors refine for high contrast. `more` is the explicit choice;
 * `system` and no controller follow the OS via @media. Cross-browser, no :host-context.
 *
 * The placeholder names --magma-text-subtle on purpose: under pref-contrast-more the
 * layer promotes it to the muted step, darker than at rest but still below the
 * value, which text-default carries (text-muted would be promoted to it). */

:host([pref-contrast='more']) {
  --mds-input-date-range-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
  --mds-input-date-range-background: rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225)));

  .input::placeholder {
    color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
  }
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-input-date-range-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
    --mds-input-date-range-background: rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225)));

    .input::placeholder {
      color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
    }
  }
}

/* The slotted mds-input-date fields hide the native calendar button of Firefox themselves, so
   the custom calendar button of the range stays visible, as in Chromium (#1235). */

@supports (-moz-appearance: none) {
  .inputs {
    justify-content: var(--mds-input-date-range-fields-firefox-justify-content, start);
  }
}

:host {
  --mds-input-date-range-icon-color: rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)));
  --mds-input-date-range-variant-color-rgb: 0 0 0;
}

:host(:focus-within) {
  --mds-input-date-range-icon-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  --mds-input-date-range-variant-color-rgb: var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255));
}

:host([variant='ai']) {
  --mds-input-date-range-icon-color: rgb(var(--magma-accent-ai-emphasis, var(--variant-ai-04, 128 78 232)));
  --mds-input-tip-background: rgb(var(--magma-accent-ai-fg, var(--variant-ai-03, 105 49 204)));
  --mds-input-date-range-variant-color-rgb: 0 0 0;
}

:host([variant='ai']:focus-within) {
  --mds-input-date-range-icon-color: rgb(var(--magma-accent-ai-fg, var(--variant-ai-03, 105 49 204)));
  --mds-input-date-range-variant-color-rgb: var(--magma-accent-ai-emphasis, var(--variant-ai-04, 128 78 232));
}

:host([variant='info']) {
  --mds-input-date-range-icon-color: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
  --mds-input-tip-background: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
  --mds-input-date-range-variant-color-rgb: 0 0 0;
}

:host([variant='info']:focus-within) {
  --mds-input-date-range-icon-color: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
  --mds-input-date-range-variant-color-rgb: var(--magma-info-emphasis, var(--status-info-04, 0 119 164));
}

:host([variant='success']) {
  --mds-input-date-range-icon-color: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
  --mds-input-tip-background: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
  --mds-input-date-range-variant-color-rgb: 0 0 0;
}

:host([variant='success']:focus-within) {
  --mds-input-date-range-icon-color: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
  --mds-input-date-range-variant-color-rgb: var(--magma-success-emphasis, var(--status-success-04, 0 128 57));
}

:host([variant='warning']) {
  --mds-input-date-range-icon-color: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
  --mds-input-tip-background: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
  --mds-input-date-range-variant-color-rgb: 0 0 0;
}

:host([variant='warning']:focus-within) {
  --mds-input-date-range-icon-color: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
  --mds-input-date-range-variant-color-rgb: var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0));
}

:host([variant='error']) {
  --mds-input-date-range-icon-color: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-input-tip-background: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-input-date-range-variant-color-rgb: 0 0 0;
}

:host([variant='error']:focus-within) {
  --mds-input-date-range-icon-color: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-input-date-range-variant-color-rgb: var(--magma-danger-emphasis, var(--status-error-04, 196 64 65));
}

