:root {
  --poll-option-color: var(--muted-color);
  --poll-option-accent-color: var(--primary-color);
  --poll-option-active-color: var(--secondary-color);
}

.ComposerBody-poll {
  margin-right: 15px;

  .PollLabel {
    font-size: 85%;
    font-weight: 600;
    display: inline-block;
    padding: 0.1em 0.5em;
    border-radius: var(--border-radius);
    background: var(--body-bg);
    color: var(--control-color);
    text-transform: none;
    border: 1px solid var(--primary-color);

    &.none {
      background: transparent;
      border: 1px dotted var(--muted-color);
      color: var(--muted-color);
    }
  }
}

.PollDiscussionModal-form {
  .Form-group {
    margin-top: 5px;

    &.hide {
      display: none;
    }
  }

  input.FormControl {
    &:invalid {
      background-color: var(--alert-error-bg);
      color: var(--alert-error-color);
    }

    + .FormControl {
      margin-top: 5px;
    }
  }

  .Poll-image-inputs {
    display: flex;
    align-items: baseline;
    gap: 10px;
  }

  .PollModal--answers {
    margin-bottom: 20px;

    .Form-group {
      display: flex;
      margin-top: 2.5px;
      margin-bottom: 18px;
    }

    fieldset {
      flex-grow: 1;
    }

    .Poll-answer-image {
      img {
        max-width: 100%;
      }
    }
  }

  .PollModal--button {
    flex-shrink: 1;
    margin-left: 10px;

    .Button--color(@muted-color; darken(@control-bg, 5%));

    .icon {
      margin-right: 0;
      font-size: 12px;
      vertical-align: baseline;
    }

    &.small {
      padding: 2px 7px;
      float: right;
    }
  }

  .PollModal--date {
    display: flex;

    input {
      flex-grow: 1;
    }

    .Button {
      flex-shrink: 1;
      margin-left: 10px;
    }
  }

  .PollModal-SubmitButton {
    margin-top: 10px;
  }

  .PollModal-deleteButton {
    margin-top: 10px;
    margin-left: 10px;
  }

  .PollModal-Button {
    margin-bottom: 15px;
  }

  .PollModal--add-button {
    margin-left: 0px;
  }

  .Checkbox.disabled {
    &,
    [disabled] {
      cursor: not-allowed;
    }

    opacity: 0.5;
  }
}

.Post-poll {
  .Post--hidden & {
    opacity: 0.5;
  }

  .PollOptions {
    display: grid;
    grid: auto-flow / repeat(auto-fit, minmax(~"min(250px, 100%)", 1fr));
    column-gap: 30px;
    row-gap: 15px;
    margin-left: 15px;
    align-items: start;
    margin-top: 15px;

    .PollAnswer when (@fof-polls-options-color-blend = true) {
      &-checkbox,
      &-text {
        & when (@config-dark-mode =true) {
          mix-blend-mode: difference;
        }

        & when (@config-dark-mode =false) {
          mix-blend-mode: darken;
        }
      }
    }
  }

  .Poll-sticky {
    position: sticky;
    bottom: 0;
    padding: 10px 0;
    margin-left: 15px;
    margin-top: 10px;
    display: flex;
    align-items: flex-start;
    column-gap: 15px;
    background-color: var(--body-bg);
    .box-shadow(inset 0px 2px 0px 0px var(--muted-more-bg));

    &:empty {
      display: none;
    }

    .PollInfoText {
      flex-grow: 1;
      margin-bottom: 0;
    }
  }

  & + & {
    margin-top: 2em;
  }

  .PollHeading {
    display: flex;
    align-items: baseline;

    &-actions {
      display: flex;
      gap: 10px;
      align-items: baseline;
    }

    &-title-container {
      flex-grow: 1;
    }

    &-voters {
      .Button--color-auto("button-primary");
    }

    .Button {
      flex-shrink: 1;
      padding: 6px 10px;

      .icon {
        margin-right: 0;
      }
    }
  }
}

.ComposePollHero {
  &-controls {
    margin-left: 2em;
    display: flex;
    justify-content: space-around;

    .Button {
      margin-right: 1em;
    }
  }
}

