//* Calendar
//================================================== *

.calendar {
  background-color: $calendar-bg-color;
  display: flex;
  height: 100%;
  overflow: auto;
  vertical-align: top;
  width: 100%;

  // The event container
  .calendar-events {
    border-right: 1px solid $calendar-line-color;
    border-top: 1px solid $calendar-line-color;
    display: inline-block;
    flex: 0 0 auto;
    height: 100%;
    margin-right: -1px;
    min-height: 235px;
    overflow: auto;
    vertical-align: top;
    width: 220px;

    .accordion {
      border-inline: 0;
    }

    .accordion-header a {
      @include font-size(16);
    }

    .accordion-header > a {
      padding-bottom: 14px;
    }

    .accordion-header > button {
      margin: 5px 0 10px 10px;

      svg {
        top: 0;
      }
    }

    .accordion-header {
      border-inline: 0;

      &.is-focused {
        &:not(.hide-focus) {
          border-top-color: $accordion-focused-border-color;
        }
      }
    }
  }

  .calendar-event-legend {
    display: none;
  }

  // Changes to the monthview container
  .calendar-monthview {
    background-color: $calendar-bg-color;
    flex: 1 1 auto;

    &.monthview {
      &.hidden {
        ~ .calendar-event-details {
          @media (max-width: ($breakpoint-wide-tablet - 1)) {
            display: none;
          }
        }
      }
    }

    .monthview-table {
      table-layout: fixed;
    }

    .monthview-header {
      height: 50px;
      background-color: $calendar-bg-color;
      position: -webkit-sticky;
      position: sticky;
      top: 0;
      z-index: 3;
    }

    .monthview-legend {
      padding: 25px 5px 15px;
    }
  }

  // Mobile Legend
  @include respond-to(phabletdown) {
    .calendar-monthview {
      .monthview-legend {
        padding: 10px 5px;
      }
    }

    .calendar-event-legend {
      display: block;
      padding: 20px 20px 0;

      .calendar-event-legend-item {
        display: inline-block;
        margin: 0 20px 10px 0;

        .calendar-event-legend-swatch {
          border-radius: 50px;
          display: inline-block;
          height: 12px;
          margin-right: 5px;
          width: 12px;

          &.ruby {
            background-color: $ids-color-palette-ruby-60;
          }

          &.amber {
            background-color: $ids-color-palette-amber-60;
          }

          &.emerald {
            background-color: $ids-color-palette-emerald-60;
          }

          &.azure {
            background-color: $ids-color-palette-azure-60;
          }

          &.turquoise {
            background-color: $ids-color-palette-turquoise-60;
          }

          &.amethyst {
            background-color: $ids-color-palette-amethyst-60;
          }

          &.slate {
            background-color: $ids-color-palette-slate-60;
          }

          &.graphite {
            background-color: $ids-color-palette-graphite-60;
          }
        }

        .calendar-event-legend-text {
          @include font-size(12);

          color: $datepicker-day-color;
          position: relative;
          top: -2px;
        }
      }
    }
  }

  .calendar-weekview {
    flex: 1 1 auto;
  }

  .calendar-event-types,
  .calendar-event-filters {
    margin-bottom: -3px;
    margin-right: 5px;

    &.event-tree {
      padding-left: 10px;

      .tree ul {
        a {
          display: inline-block;
          width: calc(90%);
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          padding-left: 0;
          margin-left: 0;

          &.is-disabled {
            color: $tree-disabled-color;
          }
        }

        li {
          margin-left: 4px;

          &.is-selected > a .tree-checkbox {
            &::before {
              background-color: transparent;
              border-color: $checkbox-color-unchecked-initial-border;
            }

            &::after {
              border-color: $ids-color-palette-slate-60;
            }
          }
        }
      }
    }

    .checkbox-label {
      margin: $label-size-regular-margin;
    }

    .tree li.is-selected > a {
      background-color: transparent;
    }
  }

  .calendar-event-more {
    @include font-size(11);

    color: $font-color-extrahighcontrast;
    display: block;
    height: 18px;
    margin: 3px 10px 0;
    text-align: left;
    width: auto;

    span {
      cursor: pointer;
    }
  }

  // The upcoming event details section
  .calendar-upcoming-events.accordion-content {
    padding: 5px 0 15px 12px !important; //so it works on RTL
  }

  .calendar-upcoming-event {
    border: 1px solid transparent;
    border-bottom: 1px solid $calendar-line-color;
    color: $font-color-extrahighcontrast;
    cursor: pointer;
    display: block;
    margin: -5px 0 5px -12px;
    padding: 0 10px 10px;
    text-decoration: none;

    &:focus {
      border-color: $ids-color-brand-primary-base !important;
      box-shadow: 0 0 4px 1px $focus-box-shadow-color;
      outline: none;
    }

    .calendar-upcoming-date {
      display: block;
      font-size: $ids-size-font-base;
      padding: 10px;
    }

    .calendar-upcoming-event-color {
      background-color: $ids-color-palette-azure-60;
      border: 1px solid transparent;
      border-radius: 50%;
      color: transparent;
      display: inline-block;
      font-size: 0;
      height: 8px;
      margin-left: 10px;
      vertical-align: top;
      width: 8px;

      &.ruby {
        background-color: $ids-color-palette-ruby-60;
      }

      &.amber {
        background-color: $ids-color-palette-amber-60;
      }

      &.emerald {
        background-color: $ids-color-palette-emerald-60;
      }

      &.azure {
        background-color: $ids-color-palette-azure-60;
      }

      &.turquoise {
        background-color: $ids-color-palette-turquoise-60;
      }

      &.amethyst {
        background-color: $ids-color-palette-amethyst-60;
      }

      &.slate {
        background-color: $ids-color-palette-slate-60;
      }

      &.graphite {
        background-color: $ids-color-palette-graphite-60;
      }
    }

    .calendar-upcoming-description {
      display: inline-block;
      font-size: $ids-size-font-sm;
      left: 5px;
      overflow-wrap: break-word;
      position: relative;
      top: -4px;
      width: 110px;
    }

    .calendar-upcoming-status-text {
      display: block;
      font-size: $ids-size-font-sm;
      font-style: italic;
      left: 25px;
      position: relative;
      top: 2px;

      &:empty + .calendar-upcoming-duration {
        top: -18px;
      }
    }

    .calendar-upcoming-duration {
      display: block;
      float: right;
      font-size: $ids-size-font-sm;
      font-style: italic;
      position: relative;
      right: 0;
      top: -12px;
    }
  }

  .calendar-event-details-mobile.listview {
    li:first-child {
      border-top: 1px solid $calendar-line-color;
    }

    li {
      border-bottom-color: $calendar-line-color;
    }

    @media (min-width: $breakpoint-wide-tablet) {
      display: none !important;
    }
  }
}

