/*
 * Copyright (c) 2010, 2026 BSI Business Systems Integration AG
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 */
.calendar-icon(@icon, @size) {
  #scout.font-icon();
  display: inline-block;
  position: relative;
  font-size: @size;
  width: 29px;
  content: @icon;
  color: @icon-color;
  text-align: center;
}

.calendar {
  white-space: nowrap;
  padding-left: 0;
}

.calendar-scrollable-components {
  height: 100%;
}

.calendar-header {
  position: relative;
  display: block;
  white-space: nowrap;
  padding: 8px @root-group-box-padding-right 12px 0;

  & > .busyindicator-label {
    display: table-cell;
    vertical-align: middle;
    text-indent: 0;
  }

  &.mobile {
    padding-right: @calendar-padding-right-mobile;
  }
}

.calendar-header-row {
  display: table;
  width: 100%;

  &.last {
    padding-top: 10px;
  }
}

.calendar-range {
  display: table-cell;
  vertical-align: middle;
  padding-left: 8px;
  width: 1%;
}

.calendar-previous,
.calendar-today,
.calendar-next {
  cursor: pointer;
  display: inline-block;
  vertical-align: middle;
  white-space: nowrap;
  text-align: center;
  height: @calendar-header-button-height;
  color: @text-color;
  background-color: @button-background-color;
  border: 1px solid @control-border-color;
  border-radius: @button-border-radius;
  margin-right: 5px;
  line-height: @calendar-header-button-height - 1px;

  &:hover {
    color: @hover-color;
  }
}

.calendar-today {
  padding-left: 15px;
  padding-right: 15px;
}

.calendar-title {
  display: table-cell;
  vertical-align: middle;
  color: @calendar-title-color;

  .calendar-header-row.last > & {
    text-align: center;
  }
}

.calendar-select {
  display: inline-block;
  vertical-align: middle;
  text-align: center;
  font-size: 16px;
  margin-left: 15px;
  margin-right: 15px;
}

.calendar-previous:hover::before,
.calendar-next:hover::before {
  color: @hover-color;
}

.calendar-previous::before {
  .calendar-icon(@icon-angle-left, 20px);
}

.calendar-next::before {
  .calendar-icon(@icon-angle-right, 20px);
}

.calendar-commands {
  display: table-cell;
  vertical-align: middle;
  text-align: right;
  white-space: nowrap;
}

.calendar-mode,
.calendar-toggle-sidebar,
.calendar-toggle-list {
  display: inline-block;
  vertical-align: middle;
  text-align: center;
  height: @calendar-header-button-height;
  line-height: @calendar-header-button-height - 1px;
  cursor: pointer;
}

.calendar-mode {
  padding: 0 8px;
  min-width: 65px;

  border-top: 1px solid @control-border-color;
  border-bottom: 1px solid @control-border-color;
  border-left: 1px solid @control-border-color;

  &.first {
    border-left: 1px solid @control-border-color;
    border-top-left-radius: @button-border-radius;
    border-bottom-left-radius: @button-border-radius;
  }

  &.last {
    border-right: 1px solid @control-border-color;
    border-top-right-radius: @button-border-radius;
    border-bottom-right-radius: @button-border-radius;
    margin-right: 5px;
  }

  &:hover {
    color: @hover-color;
  }

  &.selected {
    color: @calendar-mode-selected-color;
    background-color: @calendar-mode-selected-background-color;
  }
}

.calendar-mode-menu {
  padding: 5px 12px;
  border: 1px solid @control-border-color;
  border-radius: @button-border-radius;
}

.calendar-toggle-sidebar,
.calendar-toggle-list {
  margin-left: 5px;

  &:hover::before {
    color: @hover-color;
  }
}

.calendar-toggle-sidebar::before {
  .calendar-icon(@icon-calendar, 18px);
}

.calendar-toggle-list::before {
  .calendar-icon(@icon-list, 18px);
}

