/* ---------------------------------------- */
/*  Text Input Fields                       */
/* ---------------------------------------- */

input[type=text],
input[type=number],
input[type=password],
input[type=date],
input[type=time],
input[type=datetime-local],
input[type=search],
input[type=file],
select {
  width: 100%;
  height: var(--input-height);
  line-height: var(--input-height);
  padding: 0 0.5rem;
  background: var(--input-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  box-shadow: var(--input-box-shadow);
  outline: 1px solid transparent;
  font-family: inherit;
  font-size: inherit;
  color: var(--input-text-color);
  user-select: text;
  transition: outline-color 0.5s;
  cursor: var(--cursor-text);

  // Focused
  &:focus {
    outline: 2px solid var(--input-focus-outline-color);
    outline-offset: -2px;
  }

  // Disabled
  &:disabled {
    cursor: inherit;
    opacity: 1.0;  // browser sets 0.7
  }
}

// Select specifically
select {
  box-shadow: none;
  user-select: none;
  cursor: var(--cursor-pointer);
  option, optgroup {
    font-family: inherit;
    background: var(--color-select-option-bg);
  }
}

/** Placeholder Text */
::placeholder {
  color: var(--input-placeholder-color);
}

/** Font Awesome icon as placeholder text */
input.placeholder-fa-solid::placeholder {
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  font-family: "Font Awesome 6 Pro";
  font-weight: 900;
  font-style: normal;
  font-variant: normal;
  line-height: 1;
  text-rendering: auto;
}

/** Icon Decorated Inputs */
label.username,
label.password,
label.search {
  display: flex;
  align-items: center;
  > input {
    padding-right: 30px; // Space for icon
  }
  &::after {
    flex: 0 0 30px;
    margin-left: -30px;
    display: inline-block;
    line-height: var(--input-height);
    font-size: 12px;
    font-family: var(--font-awesome);
    font-weight: 900;
    text-align: center;
    color: var(--color-light-5);
  }
}
label.username::after {
  content: "\F007";
}
label.password::after {
  content: "\F084";
}
label.search::after {
  content: "\F002";
}

/** Search Fields */
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 0.5rem;
  background: linear-gradient(45deg, transparent 0%, transparent 43%, var(--color-light-5) 45%, var(--color-light-5) 55%, transparent 57%,transparent 100%),
    linear-gradient(135deg, transparent 0%, transparent 43%, var(--color-light-5) 45%, var(--color-light-5) 55%, transparent 57%, transparent 100%);
  cursor: var(--cursor-pointer);
}

/** Number Fields */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/** File Input Fields */
input[type="file"] {
  font-size: 0.75rem;
}

/** Hint Icons in Labels */
label.hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  > i {
    cursor: var(--cursor-pointer);
    transition: 0.5s;
  }
  > i:hover {
    color: var(--color-warm-1);
  }
}

/* ---------------------------------------- */
/*  Checkboxes                              */
/* ---------------------------------------- */

input[type="checkbox"],
input[type="radio"] {
  --checkbox-size: var(--font-size-20);

  cursor: var(--cursor-pointer);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  &:focus {
    color: inherit;
    outline: none;
  }
  &:focus-visible::before {
    outline: 2px solid var(--input-focus-outline-color);
    outline-offset: -2px;
  }
  &:checked:focus-visible::before {
    outline: 2px solid var(--input-focus-outline-color);
    outline-offset: -2px;
  }
  &::before, &::after {
    width: var(--checkbox-size);
    height: var(--checkbox-size);
    font-size: var(--checkbox-size);
    line-height: var(--checkbox-size);
    border-radius: 3px;
  }
  &::before {
    font-family: var(--font-awesome);
    font-weight: var(--checkbox-font-weight);
    color: var(--checkbox-background-color);
    outline: 1px solid transparent;
    transition: outline-color .5s;
  }
  &:checked, &:indeterminate {
    position: relative;
    &::before, &::after { font-family: var(--font-awesome-duotone); }

    &::after {
      color: var(--checkbox-checked-color);
    }

    &::before {
      color: var(--checkbox-checkmark-color);
      position: absolute;
    }
  }
  &:disabled, &[readonly] {
    --checkbox-background-color: var(--checkbox-disabled-color);
    --checkbox-checked-color: var(--checkbox-disabled-color);
    cursor: inherit;
  }
  &[readonly] {
    pointer-events: none;
  }
}