// Calendar Event Details section
.calendar-event-details {
  background-color: $body-color-primary-background;
  border-inline-start: 1px solid $calendar-line-color;
  flex: 0 0 auto;
  height: 100%;
  margin-top: -1px;
  min-height: 235px;
  overflow: auto;
  vertical-align: top;
  width: 221px;

  &.has-only-one {
    .accordion-pane {
      border-bottom: 1px solid $calendar-line-color;
    }

    .accordion-header {
      &.has-chevron > a {
        width: calc(100% - 3px);
      }

      .btn {
        display: none;
      }
    }
  }

  .accordion-pane {
    background-color: $calendar-bg-color;

    .data {
      font-size: $ids-size-font-sm;
    }

    .icon {
      color: $button-color-tertiary-initial-font;
      height: 16px;
      margin-left: 5px;
      margin-top: 1px;
      width: 16px;
    }

    .field {
      border-top: 1px solid $calendar-line-color;
      margin-bottom: 15px;
      padding-top: 15px;
      width: calc(100% - 20px);

      &:first-child {
        border-top-color: transparent;
      }
    }
  }

  .accordion-header {
    &:hover > a {
      text-decoration: none;
    }

    &.has-chevron > a {
      line-height: 15px;
      width: calc(100% - 40px);
    }

    a {
      color: $ids-color-palette-white;
      font-size: $ids-size-font-lg;
      -webkit-font-smoothing: antialiased;
      font-weight: 400;
    }

    .btn {
      margin-left: -3px;
      margin-top: 3px;

      .chevron {
        color: $ids-color-palette-white;
      }
    }

    &.ruby {
      background-color: $ids-color-palette-ruby-60;
    }

    &.amber {
      background-color: $ids-color-palette-amber-60;
    }

    &.emerald {
      background-color: $ids-color-palette-emerald-60;
    }

    &.azure {
      background-color: $ids-color-palette-azure-60;
    }

    &.turquoise {
      background-color: $ids-color-palette-turquoise-60;
    }

    &.amethyst {
      background-color: $ids-color-palette-amethyst-60;
    }

    &.slate {
      background-color: $ids-color-palette-slate-60;
    }

    &.graphite {
      background-color: $ids-color-palette-graphite-60;
    }
  }
}

