/*
  Base components
*/

.known-error .multiselect__tags {
  border-color: var(--color-red) !important;
  background-color: var(--color-warning-bg) !important;

  &::placeholder {
    color: var(--color-warning-text);
  }
}

.grid-display {
  display: grid;
  grid-gap: var(--spacing-card-md);
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));

  .grid-display__item {
    display: flex;
    flex-grow: 1;
    flex-direction: column;
    justify-content: flex-start;
    background-color: var(--color-bg);
    border-radius: var(--size-rounded-card);
    padding: var(--spacing-card-lg);
    gap: var(--spacing-card-md);
    outline: 1px solid transparent;

    .label {
      color: var(--color-heading);
      font-weight: bold;
      font-size: 1rem;
    }

    .value {
      color: var(--color-text-dark);
      font-weight: bold;
      font-size: 2rem;
    }

    .goto-link {
      margin-top: auto;
    }
  }

  &.width-12 {
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  }

  &.width-16 {
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  }
}

/*
  Cards and body styling
*/
.base-card {
  @extend .padding-lg;

  position: relative;

  background-color: var(--color-raised-bg);
  border-radius: var(--size-rounded-card);

  margin-bottom: var(--spacing-card-md);
  outline: 2px solid transparent;
  outline-offset: -2px;

  box-shadow: var(--shadow-card);

  .card__overlay {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    grid-gap: 0.5rem;
    z-index: 2;
  }

  &.moderation-card {
    background-color: var(--color-warning-banner-bg);
  }

  &.recessed {
    background-color: var(--color-bg);
    box-shadow: none;
  }
}

.universal-labels {
  label,
  .label {
    :where(.label__title) {
      display: block;
      margin-block: var(--spacing-card-md) var(--spacing-card-sm);

      // Same styling as h3
      color: var(--color-text-dark);
      font-size: 1.17rem;
      font-weight: bold;

      .required {
        color: var(--color-red);
      }

      &.size-card-header {
        font-size: var(--font-size-xl);
        margin-bottom: 1rem;
      }
    }

    :where(.label__description) {
      display: block;
      margin-block-end: var(--spacing-card-sm);

      .label__subdescription {
        display: block;
        margin-block-start: var(--spacing-card-md);
      }
    }

    :where(h1, h2, h3, h4) {
      margin-block: 0;
    }
  }
}

.padding-lg {
  padding: var(--spacing-card-lg);
}

.padding-bg {
  padding: var(--spacing-card-bg);
}

.padding-md {
  padding: var(--spacing-card-md);
}

.padding-sm {
  padding: var(--spacing-card-sm);
}

.padding-0 {
  padding: 0;
}

.padding-block-lg {
  padding-block: var(--spacing-card-lg);
}

.padding-block-bg {
  padding-block: var(--spacing-card-bg);
}

.padding-block-md {
  padding-block: var(--spacing-card-md);
}

.padding-block-sm {
  padding-block: var(--spacing-card-sm);
}

.padding-block-0 {
  padding-block: 0;
}

.padding-inline-lg {
  padding-inline: var(--spacing-card-lg);
}

.padding-inline-bg {
  padding-inline: var(--spacing-card-bg);
}

.padding-inline-md {
  padding-inline: var(--spacing-card-md);
}

.padding-inline-sm {
  padding-inline: var(--spacing-card-sm);
}

.padding-inline-0 {
  padding-inline: 0;
}

