@layer components {
  .form-group {
    @apply mb-6;
  }

  .form-label {
    @apply block mb-1.5 select-none font-medium text-sm text-gray-700 dark:text-gray-300;

    &.form-label-required {
      @apply after:content-['*'] after:absolute after:text-red-600 after:top-0 relative after:pl-px;
    }
  }

  .form-input {
    @apply rounded-md px-3 py-1.5 border border-gray-300 bg-white focus:border-gray-400/80 focus:ring-4 focus:ring-gray-400/10 focus:outline-none dark:bg-gray-800 dark:focus:border-gray-600 placeholder-gray-600/80 dark:focus:ring-gray-600/30 dark:placeholder:text-gray-200/50 font-normal antialiased font-sans w-full shadow-gray-200/30 dark:shadow-gray-900/20 dark:border-gray-600/80 shadow-xs;

    &:disabled {
      @apply shadow-none cursor-not-allowed pointer-events-none select-none bg-gray-100/90 dark:bg-gray-800/90 dark:opacity-70;
    }
  }

  .form-input-sm {
    @apply text-sm;
  }

  .form-textarea {
    @apply rounded-md px-3 py-1.5 border border-gray-300 bg-white shadow-xs focus:border-gray-400/80 focus:ring-4 focus:ring-gray-400/10 focus:outline-none dark:bg-gray-800 dark:border-gray-500/80 dark:focus:border-gray-500 placeholder-gray-500/60 dark:focus:ring-gray-500/40 dark:placeholder:text-gray-300/60 min-h-[100px] w-full;

    &:disabled {
      @apply shadow-none cursor-not-allowed pointer-events-none select-none bg-gray-100/90 dark:bg-gray-800/90 dark:opacity-70;
    }
  }

  .form-file {
    @apply block w-full text-sm text-gray-500 dark:text-gray-400 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-gray-100 file:text-gray-700 hover:file:bg-gray-200/80 dark:file:bg-primary-600 dark:file:text-gray-100 dark:hover:file:text-gray-100 dark:hover:file:bg-primary-700;
  }

  .form-input-color {
    @apply size-8 transition border border-gray-200 rounded-full appearance-none focus:border-gray-400 focus:shadow focus:ring-4 focus:ring-gray-400/10 dark:border-gray-600;

    &::-webkit-color-swatch-wrapper,
    &::-webkit-color-swatch {
      @apply p-0 border-2 border-white rounded-full dark:border-gray-700;
    }
  }

  .form-input-datalist {
    &::-webkit-calendar-picker-indicator {
      @apply hidden!;
    }
  }

  /* Requires range_controller.js */
  .form-input-range {
    @apply relative bg-transparent appearance-none focus:outline-none;

    --range-fill: 0;

    &::-webkit-slider-thumb {
      @apply appearance-none border-2 border-white h-4 w-4 rounded-full bg-white cursor-pointer relative -top-1.5 shadow outline-1 outline-gray-300 focus:ring-4 focus:outline-gray-400 hover:outline-gray-400 dark:bg-gray-800 dark:focus:outline-gray-600 dark:hover:outline-gray-600 dark:border-gray-500 dark:outline-gray-700;
    }

    &::-moz-range-thumb {
      @apply appearance-none border-2 border-white h-4 w-4 rounded-full bg-white cursor-pointer relative -top-1.5 shadow outline-1 outline-gray-300 focus:ring-4 focus:outline-gray-400 hover:outline-gray-400 dark:bg-gray-800 dark:focus:outline-gray-600 dark:hover:outline-gray-600 dark:border-gray-500 dark:outline-gray-700;
    }

    &::-ms-thumb {
      @apply appearance-none border-2 border-white h-4 w-4 rounded-full bg-white cursor-pointer relative -top-1.5 shadow outline-1 outline-gray-300 focus:ring-4 focus:outline-gray-400 hover:outline-gray-400 dark:bg-gray-800 dark:focus:outline-gray-600 dark:hover:outline-gray-600 dark:border-gray-500 dark:outline-gray-700;
    }

    &::-webkit-slider-runnable-track {
      @apply w-full h-1 rounded-lg cursor-pointer;
      background: linear-gradient(
        to right,
        var(--color-primary-500) var(--range-fill),
        var(--color-gray-300) var(--range-fill)
      );

      @variant dark {
        background: linear-gradient(
          to right,
          var(--color-primary-500) var(--range-fill),
          var(--color-gray-700) var(--range-fill)
        );
      }
    }

    &::-moz-range-track {
      @apply w-full h-1 rounded-lg cursor-pointer;
      background: linear-gradient(
        to right,
        var(--color-primary-500) var(--range-fill),
        var(--color-gray-300) var(--range-fill)
      );

      @variant dark {
        background: linear-gradient(
          to right,
          var(--color-primary-500) var(--range-fill),
          var(--color-gray-700) var(--range-fill)
        );
      }
    }

    &::-ms-track {
      @apply w-full h-1 rounded-lg cursor-pointer;
      background: linear-gradient(
        to right,
        var(--color-primary-500) var(--range-fill),
        var(--color-gray-300) var(--range-fill)
      );

      @variant dark {
        background: linear-gradient(
          to right,
          var(--color-primary-500) var(--range-fill),
          var(--color-gray-700) var(--range-fill)
        );
      }
    }

    &:focus::-webkit-slider-runnable-track {
      @apply bg-gray-200 dark:bg-gray-600;
    }

    &:focus::-moz-range-track {
      @apply bg-gray-200 dark:bg-gray-600;
    }

    &:focus::-ms-track {
      @apply bg-gray-200 dark:bg-gray-600;
    }
  }

  .form-input-error {
    @apply text-red-800 border-red-500 focus:ring-red-50 focus:border-red-400 dark:border-red-400 dark:text-red-300 dark:focus:ring-red-300/20;

    + svg {
      @apply block!;

      + p {
        @apply block!;
      }
    }
  }

  .form-select {
    @apply appearance-none px-3 py-1.5 border border-gray-300 bg-white font-normal placeholder:text-gray-500 rounded-md block w-full focus:outline-none focus:ring-4 focus:ring-gray-400/10 focus:border-gray-400/80 text-gray-900 dark:focus:border-gray-600 dark:text-white dark:placeholder:text-gray-400 shadow-xs dark:bg-gray-800 dark:focus:ring-gray-500/40 font-sans dark:shadow-gray-900/20 dark:border-gray-600/80;

    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%2334497e' stroke-linecap='round' stroke-linejoin='round' stroke-width='1' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    background-position: right calc(var(--spacing) * 2) center;
    print-color-adjust: exact;

    @variant dark {
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    }

    &:disabled {
      @apply shadow-none cursor-not-allowed pointer-events-none select-none bg-gray-100/90 dark:bg-gray-800/90 dark:opacity-70;
    }

    &.form-select-sort {
      @apply border-none shadow-none appearance-none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cg fill='none'%3E%3Cpath d='M8.25 15L12 18.75 15.75 15m-7.5-6L12 5.25 15.75 9' stroke='currentColor' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3C/path%3E%3C/g%3E%3C/svg%3E");

      @variant dark {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ctitle%3Echevron-up-down%3C/title%3E%3Cg fill='none'%3E%3Cpath d='M8.25 15L12 18.75 15.75 15m-7.5-6L12 5.25 15.75 9' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3C/path%3E%3C/g%3E%3C/svg%3E");
      }
    }
  }

  .form-datetime-select {
    @apply flex items-center gap-2.5 text-gray-300;

    select {
      @apply appearance-none px-3 py-1.5 border border-gray-300 bg-white font-normal placeholder:text-gray-500 rounded-md block w-full focus:outline-none focus:ring-4 focus:ring-gray-400/10 focus:border-gray-400/80 text-gray-900 dark:focus:border-gray-600 dark:text-white dark:placeholder:text-gray-400 shadow-xs dark:bg-gray-800 dark:focus:ring-gray-500/40 font-sans dark:shadow-gray-900/20 dark:border-gray-600/80;

      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%2334497e' stroke-linecap='round' stroke-linejoin='round' stroke-width='1' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
      background-repeat: no-repeat;
      background-size: 1.5em 1.5em;
      background-position: right calc(var(--spacing) * 2) center;
      print-color-adjust: exact;

      @variant dark {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
      }
    }
  }

  .form-input-checkbox {
    @apply rounded-sm border appearance-none border-slate-400  checked:bg-primary-500  checked:border-primary-500 checked:ring-2 checked:ring-primary-500/10 checked:accent-primary-500 text-primary-600 dark:bg-slate-700 dark:border-slate-600 focus:ring-primary-500/30 dark:checked:border-primary-400 dark:checked:accent-primary-400 size-4 outline-hidden;

    &:checked {
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3 6-6'/%3e%3c/svg%3e");
    }

    + label {
      @apply select-none;
    }
  }

  .form-input-radio {
    @apply appearance-none rounded-full border border-slate-400 focus:ring-2 checked:ring-primary-200  checked:shadow-primary-600 text-primary-600 focus-visible:text-primary-600 focus-visible:ring-primary-200 focus-visible:outline-hidden dark:bg-slate-700 dark:border-slate-600 dark:checked:border-primary-400 dark:checked:accent-primary-400 size-4 checked:bg-primary-500 checked:border-primary-500;

    &:checked {
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3ccircle cx='10' cy='10' r='4' fill='%23fff'/%3e%3c/svg%3e");
    }

    + label {
      @apply select-none;
    }
  }

  .form-input-switch {
    @apply hidden;

    &:disabled + label {
      @apply cursor-not-allowed opacity-70;
    }

    &:disabled + label::after {
      @apply shadow-none!;
    }

    &:checked + label::before {
      @apply dark:bg-emerald-600 bg-emerald-500;
    }

    &:checked + label::after {
      transform: translate3d(16px, 0, 0);
      background-size: 10px 10px;
      @apply bg-white bg-center bg-no-repeat;
    }

    + label {
      @apply inline-flex cursor-pointer leading-6 select-none relative font-normal text-[15px];

      &:before {
        @apply content-[""] block bg-gray-300 rounded-full h-6 w-10 mr-3 transition-colors ease-out flex-shrink-0 dark:bg-gray-700;
      }

      &:after {
        @apply content-[""] block bg-white rounded-full size-4 absolute top-[4px] left-[4px] transition-transform ease-out shadow-md;
      }
    }
  }
}