.calendar-component {
  display: flex;
  flex-direction: row;
  position: relative;
  float: left;
  line-height: 24px;
  height: 24px;
  min-height: 20px;
  width: calc(~'100% - ' @calendar-component-margin-left);
  text-align: left;
  color: @calendar-component-color;

  & > .content {
    #scout.overflow-ellipsis();

    & > .icon {
      padding-right: 3px;
      font-size: 14px;
      display: inline-block;
      min-width: 20px;
    }

    & > .subject {
      vertical-align: top;
    }
  }

  & > .calendar-component-leftcolorborder {
    flex-shrink: 0;
    top: 0;
    left: 0;
    width: 4px;
    margin-right: 4px;
    background-color: @palette-blue-1; /* Default colors used when component has no specific class */
  }

  /* Default colors used when component has no specific class */
  background-color: @palette-blue-0;

  &:hover {
    background-color: @palette-blue-1;

    & > .calendar-component-leftcolorborder {
      background-color: @palette-blue-3;
    }
  }

  &.comp-selected {
    background-color: @palette-blue-2;

    & > .calendar-component-leftcolorborder {
      background-color: @palette-blue-3;
    }
  }

  /* Colors for type Appointment */

  &.calendar-appointment {
    background-color: @palette-orange-0;

    & > .calendar-component-leftcolorborder {
      background-color: @palette-orange-2;
    }

    &:hover {
      background-color: @palette-orange-1;

      & > .calendar-component-leftcolorborder {
        background-color: @palette-orange-3;
      }
    }

    &.comp-selected {
      background-color: @palette-orange-2;

      & > .calendar-component-leftcolorborder {
        background-color: @palette-orange-3;
      }
    }
  }

  /* Colors for type Task */

  &.calendar-task {
    background-color: @palette-green-0;

    & > .calendar-component-leftcolorborder {
      background-color: @palette-green-2;
    }

    &:hover {
      background-color: @palette-green-1;

      & > .calendar-component-leftcolorborder {
        background-color: @palette-green-2;
      }
    }

    &.comp-selected {
      background-color: @palette-green-2;

      & > .calendar-component-leftcolorborder {
        background-color: @palette-green-3;
      }
    }
  }

  &.dragged {
    opacity: 0.5;
    z-index: 10; // High z-index to overlap all other components
  }
}

.widget-popup > .calendar-component-tooltip-content.tooltip-content {
  padding: 0;
  #scout.font-text-normal();
  max-width: 300px;
  max-height: 500px;
}

.calendar-component-header {
  padding: 18px 18px 10px 18px;
  background-color: @table-header-background-color;

  &:not(.with-description) {
    padding-bottom: 18px;
  }
}

.calendar-component-title-label {
  color: @top-label-color;
  font-size: @top-label-font-size;
  padding-bottom: @top-label-border-padding-bottom;
}

.calendar-component-title {
  font-weight: bold;
  font-size: @font-size-plus;
  #scout.overflow-ellipsis-nowrap();
}

.calendar-component-intro {
  font-size: 11px;
  margin-top: 9px;
  color: @calendar-component-intro-color;

  & > .icon {
    padding-right: 9px;
    display: inline-block;
    font-size: 12px;
    line-height: 15px;
    min-width: 27px;
    text-align: center;
    vertical-align: middle;
  }
}

.calendar-component-description-container {
  padding: 10px 18px 18px 18px;
}

.calendar-component-description-element {

  display: flex;
  align-items: center;

  & > .icon {
    padding-right: 9px;
    display: inline-block;
    min-width: 27px;
    vertical-align: top;
    text-align: center;
  }

  & > .text {
    display: inline-block;
    vertical-align: top;
    word-wrap: break-word;
    word-break: break-word;
  }

  &:not(.first) {
    padding-top: 10px;
    border-top: 1px solid @tooltip-border-color;
  }

  &:not(.last) {
    padding-bottom: 10px;
  }
}

.calendar-list-container {
  display: inline-block;
  vertical-align: top;
  width: 0;
  padding: 0;
  overflow: hidden;
}

.calendar-list {
  width: 270px;
  padding: 0 0 0 30px;
  height: 100%;

  & > .calendar-component {
    cursor: pointer;
    height: auto;
    width: calc(~'100% - 10px');
    background-color: transparent !important; /* NOSONAR (required to override original component background color) */
    margin-top: 12px;
    color: @text-color;

    & > .content {
      width: 100%;
      white-space: normal;
      line-height: normal;
    }
  }
}