.PollOption {
  &,
  .PollBar {
    border-radius: 4px;
  }

  &:hover {
    background: var(--muted-more-bg);
  }

  /* Percent */
  .PollPercent {
    padding-right: 5px;
    font-size: 11px;
    font-weight: 600;

    &--option {
      color: var(--muted-color);
    }
  }

  .PollLabel {
    font-size: 85%;
    font-weight: 600;
    display: inline-block;
    padding: 0.1em 0.5em;
    border-radius: 4px;
    background: transparent;
    color: var(--muted-color);
    text-transform: none;
  }

  &:not(.Post--hidden &) {
    .PollBar::after {
      animation: slideInPollBackground 1s ease-in-out;
      transition: background-size 0.75s ease-in-out;
    }
  }

  .PollBar {
    padding: 10px;
    position: relative;
    border: 2px solid var(--poll-option-color);
    overflow: hidden;
    isolation: isolate;

    display: grid;
    grid-template-columns: auto 1fr;
    grid-auto-flow: row;
    gap: 10px;
    align-items: flex-start;

    &:hover {
      cursor: pointer;
    }

    .PollAnswer-input[disabled] {
      cursor: not-allowed;
    }

    .PollAnswer-checkbox {
      grid-column: 1;
      grid-row: 1;

      + .PollAnswer-text {
        grid-column: 2;
      }
    }

    .PollAnswer-text {
      grid-column: ~"1 / span 2";
      grid-row: 1;

      display: flex;
      column-gap: 5px;
      align-items: first baseline;

      &-answer {
        flex-grow: 1;
      }
    }

    .PollAnswer-image {
      grid-column: ~"1 / span 2";
      grid-row: 2;
      max-width: 100%;
    }

    &::after {
      position: absolute;
      top: 0;
      bottom: 0;
      right: 0;
      left: 0;
      z-index: -1;
      background-image: linear-gradient(
        to right,
        var(--poll-option-color) 0% 100%
      );
      background-size: var(--poll-option-width) 100%;
      background-repeat: no-repeat;
      content: "";
    }

    .PollAnswer {
      flex-grow: 1;
    }

    &[data-selected] {
      --poll-option-color: var(--poll-option-active-color);
    }
  }

  .PollAnswer-checkbox {
    margin-bottom: 0;
    position: relative;
    z-index: 2;

    input[type="checkbox"] {
      position: absolute;
      opacity: 0;
      cursor: pointer;

      &:checked ~ .checkmark:after {
        display: block;
      }
    }

    .checkmark {
      position: relative;
      display: block;
      top: 0;
      left: 0;
      height: 20px;
      width: 20px;
      border: 1px solid;
      border-radius: 4px;

      &:after {
        content: "";
        position: absolute;
        display: none;
        left: 6.75px;
        top: 3px;
        width: 5px;
        height: 10px;
        border: solid var(--text-color);
        border-width: 0 3px 3px 0;
        transform: rotate(45deg);
      }
    }
  }
}

.VotesModal {
  &-list {
    display: grid;
    grid: auto-flow / repeat(auto-fill, minmax(150px, 1fr));
    column-gap: 10px;
    row-gap: 10px;
    margin-bottom: 20px;

    a {
      color: var(--text-color);
      font-size: 15px;
      font-weight: bold;
      display: block;
      text-decoration: none;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;

      &:hover .username {
        text-decoration: underline;
      }
    }
    .Avatar {
      .Avatar--size(32px);
      vertical-align: middle;
      margin-right: 5px;
    }
  }

  h2 {
    margin-bottom: 15px;
  }

  h4 {
    color: var(--text-color);
    margin-top: 0;
    margin-bottom: 20px;
  }
}

.PublicPollButton {
  display: block;
  margin: 20px 15px;
}

.PollInfoText {
  span {
    display: block;
  }

  .icon {
    margin-right: 2.5px;
  }
}

@keyframes slideInPollBackground {
  from {
    background-size: 0 100%;
  }
  to {
    background-size: var(--poll-option-width) 100%;
  }
}

