/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

:root {
  --border-style: 0.1rem solid;
  --border-radius: 0.3rem;
  --border-color: ButtonBorder;
  --button-text-color: ButtonText;
  --button-text-color-hover: SelectedItemText;
  --button-text-color-active: SelectedItem;
  --button-background: ButtonFace;
  --button-background-hover: SelectedItem;
  --button-background-active: SelectedItemText;
  --button-border-hover: SelectedItem;
  --button-border-active: SelectedItem;
  --today-background: Mark;
  --today-color: MarkText;
  --navigation-arrow-color-hover: SelectedItemText;
  --navigation-arrow-color-active: SelectedItem;
  --navigation-arrow-background-hover: SelectedItem;
  --navigation-arrow-background-active: SelectedItemText;
  --navigation-arrow-border-hover: SelectedItem;
  --navigation-arrow-border-active: SelectedItem;
  --navigation-arrow-fill-opacity: 1;
  --navigation-arrow-fill-opacity-hover: 1;
  --navigation-arrow-fill-opacity-active: 1;
  --calendar-item-background-hover: color-mix(in srgb, FieldText 20%, transparent);

  /* Use -moz-activehyperlinktext to get a system color that
     by default will be closest to Red */
  --weekend-font-color: -moz-activehyperlinktext;

  --disabled-background-color: ButtonShadow;

  /* TODO: these need to be in sync (ish) with DateTimePickerPanel.sys.mjs */
  font-size: 10px;
  --font-size-default: 1.1rem;
  --spinner-width: 3rem;
  --spinner-margin-block: 0.4rem;
  --spinner-item-height: 2.4rem;
  --spinner-item-margin-bottom: 0.1rem;
  --spinner-button-height: 1.8rem;
  --colon-width: 2rem;
  --day-period-spacing-width: 1rem;
  --date-picker-item-height: 2.4rem;
  --date-picker-item-width: 3.3rem;

  /* We need to hide the scroll bar but maintain its scrolling
     capability, so using |overflow: hidden| is not an option. */
  scrollbar-width: none;
}

@media not (prefers-contrast) {
  :root {
    --border-color: color-mix(in srgb, FieldText 65%, transparent);
    --button-text-color: inherit;
    --button-text-color-hover: inherit;
    --button-text-color-active: inherit;
    --button-background: color-mix(in srgb, FieldText 10%, transparent);
    --button-background-hover: color-mix(in srgb, FieldText 20%, transparent);
    --button-background-active: color-mix(in srgb, FieldText 30%, transparent);
    --button-border-hover: var(--border-color);
    --button-border-active: var(--border-color);
    --today-background: color-mix(in srgb, FieldText 30%, transparent);
    --today-color: inherit;
    --navigation-arrow-color-hover: inherit;
    --navigation-arrow-color-active: inherit;
    --navigation-arrow-background-hover: transparent;
    --navigation-arrow-background-active: transparent;
    --navigation-arrow-border-hover: transparent;
    --navigation-arrow-border-active: transparent;
    --navigation-arrow-fill-opacity: 0.5;
    --navigation-arrow-fill-opacity-hover: 0.8;
    --navigation-arrow-fill-opacity-active: 1;
  }
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font: message-box;
  font-size: var(--font-size-default);
  background-color: Field;
  color: FieldText;
}

button {
  appearance: none;
  padding: 0;
  color: var(--button-text-color);
  background: none;
  background-color: var(--button-background);
  background-repeat: no-repeat;
  background-position: center;
  border: var(--border-style) var(--border-color);
  border-radius: var(--border-radius);
  -moz-context-properties: fill, fill-opacity;
  fill: currentColor;
}

button:where(:hover) {
  color: var(--button-text-color-hover);
  background-color: var(--button-background-hover);
  border-color: var(--button-border-hover);
}

button:where(:hover.active) {
  color: var(--button-text-color-active);
  background-color: var(--button-background-active);
  border-color: var(--button-border-active);
}

button:focus-visible {
  outline: 0.2rem solid SelectedItem;
  outline-offset: 0.2rem;
}

#date-picker {
  /* Add some padding so outlines would not overflow our viewport. */
  padding: 0.4rem;
}