.calendar-event-modal {
  .field {
    input.spinbox {
      width: calc(100% - 66px) !important;
    }
  }

  .container .form-responsive .field .checkbox-label {
    margin-bottom: 0;
    margin-top: 0;
  }
}

// Styles to reset the modal
.calendar-popup {
  max-width: 320px;
  width: 320px;

  .tooltip-content {
    height: calc(100% - 49px);
    overflow: auto;
    padding: 20px 0 0;
  }

  .modal-buttonset {
    background-color: $modal-bg-color;
    border-top: 0;
    height: 45px;
    margin-top: 0;
    padding: 0;
    position: sticky;
    z-index: 3011;

    button {
      background-color: $modal-bg-color;
      border-top: 1px solid $modal-btn-border-color;
      width: 50%;
    }
  }
}

@include respond-to(phabletdown) {
  .monthview-table {
    border-bottom: 1px solid #E0E0E1;
  }

  .monthview-popup {
    .tooltip-content {
      .monthview {
        .monthview-table {
          border-bottom: unset;
        }
      }
    }
  }

  .calendar-popup.calendar-popup-mobile {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    max-width: 100%;
    width: 100% !important;

    .arrow {
      display: none;
    }

    .tooltip-content {
      height: calc(100% - 45px);
    }

    .modal-buttonset {
      bottom: 3px;
      position: absolute;
      width: 100%;
    }
  }
}

@include respond-to(phonedown) {
  .calendar {
    .calendar-event-details-mobile {
      .listview-micro {
        padding-right: 10px;
        position: absolute;
      }
    }
  }
}

@include respond-to(phabletup) {
  .calendar {
    .calendar-event-details {
      .listview {
        display: none;
      }
    }
  }
}