.universal-body {
  @extend .universal-labels;

  .multiselect {
    width: 15rem;
  }

  > :where(
    input + *,
    .input-group + *,
    .textarea-wrapper + *,
    .chips + *,
    .resizable-textarea-wrapper + *,
    .input-div + *
  ) {
    &:not(:empty) {
      margin-block-start: var(--spacing-card-md);
    }
  }

  :where(button, .button, .iconified-button) {
    width: fit-content;
  }

  .input-group {
    input {
      width: auto;
      flex-basis: 0;
    }
  }

  :where(input) {
    box-sizing: border-box;
    max-height: 40px;

    &:not(.stylized-toggle) {
      max-width: 100%;
    }
  }

  :where(.adjacent-input, &.adjacent-input) {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-card-sm);
    margin-bottom: calc(var(--spacing-card-sm) + var(--spacing-card-md));

    .iconified-button,
    .input-group {
      flex-shrink: 0;
    }

    input {
      flex-shrink: 1;
    }

    > :first-child {
      flex-shrink: 2;
      flex-grow: 1;
      flex-basis: min-content;
    }

    label,
    .label {
      .label__title {
        margin-block: 0;
      }

      .label__description {
        margin-block-end: 0;
      }

      .label__description:not(:first-child) {
        margin-top: var(--spacing-card-sm);
      }
    }

    @media screen and (max-width: 750px) {
      &:not(&.small) {
        flex-direction: column;
        align-items: flex-start;

        .stylized-toggle {
          flex-basis: 0;
        }
      }
    }
  }

  h1 {
    display: flex;
    align-items: center;
  }

  .markdown-body h1 {
    display: block;
  }

  > :first-child {
    :first-child {
      margin-block-start: 0;
    }

    margin-block-start: 0;
  }

  > :last-child {
    margin-block-end: 0;
  }

  :where(.header__row) {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--spacing-card-sm);

    * {
      flex-shrink: 0;
    }

    .header__title {
      margin: 0;
      flex-grow: 1;
    }

    &:not(:last-child) {
      margin-bottom: var(--spacing-card-md);
    }
  }
}

.universal-card {
  @extend .base-card;
  @extend .universal-body;
}

.universal-modal {
  @extend .universal-body;

  padding: var(--spacing-card-bg);
  display: flex;
  flex-direction: column;

  > p:first-child {
    margin-top: 0;
  }

  @media screen and (max-width: 750px) {
    .adjacent-input,
    &.adjacent-input &:not(&.small) {
      flex-direction: row;
      align-items: center;
    }
  }

  @media screen and (max-width: calc(600px + 2rem)) {
    .adjacent-input,
    &.adjacent-input &:not(&.small) {
      flex-direction: column;
      align-items: flex-start;
    }
  }
}

.navigation-card {
  @extend .base-card;
  @extend .padding-inline-lg;
  @extend .padding-block-md;

  align-items: center;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 0.5rem;
  min-height: 3.75rem;
}

/*
  Other
 */

.text-link {
  color: var(--color-link);

  &:focus-visible,
  &:hover {
    color: var(--color-link-hover);
    cursor: pointer;
    text-decoration: underline;
  }

  &:active {
    color: var(--color-link-active);
  }
}

.title-link {
  text-decoration: underline;

  &:focus-visible,
  &:hover {
    color: var(--color-heading);
  }

  &:active {
    color: var(--color-text-dark);
  }
}

.button-base {
  @extend .button-animation;
  font-weight: 500;
  outline: 2px solid transparent;

  &:focus-visible:not(&:disabled),
  &:hover:not(&:disabled) {
    cursor: pointer;
    filter: brightness(0.85);
  }

  &:active:not(&:disabled) {
    filter: brightness(0.8);
  }

  &:disabled,
  &[disabled="true"] {
    cursor: not-allowed;
    filter: grayscale(50%);
    opacity: 0.5;
    box-shadow: none;
  }
}

:not(tr).button-transparent {
  @extend .button-base;
  background-color: transparent;
  border-radius: var(--size-rounded-sm);

  &:focus-visible:not(&:disabled),
  &:hover:not(&:disabled),
  &:active:not(&:disabled) {
    background-color: var(--color-raised-bg);
  }

  &.brand-button {
    color: var(--color-brand);
  }

  &.danger-button {
    color: var(--color-red);
  }
}