.calendar-list-title {
  position: relative;
  width: calc(~'100% - 10px');
  height: @calendar-title-height;
  line-height: @calendar-title-height;
  font-weight: bold;
  color: @text-color;

  &::after {
    position: absolute;
    height: 1px;
    width: 100%;
    left: 0;
    bottom: -1px;
    content: '';
    background-color: @border-color;
  }
}

.calendar-grids {
  display: inline-block;
  vertical-align: top;
  overflow: hidden;

  --min-full-day-components: 2;
  --max-full-day-components: 4;
  --full-day-components: 0;
  --day-of-month-height: 30px; // CalendarComponent.DAY_OF_MONTH_HEIGHT
  --component-height: 24px; // CalendarComponent.COMPONENT_HEIGHT
  --component-vgap: 2px; // CalendarComponent.COMPONENT_VGAP
  --component-height-with-gap: calc(var(--component-height) + var(--component-vgap));
  --top-grid-height: calc(@calendar-title-height
  + var(--day-of-month-height)
  + (max(min(var(--full-day-components), var(--max-full-day-components)), var(--min-full-day-components)) * var(--component-height-with-gap))// number of full day components, bounded by min and max
  - (min(max(var(--full-day-components), var(--min-full-day-components)), 1) * var(--component-vgap))// remove additional gap after the last full day component if there is one
  + 1px); // border

  &.calendar-grids-month {
    --top-grid-height: @calendar-title-height + 1px;
  }
}

.calendar-grid {
  display: block;
  height: calc(~'100% - ' var(--top-grid-height));
  padding-right: @root-group-box-padding-right;

  & + .scroll-shadow {
    --scroll-shadow-inset-right: @root-group-box-padding-right;
  }

  &.mobile {
    padding-right: @calendar-padding-right-mobile;

    & + .scroll-shadow {
      --scroll-shadow-inset-right: @calendar-padding-right-mobile;
    }
  }
}

.calendar-top-grid {
  display: block;
  overflow: hidden;
  border-bottom: 1px solid @border-color;
  height: var(--top-grid-height);
  margin-right: @root-group-box-padding-right;

  &.mobile {
    margin-right: @calendar-padding-right-mobile;
  }
}

.calendar-week-header,
.calendar-week {
  display: block;
  width: 100%;
  white-space: nowrap;
}

.calendar-week-allday-container {
  height: calc(~'100% - ' @calendar-title-height);
}

.calendar-week-allday-container > .calendar-week-name {
  height: calc(~'100% - ' @calendar-title-height - 9px);
}

.calendar-week-allday-container > .calendar-day > .resource-column {
  padding-top: 30px; // for the day-of-month number
}

.calendar-week-header,
.calendar-week-header > .calendar-day-name,
.calendar-week-header > .calendar-week-name,
.calendar-week-header > .calendar-day-name > .resource-column {
  height: @calendar-title-height;
}

.calendar-week {
  position: relative;
  overflow: hidden;
}

.calendar-week-name {
  width: @calendar-week-name-width;
}

.calendar-day-name,
.calendar-week-name,
.calendar-day,
.resource-column {
  position: relative;
  display: inline-block;
  overflow: hidden;
  z-index: 1; /* draw over grid */
}