input[type="checkbox"] {
  &::before {
    content: "\f0c8";
  }
  &:checked {
    &::before {
      content: "\f14a";
    }
    &::after {
      content: "\f14a\f14a";
    }
  }
  &:indeterminate {
    &::before { content: "\f146"; }
    &::after { content: "\f146\f146"; }
  }
}

input[type="radio"] {
  &::before {
    content: "\f111";
  }
  &:checked {
    &::before {
      content: "\f192";
    }
    &::after {
      content: "\f192\f192";
    }
  }
}

/** Labeled Checkboxes and Radio Buttons */
label.checkbox {
  flex: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0;
  margin: 0;
  font-size: var(--font-size-12);
  > input[type=checkbox],
  > input[type=radio] {
    --checkbox-size: var(--font-size-16);
    flex: none;
  }
}

/* Text Areas */
textarea {
  --color-text-selection-bg: var(--color-cool-3);

  min-height: 60px;
  padding: 0.25rem 0.5rem;
  background: var(--input-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  box-shadow: var(--input-box-shadow);
  font-family: var(--font-monospace);
  font-size: var(--font-size-14);
  color: var(--input-text-color);
  user-select: text;
  cursor: var(--cursor-text);
  resize: vertical;
  &:focus {
    outline: 2px solid var(--input-focus-outline-color);
    outline-offset: -2px;
  }
  &:disabled {
    cursor: inherit;
  }
  &:read-only {
    color: var(--color-light-4);
    box-shadow: none;
  }
  &::placeholder { color: var(--input-placeholder-color); }
}

/* ---------------------------------------- */
/*  Range Inputs                            */
/* ---------------------------------------- */

input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: transparent;
  height: var(--input-height);
  margin: 0;
  width: 100%;
  border-radius: 4px;

  // Track
  .range-track() {
    width: 100%;
    height: 4px;
    background: var(--range-track-color);
    border: 1px solid var(--range-track-border-color);
    border-radius: 2px;
    cursor: var(--cursor-pointer);
  }
  &::-webkit-slider-runnable-track { .range-track(); }
  &::-moz-range-track { .range-track(); }

  // Thumb
  .range-thumb() {
    cursor: var(--cursor-pointer);
    appearance: none;
    -webkit-appearance: none;
    height: 12px;
    width: 12px;
    margin-top: -5px;
    background: var(--range-thumb-background-color);
    border: 1px solid var(--range-thumb-border-color);
    border-radius: 4px;
  }
  &::-webkit-slider-thumb { .range-thumb(); }
  &::-moz-range-thumb { .range-thumb(); }

  &:disabled, &[readonly] {
    cursor: inherit;
    opacity: 0.33;
    filter: grayscale(1);
    &::-webkit-slider-runnable-track { cursor: inherit; }
    &::-moz-range-track { cursor: inherit; }
    &::-webkit-slider-thumb { cursor: inherit; }
    &::-moz-range-thumb { cursor: inherit; }
  }
  &[readonly] {
    pointer-events: none;
  }

  &:focus {
    outline: none;
  }
}

/* ---------------------------------------- */
/*  Buttons                                 */
/* ---------------------------------------- */

a.button,
button {
  display: flex;
  justify-content: center;
  align-items: center;
  height: var(--button-size);
  min-height: var(--button-size);
  gap: 0.25rem;
  padding: 0 0.5rem;
  background: var(--button-background-color);
  border: 1px solid var(--button-border-color);
  border-radius: 4px;
  color: var(--button-text-color);
  font-family: var(--font-sans);
  font-size: var(--font-size-14);
  line-height: normal;
  text-decoration: none;
  cursor: var(--cursor-pointer);
  transition: 0.5s;

  // Inert Children
  > * {
    pointer-events: none;
  }

  &:disabled { // Anchor tags handled separately in typography
    cursor: inherit;
  }

  // Hovered Buttons
  &:hover {
    background: var(--button-hover-background-color);
    color: var(--button-hover-text-color);
    border-color: var(--button-hover-border-color);
  }

  // Focused Buttons
  &:focus {
    outline: 1px solid var(--button-focus-outline-color);
    box-shadow: 0 0 4px var(--button-focus-outline-color);
  }

  // Active Buttons - appear as focused
  &.active {
    outline: 1px solid var(--button-focus-outline-color);
    box-shadow: 0 0 4px var(--button-focus-outline-color);
  }
}

/** Bright Buttons */
// TODO this doesn't really make sense and should be deprecated
button.bright,
a.button.bright {
  text-transform: uppercase;
}