tr.button-transparent {
  @extend .button-animation;
  background-color: transparent;
  border-radius: var(--size-rounded-sm);

  &:focus-visible:not(&:disabled) > *,
  &:hover:not(&:disabled) > * {
    cursor: pointer;
    filter: brightness(0.85);
    background-color: var(--color-raised-bg);
  }

  &:active:not(&:disabled) > * {
    filter: brightness(0.8);
    background-color: var(--color-raised-bg);
  }

  &:disabled > *,
  &[disabled="true"] > * {
    cursor: not-allowed;
    filter: grayscale(50%);
    opacity: 0.5;
    box-shadow: none;
  }
}

.button-within {
  transition:
    opacity 0.5s ease-in-out,
    filter 0.2s ease-in-out,
    transform 0.05s ease-in-out,
    outline 0.2s ease-in-out;

  &:focus-visible:not(&.disabled),
  &:hover:not(&.disabled) {
    filter: brightness(0.85);
  }

  &:active:not(&.disabled) {
    filter: brightness(0.8);
  }

  &.disabled {
    cursor: not-allowed;
    filter: grayscale(50%);
    opacity: 0.5;
    box-shadow: none;

    &disabled,
    &[disabled="true"] {
      cursor: not-allowed;
      box-shadow: none;
    }
  }
}

.button-color-base {
  box-sizing: border-box;
  --text-color: var(--color-button-text);
  --background-color: var(--color-button-bg);

  color: var(--text-color);
  background-color: var(--background-color);
  box-shadow:
    var(--shadow-inset-sm),
    0 0 0 0 transparent;
  border-radius: var(--size-rounded-sm);
}

.iconified-button {
  @extend .button-base;
  @extend .button-color-base;

  display: flex;
  padding: var(--spacing-card-sm) var(--spacing-card-bg);
  margin: 0;
  font-size: var(--font-size-nm);
  align-items: center;
  cursor: pointer;
  width: fit-content;
  height: fit-content;
  transition:
    opacity 0.5s ease-in-out,
    filter 0.2s ease-in-out,
    scale 0.05s ease-in-out,
    outline 0.2s ease-in-out;

  text-decoration: none;

  svg {
    width: 1.1rem;
    height: 1.1rem;
    margin-right: 0.5rem;
  }

  &.icon-only {
    padding: 0 0.5rem;

    svg {
      margin-right: 0;
    }
  }

  &.transparent {
    background: none;
    box-shadow: none;
  }

  &.bold-button {
    font-weight: bold;
  }
}

.square-button {
  @extend .button-base;

  --text-color: var(--color-button-text);
  --background-color: var(--color-button-bg);

  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.25rem;
  width: 2.25rem;
  border-radius: var(--size-rounded-sm);
  color: var(--text-color);
  background-color: var(--background-color);
  box-shadow:
    var(--shadow-inset-sm),
    0 0 0 0 transparent;

  svg {
    min-width: 1.25rem;
    max-width: 1.25rem;
    min-height: 1.25rem;
    max-height: 1.25rem;
  }

  flex-shrink: 0;
}

.header-button {
  @extend .iconified-button;

  box-sizing: content-box;
  min-height: unset;
  border-radius: var(--size-rounded-max);
  white-space: nowrap;
  padding: 0.5rem 0.75rem;
  max-height: 1.75rem;

  svg {
    vertical-align: middle;
    margin-right: 0.5rem;
    height: 1.25rem;
    width: 1.25rem;
  }
}

.raised-button {
  --background-color: var(--color-raised-bg);
  box-shadow: var(--shadow-inset-sm), var(--shadow-raised);
}

.danger-button {
  --background-color: var(--color-red);
  --text-color: var(--color-brand-inverted);
}

.moderation-button {
  --background-color: var(--color-orange);
  --text-color: var(--color-brand-inverted);
}

.brand-button {
  --background-color: var(--color-brand);
  --text-color: var(--color-brand-inverted);
}

.alt-brand-button {
  --background-color: var(--color-brand-highlight);
  --text-color: var(--color-text);
}

.button-group {
  display: flex;
  grid-gap: var(--spacing-card-sm);
  flex-wrap: wrap;
  margin-top: var(--spacing-card-md);
  justify-content: right;
}

