// ==========================================================================
// Monitor.Cat — Form Inputs
// ==========================================================================

@use 'tokens' as *;

.monitorcat-wrap {
  // ---------------------------------------------------------------------------
  // Text inputs, selects, textareas
  // ---------------------------------------------------------------------------
  .mc-input,
  .mc-select,
  .mc-textarea {
    display: block;
    width: 100%;
    min-height: 3.1rem;
    padding: 0.74rem 1rem;
    font-family: $mc-font-body;
    font-size: 1rem;
    line-height: 1.5;
    color: $mc-text;
    background: $mc-white;
    border: 1.5px solid $mc-input-border;
    border-radius: $mc-radius-input;
    outline: none;
    transition:
      border-color $mc-transition-base,
      box-shadow $mc-transition-base;
    -webkit-appearance: none;
    appearance: none;

    &::placeholder {
      color: $mc-text-light;
    }

    &:hover {
      border-color: rgba(148, 163, 184, 0.4);
    }

    &:focus {
      border-color: $mc-primary;
      box-shadow: 0 0 0 0.25rem rgba($mc-primary, 0.16);
    }

    &:disabled {
      opacity: 0.55;
      cursor: not-allowed;
      background: $mc-base;
    }

    &.is-error {
      border-color: $mc-coral-strong;
      box-shadow: 0 0 0 0.25rem rgba($mc-coral-strong, 0.12);
    }

    &.is-success {
      border-color: $mc-mint-strong;
      box-shadow: 0 0 0 0.25rem rgba($mc-mint-strong, 0.12);
    }
  }

  // ---------------------------------------------------------------------------
  // Select — custom arrow (fallback for plain selects)
  // ---------------------------------------------------------------------------
  .mc-select {
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%2394A3B8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 12px 8px;
  }

  // ---------------------------------------------------------------------------
  // Custom dropdown (enhanced select)
  // ---------------------------------------------------------------------------
  .mc-dropdown {
    position: relative;
    display: inline-block;

    // Hide native select when enhanced.
    > .mc-select {
      position: absolute;
      opacity: 0;
      pointer-events: none;
      width: 0;
      height: 0;
      overflow: hidden;
    }

    // Open-state styles (nested to avoid .monitorcat-wrap selector issues).
    &.is-open .mc-dropdown-trigger {
      border-color: $mc-primary;
      box-shadow: 0 0 0 0.25rem rgba($mc-primary, 0.16);
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 6.5l5-5 5 5' stroke='%23FF9F43' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    }

    &.is-open .mc-dropdown-list {
      opacity: 1;
      transform: translateY(0);
      pointer-events: auto;
    }
  }

  .mc-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.74rem 1rem;
    padding-right: 2.5rem;
    font-family: $mc-font-body;
    font-size: 1rem;
    line-height: 1.5;
    color: $mc-text;
    background: $mc-white;
    border: 1.5px solid $mc-input-border;
    border-radius: $mc-radius-input;
    cursor: pointer;
    white-space: nowrap;
    outline: none;
    transition:
      border-color $mc-transition-base,
      box-shadow $mc-transition-base;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%2394A3B8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 12px 8px;

    &:hover {
      border-color: rgba(148, 163, 184, 0.4);
    }

    &:focus {
      border-color: $mc-primary;
      box-shadow: 0 0 0 0.25rem rgba($mc-primary, 0.16);
    }
  }

  .mc-dropdown-trigger-sm {
    padding: 8px 32px 8px 12px;
    font-size: 0.8125rem;
  }

  .mc-dropdown-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 100;
    min-width: 100%;
    max-height: 280px;
    overflow-y: auto;
    padding: 6px;
    background: $mc-white;
    border: 1.5px solid $mc-input-border;
    border-radius: $mc-radius-input;
    box-shadow: $mc-shadow-card;
    opacity: 0;
    transform: translateY(-4px);
    transition:
      opacity 0.2s $mc-ease-spring,
      transform 0.2s $mc-ease-spring;
    pointer-events: none;

    // Scrollbar styling.
    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: transparent;
    }

    &::-webkit-scrollbar-thumb {
      background: rgba($mc-text-light, 0.3);
      border-radius: 3px;

      &:hover {
        background: rgba($mc-text-light, 0.5);
      }
    }
  }

  .mc-dropdown-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: $mc-font-body;
    font-size: 0.875rem;
    line-height: 1.4;
    color: $mc-text-medium;
    background: none;
    border: none;
    border-radius: calc(#{$mc-radius-input} - 6px);
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    outline: none;
    transition:
      background-color 0.15s ease,
      color 0.15s ease;

    &:hover,
    &.is-focused {
      background: $mc-primary-light;
      color: $mc-text;
    }

    &.is-selected {
      background: rgba($mc-primary, 0.12);
      color: $mc-text;
      font-weight: 500;
    }

    &.is-selected::before {
      content: '';
      flex-shrink: 0;
      width: 6px;
      height: 6px;
      background: $mc-primary;
      border-radius: 50%;
    }
  }

  // ---------------------------------------------------------------------------
  // Textarea
  // ---------------------------------------------------------------------------
  .mc-textarea {
    min-height: 8rem;
    resize: vertical;
  }

  // ---------------------------------------------------------------------------
  // Checkbox / Radio (custom)
  // ---------------------------------------------------------------------------
  .mc-checkbox,
  .mc-radio {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    color: $mc-text;

    input {
      width: 20px;
      height: 20px;
      margin: 0;
      cursor: pointer;
      accent-color: $mc-primary;
    }
  }

  // ---------------------------------------------------------------------------
  // Toggle switch
  // ---------------------------------------------------------------------------
  .mc-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    cursor: pointer;

    input {
      position: absolute;
      opacity: 0;
      width: 0;
      height: 0;
    }

    .mc-toggle-track {
      width: 44px;
      height: 24px;
      background: $mc-base-alt;
      border: 1.5px solid $mc-input-border;
      border-radius: 999px;
      position: relative;
      transition:
        background-color $mc-transition-base,
        border-color $mc-transition-base;

      &::after {
        content: '';
        position: absolute;
        top: 2px;
        left: 2px;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: $mc-white;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
        transition: transform $mc-transition-base;
      }
    }

    input:checked + .mc-toggle-track {
      background: $mc-primary;
      border-color: $mc-primary;

      &::after {
        transform: translateX(20px);
      }
    }

    input:focus-visible + .mc-toggle-track {
      outline: 3px solid $mc-cyan;
      outline-offset: 2px;
    }

    input:disabled + .mc-toggle-track {
      opacity: 0.55;
      cursor: not-allowed;
    }
  }

  .mc-toggle-label {
    font-size: 0.9375rem;
    color: $mc-text-medium;
  }

  // ---------------------------------------------------------------------------
  // Form group / label
  // ---------------------------------------------------------------------------
  .mc-form-group {
    margin-bottom: 1.25rem;
  }

  .mc-form-label {
    display: block;
    font-family: $mc-font-body;
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: $mc-text-light;
    margin-bottom: 0.5rem;
  }

  .mc-form-hint {
    font-size: 0.8125rem;
    color: $mc-text-light;
    margin-top: 0.35rem;
  }

  .mc-form-error {
    font-size: 0.8125rem;
    color: $mc-coral-strong;
    margin-top: 0.35rem;
  }
}