.calendar-day {
  padding: 0;
  height: 100%;

  &:not(.calendar-no-label)::before {
    position: absolute;
    content: attr(data-day-name);
    color: @calendar-day-color;
    left: 7px;
    top: 7px;
    z-index: 1; /* draw over calendar items */
  }

  &.out {
    background-color: @calendar-out-background-color;

    &::before {
      color: @calendar-out-color;
    }
  }

  &.weekend::before {
    color: @calendar-weekend-color;
  }

  &.weekend-out {
    background-color: @calendar-weekend-out-background-color;

    &::before {
      color: @calendar-weekend-out-color;
    }
  }

  &.now::before {
    color: @highlight-color;
    font-weight: bold;
  }

  /* helps to center days between 10 and 19 nicer */

  &.selected.center-nice::before {
    padding-right: 2px;
  }

  & .calendar-component {
    margin-left: @calendar-component-margin-left;
    margin-bottom: 1px;
    margin-top: 1px;

    &.component-month.compact {
      top: 30px;
      margin-left: 0;
      width: 100%;
    }

    &.component-day,
    &.component-task {
      position: absolute;
      word-break: break-all;
      left: 0;
      margin: 0;
      width: 100%;
      height: 24px;
      line-height: 24px;
    }

    &.component-open-top {
      overflow: visible;
      padding-top: 10px;

      /* Compensate for open top padding */

      & > .calendar-component-leftcolorborder {
        height: calc(~'100% + 10px');
        top: -10px;
        position: relative;
      }

      &::before {
        position: absolute;
        display: block;
        content: '';
        width: 16px;
        height: 16px;
        left: calc(~'50% - 8px');
        top: -8px;
        transform: rotate(45deg);
        background-color: @background-color;
      }
    }

    &.component-open-bottom {
      overflow: visible;
      border-bottom: none; /* Compensate for calendar-component border */

      &::after {
        position: absolute;
        display: block;
        content: '';
        width: 16px;
        height: 16px;
        left: calc(~'50% - 8px');
        bottom: -8px;
        transform: rotate(45deg);
        background-color: inherit;
      }
    }
  }
}

.calendar-day.selected.now::before {
  left: 4px;
  top: 3px;
  font-weight: normal;
  border: solid 4px @highlight-inverted-background-color;
  border-radius: 50%;
  background-color: @highlight-inverted-background-color;
  color: @palette-white;
}

.calendar-day.selected::before {
  text-align: center;
  left: 4px;
  top: 3px;
  width: @calendar-day-selected-circle-size;
  height: @calendar-day-selected-circle-size;
  border: solid 4px @calendar-day-selected-background-color;
  border-radius: 50%;
  background-color: @calendar-day-selected-background-color;
  color: @calendar-day-selected-color;
}


.calendar-week-name {
  font-size: 11px;
  color: @calendar-week-axis-color;
  padding-top: 9px;
  text-align: center;
}

.calendar-day::after,
.calendar-day-name::after,
.resource-column::after {
  position: absolute;
  width: 1px;
  height: 100%;
  left: 0;
  top: 0;
  content: '';
  background-color: @border-color;
}

.calendar-week:not(.calendar-week-noborder)::after {
  position: absolute;
  height: 1px;
  width: 100%;
  left: 0;
  top: 0;
  content: '';
  background-color: @border-color;
}

.calendar-day-name::before {
  position: absolute;
  content: attr(data-day-name);
  color: @calendar-day-color;
  left: 7px;
  bottom: 0;
  z-index: 1; /* draw over calendar items */
  line-height: @calendar-title-height;
}

.calendar-week-axis {
  position: absolute;
  left: @calendar-week-name-width - @calendar-week-axis-overlap;
  width: calc(~'100% - @{calendar-week-name-width} + @{calendar-week-axis-overlap}');

  &:not(.first) {
    &::after {
      position: absolute;
      height: 1px;
      width: 100%;
      content: '';
      background-color: @calendar-light-line-color;
    }

    &.hour::after {
      background-color: @calendar-line-color;
    }

    &::before {
      position: absolute;
      font-size: 12px;
      left: -35px;
      top: -8px;
      color: @calendar-week-axis-color;
      content: attr(data-axis-name);
    }
  }
}

.calendar-week-task {
  position: relative;
  left: 0;
  width: 100%;
}

.calendar-week-task::after {
  position: relative;
  height: 1px;
  width: 100%;
  content: '';
  background-color: @border-color;
}

.calendar-week-task::before {
  position: absolute;
  font-size: 11px;
  top: 28px;
  left: 7px;
  color: @calendar-week-axis-color;
  content: attr(data-axis-name);
}

.calendar-range-selector {
  background-color: @selected-background-color;
  position: absolute;
  opacity: 0.3;
  width: 100%;
}

.calendar-day > .resource-column {
  height: 100%;
}

.resource-column::before {
  position: absolute;
  content: attr(data-resource-name);
  color: @calendar-day-color;
  left: 7px;
  bottom: 0;
  z-index: 1; /* draw over calendar items */
  line-height: @calendar-title-height;
}