.multiselect--above .multiselect__content-wrapper {
  border-top: none !important;
  border-top-left-radius: var(--size-rounded-card) !important;
  border-top-right-radius: var(--size-rounded-card) !important;
}

.known-error .multiselect__tags {
  border-color: var(--color-red) !important;
  background-color: var(--color-warning-bg) !important;

  &::placeholder {
    color: var(--color-warning-text);
  }
}

.switch {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;

  &:focus {
    //outline: 0; Bad for accessibility
  }
}

.stylized-toggle {
  @extend .button-base;

  box-sizing: content-box;
  min-height: 32px;
  height: 32px;
  width: 52px;
  max-width: 52px;
  border-radius: var(--size-rounded-max);
  display: inline-block;
  position: relative;
  margin: 0;
  transition: all 0.2s ease;
  background: var(--color-button-bg);

  &:after {
    content: "";
    position: absolute;
    top: 7px;
    left: 7px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--color-toggle-handle);
    transition: all 0.2s cubic-bezier(0.5, 0.1, 0.75, 1.35);
    outline: 2px solid transparent;

    @media (prefers-reduced-motion) {
      transition: none;
    }
  }

  &:checked {
    background-color: var(--color-brand);

    &:after {
      transform: translatex(20px);
      background: var(--color-brand-inverted);
    }
  }

  &:hover &:focus {
    background: var(--color-button-bg);
  }
}

.textarea-wrapper {
  display: flex;
  flex-direction: column;
  align-items: stretch;

  textarea {
    border-radius: var(--size-rounded-sm);
    flex: 1;
    overflow-y: auto;
    resize: none;
    max-width: 100%;
  }
}

.resizable-textarea-wrapper {
  display: block;

  textarea {
    border-radius: var(--size-rounded-sm);
    min-height: 10rem;
    width: calc(100% - var(--spacing-card-lg) - var(--spacing-card-sm));
    resize: vertical;
  }
}

.error {
  display: flex;
  flex-direction: column;
  width: 100%;
  justify-content: center;
  align-items: center;

  .icon {
    width: 8rem;
    height: 8rem;
    margin: 1.5rem 0;
  }

  .text {
    margin-bottom: 2rem;
    font-size: 1.25rem;
    text-align: center;
  }

  .link {
    cursor: pointer;
    text-decoration: underline;
  }
}

.card-divider {
  background-color: var(--color-button-bg);
  border: none;
  color: var(--color-button-bg);
  height: 1px;
  margin: var(--spacing-card-bg) 0;
}

.text-input-wrapper.known-error,
input.known-error,
textarea.known-error {
  outline: 2px solid var(--color-red);
  background-color: var(--color-warning-bg) !important;

  &::placeholder {
    color: var(--color-warning-text);
  }
}

.known-errors {
  min-height: 0;
  color: var(--color-red);

  ul {
    margin: 0;
  }
}

.goto-link {
  display: flex;
  align-items: center;
  gap: 3px;

  color: var(--color-link);
}