// Responsive Styles
@include respond-to(phabletdown) {
  .calendar {
    flex-wrap: wrap;

    .calendar-events,
    .calendar-event-details {
      display: none;
    }

    .calendar-event-details {
      width: 100%;

      .accordion-header,
      .accordion-pane {
        display: none;
      }

      .listview-heading {
        display: inline-block;
        width: 80%;
      }

      .listview-micro {
        display: inline-block;
        margin-top: 2px;
        text-align: right;
        width: 20%;
      }

      .status-swatch {
        border-radius: 50px;
        display: inline-block;
        height: 12px;
        margin-right: 5px;
        width: 12px;

        + p {
          display: inline-block;
          vertical-align: top;
        }

        &.ruby {
          background-color: $ids-color-palette-ruby-60;
        }

        &.amber {
          background-color: $ids-color-palette-amber-60;
        }

        &.emerald {
          background-color: $ids-color-palette-emerald-60;
        }

        &.azure {
          background-color: $ids-color-palette-azure-60;
        }

        &.turquoise {
          background-color: $ids-color-palette-turquoise-60;
        }

        &.amethyst {
          background-color: $ids-color-palette-amethyst-60;
        }

        &.slate {
          background-color: $ids-color-palette-slate-60;
        }

        &.graphite {
          background-color: $ids-color-palette-graphite-60;
        }
      }
    }

    .calendar-event-details-mobile {
      height: auto;
      margin-bottom: $input-field-bottom-margin;

      &.listview {
        cursor: pointer;
        display: inline-block;
        width: 100%;

        li {
          min-height: 70px;

          .container {
            align-items: center;
            display: flex;
          }

          .column-left {
            float: left;
            width: 70%;
          }

          .column-right {
            float: right;
            margin-right: 15px;
            text-align: right;
            width: 30%;
          }

          .listview-micro {
            display: inline-flex;
            float: none;
            padding-right: 0;
            width: auto;
          }

          .icon {
            color: $button-color-tertiary-initial-font;
            display: inline-flex;
            left: 10px;
            top: 4px;
          }
        }
      }

      .listview-heading {
        display: inline-flex;
        width: 80%;
      }

      .listview-micro {
        float: right;
        margin-top: 2px;
        position: relative;
        text-align: right;
        width: 30%;
      }

      .status-swatch {
        border-radius: 50px;
        display: inline-block;
        height: 12px;
        margin-right: 5px;
        width: 12px;

        + p {
          display: inline-block;
          vertical-align: top;
        }

        &.ruby {
          background-color: $ids-color-palette-ruby-60;
        }

        &.amber {
          background-color: $ids-color-palette-amber-60;
        }

        &.emerald {
          background-color: $ids-color-palette-emerald-60;
        }

        &.azure {
          background-color: $ids-color-palette-azure-60;
        }

        &.turquoise {
          background-color: $ids-color-palette-turquoise-60;
        }

        &.amethyst {
          background-color: $ids-color-palette-amethyst-60;
        }

        &.slate {
          background-color: $ids-color-palette-slate-60;
        }

        &.graphite {
          background-color: $ids-color-palette-graphite-60;
        }
      }
    }

    .calendar-monthview {
      border-bottom-color: transparent !important;
      border-right-color: transparent !important;
      width: 100%;
    }
  }
}

// RTL Styles
html[dir='rtl'] {
  .calendar {
    #calendar-view-changer + .dropdown-wrapper {
      float: left !important;
      right: -15px !important;
    }

    .today {
      margin-right: 15px;
    }

    .monthview.is-fullsize.monthview td:last-child {
      border-inline-start: 0;
    }
  }

  .calendar-events .accordion-header > button {
    margin: -1px 7px 2px 0;
  }

  .calendar-event {
    &.event-day-end {
      border-radius: 3px 0 0 3px;
      border-right: 0 !important;
      margin-right: 0;
    }

    &.event-day-span {
      border-right: 0 !important;
    }

    &.event-day-start {
      border-radius: 0 3px 3px 0;
      padding-left: 4px;
      padding-right: 0;
      border-right: 5px solid $ids-color-brand-primary-alt;
    }

    &.calendar-event-start {
      border-right: 5px solid $ids-color-brand-primary-alt;
    }

    .calendar-event-content {
      padding: 1px 5px;
      text-align: right;
    }
  }

  .calendar-event-details {
    border: 0;
  }

  .calendar-event-types {
    .checkbox-label {
      padding-right: 25px;

      &::after {
        right: 6px !important;
      }
    }

    &.event-tree {
      .tree li {
        margin-right: 0;

        &.is-partial > a .tree-checkbox::after {
          right: 3px;
        }

        .tree-checkbox  {
          left: 24px;

          &::after {
            right: 5px;
          }
        }
      }
    }
  }

  .calendar-toolbar .monthview-datepicker {
    margin-left: 5px;
    margin-right: 15px;
    position: static;
  }

  .calendar-upcoming-events {
    .calendar-upcoming-description {
      margin-left: 0;
      margin-right: 10px;
    }

    .calendar-upcoming-status-text {
      left: 0;
      right: 25px;
    }

    .calendar-upcoming-duration {
      float: left;
      left: 5px;
      right: 0;
    }
  }

  &.is-safari {
    .calendar-event-types {
      &.event-tree {
        .tree.is-multiselect li .tree-checkbox::before {
          right: 0;
        }
      }
    }
  }
}

