@layer components {
  /*
   * Autocomplete lookup field.
   *
   * A text input with a dropdown list of search results.
   * Driven by data attributes via app-lookup-field.js.
   */

  .app-lookup-field {
    position: relative;
  }

  /* ── Input wrapper ──────────────────────────────────────────────────── */

  .app-lookup-field-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
  }

  .app-lookup-field-input {
    padding-right: 2.5rem;
    margin-bottom: 0;
  }

  .app-lookup-field-input[aria-expanded="true"] {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-color: var(--app-primary, #635bff);
  }

  /* ── Clear / spinner icons ──────────────────────────────────────────── */

  .app-lookup-field-indicator {
    position: absolute;
    right: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    pointer-events: none;
    color: var(--app-muted-color);
  }

  .app-lookup-field-clear {
    pointer-events: auto;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    color: var(--app-muted-color);
    font-size: var(--text-base, 1rem);
    line-height: var(--leading-none);
    transition: color 0.15s ease;
  }

  .app-lookup-field-clear:hover {
    color: var(--app-color);
  }

  .app-lookup-field-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--app-border);
    border-top-color: var(--app-primary, #635bff);
    border-radius: 50%;
    animation: app-lookup-spin 0.6s linear infinite;
  }

  @keyframes app-lookup-spin {
    to { transform: rotate(360deg); }
  }

  /* ── Dropdown ───────────────────────────────────────────────────────── */

  .app-lookup-field-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--app-card-background-color, #fff);
    border: 1px solid var(--app-primary, #635bff);
    border-top: none;
    border-radius: 0 0 var(--app-border-radius) var(--app-border-radius);
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.08);
    max-height: 16rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    list-style: none;
    margin: 0;
    padding: 0.25rem 0;
  }

  .app-lookup-field-dropdown[hidden] {
    display: none;
  }

  /* ── Option items ───────────────────────────────────────────────────── */

  .app-lookup-field-option {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: var(--text-sm, 0.875rem);
    color: var(--app-color);
    transition: background-color 0.1s ease;
  }

  .app-lookup-field-option:hover,
  .app-lookup-field-option[aria-selected="true"] {
    background: color-mix(in srgb, var(--app-primary, #635bff) 8%, transparent);
  }

  .app-lookup-field-option[aria-selected="true"] {
    color: var(--app-primary, #635bff);
  }

  .app-lookup-field-option-label {
    font-weight: var(--font-medium, 500);
  }

  .app-lookup-field-option-meta {
    font-size: var(--text-xs, 0.75rem);
    color: var(--app-muted-color);
  }

  /* ── Empty / error messages ─────────────────────────────────────────── */

  .app-lookup-field-message {
    padding: 0.75rem;
    font-size: var(--text-sm, 0.875rem);
    color: var(--app-muted-color);
    text-align: center;
  }

  /* ── Selected state ─────────────────────────────────────────────────── */

  .app-lookup-field-input[data-lookup-selected] {
    background: var(--app-card-background-color, #fff);
  }
}