.goto-link:hover,
.goto-link:focus-visible {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.goto-link:active {
  color: var(--color-link-active);
}

h1 {
  .beta-badge {
    font-size: 0.4em;
  }
}

.beta-badge {
  font-size: 0.7em;
  padding: 0.2rem 0.4rem;
  background-color: transparent;
  box-sizing: border-box;
  border: 2px solid var(--color-text);
  color: var(--color-text);
  border-radius: var(--size-rounded-max);
  margin-left: 0.5rem;
  font-weight: bold;
}

.router-link-exact-active,
h1,
h2,
h3 {
  .beta-badge {
    background-color: var(--color-button-text-active);
    box-sizing: border-box;
    border-color: transparent;
    color: var(--color-raised-bg);
  }
}

@media (prefers-reduced-motion) {
  .button-animation,
  button {
    transform: none !important;
  }
}

.push-right:not(.input-group),
.push-right.input-group > :first-child {
  margin-left: auto;
  margin-right: 0;
}

.full-width-inputs {
  .multiselect,
  input,
  .iconified-input {
    width: 100%;
    flex-basis: 100%;
  }
}

input,
button {
  &:disabled {
    cursor: not-allowed !important;
  }
}

.input-group {
  display: flex;
  flex-direction: row;
  grid-gap: var(--spacing-card-sm);
  flex-wrap: wrap;
  max-width: 100%;
  align-items: center;

  .multiselect {
    width: 15rem;
  }

  input {
    flex-shrink: 2;
  }

  &.shrink-first {
    :first-child {
      flex-shrink: 2;
      flex-grow: 1;
      flex-basis: min-content;
    }

    :not(:first-child) {
      flex-shrink: 1;
    }
  }

  &.right-aligned {
    justify-content: end;
  }
}

.input-stack {
  display: flex;
  flex-direction: column;

  > *:not(:last-child) {
    margin-bottom: var(--spacing-card-sm);
  }

  > .multiselect {
    width: unset;
    height: inherit;
  }
}

.text-input-wrapper {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  background: var(--color-button-bg);
  width: fit-content;
  border-radius: var(--size-rounded-sm);
  box-shadow:
    var(--shadow-inset-sm),
    0 0 0 0 transparent;
  transition: box-shadow 0.1s ease-in-out;
  overflow: hidden;
  max-width: 100%;
  outline: 2px solid transparent;

  .text-input-wrapper__before {
    display: flex;
    color: var(--color-text);
    padding: 0.5rem 0 0.5rem 1rem;
    font-weight: var(--font-weight-medium);
    min-height: 36px;
    box-sizing: border-box;
    width: fit-content;
    align-items: center;
    filter: grayscale(50%);
    opacity: 0.5;
    box-shadow: none;
    flex-shrink: 0;
  }

  input,
  textarea {
    border-radius: 0;
    background-color: transparent;
    box-shadow: unset !important;
    padding-left: 0;
    flex-grow: 1;
    outline: none !important;
  }

  &:focus,
  &:focus-visible,
  &:focus-within {
    box-shadow:
      inset 0 0 0 transparent,
      0 0 0 0.25rem var(--color-brand-shadow);
    color: var(--color-button-text-active);
  }
}

.primary-stat {
  align-items: center;
  display: flex;
  margin-bottom: 0.6rem;

  .primary-stat__icon {
    height: 1rem;
    width: 1rem;
  }

  .primary-stat__text {
    margin-left: 0.4rem;
  }

  .primary-stat__counter {
    font-size: var(--font-size-lg);
    font-weight: bold;
  }

  &.no-margin {
    margin: 0;
  }
}

.project-list {
  width: 100%;
  gap: var(--spacing-card-md);
  overflow: hidden;

  &:not(:first-child) {
    margin-top: var(--spacing-card-md);
  }

  &:not(:empty) {
    margin-bottom: var(--spacing-card-md);
  }
}

.project-list.display-mode--list {
  display: flex;
  flex-direction: column;
}

.project-list.display-mode--gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));

  @media screen and (max-width: 750px) {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
}

.project-list.display-mode--grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));

  @media screen and (max-width: 80rem) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @media screen and (max-width: 1024px) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  @media screen and (max-width: 860px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @media screen and (max-width: 550px) {
    display: flex;
    flex-direction: column;
  }
}

.wrap-as-needed {
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  -webkit-hyphens: auto;
  hyphens: auto;
}