@media @desktop-up {
  .item-newGlobalPoll,
  .item-newPollGroup {
    .Button {
      display: block;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

.Poll {
  position: relative;
  .Poll-sticky {
    position: sticky;
    bottom: 0;
    padding: 10px 0;
    margin-top: 10px;
    display: flex;
    align-items: flex-start;
    column-gap: 15px;
    background-color: var(--body-bg);
    .box-shadow(inset 0px 2px 0px 0px var(--muted-more-bg));

    &:empty {
      display: none;
    }

    .PollInfoText {
      flex-grow: 1;
      margin-bottom: 0;
    }
  }
}

.Poll-subtitle {
  color: var(--muted-color);
}

.Poll-content {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
}

.Poll-options {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  border-radius: var(--border-radius);

  &.grid-layout {
    grid-template-columns: 1fr 1fr;
  }

  &.list-layout {
    flex-direction: column;
  }
}

.PollImage {
  width: 100%;

  &-image {
    max-width: 100%;
    border-radius: var(--border-radius);
  }
}

.PollOption {
  position: relative;
  background: var(--body-bg);
  border-radius: 4px;

  &:hover {
    background: var(--control-bg-light);
  }
}

.PollResult {
  display: flex;
  flex-direction: row;
  position: relative;
  padding: 10px;
  border-radius: 4px;

  progress {
    width: 100%;
  }
}

.PollResult-input,
.PollOption-input {
  accent-color: var(--poll-option-accent-color);
}

.PollResult-input {
  pointer-events: none;
}

.PollResult-row {
  display: flex;
  flex-grow: 1;
  justify-content: space-between;
}

.PollResult-bar {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  width: 100%;

  &::-webkit-progress-value {
    background-color: var(--muted-color-dark);
  }

  &::-webkit-progress-bar {
    background-color: var(--muted-color-light);
  }
}

.Poll-title,
.PollResult-number {
  font-weight: 600;
}

.PollOption-label {
  display: block;
  font-weight: 600;
}

.PollOption-description {
  display: block;
  color: var(--muted-color);
}

.PollOption:has(.PollOption-input:checked) {
  border-color: var(--poll-option-active-color);
  background: var(--control-bg-shaded);
}

.PollList .PollList-polls {
  list-style-type: none;
  padding: 0;
  clear: both;
}

@media (any-hover: none) {
  .PollListItem-controls > .Dropdown-toggle {
    display: none;
  }
}

.PollListItem-controls {
  float: right;
}

.PollListItem a {
  text-decoration: none;
}

.PollListItem-info {
  list-style-type: none;
  padding: 0;
  margin: 0;
  font-size: 11px;
  color: var(--muted-more-color);

  > li {
    display: inline-block;
  }

  .item-voteCount {
    margin-right: 5px;
  }
}

.PollListItem-main {
  display: inline-block;
  width: 100%;
  padding: 12px 0;
}

.PollListItem-title {
  margin: 0 0 3px;
  line-height: 1.3;
  color: var(--heading-color);
  font-weight: normal;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media @phone {
  .PollListItem-controls {
    display: none;
  }
  .PollListItem-content:active {
    background: var(--control-bg);
  }
  .PollListItem-title {
    font-size: 14px;
    text-decoration: none !important;
  }
  .PollListItem-info {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media @tablet-up {
  .PollListItem {
    position: relative;
    margin-right: -15px;
    padding-right: 25px;
    padding-left: 15px;
    margin-left: -15px;
    border-radius: var(--border-radius);
    transition: background 0.2s;

    &:hover {
      background: var(--discussion-list-item-bg-hover);
    }
    &:hover .PollListItem-controls,
    .PollListItem-controls.open {
      opacity: 1;
    }
    .PollListItem-controls.open {
      z-index: 3;
    }
  }
  .PollListItem-controls {
    position: absolute;
    right: 5px;
    top: 5px;
    z-index: 1;
    opacity: 1;
    transition: opacity 0.2s;

    &:focus-within {
      opacity: 1;
    }

    .Dropdown-toggle {
      display: block;
    }
    .Dropdown-menu {
      right: 0;
      left: auto;
    }
  }
  .PollListItem-info {
    .item-excerpt {
      margin-right: 170px;
    }
  }
  .PollListItem-title {
    font-size: 16px;
  }
}

@media @desktop-up {
  .PollsPage,
  .PollGroupsPage {
    .sideNav {
      .sideNav--horizontal();
      float: none;
      width: auto;
      margin-right: 0;
      padding-top: 0;

      &:after {
        display: none;
      }

      > ul > li:first-child {
        width: 190px;
      }
    }
    .sideNavOffset {
      margin: 15px 0 0;
    }
  }
}

.PollShowcase {
  &--item {
    background-color: @control-bg;
    border-radius: @border-radius;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 10px;
    margin-bottom: 20px;

    .Poll {
      padding: 20px;
      border-radius: @border-radius;
      background-color: @body-bg;

      .Poll-header {
        background-color: @header-bg;
        color: @header-color;
      }
    }
  }
}

// .PollsPage--groups
.PollGroupList-pollgroups,
.PollGroupListItem-polls {
  display: flex;
  flex-direction: column;
  list-style: none;
  padding-inline-start: 0;
}

.PollGroupListItem-polls {
  border: 10px solid #ededed;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 10px;
  margin-bottom: 20px;
}

.PollGroupList-pollgroups {
  gap: 20px;
}

.PollGroupListItem {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.PollGroupListItem-main {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.PollGroupListItem-title {
  display: inline-block;
  margin-block: 0;
}

// Poll Groups Composer
.PollGroupModal-SubmitButton {
  margin-right: 10px;
}