.month-year-nav {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.month-year-nav[monthPickerVisible] {
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.month-year-nav > button,
.spinner-container > button {
  background-color: transparent;
  border-color: transparent;
  fill-opacity: var(--navigation-arrow-fill-opacity);
}

.month-year-nav > button {
  height: 2.4rem;
  width: 2.4rem;
}

.month-year-nav > button:hover,
.spinner-container > button:hover {
  color: var(--navigation-arrow-color-hover);
  background-color: var(--navigation-arrow-background-hover);
  border-color: var(--navigation-arrow-border-hover);
  fill-opacity: var(--navigation-arrow-fill-opacity-hover);
}

.month-year-nav > button:hover.active,
.spinner-container > button:hover.active {
  color: var(--navigation-arrow-color-active);
  background-color: var(--navigation-arrow-background-active);
  border-color: var(--navigation-arrow-border-active);
  fill-opacity: var(--navigation-arrow-fill-opacity-active);
}

.month-year-nav > button.prev:dir(ltr),
.month-year-nav > button.next:dir(rtl) {
  background-image: url("chrome://global/skin/icons/arrow-left.svg");
}

.month-year-nav > button.prev:dir(rtl),
.month-year-nav > button.next:dir(ltr) {
  background-image: url("chrome://global/skin/icons/arrow-right.svg");
}

button.month-year {
  font-size: 1.3rem;
  height: var(--date-picker-item-height);
  padding-block: 0.2rem 0.3rem;
  padding-inline: 1.2rem 2.6rem;
  background-image: url("chrome://global/skin/icons/arrow-down.svg");
  background-position-x: right 0.5rem;
}

@media not (prefers-contrast) {
  button.month-year {
    fill-opacity: 0.5;
  }
}

button.month-year:dir(rtl) {
  background-position-x: left 0.5rem;
}

button.month-year:hover {
  color: var(--button-text-color-hover);
  background-color: var(--button-background-hover);
  border-color: var(--button-border-hover);
}

button.month-year.active {
  color: var(--button-text-color-active);
  background-color: var(--button-background-active);
  border-color: var(--button-border-active);
  background-image: url("chrome://global/skin/icons/arrow-up.svg");
}

.month-year-view > .spinner-container {
  width: 5.5rem;
  margin: 2rem 0.5rem;
}

.order-month-year > #spinner-month,
.order-year-month > #spinner-year {
  order: 1;
}

.order-month-year > #spinner-year,
.order-year-month > #spinner-month {
  order: 2;
}

.calendar-container > table {
  display: flex;
  flex-direction: column;
  border-spacing: inherit;
}

.week-header > tr,
.days-view > tr {
  display: flex;
}

.week-header > tr > th {
  opacity: 0.5;
}

.days-view {
  min-height: 15rem;
}

.week-header > tr > th,
.days-view > tr > td {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  font-weight: inherit;
  height: var(--date-picker-item-height);
  width: var(--date-picker-item-width);
  margin: 0.2rem;
  padding: 0;
  border: var(--border-style) transparent;
  border-radius: var(--border-radius);
}

.days-view > tr > td:hover,
.spinner-container > .spinner > div:hover {
  background-color: var(--calendar-item-background-hover);
  border-color: var(--border-color);
}

.days-view > tr > td:focus-visible {
  outline: 0.2rem solid SelectedItem;
  outline-offset: 0.2rem;
}

.days-view > tr > td.today {
  background-color: var(--today-background);
  color: var(--today-color);
  border-color: transparent;
  font-weight: var(--font-weight-bold);
}

.days-view > tr > td.today:hover {
  border-color: var(--border-color);
}

.days-view > tr > td.selection,
.spinner-container > .spinner:not(.scrolling) > div.selection {
  background-color: SelectedItem;
  color: SelectedItemText;
  border-color: transparent;
}

.days-view > tr > td.outside {
  opacity: 0.5;
}

.days-view > tr > td.out-of-range,
.days-view > tr > td.off-step {
  background-color: var(--disabled-background-color);
  border-color: transparent;
}

.weekend {
  color: var(--weekend-font-color);
}

#clear-button {
  height: var(--date-picker-item-height);
  font-size: 1.3rem;
  margin-top: 0.8rem;
  padding-inline: 1.2rem;
}

#time-picker,
.month-year-view {
  display: flex;
  justify-content: center;
}

.spinner-container {
  display: flex;
  flex-direction: column;
  width: var(--spinner-width);
}

.spinner-container > button {
  height: var(--spinner-button-height);

  &.prev {
    background-image: url("chrome://global/skin/icons/arrow-up.svg");
  }

  &.next {
    background-image: url("chrome://global/skin/icons/arrow-down.svg");
  }
}

.spinner-container.hide-buttons > button {
  visibility: hidden;
}

.spinner-container > .spinner {
  position: relative;
  margin-block: var(--spinner-margin-block);
  border-radius: var(--border-radius);
  overflow-y: scroll;
  scrollbar-width: none;
  scroll-snap-type: both mandatory;
}

@media not (prefers-reduced-motion) {
  .spinner-container > .spinner {
    scroll-behavior: smooth;
  }
}

.spinner-container > .spinner:focus-visible {
  outline: 0.2rem solid SelectedItem;
  outline-offset: 0.2rem;
}

.spinner-container > .spinner > div {
  display: flex;
  place-content: center;
  align-items: center;
  box-sizing: border-box;
  margin-bottom: var(--spinner-item-margin-bottom);
  height: var(--spinner-item-height);
  border: var(--border-style) transparent;
  border-radius: var(--border-radius);
  user-select: none;
  scroll-snap-align: start;
}

.spinner-container > .spinner > div.disabled {
  visibility: hidden;
}

/* Used only in <input type="time"> */

.colon {
  display: flex;
  justify-content: center;
  align-items: center;
  width: var(--colon-width);
  margin-bottom: 0.3rem;
  cursor: default;
}

.spacer {
  width: var(--day-period-spacing-width);
}

#datetime-picker {
  display: flex;
  gap: 1em;
}

#date-picker,
#time-picker {
  min-width: 0;
}