.sr-only {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.backed-svg {
  --size: 2.5rem;
  border-radius: var(--size-rounded-sm);
  background-color: var(--color-button-bg);
  width: var(--size);
  height: var(--size);
  display: inline-flex;
  justify-content: center;
  align-items: center;

  svg {
    width: calc(0.6 * var(--size));
    height: calc(0.6 * var(--size));
  }

  &.circle {
    border-radius: 50%;
  }

  &.raised {
    background-color: var(--color-raised-bg);
  }
}

a.iconified-link,
a.iconified-stacked-link {
  display: contents;

  .space {
    opacity: 0;
  }

  .title {
    font-weight: bold;
  }

  .stacked {
    display: inline-flex;
    flex-direction: column;
  }

  &:focus-visible .title,
  &:hover .title {
    text-decoration: underline;
    filter: var(--hover-filter);
  }

  &:active .title {
    filter: var(--active-filter);
  }
}

a.iconified-link {
  &:focus-visible span,
  &:hover span {
    text-decoration: underline;
    filter: var(--hover-filter);
  }

  &:active span {
    filter: var(--active-filter);
  }
}

a.subtle-link {
  &:focus-visible,
  &:hover {
    text-decoration: underline;
    filter: var(--hover-filter);
  }

  &:active {
    filter: var(--active-filter);
  }
}

.inline-svg svg,
svg.inline-svg {
  vertical-align: middle;
}

// START STUFF FOR OMORPHIA
.experimental-styles-within {
  .tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-4);
  }

  .tag-list__item {
    background-color: var(--_bg-color, var(--color-button-bg));
    padding: var(--gap-4) var(--gap-8);
    border-radius: var(--radius-max);
    font-weight: var(--weight-bold);
    font-size: var(--text-14);
    display: flex;
    gap: var(--gap-4);
    align-items: center;
    vertical-align: middle;
    color: var(--_color, var(--color-secondary));

    svg {
      width: var(--icon-14);
      height: var(--icon-14);
      display: flex;
    }
  }

  .status-list {
    display: flex;
    flex-direction: column;
    gap: var(--gap-8);
    padding-left: var(--gap-6);

    color: var(--color-base);
    font-weight: var(--weight-bold);
  }

  .status-list__item {
    display: flex;
    align-items: center;
    gap: var(--gap-4);

    svg {
      width: var(--icon-16);
      height: var(--icon-16);
      margin-right: var(--gap-4);
    }

    span {
      color: var(--color-secondary);
      font-style: italic;
      font-weight: var(--weight-normal);
    }
  }

  .status-list__item--color-green svg {
    color: var(--color-green);
  }

  .status-list__item--color-orange svg {
    color: var(--color-orange);
  }

  .status-list__item--color-red svg {
    color: var(--color-red);
  }

  .status-list__item--color-blue svg {
    color: var(--color-blue);
  }

  .status-list__item--color-purple svg {
    color: var(--color-purple);
  }

  &.flex-card,
  .flex-card {
    display: flex;
    flex-direction: column;
    gap: var(--gap-12);
    padding: var(--gap-16) var(--gap-24);

    h2 {
      font-size: var(--text-18);
      font-weight: var(--weight-extrabold);
      color: var(--color-contrast);
      line-height: initial;
      margin: 0;
    }

    h3 {
      font-size: var(--text-16);
      font-weight: var(--weight-bold);
      color: var(--color-base);
      margin: 0;
    }

    > section {
      display: flex;
      flex-direction: column;
      gap: var(--gap-8);
    }
  }

  .list-style {
    display: flex;
    flex-direction: column;
    gap: var(--gap-12);
    font-weight: var(--weight-bold);

    hr {
      width: 100%;
      border-color: var(--color-button-border);
      margin-block: var(--gap-2);
    }
  }

  .iconified-list-item {
    display: flex;
    gap: var(--gap-8);
    vertical-align: middle;
    align-items: center;
    width: fit-content;

    svg {
      width: var(--icon-16);
      height: var(--icon-16);
    }

    > svg:first-child {
      flex-shrink: 0;
    }
  }

  .links-list {
    @extend .list-style;

    > a {
      @extend .iconified-list-item;

      &:hover {
        text-decoration: underline;
      }
    }
  }

  .details-list {
    @extend .list-style;
  }

  .details-list__item {
    @extend .iconified-list-item;

    .details-list__item__text--style-secondary {
      color: var(--color-secondary);
      font-weight: var(--weight-normal);
      font-size: var(--text-14);
    }
  }
}