.monthview-header .calendar-toolbar,
.week-view-header .calendar-toolbar {
  border-bottom: 1px solid  $calendar-line-color;
  height: 50px;
  text-indent: 20px;
}

// A calendar event for week or month
.calendar-event {
  @include font-size(11);

  background-color: $ids-color-palette-azure-20;
  border: 1px solid transparent;
  border-inline-start: 5px solid $ids-color-brand-primary-alt;
  border-radius: 3px;
  color: $font-color-extrahighcontrast;
  cursor: pointer;
  display: block;
  height: 18px;
  margin: 0 2px;
  width: calc(100% - 4px);

  //Event spanning
  &.event-day-start {
    border-radius: 3px 0 0 3px;
    padding-right: 4px;
    width: calc(100% - 1px);
  }

  &.event-day-span {
    border-inline-start: 0 !important;
    border-radius: 0;
    margin: 0;
    width: 100%;
    z-index: 1;

    .calendar-event-icon {
      display: none;
    }

    .calendar-event-title {
      display: none;
    }
  }

  &.event-day-end {
    border-inline-start: 0 !important;
    border-radius: 0 3px 3px 0;
    margin-left: 0;
    width: calc(100% - 2px);
    z-index: 1;

    .calendar-event-icon {
      display: none;
    }

    .calendar-event-title {
      display: none;
    }
  }

  .calendar-event-content {
    color: $calendar-event-color;
    overflow: hidden;
    padding: 2px 5px;
    position: relative;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .calendar-event-icon {
    width: 20px;

    .icon {
      color: $calendar-event-color;
      height: 12px;
      top: 0;
      vertical-align: top;
      width: 13px;
    }
  }

  &.ruby {
    background-color: $ids-color-palette-ruby-20;
    border-inline-start: 5px solid $ids-color-palette-ruby-70;
  }

  &.azure {
    background-color: $ids-color-palette-azure-30;
    border-inline-start: 5px solid $ids-color-palette-azure-70;
  }

  &.amber {
    background-color: $ids-color-palette-amber-30;
    border-inline-start: 5px solid $ids-color-palette-amber-70;
  }

  &.emerald {
    background-color: $ids-color-palette-emerald-30;
    border-inline-start: 5px solid $ids-color-palette-emerald-70;
  }

  &.turquoise {
    background-color: $ids-color-palette-turquoise-30;
    border-inline-start: 5px solid $ids-color-palette-turquoise-70;
  }

  &.amethyst {
    background-color: $ids-color-palette-amethyst-30;
    border-inline-start: 5px solid $ids-color-palette-amethyst-70;
  }

  &.slate {
    background-color: $ids-color-palette-slate-30;
    border-inline-start: 5px solid $ids-color-palette-slate-70;
  }

  &.graphite {
    background-color: $ids-color-palette-graphite-30;
    border-inline-start: 5px solid $ids-color-palette-graphite-70;
  }

  &:focus {
    border-color: $ids-color-palette-azure-60;
    box-shadow: 0 0 4px 3px rgba(54, 138, 192, 0.3);
    outline: none;
    outline-color: transparent;
  }
}

.calendar-event-spacer {
  display: block;
  height: 18px;
}

.popover.calendar-popup {
  max-width: 320px;

  .datepicker + .btn-icon {
    margin-top: 6px;
  }

  .timepicker {
    padding: 0 15px;

    + .btn-icon {
      margin-top: 5px;
      margin-left: -32px;
    }
  }

  .modal-buttonset {
    position: relative;
    top: 0;
    width: 317px;
    right: 1px;
  }
}

#calendar-popup {
  .page-container .form-responsive .field-checkbox,
  .container .form-responsive .field-checkbox {
    margin-top: 0;
  }

  .btn-icon:hover:not([disabled]):not(.btn-primary):not(.trigger):not(:disabled) {
    background-color: rgba(0, 0, 0, 0.25) !important;

    svg {
      color: #fff !important;
    }
  }
}
